aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog19
-rw-r--r--calendar/pcs/cal-backend-file.c66
-rw-r--r--calendar/pcs/cal-backend.c56
3 files changed, 89 insertions, 52 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 5dd236f207..f20670f57c 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,5 +1,24 @@
2000-09-19 JP Rosevear <jpr@helixcode.com>
+ * pcs/cal-backend.c (cal_backend_set_uri): New utility function
+ (cal_backend_load): use above
+ (cal_backend_create): use above
+ (cal_backend_log_name): Take a uri instead of a backend param
+
+ * pcs/cal-backend-file.c: Get rid of useless hash functions
+ (cal_backend_file_load): Check to make sure path exists and is
+ local
+ (cal_backend_file_load): Unref the current uri if there is one
+ (cal_backend_file_create): ditto
+
+ * pcs/cal-backend.c (cal_backend_last_client_gone): Sync before
+ shooting ourselves in the foot
+
+ * pcs/cal-backend-file.c (save): Fully implement backing up the
+ calendar before writing out the new entry.
+
+2000-09-19 JP Rosevear <jpr@helixcode.com>
+
* conduits/todo/todo-conduit.c (check_for_slow_setting): Add some
other cases where a slow sync is in order
(pre_sync): Pre load the uids, the map and the add/mod/del lists
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index c4a047a262..959224db6a 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -182,20 +182,6 @@ free_cal_component (gpointer key, gpointer value, gpointer data)
gtk_object_unref (GTK_OBJECT (comp));
}
-/* For hashing pilot id's */
-/* FIX ME, these are not unique */
-static guint
-cbf_pilot_hash (gconstpointer v)
-{
- return *(const guint*) v;
-}
-
-static gint
-cbf_pilot_equal (gconstpointer v1, gconstpointer v2)
-{
- return *((const unsigned long*) v1) == *((const unsigned long*) v2);
-}
-
/* Saves the calendar data */
static void
save (CalBackendFile *cbfile)
@@ -204,20 +190,36 @@ save (CalBackendFile *cbfile)
GnomeVFSHandle *handle = NULL;
GnomeVFSResult result;
GnomeVFSFileSize out;
- GnomeVFSURI *backup_uri;
+ gchar *tmp;
char *buf;
priv = cbfile->priv;
g_assert (priv->uri != NULL);
g_assert (priv->icalcomp != NULL);
- /* 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);
+ /* Make a backup copy of the file if it exists */
+ if (gnome_vfs_uri_exists (priv->uri)) {
+ tmp = gnome_vfs_uri_to_string (priv->uri, GNOME_VFS_URI_HIDE_NONE);
+ if (tmp) {
+ GnomeVFSURI *backup_uri;
+ gchar *backup_uristr;
+
+ backup_uristr = g_strconcat (tmp, "~", NULL);
+ backup_uri = gnome_vfs_uri_new (backup_uristr);
+
+ result = gnome_vfs_move_uri (priv->uri, backup_uri, TRUE);
+ gnome_vfs_uri_unref (backup_uri);
+
+ g_free (tmp);
+ g_free (backup_uristr);
+ }
+ } else {
+ result = GNOME_VFS_OK;
+ }
+
-// if (result != GNOME_VFS_OK)
-// goto error;
+ if (result != GNOME_VFS_OK)
+ goto error;
/* Now write the new file out */
result = gnome_vfs_create_uri (&handle, priv->uri,
@@ -642,9 +644,11 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri)
g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_LOAD_ERROR);
g_return_val_if_fail (uri != NULL, CAL_BACKEND_LOAD_ERROR);
- /* FIXME: this looks rather bad; maybe we should check for local files
- * and fail if they are remote.
- */
+ if (!gnome_vfs_uri_is_local (uri))
+ return CAL_BACKEND_LOAD_ERROR;
+
+ if (!gnome_vfs_uri_exists (uri))
+ return CAL_BACKEND_LOAD_ERROR;;
str_uri = gnome_vfs_uri_to_string (uri,
(GNOME_VFS_URI_HIDE_USER_NAME
@@ -654,7 +658,6 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri)
| GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
/* Load! */
-
file = fopen (str_uri, "r");
g_free (str_uri);
@@ -683,12 +686,13 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri)
priv->icalcomp = icalcomp;
priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
-/* priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); */
priv->comp_pilot_hash = g_hash_table_new (g_int_hash, g_int_equal);
scan_vcalendar (cbfile);
/* Clean up */
-
+ if (priv->uri)
+ gnome_vfs_uri_unref (uri);
+
gnome_vfs_uri_ref (uri);
priv->uri = uri;
@@ -730,13 +734,13 @@ cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri)
g_assert (priv->comp_uid_hash == NULL);
priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
-/* priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); */
priv->comp_pilot_hash = g_hash_table_new (g_int_hash, g_int_equal);
- /* Done */
-
+ /* Clean up */
+ if (priv->uri)
+ gnome_vfs_uri_unref (priv->uri);
+
gnome_vfs_uri_ref (uri);
-
priv->uri = uri;
mark_dirty (cbfile);
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
index 3c7698a4d5..f02b18a0ef 100644
--- a/calendar/pcs/cal-backend.c
+++ b/calendar/pcs/cal-backend.c
@@ -135,6 +135,23 @@ cal_backend_get_uri (CalBackend *backend)
return (* CLASS (backend)->get_uri) (backend);
}
+static void
+cal_backend_set_uri (CalBackend *backend, GnomeVFSURI *uri)
+{
+ if (backend->uri)
+ gnome_vfs_uri_unref (backend->uri);
+
+ if (backend->timer)
+ gtk_timeout_remove (backend->timer);
+
+
+ gnome_vfs_uri_ref (uri);
+ backend->uri = uri;
+ backend->timer = gtk_timeout_add (60000,
+ (GtkFunction)cal_backend_log_sync,
+ backend);
+}
+
/**
* cal_backend_add_cal:
* @backend: A calendar backend.
@@ -177,20 +194,9 @@ cal_backend_load (CalBackend *backend, GnomeVFSURI *uri)
/* Remember the URI for saving the log file in the same dir and add
* a timeout handler so for saving pending entries sometimes */
- if (backend->uri)
- gnome_vfs_uri_unref (backend->uri);
-
- if (backend->timer)
- gtk_timeout_remove (backend->timer);
-
- if (result == CAL_BACKEND_LOAD_SUCCESS) {
- backend->uri = uri;
- gnome_vfs_uri_ref (uri);
- backend->timer = gtk_timeout_add (60000,
- (GtkFunction)cal_backend_log_sync,
- backend);
- }
-
+ if (result == CAL_BACKEND_LOAD_SUCCESS)
+ cal_backend_set_uri (backend, uri);
+
return result;
}
@@ -210,6 +216,10 @@ cal_backend_create (CalBackend *backend, GnomeVFSURI *uri)
g_assert (CLASS (backend)->create != NULL);
(* CLASS (backend)->create) (backend, uri);
+
+ /* Remember the URI for saving the log file in the same dir and add
+ * a timeout handler so for saving pending entries sometimes */
+ cal_backend_set_uri (backend, uri);
}
/**
@@ -435,11 +445,11 @@ typedef struct {
} CalBackendParseState;
static gchar *
-cal_backend_log_name (CalBackend *backend)
+cal_backend_log_name (GnomeVFSURI *uri)
{
gchar *path, *filename;
- path = gnome_vfs_uri_extract_dirname (backend->uri);
+ path = gnome_vfs_uri_extract_dirname (uri);
filename = g_strdup_printf ("%slog.xml", path);
g_free (path);
@@ -489,11 +499,13 @@ cal_backend_log_sync (CalBackend *backend)
int ret;
time_t start_time = (time_t) - 1;
+ g_return_val_if_fail (backend->uri != NULL, FALSE);
+
if (backend->entries == NULL)
return TRUE;
- filename = cal_backend_log_name (backend);
-
+ filename = cal_backend_log_name (backend->uri);
+
doc = xmlParseFile (filename);
if (doc == NULL) {
/* Create the document */
@@ -632,8 +644,10 @@ cal_backend_log_sax_parse (CalBackend *backend, xmlSAXHandler *handler,
int ret = 0;
xmlParserCtxtPtr ctxt;
char *filename;
+
+ g_return_val_if_fail (backend->uri != NULL, -1);
- filename = cal_backend_log_name (backend);
+ filename = cal_backend_log_name (backend->uri);
if (!g_file_exists (filename))
return 0;
@@ -763,9 +777,9 @@ cal_backend_last_client_gone (CalBackend *backend)
g_return_if_fail (backend != NULL);
g_return_if_fail (IS_CAL_BACKEND (backend));
- gtk_signal_emit (GTK_OBJECT (backend), cal_backend_signals[LAST_CLIENT_GONE]);
-
cal_backend_log_sync (backend);
+
+ gtk_signal_emit (GTK_OBJECT (backend), cal_backend_signals[LAST_CLIENT_GONE]);
}