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