Remove inclusion of sys/socket.h from nntp-thread.c
[claws.git] / src / plugins / vcalendar / vcal_prefs.c
blob5877a06f6c60eabc083c6d898bac5eeb8b04b221
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and Colin Leroy
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <stddef.h>
26 #include <glib.h>
27 #include <glib/gi18n.h>
29 #include "defs.h"
31 #include "mainwindow.h"
32 #include "passwordstore.h"
33 #include "prefs.h"
34 #include "prefs_gtk.h"
35 #include "prefswindow.h"
36 #include "common/utils.h"
38 #include "vcalendar.h"
39 #include "vcal_prefs.h"
40 #include "vcal_folder.h"
41 #include "vcal_dbus.h"
43 #define PREFS_BLOCK_NAME "VCalendar"
45 struct VcalendarPage
47 PrefsPage page;
49 GtkWidget *alert_enable_btn;
50 GtkWidget *alert_delay_h_spinbtn;
51 GtkWidget *alert_delay_m_spinbtn;
53 GtkWidget *export_enable_btn;
54 GtkWidget *export_subs_btn;
55 GtkWidget *export_path_entry;
56 GtkWidget *export_command_entry;
58 GtkWidget *export_user_label;
59 GtkWidget *export_user_entry;
60 GtkWidget *export_pass_label;
61 GtkWidget *export_pass_entry;
63 GtkWidget *export_freebusy_enable_btn;
64 GtkWidget *export_freebusy_path_entry;
65 GtkWidget *export_freebusy_command_entry;
67 GtkWidget *export_freebusy_user_label;
68 GtkWidget *export_freebusy_user_entry;
69 GtkWidget *export_freebusy_pass_label;
70 GtkWidget *export_freebusy_pass_entry;
72 GtkWidget *freebusy_get_url_entry;
74 GtkWidget *ssl_verify_peer_checkbtn;
75 GtkWidget *calendar_server_checkbtn;
78 VcalendarPrefs vcalprefs;
79 static struct VcalendarPage vcal_prefs_page;
81 static PrefParam param[] = {
82 {"alert_delay", "10", &vcalprefs.alert_delay, P_INT,
83 NULL, NULL, NULL},
84 {"alert_enable", "FALSE", &vcalprefs.alert_enable, P_BOOL,
85 NULL, NULL, NULL},
87 {"export_enable", "FALSE", &vcalprefs.export_enable, P_BOOL,
88 NULL, NULL, NULL},
89 {"export_subs", "TRUE", &vcalprefs.export_subs, P_BOOL,
90 NULL, NULL, NULL},
91 {"export_path", "", &vcalprefs.export_path, P_STRING,
92 NULL, NULL, NULL},
93 {"export_command", NULL, &vcalprefs.export_command, P_STRING,
94 NULL, NULL, NULL},
96 {"export_user", "", &vcalprefs.export_user, P_STRING,
97 NULL, NULL, NULL},
98 {"export_pass", "", &vcalprefs.export_pass, P_PASSWORD,
99 NULL, NULL, NULL},
101 {"orage_registered", "FALSE", &vcalprefs.orage_registered, P_BOOL,
102 NULL, NULL, NULL},
104 {"export_freebusy_enable", "FALSE", &vcalprefs.export_freebusy_enable, P_BOOL,
105 NULL, NULL, NULL},
106 {"export_freebusy_path", "", &vcalprefs.export_freebusy_path, P_STRING,
107 NULL, NULL, NULL},
108 {"export_freebusy_command", NULL, &vcalprefs.export_freebusy_command, P_STRING,
109 NULL, NULL, NULL},
110 {"freebusy_get_url", NULL, &vcalprefs.freebusy_get_url, P_STRING,
111 NULL, NULL, NULL},
113 {"export_freebusy_user", "", &vcalprefs.export_freebusy_user, P_STRING,
114 NULL, NULL, NULL},
115 {"export_freebusy_pass", "", &vcalprefs.export_freebusy_pass, P_PASSWORD,
116 NULL, NULL, NULL},
118 {"ssl_verify_peer", "TRUE", &vcalprefs.ssl_verify_peer, P_BOOL,
119 NULL, NULL, NULL},
121 {"calendar_server", "FALSE", &vcalprefs.calendar_server, P_BOOL,
122 NULL, NULL, NULL},
124 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
127 static void set_auth_sensitivity(struct VcalendarPage *page)
129 const gchar *export_path, *export_freebusy_path;
130 gboolean export_enable, export_freebusy_enable;
132 export_enable = gtk_toggle_button_get_active(
133 GTK_TOGGLE_BUTTON(page->export_enable_btn));
134 export_freebusy_enable = gtk_toggle_button_get_active(
135 GTK_TOGGLE_BUTTON(page->export_freebusy_enable_btn));
137 export_path = gtk_entry_get_text(GTK_ENTRY(page->export_path_entry));
138 export_freebusy_path = gtk_entry_get_text(GTK_ENTRY(page->export_freebusy_path_entry));
139 if (export_enable && export_path &&
140 (!strncmp(export_path, "http://", 7) ||
141 !strncmp(export_path, "ftp://", 6) ||
142 !strncmp(export_path, "https://", 8) ||
143 !strncmp(export_path, "ftps://", 7) ||
144 !strncmp(export_path, "sftp://", 7) ||
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);
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, "ftps://", 7) ||
162 !strncmp(export_freebusy_path, "sftp://", 7) ||
163 !strncmp(export_freebusy_path, "webcal://", 9) ||
164 !strncmp(export_freebusy_path, "webcals://", 10))) {
165 gtk_widget_set_sensitive(page->export_freebusy_user_label, TRUE);
166 gtk_widget_set_sensitive(page->export_freebusy_user_entry, TRUE);
167 gtk_widget_set_sensitive(page->export_freebusy_pass_label, TRUE);
168 gtk_widget_set_sensitive(page->export_freebusy_pass_entry, TRUE);
169 } else {
170 gtk_widget_set_sensitive(page->export_freebusy_user_label, FALSE);
171 gtk_widget_set_sensitive(page->export_freebusy_user_entry, FALSE);
172 gtk_widget_set_sensitive(page->export_freebusy_pass_label, FALSE);
173 gtk_widget_set_sensitive(page->export_freebusy_pass_entry, FALSE);
177 static void path_changed(GtkWidget *widget, gpointer data)
179 set_auth_sensitivity((struct VcalendarPage *)data);
182 static void alert_spinbutton_value_changed(GtkWidget *widget, gpointer data)
184 struct VcalendarPage *page = (struct VcalendarPage *)data;
185 gint minutes = gtk_spin_button_get_value_as_int (
186 GTK_SPIN_BUTTON (page->alert_delay_m_spinbtn));
187 gint hours = gtk_spin_button_get_value_as_int (
188 GTK_SPIN_BUTTON (page->alert_delay_h_spinbtn));
189 if (minutes < 1 && hours == 0) {
190 gtk_spin_button_set_value (
191 GTK_SPIN_BUTTON (page->alert_delay_m_spinbtn), 1.0);
195 static gboolean orage_available(void)
197 gchar *tmp = g_find_program_in_path("orage");
198 if (tmp) {
199 g_free(tmp);
200 return TRUE;
202 return FALSE;
205 static void orage_register(gboolean reg)
207 if (orage_available()) {
208 gchar *orage_argv[4];
209 gchar *cmdline = g_strdup_printf("%s%svcalendar%sinternal.ics",
210 get_rc_dir(), G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S);
212 debug_print("telling Orage %s us ...\n", reg?"about":"to forget");
213 orage_argv[0] = "orage";
214 orage_argv[1] = reg ? "--add-foreign":"--remove-foreign";
215 orage_argv[2] = cmdline;
216 orage_argv[3] = NULL;
217 g_spawn_async(NULL, (gchar **)orage_argv, NULL,
218 G_SPAWN_SEARCH_PATH|G_SPAWN_STDOUT_TO_DEV_NULL|
219 G_SPAWN_STDERR_TO_DEV_NULL,
220 NULL, NULL, NULL, FALSE);
221 g_free(cmdline);
225 void register_orage_checkbtn_toggled(GtkToggleButton *toggle_btn,
226 GtkWidget *widget)
228 orage_register(gtk_toggle_button_get_active(toggle_btn));
229 vcalprefs.orage_registered = gtk_toggle_button_get_active(toggle_btn);
232 void calendar_server_checkbtn_toggled(GtkToggleButton *toggle, GtkWidget *widget)
234 gboolean active = gtk_toggle_button_get_active(toggle);
235 if (active)
236 connect_dbus();
237 else
238 disconnect_dbus();
239 vcalprefs.calendar_server = active;
242 static void vcal_prefs_create_widget_func(PrefsPage * _page,
243 GtkWindow * window,
244 gpointer data)
246 struct VcalendarPage *page = (struct VcalendarPage *) _page;
248 GtkWidget *vbox1, *vbox2, *vbox3;
249 GtkWidget *hbox1, *hbox2, *hbox3;
251 GtkWidget *frame_alert;
252 GtkWidget *alert_enable_checkbtn;
253 GtkAdjustment *alert_enable_spinbtn_adj;
254 GtkWidget *alert_enable_h_spinbtn;
255 GtkWidget *alert_enable_m_spinbtn;
256 GtkWidget *label_alert_enable;
258 GtkWidget *frame_export;
259 GtkWidget *export_enable_checkbtn;
260 GtkWidget *export_subs_checkbtn;
261 GtkWidget *export_path_entry;
262 GtkWidget *export_command_label;
263 GtkWidget *export_command_entry;
264 GtkWidget *register_orage_checkbtn;
265 GtkWidget *calendar_server_checkbtn;
267 GtkWidget *export_user_label;
268 GtkWidget *export_user_entry;
269 GtkWidget *export_pass_label;
270 GtkWidget *export_pass_entry;
272 GtkWidget *frame_freebusy_export;
273 GtkWidget *export_freebusy_enable_checkbtn;
274 GtkWidget *export_freebusy_path_entry;
275 GtkWidget *export_freebusy_command_label;
276 GtkWidget *export_freebusy_command_entry;
278 GtkWidget *export_freebusy_user_label;
279 GtkWidget *export_freebusy_user_entry;
280 GtkWidget *export_freebusy_pass_label;
281 GtkWidget *export_freebusy_pass_entry;
283 GtkWidget *freebusy_get_url_label;
284 GtkWidget *freebusy_get_url_entry;
286 GtkWidget *frame_ssl_options;
287 GtkWidget *ssl_verify_peer_checkbtn;
288 gchar *export_pass = NULL;
289 gchar *export_freebusy_pass = NULL;
291 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
292 gtk_widget_show (vbox1);
293 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
295 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
296 gtk_widget_show (vbox2);
297 gtk_box_pack_start(GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
300 /* alert stuff */
301 PACK_FRAME(vbox2, frame_alert, _("Reminders"));
302 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
303 gtk_widget_show (vbox3);
304 gtk_container_add (GTK_CONTAINER (frame_alert), vbox3);
305 gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
306 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
307 gtk_widget_show (hbox1);
308 gtk_box_pack_start(GTK_BOX (vbox3), hbox1, TRUE, TRUE, 0);
310 alert_enable_checkbtn = gtk_check_button_new_with_label(_("Alert me"));
311 gtk_widget_show (alert_enable_checkbtn);
312 gtk_box_pack_start(GTK_BOX (hbox1), alert_enable_checkbtn, FALSE, FALSE, 0);
314 alert_enable_spinbtn_adj = gtk_adjustment_new (0, 0, 24, 1, 10, 0);
315 alert_enable_h_spinbtn = gtk_spin_button_new (
316 GTK_ADJUSTMENT (alert_enable_spinbtn_adj), 1, 0);
317 gtk_widget_set_size_request (alert_enable_h_spinbtn, 64, -1);
318 gtk_spin_button_set_numeric (
319 GTK_SPIN_BUTTON (alert_enable_h_spinbtn), TRUE);
320 gtk_widget_show (alert_enable_h_spinbtn);
321 gtk_box_pack_start (
322 GTK_BOX (hbox1), alert_enable_h_spinbtn, FALSE, FALSE, 0);
324 label_alert_enable = gtk_label_new (_("hours"));
325 gtk_widget_show (label_alert_enable);
326 gtk_box_pack_start (
327 GTK_BOX (hbox1), label_alert_enable, FALSE, FALSE, 0);
329 alert_enable_spinbtn_adj = gtk_adjustment_new (0, 0, 59, 1, 10, 0);
330 alert_enable_m_spinbtn = gtk_spin_button_new (
331 GTK_ADJUSTMENT (alert_enable_spinbtn_adj), 1, 0);
332 gtk_widget_set_size_request (alert_enable_m_spinbtn, 64, -1);
333 gtk_spin_button_set_numeric (
334 GTK_SPIN_BUTTON (alert_enable_m_spinbtn), TRUE);
335 gtk_widget_show (alert_enable_m_spinbtn);
336 gtk_box_pack_start (
337 GTK_BOX (hbox1), alert_enable_m_spinbtn, FALSE, FALSE, 0);
339 label_alert_enable = gtk_label_new(_("minutes before an event"));
340 gtk_widget_show (label_alert_enable);
341 gtk_box_pack_start (
342 GTK_BOX (hbox1), label_alert_enable, FALSE, FALSE, 0);
344 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(alert_enable_checkbtn),
345 vcalprefs.alert_enable);
346 gtk_spin_button_set_value (GTK_SPIN_BUTTON(alert_enable_h_spinbtn),
347 vcalprefs.alert_delay / 60);
348 gtk_spin_button_set_value (GTK_SPIN_BUTTON(alert_enable_m_spinbtn),
349 vcalprefs.alert_delay % 60);
350 SET_TOGGLE_SENSITIVITY(alert_enable_checkbtn, alert_enable_h_spinbtn);
351 SET_TOGGLE_SENSITIVITY(alert_enable_checkbtn, alert_enable_m_spinbtn);
353 g_signal_connect(G_OBJECT(alert_enable_h_spinbtn), "value-changed",
354 G_CALLBACK(alert_spinbutton_value_changed),
355 (gpointer) page);
356 g_signal_connect(G_OBJECT(alert_enable_m_spinbtn), "value-changed",
357 G_CALLBACK(alert_spinbutton_value_changed),
358 (gpointer) page);
360 /* calendar export */
361 /* export enable + path stuff */
362 PACK_FRAME(vbox2, frame_export, _("Calendar export"));
363 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
364 gtk_widget_show (vbox3);
365 gtk_container_add (GTK_CONTAINER (frame_export), vbox3);
366 gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
368 /* export path */
369 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
370 gtk_widget_show (hbox2);
371 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
373 export_enable_checkbtn = gtk_check_button_new_with_label(_("Automatically export calendar to"));
374 gtk_widget_show(export_enable_checkbtn);
375 gtk_box_pack_start(GTK_BOX (hbox2), export_enable_checkbtn, FALSE, FALSE, 0);
377 export_path_entry = gtk_entry_new();
378 gtk_widget_show(export_path_entry);
379 gtk_box_pack_start(GTK_BOX(hbox2), export_path_entry, TRUE, TRUE, 0);
380 SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_path_entry);
381 CLAWS_SET_TIP(export_enable_checkbtn,
382 _("You can export to a local file or URL"));
383 CLAWS_SET_TIP(export_path_entry,
384 _("Specify a local file or URL "
385 "(http://server/path/file.ics)"));
387 /* export auth */
388 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
389 gtk_widget_show (hbox2);
390 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
392 export_user_label = gtk_label_new(_("User ID"));
393 gtk_widget_show(export_user_label);
394 gtk_box_pack_start(GTK_BOX (hbox2), export_user_label, FALSE, FALSE, 0);
396 export_user_entry = gtk_entry_new();
397 gtk_widget_show(export_user_entry);
398 gtk_box_pack_start(GTK_BOX (hbox2), export_user_entry, FALSE, FALSE, 0);
400 export_pass_label = gtk_label_new(_("Password"));
401 gtk_widget_show(export_pass_label);
402 gtk_box_pack_start(GTK_BOX (hbox2), export_pass_label, FALSE, FALSE, 0);
404 export_pass_entry = gtk_entry_new();
405 gtk_entry_set_visibility(GTK_ENTRY(export_pass_entry), FALSE);
406 gtk_widget_show(export_pass_entry);
407 gtk_box_pack_start(GTK_BOX (hbox2), export_pass_entry, FALSE, FALSE, 0);
409 /* export subscriptions too */
410 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
411 gtk_widget_show (hbox2);
412 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
414 export_subs_checkbtn = gtk_check_button_new_with_label(_("Include Webcal subscriptions in export"));
415 gtk_widget_show(export_subs_checkbtn);
416 gtk_box_pack_start(GTK_BOX (hbox2), export_subs_checkbtn, FALSE, FALSE, 0);
417 SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_subs_checkbtn);
419 /* run-command after export stuff */
420 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
421 gtk_widget_show (hbox3);
422 gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
424 export_command_label = gtk_label_new(_("Command to run after calendar export"));
425 gtk_widget_show(export_command_label);
426 gtk_box_pack_start(GTK_BOX (hbox3), export_command_label, FALSE, FALSE, 0);
427 SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_command_label);
429 export_command_entry = gtk_entry_new();
430 gtk_widget_show(export_command_entry);
431 gtk_box_pack_start(GTK_BOX (hbox3), export_command_entry, TRUE, TRUE, 0);
432 SET_TOGGLE_SENSITIVITY(export_enable_checkbtn, export_command_entry);
435 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_enable_checkbtn),
436 vcalprefs.export_enable);
437 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_subs_checkbtn),
438 vcalprefs.export_subs);
439 if (vcalprefs.export_path == NULL || *vcalprefs.export_path == '\0')
440 vcalprefs.export_path = g_strconcat(get_rc_dir(),
441 G_DIR_SEPARATOR_S,
442 "claws-mail.ics", NULL);
443 if (vcalprefs.export_command == NULL)
444 vcalprefs.export_command = g_strdup("");
445 gtk_entry_set_text(GTK_ENTRY(export_path_entry),
446 vcalprefs.export_path);
447 gtk_entry_set_text(GTK_ENTRY(export_command_entry),
448 vcalprefs.export_command);
450 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
451 gtk_widget_show (hbox3);
452 gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
453 register_orage_checkbtn = gtk_check_button_new_with_label(_("Register Claws' calendar in XFCE's Orage clock"));
454 CLAWS_SET_TIP(register_orage_checkbtn,
455 _("Allows Orage (version greater than 4.4) to see Claws Mail's calendar"));
457 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(register_orage_checkbtn),
458 vcalprefs.orage_registered);
459 gtk_widget_set_sensitive(register_orage_checkbtn, orage_available());
460 g_signal_connect(G_OBJECT(register_orage_checkbtn), "toggled",
461 G_CALLBACK(register_orage_checkbtn_toggled), NULL);
462 gtk_widget_show (register_orage_checkbtn);
463 gtk_box_pack_start(GTK_BOX (hbox3), register_orage_checkbtn, TRUE, TRUE, 0);
465 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
466 gtk_widget_show (hbox3);
467 gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
468 calendar_server_checkbtn = gtk_check_button_new_with_label(_("Export as GNOME shell calendar server"));
469 CLAWS_SET_TIP(calendar_server_checkbtn,
470 _("Register D-Bus calendar server interface to export Claws Mail's calendar"));
471 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(calendar_server_checkbtn),
472 vcalprefs.calendar_server);
473 g_signal_connect(G_OBJECT(calendar_server_checkbtn), "toggled",
474 G_CALLBACK(calendar_server_checkbtn_toggled), NULL);
475 gtk_widget_show(calendar_server_checkbtn);
476 gtk_box_pack_start(GTK_BOX(hbox3), calendar_server_checkbtn, TRUE, TRUE, 0);
478 /* freebusy export */
479 /* export enable + path stuff */
480 PACK_FRAME(vbox2, frame_freebusy_export, _("Free/Busy information"));
481 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
482 gtk_widget_show (vbox3);
483 gtk_container_add (GTK_CONTAINER (frame_freebusy_export), vbox3);
484 gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
486 /* export */
487 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
488 gtk_widget_show (hbox2);
489 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
491 export_freebusy_enable_checkbtn = gtk_check_button_new_with_label(
492 _("Automatically export free/busy status to"));
493 gtk_widget_show(export_freebusy_enable_checkbtn);
494 gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_enable_checkbtn, FALSE, FALSE, 0);
496 export_freebusy_path_entry = gtk_entry_new();
497 gtk_widget_show(export_freebusy_path_entry);
498 gtk_box_pack_start(GTK_BOX(hbox2), export_freebusy_path_entry, TRUE, TRUE, 0);
499 SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_path_entry);
500 CLAWS_SET_TIP(export_freebusy_enable_checkbtn,
501 _("You can export to a local file or URL"));
502 CLAWS_SET_TIP(export_freebusy_path_entry,
503 _("Specify a local file or URL "
504 "(http://server/path/file.ifb)"));
506 /* auth */
507 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
508 gtk_widget_show (hbox2);
509 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
511 export_freebusy_user_label = gtk_label_new(_("User ID"));
512 gtk_widget_show(export_freebusy_user_label);
513 gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_label, FALSE, FALSE, 0);
515 export_freebusy_user_entry = gtk_entry_new();
516 gtk_widget_show(export_freebusy_user_entry);
517 gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_user_entry, FALSE, FALSE, 0);
519 export_freebusy_pass_label = gtk_label_new(_("Password"));
520 gtk_widget_show(export_freebusy_pass_label);
521 gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_label, FALSE, FALSE, 0);
523 export_freebusy_pass_entry = gtk_entry_new();
524 gtk_entry_set_visibility(GTK_ENTRY(export_freebusy_pass_entry), FALSE);
525 gtk_widget_show(export_freebusy_pass_entry);
526 gtk_box_pack_start(GTK_BOX (hbox2), export_freebusy_pass_entry, FALSE, FALSE, 0);
528 /* run-command after export stuff */
529 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
530 gtk_widget_show (hbox3);
531 gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
533 export_freebusy_command_label = gtk_label_new(_("Command to run after free/busy status export"));
534 gtk_widget_show(export_freebusy_command_label);
535 gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_label, FALSE, FALSE, 0);
536 SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_label);
537 export_freebusy_command_entry = gtk_entry_new();
538 gtk_widget_show(export_freebusy_command_entry);
539 gtk_box_pack_start(GTK_BOX (hbox3), export_freebusy_command_entry, TRUE, TRUE, 0);
540 SET_TOGGLE_SENSITIVITY(export_freebusy_enable_checkbtn, export_freebusy_command_entry);
542 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(export_freebusy_enable_checkbtn),
543 vcalprefs.export_freebusy_enable);
544 if (vcalprefs.export_freebusy_path == NULL ||
545 *vcalprefs.export_freebusy_path == '\0')
546 vcalprefs.export_freebusy_path = g_strconcat(get_rc_dir(),
547 G_DIR_SEPARATOR_S,
548 "claws-mail.ifb", NULL);
549 if (vcalprefs.export_freebusy_command == NULL)
550 vcalprefs.export_freebusy_command = g_strdup("");
551 if (vcalprefs.freebusy_get_url == NULL)
552 vcalprefs.freebusy_get_url = g_strdup("");
554 /* free/busy import */
555 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
556 gtk_widget_show (hbox2);
557 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
559 freebusy_get_url_label = gtk_label_new(
560 _("Get free/busy status of others from"));
561 gtk_widget_show(freebusy_get_url_label);
562 gtk_box_pack_start(GTK_BOX (hbox2), freebusy_get_url_label, FALSE, FALSE, 0);
564 freebusy_get_url_entry = gtk_entry_new();
565 gtk_widget_show(freebusy_get_url_entry);
566 gtk_box_pack_start(GTK_BOX(hbox2), freebusy_get_url_entry, TRUE, TRUE, 0);
567 CLAWS_SET_TIP(freebusy_get_url_entry,
568 _("Specify a local file or URL "
569 "(http://server/path/file.ifb). Use %u "
570 "for the left part of the email address, %d for "
571 "the domain"));
573 gtk_entry_set_text(GTK_ENTRY(export_freebusy_path_entry),
574 vcalprefs.export_freebusy_path);
575 gtk_entry_set_text(GTK_ENTRY(export_freebusy_command_entry),
576 vcalprefs.export_freebusy_command);
578 gtk_entry_set_text(GTK_ENTRY(freebusy_get_url_entry),
579 vcalprefs.freebusy_get_url);
581 /* SSL frame */
582 PACK_FRAME(vbox2, frame_ssl_options, _("TLS options"));
583 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
584 gtk_widget_show (vbox3);
585 gtk_container_add (GTK_CONTAINER (frame_ssl_options), vbox3);
586 gtk_container_set_border_width (GTK_CONTAINER (vbox3), VBOX_BORDER);
588 /* SSL peer verification */
589 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
590 gtk_widget_show (hbox2);
591 gtk_box_pack_start(GTK_BOX (vbox3), hbox2, TRUE, TRUE, 0);
593 ssl_verify_peer_checkbtn = gtk_check_button_new_with_label(
594 _("Verify TLS certificate validity"));
595 gtk_widget_show(ssl_verify_peer_checkbtn);
596 gtk_box_pack_start(GTK_BOX (hbox2), ssl_verify_peer_checkbtn, FALSE, FALSE, 0);
597 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl_verify_peer_checkbtn),
598 vcalprefs.ssl_verify_peer);
600 if (!vcalprefs.export_user)
601 vcalprefs.export_user = g_strdup("");
602 if (!vcalprefs.export_freebusy_user)
603 vcalprefs.export_freebusy_user = g_strdup("");
605 export_pass = vcal_passwd_get("export");
606 export_freebusy_pass = vcal_passwd_get("export_freebusy");
608 gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
609 gtk_entry_set_text(GTK_ENTRY(export_pass_entry), (export_pass != NULL ? export_pass : ""));
610 gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
611 gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), (export_freebusy_pass != NULL ? export_freebusy_pass : ""));
613 if (export_pass != NULL) {
614 memset(export_pass, 0, strlen(export_pass));
616 g_free(export_pass);
618 if (export_freebusy_pass != NULL) {
619 memset(export_freebusy_pass, 0, strlen(export_freebusy_pass));
621 g_free(export_freebusy_pass);
623 g_signal_connect(G_OBJECT(export_enable_checkbtn),
624 "toggled", G_CALLBACK(path_changed), page);
625 g_signal_connect(G_OBJECT(export_freebusy_enable_checkbtn),
626 "toggled", G_CALLBACK(path_changed), page);
627 g_signal_connect(G_OBJECT(export_path_entry),
628 "changed", G_CALLBACK(path_changed), page);
629 g_signal_connect(G_OBJECT(export_freebusy_path_entry),
630 "changed", G_CALLBACK(path_changed), page);
632 page->alert_enable_btn = alert_enable_checkbtn;
633 page->alert_delay_h_spinbtn = alert_enable_h_spinbtn;
634 page->alert_delay_m_spinbtn = alert_enable_m_spinbtn;
636 page->export_enable_btn = export_enable_checkbtn;
637 page->export_subs_btn = export_subs_checkbtn;
638 page->export_path_entry = export_path_entry;
639 page->export_command_entry = export_command_entry;
641 page->export_freebusy_enable_btn = export_freebusy_enable_checkbtn;
642 page->export_freebusy_path_entry = export_freebusy_path_entry;
643 page->export_freebusy_command_entry = export_freebusy_command_entry;
645 page->export_user_label = export_user_label;
646 page->export_user_entry = export_user_entry;
647 page->export_pass_label = export_pass_label;
648 page->export_pass_entry = export_pass_entry;
650 page->export_freebusy_user_label = export_freebusy_user_label;
651 page->export_freebusy_user_entry = export_freebusy_user_entry;
652 page->export_freebusy_pass_label = export_freebusy_pass_label;
653 page->export_freebusy_pass_entry = export_freebusy_pass_entry;
655 page->ssl_verify_peer_checkbtn = ssl_verify_peer_checkbtn;
657 set_auth_sensitivity(page);
659 page->freebusy_get_url_entry = freebusy_get_url_entry;
661 page->page.widget = vbox1;
664 static void vcal_prefs_destroy_widget_func(PrefsPage *_page)
668 void vcal_prefs_save(void)
670 PrefFile *pfile;
671 gchar *rcpath;
673 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
674 pfile = prefs_write_open(rcpath);
675 g_free(rcpath);
676 if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
677 return;
679 if (prefs_write_param(param, pfile->fp) < 0) {
680 g_warning("failed to write vCalendar configuration to file");
681 prefs_file_close_revert(pfile);
682 return;
684 if (fprintf(pfile->fp, "\n") < 0) {
685 FILE_OP_ERROR(rcpath, "fprintf");
686 prefs_file_close_revert(pfile);
687 } else
688 prefs_file_close(pfile);
691 static void vcal_prefs_save_func(PrefsPage * _page)
693 struct VcalendarPage *page = (struct VcalendarPage *) _page;
694 gchar *pass;
696 /* alert */
697 vcalprefs.alert_enable =
698 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
699 (page->alert_enable_btn));
700 vcalprefs.alert_delay =
701 60 * gtk_spin_button_get_value_as_int (
702 GTK_SPIN_BUTTON(page->alert_delay_h_spinbtn))
703 + gtk_spin_button_get_value_as_int (
704 GTK_SPIN_BUTTON(page->alert_delay_m_spinbtn));
706 /* calendar export */
707 vcalprefs.export_enable =
708 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
709 (page->export_enable_btn));
711 vcalprefs.export_subs =
712 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
713 (page->export_subs_btn));
715 g_free(vcalprefs.export_path);
716 vcalprefs.export_path =
717 gtk_editable_get_chars(GTK_EDITABLE(page->export_path_entry), 0, -1);
719 g_free(vcalprefs.export_command);
720 vcalprefs.export_command =
721 gtk_editable_get_chars(GTK_EDITABLE(page->export_command_entry), 0, -1);
723 g_free(vcalprefs.export_user);
724 vcalprefs.export_user =
725 gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
726 pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
728 vcal_passwd_set("export", pass);
729 memset(pass, 0, strlen(pass));
730 g_free(pass);
732 /* free/busy export */
733 vcalprefs.export_freebusy_enable =
734 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
735 (page->export_freebusy_enable_btn));
737 g_free(vcalprefs.export_freebusy_path);
738 vcalprefs.export_freebusy_path =
739 gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_path_entry), 0, -1);
741 g_free(vcalprefs.export_freebusy_command);
742 vcalprefs.export_freebusy_command =
743 gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_command_entry), 0, -1);
745 g_free(vcalprefs.export_freebusy_user);
746 vcalprefs.export_freebusy_user =
747 gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
748 pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
750 vcal_passwd_set("export_freebusy", pass);
751 memset(pass, 0, strlen(pass));
752 g_free(pass);
754 /* free/busy import */
755 g_free(vcalprefs.freebusy_get_url);
756 vcalprefs.freebusy_get_url =
757 gtk_editable_get_chars(GTK_EDITABLE(page->freebusy_get_url_entry), 0, -1);
759 /* SSL */
760 vcalprefs.ssl_verify_peer =
761 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
762 (page->ssl_verify_peer_checkbtn));
764 vcal_prefs_save();
765 passwd_store_write_config();
766 vcal_folder_export(NULL);
769 void vcal_prefs_init(void)
771 static gchar *path[3];
772 gchar *rcpath;
773 gboolean passwords_migrated = FALSE;
775 path[0] = _("Plugins");
776 path[1] = _(PLUGIN_NAME);
777 path[2] = NULL;
779 prefs_set_default(param);
780 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
781 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
782 g_free(rcpath);
784 /* Move passwords that are still in main config to password store. */
785 if (vcalprefs.export_pass != NULL &&
786 strlen(vcalprefs.export_pass) > 0) {
787 passwd_store_set(PWS_PLUGIN, PLUGIN_NAME, "export",
788 vcalprefs.export_pass, TRUE);
789 passwords_migrated = TRUE;
790 memset(vcalprefs.export_pass, 0, strlen(vcalprefs.export_pass));
791 g_free(vcalprefs.export_pass);
793 if (vcalprefs.export_freebusy_pass != NULL &&
794 strlen(vcalprefs.export_freebusy_pass) > 0) {
795 passwd_store_set(PWS_PLUGIN, PLUGIN_NAME, "export",
796 vcalprefs.export_freebusy_pass, TRUE);
797 passwords_migrated = TRUE;
798 memset(vcalprefs.export_freebusy_pass, 0, strlen(vcalprefs.export_freebusy_pass));
799 g_free(vcalprefs.export_freebusy_pass);
802 if (passwords_migrated)
803 passwd_store_write_config();
805 vcal_prefs_page.page.path = path;
806 vcal_prefs_page.page.create_widget = vcal_prefs_create_widget_func;
807 vcal_prefs_page.page.destroy_widget = vcal_prefs_destroy_widget_func;
808 vcal_prefs_page.page.save_page = vcal_prefs_save_func;
810 prefs_gtk_register_page((PrefsPage *) &vcal_prefs_page);
813 void vcal_prefs_done(void)
815 prefs_gtk_unregister_page((PrefsPage *) &vcal_prefs_page);