From 52875e80b988a7f0c5af3d4ebe720917f93c873d Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 10:37:04 +0200 Subject: libmessaging-menu: warn when desktop_id is NULL (instead of crashing) --- libmessaging-menu/messaging-menu.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 336e89c..b8aaf20 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -74,6 +74,21 @@ static void global_status_changed (IndicatorMessagesService *service, const gchar *status_str, gpointer user_data); +static void +messaging_menu_app_set_desktop_id (MessagingMenuApp *app, + const gchar *desktop_id) +{ + g_return_if_fail (desktop_id != NULL); + + /* no need to clean up, it's construct only */ + app->appinfo = g_desktop_app_info_new (desktop_id); + if (app->appinfo == NULL) + { + g_warning ("could not find the desktop file for '%s'", + desktop_id); + } +} + static void messaging_menu_app_set_property (GObject *object, guint prop_id, @@ -85,12 +100,7 @@ messaging_menu_app_set_property (GObject *object, switch (prop_id) { case PROP_DESKTOP_ID: - app->appinfo = g_desktop_app_info_new (g_value_get_string (value)); - if (app->appinfo == NULL) - { - g_warning ("could not find the desktop file for '%s'", - g_value_get_string (value)); - } + messaging_menu_app_set_desktop_id (app, g_value_get_string (value)); break; default: -- cgit v1.2.3 From dd134484da92096b4116cdfb88c36756bf234722 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 10:41:15 +0200 Subject: libmessaging-menu: annotate icon parameters with allow-none --- libmessaging-menu/messaging-menu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index b8aaf20..78fff20 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -511,7 +511,7 @@ messaging_menu_app_insert_source (MessagingMenuApp *app, * messaging_menu_app_append_source: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * * Appends a new message source to the end of the section representing @app. @@ -535,7 +535,7 @@ messaging_menu_app_append_source (MessagingMenuApp *app, * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @count: the count for the source * @@ -563,7 +563,7 @@ messaging_menu_app_insert_source_with_count (MessagingMenuApp *app, * messaging_menu_app_append_source_with_count: * @app: a #MessagingMenuApp * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @count: the count for the source * @@ -589,7 +589,7 @@ void messaging_menu_app_append_source_with_count (MessagingMenuApp *app, * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @time: the time when the source was created * @@ -618,7 +618,7 @@ messaging_menu_app_insert_source_with_time (MessagingMenuApp *app, * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @time: the time when the source was created * @@ -645,7 +645,7 @@ messaging_menu_app_append_source_with_time (MessagingMenuApp *app, * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @str: a string associated with the source * @@ -674,7 +674,7 @@ messaging_menu_app_insert_source_with_string (MessagingMenuApp *app, * @app: a #MessagingMenuApp * @position: the position at which to insert the source * @id: a unique identifier for the source to be added - * @icon: the icon associated with the source + * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source * @str: a string associated with the source * -- cgit v1.2.3 From d519ebfb52d69765f4e1ec0aa3f115f2c04c9bb4 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 12:20:21 +0200 Subject: libmessaging-menu: remove sources when they are activated Applications shouldn't leave message sources that the user clicked on in the messaging menu. This patch spares apps from having to call remove_source in all of their handlers. --- libmessaging-menu/messaging-menu.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 78fff20..daeaeb5 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -419,6 +419,8 @@ source_action_activated (GTupleAction *action, const gchar *name = g_action_get_name (G_ACTION (action)); GQuark q = g_quark_from_string (name); + messaging_menu_app_remove_source (app, name); + g_signal_emit (app, signals[ACTIVATE_SOURCE], q, name); } -- cgit v1.2.3 From 95aa2195c3e7e5873a1508e77b8305cf92e2215b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 12:23:24 +0200 Subject: libmessaging-menu: don't warn when removing a non-existant source --- libmessaging-menu/messaging-menu.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index daeaeb5..69fb3b7 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -716,10 +716,7 @@ messaging_menu_app_remove_source (MessagingMenuApp *app, g_return_if_fail (source_id != NULL); if (g_simple_action_group_lookup (app->source_actions, source_id) == NULL) - { - g_warning ("%s: a source with id '%s' doesn't exist", G_STRFUNC, source_id); return; - } n_items = g_menu_model_get_n_items (G_MENU_MODEL (app->menu)); for (i = 0; i < n_items; i++) -- cgit v1.2.3 From 423d61b377588e67cb570480828f752925371f85 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 16:31:30 +0200 Subject: libmessaging-menu: re-register with the service if it restarted --- libmessaging-menu/messaging-menu.c | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 69fb3b7..387412e 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -39,6 +39,7 @@ struct _MessagingMenuApp GMenu *menu; IndicatorMessagesService *messages_service; + guint watch_id; GCancellable *cancellable; }; @@ -119,6 +120,12 @@ messaging_menu_app_dispose (GObject *object) { MessagingMenuApp *app = MESSAGING_MENU_APP (object); + if (app->watch_id > 0) + { + g_bus_unwatch_name (app->watch_id); + app->watch_id = 0; + } + if (app->cancellable) { g_cancellable_cancel (app->cancellable); @@ -243,6 +250,17 @@ got_session_bus (GObject *source, g_error_free (error); } + g_object_unref (bus); +} + +static void +indicator_messages_appeared (GDBusConnection *bus, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + indicator_messages_service_proxy_new (bus, G_DBUS_PROXY_FLAGS_NONE, "com.canonical.indicator.messages", @@ -250,8 +268,22 @@ got_session_bus (GObject *source, app->cancellable, created_messages_service, app); +} - g_object_unref (bus); +static void +indicator_messages_vanished (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + MessagingMenuApp *app = user_data; + + if (app->messages_service) + { + g_signal_handlers_disconnect_by_func (app->messages_service, + global_status_changed, + app); + g_clear_object (&app->messages_service); + } } static void @@ -272,6 +304,14 @@ messaging_menu_app_init (MessagingMenuApp *app) app->cancellable, got_session_bus, app); + + app->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + "com.canonical.indicator.messages", + G_BUS_NAME_WATCHER_FLAGS_NONE, + indicator_messages_appeared, + indicator_messages_vanished, + app, + NULL); } /** -- cgit v1.2.3 From 195ec17a1b7e3fc89d95d21fc463499222339a63 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 23 Aug 2012 22:39:19 +0200 Subject: libmessaging-menu: fix g-ir-scanner warnings Also, enable warnings by default and only include messaging-menu.[ch] in the gir. --- libmessaging-menu/messaging-menu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 387412e..0d80163 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -327,7 +327,7 @@ messaging_menu_app_init (MessagingMenuApp *app) * The messaging menu will return to marking the application as not running as * soon as the returned #MessagingMenuApp is destroyed. * - * Returns: (transfer-full): a new #MessagingMenuApp + * Returns: (transfer full): a new #MessagingMenuApp */ MessagingMenuApp * messaging_menu_app_new (const gchar *desktop_id) @@ -658,7 +658,6 @@ messaging_menu_app_insert_source_with_time (MessagingMenuApp *app, /** * messaging_menu_app_append_source_with_time: * @app: a #MessagingMenuApp - * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source @@ -714,7 +713,6 @@ messaging_menu_app_insert_source_with_string (MessagingMenuApp *app, /** * messaging_menu_app_append_source_with_string: * @app: a #MessagingMenuApp - * @position: the position at which to insert the source * @id: a unique identifier for the source to be added * @icon: (allow-none): the icon associated with the source * @label: a user-visible string best describing the source @@ -832,7 +830,7 @@ messaging_menu_app_set_source_time (MessagingMenuApp *app, * messaging_menu_app_set_source_string: * @app: a #MessagingMenuApp * @source_id: a source id - * @string: the new string for the source + * @str: the new string for the source * * Updates the string displayed next to @source_id to @str. * -- cgit v1.2.3 From 28c6d543fc310d5098edb61d506aa8383a96de6f Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 24 Aug 2012 11:21:00 +0200 Subject: Don't use '&' in variant format strings of g_menu_item_* calls --- libmessaging-menu/messaging-menu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'libmessaging-menu/messaging-menu.c') diff --git a/libmessaging-menu/messaging-menu.c b/libmessaging-menu/messaging-menu.c index 0d80163..b090352 100644 --- a/libmessaging-menu/messaging-menu.c +++ b/libmessaging-menu/messaging-menu.c @@ -759,14 +759,18 @@ messaging_menu_app_remove_source (MessagingMenuApp *app, n_items = g_menu_model_get_n_items (G_MENU_MODEL (app->menu)); for (i = 0; i < n_items; i++) { - const gchar *action = NULL; + gchar *action; - g_menu_model_get_item_attribute (G_MENU_MODEL (app->menu), i, - "action", "&s", &action); - if (!g_strcmp0 (action, source_id)) + if (g_menu_model_get_item_attribute (G_MENU_MODEL (app->menu), i, + "action", "s", &action)) { - g_menu_remove (app->menu, i); - break; + if (!g_strcmp0 (action, source_id)) + { + g_menu_remove (app->menu, i); + break; + } + + g_free (action); } } -- cgit v1.2.3