Statistics
| Revision:

root / src / trayicon.c @ 982

History | View | Annotate | Download (6.7 kB)

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