64ea6da566ddcfa325641d0d3cad70f26f479688
[claws.git] / src / plugins / vcalendar / vcal_prefs.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net> and 
4  * the Claws Mail team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #include "claws-features.h"
24 #endif
25
26 #include <stddef.h>
27 #include <glib.h>
28 #include <glib/gi18n.h>
29
30 #include "defs.h"
31
32 #include "mainwindow.h"
33 #include "prefs.h"
34 #include "prefs_gtk.h"
35 #include "prefswindow.h"
36 #include "common/utils.h"
37
38 #include "vcalendar.h"
39 #include "vcal_prefs.h"
40 #include "vcal_folder.h"
41 #include "vcal_dbus.h"
42
43 #define PREFS_BLOCK_NAME "VCalendar"
44
45 struct VcalendarPage
46 {
47         PrefsPage page;
48         
49         GtkWidget *alert_enable_btn;
50         GtkWidget *alert_delay_spinbtn;
51
52         GtkWidget *export_enable_btn;
53         GtkWidget *export_subs_btn;
54         GtkWidget *export_path_entry;
55         GtkWidget *export_command_entry;
56         
57         GtkWidget *export_user_label;
58         GtkWidget *export_user_entry;
59         GtkWidget *export_pass_label;
60         GtkWidget *export_pass_entry;
61
62         GtkWidget *export_freebusy_enable_btn;
63         GtkWidget *export_freebusy_path_entry;
64         GtkWidget *export_freebusy_command_entry;
65         
66         GtkWidget *export_freebusy_user_label;
67         GtkWidget *export_freebusy_user_entry;
68         GtkWidget *export_freebusy_pass_label;
69         GtkWidget *export_freebusy_pass_entry;
70
71         GtkWidget *freebusy_get_url_entry;
72         
73         GtkWidget *ssl_verify_peer_checkbtn;
74         GtkWidget *calendar_server_checkbtn;
75 };
76
77 VcalendarPrefs vcalprefs;
78 static struct VcalendarPage vcal_prefs_page;
79
80 static PrefParam param[] = {
81         {"alert_delay", "10", &vcalprefs.alert_delay, P_INT,
82          NULL, NULL, NULL},
83         {"alert_enable", "FALSE", &vcalprefs.alert_enable, P_BOOL,
84          NULL, NULL, NULL},
85
86         {"export_enable", "FALSE", &vcalprefs.export_enable, P_BOOL,
87          NULL, NULL, NULL},
88         {"export_subs", "TRUE", &vcalprefs.export_subs, P_BOOL,
89          NULL, NULL, NULL},
90         {"export_path", "", &vcalprefs.export_path, P_STRING,
91          NULL, NULL, NULL},
92         {"export_command", NULL, &vcalprefs.export_command, P_STRING,
93          NULL, NULL, NULL},
94
95         {"export_user", "", &vcalprefs.export_user, P_STRING,
96          NULL, NULL, NULL},
97         {"export_pass", "", &vcalprefs.export_pass, P_PASSWORD,
98          NULL, NULL, NULL},
99
100         {"orage_registered", "FALSE", &vcalprefs.orage_registered, P_BOOL,
101          NULL, NULL, NULL},
102
103         {"export_freebusy_enable", "FALSE", &vcalprefs.export_freebusy_enable, P_BOOL,
104          NULL, NULL, NULL},
105         {"export_freebusy_path", "", &vcalprefs.export_freebusy_path, P_STRING,
106          NULL, NULL, NULL},
107         {"export_freebusy_command", NULL, &vcalprefs.export_freebusy_command, P_STRING,
108          NULL, NULL, NULL},
109         {"freebusy_get_url", NULL, &vcalprefs.freebusy_get_url, P_STRING,
110          NULL, NULL, NULL},
111
112         {"export_freebusy_user", "", &vcalprefs.export_freebusy_user, P_STRING,
113          NULL, NULL, NULL},
114         {"export_freebusy_pass", "", &vcalprefs.export_freebusy_pass, P_PASSWORD,
115          NULL, NULL, NULL},
116
117         {"ssl_verify_peer", "TRUE", &vcalprefs.ssl_verify_peer, P_BOOL,
118          NULL, NULL, NULL},
119
120         {"calendar_server", "FALSE", &vcalprefs.calendar_server, P_BOOL,
121          NULL, NULL, NULL},
122
123         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
124 };
125
126 static void set_auth_sensitivity(struct VcalendarPage *page)
127 {
128         const gchar *export_path, *export_freebusy_path;
129         gboolean export_enable, export_freebusy_enable;
130         
131         export_enable = gtk_toggle_button_get_active(
132                         GTK_TOGGLE_BUTTON(page->export_enable_btn));
133         export_freebusy_enable = gtk_toggle_button_get_active(
134                         GTK_TOGGLE_BUTTON(page->export_freebusy_enable_btn));
135         
136         export_path = gtk_entry_get_text(GTK_ENTRY(page->export_path_entry));
137         export_freebusy_path = gtk_entry_get_text(GTK_ENTRY(page->export_freebusy_path_entry));
138         if (export_enable && export_path &&
139             (!strncmp(export_path, "http://", 7) ||
140              !strncmp(export_path, "ftp://", 6) ||
141              !strncmp(export_path, "https://", 8) ||
142              !strncmp(export_path, "sftp://", 5) ||
143              !strncmp(export_path, "webcal://", 9) ||
144              !strncmp(export_path, "webcals://", 10))) {
145                 gtk_widget_set_sensitive(page->export_user_label, TRUE);        
146                 gtk_widget_set_sensitive(page->export_user_entry, TRUE);        
147                 gtk_widget_set_sensitive(page->export_pass_label, TRUE);        
148                 gtk_widget_set_sensitive(page->export_pass_entry, TRUE);        
149         } else {
150                 gtk_widget_set_sensitive(page->export_user_label, FALSE);       
151                 gtk_widget_set_sensitive(page->export_user_entry, FALSE);       
152                 gtk_widget_set_sensitive(page->export_pass_label, FALSE);       
153                 gtk_widget_set_sensitive(page->export_pass_entry, FALSE);       
154         }
155         if (export_freebusy_enable && export_freebusy_path &&
156             (!strncmp(export_freebusy_path, "http://", 7) ||
157              !strncmp(export_freebusy_path, "ftp://", 6) ||
158              !strncmp(export_freebusy_path, "https://", 8) ||
159              !strncmp(export_freebusy_path, "sftp://", 5) ||
160              !strncmp(export_freebusy_path, "webcal://", 9) ||
161              !strncmp(export_freebusy_path, "webcals://", 10))) {
162                 gtk_widget_set_sensitive(page->export_freebusy_user_label, TRUE);       
163                 gtk_widget_set_sensitive(page->export_freebusy_user_entry, TRUE);       
164                 gtk_widget_set_sensitive(page->export_freebusy_pass_label, TRUE);       
165                 gtk_widget_set_sensitive(page->export_freebusy_pass_entry, TRUE);       
166         } else {
167                 gtk_widget_set_sensitive(page->export_freebusy_user_label, FALSE);      
168                 gtk_widget_set_sensitive(page->export_freebusy_user_entry, FALSE);      
169                 gtk_widget_set_sensitive(page->export_freebusy_pass_label, FALSE);      
170                 gtk_widget_set_sensitive(page->export_freebusy_pass_entry, FALSE);      
171         }       
172 }
173
174 static void path_changed(GtkWidget *widget, gpointer data)
175 {
176         set_auth_sensitivity((struct VcalendarPage *)data);
177 }
178
179 static gboolean orage_available(void)
180 {
181         gchar *tmp = g_find_program_in_path("orage");
182         if (tmp) {
183                 g_free(tmp);
184                 return TRUE;
185         }
186         return FALSE;
187 }
188
189 static void orage_register(gboolean reg)
190 {
191         if (orage_available()) {
192                 gchar *orage_argv[4];
193                 gchar *cmdline = g_strdup_printf("%s%svcalendar%sinternal.ics",
194                                 get_rc_dir(), G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S);
195
196                 debug_print("telling Orage %s us ...\n", reg?"about":"to forget");
197                 orage_argv[0] = "orage";
198                 orage_argv[1] = reg ? "--add-foreign":"--remove-foreign";
199                 orage_argv[2] = cmdline;
200                 orage_argv[3] = NULL;
201                 g_spawn_async(NULL, (gchar **)orage_argv, NULL, 
202                         G_SPAWN_SEARCH_PATH|G_SPAWN_STDOUT_TO_DEV_NULL|
203                                 G_SPAWN_STDERR_TO_DEV_NULL,
204                         NULL, NULL, NULL, FALSE);
205                 g_free(cmdline);
206         }
207 }
208
209 void register_orage_checkbtn_toggled(GtkToggleButton    *toggle_btn,
210                                         GtkWidget               *widget)
211 {
212         orage_register(gtk_toggle_button_get_active(toggle_btn));
213         vcalprefs.orage_registered = gtk_toggle_button_get_active(toggle_btn);
214 }
215
216 void calendar_server_checkbtn_toggled(GtkToggleButton *toggle, GtkWidget *widget)
217 {
218         gboolean active = gtk_toggle_button_get_active(toggle);
219         if (active)
220                 connect_dbus();
221         else
222                 disconnect_dbus();
223         vcalprefs.calendar_server = active;
224 }
225
226 static void vcal_prefs_create_widget_func(PrefsPage * _page,
227                                            GtkWindow * window,
228                                            gpointer data)
229 {
230         struct VcalendarPage *page = (struct VcalendarPage *) _page;
231
232         GtkWidget *vbox1, *vbox2, *vbox3;
233         GtkWidget *hbox1, *hbox2, *hbox3;
234         
235         GtkWidget *frame_alert;
236         GtkWidget *alert_enable_checkbtn;
237         GtkObject *alert_enable_spinbtn_adj;
238         GtkWidget *alert_enable_spinbtn;
239         GtkWidget *label_alert_enable;
240
241         GtkWidget *frame_export;
242         GtkWidget *export_enable_checkbtn;
243         GtkWidget *export_subs_checkbtn;
244         GtkWidget *export_path_entry;
245         GtkWidget *export_command_label;
246         GtkWidget *export_command_entry;
247         GtkWidget *register_orage_checkbtn;
248         GtkWidget *calendar_server_checkbtn;
249
250         GtkWidget *export_user_label;
251         GtkWidget *export_user_entry;
252         GtkWidget *export_pass_label;
253         GtkWidget *export_pass_entry;
254
255         GtkWidget *frame_freebusy_export;
256         GtkWidget *export_freebusy_enable_checkbtn;
257         GtkWidget *export_freebusy_path_entry;
258         GtkWidget *export_freebusy_command_label;
259         GtkWidget *export_freebusy_command_entry;
260
261         GtkWidget *export_freebusy_user_label;
262         GtkWidget *export_freebusy_user_entry;
263         GtkWidget *export_freebusy_pass_label;
264         GtkWidget *export_freebusy_pass_entry;
265
266         GtkWidget *freebusy_get_url_label;
267         GtkWidget *freebusy_get_url_entry;
268
269         GtkWidget *frame_ssl_options;
270         GtkWidget *ssl_verify_peer_checkbtn;
271
272         vbox1 = gtk_vbox_new (FALSE, VSPACING);
273         gtk_widget_show (vbox1);
274         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
275
276         vbox2 = gtk_vbox_new (FALSE, 4);
277         gtk_widget_show (vbox2);
278         gtk_box_pack_start(GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
279
280
281 /* alert stuff */
282         PACK_FRAME(vbox2, frame_alert, _("Reminders"));
283         vbox3 = gtk_vbox_new (FALSE, 8);
284         gtk_widget_show (vbox3);
285         gtk_container_add (GTK_CONTAINER (frame_alert), vbox3);
286         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
287         hbox1 = gtk_hbox_new (FALSE, 8);
288         gtk_widget_show (hbox1);
289         gtk_box_pack_start(GTK_BOX (vbox3), hbox1, TRUE, TRUE, 0);
290
291         alert_enable_checkbtn = gtk_check_button_new_with_label(_("Alert me"));
292         gtk_widget_show (alert_enable_checkbtn);
293         gtk_box_pack_start(GTK_BOX (hbox1), alert_enable_checkbtn, FALSE, FALSE, 0);
294
295         alert_enable_spinbtn_adj = gtk_adjustment_new (10, 1, 24*60, 1, 10, 0);
296         alert_enable_spinbtn = gtk_spin_button_new
297                 (GTK_ADJUSTMENT (alert_enable_spinbtn_adj), 1, 0);
298         gtk_widget_set_size_request (alert_enable_spinbtn, 64, -1);
299         gtk_widget_show (alert_enable_spinbtn);
300         gtk_box_pack_start(GTK_BOX (hbox1), alert_enable_spinbtn, FALSE, FALSE, 0);
301         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (alert_enable_spinbtn), TRUE);
302
303         label_alert_enable = gtk_label_new(_("minutes before an event"));
304         gtk_widget_show (label_alert_enable);
305         gtk_box_pack_start(GTK_BOX (hbox1), label_alert_enable, FALSE, FALSE, 0);
306
307         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(alert_enable_checkbtn), 
308                         vcalprefs.alert_enable);
309         gtk_spin_button_set_value(GTK_SPIN_BUTTON(alert_enable_spinbtn),
310                         vcalprefs.alert_delay);
311         SET_TOGGLE_SENSITIVITY(alert_enable_checkbtn, alert_enable_spinbtn);
312
313 /* calendar export */
314 /* export enable + path stuff */
315         PACK_FRAME(vbox2, frame_export, _("Calendar export"));
316         vbox3 = gtk_vbox_new (FALSE, 8);
317         gtk_widget_show (vbox3);
318         gtk_container_add (GTK_CONTAINER (frame_export), vbox3);
319         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
320
321 /* export path */
322         hbox2 = gtk_hbox_new (FALSE, 8);
323         gtk_widget_show (hbox2);
324         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
325
326         export_enable_checkbtn = gtk_check_button_new_with_label(_("Automatically export calendar to"));
327         gtk_widget_show(export_enable_checkbtn);
328         gtk_box_pack_start(GTK_BOX (hbox2), export_enable_checkbtn, FALSE, FALSE, 0);
329
330         export_path_entry = gtk_entry_new();
331         gtk_widget_show(export_path_entry);
332         gtk_box_pack_start(GTK_BOX(hbox2), export_path_entry, TRUE, TRUE, 0);
333         SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_path_entry);
334         CLAWS_SET_TIP(export_enable_checkbtn, 
335                             _("You can export to a local file or URL"));
336         CLAWS_SET_TIP(export_path_entry, 
337                             _("Specify a local file or URL "
338                               "(http://server/path/file.ics)"));
339
340 /* export auth */
341         hbox2 = gtk_hbox_new (FALSE, 8);
342         gtk_widget_show (hbox2);
343         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
344
345         export_user_label = gtk_label_new(_("User ID"));
346         gtk_widget_show(export_user_label);
347         gtk_box_pack_start(GTK_BOX (hbox2), export_user_label, FALSE, FALSE, 0);
348
349         export_user_entry = gtk_entry_new();
350         gtk_widget_show(export_user_entry);
351         gtk_box_pack_start(GTK_BOX (hbox2), export_user_entry, FALSE, FALSE, 0);
352
353         export_pass_label = gtk_label_new(_("Password"));
354         gtk_widget_show(export_pass_label);
355         gtk_box_pack_start(GTK_BOX (hbox2), export_pass_label, FALSE, FALSE, 0);
356
357         export_pass_entry = gtk_entry_new();
358         gtk_entry_set_visibility(GTK_ENTRY(export_pass_entry), FALSE);
359         gtk_widget_show(export_pass_entry);
360         gtk_box_pack_start(GTK_BOX (hbox2), export_pass_entry, FALSE, FALSE, 0);
361
362 /* export subscriptions too */
363         hbox2 = gtk_hbox_new (FALSE, 8);
364         gtk_widget_show (hbox2);
365         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
366
367         export_subs_checkbtn = gtk_check_button_new_with_label(_("Include webcal subscriptions in export"));
368         gtk_widget_show(export_subs_checkbtn);
369         gtk_box_pack_start(GTK_BOX (hbox2), export_subs_checkbtn, FALSE, FALSE, 0);
370         SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_subs_checkbtn);
371
372 /* run-command after export stuff */
373         hbox3 = gtk_hbox_new (FALSE, 8);
374         gtk_widget_show (hbox3);
375         gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
376
377         export_command_label = gtk_label_new(_("Command to run after calendar export"));
378         gtk_widget_show(export_command_label);
379         gtk_box_pack_start(GTK_BOX (hbox3), export_command_label, FALSE, FALSE, 0);
380         SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_command_label);
381
382         export_command_entry = gtk_entry_new();
383         gtk_widget_show(export_command_entry);
384         gtk_box_pack_start(GTK_BOX (hbox3), export_command_entry, TRUE, TRUE, 0);
385         SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_command_entry);
386
387
388         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_enable_checkbtn), 
389                         vcalprefs.export_enable);
390         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_subs_checkbtn), 
391                         vcalprefs.export_subs);
392         if (vcalprefs.export_path == NULL || *vcalprefs.export_path == '\0')
393                 vcalprefs.export_path = g_strconcat(get_rc_dir(), 
394                                         G_DIR_SEPARATOR_S,
395                                         "claws-mail.ics", NULL);
396         if (vcalprefs.export_command == NULL)
397                 vcalprefs.export_command = g_strdup("");
398         gtk_entry_set_text(GTK_ENTRY(export_path_entry), 
399                         vcalprefs.export_path);
400         gtk_entry_set_text(GTK_ENTRY(export_command_entry), 
401                         vcalprefs.export_command);
402
403         hbox3 = gtk_hbox_new (FALSE, 8);
404         gtk_widget_show (hbox3);
405         gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
406         register_orage_checkbtn = gtk_check_button_new_with_label(_("Register Claws' calendar in XFCE's Orage clock"));
407         CLAWS_SET_TIP(register_orage_checkbtn, 
408                             _("Allows Orage (version greater than 4.4) to see Claws Mail's calendar"));
409
410         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(register_orage_checkbtn), 
411                         vcalprefs.orage_registered);
412         gtk_widget_set_sensitive(register_orage_checkbtn, orage_available());
413         g_signal_connect(G_OBJECT(register_orage_checkbtn), "toggled",
414                          G_CALLBACK(register_orage_checkbtn_toggled), NULL); 
415         gtk_widget_show (register_orage_checkbtn);
416         gtk_box_pack_start(GTK_BOX (hbox3), register_orage_checkbtn, TRUE, TRUE, 0);
417
418         calendar_server_checkbtn = gtk_check_button_new_with_label(_("Export as GNOME shell calendar server"));
419         CLAWS_SET_TIP(calendar_server_checkbtn,
420                       _("Register D-Bus calendar server interface to export Claws Mail's calendar"));
421         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(calendar_server_checkbtn),
422                                      vcalprefs.calendar_server);
423         g_signal_connect(G_OBJECT(calendar_server_checkbtn), "toggled",
424                          G_CALLBACK(calendar_server_checkbtn_toggled), NULL);
425         gtk_widget_show(calendar_server_checkbtn);
426         gtk_box_pack_start(GTK_BOX(hbox3), calendar_server_checkbtn, TRUE, TRUE, 0);
427
428 /* freebusy export */
429 /* export enable + path stuff */
430         PACK_FRAME(vbox2, frame_freebusy_export, _("Free/Busy information"));
431         vbox3 = gtk_vbox_new (FALSE, 8);
432         gtk_widget_show (vbox3);
433         gtk_container_add (GTK_CONTAINER (frame_freebusy_export), vbox3);
434         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
435
436 /* export */
437         hbox2 = gtk_hbox_new (FALSE, 8);
438         gtk_widget_show (hbox2);
439         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
440
441         export_freebusy_enable_checkbtn = gtk_check_button_new_with_label(
442                 _("Automatically export free/busy status to"));
443         gtk_widget_show(export_freebusy_enable_checkbtn);
444         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_enable_checkbtn, FALSE, FALSE, 0);
445
446         export_freebusy_path_entry = gtk_entry_new();
447         gtk_widget_show(export_freebusy_path_entry);
448         gtk_box_pack_start(GTK_BOX(hbox2), export_freebusy_path_entry, TRUE, TRUE, 0);
449         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_path_entry);
450         CLAWS_SET_TIP(export_freebusy_enable_checkbtn, 
451                             _("You can export to a local file or URL"));
452         CLAWS_SET_TIP(export_freebusy_path_entry, 
453                             _("Specify a local file or URL "
454                               "(http://server/path/file.ifb)"));
455
456 /* auth */
457         hbox2 = gtk_hbox_new (FALSE, 8);
458         gtk_widget_show (hbox2);
459         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
460
461         export_freebusy_user_label = gtk_label_new(_("User ID"));
462         gtk_widget_show(export_freebusy_user_label);
463         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_label, FALSE, FALSE, 0);
464
465         export_freebusy_user_entry = gtk_entry_new();
466         gtk_widget_show(export_freebusy_user_entry);
467         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_entry, FALSE, FALSE, 0);
468
469         export_freebusy_pass_label = gtk_label_new(_("Password"));
470         gtk_widget_show(export_freebusy_pass_label);
471         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_label, FALSE, FALSE, 0);
472
473         export_freebusy_pass_entry = gtk_entry_new();
474         gtk_entry_set_visibility(GTK_ENTRY(export_freebusy_pass_entry), FALSE);
475         gtk_widget_show(export_freebusy_pass_entry);
476         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_entry, FALSE, FALSE, 0);
477
478 /* run-command after export stuff */
479         hbox3 = gtk_hbox_new (FALSE, 8);
480         gtk_widget_show (hbox3);
481         gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
482
483         export_freebusy_command_label = gtk_label_new(_("Command to run after free/busy status export"));
484         gtk_widget_show(export_freebusy_command_label);
485         gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_label, FALSE, FALSE, 0);
486         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_label);
487         export_freebusy_command_entry = gtk_entry_new();
488         gtk_widget_show(export_freebusy_command_entry);
489         gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_entry, TRUE, TRUE, 0);
490         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_entry);
491
492         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_freebusy_enable_checkbtn), 
493                         vcalprefs.export_freebusy_enable);
494         if (vcalprefs.export_freebusy_path == NULL || 
495             *vcalprefs.export_freebusy_path == '\0')
496                 vcalprefs.export_freebusy_path = g_strconcat(get_rc_dir(), 
497                                         G_DIR_SEPARATOR_S,
498                                         "claws-mail.ifb", NULL);
499         if (vcalprefs.export_freebusy_command == NULL)
500                 vcalprefs.export_freebusy_command = g_strdup("");
501         if (vcalprefs.freebusy_get_url == NULL)
502                 vcalprefs.freebusy_get_url = g_strdup("");
503
504 /* free/busy import */
505         hbox2 = gtk_hbox_new (FALSE, 8);
506         gtk_widget_show (hbox2);
507         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
508
509         freebusy_get_url_label = gtk_label_new(
510                 _("Get free/busy status of others from"));
511         gtk_widget_show(freebusy_get_url_label);
512         gtk_box_pack_start(GTK_BOX (hbox2), freebusy_get_url_label, FALSE, FALSE, 0);
513
514         freebusy_get_url_entry = gtk_entry_new();
515         gtk_widget_show(freebusy_get_url_entry);
516         gtk_box_pack_start(GTK_BOX(hbox2), freebusy_get_url_entry, TRUE, TRUE, 0);
517         CLAWS_SET_TIP(freebusy_get_url_entry, 
518                             _("Specify a local file or URL "
519                               "(http://server/path/file.ifb). Use %u "
520                               "for the left part of the email address, %d for "
521                               "the domain"));
522
523         gtk_entry_set_text(GTK_ENTRY(export_freebusy_path_entry), 
524                         vcalprefs.export_freebusy_path);
525         gtk_entry_set_text(GTK_ENTRY(export_freebusy_command_entry), 
526                         vcalprefs.export_freebusy_command);
527
528         gtk_entry_set_text(GTK_ENTRY(freebusy_get_url_entry), 
529                         vcalprefs.freebusy_get_url);
530
531 /* SSL frame */
532         PACK_FRAME(vbox2, frame_ssl_options, _("SSL options"));
533         vbox3 = gtk_vbox_new (FALSE, 8);
534         gtk_widget_show (vbox3);
535         gtk_container_add (GTK_CONTAINER (frame_ssl_options), vbox3);
536         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
537
538 /* SSL peer verification */
539         hbox2 = gtk_hbox_new (FALSE, 8);
540         gtk_widget_show (hbox2);
541         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
542
543         ssl_verify_peer_checkbtn = gtk_check_button_new_with_label(
544                 _("Verify SSL certificate validity"));
545         gtk_widget_show(ssl_verify_peer_checkbtn);
546         gtk_box_pack_start(GTK_BOX (hbox2), ssl_verify_peer_checkbtn, FALSE, FALSE, 0);
547         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl_verify_peer_checkbtn), 
548                         vcalprefs.ssl_verify_peer);
549
550         if (!vcalprefs.export_user)
551                 vcalprefs.export_user = g_strdup("");
552         if (!vcalprefs.export_pass)
553                 vcalprefs.export_pass = g_strdup("");
554         if (!vcalprefs.export_freebusy_user)
555                 vcalprefs.export_freebusy_user = g_strdup("");
556         if (!vcalprefs.export_freebusy_pass)
557                 vcalprefs.export_freebusy_pass = g_strdup("");
558
559         gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
560         gtk_entry_set_text(GTK_ENTRY(export_pass_entry), vcalprefs.export_pass);
561         gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
562         gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), vcalprefs.export_freebusy_pass);
563
564         g_signal_connect(G_OBJECT(export_enable_checkbtn),
565                          "toggled", G_CALLBACK(path_changed), page);
566         g_signal_connect(G_OBJECT(export_freebusy_enable_checkbtn),
567                          "toggled", G_CALLBACK(path_changed), page);
568         g_signal_connect(G_OBJECT(export_path_entry),
569                          "changed", G_CALLBACK(path_changed), page);
570         g_signal_connect(G_OBJECT(export_freebusy_path_entry),
571                          "changed", G_CALLBACK(path_changed), page);
572
573         page->alert_enable_btn = alert_enable_checkbtn;
574         page->alert_delay_spinbtn = alert_enable_spinbtn;
575
576         page->export_enable_btn = export_enable_checkbtn;
577         page->export_subs_btn = export_subs_checkbtn;
578         page->export_path_entry = export_path_entry;
579         page->export_command_entry = export_command_entry;
580
581         page->export_freebusy_enable_btn = export_freebusy_enable_checkbtn;
582         page->export_freebusy_path_entry = export_freebusy_path_entry;
583         page->export_freebusy_command_entry = export_freebusy_command_entry;
584
585         page->export_user_label = export_user_label;
586         page->export_user_entry = export_user_entry;
587         page->export_pass_label = export_pass_label;
588         page->export_pass_entry = export_pass_entry;
589
590         page->export_freebusy_user_label = export_freebusy_user_label;
591         page->export_freebusy_user_entry = export_freebusy_user_entry;
592         page->export_freebusy_pass_label = export_freebusy_pass_label;
593         page->export_freebusy_pass_entry = export_freebusy_pass_entry;
594
595         page->ssl_verify_peer_checkbtn = ssl_verify_peer_checkbtn;
596
597         set_auth_sensitivity(page);
598
599         page->freebusy_get_url_entry = freebusy_get_url_entry;
600
601         page->page.widget = vbox1;
602 }
603
604 static void vcal_prefs_destroy_widget_func(PrefsPage *_page)
605 {
606 }
607
608 void vcal_prefs_save(void)
609 {
610         PrefFile *pfile;
611         gchar *rcpath;
612         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
613         pfile = prefs_write_open(rcpath);
614         g_free(rcpath);
615         if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
616                 return;
617
618         if (prefs_write_param(param, pfile->fp) < 0) {
619                 g_warning("failed to write vCalendar configuration to file");
620                 prefs_file_close_revert(pfile);
621                 return;
622         }
623         if (fprintf(pfile->fp, "\n") < 0) {
624                 FILE_OP_ERROR(rcpath, "fprintf");
625                 prefs_file_close_revert(pfile);
626         } else
627                 prefs_file_close(pfile);
628 }
629
630 static void vcal_prefs_save_func(PrefsPage * _page)
631 {
632         struct VcalendarPage *page = (struct VcalendarPage *) _page;
633
634 /* alert */
635         vcalprefs.alert_enable =
636             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
637                                          (page->alert_enable_btn));
638         vcalprefs.alert_delay =
639                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
640                                                  (page->alert_delay_spinbtn));
641
642 /* calendar export */
643         vcalprefs.export_enable = 
644             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
645                                          (page->export_enable_btn));
646         
647         vcalprefs.export_subs = 
648             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
649                                          (page->export_subs_btn));
650         
651         g_free(vcalprefs.export_path);
652         vcalprefs.export_path =
653             gtk_editable_get_chars(GTK_EDITABLE(page->export_path_entry), 0, -1);
654
655         g_free(vcalprefs.export_command);
656         vcalprefs.export_command =
657             gtk_editable_get_chars(GTK_EDITABLE(page->export_command_entry), 0, -1);
658         
659         g_free(vcalprefs.export_user);
660         vcalprefs.export_user =
661             gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
662         g_free(vcalprefs.export_pass);
663         vcalprefs.export_pass =
664             gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
665         
666 /* free/busy export */
667         vcalprefs.export_freebusy_enable = 
668             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
669                                          (page->export_freebusy_enable_btn));
670         
671         g_free(vcalprefs.export_freebusy_path);
672         vcalprefs.export_freebusy_path =
673             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_path_entry), 0, -1);
674
675         g_free(vcalprefs.export_freebusy_command);
676         vcalprefs.export_freebusy_command =
677             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_command_entry), 0, -1);
678
679         g_free(vcalprefs.export_freebusy_user);
680         vcalprefs.export_freebusy_user =
681             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
682         g_free(vcalprefs.export_freebusy_pass);
683         vcalprefs.export_freebusy_pass =
684             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
685         
686
687 /* free/busy import */
688         g_free(vcalprefs.freebusy_get_url);
689         vcalprefs.freebusy_get_url =
690             gtk_editable_get_chars(GTK_EDITABLE(page->freebusy_get_url_entry), 0, -1);
691
692 /* SSL */
693         vcalprefs.ssl_verify_peer = 
694             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
695                                          (page->ssl_verify_peer_checkbtn));
696
697         vcal_prefs_save();
698         vcal_folder_export(NULL);
699 }
700
701 void vcal_prefs_init(void)
702 {
703         static gchar *path[3];
704         gchar *rcpath;
705
706         path[0] = _("Plugins");
707         path[1] = _("vCalendar");
708         path[2] = NULL;
709
710         prefs_set_default(param);
711         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
712         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
713         g_free(rcpath);
714
715         vcal_prefs_page.page.path = path;
716         vcal_prefs_page.page.create_widget = vcal_prefs_create_widget_func;
717         vcal_prefs_page.page.destroy_widget = vcal_prefs_destroy_widget_func;
718         vcal_prefs_page.page.save_page = vcal_prefs_save_func;
719
720         prefs_gtk_register_page((PrefsPage *) &vcal_prefs_page);
721 }
722
723 void vcal_prefs_done(void)
724 {
725         prefs_gtk_unregister_page((PrefsPage *) &vcal_prefs_page);
726 }