Merge lp:~robertcarr/indicator-appmenu/webapps into lp:indicator-appmenu/12.10
- webapps
- Merge into trunk.12.10
Proposed by
Robert Carr
Status: | Merged |
---|---|
Approved by: | Charles Kerr |
Approved revision: | 194 |
Merged at revision: | 207 |
Proposed branch: | lp:~robertcarr/indicator-appmenu/webapps |
Merge into: | lp:indicator-appmenu/12.10 |
Diff against target: |
523 lines (+435/-4) 8 files modified
configure.ac (+2/-2) src/Makefile.am (+2/-0) src/hud-service.c (+10/-0) src/hudwebappsource.c (+376/-0) src/hudwebappsource.h (+36/-0) src/hudwindowsource.c (+6/-0) src/hudwindowsource.h (+1/-0) tools-vala/Makefile.am (+2/-2) |
To merge this branch: | bzr merge lp:~robertcarr/indicator-appmenu/webapps |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Charles Kerr (community) | Approve | ||
Review via email: mp+120453@code.launchpad.net |
Commit message
Description of the change
Webapp support in indicator-appmenu!
Depends on
https:/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'configure.ac' |
2 | --- configure.ac 2012-07-11 18:42:01 +0000 |
3 | +++ configure.ac 2012-08-20 19:17:24 +0000 |
4 | @@ -20,7 +20,7 @@ |
5 | # Check for programs |
6 | AC_PROG_CC |
7 | AM_PROG_CC_C_O |
8 | -AM_PROG_VALAC([0.15.2]) |
9 | +AM_PROG_VALAC([]) |
10 | |
11 | # Initialize libtool |
12 | LT_PREREQ([2.2.6]) |
13 | @@ -82,7 +82,7 @@ |
14 | |
15 | PKG_CHECK_MODULES([HUD],[ |
16 | dbusmenu-glib-0.4 >= $DBUSMENU_GLIB_REQUIRED_VERSION |
17 | - libbamf3 >= $BAMF_REQUIRED_VERSION |
18 | + libbamf3 |
19 | sqlite3 >= $SQLITE_REQUIRED_VERSION |
20 | ]) |
21 | |
22 | |
23 | === modified file 'src/Makefile.am' |
24 | --- src/Makefile.am 2012-04-11 15:15:24 +0000 |
25 | +++ src/Makefile.am 2012-08-20 19:17:24 +0000 |
26 | @@ -112,6 +112,8 @@ |
27 | hudmenumodelcollector.c \ |
28 | hudappindicatorsource.h \ |
29 | hudappindicatorsource.c \ |
30 | + hudwebappsource.h \ |
31 | + hudwebappsource.c \ |
32 | hudindicatorsource.h \ |
33 | hudindicatorsource.c \ |
34 | hudwindowsource.h \ |
35 | |
36 | === modified file 'src/hud-service.c' |
37 | --- src/hud-service.c 2012-03-16 15:25:20 +0000 |
38 | +++ src/hud-service.c 2012-08-20 19:17:24 +0000 |
39 | @@ -28,6 +28,7 @@ |
40 | |
41 | #include "hudappindicatorsource.h" |
42 | #include "hudindicatorsource.h" |
43 | +#include "hudwebappsource.h" |
44 | #include "hudwindowsource.h" |
45 | #include "huddebugsource.h" |
46 | #include "hudsourcelist.h" |
47 | @@ -303,6 +304,15 @@ |
48 | hud_source_list_add (source_list, HUD_SOURCE (source)); |
49 | g_object_unref (source); |
50 | } |
51 | + |
52 | + { |
53 | + HudWebappSource *source; |
54 | + |
55 | + source = hud_webapp_source_new (window_source); |
56 | + hud_source_list_add (source_list, HUD_SOURCE (source)); |
57 | + |
58 | + g_object_unref (G_OBJECT (source)); |
59 | + } |
60 | |
61 | if (getenv ("HUD_DEBUG_SOURCE")) |
62 | { |
63 | |
64 | === added file 'src/hudwebappsource.c' |
65 | --- src/hudwebappsource.c 1970-01-01 00:00:00 +0000 |
66 | +++ src/hudwebappsource.c 2012-08-20 19:17:24 +0000 |
67 | @@ -0,0 +1,376 @@ |
68 | +/* |
69 | + * Copyright © 2012 Canonical Ltd. |
70 | + * |
71 | + * This program is free software: you can redistribute it and/or modify it |
72 | + * under the terms of the GNU General Public License version 3, as |
73 | + * published by the Free Software Foundation. |
74 | + * |
75 | + * This program is distributed in the hope that it will be useful, but |
76 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
77 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
78 | + * PURPOSE. See the GNU General Public License for more details. |
79 | + * |
80 | + * You should have received a copy of the GNU General Public License along |
81 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
82 | + * |
83 | + * Authors: Robert Carr |
84 | + */ |
85 | + |
86 | +#include "hudwebappsource.h" |
87 | + |
88 | +#include <stdio.h> |
89 | + |
90 | +#include <glib/gi18n.h> |
91 | +#include <gio/gio.h> |
92 | + |
93 | +#include <libbamf/libbamf.h> |
94 | +#include <libbamf/bamf-application.h> |
95 | +#include <libbamf/bamf-view.h> |
96 | +#include <libbamf/bamf-tab.h> |
97 | + |
98 | +#include "hudsettings.h" |
99 | +#include "huddbusmenucollector.h" |
100 | +#include "hudsource.h" |
101 | + |
102 | +/** |
103 | + * SECTION:hudwebappsource |
104 | + * @title:HudWebappSource |
105 | + * @short_description: a #HudSource to search through the menus of |
106 | + * webapps registered with the Unity Webapps System. |
107 | + * |
108 | + * #HudWebappsSource searches through the menu items of webapps |
109 | + **/ |
110 | + |
111 | +/** |
112 | + * HudWebappSource: |
113 | + * |
114 | + * This is an opaque structure type. |
115 | + **/ |
116 | + |
117 | +struct _HudWebappSource |
118 | +{ |
119 | + GObject parent_instance; |
120 | + |
121 | + GList *applications; |
122 | + |
123 | + HudWindowSource *window_source; |
124 | +}; |
125 | + |
126 | +typedef GObjectClass HudWebappSourceClass; |
127 | + |
128 | +typedef struct _HudWebappApplicationSource { |
129 | + BamfApplication *application; |
130 | + |
131 | + HudSource *source; |
132 | + HudSource *collector; |
133 | +} HudWebappApplicationSource; |
134 | + |
135 | +static void hud_webapp_source_iface_init (HudSourceInterface *iface); |
136 | +G_DEFINE_TYPE_WITH_CODE (HudWebappSource, hud_webapp_source, G_TYPE_OBJECT, |
137 | + G_IMPLEMENT_INTERFACE (HUD_TYPE_SOURCE, hud_webapp_source_iface_init)) |
138 | + |
139 | + |
140 | + |
141 | +static void |
142 | +hud_webapp_source_collector_changed (HudSource *source, |
143 | + gpointer user_data) |
144 | +{ |
145 | + hud_source_changed ((HudSource *)user_data); |
146 | +} |
147 | + |
148 | +static void |
149 | +hud_webapp_source_application_child_moved (BamfApplication *application, |
150 | + BamfView *child, |
151 | + gpointer user_data) |
152 | +{ |
153 | + HudSource *source = HUD_SOURCE (user_data); |
154 | + |
155 | + hud_source_changed (source); |
156 | +} |
157 | + |
158 | +static gboolean |
159 | +hud_webapp_source_should_search_app (BamfApplication *application, |
160 | + guint32 active_xid) |
161 | +{ |
162 | + GList *children, *walk; |
163 | + gboolean should; |
164 | + |
165 | + should = FALSE; |
166 | + |
167 | + children = bamf_view_get_children (BAMF_VIEW (application)); |
168 | + |
169 | + for (walk = children; walk != NULL; walk = walk->next) |
170 | + { |
171 | + BamfTab *child; |
172 | + |
173 | + if (BAMF_IS_TAB (walk->data) == FALSE) |
174 | + continue; |
175 | + |
176 | + child = BAMF_TAB (walk->data); |
177 | + |
178 | + if ((active_xid == bamf_tab_get_xid (child)) && |
179 | + bamf_tab_get_is_foreground_tab (child)) |
180 | + { |
181 | + should = TRUE; |
182 | + break; |
183 | + } |
184 | + } |
185 | + |
186 | + g_list_free (children); |
187 | + return should; |
188 | +} |
189 | + |
190 | +static void |
191 | +hud_webapp_source_search (HudSource *hud_source, |
192 | + GPtrArray *results_array, |
193 | + HudTokenList *token_list) |
194 | +{ |
195 | + HudWebappSource *source; |
196 | + GList *walk; |
197 | + |
198 | + source = HUD_WEBAPP_SOURCE (hud_source); |
199 | + |
200 | + for (walk = source->applications; walk != NULL; walk = walk->next) |
201 | + { |
202 | + HudWebappApplicationSource *application_source; |
203 | + guint32 active_xid; |
204 | + |
205 | + application_source = (HudWebappApplicationSource *)walk->data; |
206 | + |
207 | + active_xid = hud_window_source_get_active_xid (source->window_source); |
208 | + |
209 | + if (hud_webapp_source_should_search_app (application_source->application, active_xid)) |
210 | + { |
211 | + hud_source_search (application_source->collector, results_array, token_list); |
212 | + } |
213 | + |
214 | + } |
215 | +} |
216 | + |
217 | +HudWebappApplicationSource * |
218 | +hud_webapp_application_source_new (HudSource *source, |
219 | + BamfApplication *application) |
220 | +{ |
221 | + HudWebappApplicationSource *application_source; |
222 | + gchar *name, *path; |
223 | + |
224 | + name = path = NULL; |
225 | + |
226 | + bamf_application_get_application_menu (application, |
227 | + &name, &path); |
228 | + |
229 | + if (name == NULL || *name == '\0') |
230 | + return NULL; |
231 | + |
232 | + application_source = g_malloc0 (sizeof (HudWebappApplicationSource)); |
233 | + |
234 | + application_source->application = g_object_ref (G_OBJECT (application)); |
235 | + application_source->source = source; |
236 | + |
237 | + application_source->collector = (HudSource *)hud_dbusmenu_collector_new_for_endpoint (bamf_view_get_name (BAMF_VIEW (application)), |
238 | + bamf_view_get_name (BAMF_VIEW (application)), |
239 | + bamf_view_get_icon (BAMF_VIEW (application)), |
240 | + 0, |
241 | + name, path); |
242 | + |
243 | + g_signal_connect_object (application, "child-moved", |
244 | + G_CALLBACK (hud_webapp_source_application_child_moved), |
245 | + source, 0); |
246 | + |
247 | + |
248 | + |
249 | + g_free (name); |
250 | + g_free (path); |
251 | + |
252 | + return application_source; |
253 | +} |
254 | + |
255 | +static void |
256 | +hud_webapp_application_source_free (HudWebappApplicationSource *application_source) |
257 | +{ |
258 | + g_object_unref (G_OBJECT (application_source->application)); |
259 | + g_object_unref (G_OBJECT (application_source->collector)); |
260 | + |
261 | + g_free (application_source); |
262 | +} |
263 | + |
264 | + |
265 | +static void |
266 | +on_active_changed (BamfApplication *application, |
267 | + gboolean active, |
268 | + HudSource *source) |
269 | +{ |
270 | + hud_source_changed (source); |
271 | +} |
272 | + |
273 | +static void |
274 | +hud_webapp_source_remove_application (HudWebappSource *source, |
275 | + BamfApplication *application) |
276 | +{ |
277 | + HudWebappApplicationSource *application_source; |
278 | + GList *walk; |
279 | + |
280 | + application_source = NULL; |
281 | + |
282 | + for (walk = source->applications; walk != NULL; walk = walk->next) |
283 | + { |
284 | + HudWebappApplicationSource *t; |
285 | + |
286 | + t = (HudWebappApplicationSource *)walk->data; |
287 | + |
288 | + if (t->application == application) |
289 | + application_source = t; |
290 | + } |
291 | + |
292 | + if (application_source == NULL) |
293 | + return; |
294 | + |
295 | + g_signal_handlers_disconnect_by_func (application_source->collector, |
296 | + G_CALLBACK (hud_webapp_source_collector_changed), |
297 | + source); |
298 | + g_signal_handlers_disconnect_by_func (application, G_CALLBACK (on_active_changed), |
299 | + source); |
300 | + |
301 | + source->applications = g_list_remove (source->applications, application_source); |
302 | + |
303 | + hud_webapp_application_source_free (application_source); |
304 | + |
305 | + hud_webapp_source_collector_changed ((HudSource *)source, source); |
306 | + |
307 | +} |
308 | + |
309 | +static void |
310 | +hud_webapp_source_bamf_view_closed (BamfMatcher *matcher, |
311 | + BamfView *view, |
312 | + gpointer user_data) |
313 | +{ |
314 | + HudWebappSource *source; |
315 | + |
316 | + source = (HudWebappSource *)user_data; |
317 | + |
318 | + if (BAMF_IS_APPLICATION (view) == FALSE) |
319 | + return; |
320 | + |
321 | + hud_webapp_source_remove_application (source, (BamfApplication *)view); |
322 | +} |
323 | + |
324 | +static void |
325 | +hud_webapp_source_register_application (HudWebappSource *source, |
326 | + BamfApplication *application) |
327 | +{ |
328 | + HudWebappApplicationSource *application_source; |
329 | + |
330 | + application_source = hud_webapp_application_source_new (HUD_SOURCE (source), application); |
331 | + |
332 | + if (application_source == NULL) |
333 | + return; |
334 | + |
335 | + g_signal_connect (application_source->collector, "changed", G_CALLBACK (hud_webapp_source_collector_changed), source); |
336 | + |
337 | + source->applications = g_list_append (source->applications, application_source); |
338 | + |
339 | + hud_webapp_source_collector_changed ((HudSource *)source, source); |
340 | + |
341 | + g_signal_connect (application, "active-changed", G_CALLBACK (on_active_changed), source); |
342 | + |
343 | +} |
344 | + |
345 | +static void |
346 | +hud_webapp_source_finalize (GObject *object) |
347 | +{ |
348 | + g_assert_not_reached (); |
349 | +} |
350 | + |
351 | +static void |
352 | +hud_webapp_source_bamf_view_opened (BamfMatcher *matcher, |
353 | + BamfView *view, |
354 | + gpointer user_data) |
355 | +{ |
356 | + HudWebappSource *source; |
357 | + BamfApplication *application; |
358 | + |
359 | + source = (HudWebappSource *)user_data; |
360 | + |
361 | + if (BAMF_IS_APPLICATION (view) == FALSE) |
362 | + return; |
363 | + |
364 | + application = BAMF_APPLICATION (view); |
365 | + |
366 | + if (g_strcmp0 (bamf_application_get_application_type (application), "webapp") != 0) |
367 | + return; |
368 | + |
369 | + hud_webapp_source_register_application (source, application); |
370 | +} |
371 | + |
372 | +static void |
373 | +hud_webapp_source_init (HudWebappSource *source) |
374 | +{ |
375 | + BamfMatcher *matcher; |
376 | + GList *applications, *walk; |
377 | + |
378 | + source->applications = NULL; |
379 | + |
380 | + matcher = bamf_matcher_get_default (); |
381 | + |
382 | + applications = bamf_matcher_get_applications (matcher); |
383 | + |
384 | + for (walk = applications; walk != NULL; walk = walk -> next) |
385 | + { |
386 | + BamfApplication *application; |
387 | + |
388 | + application = (BamfApplication *)walk->data; |
389 | + |
390 | + if (g_strcmp0 (bamf_application_get_application_type (application), "webapp") != 0) |
391 | + continue; |
392 | + |
393 | + hud_webapp_source_register_application (source, application); |
394 | + } |
395 | + |
396 | + g_signal_connect (matcher, "view-opened", G_CALLBACK (hud_webapp_source_bamf_view_opened), source); |
397 | + g_signal_connect (matcher, "view-closed", G_CALLBACK (hud_webapp_source_bamf_view_closed), source); |
398 | + |
399 | + g_list_free (applications); |
400 | +} |
401 | + |
402 | +static void |
403 | +hud_webapp_source_use (HudSource *hud_source) |
404 | +{ |
405 | +} |
406 | + |
407 | +static void |
408 | +hud_webapp_source_unuse (HudSource *hud_source) |
409 | +{ |
410 | +} |
411 | + |
412 | +static void |
413 | +hud_webapp_source_iface_init (HudSourceInterface *iface) |
414 | +{ |
415 | + iface->search = hud_webapp_source_search; |
416 | + iface->use = hud_webapp_source_use; |
417 | + iface->unuse = hud_webapp_source_unuse; |
418 | +} |
419 | + |
420 | +static void |
421 | +hud_webapp_source_class_init (HudWebappSourceClass *class) |
422 | +{ |
423 | + class->finalize = hud_webapp_source_finalize; |
424 | +} |
425 | + |
426 | +/** |
427 | + * hud_webapp_source_new: |
428 | + * |
429 | + * Creates a #HudWebappSource. |
430 | + * |
431 | + * Returns: a new #HudWebappSource |
432 | + **/ |
433 | +HudWebappSource * |
434 | +hud_webapp_source_new (HudWindowSource *window_source) |
435 | +{ |
436 | + HudWebappSource *webapp_source; |
437 | + |
438 | + webapp_source = (HudWebappSource *) g_object_new (HUD_TYPE_WEBAPP_SOURCE, NULL); |
439 | + |
440 | + webapp_source->window_source = window_source; |
441 | + |
442 | + return webapp_source; |
443 | +} |
444 | |
445 | === added file 'src/hudwebappsource.h' |
446 | --- src/hudwebappsource.h 1970-01-01 00:00:00 +0000 |
447 | +++ src/hudwebappsource.h 2012-08-20 19:17:24 +0000 |
448 | @@ -0,0 +1,36 @@ |
449 | +/* |
450 | + * Copyright © 2012 Canonical Ltd. |
451 | + * |
452 | + * This program is free software: you can redistribute it and/or modify it |
453 | + * under the terms of the GNU General Public License version 3, as |
454 | + * published by the Free Software Foundation. |
455 | + * |
456 | + * This program is distributed in the hope that it will be useful, but |
457 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
458 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
459 | + * PURPOSE. See the GNU General Public License for more details. |
460 | + * |
461 | + * You should have received a copy of the GNU General Public License along |
462 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
463 | + * |
464 | + * Author: Ryan Lortie <desrt@desrt.ca> |
465 | + */ |
466 | + |
467 | +#ifndef __HUD_WEBAPP_SOURCE_H__ |
468 | +#define __HUD_WEBAPP_SOURCE_H__ |
469 | + |
470 | +#include <glib-object.h> |
471 | +#include "hudwindowsource.h" |
472 | + |
473 | +#define HUD_TYPE_WEBAPP_SOURCE (hud_webapp_source_get_type ()) |
474 | +#define HUD_WEBAPP_SOURCE(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ |
475 | + HUD_TYPE_WEBAPP_SOURCE, HudWebappSource)) |
476 | +#define HUD_IS_WEBAPP_SOURCE(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ |
477 | + HUD_TYPE_WEBAPP_SOURCE)) |
478 | + |
479 | +typedef struct _HudWebappSource HudWebappSource; |
480 | + |
481 | +GType hud_webapp_source_get_type (void); |
482 | +HudWebappSource * hud_webapp_source_new (HudWindowSource *window_source); |
483 | + |
484 | +#endif /* __HUD_WEBAPP_SOURCE_H__ */ |
485 | |
486 | === modified file 'src/hudwindowsource.c' |
487 | --- src/hudwindowsource.c 2012-04-03 12:26:05 +0000 |
488 | +++ src/hudwindowsource.c 2012-08-20 19:17:24 +0000 |
489 | @@ -364,3 +364,9 @@ |
490 | { |
491 | return g_object_new (HUD_TYPE_WINDOW_SOURCE, NULL); |
492 | } |
493 | + |
494 | +guint32 |
495 | +hud_window_source_get_active_xid (HudWindowSource *source) |
496 | +{ |
497 | + return bamf_window_get_xid (source->active_window); |
498 | +} |
499 | |
500 | === modified file 'src/hudwindowsource.h' |
501 | --- src/hudwindowsource.h 2012-02-28 18:29:03 +0000 |
502 | +++ src/hudwindowsource.h 2012-08-20 19:17:24 +0000 |
503 | @@ -32,5 +32,6 @@ |
504 | GType hud_window_source_get_type (void); |
505 | |
506 | HudWindowSource * hud_window_source_new (void); |
507 | +guint32 hud_window_source_get_active_xid (HudWindowSource *source); |
508 | |
509 | #endif /* __HUD_WINDOW_SOURCE_H__ */ |
510 | |
511 | === modified file 'tools-vala/Makefile.am' |
512 | --- tools-vala/Makefile.am 2012-03-21 17:27:26 +0000 |
513 | +++ tools-vala/Makefile.am 2012-08-20 19:17:24 +0000 |
514 | @@ -1,7 +1,7 @@ |
515 | |
516 | EXTRA_DIST = |
517 | -bin_PROGRAMS = \ |
518 | - hud-gtk |
519 | +bin_PROGRAMS = hud-gtk |
520 | + |
521 | |
522 | #################### |
523 | # hud-gtk |
Looks good.