2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws Team
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 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "mainwindow.h"
33 #include "eggtrayicon.h"
34 #include "newmail.xpm"
35 #include "unreadmail.xpm"
40 static GdkPixmap *newmail_pixmap;
41 static GdkPixmap *newmail_bitmap;
42 static GdkPixmap *unreadmail_pixmap;
43 static GdkPixmap *unreadmail_bitmap;
44 static GdkPixmap *nomail_pixmap;
45 static GdkPixmap *nomail_bitmap;
47 static EggTrayIcon *trayicon;
48 static GtkWidget *eventbox;
49 static GtkWidget *image;
50 static GtkTooltips *tooltips;
51 guint destroy_signal_id;
57 TRAYICON_UNREADMARKED,
61 /* static gboolean mainwin_hidden = FALSE; */
63 static void set_trayicon_pixmap(TrayIconType icontype)
65 GdkPixmap *pixmap = NULL;
66 GdkBitmap *bitmap = NULL;
70 pixmap = newmail_pixmap;
71 bitmap = newmail_bitmap;
74 case TRAYICON_UNREADMARKED:
75 pixmap = unreadmail_pixmap;
76 bitmap = unreadmail_bitmap;
79 pixmap = nomail_pixmap;
80 bitmap = nomail_bitmap;
84 gtk_pixmap_set(GTK_PIXMAP(image), pixmap, bitmap);
85 gtk_widget_shape_combine_mask(GTK_WIDGET(trayicon), bitmap, GTK_WIDGET(image)->allocation.x, GTK_WIDGET(image)->allocation.y);
88 static void update(void)
90 gint new, unread, unreadmarked, total;
93 folder_count_total_msgs(&new, &unread, &unreadmarked, &total);
94 buf = g_strdup_printf("New %d, Unread: %d, Total: %d", new, unread, total);
96 gtk_tooltips_set_tip(tooltips, eventbox, buf, "");
99 set_trayicon_pixmap(new > 0 ? TRAYICON_NEW : (unread > 0 ? TRAYICON_UNREAD : TRAYICON_NOTHING));
102 static gboolean folder_item_update_hook(gpointer source, gpointer data)
109 static gboolean click_cb(GtkWidget * widget,
110 GdkEventButton * event, gpointer user_data)
114 mainwin = mainwindow_get_mainwindow();
115 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
116 main_window_hide(mainwin);
118 main_window_show(mainwin);
123 static void resize_cb(GtkWidget *widget, GtkAllocation *allocation)
128 static void create_trayicon(void);
130 static void destroy_cb(GtkWidget *widget, gpointer *data)
132 debug_print("Widget destroyed\n");
137 static void create_trayicon()
141 trayicon = egg_tray_icon_new("Sylpheed-Claws");
142 // trayicon = gtk_window_new(GTK_WINDOW_TOPLEVEL);
143 gtk_widget_realize(GTK_WIDGET(trayicon));
144 gtk_window_set_default_size(GTK_WINDOW(trayicon), 16, 16);
145 gtk_container_set_border_width(GTK_CONTAINER(trayicon), 0);
147 PIXMAP_CREATE(GTK_WIDGET(trayicon), nomail_pixmap, nomail_bitmap, nomail_xpm);
148 PIXMAP_CREATE(GTK_WIDGET(trayicon), unreadmail_pixmap, unreadmail_bitmap, unreadmail_xpm);
149 PIXMAP_CREATE(GTK_WIDGET(trayicon), newmail_pixmap, newmail_bitmap, newmail_xpm);
151 eventbox = gtk_event_box_new();
152 gtk_container_set_border_width(GTK_CONTAINER(eventbox), 0);
153 gtk_container_add(GTK_CONTAINER(trayicon), GTK_WIDGET(eventbox));
155 packer = GTK_PACKER(gtk_packer_new());
156 gtk_container_add(GTK_CONTAINER(eventbox), GTK_WIDGET(packer));
157 gtk_container_set_border_width(GTK_CONTAINER(packer), 0);
159 image = gtk_pixmap_new(nomail_pixmap, nomail_bitmap);
160 gtk_packer_add_defaults(GTK_PACKER(packer), GTK_WIDGET(image), GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_PACK_EXPAND);
163 gtk_signal_connect(GTK_OBJECT(trayicon), "destroy",
164 GTK_SIGNAL_FUNC(destroy_cb), NULL);
165 gtk_signal_connect(GTK_OBJECT(trayicon), "size_allocate",
166 GTK_SIGNAL_FUNC(resize_cb), NULL);
167 gtk_signal_connect(GTK_OBJECT(eventbox), "button-press-event",
168 GTK_SIGNAL_FUNC(click_cb), NULL);
170 tooltips = gtk_tooltips_new();
171 gtk_tooltips_set_delay(tooltips, 1000);
172 gtk_tooltips_enable(tooltips);
174 gtk_widget_show_all(GTK_WIDGET(trayicon));
179 int plugin_init(gchar **error)
181 hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, folder_item_update_hook, NULL);
183 *error = g_strdup("Failed to register folder item update hook");
192 void plugin_done(void)
194 gtk_signal_disconnect(GTK_OBJECT(trayicon), destroy_signal_id);
196 gtk_widget_destroy(GTK_WIDGET(trayicon));
197 hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, hook_id);
200 const gchar *plugin_name(void)
202 return _("Trayicon");
205 const gchar *plugin_desc(void)
207 return _("This plugin places a mailbox icon in the system tray that "
208 "indicates if you have new or unread mail.\n"
210 "The mailbox is empty if you have no unread mail, otherwise "
211 "it contains a letter. A tooltip shows new, unread and total "
212 "number of messages.");
215 const gchar *plugin_type(void)