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/idousermenuitem.c | 182 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 60 deletions(-) (limited to 'src/idousermenuitem.c') 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