4d420409c6c43a0f372ae788b10cc988dbc07954
[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         hbox3 = gtk_hbox_new (FALSE, 8);
419         gtk_widget_show (hbox3);
420         gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
421         calendar_server_checkbtn = gtk_check_button_new_with_label(_("Export as GNOME shell calendar server"));
422         CLAWS_SET_TIP(calendar_server_checkbtn,
423                       _("Register D-Bus calendar server interface to export Claws Mail's calendar"));
424         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(calendar_server_checkbtn),
425                                      vcalprefs.calendar_server);
426         g_signal_connect(G_OBJECT(calendar_server_checkbtn), "toggled",
427                          G_CALLBACK(calendar_server_checkbtn_toggled), NULL);
428         gtk_widget_show(calendar_server_checkbtn);
429         gtk_box_pack_start(GTK_BOX(hbox3), calendar_server_checkbtn, TRUE, TRUE, 0);
430
431 /* freebusy export */
432 /* export enable + path stuff */
433         PACK_FRAME(vbox2, frame_freebusy_export, _("Free/Busy information"));
434         vbox3 = gtk_vbox_new (FALSE, 8);
435         gtk_widget_show (vbox3);
436         gtk_container_add (GTK_CONTAINER (frame_freebusy_export), vbox3);
437         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
438
439 /* export */
440         hbox2 = gtk_hbox_new (FALSE, 8);
441         gtk_widget_show (hbox2);
442         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
443
444         export_freebusy_enable_checkbtn = gtk_check_button_new_with_label(
445                 _("Automatically export free/busy status to"));
446         gtk_widget_show(export_freebusy_enable_checkbtn);
447         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_enable_checkbtn, FALSE, FALSE, 0);
448
449         export_freebusy_path_entry = gtk_entry_new();
450         gtk_widget_show(export_freebusy_path_entry);
451         gtk_box_pack_start(GTK_BOX(hbox2), export_freebusy_path_entry, TRUE, TRUE, 0);
452         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_path_entry);
453         CLAWS_SET_TIP(export_freebusy_enable_checkbtn, 
454                             _("You can export to a local file or URL"));
455         CLAWS_SET_TIP(export_freebusy_path_entry, 
456                             _("Specify a local file or URL "
457                               "(http://server/path/file.ifb)"));
458
459 /* auth */
460         hbox2 = gtk_hbox_new (FALSE, 8);
461         gtk_widget_show (hbox2);
462         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
463
464         export_freebusy_user_label = gtk_label_new(_("User ID"));
465         gtk_widget_show(export_freebusy_user_label);
466         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_label, FALSE, FALSE, 0);
467
468         export_freebusy_user_entry = gtk_entry_new();
469         gtk_widget_show(export_freebusy_user_entry);
470         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_entry, FALSE, FALSE, 0);
471
472         export_freebusy_pass_label = gtk_label_new(_("Password"));
473         gtk_widget_show(export_freebusy_pass_label);
474         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_label, FALSE, FALSE, 0);
475
476         export_freebusy_pass_entry = gtk_entry_new();
477         gtk_entry_set_visibility(GTK_ENTRY(export_freebusy_pass_entry), FALSE);
478         gtk_widget_show(export_freebusy_pass_entry);
479         gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_entry, FALSE, FALSE, 0);
480
481 /* run-command after export stuff */
482         hbox3 = gtk_hbox_new (FALSE, 8);
483         gtk_widget_show (hbox3);
484         gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
485
486         export_freebusy_command_label = gtk_label_new(_("Command to run after free/busy status export"));
487         gtk_widget_show(export_freebusy_command_label);
488         gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_label, FALSE, FALSE, 0);
489         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_label);
490         export_freebusy_command_entry = gtk_entry_new();
491         gtk_widget_show(export_freebusy_command_entry);
492         gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_entry, TRUE, TRUE, 0);
493         SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_entry);
494
495         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_freebusy_enable_checkbtn), 
496                         vcalprefs.export_freebusy_enable);
497         if (vcalprefs.export_freebusy_path == NULL || 
498             *vcalprefs.export_freebusy_path == '\0')
499                 vcalprefs.export_freebusy_path = g_strconcat(get_rc_dir(), 
500                                         G_DIR_SEPARATOR_S,
501                                         "claws-mail.ifb", NULL);
502         if (vcalprefs.export_freebusy_command == NULL)
503                 vcalprefs.export_freebusy_command = g_strdup("");
504         if (vcalprefs.freebusy_get_url == NULL)
505                 vcalprefs.freebusy_get_url = g_strdup("");
506
507 /* free/busy import */
508         hbox2 = gtk_hbox_new (FALSE, 8);
509         gtk_widget_show (hbox2);
510         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
511
512         freebusy_get_url_label = gtk_label_new(
513                 _("Get free/busy status of others from"));
514         gtk_widget_show(freebusy_get_url_label);
515         gtk_box_pack_start(GTK_BOX (hbox2), freebusy_get_url_label, FALSE, FALSE, 0);
516
517         freebusy_get_url_entry = gtk_entry_new();
518         gtk_widget_show(freebusy_get_url_entry);
519         gtk_box_pack_start(GTK_BOX(hbox2), freebusy_get_url_entry, TRUE, TRUE, 0);
520         CLAWS_SET_TIP(freebusy_get_url_entry, 
521                             _("Specify a local file or URL "
522                               "(http://server/path/file.ifb). Use %u "
523                               "for the left part of the email address, %d for "
524                               "the domain"));
525
526         gtk_entry_set_text(GTK_ENTRY(export_freebusy_path_entry), 
527                         vcalprefs.export_freebusy_path);
528         gtk_entry_set_text(GTK_ENTRY(export_freebusy_command_entry), 
529                         vcalprefs.export_freebusy_command);
530
531         gtk_entry_set_text(GTK_ENTRY(freebusy_get_url_entry), 
532                         vcalprefs.freebusy_get_url);
533
534 /* SSL frame */
535         PACK_FRAME(vbox2, frame_ssl_options, _("SSL options"));
536         vbox3 = gtk_vbox_new (FALSE, 8);
537         gtk_widget_show (vbox3);
538         gtk_container_add (GTK_CONTAINER (frame_ssl_options), vbox3);
539         gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
540
541 /* SSL peer verification */
542         hbox2 = gtk_hbox_new (FALSE, 8);
543         gtk_widget_show (hbox2);
544         gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
545
546         ssl_verify_peer_checkbtn = gtk_check_button_new_with_label(
547                 _("Verify SSL certificate validity"));
548         gtk_widget_show(ssl_verify_peer_checkbtn);
549         gtk_box_pack_start(GTK_BOX (hbox2), ssl_verify_peer_checkbtn, FALSE, FALSE, 0);
550         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl_verify_peer_checkbtn), 
551                         vcalprefs.ssl_verify_peer);
552
553         if (!vcalprefs.export_user)
554                 vcalprefs.export_user = g_strdup("");
555         if (!vcalprefs.export_pass)
556                 vcalprefs.export_pass = g_strdup("");
557         if (!vcalprefs.export_freebusy_user)
558                 vcalprefs.export_freebusy_user = g_strdup("");
559         if (!vcalprefs.export_freebusy_pass)
560                 vcalprefs.export_freebusy_pass = g_strdup("");
561
562         gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
563         gtk_entry_set_text(GTK_ENTRY(export_pass_entry), vcalprefs.export_pass);
564         gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
565         gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), vcalprefs.export_freebusy_pass);
566
567         g_signal_connect(G_OBJECT(export_enable_checkbtn),
568                          "toggled", G_CALLBACK(path_changed), page);
569         g_signal_connect(G_OBJECT(export_freebusy_enable_checkbtn),
570                          "toggled", G_CALLBACK(path_changed), page);
571         g_signal_connect(G_OBJECT(export_path_entry),
572                          "changed", G_CALLBACK(path_changed), page);
573         g_signal_connect(G_OBJECT(export_freebusy_path_entry),
574                          "changed", G_CALLBACK(path_changed), page);
575
576         page->alert_enable_btn = alert_enable_checkbtn;
577         page->alert_delay_spinbtn = alert_enable_spinbtn;
578
579         page->export_enable_btn = export_enable_checkbtn;
580         page->export_subs_btn = export_subs_checkbtn;
581         page->export_path_entry = export_path_entry;
582         page->export_command_entry = export_command_entry;
583
584         page->export_freebusy_enable_btn = export_freebusy_enable_checkbtn;
585         page->export_freebusy_path_entry = export_freebusy_path_entry;
586         page->export_freebusy_command_entry = export_freebusy_command_entry;
587
588         page->export_user_label = export_user_label;
589         page->export_user_entry = export_user_entry;
590         page->export_pass_label = export_pass_label;
591         page->export_pass_entry = export_pass_entry;
592
593         page->export_freebusy_user_label = export_freebusy_user_label;
594         page->export_freebusy_user_entry = export_freebusy_user_entry;
595         page->export_freebusy_pass_label = export_freebusy_pass_label;
596         page->export_freebusy_pass_entry = export_freebusy_pass_entry;
597
598         page->ssl_verify_peer_checkbtn = ssl_verify_peer_checkbtn;
599
600         set_auth_sensitivity(page);
601
602         page->freebusy_get_url_entry = freebusy_get_url_entry;
603
604         page->page.widget = vbox1;
605 }
606
607 static void vcal_prefs_destroy_widget_func(PrefsPage *_page)
608 {
609 }
610
611 void vcal_prefs_save(void)
612 {
613         PrefFile *pfile;
614         gchar *rcpath;
615         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
616         pfile = prefs_write_open(rcpath);
617         g_free(rcpath);
618         if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
619                 return;
620
621         if (prefs_write_param(param, pfile->fp) < 0) {
622                 g_warning("failed to write vCalendar configuration to file");
623                 prefs_file_close_revert(pfile);
624                 return;
625         }
626         if (fprintf(pfile->fp, "\n") < 0) {
627                 FILE_OP_ERROR(rcpath, "fprintf");
628                 prefs_file_close_revert(pfile);
629         } else
630                 prefs_file_close(pfile);
631 }
632
633 static void vcal_prefs_save_func(PrefsPage * _page)
634 {
635         struct VcalendarPage *page = (struct VcalendarPage *) _page;
636
637 /* alert */
638         vcalprefs.alert_enable =
639             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
640                                          (page->alert_enable_btn));
641         vcalprefs.alert_delay =
642                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
643                                                  (page->alert_delay_spinbtn));
644
645 /* calendar export */
646         vcalprefs.export_enable = 
647             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
648                                          (page->export_enable_btn));
649         
650         vcalprefs.export_subs = 
651             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
652                                          (page->export_subs_btn));
653         
654         g_free(vcalprefs.export_path);
655         vcalprefs.export_path =
656             gtk_editable_get_chars(GTK_EDITABLE(page->export_path_entry), 0, -1);
657
658         g_free(vcalprefs.export_command);
659         vcalprefs.export_command =
660             gtk_editable_get_chars(GTK_EDITABLE(page->export_command_entry), 0, -1);
661         
662         g_free(vcalprefs.export_user);
663         vcalprefs.export_user =
664             gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
665         g_free(vcalprefs.export_pass);
666         vcalprefs.export_pass =
667             gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
668         
669 /* free/busy export */
670         vcalprefs.export_freebusy_enable = 
671             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
672                                          (page->export_freebusy_enable_btn));
673         
674         g_free(vcalprefs.export_freebusy_path);
675         vcalprefs.export_freebusy_path =
676             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_path_entry), 0, -1);
677
678         g_free(vcalprefs.export_freebusy_command);
679         vcalprefs.export_freebusy_command =
680             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_command_entry), 0, -1);
681
682         g_free(vcalprefs.export_freebusy_user);
683         vcalprefs.export_freebusy_user =
684             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
685         g_free(vcalprefs.export_freebusy_pass);
686         vcalprefs.export_freebusy_pass =
687             gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
688         
689
690 /* free/busy import */
691         g_free(vcalprefs.freebusy_get_url);
692         vcalprefs.freebusy_get_url =
693             gtk_editable_get_chars(GTK_EDITABLE(page->freebusy_get_url_entry), 0, -1);
694
695 /* SSL */
696         vcalprefs.ssl_verify_peer = 
697             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
698                                          (page->ssl_verify_peer_checkbtn));
699
700         vcal_prefs_save();
701         vcal_folder_export(NULL);
702 }
703
704 void vcal_prefs_init(void)
705 {
706         static gchar *path[3];
707         gchar *rcpath;
708
709         path[0] = _("Plugins");
710         path[1] = _("vCalendar");
711         path[2] = NULL;
712
713         prefs_set_default(param);
714         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
715         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
716         g_free(rcpath);
717
718         vcal_prefs_page.page.path = path;
719         vcal_prefs_page.page.create_widget = vcal_prefs_create_widget_func;
720         vcal_prefs_page.page.destroy_widget = vcal_prefs_destroy_widget_func;
721         vcal_prefs_page.page.save_page = vcal_prefs_save_func;
722
723         prefs_gtk_register_page((PrefsPage *) &vcal_prefs_page);
724 }
725
726 void vcal_prefs_done(void)
727 {
728         prefs_gtk_unregister_page((PrefsPage *) &vcal_prefs_page);
729 }