8d5561ef72c0325bfb6e28640568250cf5b0f3e1
[claws.git] / src / plugins / notification / notification_prefs.c
1 /* Notification plugin for Claws-Mail
2  * Copyright (C) 2005-2015 Hiroyuki Yamamoto and the Claws Mail team
3  * Copyright (C) 2005-2015 Holger Berndt
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 3 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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #  include "config.h"
21 #  include "claws-features.h"
22 #endif
23
24 #include <glib.h>
25 #include <glib/gi18n.h>
26
27 #include <math.h>
28
29 #include "prefs_gtk.h"
30 #include "common/prefs.h"
31 #include "common/utils.h"
32 #include "common/defs.h"
33 #include "gtk/gtkutils.h"
34 #include "gtk/filesel.h"
35 #include "main.h"
36
37 #include "notification_prefs.h"
38 #include "notification_plugin.h"
39 #include "notification_core.h"
40
41 #include "notification_popup.h"
42 #include "notification_command.h"
43 #include "notification_lcdproc.h"
44 #include "notification_trayicon.h"
45 #include "notification_indicator.h"
46 #include "notification_hotkeys.h"
47
48 #include "notification_foldercheck.h"
49
50 #ifdef HAVE_LIBNOTIFY
51 /* allow infinite timeout with libnotify */
52 # define TIMEOUT_SPINNER_MIN     0.0
53 #else
54 /* don't allow infinite timeout with self-handled popups */
55 # define TIMEOUT_SPINNER_MIN     0.2
56 #endif
57
58 #define TIMEOUT_SPINNER_MAX  3600.0
59 #define TIMEOUT_SPINNER_STEP    0.5
60
61 typedef struct
62 {
63         PrefsPage page;
64         GtkWidget *include_mail;
65         GtkWidget *include_news;
66         GtkWidget *include_rss;
67         GtkWidget *include_calendar;
68         GtkWidget *urgency_hint_new;
69         GtkWidget *urgency_hint_unread;
70 #ifdef HAVE_LIBCANBERRA_GTK
71         GtkWidget *canberra_play_sounds;
72 #endif
73 } NotifyPage;
74
75 NotifyPrefs notify_config;
76 NotifyPage notify_page;
77
78 #ifdef NOTIFICATION_BANNER
79 typedef struct {
80         PrefsPage page;
81         GtkWidget *banner_show;
82         GtkWidget *banner_speed;
83         GtkWidget *banner_width;
84         GtkWidget *banner_include_unread;
85         GtkWidget *banner_max_msgs;
86         GtkWidget *banner_sticky;
87         GtkWidget *banner_folder_specific;
88         GtkWidget *banner_enable_colors;
89         GtkWidget *banner_color_bg;
90         GtkWidget *banner_color_fg;
91         GtkWidget *banner_cont_enable;
92         GtkWidget *banner_cont_folder_specific;
93         GtkWidget *banner_cont_color_sel;
94 }NotifyBannerPage;
95 NotifyBannerPage banner_page;
96 #endif /* NOTIFICATION_BANNER */
97
98 #ifdef NOTIFICATION_POPUP
99 typedef struct {
100         PrefsPage page;
101         GtkWidget *popup_show;
102         GtkWidget *popup_timeout;
103         GtkWidget *popup_folder_specific;
104         GtkWidget *popup_cont_enable;
105         GtkWidget *popup_cont_folder_specific;
106 #ifndef HAVE_LIBNOTIFY
107         GtkWidget *popup_sticky;
108         GtkWidget *popup_enable_colors;
109         GtkWidget *popup_color_bg;
110         GtkWidget *popup_color_fg;
111         GtkWidget *popup_cont_color_sel;
112 #else /* HAVE_LIBNOTIFY */
113         GtkWidget *popup_display_folder_name;
114 #endif /* HAVE_LIBNOTIFY */
115 }NotifyPopupPage;
116 NotifyPopupPage popup_page;
117 #endif /* NOTIFICATION_POPUP */
118
119 #ifdef NOTIFICATION_COMMAND
120 typedef struct {
121         PrefsPage page;
122         GtkWidget *command_enabled;
123         GtkWidget *command_timeout;
124         GtkWidget *command_folder_specific;
125         GtkWidget *command_line;
126         GtkWidget *command_cont_enable;
127         GtkWidget *command_cont_folder_specific;
128 }NotifyCommandPage;
129 NotifyCommandPage command_page;
130 #endif /* NOTIFICATION_COMMAND */
131
132 #ifdef NOTIFICATION_LCDPROC
133 typedef struct {
134         PrefsPage page;
135         GtkWidget *lcdproc_enabled;
136         GtkWidget *lcdproc_cont_enable;
137         GtkWidget *lcdproc_hostname;
138         GtkWidget *lcdproc_port;
139 }NotifyLCDProcPage;
140 NotifyLCDProcPage lcdproc_page;
141 #endif
142
143 #ifdef NOTIFICATION_TRAYICON
144 typedef struct {
145         PrefsPage page;
146         GtkWidget *trayicon_enabled;
147         GtkWidget *trayicon_cont_enable;
148         GtkWidget *trayicon_hide_at_startup;
149         GtkWidget *trayicon_close_to_tray;
150         GtkWidget *trayicon_hide_when_iconified;
151         GtkWidget *trayicon_folder_specific;
152         GtkWidget *trayicon_cont_folder_specific;
153 #ifdef HAVE_LIBNOTIFY
154         GtkWidget *trayicon_display_folder_name;
155         GtkWidget *trayicon_popup_enabled;
156         GtkWidget *trayicon_popup_cont_enable;
157         GtkWidget *trayicon_popup_timeout;
158 #endif
159 }NotifyTrayiconPage;
160 NotifyTrayiconPage trayicon_page;
161 #endif
162
163 #ifdef NOTIFICATION_INDICATOR
164 typedef struct {
165         PrefsPage page;
166         GtkWidget *indicator_enabled;
167         GtkWidget *indicator_cont_enable;
168         GtkWidget *indicator_hide_minimized;
169 }NotifyIndicatorPage;
170 NotifyIndicatorPage indicator_page;
171 #endif
172
173 #ifdef NOTIFICATION_HOTKEYS
174 typedef struct {
175     PrefsPage page;
176     GtkWidget *hotkeys_enabled;
177     GtkWidget *hotkeys_cont_enable;
178     GtkWidget *hotkeys_toggle_mainwindow;
179 }NotifyHotkeysPage;
180 NotifyHotkeysPage hotkeys_page;
181 #endif
182
183
184 PrefParam
185                 notify_param[] =
186                 {
187
188                                 { "include_mail", "TRUE", &notify_config.include_mail, P_BOOL, NULL,
189                                                 NULL, NULL },
190                                 { "include_news", "TRUE", &notify_config.include_news, P_BOOL, NULL,
191                                                 NULL, NULL },
192                                 { "include_rss", "TRUE", &notify_config.include_rss, P_BOOL, NULL,
193                                                 NULL, NULL },
194                                 { "include_calendar", "TRUE", &notify_config.include_calendar, P_BOOL,
195                                                 NULL, NULL, NULL },
196                                 { "urgency_hint_new", "FALSE", &notify_config.urgency_hint_new, P_BOOL,
197                                                 NULL, NULL, NULL },
198                                 { "urgency_hint_unread", "FALSE", &notify_config.urgency_hint_unread, P_BOOL,
199                                                 NULL, NULL, NULL },
200
201 #ifdef HAVE_LIBCANBERRA_GTK
202                 { "canberra_play_sounds", "TRUE", &notify_config.canberra_play_sounds, P_BOOL,
203                         NULL, NULL, NULL },
204 #endif
205
206 #ifdef NOTIFICATION_BANNER
207                                 {       "banner_show", "0", &notify_config.banner_show, P_INT, NULL, NULL, NULL},
208                                 {       "banner_speed", "30", &notify_config.banner_speed, P_INT, NULL, NULL, NULL},
209                                 {       "banner_width", "0", &notify_config.banner_width, P_INT, NULL, NULL, NULL},
210                                 {       "banner_include_unread", "FALSE", &notify_config.banner_include_unread,
211                                         P_BOOL, NULL, NULL, NULL},
212                                 {       "banner_max_msgs", "100", &notify_config.banner_max_msgs, P_INT,
213                                         NULL, NULL, NULL},
214                                 {       "banner_sticky", "FALSE", &notify_config.banner_sticky,
215                                         P_BOOL, NULL, NULL, NULL},
216                                 {       "banner_root_x", "0", &notify_config.banner_root_x, P_INT,
217                                         NULL, NULL, NULL},
218                                 {       "banner_root_y", "10", &notify_config.banner_root_y, P_INT,
219                                         NULL, NULL, NULL},
220                                 {       "banner_folder_specific", "FALSE", &notify_config.banner_folder_specific,
221                                         P_BOOL, NULL, NULL, NULL},
222                                 {       "banner_enable_colors", "FALSE", &notify_config.banner_enable_colors,
223                                         P_BOOL, NULL, NULL, NULL},
224                                 {       "banner_color_bg", "0", &notify_config.banner_color_bg, P_COLOR,
225                                         NULL, NULL, NULL},
226                                 {       "banner_color_fg", "16776704", &notify_config.banner_color_fg, P_COLOR,
227                                         NULL, NULL, NULL},
228 #endif
229
230 #ifdef NOTIFICATION_POPUP
231                                 {       "popup_show", "TRUE", &notify_config.popup_show, P_BOOL, NULL, NULL, NULL},
232                                 {       "popup_timeout", "5000", &notify_config.popup_timeout,
233                                         P_INT, NULL, NULL, NULL},
234                                 {       "popup_folder_specific", "FALSE", &notify_config.popup_folder_specific,
235                                         P_BOOL, NULL, NULL, NULL},
236 #ifndef HAVE_LIBNOTIFY
237                                 {       "popup_sticky", "TRUE", &notify_config.popup_sticky, P_BOOL,
238                                         NULL, NULL, NULL},
239                                 {       "popup_root_x", "10", &notify_config.popup_root_x,
240                                         P_INT, NULL, NULL, NULL},
241                                 {       "popup_root_y", "10", &notify_config.popup_root_y,
242                                         P_INT, NULL, NULL, NULL},
243                                 {       "popup_width", "100", &notify_config.popup_width,
244                                         P_INT, NULL, NULL, NULL},
245                                 {       "popup_enable_colors", "FALSE", &notify_config.popup_enable_colors, P_BOOL,
246                                         NULL, NULL, NULL},
247                                 {       "popup_color_bg", "0", &notify_config.popup_color_bg, P_COLOR,
248                                         NULL, NULL, NULL},
249                                 {       "popup_color_fg", "16776704", &notify_config.popup_color_fg, P_COLOR,
250                                         NULL, NULL, NULL},
251 #else /* HAVE_LIBNOTIFY */
252                                 {       "popup_display_folder_name", "FALSE", &notify_config.popup_display_folder_name,
253                                         P_BOOL, NULL, NULL, NULL},
254 #endif /* HAVE_LIBNOTIFY */
255 #endif
256
257 #ifdef NOTIFICATION_COMMAND
258                                 {       "command_enabled", "FALSE", &notify_config.command_enabled, P_BOOL,
259                                         NULL, NULL, NULL},
260                                 {       "command_timeout", "60000", &notify_config.command_timeout, P_INT,
261                                         NULL, NULL, NULL},
262                                 {       "command_folder_specific", "FALSE", &notify_config.command_folder_specific,
263                                         P_BOOL, NULL, NULL, NULL},
264                                 {       "command_line", "", &notify_config.command_line, P_STRING,
265                                         NULL, NULL, NULL},
266 #endif
267
268 #ifdef NOTIFICATION_LCDPROC
269                                 {       "lcdproc_enabled", "FALSE", &notify_config.lcdproc_enabled, P_BOOL,
270                                         NULL, NULL, NULL},
271                                 {       "lcdproc_hostname", "localhost", &notify_config.lcdproc_hostname, P_STRING,
272                                         NULL, NULL, NULL},
273                                 {       "lcdproc_port", "13666", &notify_config.lcdproc_port, P_INT,
274                                         NULL, NULL, NULL},
275 #endif
276
277 #ifdef NOTIFICATION_TRAYICON
278 #ifndef G_OS_WIN32
279                                 {       "trayicon_enabled", "FALSE", &notify_config.trayicon_enabled, P_BOOL,
280                                         NULL, NULL, NULL},
281 #else
282                                 {       "trayicon_enabled", "TRUE", &notify_config.trayicon_enabled, P_BOOL,
283                                         NULL, NULL, NULL},
284 #endif
285                                 {       "trayicon_hide_at_startup", "FALSE",
286                                         &notify_config.trayicon_hide_at_startup, P_BOOL, NULL, NULL, NULL},
287                                 {       "trayicon_close_to_tray", "FALSE",
288                                         &notify_config.trayicon_close_to_tray, P_BOOL, NULL, NULL, NULL},
289                                 {       "trayicon_hide_when_iconified", "FALSE",
290                                         &notify_config.trayicon_hide_when_iconified, P_BOOL, NULL, NULL, NULL},
291                                 {       "trayicon_folder_specific", "FALSE",
292                                         &notify_config.trayicon_folder_specific,
293                                         P_BOOL, NULL, NULL, NULL},
294 #ifdef HAVE_LIBNOTIFY
295                                 {       "trayicon_display_folder_name", "FALSE",
296                                         &notify_config.trayicon_display_folder_name,
297                                         P_BOOL, NULL, NULL, NULL},
298                                 {       "trayicon_popup_enabled", "TRUE", &notify_config.trayicon_popup_enabled,
299                                         P_BOOL, NULL, NULL, NULL},
300                                 {       "trayicon_popup_timeout", "5000", &notify_config.trayicon_popup_timeout,
301                                         P_INT, NULL, NULL, NULL},
302 #endif /* HAVE_LIBNOTIFY */
303 #endif
304
305 #ifdef NOTIFICATION_INDICATOR
306                                 {       "indicator_enabled", "FALSE", &notify_config.indicator_enabled, P_BOOL,
307                                         NULL, NULL, NULL},
308                                 {       "indicator_hide_minimized", "FALSE", &notify_config.indicator_hide_minimized, P_BOOL,
309                                         NULL, NULL, NULL},
310 #endif /* NOTIFICATION_INDICATOR */
311 #ifdef NOTIFICATION_HOTKEYS
312                 {   "hotkeys_enabled", "FALSE", &notify_config.hotkeys_enabled, P_BOOL,
313                     NULL, NULL, NULL},
314                 {   "hotkeys_toggle_mainwindow", "", &notify_config.hotkeys_toggle_mainwindow,
315                     P_STRING, NULL, NULL, NULL},
316 #endif /* NOTIFICATION_HOTKEYS */
317                                 { NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL } };
318
319 static void notify_create_prefs_page(PrefsPage*, GtkWindow*, gpointer);
320 static void notify_destroy_prefs_page(PrefsPage*);
321 static void notify_save_prefs(PrefsPage*);
322
323 #ifdef NOTIFICATION_BANNER
324 static void notify_create_banner_page(PrefsPage*, GtkWindow*, gpointer);
325 static void notify_destroy_banner_page(PrefsPage*);
326 static void notify_save_banner(PrefsPage*);
327 static void notify_banner_enable_set_sensitivity(GtkComboBox*, gpointer);
328 static void notify_banner_color_sel_set_sensitivity(GtkToggleButton*,gpointer);
329 static void notify_banner_folder_specific_set_sensitivity(GtkToggleButton*,
330                 gpointer);
331 #endif
332
333 #ifdef NOTIFICATION_POPUP
334 static void notify_create_popup_page(PrefsPage*, GtkWindow*, gpointer);
335 static void notify_destroy_popup_page(PrefsPage*);
336 static void notify_save_popup(PrefsPage*);
337 static void notify_popup_folder_specific_set_sensitivity(GtkToggleButton*,
338                 gpointer);
339 static void notify_popup_enable_set_sensitivity(GtkToggleButton*, gpointer);
340 #ifndef HAVE_LIBNOTIFY
341 static void notify_popup_set_done_cb(GtkWidget*, gpointer);
342 static void notify_popup_set_cb(GtkWidget*, gpointer);
343 static void notify_popup_color_sel_set_sensitivity(GtkToggleButton*,gpointer);
344 #endif /* !HAVE_LIBNOTIFY */
345 #endif
346
347 #ifdef NOTIFICATION_COMMAND
348 static void notify_command_browse_cb(GtkWidget* widget, gpointer data);
349 static void notify_create_command_page(PrefsPage*, GtkWindow*, gpointer);
350 static void notify_destroy_command_page(PrefsPage*);
351 static void notify_save_command(PrefsPage*);
352 static void notify_command_enable_set_sensitivity(GtkToggleButton*, gpointer);
353 static void notify_command_folder_specific_set_sensitivity(GtkToggleButton*,
354                 gpointer);
355 #endif
356
357 #ifdef NOTIFICATION_LCDPROC
358 static void notify_create_lcdproc_page(PrefsPage*, GtkWindow*, gpointer);
359 static void notify_destroy_lcdproc_page(PrefsPage*);
360 static void notify_save_lcdproc(PrefsPage*);
361 static void notify_lcdproc_enable_set_sensitivity(GtkToggleButton*, gpointer);
362 #endif
363
364 #ifdef NOTIFICATION_TRAYICON
365 static void notify_create_trayicon_page(PrefsPage*, GtkWindow*, gpointer);
366 static void notify_destroy_trayicon_page(PrefsPage*);
367 static void notify_save_trayicon(PrefsPage*);
368 static void notify_trayicon_enable_set_sensitivity(GtkToggleButton*, gpointer);
369 static void notify_trayicon_folder_specific_set_sensitivity(GtkToggleButton*,
370                 gpointer);
371 #ifdef HAVE_LIBNOTIFY
372 static void notify_trayicon_popup_enable_set_sensitivity(GtkToggleButton*,
373                 gpointer);
374 #endif
375 #endif
376
377 #ifdef NOTIFICATION_INDICATOR
378 static void notify_create_indicator_page(PrefsPage*, GtkWindow*, gpointer);
379 static void notify_destroy_indicator_page(PrefsPage*);
380 static void notify_save_indicator(PrefsPage*);
381 static void notify_indicator_enable_set_sensitivity(GtkToggleButton*, gpointer);
382 #endif /* NOTIFICATION_INDICATOR */
383
384 #ifdef NOTIFICATION_HOTKEYS
385 static void notify_create_hotkeys_page(PrefsPage*, GtkWindow*, gpointer);
386 static void notify_destroy_hotkeys_page(PrefsPage*);
387 static void notify_save_hotkeys(PrefsPage*);
388 static void notify_hotkeys_enable_set_sensitivity(GtkToggleButton*, gpointer);
389 #endif /* NOTIFICATION_HOTKEYS */
390
391
392 static gint conv_color_to_int(GdkColor*);
393
394 void notify_gtk_init(void)
395 {
396         static gchar *path[3];
397
398         path[0] = _("Plugins");
399         path[1] = _("Notification");
400         path[2] = NULL;
401
402         notify_page.page.path = path;
403         notify_page.page.create_widget = notify_create_prefs_page;
404         notify_page.page.destroy_widget = notify_destroy_prefs_page;
405         notify_page.page.save_page = notify_save_prefs;
406         notify_page.page.weight = 40.0;
407         prefs_gtk_register_page((PrefsPage*) &notify_page);
408
409 #ifdef NOTIFICATION_HOTKEYS
410     {
411         static gchar *hotkeys_path[4];
412
413         hotkeys_path[0] = _("Plugins");
414         hotkeys_path[1] = _("Notification");
415         hotkeys_path[2] = _("Hotkeys");
416         hotkeys_path[3] = NULL;
417
418         hotkeys_page.page.path = hotkeys_path;
419         hotkeys_page.page.create_widget = notify_create_hotkeys_page;
420         hotkeys_page.page.destroy_widget = notify_destroy_hotkeys_page;
421         hotkeys_page.page.save_page = notify_save_hotkeys;
422         hotkeys_page.page.weight = 10.0;
423         prefs_gtk_register_page((PrefsPage*) &hotkeys_page);
424     }
425 #endif /* NOTIFICATION_HOTKEYS */
426
427
428 #ifdef NOTIFICATION_BANNER
429         {
430                 static gchar *banner_path[4];
431
432                 banner_path[0] = _("Plugins");
433                 banner_path[1] = _("Notification");
434                 banner_path[2] = _("Banner");
435                 banner_path[3] = NULL;
436
437                 banner_page.page.path = banner_path;
438                 banner_page.page.create_widget = notify_create_banner_page;
439                 banner_page.page.destroy_widget = notify_destroy_banner_page;
440                 banner_page.page.save_page = notify_save_banner;
441                 banner_page.page.weight = 20.0;
442                 prefs_gtk_register_page((PrefsPage*) &banner_page);
443         }
444 #endif /* NOTIFICATION_BANNER */
445
446 #ifdef NOTIFICATION_POPUP
447         {
448                 static gchar *popup_path[4];
449
450                 popup_path[0] = _("Plugins");
451                 popup_path[1] = _("Notification");
452                 popup_path[2] = _("Popup");
453                 popup_path[3] = NULL;
454
455                 popup_page.page.path = popup_path;
456                 popup_page.page.create_widget = notify_create_popup_page;
457                 popup_page.page.destroy_widget = notify_destroy_popup_page;
458                 popup_page.page.save_page = notify_save_popup;
459                 popup_page.page.weight = 30.0;
460                 prefs_gtk_register_page((PrefsPage*) &popup_page);
461         }
462 #endif /* NOTIFICATION_POPUP */
463
464 #ifdef NOTIFICATION_COMMAND
465         {
466                 static gchar *command_path[4];
467
468                 command_path[0] = _("Plugins");
469                 command_path[1] = _("Notification");
470                 command_path[2] = _("Command");
471                 command_path[3] = NULL;
472
473                 command_page.page.path = command_path;
474                 command_page.page.create_widget = notify_create_command_page;
475                 command_page.page.destroy_widget = notify_destroy_command_page;
476                 command_page.page.save_page = notify_save_command;
477                 command_page.page.weight = 40.0;
478                 prefs_gtk_register_page((PrefsPage*) &command_page);
479         }
480 #endif /* NOTIFICATION_COMMAND */
481
482 #ifdef NOTIFICATION_LCDPROC
483         {
484                 static gchar *lcdproc_path[4];
485
486                 lcdproc_path[0] = _("Plugins");
487                 lcdproc_path[1] = _("Notification");
488                 lcdproc_path[2] = _("LCD");
489                 lcdproc_path[3] = NULL;
490
491                 lcdproc_page.page.path = lcdproc_path;
492                 lcdproc_page.page.create_widget = notify_create_lcdproc_page;
493                 lcdproc_page.page.destroy_widget = notify_destroy_lcdproc_page;
494                 lcdproc_page.page.save_page = notify_save_lcdproc;
495                 lcdproc_page.page.weight = 50.0;
496                 prefs_gtk_register_page((PrefsPage*) &lcdproc_page);
497         }
498 #endif /* NOTIFICATION_LCDPROC */
499
500 #ifdef NOTIFICATION_TRAYICON
501         {
502                 static gchar *trayicon_path[4];
503
504                 trayicon_path[0] = _("Plugins");
505                 trayicon_path[1] = _("Notification");
506                 trayicon_path[2] = _("SysTrayicon");
507                 trayicon_path[3] = NULL;
508
509                 trayicon_page.page.path = trayicon_path;
510                 trayicon_page.page.create_widget = notify_create_trayicon_page;
511                 trayicon_page.page.destroy_widget = notify_destroy_trayicon_page;
512                 trayicon_page.page.save_page = notify_save_trayicon;
513                 trayicon_page.page.weight = 60.0;
514                 prefs_gtk_register_page((PrefsPage*) &trayicon_page);
515         }
516 #endif /* NOTIFICATION_TRAYICON */
517
518 #ifdef NOTIFICATION_INDICATOR
519         {
520                 static gchar *indicator_path[4];
521
522                 indicator_path[0] = _("Plugins");
523                 indicator_path[1] = _("Notification");
524                 indicator_path[2] = _("Indicator");
525                 indicator_path[3] = NULL;
526
527                 indicator_page.page.path = indicator_path;
528                 indicator_page.page.create_widget = notify_create_indicator_page;
529                 indicator_page.page.destroy_widget = notify_destroy_indicator_page;
530                 indicator_page.page.save_page = notify_save_indicator;
531                 indicator_page.page.weight = 70.0;
532                 prefs_gtk_register_page((PrefsPage*) &indicator_page);
533         }
534 #endif /* NOTIFICATION_INDICATOR */
535 }
536
537 void notify_gtk_done(void)
538 {
539         if (claws_is_exiting())
540                 return;
541         prefs_gtk_unregister_page((PrefsPage*) &notify_page);
542 #ifdef NOTIFICATION_BANNER
543         prefs_gtk_unregister_page((PrefsPage*) &banner_page);
544 #endif
545 #ifdef NOTIFICATION_POPUP
546         prefs_gtk_unregister_page((PrefsPage*) &popup_page);
547 #endif
548 #ifdef NOTIFICATION_COMMAND
549         prefs_gtk_unregister_page((PrefsPage*) &command_page);
550 #endif
551 #ifdef NOTIFICATION_LCDPROC
552         prefs_gtk_unregister_page((PrefsPage*) &lcdproc_page);
553 #endif
554 #ifdef NOTIFICATION_TRAYICON
555         prefs_gtk_unregister_page((PrefsPage*) &trayicon_page);
556 #endif
557 #ifdef NOTIFICATION_INDICATOR
558         prefs_gtk_unregister_page((PrefsPage*) &indicator_page);
559 #endif
560 #ifdef NOTIFICATION_HOTKEYS
561         prefs_gtk_unregister_page((PrefsPage*) &hotkeys_page);
562 #endif
563 }
564
565 void notify_save_config(void)
566 {
567         PrefFile *pfile;
568         gchar *rcpath;
569
570         debug_print("Saving Notification plugin configuration...\n");
571
572         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
573         pfile = prefs_write_open(rcpath);
574         g_free(rcpath);
575         if (!pfile || (prefs_set_block_label(pfile, "NotificationPlugin") < 0))
576                 return;
577
578         if (prefs_write_param(notify_param, pfile->fp) < 0) {
579                 debug_print("failed!\n");
580                 g_warning("Notification Plugin: Failed to write plugin configuration "
581                                                 "to file");
582                 prefs_file_close_revert(pfile);
583                 return;
584         }
585         if (fprintf(pfile->fp, "\n") < 0) {
586                 FILE_OP_ERROR(rcpath, "fprintf");
587                 prefs_file_close_revert(pfile);
588         }
589         else
590                 prefs_file_close(pfile);
591         debug_print("done.\n");
592 }
593
594 static void notify_create_prefs_page(PrefsPage *page, GtkWindow *window,
595                 gpointer data)
596 {
597         GtkWidget *pvbox;
598         GtkWidget *vbox;
599         GtkWidget *checkbox;
600         GtkWidget *frame;
601         GtkWidget *label;
602
603         /* Page vbox */
604         pvbox = gtk_vbox_new(FALSE, 0);
605
606         /* Frame */
607         PACK_FRAME (pvbox, frame, _("Include folder types"))
608         gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
609
610         /* Frame vbox */
611         vbox = gtk_vbox_new(FALSE, 4);
612         gtk_container_add(GTK_CONTAINER(frame), vbox);
613         gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
614
615         /* Include mail folders */
616         checkbox = gtk_check_button_new_with_label(_("Mail folders"));
617         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
618         notify_config.include_mail);
619         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
620         gtk_widget_show(checkbox);
621         notify_page.include_mail = checkbox;
622
623         /* Include news folders */
624         checkbox = gtk_check_button_new_with_label(_("News folders"));
625         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
626         notify_config.include_news);
627         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
628         gtk_widget_show(checkbox);
629         notify_page.include_news = checkbox;
630
631         /* Include RSSyl folders */
632         checkbox = gtk_check_button_new_with_label(_("RSSyl folders"));
633         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
634         notify_config.include_rss);
635         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
636         gtk_widget_show(checkbox);
637         notify_page.include_rss = checkbox;
638
639         /* Include calendar folders */
640         checkbox = gtk_check_button_new_with_label(_("vCalendar folders"));
641         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
642                         notify_config.include_calendar);
643         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
644         gtk_widget_show(checkbox);
645         notify_page.include_calendar = checkbox;
646
647         /* Warning-Label */
648         label = gtk_label_new(_("These settings override folder-specific "
649                         "selections."));
650         gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
651         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
652         gtk_widget_show(label);
653
654         /* done with the frame */
655         gtk_widget_show(frame);
656         gtk_widget_show(vbox);
657
658         /* Frame */
659         PACK_FRAME (pvbox, frame, _("Global notification settings"));
660         gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
661
662         /* Frame vbox */
663         vbox = gtk_vbox_new(FALSE, 4);
664         gtk_container_add(GTK_CONTAINER(frame), vbox);
665         gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
666
667         /* urgency hint new */
668         checkbox = gtk_check_button_new_with_label(_("Set window manager "
669                         "urgency hint when new messages exist"));
670         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
671                         notify_config.urgency_hint_new);
672         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
673         gtk_widget_show(checkbox);
674         notify_page.urgency_hint_new = checkbox;
675
676         /* urgency hint new */
677         checkbox = gtk_check_button_new_with_label(_("Set window manager "
678                         "urgency hint when unread messages exist"));
679         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
680                         notify_config.urgency_hint_unread);
681         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
682         gtk_widget_show(checkbox);
683         notify_page.urgency_hint_unread = checkbox;
684
685 #ifdef HAVE_LIBCANBERRA_GTK
686         /* canberra */
687     checkbox = gtk_check_button_new_with_label(_("Use sound theme"));
688     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
689             notify_config.canberra_play_sounds);
690     gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
691     gtk_widget_show(checkbox);
692     notify_page.canberra_play_sounds = checkbox;
693 #endif
694
695         /* done with the frame */
696         gtk_widget_show(frame);
697         gtk_widget_show(vbox);
698
699         /* done with the page */
700         gtk_widget_show(pvbox);
701         page->widget = pvbox;
702 }
703
704 static void notify_destroy_prefs_page(PrefsPage *page)
705 {
706 }
707
708 static void notify_save_prefs(PrefsPage *page)
709 {
710         notify_config.include_mail =gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.include_mail));
711         notify_config.include_news =gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.include_news));
712         notify_config.include_rss =gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.include_rss));
713         notify_config.include_calendar
714                         = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.include_calendar));
715         notify_config.urgency_hint_new = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.urgency_hint_new));
716         notify_config.urgency_hint_unread = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.urgency_hint_unread));
717 #ifdef HAVE_LIBCANBERRA_GTK
718    notify_config.canberra_play_sounds = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(notify_page.canberra_play_sounds));
719 #endif
720
721    notification_core_global_includes_changed();
722 }
723
724 #ifdef NOTIFICATION_BANNER
725 static void notify_banner_slider_add_cb(GtkWidget *widget, gpointer data)
726 {
727         GtkRange *slider = GTK_RANGE(data); /* inverted slider */
728         gtk_range_set_value(slider, gtk_range_get_value(slider) - 1.0);
729 }
730
731 static void notify_banner_slider_remove_cb(GtkWidget *widget, gpointer data)
732 {
733         GtkRange *slider = GTK_RANGE(data); /* inverted slider */
734         gtk_range_set_value(slider, gtk_range_get_value(slider) + 1.0);
735 }
736
737 static void notify_create_banner_page(PrefsPage *page, GtkWindow *window,
738                 gpointer data)
739 {
740         GtkRequisition requisition;
741         GtkWidget *pvbox;
742         GtkWidget *vbox;
743         GtkWidget *hbox;
744         GtkWidget *chbox, *cvbox, *cframe;
745         GtkWidget *checkbox;
746         GtkWidget *button;
747         GtkWidget *combo;
748         GtkWidget *spinner;
749         GtkWidget *label;
750         GtkWidget *slider;
751         GtkWidget *color_sel;
752         GdkColor bg;
753         GdkColor fg;
754
755         pvbox = gtk_vbox_new(FALSE, 20);
756         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
757
758         /* Always / Never / Only when non-empty */
759         hbox = gtk_hbox_new(FALSE, 20);
760         gtk_box_pack_start(GTK_BOX(pvbox), hbox, FALSE, FALSE, 0);
761         label = gtk_label_new(_("Show banner"));
762         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
763         gtk_widget_show(label);
764         combo = gtk_combo_box_new_text();
765         gtk_combo_box_insert_text(GTK_COMBO_BOX(combo), NOTIFY_BANNER_SHOW_NEVER,
766                         _("Never"));
767         gtk_combo_box_insert_text(GTK_COMBO_BOX(combo), NOTIFY_BANNER_SHOW_ALWAYS,
768                         _("Always"));
769         gtk_combo_box_insert_text(GTK_COMBO_BOX(combo), NOTIFY_BANNER_SHOW_NONEMPTY,
770                         _("Only when not empty"));
771         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), notify_config.banner_show);
772         gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
773         g_signal_connect(G_OBJECT(combo), "changed",
774                         G_CALLBACK(notify_banner_enable_set_sensitivity), NULL);
775         gtk_widget_show(combo);
776         gtk_widget_show(hbox);
777         banner_page.banner_show = combo;
778
779         /* Container vbox for greying out everything */
780         vbox = gtk_vbox_new(FALSE, 10);
781         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
782         gtk_widget_show(vbox);
783         banner_page.banner_cont_enable = vbox;
784
785         /* Banner speed */
786         hbox = gtk_hbox_new(FALSE, 10);
787         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
788
789         label = gtk_label_new(_("Banner speed"));
790         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
791         gtk_widget_show(label);
792
793         slider = gtk_hscale_new_with_range(10., 70., 10.);
794         gtk_scale_set_digits(GTK_SCALE(slider), 0);
795         gtk_widget_size_request(combo, &requisition);
796         gtk_widget_set_size_request(slider, requisition.width, -1);
797         gtk_range_set_increments(GTK_RANGE(slider), 10., 10.);
798         gtk_range_set_inverted(GTK_RANGE(slider), TRUE);
799         gtk_scale_set_draw_value(GTK_SCALE(slider), FALSE);
800         gtk_range_set_value(GTK_RANGE(slider), notify_config.banner_speed);
801
802         button = gtk_button_new();
803         gtk_button_set_image(GTK_BUTTON(button),
804                 gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
805         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
806         g_signal_connect(G_OBJECT(button), "clicked",
807                           G_CALLBACK(notify_banner_slider_remove_cb), slider);
808         gtk_widget_show(button);
809
810         gtk_box_pack_start(GTK_BOX(hbox), slider, TRUE, TRUE, 0);
811         gtk_widget_show(slider);
812
813         button = gtk_button_new();
814         gtk_button_set_image(GTK_BUTTON(button),
815                 gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
816         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
817         g_signal_connect(G_OBJECT(button), "clicked",
818                           G_CALLBACK(notify_banner_slider_add_cb), slider);
819         gtk_widget_show(button);
820
821         gtk_widget_show(hbox);
822         banner_page.banner_speed = slider;
823
824         /* Maximum number of messages in banner */
825         hbox = gtk_hbox_new(FALSE, 10);
826         label = gtk_label_new(_("Maximum number of messages"));
827         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
828         gtk_widget_show(label);
829         spinner = gtk_spin_button_new_with_range(0., 1000., 1.);
830         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), 0);
831         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), notify_config.banner_max_msgs);
832         CLAWS_SET_TIP (spinner, _("Limit the number of messages shown, use 0 for unlimited"));
833         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
834         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
835         gtk_widget_show(spinner);
836         gtk_widget_show(hbox);
837         banner_page.banner_max_msgs = spinner;
838
839         /* banner width */
840         hbox = gtk_hbox_new(FALSE, 10);
841         label = gtk_label_new(_("Banner width"));
842         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
843         gtk_widget_show(label);
844         spinner = gtk_spin_button_new_with_range(0.,5000., 50);
845         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner),0);
846         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner),notify_config.banner_width);
847         CLAWS_SET_TIP (spinner, _("Limit the size of banner, use 0 for screen width"));
848         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
849         label = gtk_label_new(_("pixel(s)"));
850         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
851         gtk_widget_show(label);
852         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
853         gtk_widget_show(spinner);
854         gtk_widget_show(hbox);
855         banner_page.banner_width = spinner;
856
857         /* Include unread */
858         checkbox = gtk_check_button_new_with_label(_("Include unread mails in banner"));
859         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
860                         notify_config.banner_include_unread);
861         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
862         gtk_widget_show(checkbox);
863         banner_page.banner_include_unread = checkbox;
864
865         /* Check button sticky */
866         checkbox = gtk_check_button_new_with_label(_("Make banner sticky"));
867         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
868                         notify_config.banner_sticky);
869         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
870         gtk_widget_show(checkbox);
871         banner_page.banner_sticky = checkbox;
872
873         /* Check box for enabling folder specific selection */
874         hbox = gtk_hbox_new(FALSE, 10);
875         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
876         checkbox = gtk_check_button_new_with_label(_("Only include selected folders"));
877         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
878                         notify_config.banner_folder_specific);
879         gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0);
880         g_signal_connect(G_OBJECT(checkbox), "toggled",
881                         G_CALLBACK(notify_banner_folder_specific_set_sensitivity),
882                         NULL);
883         gtk_widget_show(checkbox);
884         banner_page.banner_folder_specific = checkbox;
885         button = gtk_button_new_with_label(_("Select folders..."));
886         g_signal_connect(G_OBJECT(button), "clicked",
887                         G_CALLBACK(notification_foldercheck_sel_folders_cb),
888                         BANNER_SPECIFIC_FOLDER_ID_STR);
889         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
890         banner_page.banner_cont_folder_specific = button;
891         gtk_widget_show(button);
892         gtk_widget_show(hbox);
893
894         /* Check box for enabling custom colors */
895         cvbox = gtk_vbox_new(FALSE, 10);
896         gtk_widget_show(cvbox);
897         PACK_FRAME (vbox, cframe, _("Banner colors"))
898         gtk_container_set_border_width(GTK_CONTAINER(cvbox), 5);
899         gtk_container_add(GTK_CONTAINER(cframe), cvbox);
900
901         checkbox = gtk_check_button_new_with_label(_("Use custom colors"));
902         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
903                         notify_config.banner_enable_colors);
904         gtk_box_pack_start(GTK_BOX(cvbox), checkbox, FALSE, FALSE, 0);
905         g_signal_connect(G_OBJECT(checkbox), "toggled",
906                         G_CALLBACK(notify_banner_color_sel_set_sensitivity), NULL);
907         gtk_widget_show(checkbox);
908         banner_page.banner_enable_colors = checkbox;
909
910         /* Color selection dialogs for foreground and background color */
911         /* foreground */
912         chbox = gtk_hbox_new(FALSE, 10);
913         gtk_box_pack_start(GTK_BOX(cvbox), chbox, FALSE, FALSE, 0);
914         gtk_widget_show(chbox);
915
916         label = gtk_label_new(_("Foreground"));
917         gtk_box_pack_start(GTK_BOX(chbox), label, FALSE, FALSE, 0);
918         gtk_widget_show(label);
919         color_sel = gtk_color_button_new();
920         gtkut_convert_int_to_gdk_color(notify_config.banner_color_fg,&fg);
921         gtk_color_button_set_color(GTK_COLOR_BUTTON(color_sel),&fg);
922         gtk_color_button_set_title(GTK_COLOR_BUTTON(color_sel),_("Foreground color"));
923         gtk_box_pack_start(GTK_BOX(chbox), color_sel, FALSE, FALSE, 0);
924         gtk_widget_show(color_sel);
925         banner_page.banner_color_fg = color_sel;
926         /* background */
927         label = gtk_label_new(_("Background"));
928         gtk_box_pack_start(GTK_BOX(chbox), label, FALSE, FALSE, 0);
929         gtk_widget_show(label);
930         color_sel = gtk_color_button_new();
931         gtkut_convert_int_to_gdk_color(notify_config.banner_color_bg,&bg);
932         gtk_color_button_set_color(GTK_COLOR_BUTTON(color_sel),&bg);
933         gtk_color_button_set_title(GTK_COLOR_BUTTON(color_sel), _("Background color"));
934         gtk_box_pack_start(GTK_BOX(chbox), color_sel, FALSE, FALSE, 0);
935         gtk_widget_show(color_sel);
936         banner_page.banner_color_bg = color_sel;
937         banner_page.banner_cont_color_sel = chbox;
938
939         notify_banner_color_sel_set_sensitivity
940         (GTK_TOGGLE_BUTTON(banner_page.banner_enable_colors), NULL);
941         notify_banner_folder_specific_set_sensitivity
942         (GTK_TOGGLE_BUTTON(banner_page.banner_folder_specific), NULL);
943         notify_banner_enable_set_sensitivity(GTK_COMBO_BOX(combo), NULL);
944         gtk_widget_show(pvbox);
945         banner_page.page.widget = pvbox;
946 }
947
948 static void notify_destroy_banner_page(PrefsPage *page)
949 {
950 }
951
952 static void notify_save_banner(PrefsPage *page)
953 {
954         gdouble range_val;
955         GdkColor color;
956
957         notify_config.banner_show =
958                 gtk_combo_box_get_active(GTK_COMBO_BOX(banner_page.banner_show));
959         notify_config.banner_max_msgs =
960                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(banner_page.banner_max_msgs));
961         notify_config.banner_width =
962                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(banner_page.banner_width));
963         notify_config.banner_include_unread =
964         gtk_toggle_button_get_active
965         (GTK_TOGGLE_BUTTON(banner_page.banner_include_unread));
966         range_val= gtk_range_get_value(GTK_RANGE(banner_page.banner_speed));
967         notify_config.banner_speed = (gint)ceil(range_val);
968
969         notify_config.banner_sticky =
970         gtk_toggle_button_get_active
971         (GTK_TOGGLE_BUTTON(banner_page.banner_sticky));
972
973         notify_config.banner_folder_specific =
974         gtk_toggle_button_get_active
975         (GTK_TOGGLE_BUTTON(banner_page.banner_folder_specific));
976
977         notify_config.banner_enable_colors =
978         gtk_toggle_button_get_active
979         (GTK_TOGGLE_BUTTON(banner_page.banner_enable_colors));
980
981         /* Color dialogs are a bit more complicated */
982         gtk_color_button_get_color(GTK_COLOR_BUTTON(banner_page.banner_color_fg),
983                         &color);
984         notify_config.banner_color_fg = conv_color_to_int(&color);
985         gtk_color_button_get_color(GTK_COLOR_BUTTON(banner_page.banner_color_bg),
986                         &color);
987         notify_config.banner_color_bg = conv_color_to_int(&color);
988
989         notification_banner_destroy();
990         notification_update_banner();
991 }
992
993 static void notify_banner_enable_set_sensitivity(GtkComboBox *combo,
994                 gpointer data)
995 {
996         NotifyBannerShow show;
997
998         show = gtk_combo_box_get_active(GTK_COMBO_BOX(banner_page.banner_show));
999         gtk_widget_set_sensitive(banner_page.banner_cont_enable,
1000                         (show == NOTIFY_BANNER_SHOW_NEVER) ? FALSE : TRUE);
1001 }
1002
1003 static void notify_banner_color_sel_set_sensitivity(GtkToggleButton *button,
1004                 gpointer data)
1005 {
1006         gboolean active;
1007         active = gtk_toggle_button_get_active
1008         (GTK_TOGGLE_BUTTON(banner_page.banner_enable_colors));
1009         gtk_widget_set_sensitive(banner_page.banner_cont_color_sel, active);
1010 }
1011
1012 static void notify_banner_folder_specific_set_sensitivity(GtkToggleButton *bu,
1013                 gpointer data)
1014 {
1015         gboolean active;
1016         active = gtk_toggle_button_get_active
1017         (GTK_TOGGLE_BUTTON(banner_page.banner_folder_specific));
1018         gtk_widget_set_sensitive(banner_page.banner_cont_folder_specific, active);
1019 }
1020 #endif /* NOTIFICATION_BANNER */
1021
1022 #ifdef NOTIFICATION_POPUP
1023 static void notify_create_popup_page(PrefsPage *page, GtkWindow *window,
1024                 gpointer data)
1025 {
1026         gdouble timeout;
1027         GtkWidget *pvbox;
1028         GtkWidget *vbox;
1029         GtkWidget *checkbox;
1030         GtkWidget *hbox;
1031         GtkWidget *spinner;
1032         GtkWidget *label;
1033         GtkWidget *button;
1034 #ifndef HAVE_LIBNOTIFY
1035         GdkColor bg;
1036         GdkColor fg;
1037         GtkWidget *table;
1038         GtkWidget *color_sel;
1039 #endif /* !HAVE_LIBNOTIFY */
1040
1041         pvbox = gtk_vbox_new(FALSE, 20);
1042         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1043
1044         /* Enable popup */
1045         checkbox = gtk_check_button_new_with_label(_("Enable popup"));
1046         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1047                         notify_config.popup_show);
1048         gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1049         g_signal_connect(G_OBJECT(checkbox), "toggled",
1050                         G_CALLBACK(notify_popup_enable_set_sensitivity), NULL);
1051         gtk_widget_show(checkbox);
1052         popup_page.popup_show = checkbox;
1053
1054         /* Container vbox for greying out everything */
1055         vbox = gtk_vbox_new(FALSE, 10);
1056         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1057         gtk_widget_show(vbox);
1058         popup_page.popup_cont_enable = vbox;
1059
1060         /* Popup timeout */
1061         hbox = gtk_hbox_new(FALSE, 10);
1062         label = gtk_label_new(_("Popup timeout"));
1063         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1064         gtk_widget_show(label);
1065         spinner = gtk_spin_button_new_with_range(TIMEOUT_SPINNER_MIN, TIMEOUT_SPINNER_MAX, TIMEOUT_SPINNER_STEP);
1066         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), 1);
1067         timeout = notify_config.popup_timeout/1000.;
1068         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), timeout);
1069         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
1070         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1071         gtk_widget_show(spinner);
1072         label = gtk_label_new(_("seconds"));
1073         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1074         gtk_widget_show(label);
1075         gtk_widget_show(hbox);
1076         popup_page.popup_timeout = spinner;
1077
1078         /* Check box for enabling folder specific selection */
1079         hbox = gtk_hbox_new(FALSE, 10);
1080         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1081         checkbox = gtk_check_button_new_with_label(_("Only include selected folders"));
1082         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1083                         notify_config.popup_folder_specific);
1084         gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0);
1085         g_signal_connect(G_OBJECT(checkbox), "toggled",
1086                         G_CALLBACK(notify_popup_folder_specific_set_sensitivity),
1087                         NULL);
1088         gtk_widget_show(checkbox);
1089         popup_page.popup_folder_specific = checkbox;
1090         button = gtk_button_new_with_label(_("Select folders..."));
1091         g_signal_connect(G_OBJECT(button), "clicked",
1092                         G_CALLBACK(notification_foldercheck_sel_folders_cb),
1093                         POPUP_SPECIFIC_FOLDER_ID_STR);
1094         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1095         popup_page.popup_cont_folder_specific = button;
1096         gtk_widget_show(button);
1097         gtk_widget_show(hbox);
1098
1099 #ifndef HAVE_LIBNOTIFY
1100         /* Sticky check button */
1101         checkbox = gtk_check_button_new_with_label(_("Make popup sticky"));
1102         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1103                         notify_config.popup_sticky);
1104         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
1105         gtk_widget_show(checkbox);
1106         popup_page.popup_sticky = checkbox;
1107
1108         /* Button to set size and position of popup window */
1109         hbox = gtk_hbox_new(FALSE, 10);
1110         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1111         button = gtk_button_new_with_label(_("Set popup window width and position"));
1112         g_signal_connect(G_OBJECT(button), "clicked",
1113                         G_CALLBACK(notify_popup_set_cb), NULL);
1114         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1115         gtk_widget_show(button);
1116         label = gtk_label_new(_("(the window manager is free to ignore this)"));
1117         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1118         gtk_widget_show(label);
1119         gtk_widget_show(hbox);
1120
1121         /* Check box for enabling custom colors */
1122         checkbox = gtk_check_button_new_with_label(_("Use custom colors"));
1123         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1124                         notify_config.popup_enable_colors);
1125         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
1126         g_signal_connect(G_OBJECT(checkbox), "toggled",
1127                         G_CALLBACK(notify_popup_color_sel_set_sensitivity), NULL);
1128         gtk_widget_show(checkbox);
1129         popup_page.popup_enable_colors = checkbox;
1130
1131         /* Color selection dialogs for foreground and background color */
1132         table = gtk_table_new(2,2,FALSE);
1133         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
1134         /* foreground */
1135         label = gtk_label_new(_("Foreground"));
1136         gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,0,1);
1137         gtk_widget_show(label);
1138         color_sel = gtk_color_button_new();
1139         gtkut_convert_int_to_gdk_color(notify_config.popup_color_fg,&fg);
1140         gtk_color_button_set_color(GTK_COLOR_BUTTON(color_sel),&fg);
1141         gtk_color_button_set_title(GTK_COLOR_BUTTON(color_sel),_("Foreground color"));
1142         gtk_table_attach_defaults(GTK_TABLE(table),color_sel,1,2,0,1);
1143         gtk_widget_show(color_sel);
1144         popup_page.popup_color_fg = color_sel;
1145         /* background */
1146         label = gtk_label_new(_("Background"));
1147         gtk_table_attach_defaults(GTK_TABLE(table),label,0,1,1,2);
1148         gtk_widget_show(label);
1149         color_sel = gtk_color_button_new();
1150         gtkut_convert_int_to_gdk_color(notify_config.popup_color_bg,&bg);
1151         gtk_color_button_set_color(GTK_COLOR_BUTTON(color_sel),&bg);
1152         gtk_color_button_set_title(GTK_COLOR_BUTTON(color_sel),_("Background color"));
1153         gtk_table_attach_defaults(GTK_TABLE(table),color_sel,1,2,1,2);
1154         gtk_widget_show(color_sel);
1155         gtk_widget_show(table);
1156         popup_page.popup_color_bg = color_sel;
1157         popup_page.popup_cont_color_sel = table;
1158
1159         notify_popup_color_sel_set_sensitivity
1160         (GTK_TOGGLE_BUTTON(popup_page.popup_enable_colors), NULL);
1161 #else /* HAVE_LIBNOTIFY */
1162         hbox = gtk_hbox_new(FALSE, 10);
1163         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1164         checkbox = gtk_check_button_new_with_label(_("Display folder name"));
1165         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1166                         notify_config.popup_display_folder_name);
1167         gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0);
1168         gtk_widget_show(checkbox);
1169         gtk_widget_show(hbox);
1170         popup_page.popup_display_folder_name = checkbox;
1171 #endif /* HAVE_LIBNOTIFY */
1172
1173         notify_popup_enable_set_sensitivity
1174         (GTK_TOGGLE_BUTTON(popup_page.popup_show), NULL);
1175         notify_popup_folder_specific_set_sensitivity
1176         (GTK_TOGGLE_BUTTON(popup_page.popup_folder_specific), NULL);
1177         gtk_widget_show(pvbox);
1178         popup_page.page.widget = pvbox;
1179 }
1180
1181 static void notify_destroy_popup_page(PrefsPage *page)
1182 {
1183 }
1184
1185 static void notify_save_popup(PrefsPage *page)
1186 {
1187         gdouble timeout;
1188
1189 #ifndef HAVE_LIBNOTIFY
1190         GdkColor color;
1191 #endif /* !HAVE_LIBNOTIFY */
1192
1193         notify_config.popup_show =
1194         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(popup_page.popup_show));
1195         timeout =
1196         gtk_spin_button_get_value(GTK_SPIN_BUTTON(popup_page.popup_timeout));
1197         notify_config.popup_timeout = (gint)floor(timeout*1000+0.5);
1198         notify_config.popup_folder_specific =
1199         gtk_toggle_button_get_active
1200         (GTK_TOGGLE_BUTTON(popup_page.popup_folder_specific));
1201
1202 #ifndef HAVE_LIBNOTIFY
1203         notify_config.popup_sticky =
1204         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(popup_page.popup_sticky));
1205         notify_config.popup_enable_colors =
1206         gtk_toggle_button_get_active
1207         (GTK_TOGGLE_BUTTON(popup_page.popup_enable_colors));
1208
1209         /* Color dialogs are a bit more complicated */
1210         gtk_color_button_get_color(GTK_COLOR_BUTTON(popup_page.popup_color_fg),
1211                         &color);
1212         notify_config.popup_color_fg = conv_color_to_int(&color);
1213         gtk_color_button_get_color(GTK_COLOR_BUTTON(popup_page.popup_color_bg),
1214                         &color);
1215         notify_config.popup_color_bg = conv_color_to_int(&color);
1216 #else /* HAVE_LIBNOTIFY */
1217         notify_config.popup_display_folder_name =
1218         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(popup_page.popup_display_folder_name));
1219 #endif /* HAVE_LIBNOTIFY */
1220 }
1221
1222 #ifndef HAVE_LIBNOTIFY
1223 static void notify_popup_set_cb(GtkWidget *widget, gpointer data)
1224 {
1225         GtkWidget *win;
1226         GtkWidget *button;
1227
1228         win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "notification_prefs");
1229         gtk_window_set_title(GTK_WINDOW(win), _("Sample popup window"));
1230         gtk_window_set_modal(GTK_WINDOW(win), TRUE);
1231         gtk_window_set_keep_above(GTK_WINDOW(win), TRUE);
1232         gtk_window_set_resizable(GTK_WINDOW(win), TRUE);
1233         gtk_container_set_border_width(GTK_CONTAINER(win), 5);
1234
1235         button = gtk_button_new_with_label(_("Done"));
1236         g_signal_connect(G_OBJECT(button), "clicked",
1237                         G_CALLBACK(notify_popup_set_done_cb), win);
1238         gtk_container_add(GTK_CONTAINER(win), button);
1239
1240         gtk_widget_show_all(win);
1241 }
1242
1243 static void notify_popup_set_done_cb(GtkWidget *widget, gpointer data)
1244 {
1245         GtkWidget *win = data;
1246         gint dummy;
1247
1248         gtk_window_get_position(GTK_WINDOW(win),
1249                         &(notify_config.popup_root_x),
1250                         &(notify_config.popup_root_y));
1251         gtk_window_get_size(GTK_WINDOW(win),
1252                         &(notify_config.popup_width), &dummy);
1253         gtk_widget_destroy(win);
1254 }
1255
1256 static void notify_popup_color_sel_set_sensitivity(GtkToggleButton *button,
1257                 gpointer data)
1258 {
1259         gboolean active;
1260         active = gtk_toggle_button_get_active
1261         (GTK_TOGGLE_BUTTON(popup_page.popup_enable_colors));
1262         gtk_widget_set_sensitive(popup_page.popup_cont_color_sel, active);
1263 }
1264 #endif /* !HAVE_LIBNOTIFY */
1265
1266 static void notify_popup_enable_set_sensitivity(GtkToggleButton *button,
1267                 gpointer data)
1268 {
1269         gboolean active;
1270         active = gtk_toggle_button_get_active
1271         (GTK_TOGGLE_BUTTON(popup_page.popup_show));
1272         gtk_widget_set_sensitive(popup_page.popup_cont_enable, active);
1273 }
1274
1275 static void notify_popup_folder_specific_set_sensitivity(GtkToggleButton *bu,
1276                 gpointer data)
1277 {
1278         gboolean active;
1279         active = gtk_toggle_button_get_active
1280         (GTK_TOGGLE_BUTTON(popup_page.popup_folder_specific));
1281         gtk_widget_set_sensitive(popup_page.popup_cont_folder_specific, active);
1282 }
1283
1284 #endif /* NOTIFICATION_POPUP */
1285
1286 #ifdef NOTIFICATION_COMMAND
1287 static void notify_command_browse_cb(GtkWidget* widget, gpointer data)
1288 {
1289         gchar *filename;
1290         gchar *utf8_filename;
1291         GtkEntry *dest = GTK_ENTRY(data);
1292
1293         filename = filesel_select_file_open(_("Select command"), NULL);
1294         if (!filename) return;
1295
1296         utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
1297         if (!utf8_filename) {
1298                 g_warning("notify_command_browse_cb(): failed to convert character set.");
1299                 utf8_filename = g_strdup(filename);
1300         }
1301         gtk_entry_set_text(GTK_ENTRY(dest), utf8_filename);
1302         g_free(utf8_filename);
1303 }
1304
1305 static void notify_create_command_page(PrefsPage *page, GtkWindow *window,
1306                 gpointer data)
1307 {
1308         GtkWidget *pvbox;
1309         GtkWidget *vbox;
1310         GtkWidget *checkbox;
1311         GtkWidget *hbox;
1312         GtkWidget *spinner;
1313         GtkWidget *entry;
1314         GtkWidget *label;
1315         GtkWidget *button, *buttonb;
1316         gdouble timeout;
1317
1318         pvbox = gtk_vbox_new(FALSE, 20);
1319         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1320
1321         /* Enable command */
1322         checkbox = gtk_check_button_new_with_label(_("Enable command"));
1323         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1324                         notify_config.command_enabled);
1325         gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1326         g_signal_connect(G_OBJECT(checkbox), "toggled",
1327                         G_CALLBACK(notify_command_enable_set_sensitivity), NULL);
1328         gtk_widget_show(checkbox);
1329         command_page.command_enabled = checkbox;
1330
1331         /* Container vbox for greying out everything */
1332         vbox = gtk_vbox_new(FALSE, 10);
1333         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1334         gtk_widget_show(vbox);
1335         command_page.command_cont_enable = vbox;
1336
1337         /* entry field for command to execute */
1338         hbox = gtk_hbox_new(FALSE, 10);
1339         label = gtk_label_new(_("Command to execute"));
1340         gtk_widget_show(label);
1341         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1342         entry = gtk_entry_new();
1343         gtk_entry_set_text(GTK_ENTRY(entry), notify_config.command_line);
1344         gtk_widget_show(entry);
1345         gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
1346         buttonb = gtkut_get_browse_file_btn(_("Bro_wse"));
1347         gtk_box_pack_start(GTK_BOX(hbox), buttonb, FALSE, FALSE, 0);
1348         g_signal_connect(G_OBJECT(buttonb), "clicked",
1349                 G_CALLBACK(notify_command_browse_cb), entry);
1350         gtk_widget_show(buttonb);
1351         gtk_widget_show(hbox);
1352         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1353         command_page.command_line = entry;
1354
1355         /* Spin button for command timeout */
1356         hbox = gtk_hbox_new(FALSE, 10);
1357         label = gtk_label_new(_("Block command after execution for"));
1358         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1359         gtk_widget_show(label);
1360         spinner = gtk_spin_button_new_with_range(0., 600., 1.);
1361         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), 0);
1362         timeout = notify_config.command_timeout/1000.;
1363         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), timeout);
1364         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
1365         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1366         gtk_widget_show(spinner);
1367         label = gtk_label_new(_("seconds"));
1368         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1369         gtk_widget_show(label);
1370         gtk_widget_show(hbox);
1371         command_page.command_timeout = spinner;
1372
1373         /* Check box for enabling folder specific selection */
1374         hbox = gtk_hbox_new(FALSE, 10);
1375         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1376         checkbox = gtk_check_button_new_with_label(_("Only include selected folders"));
1377         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1378                         notify_config.command_folder_specific);
1379         gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0);
1380         g_signal_connect(G_OBJECT(checkbox), "toggled",
1381                         G_CALLBACK(notify_command_folder_specific_set_sensitivity),
1382                         NULL);
1383         gtk_widget_show(checkbox);
1384         command_page.command_folder_specific = checkbox;
1385         button = gtk_button_new_with_label(_("Select folders..."));
1386         g_signal_connect(G_OBJECT(button), "clicked",
1387                         G_CALLBACK(notification_foldercheck_sel_folders_cb),
1388                         COMMAND_SPECIFIC_FOLDER_ID_STR);
1389         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1390         command_page.command_cont_folder_specific = button;
1391         gtk_widget_show(button);
1392         gtk_widget_show(hbox);
1393
1394         notify_command_enable_set_sensitivity
1395         (GTK_TOGGLE_BUTTON(command_page.command_enabled), NULL);
1396         notify_command_folder_specific_set_sensitivity
1397         (GTK_TOGGLE_BUTTON(command_page.command_folder_specific), NULL);
1398         gtk_widget_show(pvbox);
1399         command_page.page.widget = pvbox;
1400 }
1401
1402 static void notify_destroy_command_page(PrefsPage *page)
1403 {
1404 }
1405
1406 static void notify_save_command(PrefsPage *page)
1407 {
1408         gdouble timeout;
1409         const gchar *tmp_str;
1410
1411         notify_config.command_enabled =
1412         gtk_toggle_button_get_active
1413         (GTK_TOGGLE_BUTTON(command_page.command_enabled));
1414
1415         timeout =
1416         gtk_spin_button_get_value(GTK_SPIN_BUTTON(command_page.command_timeout));
1417         notify_config.command_timeout = (gint)floor(timeout*1000+0.5);
1418         notify_config.command_folder_specific =
1419         gtk_toggle_button_get_active
1420         (GTK_TOGGLE_BUTTON(command_page.command_folder_specific));
1421
1422         tmp_str = gtk_entry_get_text(GTK_ENTRY(command_page.command_line));
1423         if(notify_config.command_line)
1424       g_free(notify_config.command_line);
1425         notify_config.command_line = g_strdup(tmp_str);
1426 }
1427
1428 static void notify_command_enable_set_sensitivity(GtkToggleButton *button,
1429                 gpointer data)
1430 {
1431         gboolean active;
1432         active = gtk_toggle_button_get_active
1433         (GTK_TOGGLE_BUTTON(command_page.command_enabled));
1434         gtk_widget_set_sensitive(command_page.command_cont_enable, active);
1435 }
1436
1437 static void notify_command_folder_specific_set_sensitivity(GtkToggleButton *bu,
1438                 gpointer data)
1439 {
1440         gboolean active;
1441         active = gtk_toggle_button_get_active
1442         (GTK_TOGGLE_BUTTON(command_page.command_folder_specific));
1443         gtk_widget_set_sensitive(command_page.command_cont_folder_specific, active);
1444 }
1445
1446 #endif /* NOTIFICATION_COMMAND */
1447
1448 #ifdef NOTIFICATION_LCDPROC
1449 static void notify_create_lcdproc_page(PrefsPage *page, GtkWindow *window,
1450                 gpointer data)
1451 {
1452         GtkWidget *pvbox;
1453         GtkWidget *vbox;
1454         GtkWidget *label;
1455         GtkWidget *entry;
1456         GtkWidget *spinner;
1457         GtkWidget *checkbox;
1458         GtkWidget *hbox;
1459
1460         pvbox = gtk_vbox_new(FALSE, 20);
1461         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1462
1463         /* Enable lcdproc */
1464         checkbox = gtk_check_button_new_with_label(_("Enable LCD"));
1465         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1466                         notify_config.lcdproc_enabled);
1467         gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1468         g_signal_connect(G_OBJECT(checkbox), "toggled",
1469                         G_CALLBACK(notify_lcdproc_enable_set_sensitivity), NULL);
1470         gtk_widget_show(checkbox);
1471         lcdproc_page.lcdproc_enabled = checkbox;
1472
1473         /* Container vbox for greying out everything */
1474         vbox = gtk_vbox_new(FALSE, 10);
1475         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1476         gtk_widget_show(vbox);
1477         lcdproc_page.lcdproc_cont_enable = vbox;
1478
1479         /* Hostname and port information */
1480         hbox = gtk_hbox_new(FALSE, 10);
1481         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1482         gtk_widget_show(hbox);
1483         label = gtk_label_new(_("Hostname:Port of LCDd server"));
1484         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1485         entry = gtk_entry_new();
1486         gtk_entry_set_text(GTK_ENTRY(entry), notify_config.lcdproc_hostname);
1487         gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1488         gtk_widget_show(entry);
1489         gtk_widget_show(label);
1490         label = gtk_label_new(":");
1491         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1492         gtk_widget_show(label);
1493         spinner = gtk_spin_button_new_with_range(1., 65535., 1.);
1494         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), 0);
1495         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner),
1496                         notify_config.lcdproc_port);
1497         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
1498         gtk_widget_show(spinner);
1499         lcdproc_page.lcdproc_hostname = entry;
1500         lcdproc_page.lcdproc_port = spinner;
1501
1502         notify_lcdproc_enable_set_sensitivity
1503         (GTK_TOGGLE_BUTTON(lcdproc_page.lcdproc_enabled), NULL);
1504         gtk_widget_show(pvbox);
1505         lcdproc_page.page.widget = pvbox;
1506 }
1507
1508 static void notify_destroy_lcdproc_page(PrefsPage *page)
1509 {
1510 }
1511
1512 static void notify_save_lcdproc(PrefsPage *page)
1513 {
1514         notify_config.lcdproc_enabled =
1515         gtk_toggle_button_get_active
1516         (GTK_TOGGLE_BUTTON(lcdproc_page.lcdproc_enabled));
1517
1518         if(notify_config.lcdproc_hostname)
1519         g_free(notify_config.lcdproc_hostname);
1520         notify_config.lcdproc_hostname =
1521         g_strdup(gtk_entry_get_text(GTK_ENTRY(lcdproc_page.lcdproc_hostname)));
1522
1523         notify_config.lcdproc_port =
1524         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lcdproc_page.lcdproc_port));
1525
1526         if(notify_config.lcdproc_enabled)
1527         notification_lcdproc_connect();
1528         else
1529         notification_lcdproc_disconnect();
1530 }
1531
1532 static void notify_lcdproc_enable_set_sensitivity(GtkToggleButton *button,
1533                 gpointer data)
1534 {
1535         gboolean active;
1536         active = gtk_toggle_button_get_active
1537         (GTK_TOGGLE_BUTTON(lcdproc_page.lcdproc_enabled));
1538         gtk_widget_set_sensitive(lcdproc_page.lcdproc_cont_enable, active);
1539 }
1540 #endif /* NOTIFICATION_LCDPROC */
1541
1542 #ifdef NOTIFICATION_TRAYICON
1543 static void notify_create_trayicon_page(PrefsPage *page, GtkWindow *window,
1544                 gpointer data)
1545 {
1546         GtkWidget *pvbox;
1547         GtkWidget *vbox;
1548         GtkWidget *checkbox;
1549         GtkWidget *hbox;
1550         GtkWidget *button;
1551
1552 #if defined(HAVE_LIBNOTIFY)
1553         GtkWidget *frame;
1554         GtkWidget *svbox;
1555         GtkWidget *label;
1556 #endif
1557
1558 #ifdef HAVE_LIBNOTIFY
1559         GtkWidget *ssvbox;
1560         GtkWidget *spinner;
1561         gdouble timeout;
1562 #endif
1563
1564         pvbox = gtk_vbox_new(FALSE, 20);
1565         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1566
1567         /* Enable trayicon */
1568         checkbox = gtk_check_button_new_with_label(_("Enable Trayicon"));
1569         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1570                         notify_config.trayicon_enabled);
1571         gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1572         g_signal_connect(G_OBJECT(checkbox), "toggled",
1573                         G_CALLBACK(notify_trayicon_enable_set_sensitivity), NULL);
1574         gtk_widget_show(checkbox);
1575         trayicon_page.trayicon_enabled = checkbox;
1576
1577         /* Container vbox for greying out everything */
1578         vbox = gtk_vbox_new(FALSE, 10);
1579         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1580         gtk_widget_show(vbox);
1581         trayicon_page.trayicon_cont_enable = vbox;
1582
1583         /* Hide at startup */
1584         checkbox = gtk_check_button_new_with_label(_("Hide at start-up"));
1585         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1586                         notify_config.trayicon_hide_at_startup);
1587         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
1588         gtk_widget_show(checkbox);
1589         trayicon_page.trayicon_hide_at_startup = checkbox;
1590
1591         /* Close to tray */
1592         checkbox = gtk_check_button_new_with_label(_("Close to tray"));
1593         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1594                         notify_config.trayicon_close_to_tray);
1595         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
1596         gtk_widget_show(checkbox);
1597         trayicon_page.trayicon_close_to_tray = checkbox;
1598
1599         /* Hide when iconified */
1600         checkbox = gtk_check_button_new_with_label(_("Hide when iconified"));
1601         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1602                         notify_config.trayicon_hide_when_iconified);
1603         gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
1604         gtk_widget_show(checkbox);
1605         trayicon_page.trayicon_hide_when_iconified = checkbox;
1606
1607         /* folder specific */
1608         hbox = gtk_hbox_new(FALSE, 10);
1609         gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1610         gtk_widget_show(hbox);
1611         checkbox = gtk_check_button_new_with_label(_("Only include selected folders"));
1612         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1613                         notify_config.trayicon_folder_specific);
1614         gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0);
1615         g_signal_connect(G_OBJECT(checkbox), "toggled",
1616                         G_CALLBACK(notify_trayicon_folder_specific_set_sensitivity),
1617                         NULL);
1618         gtk_widget_show(checkbox);
1619         trayicon_page.trayicon_folder_specific = checkbox;
1620         button = gtk_button_new_with_label(_("Select folders..."));
1621         g_signal_connect(G_OBJECT(button), "clicked",
1622                         G_CALLBACK(notification_foldercheck_sel_folders_cb),
1623                         TRAYICON_SPECIFIC_FOLDER_ID_STR);
1624         gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1625         trayicon_page.trayicon_cont_folder_specific = button;
1626         gtk_widget_show(button);
1627
1628 #ifdef HAVE_LIBNOTIFY
1629         /* Frame for trayicon popup stuff */
1630
1631         /* TRANSLATORS: "Toaster" does not refer to the kitchen appliance.
1632                  A toast is a small passive (non-focus-stealing)
1633                  notification bubble. If your language does not have a word
1634                  for that, go for something along the lines of "passive popup"
1635                  instead.See also
1636                  http://en.wikipedia.org/wiki/Toast_(computing) */
1637         PACK_FRAME (vbox, frame, _("Passive toaster popup"))
1638
1639         /* vbox for frame */
1640         svbox = gtk_vbox_new(FALSE, 10);
1641         gtk_container_set_border_width(GTK_CONTAINER(svbox), 5);
1642         gtk_container_add(GTK_CONTAINER(frame), svbox);
1643         gtk_widget_show(svbox);
1644
1645         /* Enable popup for the tray icon */
1646         checkbox = gtk_check_button_new_with_label(_("Enable popup"));
1647         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1648                         notify_config.trayicon_popup_enabled);
1649         g_signal_connect(G_OBJECT(checkbox), "toggled",
1650                         G_CALLBACK(notify_trayicon_popup_enable_set_sensitivity),
1651                         NULL);
1652         gtk_box_pack_start(GTK_BOX(svbox), checkbox, FALSE, FALSE, 0);
1653         gtk_widget_show(checkbox);
1654         trayicon_page.trayicon_popup_enabled = checkbox;
1655
1656         /* vbox for trayicon popup stuff enabled/disabled container */
1657         ssvbox = gtk_vbox_new(FALSE, 10);
1658         gtk_box_pack_start(GTK_BOX(svbox), ssvbox, FALSE, FALSE, 0);
1659         gtk_widget_show(ssvbox);
1660         trayicon_page.trayicon_popup_cont_enable = ssvbox;
1661
1662         /* timeout */
1663         hbox = gtk_hbox_new(FALSE, 10);
1664         label = gtk_label_new(_("Popup timeout"));
1665         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1666         gtk_widget_show(label);
1667         spinner = gtk_spin_button_new_with_range(TIMEOUT_SPINNER_MIN, TIMEOUT_SPINNER_MAX, TIMEOUT_SPINNER_STEP);
1668         gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinner), 1);
1669         timeout = notify_config.trayicon_popup_timeout/1000.;
1670         gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), timeout);
1671         gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
1672         gtk_box_pack_start(GTK_BOX(ssvbox), hbox, FALSE, FALSE, 0);
1673         label = gtk_label_new(_("seconds"));
1674         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1675
1676         checkbox = gtk_check_button_new_with_label(_("Display folder name"));
1677         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1678                         notify_config.trayicon_display_folder_name);
1679         gtk_box_pack_start(GTK_BOX(ssvbox), checkbox, FALSE, FALSE, 0);
1680         trayicon_page.trayicon_display_folder_name = checkbox;
1681         gtk_widget_show(checkbox);
1682
1683         gtk_widget_show(spinner);
1684         gtk_widget_show(label);
1685         gtk_widget_show(hbox);
1686         trayicon_page.trayicon_popup_timeout = spinner;
1687
1688 #endif
1689
1690         notify_trayicon_enable_set_sensitivity
1691         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_enabled), NULL);
1692
1693 #ifdef HAVE_LIBNOTIFY
1694         notify_trayicon_popup_enable_set_sensitivity
1695         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_popup_enabled), NULL);
1696 #endif
1697
1698         notify_trayicon_folder_specific_set_sensitivity
1699         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_folder_specific), NULL);
1700
1701         gtk_widget_show(pvbox);
1702         trayicon_page.page.widget = pvbox;
1703 }
1704
1705 static void notify_destroy_trayicon_page(PrefsPage *page)
1706 {
1707 }
1708
1709 static void notify_save_trayicon(PrefsPage *page)
1710 {
1711 #ifdef HAVE_LIBNOTIFY
1712         gdouble timeout;
1713 #endif
1714
1715         notify_config.trayicon_enabled =
1716         gtk_toggle_button_get_active
1717         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_enabled));
1718
1719         notify_config.trayicon_hide_at_startup =
1720         gtk_toggle_button_get_active
1721         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_hide_at_startup));
1722
1723         notify_config.trayicon_close_to_tray =
1724         gtk_toggle_button_get_active
1725         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_close_to_tray));
1726
1727         notify_config.trayicon_hide_when_iconified =
1728         gtk_toggle_button_get_active
1729         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_hide_when_iconified));
1730
1731 #ifdef HAVE_LIBNOTIFY
1732         notify_config.trayicon_popup_enabled =
1733         gtk_toggle_button_get_active
1734         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_popup_enabled));
1735
1736         timeout =
1737         gtk_spin_button_get_value(GTK_SPIN_BUTTON
1738                         (trayicon_page.trayicon_popup_timeout));
1739         notify_config.trayicon_popup_timeout = (gint)floor(timeout*1000+0.5);
1740
1741         notify_config.trayicon_display_folder_name =
1742                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(trayicon_page.trayicon_display_folder_name));
1743 #endif
1744
1745         notify_config.trayicon_folder_specific =
1746                 gtk_toggle_button_get_active
1747                 (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_folder_specific));
1748
1749         if(notify_config.trayicon_enabled)
1750         notification_update_msg_counts(NULL);
1751         else
1752         notification_trayicon_destroy();
1753 }
1754
1755 static void notify_trayicon_enable_set_sensitivity(GtkToggleButton *button,
1756                 gpointer data)
1757 {
1758         gboolean active;
1759         active = gtk_toggle_button_get_active
1760         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_enabled));
1761         gtk_widget_set_sensitive(trayicon_page.trayicon_cont_enable, active);
1762 }
1763
1764 static void notify_trayicon_folder_specific_set_sensitivity(GtkToggleButton *bu,
1765                 gpointer data)
1766 {
1767         gboolean active;
1768         active = gtk_toggle_button_get_active
1769         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_folder_specific));
1770         gtk_widget_set_sensitive(trayicon_page.trayicon_cont_folder_specific, active);
1771 }
1772
1773 #ifdef HAVE_LIBNOTIFY
1774 static void notify_trayicon_popup_enable_set_sensitivity(GtkToggleButton *bu,
1775                 gpointer data)
1776 {
1777         gboolean active;
1778         active = gtk_toggle_button_get_active
1779         (GTK_TOGGLE_BUTTON(trayicon_page.trayicon_popup_enabled));
1780         gtk_widget_set_sensitive(trayicon_page.trayicon_popup_cont_enable, active);
1781 }
1782
1783 #endif /* HAVE_LIBNOTIFY */
1784
1785 #endif /* NOTIFICATION_TRAYICON */
1786
1787 #ifdef NOTIFICATION_INDICATOR
1788
1789 static void notify_create_indicator_page(PrefsPage *page, GtkWindow *window,
1790                 gpointer data)
1791 {
1792         GtkWidget *pvbox;
1793         GtkWidget *vbox;
1794         GtkWidget *checkbox;
1795         GtkWidget *ind_reg;
1796
1797         pvbox = gtk_vbox_new(FALSE, 20);
1798         gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1799
1800         /* Enable indicator */
1801         checkbox = gtk_check_button_new_with_label(_("Add to Indicator Applet"));
1802         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
1803                         notify_config.indicator_enabled);
1804         gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1805         g_signal_connect(G_OBJECT(checkbox), "toggled",
1806                         G_CALLBACK(notify_indicator_enable_set_sensitivity), NULL);
1807         indicator_page.indicator_enabled = checkbox;
1808
1809         /* Container vbox for greying out everything */
1810         vbox = gtk_vbox_new(FALSE, 10);
1811         gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1812         indicator_page.indicator_cont_enable = vbox;
1813
1814         /* hide when minimized */
1815         checkbox = gtk_check_button_new_with_label(_("Hide mainwindow when minimized"));
1816         gtk_box_pack_start(GTK_BOX(indicator_page.indicator_cont_enable), checkbox, FALSE, FALSE, 0);
1817         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), notify_config.indicator_hide_minimized);
1818         indicator_page.indicator_hide_minimized = checkbox;
1819
1820         notify_indicator_enable_set_sensitivity(GTK_TOGGLE_BUTTON(indicator_page.indicator_enabled), NULL);
1821         gtk_widget_show_all(pvbox);
1822         indicator_page.page.widget = pvbox;
1823 }
1824
1825 static void notify_destroy_indicator_page(PrefsPage *page)
1826 {
1827 }
1828
1829 static void notify_save_indicator(PrefsPage *page)
1830 {
1831         notification_indicator_destroy();
1832
1833         notify_config.indicator_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(indicator_page.indicator_enabled));
1834
1835         notify_config.indicator_hide_minimized = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(indicator_page.indicator_hide_minimized));
1836
1837         if(notify_config.indicator_enabled) {
1838           notification_indicator_setup();
1839           notification_update_indicator();
1840         }
1841 }
1842
1843 static void notify_indicator_enable_set_sensitivity(GtkToggleButton *button,
1844                 gpointer data)
1845 {
1846         gboolean active;
1847         active = gtk_toggle_button_get_active
1848         (GTK_TOGGLE_BUTTON(indicator_page.indicator_enabled));
1849         gtk_widget_set_sensitive(indicator_page.indicator_cont_enable, active);
1850 }
1851 #endif /* NOTIFICATION_INDICATOR */
1852
1853 #ifdef NOTIFICATION_HOTKEYS
1854 static void notify_create_hotkeys_page(PrefsPage *page, GtkWindow *window, gpointer data)
1855 {
1856     GtkWidget *pvbox;
1857     GtkWidget *vbox;
1858     GtkWidget *checkbox;
1859     GtkWidget *label;
1860     gchar *markup;
1861     GtkWidget *hbox;
1862     GtkWidget *entry;
1863
1864     pvbox = gtk_vbox_new(FALSE, 20);
1865     gtk_container_set_border_width(GTK_CONTAINER(pvbox), 10);
1866
1867     /* Enable hotkeys */
1868     checkbox = gtk_check_button_new_with_label(_("Enable global hotkeys"));
1869     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),  notify_config.hotkeys_enabled);
1870     gtk_box_pack_start(GTK_BOX(pvbox), checkbox, FALSE, FALSE, 0);
1871     g_signal_connect(G_OBJECT(checkbox), "toggled",
1872         G_CALLBACK(notify_hotkeys_enable_set_sensitivity), NULL);
1873     hotkeys_page.hotkeys_enabled = checkbox;
1874
1875     /* Container vbox for greying out everything */
1876     vbox = gtk_vbox_new(FALSE, 10);
1877     gtk_box_pack_start(GTK_BOX(pvbox), vbox, FALSE, FALSE, 0);
1878     hotkeys_page.hotkeys_cont_enable = vbox;
1879
1880     /* description */
1881     label = gtk_label_new("");
1882     markup = g_markup_printf_escaped(_("Examples for hotkeys include <b>%s</b> and <b>%s</b>"), _("<control><shift>F11"), _("<alt>N"));
1883     gtk_label_set_markup(GTK_LABEL(label), markup);
1884     gtk_misc_set_alignment(GTK_MISC(label), 0., 0.);
1885     g_free(markup);
1886     gtk_box_pack_start(GTK_BOX(hotkeys_page.hotkeys_cont_enable), label, FALSE, FALSE, 0);
1887
1888     /* hbox for entry fields */
1889     hbox = gtk_hbox_new(FALSE, 6);
1890     gtk_box_pack_start(GTK_BOX(hotkeys_page.hotkeys_cont_enable), hbox, FALSE, FALSE, 0);
1891
1892     /* toggle mainwindow */
1893     label = gtk_label_new(_("Toggle minimize"));
1894     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1895     entry = gtk_entry_new();
1896     gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
1897     if(notify_config.hotkeys_toggle_mainwindow)
1898       gtk_entry_set_text(GTK_ENTRY(entry), notify_config.hotkeys_toggle_mainwindow);
1899     hotkeys_page.hotkeys_toggle_mainwindow = entry;
1900
1901     notify_hotkeys_enable_set_sensitivity(GTK_TOGGLE_BUTTON(hotkeys_page.hotkeys_enabled), NULL);
1902     gtk_widget_show_all(pvbox);
1903     hotkeys_page.page.widget = pvbox;
1904 }
1905
1906 static void notify_destroy_hotkeys_page(PrefsPage *page)
1907 {
1908 }
1909
1910 static void notify_save_hotkeys(PrefsPage *page)
1911 {
1912     const gchar *tmp_str;
1913     notify_config.hotkeys_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hotkeys_page.hotkeys_enabled));
1914
1915     tmp_str = gtk_entry_get_text(GTK_ENTRY(hotkeys_page.hotkeys_toggle_mainwindow));
1916     if(notify_config.hotkeys_toggle_mainwindow)
1917       g_free(notify_config.hotkeys_toggle_mainwindow);
1918     notify_config.hotkeys_toggle_mainwindow = g_strdup(tmp_str);
1919
1920     notification_hotkeys_update_bindings();
1921 }
1922
1923 static void notify_hotkeys_enable_set_sensitivity(GtkToggleButton *button,
1924         gpointer data)
1925 {
1926     gboolean active;
1927     active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hotkeys_page.hotkeys_enabled));
1928     gtk_widget_set_sensitive(hotkeys_page.hotkeys_cont_enable, active);
1929 }
1930 #endif /* hotkeys */
1931
1932
1933 /* This feels so wrong... */
1934 static gint conv_color_to_int(GdkColor *color)
1935 {
1936         gint result;
1937         guint red, green, blue;
1938
1939         red = (guint) ((gdouble)(color->red) /65535.*255.);
1940         green = (guint) ((gdouble)(color->green) /65535.*255.);
1941         blue = (guint) ((gdouble)(color->blue) /65535.*255.);
1942
1943         result = (gint) (blue | (green<<8)| (red<<16));
1944
1945         return result;
1946 }