From 8008ec3c0dbd2dca7697f4f22c90f1d84819d1e0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 23 Jun 2013 18:06:39 -0500 Subject: add ido_guest_menu_item_new_for_model() --- src/idomenuitemfactory.c | 3 + src/idousermenuitem.c | 182 +++++++++++++++++++++++++++++++---------------- src/idousermenuitem.h | 3 + 3 files changed, 128 insertions(+), 60 deletions(-) diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 650c95f..5ded309 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -54,6 +54,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, if (g_str_equal (type, "indicator.user-menu-item")) item = ido_user_menu_item_new_from_model (menuitem, actions); + if (g_str_equal (type, "indicator.guest-menu-item")) + item = ido_guest_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.calendar")) item = ido_calendar_menu_item_new_from_model (menuitem, actions); diff --git a/src/idousermenuitem.c b/src/idousermenuitem.c index 655ae21..ab95d66 100644 --- a/src/idousermenuitem.c +++ b/src/idousermenuitem.c @@ -342,6 +342,86 @@ ido_user_menu_item_new (void) return GTK_WIDGET (g_object_new (IDO_USER_MENU_ITEM_TYPE, NULL)); } +/*** +**** +***/ + +/** + * This is a helper function for creating user menuitems for both + * "indicator.user-menu-item" and "indicator.guest-menu-item", + * since they only differ in how they use their action's state. + */ +static GtkMenuItem * +user_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions, + GCallback state_changed_callback) +{ + guint i; + guint n; + IdoUserMenuItem * ido_user; + gchar * str; + gchar * action; + GVariant * v; + GParameter parameters[4]; + + /* create the ido_user */ + + n = 0; + + if (g_menu_item_get_attribute (menuitem, G_MENU_ATTRIBUTE_LABEL, "s", &str)) + { + GParameter p = { "label", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; + } + + if ((v = g_menu_item_get_attribute_value (menuitem, G_MENU_ATTRIBUTE_ICON, NULL))) + { + GParameter p = { "icon", G_VALUE_INIT }; + GIcon * icon = g_icon_deserialize (v); + g_value_init (&p.value, G_TYPE_OBJECT); + g_value_take_object (&p.value, icon); + g_variant_unref (v); + parameters[n++] = p; + } + + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_user = g_object_newv (IDO_USER_MENU_ITEM_TYPE, n, parameters); + + for (i=0; i