aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/pcs')
-rw-r--r--calendar/pcs/.cvsignore11
-rw-r--r--calendar/pcs/Makefile.am52
-rw-r--r--calendar/pcs/cal-backend-db.c1190
-rw-r--r--calendar/pcs/cal-backend-db.h56
-rw-r--r--calendar/pcs/cal-backend-file.c1932
-rw-r--r--calendar/pcs/cal-backend-file.h62
-rw-r--r--calendar/pcs/cal-backend-util.c116
-rw-r--r--calendar/pcs/cal-backend-util.h51
-rw-r--r--calendar/pcs/cal-backend.c822
-rw-r--r--calendar/pcs/cal-backend.h180
-rw-r--r--calendar/pcs/cal-common.h41
-rw-r--r--calendar/pcs/cal-factory.c820
-rw-r--r--calendar/pcs/cal-factory.h73
-rw-r--r--calendar/pcs/cal.c865
-rw-r--r--calendar/pcs/cal.h79
-rw-r--r--calendar/pcs/job.c98
-rw-r--r--calendar/pcs/job.h35
-rw-r--r--calendar/pcs/query.c1454
-rw-r--r--calendar/pcs/query.h68
19 files changed, 0 insertions, 8005 deletions
diff --git a/calendar/pcs/.cvsignore b/calendar/pcs/.cvsignore
deleted file mode 100644
index ac51a554db..0000000000
--- a/calendar/pcs/.cvsignore
+++ /dev/null
@@ -1,11 +0,0 @@
-Makefile
-Makefile.in
-.deps
-.libs
-.pure
-*.la
-*.lo
-evolution-calendar-stubs.c
-evolution-calendar-skels.c
-evolution-calendar-common.c
-evolution-calendar.h
diff --git a/calendar/pcs/Makefile.am b/calendar/pcs/Makefile.am
deleted file mode 100644
index 57c24d3130..0000000000
--- a/calendar/pcs/Makefile.am
+++ /dev/null
@@ -1,52 +0,0 @@
-INCLUDES = \
- -DG_LOG_DOMAIN=\"wombat-pcs\" \
- -I$(top_srcdir) \
- -I$(top_srcdir)/calendar \
- -I$(top_srcdir)/libical/src/libical \
- -I$(top_builddir)/libical/src/libical \
- -I$(top_srcdir)/libwombat \
- -I$(top_builddir)/libwombat \
- -DGNOMELOCALEDIR=\""$(localedir)"\" \
- $(EVOLUTION_CALENDAR_CFLAGS)
-
-CORBA_GENERATED = \
- evolution-calendar.h \
- evolution-calendar-common.c \
- evolution-calendar-skels.c \
- evolution-calendar-stubs.c
-
-idls = \
- $(srcdir)/../idl/evolution-calendar.idl
-
-idl_flags = -I $(srcdir) `$(GNOME_CONFIG) --cflags idl` -I $(datadir)/idl
-
-$(CORBA_GENERATED): $(idls)
- $(ORBIT_IDL) $(idl_flags) $(srcdir)/../idl/evolution-calendar.idl
-
-noinst_LIBRARIES = libpcs.a
-
-libpcs_a_SOURCES = \
- $(CORBA_GENERATED) \
- cal.c \
- cal.h \
- cal-backend.c \
- 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 \
- job.c \
- job.h \
- query.c \
- query.h
-
-
-BUILT_SOURCES = $(CORBA_GENERATED)
-CLEANFILES = $(BUILT_SOURCES)
-
-dist-hook:
- cd $(distdir); rm -f $(BUILT_SOURCES)
-
diff --git a/calendar/pcs/cal-backend-db.c b/calendar/pcs/cal-backend-db.c
deleted file mode 100644
index 59f49701ec..0000000000
--- a/calendar/pcs/cal-backend-db.c
+++ /dev/null
@@ -1,1190 +0,0 @@
-/* Evolution calendar - iCalendar DB backend
- *
- * Copyright (C) 2001 Ximian, Inc.
- *
- * Author: Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include <gtk/gtksignal.h>
-#include "cal-util/cal-recur.h"
-#include "cal-backend-db.h"
-#include <db.h>
-#if DB_VERSION_MAJOR < 3
-# error "You need libdb3 to compile the DB backend"
-#endif
-
-#define ENVIRONMENT_DIRECTORY "%s/evolution/local/Calendar/db.environment"
-
-/* structure to identify an open cursor */
-typedef struct {
- gint ref;
- DBC* dbc;
- DB* parent_db;
-
- /* data in the cursor */
- GList *keys;
- GList *data;
-} CalBackendDBCursor;
-
-/* private part of the CalBackendDB structure */
-struct _CalBackendDBPrivate {
- /* URI where the calendar data is stored */
- GnomeVFSURI *uri;
-
- /* Berkeley DB's library handles */
- DB_ENV *environment;
- DB *objects_db;
- DB *history_db;
-
- /* list of open cursors */
- GList *cursors;
-
- /* list of clients using this backend */
- GList *clients;
-};
-
-static void cal_backend_db_class_init (CalBackendDBClass *klass);
-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 CalBackendOpenStatus cal_backend_db_open (CalBackend *backend,
- GnomeVFSURI *uri,
- gboolean only_if_exists);
-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 GList* cal_backend_db_get_uids (CalBackend *backend, CalObjType type);
-static GList* cal_backend_db_get_objects_in_range (CalBackend *backend,
- CalObjType type,
- time_t start,
- time_t end);
-static char *cal_backend_db_get_free_busy (CalBackend *backend,
- time_t start,
- time_t end);
-static GNOME_Evolution_Calendar_CalObjChangeSeq *cal_backend_db_get_changes (
- CalBackend *backend, CalObjType type, const char *change_id);
-
-static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *cal_backend_db_get_alarms_in_range (
- CalBackend *backend, time_t start, time_t end);
-
-static GNOME_Evolution_Calendar_CalComponentAlarms *cal_backend_db_get_alarms_for_object (
- CalBackend *backend, const char *uid, time_t start, time_t end, gboolean *object_found);
-
-static gboolean cal_backend_db_update_object (CalBackend *backend,
- const char *uid,
- const char *calobj);
-static gboolean cal_backend_db_remove_object (CalBackend *backend, const char *uid);
-
-static void close_cursor (CalBackendDB *cbdb, CalBackendDBCursor *cursor);
-static CalBackendDBCursor *open_cursor (CalBackendDB *cbdb, DB *db);
-static CalBackendDBCursor *find_cursor_by_db (CalBackendDB *cbdb, DB *db);
-static DBT *find_record_by_id (CalBackendDBCursor *cursor, const gchar *id);
-
-static DB_TXN *begin_transaction (CalBackendDB *cbdb);
-static void commit_transaction (DB_TXN *tid);
-static void rollback_transaction (DB_TXN *tid);
-
-static CalBackendClass *parent_class;
-
-/**
- * cal_backend_db_get_type:
- * @void:
- *
- * Registers the #CalBackendDB class if necessary and returns the type ID
- * associated to it.
- *
- * Return value: The type ID of the #CalBackendDB class.
- */
-GtkType
-cal_backend_db_get_type (void)
-{
- static GtkType cal_backend_db_type = 0;
-
- if (!cal_backend_db_type) {
- static const GtkTypeInfo cal_backend_db_info = {
- "CalBackendDB",
- sizeof (CalBackendDB),
- sizeof (CalBackendDBClass),
- (GtkClassInitFunc) cal_backend_db_class_init,
- (GtkObjectInitFunc) cal_backend_db_init,
- NULL,
- NULL,
- (GtkClassInitFunc) NULL
- };
-
- cal_backend_db_type = gtk_type_unique(CAL_BACKEND_TYPE, &cal_backend_db_info);
- }
-
- return cal_backend_db_type;
-}
-
-/* class initialization function for the DB backend */
-static void
-cal_backend_db_class_init (CalBackendDBClass *klass)
-{
- GtkObjectClass *object_class;
- CalBackendClass *backend_class;
-
- object_class = (GtkObjectClass *) klass;
- backend_class = (CalBackendClass *) klass;
-
- parent_class = gtk_type_class(CAL_BACKEND_TYPE);
-
- object_class->destroy = cal_backend_db_destroy;
-
- backend_class->get_uri = cal_backend_db_get_uri;
- 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_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;
- backend_class->get_changes = cal_backend_db_get_changes;
- backend_class->get_alarms_in_range = cal_backend_db_get_alarms_in_range;
- backend_class->get_alarms_for_object = cal_backend_db_get_alarms_for_object;
- backend_class->update_object = cal_backend_db_update_object;
- backend_class->remove_object = cal_backend_db_remove_object;
-}
-
-/* object initialization function for the DB backend */
-static void
-cal_backend_db_init (CalBackendDB *cbdb)
-{
- CalBackendDBPrivate *priv;
-
- priv = g_new0(CalBackendDBPrivate, 1);
- cbdb->priv = priv;
-}
-
-/* Destroy handler for the DB backend */
-static void
-cal_backend_db_destroy (GtkObject *object)
-{
- CalBackendDB *cbdb;
- CalBackendDBPrivate *priv;
- GList *node;
-
- g_return_if_fail(object != NULL);
- g_return_if_fail(IS_CAL_BACKEND_DB(object));
-
- cbdb = CAL_BACKEND_DB(object);
- priv = cbdb->priv;
-
- g_assert(cbdb->priv->clients == NULL);
-
- /* clean up */
- if (priv->uri) {
- gnome_vfs_uri_unref(priv->uri);
- priv->uri = NULL;
- }
-
- /* close open cursors */
- while ((node = g_list_first(cbdb->priv->cursors))) {
- close_cursor(cbdb, (CalBackendDBCursor *) node->data);
- }
-
- /* close open databases */
- if (cbdb->priv->objects_db)
- cbdb->priv->objects_db->close(cbdb->priv->objects_db, 0);
- if (cbdb->priv->history_db)
- cbdb->priv->history_db->close(cbdb->priv->history_db, 0);
-
- /* close DB environment */
- if (cbdb->priv->environment)
- cbdb->priv->environment->close(cbdb->priv->environment, 0);
-
- g_free((gpointer) priv);
- cbdb->priv = NULL;
-
- if (GTK_OBJECT_CLASS(parent_class)->destroy)
- (*GTK_OBJECT_CLASS(parent_class)->destroy)(object);
-}
-
-/*
- * Private functions
- */
-
-/* close an open cursor and frees all associated memory */
-static void
-close_cursor (CalBackendDB *cbdb, CalBackendDBCursor *cursor)
-{
- GList *node;
- DBT *dbt;
-
- g_return_if_fail(cursor != NULL);
-
- cursor->ref--;
- if (cursor->ref > 0)
- return;
-
- /* free all keys and data */
- while ((node = g_list_first(cursor->keys))) {
- dbt = (DBT *) node->data;
- cursor->keys = g_list_remove(cursor->keys, (gpointer) dbt);
- g_free((gpointer) dbt);
- }
- while ((node = g_list_first(cursor->data))) {
- dbt = (DBT *) node->data;
- cursor->data = g_list_remove(cursor->data, (gpointer) dbt);
- g_free((gpointer) dbt);
- }
-
- /* finally, close the cursor */
- cursor->dbc->c_close(cursor->dbc);
-
- cbdb->priv->cursors = g_list_remove(cbdb->priv->cursors, (gpointer) cursor);
- g_free((gpointer) cursor);
-}
-
-/* open a cursor for the given database */
-static CalBackendDBCursor *
-open_cursor (CalBackendDB *cbdb, DB *db)
-{
- CalBackendDBCursor *cursor;
- gint ret;
-
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(db != NULL, NULL);
-
- /* search for the cursor in our list of cursors */
- cursor = find_cursor_by_db(cbdb, db);
- if (cursor) {
- cursor->ref++;
- return cursor;
- }
-
- /* create the cursor */
- cursor = g_new0(CalBackendDBCursor, 1);
- cursor->parent_db = db;
- cursor->ref = 1;
-
- ret = db->cursor(db, NULL, &cursor->dbc, 0);
- if (ret == 0) {
- DBT key;
- DBT data;
-
- /* read data */
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
-
- while ((ret = cursor->dbc->c_get(cursor->dbc, &key, &data, DB_NEXT)) == 0) {
- cursor->keys = g_list_append(cursor->keys, g_memdup(&key, sizeof(key)));
- cursor->data = g_list_append(cursor->data, g_memdup(&data, sizeof(data)));
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- }
- if (ret == DB_NOTFOUND) {
- cbdb->priv->cursors = g_list_prepend(cbdb->priv->cursors, (gpointer) cursor);
- return cursor;
- }
-
- /* close cursor on error */
- close_cursor(cbdb, cursor);
- }
-
- return NULL;
-}
-
-/* search for a cursor in the given backend */
-static CalBackendDBCursor *
-find_cursor_by_db (CalBackendDB *cbdb, DB *db)
-{
- GList *node;
-
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
- g_return_val_if_fail(db != NULL, NULL);
-
- for (node = g_list_first(cbdb->priv->cursors); node != NULL; node = g_list_next(node)) {
- CalBackendDBCursor* cursor = (CalBackendDBCursor *) node->data;
-
- if (cursor && cursor->parent_db == db)
- return cursor;
- }
-
- return NULL; /* not found */
-}
-
-/* finds a record in a cursor by its ID */
-static DBT *
-find_record_by_id (CalBackendDBCursor *cursor, const gchar *id)
-{
- GList *node;
-
- g_return_val_if_fail(cursor != NULL, NULL);
- g_return_val_if_fail(id != NULL, NULL);
-
-
- for (node = g_list_first(cursor->keys); node != NULL; node = g_list_next(node)) {
- DBT *key;
-
- key = (DBT *) node->data;
- if (key && !strcmp(key->data, id)) {
- GList *tmp;
-
- tmp = g_list_nth(cursor->data, g_list_position(cursor->keys, node));
- if (tmp)
- return (DBT *) tmp->data;
- return NULL; /* no data associated with this key */
- }
- }
-
- return NULL; /* not found */
-}
-
-/* start a new transaction */
-static DB_TXN *
-begin_transaction (CalBackendDB *cbdb)
-{
- DB_TXN *tid;
- gint ret;
-
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
-
- if ((ret = txn_begin(cbdb->priv->environment, NULL, &tid, 0)) != 0) {
- /* TODO: error logging */
- return NULL;
- }
-
- return tid;
-}
-
-/* finish successfully a transaction */
-static void
-commit_transaction (DB_TXN *tid)
-{
- gint ret;
-
- g_return_if_fail(tid != NULL);
-
- if ((ret = txn_commit(tid, 0)) != 0) {
- /* TODO: error logging? */
- }
-}
-
-/* abort a transaction */
-static void
-rollback_transaction (DB_TXN *tid)
-{
- gint ret;
-
- g_return_if_fail(tid != NULL);
-
- if ((ret = txn_abort(tid)) != 0) {
- /* TODO: error logging? */
- }
-}
-
-/*
- * Calendar backend methods
- */
-
-/* get_uri handler for the DB backend */
-static GnomeVFSURI *
-cal_backend_db_get_uri (CalBackend *backend)
-{
- CalBackendDB *cbdb;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
-
- return cbdb->priv->uri;
-}
-
-/* callback used when a Cal is destroyed */
-static void
-destroy_cal_cb (GtkObject *object, gpointer data)
-{
- Cal *cal;
- Cal *tmp_cal;
- CalBackendDB *cbdb;
- GList *node;
-
- cal = CAL(object);
- cbdb = CAL_BACKEND_DB(data);
-
- g_return_if_fail(IS_CAL_BACKEND_DB(cbdb));
- g_return_if_fail(cbdb->priv != NULL);
-
- /* find the Cal in the list of clients */
- for (node = cbdb->priv->clients; node != NULL; node = g_list_next(node)) {
- tmp_cal = CAL(node->data);
- if (tmp_cal == cal)
- break;
- }
-
- if (node) {
- /* disconnect this Cal */
- cbdb->priv->clients = g_list_remove_link(cbdb->priv->clients, node);
- g_list_free_1(node);
-
- /* when all clients go away, notify the parent factory about it so that
- * it may decide to kill the backend or not.
- */
- if (!cbdb->priv->clients)
- cal_backend_last_client_gone(CAL_BACKEND(cbdb));
- }
-}
-
-/* database file initialization */
-static gboolean
-open_database_file (CalBackendDB *cbdb, const gchar *str_uri, gboolean only_if_exists)
-{
- gint ret;
- struct stat sb;
- gchar *dir;
-
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), FALSE);
- g_return_val_if_fail(cbdb->priv != NULL, FALSE);
- g_return_val_if_fail(cbdb->priv->objects_db != NULL, FALSE);
- g_return_val_if_fail(cbdb->priv->history_db != NULL, FALSE);
- g_return_val_if_fail(str_uri != NULL, FALSE);
-
- /* initialize DB environment (for transactions) */
- dir = g_strdup_printf(ENVIRONMENT_DIRECTORY, g_get_home_dir());
- if (stat(dir, &sb) != 0) {
-
- /* if the directory exists, we're done, since DB will fail if it's the
- * wrong one. If it does not exist, create the environment */
- if (mkdir(dir, S_IRWXU) != 0) {
- g_free((gpointer) dir);
- return FALSE;
- }
-
- /* create the environment handle */
- if ((ret = db_env_create(&cbdb->priv->environment, 0)) != 0) {
- g_free((gpointer) dir);
- return FALSE;
- }
-
- cbdb->priv->environment->set_errpfx(cbdb->priv->environment, "cal-backend-db");
-
- /* open the transactional environment */
- if ((ret = cbdb->priv->environment->open(cbdb->priv->environment,
- ENVIRONMENT_DIRECTORY,
- DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
- DB_INIT_MPOOL | DB_INIT_TXN |
- DB_RECOVER | DB_THREAD,
- S_IRUSR | S_IWUSR)) != 0) {
- g_free((gpointer) dir);
- return FALSE;
- }
- }
-
- g_free((gpointer) dir);
-
- /* open/create objects database into given file */
- if ((ret = db_create(&cbdb->priv->objects_db, cbdb->priv->environment, 0)) != 0
- || (ret = db_create(&cbdb->priv->history_db, cbdb->priv->environment, 0)) != 0) {
- return FALSE;
- }
-
- if (only_if_exists) {
- ret = cbdb->priv->objects_db->open(cbdb->priv->objects_db,
- str_uri,
- "calendar_objects",
- DB_HASH,
- DB_THREAD,
- 0644);
- }
- else {
- ret = cbdb->priv->objects_db->open(cbdb->priv->objects_db,
- str_uri,
- "calendar_objects",
- DB_HASH,
- DB_CREATE | DB_THREAD,
- 0644);
- }
- if (ret == 0) {
- /* now, open the history database */
- ret = cbdb->priv->history_db->open(cbdb->priv->history_db,
- str_uri,
- "calendar_history",
- DB_BTREE,
- DB_CREATE | DB_THREAD,
- 0644);
- if (ret == 0) return TRUE;
-
- /* close objects database on error */
- cbdb->priv->objects_db->close(cbdb->priv->objects_db, 0);
- }
-
- return FALSE;
-}
-
-/* open handler for the DB backend */
-static CalBackendOpenStatus
-cal_backend_db_open (CalBackend *backend, GnomeVFSURI *uri, gboolean only_if_exists)
-{
- CalBackendDB *cbdb;
- gchar *str_uri;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail(cbdb->priv != NULL, CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail(uri != NULL, CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail(cbdb->priv->objects_db == NULL, CAL_BACKEND_OPEN_ERROR);
-
- /* open the given URI */
- if (!gnome_vfs_uri_is_local(uri))
- return CAL_BACKEND_OPEN_ERROR;
- str_uri = gnome_vfs_uri_to_string(uri,
- (GNOME_VFS_URI_HIDE_USER_NAME
- | GNOME_VFS_URI_HIDE_PASSWORD
- | GNOME_VFS_URI_HIDE_HOST_NAME
- | GNOME_VFS_URI_HIDE_HOST_PORT
- | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
-
- /* open database file */
- if (!open_database_file(cbdb, (const gchar *) str_uri, only_if_exists)) {
- g_free((gpointer) str_uri);
- return CAL_BACKEND_OPEN_ERROR;
- }
-
- gnome_vfs_uri_ref(uri);
- cbdb->priv->uri = uri;
- g_free((gpointer) str_uri);
-
- return CAL_BACKEND_OPEN_SUCCESS;
-}
-
-/* is_loaded handler for the DB backend */
-static gboolean
-cal_backend_db_is_loaded (CalBackend *backend)
-{
- CalBackendDB *cbdb;
-
- cbdb = CAL_BACKEND_DB (backend);
-
- return (cbdb->priv->uri != NULL);
-}
-
-/* get_n_objects handler for the DB backend */
-static int
-cal_backend_db_get_n_objects (CalBackend *backend, CalObjType type)
-{
- CalBackendDB *cbdb;
- CalBackendDBCursor *cursor;
- int total_count = 0;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), -1);
- g_return_val_if_fail(cbdb->priv != NULL, -1);
-
- /* open the cursor */
- cursor = open_cursor(cbdb, cbdb->priv->objects_db);
- if (cursor) {
- GList *node;
-
- /* we traverse all data, to check for each object's type */
- for (node = g_list_first(cursor->data); node != NULL; node = g_list_next(node)) {
- icalcomponent *icalcomp;
- DBT *data = (DBT *) node->data;
-
- icalcomp = icalparser_parse_string((char *) data->data);
- if (icalcomp) {
- switch (icalcomponent_isa(icalcomp)) {
- case ICAL_VEVENT_COMPONENT :
- if (type & CALOBJ_TYPE_EVENT)
- total_count++;
- break;
- case ICAL_VTODO_COMPONENT :
- if (type & CALOBJ_TYPE_TODO)
- total_count++;
- break;
- case ICAL_VJOURNAL_COMPONENT :
- if (type & CALOBJ_TYPE_JOURNAL)
- total_count++;
- break;
- default :
- break;
- }
- icalcomponent_free(icalcomp);
- }
- }
- close_cursor(cbdb, cursor);
- }
-
- return total_count;
-}
-
-/* get_object handler for the DB backend */
-static char *
-cal_backend_db_get_object (CalBackend *backend, const char *uid)
-{
- CalBackendDB *cbdb;
- gint ret;
- DBT key;
- DBT data;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
- g_return_val_if_fail(cbdb->priv->objects_db != NULL, NULL);
- g_return_val_if_fail(uid != NULL, NULL);
-
- 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) {
- gchar *str = g_strdup((gchar *) data.data);
- return str;
- }
-
- return NULL;
-}
-
-static GList *
-add_uid_if_match (GList *list, CalBackendDBCursor *cursor, GList *data_node, CalObjType type)
-{
- DBT *data;
-
- g_return_val_if_fail(cursor != NULL, list);
- g_return_val_if_fail(data_node != NULL, list);
-
- data = (DBT *) data_node->data;
- if (data) {
- icalcomponent *icalcomp;
- gchar *uid = NULL;
-
- icalcomp = icalparser_parse_string(data->data);
- if (!icalcomp) return list;
-
- switch (icalcomponent_isa(icalcomp)) {
- case ICAL_VEVENT_COMPONENT :
- if (type & CALOBJ_TYPE_EVENT)
- uid = (gchar *) icalcomponent_get_uid(icalcomp);
- break;
- case ICAL_VTODO_COMPONENT :
- if (type & CALOBJ_TYPE_TODO)
- uid = (gchar *) icalcomponent_get_uid(icalcomp);
- break;
- case ICAL_VJOURNAL_COMPONENT :
- if (type & CALOBJ_TYPE_JOURNAL)
- uid = (gchar *) icalcomponent_get_uid(icalcomp);
- break;
- default :
- uid = NULL;
- }
-
- if (uid)
- list = g_list_prepend(list, g_strdup(uid));
- icalcomponent_free(icalcomp);
- }
-
- return list;
-}
-
-/* get_uids handler for the DB backend */
-static GList *
-cal_backend_db_get_uids (CalBackend *backend, CalObjType type)
-{
- CalBackendDB *cbdb;
- GList *list = NULL;
- CalBackendDBCursor *cursor;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
- g_return_val_if_fail(cbdb->priv->objects_db != NULL, NULL);
-
- /* open cursor */
- cursor = open_cursor(cbdb, cbdb->priv->objects_db);
- if (cursor) {
- GList *node;
-
- /* we traverse all data, to check for each object's type */
- for (node = g_list_first(cursor->data); node != NULL; node = g_list_next(node)) {
- list = add_uid_if_match(list, cursor, node, type);
- }
- close_cursor(cbdb, cursor);
- }
-
- return list;
-}
-
-/* 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)
-{
- GHashTable *uid_hash;
- const char *uid;
- const char *old_uid;
-
- uid_hash = data;
-
- cal_component_get_uid(comp, &uid);
-
- old_uid = g_hash_table_lookup(uid_hash, uid);
- if (old_uid)
- return FALSE;
-
- g_hash_table_insert(uid_hash, (char *) uid, NULL);
- return FALSE;
-}
-
-/* creates the list of UIDs in the given range */
-static void
-get_instances_in_range (GHashTable *uid_hash,
- CalBackendDBCursor *cursor,
- CalObjType type,
- time_t start,
- time_t end)
-{
- GList *node;
-
- g_return_if_fail(uid_hash != NULL);
- g_return_if_fail(cursor != NULL);
-
- for (node = g_list_first(cursor->data); node != NULL; node = g_list_next(node)) {
- DBT *data;
- icalcomponent *icalcomp;
-
- data = (DBT *) node->data;
- if (data) {
- icalcomp = icalparser_parse_string((char *) data->data);
- if (icalcomp) {
- CalComponent *comp = cal_component_new();
- cal_component_set_icalcomponent(comp, icalcomp);
-
- switch (icalcomponent_isa(icalcomp)) {
- case ICAL_VEVENT_COMPONENT :
- if (type & CALOBJ_TYPE_EVENT)
- cal_recur_generate_instances(comp,
- start,
- end,
- add_instance,
- uid_hash);
- break;
- case ICAL_VTODO_COMPONENT :
- if (type & CALOBJ_TYPE_TODO)
- cal_recur_generate_instances(comp,
- start,
- end,
- add_instance,
- uid_hash);
- break;
- case ICAL_VJOURNAL_COMPONENT :
- if (type & CALOBJ_TYPE_JOURNAL)
- cal_recur_generate_instances(comp,
- start,
- end,
- add_instance,
- uid_hash);
- break;
- default :
- break;
- }
-
- gtk_object_unref(GTK_OBJECT(comp));
- icalcomponent_free(icalcomp);
- }
- }
- }
-}
-
-/* callback 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)
-{
- GList **list;
- const char *uid;
-
- list = (GList **) data;
-
- uid = (const char *) key;
- *list = g_list_prepend(*list, (gpointer) g_strdup(uid));
-}
-
-/* get_objects_in_range handler for the DB backend */
-static GList *
-cal_backend_db_get_objects_in_range (CalBackend *backend,
- CalObjType type,
- time_t start,
- time_t end)
-{
- CalBackendDB *cbdb;
- GList *list = NULL;
- CalBackendDBCursor *cursor;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
-
- /* open cursor */
- cursor = open_cursor(cbdb, cbdb->priv->objects_db);
- if (cursor) {
- GHashTable *uid_hash;
-
- /* build the hash table */
- uid_hash = g_hash_table_new(g_str_hash, g_str_equal);
- get_instances_in_range(uid_hash, cursor, type, start, end);
-
- /* build the list to be returned from the hash table */
- g_hash_table_foreach(uid_hash, add_uid_to_list, &list);
- g_hash_table_destroy(uid_hash);
-
- close_cursor(cbdb, cursor);
- }
-
- return list;
-}
-
-/* get_free_busy handler for the DB backend */
-static char *
-cal_backend_db_get_free_busy (CalBackend *backend, time_t start, time_t end)
-{
- return NULL;
-}
-
-/* get_changes handler for the DB backend */
-static GNOME_Evolution_Calendar_CalObjChangeSeq *
-cal_backend_db_get_changes (CalBackend *backend, CalObjType type, const char *change_id)
-{
- CalBackendDB *cbdb;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
-
- return NULL;
-}
-
-/* retrieve list of alarms */
-static GSList *
-get_list_of_alarms (CalBackendDBCursor *cursor, time_t start, time_t end)
-{
- GSList *list = NULL;
- GList *node;
-
- g_return_val_if_fail(cursor != NULL, NULL);
-
- for (node = g_list_first(cursor->data); node != NULL; node = g_list_next(node)) {
- icalcomponent *icalcomp;
- icalcomponent_kind kind;
- DBT *data;
-
- data = (DBT *) node->data;
- if (data) {
- icalcomp = icalparser_parse_string((char *) data->data);
- if (!icalcomp)
- continue;
-
- /* per RFC 2445, only VEVENTs and VTODOs can have alarms */
- kind = icalcomponent_isa(icalcomp);
- if (kind == ICAL_VEVENT_COMPONENT || kind == ICAL_VTODO_COMPONENT) {
- CalComponent *comp;
- CalComponentAlarms *alarms;
-
- /* create the CalComponent to compute the alarms */
- comp = cal_component_new();
- cal_component_set_icalcomponent(comp, icalcomp);
-
- alarms = cal_util_generate_alarms_for_comp (comp, start, end);
- if (alarms)
- list = g_slist_prepend(list, (gpointer) alarms);
-
- gtk_object_unref(GTK_OBJECT(comp));
- }
-
- icalcomponent_free(icalcomp);
- }
- }
-
- return list;
-}
-
-/* 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)
-{
- CalBackendDB *cbdb;
- CalBackendDBCursor *cursor;
- gint number_of_alarms;
- GSList *alarm_list;
- GSList *node;
- gint i;
- GNOME_Evolution_Calendar_CalComponentAlarmsSeq *seq = NULL;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
- g_return_val_if_fail (start != -1 && end != -1, NULL);
- g_return_val_if_fail (start <= end, NULL);
-
- /* open cursor */
- cursor = open_cursor(cbdb, cbdb->priv->objects_db);
- if (cursor) {
- alarm_list = get_list_of_alarms(cursor, start, end);
- number_of_alarms = g_slist_length(alarm_list);
-
- /* create the CORBA sequence */
- seq = GNOME_Evolution_Calendar_CalComponentAlarmsSeq__alloc();
- CORBA_sequence_set_release(seq, TRUE);
- seq->_length = number_of_alarms;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalComponentAlarms_allocbuf(
- number_of_alarms);
-
- /* populate CORBA sequence */
- for (node = alarm_list, i = 0; node != NULL; node = node->next, i++) {
- CalComponentAlarms *alarms;
- gchar *comp_str;
-
- alarms = (CalComponentAlarms *) node->data;
-
- comp_str = cal_component_get_as_string (alarms->comp);
- seq->_buffer[i].calobj = CORBA_string_dup(comp_str);
- g_free((gpointer) comp_str);
-
- cal_backend_util_fill_alarm_instances_seq (&seq->_buffer[i].alarms,
- alarms->alarms);
-
- cal_component_alarms_free(alarms);
- }
-
- g_slist_free(alarm_list);
- close_cursor(cbdb, cursor);
- }
-
- return seq;
-}
-
-/* get_alarms_for_object handler for the DB backend */
-static GNOME_Evolution_Calendar_CalComponentAlarms *
-cal_backend_db_get_alarms_for_object (CalBackend *backend,
- const char *uid,
- time_t start,
- time_t end,
- gboolean *object_found)
-{
- CalBackendDB *cbdb;
- CalBackendDBCursor *cursor;
- GNOME_Evolution_Calendar_CalComponentAlarms *corba_alarms = NULL;
- DBT *data;
- gchar *comp_str;
- CalComponentAlarms *alarms;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), NULL);
- g_return_val_if_fail(cbdb->priv != NULL, NULL);
- g_return_val_if_fail(uid != NULL, NULL);
- g_return_val_if_fail(start != -1 && end != -1, NULL);
- g_return_val_if_fail(start <= end, NULL);
- g_return_val_if_fail(object_found != NULL, NULL);
-
- *object_found = FALSE;
-
- /* open the cursor */
- cursor = open_cursor(cbdb, cbdb->priv->objects_db);
- if (cursor) {
- data = find_record_by_id(cursor, uid);
- if (data) {
- icalcomponent *icalcomp;
- CalComponent *comp;
-
- *object_found = TRUE;
-
- comp_str = (gchar *) data->data;
-
- icalcomp = icalparser_parse_string(comp_str);
- if (!icalcomp) {
- close_cursor(cbdb, cursor);
- return NULL;
- }
-
- comp = cal_component_new();
- cal_component_set_icalcomponent(comp, icalcomp);
-
- /* create the CORBA alarms */
- corba_alarms = GNOME_Evolution_Calendar_CalComponentAlarms__alloc();
- corba_alarms->calobj = CORBA_string_dup (comp_str);
-
- /* populate the CORBA sequence */
- alarms = generate_alarms_for_comp(comp, start, end);
- if (alarms) {
- cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms,
- alarms->alarms);
- cal_component_alarms_free(alarms);
- }
- else
- cal_backend_fill_alarm_instances_seq (&corba_alarms->alarms, NULL);
-
- gtk_object_unref(GTK_OBJECT(comp));
- icalcomponent_free(icalcomp);
- }
-
- close_cursor(cbdb, cursor);
- }
-
- return corba_alarms;
-}
-
-/* do notifications to Cal clients */
-static void
-do_notify (CalBackendDB *cbdb, void (*notify_fn)(Cal *, gchar *), const gchar *uid)
-{
- GList *node;
-
- g_return_if_fail(IS_CAL_BACKEND_DB(cbdb));
- g_return_if_fail(cbdb->priv != NULL);
- g_return_if_fail(notify_fn != NULL);
- g_return_if_fail(uid != NULL);
-
- /* FIXME: do notification asynchronously */
- for (node = g_list_first(cbdb->priv->clients); node != NULL; node = g_list_next(node)) {
- Cal *cal;
-
- cal = CAL(node->data);
- (*notify_fn)(cal, (gpointer) uid);
- }
-}
-
-/* adds a record to the history database */
-static gboolean
-add_history (CalBackendDB *cbdb, DB_TXN *tid, const gchar *uid, const gchar *calobj)
-{
- DBT key;
- DBT new_data;
- gint ret;
-
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), FALSE);
- g_return_val_if_fail(uid != NULL, FALSE);
- g_return_val_if_fail(calobj != NULL, FALSE);
-
- /* fill in DBT structures */
- memset(&key, 0, sizeof(key));
- key.data = (void *) uid;
- key.size = strlen(uid); // + 1
-
- memset(&new_data, 0, sizeof(new_data));
- new_data.data = (void *) calobj;
- new_data.size = strlen(calobj); // + 1
-
- /* add the new record to the database */
- if ((ret = cbdb->priv->history_db->put(cbdb->priv->objects_db,
- tid,
- &key,
- &new_data,
- 0)) != 0) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* update_object handler for the DB backend */
-static gboolean
-cal_backend_db_update_object (CalBackend *backend, const char *uid, const char *calobj)
-{
- CalBackendDB *cbdb;
- DB_TXN *tid;
- DBT key;
- DBT new_data;
- gint ret;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), FALSE);
- g_return_val_if_fail(cbdb->priv != NULL, FALSE);
- g_return_val_if_fail(cbdb->priv->objects_db != NULL, FALSE);
- g_return_val_if_fail(uid != NULL, FALSE);
- g_return_val_if_fail(calobj != NULL, FALSE);
-
- /* start transaction */
- tid = begin_transaction(cbdb);
- if (!tid)
- return FALSE;
-
- memset(&key, 0, sizeof(key));
- key.data = (void *) uid;
- key.size = strlen(uid); // + 1
-
- memset(&new_data, 0, sizeof(new_data));
- new_data.data = (void *) calobj;
- new_data.size = strlen(calobj); // + 1
-
- if ((ret = cbdb->priv->objects_db->put(cbdb->priv->objects_db,
- tid,
- &key,
- &new_data,
- 0)) != 0) {
- rollback_transaction(tid);
- return FALSE;
- }
-
- if (!add_history(cbdb, tid, uid, calobj)) {
- rollback_transaction(tid);
- return FALSE;
- }
- commit_transaction(tid);
-
- cal_backend_obj_updated (CAL_BACKEND (cbdb), uid);
- do_notify(cbdb, cal_notify_update, uid);
- return TRUE;
-}
-
-/* remove_object handler for the DB backend */
-static gboolean
-cal_backend_db_remove_object (CalBackend *backend, const char *uid)
-{
- CalBackendDB *cbdb;
- DB_TXN *tid;
- DBT key;
- gint ret;
-
- cbdb = CAL_BACKEND_DB(backend);
- g_return_val_if_fail(IS_CAL_BACKEND_DB(cbdb), FALSE);
- g_return_val_if_fail(cbdb->priv != NULL, FALSE);
- g_return_val_if_fail(uid != NULL, FALSE);
-
- memset(&key, 0, sizeof(key));
- key.data = (void *) uid;
- key.size = strlen(uid); // + 1
-
- /* start transaction */
- tid = begin_transaction(cbdb);
- if (!tid)
- return FALSE;
-
- /* remove record from database */
- if ((ret = cbdb->priv->objects_db->del(cbdb->priv->objects_db, tid, &key, 0)) != 0) {
- rollback_transaction(tid);
- return FALSE;
- }
-
- /* TODO: update history database */
- commit_transaction(tid);
-
- cal_backend_obj_removed (CAL_BACKEND (cbdb), uid);
- do_notify(cbdb, cal_notify_remove, uid);
-
- return TRUE;
-}
diff --git a/calendar/pcs/cal-backend-db.h b/calendar/pcs/cal-backend-db.h
deleted file mode 100644
index 0ed09f5ec6..0000000000
--- a/calendar/pcs/cal-backend-db.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Evolution calendar - iCalendar DB backend
- *
- * Copyright (C) 2001 Ximian, Inc.
- *
- * Author: Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_DB_H
-#define CAL_BACKEND_DB_H
-
-#include "cal-backend.h"
-
-BEGIN_GNOME_DECLS
-
-#define CAL_BACKEND_DB_TYPE (cal_backend_db_get_type ())
-#define CAL_BACKEND_DB(obj) (GTK_CHECK_CAST ((obj), CAL_BACKEND_DB_TYPE, \
- CalBackendDB))
-#define CAL_BACKEND_DB_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CAL_BACKEND_DB_TYPE, \
- CalBackendDBClass))
-#define IS_CAL_BACKEND_DB(obj) (GTK_CHECK_TYPE ((obj), CAL_BACKEND_DB_TYPE))
-#define IS_CAL_BACKEND_DB_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), CAL_BACKEND_DB_TYPE))
-
-typedef struct _CalBackendDB CalBackendDB;
-typedef struct _CalBackendDBClass CalBackendDBClass;
-
-typedef struct _CalBackendDBPrivate CalBackendDBPrivate;
-
-struct _CalBackendDB {
- CalBackend backend;
-
- /* Private data */
- CalBackendDBPrivate *priv;
-};
-
-struct _CalBackendDBClass {
- CalBackendClass parent_class;
-};
-
-GtkType cal_backend_db_get_type (void);
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c
deleted file mode 100644
index 424912e87b..0000000000
--- a/calendar/pcs/cal-backend-file.c
+++ /dev/null
@@ -1,1932 +0,0 @@
-/* Evolution calendar - iCalendar file backend
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Authors: Federico Mena-Quintero <federico@ximian.com>
- * Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include <gtk/gtksignal.h>
-#include <bonobo/bonobo-exception.h>
-#include <bonobo/bonobo-moniker-util.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include "e-util/e-dbhash.h"
-#include "cal-util/cal-recur.h"
-#include "cal-util/cal-util.h"
-#include "cal-backend-file.h"
-#include "cal-backend-util.h"
-
-
-
-/* A category that exists in some of the objects of the calendar */
-typedef struct {
- /* Category name, also used as the key in the categories hash table */
- char *name;
-
- /* Number of objects that have this category */
- int refcount;
-} Category;
-
-/* Private part of the CalBackendFile structure */
-struct _CalBackendFilePrivate {
- /* URI where the calendar data is stored */
- char *uri;
-
- /* List of Cal objects with their listeners */
- GList *clients;
-
- /* Toplevel VCALENDAR component */
- icalcomponent *icalcomp;
-
- /* All the CalComponent objects in the calendar, hashed by UID. The
- * hash key *is* the uid returned by cal_component_get_uid(); it is not
- * copied, so don't free it when you remove an object from the hash
- * table.
- */
- GHashTable *comp_uid_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
- * calendar, iterate over the hash instead.
- */
- GList *events;
- GList *todos;
- GList *journals;
-
- /* Hash table of live categories, and a temporary hash of removed categories */
- GHashTable *categories;
- GHashTable *removed_categories;
-
- /* Config database handle for free/busy organizer information */
- Bonobo_ConfigDatabase db;
-
- /* Idle handler for saving the calendar when it is dirty */
- guint idle_id;
-
- /* The calendar's default timezone, used for resolving DATE and
- floating DATE-TIME values. */
- icaltimezone *default_zone;
-};
-
-
-
-static void cal_backend_file_class_init (CalBackendFileClass *class);
-static void cal_backend_file_init (CalBackendFile *cbfile);
-static void cal_backend_file_destroy (GtkObject *object);
-
-static const char *cal_backend_file_get_uri (CalBackend *backend);
-static CalBackendOpenStatus cal_backend_file_open (CalBackend *backend,
- const char *uristr,
- gboolean only_if_exists);
-static gboolean cal_backend_file_is_loaded (CalBackend *backend);
-
-static CalMode cal_backend_file_get_mode (CalBackend *backend);
-static void cal_backend_file_set_mode (CalBackend *backend, CalMode mode);
-
-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 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);
-static GList *cal_backend_file_get_free_busy (CalBackend *backend, GList *users, time_t start, time_t end);
-static GNOME_Evolution_Calendar_CalObjChangeSeq *cal_backend_file_get_changes (
- CalBackend *backend, CalObjType type, const char *change_id);
-
-static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *cal_backend_file_get_alarms_in_range (
- CalBackend *backend, time_t start, time_t end);
-
-static GNOME_Evolution_Calendar_CalComponentAlarms *cal_backend_file_get_alarms_for_object (
- CalBackend *backend, const char *uid,
- time_t start, time_t end, gboolean *object_found);
-
-static gboolean cal_backend_file_update_objects (CalBackend *backend, const char *calobj);
-static gboolean cal_backend_file_remove_object (CalBackend *backend, const char *uid);
-
-static icaltimezone* cal_backend_file_get_timezone (CalBackend *backend, const char *tzid);
-static icaltimezone* cal_backend_file_get_default_timezone (CalBackend *backend);
-static gboolean cal_backend_file_set_default_timezone (CalBackend *backend,
- const char *tzid);
-
-static void notify_categories_changed (CalBackendFile *cbfile);
-
-static CalBackendClass *parent_class;
-
-
-
-/**
- * cal_backend_file_get_type:
- * @void:
- *
- * Registers the #CalBackendFile class if necessary, and returns the type ID
- * associated to it.
- *
- * Return value: The type ID of the #CalBackendFile class.
- **/
-GtkType
-cal_backend_file_get_type (void)
-{
- static GtkType cal_backend_file_type = 0;
-
- if (!cal_backend_file_type) {
- static const GtkTypeInfo cal_backend_file_info = {
- "CalBackendFile",
- sizeof (CalBackendFile),
- sizeof (CalBackendFileClass),
- (GtkClassInitFunc) cal_backend_file_class_init,
- (GtkObjectInitFunc) cal_backend_file_init,
- NULL, /* reserved_1 */
- NULL, /* reserved_2 */
- (GtkClassInitFunc) NULL
- };
-
- cal_backend_file_type = gtk_type_unique (CAL_BACKEND_TYPE, &cal_backend_file_info);
- }
-
- return cal_backend_file_type;
-}
-
-/* Class initialization function for the file backend */
-static void
-cal_backend_file_class_init (CalBackendFileClass *class)
-{
- GtkObjectClass *object_class;
- CalBackendClass *backend_class;
-
- object_class = (GtkObjectClass *) class;
- backend_class = (CalBackendClass *) class;
-
- parent_class = gtk_type_class (CAL_BACKEND_TYPE);
-
- object_class->destroy = cal_backend_file_destroy;
-
- backend_class->get_uri = cal_backend_file_get_uri;
- backend_class->open = cal_backend_file_open;
- backend_class->is_loaded = cal_backend_file_is_loaded;
- backend_class->get_mode = cal_backend_file_get_mode;
- backend_class->set_mode = cal_backend_file_set_mode;
- 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_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;
- backend_class->get_changes = cal_backend_file_get_changes;
- 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_objects = cal_backend_file_update_objects;
- backend_class->remove_object = cal_backend_file_remove_object;
-
- backend_class->get_timezone = cal_backend_file_get_timezone;
- backend_class->get_default_timezone = cal_backend_file_get_default_timezone;
- backend_class->set_default_timezone = cal_backend_file_set_default_timezone;
-}
-
-static Bonobo_ConfigDatabase
-load_db (void)
-{
- Bonobo_ConfigDatabase db = CORBA_OBJECT_NIL;
- CORBA_Environment ev;
-
- CORBA_exception_init (&ev);
-
- db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev);
-
- if (BONOBO_EX (&ev))
- db = CORBA_OBJECT_NIL;
-
- CORBA_exception_free (&ev);
-
- return db;
-}
-
-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)
-{
- CalBackendFilePrivate *priv;
-
- priv = g_new0 (CalBackendFilePrivate, 1);
- cbfile->priv = priv;
-
- priv->uri = NULL;
- priv->icalcomp = NULL;
- priv->comp_uid_hash = NULL;
- priv->events = NULL;
- priv->todos = NULL;
- priv->journals = NULL;
-
- priv->categories = g_hash_table_new (g_str_hash, g_str_equal);
- priv->removed_categories = g_hash_table_new (g_str_hash, g_str_equal);
-
- /* The timezone defaults to UTC. */
- priv->default_zone = icaltimezone_get_utc_timezone ();
-
- priv->db = load_db ();
-
- gtk_signal_connect (GTK_OBJECT (cbfile), "cal_added",
- GTK_SIGNAL_FUNC (cal_added_cb), NULL);
-}
-
-/* g_hash_table_foreach() callback to destroy a CalComponent */
-static void
-free_cal_component (gpointer key, gpointer value, gpointer data)
-{
- CalComponent *comp;
-
- comp = CAL_COMPONENT (value);
- gtk_object_unref (GTK_OBJECT (comp));
-}
-
-/* Saves the calendar data */
-static void
-save (CalBackendFile *cbfile)
-{
- CalBackendFilePrivate *priv;
- GnomeVFSURI *uri;
- GnomeVFSHandle *handle = NULL;
- GnomeVFSResult result;
- GnomeVFSFileSize out;
- gchar *tmp;
- char *buf;
-
- priv = cbfile->priv;
- g_assert (priv->uri != NULL);
- g_assert (priv->icalcomp != NULL);
-
- uri = gnome_vfs_uri_new (priv->uri);
-
- /* Make a backup copy of the file if it exists */
- tmp = gnome_vfs_uri_to_string (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 (uri, backup_uri, TRUE);
- gnome_vfs_uri_unref (backup_uri);
-
- g_free (tmp);
- g_free (backup_uristr);
- }
-
- /* Now write the new file out */
- result = gnome_vfs_create_uri (&handle, 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);
- gnome_vfs_uri_unref (uri);
-
- return;
-
- error:
- g_warning ("Error writing calendar file.");
- return;
-}
-
-/* Used from g_hash_table_foreach(), frees a Category structure */
-static void
-free_category_cb (gpointer key, gpointer value, gpointer data)
-{
- Category *c;
-
- c = value;
- g_free (c->name);
- g_free (c);
-}
-
-/* Destroy handler for the file backend */
-static void
-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));
-
- cbfile = CAL_BACKEND_FILE (object);
- priv = cbfile->priv;
-
- clients = CAL_BACKEND (cbfile)->clients;
- g_assert (clients == NULL);
-
- /* Save if necessary */
-
- if (priv->idle_id != 0) {
- save (cbfile);
- g_source_remove (priv->idle_id);
- priv->idle_id = 0;
- }
-
- /* Clean up */
-
- if (priv->uri) {
- g_free (priv->uri);
- priv->uri = NULL;
- }
-
- if (priv->comp_uid_hash) {
- 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;
- }
-
- g_list_free (priv->events);
- g_list_free (priv->todos);
- g_list_free (priv->journals);
- priv->events = NULL;
- priv->todos = NULL;
- priv->journals = NULL;
-
- g_hash_table_foreach (priv->categories, free_category_cb, NULL);
- g_hash_table_destroy (priv->categories);
- priv->categories = NULL;
-
- g_hash_table_foreach (priv->removed_categories, free_category_cb, NULL);
- g_hash_table_destroy (priv->removed_categories);
- priv->removed_categories = NULL;
-
- if (priv->icalcomp) {
- icalcomponent_free (priv->icalcomp);
- priv->icalcomp = NULL;
- }
-
- bonobo_object_release_unref (priv->db, NULL);
- priv->db = CORBA_OBJECT_NIL;
-
- g_free (priv);
- cbfile->priv = NULL;
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-
-
-/* Looks up a component by its UID on the backend's component hash table */
-static CalComponent *
-lookup_component (CalBackendFile *cbfile, const char *uid)
-{
- CalBackendFilePrivate *priv;
- CalComponent *comp;
-
- priv = cbfile->priv;
-
- comp = g_hash_table_lookup (priv->comp_uid_hash, uid);
-
- return comp;
-}
-
-
-
-/* Calendar backend methods */
-
-/* Get_uri handler for the file backend */
-static const char *
-cal_backend_file_get_uri (CalBackend *backend)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
- g_assert (priv->uri != NULL);
-
- return (const char *) priv->uri;
-}
-
-/* Used from g_hash_table_foreach(), adds a category name to the sequence */
-static void
-add_category_cb (gpointer key, gpointer value, gpointer data)
-{
- Category *c;
- GNOME_Evolution_Calendar_StringSeq *seq;
-
- c = value;
- seq = data;
-
- seq->_buffer[seq->_length] = CORBA_string_dup (c->name);
- seq->_length++;
-}
-
-/* Notifies the clients with the current list of categories */
-static void
-notify_categories_changed (CalBackendFile *cbfile)
-{
- CalBackendFilePrivate *priv;
- GNOME_Evolution_Calendar_StringSeq *seq;
- GList *l;
-
- priv = cbfile->priv;
-
- /* Build the sequence of category names */
-
- seq = GNOME_Evolution_Calendar_StringSeq__alloc ();
- seq->_length = 0;
- seq->_maximum = g_hash_table_size (priv->categories);
- seq->_buffer = CORBA_sequence_CORBA_string_allocbuf (seq->_maximum);
- CORBA_sequence_set_release (seq, TRUE);
-
- g_hash_table_foreach (priv->categories, add_category_cb, seq);
- g_assert (seq->_length == seq->_maximum);
-
- /* Notify the clients */
-
- for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
- Cal *cal;
-
- cal = CAL (l->data);
- cal_notify_categories_changed (cal, seq);
- }
-
- CORBA_free (seq);
-}
-
-/* Idle handler; we save the calendar since it is dirty */
-static gboolean
-save_idle (gpointer data)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (data);
- priv = cbfile->priv;
-
- g_assert (priv->icalcomp != NULL);
-
- save (cbfile);
-
- priv->idle_id = 0;
- return FALSE;
-}
-
-/* Marks the file backend as dirty and queues a save operation */
-static void
-mark_dirty (CalBackendFile *cbfile)
-{
- CalBackendFilePrivate *priv;
-
- priv = cbfile->priv;
-
- if (priv->idle_id != 0)
- return;
-
- priv->idle_id = g_idle_add (save_idle, cbfile);
-}
-
-/* Checks if the specified component has a duplicated UID and if so changes it */
-static void
-check_dup_uid (CalBackendFile *cbfile, CalComponent *comp)
-{
- CalBackendFilePrivate *priv;
- CalComponent *old_comp;
- const char *uid;
- char *new_uid;
-
- priv = cbfile->priv;
-
- cal_component_get_uid (comp, &uid);
-
- old_comp = g_hash_table_lookup (priv->comp_uid_hash, uid);
- if (!old_comp)
- return; /* Everything is fine */
-
- g_message ("check_dup_uid(): Got object with duplicated UID `%s', changing it...", uid);
-
- new_uid = cal_component_gen_uid ();
- cal_component_set_uid (comp, new_uid);
- g_free (new_uid);
-
- /* FIXME: I think we need to reset the SEQUENCE property and reset the
- * CREATED/DTSTAMP/LAST-MODIFIED.
- */
-
- mark_dirty (cbfile);
-}
-
-/* Updates the hash table of categories by adding or removing those in the
- * component.
- */
-static void
-update_categories_from_comp (CalBackendFile *cbfile, CalComponent *comp, gboolean add)
-{
- CalBackendFilePrivate *priv;
- GSList *categories, *l;
-
- priv = cbfile->priv;
-
- cal_component_get_categories_list (comp, &categories);
-
- for (l = categories; l; l = l->next) {
- const char *name;
- Category *c;
-
- name = l->data;
- c = g_hash_table_lookup (priv->categories, name);
-
- if (add) {
- /* Add the category to the set */
- if (c)
- c->refcount++;
- else {
- /* See if it was in the removed categories */
-
- c = g_hash_table_lookup (priv->removed_categories, name);
- if (c) {
- /* Move it to the set of live categories */
- g_assert (c->refcount == 0);
- g_hash_table_remove (priv->removed_categories, c->name);
-
- c->refcount = 1;
- g_hash_table_insert (priv->categories, c->name, c);
- } else {
- /* Create a new category */
- c = g_new (Category, 1);
- c->name = g_strdup (name);
- c->refcount = 1;
-
- g_hash_table_insert (priv->categories, c->name, c);
- }
- }
- } else {
- /* Remove the category from the set --- it *must* have existed */
-
- g_assert (c != NULL);
- g_assert (c->refcount > 0);
-
- c->refcount--;
-
- if (c->refcount == 0) {
- g_hash_table_remove (priv->categories, c->name);
- g_hash_table_insert (priv->removed_categories, c->name, c);
- }
- }
- }
-
- cal_component_free_categories_list (categories);
-}
-
-/* Tries to add an icalcomponent to the file backend. We only store the objects
- * of the types we support; all others just remain in the toplevel component so
- * that we don't lose them.
- */
-static void
-add_component (CalBackendFile *cbfile, CalComponent *comp, gboolean add_to_toplevel)
-{
- CalBackendFilePrivate *priv;
- GList **list;
- const char *uid;
-
- priv = cbfile->priv;
-
- switch (cal_component_get_vtype (comp)) {
- case CAL_COMPONENT_EVENT:
- list = &priv->events;
- break;
-
- case CAL_COMPONENT_TODO:
- list = &priv->todos;
- break;
-
- case CAL_COMPONENT_JOURNAL:
- list = &priv->journals;
- break;
-
- default:
- g_assert_not_reached ();
- return;
- }
-
- /* 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);
- g_hash_table_insert (priv->comp_uid_hash, (char *)uid, comp);
-
- *list = g_list_prepend (*list, comp);
-
- /* Put the object in the toplevel component if required */
-
- if (add_to_toplevel) {
- icalcomponent *icalcomp;
-
- icalcomp = cal_component_get_icalcomponent (comp);
- g_assert (icalcomp != NULL);
-
- icalcomponent_add_component (priv->icalcomp, icalcomp);
- }
-
- /* Update the set of categories */
-
- update_categories_from_comp (cbfile, comp, TRUE);
-}
-
-/* Removes a component from the backend's hash and lists. Does not perform
- * notification on the clients. Also removes the component from the toplevel
- * icalcomponent.
- */
-static void
-remove_component (CalBackendFile *cbfile, CalComponent *comp)
-{
- CalBackendFilePrivate *priv;
- icalcomponent *icalcomp;
- const char *uid;
- GList **list, *l;
-
- priv = cbfile->priv;
-
- /* Remove the icalcomp from the toplevel */
-
- icalcomp = cal_component_get_icalcomponent (comp);
- g_assert (icalcomp != NULL);
-
- icalcomponent_remove_component (priv->icalcomp, icalcomp);
-
- /* Remove it from our mapping */
-
- cal_component_get_uid (comp, &uid);
- g_hash_table_remove (priv->comp_uid_hash, uid);
-
- switch (cal_component_get_vtype (comp)) {
- case CAL_COMPONENT_EVENT:
- list = &priv->events;
- break;
-
- case CAL_COMPONENT_TODO:
- list = &priv->todos;
- break;
-
- case CAL_COMPONENT_JOURNAL:
- list = &priv->journals;
- break;
-
- default:
- /* Make the compiler shut up. */
- list = NULL;
- g_assert_not_reached ();
- }
-
- l = g_list_find (*list, comp);
- g_assert (l != NULL);
-
- *list = g_list_remove_link (*list, l);
- g_list_free_1 (l);
-
- /* Update the set of categories */
-
- update_categories_from_comp (cbfile, comp, FALSE);
-
- gtk_object_unref (GTK_OBJECT (comp));
-}
-
-/* Scans the toplevel VCALENDAR component and stores the objects it finds */
-static void
-scan_vcalendar (CalBackendFile *cbfile)
-{
- CalBackendFilePrivate *priv;
- icalcompiter iter;
-
- priv = cbfile->priv;
- g_assert (priv->icalcomp != NULL);
- g_assert (priv->comp_uid_hash != NULL);
-
- for (iter = icalcomponent_begin_component (priv->icalcomp, ICAL_ANY_COMPONENT);
- icalcompiter_deref (&iter) != NULL;
- icalcompiter_next (&iter)) {
- icalcomponent *icalcomp;
- icalcomponent_kind kind;
- CalComponent *comp;
-
- icalcomp = icalcompiter_deref (&iter);
-
- kind = icalcomponent_isa (icalcomp);
-
- if (!(kind == ICAL_VEVENT_COMPONENT
- || kind == ICAL_VTODO_COMPONENT
- || kind == ICAL_VJOURNAL_COMPONENT))
- continue;
-
- comp = cal_component_new ();
-
- if (!cal_component_set_icalcomponent (comp, icalcomp))
- continue;
-
- add_component (cbfile, comp, FALSE);
- }
-}
-
-/* Callback used from icalparser_parse() */
-static char *
-get_line_fn (char *s, size_t size, void *data)
-{
- FILE *file;
-
- file = data;
- return fgets (s, size, file);
-}
-
-/* Parses an open iCalendar file and returns a toplevel component with the contents */
-static icalcomponent *
-parse_file (FILE *file)
-{
- icalparser *parser;
- icalcomponent *icalcomp;
-
- parser = icalparser_new ();
- icalparser_set_gen_data (parser, file);
-
- icalcomp = icalparser_parse (parser, get_line_fn);
- icalparser_free (parser);
-
- return icalcomp;
-}
-
-/* Parses an open iCalendar file and loads it into the backend */
-static CalBackendOpenStatus
-open_cal (CalBackendFile *cbfile, const char *uristr, FILE *file)
-{
- CalBackendFilePrivate *priv;
- icalcomponent *icalcomp;
-
- priv = cbfile->priv;
-
- icalcomp = parse_file (file);
-
- if (fclose (file) != 0) {
- if (icalcomp)
- icalcomponent_free (icalcomp);
-
- return CAL_BACKEND_OPEN_ERROR;
- }
-
- if (!icalcomp)
- return CAL_BACKEND_OPEN_ERROR;
-
- /* FIXME: should we try to demangle XROOT components and
- * individual components as well?
- */
-
- if (icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT) {
- icalcomponent_free (icalcomp);
- return CAL_BACKEND_OPEN_ERROR;
- }
-
- priv->icalcomp = icalcomp;
-
- priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
- scan_vcalendar (cbfile);
-
- priv->uri = g_strdup (uristr);
-
- return CAL_BACKEND_OPEN_SUCCESS;
-}
-
-static CalBackendOpenStatus
-create_cal (CalBackendFile *cbfile, const char *uristr)
-{
- CalBackendFilePrivate *priv;
-
- priv = cbfile->priv;
-
- /* Create the new calendar information */
- priv->icalcomp = cal_util_new_top_level ();
-
- /* Create our internal data */
- priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
-
- priv->uri = g_strdup (uristr);
-
- mark_dirty (cbfile);
-
- return CAL_BACKEND_OPEN_SUCCESS;
-}
-
-/* Open handler for the file backend */
-static CalBackendOpenStatus
-cal_backend_file_open (CalBackend *backend, const char *uristr, gboolean only_if_exists)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- FILE *file;
- char *str_uri;
- GnomeVFSURI *uri;
- CalBackendOpenStatus status;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp == NULL, CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail (uristr != NULL, CAL_BACKEND_OPEN_ERROR);
-
- g_assert (priv->uri == NULL);
- g_assert (priv->comp_uid_hash == NULL);
-
- uri = gnome_vfs_uri_new (uristr);
- if (!uri)
- return CAL_BACKEND_OPEN_ERROR;
-
- if (!gnome_vfs_uri_is_local (uri)) {
- gnome_vfs_uri_unref (uri);
- return CAL_BACKEND_OPEN_ERROR;
- }
-
- str_uri = gnome_vfs_uri_to_string (uri,
- (GNOME_VFS_URI_HIDE_USER_NAME
- | GNOME_VFS_URI_HIDE_PASSWORD
- | GNOME_VFS_URI_HIDE_HOST_NAME
- | GNOME_VFS_URI_HIDE_HOST_PORT
- | GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD));
-
- /* Load! */
- file = fopen (str_uri, "r");
-
- if (file)
- status = open_cal (cbfile, str_uri, file);
- else {
- if (only_if_exists)
- status = CAL_BACKEND_OPEN_NOT_FOUND;
- else
- status = create_cal (cbfile, str_uri);
- }
-
- g_free (str_uri);
- gnome_vfs_uri_unref (uri);
-
- return status;
-}
-
-/* is_loaded handler for the file backend */
-static gboolean
-cal_backend_file_is_loaded (CalBackend *backend)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- return (priv->icalcomp != NULL);
-}
-
-/* is_remote handler for the file backend */
-static CalMode
-cal_backend_file_get_mode (CalBackend *backend)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- return CAL_MODE_LOCAL;
-}
-
-static void
-notify_mode (CalBackendFile *cbfile,
- GNOME_Evolution_Calendar_Listener_SetModeStatus status,
- GNOME_Evolution_Calendar_CalMode mode)
-{
- CalBackendFilePrivate *priv;
- GList *l;
-
- priv = cbfile->priv;
-
- for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
- Cal *cal;
-
- cal = CAL (l->data);
- cal_notify_mode (cal, status, mode);
- }
-}
-
-/* Set_mode handler for the file backend */
-static void
-cal_backend_file_set_mode (CalBackend *backend, CalMode mode)
-{
- notify_mode (CAL_BACKEND_FILE (backend),
- GNOME_Evolution_Calendar_Listener_MODE_NOT_SUPPORTED,
- GNOME_Evolution_Calendar_MODE_LOCAL);
-
-}
-
-/* Get_n_objects handler for the file backend */
-static int
-cal_backend_file_get_n_objects (CalBackend *backend, CalObjType type)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- int n;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, -1);
-
- n = 0;
-
- if (type & CALOBJ_TYPE_EVENT)
- n += g_list_length (priv->events);
-
- if (type & CALOBJ_TYPE_TODO)
- n += g_list_length (priv->todos);
-
- if (type & CALOBJ_TYPE_JOURNAL)
- n += g_list_length (priv->journals);
-
- return n;
-}
-
-/* Get_object handler for the file backend */
-static char *
-cal_backend_file_get_object (CalBackend *backend, const char *uid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- CalComponent *comp;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (uid != NULL, NULL);
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
- g_assert (priv->comp_uid_hash != NULL);
-
- comp = lookup_component (cbfile, uid);
-
- if (!comp)
- return NULL;
-
- return cal_component_get_as_string (comp);
-}
-
-/* Get_object handler for the file backend */
-static CalComponent *
-cal_backend_file_get_object_component (CalBackend *backend, const char *uid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (uid != NULL, NULL);
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
- g_assert (priv->comp_uid_hash != NULL);
-
- return lookup_component (cbfile, uid);
-}
-
-/* Get_object handler for the file backend */
-static char *
-cal_backend_file_get_timezone_object (CalBackend *backend, const char *tzid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- icaltimezone *zone;
- icalcomponent *icalcomp;
- char *ical_string;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (tzid != NULL, NULL);
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
- g_assert (priv->comp_uid_hash != NULL);
-
- zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
- if (!zone)
- return NULL;
-
- icalcomp = icaltimezone_get_component (zone);
- if (!icalcomp)
- return NULL;
-
- ical_string = icalcomponent_as_ical_string (icalcomp);
- /* We dup the string; libical owns that memory. */
- if (ical_string)
- return g_strdup (ical_string);
- else
- return NULL;
-}
-
-/* Builds a list of UIDs from a list of CalComponent objects */
-static void
-build_uids_list (GList **list, GList *components)
-{
- GList *l;
-
- for (l = components; l; l = l->next) {
- CalComponent *comp;
- const char *uid;
-
- comp = CAL_COMPONENT (l->data);
- cal_component_get_uid (comp, &uid);
- *list = g_list_prepend (*list, g_strdup (uid));
- }
-}
-
-/* Get_uids handler for the file backend */
-static GList *
-cal_backend_file_get_uids (CalBackend *backend, CalObjType type)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- GList *list;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- list = NULL;
-
- if (type & CALOBJ_TYPE_EVENT)
- build_uids_list (&list, priv->events);
-
- if (type & CALOBJ_TYPE_TODO)
- build_uids_list (&list, priv->todos);
-
- if (type & CALOBJ_TYPE_JOURNAL)
- build_uids_list (&list, priv->journals);
-
- return list;
-}
-
-/* function to resolve timezones */
-static icaltimezone *
-resolve_tzid (const char *tzid, gpointer user_data)
-{
- icalcomponent *vcalendar_comp = user_data;
-
- if (!tzid || !tzid[0])
- return NULL;
- else if (!strcmp (tzid, "UTC"))
- return icaltimezone_get_utc_timezone ();
-
- return icalcomponent_get_timezone (vcalendar_comp, tzid);
-}
-
-/* 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)
-{
- 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);
-
- old_uid = g_hash_table_lookup (uid_hash, uid);
- if (old_uid)
- return FALSE;
-
- g_hash_table_insert (uid_hash, (char *) uid, NULL);
- return FALSE;
-}
-
-/* Populates a hash table with the UIDs of the components that occur or recur
- * within a specific time range.
- */
-static void
-get_instances_in_range (GHashTable *uid_hash, GList *components, time_t start, time_t end, icaltimezone *default_zone)
-{
- GList *l;
-
- for (l = components; l; l = l->next) {
- CalComponent *comp;
- icalcomponent *icalcomp, *vcalendar_comp;
-
- comp = CAL_COMPONENT (l->data);
-
- /* Get the parent VCALENDAR component, so we can resolve
- TZIDs. */
- icalcomp = cal_component_get_icalcomponent (comp);
- vcalendar_comp = icalcomponent_get_parent (icalcomp);
- g_assert (vcalendar_comp != NULL);
-
- cal_recur_generate_instances (comp, start, end, add_instance, uid_hash, resolve_tzid, vcalendar_comp, default_zone);
- }
-}
-
-/* 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)
-{
- GList **list;
- const char *uid;
- char *uid_copy;
-
- list = data;
-
- uid = key;
- uid_copy = g_strdup (uid);
-
- *list = g_list_prepend (*list, uid_copy);
-}
-
-/* Get_objects_in_range handler for the file backend */
-static GList *
-cal_backend_file_get_objects_in_range (CalBackend *backend, CalObjType type,
- time_t start, time_t end)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- GList *event_list;
- GHashTable *uid_hash;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- g_return_val_if_fail (start != -1 && end != -1, NULL);
- g_return_val_if_fail (start <= end, NULL);
-
- uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
-
- if (type & CALOBJ_TYPE_EVENT)
- get_instances_in_range (uid_hash, priv->events, start, end,
- priv->default_zone);
-
- if (type & CALOBJ_TYPE_TODO)
- get_instances_in_range (uid_hash, priv->todos, start, end,
- priv->default_zone);
-
- if (type & CALOBJ_TYPE_JOURNAL)
- get_instances_in_range (uid_hash, priv->journals, start, end,
- priv->default_zone);
-
- event_list = NULL;
- g_hash_table_foreach (uid_hash, add_uid_to_list, &event_list);
- g_hash_table_destroy (uid_hash);
-
- return event_list;
-}
-
-static gboolean
-free_busy_instance (CalComponent *comp,
- time_t instance_start,
- time_t instance_end,
- gpointer data)
-{
- icalcomponent *vfb = data;
- icalproperty *prop;
- icalparameter *param;
- struct icalperiodtype ipt;
- icaltimezone *utc_zone;
-
- utc_zone = icaltimezone_get_utc_timezone ();
-
- ipt.start = icaltime_from_timet_with_zone (instance_start, FALSE, utc_zone);
- ipt.end = icaltime_from_timet_with_zone (instance_end, FALSE, utc_zone);
- ipt.duration = icaldurationtype_null_duration ();
-
- /* add busy information to the vfb component */
- prop = icalproperty_new (ICAL_FREEBUSY_PROPERTY);
- icalproperty_set_freebusy (prop, ipt);
-
- param = icalparameter_new_fbtype (ICAL_FBTYPE_BUSY);
- icalproperty_add_parameter (prop, param);
-
- icalcomponent_add_property (vfb, prop);
-
- return TRUE;
-}
-
-static icalcomponent *
-create_user_free_busy (CalBackendFile *cbfile, const char *address, const char *cn,
- time_t start, time_t end)
-{
- CalBackendFilePrivate *priv;
- GList *uids;
- GList *l;
- icalcomponent *vfb;
- icaltimezone *utc_zone;
-
- priv = cbfile->priv;
-
- /* create the (unique) VFREEBUSY object that we'll return */
- vfb = icalcomponent_new_vfreebusy ();
- if (address != NULL) {
- icalproperty *prop;
- icalparameter *param;
-
- prop = icalproperty_new_organizer (address);
- if (prop != NULL && cn != NULL) {
- param = icalparameter_new_cn (cn);
- icalproperty_add_parameter (prop, param);
- }
- if (prop != NULL)
- icalcomponent_add_property (vfb, prop);
- }
- utc_zone = icaltimezone_get_utc_timezone ();
- icalcomponent_set_dtstart (vfb, icaltime_from_timet_with_zone (start, FALSE, utc_zone));
- icalcomponent_set_dtend (vfb, icaltime_from_timet_with_zone (end, FALSE, utc_zone));
-
- /* add all objects in the given interval */
-
- uids = cal_backend_get_objects_in_range (CAL_BACKEND (cbfile),
- CALOBJ_TYPE_ANY, start, end);
- for (l = uids; l != NULL; l = l->next) {
- CalComponent *comp;
- icalcomponent *icalcomp, *vcalendar_comp;
- icalproperty *prop;
- char *uid = (char *) l->data;
-
- /* get the component from our internal list */
- comp = lookup_component (cbfile, uid);
- if (!comp)
- continue;
-
- icalcomp = cal_component_get_icalcomponent (comp);
- if (!icalcomp)
- continue;
-
- /* If the event is TRANSPARENT, skip it. */
- prop = icalcomponent_get_first_property (icalcomp,
- ICAL_TRANSP_PROPERTY);
- if (prop) {
- const char *transp_val = icalproperty_get_transp (prop);
- if (transp_val
- && !strcasecmp (transp_val, "TRANSPARENT"))
- continue;
- }
-
- vcalendar_comp = icalcomponent_get_parent (icalcomp);
- cal_recur_generate_instances (comp, start, end,
- free_busy_instance,
- vfb,
- resolve_tzid,
- vcalendar_comp,
- priv->default_zone);
-
- }
- cal_obj_uid_list_free (uids);
-
- return vfb;
-}
-
-/* Get_free_busy handler for the file backend */
-static GList *
-cal_backend_file_get_free_busy (CalBackend *backend, GList *users, time_t start, time_t end)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- gchar *address, *name;
- icalcomponent *vfb;
- char *calobj;
- GList *obj_list = NULL;
- GList *l;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
- g_return_val_if_fail (start != -1 && end != -1, NULL);
- g_return_val_if_fail (start <= end, NULL);
-
- if (users == NULL) {
- if (cal_backend_mail_account_get_default (priv->db, &address, &name)) {
- vfb = create_user_free_busy (cbfile, address, name, start, end);
- calobj = icalcomponent_as_ical_string (vfb);
- obj_list = g_list_append (obj_list, g_strdup (calobj));
- icalcomponent_free (vfb);
- g_free (address);
- g_free (name);
- }
- } else {
- for (l = users; l != NULL; l = l->next ) {
- address = l->data;
- if (cal_backend_mail_account_is_valid (priv->db, address, &name)) {
- vfb = create_user_free_busy (cbfile, address, name, start, end);
- calobj = icalcomponent_as_ical_string (vfb);
- obj_list = g_list_append (obj_list, g_strdup (calobj));
- icalcomponent_free (vfb);
- g_free (name);
- }
- }
- }
-
- return obj_list;
-}
-
-typedef struct
-{
- CalBackend *backend;
- CalObjType type;
- GList *changes;
- GList *change_ids;
-} CalBackendFileComputeChangesData;
-
-static void
-cal_backend_file_compute_changes_foreach_key (const char *key, gpointer data)
-{
- CalBackendFileComputeChangesData *be_data = data;
- char *calobj = cal_backend_get_object (be_data->backend, key);
-
- if (calobj == NULL) {
- CalComponent *comp;
- GNOME_Evolution_Calendar_CalObjChange *coc;
- char *calobj;
-
- comp = cal_component_new ();
- if (be_data->type == GNOME_Evolution_Calendar_TYPE_TODO)
- cal_component_set_new_vtype (comp, CAL_COMPONENT_TODO);
- else
- cal_component_set_new_vtype (comp, CAL_COMPONENT_EVENT);
-
- cal_component_set_uid (comp, key);
- calobj = cal_component_get_as_string (comp);
-
- coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
- coc->calobj = CORBA_string_dup (calobj);
- coc->type = GNOME_Evolution_Calendar_DELETED;
- be_data->changes = g_list_prepend (be_data->changes, coc);
- be_data->change_ids = g_list_prepend (be_data->change_ids, g_strdup (key));
-
- g_free (calobj);
- gtk_object_unref (GTK_OBJECT (comp));
- }
-}
-
-static GNOME_Evolution_Calendar_CalObjChangeSeq *
-cal_backend_file_compute_changes (CalBackend *backend, CalObjType type, const char *change_id)
-{
- char *filename;
- EDbHash *ehash;
- CalBackendFileComputeChangesData be_data;
- GNOME_Evolution_Calendar_CalObjChangeSeq *seq;
- GList *uids, *changes = NULL, *change_ids = NULL;
- GList *i, *j;
- int n;
-
- /* Find the changed ids - FIX ME, path should not be hard coded */
- if (type == GNOME_Evolution_Calendar_TYPE_TODO)
- filename = g_strdup_printf ("%s/evolution/local/Tasks/%s.db", g_get_home_dir (), change_id);
- else
- filename = g_strdup_printf ("%s/evolution/local/Calendar/%s.db", g_get_home_dir (), change_id);
- ehash = e_dbhash_new (filename);
- g_free (filename);
-
- uids = cal_backend_get_uids (backend, type);
-
- /* Calculate adds and modifies */
- for (i = uids; i != NULL; i = i->next) {
- GNOME_Evolution_Calendar_CalObjChange *coc;
- char *uid = i->data;
- char *calobj = cal_backend_get_object (backend, uid);
-
- g_assert (calobj != NULL);
-
- /* check what type of change has occurred, if any */
- switch (e_dbhash_compare (ehash, uid, calobj)) {
- case E_DBHASH_STATUS_SAME:
- break;
- case E_DBHASH_STATUS_NOT_FOUND:
- coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
- coc->calobj = CORBA_string_dup (calobj);
- coc->type = GNOME_Evolution_Calendar_ADDED;
- changes = g_list_prepend (changes, coc);
- change_ids = g_list_prepend (change_ids, g_strdup (uid));
- break;
- case E_DBHASH_STATUS_DIFFERENT:
- coc = GNOME_Evolution_Calendar_CalObjChange__alloc ();
- coc->calobj = CORBA_string_dup (calobj);
- coc->type = GNOME_Evolution_Calendar_MODIFIED;
- changes = g_list_prepend (changes, coc);
- change_ids = g_list_prepend (change_ids, g_strdup (uid));
- break;
- }
- }
-
- /* Calculate deletions */
- be_data.backend = backend;
- be_data.type = type;
- be_data.changes = changes;
- be_data.change_ids = change_ids;
- e_dbhash_foreach_key (ehash, (EDbHashFunc)cal_backend_file_compute_changes_foreach_key, &be_data);
- changes = be_data.changes;
- change_ids = be_data.change_ids;
-
- /* Build the sequence and update the hash */
- n = g_list_length (changes);
-
- seq = GNOME_Evolution_Calendar_CalObjChangeSeq__alloc ();
- seq->_length = n;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n);
- CORBA_sequence_set_release (seq, TRUE);
-
- for (i = changes, j = change_ids, n = 0; i != NULL; i = i->next, j = j->next, n++) {
- GNOME_Evolution_Calendar_CalObjChange *coc = i->data;
- GNOME_Evolution_Calendar_CalObjChange *seq_coc;
- char *uid = j->data;
-
- /* sequence building */
- seq_coc = &seq->_buffer[n];
- seq_coc->calobj = CORBA_string_dup (coc->calobj);
- seq_coc->type = coc->type;
-
- /* hash updating */
- if (coc->type == GNOME_Evolution_Calendar_ADDED
- || coc->type == GNOME_Evolution_Calendar_MODIFIED) {
- e_dbhash_add (ehash, uid, coc->calobj);
- } else {
- e_dbhash_remove (ehash, uid);
- }
-
- CORBA_free (coc);
- g_free (uid);
- }
- e_dbhash_write (ehash);
- e_dbhash_destroy (ehash);
-
- cal_obj_uid_list_free (uids);
- g_list_free (change_ids);
- g_list_free (changes);
-
- return seq;
-}
-
-/* Get_changes handler for the file backend */
-static GNOME_Evolution_Calendar_CalObjChangeSeq *
-cal_backend_file_get_changes (CalBackend *backend, CalObjType type, const char *change_id)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- return cal_backend_file_compute_changes (backend, type, change_id);
-}
-
-/* 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)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- int n_comp_alarms;
- GSList *comp_alarms;
- GSList *l;
- int i;
- GNOME_Evolution_Calendar_CalComponentAlarmsSeq *seq;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- g_return_val_if_fail (start != -1 && end != -1, NULL);
- g_return_val_if_fail (start <= end, NULL);
-
- /* Per RFC 2445, only VEVENTs and VTODOs can have alarms */
-
- n_comp_alarms = 0;
- comp_alarms = NULL;
-
- n_comp_alarms += cal_util_generate_alarms_for_list (priv->events, start, end,
- &comp_alarms, resolve_tzid,
- priv->icalcomp,
- priv->default_zone);
- n_comp_alarms += cal_util_generate_alarms_for_list (priv->todos, start, end,
- &comp_alarms, resolve_tzid,
- priv->icalcomp,
- priv->default_zone);
-
- seq = GNOME_Evolution_Calendar_CalComponentAlarmsSeq__alloc ();
- CORBA_sequence_set_release (seq, TRUE);
- seq->_length = n_comp_alarms;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalComponentAlarms_allocbuf (
- n_comp_alarms);
-
- for (l = comp_alarms, i = 0; l; l = l->next, i++) {
- CalComponentAlarms *alarms;
- char *comp_str;
-
- alarms = l->data;
-
- comp_str = cal_component_get_as_string (alarms->comp);
- seq->_buffer[i].calobj = CORBA_string_dup (comp_str);
- g_free (comp_str);
-
- cal_backend_util_fill_alarm_instances_seq (&seq->_buffer[i].alarms, alarms->alarms);
-
- cal_component_alarms_free (alarms);
- }
-
- g_slist_free (comp_alarms);
-
- return seq;
-}
-
-/* Get_alarms_for_object handler for the file backend */
-static GNOME_Evolution_Calendar_CalComponentAlarms *
-cal_backend_file_get_alarms_for_object (CalBackend *backend, const char *uid,
- time_t start, time_t end,
- gboolean *object_found)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- CalComponent *comp;
- char *comp_str;
- GNOME_Evolution_Calendar_CalComponentAlarms *corba_alarms;
- CalComponentAlarms *alarms;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- g_return_val_if_fail (uid != NULL, NULL);
- g_return_val_if_fail (start != -1 && end != -1, NULL);
- g_return_val_if_fail (start <= end, NULL);
- g_return_val_if_fail (object_found != NULL, NULL);
-
- comp = lookup_component (cbfile, uid);
- if (!comp) {
- *object_found = FALSE;
- return NULL;
- }
-
- *object_found = TRUE;
-
- comp_str = cal_component_get_as_string (comp);
- corba_alarms = GNOME_Evolution_Calendar_CalComponentAlarms__alloc ();
-
- corba_alarms->calobj = CORBA_string_dup (comp_str);
- g_free (comp_str);
-
- alarms = cal_util_generate_alarms_for_comp (comp, start, end, resolve_tzid, priv->icalcomp, priv->default_zone);
- if (alarms) {
- cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms, alarms->alarms);
- cal_component_alarms_free (alarms);
- } else
- cal_backend_util_fill_alarm_instances_seq (&corba_alarms->alarms, NULL);
-
- return corba_alarms;
-}
-
-/* Notifies a backend's clients that an object was updated */
-static void
-notify_update (CalBackendFile *cbfile, const char *uid)
-{
- CalBackendFilePrivate *priv;
- GList *l;
-
- priv = cbfile->priv;
-
- cal_backend_obj_updated (CAL_BACKEND (cbfile), uid);
-
- for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
- Cal *cal;
-
- cal = CAL (l->data);
- cal_notify_update (cal, uid);
- }
-}
-
-/* Notifies a backend's clients that an object was removed */
-static void
-notify_remove (CalBackendFile *cbfile, const char *uid)
-{
- CalBackendFilePrivate *priv;
- GList *l;
-
- priv = cbfile->priv;
-
- cal_backend_obj_removed (CAL_BACKEND (cbfile), uid);
-
- for (l = CAL_BACKEND (cbfile)->clients; l; l = l->next) {
- Cal *cal;
-
- cal = CAL (l->data);
- cal_notify_remove (cal, uid);
- }
-}
-
-/* Used from g_hash_table_foreach_remove(); removes and frees a category */
-static gboolean
-remove_category_cb (gpointer key, gpointer value, gpointer data)
-{
- Category *c;
-
- c = value;
- g_free (c->name);
- g_free (c);
-
- return TRUE;
-}
-
-/* Clears the table of removed categories */
-static void
-clean_removed_categories (CalBackendFile *cbfile)
-{
- CalBackendFilePrivate *priv;
-
- priv = cbfile->priv;
-
- g_hash_table_foreach_remove (priv->removed_categories,
- remove_category_cb,
- NULL);
-}
-
-
-/* Creates a CalComponent for the given icalcomponent and adds it to our
- cache. Note that the icalcomponent is not added to the toplevel
- icalcomponent here. That needs to be done elsewhere. It returns the uid
- of the added component, or NULL if it failed. */
-static const char*
-cal_backend_file_update_object (CalBackendFile *cbfile,
- icalcomponent *icalcomp)
-{
- CalComponent *old_comp;
- CalComponent *comp;
- const char *comp_uid;
-
- /* Create a CalComponent wrapper for the icalcomponent. */
- comp = cal_component_new ();
- if (!cal_component_set_icalcomponent (comp, icalcomp)) {
- gtk_object_unref (GTK_OBJECT (comp));
- return NULL;
- }
-
- /* Get the UID, and check it isn't empty. */
- cal_component_get_uid (comp, &comp_uid);
- if (!comp_uid || !comp_uid[0]) {
- gtk_object_unref (GTK_OBJECT (comp));
- return NULL;
- }
-
- /* Remove any old version of the component. */
- old_comp = lookup_component (cbfile, comp_uid);
- if (old_comp)
- remove_component (cbfile, old_comp);
-
- /* Now add the component to our local cache, but we pass FALSE as
- the last argument, since the libical component is assumed to have
- been added already. */
- add_component (cbfile, comp, FALSE);
-
- return comp_uid;
-}
-
-
-
-/* Update_objects handler for the file backend. */
-static gboolean
-cal_backend_file_update_objects (CalBackend *backend, const char *calobj)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- icalcomponent *toplevel_comp, *icalcomp = NULL;
- icalcomponent_kind kind;
- int old_n_categories, new_n_categories;
- icalcomponent *subcomp;
- gboolean retval = TRUE;
- GList *comp_uid_list = NULL, *elem;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
-
- g_return_val_if_fail (calobj != NULL, FALSE);
-
- /* Pull the component from the string and ensure that it is sane */
-
- toplevel_comp = icalparser_parse_string ((char *) calobj);
-
- if (!toplevel_comp)
- return FALSE;
-
- kind = icalcomponent_isa (toplevel_comp);
-
- if (kind == ICAL_VEVENT_COMPONENT
- || kind == ICAL_VTODO_COMPONENT
- || kind == ICAL_VJOURNAL_COMPONENT) {
- /* Create a temporary toplevel component and put the VEVENT
- or VTODO in it, to simplify the code below. */
- icalcomp = toplevel_comp;
- toplevel_comp = cal_util_new_top_level ();
- icalcomponent_add_component (toplevel_comp, icalcomp);
- } else if (kind != ICAL_VCALENDAR_COMPONENT) {
- /* We don't support this type of component */
- icalcomponent_free (toplevel_comp);
- return FALSE;
- }
-
- /* The list of removed categories must be empty because we are about to
- * start a new scanning process.
- */
- g_assert (g_hash_table_size (priv->removed_categories) == 0);
-
- old_n_categories = g_hash_table_size (priv->categories);
-
- /* Step throught the VEVENT/VTODOs being added, create CalComponents
- for them, and add them to our cache. */
- subcomp = icalcomponent_get_first_component (toplevel_comp,
- ICAL_ANY_COMPONENT);
- while (subcomp) {
- /* We ignore anything except VEVENT, VTODO and VJOURNAL
- components. */
- icalcomponent_kind child_kind = icalcomponent_isa (subcomp);
- if (child_kind == ICAL_VEVENT_COMPONENT
- || child_kind == ICAL_VTODO_COMPONENT
- || child_kind == ICAL_VJOURNAL_COMPONENT) {
- const char *comp_uid;
-
- comp_uid = cal_backend_file_update_object (cbfile,
- subcomp);
- if (comp_uid) {
- /* We add a copy of the UID to a list, so we
- can emit notification signals later. We do
- a g_strdup() in case any of the components
- get removed while we are emitting
- notification signals. */
- comp_uid_list = g_list_prepend (comp_uid_list,
- g_strdup (comp_uid));
- } else {
- retval = FALSE;
- }
- }
- subcomp = icalcomponent_get_next_component (toplevel_comp,
- ICAL_ANY_COMPONENT);
- }
-
- /* Merge the iCalendar components with our existing VCALENDAR,
- resolving any conflicting TZIDs. */
- icalcomponent_merge_component (priv->icalcomp, toplevel_comp);
-
- new_n_categories = g_hash_table_size (priv->categories);
-
- mark_dirty (cbfile);
-
- /* Now emit notification signals for all of the added components.
- We do this after adding them all to make sure the calendar is in a
- stable state before emitting signals. */
- for (elem = comp_uid_list; elem; elem = elem->next) {
- char *comp_uid = elem->data;
- notify_update (cbfile, comp_uid);
- g_free (comp_uid);
- }
- g_list_free (comp_uid_list);
-
- if (old_n_categories != new_n_categories ||
- g_hash_table_size (priv->removed_categories) != 0) {
- clean_removed_categories (cbfile);
- notify_categories_changed (cbfile);
- }
-
- return retval;
-}
-
-
-/* Remove_object handler for the file backend */
-static gboolean
-cal_backend_file_remove_object (CalBackend *backend, const char *uid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- CalComponent *comp;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
-
- g_return_val_if_fail (uid != NULL, FALSE);
-
- comp = lookup_component (cbfile, uid);
- if (!comp)
- return FALSE;
-
- /* The list of removed categories must be empty because we are about to
- * start a new scanning process.
- */
- g_assert (g_hash_table_size (priv->removed_categories) == 0);
-
- remove_component (cbfile, comp);
-
- mark_dirty (cbfile);
-
- notify_remove (cbfile, uid);
-
- if (g_hash_table_size (priv->removed_categories) != 0) {
- clean_removed_categories (cbfile);
- notify_categories_changed (cbfile);
- }
-
- return TRUE;
-}
-
-
-static icaltimezone*
-cal_backend_file_get_timezone (CalBackend *backend, const char *tzid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- if (!strcmp (tzid, "UTC"))
- return icaltimezone_get_utc_timezone ();
- else
- return icalcomponent_get_timezone (priv->icalcomp, tzid);
-}
-
-
-static icaltimezone*
-cal_backend_file_get_default_timezone (CalBackend *backend)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, NULL);
-
- return priv->default_zone;
-}
-
-
-static gboolean
-cal_backend_file_set_default_timezone (CalBackend *backend,
- const char *tzid)
-{
- CalBackendFile *cbfile;
- CalBackendFilePrivate *priv;
- icaltimezone *zone;
-
- cbfile = CAL_BACKEND_FILE (backend);
- priv = cbfile->priv;
-
- g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
-
- /* Look up the VTIMEZONE in our icalcomponent. */
- zone = icalcomponent_get_timezone (priv->icalcomp, tzid);
- if (!zone)
- return FALSE;
-
- /* Set the default timezone to it. */
- priv->default_zone = zone;
-
- return TRUE;
-}
-
diff --git a/calendar/pcs/cal-backend-file.h b/calendar/pcs/cal-backend-file.h
deleted file mode 100644
index c90feddea3..0000000000
--- a/calendar/pcs/cal-backend-file.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Evolution calendar - iCalendar file backend
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_FILE_H
-#define CAL_BACKEND_FILE_H
-
-#include <libgnome/gnome-defs.h>
-#include "cal-backend.h"
-
-BEGIN_GNOME_DECLS
-
-
-
-#define CAL_BACKEND_FILE_TYPE (cal_backend_file_get_type ())
-#define CAL_BACKEND_FILE(obj) (GTK_CHECK_CAST ((obj), CAL_BACKEND_FILE_TYPE, \
- CalBackendFile))
-#define CAL_BACKEND_FILE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CAL_BACKEND_FILE_TYPE, \
- CalBackendFileClass))
-#define IS_CAL_BACKEND_FILE(obj) (GTK_CHECK_TYPE ((obj), CAL_BACKEND_FILE_TYPE))
-#define IS_CAL_BACKEND_FILE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), CAL_BACKEND_FILE_TYPE))
-
-typedef struct _CalBackendFile CalBackendFile;
-typedef struct _CalBackendFileClass CalBackendFileClass;
-
-typedef struct _CalBackendFilePrivate CalBackendFilePrivate;
-
-struct _CalBackendFile {
- CalBackend backend;
-
- /* Private data */
- CalBackendFilePrivate *priv;
-};
-
-struct _CalBackendFileClass {
- CalBackendClass parent_class;
-};
-
-GtkType cal_backend_file_get_type (void);
-
-
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal-backend-util.c b/calendar/pcs/cal-backend-util.c
deleted file mode 100644
index 6ae480e30b..0000000000
--- a/calendar/pcs/cal-backend-util.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- 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 version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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;
- }
-}
-
-void
-cal_backend_mail_account_get (Bonobo_ConfigDatabase db,
- gint def,
- char **address,
- char **name)
-{
- gchar *path;
-
- *address = NULL;
- *name = NULL;
-
- /* get the identity info */
- path = g_strdup_printf ("/Mail/Accounts/identity_name_%d", def);
- *name = bonobo_config_get_string (db, path, NULL);
- g_free (path);
-
- path = g_strdup_printf ("/Mail/Accounts/identity_address_%d", def);
- *address = bonobo_config_get_string (db, path, NULL);
- g_free (path);
-}
-
-gboolean
-cal_backend_mail_account_get_default (Bonobo_ConfigDatabase db,
- char **address,
- char **name)
-{
- glong def, len;
-
- *address = NULL;
- *name = NULL;
-
- len = bonobo_config_get_long_with_default (db, "/Mail/Accounts/num", 0, NULL);
- def = bonobo_config_get_long_with_default (db, "/Mail/Accounts/default_account", 0, NULL);
-
- if (def < len)
- cal_backend_mail_account_get (db, def, address, name);
- else
- return FALSE;
-
- return TRUE;
-}
-
-gboolean
-cal_backend_mail_account_is_valid (Bonobo_ConfigDatabase db, char *user, char **name)
-{
- gchar *address;
- glong len, i;
-
- len = bonobo_config_get_long_with_default (db, "/Mail/Accounts/num", 0, NULL);
-
- for (i = 0; i < len; i++) {
- cal_backend_mail_account_get (db, i, &address, name);
- if (address != NULL && !strcmp (address, user)) {
- g_free (address);
- return TRUE;
- }
- g_free (address);
- g_free (*name);
- }
-
- return FALSE;
-}
diff --git a/calendar/pcs/cal-backend-util.h b/calendar/pcs/cal-backend-util.h
deleted file mode 100644
index f10267453a..0000000000
--- a/calendar/pcs/cal-backend-util.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- 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 version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <bonobo-conf/bonobo-config-database.h>
-#include <cal-backend.h>
-
-BEGIN_GNOME_DECLS
-
-/*
- * CORBA utility functions
- */
-
-void cal_backend_util_fill_alarm_instances_seq (
- GNOME_Evolution_Calendar_CalAlarmInstanceSeq *seq, GSList *alarms);
-
-/*
- * Functions for accessing mail configuration
- */
-
-void cal_backend_mail_account_get (Bonobo_ConfigDatabase db, gint def,
- char **address, char **name);
-gboolean cal_backend_mail_account_get_default (Bonobo_ConfigDatabase db,
- char **address, char **name);
-gboolean cal_backend_mail_account_is_valid (Bonobo_ConfigDatabase db,
- char *user, char **name);
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal-backend.c b/calendar/pcs/cal-backend.c
deleted file mode 100644
index e0dd3a713b..0000000000
--- a/calendar/pcs/cal-backend.c
+++ /dev/null
@@ -1,822 +0,0 @@
-/* -*- 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) 2000 Ximian, Inc.
- *
- * Authors: Federico Mena-Quintero <federico@ximian.com>
- * JP Rosevear <jpr@ximian.com>
- * Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include <gtk/gtkobject.h>
-#include <gtk/gtksignal.h>
-#include <gnome-xml/parser.h>
-#include <gnome-xml/parserInternals.h>
-#include <gnome-xml/xmlmemory.h>
-
-#include "cal-backend.h"
-#include "libversit/vcc.h"
-
-
-
-/* Signal IDs */
-enum {
- LAST_CLIENT_GONE,
- CAL_ADDED,
- OPENED,
- OBJ_UPDATED,
- OBJ_REMOVED,
- LAST_SIGNAL
-};
-
-static void cal_backend_class_init (CalBackendClass *class);
-
-static guint cal_backend_signals[LAST_SIGNAL];
-
-#define CLASS(backend) (CAL_BACKEND_CLASS (GTK_OBJECT (backend)->klass))
-
-
-
-/**
- * cal_backend_get_type:
- * @void:
- *
- * Registers the #CalBackend class if necessary, and returns the type ID
- * associated to it.
- *
- * Return value: The type ID of the #CalBackend class.
- **/
-GtkType
-cal_backend_get_type (void)
-{
- static GtkType cal_backend_type = 0;
-
- if (!cal_backend_type) {
- static const GtkTypeInfo cal_backend_info = {
- "CalBackend",
- sizeof (CalBackend),
- sizeof (CalBackendClass),
- (GtkClassInitFunc) cal_backend_class_init,
- (GtkObjectInitFunc) NULL,
- NULL, /* reserved_1 */
- NULL, /* reserved_2 */
- (GtkClassInitFunc) NULL
- };
-
- cal_backend_type =
- gtk_type_unique (GTK_TYPE_OBJECT, &cal_backend_info);
- }
-
- return cal_backend_type;
-}
-
-/* Class initialization function for the calendar backend */
-static void
-cal_backend_class_init (CalBackendClass *class)
-{
- GtkObjectClass *object_class;
-
- object_class = (GtkObjectClass *) class;
-
- cal_backend_signals[LAST_CLIENT_GONE] =
- gtk_signal_new ("last_client_gone",
- GTK_RUN_FIRST,
- object_class->type,
- 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,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalBackendClass, opened),
- gtk_marshal_NONE__ENUM,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_ENUM);
- cal_backend_signals[OBJ_UPDATED] =
- gtk_signal_new ("obj_updated",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalBackendClass, obj_updated),
- gtk_marshal_NONE__STRING,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_STRING);
- cal_backend_signals[OBJ_REMOVED] =
- gtk_signal_new ("obj_removed",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalBackendClass, obj_removed),
- gtk_marshal_NONE__STRING,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_STRING);
-
- gtk_object_class_add_signals (object_class, cal_backend_signals, LAST_SIGNAL);
-
- class->last_client_gone = NULL;
- class->opened = NULL;
- class->obj_updated = NULL;
- class->obj_removed = NULL;
-
- class->get_uri = NULL;
- class->open = NULL;
- class->is_loaded = NULL;
- class->get_mode = NULL;
- class->set_mode = NULL;
- class->get_n_objects = NULL;
- class->get_object = NULL;
- class->get_object_component = NULL;
- class->get_timezone_object = NULL;
- class->get_uids = NULL;
- class->get_objects_in_range = NULL;
- class->get_free_busy = NULL;
- class->get_changes = NULL;
- class->get_alarms_in_range = NULL;
- class->get_alarms_for_object = NULL;
- class->update_objects = NULL;
- class->remove_object = NULL;
-}
-
-
-
-/**
- * cal_backend_get_uri:
- * @backend: A calendar backend.
- *
- * Queries the URI of a calendar backend, which must already have an open
- * calendar.
- *
- * Return value: The URI where the calendar is stored.
- **/
-const char *
-cal_backend_get_uri (CalBackend *backend)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- g_assert (CLASS (backend)->get_uri != NULL);
- 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.
- * @cal: A calendar client interface object.
- *
- * Adds a calendar client interface object to a calendar @backend.
- * The calendar backend must already have an open calendar.
- **/
-void
-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);
-
- /* notify backend that a new Cal has been added */
- gtk_signal_emit (GTK_OBJECT (backend),
- cal_backend_signals[CAL_ADDED],
- cal);
-}
-
-/**
- * cal_backend_open:
- * @backend: A calendar backend.
- * @uristr: URI that contains the calendar data.
- * @only_if_exists: Whether the calendar should be opened only if it already
- * exists. If FALSE, a new calendar will be created when the specified @uri
- * does not exist.
- *
- * Opens a calendar backend with data from a calendar stored at the specified
- * URI.
- *
- * Return value: An operation status code.
- **/
-CalBackendOpenStatus
-cal_backend_open (CalBackend *backend, const char *uristr, gboolean only_if_exists)
-{
- CalBackendOpenStatus result;
-
- g_return_val_if_fail (backend != NULL, CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), CAL_BACKEND_OPEN_ERROR);
- g_return_val_if_fail (uristr != NULL, CAL_BACKEND_OPEN_ERROR);
-
- g_assert (CLASS (backend)->open != NULL);
- result = (* CLASS (backend)->open) (backend, uristr, only_if_exists);
-
- return result;
-}
-
-/**
- * cal_backend_is_loaded:
- * @backend: A calendar backend.
- *
- * Queries whether a calendar backend has been loaded yet.
- *
- * Return value: TRUE if the backend has been loaded with data, FALSE
- * otherwise.
- **/
-gboolean
-cal_backend_is_loaded (CalBackend *backend)
-{
- gboolean result;
-
- g_return_val_if_fail (backend != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE);
-
- g_assert (CLASS (backend)->is_loaded != NULL);
- result = (* CLASS (backend)->is_loaded) (backend);
-
- return result;
-}
-
-/**
- * cal_backend_get_mode:
- * @backend: A calendar backend.
- *
- * Queries whether a calendar backend is connected remotely.
- *
- * Return value: The current mode the calendar is in
- **/
-CalMode
-cal_backend_get_mode (CalBackend *backend)
-{
- CalMode result;
-
- g_return_val_if_fail (backend != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE);
-
- g_assert (CLASS (backend)->get_mode != NULL);
- result = (* CLASS (backend)->get_mode) (backend);
-
- return result;
-}
-
-
-/**
- * cal_backend_set_mode:
- * @backend: A calendar backend
- * @mode: Mode to change to
- *
- * Sets the mode of the calendar
- *
- **/
-void
-cal_backend_set_mode (CalBackend *backend, CalMode mode)
-{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (IS_CAL_BACKEND (backend));
-
- g_assert (CLASS (backend)->set_mode != NULL);
- (* CLASS (backend)->set_mode) (backend, mode);
-}
-
-/**
- * cal_backend_get_n_objects:
- * @backend: A calendar backend.
- * @type: Types of objects that will be included in the count.
- *
- * Queries the number of calendar objects of a particular type.
- *
- * Return value: Number of objects of the specified @type.
- **/
-int
-cal_backend_get_n_objects (CalBackend *backend, CalObjType type)
-{
- g_return_val_if_fail (backend != NULL, -1);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), -1);
-
- g_assert (CLASS (backend)->get_n_objects != NULL);
- return (* CLASS (backend)->get_n_objects) (backend, type);
-}
-
-/**
- * cal_backend_get_object:
- * @backend: A calendar backend.
- * @uid: Unique identifier for a calendar object.
- *
- * Queries a calendar backend for a calendar object based on its unique
- * identifier.
- *
- * Return value: The string representation of a complete calendar wrapping the
- * the sought object, or NULL if no object had the specified UID.
- **/
-char *
-cal_backend_get_object (CalBackend *backend, const char *uid)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (uid != NULL, NULL);
-
- g_assert (CLASS (backend)->get_object != NULL);
- return (* CLASS (backend)->get_object) (backend, uid);
-}
-
-/**
- * cal_backend_get_object_component:
- * @backend: A calendar backend.
- * @uid: Unique identifier for a calendar object.
- *
- * Queries a calendar backend for a calendar object based on its unique
- * identifier. It returns the CalComponent rather than the string
- * representation.
- *
- * Return value: The CalComponent of the sought object, or NULL if no object
- * had the specified UID.
- **/
-CalComponent *
-cal_backend_get_object_component (CalBackend *backend, const char *uid)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (uid != NULL, NULL);
-
- g_assert (CLASS (backend)->get_object_component != NULL);
- return (* CLASS (backend)->get_object_component) (backend, uid);
-}
-
-/**
- * cal_backend_get_timezone_object:
- * @backend: A calendar backend.
- * @tzid: Unique identifier for a calendar VTIMEZONE object.
- *
- * Queries a calendar backend for a VTIMEZONE calendar object based on its
- * unique TZID identifier.
- *
- * Return value: The string representation of a VTIMEZONE component, or NULL
- * if no VTIMEZONE object had the specified TZID.
- **/
-char *
-cal_backend_get_timezone_object (CalBackend *backend, const char *tzid)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (tzid != NULL, NULL);
-
- g_assert (CLASS (backend)->get_timezone_object != NULL);
- return (* CLASS (backend)->get_timezone_object) (backend, 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.
- *
- * 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. The list should be
- * freed using the cal_obj_uid_list_free() function.
- **/
-GList *
-cal_backend_get_uids (CalBackend *backend, CalObjType type)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- g_assert (CLASS (backend)->get_uids != NULL);
- return (* CLASS (backend)->get_uids) (backend, type);
-}
-
-
-/**
- * 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 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_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_objects_in_range != NULL);
- return (* CLASS (backend)->get_objects_in_range) (backend, type, start, end);
-}
-
-/**
- * cal_backend_get_free_busy:
- * @backend: A calendar backend.
- * @users: List of users to get free/busy information for.
- * @start: Start time for query.
- * @end: End time for query.
- *
- * Gets a free/busy object for the given time interval
- *
- * Return value: a list of CalObj's
- **/
-GList *
-cal_backend_get_free_busy (CalBackend *backend, GList *users, 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_free_busy != NULL);
- return (* CLASS (backend)->get_free_busy) (backend, users, start, end);
-}
-
-/**
- * cal_backend_get_changes:
- * @backend: A calendar backend
- * @type: Bitmask with types of objects to return.
- * @change_id: A unique uid for the callers change list
- *
- * Builds a sequence of objects and the type of change that occurred on them since
- * the last time the give change_id was seen
- *
- * Return value: A list of the objects that changed and the type of change
- **/
-GNOME_Evolution_Calendar_CalObjChangeSeq *
-cal_backend_get_changes (CalBackend *backend, CalObjType type, const char *change_id)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (change_id != NULL, NULL);
-
- g_assert (CLASS (backend)->get_changes != NULL);
- return (* CLASS (backend)->get_changes) (backend, type, change_id);
-}
-
-/**
- * cal_backend_get_alarms_in_range:
- * @backend: A calendar backend.
- * @start: Start time for query.
- * @end: End time for query.
- * @valid_range: Return value that says whether the range is valid or not.
- *
- * Builds a sorted list of the alarms that trigger in the specified time range.
- *
- * Return value: A sequence of component alarm instances structures, or NULL
- * if @valid_range returns FALSE.
- **/
-GNOME_Evolution_Calendar_CalComponentAlarmsSeq *
-cal_backend_get_alarms_in_range (CalBackend *backend, time_t start, time_t end,
- gboolean *valid_range)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (valid_range != NULL, NULL);
-
- g_assert (CLASS (backend)->get_alarms_in_range != NULL);
-
- if (!(start != -1 && end != -1 && start <= end)) {
- *valid_range = FALSE;
- return NULL;
- } else {
- *valid_range = TRUE;
- return (* CLASS (backend)->get_alarms_in_range) (backend, start, end);
- }
-}
-
-/**
- * cal_backend_get_alarms_for_object:
- * @backend: A calendar backend.
- * @uid: Unique identifier for a calendar object.
- * @start: Start time for query.
- * @end: End time for query.
- * @result: Return value for the result code for the operation.
- *
- * Builds a sorted list of the alarms of the specified event that trigger in a
- * particular time range.
- *
- * Return value: A structure of the component's alarm instances, or NULL if @result
- * returns something other than #CAL_BACKEND_GET_ALARMS_SUCCESS.
- **/
-GNOME_Evolution_Calendar_CalComponentAlarms *
-cal_backend_get_alarms_for_object (CalBackend *backend, const char *uid,
- time_t start, time_t end,
- CalBackendGetAlarmsForObjectResult *result)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (uid != NULL, NULL);
- g_return_val_if_fail (result != NULL, NULL);
-
- g_assert (CLASS (backend)->get_alarms_for_object != NULL);
-
- if (!(start != -1 && end != -1 && start <= end)) {
- *result = CAL_BACKEND_GET_ALARMS_INVALID_RANGE;
- return NULL;
- } else {
- gboolean object_found;
- GNOME_Evolution_Calendar_CalComponentAlarms *alarms;
-
- alarms = (* CLASS (backend)->get_alarms_for_object) (backend, uid, start, end,
- &object_found);
-
- if (object_found)
- *result = CAL_BACKEND_GET_ALARMS_SUCCESS;
- else
- *result = CAL_BACKEND_GET_ALARMS_NOT_FOUND;
-
- return alarms;
- }
-}
-
-/**
- * cal_backend_update_objects:
- * @backend: A calendar backend.
- * @calobj: String representation of the new calendar object(s).
- *
- * Updates an object in a calendar backend. It will replace any existing
- * object that has the same UID as the specified one. The backend will in
- * turn notify all of its clients about the change.
- *
- * Return value: TRUE on success, FALSE on being passed an invalid object or one
- * with an unsupported type.
- **/
-gboolean
-cal_backend_update_objects (CalBackend *backend, const char *calobj)
-{
- g_return_val_if_fail (backend != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE);
- g_return_val_if_fail (calobj != NULL, FALSE);
-
- g_assert (CLASS (backend)->update_objects != NULL);
- return (* CLASS (backend)->update_objects) (backend, calobj);
-}
-
-/**
- * cal_backend_remove_object:
- * @backend: A calendar backend.
- * @uid: Unique identifier of the object to remove.
- *
- * Removes an object in a calendar backend. The backend will notify all of its
- * clients about the change.
- *
- * Return value: TRUE on success, FALSE on being passed an UID for an object
- * that does not exist in the backend.
- **/
-gboolean
-cal_backend_remove_object (CalBackend *backend, const char *uid)
-{
- g_return_val_if_fail (backend != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE);
- g_return_val_if_fail (uid != NULL, FALSE);
-
- g_assert (CLASS (backend)->remove_object != NULL);
- return (* CLASS (backend)->remove_object) (backend, uid);
-}
-
-/**
- * cal_backend_last_client_gone:
- * @backend: A calendar backend.
- *
- * Emits the "last_client_gone" signal of a calendar backend. This function is
- * to be used only by backend implementations.
- **/
-void
-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_opened:
- * @backend: A calendar backend.
- * @status: Open status code.
- *
- * Emits the "opened" signal of a calendar backend. This function is to be used
- * only by backend implementations.
- **/
-void
-cal_backend_opened (CalBackend *backend, CalBackendOpenStatus status)
-{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (IS_CAL_BACKEND (backend));
-
- gtk_signal_emit (GTK_OBJECT (backend), cal_backend_signals[OPENED],
- status);
-}
-
-/**
- * cal_backend_obj_updated:
- * @backend: A calendar backend.
- * @uid: Unique identifier of the component that was updated.
- *
- * Emits the "obj_updated" signal of a calendar backend. This function is to be
- * used only by backend implementations.
- **/
-void
-cal_backend_obj_updated (CalBackend *backend, const char *uid)
-{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (IS_CAL_BACKEND (backend));
- g_return_if_fail (uid != NULL);
-
- gtk_signal_emit (GTK_OBJECT (backend), cal_backend_signals[OBJ_UPDATED],
- uid);
-}
-
-/**
- * cal_backend_obj_removed:
- * @backend: A calendar backend.
- * @uid: Unique identifier of the component that was removed.
- *
- * Emits the "obj_removed" signal of a calendar backend. This function is to be
- * used only by backend implementations.
- **/
-void
-cal_backend_obj_removed (CalBackend *backend, const char *uid)
-{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (IS_CAL_BACKEND (backend));
- g_return_if_fail (uid != NULL);
-
- gtk_signal_emit (GTK_OBJECT (backend), cal_backend_signals[OBJ_REMOVED],
- uid);
-}
-
-
-/**
- * cal_backend_get_timezone:
- * @backend: A calendar backend.
- * @tzid: Unique identifier of a VTIMEZONE object. Note that this must not be
- * NULL.
- *
- * Returns the icaltimezone* corresponding to the TZID, or NULL if the TZID
- * can't be found.
- *
- * Returns: The icaltimezone* corresponding to the given TZID, or NULL.
- **/
-icaltimezone*
-cal_backend_get_timezone (CalBackend *backend, const char *tzid)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (tzid != NULL, NULL);
-
- g_assert (CLASS (backend)->get_timezone != NULL);
- return (* CLASS (backend)->get_timezone) (backend, tzid);
-}
-
-
-/**
- * cal_backend_get_default_timezone:
- * @backend: A calendar backend.
- *
- * Returns the default timezone for the calendar, which is used to resolve
- * DATE and floating DATE-TIME values.
- *
- * Returns: The default icaltimezone* for the calendar.
- **/
-icaltimezone*
-cal_backend_get_default_timezone (CalBackend *backend)
-{
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- g_assert (CLASS (backend)->get_default_timezone != NULL);
- return (* CLASS (backend)->get_default_timezone) (backend);
-}
-
-
-/**
- * cal_backend_set_default_timezone:
- * @backend: A calendar backend.
- * @tzid: The TZID identifying the timezone.
- *
- * Sets the default timezone for the calendar, which is used to resolve
- * DATE and floating DATE-TIME values.
- *
- * Returns: TRUE if the VTIMEZONE data for the timezone was found, or FALSE if
- * not.
- **/
-gboolean
-cal_backend_set_default_timezone (CalBackend *backend, const char *tzid)
-{
- g_return_val_if_fail (backend != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), FALSE);
- g_return_val_if_fail (tzid != NULL, FALSE);
-
- g_assert (CLASS (backend)->set_default_timezone != NULL);
- return (* CLASS (backend)->set_default_timezone) (backend, tzid);
-}
-
diff --git a/calendar/pcs/cal-backend.h b/calendar/pcs/cal-backend.h
deleted file mode 100644
index e5f10842b4..0000000000
--- a/calendar/pcs/cal-backend.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/* -*- 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) 2000 Ximian, Inc.
- *
- * Authors: Federico Mena-Quintero <federico@ximian.com>
- * Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_H
-#define CAL_BACKEND_H
-
-#include <libgnome/gnome-defs.h>
-#include <cal-util/cal-util.h>
-#include <cal-util/cal-component.h>
-#include "evolution-calendar.h"
-#include "cal-common.h"
-#include "cal.h"
-
-BEGIN_GNOME_DECLS
-
-
-
-#define CAL_BACKEND_TYPE (cal_backend_get_type ())
-#define CAL_BACKEND(obj) (GTK_CHECK_CAST ((obj), CAL_BACKEND_TYPE, CalBackend))
-#define CAL_BACKEND_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CAL_BACKEND_TYPE, \
- CalBackendClass))
-#define IS_CAL_BACKEND(obj) (GTK_CHECK_TYPE ((obj), CAL_BACKEND_TYPE))
-#define IS_CAL_BACKEND_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), CAL_BACKEND_TYPE))
-
-/* Open status values */
-typedef enum {
- CAL_BACKEND_OPEN_SUCCESS, /* Loading OK */
- CAL_BACKEND_OPEN_ERROR, /* We need better error reporting in libversit */
- CAL_BACKEND_OPEN_NOT_FOUND
-} CalBackendOpenStatus;
-
-/* Result codes for ::get_alarms_in_range() */
-typedef enum {
- CAL_BACKEND_GET_ALARMS_SUCCESS,
- CAL_BACKEND_GET_ALARMS_NOT_FOUND,
- CAL_BACKEND_GET_ALARMS_INVALID_RANGE
-} CalBackendGetAlarmsForObjectResult;
-
-struct _CalBackend {
- GtkObject object;
- GList *clients;
-};
-
-struct _CalBackendClass {
- GtkObjectClass parent_class;
-
- /* 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);
- void (* obj_removed) (CalBackend *backend, const char *uid);
-
- /* Virtual methods */
- const char *(* get_uri) (CalBackend *backend);
-
- CalBackendOpenStatus (* open) (CalBackend *backend, const char *uristr,
- gboolean only_if_exists);
-
- gboolean (* is_loaded) (CalBackend *backend);
-
- /* Mode relate virtual methods */
- CalMode (* get_mode) (CalBackend *backend);
- void (* set_mode) (CalBackend *backend, CalMode mode);
-
- /* General object acquirement and information related virtual methods */
- int (* get_n_objects) (CalBackend *backend, CalObjType type);
- 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);
- GList *(* get_uids) (CalBackend *backend, CalObjType type);
-
- GList *(* get_objects_in_range) (CalBackend *backend, CalObjType type,
- time_t start, time_t end);
- GList *(* get_free_busy) (CalBackend *backend, GList *users, time_t start, time_t end);
-
- /* Change related virtual methods */
- GNOME_Evolution_Calendar_CalObjChangeSeq * (* get_changes) (
- CalBackend *backend, CalObjType type, const char *change_id);
-
- /* Alarm related virtual methods */
- GNOME_Evolution_Calendar_CalComponentAlarmsSeq *(* get_alarms_in_range) (
- CalBackend *backend, time_t start, time_t end);
- GNOME_Evolution_Calendar_CalComponentAlarms *(* get_alarms_for_object) (
- CalBackend *backend, const char *uid,
- time_t start, time_t end, gboolean *object_found);
-
- /* Object manipulation virtual methods */
- gboolean (* update_objects) (CalBackend *backend, const char *calobj);
- gboolean (* remove_object) (CalBackend *backend, const char *uid);
-
- /* Timezone related virtual methods */
- icaltimezone *(* get_timezone) (CalBackend *backend, const char *tzid);
- icaltimezone *(* get_default_timezone) (CalBackend *backend);
- gboolean (* set_default_timezone) (CalBackend *backend, const char *tzid);
-};
-
-GtkType cal_backend_get_type (void);
-
-const char *cal_backend_get_uri (CalBackend *backend);
-
-void cal_backend_add_cal (CalBackend *backend, Cal *cal);
-
-CalBackendOpenStatus cal_backend_open (CalBackend *backend, const char *uristr,
- gboolean only_if_exists);
-
-gboolean cal_backend_is_loaded (CalBackend *backend);
-
-CalMode cal_backend_get_mode (CalBackend *backend);
-void cal_backend_set_mode (CalBackend *backend, CalMode mode);
-
-int cal_backend_get_n_objects (CalBackend *backend, CalObjType type);
-
-char *cal_backend_get_object (CalBackend *backend, const char *uid);
-
-CalComponent *cal_backend_get_object_component (CalBackend *backend, const char *uid);
-
-gboolean cal_backend_set_default_timezone (CalBackend *backend, const char *tzid);
-
-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,
- time_t start, time_t end);
-
-GList *cal_backend_get_free_busy (CalBackend *backend, GList *users, time_t start, time_t end);
-
-GNOME_Evolution_Calendar_CalObjChangeSeq * cal_backend_get_changes (
- CalBackend *backend, CalObjType type, const char *change_id);
-
-GNOME_Evolution_Calendar_CalComponentAlarmsSeq *cal_backend_get_alarms_in_range (
- CalBackend *backend, time_t start, time_t end, gboolean *valid_range);
-
-GNOME_Evolution_Calendar_CalComponentAlarms *cal_backend_get_alarms_for_object (
- CalBackend *backend, const char *uid,
- time_t start, time_t end,
- CalBackendGetAlarmsForObjectResult *result);
-
-
-gboolean cal_backend_update_objects (CalBackend *backend, const char *calobj);
-
-gboolean cal_backend_remove_object (CalBackend *backend, const char *uid);
-
-icaltimezone* cal_backend_get_timezone (CalBackend *backend, const char *tzid);
-icaltimezone* cal_backend_get_default_timezone (CalBackend *backend);
-
-void cal_backend_last_client_gone (CalBackend *backend);
-void cal_backend_opened (CalBackend *backend, CalBackendOpenStatus status);
-void cal_backend_obj_updated (CalBackend *backend, const char *uid);
-void cal_backend_obj_removed (CalBackend *backend, const char *uid);
-
-
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal-common.h b/calendar/pcs/cal-common.h
deleted file mode 100644
index 228a67fcfe..0000000000
--- a/calendar/pcs/cal-common.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Evolution calendar server - common declarations
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_COMMON_H
-#define CAL_COMMON_H
-
-#include <libgnome/gnome-defs.h>
-
-BEGIN_GNOME_DECLS
-
-
-
-typedef struct _CalBackend CalBackend;
-typedef struct _CalBackendClass CalBackendClass;
-
-typedef struct _Cal Cal;
-typedef struct _CalClass CalClass;
-
-
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c
deleted file mode 100644
index 1df133ea90..0000000000
--- a/calendar/pcs/cal-factory.c
+++ /dev/null
@@ -1,820 +0,0 @@
-/* Evolution calendar factory
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <gtk/gtksignal.h>
-#include <liboaf/liboaf.h>
-#include "e-util/e-url.h"
-#include "evolution-calendar.h"
-#include "cal.h"
-#include "cal-backend.h"
-#include "cal-factory.h"
-#include "job.h"
-
-#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
-#define DEFAULT_CAL_FACTORY_OAF_ID "OAFIID:GNOME_Evolution_Wombat_CalendarFactory"
-
-static BonoboXObjectClass *parent_class;
-
-/* Private part of the CalFactory structure */
-struct _CalFactoryPrivate {
- /* Hash table from URI method strings to GtkType * for backend class types */
- GHashTable *methods;
-
- /* Hash table from GnomeVFSURI structures to CalBackend objects */
- GHashTable *backends;
-
- /* OAFIID of the factory */
- char *iid;
-
- /* Whether we have been registered with OAF yet */
- guint registered : 1;
-};
-
-typedef struct
-{
- CalFactory *factory;
- GNOME_Evolution_Calendar_CalMode mode;
- GNOME_Evolution_Calendar_StringSeq *list;
-} CalFactoryUriData;
-
-/* Signal IDs */
-enum SIGNALS {
- LAST_CALENDAR_GONE,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
-
-/* Frees a method/GtkType * pair from the methods hash table */
-static void
-free_method (gpointer key, gpointer value, gpointer data)
-{
- char *method;
- GtkType *type;
-
- method = key;
- type = value;
-
- g_free (method);
- g_free (type);
-}
-
-/* Frees a uri/backend pair from the backends hash table */
-static void
-free_backend (gpointer key, gpointer value, gpointer data)
-{
- char *uri;
- CalBackend *backend;
-
- uri = key;
- backend = value;
-
- g_free (uri);
- gtk_object_unref (GTK_OBJECT (backend));
-}
-
-/* Opening calendars */
-
-/* Looks up a calendar backend in a factory's hash table of uri->cal. If
- * *non-NULL, orig_uri_return will be set to point to the original key in the
- * *hash table.
- */
-static CalBackend *
-lookup_backend (CalFactory *factory, const char *uristr, char **orig_uri_return)
-{
- CalFactoryPrivate *priv;
- EUri *uri;
- char *tmp;
- gboolean found;
- gpointer orig_key;
- gpointer data;
-
- priv = factory->priv;
-
- uri = e_uri_new (uristr);
- if (!uri) {
- if (orig_uri_return)
- *orig_uri_return = NULL;
-
- return NULL;
- }
-
- tmp = e_uri_to_string (uri, FALSE);
- found = g_hash_table_lookup_extended (priv->backends, tmp, &orig_key, &data);
- g_free (tmp);
- e_uri_free (uri);
-
- if (found) {
- if (orig_uri_return)
- *orig_uri_return = orig_key;
-
- return CAL_BACKEND (data);
- } else {
- if (orig_uri_return)
- *orig_uri_return = FALSE;
-
- return NULL;
- }
-}
-
-/* Callback used when a backend loses its last connected client */
-static void
-backend_last_client_gone_cb (CalBackend *backend, gpointer data)
-{
- CalFactory *factory;
- CalFactoryPrivate *priv;
- CalBackend *ret_backend;
- const char *uristr;
- char *orig_uristr;
-
- fprintf (stderr, "backend_last_client_gone_cb() called!\n");
-
- factory = CAL_FACTORY (data);
- priv = factory->priv;
-
- /* Remove the backend from the hash table */
-
- uristr = cal_backend_get_uri (backend);
- g_assert (uristr != NULL);
-
- ret_backend = lookup_backend (factory, uristr, &orig_uristr);
- g_assert (ret_backend != NULL);
- g_assert (ret_backend == backend);
-
- g_hash_table_remove (priv->backends, orig_uristr);
- g_free (orig_uristr);
-
- gtk_object_unref (GTK_OBJECT (backend));
-
- /* Notify upstream if there are no more backends */
-
- if (g_hash_table_size (priv->backends) == 0)
- gtk_signal_emit (GTK_OBJECT (factory), signals[LAST_CALENDAR_GONE]);
-}
-
-/* Adds a backend to the calendar factory's hash table */
-static void
-add_backend (CalFactory *factory, const char *uristr, CalBackend *backend)
-{
- CalFactoryPrivate *priv;
- EUri *uri;
- char *tmp;
-
- priv = factory->priv;
-
- uri = e_uri_new (uristr);
- if (!uri)
- return;
-
- tmp = e_uri_to_string (uri, FALSE);
- g_hash_table_insert (priv->backends, tmp, backend);
- e_uri_free (uri);
-
- gtk_signal_connect (GTK_OBJECT (backend), "last_client_gone",
- GTK_SIGNAL_FUNC (backend_last_client_gone_cb),
- factory);
-}
-
-/* Tries to launch a backend for the method of the specified URI. If there is
- * no such method registered in the factory, it sends the listener the
- * MethodNotSupported error code.
- */
-static CalBackend *
-launch_backend_for_uri (CalFactory *factory,
- const char *uristr,
- GNOME_Evolution_Calendar_Listener listener)
-{
- CalFactoryPrivate *priv;
- const char *method;
- GtkType *type;
- CalBackend *backend;
- EUri *uri;
-
- priv = factory->priv;
-
- uri = e_uri_new (uristr);
- if (!uri)
- return NULL;
-
- method = uri->protocol;
- type = g_hash_table_lookup (priv->methods, method);
- e_uri_free (uri);
-
- if (!type) {
- CORBA_Environment ev;
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_METHOD_NOT_SUPPORTED,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("launch_backend_for_uri(): could not notify the listener");
-
- CORBA_exception_free (&ev);
- return NULL;
- }
-
- backend = gtk_type_new (*type);
- if (!backend)
- g_message ("launch_backend_for_uri(): could not launch the backend");
-
- return backend;
-}
-
-/* Opens a calendar backend and puts it in the factory's backend hash table */
-static CalBackend *
-open_backend (CalFactory *factory, const char *uristr, gboolean only_if_exists,
- GNOME_Evolution_Calendar_Listener listener)
-{
- CalFactoryPrivate *priv;
- CalBackend *backend;
- CalBackendOpenStatus status;
- CORBA_Environment ev;
-
- priv = factory->priv;
-
- backend = launch_backend_for_uri (factory, uristr, listener);
- if (!backend)
- return NULL;
-
- status = cal_backend_open (backend, uristr, only_if_exists);
-
- switch (status) {
- case CAL_BACKEND_OPEN_SUCCESS:
- add_backend (factory, uristr, backend);
- return backend;
-
- case CAL_BACKEND_OPEN_ERROR:
- gtk_object_unref (GTK_OBJECT (backend));
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("open_backend(): could not notify the listener");
-
- CORBA_exception_free (&ev);
- return NULL;
-
- case CAL_BACKEND_OPEN_NOT_FOUND:
- gtk_object_unref (GTK_OBJECT (backend));
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_NOT_FOUND,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("open_backend(): could not notify the listener");
-
- CORBA_exception_free (&ev);
- return NULL;
-
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-/* Adds a listener to a calendar backend by creating a calendar client interface
- * object.
- */
-static void
-add_calendar_client (CalFactory *factory,
- CalBackend *backend,
- GNOME_Evolution_Calendar_Listener listener)
-{
- Cal *cal;
- CORBA_Environment ev;
-
- cal = cal_new (backend, listener);
- if (!cal) {
- g_message ("add_calendar_client(): could not create the calendar client interface");
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("add_calendar_client(): could not notify the listener");
-
- CORBA_exception_free (&ev);
- return;
- }
-
- cal_backend_add_cal (backend, cal);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_SUCCESS,
- BONOBO_OBJREF (cal),
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_message ("add_calendar_client(): could not notify the listener");
- bonobo_object_unref (BONOBO_OBJECT (cal));
- }
-
- CORBA_exception_free (&ev);
-}
-
-/* Add a uri to a string list */
-static void
-add_uri (gpointer key, gpointer value, gpointer data)
-{
- CalFactoryUriData *cfud = data;
- CalFactory *factory = cfud->factory;
- GNOME_Evolution_Calendar_StringSeq *list = cfud->list;
- GNOME_Evolution_Calendar_CalMode mode = cfud->mode;
- char *uri_string = key;
- CalBackend *backend;
-
- switch (mode) {
- case GNOME_Evolution_Calendar_MODE_LOCAL:
- backend = lookup_backend (factory, uri_string, NULL);
- if (backend == NULL || cal_backend_get_mode (backend) != CAL_MODE_LOCAL)
- return;
- break;
- case GNOME_Evolution_Calendar_MODE_REMOTE:
- backend = lookup_backend (factory, uri_string, NULL);
- if (backend == NULL || cal_backend_get_mode (backend) != CAL_MODE_REMOTE)
- return;
- break;
- case GNOME_Evolution_Calendar_MODE_ANY:
- break;
- }
-
- list->_buffer[list->_length] = CORBA_string_dup (uri_string);
- list->_length++;
-}
-
-/* Job data */
-typedef struct {
- CalFactory *factory;
- char *uri;
- gboolean only_if_exists;
- GNOME_Evolution_Calendar_Listener listener;
-} OpenJobData;
-
-/* Job handler for the open calendar command */
-static void
-open_fn (gpointer data)
-{
- OpenJobData *jd;
- CalFactory *factory;
- gboolean only_if_exists;
- GNOME_Evolution_Calendar_Listener listener;
- CalBackend *backend;
- CORBA_Environment ev;
- char *uri_string;
-
- jd = data;
- g_assert (jd->uri != NULL);
-
- /* Check the URI */
- uri_string = g_strdup (jd->uri);
- g_free (jd->uri);
-
- only_if_exists = jd->only_if_exists;
- factory = jd->factory;
- listener = jd->listener;
- g_free (jd);
-
- if (!uri_string) {
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalOpened (
- listener,
- GNOME_Evolution_Calendar_Listener_ERROR,
- CORBA_OBJECT_NIL,
- &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("open_fn(): Could not notify the listener!");
-
- CORBA_exception_free (&ev);
- goto out;
- }
-
- /* Look up the backend and create it if needed */
-
- backend = lookup_backend (factory, uri_string, NULL);
-
- if (!backend)
- backend = open_backend (factory, uri_string, only_if_exists, listener);
-
- if (backend)
- add_calendar_client (factory, backend, listener);
-
- out:
-
- CORBA_exception_init (&ev);
- CORBA_Object_release (listener, &ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_message ("open_fn(): could not release the listener");
-
- CORBA_exception_free (&ev);
-}
-
-
-
-static void
-impl_CalFactory_open (PortableServer_Servant servant,
- const CORBA_char *str_uri,
- CORBA_boolean only_if_exists,
- GNOME_Evolution_Calendar_Listener listener,
- CORBA_Environment *ev)
-{
- CalFactory *factory;
- CalFactoryPrivate *priv;
- CORBA_Environment ev2;
- gboolean result;
- OpenJobData *jd;
- GNOME_Evolution_Calendar_Listener listener_copy;
- GtkType *type;
- EUri *uri;
-
- factory = CAL_FACTORY (bonobo_object_from_servant (servant));
- priv = factory->priv;
-
- /* check URI to see if we support it */
-
- uri = e_uri_new (str_uri);
- if (!uri) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI,
- NULL);
- return;
- }
-
- type = g_hash_table_lookup (priv->methods, uri->protocol);
-
- e_uri_free (uri);
- if (!type) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_CalFactory_UnsupportedMethod,
- NULL);
- return;
- }
-
- /* duplicate the listener object */
- CORBA_exception_init (&ev2);
- result = CORBA_Object_is_nil (listener, &ev2);
-
- if (ev2._major != CORBA_NO_EXCEPTION || result) {
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_CalFactory_NilListener,
- NULL);
-
- CORBA_exception_free (&ev2);
- return;
- }
- CORBA_exception_free (&ev2);
-
- CORBA_exception_init (&ev2);
- listener_copy = CORBA_Object_duplicate (listener, &ev2);
-
- if (ev2._major != CORBA_NO_EXCEPTION) {
- g_message ("CalFactory_open(): could not duplicate the listener");
- CORBA_exception_free (&ev2);
- CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
- ex_GNOME_Evolution_Calendar_CalFactory_NilListener,
- NULL);
- return;
- }
-
- CORBA_exception_free (&ev2);
-
- /* add new asynchronous job */
- jd = g_new (OpenJobData, 1);
- jd->factory = factory;
- jd->uri = g_strdup (str_uri);
- jd->only_if_exists = only_if_exists;
- jd->listener = listener_copy;
-
- job_add (open_fn, jd);
-}
-
-static GNOME_Evolution_Calendar_StringSeq *
-impl_CalFactory_uriList (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalMode mode,
- CORBA_Environment *ev)
-{
- CalFactory *factory;
- CalFactoryPrivate *priv;
- CalFactoryUriData cfud;
- GNOME_Evolution_Calendar_StringSeq *list;
-
- factory = CAL_FACTORY (bonobo_object_from_servant (servant));
- priv = factory->priv;
-
- list = GNOME_Evolution_Calendar_StringSeq__alloc ();
- list->_length = 0;
- list->_maximum = g_hash_table_size (priv->backends);
- list->_buffer = CORBA_sequence_CORBA_string_allocbuf (list->_maximum);
-
- cfud.factory = factory;
- cfud.mode = mode;
- cfud.list = list;
- g_hash_table_foreach (priv->backends, add_uri, &cfud);
-
- return list;
-
-}
-
-
-
-/**
- * cal_factory_new:
- * @void:
- *
- * Creates a new #CalFactory object.
- *
- * Return value: A newly-created #CalFactory, or NULL if its corresponding CORBA
- * object could not be created.
- **/
-CalFactory *
-cal_factory_new (void)
-{
- CalFactory *factory;
-
- factory = gtk_type_new (CAL_FACTORY_TYPE);
-
- return factory;
-}
-
-/* Destroy handler for the calendar */
-static void
-cal_factory_destroy (GtkObject *object)
-{
- CalFactory *factory;
- CalFactoryPrivate *priv;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (IS_CAL_FACTORY (object));
-
- factory = CAL_FACTORY (object);
- priv = factory->priv;
-
- g_hash_table_foreach (priv->methods, free_method, NULL);
- g_hash_table_destroy (priv->methods);
- priv->methods = NULL;
-
- /* Should we assert that there are no more backends? */
-
- g_hash_table_foreach (priv->backends, free_backend, NULL);
- g_hash_table_destroy (priv->backends);
- priv->backends = NULL;
-
- if (priv->registered) {
- oaf_active_server_unregister (priv->iid, BONOBO_OBJREF (factory));
- priv->registered = FALSE;
- }
- g_free (priv->iid);
-
- g_free (priv);
- factory->priv = NULL;
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-/* Class initialization function for the calendar factory */
-static void
-cal_factory_class_init (CalFactoryClass *klass)
-{
- GtkObjectClass *object_class = (GtkObjectClass *) klass;
- POA_GNOME_Evolution_Calendar_CalFactory__epv *epv = &klass->epv;
-
- parent_class = gtk_type_class (bonobo_object_get_type ());
-
- signals[LAST_CALENDAR_GONE] =
- gtk_signal_new ("last_calendar_gone",
- GTK_RUN_FIRST,
- object_class->type,
- GTK_SIGNAL_OFFSET (CalFactoryClass, last_calendar_gone),
- gtk_marshal_NONE__NONE,
- GTK_TYPE_NONE, 0);
-
- gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
-
- /* Class method overrides */
- object_class->destroy = cal_factory_destroy;
-
- /* Epv methods */
- epv->open = impl_CalFactory_open;
- epv->uriList = impl_CalFactory_uriList;
-}
-
-/* Object initialization function for the calendar factory */
-static void
-cal_factory_init (CalFactory *factory)
-{
- CalFactoryPrivate *priv;
-
- priv = g_new0 (CalFactoryPrivate, 1);
- factory->priv = priv;
-
- priv->methods = g_hash_table_new (g_str_hash, g_str_equal);
- priv->backends = g_hash_table_new (g_str_hash, g_str_equal);
- priv->registered = FALSE;
-}
-
-BONOBO_X_TYPE_FUNC_FULL (CalFactory,
- GNOME_Evolution_Calendar_CalFactory,
- PARENT_TYPE,
- cal_factory);
-
-/* Returns the lowercase version of a string */
-static char *
-str_tolower (const char *s)
-{
- char *str;
- unsigned char *p;
-
- str = g_strdup (s);
- for (p = str; *p; p++)
- if (isalpha (*p))
- *p = tolower (*p);
-
- return str;
-}
-
-/**
- * cal_factory_oaf_register:
- * @factory: A calendar factory.
- * @iid: OAFIID for the factory to be registered.
- *
- * Registers a calendar factory with the OAF object activation daemon. This
- * function must be called before any clients can activate the factory.
- *
- * Return value: TRUE on success, FALSE otherwise.
- **/
-gboolean
-cal_factory_oaf_register (CalFactory *factory, const char *iid)
-{
- CalFactoryPrivate *priv;
- OAF_RegistrationResult result;
- char *tmp_iid;
-
- g_return_val_if_fail (factory != NULL, FALSE);
- g_return_val_if_fail (IS_CAL_FACTORY (factory), FALSE);
-
- priv = factory->priv;
-
- g_return_val_if_fail (!priv->registered, FALSE);
-
- /* if iid is NULL, use the default factory OAFIID */
- if (iid)
- tmp_iid = g_strdup (iid);
- else
- tmp_iid = g_strdup (DEFAULT_CAL_FACTORY_OAF_ID);
-
- result = oaf_active_server_register (tmp_iid, BONOBO_OBJREF (factory));
-
- switch (result) {
- case OAF_REG_SUCCESS:
- priv->registered = TRUE;
- priv->iid = tmp_iid;
- return TRUE;
-
- case OAF_REG_NOT_LISTED:
- g_message ("cal_factory_oaf_register(): Cannot register the calendar factory: "
- "not listed");
- break;
-
- case OAF_REG_ALREADY_ACTIVE:
- g_message ("cal_factory_oaf_register(): Cannot register the calendar factory: "
- "already active");
- break;
-
- case OAF_REG_ERROR:
- default:
- g_message ("cal_factory_oaf_register(): Cannot register the calendar factory: "
- "generic error");
- break;
- }
-
- g_free (tmp_iid);
-
- return FALSE;
-}
-
-/**
- * cal_factory_register_method:
- * @factory: A calendar factory.
- * @method: Method for the URI, i.e. "http", "file", etc.
- * @backend_type: Class type of the backend to create for this @method.
- *
- * Registers the type of a #CalBackend subclass that will be used to handle URIs
- * with a particular method. When the factory is asked to open a particular
- * URI, it will look in its list of registered methods and create a backend of
- * the appropriate type.
- **/
-void
-cal_factory_register_method (CalFactory *factory, const char *method, GtkType backend_type)
-{
- CalFactoryPrivate *priv;
- GtkType *type;
- char *method_str;
-
- g_return_if_fail (factory != NULL);
- g_return_if_fail (IS_CAL_FACTORY (factory));
- g_return_if_fail (method != NULL);
- g_return_if_fail (backend_type != 0);
- g_return_if_fail (gtk_type_is_a (backend_type, CAL_BACKEND_TYPE));
-
- priv = factory->priv;
-
- method_str = str_tolower (method);
-
- type = g_hash_table_lookup (priv->methods, method_str);
- if (type) {
- g_message ("cal_factory_register_method(): Method `%s' already registered!",
- method_str);
- g_free (method_str);
- return;
- }
-
- type = g_new (GtkType, 1);
- *type = backend_type;
-
- g_hash_table_insert (priv->methods, method_str, type);
-}
-
-/**
- * cal_factory_get_n_backends:
- * @factory: A calendar factory.
- *
- * Queries the number of running calendar backends in a calendar factory.
- *
- * Return value: Number of running backends.
- **/
-int
-cal_factory_get_n_backends (CalFactory *factory)
-{
- CalFactoryPrivate *priv;
-
- g_return_val_if_fail (factory != NULL, -1);
- g_return_val_if_fail (IS_CAL_FACTORY (factory), -1);
-
- priv = factory->priv;
- return g_hash_table_size (priv->backends);
-}
-
-/* Frees a uri/backend pair from the backends hash table */
-static void
-dump_backend (gpointer key, gpointer value, gpointer data)
-{
- char *uri;
- CalBackend *backend;
-
- uri = key;
- backend = value;
-
- g_message (" %s: %p", uri, backend);
-}
-
-void
-cal_factory_dump_active_backends (CalFactory *factory)
-{
- CalFactoryPrivate *priv;
-
- g_message ("Active PCS backends");
-
- priv = factory->priv;
- g_hash_table_foreach (priv->backends, dump_backend, NULL);
-}
diff --git a/calendar/pcs/cal-factory.h b/calendar/pcs/cal-factory.h
deleted file mode 100644
index 46a66ed9a0..0000000000
--- a/calendar/pcs/cal-factory.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Evolution calendar factory
- *
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_FACTORY_H
-#define CAL_FACTORY_H
-
-#include <libgnome/gnome-defs.h>
-#include <bonobo/bonobo-xobject.h>
-
-#include "evolution-calendar.h"
-
-BEGIN_GNOME_DECLS
-
-
-
-#define CAL_FACTORY_TYPE (cal_factory_get_type ())
-#define CAL_FACTORY(obj) (GTK_CHECK_CAST ((obj), CAL_FACTORY_TYPE, CalFactory))
-#define CAL_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CAL_FACTORY_TYPE, \
- CalFactoryClass))
-#define IS_CAL_FACTORY(obj) (GTK_CHECK_TYPE ((obj), CAL_FACTORY_TYPE))
-#define IS_CAL_FACTORY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), CAL_FACTORY_TYPE))
-
-typedef struct _CalFactory CalFactory;
-typedef struct _CalFactoryClass CalFactoryClass;
-
-typedef struct _CalFactoryPrivate CalFactoryPrivate;
-
-struct _CalFactory {
- BonoboXObject object;
-
- /* Private data */
- CalFactoryPrivate *priv;
-};
-
-struct _CalFactoryClass {
- BonoboXObjectClass parent_class;
-
- POA_GNOME_Evolution_Calendar_CalFactory__epv epv;
-
- /* Notification signals */
- void (* last_calendar_gone) (CalFactory *factory);
-};
-
-GtkType cal_factory_get_type (void);
-CalFactory *cal_factory_new (void);
-
-gboolean cal_factory_oaf_register (CalFactory *factory, const char *iid);
-void cal_factory_register_method (CalFactory *factory,
- const char *method,
- GtkType backend_type);
-int cal_factory_get_n_backends (CalFactory *factory);
-void cal_factory_dump_active_backends (CalFactory *factory);
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/cal.c b/calendar/pcs/cal.c
deleted file mode 100644
index 9409d20120..0000000000
--- a/calendar/pcs/cal.c
+++ /dev/null
@@ -1,865 +0,0 @@
-/* Evolution calendar client interface object
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Authors: Federico Mena-Quintero <federico@ximian.com>
- * Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include <ical.h>
-#include <bonobo/bonobo-exception.h>
-#include "cal.h"
-#include "query.h"
-#include "wombat.h"
-
-#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
-
-static BonoboXObjectClass *parent_class;
-
-/* Private part of the Cal structure */
-struct _CalPrivate {
- /* Our backend */
- CalBackend *backend;
-
- /* Listener on the client we notify */
- GNOME_Evolution_Calendar_Listener listener;
-
- /* A reference to the WombatClient interface */
- GNOME_Evolution_WombatClient wombat_client;
-};
-
-
-/* Cal::get_uri method */
-static CORBA_char *
-impl_Cal_get_uri (PortableServer_Servant servant,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- const char *str_uri;
- CORBA_char *str_uri_copy;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- str_uri = cal_backend_get_uri (priv->backend);
- str_uri_copy = CORBA_string_dup (str_uri);
-
- return str_uri_copy;
-}
-
-/* Converts a calendar object type from its CORBA representation to our own
- * representation.
- */
-static CalObjType
-uncorba_obj_type (GNOME_Evolution_Calendar_CalObjType type)
-{
- return (((type & GNOME_Evolution_Calendar_TYPE_EVENT) ? CALOBJ_TYPE_EVENT : 0)
- | ((type & GNOME_Evolution_Calendar_TYPE_TODO) ? CALOBJ_TYPE_TODO : 0)
- | ((type & GNOME_Evolution_Calendar_TYPE_JOURNAL) ? CALOBJ_TYPE_JOURNAL : 0));
-}
-
-static void
-impl_Cal_set_mode (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalMode mode,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- cal_backend_set_mode (priv->backend, mode);
-}
-
-/* Cal::get_n_objects method */
-static CORBA_long
-impl_Cal_get_n_objects (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalObjType type,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- int t;
- int n;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t = uncorba_obj_type (type);
- n = cal_backend_get_n_objects (priv->backend, t);
- return n;
-}
-
-/* Cal::get_object method */
-static GNOME_Evolution_Calendar_CalObj
-impl_Cal_get_object (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalObjUID uid,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- char *calobj;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- calobj = cal_backend_get_object (priv->backend, uid);
-
- if (calobj) {
- CORBA_char *calobj_copy;
-
- calobj_copy = CORBA_string_dup (calobj);
- g_free (calobj);
- return calobj_copy;
- } else {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
-
- return NULL;
- }
-}
-
-static GNOME_Evolution_Calendar_CalObjUIDSeq *
-build_uid_seq (GList *uids)
-{
- GNOME_Evolution_Calendar_CalObjUIDSeq *seq;
- GList *l;
- int n, i;
-
- n = g_list_length (uids);
-
- seq = GNOME_Evolution_Calendar_CalObjUIDSeq__alloc ();
- CORBA_sequence_set_release (seq, TRUE);
- seq->_length = n;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjUID_allocbuf (n);
-
- /* Fill the sequence */
-
- for (i = 0, l = uids; l; i++, l = l->next) {
- char *uid;
-
- uid = l->data;
- seq->_buffer[i] = CORBA_string_dup (uid);
- }
-
- return seq;
-}
-
-/* Cal::get_uids method */
-static GNOME_Evolution_Calendar_CalObjUIDSeq *
-impl_Cal_get_uids (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalObjType type,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- GList *uids;
- GNOME_Evolution_Calendar_CalObjUIDSeq *seq;
- int t;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t = uncorba_obj_type (type);
-
- uids = cal_backend_get_uids (priv->backend, t);
- seq = build_uid_seq (uids);
-
- cal_obj_uid_list_free (uids);
-
- return seq;
-}
-
-/* Cal::get_changes method */
-static GNOME_Evolution_Calendar_CalObjChangeSeq *
-impl_Cal_get_changes (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalObjType type,
- const CORBA_char *change_id,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- int t;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t = uncorba_obj_type (type);
-
- return cal_backend_get_changes (priv->backend, t, change_id);
-}
-
-/* Cal::get_objects_in_range method */
-static GNOME_Evolution_Calendar_CalObjUIDSeq *
-impl_Cal_get_objects_in_range (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_CalObjType type,
- GNOME_Evolution_Calendar_Time_t start,
- GNOME_Evolution_Calendar_Time_t end,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- int t;
- time_t t_start, t_end;
- GNOME_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;
-
- if (t_start > t_end || t_start == -1 || t_end == -1) {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange);
- return NULL;
- }
-
- uids = cal_backend_get_objects_in_range (priv->backend, t, t_start, t_end);
- seq = build_uid_seq (uids);
-
- cal_obj_uid_list_free (uids);
-
- return seq;
-}
-
-static GNOME_Evolution_Calendar_CalObjSeq *
-build_fb_seq (GList *obj_list)
-{
- GNOME_Evolution_Calendar_CalObjSeq *seq;
- GList *l;
- int n, i;
-
- n = g_list_length (obj_list);
-
- seq = GNOME_Evolution_Calendar_CalObjSeq__alloc ();
- CORBA_sequence_set_release (seq, TRUE);
- seq->_length = n;
- seq->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObj_allocbuf (n);
-
- /* Fill the sequence */
-
- for (i = 0, l = obj_list; l; i++, l = l->next) {
- char *calobj;
-
- calobj = l->data;
- seq->_buffer[i] = CORBA_string_dup (calobj);
- }
-
- return seq;
-}
-
-/* Cal::get_free_busy method */
-static GNOME_Evolution_Calendar_CalObjSeq *
-impl_Cal_get_free_busy (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_UserList *user_list,
- const GNOME_Evolution_Calendar_Time_t start,
- const GNOME_Evolution_Calendar_Time_t end,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- time_t t_start, t_end;
- GList *users = NULL;
- GList *obj_list;
- GNOME_Evolution_Calendar_CalObjSeq *seq;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t_start = (time_t) start;
- t_end = (time_t) end;
-
- if (t_start > t_end || t_start == -1 || t_end == -1) {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange);
- return build_fb_seq (NULL);
- }
-
- /* convert the CORBA user list to a GList */
- if (user_list) {
- int i;
-
- for (i = 0; i < user_list->_length; i++)
- users = g_list_append (users, user_list->_buffer[i]);
- }
-
- /* call the backend's get_free_busy method */
- obj_list = cal_backend_get_free_busy (priv->backend, users, t_start, t_end);
- seq = build_fb_seq (obj_list);
- g_list_free (users);
-
- if (obj_list == NULL)
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
-
- return seq;
-}
-
-/* Cal::get_alarms_in_range method */
-static GNOME_Evolution_Calendar_CalComponentAlarmsSeq *
-impl_Cal_get_alarms_in_range (PortableServer_Servant servant,
- GNOME_Evolution_Calendar_Time_t start,
- GNOME_Evolution_Calendar_Time_t end,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- time_t t_start, t_end;
- gboolean valid_range;
- GNOME_Evolution_Calendar_CalComponentAlarmsSeq *seq;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t_start = (time_t) start;
- t_end = (time_t) end;
-
- seq = cal_backend_get_alarms_in_range (priv->backend, t_start, t_end, &valid_range);
- if (!valid_range) {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange);
- return NULL;
- }
-
- return seq;
-}
-
-/* Cal::get_alarms_for_object method */
-static GNOME_Evolution_Calendar_CalComponentAlarms *
-impl_Cal_get_alarms_for_object (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalObjUID uid,
- GNOME_Evolution_Calendar_Time_t start,
- GNOME_Evolution_Calendar_Time_t end,
- CORBA_Environment * ev)
-{
- Cal *cal;
- CalPrivate *priv;
- time_t t_start, t_end;
- GNOME_Evolution_Calendar_CalComponentAlarms *alarms;
- CalBackendGetAlarmsForObjectResult result;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- t_start = (time_t) start;
- t_end = (time_t) end;
-
- alarms = cal_backend_get_alarms_for_object (priv->backend, uid, t_start, t_end, &result);
-
- switch (result) {
- case CAL_BACKEND_GET_ALARMS_SUCCESS:
- return alarms;
-
- case CAL_BACKEND_GET_ALARMS_NOT_FOUND:
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
- return NULL;
-
- case CAL_BACKEND_GET_ALARMS_INVALID_RANGE:
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidRange);
- return NULL;
-
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-/* Cal::update_objects method */
-static void
-impl_Cal_update_objects (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalObj calobj,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- if (!cal_backend_update_objects (priv->backend, calobj))
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_InvalidObject);
-}
-
-/* Cal::remove_object method */
-static void
-impl_Cal_remove_object (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalObjUID uid,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- if (!cal_backend_remove_object (priv->backend, uid))
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
-}
-
-/* Cal::getQuery implementation */
-static GNOME_Evolution_Calendar_Query
-impl_Cal_get_query (PortableServer_Servant servant,
- const CORBA_char *sexp,
- GNOME_Evolution_Calendar_QueryListener ql,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- Query *query;
- CORBA_Environment ev2;
- GNOME_Evolution_Calendar_Query query_copy;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- query = query_new (priv->backend, ql, sexp);
- if (!query) {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate);
- return CORBA_OBJECT_NIL;
- }
-
- CORBA_exception_init (&ev2);
- query_copy = CORBA_Object_duplicate (BONOBO_OBJREF (query), &ev2);
- if (BONOBO_EX (&ev2)) {
- CORBA_exception_free (&ev2);
- g_message ("Cal_get_query(): Could not duplicate the query reference");
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_CouldNotCreate);
- return CORBA_OBJECT_NIL;
- }
-
- CORBA_exception_free (&ev2);
-
- return query_copy;
-}
-
-/* Cal::set_default_timezone method */
-static void
-impl_Cal_set_default_timezone (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalTimezoneObjUID tzid,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- gboolean zone_set;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- zone_set = cal_backend_set_default_timezone (priv->backend, tzid);
-
- if (!zone_set) {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
- }
-}
-
-/* Cal::get_timezone_object method */
-static GNOME_Evolution_Calendar_CalObj
-impl_Cal_get_timezone_object (PortableServer_Servant servant,
- const GNOME_Evolution_Calendar_CalTimezoneObjUID tzid,
- CORBA_Environment *ev)
-{
- Cal *cal;
- CalPrivate *priv;
- char *calobj;
-
- cal = CAL (bonobo_object_from_servant (servant));
- priv = cal->priv;
-
- calobj = cal_backend_get_timezone_object (priv->backend, tzid);
-
- if (calobj) {
- CORBA_char *calobj_copy;
-
- calobj_copy = CORBA_string_dup (calobj);
- g_free (calobj);
- return calobj_copy;
- } else {
- bonobo_exception_set (ev, ex_GNOME_Evolution_Calendar_Cal_NotFound);
- return NULL;
- }
-}
-
-/**
- * cal_construct:
- * @cal: A calendar client interface.
- * @corba_cal: CORBA object for the calendar.
- * @backend: Calendar backend that this @cal presents an interface to.
- * @listener: Calendar listener for notification.
- *
- * Constructs a calendar client interface object by binding the corresponding
- * CORBA object to it. The calendar interface is bound to the specified
- * @backend, and will notify the @listener about changes to the calendar.
- *
- * Return value: The same object as the @cal argument.
- **/
-Cal *
-cal_construct (Cal *cal,
- CalBackend *backend,
- GNOME_Evolution_Calendar_Listener listener)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_val_if_fail (cal != NULL, NULL);
- g_return_val_if_fail (IS_CAL (cal), NULL);
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- priv = cal->priv;
-
- CORBA_exception_init (&ev);
- priv->listener = CORBA_Object_duplicate (listener, &ev);
- if (BONOBO_EX (&ev)) {
- g_message ("cal_construct: could not duplicate the listener");
- priv->listener = CORBA_OBJECT_NIL;
- CORBA_exception_free (&ev);
- return NULL;
- }
-
- CORBA_exception_free (&ev);
-
- /* obtain the WombatClient interface */
- CORBA_exception_init (&ev);
- priv->wombat_client = Bonobo_Unknown_queryInterface (
- priv->listener,
- "IDL:GNOME/Evolution/WombatClient:1.0",
- &ev);
- if (BONOBO_EX (&ev)) {
- g_message ("cal_construct: could not get the WombatClient interface");
- priv->wombat_client = CORBA_OBJECT_NIL;
- }
-
- CORBA_exception_free (&ev);
-
- priv->backend = backend;
-
- return cal;
-}
-
-/**
- * cal_new:
- * @backend: A calendar backend.
- * @listener: A calendar listener.
- *
- * Creates a new calendar client interface object and binds it to the specified
- * @backend and @listener objects.
- *
- * Return value: A newly-created #Cal calendar client interface object, or NULL
- * if its corresponding CORBA object could not be created.
- **/
-Cal *
-cal_new (CalBackend *backend, GNOME_Evolution_Calendar_Listener listener)
-{
- Cal *cal, *retval;
-
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
-
- cal = CAL (gtk_type_new (CAL_TYPE));
-
- retval = cal_construct (cal, backend, listener);
- if (!retval) {
- g_message ("cal_new(): could not construct the calendar client interface");
- bonobo_object_unref (BONOBO_OBJECT (cal));
- return NULL;
- }
-
- return retval;
-}
-
-/* Destroy handler for the calendar */
-static void
-cal_destroy (GtkObject *object)
-{
- Cal *cal;
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (IS_CAL (object));
-
- cal = CAL (object);
- priv = cal->priv;
-
- priv->backend = NULL;
-
- CORBA_exception_init (&ev);
- bonobo_object_release_unref (priv->listener, &ev);
- if (BONOBO_EX (&ev))
- g_message ("cal_destroy(): could not release the listener");
-
- priv->listener = NULL;
- CORBA_exception_free (&ev);
-
- g_free (priv);
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-
-
-/* Class initialization function for the calendar */
-static void
-cal_class_init (CalClass *klass)
-{
- GtkObjectClass *object_class = (GtkObjectClass *) klass;
- POA_GNOME_Evolution_Calendar_Cal__epv *epv = &klass->epv;
-
- parent_class = gtk_type_class (PARENT_TYPE);
-
- /* Class method overrides */
- object_class->destroy = cal_destroy;
-
- /* Epv methods */
- epv->_get_uri = impl_Cal_get_uri;
- epv->setMode = impl_Cal_set_mode;
- epv->countObjects = impl_Cal_get_n_objects;
- epv->getObject = impl_Cal_get_object;
- epv->setDefaultTimezone = impl_Cal_set_default_timezone;
- epv->getTimezoneObject = impl_Cal_get_timezone_object;
- epv->getUIDs = impl_Cal_get_uids;
- epv->getChanges = impl_Cal_get_changes;
- epv->getObjectsInRange = impl_Cal_get_objects_in_range;
- epv->getFreeBusy = impl_Cal_get_free_busy;
- epv->getAlarmsInRange = impl_Cal_get_alarms_in_range;
- epv->getAlarmsForObject = impl_Cal_get_alarms_for_object;
- epv->updateObjects = impl_Cal_update_objects;
- epv->removeObject = impl_Cal_remove_object;
- epv->getQuery = impl_Cal_get_query;
-}
-
-
-/* Object initialization function for the calendar */
-static void
-cal_init (Cal *cal)
-{
- CalPrivate *priv;
-
- priv = g_new0 (CalPrivate, 1);
- cal->priv = priv;
-
- priv->listener = CORBA_OBJECT_NIL;
-}
-
-BONOBO_X_TYPE_FUNC_FULL (Cal, GNOME_Evolution_Calendar_Cal, PARENT_TYPE, cal);
-
-/**
- * cal_notify_mode:
- * @cal: A calendar client interface.
- * @status: Status of the mode set.
- * @mode: The current mode.
- *
- * Notifys the listener of the results of a setMode call.
- **/
-void
-cal_notify_mode (Cal *cal,
- GNOME_Evolution_Calendar_Listener_SetModeStatus status,
- GNOME_Evolution_Calendar_CalMode mode)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
-
- priv = cal->priv;
- g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCalSetMode (priv->listener, status, mode, &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("cal_notify_mode(): could not notify the listener "
- "about a mode change");
-
- CORBA_exception_free (&ev);
-}
-
-/**
- * cal_notify_update:
- * @cal: A calendar client interface.
- * @uid: UID of object that was updated.
- *
- * Notifies a listener attached to a calendar client interface object about an
- * update to a calendar object.
- **/
-void
-cal_notify_update (Cal *cal, const char *uid)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
- g_return_if_fail (uid != NULL);
-
- priv = cal->priv;
- g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyObjUpdated (priv->listener, (char *) uid, &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("cal_notify_update(): could not notify the listener "
- "about an updated object");
-
- CORBA_exception_free (&ev);
-}
-
-/**
- * cal_notify_remove:
- * @cal: A calendar client interface.
- * @uid: UID of object that was removed.
- *
- * Notifies a listener attached to a calendar client interface object about a
- * calendar object that was removed.
- **/
-void
-cal_notify_remove (Cal *cal, const char *uid)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
- g_return_if_fail (uid != NULL);
-
- priv = cal->priv;
- g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyObjRemoved (priv->listener, (char *) uid, &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("cal_notify_remove(): could not notify the listener "
- "about a removed object");
-
- CORBA_exception_free (&ev);
-}
-
-/**
- * cal_notify_categories_changed:
- * @cal: A calendar client interface.
- * @categories: List of categories.
- *
- * Notifies a listener attached to a calendar client interface object about the
- * current set of categories in a calendar backend.
- **/
-void
-cal_notify_categories_changed (Cal *cal, GNOME_Evolution_Calendar_StringSeq *categories)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
- g_return_if_fail (categories != NULL);
-
- priv = cal->priv;
- g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_Listener_notifyCategoriesChanged (priv->listener, categories, &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("cal_notify_categories_changed(): Could not notify the listener "
- "about the current set of categories");
-
- CORBA_exception_free (&ev);
-}
-
-/**
- * cal_get_password:
- * @cal: A calendar client interface.
- * @prompt: The message to show to the user when asking for the password.
- * @key: A key associated with the password being asked.
- *
- * Gets a password from the calendar client this Cal knows about. It does
- * so by using the WombatClient interface being used by the corresponding
- * CalClient.
- *
- * Returns: a password entered by the user.
- */
-char *
-cal_get_password (Cal *cal, const char *prompt, const char *key)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
- CORBA_char *pwd;
-
- g_return_val_if_fail (cal != NULL, NULL);
- g_return_val_if_fail (IS_CAL (cal), NULL);
-
- priv = cal->priv;
- g_return_val_if_fail (priv->wombat_client != CORBA_OBJECT_NIL, NULL);
-
- CORBA_exception_init (&ev);
- pwd = GNOME_Evolution_WombatClient_getPassword (
- priv->wombat_client,
- (const CORBA_char *) prompt,
- (const CORBA_char *) key,
- &ev);
- if (BONOBO_EX (&ev)) {
- g_message ("cal_get_password: could not get password from associated WombatClient");
- CORBA_exception_free (&ev);
- return NULL;
- }
-
- CORBA_exception_free (&ev);
-
- return pwd;
-}
-
-/**
- * cal_forget_password:
- * @cal: A calendar client interface.
- * @key: A key associated with the password to be forgotten.
- *
- * Notifies the associated calendar client that it should forget
- * about the password identified by @key, so that next time the backend
- * asks the client about it, the client would ask again the user for it.
- * This is done in cases where the password supplied the first time
- * was not a valid password and the backend needs the user to enter
- * a new one.
- */
-void
-cal_forget_password (Cal *cal, const char *key)
-{
- CalPrivate *priv;
- CORBA_Environment ev;
-
- g_return_if_fail (cal != NULL);
- g_return_if_fail (IS_CAL (cal));
-
- priv = cal->priv;
- g_return_if_fail (priv->wombat_client != CORBA_OBJECT_NIL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_WombatClient_forgetPassword (
- priv->wombat_client,
- (const CORBA_char *) key,
- &ev);
-
- if (BONOBO_EX (&ev)) {
- g_message ("cal_forget_password: could not notify WombatClient about "
- "password to be forgotten");
- }
-
- CORBA_exception_free (&ev);
-}
diff --git a/calendar/pcs/cal.h b/calendar/pcs/cal.h
deleted file mode 100644
index 81c3e55154..0000000000
--- a/calendar/pcs/cal.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Evolution calendar client interface object
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Authors: Federico Mena-Quintero <federico@ximian.com>
- * Rodrigo Moya <rodrigo@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_H
-#define CAL_H
-
-#include <libgnome/gnome-defs.h>
-#include <bonobo/bonobo-xobject.h>
-#include "evolution-calendar.h"
-#include "cal-common.h"
-
-BEGIN_GNOME_DECLS
-
-
-
-#define CAL_TYPE (cal_get_type ())
-#define CAL(obj) (GTK_CHECK_CAST ((obj), CAL_TYPE, Cal))
-#define CAL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), CAL_TYPE, CalClass))
-#define IS_CAL(obj) (GTK_CHECK_TYPE ((obj), CAL_TYPE))
-#define IS_CAL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), CAL_TYPE))
-
-typedef struct _CalPrivate CalPrivate;
-
-struct _Cal {
- BonoboXObject object;
-
- /* Private data */
- CalPrivate *priv;
-};
-
-struct _CalClass {
- BonoboXObjectClass parent_class;
-
- POA_GNOME_Evolution_Calendar_Cal__epv epv;
-};
-
-GtkType cal_get_type (void);
-
-Cal *cal_construct (Cal *cal,
- CalBackend *backend,
- GNOME_Evolution_Calendar_Listener listener);
-
-Cal *cal_new (CalBackend *backend, GNOME_Evolution_Calendar_Listener listener);
-
-void cal_notify_mode (Cal *cal,
- GNOME_Evolution_Calendar_Listener_SetModeStatus status,
- GNOME_Evolution_Calendar_CalMode mode);
-void cal_notify_update (Cal *cal, const char *uid);
-void cal_notify_remove (Cal *cal, const char *uid);
-
-void cal_notify_categories_changed (Cal *cal, GNOME_Evolution_Calendar_StringSeq *categories);
-
-char *cal_get_password (Cal *cal, const char *prompt, const char *key);
-void cal_forget_password (Cal *cal, const char *key);
-
-
-
-END_GNOME_DECLS
-
-#endif
diff --git a/calendar/pcs/job.c b/calendar/pcs/job.c
deleted file mode 100644
index 584f1a6f38..0000000000
--- a/calendar/pcs/job.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* GNOME personal calendar server - job manager
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 <config.h>
-#include "job.h"
-
-
-
-/* The job list */
-
-typedef struct {
- JobFunc func;
- gpointer data;
-} Job;
-
-static GSList *jobs_head;
-static GSList *jobs_tail;
-
-static guint jobs_idle_id;
-
-
-
-/* Runs a job and dequeues it */
-static gboolean
-run_job (gpointer data)
-{
- Job *job;
- GSList *l;
-
- g_assert (jobs_head != NULL);
-
- job = jobs_head->data;
- (* job->func) (job->data);
- g_free (job);
-
- l = jobs_head;
- jobs_head = g_slist_remove_link (jobs_head, jobs_head);
- g_slist_free_1 (l);
-
- if (!jobs_head) {
- jobs_tail = NULL;
- jobs_idle_id = 0;
- return FALSE;
- } else
- return TRUE;
-}
-
-/**
- * job_add:
- * @func: Function to run the job.
- * @data: Data to pass to @function.
- *
- * Adds a job to the queue. The job will automatically be run asynchronously.
- **/
-void
-job_add (JobFunc func, gpointer data)
-{
- Job *job;
-
- g_return_if_fail (func != NULL);
-
- job = g_new (Job, 1);
- job->func = func;
- job->data = data;
-
- if (!jobs_head) {
- g_assert (jobs_tail == NULL);
- g_assert (jobs_idle_id == 0);
-
- jobs_head = g_slist_append (NULL, job);
- jobs_tail = jobs_head;
-
- jobs_idle_id = g_idle_add (run_job, NULL);
- } else {
- g_assert (jobs_tail != NULL);
- g_assert (jobs_idle_id != 0);
-
- jobs_tail = g_slist_append (jobs_tail, job)->next;
- }
-}
diff --git a/calendar/pcs/job.h b/calendar/pcs/job.h
deleted file mode 100644
index 07e3371f89..0000000000
--- a/calendar/pcs/job.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* GNOME personal calendar server - job manager
- *
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 JOB_H
-#define JOB_H
-
-#include <glib.h>
-
-
-
-typedef void (* JobFunc) (gpointer data);
-
-void job_add (JobFunc func, gpointer data);
-
-
-
-#endif
diff --git a/calendar/pcs/query.c b/calendar/pcs/query.c
deleted file mode 100644
index bf008ab655..0000000000
--- a/calendar/pcs/query.c
+++ /dev/null
@@ -1,1454 +0,0 @@
-/* Evolution calendar - Live search query implementation
- *
- * Copyright (C) 2001 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-#include <glib.h>
-#include <libgnome/gnome-defs.h>
-#include <libgnome/gnome-i18n.h>
-#include <gtk/gtksignal.h>
-#include <bonobo/bonobo-exception.h>
-#include <gal/widgets/e-unicode.h>
-#include <e-util/e-sexp.h>
-#include <cal-util/cal-recur.h>
-#include <cal-util/timeutil.h>
-#include "query.h"
-
-
-
-/* States of a query */
-typedef enum {
- QUERY_WAIT_FOR_BACKEND, /* the query is not populated and the backend is not loaded */
- QUERY_START_PENDING, /* the query is not populated yet, but the backend is loaded */
- QUERY_IN_PROGRESS, /* the query is populated; components are still being processed */
- QUERY_DONE, /* the query is done, but still accepts object changes */
- QUERY_PARSE_ERROR /* a parse error occurred when initially creating the ESexp */
-} QueryState;
-
-/* Private part of the Query structure */
-struct _QueryPrivate {
- /* The backend we are monitoring */
- CalBackend *backend;
-
- /* The default timezone for the calendar. */
- icaltimezone *default_zone;
-
- /* Listener to which we report changes in the live query */
- GNOME_Evolution_Calendar_QueryListener ql;
-
- /* Sexp that defines the query */
- char *sexp;
- ESExp *esexp;
-
- /* Idle handler ID for asynchronous queries and the current state */
- guint idle_id;
- QueryState state;
-
- /* List of UIDs that we still have to process */
- GList *pending_uids;
- int n_pending;
- int pending_total;
-
- /* Table of the UIDs we know do match the query */
- GHashTable *uids;
-
- /* The next component that will be handled in e_sexp_eval(); put here
- * just because the query object itself is the esexp context.
- */
- CalComponent *next_comp;
-};
-
-
-
-static void query_class_init (QueryClass *class);
-static void query_init (Query *query);
-static void query_destroy (GtkObject *object);
-
-static BonoboXObjectClass *parent_class;
-
-
-
-BONOBO_X_TYPE_FUNC_FULL (Query,
- GNOME_Evolution_Calendar_Query,
- BONOBO_X_OBJECT_TYPE,
- query);
-
-/* Class initialization function for the live search query */
-static void
-query_class_init (QueryClass *class)
-{
- GtkObjectClass *object_class;
-
- object_class = (GtkObjectClass *) class;
-
- parent_class = gtk_type_class (BONOBO_X_OBJECT_TYPE);
-
- object_class->destroy = query_destroy;
-
- /* The Query interface (ha ha! query interface!) has no methods, so we
- * don't need to fiddle with the epv.
- */
-}
-
-/* Object initialization function for the live search query */
-static void
-query_init (Query *query)
-{
- QueryPrivate *priv;
-
- priv = g_new0 (QueryPrivate, 1);
- query->priv = priv;
-
- priv->backend = NULL;
- priv->default_zone = NULL;
- priv->ql = CORBA_OBJECT_NIL;
- priv->sexp = NULL;
-
- priv->idle_id = 0;
- priv->state = QUERY_WAIT_FOR_BACKEND;
-
- priv->pending_uids = NULL;
- priv->uids = g_hash_table_new (g_str_hash, g_str_equal);
-
- priv->next_comp = NULL;
-}
-
-/* Used from g_hash_table_foreach(); frees a UID */
-static void
-free_uid_cb (gpointer key, gpointer value, gpointer data)
-{
- char *uid;
-
- uid = key;
- g_free (uid);
-}
-
-/* Destroy handler for the live search query */
-static void
-query_destroy (GtkObject *object)
-{
- Query *query;
- QueryPrivate *priv;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (IS_QUERY (object));
-
- query = QUERY (object);
- priv = query->priv;
-
- if (priv->backend) {
- /* If we are waiting for the backend to be opened, we'll be
- * connected to its "opened" signal. If we are in the middle of
- * a query or if we are just waiting for object update
- * notifications, we'll have the "obj_removed" and "obj_updated"
- * connections. Otherwise, we are either in a parse error state
- * or waiting for the query to be populated, and in both cases
- * we have no signal connections.
- */
- if (priv->state == QUERY_WAIT_FOR_BACKEND
- || priv->state == QUERY_IN_PROGRESS || priv->state == QUERY_DONE)
- gtk_signal_disconnect_by_data (GTK_OBJECT (priv->backend), query);
-
- gtk_object_unref (GTK_OBJECT (priv->backend));
- priv->backend = NULL;
- }
-
- if (priv->ql != CORBA_OBJECT_NIL) {
- CORBA_Environment ev;
-
- CORBA_exception_init (&ev);
- bonobo_object_release_unref (priv->ql, &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("query_destroy(): Could not unref the listener\n");
-
- CORBA_exception_free (&ev);
-
- priv->ql = CORBA_OBJECT_NIL;
- }
-
- if (priv->sexp) {
- g_free (priv->sexp);
- priv->sexp = NULL;
- }
-
- if (priv->esexp) {
- e_sexp_unref (priv->esexp);
- priv->esexp = NULL;
- }
-
- if (priv->idle_id) {
- g_source_remove (priv->idle_id);
- priv->idle_id = 0;
- }
-
- if (priv->pending_uids) {
- GList *l;
-
- for (l = priv->pending_uids; l; l = l->next) {
- char *uid;
-
- uid = l->data;
- g_assert (uid != NULL);
- g_free (uid);
- }
-
- g_list_free (priv->pending_uids);
- priv->pending_uids = NULL;
- priv->n_pending = 0;
- }
-
- g_hash_table_foreach (priv->uids, free_uid_cb, NULL);
- g_hash_table_destroy (priv->uids);
- priv->uids = NULL;
-
- g_free (priv);
- query->priv = NULL;
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-
-
-/* E-Sexp functions */
-
-/* (time-now)
- *
- * Returns a time_t of time (NULL).
- */
-static ESExpResult *
-func_time_now (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- ESExpResult *result;
-
- if (argc != 0) {
- e_sexp_fatal_error (esexp, _("time-now expects 0 arguments"));
- return NULL;
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_TIME);
- result->value.time = time (NULL);
-
- return result;
-}
-
-/* (make-time ISODATE)
- *
- * ISODATE - string, ISO 8601 date/time representation
- *
- * Constructs a time_t value for the specified date.
- */
-static ESExpResult *
-func_make_time (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- const char *str;
- time_t t;
- ESExpResult *result;
-
- if (argc != 1) {
- e_sexp_fatal_error (esexp, _("make-time expects 1 argument"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_STRING) {
- e_sexp_fatal_error (esexp, _("make-time expects argument 1 "
- "to be a string"));
- return NULL;
- }
- str = argv[0]->value.string;
-
- t = time_from_isodate (str);
- if (t == -1) {
- e_sexp_fatal_error (esexp, _("make-time argument 1 must be an "
- "ISO 8601 date/time string"));
- return NULL;
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_TIME);
- result->value.time = t;
-
- return result;
-}
-
-/* (time-add-day TIME N)
- *
- * TIME - time_t, base time
- * N - int, number of days to add
- *
- * Adds the specified number of days to a time value.
- *
- * FIXME: TIMEZONES - need to use a timezone or daylight saving changes will
- * make the result incorrect.
- */
-static ESExpResult *
-func_time_add_day (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- ESExpResult *result;
- time_t t;
- int n;
-
- if (argc != 2) {
- e_sexp_fatal_error (esexp, _("time-add-day expects 2 arguments"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("time-add-day expects argument 1 "
- "to be a time_t"));
- return NULL;
- }
- t = argv[0]->value.time;
-
- if (argv[1]->type != ESEXP_RES_INT) {
- e_sexp_fatal_error (esexp, _("time-add-day expects argument 2 "
- "to be an integer"));
- return NULL;
- }
- n = argv[1]->value.number;
-
- result = e_sexp_result_new (esexp, ESEXP_RES_TIME);
- result->value.time = time_add_day (t, n);
-
- return result;
-}
-
-/* (time-day-begin TIME)
- *
- * TIME - time_t, base time
- *
- * Returns the start of the day, according to the local time.
- *
- * FIXME: TIMEZONES - this uses the current Unix timezone.
- */
-static ESExpResult *
-func_time_day_begin (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- time_t t;
- ESExpResult *result;
-
- if (argc != 1) {
- e_sexp_fatal_error (esexp, _("time-day-begin expects 1 argument"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("time-day-begin expects argument 1 "
- "to be a time_t"));
- return NULL;
- }
- t = argv[0]->value.time;
-
- result = e_sexp_result_new (esexp, ESEXP_RES_TIME);
- result->value.time = time_day_begin (t);
-
- return result;
-}
-
-/* (time-day-end TIME)
- *
- * TIME - time_t, base time
- *
- * Returns the end of the day, according to the local time.
- *
- * FIXME: TIMEZONES - this uses the current Unix timezone.
- */
-static ESExpResult *
-func_time_day_end (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- time_t t;
- ESExpResult *result;
-
- if (argc != 1) {
- e_sexp_fatal_error (esexp, _("time-day-end expects 1 argument"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("time-day-end expects argument 1 "
- "to be a time_t"));
- return NULL;
- }
- t = argv[0]->value.time;
-
- result = e_sexp_result_new (esexp, ESEXP_RES_TIME);
- result->value.time = time_day_end (t);
-
- return result;
-}
-
-/* (get-vtype)
- *
- * Returns a string indicating the type of component (VEVENT, VTODO, VJOURNAL,
- * VFREEBUSY, VTIMEZONE, UNKNOWN).
- */
-static ESExpResult *
-func_get_vtype (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- CalComponentVType vtype;
- char *str;
- ESExpResult *result;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc != 0) {
- e_sexp_fatal_error (esexp, _("get-vtype expects 0 arguments"));
- return NULL;
- }
-
- /* Get the type */
-
- vtype = cal_component_get_vtype (comp);
-
- switch (vtype) {
- case CAL_COMPONENT_EVENT:
- str = g_strdup ("VEVENT");
- break;
-
- case CAL_COMPONENT_TODO:
- str = g_strdup ("VTODO");
- break;
-
- case CAL_COMPONENT_JOURNAL:
- str = g_strdup ("VJOURNAL");
- break;
-
- case CAL_COMPONENT_FREEBUSY:
- str = g_strdup ("VFREEBUSY");
- break;
-
- case CAL_COMPONENT_TIMEZONE:
- str = g_strdup ("VTIMEZONE");
- break;
-
- default:
- str = g_strdup ("UNKNOWN");
- break;
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_STRING);
- result->value.string = str;
-
- return result;
-}
-
-/* Sets a boolean value in the data to TRUE; called from
- * cal_recur_generate_instances() to indicate that at least one instance occurs
- * in the sought time range. We always return FALSE because we want the
- * recurrence engine to finish as soon as possible.
- */
-static gboolean
-instance_occur_cb (CalComponent *comp, time_t start, time_t end, gpointer data)
-{
- gboolean *occurs;
-
- occurs = data;
- *occurs = TRUE;
-
- return FALSE;
-}
-
-/* Call the backend function to get a timezone from a TZID. */
-static icaltimezone*
-resolve_tzid (const char *tzid, gpointer data)
-{
- Query *query = data;
-
- if (!tzid || !tzid[0])
- return NULL;
- else
- return cal_backend_get_timezone (query->priv->backend, tzid);
-}
-
-
-/* (occur-in-time-range? START END)
- *
- * START - time_t, start of the time range
- * END - time_t, end of the time range
- *
- * Returns a boolean indicating whether the component has any occurrences in the
- * specified time range.
- */
-static ESExpResult *
-func_occur_in_time_range (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- time_t start, end;
- gboolean occurs;
- ESExpResult *result;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc != 2) {
- e_sexp_fatal_error (esexp, _("occur-in-time-range? expects 2 arguments"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("occur-in-time-range? expects argument 1 "
- "to be a time_t"));
- return NULL;
- }
- start = argv[0]->value.time;
-
- if (argv[1]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("occur-in-time-range? expects argument 2 "
- "to be a time_t"));
- return NULL;
- }
- end = argv[1]->value.time;
-
- /* See if there is at least one instance in that range */
-
- occurs = FALSE;
-
- cal_recur_generate_instances (comp, start, end,
- instance_occur_cb, &occurs,
- resolve_tzid, query, priv->default_zone);
-
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = occurs;
-
- return result;
-}
-
-/* Returns whether a list of CalComponentText items matches the specified string */
-static gboolean
-matches_text_list (GSList *text_list, const char *str)
-{
- GSList *l;
- gboolean matches;
-
- matches = FALSE;
-
- for (l = text_list; l; l = l->next) {
- CalComponentText *text;
-
- text = l->data;
- g_assert (text->value != NULL);
-
- if (e_utf8_strstrcasedecomp (text->value, str) != NULL) {
- matches = TRUE;
- break;
- }
- }
-
- return matches;
-}
-
-/* Returns whether the comments in a component matches the specified string */
-static gboolean
-matches_comment (CalComponent *comp, const char *str)
-{
- GSList *list;
- gboolean matches;
-
- cal_component_get_comment_list (comp, &list);
- matches = matches_text_list (list, str);
- cal_component_free_text_list (list);
-
- return matches;
-}
-
-/* Returns whether the description in a component matches the specified string */
-static gboolean
-matches_description (CalComponent *comp, const char *str)
-{
- GSList *list;
- gboolean matches;
-
- cal_component_get_description_list (comp, &list);
- matches = matches_text_list (list, str);
- cal_component_free_text_list (list);
-
- return matches;
-}
-
-/* Returns whether the summary in a component matches the specified string */
-static gboolean
-matches_summary (CalComponent *comp, const char *str)
-{
- CalComponentText text;
-
- cal_component_get_summary (comp, &text);
-
- if (!text.value)
- return FALSE;
-
- return e_utf8_strstrcasedecomp (text.value, str) != NULL;
-}
-
-/* Returns whether any text field in a component matches the specified string */
-static gboolean
-matches_any (CalComponent *comp, const char *str)
-{
- /* As an optimization, and to make life easier for the individual
- * predicate functions, see if we are looking for the empty string right
- * away.
- */
- if (strlen (str) == 0)
- return TRUE;
-
- return (matches_comment (comp, str)
- || matches_description (comp, str)
- || matches_summary (comp, str));
-}
-
-/* (contains? FIELD STR)
- *
- * FIELD - string, name of field to match (any, comment, description, summary)
- * STR - string, match string
- *
- * Returns a boolean indicating whether the specified field contains the
- * specified string.
- */
-static ESExpResult *
-func_contains (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- const char *field;
- const char *str;
- gboolean matches;
- ESExpResult *result;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc != 2) {
- e_sexp_fatal_error (esexp, _("contains? expects 2 arguments"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_STRING) {
- e_sexp_fatal_error (esexp, _("contains? expects argument 1 "
- "to be a string"));
- return NULL;
- }
- field = argv[0]->value.string;
-
- if (argv[1]->type != ESEXP_RES_STRING) {
- e_sexp_fatal_error (esexp, _("contains? expects argument 2 "
- "to be a string"));
- return NULL;
- }
- str = argv[1]->value.string;
-
- /* See if it matches */
-
- if (strcmp (field, "any") == 0)
- matches = matches_any (comp, str);
- else if (strcmp (field, "comment") == 0)
- matches = matches_comment (comp, str);
- else if (strcmp (field, "description") == 0)
- matches = matches_description (comp, str);
- else if (strcmp (field, "summary") == 0)
- matches = matches_summary (comp, str);
- else {
- e_sexp_fatal_error (esexp, _("contains? expects argument 1 to "
- "be one of \"any\", \"summary\", \"description\""));
- return NULL;
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = matches;
-
- return result;
-}
-
-/* (has-categories? STR+)
- * (has-categories? #f)
- *
- * STR - At least one string specifying a category
- * Or you can specify a single #f (boolean false) value for components
- * that have no categories assigned to them ("unfiled").
- *
- * Returns a boolean indicating whether the component has all the specified
- * categories.
- */
-static ESExpResult *
-func_has_categories (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- gboolean unfiled;
- int i;
- GSList *categories;
- gboolean matches;
- ESExpResult *result;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc < 1) {
- e_sexp_fatal_error (esexp, _("has-categories? expects at least 1 argument"));
- return NULL;
- }
-
- if (argc == 1 && argv[0]->type == ESEXP_RES_BOOL)
- unfiled = TRUE;
- else
- unfiled = FALSE;
-
- if (!unfiled)
- for (i = 0; i < argc; i++)
- if (argv[i]->type != ESEXP_RES_STRING) {
- e_sexp_fatal_error (esexp, _("has-categories? expects all arguments "
- "to be strings or one and only one "
- "argument to be a boolean false (#f)"));
- return NULL;
- }
-
- /* Search categories. First, if there are no categories we return
- * whether unfiled components are supposed to match.
- */
-
- cal_component_get_categories_list (comp, &categories);
- if (!categories) {
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = unfiled;
-
- return result;
- }
-
- /* Otherwise, we *do* have categories but unfiled components were
- * requested, so this component does not match.
- */
- if (unfiled) {
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = FALSE;
-
- return result;
- }
-
- matches = TRUE;
-
- for (i = 0; i < argc; i++) {
- const char *sought;
- GSList *l;
- gboolean has_category;
-
- sought = argv[i]->value.string;
-
- has_category = FALSE;
-
- for (l = categories; l; l = l->next) {
- const char *category;
-
- category = l->data;
-
- if (strcmp (category, sought) == 0) {
- has_category = TRUE;
- break;
- }
- }
-
- if (!has_category) {
- matches = FALSE;
- break;
- }
- }
-
- cal_component_free_categories_list (categories);
-
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = matches;
-
- return result;
-}
-
-/* (is-completed?)
- *
- * Returns a boolean indicating whether the component is completed (i.e. has
- * a COMPLETED property. This is really only useful for TODO components.
- */
-static ESExpResult *
-func_is_completed (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- ESExpResult *result;
- struct icaltimetype *t;
- gboolean complete = FALSE;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc != 0) {
- e_sexp_fatal_error (esexp, _("is-completed? expects 0 arguments"));
- return NULL;
- }
-
- cal_component_get_completed (comp, &t);
- if (t) {
- complete = TRUE;
- cal_component_free_icaltimetype (t);
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = complete;
-
- return result;
-}
-
-/* (completed-before? TIME)
- *
- * TIME - time_t
- *
- * Returns a boolean indicating whether the component was completed on or
- * before the given time (i.e. it checks the COMPLETED property).
- * This is really only useful for TODO components.
- */
-static ESExpResult *
-func_completed_before (ESExp *esexp, int argc, ESExpResult **argv, void *data)
-{
- Query *query;
- QueryPrivate *priv;
- CalComponent *comp;
- ESExpResult *result;
- struct icaltimetype *tt;
- icaltimezone *zone;
- gboolean retval = FALSE;
- time_t before_time, completed_time;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->next_comp != NULL);
- comp = priv->next_comp;
-
- /* Check argument types */
-
- if (argc != 1) {
- e_sexp_fatal_error (esexp, _("completed-before? expects 1 argument"));
- return NULL;
- }
-
- if (argv[0]->type != ESEXP_RES_TIME) {
- e_sexp_fatal_error (esexp, _("completed-before? expects argument 1 "
- "to be a time_t"));
- return NULL;
- }
- before_time = argv[0]->value.time;
-
- cal_component_get_completed (comp, &tt);
- if (tt) {
- /* COMPLETED must be in UTC. */
- zone = icaltimezone_get_utc_timezone ();
- completed_time = icaltime_as_timet_with_zone (*tt, zone);
-
-#if 0
- g_print ("Query Time : %s", ctime (&before_time));
- g_print ("Completed Time: %s", ctime (&completed_time));
-#endif
-
- /* We want to return TRUE if before_time is after
- completed_time. */
- if (difftime (before_time, completed_time) > 0) {
-#if 0
- g_print (" Returning TRUE\n");
-#endif
- retval = TRUE;
- }
-
- cal_component_free_icaltimetype (tt);
- }
-
- result = e_sexp_result_new (esexp, ESEXP_RES_BOOL);
- result->value.bool = retval;
-
- return result;
-}
-
-
-
-/* Adds a component to our the UIDs hash table and notifies the client */
-static void
-add_component (Query *query, const char *uid, gboolean query_in_progress, int n_scanned, int total)
-{
- QueryPrivate *priv;
- char *old_uid;
- CORBA_Environment ev;
-
- if (query_in_progress)
- g_assert (n_scanned > 0 || n_scanned <= total);
-
- priv = query->priv;
-
- if (g_hash_table_lookup_extended (priv->uids, uid, (gpointer *) &old_uid, NULL)) {
- g_hash_table_remove (priv->uids, old_uid);
- g_free (old_uid);
- }
-
- g_hash_table_insert (priv->uids, g_strdup (uid), NULL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyObjUpdated (
- priv->ql,
- (char *) uid,
- query_in_progress,
- n_scanned,
- total,
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("add_component(): Could not notify the listener of an "
- "updated component");
-
- CORBA_exception_free (&ev);
-}
-
-/* Removes a component from our the UIDs hash table and notifies the client */
-static void
-remove_component (Query *query, const char *uid)
-{
- QueryPrivate *priv;
- char *old_uid;
- CORBA_Environment ev;
-
- priv = query->priv;
-
- if (!g_hash_table_lookup_extended (priv->uids, uid, (gpointer *) &old_uid, NULL))
- return;
-
- /* The component did match the query before but it no longer does, so we
- * have to notify the client.
- */
-
- g_hash_table_remove (priv->uids, old_uid);
- g_free (old_uid);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyObjRemoved (
- priv->ql,
- (char *) uid,
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("remove_component(): Could not notify the listener of a "
- "removed component");
-
- CORBA_exception_free (&ev);
-}
-
-/* Removes a component from the list of pending UIDs */
-static void
-remove_from_pending (Query *query, const char *remove_uid)
-{
- QueryPrivate *priv;
- GList *l;
-
- priv = query->priv;
-
- for (l = priv->pending_uids; l; l = l->next) {
- char *uid;
-
- g_assert (priv->n_pending > 0);
-
- uid = l->data;
- if (strcmp (remove_uid, uid))
- continue;
-
- g_free (uid);
-
- priv->pending_uids = g_list_remove_link (priv->pending_uids, l);
- g_list_free_1 (l);
- priv->n_pending--;
-
- g_assert ((priv->pending_uids && priv->n_pending != 0)
- || (!priv->pending_uids && priv->n_pending == 0));
-
- break;
- }
-}
-
-static struct {
- char *name;
- ESExpFunc *func;
-} functions[] = {
- /* Time-related functions */
- { "time-now", func_time_now },
- { "make-time", func_make_time },
- { "time-add-day", func_time_add_day },
- { "time-day-begin", func_time_day_begin },
- { "time-day-end", func_time_day_end },
-
- /* Component-related functions */
- { "get-vtype", func_get_vtype },
- { "occur-in-time-range?", func_occur_in_time_range },
- { "contains?", func_contains },
- { "has-categories?", func_has_categories },
- { "is-completed?", func_is_completed },
- { "completed-before?", func_completed_before }
-};
-
-/* Initializes a sexp by interning our own symbols */
-static ESExp *
-create_sexp (Query *query)
-{
- ESExp *esexp;
- int i;
-
- esexp = e_sexp_new ();
-
- for (i = 0; i < (sizeof (functions) / sizeof (functions[0])); i++)
- e_sexp_add_function (esexp, 0, functions[i].name, functions[i].func, query);
-
- return esexp;
-}
-
-/* Creates the ESexp and parses the esexp. If a parse error occurs, it sets the
- * query state to QUERY_PARSE_ERROR and returns FALSE.
- */
-static gboolean
-parse_sexp (Query *query)
-{
- QueryPrivate *priv;
-
- priv = query->priv;
-
- g_assert (priv->state == QUERY_START_PENDING);
-
- /* Compile the query string */
-
- priv->esexp = create_sexp (query);
-
- g_assert (priv->sexp != NULL);
- e_sexp_input_text (priv->esexp, priv->sexp, strlen (priv->sexp));
-
- if (e_sexp_parse (priv->esexp) == -1) {
- const char *error_str;
- CORBA_Environment ev;
-
- priv->state = QUERY_PARSE_ERROR;
-
- /* Report the error to the listener */
-
- error_str = e_sexp_error (priv->esexp);
- g_assert (error_str != NULL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyQueryDone (
- priv->ql,
- GNOME_Evolution_Calendar_QueryListener_PARSE_ERROR,
- error_str,
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("parse_sexp(): Could not notify the listener of "
- "a parse error");
-
- CORBA_exception_free (&ev);
-
- e_sexp_unref (priv->esexp);
- priv->esexp = NULL;
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* Evaluates the query sexp on the specified component and notifies the listener
- * as appropriate.
- */
-static void
-match_component (Query *query, const char *uid,
- gboolean query_in_progress, int n_scanned, int total)
-{
- QueryPrivate *priv;
- CalComponent *comp;
- ESExpResult *result;
-
- priv = query->priv;
-
- g_assert (priv->state == QUERY_IN_PROGRESS || priv->state == QUERY_DONE);
- g_assert (priv->esexp != NULL);
-
- comp = cal_backend_get_object_component (priv->backend, uid);
- if (!comp)
- return;
-
- /* Eval the sexp */
-
- g_assert (priv->next_comp == NULL);
-
- priv->next_comp = comp;
- result = e_sexp_eval (priv->esexp);
- priv->next_comp = NULL;
-
- if (!result) {
- const char *error_str;
- CORBA_Environment ev;
-
- error_str = e_sexp_error (priv->esexp);
- g_assert (error_str != NULL);
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyEvalError (
- priv->ql,
- error_str,
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("match_component(): Could not notify the listener of "
- "an evaluation error");
-
- CORBA_exception_free (&ev);
- return;
- } else if (result->type != ESEXP_RES_BOOL) {
- CORBA_Environment ev;
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyEvalError (
- priv->ql,
- _("Evaluation of the search expression did not yield a boolean value"),
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("match_component(): Could not notify the listener of "
- "an unexpected result value type when evaluating the "
- "search expression");
-
- CORBA_exception_free (&ev);
- } else {
- /* Success; process the component accordingly */
-
- if (result->value.bool)
- add_component (query, uid, query_in_progress, n_scanned, total);
- else
- remove_component (query, uid);
- }
-
- e_sexp_result_free (priv->esexp, result);
-}
-
-/* Processes a single component that is queued in the list */
-static gboolean
-process_component_cb (gpointer data)
-{
- Query *query;
- QueryPrivate *priv;
- char *uid;
- GList *l;
-
- query = QUERY (data);
- priv = query->priv;
-
- /* No more components? */
-
- if (!priv->pending_uids) {
- CORBA_Environment ev;
-
- g_assert (priv->n_pending == 0);
-
- priv->idle_id = 0;
- priv->state = QUERY_DONE;
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyQueryDone (
- priv->ql,
- GNOME_Evolution_Calendar_QueryListener_SUCCESS,
- "",
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("process_component_cb(): Could not notify the listener of "
- "a finished query");
-
- CORBA_exception_free (&ev);
-
- return FALSE;
- }
-
- g_assert (priv->n_pending > 0);
-
- /* Fetch the component */
-
- l = priv->pending_uids;
- priv->pending_uids = g_list_remove_link (priv->pending_uids, l);
- priv->n_pending--;
-
- g_assert ((priv->pending_uids && priv->n_pending != 0)
- || (!priv->pending_uids && priv->n_pending == 0));
-
- uid = l->data;
- g_assert (uid != NULL);
-
- g_list_free_1 (l);
-
- bonobo_object_ref (BONOBO_OBJECT (query));
-
- match_component (query, uid,
- TRUE,
- priv->pending_total - priv->n_pending,
- priv->pending_total);
-
- bonobo_object_unref (BONOBO_OBJECT (query));
-
- g_free (uid);
-
- return TRUE;
-}
-
-/* Populates the query with pending UIDs so that they can be processed
- * asynchronously.
- */
-static void
-populate_query (Query *query)
-{
- QueryPrivate *priv;
-
- priv = query->priv;
- g_assert (priv->idle_id == 0);
- g_assert (priv->state == QUERY_START_PENDING);
-
- priv->pending_uids = cal_backend_get_uids (priv->backend, CALOBJ_TYPE_ANY);
- priv->pending_total = g_list_length (priv->pending_uids);
- priv->n_pending = priv->pending_total;
-
- priv->idle_id = g_idle_add (process_component_cb, query);
-}
-
-/* Callback used when a component changes in the backend */
-static void
-backend_obj_updated_cb (CalBackend *backend, const char *uid, gpointer data)
-{
- Query *query;
- QueryPrivate *priv;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->state == QUERY_IN_PROGRESS || priv->state == QUERY_DONE);
-
- bonobo_object_ref (BONOBO_OBJECT (query));
-
- match_component (query, uid, FALSE, 0, 0);
- remove_from_pending (query, uid);
-
- bonobo_object_unref (BONOBO_OBJECT (query));
-}
-
-/* Callback used when a component is removed from the backend */
-static void
-backend_obj_removed_cb (CalBackend *backend, const char *uid, gpointer data)
-{
- Query *query;
- QueryPrivate *priv;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->state == QUERY_IN_PROGRESS || priv->state == QUERY_DONE);
-
- bonobo_object_ref (BONOBO_OBJECT (query));
-
- remove_component (query, uid);
- remove_from_pending (query, uid);
-
- bonobo_object_unref (BONOBO_OBJECT (query));
-}
-
-/* Idle handler for starting a query */
-static gboolean
-start_query_cb (gpointer data)
-{
- Query *query;
- QueryPrivate *priv;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->state == QUERY_START_PENDING);
-
- priv->idle_id = 0;
-
- if (!parse_sexp (query))
- return FALSE;
-
- /* Populate the query with UIDs so that we can process them asynchronously */
-
- populate_query (query);
-
- gtk_signal_connect (GTK_OBJECT (priv->backend), "obj_updated",
- GTK_SIGNAL_FUNC (backend_obj_updated_cb),
- query);
- gtk_signal_connect (GTK_OBJECT (priv->backend), "obj_removed",
- GTK_SIGNAL_FUNC (backend_obj_removed_cb),
- query);
-
- priv->state = QUERY_IN_PROGRESS;
-
- return FALSE;
-}
-
-/* Callback used when the backend gets loaded; we just queue the query to be
- * started later.
- */
-static void
-backend_opened_cb (CalBackend *backend, CalBackendOpenStatus status, gpointer data)
-{
- Query *query;
- QueryPrivate *priv;
-
- query = QUERY (data);
- priv = query->priv;
-
- g_assert (priv->state == QUERY_WAIT_FOR_BACKEND);
-
- gtk_signal_disconnect_by_data (GTK_OBJECT (priv->backend), query);
- priv->state = QUERY_START_PENDING;
-
- if (status == CAL_BACKEND_OPEN_SUCCESS) {
- g_assert (cal_backend_is_loaded (backend));
- g_assert (priv->idle_id == 0);
-
- priv->idle_id = g_idle_add (start_query_cb, query);
- }
-}
-
-/**
- * query_construct:
- * @query: A live search query.
- * @backend: Calendar backend that the query object will monitor.
- * @ql: Listener for query results.
- * @sexp: Sexp that defines the query.
- *
- * Constructs a #Query object by binding it to a calendar backend and a query
- * listener. The @query object will start to populate itself asynchronously and
- * call the listener as appropriate.
- *
- * Return value: The same value as @query, or NULL if the query could not
- * be constructed.
- **/
-Query *
-query_construct (Query *query,
- CalBackend *backend,
- GNOME_Evolution_Calendar_QueryListener ql,
- const char *sexp)
-{
- QueryPrivate *priv;
- CORBA_Environment ev;
-
- g_return_val_if_fail (query != NULL, NULL);
- g_return_val_if_fail (IS_QUERY (query), NULL);
- g_return_val_if_fail (backend != NULL, NULL);
- g_return_val_if_fail (IS_CAL_BACKEND (backend), NULL);
- g_return_val_if_fail (ql != CORBA_OBJECT_NIL, NULL);
- g_return_val_if_fail (sexp != NULL, NULL);
-
- priv = query->priv;
-
- CORBA_exception_init (&ev);
- priv->ql = CORBA_Object_duplicate (ql, &ev);
- if (BONOBO_EX (&ev)) {
- g_message ("query_construct(): Could not duplicate the listener");
- priv->ql = CORBA_OBJECT_NIL;
- CORBA_exception_free (&ev);
- return NULL;
- }
- CORBA_exception_free (&ev);
-
- priv->backend = backend;
- gtk_object_ref (GTK_OBJECT (priv->backend));
-
- priv->default_zone = cal_backend_get_default_timezone (backend);
-
- priv->sexp = g_strdup (sexp);
-
- /* Queue the query to be started asynchronously */
-
- if (cal_backend_is_loaded (priv->backend)) {
- priv->state = QUERY_START_PENDING;
-
- g_assert (priv->idle_id == 0);
- priv->idle_id = g_idle_add (start_query_cb, query);
- } else
- gtk_signal_connect (GTK_OBJECT (priv->backend), "opened",
- GTK_SIGNAL_FUNC (backend_opened_cb),
- query);
-
- return query;
-}
-
-/**
- * query_new:
- * @backend: Calendar backend that the query object will monitor.
- * @ql: Listener for query results.
- * @sexp: Sexp that defines the query.
- *
- * Creates a new query engine object that monitors a calendar backend.
- *
- * Return value: A newly-created query object, or NULL on failure.
- **/
-Query *
-query_new (CalBackend *backend,
- GNOME_Evolution_Calendar_QueryListener ql,
- const char *sexp)
-{
- Query *query;
-
- query = QUERY (gtk_type_new (QUERY_TYPE));
- if (!query_construct (query, backend, ql, sexp)) {
- bonobo_object_unref (BONOBO_OBJECT (query));
- return NULL;
- }
-
- return query;
-}
diff --git a/calendar/pcs/query.h b/calendar/pcs/query.h
deleted file mode 100644
index 71f289906e..0000000000
--- a/calendar/pcs/query.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Evolution calendar - Live search query implementation
- *
- * Copyright (C) 2001 Ximian, Inc.
- *
- * Author: Federico Mena-Quintero <federico@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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 QUERY_H
-#define QUERY_H
-
-#include <libgnome/gnome-defs.h>
-#include <bonobo/bonobo-xobject.h>
-#include "cal-backend.h"
-
-BEGIN_GNOME_DECLS
-
-
-
-#define QUERY_TYPE (query_get_type ())
-#define QUERY(obj) (GTK_CHECK_CAST ((obj), QUERY_TYPE, Query))
-#define QUERY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), QUERY_TYPE, QueryClass))
-#define IS_QUERY(obj) (GTK_CHECK_TYPE ((obj), QUERY_TYPE))
-#define IS_QUERY_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), QUERY_TYPE))
-
-typedef struct _QueryPrivate QueryPrivate;
-
-typedef struct {
- BonoboXObject xobject;
-
- /* Private data */
- QueryPrivate *priv;
-} Query;
-
-typedef struct {
- BonoboXObjectClass parent_class;
-
- POA_GNOME_Evolution_Calendar_Query__epv epv;
-} QueryClass;
-
-GtkType query_get_type (void);
-
-Query *query_construct (Query *query,
- CalBackend *backend,
- GNOME_Evolution_Calendar_QueryListener ql,
- const char *sexp);
-
-Query *query_new (CalBackend *backend,
- GNOME_Evolution_Calendar_QueryListener ql,
- const char *sexp);
-
-
-
-END_GNOME_DECLS
-
-#endif