From af9183664c534c39d12e34b5c8e7c14ea189ce8b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 5 Sep 2012 15:21:16 +0200 Subject: Watch desktop files for changes This introduces a slightly clumsy "destroy" signal for AppSection to notify outsiders that the desktop file was deleted. This will do for now, but a larger refactoring which pulls all the desktop-file-reading code out of appsection is in order. --- src/messages-service.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 15c5123..ed9bfe4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -45,7 +45,6 @@ static GMenu *menu; static GMenuModel *chat_section; static GSettings *settings; - static gchar * g_app_info_get_simple_id (GAppInfo *appinfo) { @@ -138,6 +137,23 @@ uses_chat_status_changed (GObject *object, g_object_unref (first_section); } +static void +remove_section (AppSection *section, + const gchar *id) +{ + int pos = g_menu_find_section (menu, app_section_get_menu (section)); + if (pos >= 0) + g_menu_remove (menu, pos); + g_action_muxer_remove (action_muxer, id); + + g_signal_handlers_disconnect_by_func (section, actions_changed, NULL); + g_signal_handlers_disconnect_by_func (section, draws_attention_changed, NULL); + g_signal_handlers_disconnect_by_func (section, uses_chat_status_changed, NULL); + g_signal_handlers_disconnect_by_func (section, remove_section, NULL); + + g_hash_table_remove (applications, id); +} + static AppSection * add_application (const gchar *desktop_id) { @@ -167,6 +183,11 @@ add_application (const gchar *desktop_id) G_CALLBACK (draws_attention_changed), NULL); g_signal_connect (section, "notify::uses-chat-status", G_CALLBACK (uses_chat_status_changed), NULL); + g_signal_connect_data (section, "destroy", + G_CALLBACK (remove_section), + g_strdup (id), + (GClosureNotify) g_free, + 0); /* TODO insert it at the right position (alphabetically by application name) */ menuitem = g_menu_item_new_section (NULL, app_section_get_menu (section)); @@ -197,20 +218,13 @@ remove_application (const char *desktop_id) section = g_hash_table_lookup (applications, id); if (section) { - int pos = g_menu_find_section (menu, app_section_get_menu (section)); - if (pos >= 0) - g_menu_remove (menu, pos); - g_action_muxer_remove (action_muxer, id); - - g_signal_handlers_disconnect_by_func (section, actions_changed, NULL); - g_signal_handlers_disconnect_by_func (section, draws_attention_changed, NULL); - g_signal_handlers_disconnect_by_func (section, uses_chat_status_changed, NULL); + remove_section (section, id); } else { + g_hash_table_remove (applications, id); g_warning ("could not remove '%s', it's not registered", desktop_id); } - g_hash_table_remove (applications, id); g_free (id); g_object_unref (appinfo); } -- cgit v1.2.3 From bdf943c3c2d9aef1511d24e928e9d8652a17e703 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 5 Sep 2012 21:25:28 +0200 Subject: messages-service.c: remove redundant g_hash_table_remove --- src/messages-service.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index ed9bfe4..acf4995 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -221,7 +221,6 @@ remove_application (const char *desktop_id) remove_section (section, id); } else { - g_hash_table_remove (applications, id); g_warning ("could not remove '%s', it's not registered", desktop_id); } -- cgit v1.2.3