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