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