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