aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-08-12 21:33:39 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-08-12 21:33:39 +0200
commit0b24c6a91ff91400568cab9b4d192a0a85db918e (patch)
treef379fb0afa3bd5192734b5f549a0efe2e01a6f28
parentff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca (diff)
downloadayatana-indicator-messages-0b24c6a91ff91400568cab9b4d192a0a85db918e.tar.gz
ayatana-indicator-messages-0b24c6a91ff91400568cab9b4d192a0a85db918e.tar.bz2
ayatana-indicator-messages-0b24c6a91ff91400568cab9b4d192a0a85db918e.zip
Move toplevel menu logic into ImMenu
Also, get rid of only exporting sections if they were non-empty. That was a hack for non-conformant GMenuModel renderers.
-rw-r--r--src/im-menu.c14
-rw-r--r--src/im-menu.h3
-rw-r--r--src/im-phone-menu.c70
3 files changed, 39 insertions, 48 deletions
diff --git a/src/im-menu.c b/src/im-menu.c
index 9f4d3e0..4c660e5 100644
--- a/src/im-menu.c
+++ b/src/im-menu.c
@@ -146,3 +146,17 @@ im_menu_export (ImMenu *menu,
G_MENU_MODEL (priv->toplevel_menu),
error) > 0;
}
+
+void
+im_menu_append_section (ImMenu *menu,
+ GMenuModel *section)
+{
+ ImMenuPrivate *priv;
+
+ g_return_if_fail (IM_IS_MENU (menu));
+ g_return_if_fail (G_IS_MENU_MODEL (section));
+
+ priv = im_menu_get_instance_private (menu);
+
+ g_menu_append_section (priv->menu, NULL, section);
+}
diff --git a/src/im-menu.h b/src/im-menu.h
index 7276020..ec41bff 100644
--- a/src/im-menu.h
+++ b/src/im-menu.h
@@ -53,4 +53,7 @@ gboolean im_menu_export (ImMenu
const gchar *object_path,
GError **error);
+void im_menu_append_section (ImMenu *menu,
+ GMenuModel *section);
+
#endif
diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c
index b24e235..7b5132b 100644
--- a/src/im-phone-menu.c
+++ b/src/im-phone-menu.c
@@ -27,7 +27,6 @@ struct _ImPhoneMenu
{
ImMenu parent;
- GMenu *toplevel_menu;
GMenu *message_section;
GMenu *source_section;
};
@@ -59,37 +58,29 @@ im_phone_menu_foreach_item_with_action (GMenuModel *menu,
}
static void
-im_phone_menu_update_toplevel (ImPhoneMenu *menu)
+im_phone_menu_constructed (GObject *object)
{
- if (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)) ||
- g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section)))
- {
- if (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)) == 0)
- {
- GMenuItem *item;
+ ImPhoneMenu *menu = IM_PHONE_MENU (object);
+ ImApplicationList *applist;
- g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section));
- g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section));
+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->message_section));
+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->source_section));
- item = g_menu_item_new ("Clear All", "indicator.remove-all");
- g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button");
- g_menu_append_item (menu->toplevel_menu, item);
+ {
+ GMenu *clear_section;
+ GMenuItem *item;
- g_object_unref (item);
- }
- }
- else
- {
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)))
- g_menu_remove (menu->toplevel_menu, 0);
- }
-}
+ clear_section = g_menu_new ();
-static void
-im_phone_menu_constructed (GObject *object)
-{
- ImPhoneMenu *menu = IM_PHONE_MENU (object);
- ImApplicationList *applist;
+ item = g_menu_item_new ("Clear All", "indicator.remove-all");
+ g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button");
+ g_menu_append_item (clear_section, item);
+
+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (clear_section));
+
+ g_object_unref (item);
+ g_object_unref (clear_section);
+ }
applist = im_menu_get_application_list (IM_MENU (menu));
@@ -106,7 +97,6 @@ im_phone_menu_dispose (GObject *object)
{
ImPhoneMenu *menu = IM_PHONE_MENU (object);
- g_clear_object (&menu->toplevel_menu);
g_clear_object (&menu->message_section);
g_clear_object (&menu->source_section);
@@ -132,16 +122,8 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass)
static void
im_phone_menu_init (ImPhoneMenu *menu)
{
- menu->toplevel_menu = g_menu_new ();
menu->message_section = g_menu_new ();
menu->source_section = g_menu_new ();
-
- g_signal_connect_swapped (menu->message_section, "items-changed",
- G_CALLBACK (im_phone_menu_update_toplevel), menu);
- g_signal_connect_swapped (menu->source_section, "items-changed",
- G_CALLBACK (im_phone_menu_update_toplevel), menu);
-
- im_phone_menu_update_toplevel (menu);
}
ImPhoneMenu *
@@ -327,17 +309,9 @@ im_phone_menu_remove_all (ImPhoneMenu *menu)
{
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)))
- g_menu_remove (menu->toplevel_menu, 0);
-
- g_object_unref (menu->message_section);
- g_object_unref (menu->source_section);
-
- menu->message_section = g_menu_new ();
- menu->source_section = g_menu_new ();
+ while (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)))
+ g_menu_remove (menu->message_section, 0);
- g_signal_connect_swapped (menu->message_section, "items-changed",
- G_CALLBACK (im_phone_menu_update_toplevel), menu);
- g_signal_connect_swapped (menu->source_section, "items-changed",
- G_CALLBACK (im_phone_menu_update_toplevel), menu);
+ while (g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section)))
+ g_menu_remove (menu->source_section, 0);
}