merging eds-offline-branch with HEAD
[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 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 General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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::getChanges method */
240 static void
241 impl_Cal_getChanges (PortableServer_Servant servant,
242                      const CORBA_char *change_id,
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_changes (priv->backend, cal, change_id);
252 }
253
254 /* Cal::getFreeBusy method */
255 static void
256 impl_Cal_getFreeBusy (PortableServer_Servant servant,
257                       const GNOME_Evolution_Calendar_UserList *user_list,
258                       const GNOME_Evolution_Calendar_Time_t start,
259                       const GNOME_Evolution_Calendar_Time_t end,
260                       CORBA_Environment *ev)
261 {
262         EDataCal *cal;
263         EDataCalPrivate *priv;
264         GList *users = NULL;
265
266         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
267         priv = cal->priv;
268
269         /* convert the CORBA user list to a GList */
270         if (user_list) {
271                 int i;
272
273                 for (i = 0; i < user_list->_length; i++)
274                         users = g_list_append (users, user_list->_buffer[i]);
275         }
276
277         /* call the backend's get_free_busy method */
278         e_cal_backend_get_free_busy (priv->backend, cal, users, start, end);
279 }
280
281 /* Cal::discardAlarm method */
282 static void
283 impl_Cal_discardAlarm (PortableServer_Servant servant,
284                        const CORBA_char *uid,
285                        const CORBA_char *auid,
286                        CORBA_Environment *ev)
287 {
288         EDataCal *cal;
289         EDataCalPrivate *priv;
290
291         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
292         priv = cal->priv;
293
294         e_cal_backend_discard_alarm (priv->backend, cal, uid, auid);
295 }
296
297 static void
298 impl_Cal_createObject (PortableServer_Servant servant,
299                        const CORBA_char *calobj,
300                        CORBA_Environment *ev)
301 {
302         EDataCal *cal;
303         EDataCalPrivate *priv;
304
305         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
306         priv = cal->priv;
307
308         e_cal_backend_create_object (priv->backend, cal, calobj);
309 }
310
311 static void
312 impl_Cal_modifyObject (PortableServer_Servant servant,
313                        const CORBA_char *calobj,
314                        const GNOME_Evolution_Calendar_CalObjModType mod,
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_modify_object (priv->backend, cal, calobj, mod);
324 }
325
326 /* Cal::removeObject method */
327 static void
328 impl_Cal_removeObject (PortableServer_Servant servant,
329                        const CORBA_char *uid,
330                        const CORBA_char *rid,
331                        const GNOME_Evolution_Calendar_CalObjModType mod,
332                        CORBA_Environment *ev)
333 {
334         EDataCal *cal;
335         EDataCalPrivate *priv;
336
337         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
338         priv = cal->priv;
339
340         e_cal_backend_remove_object (priv->backend, cal, uid, rid, mod);
341 }
342
343 static void
344 impl_Cal_receiveObjects (PortableServer_Servant servant,
345                          const CORBA_char *calobj,
346                          CORBA_Environment *ev)
347 {
348         EDataCal *cal;
349         EDataCalPrivate *priv;
350
351         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
352         priv = cal->priv;
353
354         e_cal_backend_receive_objects (priv->backend, cal, calobj);
355 }
356
357 static void
358 impl_Cal_sendObjects (PortableServer_Servant servant,
359                       const CORBA_char *calobj,
360                       CORBA_Environment *ev)
361 {
362         EDataCal *cal;
363         EDataCalPrivate *priv;
364
365         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
366         priv = cal->priv;
367
368         e_cal_backend_send_objects (priv->backend, cal, calobj);
369 }
370
371 /* Cal::getQuery implementation */
372 static void
373 impl_Cal_getQuery (PortableServer_Servant servant,
374                    const CORBA_char *sexp,
375                    GNOME_Evolution_Calendar_CalViewListener ql,
376                    CORBA_Environment *ev)
377 {
378
379         EDataCal *cal;
380         EDataCalPrivate *priv;
381         EDataCalView *query;
382         ECalBackendSExp *obj_sexp;
383         
384         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
385         priv = cal->priv;
386
387         /* first see if we already have the query in the cache */
388         query = g_hash_table_lookup (priv->live_queries, sexp);
389         if (query) {
390                 e_data_cal_view_add_listener (query, ql);
391                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_Success, query);
392                 return;
393         }
394
395         /* we handle this entirely here, since it doesn't require any
396            backend involvement now that we have e_cal_view_start to
397            actually kick off the search. */
398
399         obj_sexp = e_cal_backend_sexp_new (sexp);
400         if (!obj_sexp) {
401                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_InvalidQuery, NULL);
402
403                 return;
404         }
405
406         query = e_data_cal_view_new (priv->backend, ql, obj_sexp);
407         if (!query) {
408                 g_object_unref (obj_sexp);
409                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_OtherError, NULL);
410
411                 return;
412         }
413
414         g_hash_table_insert (priv->live_queries, g_strdup (sexp), query);
415         e_cal_backend_add_query (priv->backend, query);
416
417         e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_Success, query);
418 }
419
420
421 /* Cal::getTimezone method */
422 static void
423 impl_Cal_getTimezone (PortableServer_Servant servant,
424                       const CORBA_char *tzid,
425                       CORBA_Environment *ev)
426 {
427         EDataCal *cal;
428         EDataCalPrivate *priv;
429
430         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
431         priv = cal->priv;
432
433         e_cal_backend_get_timezone (priv->backend, cal, tzid);
434 }
435
436 /* Cal::addTimezone method */
437 static void
438 impl_Cal_addTimezone (PortableServer_Servant servant,
439                       const CORBA_char *tz,
440                       CORBA_Environment *ev)
441 {
442         EDataCal *cal;
443         EDataCalPrivate *priv;
444
445         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
446         priv = cal->priv;
447
448         e_cal_backend_add_timezone (priv->backend, cal, tz);
449 }
450
451 /* Cal::setDefaultTimezone method */
452 static void
453 impl_Cal_setDefaultTimezone (PortableServer_Servant servant,
454                              const CORBA_char *tzid,
455                              CORBA_Environment *ev)
456 {
457         EDataCal *cal;
458         EDataCalPrivate *priv;
459
460         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
461         priv = cal->priv;
462
463         e_cal_backend_set_default_timezone (priv->backend, cal, tzid);
464 }
465
466 /**
467  * cal_construct:
468  * @cal: A calendar client interface.
469  * @corba_cal: CORBA object for the calendar.
470  * @backend: Calendar backend that this @cal presents an interface to.
471  * @listener: Calendar listener for notification.
472  *
473  * Constructs a calendar client interface object by binding the corresponding
474  * CORBA object to it.  The calendar interface is bound to the specified
475  * @backend, and will notify the @listener about changes to the calendar.
476  *
477  * Return value: The same object as the @cal argument.
478  **/
479 EDataCal *
480 e_data_cal_construct (EDataCal *cal,
481                       ECalBackend *backend,
482                       GNOME_Evolution_Calendar_CalListener listener)
483 {
484         EDataCalPrivate *priv;
485         CORBA_Environment ev;
486
487         g_return_val_if_fail (cal != NULL, NULL);
488         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
489         g_return_val_if_fail (backend != NULL, NULL);
490         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
491
492         priv = cal->priv;
493
494         CORBA_exception_init (&ev);
495         priv->listener = CORBA_Object_duplicate (listener, &ev);
496         if (BONOBO_EX (&ev)) {
497                 g_message ("cal_construct: could not duplicate the listener");
498                 priv->listener = CORBA_OBJECT_NIL;
499                 CORBA_exception_free (&ev);
500                 return NULL;
501         }
502
503         CORBA_exception_free (&ev);
504
505         priv->backend = backend;
506         
507         return cal;
508 }
509
510 /**
511  * cal_new:
512  * @backend: A calendar backend.
513  * @listener: A calendar listener.
514  *
515  * Creates a new calendar client interface object and binds it to the
516  * specified @backend and @listener objects.
517  *
518  * Return value: A newly-created #EDataCal calendar client interface
519  * object, or %NULL if its corresponding CORBA object could not be
520  * created.
521  **/
522 EDataCal *
523 e_data_cal_new (ECalBackend *backend, GNOME_Evolution_Calendar_CalListener listener)
524 {
525         EDataCal *cal, *retval;
526
527         g_return_val_if_fail (backend != NULL, NULL);
528         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
529
530         cal = E_DATA_CAL (g_object_new (E_TYPE_DATA_CAL, 
531                                  "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
532                                  NULL));
533
534         retval = e_data_cal_construct (cal, backend, listener);
535         if (!retval) {
536                 g_message (G_STRLOC ": could not construct the calendar client interface");
537                 bonobo_object_unref (BONOBO_OBJECT (cal));
538                 return NULL;
539         }
540
541         return retval;
542 }
543
544 ECalBackend *
545 e_data_cal_get_backend (EDataCal *cal)
546 {
547         g_return_val_if_fail (cal != NULL, NULL);
548         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
549
550         return cal->priv->backend;
551 }
552
553 GNOME_Evolution_Calendar_CalListener
554 e_data_cal_get_listener (EDataCal *cal)
555 {
556         g_return_val_if_fail (cal != NULL, NULL);
557         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
558
559         return cal->priv->listener;
560 }
561
562 /* Destroy handler for the calendar */
563 static void
564 e_data_cal_finalize (GObject *object)
565 {
566         EDataCal *cal;
567         EDataCalPrivate *priv;
568         CORBA_Environment ev;
569
570         g_return_if_fail (object != NULL);
571         g_return_if_fail (E_IS_DATA_CAL (object));
572
573         cal = E_DATA_CAL (object);
574         priv = cal->priv;
575
576         priv->backend = NULL;
577         
578         CORBA_exception_init (&ev);
579         bonobo_object_release_unref (priv->listener, &ev);
580         if (BONOBO_EX (&ev))
581                 g_message (G_STRLOC ": could not release the listener");
582
583         priv->listener = NULL;
584         CORBA_exception_free (&ev);
585
586         g_hash_table_destroy (priv->live_queries);
587         priv->live_queries = NULL;
588
589         g_free (priv);
590
591         if (G_OBJECT_CLASS (parent_class)->finalize)
592                 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
593 }
594
595 \f
596
597 /* Class initialization function for the calendar */
598 static void
599 e_data_cal_class_init (EDataCalClass *klass)
600 {
601         GObjectClass *object_class = (GObjectClass *) klass;
602         POA_GNOME_Evolution_Calendar_Cal__epv *epv = &klass->epv;
603
604         parent_class = g_type_class_peek_parent (klass);
605
606         /* Class method overrides */
607         object_class->finalize = e_data_cal_finalize;
608
609         /* Epv methods */
610         epv->_get_uri = impl_Cal_get_uri;
611         epv->open = impl_Cal_open;
612         epv->remove = impl_Cal_remove;
613         epv->isReadOnly = impl_Cal_isReadOnly;
614         epv->getCalAddress = impl_Cal_getCalAddress;
615         epv->getAlarmEmailAddress = impl_Cal_getAlarmEmailAddress;
616         epv->getLdapAttribute = impl_Cal_getLdapAttribute;
617         epv->getStaticCapabilities = impl_Cal_getStaticCapabilities;
618         epv->setMode = impl_Cal_setMode;
619         epv->getDefaultObject = impl_Cal_getDefaultObject;
620         epv->getObject = impl_Cal_getObject;
621         epv->getTimezone = impl_Cal_getTimezone;
622         epv->addTimezone = impl_Cal_addTimezone;
623         epv->setDefaultTimezone = impl_Cal_setDefaultTimezone;
624         epv->getObjectList = impl_Cal_getObjectList;
625         epv->getChanges = impl_Cal_getChanges;
626         epv->getFreeBusy = impl_Cal_getFreeBusy;
627         epv->discardAlarm = impl_Cal_discardAlarm;
628         epv->createObject = impl_Cal_createObject;
629         epv->modifyObject = impl_Cal_modifyObject;
630         epv->removeObject = impl_Cal_removeObject;
631         epv->receiveObjects = impl_Cal_receiveObjects;
632         epv->sendObjects = impl_Cal_sendObjects;
633         epv->getQuery = impl_Cal_getQuery;
634 }
635
636
637 /* Object initialization function for the calendar */
638 static void
639 e_data_cal_init (EDataCal *cal, EDataCalClass *klass)
640 {
641         EDataCalPrivate *priv;
642
643         priv = g_new0 (EDataCalPrivate, 1);
644         cal->priv = priv;
645
646         priv->listener = CORBA_OBJECT_NIL;
647         priv->live_queries = g_hash_table_new_full (g_str_hash, g_str_equal,
648                                                     (GDestroyNotify) g_free,
649                                                     (GDestroyNotify) g_object_unref);
650 }
651
652 BONOBO_TYPE_FUNC_FULL (EDataCal, GNOME_Evolution_Calendar_Cal, PARENT_TYPE, e_data_cal);
653
654 void 
655 e_data_cal_notify_read_only (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, gboolean read_only)
656 {
657         EDataCalPrivate *priv;
658         CORBA_Environment ev;
659
660         g_return_if_fail (cal != NULL);
661         g_return_if_fail (E_IS_DATA_CAL (cal));
662
663         priv = cal->priv;
664         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
665
666         CORBA_exception_init (&ev);
667         GNOME_Evolution_Calendar_CalListener_notifyReadOnly (priv->listener, status, read_only, &ev);
668
669         if (BONOBO_EX (&ev))
670                 g_message (G_STRLOC ": could not notify the listener of read only");
671
672         CORBA_exception_free (&ev);     
673 }
674
675 void 
676 e_data_cal_notify_cal_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
677 {
678         EDataCalPrivate *priv;
679         CORBA_Environment ev;
680
681         g_return_if_fail (cal != NULL);
682         g_return_if_fail (E_IS_DATA_CAL (cal));
683
684         priv = cal->priv;
685         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
686
687         CORBA_exception_init (&ev);
688         GNOME_Evolution_Calendar_CalListener_notifyCalAddress (priv->listener, status, address ? address : "", &ev);
689
690         if (BONOBO_EX (&ev))
691                 g_message (G_STRLOC ": could not notify the listener of cal address");
692
693         CORBA_exception_free (&ev);     
694 }
695
696 void
697 e_data_cal_notify_alarm_email_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
698 {
699         EDataCalPrivate *priv;
700         CORBA_Environment ev;
701
702         g_return_if_fail (cal != NULL);
703         g_return_if_fail (E_IS_DATA_CAL (cal));
704
705         priv = cal->priv;
706         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
707
708         CORBA_exception_init (&ev);
709         GNOME_Evolution_Calendar_CalListener_notifyAlarmEmailAddress (priv->listener, status, address ? address : "", &ev);
710
711         if (BONOBO_EX (&ev))
712                 g_message (G_STRLOC ": could not notify the listener of alarm address");
713
714         CORBA_exception_free (&ev);
715 }
716
717 void
718 e_data_cal_notify_ldap_attribute (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *attribute)
719 {
720         EDataCalPrivate *priv;
721         CORBA_Environment ev;
722
723         g_return_if_fail (cal != NULL);
724         g_return_if_fail (E_IS_DATA_CAL (cal));
725
726         priv = cal->priv;
727         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
728
729         CORBA_exception_init (&ev);
730         GNOME_Evolution_Calendar_CalListener_notifyLDAPAttribute (priv->listener, status, attribute ? attribute : "", &ev);
731
732         if (BONOBO_EX (&ev))
733                 g_message (G_STRLOC ": could not notify the listener of ldap attribute");
734
735         CORBA_exception_free (&ev);
736 }
737
738 void
739 e_data_cal_notify_static_capabilities (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *capabilities)
740 {
741         EDataCalPrivate *priv;
742         CORBA_Environment ev;
743
744         g_return_if_fail (cal != NULL);
745         g_return_if_fail (E_IS_DATA_CAL (cal));
746
747         priv = cal->priv;
748         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
749
750         CORBA_exception_init (&ev);
751         GNOME_Evolution_Calendar_CalListener_notifyStaticCapabilities (priv->listener, status,
752                                                                     capabilities ? capabilities : "", &ev);
753
754         if (BONOBO_EX (&ev))
755                 g_message (G_STRLOC ": could not notify the listener of static capabilities");
756
757         CORBA_exception_free (&ev);
758 }
759
760 void 
761 e_data_cal_notify_open (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
762 {
763         EDataCalPrivate *priv;
764         CORBA_Environment ev;
765
766         g_return_if_fail (cal != NULL);
767         g_return_if_fail (E_IS_DATA_CAL (cal));
768
769         priv = cal->priv;
770         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
771
772         CORBA_exception_init (&ev);
773         GNOME_Evolution_Calendar_CalListener_notifyCalOpened (priv->listener, status, &ev);
774
775         if (BONOBO_EX (&ev))
776                 g_message (G_STRLOC ": could not notify the listener of open");
777
778         CORBA_exception_free (&ev);
779 }
780
781 void
782 e_data_cal_notify_remove (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
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_notifyCalRemoved (priv->listener, status, &ev);
795
796         if (BONOBO_EX (&ev))
797                 g_message (G_STRLOC ": could not notify the listener of remove");
798
799         CORBA_exception_free (&ev);
800 }
801
802 void
803 e_data_cal_notify_object_created (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
804                                   const char *uid, const char *object)
805 {
806         EDataCalPrivate *priv;
807         CORBA_Environment ev;
808
809         g_return_if_fail (cal != NULL);
810         g_return_if_fail (E_IS_DATA_CAL (cal));
811
812         priv = cal->priv;
813         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
814
815         if (status == GNOME_Evolution_Calendar_Success)
816                 e_cal_backend_notify_object_created (priv->backend, object);
817
818         CORBA_exception_init (&ev);
819         GNOME_Evolution_Calendar_CalListener_notifyObjectCreated (priv->listener, status, uid ? uid : "", &ev);
820
821         if (BONOBO_EX (&ev))
822                 g_message (G_STRLOC ": could not notify the listener of object creation");
823
824         CORBA_exception_free (&ev);
825 }
826
827 void
828 e_data_cal_notify_object_modified (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
829                                    const char *old_object, const char *object)
830 {
831         EDataCalPrivate *priv;
832         CORBA_Environment ev;
833
834         g_return_if_fail (cal != NULL);
835         g_return_if_fail (E_IS_DATA_CAL (cal));
836
837         priv = cal->priv;
838         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
839
840         if (status == GNOME_Evolution_Calendar_Success)
841                 e_cal_backend_notify_object_modified (priv->backend, old_object, object);
842
843         CORBA_exception_init (&ev);
844         GNOME_Evolution_Calendar_CalListener_notifyObjectModified (priv->listener, status, &ev);
845
846         if (BONOBO_EX (&ev))
847                 g_message (G_STRLOC ": could not notify the listener of object creation");
848
849         CORBA_exception_free (&ev);
850 }
851
852 void
853 e_data_cal_notify_object_removed (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
854                                   const char *uid, const char *old_object, const char *object)
855 {
856         EDataCalPrivate *priv;
857         CORBA_Environment ev;
858
859         g_return_if_fail (cal != NULL);
860         g_return_if_fail (E_IS_DATA_CAL (cal));
861
862         priv = cal->priv;
863         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
864
865         if (status == GNOME_Evolution_Calendar_Success)
866                 e_cal_backend_notify_object_removed (priv->backend, uid, old_object, object);
867
868         CORBA_exception_init (&ev);
869         GNOME_Evolution_Calendar_CalListener_notifyObjectRemoved (priv->listener, status, &ev);
870
871         if (BONOBO_EX (&ev))
872                 g_message (G_STRLOC ": could not notify the listener of object removal");
873
874         CORBA_exception_free (&ev);
875 }
876
877 void
878 e_data_cal_notify_objects_received (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
879 {
880         EDataCalPrivate *priv;
881         CORBA_Environment ev;
882
883         g_return_if_fail (cal != NULL);
884         g_return_if_fail (E_IS_DATA_CAL (cal));
885
886         priv = cal->priv;
887         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
888
889         CORBA_exception_init (&ev);
890         GNOME_Evolution_Calendar_CalListener_notifyObjectsReceived (priv->listener, status, &ev);
891
892         if (BONOBO_EX (&ev))
893                 g_message (G_STRLOC ": could not notify the listener of objects received");
894
895         CORBA_exception_free (&ev);
896 }
897
898 void
899 e_data_cal_notify_alarm_discarded (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
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         CORBA_exception_init (&ev);
911         GNOME_Evolution_Calendar_CalListener_notifyAlarmDiscarded (priv->listener, status, &ev);
912
913         if (BONOBO_EX (&ev))
914                 g_message (G_STRLOC ": could not notify the listener of alarm discarded");
915
916         CORBA_exception_free (&ev);     
917 }
918
919 void
920 e_data_cal_notify_objects_sent (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *users, const char *calobj)
921 {
922         EDataCalPrivate *priv;
923         CORBA_Environment ev;
924         GNOME_Evolution_Calendar_UserList *corba_users;
925
926         g_return_if_fail (cal != NULL);
927         g_return_if_fail (E_IS_DATA_CAL (cal));
928
929         priv = cal->priv;
930         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
931
932         corba_users = GNOME_Evolution_Calendar_UserList__alloc ();
933         corba_users->_length = g_list_length (users);
934         if (users) {
935                 GList *l;
936                 int n;
937
938                 corba_users->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_User_allocbuf (corba_users->_length);
939                 for (l = users, n = 0; l != NULL; l = l->next, n++)
940                         corba_users->_buffer[n] = CORBA_string_dup (l->data);
941         }
942
943         CORBA_exception_init (&ev);
944         GNOME_Evolution_Calendar_CalListener_notifyObjectsSent (priv->listener, status, corba_users,
945                                                                 calobj ? calobj : "", &ev);
946
947         if (BONOBO_EX (&ev))
948                 g_message (G_STRLOC ": could not notify the listener of objects sent");
949
950         CORBA_exception_free (&ev);
951         CORBA_free (corba_users);
952 }
953
954 void
955 e_data_cal_notify_default_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
956 {
957         EDataCalPrivate *priv;
958         CORBA_Environment ev;
959         
960         g_return_if_fail (cal != NULL);
961         g_return_if_fail (E_IS_DATA_CAL (cal));
962
963         priv = cal->priv;
964         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
965
966         CORBA_exception_init (&ev);
967
968         GNOME_Evolution_Calendar_CalListener_notifyDefaultObjectRequested (priv->listener, status, 
969                                                                            object ? object : "", &ev);
970
971         if (BONOBO_EX (&ev))
972                 g_message (G_STRLOC ": could not notify the listener of default object");
973
974         CORBA_exception_free (&ev);
975 }
976
977 void
978 e_data_cal_notify_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
979 {
980         EDataCalPrivate *priv;
981         CORBA_Environment ev;
982         
983         g_return_if_fail (cal != NULL);
984         g_return_if_fail (E_IS_DATA_CAL (cal));
985
986         priv = cal->priv;
987         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
988
989         CORBA_exception_init (&ev);
990
991         GNOME_Evolution_Calendar_CalListener_notifyObjectRequested (priv->listener, status,
992                                                                     object ? object : "", &ev);
993
994         if (BONOBO_EX (&ev))
995                 g_message (G_STRLOC ": could not notify the listener of object");
996
997         CORBA_exception_free (&ev);
998 }
999
1000 void
1001 e_data_cal_notify_object_list (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *objects)
1002 {
1003         EDataCalPrivate *priv;
1004         CORBA_Environment ev;
1005         GNOME_Evolution_Calendar_stringlist seq;
1006         GList *l;
1007         int i;
1008         
1009         g_return_if_fail (cal != NULL);
1010         g_return_if_fail (E_IS_DATA_CAL (cal));
1011
1012         priv = cal->priv;
1013         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1014
1015         CORBA_exception_init (&ev);
1016
1017         seq._maximum = g_list_length (objects);
1018         seq._length = 0;
1019         seq._buffer = GNOME_Evolution_Calendar_stringlist_allocbuf (seq._maximum);
1020
1021         for (l = objects, i = 0; l; l = l->next, i++) {
1022                 seq._buffer[i] = CORBA_string_dup (l->data);
1023                 seq._length++;
1024         }
1025
1026         GNOME_Evolution_Calendar_CalListener_notifyObjectListRequested (priv->listener, status, &seq, &ev);
1027
1028         if (BONOBO_EX (&ev))
1029                 g_message (G_STRLOC ": could not notify the listener of object list");
1030
1031         CORBA_exception_free (&ev);
1032
1033         CORBA_free(seq._buffer);
1034 }
1035
1036 void
1037 e_data_cal_notify_query (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, EDataCalView *query)
1038 {
1039         EDataCalPrivate *priv;
1040         CORBA_Environment ev;
1041
1042         g_return_if_fail (cal != NULL);
1043         g_return_if_fail (E_IS_DATA_CAL (cal));
1044
1045         priv = cal->priv;
1046         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1047
1048         CORBA_exception_init (&ev);
1049         GNOME_Evolution_Calendar_CalListener_notifyQuery (priv->listener, status, BONOBO_OBJREF (query), &ev);
1050
1051         if (BONOBO_EX (&ev))
1052                 g_message (G_STRLOC ": could not notify the listener of query");
1053
1054         CORBA_exception_free (&ev);     
1055 }
1056
1057 void
1058 e_data_cal_notify_timezone_requested (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
1059 {
1060         EDataCalPrivate *priv;
1061         CORBA_Environment ev;
1062
1063         g_return_if_fail (E_IS_DATA_CAL (cal));
1064
1065         priv = cal->priv;
1066         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1067
1068         CORBA_exception_init (&ev);
1069         GNOME_Evolution_Calendar_CalListener_notifyTimezoneRequested (priv->listener, status, object ? object : "", &ev);
1070
1071         if (BONOBO_EX (&ev))
1072                 g_warning (G_STRLOC ": could not notify the listener of timezone requested");
1073
1074         CORBA_exception_free (&ev);
1075 }
1076
1077 void
1078 e_data_cal_notify_timezone_added (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *tzid)
1079 {
1080         EDataCalPrivate *priv;
1081         CORBA_Environment ev;
1082
1083         g_return_if_fail (E_IS_DATA_CAL (cal));
1084
1085         priv = cal->priv;
1086         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1087
1088         CORBA_exception_init (&ev);
1089         GNOME_Evolution_Calendar_CalListener_notifyTimezoneAdded (priv->listener, status, tzid ? tzid : "", &ev);
1090
1091         if (BONOBO_EX (&ev))
1092                 g_warning (G_STRLOC ": could not notify the listener of timezone added");
1093
1094         CORBA_exception_free (&ev);
1095 }
1096
1097 void
1098 e_data_cal_notify_default_timezone_set (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
1099 {
1100         EDataCalPrivate *priv;
1101         CORBA_Environment ev;
1102
1103         g_return_if_fail (E_IS_DATA_CAL (cal));
1104
1105         priv = cal->priv;
1106         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1107
1108         CORBA_exception_init (&ev);
1109         GNOME_Evolution_Calendar_CalListener_notifyDefaultTimezoneSet (priv->listener, status, &ev);
1110
1111         if (BONOBO_EX (&ev))
1112                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1113
1114         CORBA_exception_free (&ev);
1115 }
1116
1117 void
1118 e_data_cal_notify_changes (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
1119                            GList *adds, GList *modifies, GList *deletes)
1120 {
1121         EDataCalPrivate *priv;
1122         CORBA_Environment ev;
1123         GNOME_Evolution_Calendar_CalObjChangeSeq seq;
1124         GList *l;       
1125         int n, i;
1126
1127         g_return_if_fail (E_IS_DATA_CAL (cal));
1128
1129         priv = cal->priv;
1130         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1131
1132         n = g_list_length (adds) + g_list_length (modifies) + g_list_length (deletes);
1133         seq._maximum = n;
1134         seq._length = n;
1135         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n);
1136
1137         i = 0;
1138         for (l = adds; l; i++, l = l->next) {
1139                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1140                 
1141                 change->calobj = CORBA_string_dup (l->data);
1142                 change->type = GNOME_Evolution_Calendar_ADDED;
1143         }
1144
1145         for (l = modifies; l; i++, l = l->next) {
1146                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1147
1148                 change->calobj = CORBA_string_dup (l->data);
1149                 change->type = GNOME_Evolution_Calendar_MODIFIED;
1150         }
1151
1152         for (l = deletes; l; i++, l = l->next) {
1153                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1154
1155                 change->calobj = CORBA_string_dup (l->data);
1156                 change->type = GNOME_Evolution_Calendar_DELETED;
1157         }
1158         
1159         CORBA_exception_init (&ev);
1160         GNOME_Evolution_Calendar_CalListener_notifyChanges (priv->listener, status, &seq, &ev);
1161
1162         CORBA_free (seq._buffer);
1163
1164         if (BONOBO_EX (&ev))
1165                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1166
1167         CORBA_exception_free (&ev);
1168 }
1169
1170 void
1171 e_data_cal_notify_free_busy (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *freebusy)
1172 {
1173         EDataCalPrivate *priv;
1174         CORBA_Environment ev;
1175         GNOME_Evolution_Calendar_CalObjSeq seq;
1176         GList *l;
1177         int n, i;
1178         
1179         g_return_if_fail (E_IS_DATA_CAL (cal));
1180
1181         priv = cal->priv;
1182         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1183
1184         n = g_list_length (freebusy);
1185         seq._maximum = n;
1186         seq._length = n;
1187         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObj_allocbuf (n);
1188
1189         for (i = 0, l = freebusy; l; i++, l = l->next)
1190                 seq._buffer[i] = CORBA_string_dup (l->data);
1191         
1192         CORBA_exception_init (&ev);
1193         GNOME_Evolution_Calendar_CalListener_notifyFreeBusy (priv->listener, status, &seq, &ev);
1194
1195         CORBA_free (seq._buffer);
1196
1197         if (BONOBO_EX (&ev))
1198                 g_warning (G_STRLOC ": could not notify the listener of freebusy");
1199
1200         CORBA_exception_free (&ev);
1201 }
1202
1203 /**
1204  * e_data_cal_notify_mode:
1205  * @cal: A calendar client interface.
1206  * @status: Status of the mode set.
1207  * @mode: The current mode.
1208  * 
1209  * Notifys the listener of the results of a setMode call.
1210  **/
1211 void
1212 e_data_cal_notify_mode (EDataCal *cal,
1213                         GNOME_Evolution_Calendar_CalListener_SetModeStatus status,
1214                         GNOME_Evolution_Calendar_CalMode mode)
1215 {
1216         EDataCalPrivate *priv;
1217         CORBA_Environment ev;
1218
1219         g_return_if_fail (cal != NULL);
1220         g_return_if_fail (E_IS_DATA_CAL (cal));
1221
1222         priv = cal->priv;
1223         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1224
1225         CORBA_exception_init (&ev);
1226         GNOME_Evolution_Calendar_CalListener_notifyCalSetMode (priv->listener, status, mode, &ev);
1227
1228         if (BONOBO_EX (&ev))
1229                 g_message ("e_data_cal_notify_mode(): could not notify the listener "
1230                            "about a mode change");
1231
1232         CORBA_exception_free (&ev);     
1233 }
1234
1235
1236 void 
1237 e_data_cal_notify_auth_required (EDataCal *cal)
1238 {
1239        EDataCalPrivate *priv;
1240        CORBA_Environment ev;
1241        
1242        g_return_if_fail (cal != NULL);
1243        g_return_if_fail (E_IS_DATA_CAL (cal));
1244        
1245        priv = cal->priv;
1246        g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1247        
1248        CORBA_exception_init (&ev);
1249        GNOME_Evolution_Calendar_CalListener_notifyAuthRequired (priv->listener,  &ev);
1250        if (BONOBO_EX (&ev))
1251                 g_message ("e_data_cal_notify_auth_required: could not notify the listener "
1252                            "about auth required");
1253
1254         CORBA_exception_free (&ev);
1255 }
1256
1257 /**
1258  * e_data_cal_notify_error
1259  * @cal: A calendar client interface.
1260  * @message: Error message.
1261  *
1262  * Notify a calendar client of an error occurred in the backend.
1263  */
1264 void
1265 e_data_cal_notify_error (EDataCal *cal, const char *message)
1266 {
1267         EDataCalPrivate *priv;
1268         CORBA_Environment ev;
1269
1270         g_return_if_fail (cal != NULL);
1271         g_return_if_fail (E_IS_DATA_CAL (cal));
1272         g_return_if_fail (message != NULL);
1273
1274         priv = cal->priv;
1275         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1276
1277         CORBA_exception_init (&ev);
1278         GNOME_Evolution_Calendar_CalListener_notifyErrorOccurred (priv->listener, (char *) message, &ev);
1279
1280         if (BONOBO_EX (&ev))
1281                 g_message ("e_data_cal_notify_remove(): could not notify the listener "
1282                            "about a removed object");
1283
1284         CORBA_exception_free (&ev);
1285 }
1286
1287 /**
1288  * e_data_cal_notify_categories_changed:
1289  * @cal: A calendar client interface.
1290  * @categories: List of categories.
1291  * 
1292  * Notifies a listener attached to a calendar client interface object about the
1293  * current set of categories in a calendar backend.
1294  **/
1295 void
1296 e_data_cal_notify_categories_changed (EDataCal *cal, GNOME_Evolution_Calendar_StringSeq *categories)
1297 {
1298         EDataCalPrivate *priv;
1299         CORBA_Environment ev;
1300
1301         g_return_if_fail (cal != NULL);
1302         g_return_if_fail (E_IS_DATA_CAL (cal));
1303         g_return_if_fail (categories != NULL);
1304
1305         priv = cal->priv;
1306         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1307
1308         CORBA_exception_init (&ev);
1309         GNOME_Evolution_Calendar_CalListener_notifyCategoriesChanged (priv->listener, categories, &ev);
1310
1311         if (BONOBO_EX (&ev))
1312                 g_message ("e_data_cal_notify_categories_changed(): Could not notify the listener "
1313                            "about the current set of categories");
1314
1315         CORBA_exception_free (&ev);
1316 }