1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2006 Hiroyuki Yamamoto
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkeventbox.h>
#include <gtk/gtktooltips.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkmenuitem.h>
#include "eggtrayicon.h"
#include "trayicon.h"
#include "mainwindow.h"
#include "utils.h"
#include "gtkutils.h"
#include "eggtrayicon.h"
#include "stock_pixmap.h"
#include "menu.h"
#include "main.h"
#include "inc.h"
#include "compose.h"
#include "about.h"
#ifdef GDK_WINDOWING_X11
static GtkWidget *trayicon;
static GtkWidget *trayicon_img;
static GtkWidget *eventbox;
static GtkTooltips *trayicon_tip;
static GtkWidget *trayicon_menu;
static gboolean default_tooltip = FALSE;
static void trayicon_button_pressed (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
static void trayicon_destroy_cb (GtkWidget *widget,
gpointer data);
static void trayicon_inc (GtkWidget *widget,
gpointer data);
static void trayicon_inc_all (GtkWidget *widget,
gpointer data);
static void trayicon_send (GtkWidget *widget,
gpointer data);
static void trayicon_compose (GtkWidget *widget,
gpointer data);
static void trayicon_about (GtkWidget *widget,
gpointer data);
static void trayicon_app_exit (GtkWidget *widget,
gpointer data);
GtkWidget *trayicon_create(MainWindow *mainwin)
{
GtkWidget *menuitem;
trayicon = GTK_WIDGET(egg_tray_icon_new("Sylpheed"));
g_signal_connect(G_OBJECT(trayicon), "destroy",
G_CALLBACK(trayicon_destroy_cb), mainwin);
eventbox = gtk_event_box_new();
gtk_widget_show(eventbox);
gtk_container_add(GTK_CONTAINER(trayicon), eventbox);
g_signal_connect(G_OBJECT(eventbox), "button_press_event",
G_CALLBACK(trayicon_button_pressed), mainwin);
trayicon_img = stock_pixbuf_widget_scale(NULL, STOCK_PIXMAP_SYLPHEED,
24, 24);
gtk_widget_show(trayicon_img);
gtk_container_add(GTK_CONTAINER(eventbox), trayicon_img);
default_tooltip = FALSE;
trayicon_tip = gtk_tooltips_new();
trayicon_set_tooltip(NULL);
if (!trayicon_menu) {
trayicon_menu = gtk_menu_new();
gtk_widget_show(trayicon_menu);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("Get from _current account"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_inc), mainwin);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("Get from _all accounts"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_inc_all), mainwin);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("_Send queued messages"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_send), mainwin);
MENUITEM_ADD(trayicon_menu, menuitem, NULL, 0);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("Compose _new message"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_compose), mainwin);
MENUITEM_ADD(trayicon_menu, menuitem, NULL, 0);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("_About"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_about), NULL);
MENUITEM_ADD_WITH_MNEMONIC(trayicon_menu, menuitem,
_("E_xit"), 0);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(trayicon_app_exit), mainwin);
}
return trayicon;
}
void trayicon_set_tooltip(const gchar *text)
{
if (text) {
default_tooltip = FALSE;
gtk_tooltips_set_tip(trayicon_tip, trayicon, text, NULL);
} else if (!default_tooltip) {
default_tooltip = TRUE;
gtk_tooltips_set_tip(trayicon_tip, trayicon, _("Sylpheed"),
NULL);
}
}
void trayicon_set_stock_icon(StockPixmap icon)
{
GdkPixbuf *pixbuf;
GdkPixbuf *scaled_pixbuf;
stock_pixbuf_gdk(NULL, icon, &pixbuf);
scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf, 24, 24,
GDK_INTERP_HYPER);
gtk_image_set_from_pixbuf(GTK_IMAGE(trayicon_img), scaled_pixbuf);
g_object_unref(scaled_pixbuf);
}
static void trayicon_button_pressed(GtkWidget *widget, GdkEventButton *event,
gpointer data)
{
MainWindow *mainwin = (MainWindow *)data;
GtkWindow *window = GTK_WINDOW(mainwin->window);
if (!event)
return;
if (event->button == 1) {
if (mainwin->window_hidden || mainwin->window_obscured) {
gtk_window_set_skip_taskbar_hint(window, FALSE);
gtk_window_present(window);
/* window may be obscured by always-on-top windows */
mainwin->window_obscured = FALSE;
} else {
gtk_window_iconify(window);
gtk_window_set_skip_taskbar_hint(window, TRUE);
}
} else if (event->button == 3) {
gtk_menu_popup(GTK_MENU(trayicon_menu), NULL, NULL, NULL, NULL,
event->button, event->time);
}
}
static gboolean trayicon_restore(gpointer data)
{
MainWindow *mainwin = (MainWindow *)data;
mainwin->tray_icon = trayicon_create(mainwin);
return FALSE;
}
static void trayicon_destroy_cb(GtkWidget *widget, gpointer data)
{
g_idle_add(trayicon_restore, data);
}
static void trayicon_inc(GtkWidget *widget, gpointer data)
{
if (!inc_is_active() && !gtkut_window_modal_exist())
inc_mail((MainWindow *)data);
}
static void trayicon_inc_all(GtkWidget *widget, gpointer data)
{
if (!inc_is_active() && !gtkut_window_modal_exist())
inc_all_account_mail((MainWindow *)data, FALSE);
}
static void trayicon_send(GtkWidget *widget, gpointer data)
{
if (!gtkut_window_modal_exist())
main_window_send_queue((MainWindow *)data);
}
static void trayicon_compose(GtkWidget *widget, gpointer data)
{
if (!gtkut_window_modal_exist())
compose_new(NULL, NULL, NULL, NULL);
}
static void trayicon_about(GtkWidget *widget, gpointer data)
{
if (!gtkut_window_modal_exist())
about_show();
}
static void trayicon_app_exit(GtkWidget *widget, gpointer data)
{
MainWindow *mainwin = (MainWindow *)data;
if (mainwin->lock_count == 0 && !gtkut_window_modal_exist())
app_will_exit(FALSE);
}
#else /* GDK_WINDOWING_X11 */
GtkWidget *trayicon_create(MainWindow *mainwin)
{
return NULL;
}
void trayicon_set_tooltip(const gchar *text)
{
}
void trayicon_set_stock_icon(StockPixmap icon)
{
}
#endif /* GDK_WINDOWING_X11 */
|