Fix capitalization of a one Web[cC]al occurrence.
[claws.git] / src / plugins / vcalendar / vcal_folder.c
index a11ff96c0103ceb670dbf530ae6ff7cfba5f57c1..4cde1bce6ab0d4cadb1547cf1d39b066af2f7515 100644 (file)
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <curl/curl.h>
 #include <curl/curlver.h>
+#include <ctype.h>
 
 #include "account.h"
 #include "utils.h"
@@ -610,7 +611,8 @@ add_new:
                        }
                        if (rprop && ritr) {
                                struct icaldurationtype ical_dur;
-                               struct icaltimetype dtstart, dtend;
+                               struct icaltimetype dtstart = icaltime_null_time();
+                               struct icaltimetype dtend = icaltime_null_time();
                                evt = icalcomponent_new_clone(evt);
                                prop = icalcomponent_get_first_property(evt, ICAL_RRULE_PROPERTY);
                                if (prop) {
@@ -620,9 +622,13 @@ add_new:
                                prop = icalcomponent_get_first_property(evt, ICAL_DTSTART_PROPERTY);
                                if (prop)
                                        dtstart = icalproperty_get_dtstart(prop);
+                               else
+                                       debug_print("event has no DTSTART!\n");
                                prop = icalcomponent_get_first_property(evt, ICAL_DTEND_PROPERTY);
                                if (prop)
                                        dtend = icalproperty_get_dtend(prop);
+                               else
+                                       debug_print("event has no DTEND!\n");
                                ical_dur = icaltime_subtract(dtend, dtstart);
                                next = icalrecur_iterator_next(ritr);
                                if (!icaltime_is_null_time(next) &&
@@ -1526,8 +1532,7 @@ gchar* get_item_event_list_for_date(FolderItem *item, EventTime date)
                        strcpy(result+e_len+2, (gchar *)cur->data);
                }
        }
-       slist_free_strings(strs);
-       g_slist_free(strs);
+       slist_free_strings_full(strs);
        return result;
 }
 
@@ -1642,7 +1647,6 @@ gchar *vcal_curl_read(const char *url, const gchar *label, gboolean verbose,
        thread_data *td;
 #ifdef USE_PTHREAD
        pthread_t pt;
-       pthread_attr_t pta;
 #endif
        void *res;
        gchar *error = NULL;
@@ -1657,10 +1661,7 @@ gchar *vcal_curl_read(const char *url, const gchar *label, gboolean verbose,
        STATUSBAR_PUSH(mainwindow_get_mainwindow(), label);
 
 #ifdef USE_PTHREAD
-       if (pthread_attr_init(&pta) != 0 ||
-           pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE) != 0 ||
-           pthread_create(&pt, &pta, 
-                       url_read_thread, td) != 0) {
+       if (pthread_create(&pt, NULL, url_read_thread, td) != 0) {
                url_read_thread(td);    
        }
        while (!td->done)  {
@@ -1807,9 +1808,10 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
        }
 
        if (feed == NULL) {
+               gchar *err_msg = _("Could not retrieve the Webcal URL:\n%s:\n\n%s");
+
                if (verbose && manual_update) {
-                       gchar *tmp; 
-                       tmp = g_strdup(uri);
+                       gchar *tmp = g_strdup(uri);
                        if (strlen(uri) > 61) {
                                tmp[55]='[';
                                tmp[56]='.';
@@ -1818,12 +1820,12 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
                                tmp[59]=']';
                                tmp[60]='\0';
                        } 
-                       alertpanel_error(_("Could not retrieve the Webcal URL:\n%s:\n\n%s"),
-                                       tmp, error ? error:_("Unknown error"));
+                       alertpanel_error(err_msg, tmp, error ? error:_("Unknown error"));
                        g_free(tmp);
                } else  {
-                       log_error(LOG_PROTOCOL, _("Could not retrieve the Webcal URL:\n%s:\n\n%s\n"),
-                                       uri, error ? error:_("Unknown error"));
+                       gchar *msg = g_strdup_printf("%s\n", err_msg);
+                       log_error(LOG_PROTOCOL, msg, uri, error ? error:_("Unknown error"));
+                       g_free(msg);
                }
                main_window_cursor_normal(mainwindow_get_mainwindow());
                g_free(feed);
@@ -1831,13 +1833,20 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
                        g_free(error);
                return;
        }
-       if (strncmp(feed, "BEGIN:VCALENDAR", strlen("BEGIN:VCALENDAR"))) {
+
+       gchar *tmp = feed;
+       while (*tmp && isspace((unsigned char)*tmp))
+               tmp++;
+
+       if (strncmp(tmp, "BEGIN:VCALENDAR", strlen("BEGIN:VCALENDAR"))) {
+               gchar *err_msg = _("This URL does not look like a Webcal URL:\n%s\n%s");
+
                if (verbose && manual_update) {
-                       alertpanel_error(_("This URL does not look like a Webcal URL:\n%s\n%s"),
-                                       uri, error ? error:_("Unknown error"));
+                       alertpanel_error(err_msg, uri, error ? error:_("Unknown error"));
                } else  {
-                       log_error(LOG_PROTOCOL, _("This URL does not look like a Webcal URL:\n%s\n%s\n"),
-                                       uri, error ? error:_("Unknown error"));
+                       gchar *msg = g_strdup_printf("%s\n", err_msg);
+                       log_error(LOG_PROTOCOL, msg, uri, error ? error:_("Unknown error"));
+                       g_free(msg);
                }
                g_free(feed);
                main_window_cursor_normal(mainwindow_get_mainwindow());
@@ -1939,7 +1948,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;
        
@@ -1981,8 +1990,8 @@ static void unsubscribe_cal_cb(GtkAction *action, gpointer data)
        message = g_strdup_printf
                (_("Do you really want to unsubscribe?"));
        avalue = alertpanel_full(_("Delete subscription"), message,
-                                GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, 
-                                FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
+                                GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, ALERTFOCUS_FIRST, 
+                                FALSE, NULL, ALERT_WARNING);
        g_free(message);
        if (avalue != G_ALERTALTERNATE) return;
 
@@ -2237,7 +2246,6 @@ VCalEvent *vcal_get_event_from_ical(const gchar *ical, const gchar *charset)
        gchar *int_ical = g_strdup(ical);
        icalcomponent *comp = icalcomponent_new_from_string(int_ical);
        icalcomponent *inner = NULL;
-       icalcomponent *tzcomp = NULL;
        icalproperty *prop = NULL;
        GSList *list = NULL, *cur = NULL;
        gchar *uid = NULL;