Fix bug #3808: Replace icaltime_from_timet with icaltime_from_timet_with_zone
[claws.git] / src / plugins / vcalendar / vcal_meeting_gtk.c
index bf23801197f84aedb578cd769343269ebdaaf76b..976d7da2f15a18f40a636d7991c640dd7e8402e9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net> and 
+ * Copyright (C) 1999-2013 Colin Leroy <colin@colino.net> and 
  * the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -32,7 +32,7 @@
 #ifdef USE_PTHREAD
 #include <pthread.h>
 #endif
-#include <ical.h>
+#include <libical/ical.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <curl/curl.h>
@@ -88,9 +88,6 @@ struct _VCalMeeting
        GtkWidget *total_avail_msg;
        PrefsAccount *account;
        gboolean visible;
-#if !GTK_CHECK_VERSION(2,12,0)
-       GtkTooltips *tips;
-#endif
 };
 
 struct _VCalAttendee {
@@ -278,9 +275,6 @@ VCalAttendee *attendee_add(VCalMeeting *meet, gchar *address, gchar *name, gchar
 {
        GtkWidget *att_hbox = gtk_hbox_new(FALSE, 6);
        VCalAttendee *attendee  = g_new0(VCalAttendee, 1);
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = meet->tips;
-#endif
 
        attendee->address       = gtk_entry_new();
        attendee->cutype        = gtk_combo_box_new_text();
@@ -368,7 +362,7 @@ static gchar *get_organizer(VCalMeeting *meet)
                cur = cur->next;
                i++;
        }
-       if (cur)
+       if (cur && cur->data)
                return g_strdup(((PrefsAccount *)(cur->data))->address);
        else
                return g_strdup("");
@@ -384,7 +378,7 @@ static gchar *get_organizer_name(VCalMeeting *meet)
                cur = cur->next;
                i++;
        }
-       if (cur)
+       if (cur && cur->data)
                return g_strdup(((PrefsAccount *)(cur->data))->name);
        else
                return g_strdup("");
@@ -483,7 +477,7 @@ static gchar *get_date(VCalMeeting *meet, int start)
        debug_print("DST change offset to apply to time %d\n", dst_offset);
        t += dst_offset;
        debug_print("%s\n", ctime(&t));
-       return g_strdup(icaltime_as_ical_string(icaltime_from_timet(t, FALSE)));
+       return g_strdup(icaltime_as_ical_string(icaltime_from_timet_with_zone(t, FALSE, NULL)));
 }
 
 static gchar *get_location(VCalMeeting *meet)
@@ -714,9 +708,6 @@ static void meeting_end_changed(GtkWidget *widget, gpointer data)
 static void att_update_icon(VCalMeeting *meet, VCalAttendee *attendee, gint avail, gchar *text)
 {
        const gchar *icon = GTK_STOCK_DIALOG_INFO;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = meet->tips;
-#endif
 
        switch (avail) {
                case 0:  icon = GTK_STOCK_DIALOG_WARNING;       break;
@@ -785,7 +776,7 @@ static gchar *get_avail_msg(const gchar *unavailable_persons, gboolean multiple,
        gchar *msg, *intro = NULL, *outro = NULL, *before = NULL, *after = NULL;
 
        if (multiple)
-               intro = g_strdup(_("The following person(s) are busy at the time of your planned meeting:\n- "));
+               intro = g_strdup(_("The following people are busy at the time of your planned meeting:\n- "));
        else if (!strcmp(unavailable_persons, _("You")))
                intro = g_strdup(_("You are busy at the time of your planned meeting"));
        else
@@ -867,9 +858,6 @@ static gboolean find_availability(const gchar *dtstart, const gchar *dtend, GSLi
        GHashTable *avail_table_avail = g_hash_table_new(NULL, g_direct_equal);
        GHashTable *avail_table_before = g_hash_table_new(NULL, g_direct_equal);
        GHashTable *avail_table_after = g_hash_table_new(NULL, g_direct_equal);
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = meet->tips;
-#endif
        
        for (cur = attendees; cur; cur = cur->next) {
                VCalAttendee *attendee = (VCalAttendee *)cur->data;
@@ -905,8 +893,8 @@ static gboolean find_availability(const gchar *dtstart, const gchar *dtend, GSLi
        found = FALSE;
        while (!found && offset >= -3600*6) {
                gboolean ok = TRUE;
-               struct icaltimetype new_start = icaltime_from_timet(icaltime_as_timet(start)+offset, FALSE);
-               struct icaltimetype new_end   = icaltime_from_timet(icaltime_as_timet(end)+offset, FALSE);
+               struct icaltimetype new_start = icaltime_from_timet_with_zone(icaltime_as_timet(start)+offset, FALSE, NULL);
+               struct icaltimetype new_end   = icaltime_from_timet_with_zone(icaltime_as_timet(end)+offset, FALSE, NULL);
                for (cur = attendees; cur; cur = cur->next) {
                        VCalAttendee *attendee = (VCalAttendee *)cur->data;
                        debug_print("trying %s - %s (offset %d)\n", 
@@ -931,8 +919,8 @@ static gboolean find_availability(const gchar *dtstart, const gchar *dtend, GSLi
        offset = 1800;
        while (!found && offset <= 3600*6) {
                gboolean ok = TRUE;
-               struct icaltimetype new_start = icaltime_from_timet(icaltime_as_timet(start)+offset, FALSE);
-               struct icaltimetype new_end   = icaltime_from_timet(icaltime_as_timet(end)+offset, FALSE);
+               struct icaltimetype new_start = icaltime_from_timet_with_zone(icaltime_as_timet(start)+offset, FALSE, NULL);
+               struct icaltimetype new_end   = icaltime_from_timet_with_zone(icaltime_as_timet(end)+offset, FALSE, NULL);
                for (cur = attendees; cur; cur = cur->next) {
                        VCalAttendee *attendee = (VCalAttendee *)cur->data;
                        debug_print("trying %s - %s (offset %d)\n", 
@@ -1015,9 +1003,6 @@ static gboolean check_attendees_availability(VCalMeeting *meet, gboolean tell_if
                                "internal.ifb", NULL);
        gboolean local_only = FALSE;
        GSList *attlist;
-#if !(GTK_CHECK_VERSION(2,12,0))
-       GtkTooltips *tips = meet->tips;
-#endif
 
        if (vcalprefs.freebusy_get_url == NULL
        ||  *vcalprefs.freebusy_get_url == '\0') {
@@ -1031,7 +1016,7 @@ static gboolean check_attendees_availability(VCalMeeting *meet, gboolean tell_if
                        num_format++;
                }
                if (num_format > 2) {
-                       g_warning("wrong format in %s!\n", real_url);
+                       g_warning("wrong format in %s!", real_url);
                        g_free(real_url);
                        return FALSE;
                }
@@ -1126,12 +1111,13 @@ static gboolean check_attendees_availability(VCalMeeting *meet, gboolean tell_if
                        if (strncmp(tmp, "http://", 7) 
                        && strncmp(tmp, "https://", 8)
                        && strncmp(tmp, "webcal://", 9)
+                       && strncmp(tmp, "webcals://", 10)
                        && strncmp(tmp, "ftp://", 6))
                                contents = file_read_to_str(tmp);
                        else {
                                gchar *label = g_strdup_printf(_("Fetching planning for %s..."), email);
-                               if (!strncmp(tmp, "webcal://", 9)) {
-                                       gchar *tmp2 = g_strdup_printf("http://%s", tmp+9);
+                               if (!strncmp(tmp, "webcal", 6)) {
+                                       gchar *tmp2 = g_strdup_printf("http%s", tmp+6);
                                        g_free(tmp);
                                        tmp = tmp2;
                                }
@@ -1235,12 +1221,11 @@ static gboolean send_meeting_cb(GtkButton *widget, gpointer data)
        gchar *summary = NULL;
        gchar *description = NULL;
        VCalEvent *event = NULL;
-       gchar buf[256];
        GSList *cur;
        PrefsAccount *account = NULL;
        gboolean res = FALSE;
        gboolean found_att = FALSE;
-       Folder *folder = folder_find_from_name ("vCalendar", vcal_folder_get_class());
+       Folder *folder = folder_find_from_name (PLUGIN_NAME, vcal_folder_get_class());
        gboolean redisp = FALSE;
 
        if (meet->uid == NULL && meet->visible && 
@@ -1261,25 +1246,20 @@ static gboolean send_meeting_cb(GtkButton *widget, gpointer data)
                gdk_window_set_cursor(meet->window->window, watch_cursor);
 
        organizer       = get_organizer(meet);
-       organizer_name  = get_organizer_name(meet);
        account         = account_find_from_address(organizer, FALSE);
 
-       if (account && account->set_domain && account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(account->address, '@') ?
-                               strchr(account->address, '@')+1 :
-                               account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
+       if(account == NULL) {
+               debug_print("can't get account from address %s\n", organizer);
+               g_free(organizer);
+               return FALSE;
        }
-       generate_msgid(buf, 255, account->address);
+
+       organizer_name  = get_organizer_name(meet);
 
        if (meet->uid) {
                uid     = g_strdup(meet->uid);
        } else {
-               uid     = g_strdup(buf);
+               uid     = prefs_account_generate_msgid(account);
        }
 
        dtstart         = get_date(meet, TRUE);
@@ -1391,12 +1371,10 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
        GtkTextBuffer *buffer = NULL;
        GtkWidget *date_hbox, *date_vbox, *save_hbox, *label, *hbox;
        gchar *s = NULL;
-       GtkObject *start_h_adj, *start_m_adj, *end_h_adj, *end_m_adj;
        int i = 0, num = 0;
        GtkWidget *scrolledwin;
        GList *times = NULL;
        GList *accounts;
-       GtkListStore *menu;
        gchar *time_text = NULL;
 #ifdef GENERIC_UMPC
        GtkWidget *notebook;
@@ -1406,14 +1384,7 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
        if (!watch_cursor)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
 
-#if !(GTK_CHECK_VERSION(2,12,0))
-       meet->tips = tips;
-#endif
        meet->visible = visible;
-       start_h_adj = gtk_adjustment_new (0, 0, 23, 1, 10, 10);
-       start_m_adj = gtk_adjustment_new (0, 0, 59, 1, 10, 10);
-       end_h_adj   = gtk_adjustment_new (0, 0, 23, 1, 10, 10);
-       end_m_adj   = gtk_adjustment_new (0, 0, 59, 1, 10, 10);
 
        meet->window            = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "vcal_meeting_gtk");
 #ifndef GENERIC_UMPC
@@ -1433,15 +1404,29 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
 
        times = get_predefined_times();
 
-       meet->start_time        = gtk_combo_box_entry_new_text ();
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       meet->start_time = gtk_combo_box_entry_new_text();
+#else
+       meet->start_time = gtk_combo_box_text_new_with_entry();
+#endif
        gtk_combo_box_set_active(GTK_COMBO_BOX(meet->start_time), -1);
-       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(meet->start_time)));
+#if !GTK_CHECK_VERSION(2, 24, 0)       
        combobox_set_popdown_strings(GTK_COMBO_BOX(meet->start_time), times);
-
-       meet->end_time          = gtk_combo_box_entry_new_text ();
+#else  
+       combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(meet->start_time), times);
+#endif
+       
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       meet->end_time = gtk_combo_box_entry_new_text();
+#else
+       meet->end_time = gtk_combo_box_text_new_with_entry();
+#endif
        gtk_combo_box_set_active(GTK_COMBO_BOX(meet->end_time), -1);
-       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(meet->end_time)));
+#if !GTK_CHECK_VERSION(2, 24, 0)       
        combobox_set_popdown_strings(GTK_COMBO_BOX(meet->end_time), times);
+#else  
+       combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(meet->end_time), times);
+#endif
 
        list_free_strings(times);
        g_list_free(times);
@@ -1597,12 +1582,14 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
        date_hbox = gtk_hbox_new(FALSE, 6);
        date_vbox = gtk_vbox_new(FALSE, 6);
        hbox = gtk_hbox_new(FALSE, 6);
-       label = gtk_label_new(_("<b>Starts at:</b> ")); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       label = gtk_label_new(g_strconcat("<b>",_("Starts at:"),"</b> ",NULL));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
        
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), meet->start_time, FALSE, FALSE, 0);
-       label = gtk_label_new(_("<b> on:</b>")); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       label = gtk_label_new(g_strconcat("<b> ",_("on:"),"</b>",NULL));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(date_vbox), hbox, FALSE, FALSE, 0);
@@ -1619,12 +1606,14 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
 
        date_vbox = gtk_vbox_new(FALSE, 6);
        hbox = gtk_hbox_new(FALSE, 6);
-       label = gtk_label_new(_("<b>Ends at:</b> ")); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       label = gtk_label_new(g_strconcat("<b>",_("Ends at:"),"</b> ", NULL));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
        
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(hbox), meet->end_time, FALSE, FALSE, 0);
-       label = gtk_label_new(_("<b> on:</b>")); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       label = gtk_label_new(g_strconcat("<b> ",_("on:"),"</b>",NULL));
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(date_vbox), hbox, FALSE, FALSE, 0);
@@ -1754,9 +1743,6 @@ static VCalMeeting *vcal_meeting_create_real(VCalEvent *event, gboolean visible)
        if (visible) {
                GSList *cur;
                gtk_widget_show_all(meet->window);
-#ifdef MAEMO
-               maemo_window_full_screen_if_needed(GTK_WINDOW(meet->window));
-#endif
                for (cur = meet->attendees; cur; cur = cur->next) {
                        gtk_widget_hide(((VCalAttendee *)cur->data)->avail_img);
                }
@@ -1951,12 +1937,11 @@ void multisync_export(void)
        icalcomponent *calendar = NULL;
        FILE *fp;
 
-       if (is_dir_exist(path))
-               remove_dir_recursive(path);
-       if (!is_dir_exist(path))
-               make_dir(path);
-       if (!is_dir_exist(path)) {
-               perror(path);
+       if (is_dir_exist(path) && remove_dir_recursive(path) < 0) {
+               g_free(path);
+               return;
+       }
+       if (make_dir(path) != 0) {
                g_free(path);
                return;
        }
@@ -1964,7 +1949,8 @@ void multisync_export(void)
        list = vcal_folder_get_waiting_events();
        for (cur = list; cur; cur = cur->next) {
                VCalEvent *event = (VCalEvent *)cur->data;
-               file = g_strdup_printf("multisync%lu-%d", time(NULL), i);
+               file = g_strdup_printf("multisync%lld-%d",
+                               (long long)time(NULL), i);
 
                i++;
 
@@ -1975,7 +1961,7 @@ void multisync_export(void)
                            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);
                tmp = g_strconcat(path, G_DIR_SEPARATOR_S, file, NULL);
@@ -1995,13 +1981,13 @@ void multisync_export(void)
                for (cur = files; cur; cur = cur->next) {
                        file = (char *)cur->data;
                        if (fprintf(fp, "1 1 %s\n", file) < 0)
-                               perror(file);
+                               FILE_OP_ERROR(file, "fprintf");
                        g_free(file);
                }
                if (fclose(fp) == EOF)
-                       perror(file);
+                       FILE_OP_ERROR(file, "fclose");
        } else {
-               perror(file);
+               FILE_OP_ERROR(file, "fopen");
        }
        g_free(path);
        g_slist_free(files);
@@ -2051,7 +2037,7 @@ gboolean vcal_meeting_export_calendar(const gchar *path,
                    icalproperty_new_prodid(
                         "-//Claws Mail//NONSGML Claws Mail Calendar//EN"),
                    icalproperty_new_calscale("GREGORIAN"),
-                   0
+                   (void*)0
             );         
 
        for (cur = list; cur; cur = cur->next) {
@@ -2061,7 +2047,7 @@ gboolean vcal_meeting_export_calendar(const gchar *path,
        }
 
        if (str_write_to_file(icalcomponent_as_ical_string(calendar), internal_file) < 0) {
-               g_warning("can't export internal cal\n");
+               g_warning("can't export internal cal");
        }
        
        g_free(internal_file);
@@ -2105,6 +2091,7 @@ putfile:
        && strncmp(file, "http://", 7) 
        && strncmp(file, "https://", 8)
        && strncmp(file, "webcal://", 9)
+       && strncmp(file, "webcals://", 10)
        && strncmp(file, "ftp://", 6)) {
                gchar *afile = NULL;
                if (file[0] != G_DIR_SEPARATOR)
@@ -2121,13 +2108,13 @@ putfile:
                g_free(file);
        } else if (file) {
                FILE *fp = g_fopen(tmpfile, "rb");
-               if (!strncmp(file, "webcal://", 9)) {
-                       gchar *tmp = g_strdup_printf("http://%s", file+9);
+               if (!strncmp(file, "webcal", 6)) {
+                       gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
                        file = tmp;
                }
                if (fp) {
-                       res = vcal_curl_put(file, fp, filesize, user, pass);
+                       res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
                        fclose(fp);
                }
                g_free(file);
@@ -2162,7 +2149,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
                    icalproperty_new_prodid(
                         "-//Claws Mail//NONSGML Claws Mail Calendar//EN"),
                    icalproperty_new_calscale("GREGORIAN"),
-                   0
+                   (void*)0
             );         
 
        timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT);
@@ -2185,8 +2172,8 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
 
        icalcomponent_add_component(calendar, timezone);
 
-       itt_start = icaltime_from_timet(whole_start, FALSE);
-       itt_end = icaltime_from_timet(whole_end, FALSE);
+       itt_start = icaltime_from_timet_with_zone(whole_start, FALSE, NULL);
+       itt_end = icaltime_from_timet_with_zone(whole_end, FALSE, NULL);
        itt_start.second = itt_start.minute = itt_start.hour = 0;
        itt_end.second = 59; itt_end.minute = 59; itt_end.hour = 23;
 
@@ -2196,7 +2183,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
                 ICAL_VFREEBUSY_COMPONENT,
                icalproperty_vanew_dtstart(itt_start, 0),
                icalproperty_vanew_dtend(itt_end, 0),
-                0
+                (void*)0
                 );
 
        debug_print("DTSTART:%s\nDTEND:%s\n",
@@ -2222,7 +2209,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
        icalcomponent_add_component(calendar, vfreebusy);
        
        if (str_write_to_file(icalcomponent_as_ical_string(calendar), internal_file) < 0) {
-               g_warning("can't export freebusy\n");
+               g_warning("can't export freebusy");
        }
        
        g_free(internal_file);
@@ -2252,6 +2239,7 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
        && strncmp(file, "http://", 7) 
        && strncmp(file, "https://", 8)
        && strncmp(file, "webcal://", 9)
+       && strncmp(file, "webcals://", 10)
        && strncmp(file, "ftp://", 6)) {
                gchar *afile = NULL;
                if (file[0] != G_DIR_SEPARATOR)
@@ -2268,13 +2256,13 @@ gboolean vcal_meeting_export_freebusy(const gchar *path, const gchar *user,
                g_free(file);
        } else if (file) {
                FILE *fp = g_fopen(tmpfile, "rb");
-               if (!strncmp(file, "webcal://", 9)) {
-                       gchar *tmp = g_strdup_printf("http://%s", file+9);
+               if (!strncmp(file, "webcal", 6)) {
+                       gchar *tmp = g_strdup_printf("http%s", file+6);
                        g_free(file);
                        file = tmp;
                }
                if (fp) {
-                       res = vcal_curl_put(file, fp, filesize, user, pass);
+                       res = vcal_curl_put(file, fp, filesize, user, (pass != NULL ? pass : ""));
                        fclose(fp);
                }
                g_free(file);