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