[evolution-patches] patch for #57567 (calendar)



This should probably be committed to the 2.0 branch. Already committed
to HEAD.
-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.380
diff -u -p -r1.380 ChangeLog
--- ChangeLog	17 Jan 2005 11:08:30 -0000	1.380
+++ ChangeLog	17 Jan 2005 11:52:56 -0000
@@ -1,5 +1,15 @@
 2005-01-17  Rodrigo Moya <rodrigo novell com>
 
+	* backends/file/e-cal-backend-file.c (save_file_when_idle): new
+	function, to save the file to disk at application's idle times.
+	(save): changed to just set the idle callback the first time and then,
+	just mark the file as dirty.
+	(e_cal_backend_file_finalize): remove the idle callback.
+	(e_cal_backend_file_dispose): save the file if dirty.
+	(e_cal_backend_file_init): initialize new members.
+
+2005-01-17  Rodrigo Moya <rodrigo novell com>
+
 	* libecal/e-cal-view.c (e_cal_view_set_property): make sure we clean
 	up the old view and listener before setting the new ones.
 
Index: backends/file/e-cal-backend-file.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/file/e-cal-backend-file.c,v
retrieving revision 1.41
diff -u -p -r1.41 e-cal-backend-file.c
--- backends/file/e-cal-backend-file.c	10 Jan 2005 21:26:01 -0000	1.41
+++ backends/file/e-cal-backend-file.c	17 Jan 2005 11:52:56 -0000
@@ -58,6 +58,8 @@ struct _ECalBackendFilePrivate {
 	/* Filename in the dir */
 	char *file_name;	
 	gboolean read_only;
+	gboolean is_dirty;
+	gint dirty_idle_id;
 
 	/* Toplevel VCALENDAR component */
 	icalcomponent *icalcomp;
@@ -104,8 +106,8 @@ free_object (gpointer key, gpointer valu
 }
 
 /* Saves the calendar data */
-static void
-save (ECalBackendFile *cbfile)
+static gboolean
+save_file_when_idle (gpointer user_data)
 {
 	ECalBackendFilePrivate *priv;
 	GnomeVFSURI *uri, *backup_uri;
@@ -114,6 +116,7 @@ save (ECalBackendFile *cbfile)
 	GnomeVFSFileSize out;
 	gchar *tmp, *backup_uristr;
 	char *buf;
+	ECalBackendFile *cbfile = user_data;
 	
 	priv = cbfile->priv;
 	g_assert (priv->uri != NULL);
@@ -167,16 +170,32 @@ save (ECalBackendFile *cbfile)
 	if (result != GNOME_VFS_OK)
 		goto error;
 
-	return;
+	priv->is_dirty = FALSE;
+
+	return TRUE;
 
  error_malformed_uri:
 	e_cal_backend_notify_error (E_CAL_BACKEND (cbfile),
 				  _("Can't save calendar data: Malformed URI."));
-	return;
+	return TRUE;
 
  error:
 	e_cal_backend_notify_error (E_CAL_BACKEND (cbfile), gnome_vfs_result_to_string (result));
-	return;
+	return TRUE;
+}
+
+static void
+save (ECalBackendFile *cbfile)
+{
+	ECalBackendFilePrivate *priv;
+
+	priv = cbfile->priv;
+
+	if (!priv->dirty_idle_id) {
+		priv->dirty_idle_id = g_idle_add ((GSourceFunc) save_file_when_idle, cbfile);
+	}
+
+	priv->is_dirty = TRUE;
 }
 
 static void
@@ -218,6 +237,8 @@ e_cal_backend_file_dispose (GObject *obj
 	priv = cbfile->priv;
 
 	/* Save if necessary */
+	if (priv->is_dirty)
+		save_file_when_idle (cbfile);
 
 	free_calendar_data (cbfile);
 
@@ -240,6 +261,11 @@ e_cal_backend_file_finalize (GObject *ob
 
 	/* Clean up */
 
+	if (priv->dirty_idle_id) {
+		g_source_remove (priv->dirty_idle_id);
+		priv->dirty_idle_id = 0;
+	}
+
 	if (priv->uri) {
 	        g_free (priv->uri);
 		priv->uri = NULL;
@@ -2400,6 +2426,8 @@ e_cal_backend_file_init (ECalBackendFile
 	priv->uri = NULL;
 	priv->file_name = g_strdup ("calendar.ics");
 	priv->read_only = FALSE;
+	priv->is_dirty = FALSE;
+	priv->dirty_idle_id = 0;
 	priv->icalcomp = NULL;
 	priv->comp_uid_hash = NULL;
 	priv->comp = NULL;


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