From cb6475e58a7af64db828471962d2400cda841395 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 31 May 2013 17:26:12 -0400 Subject: idoscalemenuitem: make the scale expand and fill in the menu item --- src/idoscalemenuitem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 25460bb..9f1c57d 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -389,18 +389,18 @@ update_packing (IdoScaleMenuItem *self, IdoScaleMenuItemStyle style) { case IDO_SCALE_MENU_ITEM_STYLE_IMAGE: gtk_box_pack_start (box, priv->primary_image, FALSE, FALSE, 0); - gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0); + gtk_box_pack_start (box, priv->scale, TRUE, TRUE, 0); gtk_box_pack_start (box, priv->secondary_image, FALSE, FALSE, 0); break; case IDO_SCALE_MENU_ITEM_STYLE_LABEL: gtk_box_pack_start (box, priv->primary_label, FALSE, FALSE, 0); - gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0); + gtk_box_pack_start (box, priv->scale, TRUE, TRUE, 0); gtk_box_pack_start (box, priv->secondary_label, FALSE, FALSE, 0); break; default: - gtk_box_pack_start (box, priv->scale, FALSE, FALSE, 0); + gtk_box_pack_start (box, priv->scale, TRUE, TRUE, 0); break; } -- cgit v1.2.3 From 03dc54fbc259422813dc790c1d7f39757cb9b7ec Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 31 May 2013 18:50:09 -0400 Subject: Add ido_action_helper_change_state --- src/idoactionhelper.c | 25 +++++++++++++++++++++++++ src/idoactionhelper.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/idoactionhelper.c b/src/idoactionhelper.c index fdd9479..f0e300b 100644 --- a/src/idoactionhelper.c +++ b/src/idoactionhelper.c @@ -401,3 +401,28 @@ ido_action_helper_activate (IdoActionHelper *helper) if (helper->actions && helper->action_name) g_action_group_activate_action (helper->actions, helper->action_name, helper->action_target); } + +/** + * ido_action_helper_change_action_state: + * @helper: an #IdoActionHelper + * @state: the proposed new state of the action + * + * Requests changing the state of the action that is associated with + * @helper to @state. + * + * If @state is floating, it is consumed. + */ +void +ido_action_helper_change_action_state (IdoActionHelper *helper, + GVariant *state) +{ + g_return_if_fail (IDO_IS_ACTION_HELPER (helper)); + g_return_if_fail (state != NULL); + + g_variant_ref_sink (state); + + if (helper->actions && helper->action_name) + g_action_group_change_action_state (helper->actions, helper->action_name, state); + + g_variant_unref (state); +} diff --git a/src/idoactionhelper.h b/src/idoactionhelper.h index 22cdcae..27dafb7 100644 --- a/src/idoactionhelper.h +++ b/src/idoactionhelper.h @@ -41,4 +41,7 @@ GVariant * ido_action_helper_get_action_target (IdoActionHelper *helper void ido_action_helper_activate (IdoActionHelper *helper); +void ido_action_helper_change_action_state (IdoActionHelper *helper, + GVariant *state); + #endif -- cgit v1.2.3 From 26d057cbae600da0a1e5601187e899707c1b1738 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 31 May 2013 18:51:10 -0400 Subject: Add support for creating scale menu items from a menu model --- src/idomenuitemfactory.c | 4 ++ src/idoscalemenuitem.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++ src/idoscalemenuitem.h | 3 ++ 3 files changed, 134 insertions(+) diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 59f3630..0ff84a8 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -21,6 +21,7 @@ #include #include "idousermenuitem.h" +#include "idoscalemenuitem.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)) @@ -48,6 +49,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); + else if (g_str_equal (type, "com.canonical.unity.slider")) + item = ido_scale_menu_item_new_from_model (menuitem, actions); + return item; } diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 9f1c57d..8fca9f6 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -30,6 +30,7 @@ #include "idorange.h" #include "idoscalemenuitem.h" #include "idotypebuiltins.h" +#include "idoactionhelper.h" static void ido_scale_menu_item_set_property (GObject *object, guint prop_id, @@ -802,6 +803,37 @@ ido_scale_menu_item_get_secondary_image (IdoScaleMenuItem *menuitem) return priv->secondary_image; } +/** + * ido_scale_menu_item_set_icons: + * @item: a #IdoScaleMenuItem + * @primary-icon: (allow-none): the primary icon, or %NULL + * @secondary-icon: (allow-non): the secondary icon, %NULL + * + * Sets the icons of @item to @primary_icon and @secondary_icon. + * Pass %NULL for either of them to unset the icon. + */ +static void +ido_scale_menu_item_set_icons (IdoScaleMenuItem *item, + GIcon *primary_icon, + GIcon *secondary_icon) +{ + GtkWidget *primary; + GtkWidget *secondary; + + primary = ido_scale_menu_item_get_primary_image (item); + secondary = ido_scale_menu_item_get_secondary_image (item); + + if (primary_icon) + gtk_image_set_from_gicon (GTK_IMAGE (primary), primary_icon, GTK_ICON_SIZE_MENU); + else + gtk_image_clear (GTK_IMAGE (primary)); + + if (secondary_icon) + gtk_image_set_from_gicon (GTK_IMAGE (secondary), secondary_icon, GTK_ICON_SIZE_MENU); + else + gtk_image_clear (GTK_IMAGE (secondary)); +} + /** * ido_scale_menu_item_get_primary_label: * @menuitem: The #IdoScaleMenuItem @@ -942,4 +974,99 @@ default_secondary_clicked_handler (IdoScaleMenuItem * item) gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj)); } +/** + * ido_scale_menu_item_state_changed: + * + * Updates a IdoScaleMenuItem from @state. State must be a double which + * contains the current value of the slider. + */ +static void +ido_scale_menu_item_state_changed (IdoActionHelper *helper, + GVariant *state, + gpointer user_data) +{ + GtkWidget *scale; + + scale = ido_scale_menu_item_get_scale (IDO_SCALE_MENU_ITEM (ido_action_helper_get_widget (helper))); + gtk_range_set_value (GTK_RANGE (scale), g_variant_get_double (state)); +} + +static void +ido_scale_menu_item_value_changed (GtkScale *scale, + gpointer user_data) +{ + IdoActionHelper *helper = user_data; + gdouble value; + + value = gtk_range_get_value (GTK_RANGE (scale)); + ido_action_helper_change_action_state (helper, g_variant_new_double (value)); +} + +static GIcon * +menu_item_get_icon (GMenuItem *menuitem, + const gchar *attribute) +{ + GVariant *value; + + value = g_menu_item_get_attribute_value (menuitem, attribute, NULL); + + return value ? g_icon_deserialize (value) : NULL; +} + +/** + * ido_scale_menu_item_new_from_model: + * + * Creates a new #IdoScaleMenuItem. If @menuitem contains an action, it + * will be bound to that action in @actions. + * + * Returns: (transfer full): a new #IdoScaleMenuItem + */ +GtkMenuItem * +ido_scale_menu_item_new_from_model (GMenuItem *menuitem, + GActionGroup *actions) +{ + GtkWidget *item; + gchar *action; + gdouble min = 0.0; + gdouble max = 100.0; + gdouble step = 1.0; + GIcon *primary_icon; + GIcon *secondary_icon; + + g_menu_item_get_attribute (menuitem, "min-value", "d", &min); + g_menu_item_get_attribute (menuitem, "max-value", "d", &max); + g_menu_item_get_attribute (menuitem, "step", "d", &step); + + item = ido_scale_menu_item_new_with_range ("Volume", IDO_RANGE_STYLE_DEFAULT, 0.0, min, max, step); + ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (item), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); + + if (g_menu_item_get_attribute (menuitem, "action", "s", &action)) + { + IdoActionHelper *helper; + GtkWidget *scale; + + helper = ido_action_helper_new (item, actions, action, NULL); + g_signal_connect (helper, "action-state-changed", + G_CALLBACK (ido_scale_menu_item_state_changed), NULL); + + scale = ido_scale_menu_item_get_scale (IDO_SCALE_MENU_ITEM (item)); + g_signal_connect (scale, "value-changed", G_CALLBACK (ido_scale_menu_item_value_changed), helper); + + g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); + + g_free (action); + } + + primary_icon = menu_item_get_icon (menuitem, "primary-icon"); + secondary_icon = menu_item_get_icon (menuitem, "secondary-icon"); + ido_scale_menu_item_set_icons (IDO_SCALE_MENU_ITEM (item), primary_icon, secondary_icon); + + if (primary_icon) + g_object_unref (primary_icon); + if (secondary_icon) + g_object_unref (secondary_icon); + + return GTK_MENU_ITEM (item); +} + #define __IDO_SCALE_MENU_ITEM_C__ diff --git a/src/idoscalemenuitem.h b/src/idoscalemenuitem.h index 2d63f3c..2c32a49 100644 --- a/src/idoscalemenuitem.h +++ b/src/idoscalemenuitem.h @@ -92,6 +92,9 @@ void ido_scale_menu_item_set_secondary_label (IdoScaleMenuItem void ido_scale_menu_item_primary_clicked (IdoScaleMenuItem *menuitem); void ido_scale_menu_item_secondary_clicked (IdoScaleMenuItem *menuitem); +GtkMenuItem * ido_scale_menu_item_new_from_model (GMenuItem *menuitem, + GActionGroup *actions); + G_END_DECLS #endif /* __IDO_SCALE_MENU_ITEM_H__ */ -- cgit v1.2.3 From c23cdfcb1536e1ed01b728c629ec1ee9ff0d8f01 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 31 May 2013 19:38:19 -0400 Subject: debian: add new symbols --- debian/libido3-0.1-0.symbols | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 342ee31..b03c9da 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -33,6 +33,7 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_scale_menu_item_set_secondary_label@Base 0.1.9 ido_scale_menu_item_set_style@Base 0.1.9 ido_scale_menu_item_style_get_type@Base 0.1.9 + ido_scale_menu_item_new_from_model@Base 0replaceme ido_switch_menu_item_get_content_area@Base 12.10.0 ido_switch_menu_item_get_type@Base 12.10.0 ido_switch_menu_item_new@Base 12.10.0 @@ -59,6 +60,7 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_timeline_set_screen@Base 0.1.8 ido_timeline_start@Base 0.1.8 ido_action_helper_activate@Base 0replaceme + ido_action_helper_change_action_state@Base 0replaceme ido_action_helper_get_action_target@Base 0replaceme ido_action_helper_get_type@Base 0replaceme ido_action_helper_get_widget@Base 0replaceme -- cgit v1.2.3 From 8db174af12924e1800de19df436fe8592ea50f23 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 7 Jun 2013 16:55:11 -0400 Subject: idoscalemenuitem: look "{min,max}-icon" on the GMenuItem 'primary' and 'secondary' might be confusing. --- src/idoscalemenuitem.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 8fca9f6..7aaf9d6 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -1030,8 +1030,8 @@ ido_scale_menu_item_new_from_model (GMenuItem *menuitem, gdouble min = 0.0; gdouble max = 100.0; gdouble step = 1.0; - GIcon *primary_icon; - GIcon *secondary_icon; + GIcon *min_icon; + GIcon *max_icon; g_menu_item_get_attribute (menuitem, "min-value", "d", &min); g_menu_item_get_attribute (menuitem, "max-value", "d", &max); @@ -1057,14 +1057,14 @@ ido_scale_menu_item_new_from_model (GMenuItem *menuitem, g_free (action); } - primary_icon = menu_item_get_icon (menuitem, "primary-icon"); - secondary_icon = menu_item_get_icon (menuitem, "secondary-icon"); - ido_scale_menu_item_set_icons (IDO_SCALE_MENU_ITEM (item), primary_icon, secondary_icon); + min_icon = menu_item_get_icon (menuitem, "min-icon"); + max_icon = menu_item_get_icon (menuitem, "max-icon"); + ido_scale_menu_item_set_icons (IDO_SCALE_MENU_ITEM (item), min_icon, max_icon); - if (primary_icon) - g_object_unref (primary_icon); - if (secondary_icon) - g_object_unref (secondary_icon); + if (min_icon) + g_object_unref (min_icon); + if (max_icon) + g_object_unref (max_icon); return GTK_MENU_ITEM (item); } -- cgit v1.2.3