From 7614e880579dce57aca4ba01dca328d03a1271fc Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 26 Mar 2014 17:07:21 +0100 Subject: idobasicmenuitem: put progress menu item into its own file --- src/Makefile.am | 2 + src/idobasicmenuitem.c | 84 -------------------------------------- src/idobasicmenuitem.h | 8 ---- src/idomenuitemfactory.c | 1 + src/idoprogressmenuitem.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ src/idoprogressmenuitem.h | 28 +++++++++++++ 6 files changed, 132 insertions(+), 92 deletions(-) create mode 100644 src/idoprogressmenuitem.c create mode 100644 src/idoprogressmenuitem.h diff --git a/src/Makefile.am b/src/Makefile.am index 3a3ea31..9b722cb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ sources_h = \ idousermenuitem.h \ idoappointmentmenuitem.h \ idobasicmenuitem.h \ + idoprogressmenuitem.h \ idotimestampmenuitem.h \ idolocationmenuitem.h \ idotimeline.h \ @@ -88,6 +89,7 @@ libido_0_1_la_SOURCES = \ idoplaybackmenuitem.c \ idoappointmentmenuitem.c \ idobasicmenuitem.c \ + idoprogressmenuitem.c \ idotimestampmenuitem.c \ idolocationmenuitem.c \ idoapplicationmenuitem.c \ diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index f07cc14..d5ab0de 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -305,87 +305,3 @@ ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * se NULL); } } - -/*** -**** -**** Progress Menu Item -**** -***/ - -static void -on_progress_action_state_changed (IdoActionHelper * helper, - GVariant * state, - gpointer unused G_GNUC_UNUSED) -{ - IdoBasicMenuItem * ido_menu_item; - char * str; - - ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper)); - - g_return_if_fail (ido_menu_item != NULL); - g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32)); - - str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state)); - ido_basic_menu_item_set_secondary_text (ido_menu_item, str); - g_free (str); -} - -/** - * ido_progress_menu_item_new_from_model: - * @menu_item: the corresponding menuitem - * @actions: action group to tell when this GtkMenuItem is activated - * - * Creates a new progress menuitem with properties initialized from - * the menuitem's attributes. - * - * If the menuitem's 'action' attribute is set, trigger that action - * in @actions when this IdoBasicMenuItem is activated. - */ -GtkMenuItem * -ido_progress_menu_item_new_from_model (GMenuItem * menu_item, - GActionGroup * actions) -{ - guint i; - guint n; - gchar * str; - IdoBasicMenuItem * ido_menu_item; - GParameter parameters[4]; - - /* create the ido menuitem */; - - n = 0; - - if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) - { - GParameter p = { "text", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_STRING); - g_value_take_string (&p.value, str); - parameters[n++] = p; - } - - g_assert (n <= G_N_ELEMENTS (parameters)); - ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters); - - for (i=0; i + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "idoprogressmenuitem.h" +#include "idobasicmenuitem.h" +#include "idoactionhelper.h" + +static void +on_progress_action_state_changed (IdoActionHelper * helper, + GVariant * state, + gpointer unused G_GNUC_UNUSED) +{ + IdoBasicMenuItem * ido_menu_item; + char * str; + + ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper)); + + g_return_if_fail (ido_menu_item != NULL); + g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32)); + + str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state)); + ido_basic_menu_item_set_secondary_text (ido_menu_item, str); + g_free (str); +} + +/** + * ido_progress_menu_item_new_from_model: + * @menu_item: the corresponding menuitem + * @actions: action group to tell when this GtkMenuItem is activated + * + * Creates a new progress menuitem with properties initialized from + * the menuitem's attributes. + * + * If the menuitem's 'action' attribute is set, trigger that action + * in @actions when this IdoBasicMenuItem is activated. + */ +GtkMenuItem * +ido_progress_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + guint i; + guint n; + gchar * str; + IdoBasicMenuItem * ido_menu_item; + GParameter parameters[4]; + + /* create the ido menuitem */; + + n = 0; + + if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + { + GParameter p = { "text", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; + } + + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters); + + for (i=0; i + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef __IDO_PROGRESS_MENU_ITEM_H__ +#define __IDO_PROGRESS_MENU_ITEM_H__ + +#include + +GtkMenuItem * ido_progress_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + +#endif -- cgit v1.2.3 From b5fe1d71145ecb8b9e31e7baafc89a46506dae4c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 27 Mar 2014 13:16:10 +0100 Subject: Expose IdoBasicMenuItem as com.canonical.indicator.basic --- src/idobasicmenuitem.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ src/idobasicmenuitem.h | 3 +++ src/idomenuitemfactory.c | 3 +++ 3 files changed, 65 insertions(+) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index d5ab0de..c023b7b 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -305,3 +305,62 @@ ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * se NULL); } } + +static void +ido_basic_menu_item_activate (GtkMenuItem *item, + gpointer user_data) +{ + IdoActionHelper *helper = user_data; + + ido_action_helper_activate (helper); +} + +GtkMenuItem * +ido_basic_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + GtkWidget *item; + gchar *label; + gchar *action; + GVariant *serialized_icon; + + item = ido_basic_menu_item_new (); + + if (g_menu_item_get_attribute (menu_item, "label", "s", &label)) + { + ido_basic_menu_item_set_text (IDO_BASIC_MENU_ITEM (item), label); + g_free (label); + } + + serialized_icon = g_menu_item_get_attribute_value (menu_item, "icon", NULL); + if (serialized_icon) + { + GIcon *icon; + + icon = g_icon_deserialize (serialized_icon); + ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM (item), icon); + + g_object_unref (icon); + g_variant_unref (serialized_icon); + } + + if (g_menu_item_get_attribute (menu_item, "action", "s", &action)) + { + IdoActionHelper *helper; + GVariant *target; + + target = g_menu_item_get_attribute_value (menu_item, "target", NULL); + + helper = ido_action_helper_new (item, actions, action, target); + g_signal_connect_object (item, "activate", + G_CALLBACK (ido_basic_menu_item_activate), helper, + 0); + g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); + + if (target) + g_variant_unref (target); + g_free (action); + } + + return GTK_MENU_ITEM (item); +} diff --git a/src/idobasicmenuitem.h b/src/idobasicmenuitem.h index da1216e..6a4b83a 100644 --- a/src/idobasicmenuitem.h +++ b/src/idobasicmenuitem.h @@ -64,6 +64,9 @@ void ido_basic_menu_item_set_text (IdoBasicMenuItem * self, void ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * text); +GtkMenuItem * ido_basic_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + G_END_DECLS #endif diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 7f5d932..cb10cce 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -75,6 +75,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, else if (g_str_equal (type, "com.canonical.indicator.alarm")) item = ido_alarm_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.basic")) + item = ido_basic_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.progress")) item = ido_progress_menu_item_new_from_model (menuitem, actions); -- cgit v1.2.3 From d1403ebce170bbc2d4a53d9e5f4a56156f9a248b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 27 Mar 2014 13:16:39 +0100 Subject: idobasicmenuitem: support non-square icons --- src/idobasicmenuitem.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index c023b7b..da17211 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -253,9 +253,21 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) } else { + GtkIconInfo *info; + const gchar *filename; + GdkPixbuf *pixbuf; + p->icon = g_object_ref (icon); - gtk_image_set_from_gicon (GTK_IMAGE(p->image), p->icon, GTK_ICON_SIZE_MENU); + + info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); + filename = gtk_icon_info_get_filename (info); + pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); + + gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf); gtk_widget_set_visible (p->image, TRUE); + + g_object_unref (info); + g_object_unref (pixbuf); } } } -- cgit v1.2.3 From ab158b1d5405ef962b63f21650521e762e35fc9b Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 27 Mar 2014 17:10:17 +0100 Subject: idobasicmenuitem: add symbol for _new_from_model() --- debian/libido3-0.1-0.symbols | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 8efde79..e1370ad 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -16,6 +16,7 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_basic_menu_item_set_icon_from_file@Base 13.10.0+13.10.20130731 ido_basic_menu_item_set_secondary_text@Base 13.10.0+13.10.20130731 ido_basic_menu_item_set_text@Base 13.10.0+13.10.20130731 + ido_basic_menu_item_new_from_model@Base 0replaceme ido_calendar_menu_item_clear_marks@Base 0.2.1 ido_calendar_menu_item_get_calendar@Base 0.1.10 ido_calendar_menu_item_get_date@Base 0.2.1 -- cgit v1.2.3 From 8269c14ba6a9865cfef818a5ceea0eb93f2ec2ae Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 28 Mar 2014 11:27:12 +0100 Subject: idobasicmenuitem: check return value of gtk_icon_info_get_filename() for NULL --- src/idobasicmenuitem.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index da17211..6185d23 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -245,29 +245,35 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) if (p->icon != icon) { g_clear_object (&p->icon); + gtk_image_clear (GTK_IMAGE(p->image)); if (icon == NULL) { - gtk_image_clear (GTK_IMAGE(p->image)); gtk_widget_set_visible (p->image, FALSE); } else { GtkIconInfo *info; const gchar *filename; - GdkPixbuf *pixbuf; p->icon = g_object_ref (icon); info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); filename = gtk_icon_info_get_filename (info); - pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); - gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf); - gtk_widget_set_visible (p->image, TRUE); + if (filename) + { + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf); + + g_object_unref (pixbuf); + } + + gtk_widget_set_visible (p->image, filename != NULL); g_object_unref (info); - g_object_unref (pixbuf); } } } -- cgit v1.2.3