1 /* $Id$ */
2 /* Copyright (c) 2011-2015 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Phone */
4 /* This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16
17
18 #include <System.h>
19 #include <Desktop.h>
20 #ifdef DEBUG
21 # include <stdio.h>
22 #endif
23 #include <gtk/gtk.h>
24 #include "Phone.h"
25 #include "../../config.h"
26
27
28 /* Systray */
29 /* private */
30 /* types */
31 typedef struct _PhonePlugin
32 {
33 PhonePluginHelper * helper;
34 GtkStatusIcon * icon;
35 GtkWidget * ab_window;
36 } Systray;
37
38
39 /* prototypes */
40 /* plug-in */
41 static Systray * _systray_init(PhonePluginHelper * helper);
42 static void _systray_destroy(Systray * systray);
43
44 /* callbacks */
45 #if GTK_CHECK_VERSION(2, 10, 0)
46 static void _systray_on_activate(gpointer data);
47 static void _systray_on_popup_menu(GtkStatusIcon * icon, guint button,
48 guint time, gpointer data);
49 #endif
50
51
52 /* public */
53 /* variables */
54 PhonePluginDefinition plugin =
55 {
56 "System tray",
57 "gnome-monitor",
58 NULL,
59 _systray_init,
60 _systray_destroy,
61 NULL,
62 NULL
63 };
64
65
66 /* private */
67 /* functions */
68 /* systray_init */
_systray_init(PhonePluginHelper * helper)69 static Systray * _systray_init(PhonePluginHelper * helper)
70 {
71 Systray * systray;
72
73 #ifdef DEBUG
74 fprintf(stderr, "DEBUG: %s()\n", __func__);
75 #endif
76 #if GTK_CHECK_VERSION(2, 10, 0)
77 if((systray = object_new(sizeof(*systray))) == NULL)
78 return NULL;
79 systray->helper = helper;
80 systray->icon = gtk_status_icon_new_from_icon_name("call-start");
81 # if GTK_CHECK_VERSION(2, 16, 0)
82 gtk_status_icon_set_tooltip_text(systray->icon, "Phone");
83 # endif
84 g_signal_connect_swapped(systray->icon, "activate", G_CALLBACK(
85 _systray_on_activate), systray);
86 g_signal_connect(systray->icon, "popup-menu", G_CALLBACK(
87 _systray_on_popup_menu), systray);
88 systray->ab_window = NULL;
89 return systray;
90 #else
91 return NULL;
92 #endif
93 }
94
95
96 /* systray_destroy */
_systray_destroy(Systray * systray)97 static void _systray_destroy(Systray * systray)
98 {
99 g_object_unref(systray->icon);
100 object_delete(systray);
101 }
102
103
104 #if GTK_CHECK_VERSION(2, 10, 0)
105 /* callbacks */
106 /* systray_on_activate */
_systray_on_activate(gpointer data)107 static void _systray_on_activate(gpointer data)
108 {
109 Systray * systray = data;
110 PhonePluginHelper * helper = systray->helper;
111
112 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
113 PHONE_MESSAGE_SHOW_DIALER);
114 }
115
116
117 /* systray_on_popup_menu */
118 static void _popup_menu_on_show_contacts(gpointer data);
119 static void _popup_menu_on_show_dialer(gpointer data);
120 static void _popup_menu_on_show_logs(gpointer data);
121 static void _popup_menu_on_show_messages(gpointer data);
122 static void _popup_menu_on_show_write(gpointer data);
123 static void _popup_menu_on_show_settings(gpointer data);
124 static void _popup_menu_on_resume(gpointer data);
125 static void _popup_menu_on_suspend(gpointer data);
126 static void _popup_menu_on_contents(gpointer data);
127 static void _popup_menu_on_show_about(gpointer data);
128 static void _popup_menu_on_quit(gpointer data);
129
_systray_on_popup_menu(GtkStatusIcon * icon,guint button,guint time,gpointer data)130 static void _systray_on_popup_menu(GtkStatusIcon * icon, guint button,
131 guint time, gpointer data)
132 {
133 Systray * systray = data;
134 GtkWidget * menu;
135 GtkWidget * menuitem;
136 GtkWidget * image;
137 struct
138 {
139 char const * icon;
140 char const * name;
141 void (*callback)(gpointer data);
142 } items[] = {
143 { "stock_addressbook", "Show _contacts",
144 _popup_menu_on_show_contacts },
145 { "call-start", "Show _dialer", _popup_menu_on_show_dialer },
146 { "gnome-monitor", "Show _logs", _popup_menu_on_show_logs },
147 { "stock_mail-compose", "Show _messages",
148 _popup_menu_on_show_messages },
149 { "stock_mail-compose", "_Write a message",
150 _popup_menu_on_show_write },
151 { NULL, NULL, NULL },
152 { "gtk-preferences", "_Preferences",
153 _popup_menu_on_show_settings },
154 { NULL, NULL, NULL },
155 { "gtk-media-play-ltr", "_Resume telephony",
156 _popup_menu_on_resume },
157 { "gtk-media-pause", "S_uspend telephony",
158 _popup_menu_on_suspend },
159 { NULL, NULL, NULL },
160 { "help-contents", "_Help contents", _popup_menu_on_contents },
161 #if GTK_CHECK_VERSION(2, 6, 0)
162 { GTK_STOCK_ABOUT, "_About", _popup_menu_on_show_about },
163 #else
164 { NULL, "_About", _popup_menu_on_show_about },
165 #endif
166 { NULL, NULL, NULL },
167 { "gtk-quit", "_Quit", _popup_menu_on_quit },
168 };
169 size_t i;
170
171 menu = gtk_menu_new();
172 for(i = 0; i < sizeof(items) / sizeof(*items); i++)
173 {
174 if(items[i].name == NULL)
175 {
176 menuitem = gtk_separator_menu_item_new();
177 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
178 continue;
179 }
180 menuitem = gtk_image_menu_item_new_with_mnemonic(items[i].name);
181 if(items[i].icon != NULL)
182 {
183 image = gtk_image_new_from_icon_name(items[i].icon,
184 GTK_ICON_SIZE_MENU);
185 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(
186 menuitem), image);
187 }
188 g_signal_connect_swapped(menuitem, "activate", G_CALLBACK(
189 items[i].callback), systray);
190 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
191 }
192 gtk_widget_show_all(menu);
193 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time);
194 }
195
_popup_menu_on_contents(gpointer data)196 static void _popup_menu_on_contents(gpointer data)
197 {
198 desktop_help_contents(PACKAGE, "phone");
199 }
200
_popup_menu_on_show_about(gpointer data)201 static void _popup_menu_on_show_about(gpointer data)
202 {
203 Systray * systray = data;
204 PhonePluginHelper * helper = systray->helper;
205
206 helper->about_dialog(helper->phone);
207 }
208
_popup_menu_on_show_contacts(gpointer data)209 static void _popup_menu_on_show_contacts(gpointer data)
210 {
211 Systray * systray = data;
212 PhonePluginHelper * helper = systray->helper;
213
214 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
215 PHONE_MESSAGE_SHOW_CONTACTS);
216 }
217
_popup_menu_on_show_dialer(gpointer data)218 static void _popup_menu_on_show_dialer(gpointer data)
219 {
220 Systray * systray = data;
221 PhonePluginHelper * helper = systray->helper;
222
223 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
224 PHONE_MESSAGE_SHOW_DIALER);
225 }
226
_popup_menu_on_show_logs(gpointer data)227 static void _popup_menu_on_show_logs(gpointer data)
228 {
229 Systray * systray = data;
230 PhonePluginHelper * helper = systray->helper;
231
232 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
233 PHONE_MESSAGE_SHOW_LOGS);
234 }
235
_popup_menu_on_show_messages(gpointer data)236 static void _popup_menu_on_show_messages(gpointer data)
237 {
238 Systray * systray = data;
239 PhonePluginHelper * helper = systray->helper;
240
241 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
242 PHONE_MESSAGE_SHOW_MESSAGES);
243 }
244
_popup_menu_on_show_settings(gpointer data)245 static void _popup_menu_on_show_settings(gpointer data)
246 {
247 Systray * systray = data;
248 PhonePluginHelper * helper = systray->helper;
249
250 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
251 PHONE_MESSAGE_SHOW_SETTINGS);
252 }
253
_popup_menu_on_show_write(gpointer data)254 static void _popup_menu_on_show_write(gpointer data)
255 {
256 Systray * systray = data;
257 PhonePluginHelper * helper = systray->helper;
258
259 helper->message(helper->phone, PHONE_MESSAGE_SHOW,
260 PHONE_MESSAGE_SHOW_WRITE);
261 }
262
_popup_menu_on_resume(gpointer data)263 static void _popup_menu_on_resume(gpointer data)
264 {
265 Systray * systray = data;
266 PhonePluginHelper * helper = systray->helper;
267
268 helper->message(helper->phone, PHONE_MESSAGE_POWER_MANAGEMENT,
269 PHONE_MESSAGE_POWER_MANAGEMENT_RESUME);
270 }
271
_popup_menu_on_suspend(gpointer data)272 static void _popup_menu_on_suspend(gpointer data)
273 {
274 Systray * systray = data;
275 PhonePluginHelper * helper = systray->helper;
276
277 helper->message(helper->phone, PHONE_MESSAGE_POWER_MANAGEMENT,
278 PHONE_MESSAGE_POWER_MANAGEMENT_SUSPEND);
279 }
280
_popup_menu_on_quit(gpointer data)281 static void _popup_menu_on_quit(gpointer data)
282 {
283 gtk_main_quit();
284 }
285 #endif
286