2010-10-02 [colin] 3.7.6cvs47
[claws.git] / src / plugins / trayicon / trayicon.c
index 94ac0c2ba10a66d67edee4423962f0843cd4cba3..8b815953dc1f0a66f208239b54431a712a729d2f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2008 the Claws Mail Team
+ * Copyright (C) 2003-2009 the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,8 +43,6 @@
 #include "account.h"
 #include "gtk/manage_window.h"
 
-#include "eggtrayicon.h"
-
 #include "trayicon_prefs.h"
 
 #include "stock_pixmap.h"
@@ -59,27 +57,19 @@ static guint close_hook_id;
 static guint iconified_hook_id;
 static guint theme_hook_id;
 
-static GdkPixmap *newmail_pixmap[2] = {NULL, NULL};
-static GdkPixmap *newmail_bitmap[2] = {NULL, NULL};
-static GdkPixmap *unreadmail_pixmap[2] = {NULL, NULL};
-static GdkPixmap *unreadmail_bitmap[2] = {NULL, NULL};
-static GdkPixmap *newmarkedmail_pixmap[2] = {NULL, NULL};
-static GdkPixmap *newmarkedmail_bitmap[2] = {NULL, NULL};
-static GdkPixmap *unreadmarkedmail_pixmap[2] = {NULL, NULL};
-static GdkPixmap *unreadmarkedmail_bitmap[2] = {NULL, NULL};
-static GdkPixmap *nomail_pixmap[2] = {NULL, NULL};
-static GdkPixmap *nomail_bitmap[2] = {NULL, NULL};
-
-static EggTrayIcon *trayicon;
-static GtkWidget *eventbox;
+static GdkPixbuf *newmail_pixbuf[2] = {NULL, NULL};
+static GdkPixbuf *unreadmail_pixbuf[2] = {NULL, NULL};
+static GdkPixbuf *newmarkedmail_pixbuf[2] = {NULL, NULL};
+static GdkPixbuf *unreadmarkedmail_pixbuf[2] = {NULL, NULL};
+static GdkPixbuf *nomail_pixbuf[2] = {NULL, NULL};
+
+static GtkStatusIcon *trayicon;
 static GtkWidget *image = NULL;
-static GtkTooltips *tooltips;
+static GtkWidget *focused_widget = NULL;
+
 static GtkWidget *traymenu_popup;
-static GtkItemFactory *traymenu_factory;
 static gboolean updating_menu = FALSE;
 
-guint destroy_signal_id;
-
 typedef enum
 {
        TRAYICON_NEW,
@@ -89,48 +79,43 @@ typedef enum
        TRAYICON_NOTHING
 } TrayIconType;
 
-static void trayicon_get_all_cb            (gpointer data, guint action, GtkWidget *widget);
-static void trayicon_compose_cb            (gpointer data, guint action, GtkWidget *widget);
+static void trayicon_get_all_cb            (GtkAction *action, gpointer data);
+static void trayicon_compose_cb            (GtkAction *action, gpointer data);
 static void trayicon_compose_acc_cb (GtkMenuItem *menuitem, gpointer data );
-static void trayicon_addressbook_cb (gpointer data, guint action, GtkWidget *widget);
-static void trayicon_exit_cb       (gpointer data, guint action, GtkWidget *widget);
-static void trayicon_toggle_offline_cb (gpointer data, guint action, GtkWidget *widget);
-static void resize_cb              (GtkWidget *widget, GtkRequisition *req, gpointer user_data);
+static void trayicon_addressbook_cb (GtkAction *action, gpointer data);
+static void trayicon_exit_cb       (GtkAction *action, gpointer data);
+static void trayicon_toggle_offline_cb (GtkAction *action, gpointer data);
 
-static GtkItemFactoryEntry trayicon_popup_menu_entries[] =
+static GtkActionEntry trayicon_popup_menu_entries[] =
 {
-       {N_("/_Get Mail"),              NULL, trayicon_get_all_cb,              0, NULL},
-       {"/---",                        NULL, NULL,                             0, "<Separator>"},
-       {N_("/_Email"),                 NULL, trayicon_compose_cb,              0, NULL},
-       {N_("/_Email from account"),    NULL, NULL,                             0, "<Branch>"},
-       {"/---",                        NULL, NULL,                             0, "<Separator>"},
-       {N_("/Open A_ddressbook"),      NULL, trayicon_addressbook_cb,          0, NULL},
-       {"/---",                        NULL, NULL,                             0, "<Separator>"},
-       {N_("/_Work Offline"),          NULL, trayicon_toggle_offline_cb,       0, "<CheckItem>"},
-       {"/---",                        NULL, NULL,                             0, "<Separator>"},
-       {N_("/E_xit Claws Mail"),       NULL, trayicon_exit_cb,                 0, NULL}
+       {"TrayiconPopup",                       NULL, "TrayiconPopup" },
+       {"TrayiconPopup/GetMail",               NULL, N_("_Get Mail"), NULL, NULL, G_CALLBACK(trayicon_get_all_cb) },
+       {"TrayiconPopup/---",                   NULL, "---", NULL, NULL, G_CALLBACK(trayicon_compose_cb) },
+       {"TrayiconPopup/Email",                 NULL, N_("_Email"), NULL, NULL, G_CALLBACK(trayicon_compose_cb) },
+       {"TrayiconPopup/EmailAcc",              NULL, N_("E_mail from account"), NULL, NULL, NULL },
+       {"TrayiconPopup/OpenAB",                NULL, N_("Open A_ddressbook"), NULL, NULL, G_CALLBACK(trayicon_addressbook_cb) },
+       {"TrayiconPopup/Exit",                  NULL, N_("E_xit Claws Mail"), NULL, NULL, G_CALLBACK(trayicon_exit_cb) },
+};
+
+static GtkToggleActionEntry trayicon_popup_toggle_menu_entries[] =
+{
+       {"TrayiconPopup/ToggleOffline",         NULL, N_("_Work Offline"), NULL, NULL, G_CALLBACK(trayicon_toggle_offline_cb) },
 };
 
 static gboolean trayicon_set_accounts_hook(gpointer source, gpointer data)
 {
-       GList *cur_ac, *cur_item = NULL;
-       GtkWidget *menu;
+       GList *cur_ac;
+       GtkWidget *menu, *submenu;
        GtkWidget *menuitem;
        PrefsAccount *ac_prefs;
 
        GList *account_list = account_get_list();
 
-       menu = gtk_item_factory_get_widget(traymenu_factory,
-                                          "/Email from account");
-
-       /* destroy all previous menu item */
-       cur_item = GTK_MENU_SHELL(menu)->children;
-       while (cur_item != NULL) {
-               GList *next = cur_item->next;
-               gtk_widget_destroy(GTK_WIDGET(cur_item->data));
-               cur_item = next;
-       }
+       menu = gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TrayiconPopup/EmailAcc");
+       gtk_widget_show(menu);
 
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), NULL);
+       submenu = gtk_menu_new();
        for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
                ac_prefs = (PrefsAccount *)cur_ac->data;
 
@@ -138,50 +123,46 @@ static gboolean trayicon_set_accounts_hook(gpointer source, gpointer data)
                        (ac_prefs->account_name ? ac_prefs->account_name
                         : _("Untitled"));
                gtk_widget_show(menuitem);
-               gtk_menu_append(GTK_MENU(menu), menuitem);
+               gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
                g_signal_connect(G_OBJECT(menuitem), "activate",
                                 G_CALLBACK(trayicon_compose_acc_cb),
                                 ac_prefs);
        }
+       gtk_widget_show(submenu);
+       gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);
        return FALSE;
 }
 
-static void set_trayicon_pixmap(TrayIconType icontype)
+static void set_trayicon_pixbuf(TrayIconType icontype)
 {
-       GdkPixmap *pixmap = NULL;
-       GdkBitmap *bitmap = NULL;
-       static GdkPixmap *last_pixmap = NULL;
+       GdkPixbuf *pixbuf = NULL;
+       static GdkPixbuf *last_pixbuf = NULL;
 
        switch(icontype) {
        case TRAYICON_NEW:
-               pixmap = newmail_pixmap[prefs_common.work_offline];
-               bitmap = newmail_bitmap[prefs_common.work_offline];
+               pixbuf = newmail_pixbuf[prefs_common.work_offline];
                break;
        case TRAYICON_NEWMARKED:
-               pixmap = newmarkedmail_pixmap[prefs_common.work_offline];
-               bitmap = newmarkedmail_bitmap[prefs_common.work_offline];
+               pixbuf = newmarkedmail_pixbuf[prefs_common.work_offline];
                break;
        case TRAYICON_UNREAD:
-               pixmap = unreadmail_pixmap[prefs_common.work_offline];
-               bitmap = unreadmail_bitmap[prefs_common.work_offline];
+               pixbuf = unreadmail_pixbuf[prefs_common.work_offline];
                break;
        case TRAYICON_UNREADMARKED:
-               pixmap = unreadmarkedmail_pixmap[prefs_common.work_offline];
-               bitmap = unreadmarkedmail_bitmap[prefs_common.work_offline];
+               pixbuf = unreadmarkedmail_pixbuf[prefs_common.work_offline];
                break;
        default:
-               pixmap = nomail_pixmap[prefs_common.work_offline];
-               bitmap = nomail_bitmap[prefs_common.work_offline];
+               pixbuf = nomail_pixbuf[prefs_common.work_offline];
                break;
        }
 
-       if (pixmap == last_pixmap) {
+       if (pixbuf == last_pixbuf) {
                return;
        }
 
-       gtk_image_set_from_pixmap(GTK_IMAGE(image), pixmap, bitmap);
+       gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(trayicon), pixbuf);
 
-       last_pixmap = pixmap;
+       last_pixbuf = pixbuf;
 }
 
 static void update(FolderItem *removed_item)
@@ -202,7 +183,11 @@ static void update(FolderItem *removed_item)
 
        buf = g_strdup_printf(_("New %d, Unread: %d, Total: %d"), new, unread, total);
 
-        gtk_tooltips_set_tip(tooltips, eventbox, buf, "");
+#if !(GTK_CHECK_VERSION(2,16,0))
+       gtk_status_icon_set_tooltip(trayicon, buf);
+#else
+       gtk_status_icon_set_tooltip_text(trayicon, buf);
+#endif
        g_free(buf);
 
        if (new > 0 && unreadmarked > 0) {
@@ -215,7 +200,7 @@ static void update(FolderItem *removed_item)
                icontype = TRAYICON_UNREAD;
        }
 
-       set_trayicon_pixmap(icontype);
+       set_trayicon_pixbuf(icontype);
 }
 
 static gboolean folder_item_update_hook(gpointer source, gpointer data)
@@ -249,12 +234,14 @@ static gboolean trayicon_close_hook(gpointer source, gpointer data)
                gboolean *close_allowed = (gboolean*)source;
 
                if (trayicon_prefs.close_to_tray) {
-               MainWindow *mainwin = mainwindow_get_mainwindow();
+                       MainWindow *mainwin = mainwindow_get_mainwindow();
 
                        *close_allowed = FALSE;
-               if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
-                       main_window_hide(mainwin);
-       }
+                       focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
+                       
+                       if (gtkut_widget_get_visible(GTK_WIDGET(mainwin->window)))
+                               main_window_hide(mainwin);
+               }
        }
        return FALSE;
 }
@@ -264,19 +251,14 @@ static gboolean trayicon_got_iconified_hook(gpointer source, gpointer data)
        MainWindow *mainwin = mainwindow_get_mainwindow();
 
        if (trayicon_prefs.hide_when_iconified
-                       && GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))
+                       && gtkut_widget_get_visible(GTK_WIDGET(mainwin->window))
                        && !gtk_window_get_skip_taskbar_hint(GTK_WINDOW(mainwin->window))) {
+               focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
                gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), TRUE);
        }
        return FALSE;
 }
 
-static void resize_cb(GtkWidget *widget, GtkRequisition *req,
-                     gpointer user_data)
-{
-       update(NULL);
-}
-
 static void fix_folderview_scroll(MainWindow *mainwin)
 {
        static gboolean fix_done = FALSE;
@@ -302,14 +284,16 @@ static gboolean click_cb(GtkWidget * widget,
 
        switch (event->button) {
        case 1:
-               if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
+               if (gtkut_widget_get_visible(GTK_WIDGET(mainwin->window))) {
                        if ((gdk_window_get_state(GTK_WIDGET(mainwin->window)->window)&GDK_WINDOW_STATE_ICONIFIED)
                                        || mainwindow_is_obscured()) {
                                gtk_window_deiconify(GTK_WINDOW(mainwin->window));
                                gtk_window_set_skip_taskbar_hint(GTK_WINDOW(mainwin->window), FALSE);
                                main_window_show(mainwin);
                                gtk_window_present(GTK_WINDOW(mainwin->window));
+                               gtk_window_set_focus(GTK_WINDOW(mainwin->window), focused_widget);
                        } else {
+                               focused_widget = gtk_window_get_focus(GTK_WINDOW(mainwin->window));
                                main_window_hide(mainwin);
                        }
                } else {
@@ -318,18 +302,15 @@ static gboolean click_cb(GtkWidget * widget,
                        main_window_show(mainwin);
                        gtk_window_present(GTK_WINDOW(mainwin->window));
                        fix_folderview_scroll(mainwin);
+                       gtk_window_set_focus(GTK_WINDOW(mainwin->window), focused_widget);
         }
                break;
        case 3:
                /* tell callbacks to skip any event */
                updating_menu = TRUE;
                /* initialize checkitem according to current offline state */
-               gtk_check_menu_item_set_active(
-                       GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(traymenu_factory,
-                       "/Work Offline")), prefs_common.work_offline);
-               gtk_widget_set_sensitive(
-                       GTK_WIDGET(gtk_item_factory_get_item(traymenu_factory,
-                       "/Get Mail")), mainwin->lock_count == 0);
+               cm_toggle_menu_set_active("TrayiconPopup/ToggleOffline", prefs_common.work_offline);
+               cm_menu_set_sensitive("TrayiconPopup/GetMail", mainwin->lock_count == 0);
                updating_menu = FALSE;
 
                gtk_menu_popup( GTK_MENU(traymenu_popup), NULL, NULL, NULL, NULL,
@@ -343,26 +324,20 @@ static gboolean click_cb(GtkWidget * widget,
 
 static void create_trayicon(void);
 
-static void destroy_cb(GtkWidget *widget, gpointer *data)
-{
-       debug_print("Widget destroyed\n");
-
-       create_trayicon();
-}
-
 static gboolean trayicon_update_theme(gpointer source, gpointer data)
 {
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NOMAIL, &nomail_pixmap[0], &nomail_bitmap[0]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_UNREADMAIL, &unreadmail_pixmap[0], &unreadmail_bitmap[0]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NEWMAIL, &newmail_pixmap[0], &newmail_bitmap[0]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL, &unreadmarkedmail_pixmap[0], &unreadmarkedmail_bitmap[0]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL, &newmarkedmail_pixmap[0], &newmarkedmail_bitmap[0]);
-
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NOMAIL_OFFLINE, &nomail_pixmap[1], &nomail_bitmap[1]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_UNREADMAIL_OFFLINE, &unreadmail_pixmap[1], &unreadmail_bitmap[1]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NEWMAIL_OFFLINE, &newmail_pixmap[1], &newmail_bitmap[1]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL_OFFLINE, &unreadmarkedmail_pixmap[1], &unreadmarkedmail_bitmap[1]);
-       stock_pixmap_gdk(GTK_WIDGET(trayicon), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL_OFFLINE, &newmarkedmail_pixmap[1], &newmarkedmail_bitmap[1]);
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NOMAIL, &nomail_pixbuf[0]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMAIL, &unreadmail_pixbuf[0]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMAIL, &newmail_pixbuf[0]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL, &unreadmarkedmail_pixbuf[0]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL, &newmarkedmail_pixbuf[0]);
+
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NOMAIL_OFFLINE, &nomail_pixbuf[1]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMAIL_OFFLINE, &unreadmail_pixbuf[1]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMAIL_OFFLINE, &newmail_pixbuf[1]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_UNREADMARKEDMAIL_OFFLINE, &unreadmarkedmail_pixbuf[1]);
+       stock_pixbuf_gdk(GTK_WIDGET(mainwin->window), STOCK_PIXMAP_TRAY_NEWMARKEDMAIL_OFFLINE, &newmarkedmail_pixbuf[1]);
 
        if (image != NULL)
                update(NULL);
@@ -372,40 +347,37 @@ static gboolean trayicon_update_theme(gpointer source, gpointer data)
 
 static void create_trayicon()
 {
-       gint n_entries = 0;
-
-       trayicon = egg_tray_icon_new("Claws Mail");
-       gtk_widget_realize(GTK_WIDGET(trayicon));
-       gtk_window_set_default_size(GTK_WINDOW(trayicon), 16, 16);
-       gtk_container_set_border_width(GTK_CONTAINER(trayicon), 0);
-
+       GtkActionGroup *action_group;
+       trayicon = gtk_status_icon_new();
+#if GTK_CHECK_VERSION(2,14,0)
+       gtk_status_icon_set_title(GTK_STATUS_ICON(trayicon), _("Claws Mail"));
+#endif
        trayicon_update_theme(NULL, NULL);
 
-       eventbox = gtk_event_box_new();
-       gtk_container_set_border_width(GTK_CONTAINER(eventbox), 0);
-       gtk_container_add(GTK_CONTAINER(trayicon), GTK_WIDGET(eventbox));
+       gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(trayicon), nomail_pixbuf[0]);
 
-       image = gtk_image_new_from_pixmap(nomail_pixmap[0], nomail_bitmap[0]);
-       gtk_container_add(GTK_CONTAINER(eventbox), image);
-
-       destroy_signal_id =
-       g_signal_connect(G_OBJECT(trayicon), "destroy",
-               G_CALLBACK(destroy_cb), NULL);
-       g_signal_connect(GTK_OBJECT(trayicon), "size-request",
-               G_CALLBACK(resize_cb), NULL);
-       g_signal_connect(G_OBJECT(eventbox), "button-press-event",
+       g_signal_connect(G_OBJECT(trayicon), "button-press-event",
                G_CALLBACK(click_cb), NULL);
 
-       tooltips = gtk_tooltips_new();
-       gtk_tooltips_enable(tooltips);
-
-       n_entries = sizeof(trayicon_popup_menu_entries) /
-       sizeof(trayicon_popup_menu_entries[0]);
-       traymenu_popup = menu_create_items(trayicon_popup_menu_entries,
-                                               n_entries, "<TrayiconMenu>", &traymenu_factory,
-                                               NULL);
-
-       gtk_widget_show_all(GTK_WIDGET(trayicon));
+       action_group = cm_menu_create_action_group("TrayiconPopup", trayicon_popup_menu_entries,
+                       G_N_ELEMENTS(trayicon_popup_menu_entries), (gpointer)NULL);
+       gtk_action_group_add_toggle_actions(action_group, trayicon_popup_toggle_menu_entries,
+                       G_N_ELEMENTS(trayicon_popup_toggle_menu_entries), (gpointer)NULL);
+
+       MENUITEM_ADDUI("/Menus", "TrayiconPopup", "TrayiconPopup", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "GetMail", "TrayiconPopup/GetMail", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator1", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Email", "TrayiconPopup/Email", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "EmailAcc", "TrayiconPopup/EmailAcc", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator2", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "OpenAB", "TrayiconPopup/OpenAB", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator3", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "ToggleOffline", "TrayiconPopup/ToggleOffline", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Separator4", "TrayiconPopup/---", GTK_UI_MANAGER_SEPARATOR)
+       MENUITEM_ADDUI("/Menus/TrayiconPopup", "Exit", "TrayiconPopup/Exit", GTK_UI_MANAGER_MENUITEM)
+
+       traymenu_popup = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
+                               gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TrayiconPopup")) );
 
        update(NULL);
 }
@@ -466,7 +438,7 @@ int plugin_init(gchar **error)
        if (trayicon_prefs.hide_at_startup && claws_is_starting()) {
                MainWindow *mainwin = mainwindow_get_mainwindow();
 
-               if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
+               if (gtkut_widget_get_visible(GTK_WIDGET(mainwin->window)))
                        main_window_hide(mainwin);
                main_set_show_at_startup(FALSE);
        }
@@ -504,9 +476,8 @@ gboolean plugin_done(void)
        if (claws_is_exiting())
                return TRUE;
 
-       g_signal_handler_disconnect(G_OBJECT(trayicon), destroy_signal_id);
-       
-       gtk_widget_destroy(GTK_WIDGET(trayicon));
+       g_object_unref(G_OBJECT(trayicon));
+       trayicon = NULL;
 
        while (gtk_events_pending()) {
                gtk_main_iteration();
@@ -546,13 +517,13 @@ const gchar *plugin_version(void)
 
 
 /* popup menu callbacks */
-static void trayicon_get_all_cb( gpointer data, guint action, GtkWidget *widget )
+static void trayicon_get_all_cb( GtkAction *action, gpointer data )
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
        inc_all_account_mail_cb(mainwin, 0, NULL);
 }
 
-static void trayicon_compose_cb( gpointer data, guint action, GtkWidget *widget )
+static void trayicon_compose_cb( GtkAction *action, gpointer data )
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();
        compose_mail_cb(mainwin, 0, NULL);
@@ -563,12 +534,12 @@ static void trayicon_compose_acc_cb( GtkMenuItem *menuitem, gpointer data )
        compose_new((PrefsAccount *)data, NULL, NULL);
 }
 
-static void trayicon_addressbook_cb( gpointer data, guint action, GtkWidget *widget )
+static void trayicon_addressbook_cb( GtkAction *action, gpointer data )
 {
        addressbook_open(NULL);
 }
 
-static void trayicon_toggle_offline_cb( gpointer data, guint action, GtkWidget *widget )
+static void trayicon_toggle_offline_cb( GtkAction *action, gpointer data )
 {
        /* toggle offline mode if menu checkitem has been clicked */
        if (!updating_menu) {
@@ -579,6 +550,11 @@ static void trayicon_toggle_offline_cb( gpointer data, guint action, GtkWidget *
 
 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
+       if (prefs_common.clean_on_exit) {
+               if (!main_window_empty_trash(mainwin, prefs_common.ask_on_clean, TRUE))
+                       return;
+       }
+
        if (prefs_common.confirm_on_exit) {
                if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
                               GTK_STOCK_CANCEL, GTK_STOCK_OK,
@@ -591,7 +567,7 @@ static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        app_will_exit(NULL, mainwin);
 }
 
-static void trayicon_exit_cb( gpointer data, guint action, GtkWidget *widget )
+static void trayicon_exit_cb( GtkAction *action, gpointer data )
 {
        MainWindow *mainwin = mainwindow_get_mainwindow();