0.9.3claws23
[claws.git] / src / plugins / trayicon / trayicon.c
index 0494e1dab20a60d5ad3a3403378100d1d6e01da8..56f185955a4f11fbbefda31b5a1b857fce369c0f 100644 (file)
@@ -23,6 +23,7 @@
 #include <gtk/gtk.h>
 
 #include "plugin.h"
+#include "utils.h"
 #include "hooks.h"
 #include "folder.h"
 #include "mainwindow.h"
@@ -34,7 +35,7 @@
 #include "unreadmail.xpm"
 #include "nomail.xpm"
 
-static gint hook_id;
+static guint hook_id;
 
 static GdkPixmap *newmail_pixmap;
 static GdkPixmap *newmail_bitmap;
@@ -47,6 +48,7 @@ static EggTrayIcon *trayicon;
 static GtkWidget *eventbox;
 static GtkWidget *image;
 static GtkTooltips *tooltips;
+guint destroy_signal_id;
 
 typedef enum
 {
@@ -109,14 +111,12 @@ static gboolean click_cb(GtkWidget * widget,
 {
        MainWindow *mainwin;
 
-/*
        mainwin = mainwindow_get_mainwindow();
        if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
-               gtk_widget_hide_all(mainwin->window);
+               main_window_hide(mainwin);
        } else {
-               gtk_widget_show_all(mainwin->window);
+               main_window_show(mainwin);
         }
-*/
        return TRUE;
 }
 
@@ -125,18 +125,22 @@ static void resize_cb(GtkWidget *widget, GtkAllocation *allocation)
        update();
 }
 
-int plugin_init(gchar **error)
+static void create_trayicon(void);
+
+static void destroy_cb(GtkWidget *widget, gpointer *data)
 {
-       GtkPacker *packer;
+       debug_print("Widget destroyed\n");
 
-       hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, folder_item_update_hook, NULL);
-       if (hook_id == -1) {
-               *error = g_strdup("Failed to register folder item update hook");
-               return -1;
-       }
+       create_trayicon();
+}
+
+static void create_trayicon()
+{
+       GtkPacker *packer;
 
         trayicon = egg_tray_icon_new("Sylpheed-Claws");
-/*        trayicon = gtk_window_new(GTK_WINDOW_TOPLEVEL); */
+//        trayicon = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       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);
 
@@ -155,8 +159,13 @@ int plugin_init(gchar **error)
         image = gtk_pixmap_new(nomail_pixmap, nomail_bitmap);
         gtk_packer_add_defaults(GTK_PACKER(packer), GTK_WIDGET(image), GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_PACK_EXPAND);
 
-       gtk_signal_connect(GTK_OBJECT(trayicon), "size_allocate", GTK_SIGNAL_FUNC(resize_cb), NULL);
-        gtk_signal_connect(GTK_OBJECT(eventbox), "button-press-event", GTK_SIGNAL_FUNC(click_cb), NULL);
+       destroy_signal_id =
+       gtk_signal_connect(GTK_OBJECT(trayicon), "destroy",
+                     GTK_SIGNAL_FUNC(destroy_cb), NULL);
+       gtk_signal_connect(GTK_OBJECT(trayicon), "size_allocate",
+                   GTK_SIGNAL_FUNC(resize_cb), NULL);
+       gtk_signal_connect(GTK_OBJECT(eventbox), "button-press-event",
+                   GTK_SIGNAL_FUNC(click_cb), NULL);
 
         tooltips = gtk_tooltips_new();
         gtk_tooltips_set_delay(tooltips, 1000);
@@ -165,12 +174,25 @@ int plugin_init(gchar **error)
         gtk_widget_show_all(GTK_WIDGET(trayicon));
 
        update();
+}
+
+int plugin_init(gchar **error)
+{
+       hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, folder_item_update_hook, NULL);
+       if (hook_id == -1) {
+               *error = g_strdup("Failed to register folder item update hook");
+               return -1;
+       }
+
+       create_trayicon();
 
         return 0;
 }
 
 void plugin_done(void)
 {
+       gtk_signal_disconnect(GTK_OBJECT(trayicon), destroy_signal_id);
+
        gtk_widget_destroy(GTK_WIDGET(trayicon));
        hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, hook_id);
 }