2012-07-07 [colin] 3.8.1cvs7
[claws.git] / src / plugins / trayicon / trayicon.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2012 the Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include <stdio.h>
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30
31 #include "common/claws.h"
32 #include "common/version.h"
33 #include "plugin.h"
34 #include "utils.h"
35 #include "hooks.h"
36 #include "folder.h"
37 #include "mainwindow.h"
38 #include "gtkutils.h"
39 #include "menu.h"
40 #include "toolbar.h"
41 #include "prefs_common.h"
42 #include "main.h"
43 #include "alertpanel.h"
44 #include "account.h"
45 #include "gtk/manage_window.h"
46 #ifdef USE_NEW_ADDRBOOK
47         #include "addressbook-dbus.h"
48 #endif
49
50 #include "trayicon_prefs.h"
51
52 #include "stock_pixmap.h"
53
54 #define PLUGIN_NAME (_("Trayicon"))
55
56 static guint item_hook_id;
57 static guint folder_hook_id;
58 static guint offline_hook_id;
59 static guint account_hook_id;
60 static guint close_hook_id;
61 static guint iconified_hook_id;
62 static guint theme_hook_id;
63
64 static GdkPixbuf *newmail_pixbuf[2] = {NULL, NULL};
65 static GdkPixbuf *unreadmail_pixbuf[2] = {NULL, NULL};
66 static GdkPixbuf *newmarkedmail_pixbuf[2] = {NULL, NULL};
67 static GdkPixbuf *unreadmarkedmail_pixbuf[2] = {NULL, NULL};
68 static GdkPixbuf *nomail_pixbuf[2] = {NULL, NULL};
69
70 static GtkStatusIcon *trayicon;
71 static GtkWidget *focused_widget = NULL;
72
73 static GtkWidget *traymenu_popup;
74 static gboolean updating_menu = FALSE;
75
76 typedef enum
77 {
78         TRAYICON_NEW,
79         TRAYICON_NEWMARKED,
80         TRAYICON_UNREAD,
81         TRAYICON_UNREADMARKED,
82         TRAYICON_NOTHING
83 } TrayIconType;
84
85 static void trayicon_get_all_cb     (GtkAction *action, gpointer data);
86 static void trayicon_compose_cb     (GtkAction *action, gpointer data);
87 static void trayicon_compose_acc_cb (GtkMenuItem *menuitem, gpointer data );
88 static void trayicon_addressbook_cb (GtkAction *action, gpointer data);
89 static void trayicon_exit_cb        (GtkAction *action, gpointer data);
90 static void trayicon_toggle_offline_cb  (GtkAction *action, gpointer data);
91
92 static GtkActionEntry trayicon_popup_menu_entries[] =
93 {
94         {"TrayiconPopup",                       NULL, "TrayiconPopup" },
95         {"TrayiconPopup/GetMail",               NULL, N_("_Get Mail"), NULL, NULL, G_CALLBACK(trayicon_get_all_cb) },
96         {"TrayiconPopup/---",                   NULL, "---", NULL, NULL, G_CALLBACK(trayicon_compose_cb) },
97         {"TrayiconPopup/Email",                 NULL, N_("_Email"), NULL, NULL, G_CALLBACK(trayicon_compose_cb) },
98         {"TrayiconPopup/EmailAcc",              NULL, N_("E_mail from account"), NULL, NULL, NULL },
99         {"TrayiconPopup/OpenAB",                NULL, N_("Open A_ddressbook"), NULL, NULL, G_CALLBACK(trayicon_addressbook_cb) },
100         {"TrayiconPopup/Exit",                  NULL, N_("E_xit Claws Mail"), NULL, NULL, G_CALLBACK(trayicon_exit_cb) },
101 };
102
103 static GtkToggleActionEntry trayicon_popup_toggle_menu_entries[] =
104 {
105         {"TrayiconPopup/ToggleOffline",         NULL, N_("_Work Offline"), NULL, NULL, G_CALLBACK(trayicon_toggle_offline_cb) },
106 };
107
108 static gboolean trayicon_set_accounts_hook(gpointer source, gpointer data)
109 {
110         GList *cur_ac;
111         GtkWidget *menu, *submenu;
112         GtkWidget *menuitem;
113         PrefsAccount *ac_prefs;
114
115         GList *account_list = account_get_list();
116
117         menu = gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TrayiconPopup/EmailAcc");
118         gtk_widget_show(menu);
119
120         gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), NULL);
121         submenu = gtk_menu_new();
122         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
123                 ac_prefs = (PrefsAccount *)cur_ac->data;
124
125                 menuitem = gtk_menu_item_new_with_label
126                         (ac_prefs->account_name ? ac_prefs->account_name
127                          : _("Untitled"));
128                 gtk_widget_show(menuitem);
129                 gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
130                 g_signal_connect(G_OBJECT(menuitem), "activate",
131                                  G_CALLBACK(trayicon_compose_acc_cb),
132                                  ac_prefs);
133         }
134         gtk_widget_show(submenu);
135         gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);
136         return FALSE;
137 }
138
139 static void set_trayicon_pixbuf(TrayIconType icontype)
140 {
141         GdkPixbuf *pixbuf = NULL;
142         static GdkPixbuf *last_pixbuf = NULL;
143
144         switch(icontype) {
145         case TRAYICON_NEW:
146                 pixbuf = newmail_pixbuf[prefs_common.work_offline];
147                 break;
148         case TRAYICON_NEWMARKED:
149                 pixbuf = newmarkedmail_pixbuf[prefs_common.work_offline];
150                 break;
151         case TRAYICON_UNREAD:
152                 pixbuf = unreadmail_pixbuf[prefs_common.work_offline];
153                 break;
154         case TRAYICON_UNREADMARKED:
155                 pixbuf = unreadmarkedmail_pixbuf[prefs_common.work_offline];
156                 break;
157         default:
158                 pixbuf = nomail_pixbuf[prefs_common.work_offline];
159                 break;
160         }
161
162         if (pixbuf == last_pixbuf) {
163                 return;
164         }
165
166         gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(trayicon), pixbuf);
167
168         last_pixbuf = pixbuf;
169 }
170
171 static void update(FolderItem *removed_item)
172 {
173         guint new, unread, unreadmarked, marked, total;
174         guint replied, forwarded, locked, ignored, watched;
175         gchar *buf;
176         TrayIconType icontype = TRAYICON_NOTHING;
177
178         folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
179                                 &replied, &forwarded, &locked, &ignored,
180                                 &watched);
181         if (removed_item) {
182                 total -= removed_item->total_msgs;
183                 new -= removed_item->new_msgs;
184                 unread -= removed_item->unread_msgs;
185         }
186
187         buf = g_strdup_printf(_("New %d, Unread: %d, Total: %d"), new, unread, total);
188
189 #if !(GTK_CHECK_VERSION(2,16,0))
190         gtk_status_icon_set_tooltip(trayicon, buf);
191 #else
192         gtk_status_icon_set_tooltip_text(trayicon, buf);
193 #endif
194         g_free(buf);
195
196         if (new > 0 && unreadmarked > 0) {
197                 icontype = TRAYICON_NEWMARKED;
198         } else if (new > 0) {
199                 icontype = TRAYICON_NEW;
200         } else if (unreadmarked > 0) {
201                 icontype = TRAYICON_UNREADMARKED;
202         } else if (unread > 0) {
203                 icontype = TRAYICON_UNREAD;
204         }
205
206         set_trayicon_pixbuf(icontype);
207 }
208
209 static gboolean folder_item_update_hook(gpointer source, gpointer data)
210 {
211         update(NULL);
212
213         return FALSE;
214 }
215
216 static gboolean folder_update_hook(gpointer source, gpointer data)
217 {
218         FolderUpdateData *hookdata;
219         hookdata = source;
220         if (hookdata->update_flags & FOLDER_REMOVE_FOLDERITEM)
221                 update(hookdata->item);
222         else
223                 update(NULL);
224
225         return FALSE;
226 }
227
228 static gboolean offline_update_hook(gpointer source, gpointer data)
229 {
230         update(NULL);
231         return FALSE;
232 }
233
234 static gboolean trayicon_close_hook(gpointer source, gpointer data)
235 {
236         if (source) {
237                 gboolean *close_allowed = (gboolean*)source;
238
239                 if (trayicon_prefs.close_to_tray) {
240                         MainWindow *mainwin = mainwindow_get_mainwindow();
241
242                         *close_allowed = FALSE;
243                         focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
244                         
245                         if (gtk_widget_get_visible(GTK_WIDGET(mainwin->window)))
246                                 main_window_hide(mainwin);
247                 }
248         }
249         return FALSE;
250 }
251
252 static gboolean trayicon_got_iconified_hook(gpointer source, gpointer data)
253 {
254         MainWindow *mainwin = mainwindow_get_mainwindow();
255
256         if (trayicon_prefs.hide_when_iconified
257                         && gtk_widget_get_visible(GTK_WIDGET(mainwin->window))
258                         && !gtk_window_get_skip_taskbar_hint(GTK_WINDOW(mainwin->window))) {
259                 focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
260                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), TRUE);
261         }
262         return FALSE;
263 }
264
265 static void fix_folderview_scroll(MainWindow *mainwin)
266 {
267         static gboolean fix_done = FALSE;
268
269         if (fix_done)
270                 return;
271
272         gtk_widget_queue_resize(mainwin->folderview->ctree);
273
274         fix_done = TRUE;
275 }
276
277 static gboolean click_cb(GtkWidget * widget,
278                          GdkEventButton * event, gpointer user_data)
279 {
280         MainWindow *mainwin;
281
282         if (event == NULL) {
283                 return TRUE;
284         }
285
286         mainwin = mainwindow_get_mainwindow();
287
288         switch (event->button) {
289         case 1:
290                 if (gtk_widget_get_visible(GTK_WIDGET(mainwin->window))) {
291                         if ((gdk_window_get_state(gtk_widget_get_window(
292                                 GTK_WIDGET(mainwin->window)))&GDK_WINDOW_STATE_ICONIFIED)
293                                         || mainwindow_is_obscured()) {
294                                 gtk_window_deiconify(GTK_WINDOW(mainwin->window));
295                                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
296                                 main_window_show(mainwin);
297                                 gtk_window_present(GTK_WINDOW(mainwin->window));
298                                 gtk_window_set_focus(GTK_WINDOW(mainwin->window), focused_widget);
299                         } else {
300                                 focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
301                                 main_window_hide(mainwin);
302                         }
303                 } else {
304                         gtk_window_deiconify(GTK_WINDOW(mainwin->window));
305                         gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
306                         main_window_show(mainwin);
307                         gtk_window_present(GTK_WINDOW(mainwin->window));
308                         fix_folderview_scroll(mainwin);
309                         gtk_window_set_focus(GTK_WINDOW(mainwin->window), focused_widget);
310         }
311                 break;
312         case 3:
313                 /* tell callbacks to skip any event */
314                 updating_menu = TRUE;
315                 /* initialize checkitem according to current offline state */
316                 cm_toggle_menu_set_active("TrayiconPopup/ToggleOffline", prefs_common.work_offline);
317                 cm_menu_set_sensitive("TrayiconPopup/GetMail", mainwin->lock_count == 0);
318                 updating_menu = FALSE;
319
320                 gtk_menu_popup( GTK_MENU(traymenu_popup), NULL, NULL, NULL, NULL,
321                        event->button, event->time );
322                 break;
323         default:
324                 return TRUE;
325         }
326         return TRUE;
327 }
328
329 static void create_trayicon(void);
330
331 static gboolean trayicon_update_theme(gpointer source, gpointer data)
332 {
333         MainWindow *mainwin = mainwindow_get_mainwindow();
334         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NOMAIL, &nomail_pixbuf[0]);
335         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMAIL, &unreadmail_pixbuf[0]);
336         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMAIL, &newmail_pixbuf[0]);
337         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL, &unreadmarkedmail_pixbuf[0]);
338         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL, &newmarkedmail_pixbuf[0]);
339
340         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NOMAIL_OFFLINE, &nomail_pixbuf[1]);
341         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMAIL_OFFLINE, &unreadmail_pixbuf[1]);
342         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMAIL_OFFLINE, &newmail_pixbuf[1]);
343         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL_OFFLINE, &unreadmarkedmail_pixbuf[1]);
344         stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL_OFFLINE, &newmarkedmail_pixbuf[1]);
345
346         update(NULL);
347
348         return FALSE;
349 }
350
351 static void create_trayicon()
352 {
353         GtkActionGroup *action_group;
354         trayicon = gtk_status_icon_new();
355         gtk_status_icon_set_title(GTK_STATUS_ICON(trayicon), _("Claws Mail"));
356         g_signal_connect(G_OBJECT(trayicon), "button-press-event",
357                 G_CALLBACK(click_cb), NULL);
358
359         action_group = cm_menu_create_action_group("TrayiconPopup", trayicon_popup_menu_entries,
360                         G_N_ELEMENTS(trayicon_popup_menu_entries), (gpointer)NULL);
361         gtk_action_group_add_toggle_actions(action_group, trayicon_popup_toggle_menu_entries,
362                         G_N_ELEMENTS(trayicon_popup_toggle_menu_entries), (gpointer)NULL);
363
364         MENUITEM_ADDUI("/Menus", "TrayiconPopup", "TrayiconPopup", GTK_UI_MANAGER_MENU)
365         MENUITEM_ADDUI("/Menus/TrayiconPopup", "GetMail", "TrayiconPopup/GetMail", GTK_UI_MANAGER_MENUITEM)
366         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator1", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
367         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Email", "TrayiconPopup/Email", GTK_UI_MANAGER_MENUITEM)
368         MENUITEM_ADDUI("/Menus/TrayiconPopup", "EmailAcc", "TrayiconPopup/EmailAcc", GTK_UI_MANAGER_MENU)
369         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator2", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
370         MENUITEM_ADDUI("/Menus/TrayiconPopup", "OpenAB", "TrayiconPopup/OpenAB", GTK_UI_MANAGER_MENUITEM)
371         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator3", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
372         MENUITEM_ADDUI("/Menus/TrayiconPopup", "ToggleOffline", "TrayiconPopup/ToggleOffline", GTK_UI_MANAGER_MENUITEM)
373         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator4", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
374         MENUITEM_ADDUI("/Menus/TrayiconPopup", "Exit", "TrayiconPopup/Exit", GTK_UI_MANAGER_MENUITEM)
375
376         traymenu_popup = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
377                                 gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TrayiconPopup")) );
378
379         trayicon_update_theme(NULL, NULL);
380 }
381
382 int plugin_init(gchar **error)
383 {
384         if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
385                                 VERSION_NUMERIC, PLUGIN_NAME, error))
386                 return -1;
387
388         item_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, folder_item_update_hook, NULL);
389         if (item_hook_id == -1) {
390                 *error = g_strdup(_("Failed to register folder item update hook"));
391                 goto err_out_item;
392         }
393
394         folder_hook_id = hooks_register_hook (FOLDER_UPDATE_HOOKLIST, folder_update_hook, NULL);
395         if (folder_hook_id == -1) {
396                 *error = g_strdup(_("Failed to register folder update hook"));
397                 goto err_out_folder;
398         }
399
400         offline_hook_id = hooks_register_hook (OFFLINE_SWITCH_HOOKLIST, offline_update_hook, NULL);
401         if (offline_hook_id == -1) {
402                 *error = g_strdup(_("Failed to register offline switch hook"));
403                 goto err_out_offline;
404         }
405
406         account_hook_id = hooks_register_hook (ACCOUNT_LIST_CHANGED_HOOKLIST, trayicon_set_accounts_hook, NULL);
407         if (account_hook_id == -1) {
408                 *error = g_strdup(_("Failed to register account list changed hook"));
409                 goto err_out_account;
410         }
411
412         close_hook_id = hooks_register_hook (MAIN_WINDOW_CLOSE, trayicon_close_hook, NULL);
413         if (close_hook_id == -1) {
414                 *error = g_strdup(_("Failed to register close hook"));
415                 goto err_out_close;
416         }
417
418         iconified_hook_id = hooks_register_hook (MAIN_WINDOW_GOT_ICONIFIED, trayicon_got_iconified_hook, NULL);
419         if (iconified_hook_id == -1) {
420                 *error = g_strdup(_("Failed to register got iconified hook"));
421                 goto err_out_iconified;
422         }
423
424         theme_hook_id = hooks_register_hook(THEME_CHANGED_HOOKLIST, trayicon_update_theme, NULL);
425         if (theme_hook_id == -1) {
426                 *error = g_strdup(_("Failed to register theme change hook"));
427                 goto err_out_theme;
428         }
429
430         create_trayicon();
431         trayicon_set_accounts_hook(NULL, NULL);
432
433         trayicon_prefs_init();
434
435         if (trayicon_prefs.hide_at_startup && claws_is_starting()) {
436                 MainWindow *mainwin = mainwindow_get_mainwindow();
437
438                 if (gtk_widget_get_visible(GTK_WIDGET(mainwin->window)))
439                         main_window_hide(mainwin);
440                 main_set_show_at_startup(FALSE);
441         }
442
443         return 0;
444
445 err_out_theme:
446         hooks_unregister_hook(MAIN_WINDOW_GOT_ICONIFIED, iconified_hook_id);
447 err_out_iconified:
448         hooks_unregister_hook(MAIN_WINDOW_CLOSE, close_hook_id);
449 err_out_close:
450         hooks_unregister_hook(ACCOUNT_LIST_CHANGED_HOOKLIST, account_hook_id);
451 err_out_account:
452         hooks_unregister_hook(OFFLINE_SWITCH_HOOKLIST, offline_hook_id);
453 err_out_offline:
454         hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST, folder_hook_id);
455 err_out_folder:
456         hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, item_hook_id);
457 err_out_item:
458         return -1;
459 }
460
461 gboolean plugin_done(void)
462 {
463         trayicon_prefs_done();
464
465         hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, item_hook_id);
466         hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST, folder_hook_id);
467         hooks_unregister_hook(OFFLINE_SWITCH_HOOKLIST, offline_hook_id);
468         hooks_unregister_hook(ACCOUNT_LIST_CHANGED_HOOKLIST, account_hook_id);
469         hooks_unregister_hook(MAIN_WINDOW_CLOSE, close_hook_id);
470         hooks_unregister_hook(MAIN_WINDOW_GOT_ICONIFIED, iconified_hook_id);
471         hooks_unregister_hook(THEME_CHANGED_HOOKLIST, theme_hook_id);
472
473         if (claws_is_exiting())
474                 return TRUE;
475
476         gtk_status_icon_set_visible(trayicon, FALSE);
477         g_object_unref(G_OBJECT(trayicon));
478         trayicon = NULL;
479
480         while (gtk_events_pending()) {
481                 gtk_main_iteration();
482         }
483         return TRUE;
484 }
485
486 const gchar *plugin_name(void)
487 {
488         return PLUGIN_NAME;
489 }
490
491 const gchar *plugin_desc(void)
492 {
493         return _("This plugin places a mailbox icon in the system tray that "
494                  "indicates if you have new or unread mail.\n"
495                  "\n"
496                  "The mailbox is empty if you have no unread mail, otherwise "
497                  "it contains a letter. A tooltip shows new, unread and total "
498                  "number of messages.");
499 }
500
501 const gchar *plugin_type(void)
502 {
503         return "GTK2";
504 }
505
506 const gchar *plugin_licence(void)
507 {
508         return "GPL3+";
509 }
510
511 const gchar *plugin_version(void)
512 {
513         return VERSION;
514 }
515
516
517 /* popup menu callbacks */
518 static void trayicon_get_all_cb( GtkAction *action, gpointer data )
519 {
520         MainWindow *mainwin = mainwindow_get_mainwindow();
521         inc_all_account_mail_cb(mainwin, 0, NULL);
522 }
523
524 static void trayicon_compose_cb( GtkAction *action, gpointer data )
525 {
526         MainWindow *mainwin = mainwindow_get_mainwindow();
527         compose_mail_cb(mainwin, 0, NULL);
528 }
529
530 static void trayicon_compose_acc_cb( GtkMenuItem *menuitem, gpointer data )
531 {
532         compose_new((PrefsAccount *)data, NULL, NULL);
533 }
534
535 static void trayicon_addressbook_cb( GtkAction *action, gpointer data )
536 {
537 #ifndef USE_NEW_ADDRBOOK
538         addressbook_open(NULL);
539 #else
540         GError* error = NULL;
541         addressbook_dbus_open(FALSE, &error);
542         if (error) {
543                 g_warning("%s", error->message);
544                 g_error_free(error);
545         }
546 #endif
547 }
548
549 static void trayicon_toggle_offline_cb( GtkAction *action, gpointer data )
550 {
551         /* toggle offline mode if menu checkitem has been clicked */
552         if (!updating_menu) {
553                 MainWindow *mainwin = mainwindow_get_mainwindow();
554                 main_window_toggle_work_offline(mainwin, !prefs_common.work_offline, TRUE);
555         }
556 }
557
558 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
559 {
560         if (prefs_common.clean_on_exit) {
561                 if (!main_window_empty_trash(mainwin, prefs_common.ask_on_clean, TRUE))
562                         return;
563         }
564
565         if (prefs_common.confirm_on_exit) {
566                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
567                                GTK_STOCK_CANCEL, GTK_STOCK_OK,
568                                NULL) != G_ALERTALTERNATE) {
569                         return;
570                 }
571                 manage_window_focus_in(mainwin->window, NULL, NULL);
572         }
573
574         app_will_exit(NULL, mainwin);
575 }
576
577 static void trayicon_exit_cb( GtkAction *action, gpointer data )
578 {
579         MainWindow *mainwin = mainwindow_get_mainwindow();
580
581         if (mainwin->lock_count == 0) {
582                 app_exit_cb(mainwin, 0, NULL);
583         }
584 }
585
586 struct PluginFeature *plugin_provides(void)
587 {
588         static struct PluginFeature features[] = 
589                 { {PLUGIN_NOTIFIER, N_("Trayicon")},
590                   {PLUGIN_NOTHING, NULL}};
591         return features;
592 }