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