Actually encrypt passwords before storing them
[claws.git] / src / plugins / vcalendar / vcal_prefs.c
index 554c3bc..a039d3f 100644 (file)
@@ -30,6 +30,7 @@
 #include "defs.h"
 
 #include "mainwindow.h"
 #include "defs.h"
 
 #include "mainwindow.h"
+#include "password.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
 #include "prefs.h"
 #include "prefs_gtk.h"
 #include "prefswindow.h"
@@ -38,6 +39,7 @@
 #include "vcalendar.h"
 #include "vcal_prefs.h"
 #include "vcal_folder.h"
 #include "vcalendar.h"
 #include "vcal_prefs.h"
 #include "vcal_folder.h"
+#include "vcal_dbus.h"
 
 #define PREFS_BLOCK_NAME "VCalendar"
 
 
 #define PREFS_BLOCK_NAME "VCalendar"
 
@@ -70,6 +72,7 @@ struct VcalendarPage
        GtkWidget *freebusy_get_url_entry;
        
        GtkWidget *ssl_verify_peer_checkbtn;
        GtkWidget *freebusy_get_url_entry;
        
        GtkWidget *ssl_verify_peer_checkbtn;
+       GtkWidget *calendar_server_checkbtn;
 };
 
 VcalendarPrefs vcalprefs;
 };
 
 VcalendarPrefs vcalprefs;
@@ -115,6 +118,9 @@ static PrefParam param[] = {
        {"ssl_verify_peer", "TRUE", &vcalprefs.ssl_verify_peer, P_BOOL,
         NULL, NULL, NULL},
 
        {"ssl_verify_peer", "TRUE", &vcalprefs.ssl_verify_peer, P_BOOL,
         NULL, NULL, NULL},
 
+       {"calendar_server", "FALSE", &vcalprefs.calendar_server, P_BOOL,
+        NULL, NULL, NULL},
+
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -208,6 +214,16 @@ void register_orage_checkbtn_toggled(GtkToggleButton       *toggle_btn,
        vcalprefs.orage_registered = gtk_toggle_button_get_active(toggle_btn);
 }
 
        vcalprefs.orage_registered = gtk_toggle_button_get_active(toggle_btn);
 }
 
+void calendar_server_checkbtn_toggled(GtkToggleButton *toggle, GtkWidget *widget)
+{
+       gboolean active = gtk_toggle_button_get_active(toggle);
+       if (active)
+               connect_dbus();
+       else
+               disconnect_dbus();
+       vcalprefs.calendar_server = active;
+}
+
 static void vcal_prefs_create_widget_func(PrefsPage * _page,
                                           GtkWindow * window,
                                           gpointer data)
 static void vcal_prefs_create_widget_func(PrefsPage * _page,
                                           GtkWindow * window,
                                           gpointer data)
@@ -230,6 +246,7 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
        GtkWidget *export_command_label;
        GtkWidget *export_command_entry;
        GtkWidget *register_orage_checkbtn;
        GtkWidget *export_command_label;
        GtkWidget *export_command_entry;
        GtkWidget *register_orage_checkbtn;
+       GtkWidget *calendar_server_checkbtn;
 
        GtkWidget *export_user_label;
        GtkWidget *export_user_entry;
 
        GtkWidget *export_user_label;
        GtkWidget *export_user_entry;
@@ -252,6 +269,8 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
 
        GtkWidget *frame_ssl_options;
        GtkWidget *ssl_verify_peer_checkbtn;
 
        GtkWidget *frame_ssl_options;
        GtkWidget *ssl_verify_peer_checkbtn;
+       gchar *export_pass = NULL;
+       gchar *export_freebusy_pass = NULL;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
@@ -399,6 +418,19 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
        gtk_widget_show (register_orage_checkbtn);
        gtk_box_pack_start(GTK_BOX (hbox3), register_orage_checkbtn, TRUE, TRUE, 0);
 
        gtk_widget_show (register_orage_checkbtn);
        gtk_box_pack_start(GTK_BOX (hbox3), register_orage_checkbtn, TRUE, TRUE, 0);
 
+       hbox3 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox3);
+       gtk_box_pack_start(GTK_BOX (vbox3), hbox3, TRUE, TRUE, 0);
+       calendar_server_checkbtn = gtk_check_button_new_with_label(_("Export as GNOME shell calendar server"));
+       CLAWS_SET_TIP(calendar_server_checkbtn,
+                     _("Register D-Bus calendar server interface to export Claws Mail's calendar"));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(calendar_server_checkbtn),
+                                    vcalprefs.calendar_server);
+       g_signal_connect(G_OBJECT(calendar_server_checkbtn), "toggled",
+                        G_CALLBACK(calendar_server_checkbtn_toggled), NULL);
+       gtk_widget_show(calendar_server_checkbtn);
+       gtk_box_pack_start(GTK_BOX(hbox3), calendar_server_checkbtn, TRUE, TRUE, 0);
+
 /* freebusy export */
 /* export enable + path stuff */
        PACK_FRAME(vbox2, frame_freebusy_export, _("Free/Busy information"));
 /* freebusy export */
 /* export enable + path stuff */
        PACK_FRAME(vbox2, frame_freebusy_export, _("Free/Busy information"));
@@ -530,10 +562,23 @@ static void vcal_prefs_create_widget_func(PrefsPage * _page,
        if (!vcalprefs.export_freebusy_pass)
                vcalprefs.export_freebusy_pass = g_strdup("");
 
        if (!vcalprefs.export_freebusy_pass)
                vcalprefs.export_freebusy_pass = g_strdup("");
 
+       export_pass = password_decrypt(vcalprefs.export_pass, NULL);
+       export_freebusy_pass = password_decrypt(vcalprefs.export_freebusy_pass, NULL);
+       
        gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
        gtk_entry_set_text(GTK_ENTRY(export_user_entry), vcalprefs.export_user);
-       gtk_entry_set_text(GTK_ENTRY(export_pass_entry), vcalprefs.export_pass);
+       gtk_entry_set_text(GTK_ENTRY(export_pass_entry), (export_pass != NULL ? export_pass : ""));
        gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
        gtk_entry_set_text(GTK_ENTRY(export_freebusy_user_entry), vcalprefs.export_freebusy_user);
-       gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), vcalprefs.export_freebusy_pass);
+       gtk_entry_set_text(GTK_ENTRY(export_freebusy_pass_entry), (export_freebusy_pass != NULL ? export_freebusy_pass : ""));
+
+       if (export_pass != NULL) {
+               memset(export_pass, 0, strlen(export_pass));
+       }
+       g_free(export_pass);
+
+       if (export_freebusy_pass != NULL) {
+               memset(export_freebusy_pass, 0, strlen(export_freebusy_pass));
+       }
+       g_free(export_freebusy_pass);
 
        g_signal_connect(G_OBJECT(export_enable_checkbtn),
                         "toggled", G_CALLBACK(path_changed), page);
 
        g_signal_connect(G_OBJECT(export_enable_checkbtn),
                         "toggled", G_CALLBACK(path_changed), page);
@@ -583,6 +628,7 @@ void vcal_prefs_save(void)
 {
        PrefFile *pfile;
        gchar *rcpath;
 {
        PrefFile *pfile;
        gchar *rcpath;
+
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
        pfile = prefs_write_open(rcpath);
        g_free(rcpath);
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
        pfile = prefs_write_open(rcpath);
        g_free(rcpath);
@@ -590,7 +636,7 @@ void vcal_prefs_save(void)
                return;
 
        if (prefs_write_param(param, pfile->fp) < 0) {
                return;
 
        if (prefs_write_param(param, pfile->fp) < 0) {
-               g_warning("failed to write Vcalendar configuration to file\n");
+               g_warning("failed to write vCalendar configuration to file");
                prefs_file_close_revert(pfile);
                return;
        }
                prefs_file_close_revert(pfile);
                return;
        }
@@ -604,6 +650,7 @@ void vcal_prefs_save(void)
 static void vcal_prefs_save_func(PrefsPage * _page)
 {
        struct VcalendarPage *page = (struct VcalendarPage *) _page;
 static void vcal_prefs_save_func(PrefsPage * _page)
 {
        struct VcalendarPage *page = (struct VcalendarPage *) _page;
+       gchar *pass;
 
 /* alert */
        vcalprefs.alert_enable =
 
 /* alert */
        vcalprefs.alert_enable =
@@ -634,8 +681,11 @@ static void vcal_prefs_save_func(PrefsPage * _page)
        vcalprefs.export_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
        g_free(vcalprefs.export_pass);
        vcalprefs.export_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_user_entry), 0, -1);
        g_free(vcalprefs.export_pass);
-       vcalprefs.export_pass =
-           gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
+       pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_pass_entry), 0, -1);
+       
+       vcalprefs.export_pass = password_encrypt(pass, NULL);
+       memset(pass, 0, strlen(pass));
+       g_free(pass);
        
 /* free/busy export */
        vcalprefs.export_freebusy_enable = 
        
 /* free/busy export */
        vcalprefs.export_freebusy_enable = 
@@ -654,9 +704,10 @@ static void vcal_prefs_save_func(PrefsPage * _page)
        vcalprefs.export_freebusy_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
        g_free(vcalprefs.export_freebusy_pass);
        vcalprefs.export_freebusy_user =
            gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_user_entry), 0, -1);
        g_free(vcalprefs.export_freebusy_pass);
-       vcalprefs.export_freebusy_pass =
-           gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
-       
+       pass = gtk_editable_get_chars(GTK_EDITABLE(page->export_freebusy_pass_entry), 0, -1);
+       vcalprefs.export_freebusy_pass = password_encrypt(pass, NULL);
+       memset(pass, 0, strlen(pass));
+       g_free(pass);
 
 /* free/busy import */
        g_free(vcalprefs.freebusy_get_url);
 
 /* free/busy import */
        g_free(vcalprefs.freebusy_get_url);