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