aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs/cal-backend-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/pcs/cal-backend-file.c')
-rw-r--r--calendar/pcs/cal-backend-file.c63
1 files changed, 54 insertions, 9 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index c60c0c118a..5b03150001 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -44,6 +44,13 @@ struct _CalBackendFilePrivate {
*/
GHashTable *comp_uid_hash;
+ /* All the uids in the calendar, hashed by pilot ID. The
+ * hash key *is* the pilot id returned by cal_component_get_pilot_id();
+ * it is not copied, so don't free it when you remove an object from
+ * the hash table.
+ */
+ GHashTable *comp_pilot_hash;
+
/* All event, to-do, and journal components in the calendar; they are
* here just for easy access (i.e. so that you don't have to iterate
* over the comp_uid_hash). If you need *all* the components in the
@@ -173,6 +180,20 @@ 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)
@@ -250,11 +271,17 @@ cal_backend_file_destroy (GtkObject *object)
}
if (priv->comp_uid_hash) {
- g_hash_table_foreach (priv->comp_uid_hash, free_cal_component, NULL);
+ g_hash_table_foreach (priv->comp_uid_hash,
+ free_cal_component, NULL);
g_hash_table_destroy (priv->comp_uid_hash);
priv->comp_uid_hash = NULL;
}
+ if (priv->comp_pilot_hash) {
+ g_hash_table_destroy (priv->comp_pilot_hash);
+ priv->comp_pilot_hash = NULL;
+ }
+
g_list_free (priv->events);
g_list_free (priv->todos);
g_list_free (priv->journals);
@@ -445,7 +472,8 @@ add_component (CalBackendFile *cbfile, CalComponent *comp, gboolean add_to_tople
CalBackendFilePrivate *priv;
GList **list;
const char *uid;
-
+ unsigned long *pilot_id;
+
priv = cbfile->priv;
switch (cal_component_get_vtype (comp)) {
@@ -471,8 +499,14 @@ add_component (CalBackendFile *cbfile, CalComponent *comp, gboolean add_to_tople
*/
check_dup_uid (cbfile, comp);
cal_component_get_uid (comp, &uid);
-
g_hash_table_insert (priv->comp_uid_hash, (char *) uid, comp);
+
+ /* Update the pilot list, if there is a pilot id */
+ cal_component_get_pilot_id (comp, &pilot_id);
+ if (pilot_id)
+ g_hash_table_insert (priv->comp_pilot_hash,
+ pilot_id, (char *)uid);
+
*list = g_list_prepend (*list, comp);
/* Put the object in the toplevel component if required */
@@ -497,6 +531,7 @@ remove_component (CalBackendFile *cbfile, CalComponent *comp)
CalBackendFilePrivate *priv;
icalcomponent *icalcomp;
const char *uid;
+ unsigned long *pilot_id;
GList **list, *l;
priv = cbfile->priv;
@@ -511,8 +546,10 @@ remove_component (CalBackendFile *cbfile, CalComponent *comp)
/* Remove it from our mapping */
cal_component_get_uid (comp, &uid);
+ cal_component_get_pilot_id (comp, &pilot_id);
g_hash_table_remove (priv->comp_uid_hash, uid);
-
+ g_hash_table_remove (priv->comp_pilot_hash, pilot_id);
+
switch (cal_component_get_vtype (comp)) {
case CAL_COMPONENT_EVENT:
list = &priv->events;
@@ -642,6 +679,7 @@ 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);
scan_vcalendar (cbfile);
/* Clean up */
@@ -687,6 +725,7 @@ 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);
/* Done */
@@ -1074,14 +1113,14 @@ cal_backend_file_get_uid_by_pilot_id (CalBackend *backend, unsigned long int pil
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
+ char *uid;
cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
- g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
+ uid = g_hash_table_lookup (priv->comp_pilot_hash, &pilot_id);
- /* FIXME */
- return NULL;
+ return uid;
}
/* Update_pilot_id handler for the file backend */
@@ -1093,13 +1132,19 @@ cal_backend_file_update_pilot_id (CalBackend *backend,
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
+ CalComponent *comp;
cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
g_return_if_fail (priv->icalcomp != NULL);
-
g_return_if_fail (uid != NULL);
- /* FIXME */
+ comp = lookup_component (cbfile, uid);
+ if (!comp)
+ return;
+
+ cal_component_set_pilot_id (comp, &pilot_id);
+ cal_component_set_pilot_status (comp, &pilot_status);
}
+