While we're at it, fix typos like prefered occurences in variable names.
[claws.git] / src / plugins / vcalendar / vcal_folder.c
index ec8657488ea90ec64eb738b944c83850d273cd82..6ed463dce0b0e98a0b08501849cb3b56cc3a9162 100644 (file)
@@ -60,6 +60,7 @@
 #include "mainwindow.h"
 #include "statusbar.h"
 #include "msgcache.h"
+#include "passwordstore.h"
 #include "timing.h"
 #include "messageview.h"
 
@@ -163,7 +164,7 @@ static char *vcal_popup_labels[] =
 {
        N_("_New meeting..."),
        N_("_Export calendar..."),
-       N_("_Subscribe to webCal..."),
+       N_("_Subscribe to Webcal..."),
        N_("_Unsubscribe..."),
        N_("_Rename..."),
        N_("U_pdate subscriptions"),
@@ -745,7 +746,7 @@ GSList *vcal_get_events_list(FolderItem *item)
                event = vcal_manager_load_event(d);
                if (!event)
                        continue;
-               if (event->rec_occurence) {
+               if (event->rec_occurrence) {
                        vcal_manager_free_event(event);
                        claws_unlink(d);
                        continue;
@@ -803,7 +804,7 @@ GSList *vcal_get_events_list(FolderItem *item)
                                                                event->sequence, event->type);
                                        g_free(uid);
                                        vcal_manager_copy_attendees(event, nevent);
-                                       nevent->rec_occurence = TRUE;
+                                       nevent->rec_occurrence = TRUE;
                                        vcal_manager_save_event(nevent, FALSE);
                                        account = vcal_manager_get_account_from_event(event);
                                        status =
@@ -862,7 +863,7 @@ static gint vcal_get_num_list(Folder *folder, FolderItem *item,
                        continue;
                g_hash_table_insert(hash_uids, GINT_TO_POINTER(n_msg), g_strdup(event->uid));
                
-               if (event->rec_occurence) {
+               if (event->rec_occurrence) {
                        vcal_manager_free_event(event);
                        continue;
                }
@@ -1053,7 +1054,7 @@ static gint vcal_remove_msg(Folder *folder, FolderItem *_item, gint num)
        if (_item == folder->inbox)
                vcal_remove_event(folder, msginfo);
 
-       procmsg_msginfo_free(msginfo);
+       procmsg_msginfo_free(&msginfo);
        return 0;
 }
 
@@ -1170,31 +1171,45 @@ void vcal_folder_export(Folder *folder)
 {      
        FolderItem *item = folder?folder->inbox:NULL;
        gboolean need_scan = folder?vcal_scan_required(folder, item):TRUE;
+       gchar *export_pass = NULL;
+       gchar *export_freebusy_pass = NULL;
 
        if (vcal_folder_lock_count) /* blocked */
                return;
        vcal_folder_lock_count++;
+       
+       export_pass = vcal_passwd_get("export");
+       export_freebusy_pass = vcal_passwd_get("export_freebusy");
+
        if (vcal_meeting_export_calendar(vcalprefs.export_path, 
                        vcalprefs.export_user, 
-                       vcalprefs.export_pass,
+                       export_pass,
                        TRUE)) {
                debug_print("exporting calendar\n");
                if (vcalprefs.export_enable &&
                    vcalprefs.export_command &&
                    strlen(vcalprefs.export_command))
                        execute_command_line(
-                               vcalprefs.export_command, TRUE);
+                               vcalprefs.export_command, TRUE, NULL);
+       }
+       if (export_pass != NULL) {
+               memset(export_pass, 0, strlen(export_pass));
        }
+       g_free(export_pass);
        if (vcal_meeting_export_freebusy(vcalprefs.export_freebusy_path,
                        vcalprefs.export_freebusy_user,
-                       vcalprefs.export_freebusy_pass)) {
+                       export_freebusy_pass)) {
                debug_print("exporting freebusy\n");
                if (vcalprefs.export_freebusy_enable &&
                    vcalprefs.export_freebusy_command &&
                    strlen(vcalprefs.export_freebusy_command))
                        execute_command_line(
-                               vcalprefs.export_freebusy_command, TRUE);
+                               vcalprefs.export_freebusy_command, TRUE, NULL);
        }
+       if (export_freebusy_pass != NULL) {
+               memset(export_freebusy_pass, 0, strlen(export_freebusy_pass));
+       }
+       g_free(export_freebusy_pass);
        vcal_folder_lock_count--;
        if (!need_scan && folder) {
                vcal_set_mtime(folder, folder->inbox);
@@ -1817,10 +1832,10 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
        }
        if (strncmp(feed, "BEGIN:VCALENDAR", strlen("BEGIN:VCALENDAR"))) {
                if (verbose && manual_update) {
-                       alertpanel_error(_("This URL does not look like a WebCal URL:\n%s\n%s"),
+                       alertpanel_error(_("This URL does not look like a Webcal URL:\n%s\n%s"),
                                        uri, error ? error:_("Unknown error"));
                } else  {
-                       log_error(LOG_PROTOCOL, _("This URL does not look like a WebCal URL:\n%s\n%s\n"),
+                       log_error(LOG_PROTOCOL, _("This URL does not look like a Webcal URL:\n%s\n%s\n"),
                                        uri, error ? error:_("Unknown error"));
                }
                g_free(feed);
@@ -1837,14 +1852,10 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
                gchar *title = feed_get_title(feed);
                if (title == NULL) {
                        if (strstr(uri, "://"))
-                               title = g_strdup(strstr(uri,"://")+3);
+                               title = g_path_get_basename(strstr(uri,"://")+3);
                        else
                                title = g_strdup(uri);
                        subst_for_filename(title);
-                       if (strlen(title) > 32) {
-                               title[29]=title[30]=title[31]='.';
-                               title[32]='\0';
-                       }
                }
                item = folder_create_folder(root->node->data, title);
                if (!item) {
@@ -1925,7 +1936,7 @@ static void subscribe_cal_cb(GtkAction *action, gpointer data)
        gchar *uri = NULL;
        gchar *tmp = NULL;
 
-       tmp = input_dialog(_("Subscribe to WebCal"), _("Enter the WebCal URL:"), NULL);
+       tmp = input_dialog(_("Subscribe to Webcal"), _("Enter the WebCal URL:"), NULL);
        if (tmp == NULL)
                return;
        
@@ -1951,8 +1962,7 @@ static void subscribe_cal_cb(GtkAction *action, gpointer data)
 static void unsubscribe_cal_cb(GtkAction *action, gpointer data)
 {
        FolderView *folderview = (FolderView *)data;
-       GtkCMCTree *ctree = GTK_CMCTREE(folderview->ctree);
-       FolderItem *item;
+       FolderItem *item, *opened;
        gchar *message;
        AlertValue avalue;
        gchar *old_id;
@@ -1963,10 +1973,11 @@ static void unsubscribe_cal_cb(GtkAction *action, gpointer data)
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->path != NULL);
        g_return_if_fail(item->folder != NULL);
+       opened = folderview_get_opened_item(folderview);
 
        message = g_strdup_printf
                (_("Do you really want to unsubscribe?"));
-       avalue = alertpanel_full(_("Delete folder"), message,
+       avalue = alertpanel_full(_("Delete subscription"), message,
                                 GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, 
                                 FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
        g_free(message);
@@ -1976,12 +1987,10 @@ static void unsubscribe_cal_cb(GtkAction *action, gpointer data)
 
        vcal_item_closed(item);
 
-       if (folderview->opened == folderview->selected ||
-           gtk_cmctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
+       if (item == opened ||
+                       folder_is_child_of(item, opened)) {
                summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
+               folderview_close_opened(folderview, TRUE);
        }
 
        if (item->folder->klass->remove_folder(item->folder, item) < 0) {
@@ -2066,13 +2075,12 @@ static void set_view_cb(GtkAction *gaction, GtkRadioAction *current, gpointer da
 {
        FolderView *folderview = (FolderView *)data;
        gint action = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
-       GtkCMCTree *ctree = GTK_CMCTREE(folderview->ctree);
        FolderItem *item = NULL, *oitem = NULL;
 
        if (!folderview->selected) return;
        if (setting_sensitivity) return;
 
-       oitem = gtk_cmctree_node_get_row_data(ctree, folderview->opened);
+       oitem = folderview_get_opened_item(folderview);
        item = folderview_get_selected_item(folderview);
 
        if (!item)
@@ -2099,7 +2107,7 @@ gchar *vcal_get_event_as_ical_str(VCalEvent *event)
             icalproperty_new_prodid(
                  "-//Claws Mail//NONSGML Claws Mail Calendar//EN"),
            icalproperty_new_calscale("GREGORIAN"),
-            0);
+            (void*)0);
        vcal_manager_event_dump(event, FALSE, FALSE, calendar, FALSE);
        ical = g_strdup(icalcomponent_as_ical_string(calendar));
        icalcomponent_free(calendar);
@@ -2418,7 +2426,7 @@ gboolean vcal_event_exists(const gchar *id)
 
        info = folder_item_get_msginfo_by_msgid(folder->inbox, id);
        if (info != NULL) {
-               procmsg_msginfo_free(info);
+               procmsg_msginfo_free(&info);
                return TRUE;
        }
        return FALSE;
@@ -2456,7 +2464,7 @@ gboolean vcal_delete_event(const gchar *id)
        if (info != NULL) {
                debug_print("removing event %s\n", id);
                vcal_remove_event(folder, info);
-               procmsg_msginfo_free(info);
+               procmsg_msginfo_free(&info);
                folder_item_scan(folder->inbox);
                return TRUE;
        }