diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-10-22 11:38:57 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-10-22 11:38:57 -0400 |
commit | 898a2216d7e206197476741196f8490b137c0260 (patch) | |
tree | 79ab1994af6ecb6f19aa712dc8351b831efabcb6 /src/idoswitchmenuitem.c | |
parent | 8a99eded6f8c2830f6b9c8b3acaddf781e28884e (diff) | |
download | ayatana-ido-898a2216d7e206197476741196f8490b137c0260.tar.gz ayatana-ido-898a2216d7e206197476741196f8490b137c0260.tar.bz2 ayatana-ido-898a2216d7e206197476741196f8490b137c0260.zip |
Make IdoSwitchMenuItem accessible from gtk_menu_new_from_model
Diffstat (limited to 'src/idoswitchmenuitem.c')
-rw-r--r-- | src/idoswitchmenuitem.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/idoswitchmenuitem.c b/src/idoswitchmenuitem.c index 100c6fb..16122f3 100644 --- a/src/idoswitchmenuitem.c +++ b/src/idoswitchmenuitem.c @@ -21,6 +21,7 @@ #include "config.h" #include "idoswitchmenuitem.h" +#include "idoactionhelper.h" static gboolean ido_switch_menu_button_release_event (GtkWidget * widget, GdkEventButton * event); @@ -206,3 +207,63 @@ ido_switch_menu_item_set_icon (IdoSwitchMenuItem *item, gtk_image_clear (GTK_IMAGE (priv->image)); } } + +static void +ido_source_menu_item_state_changed (IdoActionHelper *helper, + GVariant *state, + gpointer user_data) +{ + IdoSwitchMenuItem *item = user_data; + + if (g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN)) + gtk_switch_set_active (GTK_SWITCH (item->priv->switch_w), + g_variant_get_boolean (state)); +} + +GtkMenuItem * +ido_switch_menu_item_new_from_menu_model (GMenuItem *menuitem, + GActionGroup *actions) +{ + GtkMenuItem *item; + gchar *label; + GVariant *serialized_icon; + gchar *action = NULL; + + item = g_object_new (IDO_TYPE_SWITCH_MENU_ITEM, NULL); + + if (g_menu_item_get_attribute (menuitem, "label", "s", &label)) + { + ido_switch_menu_item_set_label (IDO_SWITCH_MENU_ITEM (item), label); + g_free (label); + } + + serialized_icon = g_menu_item_get_attribute_value (menuitem, "icon", NULL); + if (serialized_icon) + { + GIcon *icon; + + icon = g_icon_deserialize (serialized_icon); + if (icon) + { + ido_switch_menu_item_set_icon (IDO_SWITCH_MENU_ITEM (item), icon); + g_object_unref (icon); + } + } + + if (g_menu_item_get_attribute (menuitem, "action", "s", &action)) + { + IdoActionHelper *helper; + + helper = ido_action_helper_new (GTK_WIDGET (item), actions, action, NULL); + g_signal_connect (helper, "action-state-changed", + G_CALLBACK (ido_source_menu_item_state_changed), item); + g_signal_connect_object (item, "activate", + G_CALLBACK (ido_action_helper_activate), helper, + G_CONNECT_SWAPPED); + g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); + + g_free (action); + } + + return item; +} |