aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-pub-utils.c
diff options
context:
space:
mode:
authorGary Ekker <gekker@novell.com>2004-01-13 09:59:28 +0800
committerJP Rosevear <jpr@src.gnome.org>2004-01-13 09:59:28 +0800
commit449f48576b556874742934cacfbc80c041ff12fd (patch)
tree373f3fbea0dcc0c4aa8756ce56d7b085a079b6c9 /calendar/gui/e-pub-utils.c
parent99f392e5f1db3f927ae93eef5ca657f5a3db7f72 (diff)
downloadgsoc2013-evolution-449f48576b556874742934cacfbc80c041ff12fd.tar.gz
gsoc2013-evolution-449f48576b556874742934cacfbc80c041ff12fd.tar.zst
gsoc2013-evolution-449f48576b556874742934cacfbc80c041ff12fd.zip
add e-pub-utils.[ch] for Free/Busy publishing
2004-01-12 Gary Ekker <gekker@novell.com> * gui/Makefile.am: add e-pub-utils.[ch] for Free/Busy publishing * gui/apps_evolution_calendar.schemas.in.in: add schema for /apps/evo/calendar/free_busy key * gui/calendar-commands.c (publish_freebusy_cmd): change to publish component rather than attach as email * gui/calendar-config-keys.h: add free_busy/urls key definition * gui/calendar-config.[ch] (calendar_config_get_free_busy): new method for retrieving FB gconf key (calendar_config_set_free_busy): new method for saving FB gconf key * gui/e-cal-view.c (on_publish): change to publish component rather than attach as email * gui/itip-utils.[ch] (itip_publish_begin): new method to process e_cal_components and aggregate the data if we are publishing for multiple calendars (itip_publish_comp): new method to publish the ical data to an http server via libsoup (comp_fb_normalize): new static method to ensure rfc 2446 compliant data before publishing icalcomponent_get_uid (fb_sort): new static method to sort FB properties in ascending order * gui/dialogs/Makefile.am: add url-editor-dialog.[ch] and url-editor-dialog.glade for configure FB publishing * gui/dialogs/cal-prefs-dialog.[ch] (cal_prefs_dialog_url_add_clicked): (cal_prefs_dialog_url_edit_clicked):new method for events in FB tab of cal-prefs-dialog (cal_prefs_dialog_url_remove_clicked): ditto (cal_prefs_dialog_url_enable_clicked): ditto (cal_prefs_dialog_url_url_list_change): ditto (cal_prefs_dialog_url_url_list_enable_toggled): ditto (cal_prefs_dialog_url_url_list_double_click): ditto (show_fb_config): new method for updating dialog with FB specific data in gconf (update_fb_config): new method for updating gconf with FB specific data from dialogs (setup_changes): detect changes in url_list gtk_tree_view (get_widgets): include new dialog widgets for FB config (init_widgets): connect signals for new FB config widgets * gui/dialogs/cal-prefs-dialog.glade: add new widgets for FB config * gui/dialogs/url-editor-dialog.[ch]: add files for FB url-editor dialog * gui/dialogs/url-editor-dialog.glade: ditto * gui/e-pub-utils.[ch]: add files with FB publishing utilities * gui/calendar-component.c (init_calendar_publishing): sets up listeners to publish calendar, g_idle_add, and on gconf change (init_calendar_publishing_cb): ditto (conf_changed_callback): ditto (impl_createControls): ditto svn path=/trunk/; revision=24190
Diffstat (limited to 'calendar/gui/e-pub-utils.c')
-rw-r--r--calendar/gui/e-pub-utils.c310
1 files changed, 310 insertions, 0 deletions
diff --git a/calendar/gui/e-pub-utils.c b/calendar/gui/e-pub-utils.c
new file mode 100644
index 0000000000..2d6cce62ec
--- /dev/null
+++ b/calendar/gui/e-pub-utils.c
@@ -0,0 +1,310 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Evolution calendar Free/Busy utilities and types
+ *
+ * Copyright (C) 2004 Ximian, Inc.
+ *
+ * Author: Gary Ekker <gekker@novell.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <glib.h>
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+#include <libedataserver/e-source.h>
+#include <libedataserver/e-source-list.h>
+#include <libecal/e-cal-time-util.h>
+#include "calendar-config.h"
+#include "common/authentication.h"
+#include "itip-utils.h"
+#include "e-pub-utils.h"
+
+void
+e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml)
+{
+ xmlDocPtr doc;
+ xmlNodePtr root, p;
+ xmlChar *location, *enabled, *frequency;
+ xmlChar *username, *password, *publish_time;
+ GSList *l = NULL;
+
+ uri->location = NULL;
+ doc = xmlParseDoc ((char *)xml);
+ if (doc == NULL) {
+ uri->location = NULL;
+ return;
+ }
+
+ root = doc->children;
+ if (strcmp (root->name, "uri") != 0) {
+ return;
+ }
+ location = xmlGetProp (root, "location");
+ enabled = xmlGetProp (root, "enabled");
+ frequency = xmlGetProp (root, "frequency");
+ username = xmlGetProp (root, "username");
+ password = xmlGetProp (root, "password");
+ publish_time = xmlGetProp (root, "publish_time");
+
+ if (location != NULL)
+ uri->location = g_strdup (location);
+ if (enabled != NULL)
+ uri->enabled = atoi (enabled);
+ if (frequency != NULL)
+ uri->publish_freq = atoi (frequency);
+ if (username != NULL)
+ uri->username = g_strdup (username);
+ if (password != NULL)
+ uri->password = g_strdup (password);
+ if (publish_time != NULL)
+ uri->last_pub_time = g_strdup (publish_time);
+
+ for (p = root->children; p != NULL; p = p->next) {
+ xmlChar *uid = xmlGetProp (p, "uid");
+
+ l = g_slist_append (l, uid);
+ }
+ uri->calendars = l;
+
+ xmlFree(location);
+ xmlFree(enabled);
+ xmlFreeDoc(doc);
+ return;
+}
+
+gchar *
+e_pub_uri_to_xml (EPublishUri *uri)
+{
+ xmlDocPtr doc;
+ xmlNodePtr root;
+ gchar *enabled, *frequency;
+ GSList *cals = NULL;
+ xmlChar *xml_buffer;
+ char *returned_buffer;
+ int xml_buffer_size;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (uri->location != NULL, NULL);
+
+ doc = xmlNewDoc ("1.0");
+
+ root = xmlNewDocNode (doc, NULL, "uri", NULL);
+ enabled = g_strdup_printf ("%d", uri->enabled);
+ frequency = g_strdup_printf ("%d", uri->publish_freq);
+ xmlSetProp (root, "location", uri->location);
+ xmlSetProp (root, "enabled", enabled);
+ xmlSetProp (root, "frequency", frequency);
+ xmlSetProp (root, "username", uri->username);
+ xmlSetProp (root, "password", uri->password);
+ xmlSetProp (root, "publish_time", uri->last_pub_time);
+
+ for (cals = uri->calendars; cals != NULL; cals = cals->next) {
+ xmlNodePtr node;
+
+ node = xmlNewChild (root, NULL, "source", NULL);
+ xmlSetProp (node, "uid", cals->data);
+ }
+ xmlDocSetRootElement (doc, root);
+
+ xmlDocDumpMemory (doc, &xml_buffer, &xml_buffer_size);
+ xmlFreeDoc (doc);
+
+ returned_buffer = g_malloc (xml_buffer_size + 1);
+ memcpy (returned_buffer, xml_buffer, xml_buffer_size);
+ returned_buffer [xml_buffer_size] = '\0';
+ xmlFree (xml_buffer);
+ g_free (enabled);
+
+ return returned_buffer;
+}
+
+static gboolean
+is_publish_time (EPublishUri *uri) {
+ icaltimezone *utc;
+ struct icaltimetype current_itt, adjust_itt;
+
+ if (!uri->last_pub_time) {
+ utc = icaltimezone_get_utc_timezone ();
+ current_itt = icaltime_current_time_with_zone (utc);
+ uri->last_pub_time = g_strdup (icaltime_as_ical_string (current_itt));
+ return TRUE;
+
+ } else {
+ if (strlen (uri->last_pub_time) == 0) {
+ uri->last_pub_time = g_strdup (icaltime_as_ical_string (current_itt));
+ return TRUE;
+ }
+
+ utc = icaltimezone_get_utc_timezone ();
+ current_itt = icaltime_current_time_with_zone (utc);
+ adjust_itt = icaltime_from_string (uri->last_pub_time);
+
+ switch (uri->publish_freq) {
+ case URI_PUBLISH_DAILY:
+ icaltime_adjust (&adjust_itt, 1, 0, 0, 0);
+ if (icaltime_compare_date_only (adjust_itt, current_itt ) < 0) {
+ uri->last_pub_time = g_strdup (icaltime_as_ical_string (current_itt));
+ return TRUE;
+ }
+ break;
+ case URI_PUBLISH_WEEKLY:
+ icaltime_adjust (&adjust_itt, 7, 0, 0, 0);
+ if (icaltime_compare_date_only (adjust_itt, current_itt ) < 0) {
+ uri->last_pub_time = g_strdup (icaltime_as_ical_string (current_itt));
+ return TRUE;
+ }
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+just_published (gchar *last_pub_time) {
+ icaltimezone *utc;
+ struct icaltimetype pubtime_itt, adjust_itt;
+
+ if (strlen (last_pub_time) != 0) {
+ utc = icaltimezone_get_utc_timezone ();
+ pubtime_itt = icaltime_from_string (last_pub_time);
+ adjust_itt = icaltime_current_time_with_zone (utc);
+ icaltime_adjust (&adjust_itt, 0, 0, 0, 3);
+ if (icaltime_compare_date_only (pubtime_itt, adjust_itt) < 0)
+ return TRUE;
+ }
+
+
+ return FALSE;
+}
+
+void
+e_pub_publish (gboolean publish) {
+ icaltimezone *utc;
+ time_t start = time (NULL), end;
+ GSList *uri_config_list, *l, *uri_list = NULL;
+ ESourceList *source_list;
+ GConfClient *gconf_client;
+ gboolean published = FALSE;
+
+ gconf_client = gconf_client_get_default ();
+ source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/calendar/sources");
+
+ utc = icaltimezone_get_utc_timezone ();
+ start = time_day_begin_with_zone (start, utc);
+ end = time_add_week_with_zone (start, 6, utc);
+
+ uri_config_list = calendar_config_get_free_busy ();
+
+ for (l = uri_config_list; l != NULL; l = l->next) {
+ GSList *p =NULL;
+ EPublishUri *uri;
+ ECalComponent *clone = NULL;
+ gboolean cloned = FALSE;
+ ECal *client = NULL;
+ gchar *xml = (gchar *)uri_config_list->data;
+
+ uri = g_new0 (EPublishUri, 1);
+ e_pub_uri_from_xml (uri, xml);
+
+ /* kludge to safeguard against loop from gconf update */
+ if (just_published (uri->last_pub_time))
+ return;
+
+ /* TODO: make sure we're online */
+ /* skip this url if it isn't enabled or if it is manual */
+ if (!uri->enabled) {
+ uri_config_list = g_slist_next (uri_config_list);
+ continue;
+ }
+
+ if (!publish) {
+ /* a g_idle publish, make sure we are not set to user only */
+ if (uri->publish_freq == URI_PUBLISH_USER) {
+ uri_config_list = g_slist_next (uri_config_list);
+ continue;
+ }
+
+ /* If not is it time to publish again? */
+ publish = is_publish_time (uri);
+
+ }
+
+ /* User published or config change */
+ if (publish) {
+ /* We still need to set the last_pub_time */
+ uri->last_pub_time = 0;
+ is_publish_time (uri);
+
+ for (p = uri->calendars; p != NULL; p = p->next) {
+ GList *comp_list = NULL;
+ gchar *source_uid;
+ ESource * source;
+
+ source_uid = g_strdup (p->data);
+ source = e_source_list_peek_source_by_uid (source_list, source_uid);
+
+ client = auth_new_cal_from_uri (e_source_get_uri (source), E_CAL_SOURCE_TYPE_EVENT);
+
+ if (!client) {
+ g_warning (G_STRLOC ": Could not publish Free/Busy: Calendar backend no longer exists");
+
+ continue;
+ }
+
+ e_cal_open (client, TRUE, NULL);
+
+ if (e_cal_get_free_busy ((ECal *) client, NULL,
+ start, end,
+ &comp_list, NULL)) {
+ GList *l;
+
+ for (l = comp_list; l; l = l->next) {
+ ECalComponent *comp = E_CAL_COMPONENT (l->data);
+
+ cloned = itip_publish_begin (comp, (ECal *) client, cloned, &clone);
+ g_object_unref (comp);
+ }
+ g_list_free (comp_list);
+ }
+
+ g_object_unref (client);
+
+ g_free (source_uid);
+ }
+
+ published = itip_publish_comp ((ECal *) client,
+ uri->location,
+ uri->username,
+ uri->password, &clone);
+
+ g_slist_free (p);
+ }
+ xml = e_pub_uri_to_xml (uri);
+ if (xml != NULL) {
+ uri_list = g_slist_append (uri_list, xml);
+ }
+ g_free (uri);
+ }
+
+ if (published) {
+ /* Update gconf so we have the last_pub_time */
+ calendar_config_set_free_busy (uri_list);
+ }
+
+ g_slist_free (uri_config_list);
+ g_slist_free (uri_list);
+}