Merge lp:~larsu/evolution-indicator/messaging-menu-fixes into lp:evolution-indicator

Proposed by Lars Karlitski
Status: Superseded
Proposed branch: lp:~larsu/evolution-indicator/messaging-menu-fixes
Merge into: lp:evolution-indicator
Diff against target: 993 lines (+172/-550)
3 files modified
configure.ac (+1/-1)
src/evolution-indicator.c (+169/-548)
src/org-freedesktop-evolution-indicator.eplug.xml (+2/-1)
To merge this branch: bzr merge lp:~larsu/evolution-indicator/messaging-menu-fixes
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
Review via email: mp+153957@code.launchpad.net

This proposal has been superseded by a proposal from 2013-03-21.

Description of the change

A couple of minor fixes to lp:~twolife/evolution-indicator/eds-3.6_messaging-menu that I found while testing.

To post a comment you must log in.
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Seems to me like this would be a perpetuating a regression that we have since evo switched to a source registry: accounts won't be updated when added/removed or changed.

Consider adding the necesary code to watch the source registry signals described at https://developer.gnome.org/libedataserver/stable/ESourceRegistry.html#ESourceRegistry.signals in place of your TODO at line 688.

Otherwise, looks good :) Since the code itself looks fine and we already have the above regression, I'm approving the merge.

review: Approve
93. By Lars Karlitski

update_accounts: fix indentation and use consistent code style

94. By Lars Karlitski

update_accounts: recreate accounts list from scratch

This function is only ever called when the global 'accounts' list is NULL,
there's no need to check for existing accounts.

95. By Lars Karlitski

update_accounts: move name and url fetching into separate function

Also removes some unnecessary string allocations and a memory leak.

96. By Lars Karlitski

update_accounts: fix memory leak

97. By Lars Karlitski

Use evolution's uids instead of self-assembled urls as message source identifiers

This simplifies the code and fixes a bug: all POP accounts got the url "pop:",
making them show up as the same entry in the messaging menu.

98. By Lars Karlitski

Remove n_accounts global variable

It gets in the way of the next patch.

99. By Lars Karlitski

Update the list of accounts on-the-fly

We don't need any information about sources until new messages arrive. Create
the account objects then, instead of listening to "source-added" and
"source-removed" signals.

100. By Lars Karlitski

Use GMutex instead of the deprecated GStaticMutex

101. By Lars Karlitski

e_plugin_get_configure_widget: return NULL instead of an empty widget

To get rid of warnings about deprecated gtk functions.

102. By Lars Karlitski

Declare update_unity_launcher_count before first use

103. By Lars Karlitski

Use new-style GtkBox constructors

Unmerged revisions

103. By Lars Karlitski

Use new-style GtkBox constructors

102. By Lars Karlitski

Declare update_unity_launcher_count before first use

101. By Lars Karlitski

e_plugin_get_configure_widget: return NULL instead of an empty widget

To get rid of warnings about deprecated gtk functions.

100. By Lars Karlitski

Use GMutex instead of the deprecated GStaticMutex

99. By Lars Karlitski

Update the list of accounts on-the-fly

We don't need any information about sources until new messages arrive. Create
the account objects then, instead of listening to "source-added" and
"source-removed" signals.

98. By Lars Karlitski

Remove n_accounts global variable

It gets in the way of the next patch.

97. By Lars Karlitski

Use evolution's uids instead of self-assembled urls as message source identifiers

This simplifies the code and fixes a bug: all POP accounts got the url "pop:",
making them show up as the same entry in the messaging menu.

96. By Lars Karlitski

update_accounts: fix memory leak

95. By Lars Karlitski

update_accounts: move name and url fetching into separate function

Also removes some unnecessary string allocations and a memory leak.

94. By Lars Karlitski

update_accounts: recreate accounts list from scratch

This function is only ever called when the global 'accounts' list is NULL,
there's no need to check for existing accounts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2012-05-25 21:05:11 +0000
+++ configure.ac 2013-03-21 23:26:20 +0000
@@ -70,7 +70,6 @@
70AC_SUBST(GCC_FLAGS)70AC_SUBST(GCC_FLAGS)
7171
72PKG_CHECK_MODULES(DEPS,72PKG_CHECK_MODULES(DEPS,
73 indicate-0.7 >= 0.6.90
74 $EVOLUTION_PLUGIN73 $EVOLUTION_PLUGIN
75 dbus-174 dbus-1
76 dbus-glib-175 dbus-glib-1
@@ -81,6 +80,7 @@
81 libebackend-1.280 libebackend-1.2
82 libsoup-2.481 libsoup-2.4
83 gconf-2.082 gconf-2.0
83 messaging-menu
84 )84 )
85AC_SUBST(DEPS_CFLAGS)85AC_SUBST(DEPS_CFLAGS)
86AC_SUBST(DEPS_LIBS)86AC_SUBST(DEPS_LIBS)
8787
=== modified file 'src/evolution-indicator.c'
--- src/evolution-indicator.c 2012-05-25 21:05:11 +0000
+++ src/evolution-indicator.c 2013-03-21 23:26:20 +0000
@@ -28,6 +28,7 @@
28#include <glib/gprintf.h>28#include <glib/gprintf.h>
2929
30#include <gconf/gconf.h>30#include <gconf/gconf.h>
31#include <gconf/gconf-client.h>
3132
32#include <canberra.h>33#include <canberra.h>
33#include <libnotify/notify.h>34#include <libnotify/notify.h>
@@ -44,9 +45,7 @@
4445
45#include <camel/camel.h>46#include <camel/camel.h>
4647
47#include <libindicate/server.h>48#include <messaging-menu.h>
48#include <libindicate/indicator.h>
49#include <libindicate/indicator-messages.h>
5049
51#include <unity.h>50#include <unity.h>
5251
@@ -58,22 +57,15 @@
58#define SHOW_BUBBLE CONF_DIR"/show_bubble"57#define SHOW_BUBBLE CONF_DIR"/show_bubble"
59#define SHOW_NEW_IN_PANEL CONF_DIR"/show_new_messages_in_panel"58#define SHOW_NEW_IN_PANEL CONF_DIR"/show_new_messages_in_panel"
6059
61#define ACCOUNT_DIR "/apps/evolution/mail"
62#define ACCOUNTS ACCOUNT_DIR"/accounts"
63
64#define EVOLUTION_DESKTOP_FILE "/usr/share/applications/evolution.desktop"60#define EVOLUTION_DESKTOP_FILE "/usr/share/applications/evolution.desktop"
6561
66#define UNREAD_DATA "unread"62#define UNREAD_DATA "unread"
6763
68#define USER_BLACKLIST_DIR "indicators/messages/applications-blacklist"64static GMutex mlock;
69#define USER_BLACKLIST_FILENAME "evolution"
70
71static GStaticMutex mlock = G_STATIC_MUTEX_INIT;
72static GConfClient *client = NULL;65static GConfClient *client = NULL;
7366
74static IndicateServer *server = NULL;67static MessagingMenuApp *mmapp = NULL;
75static GSList *indicators = NULL;68static GSList *accounts = NULL;
76static gint n_accounts = 0;
7769
78static UnityLauncherEntry *launcher = NULL;70static UnityLauncherEntry *launcher = NULL;
7971
@@ -91,50 +83,25 @@
91static guint play_sound_id = 0;83static guint play_sound_id = 0;
92static guint show_bubble_id = 0;84static guint show_bubble_id = 0;
93static guint show_count_id = 0;85static guint show_count_id = 0;
94static guint accounts_id = 0;
9586
96static gint message_count = 0;87static gint message_count = 0;
9788
98void org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t);89void org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t);
99void org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t);90void org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t);
91void update_unity_launcher_count ();
10092
101int e_plugin_lib_enable (EPlugin *ep, int enable);93int e_plugin_lib_enable (EPlugin *ep, int enable);
102GtkWidget * e_plugin_lib_get_configure_widget (EPlugin *ep);94GtkWidget * e_plugin_lib_get_configure_widget (EPlugin *ep);
10395
104static void show_evolution (gpointer arg0, guint timestamp, gpointer arg1);96static void show_evolution (MessagingMenuApp *mmapp, const gchar *uid, gpointer user_data);
105
106static void show_evolution_in_indicator_applet (void);
107static void hide_evolution_in_indicator_applet (void);
10897
109typedef struct {98typedef struct {
110 gchar *url;99 gchar *name;
111 gchar *name;100 gchar *uid;
112 gchar *parent;101 gint n_count;
113 gchar *last_parent;102} MessagingMailAccount;
114103MessagingMailAccount * find_account_for_uid(GSList*, const gchar*);
115 gint reap_type;104static MessagingMailAccount * ensure_account_for_uid(const gchar*);
116
117 gboolean enabled;
118
119} ParserData;
120
121enum {
122 REAP_NONE = 0,
123 REAP_URL,
124 REAP_NAME
125};
126
127static GtkWidget *
128get_cfg_widget (void)
129{
130 GtkWidget *vbox;
131
132 vbox = gtk_vbox_new (FALSE, 6);
133
134 gtk_widget_show (vbox);
135
136 return vbox;
137}
138105
139static gboolean106static gboolean
140evolution_is_focused (void)107evolution_is_focused (void)
@@ -195,95 +162,57 @@
195 return FALSE;162 return FALSE;
196}163}
197164
198static gint
199get_indicator_unread_count (IndicateIndicator *indicator)
200{
201 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (indicator),
202 UNREAD_DATA));
203}
204
205static void
206set_indicator_unread_count (IndicateIndicator *indicator, gint count)
207{
208 gchar *count_str;
209
210 count_str = g_strdup_printf ("%d", count);
211 indicate_indicator_set_property (indicator,
212 INDICATE_INDICATOR_MESSAGES_PROP_COUNT,
213 count_str);
214 g_object_set_data (G_OBJECT (indicator),
215 UNREAD_DATA,
216 GINT_TO_POINTER (count));
217
218 g_free (count_str);
219}
220
221void165void
222org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t)166org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t)
223{167{
224 gchar *url;168 MessagingMailAccount *account;
225 CamelURL *service_url;169 const gchar *uid;
226170
227 g_return_if_fail (t != NULL);171 g_return_if_fail (t != NULL);
228172
229 service_url = camel_service_new_camel_url (CAMEL_SERVICE (t->store));173 uid = camel_service_get_uid (CAMEL_SERVICE (t->store));
230 url = camel_url_to_string (service_url, 0);
231 camel_url_free (service_url);
232174
233 if (!t->new)175 if (!t->new)
234 return;176 return;
235177
236 if (only_inbox && !(t->is_inbox))178 if (only_inbox && !(t->is_inbox))
237 {179 {
238 g_debug ("EI: %s is not an inbox", url);180 g_debug ("EI: %s is not an inbox", t->folder_name);
239 return;181 return;
240 }182 }
241183
242 if (evolution_is_focused ())184 if (evolution_is_focused ())
243{185 {
244 g_debug ("EI: Evolution is focused");186 g_debug ("EI: Evolution is focused");
245 return;187 return;
246 }188 }
247189
248 g_static_mutex_lock (&mlock);190 g_mutex_lock (&mlock);
249191
250 g_debug ("EI:mail_new_notify: %s", url);192 g_debug ("EI:mail_new_notify: %s/%s", uid, t->folder_name);
251193
252 message_count += t->new;194 account = ensure_account_for_uid (uid);
253 195 if(account) {
254 if (show_count)196 account->n_count += t->new;
255 {197 message_count += t->new;
256 IndicateIndicator *indicator = NULL;198
257 GSList *i;199 if (show_count)
258200 {
259 for (i = indicators; i; i = i->next)201 if (messaging_menu_app_has_source(MESSAGING_MENU_APP (mmapp), uid))
260 {
261 IndicateIndicator *indi = i->data;
262
263 if (g_strstr_len (url,
264 -1,
265 indicate_indicator_get_property (indi, "url")))
266 {202 {
267 indicator = indi;203 messaging_menu_app_set_source_count (MESSAGING_MENU_APP (mmapp), uid, account->n_count);
268 break;204 }
269 }205 else {
270 }206 gchar *name = account->name;
271 if (indicator)207 messaging_menu_app_append_source_with_count (MESSAGING_MENU_APP (mmapp), uid, NULL, name, account->n_count);
272 {208 }
273 gint count;209 messaging_menu_app_draw_attention (MESSAGING_MENU_APP (mmapp), uid);
274 210 }
275 count = get_indicator_unread_count (indicator);
276 set_indicator_unread_count (indicator, count + t->new);
277211
278 indicate_indicator_set_property (indicator,212 }
279 INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,213 else {
280 "true");214 g_warning ("EI: Unable to find account that matches %s", uid);
281 }215 }
282 else
283 {
284 g_warning ("EI: Unable to find account that matches %s", url);
285 }
286 }
287216
288 update_unity_launcher_count ();217 update_unity_launcher_count ();
289218
@@ -340,59 +269,47 @@
340 g_warning ("EI: Unable to play sound: %s\n", ca_strerror (ret));269 g_warning ("EI: Unable to play sound: %s\n", ca_strerror (ret));
341 }270 }
342271
343 g_static_mutex_unlock (&mlock);272 g_mutex_unlock (&mlock);
344}273}
345274
346void275void
347org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t)276org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t)
348{277{
278 MessagingMailAccount *account;
279 const gchar *uid;
280
349 g_return_if_fail (t != NULL);281 g_return_if_fail (t != NULL);
350282
351 GSList *i;283 uid = camel_service_get_uid (CAMEL_SERVICE (camel_folder_get_parent_store (t->folder)));
352284
353 g_static_mutex_lock (&mlock);285 g_mutex_lock (&mlock);
354286
355 g_debug ("EI: mail_read_notify");287 g_debug ("EI: mail_read_notify");
356288
357 for (i = indicators; i; i = i->next)289 account = ensure_account_for_uid (uid);
358 {290 if(account)
359 IndicateIndicator *indicator = i->data;291 {
360292 messaging_menu_app_remove_source (MESSAGING_MENU_APP (mmapp), uid);
361 set_indicator_unread_count (indicator, 0);293 message_count -= account->n_count;
362 indicate_indicator_set_property (indicator,294 account->n_count = 0;
363 INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,295 g_debug ("EI: Setting %s to 0 unread messages", uid);
364 "false");296 }
365297 else {
366 g_debug ("EI: Setting %s to 0 unread messages",298 g_warning ("EI: Unable to find account that matches %s", uid);
367 indicate_indicator_get_property (indicator, "name"));299 }
368
369 }
370 message_count = 0;
371300
372 update_unity_launcher_count ();301 update_unity_launcher_count ();
373302
374 g_static_mutex_unlock (&mlock);303 g_mutex_unlock (&mlock);
375}304}
376305
377void306void
378update_unity_launcher_count ()307update_unity_launcher_count ()
379{308{
380 GSList *i;
381 int count = 0;
382
383 g_debug ("EI: update_unity_launcher_count");309 g_debug ("EI: update_unity_launcher_count");
384310
385 for (i = indicators; i; i = i->next)311 unity_launcher_entry_set_count (launcher, message_count);
386 {312 if (message_count > 0)
387 IndicateIndicator *indicator = i->data;
388
389 count = count + get_indicator_unread_count (indicator);
390
391 g_debug ("EI: Setting count to %d unread messages", count);
392
393 }
394 unity_launcher_entry_set_count (launcher, count);
395 if (count > 0)
396 {313 {
397 unity_launcher_entry_set_count_visible (launcher, TRUE);314 unity_launcher_entry_set_count_visible (launcher, TRUE);
398 } else {315 } else {
@@ -444,17 +361,11 @@
444 value = entry->value;361 value = entry->value;
445362
446 show_count = gconf_value_get_bool (value);363 show_count = gconf_value_get_bool (value);
447 364
448 if (show_count)365 if (show_count)
449 {366 messaging_menu_app_register (mmapp);
450 indicate_server_show (server);
451 show_evolution_in_indicator_applet ();
452 }
453 else367 else
454 {368 messaging_menu_app_unregister (mmapp);
455 indicate_server_hide (server);
456 hide_evolution_in_indicator_applet ();
457 }
458369
459 g_debug ("EI: Messages in panel %s", 370 g_debug ("EI: Messages in panel %s",
460 show_count ? "true" : "false");371 show_count ? "true" : "false");
@@ -475,246 +386,103 @@
475 g_debug ("EI: Show Bubbles %s", show_bubble ? "true" : "false");386 g_debug ("EI: Show Bubbles %s", show_bubble ? "true" : "false");
476}387}
477388
478static IndicateIndicator *389MessagingMailAccount *
479find_indicator_for_url (GSList *indicator_list, const gchar *url)390find_account_for_uid (GSList *accounts_list, const gchar *uid)
480{391{
481 GSList *i;392 GSList *i;
482393
483 for (i = indicator_list; i; i = i->next)394 for (i = accounts_list; i; i = i->next)
484 {395 {
485 IndicateIndicator *indicator = i->data;396 MessagingMailAccount *a = i->data;
486397
487 if (g_strcmp0 (indicate_indicator_get_property (indicator, "url"), url)398 if (g_strcmp0 (a->uid, uid)
488 == 0)399 == 0)
489 return indicator;400 return a;
490 }401 }
491 return NULL;402 return NULL;
492}403}
493404
494static IndicateIndicator *405void
495create_indicator (const gchar *url, const gchar *name)406unref_account(MessagingMailAccount *m)
496{407{
497 IndicateIndicator *indicator;408 g_free(m->name);
498409 g_free(m->uid);
499 indicator = indicate_indicator_new ();410 g_free(m);
500 indicate_indicator_set_property (indicator,
501 INDICATE_INDICATOR_MESSAGES_PROP_NAME,
502 name);
503 indicate_indicator_set_property (indicator,
504 "url",
505 url);
506 set_indicator_unread_count (indicator, 0);
507 indicate_indicator_show (indicator);
508
509 /* FIXME: I need to find a way to show a mailbox individually */
510 g_signal_connect (indicator, "user-display",
511 G_CALLBACK (show_evolution), NULL);
512
513 g_debug ("EI: New Indicator: %s %s", name, url);
514
515 return indicator;
516}411}
517412
518static void413static ESource *
519start_element_handler (GMarkupParseContext *context,414mail_source_from_uid (const gchar *uid)
520 const gchar *element_name,
521 const gchar **attribute_names,
522 const gchar **attribute_values,
523 gpointer user_data,
524 GError **error)
525{415{
526 ParserData *data = (ParserData *)user_data;416 ESourceRegistry *registry;
527417 GError *error = NULL;
528 if (g_strcmp0 (element_name, "account") == 0)418 GList *sources;
529 {419 GList *it;
530 gint i = 0;420 ESource *source = NULL;
531421
532 while (attribute_names[i] != NULL)422 registry = e_source_registry_new_sync (NULL, &error);
423 if (!registry)
424 {
425 g_warning ("Failed to get access to source registry: %s\n", error->message);
426 g_error_free (error);
427 return NULL;
428 }
429
430 sources = e_source_registry_list_sources (registry, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
431 for (it = sources; it; it = it->next)
432 {
433 if (g_str_equal (uid, e_source_get_uid (it->data)))
533 {434 {
534 if (g_strcmp0 (attribute_names[i], "name") == 0)435 source = g_object_ref (it->data);
535 {436 break;
536 data->name = g_strdup (attribute_values[i]);
537 }
538 else if (g_strcmp0 (attribute_names[i], "enabled") == 0)
539 {
540 if (g_strcmp0 (attribute_values[i], "false") == 0)
541 data->enabled = FALSE;
542 }
543 i++;
544 }437 }
545 }438 }
546 else if (g_strcmp0 (element_name, "url") == 0)439
547 data->reap_type = REAP_URL;440 g_list_free_full (sources, g_object_unref);
548 else441 g_object_unref (registry);
549 data->reap_type = REAP_NONE;442 return source;
550443}
551 if (data->last_parent)444
552 g_free (data->last_parent);445static MessagingMailAccount *
553 446ensure_account_for_uid (const gchar *uid)
554 data->last_parent = data->parent;447{
555 data->parent = g_strdup (element_name);448 MessagingMailAccount *account;
556}449 ESource *source;
557450
558static void451 if ((account = find_account_for_uid (accounts, uid)))
559text_handler (GMarkupParseContext *context,452 return account;
560 const gchar *text,453
561 gsize text_len,454 if ((source = mail_source_from_uid (uid)))
562 gpointer user_data,455 {
563 GError **error)456 if (e_source_get_removable(source) && e_source_get_enabled(source))
564{
565 ParserData *data = (ParserData *)user_data;
566
567 if (!data->url
568 && data->reap_type == REAP_URL
569 && g_strcmp0(data->last_parent, "source") == 0)
570 {
571 gchar **tokens;
572
573 tokens = g_strsplit (text, ";", 2);
574
575 data->url = g_strdup (tokens[0]);
576
577 /* Accounts with no configured way to receive mail will not have a URL */
578 if (!data->url)
579 data->enabled = FALSE;
580
581 g_strfreev (tokens);
582 }
583}
584
585static void
586update_accounts (void)
587{
588 GSList *accounts;
589 GError *error = NULL;
590 gint i = 1;
591 GTimeVal timeval = { 0 };
592
593 g_get_current_time (&timeval);
594 accounts = gconf_client_get_list (client,
595 ACCOUNTS,
596 GCONF_VALUE_STRING,
597 &error);
598 if (accounts == NULL || error)
599 {
600 g_warning ("EI: Unable to determine number of accounts, "
601 "defaulting to '1' (%s)",
602 error ? error->message : "unknown");
603 if (error)
604 g_error_free (error);
605
606 /* We could have this as 0 too, as it won't effect anything. It just
607 * seems to make more sense to have it default at 1
608 */
609 n_accounts = 1;
610 }
611 else
612 {
613 GSList *old_list;
614 GSList *a;
615 static GMarkupParser parser = {
616 start_element_handler,
617 NULL,
618 text_handler,
619 NULL,
620 NULL
621 };
622
623 old_list = indicators;
624 indicators = NULL;
625
626 for (a = accounts; a; a = a->next)
627 {457 {
628 gchar *account_info = a->data;458 ESourceExtension *extension;
629 GMarkupParseContext *context;459 const gchar *protocol;
630 ParserData data = { NULL, NULL, NULL, NULL, 0, TRUE };460
631 IndicateIndicator *indicator;461 extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
632 462 protocol = e_source_backend_get_backend_name (E_SOURCE_BACKEND (extension));
633 /* Parse account XML to get some useful details about the account */463
634 context = g_markup_parse_context_new (&parser, 0, &data, NULL);464 account = g_new(MessagingMailAccount, 1);
635 g_markup_parse_context_parse (context,465 account->uid = g_strdup (uid);
636 account_info,466 account->n_count = 0;
637 strlen (account_info),467
638 NULL);468 if (g_str_has_prefix (protocol, "pop"))
639469 account->name = g_strdup (g_dgettext (EVO_I18N_DOMAIN, "Inbox"));
640 /* Check to see account already exists and, if not, create it */
641 indicator = find_indicator_for_url (indicators, data.url);
642 if (indicator)
643 {
644 old_list = g_slist_remove (old_list, indicator);
645 indicators = g_slist_append (indicators, indicator);
646 }
647 else470 else
648 {471 account->name = e_source_dup_display_name (source);
649 if (data.url && g_str_has_prefix (data.url, "pop:"))472
650 {473 accounts = g_slist_append (accounts, account);
651 indicator = create_indicator ("pop:",474 g_debug ("EI: New account: %s (%s)", account->name, account->uid);
652 g_dgettext (EVO_I18N_DOMAIN,
653 "Inbox"));
654 }
655 else
656 {
657 indicator = create_indicator (data.url, data.name);
658 }
659 indicators = g_slist_append (indicators, indicator);
660
661 g_debug ("EI: New account: %s (%s)", data.name, data.url);
662 }
663
664 if (!data.enabled)
665 indicate_indicator_hide (indicator);
666
667 /* Fake a time */
668 g_time_val_add (&timeval, -1000000 * 60 * i);
669 indicate_indicator_set_property_time (indicator,
670 INDICATE_INDICATOR_MESSAGES_PROP_TIME,
671 &timeval);
672
673 i++;
674
675 /* Clean up */
676 g_free (data.url);
677 g_free (data.name);
678 g_free (data.parent);
679 g_free (data.last_parent);
680 data.reap_type = REAP_NONE;
681 data.enabled = TRUE;
682
683 g_markup_parse_context_free (context);
684 }475 }
685476
686 g_slist_foreach (old_list, (GFunc)g_object_unref, NULL);477 g_object_unref (source);
687 g_slist_free (old_list);
688
689 n_accounts = g_slist_length (accounts);
690 g_slist_free (accounts);
691 }478 }
692479
693 g_debug ("EI: Number of email accounts: %d", n_accounts);480 return account;
694}
695
696static void
697on_accounts_changed (GConfClient *gclient,
698 guint id,
699 GConfEntry *entry,
700 gpointer data)
701{
702 update_accounts ();
703}481}
704482
705#define EVO_CONTACTS_CMD "evolution -c contacts"483#define EVO_CONTACTS_CMD "evolution -c contacts"
706#define EVO_COMPOSE_CMD "evolution mailto:"484#define EVO_COMPOSE_CMD "evolution mailto:"
707485
708static void
709command_item_activate (DbusmenuMenuitem * mi, guint timestamp, gpointer user_data)
710{
711 gchar * command = (gchar *)user_data;
712 if (!g_spawn_command_line_async(command, NULL)) {
713 g_warning("EI: Unable to execute command '%s'", command);
714 }
715 return;
716}
717
718int486int
719e_plugin_lib_enable (EPlugin *ep, int enable)487e_plugin_lib_enable (EPlugin *ep, int enable)
720{488{
@@ -748,27 +516,10 @@
748 }516 }
749 }517 }
750518
751 server = indicate_server_ref_default ();519 if (mmapp == NULL)
752 indicate_server_set_type (server, "message");520 mmapp = messaging_menu_app_new ("evolution.desktop");
753 indicate_server_set_desktop_file (server, EVOLUTION_DESKTOP_FILE);521
754 g_signal_connect (server, "server-display",522 g_signal_connect (mmapp, "activate-source", G_CALLBACK (show_evolution), NULL);
755 G_CALLBACK (show_evolution), NULL);
756
757 DbusmenuServer * menu_server = dbusmenu_server_new("/messaging/commands");
758 DbusmenuMenuitem * root = dbusmenu_menuitem_new();
759
760 DbusmenuMenuitem * mi = dbusmenu_menuitem_new();
761 dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Compose New Message"));
762 g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(command_item_activate), EVO_COMPOSE_CMD);
763 dbusmenu_menuitem_child_append(root, mi);
764
765 mi = dbusmenu_menuitem_new();
766 dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Contacts"));
767 g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(command_item_activate), EVO_CONTACTS_CMD);
768 dbusmenu_menuitem_child_append(root, mi);
769
770 dbusmenu_server_set_root(menu_server, root);
771 indicate_server_set_menu(server, menu_server);
772523
773 launcher = unity_launcher_entry_get_for_desktop_file (EVOLUTION_DESKTOP_FILE);524 launcher = unity_launcher_entry_get_for_desktop_file (EVOLUTION_DESKTOP_FILE);
774525
@@ -797,22 +548,10 @@
797 show_count_id = gconf_client_notify_add (client, SHOW_NEW_IN_PANEL, 548 show_count_id = gconf_client_notify_add (client, SHOW_NEW_IN_PANEL,
798 show_new_in_panel_changed, NULL, NULL, NULL);549 show_new_in_panel_changed, NULL, NULL, NULL);
799550
800 gconf_client_add_dir (client, ACCOUNT_DIR,GCONF_CLIENT_PRELOAD_NONE, NULL);
801 update_accounts ();
802 accounts_id = gconf_client_notify_add (client, ACCOUNTS,
803 on_accounts_changed, NULL,
804 NULL, NULL);
805
806 if (show_count)551 if (show_count)
807 {552 messaging_menu_app_register (mmapp);
808 indicate_server_show (server);
809 show_evolution_in_indicator_applet ();
810 }
811 else553 else
812 {554 messaging_menu_app_unregister (mmapp);
813 indicate_server_hide (server);
814 hide_evolution_in_indicator_applet ();
815 }
816 }555 }
817 else556 else
818 {557 {
@@ -820,35 +559,28 @@
820 gconf_client_notify_remove (client, play_sound_id);559 gconf_client_notify_remove (client, play_sound_id);
821 gconf_client_notify_remove (client, show_bubble_id);560 gconf_client_notify_remove (client, show_bubble_id);
822 gconf_client_notify_remove (client, show_count_id);561 gconf_client_notify_remove (client, show_count_id);
823 gconf_client_notify_remove (client, accounts_id);
824562
825 g_object_unref (client);563 g_object_unref (client);
826 client = NULL;564 client = NULL;
827 565
828 /* Free indicators */566 /* Free indicators */
829 g_slist_foreach (indicators, (GFunc)g_object_unref, NULL);567 g_slist_foreach (accounts, (GFunc)unref_account, NULL);
830 g_slist_free (indicators);568 g_slist_free (accounts);
831 indicators = NULL;569 accounts = NULL;
832570
833 /* Free server */571 messaging_menu_app_unregister (mmapp);
834 indicate_server_hide (server);572
835 g_object_unref (server);
836 server = NULL;
837
838 /* Remove evolution from indicator menu */
839 hide_evolution_in_indicator_applet ();
840
841 g_debug ("EI: Disabled");573 g_debug ("EI: Disabled");
842 }574 }
843575
844 return 0;576 return 0;
845}577}
846578
847GtkWidget *579GtkWidget *
848e_plugin_lib_get_configure_widget (EPlugin *ep)580e_plugin_lib_get_configure_widget (EPlugin *ep)
849{581{
850 g_debug ("EI: Get Configure Widget");582 g_debug ("EI: Get Configure Widget");
851 return get_cfg_widget ();583 return NULL;
852}584}
853585
854static void586static void
@@ -911,7 +643,7 @@
911643
912 gtk_box_reorder_child (GTK_BOX (gtk_widget_get_parent (frame)), frame, 0);644 gtk_box_reorder_child (GTK_BOX (gtk_widget_get_parent (frame)), frame, 0);
913645
914 box = gtk_hbox_new (FALSE, 0);646 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
915 gtk_frame_set_label_widget (GTK_FRAME (frame), box);647 gtk_frame_set_label_widget (GTK_FRAME (frame), box);
916 gtk_widget_show (frame);648 gtk_widget_show (frame);
917649
@@ -925,12 +657,12 @@
925#if GTK_CHECK_VERSION(2, 91, 0)657#if GTK_CHECK_VERSION(2, 91, 0)
926 combo = gtk_combo_box_text_new ();658 combo = gtk_combo_box_text_new ();
927 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo),659 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo),
928 n_accounts > 1 ? _("any Inbox") : _("Inbox"));660 g_slist_length (accounts) > 1 ? _("any Inbox") : _("Inbox"));
929 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("any Folder"));661 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), _("any Folder"));
930#else662#else
931 combo = gtk_combo_box_new_text ();663 combo = gtk_combo_box_new_text ();
932 gtk_combo_box_append_text (GTK_COMBO_BOX (combo),664 gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
933 n_accounts > 1 ? _("any Inbox") : _("Inbox"));665 g_slist_length (accounts) > 1 ? _("any Inbox") : _("Inbox"));
934 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("any Folder"));666 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("any Folder"));
935#endif667#endif
936 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 668 gtk_combo_box_set_active (GTK_COMBO_BOX (combo),
@@ -965,7 +697,7 @@
965 g_debug ("EI: Woops, couldn't find the GtkFrame in the widget hierarchy"); 697 g_debug ("EI: Woops, couldn't find the GtkFrame in the widget hierarchy");
966 }698 }
967699
968 vbox = gtk_vbox_new (FALSE, 8);700 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
969 gtk_table_attach((GtkTable *)data->parent, vbox, 0, 1, 0, 1, 0, 0, 0, 0);701 gtk_table_attach((GtkTable *)data->parent, vbox, 0, 1, 0, 1, 0, 0, 0, 0);
970702
971 check = gtk_check_button_new_with_mnemonic (_("Pla_y a sound"));703 check = gtk_check_button_new_with_mnemonic (_("Pla_y a sound"));
@@ -995,7 +727,7 @@
995 */727 */
996728
997static void729static void
998show_evolution (gpointer arg0, guint timestamp, gpointer arg1)730show_evolution (MessagingMenuApp *mmapp, const gchar *uid, gpointer user_data)
999{731{
1000#define MAIL_ICON "evolution-mail"732#define MAIL_ICON "evolution-mail"
1001 EShell *shell = e_shell_get_default ();733 EShell *shell = e_shell_get_default ();
@@ -1004,7 +736,7 @@
1004736
1005 if (shell)737 if (shell)
1006 {738 {
1007 GSList *i;739 MessagingMailAccount *account;
1008 EShellWindow *shell_window;740 EShellWindow *shell_window;
1009 EShellView *shell_view;741 EShellView *shell_view;
1010 GtkAction *action;742 GtkAction *action;
@@ -1014,7 +746,7 @@
1014 shell_window = E_SHELL_WINDOW (e_shell_get_active_window (shell));746 shell_window = E_SHELL_WINDOW (e_shell_get_active_window (shell));
1015 if (!evolution_is_focused ())747 if (!evolution_is_focused ())
1016 {748 {
1017 gtk_window_present_with_time (GTK_WINDOW (shell_window), timestamp);749 gtk_window_present (GTK_WINDOW (shell_window));
1018 }750 }
1019751
1020 /* Switch to the mail view. */752 /* Switch to the mail view. */
@@ -1023,20 +755,19 @@
1023 gtk_action_activate (action);755 gtk_action_activate (action);
1024756
1025 /* Setup the indicators */757 /* Setup the indicators */
1026 for (i = indicators; i; i = i->next)758 account = ensure_account_for_uid (uid);
759 if(account)
1027 {760 {
1028 IndicateIndicator *indicator = i->data;761 gchar *uid = account->uid;
1029762
1030 set_indicator_unread_count (indicator, 0);763 message_count -= account->n_count;
1031 indicate_indicator_set_property (indicator,764 account->n_count = 0;
1032 INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION,765 g_debug ("EI: Setting %s to 0 unread messages", uid);
1033 "false");766 }
1034767 else {
1035 g_debug ("EI: Setting %s to 0 unread messages",768 g_warning ("EI: Unable to find account that matches %s", uid);
1036 indicate_indicator_get_property (indicator, "name"));769 }
1037770
1038 }
1039 message_count = 0;
1040 update_unity_launcher_count ();771 update_unity_launcher_count ();
1041 }772 }
1042 else773 else
@@ -1045,113 +776,3 @@
1045 return;776 return;
1046 }777 }
1047}778}
1048
1049
1050/*
1051 *
1052 * SHOW/HIDE EVOLUTION IN INDICATOR APPLET
1053 *
1054 */
1055
1056static void
1057show_evolution_in_indicator_applet (void)
1058{
1059 gchar *bpath;
1060
1061 bpath = g_build_filename (g_get_user_config_dir (),
1062 USER_BLACKLIST_DIR,
1063 USER_BLACKLIST_FILENAME,
1064 NULL);
1065
1066 if (g_file_test (bpath, G_FILE_TEST_EXISTS))
1067 {
1068 GFile *bfile;
1069
1070 bfile = g_file_new_for_path (bpath);
1071
1072 if (bfile)
1073 {
1074 GError *error = NULL;
1075
1076 g_file_delete (bfile, NULL, &error);
1077
1078 if (error)
1079 {
1080 g_warning ("EI: Unable to remove blacklist file: %s", error->message);
1081 g_error_free (error);
1082 }
1083
1084 g_object_unref (bfile);
1085 }
1086 }
1087
1088 g_free (bpath);
1089}
1090
1091static void
1092hide_evolution_in_indicator_applet (void)
1093{
1094 gchar *bdir;
1095 gchar *bpath;
1096 GError *error = NULL;
1097
1098 bdir = g_build_filename (g_get_user_config_dir (),
1099 USER_BLACKLIST_DIR,
1100 NULL);
1101 if (!g_file_test (bdir, G_FILE_TEST_IS_DIR))
1102 {
1103 GFile *dirfile;
1104
1105 dirfile = g_file_new_for_path (bdir);
1106 if (dirfile)
1107 {
1108 g_file_make_directory_with_parents (dirfile,
1109 NULL,
1110 &error);
1111 if (error)
1112 {
1113 g_warning ("EI: Unable to create blacklist directory: %s",
1114 error->message);
1115 g_error_free (error);
1116 g_object_unref (dirfile);
1117 g_free (bdir);
1118 g_free (bpath);
1119 return;
1120 }
1121 }
1122 else
1123 {
1124 g_warning ("EI: Unable to create blacklist directory: Unable to create "
1125 "GFile for path %s", bdir);
1126 g_free (bdir);
1127 g_free (bpath);
1128 return;
1129 }
1130
1131 g_object_unref (dirfile);
1132 }
1133 g_free (bdir);
1134
1135 bpath = g_build_filename (g_get_user_config_dir (),
1136 USER_BLACKLIST_DIR,
1137 USER_BLACKLIST_FILENAME,
1138 NULL);
1139
1140 if (g_file_set_contents (bpath,
1141 EVOLUTION_DESKTOP_FILE,
1142 -1,
1143 &error))
1144 {
1145 g_debug ("EI: Successfully wrote blacklist file to %s", bpath);
1146 }
1147 else
1148 {
1149 g_debug ("EI: Unable to write blacklist file to %s: %s",
1150 bpath,
1151 error ? error->message : "Unknown");
1152 if (error)
1153 g_error_free (error);
1154 }
1155
1156 g_free (bpath);
1157}
1158779
=== modified file 'src/org-freedesktop-evolution-indicator.eplug.xml'
--- src/org-freedesktop-evolution-indicator.eplug.xml 2011-07-10 13:45:32 +0000
+++ src/org-freedesktop-evolution-indicator.eplug.xml 2013-03-21 23:26:20 +0000
@@ -5,7 +5,8 @@
5 location="@PLUGINDIR@/liborg-freedesktop-evolution-indicator.so" 5 location="@PLUGINDIR@/liborg-freedesktop-evolution-indicator.so"
6 id="org.freedesktop.evolution_indicator" 6 id="org.freedesktop.evolution_indicator"
7 domain="@GETTEXT_PACKAGE@"7 domain="@GETTEXT_PACKAGE@"
8 _name="Evolution Indicator">8 _name="Evolution Indicator"
9 load-on-startup="true">
910
10 <_description>Shows new mail count in a message indicator.</_description>11 <_description>Shows new mail count in a message indicator.</_description>
11 <author name="Neil Jagdish Patel" email="neil.patel@canonical.com"/>12 <author name="Neil Jagdish Patel" email="neil.patel@canonical.com"/>

Subscribers

People subscribed via source and target branches