Merge lp:~indicator-applet-developers/evolution-indicator/multiple-mailbox-indication into lp:evolution-indicator
- multiple-mailbox-indication
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~indicator-applet-developers/evolution-indicator/multiple-mailbox-indication |
Merge into: | lp:evolution-indicator |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~indicator-applet-developers/evolution-indicator/multiple-mailbox-indication |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Neil J. Patel (njpatel) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ted Gould (ted) wrote : | # |
In set_indicator_
instead of g_sprintf because you don't have to choose how many character
it'll be. But, you need to g_free it at the end.
I'd pull "unread" into a #define to just ensure that it's the same in
all places it's used.
In update_accounts timeval should probably be init'd with {0} instead of
{0,} as I think one will initialize all fields of the struct and the
other only the first.
In general, I consider all of these comments pretty minor. Clean up
stuff, I'm going to mark the review as approved. Cool!
review approve
- 55. By Neil J. Patel
-
modified:
Makefile.am
- Add support for generating ChangeLog on make distsrc/evolution
-indicator. c
Make Ted's suggested changes (thanks!)
- Move "unread" string into #define
- Use g_strdup_printf instead of pre-alloc'ed buf & g_sprintf
- Initialise GTimeVal struct to NULL properly
Preview Diff
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2009-08-04 16:58:03 +0000 |
3 | +++ .bzrignore 2009-09-09 17:04:22 +0000 |
4 | @@ -56,3 +56,4 @@ |
5 | src/mail-server.lo |
6 | src/org-freedesktop-evolution-indicator.eplug |
7 | src/xutils.lo |
8 | +autom4te.cache |
9 | |
10 | === modified file 'configure.ac' |
11 | --- configure.ac 2009-08-04 17:15:06 +0000 |
12 | +++ configure.ac 2009-09-09 17:02:23 +0000 |
13 | @@ -1,6 +1,7 @@ |
14 | AC_PREREQ(2.53) |
15 | -AC_INIT(evolution-indicator, 0.1.16, []) |
16 | +AC_INIT(evolution-indicator, 0.1.17, []) |
17 | AM_INIT_AUTOMAKE() |
18 | +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) |
19 | AC_CONFIG_SRCDIR(src/evolution-indicator.c) |
20 | AM_CONFIG_HEADER(config.h) |
21 | AM_MAINTAINER_MODE |
22 | |
23 | === modified file 'src/Makefile.am' |
24 | --- src/Makefile.am 2009-04-03 21:46:11 +0000 |
25 | +++ src/Makefile.am 2009-09-09 17:02:23 +0000 |
26 | @@ -9,8 +9,6 @@ |
27 | liborg_freedesktop_evolution_indicator_la_SOURCES = \ |
28 | e-shell.h \ |
29 | evolution-indicator.c \ |
30 | - mail-server.c \ |
31 | - mail-server.h \ |
32 | xutils.c \ |
33 | xutils.h |
34 | |
35 | |
36 | === modified file 'src/evolution-indicator.c' |
37 | --- src/evolution-indicator.c 2009-09-08 10:26:58 +0000 |
38 | +++ src/evolution-indicator.c 2009-09-09 18:26:17 +0000 |
39 | @@ -25,14 +25,15 @@ |
40 | #include <string.h> |
41 | #include <glib.h> |
42 | #include <glib/gi18n-lib.h> |
43 | +#include <glib/gprintf.h> |
44 | |
45 | #include <gconf/gconf.h> |
46 | |
47 | #include <canberra.h> |
48 | #include <libnotify/notify.h> |
49 | -#include <libindicate/indicator-message.h> |
50 | |
51 | #include <time.h> |
52 | +#include <string.h> |
53 | |
54 | #include <e-util/e-config.h> |
55 | #include <mail/em-utils.h> |
56 | @@ -42,8 +43,11 @@ |
57 | #include <shell/e-component-view.h> |
58 | #include <shell/es-event.h> |
59 | |
60 | +#include <libindicate/server.h> |
61 | +#include <libindicate/indicator.h> |
62 | +#include <libindicate/indicator-messages.h> |
63 | + |
64 | #include "e-shell.h" |
65 | -#include "mail-server.h" |
66 | #include "xutils.h" |
67 | |
68 | #define CONF_DIR "/apps/evolution/eplugin/evolution_indicator" |
69 | @@ -55,12 +59,15 @@ |
70 | #define ACCOUNT_DIR "/apps/evolution/mail" |
71 | #define ACCOUNTS ACCOUNT_DIR"/accounts" |
72 | |
73 | +#define EVOLUTION_DESKTOP_FILE "/usr/share/applications/evolution-mail.desktop" |
74 | + |
75 | static EShell *evo_shell = NULL; |
76 | -static MailServer *mail_server = NULL; |
77 | static GStaticMutex mlock = G_STATIC_MUTEX_INIT; |
78 | static GConfClient *client = NULL; |
79 | |
80 | -static gint n_accounts = 0; |
81 | +static IndicateServer *server = NULL; |
82 | +static GSList *indicators = NULL; |
83 | +static gint n_accounts = 0; |
84 | |
85 | static NotifyNotification *notification = NULL; |
86 | static ca_context *canberra_cxt = NULL; |
87 | @@ -87,6 +94,24 @@ |
88 | int e_plugin_lib_enable (EPluginLib *ep, int enable); |
89 | GtkWidget * e_plugin_lib_get_configure_widget (EPlugin *epl); |
90 | |
91 | +static void show_evolution (gpointer arg0, gpointer arg1); |
92 | + |
93 | +typedef struct { |
94 | + gchar *url; |
95 | + gchar *name; |
96 | + gchar *parent; |
97 | + gchar *last_parent; |
98 | + |
99 | + gint reap_type; |
100 | + |
101 | +} ParserData; |
102 | + |
103 | +enum { |
104 | + REAP_NONE = 0, |
105 | + REAP_URL, |
106 | + REAP_NAME |
107 | +}; |
108 | + |
109 | static GtkWidget * |
110 | get_cfg_widget (void) |
111 | { |
112 | @@ -157,6 +182,26 @@ |
113 | return FALSE; |
114 | } |
115 | |
116 | +static gint |
117 | +get_indicator_unread_count (IndicateIndicator *indicator) |
118 | +{ |
119 | + return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (indicator), "unread")); |
120 | +} |
121 | + |
122 | +static void |
123 | +set_indicator_unread_count (IndicateIndicator *indicator, gint count) |
124 | +{ |
125 | + gchar buf[21]; |
126 | + |
127 | + g_sprintf (buf, "%d", count); |
128 | + indicate_indicator_set_property (indicator, |
129 | + INDICATE_INDICATOR_MESSAGES_PROP_COUNT, |
130 | + buf); |
131 | + g_object_set_data (G_OBJECT (indicator), |
132 | + "unread", |
133 | + GINT_TO_POINTER (count)); |
134 | +} |
135 | + |
136 | void |
137 | org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t) |
138 | { |
139 | @@ -185,8 +230,36 @@ |
140 | |
141 | if (show_count) |
142 | { |
143 | - /* Update libindicate */ |
144 | - mail_server_set_message_count (mail_server, message_count); |
145 | + IndicateIndicator *indicator = NULL; |
146 | + GSList *i; |
147 | + |
148 | + for (i = indicators; i; i = i->next) |
149 | + { |
150 | + IndicateIndicator *indi = i->data; |
151 | + |
152 | + if (g_strstr_len (t->uri, |
153 | + -1, |
154 | + indicate_indicator_get_property (indi, "url"))) |
155 | + { |
156 | + indicator = indi; |
157 | + break; |
158 | + } |
159 | + } |
160 | + if (indicator) |
161 | + { |
162 | + gint count; |
163 | + |
164 | + count = get_indicator_unread_count (indicator); |
165 | + set_indicator_unread_count (indicator, count + t->new); |
166 | + |
167 | + indicate_indicator_set_property (indicator, |
168 | + INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, |
169 | + "true"); |
170 | + } |
171 | + else |
172 | + { |
173 | + g_warning ("Unable to find account that matches %s", t->uri); |
174 | + } |
175 | } |
176 | |
177 | /* Show bubble */ |
178 | @@ -248,19 +321,28 @@ |
179 | void |
180 | org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t) |
181 | { |
182 | - g_return_if_fail (t != NULL); |
183 | + GSList *i; |
184 | + |
185 | + g_return_if_fail (t != NULL); |
186 | |
187 | g_static_mutex_lock (&mlock); |
188 | |
189 | g_debug ("EI: mail_read_notify"); |
190 | |
191 | - message_count = 0; |
192 | - |
193 | - if (show_count) |
194 | - { |
195 | - mail_server_set_message_count (mail_server, message_count); |
196 | - } |
197 | - |
198 | + for (i = indicators; i; i = i->next) |
199 | + { |
200 | + IndicateIndicator *indicator = i->data; |
201 | + |
202 | + set_indicator_unread_count (indicator, 0); |
203 | + indicate_indicator_set_property (indicator, |
204 | + INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, |
205 | + "false"); |
206 | + |
207 | + g_debug ("Setting %s to 0 unread messages", |
208 | + indicate_indicator_get_property (indicator, "name")); |
209 | + |
210 | + } |
211 | + |
212 | g_static_mutex_unlock (&mlock); |
213 | } |
214 | |
215 | @@ -309,8 +391,8 @@ |
216 | |
217 | show_count = gconf_value_get_bool (value); |
218 | |
219 | - show_count ? indicate_server_show (INDICATE_SERVER (mail_server)) |
220 | - : indicate_server_hide (INDICATE_SERVER (mail_server)); |
221 | + show_count ? indicate_server_show (server) |
222 | + : indicate_server_hide (server); |
223 | |
224 | g_debug ("EI: Messages in panel %s", |
225 | show_count ? "true" : "false"); |
226 | @@ -331,19 +413,110 @@ |
227 | g_debug ("EI: Show Bubbles %s", show_bubble ? "true" : "false"); |
228 | } |
229 | |
230 | +static IndicateIndicator * |
231 | +find_indicator_for_url (GSList *indicator_list, const gchar *url) |
232 | +{ |
233 | + GSList *i; |
234 | + |
235 | + for (i = indicator_list; i; i = i->next) |
236 | + { |
237 | + IndicateIndicator *indicator = i->data; |
238 | + |
239 | + if (g_strcmp0 (indicate_indicator_get_property (indicator, "url"), url) |
240 | + == 0) |
241 | + return indicator; |
242 | + } |
243 | + return NULL; |
244 | +} |
245 | + |
246 | +static IndicateIndicator * |
247 | +create_indicator (const gchar *url, const gchar *name) |
248 | +{ |
249 | + IndicateIndicator *indicator; |
250 | + |
251 | + indicator = indicate_indicator_new (); |
252 | + indicate_indicator_set_property (indicator, |
253 | + INDICATE_INDICATOR_MESSAGES_PROP_NAME, |
254 | + name); |
255 | + indicate_indicator_set_property (indicator, |
256 | + "url", |
257 | + url); |
258 | + set_indicator_unread_count (indicator, 0); |
259 | + indicate_indicator_show (indicator); |
260 | + |
261 | + /* FIXME: I need to find a way to show a mailbox individually */ |
262 | + g_signal_connect (indicator, "user-display", |
263 | + G_CALLBACK (show_evolution), NULL); |
264 | + |
265 | + return indicator; |
266 | +} |
267 | + |
268 | +static void |
269 | +start_element_handler (GMarkupParseContext *context, |
270 | + const gchar *element_name, |
271 | + const gchar **attribute_names, |
272 | + const gchar **attribute_values, |
273 | + gpointer user_data, |
274 | + GError **error) |
275 | +{ |
276 | + ParserData *data = (ParserData *)user_data; |
277 | + |
278 | + if (g_strcmp0 (element_name, "account") == 0) |
279 | + { |
280 | + data->name = g_strdup (attribute_values[0]); |
281 | + } |
282 | + else if (g_strcmp0 (element_name, "url") == 0) |
283 | + data->reap_type = REAP_URL; |
284 | + else |
285 | + data->reap_type = REAP_NONE; |
286 | + |
287 | + if (data->last_parent) |
288 | + g_free (data->last_parent); |
289 | + |
290 | + data->last_parent = data->parent; |
291 | + data->parent = g_strdup (element_name); |
292 | +} |
293 | + |
294 | +static void |
295 | +text_handler (GMarkupParseContext *context, |
296 | + const gchar *text, |
297 | + gsize text_len, |
298 | + gpointer user_data, |
299 | + GError **error) |
300 | +{ |
301 | + ParserData *data = (ParserData *)user_data; |
302 | + |
303 | + if (!data->url |
304 | + && data->reap_type == REAP_URL |
305 | + && g_strcmp0(data->last_parent, "source") == 0) |
306 | + { |
307 | + gchar **tokens; |
308 | + |
309 | + tokens = g_strsplit (text, ";", 2); |
310 | + |
311 | + data->url = g_strdup (tokens[0]); |
312 | + |
313 | + g_strfreev (tokens); |
314 | + } |
315 | +} |
316 | + |
317 | static void |
318 | update_accounts (void) |
319 | { |
320 | - GSList *accounts; |
321 | - GError *error = NULL; |
322 | - |
323 | + GSList *accounts; |
324 | + GError *error = NULL; |
325 | + gint i = 0; |
326 | + GTimeVal timeval = { 0, }; |
327 | + |
328 | + g_get_current_time (&timeval); |
329 | accounts = gconf_client_get_list (client, |
330 | ACCOUNTS, |
331 | GCONF_VALUE_STRING, |
332 | &error); |
333 | if (accounts == NULL || error) |
334 | { |
335 | - g_warning ("Unable to determine number of accounts, defaulting to '1' (%s)", |
336 | + g_warning ("Unable to determine number of accounts, " |
337 | + "defaulting to '1' (%s)", |
338 | error ? error->message : "unknown"); |
339 | if (error) |
340 | g_error_free (error); |
341 | @@ -355,8 +528,69 @@ |
342 | } |
343 | else |
344 | { |
345 | + GSList *old_list; |
346 | + GSList *a; |
347 | + static GMarkupParser parser = { |
348 | + start_element_handler, |
349 | + NULL, |
350 | + text_handler, |
351 | + NULL, |
352 | + NULL |
353 | + }; |
354 | + |
355 | + old_list = indicators; |
356 | + indicators = NULL; |
357 | + |
358 | + for (a = accounts; a; a = a->next) |
359 | + { |
360 | + gchar *account_info = a->data; |
361 | + GMarkupParseContext *context; |
362 | + ParserData data = { NULL, NULL, REAP_NONE }; |
363 | + IndicateIndicator *indicator; |
364 | + |
365 | + /* Parse account XML to get some useful details about the account */ |
366 | + context = g_markup_parse_context_new (&parser, 0, &data, NULL); |
367 | + g_markup_parse_context_parse (context, |
368 | + account_info, |
369 | + strlen (account_info), |
370 | + NULL); |
371 | + |
372 | + /* Check to see account already exists and, if not, create it */ |
373 | + indicator = find_indicator_for_url (indicators, data.url); |
374 | + if (indicator) |
375 | + { |
376 | + old_list = g_slist_remove (old_list, indicator); |
377 | + indicators = g_slist_append (indicators, indicator); |
378 | + } |
379 | + else |
380 | + { |
381 | + indicator = create_indicator (data.url, data.name); |
382 | + indicators = g_slist_append (indicators, indicator); |
383 | + |
384 | + g_debug ("New account: %s (%s)", data.name, data.url); |
385 | + } |
386 | + |
387 | + /* Fake a time */ |
388 | + g_time_val_add (&timeval, -1000000 * 60 * i); |
389 | + indicate_indicator_set_property_time (indicator, |
390 | + INDICATE_INDICATOR_MESSAGES_PROP_TIME, |
391 | + &timeval); |
392 | + |
393 | + /* Clean up */ |
394 | + g_free (data.url); |
395 | + g_free (data.name); |
396 | + g_free (data.parent); |
397 | + g_free (data.last_parent); |
398 | + |
399 | + g_markup_parse_context_free (context); |
400 | + |
401 | + i++; |
402 | + } |
403 | + |
404 | + g_slist_foreach (old_list, (GFunc)g_object_unref, NULL); |
405 | + g_slist_free (old_list); |
406 | + |
407 | n_accounts = g_slist_length (accounts); |
408 | - |
409 | g_slist_free (accounts); |
410 | } |
411 | |
412 | @@ -405,7 +639,11 @@ |
413 | } |
414 | } |
415 | |
416 | - mail_server = mail_server_get_default (); |
417 | + server = indicate_server_ref_default (); |
418 | + indicate_server_set_type (server, "message"); |
419 | + indicate_server_set_desktop_file (server, EVOLUTION_DESKTOP_FILE); |
420 | + g_signal_connect (server, "server-display", |
421 | + G_CALLBACK (show_evolution), NULL); |
422 | |
423 | client = gconf_client_get_default (); |
424 | gconf_client_add_dir (client, CONF_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL); |
425 | @@ -440,7 +678,7 @@ |
426 | |
427 | if (show_count) |
428 | { |
429 | - indicate_server_show (INDICATE_SERVER (mail_server)); |
430 | + indicate_server_show (server); |
431 | } |
432 | } |
433 | else |
434 | @@ -452,7 +690,16 @@ |
435 | gconf_client_notify_remove (client, accounts_id); |
436 | |
437 | g_object_unref (client); client = NULL; |
438 | - g_object_unref (mail_server); mail_server = NULL; |
439 | + |
440 | + /* Free indicators */ |
441 | + g_slist_foreach (indicators, (GFunc)g_object_unref, NULL); |
442 | + g_slist_free (indicators); |
443 | + indicators = NULL; |
444 | + |
445 | + /* Free server */ |
446 | + indicate_server_hide (server); |
447 | + g_object_unref (server); |
448 | + server = NULL; |
449 | |
450 | g_debug ("EI: Disabled"); |
451 | } |
452 | @@ -486,7 +733,6 @@ |
453 | g_debug ("EI: SHELL STARTUP"); |
454 | |
455 | evo_shell = t->shell; |
456 | - mail_server_set_e_shell (mail_server_get_default (), t->shell); |
457 | } |
458 | |
459 | static void |
460 | @@ -618,3 +864,117 @@ |
461 | |
462 | return check; |
463 | } |
464 | + |
465 | +/* |
466 | + * |
467 | + * SHOW EVOLUTION CODE |
468 | + * |
469 | + */ |
470 | + |
471 | +/* |
472 | + * Taken from libtomboy, (C) 2008 Novell, LGPL v2 or later |
473 | + */ |
474 | +static void |
475 | +tomboy_window_override_user_time (GtkWindow *window) |
476 | +{ |
477 | + guint32 ev_time = gtk_get_current_event_time(); |
478 | + |
479 | + if (ev_time == 0) { |
480 | + /* |
481 | + * FIXME: Global keypresses use an event filter on the root |
482 | + * window, which processes events before GDK sees them. |
483 | + */ |
484 | + //ev_time = tomboy_keybinder_get_current_event_time (); |
485 | + ev_time = GDK_CURRENT_TIME; |
486 | + } |
487 | + if (ev_time == 0) { |
488 | + gint ev_mask = gtk_widget_get_events (GTK_WIDGET(window)); |
489 | + if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) { |
490 | + gtk_widget_add_events (GTK_WIDGET (window), |
491 | + GDK_PROPERTY_CHANGE_MASK); |
492 | + } |
493 | + |
494 | + /* |
495 | + * NOTE: Last resort for D-BUS or other non-interactive |
496 | + * openings. Causes roundtrip to server. Lame. |
497 | + */ |
498 | + ev_time = gdk_x11_get_server_time (GTK_WIDGET(window)->window); |
499 | + } |
500 | + |
501 | + gdk_x11_window_set_user_time (GTK_WIDGET(window)->window, ev_time); |
502 | +} |
503 | + |
504 | +static void |
505 | +really_present_window (GtkWindow *window) |
506 | +{ |
507 | + if (!GTK_WIDGET_REALIZED (window)) |
508 | + gtk_widget_realize (GTK_WIDGET (window)); |
509 | + |
510 | + tomboy_window_override_user_time (window); |
511 | + |
512 | + gtk_window_present (window); |
513 | +} |
514 | + |
515 | +static void |
516 | +show_evolution (gpointer arg0, gpointer arg1) |
517 | +{ |
518 | +#define MAIL_ICON "evolution-mail" |
519 | + EShell *shell = evo_shell; |
520 | + |
521 | + g_debug ("Showing Evolution to user"); |
522 | + |
523 | + if (shell) |
524 | + { |
525 | + GSList *i; |
526 | + GList *w; |
527 | + GtkWindow *mail_window = NULL; |
528 | + |
529 | + for (w = shell->priv->windows; w; w = w->next) |
530 | + { |
531 | + GtkWindow *window = w->data; |
532 | + |
533 | + if (GTK_IS_WINDOW (window)) |
534 | + { |
535 | + if (g_strcmp0 (MAIL_ICON, gtk_window_get_icon_name (window)) == 0) |
536 | + { |
537 | + mail_window = window; |
538 | + } |
539 | + } |
540 | + else |
541 | + { |
542 | + g_warning ("No open windows: Wait, we're not a mac :-/"); |
543 | + return; |
544 | + } |
545 | + } |
546 | + |
547 | + if (!GTK_IS_WINDOW (mail_window)) |
548 | + { |
549 | + if (shell->priv->windows && shell->priv->windows->data) |
550 | + mail_window = shell->priv->windows->data; |
551 | + else |
552 | + return; |
553 | + } |
554 | + |
555 | + really_present_window (mail_window); |
556 | + for (i = indicators; i; i = i->next) |
557 | + { |
558 | + IndicateIndicator *indicator = i->data; |
559 | + |
560 | + set_indicator_unread_count (indicator, 0); |
561 | + indicate_indicator_set_property (indicator, |
562 | + INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, |
563 | + "false"); |
564 | + |
565 | + g_debug ("Setting %s to 0 unread messages", |
566 | + indicate_indicator_get_property (indicator, "name")); |
567 | + |
568 | + } |
569 | + } |
570 | + else |
571 | + { |
572 | + g_warning ("Cannot show window, no shell"); |
573 | + return; |
574 | + } |
575 | +} |
576 | + |
577 | + |
578 | |
579 | === removed file 'src/mail-server.c' |
580 | --- src/mail-server.c 2009-03-15 11:21:09 +0000 |
581 | +++ src/mail-server.c 1970-01-01 00:00:00 +0000 |
582 | @@ -1,352 +0,0 @@ |
583 | -/* |
584 | - * Copyright (C) 2009 Canonical Ltd |
585 | - * |
586 | - * This program is free software: you can redistribute it and/or modify |
587 | - * it under the terms of the GNU General Public License version 3 as |
588 | - * published by the Free Software Foundation. |
589 | - * |
590 | - * This program is distributed in the hope that it will be useful, |
591 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
592 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
593 | - * GNU General Public License for more details. |
594 | - * |
595 | - * You should have received a copy of the GNU General Public License |
596 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
597 | - * |
598 | - * Authored by Neil Jagdish Patel <neil.patel@canonical.com> |
599 | - * |
600 | - */ |
601 | - |
602 | -#include "mail-server.h" |
603 | - |
604 | -G_DEFINE_TYPE (MailServer, mail_server, INDICATE_TYPE_SERVER); |
605 | - |
606 | -#define MAIL_SERVER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ |
607 | - MAIL_TYPE_SERVER, \ |
608 | - MailServerPrivate)) |
609 | - |
610 | -struct _MailServerPrivate |
611 | -{ |
612 | - EShell *shell; |
613 | - guint count; |
614 | -}; |
615 | - |
616 | -enum |
617 | -{ |
618 | - PROP_0, |
619 | - |
620 | - PROP_COUNT |
621 | -}; |
622 | - |
623 | -/* Forwards */ |
624 | -static gboolean mail_server_get_indicator_count (IndicateServer *server, |
625 | - guint *count, |
626 | - GError **error); |
627 | -static gboolean mail_server_get_indicator_property (IndicateServer *server, |
628 | - guint id, |
629 | - gchar *type, |
630 | - gchar **value, |
631 | - GError **error); |
632 | - |
633 | -static gboolean mail_server_show_indicator_to_user (IndicateServer *server, |
634 | - guint id, |
635 | - GError **error); |
636 | - |
637 | -static void really_present_window (GtkWindow *window); |
638 | - |
639 | -/* GObject stuff */ |
640 | -static void |
641 | -mail_server_get_property (GObject *object, |
642 | - guint prop_id, |
643 | - GValue *value, |
644 | - GParamSpec *pspec) |
645 | -{ |
646 | - MailServer *server = MAIL_SERVER (object); |
647 | - |
648 | - switch (prop_id) |
649 | - { |
650 | - case PROP_COUNT: |
651 | - g_value_set_uint (value, server->priv->count); |
652 | - break; |
653 | - |
654 | - default: |
655 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
656 | - } |
657 | -} |
658 | - |
659 | -static void |
660 | -mail_server_set_property (GObject *object, |
661 | - guint prop_id, |
662 | - const GValue *value, |
663 | - GParamSpec *pspec) |
664 | -{ |
665 | - MailServer *server = MAIL_SERVER (object); |
666 | - |
667 | - switch (prop_id) |
668 | - { |
669 | - case PROP_COUNT: |
670 | - mail_server_set_message_count (server, g_value_get_uint (value)); |
671 | - break; |
672 | - |
673 | - default: |
674 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
675 | - } |
676 | -} |
677 | - |
678 | - |
679 | -static void |
680 | -mail_server_finalize (GObject *obj) |
681 | -{ |
682 | - MailServer *server = MAIL_SERVER (obj); |
683 | - MailServerPrivate *priv; |
684 | - |
685 | - g_return_if_fail (MAIL_IS_SERVER (server)); |
686 | - priv = server->priv; |
687 | - |
688 | - G_OBJECT_CLASS (mail_server_parent_class)->finalize (obj); |
689 | -} |
690 | - |
691 | -static void |
692 | -mail_server_class_init (MailServerClass *klass) |
693 | -{ |
694 | - GParamSpec *pspec; |
695 | - GObjectClass *obj_class = G_OBJECT_CLASS (klass); |
696 | - IndicateServerClass * ind_class = INDICATE_SERVER_CLASS (klass); |
697 | - |
698 | - obj_class->finalize = mail_server_finalize; |
699 | - obj_class->set_property = mail_server_set_property; |
700 | - obj_class->get_property = mail_server_get_property; |
701 | - |
702 | - ind_class->get_indicator_count = mail_server_get_indicator_count; |
703 | - ind_class->get_indicator_property = mail_server_get_indicator_property; |
704 | - ind_class->show_indicator_to_user = mail_server_show_indicator_to_user; |
705 | - |
706 | - /* Property */ |
707 | - pspec = g_param_spec_uint ("count", |
708 | - "count", |
709 | - "count", |
710 | - 0, G_MAXUINT, 0, |
711 | - G_PARAM_READWRITE); |
712 | - g_object_class_install_property (obj_class, PROP_COUNT, pspec); |
713 | - |
714 | - g_type_class_add_private (obj_class, sizeof (MailServerPrivate)); |
715 | -} |
716 | - |
717 | -static void |
718 | -mail_server_init (MailServer *server) |
719 | -{ |
720 | - MailServerPrivate *priv; |
721 | - |
722 | - priv = server->priv = MAIL_SERVER_GET_PRIVATE (server); |
723 | - |
724 | - indicate_server_set_desktop_file(INDICATE_SERVER(server), "/usr/share/applications/evolution-mail.desktop"); |
725 | - indicate_server_set_type(INDICATE_SERVER(server), "message.mail"); |
726 | -} |
727 | - |
728 | -/* |
729 | - * Public Functions |
730 | - */ |
731 | - |
732 | -MailServer * |
733 | -mail_server_get_default (void) |
734 | -{ |
735 | - static MailServer *server = NULL; |
736 | - |
737 | - if (!server) |
738 | - server = g_object_new (MAIL_TYPE_SERVER, |
739 | - NULL); |
740 | - return server; |
741 | -} |
742 | - |
743 | -guint |
744 | -mail_server_get_message_count (MailServer *server) |
745 | -{ |
746 | - g_return_val_if_fail (MAIL_IS_SERVER (server), 0); |
747 | - |
748 | - return server->priv->count; |
749 | -} |
750 | - |
751 | -void |
752 | -mail_server_set_message_count (MailServer *server, |
753 | - guint count) |
754 | -{ |
755 | - MailServerPrivate *priv; |
756 | - gint i, diff; |
757 | - gboolean added = TRUE; |
758 | - |
759 | - g_return_if_fail (MAIL_IS_SERVER (server)); |
760 | - priv = server->priv; |
761 | - |
762 | - g_debug ("MAIL SERVER: Count changed: %d", count); |
763 | - |
764 | - if (priv->count >= count) |
765 | - { |
766 | - added = FALSE; |
767 | - diff = priv->count - count; |
768 | - } |
769 | - else |
770 | - { |
771 | - diff = count - priv->count; |
772 | - } |
773 | - |
774 | - server->priv->count = count; |
775 | - |
776 | - for (i = 0; i < diff; i++) |
777 | - added ? indicate_server_emit_indicator_added (INDICATE_SERVER (server), |
778 | - i + 1, "message") |
779 | - : indicate_server_emit_indicator_removed (INDICATE_SERVER (server), |
780 | - diff - i, "message"); |
781 | -} |
782 | - |
783 | -/* |
784 | - * Indicate Server overrides |
785 | - */ |
786 | -static gboolean |
787 | -mail_server_get_indicator_count (IndicateServer *server, |
788 | - guint *count, |
789 | - GError **error) |
790 | -{ |
791 | - g_return_val_if_fail (MAIL_IS_SERVER (server), FALSE); |
792 | - |
793 | - *count = MAIL_SERVER (server)->priv->count; |
794 | - return TRUE; |
795 | -} |
796 | - |
797 | -static gboolean |
798 | -mail_server_get_indicator_property (IndicateServer *server, |
799 | - guint id, |
800 | - gchar *type, |
801 | - gchar **value, |
802 | - GError **error) |
803 | -{ |
804 | - g_return_val_if_fail (MAIL_IS_SERVER (server), FALSE); |
805 | - |
806 | - if (g_strcmp0 (type, "subtype") == 0) |
807 | - { |
808 | - *value = g_strdup ("email"); |
809 | - return TRUE; |
810 | - } |
811 | - |
812 | - if (g_strcmp0 (type, "desktop") == 0) |
813 | - { |
814 | - /* We should probably do something clever here */ |
815 | - *value = g_strdup ("/usr/share/applications/evolution-mail.desktop"); |
816 | - return TRUE; |
817 | - } |
818 | - |
819 | - g_warning ("Mail Server does not support the \"%s\" property", type); |
820 | - |
821 | - return FALSE; |
822 | -} |
823 | - |
824 | -static gboolean |
825 | -mail_server_show_indicator_to_user (IndicateServer *server, |
826 | - guint id, |
827 | - GError **error) |
828 | -{ |
829 | -#define MAIL_ICON "evolution-mail" |
830 | - MailServerPrivate *priv; |
831 | - |
832 | - g_return_val_if_fail (MAIL_IS_SERVER (server), FALSE); |
833 | - priv = MAIL_SERVER (server)->priv; |
834 | - |
835 | - g_debug ("MAIL SERVER: Show Evolution to user"); |
836 | - |
837 | - if (priv->shell) |
838 | - { |
839 | - GList *w; |
840 | - GtkWindow *mail_window = NULL; |
841 | - |
842 | - for (w = priv->shell->priv->windows; w; w = w->next) |
843 | - { |
844 | - GtkWindow *window = w->data; |
845 | - |
846 | - if (GTK_IS_WINDOW (window)) |
847 | - { |
848 | - if (g_strcmp0 (MAIL_ICON, gtk_window_get_icon_name (window)) == 0) |
849 | - { |
850 | - mail_window = window; |
851 | - } |
852 | - } |
853 | - else |
854 | - { |
855 | - g_warning ("No open windows: Wait, we're not a mac :-/"); |
856 | - return FALSE; |
857 | - } |
858 | - } |
859 | - |
860 | - if (!GTK_IS_WINDOW (mail_window)) |
861 | - { |
862 | - if (priv->shell->priv->windows && priv->shell->priv->windows->data) |
863 | - mail_window = priv->shell->priv->windows->data; |
864 | - else |
865 | - return FALSE; |
866 | - } |
867 | - |
868 | - really_present_window (mail_window); |
869 | - mail_server_set_message_count (MAIL_SERVER (server), 0); |
870 | - } |
871 | - else |
872 | - { |
873 | - g_warning ("Cannot show window, no shell"); |
874 | - return FALSE; |
875 | - } |
876 | - |
877 | - return TRUE; |
878 | -} |
879 | - |
880 | -void |
881 | -mail_server_set_e_shell (MailServer *server, |
882 | - EShell *shell) |
883 | -{ |
884 | - g_return_if_fail (MAIL_IS_SERVER (server)); |
885 | - |
886 | - server->priv->shell = shell; |
887 | -} |
888 | - |
889 | - |
890 | -/* |
891 | - * Taken from libtomboy, (C) 2008 Novell, LGPL v2 or later |
892 | - */ |
893 | - |
894 | -static void |
895 | -tomboy_window_override_user_time (GtkWindow *window) |
896 | -{ |
897 | - guint32 ev_time = gtk_get_current_event_time(); |
898 | - |
899 | - if (ev_time == 0) { |
900 | - /* |
901 | - * FIXME: Global keypresses use an event filter on the root |
902 | - * window, which processes events before GDK sees them. |
903 | - */ |
904 | - //ev_time = tomboy_keybinder_get_current_event_time (); |
905 | - ev_time = GDK_CURRENT_TIME; |
906 | - } |
907 | - if (ev_time == 0) { |
908 | - gint ev_mask = gtk_widget_get_events (GTK_WIDGET(window)); |
909 | - if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) { |
910 | - gtk_widget_add_events (GTK_WIDGET (window), |
911 | - GDK_PROPERTY_CHANGE_MASK); |
912 | - } |
913 | - |
914 | - /* |
915 | - * NOTE: Last resort for D-BUS or other non-interactive |
916 | - * openings. Causes roundtrip to server. Lame. |
917 | - */ |
918 | - ev_time = gdk_x11_get_server_time (GTK_WIDGET(window)->window); |
919 | - } |
920 | - |
921 | - gdk_x11_window_set_user_time (GTK_WIDGET(window)->window, ev_time); |
922 | -} |
923 | - |
924 | -static void |
925 | -really_present_window (GtkWindow *window) |
926 | -{ |
927 | - if (!GTK_WIDGET_REALIZED (window)) |
928 | - gtk_widget_realize (GTK_WIDGET (window)); |
929 | - |
930 | - tomboy_window_override_user_time (window); |
931 | - |
932 | - gtk_window_present (window); |
933 | -} |
934 | - |
935 | |
936 | === removed file 'src/mail-server.h' |
937 | --- src/mail-server.h 2009-02-04 10:45:24 +0000 |
938 | +++ src/mail-server.h 1970-01-01 00:00:00 +0000 |
939 | @@ -1,72 +0,0 @@ |
940 | -/* |
941 | - * Copyright (C) 2009 Canonical Ltd |
942 | - * |
943 | - * This program is free software: you can redistribute it and/or modify |
944 | - * it under the terms of the GNU General Public License version 3 as |
945 | - * published by the Free Software Foundation. |
946 | - * |
947 | - * This program is distributed in the hope that it will be useful, |
948 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
949 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
950 | - * GNU General Public License for more details. |
951 | - * |
952 | - * You should have received a copy of the GNU General Public License |
953 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
954 | - * |
955 | - * Authored by Neil Jagdish Patel <neil.patel@canonical.com> |
956 | - * |
957 | - */ |
958 | - |
959 | -#ifndef _MAIL_SERVER_H_ |
960 | -#define _MAIL_SERVER_H_ |
961 | - |
962 | -#include <glib.h> |
963 | -#include <glib-object.h> |
964 | -#include <libindicate/server.h> |
965 | - |
966 | -#include "e-shell.h" |
967 | - |
968 | -#define MAIL_TYPE_SERVER (mail_server_get_type ()) |
969 | - |
970 | -#define MAIL_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ |
971 | - MAIL_TYPE_SERVER, MailServer)) |
972 | - |
973 | -#define MAIL_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ |
974 | - MAIL_TYPE_SERVER, MailServerClass)) |
975 | - |
976 | -#define MAIL_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ |
977 | - MAIL_TYPE_SERVER)) |
978 | - |
979 | -#define MAIL_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ |
980 | - MAIL_TYPE_SERVER)) |
981 | - |
982 | -#define MAIL_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\ |
983 | - MAIL_TYPE_SERVER, MailServerClass)) |
984 | - |
985 | -typedef struct _MailServer MailServer; |
986 | -typedef struct _MailServerClass MailServerClass; |
987 | -typedef struct _MailServerPrivate MailServerPrivate; |
988 | - |
989 | -struct _MailServer |
990 | -{ |
991 | - IndicateServer parent; |
992 | - |
993 | - MailServerPrivate *priv; |
994 | -}; |
995 | - |
996 | -struct _MailServerClass |
997 | -{ |
998 | - IndicateServerClass parent_class; |
999 | -}; |
1000 | - |
1001 | -GType mail_server_get_type (void) G_GNUC_CONST; |
1002 | - |
1003 | -MailServer * mail_server_get_default (void); |
1004 | - |
1005 | -guint mail_server_get_message_count (MailServer *server); |
1006 | -void mail_server_set_message_count (MailServer *server, |
1007 | - guint count); |
1008 | -void mail_server_set_e_shell (MailServer *server, |
1009 | - EShell *shell); |
1010 | - |
1011 | -#endif /* _MAIL_SERVER_H_ */ |
So, this branch adds support for the latest indicator API. It
- Removes the old "mail-server" object
- Creates a simple server using ref_default ()
- Creates 1 indicator per account, using the user-defined name
- Changes the way we set the unread count by changing it per account
- Cleans them all out when evolution sends the 'read' signal
- Shows the evolution window when the user clicks on the server or indicators (still working on how to show the individual accounts when they click on them).
They'll be other bits and pieces, but I've been testing for a bit and it seems to work fine with ~4 accounts.