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