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 g_object_ref (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 g_assert (CLASS (backend)->create_object != NULL);
812 (* CLASS (backend)->create_object) (backend, cal, calobj);
816 e_cal_backend_modify_object (ECalBackend *backend, EDataCal *cal, const char *calobj, CalObjModType mod)
818 g_return_if_fail (backend != NULL);
819 g_return_if_fail (E_IS_CAL_BACKEND (backend));
820 g_return_if_fail (calobj != NULL);
822 g_assert (CLASS (backend)->modify_object != NULL);
823 (* CLASS (backend)->modify_object) (backend, cal, calobj, mod);
827 * e_cal_backend_remove_object:
828 * @backend: A calendar backend.
829 * @uid: Unique identifier of the object to remove.
830 * @rid: A recurrence ID.
832 * Removes an object in a calendar backend. The backend will notify all of its
833 * clients about the change.
837 e_cal_backend_remove_object (ECalBackend *backend, EDataCal *cal, const char *uid, const char *rid, CalObjModType mod)
839 g_return_if_fail (backend != NULL);
840 g_return_if_fail (E_IS_CAL_BACKEND (backend));
841 g_return_if_fail (uid != NULL);
843 g_assert (CLASS (backend)->remove_object != NULL);
844 (* CLASS (backend)->remove_object) (backend, cal, uid, rid, mod);
848 e_cal_backend_receive_objects (ECalBackend *backend, EDataCal *cal, const char *calobj)
850 g_return_if_fail (backend != NULL);
851 g_return_if_fail (E_IS_CAL_BACKEND (backend));
852 g_return_if_fail (calobj != NULL);
854 g_assert (CLASS (backend)->receive_objects != NULL);
855 (* CLASS (backend)->receive_objects) (backend, cal, calobj);
859 e_cal_backend_send_objects (ECalBackend *backend, EDataCal *cal, const char *calobj)
861 g_return_if_fail (backend != NULL);
862 g_return_if_fail (E_IS_CAL_BACKEND (backend));
863 g_return_if_fail (calobj != NULL);
865 g_assert (CLASS (backend)->send_objects != NULL);
866 (* CLASS (backend)->send_objects) (backend, cal, calobj);
870 * e_cal_backend_get_timezone:
871 * @backend: A calendar backend.
872 * @tzid: Unique identifier of a VTIMEZONE object. Note that this must not be
875 * Returns the icaltimezone* corresponding to the TZID, or NULL if the TZID
878 * Returns: The icaltimezone* corresponding to the given TZID, or NULL.
881 e_cal_backend_get_timezone (ECalBackend *backend, EDataCal *cal, const char *tzid)
883 g_return_if_fail (backend != NULL);
884 g_return_if_fail (E_IS_CAL_BACKEND (backend));
885 g_return_if_fail (tzid != NULL);
887 g_assert (CLASS (backend)->get_timezone != NULL);
888 (* CLASS (backend)->get_timezone) (backend, cal, tzid);
892 * e_cal_backend_set_default_timezone:
893 * @backend: A calendar backend.
894 * @tzid: The TZID identifying the timezone.
896 * Sets the default timezone for the calendar, which is used to resolve
897 * DATE and floating DATE-TIME values.
899 * Returns: TRUE if the VTIMEZONE data for the timezone was found, or FALSE if
903 e_cal_backend_set_default_timezone (ECalBackend *backend, EDataCal *cal, const char *tzid)
905 g_return_if_fail (backend != NULL);
906 g_return_if_fail (E_IS_CAL_BACKEND (backend));
907 g_return_if_fail (tzid != NULL);
909 g_assert (CLASS (backend)->set_default_timezone != NULL);
910 (* CLASS (backend)->set_default_timezone) (backend, cal, tzid);
914 * e_cal_backend_add_timezone
915 * @backend: A calendar backend.
916 * @tzobj: The timezone object, in a string.
918 * Add a timezone object to the given backend.
920 * Returns: TRUE if successful, or FALSE if not.
923 e_cal_backend_add_timezone (ECalBackend *backend, EDataCal *cal, const char *tzobj)
925 g_return_if_fail (E_IS_CAL_BACKEND (backend));
926 g_return_if_fail (tzobj != NULL);
927 g_return_if_fail (CLASS (backend)->add_timezone != NULL);
929 (* CLASS (backend)->add_timezone) (backend, cal, tzobj);
933 e_cal_backend_internal_get_default_timezone (ECalBackend *backend)
935 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
936 g_return_val_if_fail (CLASS (backend)->internal_get_default_timezone != NULL, NULL);
938 return (* CLASS (backend)->internal_get_default_timezone) (backend);
942 e_cal_backend_internal_get_timezone (ECalBackend *backend, const char *tzid)
944 g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
945 g_return_val_if_fail (tzid != NULL, NULL);
946 g_return_val_if_fail (CLASS (backend)->internal_get_timezone != NULL, NULL);
948 return (* CLASS (backend)->internal_get_timezone) (backend, tzid);
952 e_cal_backend_set_notification_proxy (ECalBackend *backend, ECalBackend *proxy)
954 ECalBackendPrivate *priv;
956 g_return_if_fail (E_IS_CAL_BACKEND (backend));
958 priv = backend->priv;
960 priv->notification_proxy = proxy;
964 * e_cal_backend_notify_object_created:
965 * @backend: A calendar backend.
966 * @calobj: iCalendar representation of new object
968 * Notifies each of the backend's listeners about a new object.
970 * cal_notify_object_created() calls this for you. You only need to
971 * call e_cal_backend_notify_object_created() yourself to report objects
972 * created by non-PCS clients.
975 e_cal_backend_notify_object_created (ECalBackend *backend, const char *calobj)
977 ECalBackendPrivate *priv;
982 priv = backend->priv;
984 if (priv->notification_proxy) {
985 e_cal_backend_notify_object_created (priv->notification_proxy, calobj);
989 queries = e_cal_backend_get_queries (backend);
990 iter = e_list_get_iterator (queries);
992 while (e_iterator_is_valid (iter)) {
993 query = QUERY (e_iterator_get (iter));
995 bonobo_object_ref (query);
996 if (e_data_cal_view_object_matches (query, calobj))
997 e_data_cal_view_notify_objects_added_1 (query, calobj);
998 bonobo_object_unref (query);
1000 e_iterator_next (iter);
1002 g_object_unref (iter);
1003 g_object_unref (queries);
1007 * e_cal_backend_notify_object_modified:
1008 * @backend: A calendar backend.
1009 * @old_object: iCalendar representation of the original form of the object
1010 * @object: iCalendar representation of the new form of the object
1012 * Notifies each of the backend's listeners about a modified object.
1014 * cal_notify_object_modified() calls this for you. You only need to
1015 * call e_cal_backend_notify_object_modified() yourself to report objects
1016 * modified by non-PCS clients.
1019 e_cal_backend_notify_object_modified (ECalBackend *backend,
1020 const char *old_object, const char *object)
1022 ECalBackendPrivate *priv;
1025 EDataCalView *query;
1026 gboolean old_match, new_match;
1028 priv = backend->priv;
1030 if (priv->notification_proxy) {
1031 e_cal_backend_notify_object_modified (priv->notification_proxy, old_object, object);
1035 queries = e_cal_backend_get_queries (backend);
1036 iter = e_list_get_iterator (queries);
1038 while (e_iterator_is_valid (iter)) {
1039 query = QUERY (e_iterator_get (iter));
1041 bonobo_object_ref (query);
1043 old_match = e_data_cal_view_object_matches (query, old_object);
1044 new_match = e_data_cal_view_object_matches (query, object);
1045 if (old_match && new_match)
1046 e_data_cal_view_notify_objects_modified_1 (query, object);
1048 e_data_cal_view_notify_objects_added_1 (query, object);
1049 else /* if (old_match) */ {
1050 icalcomponent *comp;
1052 comp = icalcomponent_new_from_string ((char *)old_object);
1053 e_data_cal_view_notify_objects_removed_1 (query, icalcomponent_get_uid (comp));
1054 icalcomponent_free (comp);
1057 bonobo_object_unref (query);
1059 e_iterator_next (iter);
1061 g_object_unref (iter);
1062 g_object_unref (queries);
1066 * e_cal_backend_notify_object_removed:
1067 * @backend: A calendar backend.
1068 * @uid: the UID of the removed object
1069 * @old_object: iCalendar representation of the removed object
1071 * Notifies each of the backend's listeners about a removed object.
1073 * cal_notify_object_removed() calls this for you. You only need to
1074 * call e_cal_backend_notify_object_removed() yourself to report objects
1075 * removed by non-PCS clients.
1078 e_cal_backend_notify_object_removed (ECalBackend *backend, const char *uid,
1079 const char *old_object)
1081 ECalBackendPrivate *priv;
1084 EDataCalView *query;
1086 priv = backend->priv;
1088 if (priv->notification_proxy) {
1089 e_cal_backend_notify_object_removed (priv->notification_proxy, uid, old_object);
1093 queries = e_cal_backend_get_queries (backend);
1094 iter = e_list_get_iterator (queries);
1096 while (e_iterator_is_valid (iter)) {
1097 query = QUERY (e_iterator_get (iter));
1099 bonobo_object_ref (query);
1100 if (e_data_cal_view_object_matches (query, old_object))
1101 e_data_cal_view_notify_objects_removed_1 (query, uid);
1102 bonobo_object_unref (query);
1104 e_iterator_next (iter);
1106 g_object_unref (iter);
1107 g_object_unref (queries);
1111 * e_cal_backend_notify_mode:
1112 * @backend: A calendar backend.
1113 * @status: Status of the mode set
1114 * @mode: the current mode
1116 * Notifies each of the backend's listeners about the results of a
1120 e_cal_backend_notify_mode (ECalBackend *backend,
1121 GNOME_Evolution_Calendar_CalListener_SetModeStatus status,
1122 GNOME_Evolution_Calendar_CalMode mode)
1124 ECalBackendPrivate *priv = backend->priv;
1127 if (priv->notification_proxy) {
1128 e_cal_backend_notify_mode (priv->notification_proxy, status, mode);
1132 for (l = priv->clients; l; l = l->next)
1133 e_data_cal_notify_mode (l->data, status, mode);
1137 * e_cal_backend_notify_error:
1138 * @backend: A calendar backend.
1139 * @message: Error message
1141 * Notifies each of the backend's listeners about an error
1144 e_cal_backend_notify_error (ECalBackend *backend, const char *message)
1146 ECalBackendPrivate *priv = backend->priv;
1149 if (priv->notification_proxy) {
1150 e_cal_backend_notify_error (priv->notification_proxy, message);
1154 for (l = priv->clients; l; l = l->next)
1155 e_data_cal_notify_error (l->data, message);
1159 add_category_cb (gpointer name, gpointer category, gpointer data)
1161 GNOME_Evolution_Calendar_StringSeq *seq = data;
1163 seq->_buffer[seq->_length++] = CORBA_string_dup (name);
1167 notify_categories_changed (ECalBackend *backend)
1169 ECalBackendPrivate *priv = backend->priv;
1170 GNOME_Evolution_Calendar_StringSeq *seq;
1173 /* Build the sequence of category names */
1174 seq = GNOME_Evolution_Calendar_StringSeq__alloc ();
1176 seq->_maximum = g_hash_table_size (priv->categories);
1177 seq->_buffer = CORBA_sequence_CORBA_string_allocbuf (seq->_maximum);
1178 CORBA_sequence_set_release (seq, TRUE);
1180 g_hash_table_foreach (priv->categories, add_category_cb, seq);
1182 /* Notify the clients */
1183 for (l = priv->clients; l; l = l->next)
1184 e_data_cal_notify_categories_changed (l->data, seq);
1190 idle_notify_categories_changed (gpointer data)
1192 ECalBackend *backend = E_CAL_BACKEND (data);
1193 ECalBackendPrivate *priv = backend->priv;
1195 if (g_hash_table_size (priv->changed_categories)) {
1196 notify_categories_changed (backend);
1197 g_hash_table_foreach_remove (priv->changed_categories, prune_changed_categories, NULL);
1200 priv->category_idle_id = 0;
1206 * e_cal_backend_ref_categories:
1207 * @backend: A calendar backend
1208 * @categories: a list of categories
1210 * Adds 1 to the refcount of each of the named categories. If any of
1211 * the categories are new, clients will be notified of the updated
1212 * category list at idle time.
1215 e_cal_backend_ref_categories (ECalBackend *backend, GSList *categories)
1217 ECalBackendPrivate *priv;
1218 ECalBackendCategory *c;
1221 priv = backend->priv;
1223 while (categories) {
1224 name = categories->data;
1225 c = g_hash_table_lookup (priv->categories, name);
1230 /* See if it was recently removed */
1232 c = g_hash_table_lookup (priv->changed_categories, name);
1233 if (c && c->refcount == 0) {
1234 /* Move it back to the set of live categories */
1235 g_hash_table_remove (priv->changed_categories, c->name);
1238 g_hash_table_insert (priv->categories, c->name, c);
1240 /* Create a new category */
1241 c = g_new (ECalBackendCategory, 1);
1242 c->name = g_strdup (name);
1244 g_hash_table_insert (priv->categories, c->name, c);
1245 g_hash_table_insert (priv->changed_categories, c->name, c);
1249 categories = categories->next;
1252 if (g_hash_table_size (priv->changed_categories) &&
1253 !priv->category_idle_id)
1254 priv->category_idle_id = g_idle_add (idle_notify_categories_changed, backend);
1258 * e_cal_backend_unref_categories:
1259 * @backend: A calendar backend
1260 * @categories: a list of categories
1262 * Subtracts 1 from the refcount of each of the named categories. If
1263 * any of the refcounts go down to 0, clients will be notified of the
1264 * updated category list at idle time.
1267 e_cal_backend_unref_categories (ECalBackend *backend, GSList *categories)
1269 ECalBackendPrivate *priv;
1270 ECalBackendCategory *c;
1273 priv = backend->priv;
1275 while (categories) {
1276 name = categories->data;
1277 c = g_hash_table_lookup (priv->categories, name);
1280 g_assert (c != NULL);
1281 g_assert (c->refcount > 0);
1285 if (c->refcount == 0) {
1286 g_hash_table_remove (priv->categories, c->name);
1287 g_hash_table_insert (priv->changed_categories, c->name, c);
1291 categories = categories->next;
1294 if (g_hash_table_size (priv->changed_categories) &&
1295 !priv->category_idle_id)
1296 priv->category_idle_id = g_idle_add (idle_notify_categories_changed, backend);