aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/pcs')
-rw-r--r--calendar/pcs/cal-backend-file.c102
-rw-r--r--calendar/pcs/cal-backend.c26
-rw-r--r--calendar/pcs/cal-backend.h9
-rw-r--r--calendar/pcs/cal.c120
4 files changed, 124 insertions, 133 deletions
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index f23024cec6..5e74689095 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -71,7 +71,8 @@ static void cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri);
static int cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type);
static char *cal_backend_file_get_object (CalBackend *backend, const char *uid);
static GList *cal_backend_file_get_uids (CalBackend *backend, CalObjType type);
-static GList *cal_backend_file_get_events_in_range (CalBackend *backend, time_t start, time_t end);
+static GList *cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
+ time_t start, time_t end);
static GList *cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t end);
static gboolean cal_backend_file_get_alarms_for_object (CalBackend *backend, const char *uid,
time_t start, time_t end,
@@ -143,7 +144,7 @@ cal_backend_file_class_init (CalBackendFileClass *class)
backend_class->get_n_objects = cal_backend_file_get_n_objects;
backend_class->get_object = cal_backend_file_get_object;
backend_class->get_uids = cal_backend_file_get_uids;
- backend_class->get_events_in_range = cal_backend_file_get_events_in_range;
+ backend_class->get_objects_in_range = cal_backend_file_get_objects_in_range;
backend_class->get_alarms_in_range = cal_backend_file_get_alarms_in_range;
backend_class->get_alarms_for_object = cal_backend_file_get_alarms_for_object;
backend_class->update_object = cal_backend_file_update_object;
@@ -740,64 +741,74 @@ cal_backend_file_get_uids (CalBackend *backend, CalObjType type)
return list;
}
-/* Allocates and fills in a new CalComponentInstance structure */
-static CalObjInstance *
-build_cal_obj_instance (CalComponent *comp, time_t start, time_t end)
+/* Callback used from cal_recur_generate_instances(); adds the component's UID
+ * to our hash table.
+ */
+static gboolean
+add_instance (CalComponent *comp, time_t start, time_t end, gpointer data)
{
- CalObjInstance *icoi;
+ GHashTable *uid_hash;
const char *uid;
+ const char *old_uid;
+
+ uid_hash = data;
+
+ /* We only care that the component's UID is listed in the hash table;
+ * that's why we only allow generation of one instance (i.e. return
+ * FALSE every time).
+ */
cal_component_get_uid (comp, &uid);
- icoi = g_new (CalObjInstance, 1);
- icoi->uid = g_strdup (uid);
- icoi->start = start;
- icoi->end = end;
+ old_uid = g_hash_table_lookup (uid_hash, uid);
+ if (old_uid)
+ return FALSE;
- return icoi;
+ g_hash_table_insert (uid_hash, (char *) uid, NULL);
+ return FALSE;
}
-/* Builds a list of event component instances. Used as a callback from
- * cal_recur_generate_instances().
+/* Populates a hash table with the UIDs of the components that occur or recur
+ * within a specific time range.
*/
-static gboolean
-build_event_list (CalComponent *comp, time_t start, time_t end, gpointer data)
+static void
+get_instances_in_range (GHashTable *uid_hash, GList *components, time_t start, time_t end)
{
- CalObjInstance *icoi;
- GList **l;
-
- l = data;
+ GList *l;
- icoi = build_cal_obj_instance (comp, start, end);
- *l = g_list_prepend (*l, icoi);
+ for (l = components; l; l = l->next) {
+ CalComponent *comp;
- return TRUE;
+ comp = CAL_COMPONENT (l->data);
+ cal_recur_generate_instances (comp, start, end, add_instance, uid_hash);
+ }
}
-/* Compares two CalObjInstance structures by their start times. Called from
- * g_list_sort().
- */
-static gint
-compare_instance_func (gconstpointer a, gconstpointer b)
+/* Used from g_hash_table_foreach(), adds a UID from the hash table to our list */
+static void
+add_uid_to_list (gpointer key, gpointer value, gpointer data)
{
- const CalObjInstance *ca, *cb;
- time_t diff;
+ GList **list;
+ const char *uid;
+ char *uid_copy;
- ca = a;
- cb = b;
+ list = data;
- diff = ca->start - cb->start;
- return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
+ uid = key;
+ uid_copy = g_strdup (uid);
+
+ *list = g_list_prepend (*list, uid_copy);
}
-/* Get_events_in_range handler for the file backend */
+/* Get_objects_in_range handler for the file backend */
static GList *
-cal_backend_file_get_events_in_range (CalBackend *backend, time_t start, time_t end)
+cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
+ time_t start, time_t end)
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
- GList *l;
GList *event_list;
+ GHashTable *uid_hash;
cbfile = CAL_BACKEND_FILE (backend);
priv = cbfile->priv;
@@ -807,16 +818,21 @@ cal_backend_file_get_events_in_range (CalBackend *backend, time_t start, time_t
g_return_val_if_fail (start != -1 && end != -1, NULL);
g_return_val_if_fail (start <= end, NULL);
- event_list = NULL;
+ uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
- for (l = priv->events; l; l = l->next) {
- CalComponent *comp;
+ if (type & CALOBJ_TYPE_EVENT)
+ get_instances_in_range (uid_hash, priv->events, start, end);
- comp = l->data;
- cal_recur_generate_instances (comp, start, end, build_event_list, &event_list);
- }
+ if (type & CALOBJ_TYPE_TODO)
+ get_instances_in_range (uid_hash, priv->todos, start, end);
+
+ if (type & CALOBJ_TYPE_JOURNAL)
+ get_instances_in_range (uid_hash, priv->journals, start, end);
+
+ event_list = NULL;
+ g_hash_table_foreach (uid_hash, add_uid_to_list, &event_list);
+ g_hash_table_destroy (uid_hash);
- event_list = g_list_sort (event_list, compare_instance_func);
return event_list;
}
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
index 97d09fac24..e33cedeae8 100644
--- a/calendar/pcs/cal-backend.c
+++ b/calendar/pcs/cal-backend.c
@@ -226,7 +226,8 @@ cal_backend_get_object (CalBackend *backend, const char *uid)
* Builds a list of unique identifiers corresponding to calendar objects whose
* type matches one of the types specified in the @type flags.
*
- * Return value: A list of strings that are the sought UIDs.
+ * Return value: A list of strings that are the sought UIDs. The list should be
+ * freed using the cal_obj_uid_list_free() function.
**/
GList *
cal_backend_get_uids (CalBackend *backend, CalObjType type)
@@ -239,28 +240,29 @@ cal_backend_get_uids (CalBackend *backend, CalObjType type)
}
/**
- * cal_backend_get_events_in_range:
+ * cal_backend_get_objects_in_range:
* @backend: A calendar backend.
+ * @type: Bitmask with types of objects to return.
* @start: Start time for query.
* @end: End time for query.
- *
- * Builds a sorted list of calendar event object instances that occur or recur
- * within the specified time range. Each object instance contains the object
- * itself and the start/end times at which it occurs or recurs.
- *
- * Return value: A list of calendar event object instances, sorted by their
- * start times.
+ *
+ * Builds a list of unique identifiers corresponding to calendar objects of the
+ * specified type that occur or recur within the specified time range.
+ *
+ * Return value: A list of UID strings. The list should be freed using the
+ * cal_obj_uid_list_free() function.
**/
GList *
-cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_t end)
+cal_backend_get_objects_in_range (CalBackend *backend, CalObjType type,
+ time_t start, time_t end)
{
g_return_val_if_fail (backend != NULL, NULL);
g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
g_return_val_if_fail (start != -1 && end != -1, NULL);
g_return_val_if_fail (start <= end, NULL);
- g_assert (CLASS (backend)->get_events_in_range != NULL);
- return (* CLASS (backend)->get_events_in_range) (backend, start, end);
+ g_assert (CLASS (backend)->get_objects_in_range != NULL);
+ return (* CLASS (backend)->get_objects_in_range) (backend, type, start, end);
}
/**
diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h
index 2daa4ad56b..e1122f4d1c 100644
--- a/calendar/pcs/cal-backend.h
+++ b/calendar/pcs/cal-backend.h
@@ -69,7 +69,8 @@ struct _CalBackendClass {
int (* get_n_objects) (CalBackend *backend, CalObjType type);
char *(* get_object) (CalBackend *backend, const char *uid);
GList *(* get_uids) (CalBackend *backend, CalObjType type);
- GList *(* get_events_in_range) (CalBackend *backend, time_t start, time_t end);
+ GList *(* get_objects_in_range) (CalBackend *backend, CalObjType type,
+ time_t start, time_t end);
GList *(* get_alarms_in_range) (CalBackend *backend, time_t start, time_t end);
gboolean (* get_alarms_for_object) (CalBackend *backend, const char *uid,
time_t start, time_t end,
@@ -77,7 +78,8 @@ struct _CalBackendClass {
gboolean (* update_object) (CalBackend *backend, const char *uid, const char *calobj);
gboolean (* remove_object) (CalBackend *backend, const char *uid);
char *(* get_uid_by_pilot_id) (CalBackend *backend, unsigned long int pilot_id);
- void (* update_pilot_id) (CalBackend *backend, const char *uid, unsigned long int pilot_id, unsigned long int pilot_status);
+ void (* update_pilot_id) (CalBackend *backend, const char *uid,
+ unsigned long int pilot_id, unsigned long int pilot_status);
};
GtkType cal_backend_get_type (void);
@@ -96,7 +98,8 @@ char *cal_backend_get_object (CalBackend *backend, const char *uid);
GList *cal_backend_get_uids (CalBackend *backend, CalObjType type);
-GList *cal_backend_get_events_in_range (CalBackend *backend, time_t start, time_t end);
+GList *cal_backend_get_objects_in_range (CalBackend *backend, CalObjType type,
+ time_t start, time_t end);
GList *cal_backend_get_alarms_in_range (CalBackend *backend, time_t start, time_t end);
diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c
index 36791fefcd..5610267b9a 100644
--- a/calendar/pcs/cal.c
+++ b/calendar/pcs/cal.c
@@ -168,6 +168,17 @@ Cal_get_uri (PortableServer_Servant servant,
return str_uri_copy;
}
+/* Converts a calendar object type from its CORBA representation to our own
+ * representation.
+ */
+static CalObjType
+uncorba_obj_type (Evolution_Calendar_CalObjType type)
+{
+ return (((type & Evolution_Calendar_TYPE_EVENT) ? CALOBJ_TYPE_EVENT : 0)
+ | ((type & Evolution_Calendar_TYPE_TODO) ? CALOBJ_TYPE_TODO : 0)
+ | ((type & Evolution_Calendar_TYPE_JOURNAL) ? CALOBJ_TYPE_JOURNAL : 0));
+}
+
/* Cal::get_n_objects method */
static CORBA_long
Cal_get_n_objects (PortableServer_Servant servant,
@@ -182,16 +193,7 @@ Cal_get_n_objects (PortableServer_Servant servant,
cal = CAL (bonobo_object_from_servant (servant));
priv = cal->priv;
- /* Translate the CORBA flags to our own flags */
-
- t = (((type & Evolution_Calendar_TYPE_EVENT) ? CALOBJ_TYPE_EVENT : 0)
- | ((type & Evolution_Calendar_TYPE_TODO) ? CALOBJ_TYPE_TODO : 0)
- | ((type & Evolution_Calendar_TYPE_JOURNAL) ? CALOBJ_TYPE_JOURNAL : 0)
- /*
- | ((type & Evolution_Calendar_TYPE_ANY) ? CALOBJ_TYPE_ANY : 0)
- */
- );
-
+ t = uncorba_obj_type (type);
n = cal_backend_get_n_objects (priv->backend, t);
return n;
}
@@ -225,33 +227,13 @@ Cal_get_object (PortableServer_Servant servant,
}
}
-/* Cal::get_uids method */
static Evolution_Calendar_CalObjUIDSeq *
-Cal_get_uids (PortableServer_Servant servant,
- Evolution_Calendar_CalObjType type,
- CORBA_Environment *ev)
+build_uid_seq (GList *uids)
{
- Cal *cal;
- CalPrivate *priv;
- GList *uids, *l;
Evolution_Calendar_CalObjUIDSeq *seq;
- int t;
+ GList *l;
int n, i;
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- /* Translate the CORBA flags to our own flags */
-
- t = (((type & Evolution_Calendar_TYPE_EVENT) ? CALOBJ_TYPE_EVENT : 0)
- | ((type & Evolution_Calendar_TYPE_TODO) ? CALOBJ_TYPE_TODO : 0)
- | ((type & Evolution_Calendar_TYPE_JOURNAL) ? CALOBJ_TYPE_JOURNAL : 0)
- /*
- | ((type & Evolution_Calendar_TYPE_ANY) ? CALOBJ_TYPE_ANY : 0)
- */
- );
-
- uids = cal_backend_get_uids (priv->backend, t);
n = g_list_length (uids);
seq = Evolution_Calendar_CalObjUIDSeq__alloc ();
@@ -265,67 +247,56 @@ Cal_get_uids (PortableServer_Servant servant,
char *uid;
uid = l->data;
-
seq->_buffer[i] = CORBA_string_dup (uid);
}
- /* Done */
-
- cal_obj_uid_list_free (uids);
-
return seq;
}
-/* Builds a CORBA sequence of calendar object instances from a CalObjInstance
- * list.
- */
-static Evolution_Calendar_CalObjInstanceSeq *
-build_object_instance_seq (GList *list)
+/* Cal::get_uids method */
+static Evolution_Calendar_CalObjUIDSeq *
+Cal_get_uids (PortableServer_Servant servant,
+ Evolution_Calendar_CalObjType type,
+ CORBA_Environment *ev)
{
- GList *l;
- int n, i;
- Evolution_Calendar_CalObjInstanceSeq *seq;
-
- n = g_list_length (list);
-
- seq = Evolution_Calendar_CalObjInstanceSeq__alloc ();
- CORBA_sequence_set_release (seq, TRUE);
- seq->_length = n;
- seq->_buffer = CORBA_sequence_Evolution_Calendar_CalObjInstance_allocbuf (n);
+ Cal *cal;
+ CalPrivate *priv;
+ GList *uids;
+ Evolution_Calendar_CalObjUIDSeq *seq;
+ int t;
- /* Fill the sequence */
+ cal = CAL (bonobo_object_from_servant (servant));
+ priv = cal->priv;
- for (i = 0, l = list; l; i++, l = l->next) {
- CalObjInstance *icoi;
- Evolution_Calendar_CalObjInstance *corba_icoi;
+ t = uncorba_obj_type (type);
- icoi = l->data;
- corba_icoi = &seq->_buffer[i];
+ uids = cal_backend_get_uids (priv->backend, t);
+ seq = build_uid_seq (uids);
- corba_icoi->uid = CORBA_string_dup (icoi->uid);
- corba_icoi->start = icoi->start;
- corba_icoi->end = icoi->end;
- }
+ cal_obj_uid_list_free (uids);
return seq;
}
-/* Cal::get_events_in_range method */
-static Evolution_Calendar_CalObjInstanceSeq *
-Cal_get_events_in_range (PortableServer_Servant servant,
- Evolution_Calendar_Time_t start,
- Evolution_Calendar_Time_t end,
- CORBA_Environment *ev)
+/* Cal::get_objects_in_range method */
+static Evolution_Calendar_CalObjUIDSeq *
+Cal_get_objects_in_range (PortableServer_Servant servant,
+ Evolution_Calendar_CalObjType type,
+ Evolution_Calendar_Time_t start,
+ Evolution_Calendar_Time_t end,
+ CORBA_Environment *ev)
{
Cal *cal;
CalPrivate *priv;
+ int t;
time_t t_start, t_end;
- Evolution_Calendar_CalObjInstanceSeq *seq;
- GList *elist;
+ Evolution_Calendar_CalObjUIDSeq *seq;
+ GList *uids;
cal = CAL (bonobo_object_from_servant (servant));
priv = cal->priv;
+ t = uncorba_obj_type (type);
t_start = (time_t) start;
t_end = (time_t) end;
@@ -336,11 +307,10 @@ Cal_get_events_in_range (PortableServer_Servant servant,
return NULL;
}
- /* Figure out the list and allocate the sequence */
+ uids = cal_backend_get_objects_in_range (priv->backend, t, t_start, t_end);
+ seq = build_uid_seq (uids);
- elist = cal_backend_get_events_in_range (priv->backend, t_start, t_end);
- seq = build_object_instance_seq (elist);
- cal_obj_instance_list_free (elist);
+ cal_obj_uid_list_free (uids);
return seq;
}
@@ -588,7 +558,7 @@ cal_get_epv (void)
epv->get_n_objects = Cal_get_n_objects;
epv->get_object = Cal_get_object;
epv->get_uids = Cal_get_uids;
- epv->get_events_in_range = Cal_get_events_in_range;
+ epv->get_objects_in_range = Cal_get_objects_in_range;
epv->get_alarms_in_range = Cal_get_alarms_in_range;
epv->get_alarms_for_object = Cal_get_alarms_for_object;
epv->update_object = Cal_update_object;