From da7efb27a9a7ceef7b6b3a09f2e104dad4d6bd26 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 1 Mar 2015 11:06:48 +0000 Subject: [PATCH] Support for launcher_apps_dir git-svn-id: http://tint2.googlecode.com/svn/trunk@727 121b4492-b84c-0410-8b4c-0d4edfb3f3cc --- src/config.c | 24 ++++++++++++++++++++++++ src/launcher/icon-theme-common.c | 2 +- src/tint2conf/properties.c | 13 ++++++++++++- src/tint2conf/properties.h | 1 + src/tint2conf/properties_rw.c | 22 ++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index abca070..58f25b3 100644 --- a/src/config.c +++ b/src/config.c @@ -149,6 +149,25 @@ int config_get_monitor(char* monitor) return -1; } +void load_launcher_app_dir(const char *path) +{ + GDir *d = g_dir_open(path, 0, NULL); + if (d) { + const gchar *name; + while ((name = g_dir_read_name(d))) { + gchar *file = g_build_filename(path, name, NULL); + if (!g_file_test(file, G_FILE_TEST_IS_DIR) && + g_str_has_suffix(file, ".desktop")) { + panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, (char *)strdup(file)); + } else if (g_file_test(file, G_FILE_TEST_IS_DIR)) { + load_launcher_app_dir(file); + } + g_free(file); + } + g_dir_close(d); + } +} + void add_entry (char *key, char *value) { char *value1=0, *value2=0, *value3=0; @@ -606,6 +625,11 @@ void add_entry (char *key, char *value) char *app = expand_tilde(value); panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app); } + else if (strcmp(key, "launcher_apps_dir") == 0) { + char *path = expand_tilde(value); + load_launcher_app_dir(path); + free(path); + } else if (strcmp(key, "launcher_icon_theme") == 0) { // if XSETTINGS manager running, tint2 use it. if (!icon_theme_name) diff --git a/src/launcher/icon-theme-common.c b/src/launcher/icon-theme-common.c index 21e6e4f..44790a5 100644 --- a/src/launcher/icon-theme-common.c +++ b/src/launcher/icon-theme-common.c @@ -428,7 +428,7 @@ IconThemeWrapper *load_themes(const char *icon_theme_name) while ((name = g_dir_read_name(d))) { gchar *file_name = g_build_filename(path, name, "index.theme", NULL); if (g_file_test(file_name, G_FILE_TEST_EXISTS) && - g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) { + !g_file_test(file_name, G_FILE_TEST_IS_DIR)) { load_themes_helper(name, &wrapper->themes_fallback, &queued); } g_free(file_name); diff --git a/src/tint2conf/properties.c b/src/tint2conf/properties.c index 5aed407..1e02686 100644 --- a/src/tint2conf/properties.c +++ b/src/tint2conf/properties.c @@ -102,6 +102,7 @@ GtkWidget *tooltip_background; GtkListStore *launcher_apps, *all_apps; GtkWidget *launcher_apps_view, *all_apps_view; +GtkWidget *launcher_apps_dirs; GtkWidget *launcher_icon_size, *launcher_icon_theme, *launcher_padding_x, *launcher_padding_y, *launcher_spacing; GtkWidget *margin_x, *margin_y; @@ -1538,7 +1539,7 @@ void load_desktop_files(const gchar *path) const gchar *name; while ((name = g_dir_read_name(d))) { gchar *file = g_build_filename(path, name, NULL); - if (g_file_test(file, G_FILE_TEST_IS_REGULAR) && + if (!g_file_test(file, G_FILE_TEST_IS_DIR) && g_str_has_suffix(file, ".desktop")) { load_desktop_file(file, FALSE); } else if (g_file_test(file, G_FILE_TEST_IS_DIR)) { @@ -1762,6 +1763,16 @@ void create_launcher(GtkWidget *parent) change_paragraph(parent); + label = gtk_label_new(_("Additional application directories")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_label_set_use_markup(GTK_LABEL(label), TRUE); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(parent), label, FALSE, FALSE, 0); + + launcher_apps_dirs = gtk_entry_new(); + gtk_widget_show(launcher_apps_dirs); + gtk_box_pack_start(GTK_BOX(parent), launcher_apps_dirs, FALSE, FALSE, 0); + label = gtk_label_new(_("Appearance")); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); diff --git a/src/tint2conf/properties.h b/src/tint2conf/properties.h index 7c35673..10b8660 100644 --- a/src/tint2conf/properties.h +++ b/src/tint2conf/properties.h @@ -115,6 +115,7 @@ enum { extern GtkListStore *launcher_apps, *all_apps; extern GtkWidget *launcher_apps_view, *all_apps_view; +extern GtkWidget *launcher_apps_dirs; extern GtkWidget *launcher_icon_size, *launcher_icon_theme, *launcher_padding_x, *launcher_padding_y, *launcher_spacing; extern GtkWidget *margin_x, *margin_y; diff --git a/src/tint2conf/properties_rw.c b/src/tint2conf/properties_rw.c index 3cb8c9a..acf0a70 100644 --- a/src/tint2conf/properties_rw.c +++ b/src/tint2conf/properties_rw.c @@ -415,6 +415,18 @@ void config_write_launcher(FILE *fp) g_free(app_path); } + gchar **app_dirs = g_strsplit(gtk_entry_get_text(GTK_ENTRY(launcher_apps_dirs)), ",", 0); + for (index = 0; app_dirs[index]; index++) { + gchar *dir = app_dirs[index]; + g_strstrip(dir); + if (strlen(dir) > 0) { + char *contracted = contract_tilde(dir); + fprintf(fp, "launcher_item_app = %s\n", contracted); + free(contracted); + } + } + g_strfreev(app_dirs); + fprintf(fp, "\n"); } @@ -1086,6 +1098,16 @@ void add_entry(char *key, char *value) load_desktop_file(path, FALSE); free(path); } + else if (strcmp(key, "launcher_apps_dir") == 0) { + char *path = expand_tilde(value); + + if (gtk_entry_get_text_length(GTK_ENTRY(launcher_apps_dirs)) > 0) { + gtk_entry_append_text(GTK_ENTRY(launcher_apps_dirs), ","); + } + gtk_entry_append_text(GTK_ENTRY(launcher_apps_dirs), path); + + free(path); + } else if (strcmp(key, "launcher_icon_theme") == 0) { set_current_icon_theme(value); }