~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/utility.c

  • Committer: Osmo Antero
  • Date: 2021-11-01 16:08:01 UTC
  • Revision ID: osmoma@gmail.com-20211101160801-hv2sap9ri52ii3zq
Version 3.3.0. Initial suport for PipeWire. Removed suport for Skype

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
gchar *substitute_time_and_date_pattern(gchar *pattern) {
304
304
    // Substitue time+date pattern
305
305
 
306
 
    // Typical pattern is: "%Y-%m-%d-%H:%M:%S"
 
306
    // Typical pattern is: "%Y-%m-%d-%H-%M-%S"
307
307
    // See: https://linux.die.net/man/3/strftime
308
308
    time_t t;
309
309
    struct tm *tmp;
749
749
        g_free(filename_pattern);
750
750
 
751
751
        // Translators: This is a default filename pattern. You can keept this as it is.
752
 
        filename_pattern = g_strdup(_("%Y-%m-%d-%H:%M:%S"));
 
752
        filename_pattern = g_strdup(_("%Y-%m-%d-%H-%M-%S"));
753
753
        conf_save_string_value("filename-pattern", filename_pattern);
754
754
    }
755
755
 
889
889
    return TRUE;
890
890
}
891
891
 
892
 
gchar *g_strrstr0(gchar *haystack, gchar *needle) {
 
892
gchar *g_strrstr0(const gchar *haystack, const gchar *needle) {
893
893
    // Same as g_strrstr() but this tests for NULL values (and avoids annoying warnings).
894
894
    if (!(haystack && needle)) return NULL;
895
895
    return g_strrstr(haystack, needle);
931
931
 
932
932
GdkPixbuf *load_icon_pixbuf(gchar *icon_name, guint _size) {
933
933
    // Load icon pixbuf from current icon theme.
934
 
    GdkPixbuf *pixbuf = NULL;
935
 
 
936
934
    if (!icon_name) {
937
935
        return NULL;
938
936
    }
939
937
 
940
 
    // Normally icon name should equal exec name (without path) in .desktip files 
 
938
    // Normally icon name should equal exec name (without path) in .desktop files 
941
939
 
942
940
    // Current icon theme
943
941
    GtkIconTheme *theme = gtk_icon_theme_get_default();
944
942
 
945
943
    // Load icon from its theme
946
 
    pixbuf = gtk_icon_theme_load_icon(theme, icon_name, _size, 0, NULL);
 
944
    GError *error = NULL;
 
945
    GdkPixbuf *pixbuf = NULL;
 
946
    
 
947
    // Check first with gtk_icon_theme_has_icon() to avoid GTK-warning 
 
948
        if (gtk_icon_theme_has_icon(theme, icon_name)) {
 
949
        pixbuf = gtk_icon_theme_load_icon(theme, icon_name, _size, 0, &error);
 
950
        }
947
951
 
948
952
    // Got it?
949
 
    if (!GDK_IS_PIXBUF(pixbuf)) {
 
953
    if (error) {
950
954
                // Some media players set entire path for the icon in .desktop file (this is probably a mistake)
951
955
        // Like: /snap/imsplayer/34/usr/share/imsplayer/icons/imsplayer-128.png
952
956
 
 
957
        g_error_free(error);
 
958
 
953
959
        // Load directly from a file
954
960
        pixbuf = get_pixbuf_from_file(icon_name, _size, _size);
955
961
    }
965
971
    return pixbuf;
966
972
}
967
973
 
 
974
GdkPixbuf *load_icon_pixbuf_from_name_list(gchar *icon_name_list, gchar *delim, guint _size) {
 
975
        // icon_name_list has candidate icon names delimited by delim.
 
976
        //
 
977
        // If ordinary icon_names fail, then try to locad own "xxx.png" icon.
 
978
        // Eg. "audio-card\naudio-speaker-center\nloudspeakers.png";
 
979
 
 
980
        GdkPixbuf *pixbuf = NULL;
 
981
 
 
982
        gchar **lst = g_strsplit(icon_name_list, delim, 20);
 
983
        gint i = 0; 
 
984
        while (lst && lst[i]) {
 
985
 
 
986
                pixbuf = load_icon_pixbuf((gchar*)lst[i], _size);
 
987
 
 
988
                // Got an icon image?
 
989
                if (GDK_IS_PIXBUF(pixbuf)) {
 
990
                        break;
 
991
                }
 
992
                
 
993
                // Is it our own "xxx.png" icon?
 
994
                if (g_strrstr0(lst[i], ".")) {
 
995
                
 
996
                        gchar *path = get_image_path(lst[i]);
 
997
                        pixbuf = get_pixbuf_from_file(path, _size, _size);
 
998
                        g_free(path);
 
999
 
 
1000
                        // Got an icon image?
 
1001
                        if (GDK_IS_PIXBUF(pixbuf)) {
 
1002
                            break;
 
1003
                        }
 
1004
                }
 
1005
                
 
1006
                // Next i
 
1007
                i++;
 
1008
        }
 
1009
 
 
1010
        // Free lst 
 
1011
        g_strfreev(lst);
 
1012
    
 
1013
        return pixbuf;
 
1014
}
 
1015
 
 
1016
#if 0 
 
1017
GdkPixbuf* load_icon_pixbuf(gchar *icon_name) {
 
1018
    GtkIconTheme *icon_theme;
 
1019
    GdkPixbuf *pixbuf;
 
1020
    GError *error = NULL;
 
1021
 
 
1022
    guint size = 22;
 
1023
 
 
1024
    icon_theme = gtk_icon_theme_get_default();
 
1025
 
 
1026
    pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, size, 0, &error);
 
1027
 
 
1028
    if (error) {
 
1029
        g_debug("Couldn't load icon: %s", error->message);
 
1030
        g_error_free(error);
 
1031
    }
 
1032
 
 
1033
    return pixbuf;
 
1034
}
 
1035
#endif
 
1036
 
 
1037
 
968
1038
void kill_program_by_name(gchar *app_name, GPid preserve_pid) {
969
1039
    // Kill all app_name processes. But do not kill preserve_pid.
970
1040
    // Use this to kill programs that do not respond to client requests (dbus request).