From b0f699b4d657330edfa56cd27c856db9941d3a0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:04:58 -0500 Subject: Adding in a couple of blacklist check point. --- src/messages-service.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 2020dd3..8743b62 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -143,6 +143,13 @@ launcherList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +static gboolean +blacklist_check (const gchar * desktop_file) +{ + + return FALSE; +} + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -555,6 +562,8 @@ remove_eclipses (AppMenuItem * ai) const gchar * aidesktop = app_menu_item_get_desktop(ai); if (aidesktop == NULL) return; + if (blacklist_check(aidesktop)) return; + GList * llitem; for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { launcherList_t * ll = (launcherList_t *)llitem->data; @@ -602,6 +611,10 @@ build_launcher (gpointer data) dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); resort_menu(root_menuitem); + if (blacklist_check(trimdesktop)) { + launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); + } + return FALSE; } -- cgit v1.2.3 From 754694356af4079753531d5a090c0d7ed9eee828 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:06:52 -0500 Subject: Adding in some seperators to make things more clear. --- src/messages-service.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 8743b62..9879e3a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -51,6 +51,11 @@ static void remove_eclipses (AppMenuItem * ai); static gboolean build_launcher (gpointer data); static gboolean build_launchers (gpointer data); + +/* + * Server List + */ + typedef struct _serverList_t serverList_t; struct _serverList_t { IndicateListenerServer * server; @@ -86,6 +91,10 @@ serverList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +/* + * Item List + */ + typedef struct _imList_t imList_t; struct _imList_t { IndicateListenerServer * server; @@ -124,6 +133,10 @@ imList_sort (gconstpointer a, gconstpointer b) return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem))); } +/* + * Launcher List + */ + typedef struct _launcherList_t launcherList_t; struct _launcherList_t { LauncherMenuItem * menuitem; @@ -143,6 +156,10 @@ launcherList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +/* + * Black List + */ + static gboolean blacklist_check (const gchar * desktop_file) { @@ -150,6 +167,10 @@ blacklist_check (const gchar * desktop_file) return FALSE; } +/* + * More code + */ + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { -- cgit v1.2.3 From ee713f22dd253cf6e757f3ffb4ec839dad91bf31 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:26:56 -0500 Subject: More of a basis for the black list stuff. Some functions and an interface. --- src/messages-service.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 9879e3a..1ff97ca 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -160,9 +160,41 @@ launcherList_sort (gconstpointer a, gconstpointer b) * Black List */ +static GHashTable * blacklist = NULL; + +/* Initialize the black list and start to setup + handlers for it. */ +static void +blacklist_init (gpointer data) +{ + + return; +} + +/* Add a definition file into the black list and eclipse + and launchers that have the same file. */ +static void +blacklist_add (const gchar * definition_file) +{ + + return; +} + +/* Remove a black list item based on the definition file + and uneclipse those launchers blocked by it. */ +static void +blacklist_remove (const gchar * definition_file) +{ + + return; +} + +/* Check to see if a particular desktop file is + in the blacklist. */ static gboolean blacklist_check (const gchar * desktop_file) { + if (blacklist == NULL) return FALSE; return FALSE; } -- cgit v1.2.3 From 528c37375ce30f80c2ca0376d62fd41a3629b66e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:59:45 -0500 Subject: Fleshing out the add function. Just a little. --- src/messages-service.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/messages-service.c b/src/messages-service.c index 1ff97ca..e4290f4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -167,6 +167,8 @@ static GHashTable * blacklist = NULL; static void blacklist_init (gpointer data) { + blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); return; } @@ -174,8 +176,46 @@ blacklist_init (gpointer data) /* Add a definition file into the black list and eclipse and launchers that have the same file. */ static void -blacklist_add (const gchar * definition_file) +blacklist_add (gchar * definition_file) { + /* Dump the file */ + gchar * desktop; + g_file_get_contents(definition_file, &desktop, NULL, NULL); + if (desktop == NULL) { + g_warning("Couldn't get data out of: %s", definition_file); + return; + } + + /* Clean up the data */ + gchar * trimdesktop = pango_trim_string(desktop); + g_free(desktop); + + /* Check for conflicts */ + gpointer data = g_hash_table_lookup(blacklist, trimdesktop); + if (data != NULL) { + gchar * oldfile = (gchar *)data; + if (!g_strcmp0(oldfile, definition_file)) { + g_warning("Already added file '%s'", oldfile); + } else { + g_warning("Already have desktop file '%s' in blacklist file '%s' not adding from '%s'", trimdesktop, oldfile, definition_file); + } + + g_free(trimdesktop); + return; + } + + /* Actually blacklist this thing */ + g_hash_table_insert(blacklist, trimdesktop, definition_file); + g_debug("Adding Blacklist item '%s' for desktop '%s'", definition_file, trimdesktop); + + /* Go through and eclipse folks */ + GList * launcher; + for (launcher = launcherList; launcher != NULL; launcher = launcher->next) { + launcherList_t * item = (launcherList_t *)launcher->data; + if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) { + launcher_menu_item_set_eclipsed(item->menuitem, TRUE); + } + } return; } -- cgit v1.2.3 From cc75cbe10d562c29657f61deda56115362df6179 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:00:25 -0500 Subject: We're taking ownership of that variable as well --- src/messages-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/messages-service.c b/src/messages-service.c index e4290f4..61a4b1a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -201,6 +201,7 @@ blacklist_add (gchar * definition_file) } g_free(trimdesktop); + g_free(definition_file); return; } -- cgit v1.2.3 From 333467a2e1736c372108c954a191e6206cb18849 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:05:38 -0500 Subject: Writing the fairly extensive and complex check function. But, if that's the way it needs to be, I guess it needs to be that way. --- src/messages-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 61a4b1a..e238b78 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -237,6 +237,10 @@ blacklist_check (const gchar * desktop_file) { if (blacklist == NULL) return FALSE; + if (g_hash_table_lookup(blacklist, desktop_file)) { + return TRUE; + } + return FALSE; } -- cgit v1.2.3 From e5d4b846037b0397022f12b5355d6889e5b9adec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:51:01 -0500 Subject: Now parsing the directory on start up. Getting this whole thing started up. --- src/messages-service.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index e238b78..f2768cb 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -50,6 +50,9 @@ static void check_eclipses (AppMenuItem * ai); static void remove_eclipses (AppMenuItem * ai); static gboolean build_launcher (gpointer data); static gboolean build_launchers (gpointer data); +static gboolean blacklist_init (gpointer data); +static gboolean blacklist_add (gpointer data); +static void blacklist_remove (const gchar * definition_file); /* @@ -164,26 +167,53 @@ static GHashTable * blacklist = NULL; /* Initialize the black list and start to setup handlers for it. */ -static void +static gboolean blacklist_init (gpointer data) { blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - return; + gchar * blacklistdir = g_build_filename(g_get_user_config_dir(), USER_BLACKLIST_DIR, NULL); + g_debug("Looking at blacklist: %s", blacklistdir); + if (!g_file_test(blacklistdir, G_FILE_TEST_IS_DIR)) { + g_free(blacklistdir); + return FALSE; + } + + GError * error = NULL; + GDir * dir = g_dir_open(blacklistdir, 0, &error); + if (dir == NULL) { + g_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error->message); + g_error_free(error); + g_free(blacklistdir); + return FALSE; + } + + const gchar * filename = NULL; + while ((filename = g_dir_read_name(dir)) != NULL) { + g_debug("Found file: %s", filename); + gchar * path = g_build_filename(blacklistdir, filename, NULL); + g_idle_add(blacklist_add, path); + } + + g_dir_close(dir); + g_free(blacklistdir); + + return FALSE; } /* Add a definition file into the black list and eclipse and launchers that have the same file. */ -static void -blacklist_add (gchar * definition_file) +static gboolean +blacklist_add (gpointer udata) { + gchar * definition_file = (gchar *)udata; /* Dump the file */ gchar * desktop; g_file_get_contents(definition_file, &desktop, NULL, NULL); if (desktop == NULL) { g_warning("Couldn't get data out of: %s", definition_file); - return; + return FALSE; } /* Clean up the data */ @@ -202,7 +232,7 @@ blacklist_add (gchar * definition_file) g_free(trimdesktop); g_free(definition_file); - return; + return FALSE; } /* Actually blacklist this thing */ @@ -218,7 +248,8 @@ blacklist_add (gchar * definition_file) } } - return; + blacklist_remove(NULL); + return FALSE; } /* Remove a black list item based on the definition file @@ -781,6 +812,7 @@ main (int argc, char ** argv) g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem); g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem); + g_idle_add(blacklist_init, NULL); g_idle_add(build_launchers, NULL); mainloop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3 From f41d2527cb53f8a5ca091e860b6fd5f25f6ce87a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 16:00:12 -0500 Subject: Some debug and fixing checking the desktop file. All good. --- src/messages-service.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/messages-service.c b/src/messages-service.c index f2768cb..a4e8870 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -266,9 +266,11 @@ blacklist_remove (const gchar * definition_file) static gboolean blacklist_check (const gchar * desktop_file) { + g_debug("Checking blacklist for: %s", desktop_file); if (blacklist == NULL) return FALSE; if (g_hash_table_lookup(blacklist, desktop_file)) { + g_debug("\tFound!"); return TRUE; } @@ -740,7 +742,7 @@ build_launcher (gpointer data) dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); resort_menu(root_menuitem); - if (blacklist_check(trimdesktop)) { + if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) { launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); } -- cgit v1.2.3 From 33f40e13838d18687507145c98c1cae48c0bc033 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 20:48:52 -0500 Subject: Switching the build to take the directory as a parameter --- src/messages-service.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index a4e8870..0e4c296 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -756,12 +756,14 @@ build_launcher (gpointer data) static gboolean build_launchers (gpointer data) { - if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) { + gchar * directory = (gchar *)data; + + if (!g_file_test(directory, G_FILE_TEST_IS_DIR)) { return FALSE; } GError * error = NULL; - GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error); + GDir * dir = g_dir_open(directory, 0, &error); if (dir == NULL) { g_warning("Unable to open system apps directory: %s", error->message); g_error_free(error); @@ -771,7 +773,7 @@ build_launchers (gpointer data) const gchar * filename = NULL; while ((filename = g_dir_read_name(dir)) != NULL) { g_debug("Found file: %s", filename); - gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL); + gchar * path = g_build_filename(directory, filename, NULL); g_idle_add(build_launcher, path); } @@ -815,7 +817,7 @@ main (int argc, char ** argv) g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem); g_idle_add(blacklist_init, NULL); - g_idle_add(build_launchers, NULL); + g_idle_add(build_launchers, SYSTEM_APPS_DIR); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); -- cgit v1.2.3 From ce045e0d41054c2ccf8c9e524a4997ea2ee38601 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 20:52:12 -0500 Subject: Adding the user APPS directory to the places where we can find applications --- src/messages-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 0e4c296..8b9b5cb 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -818,9 +818,13 @@ main (int argc, char ** argv) g_idle_add(blacklist_init, NULL); g_idle_add(build_launchers, SYSTEM_APPS_DIR); + gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL); + g_idle_add(build_launchers, userdir); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_free(userdir); + return 0; } -- cgit v1.2.3