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