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