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(+) 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(-) 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(+) 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(-) 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(+) 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(-) 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(+) 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(+) 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 From 19f312f6319d5c3fcb4b21d1e655b08bc4a609de Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Aug 2009 16:01:45 -0500 Subject: Checking to see if error is null before looking inside it. --- src/messages-service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages-service.c b/src/messages-service.c index 384198a..e4982a2 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -195,7 +195,7 @@ blacklist_init (gpointer data) 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_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error == NULL ? "No Message" : error->message); g_error_free(error); g_free(blacklistdir); return FALSE; -- cgit v1.2.3