aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-10-22 11:38:57 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-10-22 11:38:57 -0400
commit898a2216d7e206197476741196f8490b137c0260 (patch)
tree79ab1994af6ecb6f19aa712dc8351b831efabcb6 /src
parent8a99eded6f8c2830f6b9c8b3acaddf781e28884e (diff)
downloadayatana-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')
-rw-r--r--src/idomenuitemfactory.c4
-rw-r--r--src/idoswitchmenuitem.c61
-rw-r--r--src/idoswitchmenuitem.h3
3 files changed, 68 insertions, 0 deletions
diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c
index 376134e..11beaa8 100644
--- a/src/idomenuitemfactory.c
+++ b/src/idomenuitemfactory.c
@@ -31,6 +31,7 @@
#include "idoplaybackmenuitem.h"
#include "idoapplicationmenuitem.h"
#include "idosourcemenuitem.h"
+#include "idoswitchmenuitem.h"
#define IDO_TYPE_MENU_ITEM_FACTORY (ido_menu_item_factory_get_type ())
#define IDO_MENU_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory))
@@ -91,6 +92,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory,
else if (g_str_equal (type, "com.canonical.indicator.messages.source"))
item = ido_source_menu_item_new_from_menu_model (menuitem, actions);
+ else if (g_str_equal (type, "com.canonical.indicator.switch"))
+ item = ido_switch_menu_item_new_from_menu_model (menuitem, actions);
+
return item;
}
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;
+}
diff --git a/src/idoswitchmenuitem.h b/src/idoswitchmenuitem.h
index 9130edd..222b473 100644
--- a/src/idoswitchmenuitem.h
+++ b/src/idoswitchmenuitem.h
@@ -52,6 +52,9 @@ GType ido_switch_menu_item_get_type (void) G_GNUC_CONST;
GtkWidget *ido_switch_menu_item_new (void);
GtkContainer *ido_switch_menu_item_get_content_area (IdoSwitchMenuItem * item);
+GtkMenuItem * ido_switch_menu_item_new_from_menu_model (GMenuItem *menuitem,
+ GActionGroup *actions);
+
void ido_switch_menu_item_set_label (IdoSwitchMenuItem *item,
const gchar *label);