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