aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs
diff options
context:
space:
mode:
authorJP Rosevear <jpr@helixcode.com>2000-08-28 09:50:39 +0800
committerJP Rosevear <jpr@src.gnome.org>2000-08-28 09:50:39 +0800
commit27084dc009197c71bd4162dc26b9f821ebf4863d (patch)
tree6ecad514dfab51777ab6981266629d5300e6299a /calendar/pcs
parent2831015fa1dafabf1246755513c18df4101d3414 (diff)
downloadgsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar.gz
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar.bz2
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar.lz
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar.xz
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.tar.zst
gsoc2013-evolution-27084dc009197c71bd4162dc26b9f821ebf4863d.zip
Write out the calendar object (cal_backend_file_update_object): Remove/add
2000-08-27 JP Rosevear <jpr@helixcode.com> * pcs/cal-backend-file.c (save): Write out the calendar object (cal_backend_file_update_object): Remove/add the icalcomponent from our master icalcomponent (the calendar) (cal_backend_file_remove_object): Remove the icalcomponent from our master icalcomponent svn path=/trunk/; revision=5069
Diffstat (limited to 'calendar/pcs')
-rw-r--r--calendar/pcs/cal-backend-file.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index 5e74689095..6747280f38 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -178,16 +178,45 @@ static void
save (CalBackendFile *cbfile)
{
CalBackendFilePrivate *priv;
-
+ GnomeVFSHandle *handle = NULL;
+ GnomeVFSResult result;
+ GnomeVFSFileSize out;
+ GnomeVFSURI *backup_uri;
+ char *buf;
+
priv = cbfile->priv;
g_assert (priv->uri != NULL);
g_assert (priv->icalcomp != NULL);
- /* FIXME */
-
- /* FIXME: ensure we have the mandatory PRODID and VERSION properties, and throw
- * in CALSCALE for good measure.
- */
+ /* Make a backup copy of the file */
+ backup_uri = gnome_vfs_uri_append_file_name (priv->uri, "~");
+ result = gnome_vfs_move_uri (priv->uri, backup_uri, TRUE);
+ gnome_vfs_uri_unref (backup_uri);
+
+// if (result != GNOME_VFS_OK)
+// goto error;
+
+ /* Now write the new file out */
+ result = gnome_vfs_create_uri (&handle, priv->uri,
+ GNOME_VFS_OPEN_WRITE,
+ FALSE, 0666);
+
+ if (result != GNOME_VFS_OK)
+ goto error;
+
+ buf = icalcomponent_as_ical_string (priv->icalcomp);
+ result = gnome_vfs_write (handle, buf, strlen (buf) * sizeof (char), &out);
+
+ if (result != GNOME_VFS_OK)
+ goto error;
+
+ gnome_vfs_close (handle);
+
+ return;
+
+ error:
+ g_warning ("Error writing calendar file.");
+ return;
}
/* Destroy handler for the file backend */
@@ -440,7 +469,6 @@ add_component (CalBackendFile *cbfile, CalComponent *comp)
/* Ensure that the UID is unique; some broken implementations spit
* components with duplicated UIDs.
*/
-
check_dup_uid (cbfile, comp);
cal_component_get_uid (comp, &uid);
@@ -922,7 +950,7 @@ cal_backend_file_update_object (CalBackend *backend, const char *uid, const char
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
- icalcomponent *icalcomp;
+ icalcomponent *icalcomp, *icalcomp2;
icalcomponent_kind kind;
CalComponent *old_comp;
CalComponent *comp;
@@ -973,8 +1001,17 @@ cal_backend_file_update_object (CalBackend *backend, const char *uid, const char
old_comp = lookup_component (cbfile, uid);
- if (old_comp)
+ if (old_comp) {
+ /* Remove it from our calendar component */
+ icalcomp2 = cal_component_get_icalcomponent (old_comp);
+ icalcomponent_remove_component (priv->icalcomp, icalcomp2);
+
remove_component (cbfile, old_comp);
+ }
+
+ /* Add it to our calendar component */
+ icalcomp2 = cal_component_get_icalcomponent (comp);
+ icalcomponent_add_component (priv->icalcomp, icalcomp2);
add_component (cbfile, comp);
#if 0
@@ -997,6 +1034,7 @@ cal_backend_file_remove_object (CalBackend *backend, const char *uid)
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
CalComponent *comp;
+ icalcomponent *icalcomp;
cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
@@ -1009,6 +1047,10 @@ cal_backend_file_remove_object (CalBackend *backend, const char *uid)
if (!comp)
return FALSE;
+ /* Remove it from our calendar component */
+ icalcomp = cal_component_get_icalcomponent (comp);
+ icalcomponent_remove_component (priv->icalcomp, icalcomp);
+
remove_component (cbfile, comp);
mark_dirty (cbfile);