updated novell copyright notices
[platform/upstream/evolution-data-server.git] / calendar / libedata-cal / e-data-cal.c
1 /* Evolution calendar client interface object
2  *
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
5  * Authors: Federico Mena-Quintero <federico@ximian.com>
6  *          Rodrigo Moya <rodrigo@ximian.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of version 2 of the GNU Lesser General Public
10  * License as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <libical/ical.h>
27 #include <bonobo/bonobo-main.h>
28 #include <bonobo/bonobo-exception.h>
29 #include <libedata-cal/e-cal-backend.h>
30 #include "e-data-cal.h"
31
32 #define PARENT_TYPE         BONOBO_TYPE_OBJECT
33
34 static BonoboObjectClass *parent_class;
35
36 /* Private part of the Cal structure */
37 struct _EDataCalPrivate {
38         /* Our backend */
39         ECalBackend *backend;
40
41         /* Listener on the client we notify */
42         GNOME_Evolution_Calendar_CalListener listener;
43
44         /* Cache of live queries */
45         GHashTable *live_queries;
46 };
47
48 /* Cal::get_uri method */
49 static CORBA_char *
50 impl_Cal_get_uri (PortableServer_Servant servant,
51                   CORBA_Environment *ev)
52 {
53         EDataCal *cal;
54         EDataCalPrivate *priv;
55         const char *str_uri;
56         CORBA_char *str_uri_copy;
57
58         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
59         priv = cal->priv;
60
61         str_uri = e_cal_backend_get_uri (priv->backend);
62         str_uri_copy = CORBA_string_dup (str_uri);
63
64         return str_uri_copy;
65 }
66
67 static void
68 impl_Cal_open (PortableServer_Servant servant,
69                CORBA_boolean only_if_exists,
70                const CORBA_char *username,
71                const CORBA_char *password,
72                CORBA_Environment *ev)
73 {
74         EDataCal *cal;
75         EDataCalPrivate *priv;
76
77         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
78         priv = cal->priv;
79
80         e_cal_backend_open (priv->backend, cal, only_if_exists, username, password);
81 }
82
83 static void
84 impl_Cal_remove (PortableServer_Servant servant,
85                  CORBA_Environment *ev)
86 {
87         EDataCal *cal;
88         EDataCalPrivate *priv;
89
90         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
91         priv = cal->priv;
92
93         e_cal_backend_remove (priv->backend, cal);
94 }
95
96 /* Cal::isReadOnly method */
97 static void
98 impl_Cal_isReadOnly (PortableServer_Servant servant,
99                      CORBA_Environment *ev)
100 {
101         EDataCal *cal;
102         EDataCalPrivate *priv;
103
104         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
105         priv = cal->priv;
106
107         e_cal_backend_is_read_only (priv->backend, cal);
108 }
109
110 /* Cal::getEmailAddress method */
111 static void
112 impl_Cal_getCalAddress (PortableServer_Servant servant,
113                         CORBA_Environment *ev)
114 {
115         EDataCal *cal;
116         EDataCalPrivate *priv;
117
118         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
119         priv = cal->priv;
120
121         e_cal_backend_get_cal_address (priv->backend, cal);
122 }
123
124 /* Cal::get_alarm_email_address method */
125 static void
126 impl_Cal_getAlarmEmailAddress (PortableServer_Servant servant,
127                                CORBA_Environment *ev)
128 {
129         EDataCal *cal;
130         EDataCalPrivate *priv;
131
132         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
133         priv = cal->priv;
134
135         e_cal_backend_get_alarm_email_address (priv->backend, cal);
136 }
137
138 /* Cal::get_ldap_attribute method */
139 static void
140 impl_Cal_getLdapAttribute (PortableServer_Servant servant,
141                            CORBA_Environment *ev)
142 {
143         EDataCal *cal;
144         EDataCalPrivate *priv;
145
146         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
147         priv = cal->priv;
148
149         e_cal_backend_get_ldap_attribute (priv->backend, cal);
150 }
151
152 /* Cal::getSchedulingInformation method */
153 static void
154 impl_Cal_getStaticCapabilities (PortableServer_Servant servant,
155                                 CORBA_Environment *ev)
156 {
157         EDataCal *cal;
158         EDataCalPrivate *priv;
159
160         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
161         priv = cal->priv;
162
163         e_cal_backend_get_static_capabilities (priv->backend, cal);
164 }
165
166 /* Cal::setMode method */
167 static void
168 impl_Cal_setMode (PortableServer_Servant servant,
169                   GNOME_Evolution_Calendar_CalMode mode,
170                   CORBA_Environment *ev)
171 {
172         EDataCal *cal;
173         EDataCalPrivate *priv;
174
175         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
176         priv = cal->priv;
177
178         e_cal_backend_set_mode (priv->backend, mode);
179 }
180
181 static void
182 impl_Cal_getDefaultObject (PortableServer_Servant servant,
183                            CORBA_Environment *ev)
184 {
185         EDataCal *cal;
186         EDataCalPrivate *priv;
187
188         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
189         priv = cal->priv;
190
191         e_cal_backend_get_default_object (priv->backend, cal);
192 }
193
194 /* Cal::getObject method */
195 static void
196 impl_Cal_getObject (PortableServer_Servant servant,
197                     const CORBA_char *uid,
198                     const CORBA_char *rid,
199                     CORBA_Environment *ev)
200 {
201         EDataCal *cal;
202         EDataCalPrivate *priv;
203
204         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
205         priv = cal->priv;
206
207         e_cal_backend_get_object (priv->backend, cal, uid, rid);
208 }
209
210 /* Cal::getObjectList method */
211 static void
212 impl_Cal_getObjectList (PortableServer_Servant servant,
213                         const CORBA_char *sexp,
214                         CORBA_Environment *ev)
215 {
216         EDataCal *cal;
217         EDataCalPrivate *priv;
218         EDataCalView *query;
219
220         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
221         priv = cal->priv;
222
223         query = g_hash_table_lookup (priv->live_queries, sexp);
224         if (query) {
225                 GList *matched_objects;
226
227                 matched_objects = e_data_cal_view_get_matched_objects (query);
228                 e_data_cal_notify_object_list (
229                         cal,
230                         e_data_cal_view_is_done (query) ? e_data_cal_view_get_done_status (query) : GNOME_Evolution_Calendar_Success,
231                         matched_objects);
232
233                 g_list_free (matched_objects);
234         } else
235                 e_cal_backend_get_object_list (priv->backend, cal, sexp);
236 }
237
238 /* Cal::getAttachmentList method */
239 static void
240 impl_Cal_getAttachmentList (PortableServer_Servant servant,
241                     const CORBA_char *uid,
242                     const CORBA_char *rid,
243                     CORBA_Environment *ev)
244 {
245         EDataCal *cal;
246         EDataCalPrivate *priv;
247
248         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
249         priv = cal->priv;
250
251         e_cal_backend_get_attachment_list (priv->backend, cal, uid, rid);
252 }
253
254 /* Cal::getChanges method */
255 static void
256 impl_Cal_getChanges (PortableServer_Servant servant,
257                      const CORBA_char *change_id,
258                      CORBA_Environment *ev)
259 {
260        EDataCal *cal;
261        EDataCalPrivate *priv;
262
263        cal = E_DATA_CAL (bonobo_object_from_servant (servant));
264        priv = cal->priv;
265
266        e_cal_backend_get_changes (priv->backend, cal, change_id);
267 }
268
269 /* Cal::getFreeBusy method */
270 static void
271 impl_Cal_getFreeBusy (PortableServer_Servant servant,
272                       const GNOME_Evolution_Calendar_UserList *user_list,
273                       const GNOME_Evolution_Calendar_Time_t start,
274                       const GNOME_Evolution_Calendar_Time_t end,
275                       CORBA_Environment *ev)
276 {
277         EDataCal *cal;
278         EDataCalPrivate *priv;
279         GList *users = NULL;
280
281         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
282         priv = cal->priv;
283
284         /* convert the CORBA user list to a GList */
285         if (user_list) {
286                 int i;
287
288                 for (i = 0; i < user_list->_length; i++)
289                         users = g_list_append (users, user_list->_buffer[i]);
290         }
291
292         /* call the backend's get_free_busy method */
293         e_cal_backend_get_free_busy (priv->backend, cal, users, start, end);
294 }
295
296 /* Cal::discardAlarm method */
297 static void
298 impl_Cal_discardAlarm (PortableServer_Servant servant,
299                        const CORBA_char *uid,
300                        const CORBA_char *auid,
301                        CORBA_Environment *ev)
302 {
303         EDataCal *cal;
304         EDataCalPrivate *priv;
305
306         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
307         priv = cal->priv;
308
309         e_cal_backend_discard_alarm (priv->backend, cal, uid, auid);
310 }
311
312 static void
313 impl_Cal_createObject (PortableServer_Servant servant,
314                        const CORBA_char *calobj,
315                        CORBA_Environment *ev)
316 {
317         EDataCal *cal;
318         EDataCalPrivate *priv;
319
320         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
321         priv = cal->priv;
322
323         e_cal_backend_create_object (priv->backend, cal, calobj);
324 }
325
326 static void
327 impl_Cal_modifyObject (PortableServer_Servant servant,
328                        const CORBA_char *calobj,
329                        const GNOME_Evolution_Calendar_CalObjModType mod,
330                        CORBA_Environment *ev)
331 {
332         EDataCal *cal;
333         EDataCalPrivate *priv;
334
335         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
336         priv = cal->priv;
337
338         e_cal_backend_modify_object (priv->backend, cal, calobj, mod);
339 }
340
341 /* Cal::removeObject method */
342 static void
343 impl_Cal_removeObject (PortableServer_Servant servant,
344                        const CORBA_char *uid,
345                        const CORBA_char *rid,
346                        const GNOME_Evolution_Calendar_CalObjModType mod,
347                        CORBA_Environment *ev)
348 {
349         EDataCal *cal;
350         EDataCalPrivate *priv;
351
352         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
353         priv = cal->priv;
354
355         e_cal_backend_remove_object (priv->backend, cal, uid, rid, mod);
356 }
357
358 static void
359 impl_Cal_receiveObjects (PortableServer_Servant servant,
360                          const CORBA_char *calobj,
361                          CORBA_Environment *ev)
362 {
363         EDataCal *cal;
364         EDataCalPrivate *priv;
365
366         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
367         priv = cal->priv;
368
369         e_cal_backend_receive_objects (priv->backend, cal, calobj);
370 }
371
372 static void
373 impl_Cal_sendObjects (PortableServer_Servant servant,
374                       const CORBA_char *calobj,
375                       CORBA_Environment *ev)
376 {
377         EDataCal *cal;
378         EDataCalPrivate *priv;
379
380         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
381         priv = cal->priv;
382
383         e_cal_backend_send_objects (priv->backend, cal, calobj);
384 }
385
386 static void
387 disconnect_query (gpointer key, EDataCalView *query, EDataCal *cal)
388 {
389         g_signal_handlers_disconnect_matched (query, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, cal);
390         e_cal_backend_remove_query (cal->priv->backend, query);
391 }
392
393 static void
394 query_last_listener_gone_cb (EDataCalView *query, EDataCal *cal)
395 {
396         EDataCalPrivate *priv;
397
398         g_return_if_fail (cal != NULL);
399
400         priv = cal->priv;
401
402         disconnect_query (NULL, query, cal);
403         g_hash_table_remove (priv->live_queries, e_data_cal_view_get_text (query));
404 }
405
406 /* Cal::getQuery implementation */
407 static void
408 impl_Cal_getQuery (PortableServer_Servant servant,
409                    const CORBA_char *sexp,
410                    GNOME_Evolution_Calendar_CalViewListener ql,
411                    CORBA_Environment *ev)
412 {
413
414         EDataCal *cal;
415         EDataCalPrivate *priv;
416         EDataCalView *query;
417         ECalBackendSExp *obj_sexp;
418
419         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
420         priv = cal->priv;
421
422         /* first see if we already have the query in the cache */
423         query = g_hash_table_lookup (priv->live_queries, sexp);
424         if (query) {
425                 e_data_cal_view_add_listener (query, ql);
426                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_Success, query);
427                 return;
428         }
429
430         /* we handle this entirely here, since it doesn't require any
431            backend involvement now that we have e_cal_view_start to
432            actually kick off the search. */
433
434         obj_sexp = e_cal_backend_sexp_new (sexp);
435         if (!obj_sexp) {
436                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_InvalidQuery, NULL);
437
438                 return;
439         }
440
441         query = e_data_cal_view_new (priv->backend, ql, obj_sexp);
442         if (!query) {
443                 g_object_unref (obj_sexp);
444                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_OtherError, NULL);
445
446                 return;
447         }
448
449         g_signal_connect (query, "last_listener_gone", G_CALLBACK (query_last_listener_gone_cb), cal);
450
451         g_hash_table_insert (priv->live_queries, g_strdup (sexp), query);
452         e_cal_backend_add_query (priv->backend, query);
453
454         e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_Success, query);
455 }
456
457
458 /* Cal::getTimezone method */
459 static void
460 impl_Cal_getTimezone (PortableServer_Servant servant,
461                       const CORBA_char *tzid,
462                       CORBA_Environment *ev)
463 {
464         EDataCal *cal;
465         EDataCalPrivate *priv;
466
467         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
468         priv = cal->priv;
469
470         e_cal_backend_get_timezone (priv->backend, cal, tzid);
471 }
472
473 /* Cal::addTimezone method */
474 static void
475 impl_Cal_addTimezone (PortableServer_Servant servant,
476                       const CORBA_char *tz,
477                       CORBA_Environment *ev)
478 {
479         EDataCal *cal;
480         EDataCalPrivate *priv;
481
482         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
483         priv = cal->priv;
484
485         e_cal_backend_add_timezone (priv->backend, cal, tz);
486 }
487
488 /* Cal::setDefaultTimezone method */
489 static void
490 impl_Cal_setDefaultTimezone (PortableServer_Servant servant,
491                              const CORBA_char *tz,
492                              CORBA_Environment *ev)
493 {
494         EDataCal *cal;
495         EDataCalPrivate *priv;
496
497         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
498         priv = cal->priv;
499
500         e_cal_backend_set_default_zone (priv->backend, cal, tz);
501 }
502
503 /**
504  * e_data_cal_construct:
505  * @cal: A calendar client interface.
506  * @backend: Calendar backend that this @cal presents an interface to.
507  * @listener: Calendar listener for notification.
508  *
509  * Constructs a calendar client interface object by binding the corresponding
510  * CORBA object to it.  The calendar interface is bound to the specified
511  * @backend, and will notify the @listener about changes to the calendar.
512  *
513  * Return value: The same object as the @cal argument.
514  **/
515 EDataCal *
516 e_data_cal_construct (EDataCal *cal,
517                       ECalBackend *backend,
518                       GNOME_Evolution_Calendar_CalListener listener)
519 {
520         EDataCalPrivate *priv;
521         CORBA_Environment ev;
522
523         g_return_val_if_fail (cal != NULL, NULL);
524         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
525         g_return_val_if_fail (backend != NULL, NULL);
526         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
527
528         priv = cal->priv;
529
530         CORBA_exception_init (&ev);
531         priv->listener = CORBA_Object_duplicate (listener, &ev);
532         if (BONOBO_EX (&ev)) {
533                 g_message ("cal_construct: could not duplicate the listener");
534                 priv->listener = CORBA_OBJECT_NIL;
535                 CORBA_exception_free (&ev);
536                 return NULL;
537         }
538
539         CORBA_exception_free (&ev);
540
541         priv->backend = backend;
542
543         return cal;
544 }
545
546 /**
547  * e_data_cal_new:
548  * @backend: A calendar backend.
549  * @listener: A calendar listener.
550  *
551  * Creates a new calendar client interface object and binds it to the
552  * specified @backend and @listener objects.
553  *
554  * Return value: A newly-created #EDataCal calendar client interface
555  * object, or %NULL if its corresponding CORBA object could not be
556  * created.
557  **/
558 EDataCal *
559 e_data_cal_new (ECalBackend *backend, GNOME_Evolution_Calendar_CalListener listener)
560 {
561         EDataCal *cal, *retval;
562
563         g_return_val_if_fail (backend != NULL, NULL);
564         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
565
566         cal = E_DATA_CAL (g_object_new (E_TYPE_DATA_CAL,
567                                  "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
568                                  NULL));
569
570         retval = e_data_cal_construct (cal, backend, listener);
571         if (!retval) {
572                 g_message (G_STRLOC ": could not construct the calendar client interface");
573                 bonobo_object_unref (BONOBO_OBJECT (cal));
574                 return NULL;
575         }
576
577         return retval;
578 }
579
580 /**
581  * e_data_cal_get_backend:
582  * @cal: A calendar client interface.
583  *
584  * Gets the associated backend.
585  *
586  * Return value: An #ECalBackend.
587  */
588 ECalBackend *
589 e_data_cal_get_backend (EDataCal *cal)
590 {
591         g_return_val_if_fail (cal != NULL, NULL);
592         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
593
594         return cal->priv->backend;
595 }
596
597 /**
598  * e_data_cal_get_listener:
599  * @cal: A calendar client interface.
600  *
601  * Gets the listener associated with a calendar client interface.
602  *
603  * Return value: The listener.
604  */
605 GNOME_Evolution_Calendar_CalListener
606 e_data_cal_get_listener (EDataCal *cal)
607 {
608         g_return_val_if_fail (cal != NULL, NULL);
609         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
610
611         return cal->priv->listener;
612 }
613
614 /* Destroy handler for the calendar */
615 static void
616 e_data_cal_finalize (GObject *object)
617 {
618         EDataCal *cal;
619         EDataCalPrivate *priv;
620         CORBA_Environment ev;
621
622         g_return_if_fail (object != NULL);
623         g_return_if_fail (E_IS_DATA_CAL (object));
624
625         cal = E_DATA_CAL (object);
626         priv = cal->priv;
627
628         priv->backend = NULL;
629
630         CORBA_exception_init (&ev);
631         bonobo_object_release_unref (priv->listener, &ev);
632         if (BONOBO_EX (&ev))
633                 g_message (G_STRLOC ": could not release the listener");
634
635         priv->listener = NULL;
636         CORBA_exception_free (&ev);
637
638         g_hash_table_foreach (priv->live_queries, (GHFunc) disconnect_query, cal);
639         g_hash_table_destroy (priv->live_queries);
640         priv->live_queries = NULL;
641
642         g_free (priv);
643
644         if (G_OBJECT_CLASS (parent_class)->finalize)
645                 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
646 }
647
648 \f
649
650 /* Class initialization function for the calendar */
651 static void
652 e_data_cal_class_init (EDataCalClass *klass)
653 {
654         GObjectClass *object_class = (GObjectClass *) klass;
655         POA_GNOME_Evolution_Calendar_Cal__epv *epv = &klass->epv;
656
657         parent_class = g_type_class_peek_parent (klass);
658
659         /* Class method overrides */
660         object_class->finalize = e_data_cal_finalize;
661
662         /* Epv methods */
663         epv->_get_uri = impl_Cal_get_uri;
664         epv->open = impl_Cal_open;
665         epv->remove = impl_Cal_remove;
666         epv->isReadOnly = impl_Cal_isReadOnly;
667         epv->getCalAddress = impl_Cal_getCalAddress;
668         epv->getAlarmEmailAddress = impl_Cal_getAlarmEmailAddress;
669         epv->getLdapAttribute = impl_Cal_getLdapAttribute;
670         epv->getStaticCapabilities = impl_Cal_getStaticCapabilities;
671         epv->setMode = impl_Cal_setMode;
672         epv->getDefaultObject = impl_Cal_getDefaultObject;
673         epv->getObject = impl_Cal_getObject;
674         epv->getTimezone = impl_Cal_getTimezone;
675         epv->addTimezone = impl_Cal_addTimezone;
676         epv->setDefaultTimezone = impl_Cal_setDefaultTimezone;
677         epv->getObjectList = impl_Cal_getObjectList;
678         epv->getAttachmentList = impl_Cal_getAttachmentList;
679         epv->getChanges = impl_Cal_getChanges;
680         epv->getFreeBusy = impl_Cal_getFreeBusy;
681         epv->discardAlarm = impl_Cal_discardAlarm;
682         epv->createObject = impl_Cal_createObject;
683         epv->modifyObject = impl_Cal_modifyObject;
684         epv->removeObject = impl_Cal_removeObject;
685         epv->receiveObjects = impl_Cal_receiveObjects;
686         epv->sendObjects = impl_Cal_sendObjects;
687         epv->getQuery = impl_Cal_getQuery;
688 }
689
690 /* Object initialization function for the calendar */
691 static void
692 e_data_cal_init (EDataCal *cal, EDataCalClass *klass)
693 {
694         EDataCalPrivate *priv;
695
696         priv = g_new0 (EDataCalPrivate, 1);
697         cal->priv = priv;
698
699         priv->listener = CORBA_OBJECT_NIL;
700         priv->live_queries = g_hash_table_new_full (g_str_hash, g_str_equal,
701                                                     (GDestroyNotify) g_free,
702                                                     (GDestroyNotify) bonobo_object_unref);
703 }
704
705 BONOBO_TYPE_FUNC_FULL (EDataCal, GNOME_Evolution_Calendar_Cal, PARENT_TYPE, e_data_cal);
706
707 /**
708  * e_data_cal_notify_read_only:
709  * @cal: A calendar client interface.
710  * @status: Status code.
711  * @read_only: Read only value.
712  *
713  * Notifies listeners of the completion of the is_read_only method call.
714  */
715 void
716 e_data_cal_notify_read_only (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, gboolean read_only)
717 {
718         EDataCalPrivate *priv;
719         CORBA_Environment ev;
720
721         g_return_if_fail (cal != NULL);
722         g_return_if_fail (E_IS_DATA_CAL (cal));
723
724         priv = cal->priv;
725         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
726
727         CORBA_exception_init (&ev);
728         GNOME_Evolution_Calendar_CalListener_notifyReadOnly (priv->listener, status, read_only, &ev);
729
730         if (BONOBO_EX (&ev))
731                 g_message (G_STRLOC ": could not notify the listener of read only");
732
733         CORBA_exception_free (&ev);
734 }
735
736 /**
737  * e_data_cal_notify_cal_address:
738  * @cal: A calendar client interface.
739  * @status: Status code.
740  * @address: Calendar address.
741  *
742  * Notifies listeners of the completion of the get_cal_address method call.
743  */
744 void
745 e_data_cal_notify_cal_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
746 {
747         EDataCalPrivate *priv;
748         CORBA_Environment ev;
749
750         g_return_if_fail (cal != NULL);
751         g_return_if_fail (E_IS_DATA_CAL (cal));
752
753         priv = cal->priv;
754         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
755
756         CORBA_exception_init (&ev);
757         GNOME_Evolution_Calendar_CalListener_notifyCalAddress (priv->listener, status, address ? address : "", &ev);
758
759         if (BONOBO_EX (&ev))
760                 g_message (G_STRLOC ": could not notify the listener of cal address");
761
762         CORBA_exception_free (&ev);
763 }
764
765 /**
766  * e_data_cal_notify_alarm_email_address:
767  * @cal: A calendar client interface.
768  * @status: Status code.
769  * @address: Alarm email address.
770  *
771  * Notifies listeners of the completion of the get_alarm_email_address method call.
772  */
773 void
774 e_data_cal_notify_alarm_email_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
775 {
776         EDataCalPrivate *priv;
777         CORBA_Environment ev;
778
779         g_return_if_fail (cal != NULL);
780         g_return_if_fail (E_IS_DATA_CAL (cal));
781
782         priv = cal->priv;
783         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
784
785         CORBA_exception_init (&ev);
786         GNOME_Evolution_Calendar_CalListener_notifyAlarmEmailAddress (priv->listener, status, address ? address : "", &ev);
787
788         if (BONOBO_EX (&ev))
789                 g_message (G_STRLOC ": could not notify the listener of alarm address");
790
791         CORBA_exception_free (&ev);
792 }
793
794 /**
795  * e_data_cal_notify_ldap_attribute:
796  * @cal: A calendar client interface.
797  * @status: Status code.
798  * @attibute: LDAP attribute.
799  *
800  * Notifies listeners of the completion of the get_ldap_attribute method call.
801  */
802 void
803 e_data_cal_notify_ldap_attribute (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *attribute)
804 {
805         EDataCalPrivate *priv;
806         CORBA_Environment ev;
807
808         g_return_if_fail (cal != NULL);
809         g_return_if_fail (E_IS_DATA_CAL (cal));
810
811         priv = cal->priv;
812         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
813
814         CORBA_exception_init (&ev);
815         GNOME_Evolution_Calendar_CalListener_notifyLDAPAttribute (priv->listener, status, attribute ? attribute : "", &ev);
816
817         if (BONOBO_EX (&ev))
818                 g_message (G_STRLOC ": could not notify the listener of ldap attribute");
819
820         CORBA_exception_free (&ev);
821 }
822
823 /**
824  * e_data_cal_notify_static_capabilities:
825  * @cal: A calendar client interface.
826  * @status: Status code.
827  * @capabilities: Static capabilities from the backend.
828  *
829  * Notifies listeners of the completion of the get_static_capabilities method call.
830  */
831 void
832 e_data_cal_notify_static_capabilities (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *capabilities)
833 {
834         EDataCalPrivate *priv;
835         CORBA_Environment ev;
836
837         g_return_if_fail (cal != NULL);
838         g_return_if_fail (E_IS_DATA_CAL (cal));
839
840         priv = cal->priv;
841         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
842
843         CORBA_exception_init (&ev);
844         GNOME_Evolution_Calendar_CalListener_notifyStaticCapabilities (priv->listener, status,
845                                                                     capabilities ? capabilities : "", &ev);
846
847         if (BONOBO_EX (&ev))
848                 g_message (G_STRLOC ": could not notify the listener of static capabilities");
849
850         CORBA_exception_free (&ev);
851 }
852
853 /**
854  * e_data_cal_notify_open:
855  * @cal: A calendar client interface.
856  * @status: Status code.
857  *
858  * Notifies listeners of the completion of the open method call.
859  */
860 void
861 e_data_cal_notify_open (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
862 {
863         EDataCalPrivate *priv;
864         CORBA_Environment ev;
865
866         g_return_if_fail (cal != NULL);
867         g_return_if_fail (E_IS_DATA_CAL (cal));
868
869         priv = cal->priv;
870         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
871
872         CORBA_exception_init (&ev);
873         GNOME_Evolution_Calendar_CalListener_notifyCalOpened (priv->listener, status, &ev);
874
875         if (BONOBO_EX (&ev))
876                 g_message (G_STRLOC ": could not notify the listener of open");
877
878         CORBA_exception_free (&ev);
879 }
880
881 /**
882  * e_data_cal_notify_remove:
883  * @cal: A calendar client interface.
884  * @status: Status code.
885  *
886  * Notifies listeners of the completion of the remove method call.
887  */
888 void
889 e_data_cal_notify_remove (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
890 {
891         EDataCalPrivate *priv;
892         CORBA_Environment ev;
893
894         g_return_if_fail (cal != NULL);
895         g_return_if_fail (E_IS_DATA_CAL (cal));
896
897         priv = cal->priv;
898         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
899
900         CORBA_exception_init (&ev);
901         GNOME_Evolution_Calendar_CalListener_notifyCalRemoved (priv->listener, status, &ev);
902
903         if (BONOBO_EX (&ev))
904                 g_message (G_STRLOC ": could not notify the listener of remove");
905
906         CORBA_exception_free (&ev);
907 }
908
909 /**
910  * e_data_cal_notify_object_created:
911  * @cal: A calendar client interface.
912  * @status: Status code.
913  * @uid: UID of the object created.
914  * @object: The object created as an iCalendar string.
915  *
916  * Notifies listeners of the completion of the create_object method call.
917  */
918 void
919 e_data_cal_notify_object_created (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
920                                   const char *uid, const char *object)
921 {
922         EDataCalPrivate *priv;
923         CORBA_Environment ev;
924
925         g_return_if_fail (cal != NULL);
926         g_return_if_fail (E_IS_DATA_CAL (cal));
927
928         priv = cal->priv;
929         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
930
931         /* If the object is NULL, it means the object has been created on the server sucessfully,
932            but it is not shown in the UI if delay delivery is set */
933         if (status == GNOME_Evolution_Calendar_Success && object)
934                 e_cal_backend_notify_object_created (priv->backend, object);
935
936         CORBA_exception_init (&ev);
937         GNOME_Evolution_Calendar_CalListener_notifyObjectCreated (priv->listener, status, uid ? uid : "", &ev);
938
939         if (BONOBO_EX (&ev))
940                 g_message (G_STRLOC ": could not notify the listener of object creation");
941
942         CORBA_exception_free (&ev);
943 }
944
945 /**
946  * e_data_cal_notify_object_modified:
947  * @cal: A calendar client interface.
948  * @status: Status code.
949  * @old_object: The old object as an iCalendar string.
950  * @object: The modified object as an iCalendar string.
951  *
952  * Notifies listeners of the completion of the modify_object method call.
953  */
954 void
955 e_data_cal_notify_object_modified (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
956                                    const char *old_object, const char *object)
957 {
958         EDataCalPrivate *priv;
959         CORBA_Environment ev;
960
961         g_return_if_fail (cal != NULL);
962         g_return_if_fail (E_IS_DATA_CAL (cal));
963
964         priv = cal->priv;
965         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
966
967         if (status == GNOME_Evolution_Calendar_Success)
968                 e_cal_backend_notify_object_modified (priv->backend, old_object, object);
969
970         CORBA_exception_init (&ev);
971         GNOME_Evolution_Calendar_CalListener_notifyObjectModified (priv->listener, status, &ev);
972
973         if (BONOBO_EX (&ev))
974                 g_message (G_STRLOC ": could not notify the listener of object creation");
975
976         CORBA_exception_free (&ev);
977 }
978
979 /**
980  * e_data_cal_notify_object_removed:
981  * @cal: A calendar client interface.
982  * @status: Status code.
983  * @uid: UID of the removed object.
984  * @old_object: The old object as an iCalendar string.
985  * @object: The new object as an iCalendar string. This will not be NULL only
986  * when removing instances of a recurring appointment.
987  *
988  * Notifies listeners of the completion of the remove_object method call.
989  */
990 void
991 e_data_cal_notify_object_removed (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
992                                   const ECalComponentId *id, const char *old_object, const char *object)
993 {
994         EDataCalPrivate *priv;
995         CORBA_Environment ev;
996
997         g_return_if_fail (cal != NULL);
998         g_return_if_fail (E_IS_DATA_CAL (cal));
999
1000         priv = cal->priv;
1001         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1002
1003         if (status == GNOME_Evolution_Calendar_Success)
1004                 e_cal_backend_notify_object_removed (priv->backend, id, old_object, object);
1005
1006         CORBA_exception_init (&ev);
1007         GNOME_Evolution_Calendar_CalListener_notifyObjectRemoved (priv->listener, status, &ev);
1008
1009         if (BONOBO_EX (&ev))
1010                 g_message (G_STRLOC ": could not notify the listener of object removal");
1011
1012         CORBA_exception_free (&ev);
1013 }
1014
1015 /**
1016  * e_data_cal_notify_objects_received:
1017  * @cal: A calendar client interface.
1018  * @status: Status code.
1019  *
1020  * Notifies listeners of the completion of the receive_objects method call.
1021  */
1022 void
1023 e_data_cal_notify_objects_received (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
1024 {
1025         EDataCalPrivate *priv;
1026         CORBA_Environment ev;
1027
1028         g_return_if_fail (cal != NULL);
1029         g_return_if_fail (E_IS_DATA_CAL (cal));
1030
1031         priv = cal->priv;
1032         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1033
1034         CORBA_exception_init (&ev);
1035         GNOME_Evolution_Calendar_CalListener_notifyObjectsReceived (priv->listener, status, &ev);
1036
1037         if (BONOBO_EX (&ev))
1038                 g_message (G_STRLOC ": could not notify the listener of objects received");
1039
1040         CORBA_exception_free (&ev);
1041 }
1042
1043 /**
1044  * e_data_cal_notify_alarm_discarded:
1045  * @cal: A calendar client interface.
1046  * @status: Status code.
1047  *
1048  * Notifies listeners of the completion of the discard_alarm method call.
1049  */
1050 void
1051 e_data_cal_notify_alarm_discarded (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
1052 {
1053         EDataCalPrivate *priv;
1054         CORBA_Environment ev;
1055
1056         g_return_if_fail (cal != NULL);
1057         g_return_if_fail (E_IS_DATA_CAL (cal));
1058
1059         priv = cal->priv;
1060         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1061
1062         CORBA_exception_init (&ev);
1063         GNOME_Evolution_Calendar_CalListener_notifyAlarmDiscarded (priv->listener, status, &ev);
1064
1065         if (BONOBO_EX (&ev))
1066                 g_message (G_STRLOC ": could not notify the listener of alarm discarded");
1067
1068         CORBA_exception_free (&ev);
1069 }
1070
1071 /**
1072  * e_data_cal_notify_objects_sent:
1073  * @cal: A calendar client interface.
1074  * @status: Status code.
1075  * @users: List of users.
1076  * @calobj: An iCalendar string representing the object sent.
1077  *
1078  * Notifies listeners of the completion of the send_objects method call.
1079  */
1080 void
1081 e_data_cal_notify_objects_sent (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *users, const char *calobj)
1082 {
1083         EDataCalPrivate *priv;
1084         CORBA_Environment ev;
1085         GNOME_Evolution_Calendar_UserList *corba_users;
1086
1087         g_return_if_fail (cal != NULL);
1088         g_return_if_fail (E_IS_DATA_CAL (cal));
1089
1090         priv = cal->priv;
1091         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1092
1093         corba_users = GNOME_Evolution_Calendar_UserList__alloc ();
1094         corba_users->_length = g_list_length (users);
1095         if (users) {
1096                 GList *l;
1097                 int n;
1098
1099                 corba_users->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_User_allocbuf (corba_users->_length);
1100                 for (l = users, n = 0; l != NULL; l = l->next, n++)
1101                         corba_users->_buffer[n] = CORBA_string_dup (l->data);
1102         }
1103
1104         CORBA_exception_init (&ev);
1105         GNOME_Evolution_Calendar_CalListener_notifyObjectsSent (priv->listener, status, corba_users,
1106                                                                 calobj ? calobj : "", &ev);
1107
1108         if (BONOBO_EX (&ev))
1109                 g_message (G_STRLOC ": could not notify the listener of objects sent");
1110
1111         CORBA_exception_free (&ev);
1112         CORBA_free (corba_users);
1113 }
1114
1115 /**
1116  * e_data_cal_notify_default_object:
1117  * @cal: A calendar client interface.
1118  * @status: Status code.
1119  * @object: The default object as an iCalendar string.
1120  *
1121  * Notifies listeners of the completion of the get_default_object method call.
1122  */
1123 void
1124 e_data_cal_notify_default_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
1125 {
1126         EDataCalPrivate *priv;
1127         CORBA_Environment ev;
1128
1129         g_return_if_fail (cal != NULL);
1130         g_return_if_fail (E_IS_DATA_CAL (cal));
1131
1132         priv = cal->priv;
1133         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1134
1135         CORBA_exception_init (&ev);
1136
1137         GNOME_Evolution_Calendar_CalListener_notifyDefaultObjectRequested (priv->listener, status,
1138                                                                            object ? object : "", &ev);
1139
1140         if (BONOBO_EX (&ev))
1141                 g_message (G_STRLOC ": could not notify the listener of default object");
1142
1143         CORBA_exception_free (&ev);
1144 }
1145
1146 /**
1147  * e_data_cal_notify_object:
1148  * @cal: A calendar client interface.
1149  * @status: Status code.
1150  * @object: The object retrieved as an iCalendar string.
1151  *
1152  * Notifies listeners of the completion of the get_object method call.
1153  */
1154 void
1155 e_data_cal_notify_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
1156 {
1157         EDataCalPrivate *priv;
1158         CORBA_Environment ev;
1159
1160         g_return_if_fail (cal != NULL);
1161         g_return_if_fail (E_IS_DATA_CAL (cal));
1162
1163         priv = cal->priv;
1164         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1165
1166         CORBA_exception_init (&ev);
1167
1168         GNOME_Evolution_Calendar_CalListener_notifyObjectRequested (priv->listener, status,
1169                                                                     object ? object : "", &ev);
1170
1171         if (BONOBO_EX (&ev))
1172                 g_message (G_STRLOC ": could not notify the listener of object");
1173
1174         CORBA_exception_free (&ev);
1175 }
1176
1177 /**
1178  * e_data_cal_notify_object_list:
1179  * @cal: A calendar client interface.
1180  * @status: Status code.
1181  * @objects: List of retrieved objects.
1182  *
1183  * Notifies listeners of the completion of the get_object_list method call.
1184  */
1185 void
1186 e_data_cal_notify_object_list (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *objects)
1187 {
1188         EDataCalPrivate *priv;
1189         CORBA_Environment ev;
1190         GNOME_Evolution_Calendar_stringlist seq;
1191         GList *l;
1192         int i;
1193
1194         g_return_if_fail (cal != NULL);
1195         g_return_if_fail (E_IS_DATA_CAL (cal));
1196
1197         priv = cal->priv;
1198         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1199
1200         CORBA_exception_init (&ev);
1201
1202         seq._maximum = g_list_length (objects);
1203         seq._length = 0;
1204         seq._buffer = GNOME_Evolution_Calendar_stringlist_allocbuf (seq._maximum);
1205
1206         for (l = objects, i = 0; l; l = l->next, i++) {
1207                 seq._buffer[i] = CORBA_string_dup (l->data);
1208                 seq._length++;
1209         }
1210
1211         GNOME_Evolution_Calendar_CalListener_notifyObjectListRequested (priv->listener, status, &seq, &ev);
1212
1213         if (BONOBO_EX (&ev))
1214                 g_message (G_STRLOC ": could not notify the listener of object list");
1215
1216         CORBA_exception_free (&ev);
1217
1218         CORBA_free(seq._buffer);
1219 }
1220
1221 /**
1222  * e_data_cal_notify_attachment_list:
1223  * @cal: A calendar client interface.
1224  * @status: Status code.
1225  * @attachments: List of retrieved attachment uri's.
1226  *
1227  * Notifies listeners of the completion of the get_attachment_list method call.
1228  */
1229 void
1230 e_data_cal_notify_attachment_list (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GSList *attachments)
1231 {
1232         EDataCalPrivate *priv;
1233         CORBA_Environment ev;
1234         GNOME_Evolution_Calendar_stringlist seq;
1235         GSList *l;
1236         int i;
1237
1238         g_return_if_fail (cal != NULL);
1239         g_return_if_fail (E_IS_DATA_CAL (cal));
1240
1241         priv = cal->priv;
1242         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1243
1244         CORBA_exception_init (&ev);
1245
1246         seq._maximum = g_slist_length (attachments);
1247         seq._length = 0;
1248         seq._buffer = GNOME_Evolution_Calendar_stringlist_allocbuf (seq._maximum);
1249
1250         for (l = attachments, i = 0; l; l = l->next, i++) {
1251                 seq._buffer[i] = CORBA_string_dup (l->data);
1252                 seq._length++;
1253         }
1254
1255         GNOME_Evolution_Calendar_CalListener_notifyAttachmentListRequested (priv->listener, status, &seq, &ev);
1256
1257         if (BONOBO_EX (&ev))
1258                 g_message (G_STRLOC ": could not notify the listener of object list");
1259
1260         CORBA_exception_free (&ev);
1261
1262         CORBA_free(seq._buffer);
1263 }
1264
1265 /**
1266  * e_data_cal_notify_query:
1267  * @cal: A calendar client interface.
1268  * @status: Status code.
1269  * @query: The new live query.
1270  *
1271  * Notifies listeners of the completion of the get_query method call.
1272  */
1273 void
1274 e_data_cal_notify_query (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, EDataCalView *query)
1275 {
1276         EDataCalPrivate *priv;
1277         CORBA_Environment ev;
1278
1279         g_return_if_fail (cal != NULL);
1280         g_return_if_fail (E_IS_DATA_CAL (cal));
1281
1282         priv = cal->priv;
1283         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1284
1285         CORBA_exception_init (&ev);
1286         GNOME_Evolution_Calendar_CalListener_notifyQuery (priv->listener, status, BONOBO_OBJREF (query), &ev);
1287
1288         if (BONOBO_EX (&ev))
1289                 g_message (G_STRLOC ": could not notify the listener of query");
1290
1291         CORBA_exception_free (&ev);
1292 }
1293
1294 /**
1295  * e_data_cal_notify_timezone_requested:
1296  * @cal: A calendar client interface.
1297  * @status: Status code.
1298  * @object: The requested timezone as an iCalendar string.
1299  *
1300  * Notifies listeners of the completion of the get_timezone method call.
1301  */
1302 void
1303 e_data_cal_notify_timezone_requested (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
1304 {
1305         EDataCalPrivate *priv;
1306         CORBA_Environment ev;
1307
1308         g_return_if_fail (E_IS_DATA_CAL (cal));
1309
1310         priv = cal->priv;
1311         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1312
1313         CORBA_exception_init (&ev);
1314         GNOME_Evolution_Calendar_CalListener_notifyTimezoneRequested (priv->listener, status, object ? object : "", &ev);
1315
1316         if (BONOBO_EX (&ev))
1317                 g_warning (G_STRLOC ": could not notify the listener of timezone requested");
1318
1319         CORBA_exception_free (&ev);
1320 }
1321
1322 /**
1323  * e_data_cal_notify_timezone_added:
1324  * @cal: A calendar client interface.
1325  * @status: Status code.
1326  * @tzid: ID of the added timezone.
1327  *
1328  * Notifies listeners of the completion of the add_timezone method call.
1329  */
1330 void
1331 e_data_cal_notify_timezone_added (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *tzid)
1332 {
1333         EDataCalPrivate *priv;
1334         CORBA_Environment ev;
1335
1336         g_return_if_fail (E_IS_DATA_CAL (cal));
1337
1338         priv = cal->priv;
1339         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1340
1341         CORBA_exception_init (&ev);
1342         GNOME_Evolution_Calendar_CalListener_notifyTimezoneAdded (priv->listener, status, tzid ? tzid : "", &ev);
1343
1344         if (BONOBO_EX (&ev))
1345                 g_warning (G_STRLOC ": could not notify the listener of timezone added");
1346
1347         CORBA_exception_free (&ev);
1348 }
1349
1350 /**
1351  * e_data_cal_notify_default_timezone_set:
1352  * @cal: A calendar client interface.
1353  * @status: Status code.
1354  *
1355  * Notifies listeners of the completion of the set_default_timezone method call.
1356  */
1357 void
1358 e_data_cal_notify_default_timezone_set (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
1359 {
1360         EDataCalPrivate *priv;
1361         CORBA_Environment ev;
1362
1363         g_return_if_fail (E_IS_DATA_CAL (cal));
1364
1365         priv = cal->priv;
1366         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1367
1368         CORBA_exception_init (&ev);
1369         GNOME_Evolution_Calendar_CalListener_notifyDefaultTimezoneSet (priv->listener, status, &ev);
1370
1371         if (BONOBO_EX (&ev))
1372                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1373
1374         CORBA_exception_free (&ev);
1375 }
1376
1377 /**
1378  * e_data_cal_notify_changes:
1379  * @cal: A calendar client interface.
1380  * @status: Status code.
1381  * @adds: List of additions.
1382  * @modifies: List of modifications.
1383  * @deletes: List of removals.
1384  *
1385  * Notifies listeners of the completion of the get_changes method call.
1386  */
1387 void
1388 e_data_cal_notify_changes (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
1389                            GList *adds, GList *modifies, GList *deletes)
1390 {
1391         EDataCalPrivate *priv;
1392         CORBA_Environment ev;
1393         GNOME_Evolution_Calendar_CalObjChangeSeq seq;
1394         GList *l;
1395         int n, i;
1396
1397         g_return_if_fail (E_IS_DATA_CAL (cal));
1398
1399         priv = cal->priv;
1400         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1401
1402         n = g_list_length (adds) + g_list_length (modifies) + g_list_length (deletes);
1403         seq._maximum = n;
1404         seq._length = n;
1405         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n);
1406
1407         i = 0;
1408         for (l = adds; l; i++, l = l->next) {
1409                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1410
1411                 change->calobj = CORBA_string_dup (l->data);
1412                 change->type = GNOME_Evolution_Calendar_ADDED;
1413         }
1414
1415         for (l = modifies; l; i++, l = l->next) {
1416                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1417
1418                 change->calobj = CORBA_string_dup (l->data);
1419                 change->type = GNOME_Evolution_Calendar_MODIFIED;
1420         }
1421
1422         for (l = deletes; l; i++, l = l->next) {
1423                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1424
1425                 change->calobj = CORBA_string_dup (l->data);
1426                 change->type = GNOME_Evolution_Calendar_DELETED;
1427         }
1428
1429         CORBA_exception_init (&ev);
1430         GNOME_Evolution_Calendar_CalListener_notifyChanges (priv->listener, status, &seq, &ev);
1431
1432         CORBA_free (seq._buffer);
1433
1434         if (BONOBO_EX (&ev))
1435                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1436
1437         CORBA_exception_free (&ev);
1438 }
1439
1440 /**
1441  * e_data_cal_notify_free_busy:
1442  * @cal: A calendar client interface.
1443  * @status: Status code.
1444  * @freebusy: List of free/busy objects.
1445  *
1446  * Notifies listeners of the completion of the get_free_busy method call.
1447  */
1448 void
1449 e_data_cal_notify_free_busy (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *freebusy)
1450 {
1451         EDataCalPrivate *priv;
1452         CORBA_Environment ev;
1453         GNOME_Evolution_Calendar_CalObjSeq seq;
1454         GList *l;
1455         int n, i;
1456
1457         g_return_if_fail (E_IS_DATA_CAL (cal));
1458
1459         priv = cal->priv;
1460         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1461
1462         n = g_list_length (freebusy);
1463         seq._maximum = n;
1464         seq._length = n;
1465         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObj_allocbuf (n);
1466
1467         for (i = 0, l = freebusy; l; i++, l = l->next)
1468                 seq._buffer[i] = CORBA_string_dup (l->data);
1469
1470         CORBA_exception_init (&ev);
1471         GNOME_Evolution_Calendar_CalListener_notifyFreeBusy (priv->listener, status, &seq, &ev);
1472
1473         CORBA_free (seq._buffer);
1474
1475         if (BONOBO_EX (&ev))
1476                 g_warning (G_STRLOC ": could not notify the listener of freebusy");
1477
1478         CORBA_exception_free (&ev);
1479 }
1480
1481 /**
1482  * e_data_cal_notify_mode:
1483  * @cal: A calendar client interface.
1484  * @status: Status of the mode set.
1485  * @mode: The current mode.
1486  *
1487  * Notifies the listener of the results of a set_mode call.
1488  **/
1489 void
1490 e_data_cal_notify_mode (EDataCal *cal,
1491                         GNOME_Evolution_Calendar_CalListener_SetModeStatus status,
1492                         GNOME_Evolution_Calendar_CalMode mode)
1493 {
1494         EDataCalPrivate *priv;
1495         CORBA_Environment ev;
1496
1497         g_return_if_fail (cal != NULL);
1498         g_return_if_fail (E_IS_DATA_CAL (cal));
1499
1500         priv = cal->priv;
1501         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1502
1503         CORBA_exception_init (&ev);
1504         GNOME_Evolution_Calendar_CalListener_notifyCalSetMode (priv->listener, status, mode, &ev);
1505
1506         if (BONOBO_EX (&ev))
1507                 g_message ("e_data_cal_notify_mode(): could not notify the listener "
1508                            "about a mode change");
1509
1510         CORBA_exception_free (&ev);
1511 }
1512
1513 /**
1514  * e_data_cal_notify_auth_required:
1515  * @cal: A calendar client interface.
1516  *
1517  * Notifies listeners that authorization is required to open the calendar.
1518  */
1519 void
1520 e_data_cal_notify_auth_required (EDataCal *cal)
1521 {
1522        EDataCalPrivate *priv;
1523        CORBA_Environment ev;
1524
1525        g_return_if_fail (cal != NULL);
1526        g_return_if_fail (E_IS_DATA_CAL (cal));
1527
1528        priv = cal->priv;
1529        g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1530
1531        CORBA_exception_init (&ev);
1532        GNOME_Evolution_Calendar_CalListener_notifyAuthRequired (priv->listener,  &ev);
1533        if (BONOBO_EX (&ev))
1534                 g_message ("e_data_cal_notify_auth_required: could not notify the listener "
1535                            "about auth required");
1536
1537         CORBA_exception_free (&ev);
1538 }
1539
1540 /**
1541  * e_data_cal_notify_error
1542  * @cal: A calendar client interface.
1543  * @message: Error message.
1544  *
1545  * Notify a calendar client of an error occurred in the backend.
1546  */
1547 void
1548 e_data_cal_notify_error (EDataCal *cal, const char *message)
1549 {
1550         EDataCalPrivate *priv;
1551         CORBA_Environment ev;
1552
1553         g_return_if_fail (cal != NULL);
1554         g_return_if_fail (E_IS_DATA_CAL (cal));
1555         g_return_if_fail (message != NULL);
1556
1557         priv = cal->priv;
1558         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1559
1560         CORBA_exception_init (&ev);
1561         GNOME_Evolution_Calendar_CalListener_notifyErrorOccurred (priv->listener, (char *) message, &ev);
1562
1563         if (BONOBO_EX (&ev))
1564                 g_message ("e_data_cal_notify_remove(): could not notify the listener "
1565                            "about a removed object");
1566
1567         CORBA_exception_free (&ev);
1568 }