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