aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2001-08-21 21:21:23 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2001-08-21 21:21:23 +0800
commitcc1b730fe46aa2324a203e7af8b6f9a71cb121b9 (patch)
tree7cde3af4441494954be4d07811a6edc30b2d6d71 /calendar
parentbd866109877225814415c16af9fcf5601078e32a (diff)
downloadgsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar.gz
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar.bz2
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar.lz
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar.xz
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.tar.zst
gsoc2013-evolution-cc1b730fe46aa2324a203e7af8b6f9a71cb121b9.zip
new files to contain utility functions for calendar backends
2001-08-21 Rodrigo Moya <rodrigo@ximian.com> * pcs/cal-backend-util.[ch]: new files to contain utility functions for calendar backends * pcs/cal-backend.c (cal_backend_add_cal): implement it here, and not in the calendar backends. Add a "cal_added" signal, so that backends are notified when a new Cal is added, if they need to (cal_backend_get_type_by_uid): implement it here * pcs/cal-backend-file.c (fill_alarm_instances_seq): moved to cal-backend-util.c (cal_backend_file_add_cal): removed (cal_backend_file_init): connect to the "cal_added" signal in the CalBackend class so that we can update categories when a new Cal is added (cal_backend_file_get_type_by_uid): removed * pcs/cal-backend-db.c (fill_alarm_instances_seq): moved to cal-backend-util.c (cal_backend_db_add_cal): removed (cal_backend_db_get_type_by_uid): removed * AUTHORS: added JP and Damon to list of authors svn path=/trunk/; revision=12339
Diffstat (limited to 'calendar')
-rw-r--r--calendar/AUTHORS2
-rw-r--r--calendar/ChangeLog25
-rw-r--r--calendar/pcs/Makefile.am2
-rw-r--r--calendar/pcs/cal-backend-db.c113
-rw-r--r--calendar/pcs/cal-backend-file.c158
-rw-r--r--calendar/pcs/cal-backend-util.c54
-rw-r--r--calendar/pcs/cal-backend-util.h36
-rw-r--r--calendar/pcs/cal-backend.c107
-rw-r--r--calendar/pcs/cal-backend.h6
9 files changed, 252 insertions, 251 deletions
diff --git a/calendar/AUTHORS b/calendar/AUTHORS
index 0049fa248e..e4fda3d3bc 100644
--- a/calendar/AUTHORS
+++ b/calendar/AUTHORS
@@ -3,3 +3,5 @@ Federico Mena <federico@helixcode.com>
Arturo Esponosa <arturo@nuclecu.unam.mx>
Russell Steinthal <rms39@columbia.edu>
Rodrigo Moya <rodrigo@ximian.com>
+JP Rosevear <jpr@ximian.com>
+Damon Chaplin <damon@ximian.com>
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index f36523caf8..7c4ab63228 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,28 @@
+2001-08-21 Rodrigo Moya <rodrigo@ximian.com>
+
+ * pcs/cal-backend-util.[ch]: new files to contain utility functions
+ for calendar backends
+
+ * pcs/cal-backend.c (cal_backend_add_cal): implement it here, and not in
+ the calendar backends. Add a "cal_added" signal, so that backends are
+ notified when a new Cal is added, if they need to
+ (cal_backend_get_type_by_uid): implement it here
+
+ * pcs/cal-backend-file.c (fill_alarm_instances_seq): moved to
+ cal-backend-util.c
+ (cal_backend_file_add_cal): removed
+ (cal_backend_file_init): connect to the "cal_added" signal in the
+ CalBackend class so that we can update categories when a new Cal is
+ added
+ (cal_backend_file_get_type_by_uid): removed
+
+ * pcs/cal-backend-db.c (fill_alarm_instances_seq): moved to
+ cal-backend-util.c
+ (cal_backend_db_add_cal): removed
+ (cal_backend_db_get_type_by_uid): removed
+
+ * AUTHORS: added JP and Damon to list of authors
+
2001-08-20 Rodrigo Moya <rodrigo@ximian.com>
* cal-util/cal-util.[ch] (cal_util_generate_alarms_for_list):
diff --git a/calendar/pcs/Makefile.am b/calendar/pcs/Makefile.am
index 9806c13fb3..b9733f26dc 100644
--- a/calendar/pcs/Makefile.am
+++ b/calendar/pcs/Makefile.am
@@ -34,6 +34,8 @@ libpcs_a_SOURCES = \
cal-backend.h \
cal-backend-file.c \
cal-backend-file.h \
+ cal-backend-util.c \
+ cal-backend-util.h \
cal-common.h \
cal-factory.c \
cal-factory.h \
diff --git a/calendar/pcs/cal-backend-db.c b/calendar/pcs/cal-backend-db.c
index bbb4590fc2..bb2a22a7f2 100644
--- a/calendar/pcs/cal-backend-db.c
+++ b/calendar/pcs/cal-backend-db.c
@@ -63,7 +63,6 @@ static void cal_backend_db_init (CalBackendDB *cbdb);
static void cal_backend_db_destroy (GtkObject *object);
static GnomeVFSURI *cal_backend_db_get_uri (CalBackend *backend);
-static void cal_backend_db_add_cal (CalBackend *backend, Cal *cal);
static CalBackendOpenStatus cal_backend_db_open (CalBackend *backend,
GnomeVFSURI *uri,
gboolean only_if_exists);
@@ -71,7 +70,6 @@ static gboolean cal_backend_db_is_loaded (CalBackend *backend);
static int cal_backend_db_get_n_objects (CalBackend *backend, CalObjType type);
static char *cal_backend_db_get_object (CalBackend *backend, const char *uid);
-static CalObjType cal_backend_db_get_type_by_uid (CalBackend *backend, const char *uid);
static GList* cal_backend_db_get_uids (CalBackend *backend, CalObjType type);
static GList* cal_backend_db_get_objects_in_range (CalBackend *backend,
CalObjType type,
@@ -152,12 +150,10 @@ cal_backend_db_class_init (CalBackendDBClass *klass)
object_class->destroy = cal_backend_db_destroy;
backend_class->get_uri = cal_backend_db_get_uri;
- backend_class->add_cal = cal_backend_db_add_cal;
backend_class->open = cal_backend_db_open;
backend_class->is_loaded = cal_backend_db_is_loaded;
backend_class->get_n_objects = cal_backend_db_get_n_objects;
backend_class->get_object = cal_backend_db_get_object;
- backend_class->get_type_by_uid = cal_backend_db_get_type_by_uid;
backend_class->get_uids = cal_backend_db_get_uids;
backend_class->get_objects_in_range = cal_backend_db_get_objects_in_range;
backend_class->get_free_busy = cal_backend_db_get_free_busy;
@@ -451,28 +447,6 @@ destroy_cal_cb (GtkObject *object, gpointer data)
}
}
-/* add_cal_handler for the DB backend */
-static void
-cal_backend_db_add_cal (CalBackend *backend, Cal *cal)
-{
- CalBackendDB *cbdb;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_if_fail(IS_CAL_BACKEND_DB(cbdb));
- g_return_if_fail(cbdb->priv != NULL);
- g_return_if_fail(IS_CAL(cal));
-
- /* we do not keep a reference to the Cal since the calendar user agent
- * owns it
- */
- gtk_signal_connect(GTK_OBJECT(cal),
- "destroy",
- GTK_SIGNAL_FUNC(destroy_cal_cb),
- backend);
-
- cbdb->priv->clients = g_list_prepend(cbdb->priv->clients, (gpointer) cal);
-}
-
/* database file initialization */
static gboolean
open_database_file (CalBackendDB *cbdb, const gchar *str_uri, gboolean only_if_exists)
@@ -688,58 +662,6 @@ cal_backend_db_get_object (CalBackend *backend, const char *uid)
return NULL;
}
-/* get_type_by_uid handler for the DB backend */
-static CalObjType
-cal_backend_db_get_type_by_uid (CalBackend *backend, const char *uid)
-{
- CalBackendDB *cbdb;
- DBT key;
- DBT data;
- gint ret;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), CAL_COMPONENT_NO_TYPE);
- g_return_val_if_fail(cbdb->priv != NULL, CAL_COMPONENT_NO_TYPE);
- g_return_val_if_fail(cbdb->priv->objects_db != NULL, CAL_COMPONENT_NO_TYPE);
- g_return_val_if_fail(uid != NULL, CAL_COMPONENT_NO_TYPE);
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- key.data = (void *) uid;
- key.size = strlen(uid); // + 1
-
- /* read record from database */
- if ((ret = cbdb->priv->objects_db->get(cbdb->priv->objects_db,
- NULL,
- &key,
- &data,
- 0)) == 0) {
- icalcomponent *icalcomp = icalparser_parse_string((char *) data.data);
- if (icalcomp) {
- CalObjType type;
-
- switch (icalcomponent_isa(icalcomp)) {
- case ICAL_VEVENT_COMPONENT :
- type = CALOBJ_TYPE_EVENT;
- break;
- case ICAL_VTODO_COMPONENT :
- type = CALOBJ_TYPE_TODO;
- break;
- case ICAL_VJOURNAL_COMPONENT :
- type = CALOBJ_TYPE_JOURNAL;
- break;
- default :
- type = CAL_COMPONENT_NO_TYPE;
- }
-
- icalcomponent_free(icalcomp);
- return type;
- }
- }
-
- return CAL_COMPONENT_NO_TYPE;
-}
-
static GList *
add_uid_if_match (GList *list, CalBackendDBCursor *cursor, GList *data_node, CalObjType type)
{
@@ -1002,33 +924,6 @@ get_list_of_alarms (CalBackendDBCursor *cursor, time_t start, time_t end)
return list;
}
-/* fills a CORBA sequence of alarm instances */
-static void
-fill_alarm_instances_seq (GNOME_Evolution_Calendar_CalAlarmInstanceSeq *seq, GSList *alarms)
-{
- int n_alarms;
- GSList *l;
- int i;
-
- n_alarms = g_slist_length(alarms);
-
- CORBA_sequence_set_release(seq, TRUE);
- seq->_length = n_alarms;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalAlarmInstance_allocbuf(n_alarms);
-
- for (l = alarms, i = 0; l != NULL; l = l->next, i++) {
- CalAlarmInstance *instance;
- GNOME_Evolution_Calendar_CalAlarmInstance *corba_instance;
-
- instance = (CalAlarmInstance *) l->data;
- corba_instance = seq->_buffer + i;
-
- corba_instance->auid = CORBA_string_dup(instance->auid);
- corba_instance->trigger = (long) instance->trigger;
- corba_instance->occur = (long) instance->occur;
- }
-}
-
/* get_alarms_in_range handler for the DB backend */
static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *
cal_backend_db_get_alarms_in_range (CalBackend *backend, time_t start, time_t end)
@@ -1071,7 +966,8 @@ cal_backend_db_get_alarms_in_range (CalBackend *backend, time_t start, time_t en
seq->_buffer[i].calobj = CORBA_string_dup(comp_str);
g_free((gpointer) comp_str);
- fill_alarm_instances_seq(&seq->_buffer[i].alarms, alarms->alarms);
+ cal_backend_util_fill_alarm_instances_seq (&seq->_buffer[i].alarms,
+ alarms->alarms);
cal_component_alarms_free(alarms);
}
@@ -1136,11 +1032,12 @@ cal_backend_db_get_alarms_for_object (CalBackend *backend,
/* populate the CORBA sequence */
alarms = generate_alarms_for_comp(comp, start, end);
if (alarms) {
- fill_alarm_instances_seq(&corba_alarms->alarms, alarms->alarms);
+ cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms,
+ alarms->alarms);
cal_component_alarms_free(alarms);
}
else
- fill_alarm_instances_seq(&corba_alarms->alarms, NULL);
+ cal_backend_fill_alarm_instances_seq (&corba_alarms->alarms, NULL);
gtk_object_unref(GTK_OBJECT(comp));
icalcomponent_free(icalcomp);
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
index 81d2739123..3817382a71 100644
--- a/calendar/pcs/cal-backend-file.c
+++ b/calendar/pcs/cal-backend-file.c
@@ -26,6 +26,7 @@
#include "cal-util/cal-recur.h"
#include "cal-util/cal-util.h"
#include "cal-backend-file.h"
+#include "cal-backend-util.h"
@@ -79,7 +80,6 @@ static void cal_backend_file_init (CalBackendFile *cbfile);
static void cal_backend_file_destroy (GtkObject *object);
static GnomeVFSURI *cal_backend_file_get_uri (CalBackend *backend);
-static void cal_backend_file_add_cal (CalBackend *backend, Cal *cal);
static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend, GnomeVFSURI *uri,
gboolean only_if_exists);
static gboolean cal_backend_file_is_loaded (CalBackend *backend);
@@ -88,7 +88,6 @@ 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 CalComponent *cal_backend_file_get_object_component (CalBackend *backend, const char *uid);
static char *cal_backend_file_get_timezone_object (CalBackend *backend, const char *tzid);
-static CalObjType cal_backend_file_get_type_by_uid (CalBackend *backend, const char *uid);
static GList *cal_backend_file_get_uids (CalBackend *backend, CalObjType type);
static GList *cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
time_t start, time_t end);
@@ -108,6 +107,8 @@ static gboolean cal_backend_file_remove_object (CalBackend *backend, const char
static icaltimezone* cal_backend_file_get_timezone (CalBackend *backend, const char *tzid);
+static void notify_categories_changed (CalBackendFile *cbfile);
+
static CalBackendClass *parent_class;
@@ -159,14 +160,12 @@ cal_backend_file_class_init (CalBackendFileClass *class)
object_class->destroy = cal_backend_file_destroy;
backend_class->get_uri = cal_backend_file_get_uri;
- backend_class->add_cal = cal_backend_file_add_cal;
backend_class->open = cal_backend_file_open;
backend_class->is_loaded = cal_backend_file_is_loaded;
backend_class->get_n_objects = cal_backend_file_get_n_objects;
backend_class->get_object = cal_backend_file_get_object;
backend_class->get_object_component = cal_backend_file_get_object_component;
backend_class->get_timezone_object = cal_backend_file_get_timezone_object;
- backend_class->get_type_by_uid = cal_backend_file_get_type_by_uid;
backend_class->get_uids = cal_backend_file_get_uids;
backend_class->get_objects_in_range = cal_backend_file_get_objects_in_range;
backend_class->get_free_busy = cal_backend_file_get_free_busy;
@@ -179,6 +178,12 @@ cal_backend_file_class_init (CalBackendFileClass *class)
backend_class->get_timezone = cal_backend_file_get_timezone;
}
+static void
+cal_added_cb (CalBackend *backend, gpointer user_data)
+{
+ notify_categories_changed (CAL_BACKEND_FILE (backend));
+}
+
/* Object initialization function for the file backend */
static void
cal_backend_file_init (CalBackendFile *cbfile)
@@ -189,7 +194,6 @@ cal_backend_file_init (CalBackendFile *cbfile)
cbfile->priv = priv;
priv->uri = NULL;
- priv->clients = NULL;
priv->icalcomp = NULL;
priv->comp_uid_hash = NULL;
priv->events = NULL;
@@ -197,6 +201,9 @@ cal_backend_file_init (CalBackendFile *cbfile)
priv->journals = NULL;
priv->categories = g_hash_table_new (g_str_hash, g_str_equal);
+
+ gtk_signal_connect (GTK_OBJECT (cbfile), "cal_added",
+ GTK_SIGNAL_FUNC (cal_added_cb), NULL);
}
/* g_hash_table_foreach() callback to destroy a CalComponent */
@@ -280,6 +287,7 @@ cal_backend_file_destroy (GtkObject *object)
{
CalBackendFile *cbfile;
CalBackendFilePrivate *priv;
+ GList *clients;
g_return_if_fail (object != NULL);
g_return_if_fail (IS_CAL_BACKEND_FILE (object));
@@ -287,7 +295,8 @@ cal_backend_file_destroy (GtkObject *object)
cbfile = CAL_BACKEND_FILE (object);
priv = cbfile->priv;
- g_assert (priv->clients == NULL);
+ clients = CAL_BACKEND (cbfile)->clients;
+ g_assert (clients == NULL);
/* Save if necessary */
@@ -370,44 +379,6 @@ cal_backend_file_get_uri (CalBackend *backend)
return priv->uri;
}
-/* Callback used when a Cal is destroyed */
-static void
-cal_destroy_cb (GtkObject *object, gpointer data)
-{
- Cal *cal;
- Cal *lcal;
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- GList *l;
-
- cal = CAL (object);
-
- cbfile = CAL_BACKEND_FILE (data);
- priv = cbfile->priv;
-
- /* Find the cal in the list of clients */
-
- for (l = priv->clients; l; l = l->next) {
- lcal = CAL (l->data);
-
- if (lcal == cal)
- break;
- }
-
- g_assert (l != NULL);
-
- /* Disconnect */
-
- priv->clients = g_list_remove_link (priv->clients, l);
- g_list_free_1 (l);
-
- /* When all clients go away, notify the parent factory about it so that
- * it may decide whether to kill the backend or not.
- */
- if (!priv->clients)
- cal_backend_last_client_gone (CAL_BACKEND (cbfile));
-}
-
/* Used from g_hash_table_foreach(), adds a category name to the sequence */
static void
add_category_cb (gpointer key, gpointer value, gpointer data)
@@ -445,7 +416,7 @@ notify_categories_changed (CalBackendFile *cbfile)
/* Notify the clients */
- for (l = priv->clients; l; l = l->next) {
+ for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
Cal *cal;
cal = CAL (l->data);
@@ -455,37 +426,6 @@ notify_categories_changed (CalBackendFile *cbfile)
CORBA_free (seq);
}
-/* Add_cal handler for the file backend */
-static void
-cal_backend_file_add_cal (CalBackend *backend, Cal *cal)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_if_fail (priv->icalcomp != NULL);
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
-
- /* We do not keep a reference to the Cal since the calendar user agent
- * owns it.
- */
-
- gtk_signal_connect (GTK_OBJECT (cal), "destroy",
- GTK_SIGNAL_FUNC (cal_destroy_cb),
- backend);
-
- priv->clients = g_list_prepend (priv->clients, cal);
-
- /* Notify the client about changed categories so that it can populate
- * its lists.
- */
-
- notify_categories_changed (cbfile);
-}
-
/* Idle handler; we save the calendar since it is dirty */
static gboolean
save_idle (gpointer data)
@@ -994,34 +934,6 @@ cal_backend_file_get_timezone_object (CalBackend *backend, const char *tzid)
return NULL;
}
-static CalObjType
-cal_backend_file_get_type_by_uid (CalBackend *backend, const char *uid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- CalComponent *comp;
- CalComponentVType type;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- comp = lookup_component (cbfile, uid);
- if (!comp)
- return CAL_COMPONENT_NO_TYPE;
-
- type = cal_component_get_vtype (comp);
- switch (type) {
- case CAL_COMPONENT_EVENT:
- return CALOBJ_TYPE_EVENT;
- case CAL_COMPONENT_TODO:
- return CALOBJ_TYPE_TODO;
- case CAL_COMPONENT_JOURNAL:
- return CALOBJ_TYPE_JOURNAL;
- default:
- return CAL_COMPONENT_NO_TYPE;
- }
-}
-
/* Builds a list of UIDs from a list of CalComponent objects */
static void
build_uids_list (GList **list, GList *components)
@@ -1395,34 +1307,6 @@ cal_backend_file_get_changes (CalBackend *backend, CalObjType type, const char *
return cal_backend_file_compute_changes (backend, type, change_id);
}
-/* Fills a CORBA sequence of alarm instances */
-static void
-fill_alarm_instances_seq (GNOME_Evolution_Calendar_CalAlarmInstanceSeq *seq, GSList *alarms)
-{
- int n_alarms;
- GSList *l;
- int i;
-
- n_alarms = g_slist_length (alarms);
-
- CORBA_sequence_set_release (seq, TRUE);
- seq->_length = n_alarms;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalAlarmInstance_allocbuf (n_alarms);
-
- for (l = alarms, i = 0; l; l = l->next, i++) {
- CalAlarmInstance *instance;
- GNOME_Evolution_Calendar_CalAlarmInstance *corba_instance;
-
- instance = l->data;
- corba_instance = seq->_buffer + i;
-
- corba_instance->auid = CORBA_string_dup (instance->auid);
- corba_instance->trigger = (long) instance->trigger;
- corba_instance->occur_start = (long) instance->occur_start;
- corba_instance->occur_end = (long) instance->occur_end;
- }
-}
-
/* Get_alarms_in_range handler for the file backend */
static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *
cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t end)
@@ -1471,7 +1355,7 @@ cal_backend_file_get_alarms_in_range (CalBackend *backend, time_t start, time_t
seq->_buffer[i].calobj = CORBA_string_dup (comp_str);
g_free (comp_str);
- fill_alarm_instances_seq (&seq->_buffer[i].alarms, alarms->alarms);
+ cal_backend_util_fill_alarm_instances_seq (&seq->_buffer[i].alarms, alarms->alarms);
cal_component_alarms_free (alarms);
}
@@ -1519,10 +1403,10 @@ cal_backend_file_get_alarms_for_object (CalBackend *backend, const char *uid,
alarms = cal_util_generate_alarms_for_comp (comp, start, end, resolve_tzid, priv->icalcomp);
if (alarms) {
- fill_alarm_instances_seq (&corba_alarms->alarms, alarms->alarms);
+ cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms, alarms->alarms);
cal_component_alarms_free (alarms);
} else
- fill_alarm_instances_seq (&corba_alarms->alarms, NULL);
+ cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms, NULL);
return corba_alarms;
}
@@ -1538,7 +1422,7 @@ notify_update (CalBackendFile *cbfile, const char *uid)
cal_backend_obj_updated (CAL_BACKEND (cbfile), uid);
- for (l = priv->clients; l; l = l->next) {
+ for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
Cal *cal;
cal = CAL (l->data);
@@ -1557,7 +1441,7 @@ notify_remove (CalBackendFile *cbfile, const char *uid)
cal_backend_obj_removed (CAL_BACKEND (cbfile), uid);
- for (l = priv->clients; l; l = l->next) {
+ for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
Cal *cal;
cal = CAL (l->data);
diff --git a/calendar/pcs/cal-backend-util.c b/calendar/pcs/cal-backend-util.c
new file mode 100644
index 0000000000..e2d138e372
--- /dev/null
+++ b/calendar/pcs/cal-backend-util.c
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Evolution calendar - generic backend class
+ *
+ * Copyright (C) 2000 Ximian, Inc.
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Authors: Rodrigo Moya <rodrigo@ximian.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "cal-backend-util.h"
+
+void
+cal_backend_util_fill_alarm_instances_seq (GNOME_Evolution_Calendar_CalAlarmInstanceSeq *seq,
+ GSList *alarms)
+{
+ int n_alarms;
+ GSList *l;
+ int i;
+
+ g_return_if_fail (seq != NULL);
+
+ n_alarms = g_slist_length (alarms);
+
+ CORBA_sequence_set_release (seq, TRUE);
+ seq->_length = n_alarms;
+ seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalAlarmInstance_allocbuf (n_alarms);
+
+ for (l = alarms, i = 0; l; l = l->next, i++) {
+ CalAlarmInstance *instance;
+ GNOME_Evolution_Calendar_CalAlarmInstance *corba_instance;
+
+ instance = l->data;
+ corba_instance = seq->_buffer + i;
+
+ corba_instance->auid = CORBA_string_dup (instance->auid);
+ corba_instance->trigger = (long) instance->trigger;
+ corba_instance->occur_start = (long) instance->occur_start;
+ corba_instance->occur_end = (long) instance->occur_end;
+ }
+}
diff --git a/calendar/pcs/cal-backend-util.h b/calendar/pcs/cal-backend-util.h
new file mode 100644
index 0000000000..2d9c9bd554
--- /dev/null
+++ b/calendar/pcs/cal-backend-util.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Evolution calendar - generic backend class
+ *
+ * Copyright (C) 2000 Ximian, Inc.
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Authors: Rodrigo Moya <rodrigo@ximian.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef CAL_BACKEND_UTIL_H
+#define CAL_BACKEND_UTIL_H
+
+#include <cal-backend.h>
+
+BEGIN_GNOME_DECLS
+
+void cal_backend_util_fill_alarm_instances_seq (
+ GNOME_Evolution_Calendar_CalAlarmInstanceSeq *seq, GSList *alarms);
+
+END_GNOME_DECLS
+
+#endif
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
index b67fce3b9a..b19c141446 100644
--- a/calendar/pcs/cal-backend.c
+++ b/calendar/pcs/cal-backend.c
@@ -38,6 +38,7 @@
/* Signal IDs */
enum {
LAST_CLIENT_GONE,
+ CAL_ADDED,
OPENED,
OBJ_UPDATED,
OBJ_REMOVED,
@@ -100,6 +101,14 @@ cal_backend_class_init (CalBackendClass *class)
GTK_SIGNAL_OFFSET (CalBackendClass, last_client_gone),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
+ cal_backend_signals[CAL_ADDED] =
+ gtk_signal_new ("cal_added",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (CalBackendClass, cal_added),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_POINTER);
cal_backend_signals[OPENED] =
gtk_signal_new ("opened",
GTK_RUN_FIRST,
@@ -133,14 +142,12 @@ cal_backend_class_init (CalBackendClass *class)
class->obj_removed = NULL;
class->get_uri = NULL;
- class->add_cal = NULL;
class->open = NULL;
class->is_loaded = NULL;
class->get_n_objects = NULL;
class->get_object = NULL;
class->get_object_component = NULL;
class->get_timezone_object = NULL;
- class->get_type_by_uid = NULL;
class->get_uids = NULL;
class->get_objects_in_range = NULL;
class->get_free_busy = NULL;
@@ -172,6 +179,42 @@ cal_backend_get_uri (CalBackend *backend)
return (* CLASS (backend)->get_uri) (backend);
}
+/* Callback used when a Cal is destroyed */
+static void
+cal_destroy_cb (GtkObject *object, gpointer data)
+{
+ Cal *cal;
+ Cal *lcal;
+ CalBackend *backend;
+ GList *l;
+
+ cal = CAL (object);
+
+ backend = CAL_BACKEND (data);
+
+ /* Find the cal in the list of clients */
+
+ for (l = backend->clients; l; l = l->next) {
+ lcal = CAL (l->data);
+
+ if (lcal == cal)
+ break;
+ }
+
+ g_assert (l != NULL);
+
+ /* Disconnect */
+
+ backend->clients = g_list_remove_link (backend->clients, l);
+ g_list_free_1 (l);
+
+ /* When all clients go away, notify the parent factory about it so that
+ * it may decide whether to kill the backend or not.
+ */
+ if (!backend->clients)
+ cal_backend_last_client_gone (backend);
+}
+
/**
* cal_backend_add_cal:
* @backend: A calendar backend.
@@ -185,9 +228,20 @@ cal_backend_add_cal (CalBackend *backend, Cal *cal)
{
g_return_if_fail (backend != NULL);
g_return_if_fail (IS_CAL_BACKEND (backend));
+ g_return_if_fail (IS_CAL (cal));
+
+ /* we do not keep a reference to the Cal since the Calendar
+ * user agent owns it */
+ gtk_signal_connect (GTK_OBJECT (cal), "destroy",
+ GTK_SIGNAL_FUNC (cal_destroy_cb),
+ backend);
+
+ backend->clients = g_list_prepend (backend->clients, cal);
- g_assert (CLASS (backend)->add_cal != NULL);
- (* CLASS (backend)->add_cal) (backend, cal);
+ /* notify backend that a new Cal has been added */
+ gtk_signal_emit (GTK_OBJECT (backend),
+ cal_backend_signals[CAL_ADDED],
+ cal);
}
/**
@@ -327,6 +381,51 @@ cal_backend_get_timezone_object (CalBackend *backend, const char *tzid)
}
/**
+ * cal_backend_get_type_by_uid
+ * @backend: A calendar backend.
+ * @uid: Unique identifier for a Calendar object.
+ *
+ * Returns the type of the object identified by the @uid argument
+ */
+CalObjType
+cal_backend_get_type_by_uid (CalBackend *backend, const char *uid)
+{
+ icalcomponent *icalcomp;
+ char *comp_str;
+ CalObjType type = CAL_COMPONENT_NO_TYPE;
+
+ g_return_val_if_fail (IS_CAL_BACKEND (backend), CAL_COMPONENT_NO_TYPE);
+ g_return_val_if_fail (uid != NULL, CAL_COMPONENT_NO_TYPE);
+
+ comp_str = cal_backend_get_object (backend, uid);
+ if (!comp_str)
+ return CAL_COMPONENT_NO_TYPE;
+
+ icalcomp = icalparser_parse_string (comp_str);
+ if (icalcomp) {
+ switch (icalcomponent_isa (icalcomp)) {
+ case ICAL_VEVENT_COMPONENT :
+ type = CALOBJ_TYPE_EVENT;
+ break;
+ case ICAL_VTODO_COMPONENT :
+ type = CALOBJ_TYPE_TODO;
+ break;
+ case ICAL_VJOURNAL_COMPONENT :
+ type = CALOBJ_TYPE_JOURNAL;
+ break;
+ default :
+ type = CAL_COMPONENT_NO_TYPE;
+ }
+
+ icalcomponent_free (icalcomp);
+ }
+
+ g_free (comp_str);
+
+ return type;
+}
+
+/**
* cal_backend_get_uids:
* @backend: A calendar backend.
* @type: Bitmask with types of objects to return.
diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h
index 4af8befa84..59b5023a7d 100644
--- a/calendar/pcs/cal-backend.h
+++ b/calendar/pcs/cal-backend.h
@@ -60,6 +60,7 @@ typedef enum {
struct _CalBackend {
GtkObject object;
+ GList *clients;
};
struct _CalBackendClass {
@@ -67,6 +68,7 @@ struct _CalBackendClass {
/* Notification signals */
void (* last_client_gone) (CalBackend *backend);
+ void (* cal_added) (CalBackend *backend, Cal *cal);
void (* opened) (CalBackend *backend, CalBackendOpenStatus status);
void (* obj_updated) (CalBackend *backend, const char *uid);
@@ -74,7 +76,6 @@ struct _CalBackendClass {
/* Virtual methods */
GnomeVFSURI *(* get_uri) (CalBackend *backend);
- void (* add_cal) (CalBackend *backend, Cal *cal);
CalBackendOpenStatus (* open) (CalBackend *backend, GnomeVFSURI *uri,
gboolean only_if_exists);
@@ -86,7 +87,6 @@ struct _CalBackendClass {
char *(* get_object) (CalBackend *backend, const char *uid);
CalComponent *(* get_object_component) (CalBackend *backend, const char *uid);
char *(* get_timezone_object) (CalBackend *backend, const char *tzid);
- CalObjType(* get_type_by_uid) (CalBackend *backend, const char *uid);
GList *(* get_uids) (CalBackend *backend, CalObjType type);
GList *(* get_objects_in_range) (CalBackend *backend, CalObjType type,
@@ -131,6 +131,8 @@ CalComponent *cal_backend_get_object_component (CalBackend *backend, const char
char *cal_backend_get_timezone_object (CalBackend *backend, const char *tzid);
+CalObjType cal_backend_get_type_by_uid (CalBackend *backend, const char *uid);
+
GList *cal_backend_get_uids (CalBackend *backend, CalObjType type);
GList *cal_backend_get_objects_in_range (CalBackend *backend, CalObjType type,