From eea45a449eb4de159aab08bad864b27f584af519 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 31 May 2012 19:29:27 +0200 Subject: Put the 'launch' action onto app's menu sections This requires clients to make those menu sections clickable. --- src/app-section.c | 33 +++++++++++++++++++++------------ src/app-section.h | 1 + src/messages-service.c | 9 +++++---- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app-section.c b/src/app-section.c index 5a5e838..5cb2c25 100644 --- a/src/app-section.c +++ b/src/app-section.c @@ -192,9 +192,6 @@ app_section_set_app_info (AppSection *self, { AppSectionPrivate *priv = APP_SECTION_GET_PRIVATE (self); GSimpleAction *launch; - GMenuItem *menuitem; - GIcon *icon; - gchar *iconstr = NULL; gchar *label; g_return_if_fail (priv->appinfo == NULL); @@ -206,9 +203,6 @@ app_section_set_app_info (AppSection *self, priv->appinfo = g_object_ref (appinfo); - icon = g_app_info_get_icon (G_APP_INFO(priv->appinfo)); - iconstr = g_icon_to_string (icon); - launch = g_simple_action_new ("launch", NULL); g_signal_connect (launch, "activate", G_CALLBACK (activate_cb), self); g_simple_action_group_insert (priv->static_shortcuts, G_ACTION (launch)); @@ -218,10 +212,6 @@ app_section_set_app_info (AppSection *self, else label = g_strdup(app_section_get_name (self)); - menuitem = g_menu_item_new (label, "launch"); - g_menu_item_set_attribute (menuitem, INDICATOR_MENU_ATTRIBUTE_ICON_NAME, "s", iconstr); - g_menu_append_item (priv->menu, menuitem); - /* Start to build static shortcuts */ priv->ids = indicator_desktop_shortcuts_new(g_desktop_app_info_get_filename (priv->appinfo), "Messaging Menu"); const gchar ** nicks = indicator_desktop_shortcuts_get_nicks(priv->ids); @@ -245,9 +235,7 @@ app_section_set_app_info (AppSection *self, } g_free(label); - g_free(iconstr); g_object_unref (launch); - g_object_unref (menuitem); } AppSection * @@ -319,3 +307,24 @@ app_section_get_app_info (AppSection *self) return G_APP_INFO (priv->appinfo); } +GMenuItem * +app_section_create_menu_item (AppSection *self) +{ + AppSectionPrivate *priv = APP_SECTION_GET_PRIVATE (self); + GMenuItem *item; + const gchar *name; + gchar *iconstr; + + g_return_val_if_fail (priv->appinfo != NULL, NULL); + + name = g_app_info_get_name (G_APP_INFO (priv->appinfo)); + iconstr = g_icon_to_string (g_app_info_get_icon (G_APP_INFO (priv->appinfo))); + + item = g_menu_item_new (name, "launch"); + g_menu_item_set_attribute (item, INDICATOR_MENU_ATTRIBUTE_ICON_NAME, "s", iconstr); + g_menu_item_set_section (item, G_MENU_MODEL (priv->menu)); + + g_free(iconstr); + return item; +} + diff --git a/src/app-section.h b/src/app-section.h index 7989824..e5c3892 100644 --- a/src/app-section.h +++ b/src/app-section.h @@ -51,6 +51,7 @@ const gchar * app_section_get_name (AppSection * appitem); const gchar * app_section_get_desktop (AppSection * appitem); GMenuModel * app_section_get_menu (AppSection *appitem); GAppInfo * app_section_get_app_info (AppSection *appitem); +GMenuItem * app_section_create_menu_item (AppSection *self); G_END_DECLS diff --git a/src/messages-service.c b/src/messages-service.c index dcce1c5..ddedee9 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -64,13 +64,14 @@ add_application (const gchar *desktop_id, if (!g_hash_table_lookup (applications, desktop_file)) { AppSection *section = app_section_new(appinfo); + GMenuItem *item = app_section_create_menu_item (section); + + g_hash_table_insert (applications, g_strdup (desktop_file), section); /* TODO insert it at the right position (alphabetically by application name) */ - g_menu_insert_section (menu, 2, - app_section_get_name (section), - app_section_get_menu (section)); + g_menu_insert_item (menu, 2, item); - g_hash_table_insert (applications, g_strdup (desktop_file), section); + g_object_unref (item); } g_object_unref (appinfo); -- cgit v1.2.3