From b73ed1d9ffd6975d94638364b6a7fcd7f29a6c23 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Mon, 4 May 2009 16:31:12 +0200 Subject: BUGFIX: 547414 - Publish Free/Busy calendar for configurable time Allow user define time duration for the Free/Busy calendar information in the publish-calendar plugin. --- plugins/publish-calendar/publish-calendar.glade | 102 +++++++++++++++++++++--- plugins/publish-calendar/publish-format-fb.c | 18 ++++- plugins/publish-calendar/publish-location.c | 34 +++++++- plugins/publish-calendar/publish-location.h | 8 ++ plugins/publish-calendar/url-editor-dialog.c | 21 ++++- plugins/publish-calendar/url-editor-dialog.h | 5 +- 6 files changed, 171 insertions(+), 17 deletions(-) (limited to 'plugins/publish-calendar') diff --git a/plugins/publish-calendar/publish-calendar.glade b/plugins/publish-calendar/publish-calendar.glade index 6f6ae9dcf2..1f1dca0202 100644 --- a/plugins/publish-calendar/publish-calendar.glade +++ b/plugins/publish-calendar/publish-calendar.glade @@ -382,7 +382,7 @@ True - 2 + 3 2 False 6 @@ -417,6 +417,24 @@ + + + True + iCal +Free/Busy + False + True + + + 1 + 2 + 0 + 1 + fill + fill + + + True @@ -439,8 +457,8 @@ 0 1 - 1 - 2 + 2 + 3 fill @@ -458,25 +476,87 @@ Manual (via Actions menu) 1 2 + 2 + 3 + fill + + + + + + True + Time _duration: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + fb_duration_spin + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 1 2 - fill + fill + - + True - iCal -Free/Busy - False - True + False + 0 + + + + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 1 1 100 1 10 0 + + + 0 + False + False + + + + + + True + days +weeks +months + False + True + + + 0 + True + True + + 1 2 - 0 - 1 + 1 + 2 fill fill diff --git a/plugins/publish-calendar/publish-format-fb.c b/plugins/publish-calendar/publish-format-fb.c index 5956b0ff8d..a4b3a44544 100644 --- a/plugins/publish-calendar/publish-format-fb.c +++ b/plugins/publish-calendar/publish-format-fb.c @@ -33,7 +33,7 @@ #include "publish-format-fb.h" static gboolean -write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream, GError **error) +write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream, int dur_type, int dur_value, GError **error) { ESource *source; ECal *client = NULL; @@ -47,7 +47,19 @@ write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream, GEr utc = icaltimezone_get_utc_timezone (); start = time_day_begin_with_zone (start, utc); - end = time_add_week_with_zone (start, 6, utc); + + switch (dur_type) { + case FB_DURATION_DAYS: + end = time_add_day_with_zone (start, dur_value, utc); + break; + default: + case FB_DURATION_WEEKS: + end = time_add_week_with_zone (start, dur_value, utc); + break; + case FB_DURATION_MONTHS: + end = time_add_month_with_zone (start, dur_value, utc); + break; + } source = e_source_list_peek_source_by_uid (source_list, uid); if (source) @@ -109,7 +121,7 @@ publish_calendar_as_fb (GOutputStream *stream, EPublishUri *uri, GError **error) l = uri->events; while (l) { gchar *uid = l->data; - if (!write_calendar (uid, source_list, stream, error)) + if (!write_calendar (uid, source_list, stream, uri->fb_duration_type, uri->fb_duration_value, error)) break; l = g_slist_next (l); } diff --git a/plugins/publish-calendar/publish-location.c b/plugins/publish-calendar/publish-location.c index 2de877b093..1ebe2cfefb 100644 --- a/plugins/publish-calendar/publish-location.c +++ b/plugins/publish-calendar/publish-location.c @@ -120,7 +120,7 @@ e_publish_uri_from_xml (const gchar *xml) { xmlDocPtr doc; xmlNodePtr root, p; - xmlChar *location, *enabled, *frequency; + xmlChar *location, *enabled, *frequency, *fb_duration_value, *fb_duration_type; xmlChar *publish_time, *format, *username = NULL; GSList *events = NULL; EPublishUri *uri; @@ -146,6 +146,8 @@ e_publish_uri_from_xml (const gchar *xml) frequency = xmlGetProp (root, (const unsigned char *)"frequency"); format = xmlGetProp (root, (const unsigned char *)"format"); publish_time = xmlGetProp (root, (const unsigned char *)"publish_time"); + fb_duration_value = xmlGetProp (root, (xmlChar *)"fb_duration_value"); + fb_duration_type = xmlGetProp (root, (xmlChar *)"fb_duration_type"); if (location != NULL) uri->location = (char *)location; @@ -158,6 +160,23 @@ e_publish_uri_from_xml (const gchar *xml) if (publish_time != NULL) uri->last_pub_time = (char *)publish_time; + if (fb_duration_value) + uri->fb_duration_value = atoi ((char *)fb_duration_value); + else + uri->fb_duration_value = -1; + + if (uri->fb_duration_value < 1) + uri->fb_duration_value = 6; + else if (uri->fb_duration_value > 100) + uri->fb_duration_value = 100; + + if (fb_duration_type && g_str_equal ((char *)fb_duration_type, "days")) + uri->fb_duration_type = FB_DURATION_DAYS; + else if (fb_duration_type && g_str_equal ((char *)fb_duration_type, "months")) + uri->fb_duration_type = FB_DURATION_MONTHS; + else + uri->fb_duration_type = FB_DURATION_WEEKS; + uri->password = g_strdup (""); for (p = root->children; p != NULL; p = p->next) { @@ -173,6 +192,8 @@ e_publish_uri_from_xml (const gchar *xml) xmlFree (enabled); xmlFree (frequency); xmlFree (format); + xmlFree (fb_duration_value); + xmlFree (fb_duration_type); xmlFreeDoc (doc); return uri; @@ -204,6 +225,17 @@ e_publish_uri_to_xml (EPublishUri *uri) xmlSetProp (root, (const unsigned char *)"format", (unsigned char *)format); xmlSetProp (root, (const unsigned char *)"publish_time", (unsigned char *)uri->last_pub_time); + g_free (format); + format = g_strdup_printf ("%d", uri->fb_duration_value); + xmlSetProp (root, (xmlChar *)"fb_duration_value", (xmlChar *)format); + + if (uri->fb_duration_type == FB_DURATION_DAYS) + xmlSetProp (root, (xmlChar *)"fb_duration_type", (xmlChar *)"days"); + else if (uri->fb_duration_type == FB_DURATION_MONTHS) + xmlSetProp (root, (xmlChar *)"fb_duration_type", (xmlChar *)"months"); + else + xmlSetProp (root, (xmlChar *)"fb_duration_type", (xmlChar *)"weeks"); + for (calendars = uri->events; calendars != NULL; calendars = g_slist_next (calendars)) { xmlNodePtr node; node = xmlNewChild (root, NULL, (const unsigned char *)"event", NULL); diff --git a/plugins/publish-calendar/publish-location.h b/plugins/publish-calendar/publish-location.h index f3fbf03d49..ec627d18ce 100644 --- a/plugins/publish-calendar/publish-location.h +++ b/plugins/publish-calendar/publish-location.h @@ -56,6 +56,12 @@ static const int publish_format_type_mask[] = { -1, }; +enum FBDurationType { + FB_DURATION_DAYS, + FB_DURATION_WEEKS, + FB_DURATION_MONTHS +}; + typedef struct _EPublishUri EPublishUri; struct _EPublishUri { gboolean enabled; @@ -65,6 +71,8 @@ struct _EPublishUri { gchar *password; GSList *events; gchar *last_pub_time; + int fb_duration_value; + int fb_duration_type; gint service_type; }; diff --git a/plugins/publish-calendar/url-editor-dialog.c b/plugins/publish-calendar/url-editor-dialog.c index 8e1c735dc3..ea03320ae8 100644 --- a/plugins/publish-calendar/url-editor-dialog.c +++ b/plugins/publish-calendar/url-editor-dialog.c @@ -90,6 +90,9 @@ create_uri (UrlEditorDialog *dialog) g_free (username); g_free (password); } + + uri->fb_duration_value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->fb_duration_spin)); + uri->fb_duration_type = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->fb_duration_combo)); } static void @@ -101,6 +104,16 @@ check_input (UrlEditorDialog *dialog) uri = dialog->uri; + if (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->type_selector)) == 1) { + gtk_widget_show (dialog->fb_duration_label); + gtk_widget_show (dialog->fb_duration_spin); + gtk_widget_show (dialog->fb_duration_combo); + } else { + gtk_widget_hide (dialog->fb_duration_label); + gtk_widget_hide (dialog->fb_duration_spin); + gtk_widget_hide (dialog->fb_duration_combo); + } + if (GTK_WIDGET_IS_SENSITIVE (dialog->events_selector)) { sources = e_source_selector_get_selection (E_SOURCE_SELECTOR (dialog->events_selector)); n += g_slist_length (sources); @@ -329,8 +342,11 @@ url_editor_dialog_construct (UrlEditorDialog *dialog) dialog->gui = gui; #define GW(name) ((dialog->name) = glade_xml_get_widget (dialog->gui, #name)) - GW(publish_frequency); GW(type_selector); + GW(fb_duration_label); + GW(fb_duration_spin); + GW(fb_duration_combo); + GW(publish_frequency); GW(events_swin); @@ -429,6 +445,9 @@ url_editor_dialog_construct (UrlEditorDialog *dialog) } } + gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->fb_duration_spin), uri->fb_duration_value); + gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->fb_duration_combo), uri->fb_duration_type); + g_signal_connect (G_OBJECT (dialog->publish_service), "changed", G_CALLBACK (publish_service_changed), dialog); g_signal_connect (G_OBJECT (dialog->type_selector), "changed", G_CALLBACK (type_selector_changed), dialog); g_signal_connect (G_OBJECT (dialog->publish_frequency), "changed", G_CALLBACK (frequency_changed_cb), dialog); diff --git a/plugins/publish-calendar/url-editor-dialog.h b/plugins/publish-calendar/url-editor-dialog.h index 2d985e90e5..3a85fc895e 100644 --- a/plugins/publish-calendar/url-editor-dialog.h +++ b/plugins/publish-calendar/url-editor-dialog.h @@ -64,8 +64,11 @@ struct _UrlEditorDialog { GladeXML *gui; - GtkWidget *publish_frequency; GtkWidget *type_selector; + GtkWidget *fb_duration_label; + GtkWidget *fb_duration_spin; + GtkWidget *fb_duration_combo; + GtkWidget *publish_frequency; GtkWidget *events_swin; -- cgit