Merge lp:~larsu/ido/basic-menu-item into lp:ido/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: 180
Merged at revision: 177
Proposed branch: lp:~larsu/ido/basic-menu-item
Merge into: lp:ido/14.04
Diff against target: 393 lines (+210/-86)
7 files modified
debian/libido3-0.1-0.symbols (+1/-0)
src/Makefile.am (+2/-0)
src/idobasicmenuitem.c (+72/-79)
src/idobasicmenuitem.h (+2/-7)
src/idomenuitemfactory.c (+4/-0)
src/idoprogressmenuitem.c (+101/-0)
src/idoprogressmenuitem.h (+28/-0)
To merge this branch: bzr merge lp:~larsu/ido/basic-menu-item
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Sebastien Bacher Needs Fixing
Review via email: mp+213037@code.launchpad.net

Commit message

expose idobasicmenuitem, a normal menu item that supports non-square icons

Description of the change

expose idobasicmenuitem, a normal menu item that supports non-square icons

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

thanks, as the CI pointed you need to update debian/libido3-0.1-0.symbols, add it this line
"ido_basic_menu_item_new_from_model@Base 0replaceme"

review: Needs Fixing
lp:~larsu/ido/basic-menu-item updated
179. By Lars Karlitski

idobasicmenuitem: add symbol for _new_from_model()

Revision history for this message
Lars Karlitski (larsu) wrote :

Of course, thanks.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

This works for the current use cases, but I'm not comfortable with the new assumption that every GIcon has a filename. Could you handle the case where _get_filename() returns NULL?

review: Needs Fixing
lp:~larsu/ido/basic-menu-item updated
180. By Lars Karlitski

idobasicmenuitem: check return value of gtk_icon_info_get_filename() for NULL

Revision history for this message
Lars Karlitski (larsu) wrote :

According to the docs, that function seems to only return NULL when GTK_ICON_LOOKUP_USE_BUILTIN was passed to gtk_icon_theme_lookup_by_gicon(). However, I couldn't bother to find out what it does in the icon-not-found case and having the check doesn't hurt, so I've added it in r180.

Thanks for the catch!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks Lars!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libido3-0.1-0.symbols'
2--- debian/libido3-0.1-0.symbols 2013-11-05 11:01:43 +0000
3+++ debian/libido3-0.1-0.symbols 2014-03-28 10:27:56 +0000
4@@ -16,6 +16,7 @@
5 ido_basic_menu_item_set_icon_from_file@Base 13.10.0+13.10.20130731
6 ido_basic_menu_item_set_secondary_text@Base 13.10.0+13.10.20130731
7 ido_basic_menu_item_set_text@Base 13.10.0+13.10.20130731
8+ ido_basic_menu_item_new_from_model@Base 0replaceme
9 ido_calendar_menu_item_clear_marks@Base 0.2.1
10 ido_calendar_menu_item_get_calendar@Base 0.1.10
11 ido_calendar_menu_item_get_date@Base 0.2.1
12
13=== modified file 'src/Makefile.am'
14--- src/Makefile.am 2014-01-07 18:57:50 +0000
15+++ src/Makefile.am 2014-03-28 10:27:56 +0000
16@@ -21,6 +21,7 @@
17 idousermenuitem.h \
18 idoappointmentmenuitem.h \
19 idobasicmenuitem.h \
20+ idoprogressmenuitem.h \
21 idotimestampmenuitem.h \
22 idolocationmenuitem.h \
23 idotimeline.h \
24@@ -88,6 +89,7 @@
25 idoplaybackmenuitem.c \
26 idoappointmentmenuitem.c \
27 idobasicmenuitem.c \
28+ idoprogressmenuitem.c \
29 idotimestampmenuitem.c \
30 idolocationmenuitem.c \
31 idoapplicationmenuitem.c \
32
33=== modified file 'src/idobasicmenuitem.c'
34--- src/idobasicmenuitem.c 2013-07-25 21:22:45 +0000
35+++ src/idobasicmenuitem.c 2014-03-28 10:27:56 +0000
36@@ -245,17 +245,35 @@
37 if (p->icon != icon)
38 {
39 g_clear_object (&p->icon);
40+ gtk_image_clear (GTK_IMAGE(p->image));
41
42 if (icon == NULL)
43 {
44- gtk_image_clear (GTK_IMAGE(p->image));
45 gtk_widget_set_visible (p->image, FALSE);
46 }
47 else
48 {
49+ GtkIconInfo *info;
50+ const gchar *filename;
51+
52 p->icon = g_object_ref (icon);
53- gtk_image_set_from_gicon (GTK_IMAGE(p->image), p->icon, GTK_ICON_SIZE_MENU);
54- gtk_widget_set_visible (p->image, TRUE);
55+
56+ info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0);
57+ filename = gtk_icon_info_get_filename (info);
58+
59+ if (filename)
60+ {
61+ GdkPixbuf *pixbuf;
62+
63+ pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL);
64+ gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf);
65+
66+ g_object_unref (pixbuf);
67+ }
68+
69+ gtk_widget_set_visible (p->image, filename != NULL);
70+
71+ g_object_unref (info);
72 }
73 }
74 }
75@@ -306,86 +324,61 @@
76 }
77 }
78
79-/***
80-****
81-**** Progress Menu Item
82-****
83-***/
84-
85 static void
86-on_progress_action_state_changed (IdoActionHelper * helper,
87- GVariant * state,
88- gpointer unused G_GNUC_UNUSED)
89+ido_basic_menu_item_activate (GtkMenuItem *item,
90+ gpointer user_data)
91 {
92- IdoBasicMenuItem * ido_menu_item;
93- char * str;
94-
95- ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper));
96-
97- g_return_if_fail (ido_menu_item != NULL);
98- g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32));
99-
100- str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state));
101- ido_basic_menu_item_set_secondary_text (ido_menu_item, str);
102- g_free (str);
103+ IdoActionHelper *helper = user_data;
104+
105+ ido_action_helper_activate (helper);
106 }
107
108-/**
109- * ido_progress_menu_item_new_from_model:
110- * @menu_item: the corresponding menuitem
111- * @actions: action group to tell when this GtkMenuItem is activated
112- *
113- * Creates a new progress menuitem with properties initialized from
114- * the menuitem's attributes.
115- *
116- * If the menuitem's 'action' attribute is set, trigger that action
117- * in @actions when this IdoBasicMenuItem is activated.
118- */
119 GtkMenuItem *
120-ido_progress_menu_item_new_from_model (GMenuItem * menu_item,
121- GActionGroup * actions)
122+ido_basic_menu_item_new_from_model (GMenuItem * menu_item,
123+ GActionGroup * actions)
124 {
125- guint i;
126- guint n;
127- gchar * str;
128- IdoBasicMenuItem * ido_menu_item;
129- GParameter parameters[4];
130-
131- /* create the ido menuitem */;
132-
133- n = 0;
134-
135- if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
136- {
137- GParameter p = { "text", G_VALUE_INIT };
138- g_value_init (&p.value, G_TYPE_STRING);
139- g_value_take_string (&p.value, str);
140- parameters[n++] = p;
141- }
142-
143- g_assert (n <= G_N_ELEMENTS (parameters));
144- ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters);
145-
146- for (i=0; i<n; i++)
147- g_value_unset (&parameters[i].value);
148-
149- /* give it an ActionHelper */
150-
151- if (g_menu_item_get_attribute (menu_item, "action", "s", &str))
152- {
153- IdoActionHelper * helper;
154-
155- helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item),
156- actions,
157- str,
158- NULL);
159- g_signal_connect (helper, "action-state-changed",
160- G_CALLBACK (on_progress_action_state_changed), NULL);
161- g_signal_connect_swapped (ido_menu_item, "destroy",
162- G_CALLBACK (g_object_unref), helper);
163-
164- g_free (str);
165- }
166-
167- return GTK_MENU_ITEM (ido_menu_item);
168+ GtkWidget *item;
169+ gchar *label;
170+ gchar *action;
171+ GVariant *serialized_icon;
172+
173+ item = ido_basic_menu_item_new ();
174+
175+ if (g_menu_item_get_attribute (menu_item, "label", "s", &label))
176+ {
177+ ido_basic_menu_item_set_text (IDO_BASIC_MENU_ITEM (item), label);
178+ g_free (label);
179+ }
180+
181+ serialized_icon = g_menu_item_get_attribute_value (menu_item, "icon", NULL);
182+ if (serialized_icon)
183+ {
184+ GIcon *icon;
185+
186+ icon = g_icon_deserialize (serialized_icon);
187+ ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM (item), icon);
188+
189+ g_object_unref (icon);
190+ g_variant_unref (serialized_icon);
191+ }
192+
193+ if (g_menu_item_get_attribute (menu_item, "action", "s", &action))
194+ {
195+ IdoActionHelper *helper;
196+ GVariant *target;
197+
198+ target = g_menu_item_get_attribute_value (menu_item, "target", NULL);
199+
200+ helper = ido_action_helper_new (item, actions, action, target);
201+ g_signal_connect_object (item, "activate",
202+ G_CALLBACK (ido_basic_menu_item_activate), helper,
203+ 0);
204+ g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper);
205+
206+ if (target)
207+ g_variant_unref (target);
208+ g_free (action);
209+ }
210+
211+ return GTK_MENU_ITEM (item);
212 }
213
214=== modified file 'src/idobasicmenuitem.h'
215--- src/idobasicmenuitem.h 2013-07-25 20:51:57 +0000
216+++ src/idobasicmenuitem.h 2014-03-28 10:27:56 +0000
217@@ -64,13 +64,8 @@
218 void ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self,
219 const char * text);
220
221-/**
222-***
223-**/
224-
225-GtkMenuItem * ido_progress_menu_item_new_from_model (GMenuItem * menuitem,
226- GActionGroup * actions);
227-
228+GtkMenuItem * ido_basic_menu_item_new_from_model (GMenuItem * menuitem,
229+ GActionGroup * actions);
230
231 G_END_DECLS
232
233
234=== modified file 'src/idomenuitemfactory.c'
235--- src/idomenuitemfactory.c 2013-10-22 15:38:57 +0000
236+++ src/idomenuitemfactory.c 2014-03-28 10:27:56 +0000
237@@ -32,6 +32,7 @@
238 #include "idoapplicationmenuitem.h"
239 #include "idosourcemenuitem.h"
240 #include "idoswitchmenuitem.h"
241+#include "idoprogressmenuitem.h"
242
243 #define IDO_TYPE_MENU_ITEM_FACTORY (ido_menu_item_factory_get_type ())
244 #define IDO_MENU_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory))
245@@ -74,6 +75,9 @@
246 else if (g_str_equal (type, "com.canonical.indicator.alarm"))
247 item = ido_alarm_menu_item_new_from_model (menuitem, actions);
248
249+ else if (g_str_equal (type, "com.canonical.indicator.basic"))
250+ item = ido_basic_menu_item_new_from_model (menuitem, actions);
251+
252 else if (g_str_equal (type, "com.canonical.indicator.progress"))
253 item = ido_progress_menu_item_new_from_model (menuitem, actions);
254
255
256=== added file 'src/idoprogressmenuitem.c'
257--- src/idoprogressmenuitem.c 1970-01-01 00:00:00 +0000
258+++ src/idoprogressmenuitem.c 2014-03-28 10:27:56 +0000
259@@ -0,0 +1,101 @@
260+/**
261+ * Copyright 2013 Canonical Ltd.
262+ *
263+ * Authors:
264+ * Charles Kerr <charles.kerr@canonical.com>
265+ *
266+ * This program is free software: you can redistribute it and/or modify it
267+ * under the terms of the GNU General Public License version 3, as published
268+ * by the Free Software Foundation.
269+ *
270+ * This program is distributed in the hope that it will be useful, but
271+ * WITHOUT ANY WARRANTY; without even the implied warranties of
272+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
273+ * PURPOSE. See the GNU General Public License for more details.
274+ *
275+ * You should have received a copy of the GNU General Public License along
276+ * with this program. If not, see <http://www.gnu.org/licenses/>.
277+ */
278+
279+#include "idoprogressmenuitem.h"
280+#include "idobasicmenuitem.h"
281+#include "idoactionhelper.h"
282+
283+static void
284+on_progress_action_state_changed (IdoActionHelper * helper,
285+ GVariant * state,
286+ gpointer unused G_GNUC_UNUSED)
287+{
288+ IdoBasicMenuItem * ido_menu_item;
289+ char * str;
290+
291+ ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper));
292+
293+ g_return_if_fail (ido_menu_item != NULL);
294+ g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32));
295+
296+ str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state));
297+ ido_basic_menu_item_set_secondary_text (ido_menu_item, str);
298+ g_free (str);
299+}
300+
301+/**
302+ * ido_progress_menu_item_new_from_model:
303+ * @menu_item: the corresponding menuitem
304+ * @actions: action group to tell when this GtkMenuItem is activated
305+ *
306+ * Creates a new progress menuitem with properties initialized from
307+ * the menuitem's attributes.
308+ *
309+ * If the menuitem's 'action' attribute is set, trigger that action
310+ * in @actions when this IdoBasicMenuItem is activated.
311+ */
312+GtkMenuItem *
313+ido_progress_menu_item_new_from_model (GMenuItem * menu_item,
314+ GActionGroup * actions)
315+{
316+ guint i;
317+ guint n;
318+ gchar * str;
319+ IdoBasicMenuItem * ido_menu_item;
320+ GParameter parameters[4];
321+
322+ /* create the ido menuitem */;
323+
324+ n = 0;
325+
326+ if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
327+ {
328+ GParameter p = { "text", G_VALUE_INIT };
329+ g_value_init (&p.value, G_TYPE_STRING);
330+ g_value_take_string (&p.value, str);
331+ parameters[n++] = p;
332+ }
333+
334+ g_assert (n <= G_N_ELEMENTS (parameters));
335+ ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters);
336+
337+ for (i=0; i<n; i++)
338+ g_value_unset (&parameters[i].value);
339+
340+ /* give it an ActionHelper */
341+
342+ if (g_menu_item_get_attribute (menu_item, "action", "s", &str))
343+ {
344+ IdoActionHelper * helper;
345+
346+ helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item),
347+ actions,
348+ str,
349+ NULL);
350+ g_signal_connect (helper, "action-state-changed",
351+ G_CALLBACK (on_progress_action_state_changed), NULL);
352+ g_signal_connect_swapped (ido_menu_item, "destroy",
353+ G_CALLBACK (g_object_unref), helper);
354+
355+ g_free (str);
356+ }
357+
358+ return GTK_MENU_ITEM (ido_menu_item);
359+}
360+
361
362=== added file 'src/idoprogressmenuitem.h'
363--- src/idoprogressmenuitem.h 1970-01-01 00:00:00 +0000
364+++ src/idoprogressmenuitem.h 2014-03-28 10:27:56 +0000
365@@ -0,0 +1,28 @@
366+/**
367+ * Copyright 2013 Canonical Ltd.
368+ *
369+ * Authors:
370+ * Charles Kerr <charles.kerr@canonical.com>
371+ *
372+ * This program is free software: you can redistribute it and/or modify it
373+ * under the terms of the GNU General Public License version 3, as published
374+ * by the Free Software Foundation.
375+ *
376+ * This program is distributed in the hope that it will be useful, but
377+ * WITHOUT ANY WARRANTY; without even the implied warranties of
378+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
379+ * PURPOSE. See the GNU General Public License for more details.
380+ *
381+ * You should have received a copy of the GNU General Public License along
382+ * with this program. If not, see <http://www.gnu.org/licenses/>.
383+ */
384+
385+#ifndef __IDO_PROGRESS_MENU_ITEM_H__
386+#define __IDO_PROGRESS_MENU_ITEM_H__
387+
388+#include <gtk/gtk.h>
389+
390+GtkMenuItem * ido_progress_menu_item_new_from_model (GMenuItem * menuitem,
391+ GActionGroup * actions);
392+
393+#endif

Subscribers

People subscribed via source and target branches