Merge lp:~indicator-applet-developers/ido/add-messaging-menu into lp:ido/13.10
- add-messaging-menu
- Merge into trunk.13.10
Status: | Merged |
---|---|
Approved by: | Ted Gould |
Approved revision: | 148 |
Merged at revision: | 145 |
Proposed branch: | lp:~indicator-applet-developers/ido/add-messaging-menu |
Merge into: | lp:ido/13.10 |
Diff against target: |
1163 lines (+1044/-2) 11 files modified
debian/libido3-0.1-0.symbols (+10/-0) src/Makefile.am (+8/-2) src/idoactionhelper.c (+24/-0) src/idoactionhelper.h (+3/-0) src/idoapplicationmenuitem.c (+195/-0) src/idoapplicationmenuitem.h (+36/-0) src/idodetaillabel.c (+401/-0) src/idodetaillabel.h (+59/-0) src/idomenuitemfactory.c (+8/-0) src/idosourcemenuitem.c (+264/-0) src/idosourcemenuitem.h (+36/-0) |
To merge this branch: | bzr merge lp:~indicator-applet-developers/ido/add-messaging-menu |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Ted Gould (community) | Approve | ||
Review via email: mp+179962@code.launchpad.net |
Commit message
Add widgets for messaging menu
Description of the change
Adds the widgets needed for messaging menu integration. Might be broken, getting a diff and Jenkins comment right now while doing further testing.
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:147
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ted Gould (ted) wrote : | # |
Fixed a couple of little things. But this seems sane.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:148
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'debian/libido3-0.1-0.symbols' | |||
2 | --- debian/libido3-0.1-0.symbols 2013-07-31 02:02:53 +0000 | |||
3 | +++ debian/libido3-0.1-0.symbols 2013-08-13 20:56:02 +0000 | |||
4 | @@ -1,11 +1,14 @@ | |||
5 | 1 | libido3-0.1.so.0 libido3-0.1-0 #MINVER# | 1 | libido3-0.1.so.0 libido3-0.1-0 #MINVER# |
6 | 2 | ido_action_helper_activate@Base 13.10.0daily13.06.19 | 2 | ido_action_helper_activate@Base 13.10.0daily13.06.19 |
7 | 3 | ido_action_helper_activate_with_parameter@Base 0replaceme | ||
8 | 3 | ido_action_helper_change_action_state@Base 13.10.0daily13.06.19 | 4 | ido_action_helper_change_action_state@Base 13.10.0daily13.06.19 |
9 | 4 | ido_action_helper_get_action_target@Base 13.10.0daily13.06.19 | 5 | ido_action_helper_get_action_target@Base 13.10.0daily13.06.19 |
10 | 5 | ido_action_helper_get_type@Base 13.10.0daily13.06.19 | 6 | ido_action_helper_get_type@Base 13.10.0daily13.06.19 |
11 | 6 | ido_action_helper_get_widget@Base 13.10.0daily13.06.19 | 7 | ido_action_helper_get_widget@Base 13.10.0daily13.06.19 |
12 | 7 | ido_action_helper_new@Base 13.10.0daily13.06.19 | 8 | ido_action_helper_new@Base 13.10.0daily13.06.19 |
13 | 8 | ido_alarm_menu_item_new_from_model@Base 13.10.0+13.10.20130731 | 9 | ido_alarm_menu_item_new_from_model@Base 13.10.0+13.10.20130731 |
14 | 10 | ido_application_menu_item_get_type@Base 0replaceme | ||
15 | 11 | ido_application_menu_item_new_from_model@Base 0replaceme | ||
16 | 9 | ido_appointment_menu_item_new_from_model@Base 13.10.0daily13.06.19 | 12 | ido_appointment_menu_item_new_from_model@Base 13.10.0daily13.06.19 |
17 | 10 | ido_basic_menu_item_get_type@Base 13.10.0+13.10.20130731 | 13 | ido_basic_menu_item_get_type@Base 13.10.0+13.10.20130731 |
18 | 11 | ido_basic_menu_item_new@Base 13.10.0+13.10.20130731 | 14 | ido_basic_menu_item_new@Base 13.10.0+13.10.20130731 |
19 | @@ -24,6 +27,11 @@ | |||
20 | 24 | ido_calendar_menu_item_set_date@Base 0.2.2 | 27 | ido_calendar_menu_item_set_date@Base 0.2.2 |
21 | 25 | ido_calendar_menu_item_set_display_options@Base 0.2.1 | 28 | ido_calendar_menu_item_set_display_options@Base 0.2.1 |
22 | 26 | ido_calendar_menu_item_unmark_day@Base 0.2.1 | 29 | ido_calendar_menu_item_unmark_day@Base 0.2.1 |
23 | 30 | ido_detail_label_get_text@Base 0replaceme | ||
24 | 31 | ido_detail_label_get_type@Base 0replaceme | ||
25 | 32 | ido_detail_label_new@Base 0replaceme | ||
26 | 33 | ido_detail_label_set_count@Base 0replaceme | ||
27 | 34 | ido_detail_label_set_text@Base 0replaceme | ||
28 | 27 | ido_entry_menu_item_get_entry@Base 0.1.0 | 35 | ido_entry_menu_item_get_entry@Base 0.1.0 |
29 | 28 | ido_entry_menu_item_get_type@Base 0.1.0 | 36 | ido_entry_menu_item_get_type@Base 0.1.0 |
30 | 29 | ido_entry_menu_item_new@Base 0.1.0 | 37 | ido_entry_menu_item_new@Base 0.1.0 |
31 | @@ -57,6 +65,8 @@ | |||
32 | 57 | ido_scale_menu_item_set_secondary_label@Base 0.1.9 | 65 | ido_scale_menu_item_set_secondary_label@Base 0.1.9 |
33 | 58 | ido_scale_menu_item_set_style@Base 0.1.9 | 66 | ido_scale_menu_item_set_style@Base 0.1.9 |
34 | 59 | ido_scale_menu_item_style_get_type@Base 0.1.9 | 67 | ido_scale_menu_item_style_get_type@Base 0.1.9 |
35 | 68 | ido_source_menu_item_get_type@Base 0replaceme | ||
36 | 69 | ido_source_menu_item_new_from_menu_model@Base 0replaceme | ||
37 | 60 | ido_switch_menu_item_get_content_area@Base 12.10.0 | 70 | ido_switch_menu_item_get_content_area@Base 12.10.0 |
38 | 61 | ido_switch_menu_item_get_type@Base 12.10.0 | 71 | ido_switch_menu_item_get_type@Base 12.10.0 |
39 | 62 | ido_switch_menu_item_new@Base 12.10.0 | 72 | ido_switch_menu_item_new@Base 12.10.0 |
40 | 63 | 73 | ||
41 | === modified file 'src/Makefile.am' | |||
42 | --- src/Makefile.am 2013-07-25 23:53:48 +0000 | |||
43 | +++ src/Makefile.am 2013-08-13 20:56:02 +0000 | |||
44 | @@ -27,7 +27,10 @@ | |||
45 | 27 | libido.h \ | 27 | libido.h \ |
46 | 28 | idoactionhelper.h \ | 28 | idoactionhelper.h \ |
47 | 29 | idomediaplayermenuitem.h \ | 29 | idomediaplayermenuitem.h \ |
49 | 30 | idoplaybackmenuitem.h | 30 | idoplaybackmenuitem.h \ |
50 | 31 | idoapplicationmenuitem.h \ | ||
51 | 32 | idodetaillabel.h \ | ||
52 | 33 | idosourcemenuitem.h | ||
53 | 31 | 34 | ||
54 | 32 | EXTRA_DIST = \ | 35 | EXTRA_DIST = \ |
55 | 33 | ido.list \ | 36 | ido.list \ |
56 | @@ -86,7 +89,10 @@ | |||
57 | 86 | idoappointmentmenuitem.c \ | 89 | idoappointmentmenuitem.c \ |
58 | 87 | idobasicmenuitem.c \ | 90 | idobasicmenuitem.c \ |
59 | 88 | idotimestampmenuitem.c \ | 91 | idotimestampmenuitem.c \ |
61 | 89 | idolocationmenuitem.c | 92 | idolocationmenuitem.c \ |
62 | 93 | idoapplicationmenuitem.c \ | ||
63 | 94 | idodetaillabel.c \ | ||
64 | 95 | idosourcemenuitem.c | ||
65 | 90 | 96 | ||
66 | 91 | libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES) | 97 | libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES) |
67 | 92 | 98 | ||
68 | 93 | 99 | ||
69 | === modified file 'src/idoactionhelper.c' | |||
70 | --- src/idoactionhelper.c 2013-05-31 22:50:09 +0000 | |||
71 | +++ src/idoactionhelper.c 2013-08-13 20:56:02 +0000 | |||
72 | @@ -403,6 +403,30 @@ | |||
73 | 403 | } | 403 | } |
74 | 404 | 404 | ||
75 | 405 | /** | 405 | /** |
76 | 406 | * ido_action_helper_activate_with_parameter: | ||
77 | 407 | * @helper: an #IdoActionHelper | ||
78 | 408 | * @parameter: a #GVariant containing the parameter | ||
79 | 409 | * | ||
80 | 410 | * Activates the action that is associated with this helper passing | ||
81 | 411 | * @parameter instead the "target" associated with the menu item this | ||
82 | 412 | * helper is bound to. | ||
83 | 413 | */ | ||
84 | 414 | void | ||
85 | 415 | ido_action_helper_activate_with_parameter (IdoActionHelper *helper, | ||
86 | 416 | GVariant *parameter) | ||
87 | 417 | { | ||
88 | 418 | g_return_if_fail (IDO_IS_ACTION_HELPER (helper)); | ||
89 | 419 | g_return_if_fail (parameter != NULL); | ||
90 | 420 | |||
91 | 421 | g_variant_ref_sink (parameter); | ||
92 | 422 | |||
93 | 423 | if (helper->actions && helper->action_name) | ||
94 | 424 | g_action_group_activate_action (helper->actions, helper->action_name, parameter); | ||
95 | 425 | |||
96 | 426 | g_variant_unref (parameter); | ||
97 | 427 | } | ||
98 | 428 | |||
99 | 429 | /** | ||
100 | 406 | * ido_action_helper_change_action_state: | 430 | * ido_action_helper_change_action_state: |
101 | 407 | * @helper: an #IdoActionHelper | 431 | * @helper: an #IdoActionHelper |
102 | 408 | * @state: the proposed new state of the action | 432 | * @state: the proposed new state of the action |
103 | 409 | 433 | ||
104 | === modified file 'src/idoactionhelper.h' | |||
105 | --- src/idoactionhelper.h 2013-05-31 22:50:09 +0000 | |||
106 | +++ src/idoactionhelper.h 2013-08-13 20:56:02 +0000 | |||
107 | @@ -41,6 +41,9 @@ | |||
108 | 41 | 41 | ||
109 | 42 | void ido_action_helper_activate (IdoActionHelper *helper); | 42 | void ido_action_helper_activate (IdoActionHelper *helper); |
110 | 43 | 43 | ||
111 | 44 | void ido_action_helper_activate_with_parameter (IdoActionHelper *helper, | ||
112 | 45 | GVariant *parameter); | ||
113 | 46 | |||
114 | 44 | void ido_action_helper_change_action_state (IdoActionHelper *helper, | 47 | void ido_action_helper_change_action_state (IdoActionHelper *helper, |
115 | 45 | GVariant *state); | 48 | GVariant *state); |
116 | 46 | 49 | ||
117 | 47 | 50 | ||
118 | === added file 'src/idoapplicationmenuitem.c' | |||
119 | --- src/idoapplicationmenuitem.c 1970-01-01 00:00:00 +0000 | |||
120 | +++ src/idoapplicationmenuitem.c 2013-08-13 20:56:02 +0000 | |||
121 | @@ -0,0 +1,195 @@ | |||
122 | 1 | /* | ||
123 | 2 | * Copyright 2013 Canonical Ltd. | ||
124 | 3 | * | ||
125 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
126 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
127 | 6 | * by the Free Software Foundation. | ||
128 | 7 | * | ||
129 | 8 | * This program is distributed in the hope that it will be useful, but | ||
130 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
131 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
132 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
133 | 12 | * | ||
134 | 13 | * You should have received a copy of the GNU General Public License along | ||
135 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
136 | 15 | * | ||
137 | 16 | * Authors: | ||
138 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
139 | 18 | */ | ||
140 | 19 | |||
141 | 20 | #include "idoapplicationmenuitem.h" | ||
142 | 21 | #include "idoactionhelper.h" | ||
143 | 22 | |||
144 | 23 | typedef GtkMenuItemClass IdoApplicationMenuItemClass; | ||
145 | 24 | |||
146 | 25 | struct _IdoApplicationMenuItem | ||
147 | 26 | { | ||
148 | 27 | GtkMenuItem parent; | ||
149 | 28 | |||
150 | 29 | gboolean is_running; | ||
151 | 30 | |||
152 | 31 | GtkWidget *icon; | ||
153 | 32 | GtkWidget *label; | ||
154 | 33 | }; | ||
155 | 34 | |||
156 | 35 | G_DEFINE_TYPE (IdoApplicationMenuItem, ido_application_menu_item, GTK_TYPE_MENU_ITEM); | ||
157 | 36 | |||
158 | 37 | static void | ||
159 | 38 | ido_application_menu_item_constructed (GObject *object) | ||
160 | 39 | { | ||
161 | 40 | IdoApplicationMenuItem *item = IDO_APPLICATION_MENU_ITEM (object); | ||
162 | 41 | GtkWidget *grid; | ||
163 | 42 | |||
164 | 43 | item->icon = g_object_ref (gtk_image_new ()); | ||
165 | 44 | gtk_widget_set_margin_right (item->icon, 6); | ||
166 | 45 | |||
167 | 46 | item->label = g_object_ref (gtk_label_new ("")); | ||
168 | 47 | |||
169 | 48 | grid = gtk_grid_new (); | ||
170 | 49 | gtk_grid_attach (GTK_GRID (grid), item->icon, 0, 0, 1, 1); | ||
171 | 50 | gtk_grid_attach (GTK_GRID (grid), item->label, 1, 0, 1, 1); | ||
172 | 51 | |||
173 | 52 | gtk_container_add (GTK_CONTAINER (object), grid); | ||
174 | 53 | gtk_widget_show_all (grid); | ||
175 | 54 | |||
176 | 55 | G_OBJECT_CLASS (ido_application_menu_item_parent_class)->constructed (object); | ||
177 | 56 | } | ||
178 | 57 | |||
179 | 58 | static void | ||
180 | 59 | ido_application_menu_item_dispose (GObject *object) | ||
181 | 60 | { | ||
182 | 61 | IdoApplicationMenuItem *self = IDO_APPLICATION_MENU_ITEM (object); | ||
183 | 62 | |||
184 | 63 | g_clear_object (&self->icon); | ||
185 | 64 | g_clear_object (&self->label); | ||
186 | 65 | |||
187 | 66 | G_OBJECT_CLASS (ido_application_menu_item_parent_class)->dispose (object); | ||
188 | 67 | } | ||
189 | 68 | |||
190 | 69 | static gboolean | ||
191 | 70 | ido_application_menu_item_draw (GtkWidget *widget, | ||
192 | 71 | cairo_t *cr) | ||
193 | 72 | { | ||
194 | 73 | IdoApplicationMenuItem *item = IDO_APPLICATION_MENU_ITEM (widget); | ||
195 | 74 | |||
196 | 75 | GTK_WIDGET_CLASS (ido_application_menu_item_parent_class)->draw (widget, cr); | ||
197 | 76 | |||
198 | 77 | if (item->is_running) | ||
199 | 78 | { | ||
200 | 79 | const int arrow_width = 5; | ||
201 | 80 | const double half_arrow_height = 4.5; | ||
202 | 81 | GtkAllocation alloc; | ||
203 | 82 | GdkRGBA color; | ||
204 | 83 | double center; | ||
205 | 84 | |||
206 | 85 | gtk_widget_get_allocation (widget, &alloc); | ||
207 | 86 | |||
208 | 87 | gtk_style_context_get_color (gtk_widget_get_style_context (widget), | ||
209 | 88 | gtk_widget_get_state_flags (widget), | ||
210 | 89 | &color); | ||
211 | 90 | gdk_cairo_set_source_rgba (cr, &color); | ||
212 | 91 | |||
213 | 92 | center = alloc.height / 2 + 0.5; | ||
214 | 93 | |||
215 | 94 | cairo_move_to (cr, 0, center - half_arrow_height); | ||
216 | 95 | cairo_line_to (cr, 0, center + half_arrow_height); | ||
217 | 96 | cairo_line_to (cr, arrow_width, center); | ||
218 | 97 | cairo_close_path (cr); | ||
219 | 98 | |||
220 | 99 | cairo_fill (cr); | ||
221 | 100 | } | ||
222 | 101 | |||
223 | 102 | return FALSE; | ||
224 | 103 | } | ||
225 | 104 | |||
226 | 105 | void | ||
227 | 106 | ido_application_menu_item_class_init (IdoApplicationMenuItemClass *klass) | ||
228 | 107 | { | ||
229 | 108 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
230 | 109 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); | ||
231 | 110 | |||
232 | 111 | object_class->constructed = ido_application_menu_item_constructed; | ||
233 | 112 | object_class->dispose = ido_application_menu_item_dispose; | ||
234 | 113 | |||
235 | 114 | widget_class->draw = ido_application_menu_item_draw; | ||
236 | 115 | } | ||
237 | 116 | |||
238 | 117 | static void | ||
239 | 118 | ido_application_menu_item_init (IdoApplicationMenuItem *self) | ||
240 | 119 | { | ||
241 | 120 | } | ||
242 | 121 | |||
243 | 122 | static void | ||
244 | 123 | ido_application_menu_item_set_label (IdoApplicationMenuItem *item, | ||
245 | 124 | const gchar *label) | ||
246 | 125 | { | ||
247 | 126 | gtk_label_set_label (GTK_LABEL (item->label), label); | ||
248 | 127 | } | ||
249 | 128 | |||
250 | 129 | static void | ||
251 | 130 | ido_application_menu_item_set_icon (IdoApplicationMenuItem *item, | ||
252 | 131 | GIcon *icon) | ||
253 | 132 | { | ||
254 | 133 | gtk_image_set_from_gicon (GTK_IMAGE (item->icon), icon, GTK_ICON_SIZE_MENU); | ||
255 | 134 | } | ||
256 | 135 | |||
257 | 136 | static void | ||
258 | 137 | ido_application_menu_item_state_changed (IdoActionHelper *helper, | ||
259 | 138 | GVariant *state, | ||
260 | 139 | gpointer user_data) | ||
261 | 140 | { | ||
262 | 141 | IdoApplicationMenuItem *item = user_data; | ||
263 | 142 | |||
264 | 143 | item->is_running = g_variant_get_boolean (state); | ||
265 | 144 | gtk_widget_queue_draw (GTK_WIDGET (item)); | ||
266 | 145 | } | ||
267 | 146 | |||
268 | 147 | GtkMenuItem * | ||
269 | 148 | ido_application_menu_item_new_from_model (GMenuItem *menuitem, | ||
270 | 149 | GActionGroup *actions) | ||
271 | 150 | { | ||
272 | 151 | GtkMenuItem *item; | ||
273 | 152 | gchar *label; | ||
274 | 153 | GVariant *serialized_icon; | ||
275 | 154 | gchar *action; | ||
276 | 155 | |||
277 | 156 | item = g_object_new (IDO_TYPE_APPLICATION_MENU_ITEM, NULL); | ||
278 | 157 | |||
279 | 158 | if (g_menu_item_get_attribute (menuitem, "label", "s", &label)) | ||
280 | 159 | { | ||
281 | 160 | ido_application_menu_item_set_label (IDO_APPLICATION_MENU_ITEM (item), label); | ||
282 | 161 | g_free (label); | ||
283 | 162 | } | ||
284 | 163 | |||
285 | 164 | serialized_icon = g_menu_item_get_attribute_value (menuitem, "icon", NULL); | ||
286 | 165 | if (serialized_icon) | ||
287 | 166 | { | ||
288 | 167 | GIcon *icon; | ||
289 | 168 | |||
290 | 169 | icon = g_icon_deserialize (serialized_icon); | ||
291 | 170 | if (icon) | ||
292 | 171 | { | ||
293 | 172 | ido_application_menu_item_set_icon (IDO_APPLICATION_MENU_ITEM (item), icon); | ||
294 | 173 | g_object_unref (icon); | ||
295 | 174 | } | ||
296 | 175 | |||
297 | 176 | g_variant_unref (serialized_icon); | ||
298 | 177 | } | ||
299 | 178 | |||
300 | 179 | if (g_menu_item_get_attribute (menuitem, "action", "s", &action)) | ||
301 | 180 | { | ||
302 | 181 | IdoActionHelper *helper; | ||
303 | 182 | |||
304 | 183 | helper = ido_action_helper_new (GTK_WIDGET (item), actions, action, NULL); | ||
305 | 184 | g_signal_connect (helper, "action-state-changed", | ||
306 | 185 | G_CALLBACK (ido_application_menu_item_state_changed), item); | ||
307 | 186 | g_signal_connect_object (item, "activate", | ||
308 | 187 | G_CALLBACK (ido_action_helper_activate), helper, | ||
309 | 188 | G_CONNECT_SWAPPED); | ||
310 | 189 | g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); | ||
311 | 190 | |||
312 | 191 | g_free (action); | ||
313 | 192 | } | ||
314 | 193 | |||
315 | 194 | return item; | ||
316 | 195 | } | ||
317 | 0 | 196 | ||
318 | === added file 'src/idoapplicationmenuitem.h' | |||
319 | --- src/idoapplicationmenuitem.h 1970-01-01 00:00:00 +0000 | |||
320 | +++ src/idoapplicationmenuitem.h 2013-08-13 20:56:02 +0000 | |||
321 | @@ -0,0 +1,36 @@ | |||
322 | 1 | /* | ||
323 | 2 | * Copyright 2013 Canonical Ltd. | ||
324 | 3 | * | ||
325 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
326 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
327 | 6 | * by the Free Software Foundation. | ||
328 | 7 | * | ||
329 | 8 | * This program is distributed in the hope that it will be useful, but | ||
330 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
331 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
332 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
333 | 12 | * | ||
334 | 13 | * You should have received a copy of the GNU General Public License along | ||
335 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
336 | 15 | * | ||
337 | 16 | * Authors: | ||
338 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
339 | 18 | */ | ||
340 | 19 | |||
341 | 20 | #ifndef __IDO_APPLICATION_MENU_ITEM_H__ | ||
342 | 21 | #define __IDO_APPLICATION_MENU_ITEM_H__ | ||
343 | 22 | |||
344 | 23 | #include <gtk/gtk.h> | ||
345 | 24 | |||
346 | 25 | #define IDO_TYPE_APPLICATION_MENU_ITEM (ido_application_menu_item_get_type ()) | ||
347 | 26 | #define IDO_APPLICATION_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_APPLICATION_MENU_ITEM, IdoApplicationMenuItem)) | ||
348 | 27 | #define IS_IDO_APPLICATION_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_APPLICATION_MENU_ITEM)) | ||
349 | 28 | |||
350 | 29 | typedef struct _IdoApplicationMenuItem IdoApplicationMenuItem; | ||
351 | 30 | |||
352 | 31 | GType ido_application_menu_item_get_type (void); | ||
353 | 32 | |||
354 | 33 | GtkMenuItem * ido_application_menu_item_new_from_model (GMenuItem *item, | ||
355 | 34 | GActionGroup *actions); | ||
356 | 35 | |||
357 | 36 | #endif | ||
358 | 0 | 37 | ||
359 | === added file 'src/idodetaillabel.c' | |||
360 | --- src/idodetaillabel.c 1970-01-01 00:00:00 +0000 | |||
361 | +++ src/idodetaillabel.c 2013-08-13 20:56:02 +0000 | |||
362 | @@ -0,0 +1,401 @@ | |||
363 | 1 | /* | ||
364 | 2 | * Copyright 2012 Canonical Ltd. | ||
365 | 3 | * | ||
366 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
367 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
368 | 6 | * by the Free Software Foundation. | ||
369 | 7 | * | ||
370 | 8 | * This program is distributed in the hope that it will be useful, but | ||
371 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
372 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
373 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
374 | 12 | * | ||
375 | 13 | * You should have received a copy of the GNU General Public License along | ||
376 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
377 | 15 | * | ||
378 | 16 | * Authors: | ||
379 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
380 | 18 | */ | ||
381 | 19 | |||
382 | 20 | #include "idodetaillabel.h" | ||
383 | 21 | |||
384 | 22 | #include <math.h> | ||
385 | 23 | |||
386 | 24 | G_DEFINE_TYPE (IdoDetailLabel, ido_detail_label, GTK_TYPE_WIDGET) | ||
387 | 25 | |||
388 | 26 | struct _IdoDetailLabelPrivate | ||
389 | 27 | { | ||
390 | 28 | gchar *text; | ||
391 | 29 | PangoLayout *layout; | ||
392 | 30 | gboolean draw_lozenge; | ||
393 | 31 | }; | ||
394 | 32 | |||
395 | 33 | enum | ||
396 | 34 | { | ||
397 | 35 | PROP_0, | ||
398 | 36 | PROP_TEXT, | ||
399 | 37 | NUM_PROPERTIES | ||
400 | 38 | }; | ||
401 | 39 | |||
402 | 40 | static GParamSpec *properties[NUM_PROPERTIES]; | ||
403 | 41 | |||
404 | 42 | static void | ||
405 | 43 | ido_detail_label_get_property (GObject *object, | ||
406 | 44 | guint property_id, | ||
407 | 45 | GValue *value, | ||
408 | 46 | GParamSpec *pspec) | ||
409 | 47 | { | ||
410 | 48 | IdoDetailLabel *self = IDO_DETAIL_LABEL (object); | ||
411 | 49 | |||
412 | 50 | switch (property_id) | ||
413 | 51 | { | ||
414 | 52 | case PROP_TEXT: | ||
415 | 53 | g_value_set_string (value, self->priv->text); | ||
416 | 54 | break; | ||
417 | 55 | |||
418 | 56 | default: | ||
419 | 57 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | ||
420 | 58 | } | ||
421 | 59 | } | ||
422 | 60 | |||
423 | 61 | static void | ||
424 | 62 | ido_detail_label_set_property (GObject *object, | ||
425 | 63 | guint property_id, | ||
426 | 64 | const GValue *value, | ||
427 | 65 | GParamSpec *pspec) | ||
428 | 66 | { | ||
429 | 67 | IdoDetailLabel *self = IDO_DETAIL_LABEL (object); | ||
430 | 68 | |||
431 | 69 | switch (property_id) | ||
432 | 70 | { | ||
433 | 71 | case PROP_TEXT: | ||
434 | 72 | ido_detail_label_set_text (self, g_value_get_string (value)); | ||
435 | 73 | break; | ||
436 | 74 | |||
437 | 75 | default: | ||
438 | 76 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | ||
439 | 77 | } | ||
440 | 78 | } | ||
441 | 79 | |||
442 | 80 | |||
443 | 81 | static void | ||
444 | 82 | ido_detail_label_finalize (GObject *object) | ||
445 | 83 | { | ||
446 | 84 | IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; | ||
447 | 85 | |||
448 | 86 | g_free (priv->text); | ||
449 | 87 | |||
450 | 88 | G_OBJECT_CLASS (ido_detail_label_parent_class)->finalize (object); | ||
451 | 89 | } | ||
452 | 90 | |||
453 | 91 | static void | ||
454 | 92 | ido_detail_label_dispose (GObject *object) | ||
455 | 93 | { | ||
456 | 94 | IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; | ||
457 | 95 | |||
458 | 96 | g_clear_object (&priv->layout); | ||
459 | 97 | |||
460 | 98 | G_OBJECT_CLASS (ido_detail_label_parent_class)->dispose (object); | ||
461 | 99 | } | ||
462 | 100 | |||
463 | 101 | static void | ||
464 | 102 | ido_detail_label_ensure_layout (IdoDetailLabel *label) | ||
465 | 103 | { | ||
466 | 104 | IdoDetailLabelPrivate *priv = label->priv; | ||
467 | 105 | |||
468 | 106 | if (priv->layout == NULL) | ||
469 | 107 | { | ||
470 | 108 | priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (label), priv->text); | ||
471 | 109 | pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER); | ||
472 | 110 | pango_layout_set_ellipsize (priv->layout, PANGO_ELLIPSIZE_END); | ||
473 | 111 | pango_layout_set_height (priv->layout, -1); | ||
474 | 112 | |||
475 | 113 | // TODO update layout on "style-updated" and "direction-changed" | ||
476 | 114 | } | ||
477 | 115 | } | ||
478 | 116 | |||
479 | 117 | static void | ||
480 | 118 | cairo_lozenge (cairo_t *cr, | ||
481 | 119 | double x, | ||
482 | 120 | double y, | ||
483 | 121 | double w, | ||
484 | 122 | double h, | ||
485 | 123 | double radius) | ||
486 | 124 | { | ||
487 | 125 | double x1 = x + w - radius; | ||
488 | 126 | double x2 = x + radius; | ||
489 | 127 | double y1 = y + radius; | ||
490 | 128 | double y2 = y + h - radius; | ||
491 | 129 | |||
492 | 130 | cairo_move_to (cr, x + radius, y); | ||
493 | 131 | cairo_arc (cr, x1, y1, radius, G_PI * 1.5, G_PI * 2); | ||
494 | 132 | cairo_arc (cr, x1, y2, radius, 0, G_PI * 0.5); | ||
495 | 133 | cairo_arc (cr, x2, y2, radius, G_PI * 0.5, G_PI); | ||
496 | 134 | cairo_arc (cr, x2, y1, radius, G_PI, G_PI * 1.5); | ||
497 | 135 | } | ||
498 | 136 | |||
499 | 137 | static PangoFontMetrics * | ||
500 | 138 | gtk_widget_get_font_metrics (GtkWidget *widget, | ||
501 | 139 | PangoContext *context) | ||
502 | 140 | { | ||
503 | 141 | PangoFontDescription *font; | ||
504 | 142 | PangoFontMetrics *metrics; | ||
505 | 143 | |||
506 | 144 | gtk_style_context_get (gtk_widget_get_style_context (widget), | ||
507 | 145 | gtk_widget_get_state_flags (widget), | ||
508 | 146 | "font", &font, NULL); | ||
509 | 147 | |||
510 | 148 | metrics = pango_context_get_metrics (context, | ||
511 | 149 | font, | ||
512 | 150 | pango_context_get_language (context)); | ||
513 | 151 | |||
514 | 152 | pango_font_description_free (font); | ||
515 | 153 | return metrics; | ||
516 | 154 | } | ||
517 | 155 | |||
518 | 156 | static gint | ||
519 | 157 | ido_detail_label_get_minimum_text_width (IdoDetailLabel *label) | ||
520 | 158 | { | ||
521 | 159 | IdoDetailLabelPrivate *priv = label->priv; | ||
522 | 160 | PangoContext *context; | ||
523 | 161 | PangoFontMetrics *metrics; | ||
524 | 162 | gint char_width; | ||
525 | 163 | gint w; | ||
526 | 164 | |||
527 | 165 | context = pango_layout_get_context (priv->layout); | ||
528 | 166 | metrics = gtk_widget_get_font_metrics (GTK_WIDGET (label), context); | ||
529 | 167 | char_width = pango_font_metrics_get_approximate_digit_width (metrics); | ||
530 | 168 | |||
531 | 169 | w = 2 * char_width / PANGO_SCALE; | ||
532 | 170 | pango_font_metrics_unref (metrics); | ||
533 | 171 | return w; | ||
534 | 172 | } | ||
535 | 173 | |||
536 | 174 | static gboolean | ||
537 | 175 | ido_detail_label_draw (GtkWidget *widget, | ||
538 | 176 | cairo_t *cr) | ||
539 | 177 | { | ||
540 | 178 | IdoDetailLabel *label = IDO_DETAIL_LABEL (widget); | ||
541 | 179 | IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; | ||
542 | 180 | PangoRectangle extents; | ||
543 | 181 | GtkAllocation allocation; | ||
544 | 182 | double x, w, h, radius; | ||
545 | 183 | GdkRGBA color; | ||
546 | 184 | |||
547 | 185 | if (!priv->text || !*priv->text) | ||
548 | 186 | return TRUE; | ||
549 | 187 | |||
550 | 188 | gtk_widget_get_allocation (widget, &allocation); | ||
551 | 189 | |||
552 | 190 | ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); | ||
553 | 191 | |||
554 | 192 | pango_layout_get_extents (priv->layout, NULL, &extents); | ||
555 | 193 | pango_extents_to_pixels (&extents, NULL); | ||
556 | 194 | |||
557 | 195 | h = MIN (allocation.height, extents.height); | ||
558 | 196 | radius = floor (h / 2.0); | ||
559 | 197 | w = MAX (ido_detail_label_get_minimum_text_width (label), extents.width) + 2.0 * radius; | ||
560 | 198 | x = allocation.width - w; | ||
561 | 199 | |||
562 | 200 | pango_layout_set_width (priv->layout, (allocation.width - 2 * radius) * PANGO_SCALE); | ||
563 | 201 | pango_layout_get_extents (priv->layout, NULL, &extents); | ||
564 | 202 | pango_extents_to_pixels (&extents, NULL); | ||
565 | 203 | |||
566 | 204 | gtk_style_context_get_color (gtk_widget_get_style_context (widget), | ||
567 | 205 | gtk_widget_get_state_flags (widget), | ||
568 | 206 | &color); | ||
569 | 207 | gdk_cairo_set_source_rgba (cr, &color); | ||
570 | 208 | |||
571 | 209 | cairo_set_line_width (cr, 1.0); | ||
572 | 210 | cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); | ||
573 | 211 | |||
574 | 212 | if (priv->draw_lozenge) | ||
575 | 213 | cairo_lozenge (cr, x, 0.0, w, h, radius); | ||
576 | 214 | |||
577 | 215 | cairo_move_to (cr, x + radius, (allocation.height - extents.height) / 2.0); | ||
578 | 216 | pango_cairo_layout_path (cr, priv->layout); | ||
579 | 217 | cairo_fill (cr); | ||
580 | 218 | |||
581 | 219 | return TRUE; | ||
582 | 220 | } | ||
583 | 221 | |||
584 | 222 | static void | ||
585 | 223 | ido_detail_label_get_preferred_width (GtkWidget *widget, | ||
586 | 224 | gint *minimum, | ||
587 | 225 | gint *natural) | ||
588 | 226 | { | ||
589 | 227 | IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; | ||
590 | 228 | PangoRectangle extents; | ||
591 | 229 | double radius; | ||
592 | 230 | |||
593 | 231 | ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); | ||
594 | 232 | |||
595 | 233 | pango_layout_get_extents (priv->layout, NULL, &extents); | ||
596 | 234 | pango_extents_to_pixels (&extents, NULL); | ||
597 | 235 | |||
598 | 236 | radius = floor (extents.height / 2.0); | ||
599 | 237 | |||
600 | 238 | *minimum = ido_detail_label_get_minimum_text_width (IDO_DETAIL_LABEL (widget)) + 2.0 * radius; | ||
601 | 239 | *natural = MAX (*minimum, extents.width + 2.0 * radius); | ||
602 | 240 | } | ||
603 | 241 | |||
604 | 242 | static void | ||
605 | 243 | ido_detail_label_get_preferred_height (GtkWidget *widget, | ||
606 | 244 | gint *minimum, | ||
607 | 245 | gint *natural) | ||
608 | 246 | { | ||
609 | 247 | IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; | ||
610 | 248 | PangoContext *context; | ||
611 | 249 | PangoFontMetrics *metrics; | ||
612 | 250 | PangoRectangle extents; | ||
613 | 251 | |||
614 | 252 | ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); | ||
615 | 253 | |||
616 | 254 | pango_layout_get_extents (priv->layout, NULL, &extents); | ||
617 | 255 | pango_extents_to_pixels (&extents, NULL); | ||
618 | 256 | context = pango_layout_get_context (priv->layout); | ||
619 | 257 | metrics = gtk_widget_get_font_metrics (widget, context); | ||
620 | 258 | |||
621 | 259 | *minimum = *natural = (pango_font_metrics_get_ascent (metrics) + | ||
622 | 260 | pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; | ||
623 | 261 | |||
624 | 262 | pango_font_metrics_unref (metrics); | ||
625 | 263 | } | ||
626 | 264 | |||
627 | 265 | static void | ||
628 | 266 | ido_detail_label_class_init (IdoDetailLabelClass *klass) | ||
629 | 267 | { | ||
630 | 268 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
631 | 269 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); | ||
632 | 270 | |||
633 | 271 | object_class->get_property = ido_detail_label_get_property; | ||
634 | 272 | object_class->set_property = ido_detail_label_set_property; | ||
635 | 273 | object_class->finalize = ido_detail_label_finalize; | ||
636 | 274 | object_class->dispose = ido_detail_label_dispose; | ||
637 | 275 | |||
638 | 276 | widget_class->draw = ido_detail_label_draw; | ||
639 | 277 | widget_class->get_preferred_width = ido_detail_label_get_preferred_width; | ||
640 | 278 | widget_class->get_preferred_height = ido_detail_label_get_preferred_height; | ||
641 | 279 | |||
642 | 280 | g_type_class_add_private (klass, sizeof (IdoDetailLabelPrivate)); | ||
643 | 281 | |||
644 | 282 | properties[PROP_TEXT] = g_param_spec_string ("text", | ||
645 | 283 | "Text", | ||
646 | 284 | "The text of the label", | ||
647 | 285 | NULL, | ||
648 | 286 | G_PARAM_READWRITE | | ||
649 | 287 | G_PARAM_STATIC_STRINGS); | ||
650 | 288 | |||
651 | 289 | g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); | ||
652 | 290 | } | ||
653 | 291 | |||
654 | 292 | static void | ||
655 | 293 | ido_detail_label_init (IdoDetailLabel *self) | ||
656 | 294 | { | ||
657 | 295 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, | ||
658 | 296 | IDO_TYPE_DETAIL_LABEL, | ||
659 | 297 | IdoDetailLabelPrivate); | ||
660 | 298 | |||
661 | 299 | gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); | ||
662 | 300 | } | ||
663 | 301 | |||
664 | 302 | GtkWidget * | ||
665 | 303 | ido_detail_label_new (const gchar *label) | ||
666 | 304 | { | ||
667 | 305 | return g_object_new (IDO_TYPE_DETAIL_LABEL, | ||
668 | 306 | "text", label, | ||
669 | 307 | NULL); | ||
670 | 308 | } | ||
671 | 309 | |||
672 | 310 | const gchar * | ||
673 | 311 | ido_detail_label_get_text (IdoDetailLabel *label) | ||
674 | 312 | { | ||
675 | 313 | g_return_val_if_fail (IDO_IS_DETAIL_LABEL (label), NULL); | ||
676 | 314 | return label->priv->text; | ||
677 | 315 | } | ||
678 | 316 | |||
679 | 317 | /* collapse_whitespace: | ||
680 | 318 | * @str: the source string | ||
681 | 319 | * | ||
682 | 320 | * Collapses all occurences of consecutive whitespace charactes in @str | ||
683 | 321 | * into a single space. | ||
684 | 322 | * | ||
685 | 323 | * Returns: (transfer full): a newly-allocated string | ||
686 | 324 | */ | ||
687 | 325 | static gchar * | ||
688 | 326 | collapse_whitespace (const gchar *str) | ||
689 | 327 | { | ||
690 | 328 | GString *result; | ||
691 | 329 | gboolean in_space = FALSE; | ||
692 | 330 | |||
693 | 331 | if (str == NULL) | ||
694 | 332 | return NULL; | ||
695 | 333 | |||
696 | 334 | result = g_string_new (""); | ||
697 | 335 | |||
698 | 336 | while (*str) | ||
699 | 337 | { | ||
700 | 338 | gunichar c = g_utf8_get_char_validated (str, -1); | ||
701 | 339 | |||
702 | 340 | if (c == (gunichar) -1) | ||
703 | 341 | break; | ||
704 | 342 | |||
705 | 343 | if (!g_unichar_isspace (c)) | ||
706 | 344 | { | ||
707 | 345 | g_string_append_unichar (result, c); | ||
708 | 346 | in_space = FALSE; | ||
709 | 347 | } | ||
710 | 348 | else if (!in_space) | ||
711 | 349 | { | ||
712 | 350 | g_string_append_c (result, ' '); | ||
713 | 351 | in_space = TRUE; | ||
714 | 352 | } | ||
715 | 353 | |||
716 | 354 | str = g_utf8_next_char (str); | ||
717 | 355 | } | ||
718 | 356 | |||
719 | 357 | return g_string_free (result, FALSE); | ||
720 | 358 | } | ||
721 | 359 | |||
722 | 360 | static void | ||
723 | 361 | ido_detail_label_set_text_impl (IdoDetailLabel *label, | ||
724 | 362 | const gchar *text, | ||
725 | 363 | gboolean draw_lozenge) | ||
726 | 364 | { | ||
727 | 365 | IdoDetailLabelPrivate * priv = label->priv; | ||
728 | 366 | |||
729 | 367 | g_clear_object (&priv->layout); | ||
730 | 368 | g_free (priv->text); | ||
731 | 369 | |||
732 | 370 | priv->text = g_strdup (text); | ||
733 | 371 | priv->draw_lozenge = draw_lozenge; | ||
734 | 372 | |||
735 | 373 | g_object_notify_by_pspec (G_OBJECT (label), properties[PROP_TEXT]); | ||
736 | 374 | gtk_widget_queue_resize (GTK_WIDGET (label)); | ||
737 | 375 | } | ||
738 | 376 | |||
739 | 377 | void | ||
740 | 378 | ido_detail_label_set_text (IdoDetailLabel *label, | ||
741 | 379 | const gchar *text) | ||
742 | 380 | { | ||
743 | 381 | gchar *str; | ||
744 | 382 | |||
745 | 383 | g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); | ||
746 | 384 | |||
747 | 385 | str = collapse_whitespace (text); | ||
748 | 386 | ido_detail_label_set_text_impl (label, str, FALSE); | ||
749 | 387 | g_free (str); | ||
750 | 388 | } | ||
751 | 389 | |||
752 | 390 | void | ||
753 | 391 | ido_detail_label_set_count (IdoDetailLabel *label, | ||
754 | 392 | gint count) | ||
755 | 393 | { | ||
756 | 394 | gchar *text; | ||
757 | 395 | |||
758 | 396 | g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); | ||
759 | 397 | |||
760 | 398 | text = g_strdup_printf ("%d", count); | ||
761 | 399 | ido_detail_label_set_text_impl (label, text, TRUE); | ||
762 | 400 | g_free (text); | ||
763 | 401 | } | ||
764 | 0 | 402 | ||
765 | === added file 'src/idodetaillabel.h' | |||
766 | --- src/idodetaillabel.h 1970-01-01 00:00:00 +0000 | |||
767 | +++ src/idodetaillabel.h 2013-08-13 20:56:02 +0000 | |||
768 | @@ -0,0 +1,59 @@ | |||
769 | 1 | /* | ||
770 | 2 | * Copyright 2012 Canonical Ltd. | ||
771 | 3 | * | ||
772 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
773 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
774 | 6 | * by the Free Software Foundation. | ||
775 | 7 | * | ||
776 | 8 | * This program is distributed in the hope that it will be useful, but | ||
777 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
778 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
779 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
780 | 12 | * | ||
781 | 13 | * You should have received a copy of the GNU General Public License along | ||
782 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
783 | 15 | * | ||
784 | 16 | * Authors: | ||
785 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
786 | 18 | */ | ||
787 | 19 | |||
788 | 20 | #ifndef __IDO_DETAIL_LABEL_H__ | ||
789 | 21 | #define __IDO_DETAIL_LABEL_H__ | ||
790 | 22 | |||
791 | 23 | #include <gtk/gtk.h> | ||
792 | 24 | |||
793 | 25 | #define IDO_TYPE_DETAIL_LABEL (ido_detail_label_get_type()) | ||
794 | 26 | #define IDO_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabel)) | ||
795 | 27 | #define IDO_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) | ||
796 | 28 | #define IDO_IS_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_DETAIL_LABEL)) | ||
797 | 29 | #define IDO_IS_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_DETAIL_LABEL)) | ||
798 | 30 | #define IDO_DETAIL_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) | ||
799 | 31 | |||
800 | 32 | typedef struct _IdoDetailLabel IdoDetailLabel; | ||
801 | 33 | typedef struct _IdoDetailLabelClass IdoDetailLabelClass; | ||
802 | 34 | typedef struct _IdoDetailLabelPrivate IdoDetailLabelPrivate; | ||
803 | 35 | |||
804 | 36 | struct _IdoDetailLabel | ||
805 | 37 | { | ||
806 | 38 | GtkWidget parent; | ||
807 | 39 | IdoDetailLabelPrivate *priv; | ||
808 | 40 | }; | ||
809 | 41 | |||
810 | 42 | struct _IdoDetailLabelClass | ||
811 | 43 | { | ||
812 | 44 | GtkWidgetClass parent_class; | ||
813 | 45 | }; | ||
814 | 46 | |||
815 | 47 | GType ido_detail_label_get_type (void) G_GNUC_CONST; | ||
816 | 48 | |||
817 | 49 | GtkWidget * ido_detail_label_new (const gchar *str); | ||
818 | 50 | |||
819 | 51 | const gchar * ido_detail_label_get_text (IdoDetailLabel *label); | ||
820 | 52 | |||
821 | 53 | void ido_detail_label_set_text (IdoDetailLabel *label, | ||
822 | 54 | const gchar *text); | ||
823 | 55 | |||
824 | 56 | void ido_detail_label_set_count (IdoDetailLabel *label, | ||
825 | 57 | gint count); | ||
826 | 58 | |||
827 | 59 | #endif | ||
828 | 0 | 60 | ||
829 | === modified file 'src/idomenuitemfactory.c' | |||
830 | --- src/idomenuitemfactory.c 2013-07-25 23:53:48 +0000 | |||
831 | +++ src/idomenuitemfactory.c 2013-08-13 20:56:02 +0000 | |||
832 | @@ -29,6 +29,8 @@ | |||
833 | 29 | #include "idousermenuitem.h" | 29 | #include "idousermenuitem.h" |
834 | 30 | #include "idomediaplayermenuitem.h" | 30 | #include "idomediaplayermenuitem.h" |
835 | 31 | #include "idoplaybackmenuitem.h" | 31 | #include "idoplaybackmenuitem.h" |
836 | 32 | #include "idoapplicationmenuitem.h" | ||
837 | 33 | #include "idosourcemenuitem.h" | ||
838 | 32 | 34 | ||
839 | 33 | #define IDO_TYPE_MENU_ITEM_FACTORY (ido_menu_item_factory_get_type ()) | 35 | #define IDO_TYPE_MENU_ITEM_FACTORY (ido_menu_item_factory_get_type ()) |
840 | 34 | #define IDO_MENU_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory)) | 36 | #define IDO_MENU_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory)) |
841 | @@ -83,6 +85,12 @@ | |||
842 | 83 | else if (g_str_equal (type, "com.canonical.unity.playback-item")) | 85 | else if (g_str_equal (type, "com.canonical.unity.playback-item")) |
843 | 84 | item = ido_playback_menu_item_new_from_model (menuitem, actions); | 86 | item = ido_playback_menu_item_new_from_model (menuitem, actions); |
844 | 85 | 87 | ||
845 | 88 | else if (g_str_equal (type, "com.canonical.application")) | ||
846 | 89 | item = ido_application_menu_item_new_from_model (menuitem, actions); | ||
847 | 90 | |||
848 | 91 | else if (g_str_equal (type, "com.canonical.indicator.messages.source")) | ||
849 | 92 | item = ido_source_menu_item_new_from_menu_model (menuitem, actions); | ||
850 | 93 | |||
851 | 86 | return item; | 94 | return item; |
852 | 87 | } | 95 | } |
853 | 88 | 96 | ||
854 | 89 | 97 | ||
855 | === added file 'src/idosourcemenuitem.c' | |||
856 | --- src/idosourcemenuitem.c 1970-01-01 00:00:00 +0000 | |||
857 | +++ src/idosourcemenuitem.c 2013-08-13 20:56:02 +0000 | |||
858 | @@ -0,0 +1,264 @@ | |||
859 | 1 | /* | ||
860 | 2 | * Copyright 2013 Canonical Ltd. | ||
861 | 3 | * | ||
862 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
863 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
864 | 6 | * by the Free Software Foundation. | ||
865 | 7 | * | ||
866 | 8 | * This program is distributed in the hope that it will be useful, but | ||
867 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
868 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
869 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
870 | 12 | * | ||
871 | 13 | * You should have received a copy of the GNU General Public License along | ||
872 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
873 | 15 | * | ||
874 | 16 | * Authors: | ||
875 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
876 | 18 | */ | ||
877 | 19 | |||
878 | 20 | #include "idosourcemenuitem.h" | ||
879 | 21 | |||
880 | 22 | #include <libintl.h> | ||
881 | 23 | #include "idodetaillabel.h" | ||
882 | 24 | #include "idoactionhelper.h" | ||
883 | 25 | |||
884 | 26 | typedef GtkMenuItemClass IdoSourceMenuItemClass; | ||
885 | 27 | |||
886 | 28 | struct _IdoSourceMenuItem | ||
887 | 29 | { | ||
888 | 30 | GtkMenuItem parent; | ||
889 | 31 | |||
890 | 32 | GtkWidget *icon; | ||
891 | 33 | GtkWidget *label; | ||
892 | 34 | GtkWidget *detail; | ||
893 | 35 | |||
894 | 36 | gint64 time; | ||
895 | 37 | guint timer_id; | ||
896 | 38 | }; | ||
897 | 39 | |||
898 | 40 | G_DEFINE_TYPE (IdoSourceMenuItem, ido_source_menu_item, GTK_TYPE_MENU_ITEM); | ||
899 | 41 | |||
900 | 42 | static void | ||
901 | 43 | ido_source_menu_item_constructed (GObject *object) | ||
902 | 44 | { | ||
903 | 45 | IdoSourceMenuItem *item = IDO_SOURCE_MENU_ITEM (object); | ||
904 | 46 | GtkWidget *grid; | ||
905 | 47 | gint icon_width; | ||
906 | 48 | |||
907 | 49 | gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL); | ||
908 | 50 | |||
909 | 51 | item->icon = g_object_ref (gtk_image_new ()); | ||
910 | 52 | gtk_widget_set_margin_left (item->icon, icon_width); | ||
911 | 53 | gtk_widget_set_margin_right (item->icon, 6); | ||
912 | 54 | |||
913 | 55 | item->label = g_object_ref (gtk_label_new ("")); | ||
914 | 56 | gtk_label_set_max_width_chars (GTK_LABEL (item->label), 40); | ||
915 | 57 | gtk_label_set_ellipsize (GTK_LABEL (item->label), PANGO_ELLIPSIZE_END); | ||
916 | 58 | gtk_misc_set_alignment (GTK_MISC (item->label), 0.0, 0.5); | ||
917 | 59 | |||
918 | 60 | item->detail = g_object_ref (ido_detail_label_new ("")); | ||
919 | 61 | gtk_widget_set_halign (item->detail, GTK_ALIGN_END); | ||
920 | 62 | gtk_widget_set_hexpand (item->detail, TRUE); | ||
921 | 63 | gtk_style_context_add_class (gtk_widget_get_style_context (item->detail), "accelerator"); | ||
922 | 64 | |||
923 | 65 | grid = gtk_grid_new (); | ||
924 | 66 | gtk_grid_attach (GTK_GRID (grid), item->icon, 0, 0, 1, 1); | ||
925 | 67 | gtk_grid_attach (GTK_GRID (grid), item->label, 1, 0, 1, 1); | ||
926 | 68 | gtk_grid_attach (GTK_GRID (grid), item->detail, 2, 0, 1, 1); | ||
927 | 69 | |||
928 | 70 | gtk_container_add (GTK_CONTAINER (object), grid); | ||
929 | 71 | gtk_widget_show_all (grid); | ||
930 | 72 | |||
931 | 73 | G_OBJECT_CLASS (ido_source_menu_item_parent_class)->constructed (object); | ||
932 | 74 | } | ||
933 | 75 | |||
934 | 76 | static gchar * | ||
935 | 77 | ido_source_menu_item_time_span_string (gint64 timestamp) | ||
936 | 78 | { | ||
937 | 79 | gchar *str; | ||
938 | 80 | gint64 span; | ||
939 | 81 | gint hours; | ||
940 | 82 | gint minutes; | ||
941 | 83 | |||
942 | 84 | span = MAX (g_get_real_time () - timestamp, 0) / G_USEC_PER_SEC; | ||
943 | 85 | hours = span / 3600; | ||
944 | 86 | minutes = (span / 60) % 60; | ||
945 | 87 | |||
946 | 88 | if (hours == 0) | ||
947 | 89 | { | ||
948 | 90 | /* TRANSLATORS: number of minutes that have passed */ | ||
949 | 91 | str = g_strdup_printf (ngettext ("%d min", "%d min", minutes), minutes); | ||
950 | 92 | } | ||
951 | 93 | else | ||
952 | 94 | { | ||
953 | 95 | /* TRANSLATORS: number of hours that have passed */ | ||
954 | 96 | str = g_strdup_printf (ngettext ("%d h", "%d h", hours), hours); | ||
955 | 97 | } | ||
956 | 98 | |||
957 | 99 | return str; | ||
958 | 100 | } | ||
959 | 101 | |||
960 | 102 | static void | ||
961 | 103 | ido_source_menu_item_set_detail_time (IdoSourceMenuItem *self, | ||
962 | 104 | gint64 time) | ||
963 | 105 | { | ||
964 | 106 | gchar *str; | ||
965 | 107 | |||
966 | 108 | self->time = time; | ||
967 | 109 | |||
968 | 110 | str = ido_source_menu_item_time_span_string (self->time); | ||
969 | 111 | ido_detail_label_set_text (IDO_DETAIL_LABEL (self->detail), str); | ||
970 | 112 | |||
971 | 113 | g_free (str); | ||
972 | 114 | } | ||
973 | 115 | |||
974 | 116 | static gboolean | ||
975 | 117 | ido_source_menu_item_update_time (gpointer data) | ||
976 | 118 | { | ||
977 | 119 | IdoSourceMenuItem *self = data; | ||
978 | 120 | |||
979 | 121 | ido_source_menu_item_set_detail_time (self, self->time); | ||
980 | 122 | |||
981 | 123 | return TRUE; | ||
982 | 124 | } | ||
983 | 125 | |||
984 | 126 | static void | ||
985 | 127 | ido_source_menu_item_dispose (GObject *object) | ||
986 | 128 | { | ||
987 | 129 | IdoSourceMenuItem *self = IDO_SOURCE_MENU_ITEM (object); | ||
988 | 130 | |||
989 | 131 | if (self->timer_id != 0) | ||
990 | 132 | { | ||
991 | 133 | g_source_remove (self->timer_id); | ||
992 | 134 | self->timer_id = 0; | ||
993 | 135 | } | ||
994 | 136 | |||
995 | 137 | g_clear_object (&self->icon); | ||
996 | 138 | g_clear_object (&self->label); | ||
997 | 139 | g_clear_object (&self->detail); | ||
998 | 140 | |||
999 | 141 | G_OBJECT_CLASS (ido_source_menu_item_parent_class)->dispose (object); | ||
1000 | 142 | } | ||
1001 | 143 | |||
1002 | 144 | static void | ||
1003 | 145 | ido_source_menu_item_class_init (IdoSourceMenuItemClass *klass) | ||
1004 | 146 | { | ||
1005 | 147 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
1006 | 148 | |||
1007 | 149 | object_class->constructed = ido_source_menu_item_constructed; | ||
1008 | 150 | object_class->dispose = ido_source_menu_item_dispose; | ||
1009 | 151 | } | ||
1010 | 152 | |||
1011 | 153 | static void | ||
1012 | 154 | ido_source_menu_item_init (IdoSourceMenuItem *self) | ||
1013 | 155 | { | ||
1014 | 156 | } | ||
1015 | 157 | |||
1016 | 158 | static void | ||
1017 | 159 | ido_source_menu_item_set_label (IdoSourceMenuItem *item, | ||
1018 | 160 | const gchar *label) | ||
1019 | 161 | { | ||
1020 | 162 | gtk_label_set_label (GTK_LABEL (item->label), label ? label : ""); | ||
1021 | 163 | } | ||
1022 | 164 | |||
1023 | 165 | static void | ||
1024 | 166 | ido_source_menu_item_set_icon (IdoSourceMenuItem *item, | ||
1025 | 167 | GIcon *icon) | ||
1026 | 168 | { | ||
1027 | 169 | if (icon) | ||
1028 | 170 | gtk_image_set_from_gicon (GTK_IMAGE (item->icon), icon, GTK_ICON_SIZE_MENU); | ||
1029 | 171 | else | ||
1030 | 172 | gtk_image_clear (GTK_IMAGE (item->icon)); | ||
1031 | 173 | } | ||
1032 | 174 | |||
1033 | 175 | |||
1034 | 176 | static void | ||
1035 | 177 | ido_source_menu_item_activate (GtkMenuItem *item, | ||
1036 | 178 | gpointer user_data) | ||
1037 | 179 | { | ||
1038 | 180 | IdoActionHelper *helper = user_data; | ||
1039 | 181 | |||
1040 | 182 | /* The parameter signifies whether this source was activated (TRUE) or | ||
1041 | 183 | * dismissed (FALSE). Since there's no UI to dismiss a gtkmenuitem, | ||
1042 | 184 | * this always passes TRUE. */ | ||
1043 | 185 | ido_action_helper_activate_with_parameter (helper, g_variant_new_boolean (TRUE)); | ||
1044 | 186 | } | ||
1045 | 187 | |||
1046 | 188 | static void | ||
1047 | 189 | ido_source_menu_item_state_changed (IdoActionHelper *helper, | ||
1048 | 190 | GVariant *state, | ||
1049 | 191 | gpointer user_data) | ||
1050 | 192 | { | ||
1051 | 193 | IdoSourceMenuItem *item = user_data; | ||
1052 | 194 | guint32 count; | ||
1053 | 195 | gint64 time; | ||
1054 | 196 | const gchar *str; | ||
1055 | 197 | |||
1056 | 198 | if (item->timer_id != 0) | ||
1057 | 199 | { | ||
1058 | 200 | g_source_remove (item->timer_id); | ||
1059 | 201 | item->timer_id = 0; | ||
1060 | 202 | } | ||
1061 | 203 | |||
1062 | 204 | g_return_val_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE ("(uxsb)")), FALSE); | ||
1063 | 205 | |||
1064 | 206 | g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); | ||
1065 | 207 | |||
1066 | 208 | if (count != 0) | ||
1067 | 209 | ido_detail_label_set_count (IDO_DETAIL_LABEL (item->detail), count); | ||
1068 | 210 | else if (time != 0) | ||
1069 | 211 | { | ||
1070 | 212 | ido_source_menu_item_set_detail_time (item, time); | ||
1071 | 213 | item->timer_id = g_timeout_add_seconds (59, ido_source_menu_item_update_time, item); | ||
1072 | 214 | } | ||
1073 | 215 | else if (str != NULL && *str) | ||
1074 | 216 | ido_detail_label_set_text (IDO_DETAIL_LABEL (item->detail), str); | ||
1075 | 217 | } | ||
1076 | 218 | |||
1077 | 219 | GtkMenuItem * | ||
1078 | 220 | ido_source_menu_item_new_from_menu_model (GMenuItem *menuitem, | ||
1079 | 221 | GActionGroup *actions) | ||
1080 | 222 | { | ||
1081 | 223 | GtkMenuItem *item; | ||
1082 | 224 | GVariant *serialized_icon; | ||
1083 | 225 | GIcon *icon = NULL; | ||
1084 | 226 | gchar *label; | ||
1085 | 227 | gchar *action = NULL; | ||
1086 | 228 | |||
1087 | 229 | item = g_object_new (IDO_TYPE_SOURCE_MENU_ITEM, NULL); | ||
1088 | 230 | |||
1089 | 231 | if (g_menu_item_get_attribute (menuitem, "label", "s", &label)) | ||
1090 | 232 | { | ||
1091 | 233 | ido_source_menu_item_set_label (IDO_SOURCE_MENU_ITEM (item), label); | ||
1092 | 234 | g_free (label); | ||
1093 | 235 | } | ||
1094 | 236 | |||
1095 | 237 | serialized_icon = g_menu_item_get_attribute_value (menuitem, "icon", NULL); | ||
1096 | 238 | if (serialized_icon) | ||
1097 | 239 | { | ||
1098 | 240 | icon = g_icon_deserialize (serialized_icon); | ||
1099 | 241 | g_variant_unref (serialized_icon); | ||
1100 | 242 | } | ||
1101 | 243 | ido_source_menu_item_set_icon (IDO_SOURCE_MENU_ITEM (item), icon); | ||
1102 | 244 | |||
1103 | 245 | if (g_menu_item_get_attribute (menuitem, "action", "s", &action)) | ||
1104 | 246 | { | ||
1105 | 247 | IdoActionHelper *helper; | ||
1106 | 248 | |||
1107 | 249 | helper = ido_action_helper_new (GTK_WIDGET (item), actions, action, NULL); | ||
1108 | 250 | g_signal_connect (helper, "action-state-changed", | ||
1109 | 251 | G_CALLBACK (ido_source_menu_item_state_changed), item); | ||
1110 | 252 | g_signal_connect_object (item, "activate", | ||
1111 | 253 | G_CALLBACK (ido_source_menu_item_activate), helper, | ||
1112 | 254 | 0); | ||
1113 | 255 | g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); | ||
1114 | 256 | |||
1115 | 257 | g_free (action); | ||
1116 | 258 | } | ||
1117 | 259 | |||
1118 | 260 | if (icon) | ||
1119 | 261 | g_object_unref (icon); | ||
1120 | 262 | |||
1121 | 263 | return item; | ||
1122 | 264 | } | ||
1123 | 0 | 265 | ||
1124 | === added file 'src/idosourcemenuitem.h' | |||
1125 | --- src/idosourcemenuitem.h 1970-01-01 00:00:00 +0000 | |||
1126 | +++ src/idosourcemenuitem.h 2013-08-13 20:56:02 +0000 | |||
1127 | @@ -0,0 +1,36 @@ | |||
1128 | 1 | /* | ||
1129 | 2 | * Copyright 2013 Canonical Ltd. | ||
1130 | 3 | * | ||
1131 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1132 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
1133 | 6 | * by the Free Software Foundation. | ||
1134 | 7 | * | ||
1135 | 8 | * This program is distributed in the hope that it will be useful, but | ||
1136 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1137 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1138 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
1139 | 12 | * | ||
1140 | 13 | * You should have received a copy of the GNU General Public License along | ||
1141 | 14 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1142 | 15 | * | ||
1143 | 16 | * Authors: | ||
1144 | 17 | * Lars Uebernickel <lars.uebernickel@canonical.com> | ||
1145 | 18 | */ | ||
1146 | 19 | |||
1147 | 20 | #ifndef __IDO_SOURCE_MENU_ITEM_H__ | ||
1148 | 21 | #define __IDO_SOURCE_MENU_ITEM_H__ | ||
1149 | 22 | |||
1150 | 23 | #include <gtk/gtk.h> | ||
1151 | 24 | |||
1152 | 25 | #define IDO_TYPE_SOURCE_MENU_ITEM (ido_source_menu_item_get_type ()) | ||
1153 | 26 | #define IDO_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SOURCE_MENU_ITEM, IdoSourceMenuItem)) | ||
1154 | 27 | #define IDO_IS_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SOURCE_MENU_ITEM)) | ||
1155 | 28 | |||
1156 | 29 | typedef struct _IdoSourceMenuItem IdoSourceMenuItem; | ||
1157 | 30 | |||
1158 | 31 | GType ido_source_menu_item_get_type (void); | ||
1159 | 32 | |||
1160 | 33 | GtkMenuItem * ido_source_menu_item_new_from_menu_model (GMenuItem *menuitem, | ||
1161 | 34 | GActionGroup *actions); | ||
1162 | 35 | |||
1163 | 36 | #endif |
FAILED: Continuous integration, rev:146 jenkins. qa.ubuntu. com/job/ ido-ci/ 32/ jenkins. qa.ubuntu. com/job/ ido-saucy- amd64-ci/ 31/console jenkins. qa.ubuntu. com/job/ ido-saucy- armhf-ci/ 14/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ ido-ci/ 32/rebuild
http://