1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* Evolution calendar - generic backend class
4 * Copyright (C) 2000 Ximian, Inc.
5 * Copyright (C) 2000 Ximian, Inc.
7 * Authors: Federico Mena-Quintero <federico@ximian.com>
8 * JP Rosevear <jpr@ximian.com>
9 * Rodrigo Moya <rodrigo@ximian.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
26 #include <libxml/parser.h>
27 #include <libxml/parserInternals.h>
28 #include <libxml/xmlmemory.h>
30 #include "e-cal-backend.h"
34 /* A category that exists in some of the objects of the calendar */
36 /* Category name, also used as the key in the categories hash table */
39 /* Number of objects that have this category */
41 } ECalBackendCategory;
43 /* Private part of the CalBackend structure */
44 struct _ECalBackendPrivate {
45 /* The source for this backend */
48 /* URI, from source. This is cached, since we return const. */
51 /* The kind of components for this backend */
52 icalcomponent_kind kind;
54 /* List of Cal objects */
55 GMutex *clients_mutex;
58 GMutex *queries_mutex;
61 /* Hash table of live categories, temporary hash of
62 * added/removed categories, and idle handler for sending
65 GHashTable *categories;
66 GHashTable *changed_categories;
67 guint category_idle_id;
69 /* ECalBackend to pass notifications on to */
70 ECalBackend *notification_proxy;
88 static guint e_cal_backend_signals[LAST_SIGNAL];
90 static void e_cal_backend_class_init (ECalBackendClass *class);
91 static void e_cal_backend_init (ECalBackend *backend);
92 static void e_cal_backend_finalize (GObject *object);
94 static void notify_categories_changed (ECalBackend *backend);
96 #define CLASS(backend) (E_CAL_BACKEND_CLASS (G_OBJECT_GET_CLASS (backend)))
98 static GObjectClass *parent_class;
103 * e_cal_backend_get_type:
106 * Registers the #ECalBackend class if necessary, and returns the type ID
109 * Return value: The type ID of the #ECalBackend class.
112 e_cal_backend_get_type (void)
114 static GType e_cal_backend_type = 0;
116 if (!e_cal_backend_type) {
117 static GTypeInfo info = {
118 sizeof (ECalBackendClass),
119 (GBaseInitFunc) NULL,
120 (GBaseFinalizeFunc) NULL,
121 (GClassInitFunc) e_cal_backend_class_init,
123 sizeof (ECalBackend),
125 (GInstanceInitFunc) e_cal_backend_init,
127 e_cal_backend_type = g_type_register_static (G_TYPE_OBJECT, "ECalBackend", &info, 0);
130 return e_cal_backend_type;
134 e_cal_backend_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
136 ECalBackend *backend;
137 ECalBackendPrivate *priv;
139 backend = E_CAL_BACKEND (object);
140 priv = backend->priv;
142 switch (property_id) {
147 new_source = g_value_get_object (value);
149 g_object_ref (new_source);
152 g_object_unref (priv->source);
154 priv->source = new_source;
159 priv->uri = e_source_get_uri (priv->source);
166 priv->uri = g_value_dup_string (value);
170 priv->kind = g_value_get_ulong (value);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
179 e_cal_backend_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
181 ECalBackend *backend;
182 ECalBackendPrivate *priv;
184 backend = E_CAL_BACKEND (object);
185 priv = backend->priv;
187 switch (property_id) {
189 g_value_set_object (value, e_cal_backend_get_source (backend));
192 g_value_set_string (value, e_cal_backend_get_uri (backend));
195 g_value_set_ulong (value, e_cal_backend_get_kind (backend));
198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
203 /* Class initialization function for the calendar backend */
205 e_cal_backend_class_init (ECalBackendClass *class)
207 GObjectClass *object_class;
209 parent_class = (GObjectClass *) g_type_class_peek_parent (class);
211 object_class = (GObjectClass *) class;
213 object_class->set_property = e_cal_backend_set_property;
214 object_class->get_property = e_cal_backend_get_property;
215 object_class->finalize = e_cal_backend_finalize;
217 g_object_class_install_property (object_class, PROP_SOURCE,
218 g_param_spec_object ("source", NULL, NULL, E_TYPE_SOURCE,
219 G_PARAM_READABLE | G_PARAM_WRITABLE
220 | G_PARAM_CONSTRUCT_ONLY));
222 g_object_class_install_property (object_class, PROP_URI,
223 g_param_spec_string ("uri", NULL, NULL, "",
224 G_PARAM_READABLE | G_PARAM_WRITABLE
225 | G_PARAM_CONSTRUCT_ONLY));
227 g_object_class_install_property (object_class, PROP_KIND,
228 g_param_spec_ulong ("kind", NULL, NULL,
229 ICAL_NO_COMPONENT, ICAL_XLICMIMEPART_COMPONENT,
231 G_PARAM_READABLE | G_PARAM_WRITABLE
232 | G_PARAM_CONSTRUCT_ONLY));
233 e_cal_backend_signals[LAST_CLIENT_GONE] =
234 g_signal_new ("last_client_gone",
235 G_TYPE_FROM_CLASS (class),
237 G_STRUCT_OFFSET (ECalBackendClass, last_client_gone),
239 g_cclosure_marshal_VOID__VOID,
241 e_cal_backend_signals[OPENED] =
242 g_signal_new ("opened",
243 G_TYPE_FROM_CLASS (class),
245 G_STRUCT_OFFSET (ECalBackendClass, opened),
247 g_cclosure_marshal_VOID__ENUM,
250 e_cal_backend_signals[REMOVED] =
251 g_signal_new ("removed",
252 G_TYPE_FROM_CLASS (class),
254 G_STRUCT_OFFSET (ECalBackendClass, removed),
256 g_cclosure_marshal_VOID__ENUM,
260 class->last_client_gone = NULL;
261 class->opened = NULL;
262 class->obj_updated = NULL;
264 class->get_cal_address = NULL;
265 class->get_alarm_email_address = NULL;
266 class->get_static_capabilities = NULL;
268 class->is_loaded = NULL;
269 class->is_read_only = NULL;
270 class->start_query = NULL;
271 class->get_mode = NULL;
272 class->set_mode = NULL;
273 class->get_object = NULL;
274 class->get_default_object = NULL;
275 class->get_object_list = NULL;
276 class->get_free_busy = NULL;
277 class->get_changes = NULL;
278 class->discard_alarm = NULL;
279 class->create_object = NULL;
280 class->modify_object = NULL;
281 class->remove_object = NULL;
282 class->receive_objects = NULL;
283 class->send_objects = NULL;
284 class->get_timezone = NULL;
285 class->add_timezone = NULL;
286 class->set_default_timezone = NULL;
289 /* Object initialization func for the calendar backend */
291 e_cal_backend_init (ECalBackend *backend)
293 ECalBackendPrivate *priv;
295 priv = g_new0 (ECalBackendPrivate, 1);
296 backend->priv = priv;
298 priv->clients = NULL;
299 priv->clients_mutex = g_mutex_new ();
301 /* FIXME bonobo_object_ref/unref? */
302 priv->queries = e_list_new((EListCopyFunc) g_object_ref, (EListFreeFunc) g_object_unref, NULL);
303 priv->queries_mutex = g_mutex_new ();
305 priv->categories = g_hash_table_new (g_str_hash, g_str_equal);
306 priv->changed_categories = g_hash_table_new (g_str_hash, g_str_equal);
309 /* Used from g_hash_table_foreach(), frees a ECalBackendCategory structure */
311 free_category_cb (gpointer key, gpointer value, gpointer data)
313 ECalBackendCategory *c = value;
320 prune_changed_categories (gpointer key, gpointer value, gpointer data)
322 ECalBackendCategory *c = value;
325 free_category_cb (key, value, data);
330 e_cal_backend_finalize (GObject *object)
332 ECalBackend *backend = (ECalBackend *)object;
333 ECalBackendPrivate *priv;
335 priv = backend->priv;
337 g_assert (priv->clients == NULL);
339 g_object_unref (priv->queries);
341 g_hash_table_foreach_remove (priv->changed_categories, prune_changed_categories, NULL);
342 g_hash_table_destroy (priv->changed_categories);
344 g_hash_table_foreach (priv->categories, free_category_cb, NULL);
345 g_hash_table_destroy (priv->categories);
347 g_mutex_free (priv->clients_mutex);
348 g_mutex_free (priv->queries_mutex);
350 if (priv->category_idle_id)
351 g_source_remove (priv->category_idle_id);
355 G_OBJECT_CLASS (parent_class)->finalize (object);
361 e_cal_backend_get_source (ECalBackend *backend)
363 ECalBackendPrivate *priv;
365 g_return_val_if_fail (backend != NULL, NULL);
366 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
368 priv = backend->priv;
374 * e_cal_backend_get_uri:
375 * @backend: A calendar backend.
377 * Queries the URI of a calendar backend, which must already have an open
380 * Return value: The URI where the calendar is stored.
383 e_cal_backend_get_uri (ECalBackend *backend)
385 ECalBackendPrivate *priv;
387 g_return_val_if_fail (backend != NULL, NULL);
388 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
390 priv = backend->priv;
396 e_cal_backend_get_kind (ECalBackend *backend)
398 ECalBackendPrivate *priv;
400 g_return_val_if_fail (backend != NULL, ICAL_NO_COMPONENT);
401 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), ICAL_NO_COMPONENT);
403 priv = backend->priv;
409 cal_destroy_cb (gpointer data, GObject *where_cal_was)
411 ECalBackend *backend = E_CAL_BACKEND (data);
413 e_cal_backend_remove_client (backend, (EDataCal *) where_cal_was);
417 listener_died_cb (gpointer cnx, gpointer data)
419 EDataCal *cal = E_DATA_CAL (data);
421 e_cal_backend_remove_client (e_data_cal_get_backend (cal), cal);
425 last_client_gone (ECalBackend *backend)
427 g_signal_emit (backend, e_cal_backend_signals[LAST_CLIENT_GONE], 0);
431 e_cal_backend_add_client (ECalBackend *backend, EDataCal *cal)
433 ECalBackendPrivate *priv;
435 g_return_if_fail (backend != NULL);
436 g_return_if_fail (E_IS_CAL_BACKEND (backend));
437 g_return_if_fail (cal != NULL);
438 g_return_if_fail (E_IS_DATA_CAL (cal));
440 priv = backend->priv;
442 bonobo_object_set_immortal (BONOBO_OBJECT (cal), TRUE);
444 g_object_weak_ref (G_OBJECT (cal), cal_destroy_cb, backend);
446 ORBit_small_listen_for_broken (e_data_cal_get_listener (cal), G_CALLBACK (listener_died_cb), cal);
448 g_mutex_lock (priv->clients_mutex);
449 priv->clients = g_list_append (priv->clients, cal);
450 g_mutex_unlock (priv->clients_mutex);
452 /* Tell the new client about the list of categories.
453 * (Ends up telling all the other clients too, but *shrug*.)
455 /* FIXME This doesn't seem right at all */
456 notify_categories_changed (backend);
460 e_cal_backend_remove_client (ECalBackend *backend, EDataCal *cal)
462 ECalBackendPrivate *priv;
464 /* XXX this needs a bit more thinking wrt the mutex - we
465 should be holding it when we check to see if clients is
467 g_return_if_fail (backend != NULL);
468 g_return_if_fail (E_IS_CAL_BACKEND (backend));
469 g_return_if_fail (cal != NULL);
470 g_return_if_fail (E_IS_DATA_CAL (cal));
472 priv = backend->priv;
475 g_mutex_lock (priv->clients_mutex);
476 priv->clients = g_list_remove (priv->clients, cal);
477 g_mutex_unlock (priv->clients_mutex);
479 /* When all clients go away, notify the parent factory about it so that
480 * it may decide whether to kill the backend or not.
483 last_client_gone (backend);
487 e_cal_backend_add_query (ECalBackend *backend, EDataCalView *query)
489 g_return_if_fail (backend != NULL);
490 g_return_if_fail (E_IS_CAL_BACKEND (backend));
492 g_mutex_lock (backend->priv->queries_mutex);
494 e_list_append (backend->priv->queries, query);
496 g_mutex_unlock (backend->priv->queries_mutex);
500 e_cal_backend_get_queries (ECalBackend *backend)
502 g_return_val_if_fail (backend != NULL, NULL);
503 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
505 return backend->priv->queries;
510 * e_cal_backend_get_cal_address:
511 * @backend: A calendar backend.
513 * Queries the cal address associated with a calendar backend, which
514 * must already have an open calendar.
516 * Return value: The cal address associated with the calendar.
519 e_cal_backend_get_cal_address (ECalBackend *backend, EDataCal *cal)
521 g_return_if_fail (backend != NULL);
522 g_return_if_fail (E_IS_CAL_BACKEND (backend));
524 g_assert (CLASS (backend)->get_cal_address != NULL);
525 (* CLASS (backend)->get_cal_address) (backend, cal);
529 e_cal_backend_get_alarm_email_address (ECalBackend *backend, EDataCal *cal)
531 g_return_if_fail (backend != NULL);
532 g_return_if_fail (E_IS_CAL_BACKEND (backend));
534 g_assert (CLASS (backend)->get_alarm_email_address != NULL);
535 (* CLASS (backend)->get_alarm_email_address) (backend, cal);
539 e_cal_backend_get_ldap_attribute (ECalBackend *backend, EDataCal *cal)
541 g_return_if_fail (backend != NULL);
542 g_return_if_fail (E_IS_CAL_BACKEND (backend));
544 g_assert (CLASS (backend)->get_ldap_attribute != NULL);
545 (* CLASS (backend)->get_ldap_attribute) (backend, cal);
549 e_cal_backend_get_static_capabilities (ECalBackend *backend, EDataCal *cal)
551 g_return_if_fail (backend != NULL);
552 g_return_if_fail (E_IS_CAL_BACKEND (backend));
554 g_assert (CLASS (backend)->get_static_capabilities != NULL);
555 (* CLASS (backend)->get_static_capabilities) (backend, cal);
559 * e_cal_backend_open:
560 * @backend: A calendar backend.
561 * @uristr: URI that contains the calendar data.
562 * @only_if_exists: Whether the calendar should be opened only if it already
563 * exists. If FALSE, a new calendar will be created when the specified @uri
565 * @username: User name to use for authentication (if needed).
566 * @password: Password for @username.
568 * Opens a calendar backend with data from a calendar stored at the specified
571 * Return value: An operation status code.
574 e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists,
575 const char *username, const char *password)
577 g_return_if_fail (backend != NULL);
578 g_return_if_fail (E_IS_CAL_BACKEND (backend));
580 g_assert (CLASS (backend)->open != NULL);
581 (* CLASS (backend)->open) (backend, cal, only_if_exists, username, password);
585 e_cal_backend_remove (ECalBackend *backend, EDataCal *cal)
587 g_return_if_fail (backend != NULL);
588 g_return_if_fail (E_IS_CAL_BACKEND (backend));
590 g_assert (CLASS (backend)->remove != NULL);
591 (* CLASS (backend)->remove) (backend, cal);
595 * e_cal_backend_is_loaded:
596 * @backend: A calendar backend.
598 * Queries whether a calendar backend has been loaded yet.
600 * Return value: TRUE if the backend has been loaded with data, FALSE
604 e_cal_backend_is_loaded (ECalBackend *backend)
608 g_return_val_if_fail (backend != NULL, FALSE);
609 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE);
611 g_assert (CLASS (backend)->is_loaded != NULL);
612 result = (* CLASS (backend)->is_loaded) (backend);
618 * e_cal_backend_is_read_only
619 * @backend: A calendar backend.
621 * Queries whether a calendar backend is read only or not.
623 * Return value: TRUE if the calendar is read only, FALSE otherwise.
626 e_cal_backend_is_read_only (ECalBackend *backend, EDataCal *cal)
628 g_return_if_fail (backend != NULL);
629 g_return_if_fail (E_IS_CAL_BACKEND (backend));
631 g_assert (CLASS (backend)->is_read_only != NULL);
632 (* CLASS (backend)->is_read_only) (backend, cal);
636 e_cal_backend_start_query (ECalBackend *backend, EDataCalView *query)
638 g_return_if_fail (backend != NULL);
639 g_return_if_fail (E_IS_CAL_BACKEND (backend));
641 g_assert (CLASS (backend)->start_query != NULL);
642 (* CLASS (backend)->start_query) (backend, query);
646 * e_cal_backend_get_mode:
647 * @backend: A calendar backend.
649 * Queries whether a calendar backend is connected remotely.
651 * Return value: The current mode the calendar is in
654 e_cal_backend_get_mode (ECalBackend *backend)
658 g_return_val_if_fail (backend != NULL, FALSE);
659 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE);
661 g_assert (CLASS (backend)->get_mode != NULL);
662 result = (* CLASS (backend)->get_mode) (backend);
669 * e_cal_backend_set_mode:
670 * @backend: A calendar backend
671 * @mode: Mode to change to
673 * Sets the mode of the calendar
677 e_cal_backend_set_mode (ECalBackend *backend, CalMode mode)
679 g_return_if_fail (backend != NULL);
680 g_return_if_fail (E_IS_CAL_BACKEND (backend));
682 g_assert (CLASS (backend)->set_mode != NULL);
683 (* CLASS (backend)->set_mode) (backend, mode);
687 e_cal_backend_get_default_object (ECalBackend *backend, EDataCal *cal)
689 g_return_if_fail (backend != NULL);
690 g_return_if_fail (E_IS_CAL_BACKEND (backend));
692 g_assert (CLASS (backend)->get_default_object != NULL);
693 (* CLASS (backend)->get_default_object) (backend, cal);
697 * e_cal_backend_get_object:
698 * @backend: A calendar backend.
699 * @uid: Unique identifier for a calendar object.
700 * @rid: ID for the object's recurrence to get.
702 * Queries a calendar backend for a calendar object based on its unique
703 * identifier and its recurrence ID (if a recurrent appointment).
705 * Return value: The string representation of a complete calendar wrapping the
706 * the sought object, or NULL if no object had the specified UID.
709 e_cal_backend_get_object (ECalBackend *backend, EDataCal *cal, const char *uid, const char *rid)
711 g_return_if_fail (backend != NULL);
712 g_return_if_fail (E_IS_CAL_BACKEND (backend));
713 g_return_if_fail (uid != NULL);
715 g_assert (CLASS (backend)->get_object != NULL);
716 (* CLASS (backend)->get_object) (backend, cal, uid, rid);
720 * e_cal_backend_get_object_list:
729 e_cal_backend_get_object_list (ECalBackend *backend, EDataCal *cal, const char *sexp)
731 g_return_if_fail (backend != NULL);
732 g_return_if_fail (E_IS_CAL_BACKEND (backend));
734 g_assert (CLASS (backend)->get_object_list != NULL);
735 return (* CLASS (backend)->get_object_list) (backend, cal, sexp);
739 * e_cal_backend_get_free_busy:
740 * @backend: A calendar backend.
741 * @users: List of users to get free/busy information for.
742 * @start: Start time for query.
743 * @end: End time for query.
745 * Gets a free/busy object for the given time interval
747 * Return value: a list of CalObj's
750 e_cal_backend_get_free_busy (ECalBackend *backend, EDataCal *cal, GList *users, time_t start, time_t end)
752 g_return_if_fail (backend != NULL);
753 g_return_if_fail (E_IS_CAL_BACKEND (backend));
754 g_return_if_fail (start != -1 && end != -1);
755 g_return_if_fail (start <= end);
757 g_assert (CLASS (backend)->get_free_busy != NULL);
758 (* CLASS (backend)->get_free_busy) (backend, cal, users, start, end);
762 * e_cal_backend_get_changes:
763 * @backend: A calendar backend
764 * @change_id: A unique uid for the callers change list
766 * Builds a sequence of objects and the type of change that occurred on them since
767 * the last time the give change_id was seen
769 * Return value: A list of the objects that changed and the type of change
772 e_cal_backend_get_changes (ECalBackend *backend, EDataCal *cal, const char *change_id)
774 g_return_if_fail (backend != NULL);
775 g_return_if_fail (E_IS_CAL_BACKEND (backend));
776 g_return_if_fail (change_id != NULL);
778 g_assert (CLASS (backend)->get_changes != NULL);
779 (* CLASS (backend)->get_changes) (backend, cal, change_id);
783 * e_cal_backend_discard_alarm
784 * @backend: A calendar backend.
785 * @uid: UID of the component to discard the alarm from.
788 * Discards an alarm from the given component. This allows the specific backend
789 * to do whatever is needed to really discard the alarm.
793 e_cal_backend_discard_alarm (ECalBackend *backend, EDataCal *cal, const char *uid, const char *auid)
795 g_return_if_fail (backend != NULL);
796 g_return_if_fail (E_IS_CAL_BACKEND (backend));
797 g_return_if_fail (uid != NULL);
798 g_return_if_fail (auid != NULL);
800 g_assert (CLASS (backend)->discard_alarm != NULL);
801 (* CLASS (backend)->discard_alarm) (backend, cal, uid, auid);
805 e_cal_backend_create_object (ECalBackend *backend, EDataCal *cal, const char *calobj)
807 g_return_if_fail (backend != NULL);
808 g_return_if_fail (E_IS_CAL_BACKEND (backend));
809 g_return_if_fail (calobj != NULL);
811 if (CLASS (backend)->create_object)
812 (* CLASS (backend)->create_object) (backend, cal, calobj);
814 e_data_cal_notify_object_created (cal, GNOME_Evolution_Calendar_PermissionDenied, NULL, NULL);
818 e_cal_backend_modify_object (ECalBackend *backend, EDataCal *cal, const char *calobj, CalObjModType mod)
820 g_return_if_fail (backend != NULL);
821 g_return_if_fail (E_IS_CAL_BACKEND (backend));
822 g_return_if_fail (calobj != NULL);
824 if (CLASS (backend)->modify_object)
825 (* CLASS (backend)->modify_object) (backend, cal, calobj, mod);
827 e_data_cal_notify_object_removed (cal, GNOME_Evolution_Calendar_PermissionDenied, NULL, NULL);
831 * e_cal_backend_remove_object:
832 * @backend: A calendar backend.
833 * @uid: Unique identifier of the object to remove.
834 * @rid: A recurrence ID.
836 * Removes an object in a calendar backend. The backend will notify all of its
837 * clients about the change.
841 e_cal_backend_remove_object (ECalBackend *backend, EDataCal *cal, const char *uid, const char *rid, CalObjModType mod)
843 g_return_if_fail (backend != NULL);
844 g_return_if_fail (E_IS_CAL_BACKEND (backend));
845 g_return_if_fail (uid != NULL);
847 g_assert (CLASS (backend)->remove_object != NULL);
848 (* CLASS (backend)->remove_object) (backend, cal, uid, rid, mod);
852 e_cal_backend_receive_objects (ECalBackend *backend, EDataCal *cal, const char *calobj)
854 g_return_if_fail (backend != NULL);
855 g_return_if_fail (E_IS_CAL_BACKEND (backend));
856 g_return_if_fail (calobj != NULL);
858 g_assert (CLASS (backend)->receive_objects != NULL);
859 (* CLASS (backend)->receive_objects) (backend, cal, calobj);
863 e_cal_backend_send_objects (ECalBackend *backend, EDataCal *cal, const char *calobj)
865 g_return_if_fail (backend != NULL);
866 g_return_if_fail (E_IS_CAL_BACKEND (backend));
867 g_return_if_fail (calobj != NULL);
869 g_assert (CLASS (backend)->send_objects != NULL);
870 (* CLASS (backend)->send_objects) (backend, cal, calobj);
874 * e_cal_backend_get_timezone:
875 * @backend: A calendar backend.
876 * @tzid: Unique identifier of a VTIMEZONE object. Note that this must not be
879 * Returns the icaltimezone* corresponding to the TZID, or NULL if the TZID
882 * Returns: The icaltimezone* corresponding to the given TZID, or NULL.
885 e_cal_backend_get_timezone (ECalBackend *backend, EDataCal *cal, const char *tzid)
887 g_return_if_fail (backend != NULL);
888 g_return_if_fail (E_IS_CAL_BACKEND (backend));
889 g_return_if_fail (tzid != NULL);
891 g_assert (CLASS (backend)->get_timezone != NULL);
892 (* CLASS (backend)->get_timezone) (backend, cal, tzid);
896 * e_cal_backend_set_default_timezone:
897 * @backend: A calendar backend.
898 * @tzid: The TZID identifying the timezone.
900 * Sets the default timezone for the calendar, which is used to resolve
901 * DATE and floating DATE-TIME values.
903 * Returns: TRUE if the VTIMEZONE data for the timezone was found, or FALSE if
907 e_cal_backend_set_default_timezone (ECalBackend *backend, EDataCal *cal, const char *tzid)
909 g_return_if_fail (backend != NULL);
910 g_return_if_fail (E_IS_CAL_BACKEND (backend));
911 g_return_if_fail (tzid != NULL);
913 g_assert (CLASS (backend)->set_default_timezone != NULL);
914 (* CLASS (backend)->set_default_timezone) (backend, cal, tzid);
918 * e_cal_backend_add_timezone
919 * @backend: A calendar backend.
920 * @tzobj: The timezone object, in a string.
922 * Add a timezone object to the given backend.
924 * Returns: TRUE if successful, or FALSE if not.
927 e_cal_backend_add_timezone (ECalBackend *backend, EDataCal *cal, const char *tzobj)
929 g_return_if_fail (E_IS_CAL_BACKEND (backend));
930 g_return_if_fail (tzobj != NULL);
931 g_return_if_fail (CLASS (backend)->add_timezone != NULL);
933 (* CLASS (backend)->add_timezone) (backend, cal, tzobj);
937 e_cal_backend_internal_get_default_timezone (ECalBackend *backend)
939 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
940 g_return_val_if_fail (CLASS (backend)->internal_get_default_timezone != NULL, NULL);
942 return (* CLASS (backend)->internal_get_default_timezone) (backend);
946 e_cal_backend_internal_get_timezone (ECalBackend *backend, const char *tzid)
948 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
949 g_return_val_if_fail (tzid != NULL, NULL);
950 g_return_val_if_fail (CLASS (backend)->internal_get_timezone != NULL, NULL);
952 return (* CLASS (backend)->internal_get_timezone) (backend, tzid);
956 e_cal_backend_set_notification_proxy (ECalBackend *backend, ECalBackend *proxy)
958 ECalBackendPrivate *priv;
960 g_return_if_fail (E_IS_CAL_BACKEND (backend));
962 priv = backend->priv;
964 priv->notification_proxy = proxy;
968 * e_cal_backend_notify_object_created:
969 * @backend: A calendar backend.
970 * @calobj: iCalendar representation of new object
972 * Notifies each of the backend's listeners about a new object.
974 * cal_notify_object_created() calls this for you. You only need to
975 * call e_cal_backend_notify_object_created() yourself to report objects
976 * created by non-PCS clients.
979 e_cal_backend_notify_object_created (ECalBackend *backend, const char *calobj)
981 ECalBackendPrivate *priv;
986 priv = backend->priv;
988 if (priv->notification_proxy) {
989 e_cal_backend_notify_object_created (priv->notification_proxy, calobj);
993 queries = e_cal_backend_get_queries (backend);
994 iter = e_list_get_iterator (queries);
996 while (e_iterator_is_valid (iter)) {
997 query = QUERY (e_iterator_get (iter));
999 bonobo_object_ref (query);
1000 if (e_data_cal_view_object_matches (query, calobj))
1001 e_data_cal_view_notify_objects_added_1 (query, calobj);
1002 bonobo_object_unref (query);
1004 e_iterator_next (iter);
1006 g_object_unref (iter);
1007 g_object_unref (queries);
1011 * e_cal_backend_notify_object_modified:
1012 * @backend: A calendar backend.
1013 * @old_object: iCalendar representation of the original form of the object
1014 * @object: iCalendar representation of the new form of the object
1016 * Notifies each of the backend's listeners about a modified object.
1018 * cal_notify_object_modified() calls this for you. You only need to
1019 * call e_cal_backend_notify_object_modified() yourself to report objects
1020 * modified by non-PCS clients.
1023 e_cal_backend_notify_object_modified (ECalBackend *backend,
1024 const char *old_object, const char *object)
1026 ECalBackendPrivate *priv;
1029 EDataCalView *query;
1030 gboolean old_match, new_match;
1032 priv = backend->priv;
1034 if (priv->notification_proxy) {
1035 e_cal_backend_notify_object_modified (priv->notification_proxy, old_object, object);
1039 queries = e_cal_backend_get_queries (backend);
1040 iter = e_list_get_iterator (queries);
1042 while (e_iterator_is_valid (iter)) {
1043 query = QUERY (e_iterator_get (iter));
1045 bonobo_object_ref (query);
1047 old_match = e_data_cal_view_object_matches (query, old_object);
1048 new_match = e_data_cal_view_object_matches (query, object);
1049 if (old_match && new_match)
1050 e_data_cal_view_notify_objects_modified_1 (query, object);
1052 e_data_cal_view_notify_objects_added_1 (query, object);
1053 else if (old_match) {
1054 icalcomponent *comp;
1056 comp = icalcomponent_new_from_string ((char *)old_object);
1057 e_data_cal_view_notify_objects_removed_1 (query, icalcomponent_get_uid (comp));
1058 icalcomponent_free (comp);
1061 bonobo_object_unref (query);
1063 e_iterator_next (iter);
1065 g_object_unref (iter);
1066 g_object_unref (queries);
1070 * e_cal_backend_notify_object_removed:
1071 * @backend: A calendar backend.
1072 * @uid: the UID of the removed object
1073 * @old_object: iCalendar representation of the removed object
1075 * Notifies each of the backend's listeners about a removed object.
1077 * cal_notify_object_removed() calls this for you. You only need to
1078 * call e_cal_backend_notify_object_removed() yourself to report objects
1079 * removed by non-PCS clients.
1082 e_cal_backend_notify_object_removed (ECalBackend *backend, const char *uid,
1083 const char *old_object)
1085 ECalBackendPrivate *priv;
1088 EDataCalView *query;
1090 priv = backend->priv;
1092 if (priv->notification_proxy) {
1093 e_cal_backend_notify_object_removed (priv->notification_proxy, uid, old_object);
1097 queries = e_cal_backend_get_queries (backend);
1098 iter = e_list_get_iterator (queries);
1100 while (e_iterator_is_valid (iter)) {
1101 query = QUERY (e_iterator_get (iter));
1103 bonobo_object_ref (query);
1104 if (e_data_cal_view_object_matches (query, old_object))
1105 e_data_cal_view_notify_objects_removed_1 (query, uid);
1106 bonobo_object_unref (query);
1108 e_iterator_next (iter);
1110 g_object_unref (iter);
1111 g_object_unref (queries);
1115 * e_cal_backend_notify_mode:
1116 * @backend: A calendar backend.
1117 * @status: Status of the mode set
1118 * @mode: the current mode
1120 * Notifies each of the backend's listeners about the results of a
1124 e_cal_backend_notify_mode (ECalBackend *backend,
1125 GNOME_Evolution_Calendar_CalListener_SetModeStatus status,
1126 GNOME_Evolution_Calendar_CalMode mode)
1128 ECalBackendPrivate *priv = backend->priv;
1131 if (priv->notification_proxy) {
1132 e_cal_backend_notify_mode (priv->notification_proxy, status, mode);
1136 for (l = priv->clients; l; l = l->next)
1137 e_data_cal_notify_mode (l->data, status, mode);
1141 * e_cal_backend_notify_error:
1142 * @backend: A calendar backend.
1143 * @message: Error message
1145 * Notifies each of the backend's listeners about an error
1148 e_cal_backend_notify_error (ECalBackend *backend, const char *message)
1150 ECalBackendPrivate *priv = backend->priv;
1153 if (priv->notification_proxy) {
1154 e_cal_backend_notify_error (priv->notification_proxy, message);
1158 for (l = priv->clients; l; l = l->next)
1159 e_data_cal_notify_error (l->data, message);
1163 add_category_cb (gpointer name, gpointer category, gpointer data)
1165 GNOME_Evolution_Calendar_StringSeq *seq = data;
1167 seq->_buffer[seq->_length++] = CORBA_string_dup (name);
1171 notify_categories_changed (ECalBackend *backend)
1173 ECalBackendPrivate *priv = backend->priv;
1174 GNOME_Evolution_Calendar_StringSeq *seq;
1177 /* Build the sequence of category names */
1178 seq = GNOME_Evolution_Calendar_StringSeq__alloc ();
1180 seq->_maximum = g_hash_table_size (priv->categories);
1181 seq->_buffer = CORBA_sequence_CORBA_string_allocbuf (seq->_maximum);
1182 CORBA_sequence_set_release (seq, TRUE);
1184 g_hash_table_foreach (priv->categories, add_category_cb, seq);
1186 /* Notify the clients */
1187 for (l = priv->clients; l; l = l->next)
1188 e_data_cal_notify_categories_changed (l->data, seq);
1194 idle_notify_categories_changed (gpointer data)
1196 ECalBackend *backend = E_CAL_BACKEND (data);
1197 ECalBackendPrivate *priv = backend->priv;
1199 if (g_hash_table_size (priv->changed_categories)) {
1200 notify_categories_changed (backend);
1201 g_hash_table_foreach_remove (priv->changed_categories, prune_changed_categories, NULL);
1204 priv->category_idle_id = 0;
1210 * e_cal_backend_ref_categories:
1211 * @backend: A calendar backend
1212 * @categories: a list of categories
1214 * Adds 1 to the refcount of each of the named categories. If any of
1215 * the categories are new, clients will be notified of the updated
1216 * category list at idle time.
1219 e_cal_backend_ref_categories (ECalBackend *backend, GSList *categories)
1221 ECalBackendPrivate *priv;
1222 ECalBackendCategory *c;
1225 priv = backend->priv;
1227 while (categories) {
1228 name = categories->data;
1229 c = g_hash_table_lookup (priv->categories, name);
1234 /* See if it was recently removed */
1236 c = g_hash_table_lookup (priv->changed_categories, name);
1237 if (c && c->refcount == 0) {
1238 /* Move it back to the set of live categories */
1239 g_hash_table_remove (priv->changed_categories, c->name);
1242 g_hash_table_insert (priv->categories, c->name, c);
1244 /* Create a new category */
1245 c = g_new (ECalBackendCategory, 1);
1246 c->name = g_strdup (name);
1248 g_hash_table_insert (priv->categories, c->name, c);
1249 g_hash_table_insert (priv->changed_categories, c->name, c);
1253 categories = categories->next;
1256 if (g_hash_table_size (priv->changed_categories) &&
1257 !priv->category_idle_id)
1258 priv->category_idle_id = g_idle_add (idle_notify_categories_changed, backend);
1262 * e_cal_backend_unref_categories:
1263 * @backend: A calendar backend
1264 * @categories: a list of categories
1266 * Subtracts 1 from the refcount of each of the named categories. If
1267 * any of the refcounts go down to 0, clients will be notified of the
1268 * updated category list at idle time.
1271 e_cal_backend_unref_categories (ECalBackend *backend, GSList *categories)
1273 ECalBackendPrivate *priv;
1274 ECalBackendCategory *c;
1277 priv = backend->priv;
1279 while (categories) {
1280 name = categories->data;
1281 c = g_hash_table_lookup (priv->categories, name);
1284 g_assert (c != NULL);
1285 g_assert (c->refcount > 0);
1289 if (c->refcount == 0) {
1290 g_hash_table_remove (priv->categories, c->name);
1291 g_hash_table_insert (priv->changed_categories, c->name, c);
1295 categories = categories->next;
1298 if (g_hash_table_size (priv->changed_categories) &&
1299 !priv->category_idle_id)
1300 priv->category_idle_id = g_idle_add (idle_notify_categories_changed, backend);