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(+) (limited to 'src') 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(+) (limited to 'src') 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(+) (limited to 'src') 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(-) (limited to 'src') 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(+) (limited to 'src') 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(+) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(-) (limited to 'src') 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(+) (limited to 'src') 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 From 79f4b7e53cc1a26d37de1daf98fdcb9a6f803aa8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 21:24:31 -0500 Subject: Basic code to monitor the directories --- src/messages-service.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 8b9b5cb..b153eda 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -24,6 +24,7 @@ with this program. If not, see . #include #include #include +#include #include @@ -53,6 +54,8 @@ 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); +static void blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); +static void app_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); /* @@ -164,6 +167,7 @@ launcherList_sort (gconstpointer a, gconstpointer b) */ static GHashTable * blacklist = NULL; +static GFileMonitor * blacklistdirmon = NULL; /* Initialize the black list and start to setup handlers for it. */ @@ -180,6 +184,12 @@ blacklist_init (gpointer data) return FALSE; } + GFile * filedir = g_file_new_for_path(blacklistdir); + blacklistdirmon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); + if (blacklistdirmon != NULL) { + g_signal_connect(G_OBJECT(blacklistdirmon), "changed", G_CALLBACK(blacklist_dir_changed), NULL); + } + GError * error = NULL; GDir * dir = g_dir_open(blacklistdir, 0, &error); if (dir == NULL) { @@ -277,6 +287,16 @@ blacklist_check (const gchar * desktop_file) return FALSE; } +/* A callback everytime the blacklist directory changes + in some way. It needs to handle that. */ +static void +blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + g_debug("Blacklist directory changed!"); + + return; +} + /* * More code */ @@ -659,6 +679,14 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } +static void +app_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data) +{ + gchar * directory = (gchar *)user_data; + g_debug("Application directory changed: %s", directory); + return; +} + /* Check to see if a new desktop file causes any of the launchers to be eclipsed by a running process */ @@ -762,6 +790,12 @@ build_launchers (gpointer data) return FALSE; } + GFile * filedir = g_file_new_for_path(directory); + GFileMonitor * dirmon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); + if (dirmon != NULL) { + g_signal_connect(G_OBJECT(dirmon), "changed", G_CALLBACK(app_dir_changed), directory); + } + GError * error = NULL; GDir * dir = g_dir_open(directory, 0, &error); if (dir == NULL) { -- cgit v1.2.3 From 33e07dab3aafaf7219b3284a95ad4f16755d677d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 14:01:38 -0500 Subject: Turning blacklist dir changes into events --- src/messages-service.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index b153eda..4e03c26 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -53,7 +53,7 @@ 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); +static gboolean blacklist_remove (gpointer data); static void blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); static void app_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); @@ -258,17 +258,18 @@ blacklist_add (gpointer udata) } } - blacklist_remove(NULL); return FALSE; } /* 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) +static gboolean +blacklist_remove (gpointer data) { + gchar * definition_file = (gchar *)data; + g_debug("Removing: %s", definition_file); - return; + return FALSE; } /* Check to see if a particular desktop file is @@ -294,6 +295,23 @@ blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, { g_debug("Blacklist directory changed!"); + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: { + gchar * path = g_file_get_path(file); + g_debug("\tDelete: %s", path); + g_idle_add(blacklist_remove, path); + break; + } + case G_FILE_MONITOR_EVENT_CREATED: { + gchar * path = g_file_get_path(file); + g_debug("\tCreate: %s", path); + g_idle_add(blacklist_add, path); + break; + } + default: + break; + } + return; } -- cgit v1.2.3 From 10a149cf899e14f6ef5dd4be97d21f450fd8bd0f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 14:53:06 -0500 Subject: Fleshing out remove to try to get rid of all these blacklist items. --- src/messages-service.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 4e03c26..9c015e2 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -261,6 +261,14 @@ blacklist_add (gpointer udata) return FALSE; } +/* Looks through the list of definition files and + tries to match the one passed in. */ +static gboolean +blacklist_find_def (gpointer key, gpointer value, gpointer data) +{ + return !g_strcmp0((gchar *)value, (gchar *)data); +} + /* Remove a black list item based on the definition file and uneclipse those launchers blocked by it. */ static gboolean @@ -269,6 +277,31 @@ blacklist_remove (gpointer data) gchar * definition_file = (gchar *)data; g_debug("Removing: %s", definition_file); + gpointer key = g_hash_table_find(blacklist, blacklist_find_def, data); + if (key == NULL) { + g_debug("\tNot found!"); + return FALSE; + } + + GList * launcheritem; + for (launcheritem = launcherList; launcheritem != NULL; launcheritem = launcheritem->next) { + launcherList_t * li = (launcherList_t *)launcheritem->data; + if (!g_strcmp0(launcher_menu_item_get_desktop(li->menuitem), (gchar *)key)) { + GList * serveritem; + for (serveritem = serverList; serveritem != NULL; serveritem = serveritem->next) { + serverList_t * si = (serverList_t *)serveritem->data; + if (!g_strcmp0(app_menu_item_get_desktop(si->menuitem), (gchar *)key)) { + break; + } + } + if (serveritem == NULL) { + launcher_menu_item_set_eclipsed(li->menuitem, FALSE); + } + } + } + + g_hash_table_remove(blacklist, key); + return FALSE; } -- cgit v1.2.3 From 51992ee519580718b3904adaabc76004dba6f323 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 15:12:51 -0500 Subject: I'd have to say that hash_table_find didn't do what I expected, and is pretty useless. --- src/messages-service.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 9c015e2..7d48769 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -261,14 +261,6 @@ blacklist_add (gpointer udata) return FALSE; } -/* Looks through the list of definition files and - tries to match the one passed in. */ -static gboolean -blacklist_find_def (gpointer key, gpointer value, gpointer data) -{ - return !g_strcmp0((gchar *)value, (gchar *)data); -} - /* Remove a black list item based on the definition file and uneclipse those launchers blocked by it. */ static gboolean @@ -277,8 +269,19 @@ blacklist_remove (gpointer data) gchar * definition_file = (gchar *)data; g_debug("Removing: %s", definition_file); - gpointer key = g_hash_table_find(blacklist, blacklist_find_def, data); - if (key == NULL) { + GHashTableIter iter; + gpointer key, value; + gboolean found = FALSE; + + g_hash_table_iter_init(&iter, blacklist); + while (g_hash_table_iter_next(&iter, &key, &value)) { + if (!g_strcmp0((gchar *)value, definition_file)) { + found = TRUE; + break; + } + } + + if (!found) { g_debug("\tNot found!"); return FALSE; } @@ -300,7 +303,9 @@ blacklist_remove (gpointer data) } } - g_hash_table_remove(blacklist, key); + if (!g_hash_table_remove(blacklist, key)) { + g_warning("Unable to remove '%s' with value '%s'", definition_file, (gchar *)key); + } return FALSE; } -- cgit v1.2.3 From 50a2c4e02d275a88e5c917e4946410383c44b3ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 15:31:13 -0500 Subject: Start responding to changes in the applications directories --- src/messages-service.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 7d48769..3a145d6 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -56,6 +56,7 @@ static gboolean blacklist_add (gpointer data); static gboolean blacklist_remove (gpointer data); static void blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); static void app_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFileMonitorEvent event_type, gpointer user_data); +static gboolean destroy_launcher (gpointer data); /* @@ -740,6 +741,24 @@ app_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, GFile { gchar * directory = (gchar *)user_data; g_debug("Application directory changed: %s", directory); + + switch (event_type) { + case G_FILE_MONITOR_EVENT_DELETED: { + gchar * path = g_file_get_path(file); + g_debug("\tDelete: %s", path); + g_idle_add(destroy_launcher, path); + break; + } + case G_FILE_MONITOR_EVENT_CREATED: { + gchar * path = g_file_get_path(file); + g_debug("\tCreate: %s", path); + g_idle_add(build_launcher, path); + break; + } + default: + break; + } + return; } @@ -793,6 +812,15 @@ remove_eclipses (AppMenuItem * ai) return; } +/* Remove a launcher from the system. We need to figure + out what it's up to! */ +static gboolean +destroy_launcher (gpointer data) +{ + + return FALSE; +} + /* This function turns a specific file into a menu item and registers it appropriately with everyone */ static gboolean -- cgit v1.2.3 From 1827c88f591eeefa129b700c0eb4b1710f712272 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 15:56:16 -0500 Subject: The launcher creation didn't test to see if it already exists. Now we keep one launcher per desktop file. Makes sense, eh? That's what we're going for. --- src/messages-service.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 3a145d6..41afb6b 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -147,6 +147,7 @@ imList_sort (gconstpointer a, gconstpointer b) typedef struct _launcherList_t launcherList_t; struct _launcherList_t { LauncherMenuItem * menuitem; + GList * appdiritems; }; static gint @@ -832,7 +833,6 @@ build_launcher (gpointer data) gchar * desktop = NULL; g_file_get_contents(path, &desktop, NULL, NULL); - g_free(path); if (desktop == NULL) { return FALSE; @@ -842,20 +842,37 @@ build_launcher (gpointer data) g_free(desktop); g_debug("\tcontents: %s", trimdesktop); - /* Build the item */ - launcherList_t * ll = g_new0(launcherList_t, 1); - ll->menuitem = launcher_menu_item_new(trimdesktop); - g_free(trimdesktop); + /* Check to see if we already have a launcher */ + GList * listitem; + for (listitem = launcherList; listitem != NULL; listitem = listitem->next) { + launcherList_t * li = (launcherList_t *)listitem->data; + if (!g_strcmp0(launcher_menu_item_get_desktop(li->menuitem), trimdesktop)) { + break; + } + } - /* Add it to the list */ - launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); + if (listitem == NULL) { + /* If not */ + /* Build the item */ + launcherList_t * ll = g_new0(launcherList_t, 1); + ll->menuitem = launcher_menu_item_new(trimdesktop); + g_free(trimdesktop); + ll->appdiritems = g_list_append(NULL, path); - /* Add it to the menu */ - dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); - resort_menu(root_menuitem); + /* Add it to the list */ + launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); - if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) { - launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); + /* Add it to the menu */ + dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); + resort_menu(root_menuitem); + + if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) { + launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); + } + } else { + /* If so add ourselves */ + launcherList_t * ll = (launcherList_t *)listitem->data; + ll->appdiritems = g_list_append(ll->appdiritems, path); } return FALSE; -- cgit v1.2.3 From 286c51ca41139a2961cfe68a80a458ebf882bae9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 16:15:16 -0500 Subject: Fleshing out the first part of destroy, in that we're just removing an item from a list. --- src/messages-service.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 41afb6b..8617c5d 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -818,6 +818,41 @@ remove_eclipses (AppMenuItem * ai) static gboolean destroy_launcher (gpointer data) { + gchar * appdirentry = (gchar *)data; + + GList * listitem; + GList * direntry; + launcherList_t * li; + gchar * appdir; + + for (listitem = launcherList; listitem != NULL; listitem = listitem->next) { + li = (launcherList_t *)listitem->data; + for (direntry = li->appdiritems; direntry != NULL; direntry = direntry->next) { + appdir = (gchar *)direntry->data; + if (!g_strcmp0(appdir, appdirentry)) { + break; + } + } + + if (direntry != NULL) { + break; + } + } + + if (listitem == NULL) { + g_warning("Removed '%s' by the way of it not seeming to exist anywhere.", appdirentry); + return FALSE; + } + + if (g_list_length(li->appdiritems) > 1) { + /* Just remove this item, and we can move on */ + g_debug("Just removing file entry: %s", appdir); + li->appdiritems = g_list_remove(li->appdiritems, appdir); + g_free(appdir); + return FALSE; + } + + /* Full Destroy */ return FALSE; } -- cgit v1.2.3 From acf054710bea98ee0a63c72cf5e5bcbff8b9bc74 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Aug 2009 16:27:59 -0500 Subject: Now we're really killing these puppies! Don't cry, they weren't cuddly puppies. --- src/messages-service.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/messages-service.c b/src/messages-service.c index 8617c5d..384198a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -853,6 +853,18 @@ destroy_launcher (gpointer data) } /* Full Destroy */ + g_free(appdir); + g_list_free(li->appdiritems); + + if (li->menuitem != NULL) { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li->menuitem), "visible", "false"); + dbusmenu_menuitem_child_delete(root_menuitem, DBUSMENU_MENUITEM(li->menuitem)); + g_object_unref(G_OBJECT(li->menuitem)); + li->menuitem = NULL; + } + + launcherList = g_list_remove(launcherList, li); + g_free(li); return FALSE; } -- cgit v1.2.3