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.
28 #include "mainwindow.h"
32 #include "eggtrayicon.h"
33 #include "newmail.xpm"
34 #include "unreadmail.xpm"
39 static GdkPixmap *newmail_pixmap;
40 static GdkPixmap *newmail_bitmap;
41 static GdkPixmap *unreadmail_pixmap;
42 static GdkPixmap *unreadmail_bitmap;
43 static GdkPixmap *nomail_pixmap;
44 static GdkPixmap *nomail_bitmap;
46 static EggTrayIcon *trayicon;
47 static GtkWidget *eventbox;
48 static GtkWidget *image;
49 static GtkTooltips *tooltips;
55 TRAYICON_UNREADMARKED,
59 /* static gboolean mainwin_hidden = FALSE; */
61 static void set_trayicon_pixmap(TrayIconType icontype)
63 GdkPixmap *pixmap = NULL;
64 GdkBitmap *bitmap = NULL;
68 pixmap = newmail_pixmap;
69 bitmap = newmail_bitmap;
72 case TRAYICON_UNREADMARKED:
73 pixmap = unreadmail_pixmap;
74 bitmap = unreadmail_bitmap;
77 pixmap = nomail_pixmap;
78 bitmap = nomail_bitmap;
82 gtk_pixmap_set(GTK_PIXMAP(image), pixmap, bitmap);
83 gtk_widget_shape_combine_mask(GTK_WIDGET(trayicon), bitmap, GTK_WIDGET(image)->allocation.x, GTK_WIDGET(image)->allocation.y);
86 static void update(void)
88 gint new, unread, unreadmarked, total;
91 folder_count_total_msgs(&new, &unread, &unreadmarked, &total);
92 buf = g_strdup_printf("New %d, Unread: %d, Total: %d", new, unread, total);
94 gtk_tooltips_set_tip(tooltips, eventbox, buf, "");
97 set_trayicon_pixmap(new > 0 ? TRAYICON_NEW : (unread > 0 ? TRAYICON_UNREAD : TRAYICON_NOTHING));
100 static gboolean folder_item_update_hook(gpointer source, gpointer data)
107 static gboolean click_cb(GtkWidget * widget,
108 GdkEventButton * event, gpointer user_data)
113 mainwin = mainwindow_get_mainwindow();
114 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window))) {
115 gtk_widget_hide_all(mainwin->window);
117 gtk_widget_show_all(mainwin->window);
123 static void resize_cb(GtkWidget *widget, GtkAllocation *allocation)
128 int plugin_init(gchar **error)
132 hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST, folder_item_update_hook, NULL);
134 *error = g_strdup("Failed to register folder item update hook");
138 trayicon = egg_tray_icon_new("Sylpheed-Claws");
139 /* trayicon = gtk_window_new(GTK_WINDOW_TOPLEVEL); */
140 gtk_window_set_default_size(GTK_WINDOW(trayicon), 16, 16);
141 gtk_container_set_border_width(GTK_CONTAINER(trayicon), 0);
143 PIXMAP_CREATE(GTK_WIDGET(trayicon), nomail_pixmap, nomail_bitmap, nomail_xpm);
144 PIXMAP_CREATE(GTK_WIDGET(trayicon), unreadmail_pixmap, unreadmail_bitmap, unreadmail_xpm);
145 PIXMAP_CREATE(GTK_WIDGET(trayicon), newmail_pixmap, newmail_bitmap, newmail_xpm);
147 eventbox = gtk_event_box_new();
148 gtk_container_set_border_width(GTK_CONTAINER(eventbox), 0);
149 gtk_container_add(GTK_CONTAINER(trayicon), GTK_WIDGET(eventbox));
151 packer = GTK_PACKER(gtk_packer_new());
152 gtk_container_add(GTK_CONTAINER(eventbox), GTK_WIDGET(packer));
153 gtk_container_set_border_width(GTK_CONTAINER(packer), 0);
155 image = gtk_pixmap_new(nomail_pixmap, nomail_bitmap);
156 gtk_packer_add_defaults(GTK_PACKER(packer), GTK_WIDGET(image), GTK_SIDE_TOP, GTK_ANCHOR_CENTER, GTK_PACK_EXPAND);
158 gtk_signal_connect(GTK_OBJECT(trayicon), "size_allocate", GTK_SIGNAL_FUNC(resize_cb), NULL);
159 gtk_signal_connect(GTK_OBJECT(eventbox), "button-press-event", GTK_SIGNAL_FUNC(click_cb), NULL);
161 tooltips = gtk_tooltips_new();
162 gtk_tooltips_set_delay(tooltips, 1000);
163 gtk_tooltips_enable(tooltips);
165 gtk_widget_show_all(GTK_WIDGET(trayicon));
172 void plugin_done(void)
174 gtk_widget_destroy(GTK_WIDGET(trayicon));
175 hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, hook_id);
178 const gchar *plugin_name(void)
180 return _("Trayicon");
183 const gchar *plugin_desc(void)
185 return _("This plugin places a mailbox icon in the system tray that "
186 "indicates if you have new or unread mail.\n"
188 "The mailbox is empty if you have no unread mail, otherwise "
189 "it contains a letter. A tooltip shows new, unread and total "
190 "number of messages.");
193 const gchar *plugin_type(void)