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