[evolution-patches] Re: Save-calendar plugin: corrected GTK_STOCK_SAVE_AS behavior and support for comma seperated files



Heh .. I forgot to attach the patch itself.

On Wed, 2004-11-24 at 10:49 +0100, Philip Van Hoof wrote:
> Hi there,
> 
> This patch corrects the dialogs behavior to a GTK_STOCK_SAVE_AS. Notice
> the title-change!
> 
> The issue is that the e_cal_new_from_uri () will create a directory. The
> old title didn't tell the user about that. it simply stated: "Select
> destination file". It will not be created as only a file. Rather a
> directory with a file in it.
> 
> I've also added support for comma separated files as feature-requested
> by this GNOME Bounty: 
> 
> 	http://bugzilla.gnome.org/show_bug.cgi?id=127557
> 	http://www.gnome.org/bounties/Tasks.html#127557
> 
> This support was also in my previous save-calendar patches of 23 and 19
> November. 
> 
> This new patch proposes a few GtkDialog-title-changes. Review them
> first, of course.
> 
> ps. I've put the original authors as found in the ChangeLog in CC.
> 
> 
-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
gnome: pvanhoof at gnome dot org
work: philip dot vanhoof at cronos dot be
junk: philip dot vanhoof at gmail dot com
http://www.freax.be, http://www.freax.eu.org
Index: org-gnome-save-calendar.eplug.in
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/org-gnome-save-calendar.eplug.in,v
retrieving revision 1.4
diff -u -r1.4 org-gnome-save-calendar.eplug.in
--- org-gnome-save-calendar.eplug.in	21 Oct 2004 01:32:26 -0000	1.4
+++ org-gnome-save-calendar.eplug.in	24 Nov 2004 09:38:05 -0000
@@ -1,14 +1,27 @@
 <e-plugin-list>
 	<e-plugin id="org.gnome.evolution.save_calendar" type="shlib" name="Save Selected Calendar or Tasks List" description="Saves selected calendar or tasks list to disk"
 		location="@PLUGINDIR@/liborg-gnome-save-calendar.so">
-	
 		<hook class="org.gnome.evolution.calendar.popup:1.0">
-			<menu id="org.gnome.evolution.tasks.source.popup" target="source">
-				<item type="item" path="19.save_tasks" label="Save to _Disk" icon="stock_save" activate="org_gnome_save_tasks"/>
-			</menu>
-			<menu id="org.gnome.evolution.calendar.source.popup" target="source">
-				<item type="item" path="19.save_calendar" label="Save to _Disk" icon="stock_save" activate="org_gnome_save_calendar"/>
-			</menu>
+				<menu id="org.gnome.evolution.tasks.source.popup" target="source">
+					<item type="submenu" path="19.save" visible="mailing_list" activate="org_gnome_popup" icon="stock_save" label="Save to _Disk..."/>
+				</menu>
+				<menu id="org.gnome.evolution.calendar.source.popup" target="source">
+					<item type="submenu" path="19.save" visible="mailing_list" activate="org_gnome_popup" icon="stock_save" label="Save to _Disk..."/>
+				</menu>
+				<menu id="org.gnome.evolution.tasks.source.popup" target="source">
+					<item type="item" path="19.save/00.save_tasks_ical" label="iCalendar format" icon="stock_save" activate="org_gnome_save_tasks_ical"/>
+				</menu>
+
+				<menu id="org.gnome.evolution.calendar.source.popup" target="source">
+					<item type="item" path="19.save/10.save_calendar_ical" label="iCalendar format" icon="stock_save" activate="org_gnome_save_calendar_ical"/>
+				</menu>
+				<menu id="org.gnome.evolution.tasks.source.popup" target="source">
+					<item type="item" path="19.save/00.save_tasks_csv" label="Comma separated" icon="stock_save" activate="org_gnome_save_tasks_csv"/>
+				</menu>
+				<menu id="org.gnome.evolution.calendar.source.popup" target="source">
+						<item type="item" path="19.save/10.save_calendar_csv" label="Comma separated" icon="stock_save" activate="org_gnome_save_calendar_csv"/>
+				</menu>
 		</hook>
+
 	</e-plugin>
-</e-plugin-list>
\ No newline at end of file
+</e-plugin-list>
Index: save-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/save-calendar.c,v
retrieving revision 1.3
diff -u -r1.3 save-calendar.c
--- save-calendar.c	21 Oct 2004 11:21:42 -0000	1.3
+++ save-calendar.c	24 Nov 2004 09:38:05 -0000
@@ -40,9 +40,14 @@
 #include <libedataserverui/e-source-selector.h>
 #include <libecal/e-cal.h>
 #include <calendar/gui/e-cal-popup.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <string.h>
 
-void org_gnome_save_calendar (EPlugin *ep, ECalPopupTargetSource *target);
-void org_gnome_save_tasks (EPlugin *ep, ECalPopupTargetSource *target);
+void org_gnome_save_calendar_ical (EPlugin *ep, ECalPopupTargetSource *target);
+void org_gnome_save_tasks_ical (EPlugin *ep, ECalPopupTargetSource *target);
+void org_gnome_save_calendar_csv (EPlugin *ep, ECalPopupTargetSource *target);
+void org_gnome_save_tasks_csv (EPlugin *ep, ECalPopupTargetSource *target);
+void org_gnome_popup (EPlugin *ep, ECalPopupTargetSource *target);
 
 static void
 display_error_message (GtkWidget *parent, GError *error)
@@ -55,8 +60,177 @@
 	gtk_widget_destroy (dialog);
 }
 
+
+/* Some helpers for the csv stuff */
+
+/* Turns a text-GSLis into a comma-separated, unquoted string (result should be freed) */
+static GString *
+gslist_to_csv (GSList *list_in)
+{
+	GSList *list = list_in;
+	GString *str = g_string_new ("");
+	while (list) {
+		str = g_string_append (str, (const char*)list->data);
+		list = g_slist_next (list);
+		if (list) str = g_string_append (str, ", ");
+	}
+	return str;
+}
+
+/* Returns an icaltimetype as a (localized) string (result should be freed) */
+static gchar *
+icaltimetype_to_gchar (icaltimetype *t)
+{
+	if (t) return g_strdup_printf (_("%2d/%2d/%4d %2d:%2d:%2d"), t->month, t->day, t->year, t->hour, t->minute, t->second);
+	else return g_strdup ("");
+}
+
 static void
-do_save_calendar (EPlugin *ep, ECalPopupTargetSource *target, ECalSourceType type)
+do_save_calendar_csv (EPlugin *ep, ECalPopupTargetSource *target, ECalSourceType type)
+{
+	ESource *primary_source;
+	char *dest_uri;
+	ECal *source_client;
+	GtkWidget *dialog;
+	GError *error = NULL;
+	GList *objects=NULL;
+	GnomeVFSResult result;
+	GnomeVFSHandle *handle;
+	GnomeVFSURI *uri;
+
+	primary_source = e_source_selector_peek_primary_selection (target->selector);
+
+	/* ask the user for destination file */
+#ifdef USE_GTKFILECHOOSER
+	dialog = gtk_file_chooser_dialog_new (_("Select destination CSV file"),
+					      NULL,
+					      GTK_FILE_CHOOSER_ACTION_SAVE,
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					      GTK_STOCK_SAVE_AS, GTK_RESPONSE_OK,
+					      NULL);
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+#else
+	dialog = gtk_file_selection_new (_("Select destination CSV file"));
+#endif
+
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) {
+		gtk_widget_destroy (dialog);
+		return;
+	}
+
+#ifdef USE_GTKFILECHOOSER
+	dest_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+#else
+	dest_uri = g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog)));
+#endif
+	gtk_widget_destroy (dialog);
+	if (!dest_uri)
+		return;
+
+	/* open source client */
+	source_client = e_cal_new (primary_source, type);
+	if (!e_cal_open (source_client, TRUE, &error)) {
+		display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
+		g_object_unref (source_client);
+		g_free (dest_uri);
+		g_error_free (error);
+		return;
+	}
+
+	uri = gnome_vfs_uri_new (dest_uri);
+	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+	if (result != GNOME_VFS_OK) {
+		gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
+		result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+	}
+
+	if (result == GNOME_VFS_OK && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
+		while (objects != NULL) {
+			const char *uid, *categories, *url;
+			GString *comment_list_str, *contact_list_str, *description_list_str, *attendee_list_str;
+			GSList *comment_list, *contact_list, *description_list, *attendee_list;
+			struct icaltimetype *completed, *created;
+			gchar *completed_gchar, *created_gchar, *dtend_gchar, *dtstart_gchar, *dtdue_gchar, *line=NULL;
+			ECalComponentDateTime dtend, dtstart, dtdue;
+			int *percent, *priority;
+			ECalComponentText summary; 
+			ECalComponent *comp = objects->data;
+
+			/* I don't know, the documentation told me to do this */
+			e_cal_component_commit_sequence (comp);
+
+			/* Question: In what format and what information do you (bounty-team)/we want this? */
+
+			/* Getting the stuff */
+			e_cal_component_get_uid (comp, &uid);
+			e_cal_component_get_categories (comp, &categories);
+			e_cal_component_get_comment_list (comp, &comment_list);
+			e_cal_component_get_completed (comp, &completed);
+			e_cal_component_get_contact_list (comp, &contact_list);
+			e_cal_component_get_created (comp, &created);
+			e_cal_component_get_description_list (comp, &description_list);
+			e_cal_component_get_dtend (comp, &dtend);
+			e_cal_component_get_dtstart (comp, &dtstart);
+			e_cal_component_get_due (comp, &dtdue);
+			e_cal_component_get_percent (comp, &percent);
+			e_cal_component_get_priority (comp, &priority);
+			e_cal_component_get_summary (comp, &summary);
+			e_cal_component_get_url (comp, &url);
+			e_cal_component_get_attendee_list (comp, &attendee_list);
+
+			/* Convertions */
+			dtend_gchar = icaltimetype_to_gchar (dtend.value);
+			dtstart_gchar = icaltimetype_to_gchar (dtstart.value);
+			dtdue_gchar = icaltimetype_to_gchar (dtdue.value);
+			completed_gchar = icaltimetype_to_gchar (completed);
+			created_gchar = icaltimetype_to_gchar (created);
+			comment_list_str = gslist_to_csv (comment_list);
+			contact_list_str = gslist_to_csv (contact_list);
+			description_list_str = gslist_to_csv (description_list);
+			attendee_list_str = gslist_to_csv (attendee_list);
+
+			/* Dump it as a CSV in the file */
+
+			line = g_strdup_printf (
+
+					"\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", "
+					"\"%s\", \"%s\", \"%s\", %d, %d, \"%s\", \"%s\", \"%s\"\n",
+
+					uid?uid:"", categories?categories:"", 
+					comment_list_str->str, completed_gchar, 
+					contact_list_str->str, created_gchar, 
+					description_list_str->str, dtend_gchar, 
+					dtstart_gchar, dtdue_gchar, 
+					percent?*percent:-1, priority?*priority:-1, 
+					summary.value?summary.value:"", url?url:"", 
+					attendee_list_str->str);
+
+			
+
+			/* Free memory for this record */
+			g_string_free (comment_list_str, TRUE);
+			g_string_free (contact_list_str, TRUE);
+			g_string_free (description_list_str, TRUE);
+			g_string_free (attendee_list_str, TRUE);
+			g_free (completed_gchar); g_free (created_gchar);
+			g_free (dtend_gchar); g_free (dtstart_gchar); 
+			g_free (dtdue_gchar);
+
+			gnome_vfs_write (handle, line, strlen (line), NULL);
+
+			g_free (line);
+
+			objects = g_list_next (objects);
+		}
+
+		gnome_vfs_close (handle);
+	}
+	g_object_unref (source_client);
+	g_free (dest_uri);
+}
+
+static void
+do_save_calendar_ical (EPlugin *ep, ECalPopupTargetSource *target, ECalSourceType type)
 {
 	ESource *primary_source;
 	char *dest_uri;
@@ -68,15 +242,15 @@
 
 	/* ask the user for destination file */
 #ifdef USE_GTKFILECHOOSER
-	dialog = gtk_file_chooser_dialog_new (_("Select destination file"),
+	dialog = gtk_file_chooser_dialog_new (_("Choose destination ical folder"),
 					      NULL,
 					      GTK_FILE_CHOOSER_ACTION_SAVE,
 					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					      GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+					      GTK_STOCK_SAVE_AS, GTK_RESPONSE_OK,
 					      NULL);
 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 #else
-	dialog = gtk_file_selection_new (_("Select destination file"));
+	dialog = gtk_file_selection_new (_("Choose destination ical folder"));
 #endif
 
 	if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) {
@@ -137,13 +311,31 @@
 }
 
 void
-org_gnome_save_calendar (EPlugin *ep, ECalPopupTargetSource *target)
+org_gnome_save_calendar_ical (EPlugin *ep, ECalPopupTargetSource *target)
+{
+	do_save_calendar_ical (ep, target, E_CAL_SOURCE_TYPE_EVENT);
+}
+
+void
+org_gnome_save_tasks_ical (EPlugin *ep, ECalPopupTargetSource *target)
 {
-	do_save_calendar (ep, target, E_CAL_SOURCE_TYPE_EVENT);
+	do_save_calendar_ical (ep, target, E_CAL_SOURCE_TYPE_TODO);
 }
 
 void
-org_gnome_save_tasks (EPlugin *ep, ECalPopupTargetSource *target)
+org_gnome_save_calendar_csv (EPlugin *ep, ECalPopupTargetSource *target)
+{
+	do_save_calendar_csv (ep, target, E_CAL_SOURCE_TYPE_EVENT);
+}
+
+void
+org_gnome_save_tasks_csv (EPlugin *ep, ECalPopupTargetSource *target)
+{
+	do_save_calendar_csv (ep, target, E_CAL_SOURCE_TYPE_TODO);
+}
+
+void org_gnome_popup (EPlugin *ep, ECalPopupTargetSource *target)
 {
-	do_save_calendar (ep, target, E_CAL_SOURCE_TYPE_TODO);
+	/* This one avoids an ugly WARNING if the activate-handler does not exist */
+	return;
 }


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