[evolution/kill-bonobo] Handle calendar URIs from the command line.



commit f2b2d42471dc6a820c94f8888bd4f13a5c00a530
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Aug 24 21:29:25 2009 -0400

    Handle calendar URIs from the command line.

 calendar/gui/gnome-cal.c                    |   38 -------
 calendar/gui/gnome-cal.h                    |    6 -
 modules/calendar/e-cal-shell-backend.c      |  151 ++++++++++++++++++++++++++-
 modules/calendar/e-cal-shell-view-private.c |    2 +-
 modules/calendar/e-task-shell-backend.c     |    2 +-
 5 files changed, 151 insertions(+), 48 deletions(-)
---
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 7f2328f..2fa1a38 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -2624,41 +2624,3 @@ gnome_calendar_purge (GnomeCalendar *gcal, time_t older_than)
 	g_free (end);
 
 }
-
-void
-gnome_calendar_edit_appointment (GnomeCalendar *gcal,
-				 const gchar * src_uid,
-				 const gchar * comp_uid,
-				 const gchar * comp_rid)
-{
-	ECal *client = NULL;
-	GList *l;
-	icalcomponent* icalcomp = NULL;
-	icalproperty *attendee_prop = NULL;
-
-	if (!src_uid || !comp_uid)
-		return;
-
-	for (l = gcal->priv->clients_list; l != NULL; l = l->next) {
-		ESource *client_src;
-
-		client = l->data;
-		client_src = e_cal_get_source (client);
-
-		if (!strcmp (src_uid, e_source_peek_uid (client_src)))
-			break;
-	}
-
-	if (!client)
-		return;
-
-	e_cal_get_object (client, comp_uid, comp_rid, &icalcomp, NULL);
-
-	if (!icalcomp)
-		return;
-
-	attendee_prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTENDEE_PROPERTY);
-	e_calendar_view_edit_appointment (gcal->priv->views[gcal->priv->current_view_type],
-					  client, icalcomp, attendee_prop ? TRUE:FALSE);
-	icalcomponent_free (icalcomp);
-}
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index 2b7eac8..0cc528f 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -184,12 +184,6 @@ gint		gnome_calendar_get_num_events_selected
 void		gnome_calendar_purge		(GnomeCalendar  *gcal,
 						 time_t older_than);
 
-/* Direct calendar component operations */
-void		gnome_calendar_edit_appointment	(GnomeCalendar *gcal,
-						 const gchar * src_uid,
-						 const gchar * comp_uid,
-						 const gchar * comp_rid);
-
 G_END_DECLS
 
 #endif
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index 145bff6..6d9c744 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <libecal/e-cal.h>
+#include <libecal/e-cal-time-util.h>
 #include <libedataserver/e-url.h>
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-source-group.h>
@@ -552,8 +553,154 @@ static gboolean
 cal_shell_backend_handle_uri_cb (EShellBackend *shell_backend,
                                  const gchar *uri)
 {
-	/* FIXME */
-	return FALSE;
+	EShell *shell;
+	CompEditor *editor;
+	CompEditorFlags flags = 0;
+	ECal *client;
+	ECalComponent *comp;
+	ESource *source;
+	ESourceList *source_list;
+	ECalSourceType source_type;
+	EUri *euri;
+	icalcomponent *icalcomp;
+	icalproperty *icalprop;
+	const gchar *cp;
+	gchar *source_uid = NULL;
+	gchar *comp_uid = NULL;
+	gchar *comp_rid = NULL;
+	time_t startdate = -1;
+	time_t enddate = -1;
+	gboolean handled = FALSE;
+	GError *error = NULL;
+
+	source_type = E_CAL_SOURCE_TYPE_EVENT;
+	shell = e_shell_backend_get_shell (shell_backend);
+
+	if (strncmp (uri, "calendar:", 9) != 0)
+		return FALSE;
+
+	euri = e_uri_new (uri);
+	cp = euri->query;
+	if (cp == NULL)
+		goto exit;
+
+	while (*cp != '\0') {
+		gchar *header;
+		gchar *content;
+		gsize header_len;
+		gsize content_len;
+
+		header_len = strcspn (cp, "=&");
+
+		/* It it's malformed, give up. */
+		if (cp[header_len] != '=')
+			break;
+
+		header = (gchar *) cp;
+		header[header_len] = '\0';
+		cp += header_len + 1;
+
+		content_len = strcspn (cp, "&");
+
+		content = g_strndup (cp, content_len);
+		if (g_ascii_strcasecmp (header, "startdate") == 0)
+			startdate = time_from_isodate (content);
+		else if (g_ascii_strcasecmp (header, "enddate") == 0)
+			enddate = time_from_isodate (content);
+		else if (g_ascii_strcasecmp (header, "source-uid") == 0)
+			source_uid = g_strdup (content);
+		else if (g_ascii_strcasecmp (header, "comp-uid") == 0)
+			comp_uid = g_strdup (content);
+		else if (g_ascii_strcasecmp (header, "comp-rid") == 0)
+			comp_rid = g_strdup (content);
+		g_free (content);
+
+		cp += content_len;
+		if (*cp == '&') {
+			cp++;
+			if (strcmp (cp, "amp;") == 0)
+				cp += 4;
+		}
+	}
+
+	if (source_uid == NULL || comp_uid == NULL)
+		goto exit;
+
+	/* URI is valid, so consider it handled.  Whether
+	 * we successfully open it is another matter... */
+	handled = TRUE;
+
+	if (!e_cal_get_sources (&source_list, source_type, NULL)) {
+		g_printerr ("Could not get calendar sources from GConf!\n");
+		goto exit;
+	}
+
+	source = e_source_list_peek_source_by_uid (source_list, source_uid);
+	if (source == NULL) {
+		g_printerr ("No source for UID `%s'\n", source_uid);
+		g_object_unref (source_list);
+		goto exit;
+	}
+
+	client = auth_new_cal_from_source (source, source_type);
+	if (client == NULL || !e_cal_open (client, TRUE, &error)) {
+		g_printerr ("%s\n", error->message);
+		g_object_unref (source_list);
+		g_error_free (error);
+		goto exit;
+	}
+
+	/* XXX Copied from e_cal_shell_view_open_event().
+	 *     Clearly a new utility function is needed. */
+
+	editor = comp_editor_find_instance (comp_uid);
+
+	if (editor != NULL)
+		goto present;
+
+	if (!e_cal_get_object (client, comp_uid, comp_rid, &icalcomp, &error)) {
+		g_printerr ("%s\n", error->message);
+		g_object_unref (source_list);
+		g_error_free (error);
+		goto exit;
+	}
+
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomp);
+
+	icalprop = icalcomponent_get_first_property (
+		icalcomp, ICAL_ATTENDEE_PROPERTY);
+	if (icalprop != NULL)
+		flags |= COMP_EDITOR_MEETING;
+
+	if (itip_organizer_is_user (comp, client))
+		flags |= COMP_EDITOR_USER_ORG;
+
+	if (itip_sentby_is_user (comp, client))
+		flags |= COMP_EDITOR_USER_ORG;
+
+	if (!e_cal_component_has_attendees (comp))
+		flags |= COMP_EDITOR_USER_ORG;
+
+	editor = event_editor_new (client, shell, flags);
+	comp_editor_edit_comp (editor, comp);
+
+	g_object_unref (comp);
+
+present:
+	gtk_window_present (GTK_WINDOW (editor));
+
+	g_object_unref (source_list);
+	g_object_unref (client);
+
+exit:
+	g_free (source_uid);
+	g_free (comp_uid);
+	g_free (comp_rid);
+
+	e_uri_free (euri);
+
+	return handled;
 }
 
 static void
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index d677131..6601228 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -780,7 +780,7 @@ e_cal_shell_view_open_event (ECalShellView *cal_shell_view,
 	editor = event_editor_new (comp_data->client, shell, flags);
 	comp_editor_edit_comp (editor, comp);
 
-	g_object_ref (comp);
+	g_object_unref (comp);
 
 exit:
 	gtk_window_present (GTK_WINDOW (editor));
diff --git a/modules/calendar/e-task-shell-backend.c b/modules/calendar/e-task-shell-backend.c
index 23d5e35..500dd30 100644
--- a/modules/calendar/e-task-shell-backend.c
+++ b/modules/calendar/e-task-shell-backend.c
@@ -430,7 +430,7 @@ task_module_handle_uri_cb (EShellBackend *shell_backend,
 		}
 	}
 
-	if (source_uid != NULL || comp_uid != NULL)
+	if (source_uid == NULL || comp_uid == NULL)
 		goto exit;
 
 	/* URI is valid, so consider it handled.  Whether



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]