Fixed a c/p bug. Don't call notifyDefaultTimezoneSet, we want to
[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
46 /* Cal::get_uri method */
47 static CORBA_char *
48 impl_Cal_get_uri (PortableServer_Servant servant,
49                   CORBA_Environment *ev)
50 {
51         EDataCal *cal;
52         EDataCalPrivate *priv;
53         const char *str_uri;
54         CORBA_char *str_uri_copy;
55
56         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
57         priv = cal->priv;
58
59         str_uri = e_cal_backend_get_uri (priv->backend);
60         str_uri_copy = CORBA_string_dup (str_uri);
61
62         return str_uri_copy;
63 }
64
65 static void
66 impl_Cal_open (PortableServer_Servant servant,
67                CORBA_boolean only_if_exists,
68                const CORBA_char *username,
69                const CORBA_char *password,
70                CORBA_Environment *ev)
71 {
72         EDataCal *cal;
73         EDataCalPrivate *priv;
74         
75         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
76         priv = cal->priv;
77
78         e_cal_backend_open (priv->backend, cal, only_if_exists, username, password);
79 }
80
81 static void
82 impl_Cal_remove (PortableServer_Servant servant,
83                  CORBA_Environment *ev)
84 {
85         EDataCal *cal;
86         EDataCalPrivate *priv;
87         
88         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
89         priv = cal->priv;
90
91         e_cal_backend_remove (priv->backend, cal);
92 }
93
94 /* Cal::isReadOnly method */
95 static void
96 impl_Cal_isReadOnly (PortableServer_Servant servant,
97                      CORBA_Environment *ev)
98 {
99         EDataCal *cal;
100         EDataCalPrivate *priv;
101
102         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
103         priv = cal->priv;
104
105         e_cal_backend_is_read_only (priv->backend, cal);
106 }
107                        
108 /* Cal::getEmailAddress method */
109 static void
110 impl_Cal_getCalAddress (PortableServer_Servant servant,
111                         CORBA_Environment *ev)
112 {
113         EDataCal *cal;
114         EDataCalPrivate *priv;
115
116         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
117         priv = cal->priv;
118
119         e_cal_backend_get_cal_address (priv->backend, cal);
120 }
121                        
122 /* Cal::get_alarm_email_address method */
123 static void
124 impl_Cal_getAlarmEmailAddress (PortableServer_Servant servant,
125                                CORBA_Environment *ev)
126 {
127         EDataCal *cal;
128         EDataCalPrivate *priv;
129
130         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
131         priv = cal->priv;
132
133         e_cal_backend_get_alarm_email_address (priv->backend, cal);
134 }
135                        
136 /* Cal::get_ldap_attribute method */
137 static void
138 impl_Cal_getLdapAttribute (PortableServer_Servant servant,
139                            CORBA_Environment *ev)
140 {
141         EDataCal *cal;
142         EDataCalPrivate *priv;
143
144         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
145         priv = cal->priv;
146
147         e_cal_backend_get_ldap_attribute (priv->backend, cal);
148 }
149
150 /* Cal::getSchedulingInformation method */
151 static void
152 impl_Cal_getStaticCapabilities (PortableServer_Servant servant,
153                                 CORBA_Environment *ev)
154 {
155         EDataCal *cal;
156         EDataCalPrivate *priv;
157
158         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
159         priv = cal->priv;
160
161         e_cal_backend_get_static_capabilities (priv->backend, cal);
162 }
163
164 /* Cal::setMode method */
165 static void
166 impl_Cal_setMode (PortableServer_Servant servant,
167                   GNOME_Evolution_Calendar_CalMode mode,
168                   CORBA_Environment *ev)
169 {
170         EDataCal *cal;
171         EDataCalPrivate *priv;
172         
173         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
174         priv = cal->priv;
175
176         e_cal_backend_set_mode (priv->backend, mode);
177 }
178
179 static void
180 impl_Cal_getDefaultObject (PortableServer_Servant servant,
181                            CORBA_Environment *ev)
182 {
183         EDataCal *cal;
184         EDataCalPrivate *priv;
185  
186         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
187         priv = cal->priv;
188  
189         e_cal_backend_get_default_object (priv->backend, cal);
190 }
191
192 /* Cal::getObject method */
193 static void
194 impl_Cal_getObject (PortableServer_Servant servant,
195                     const CORBA_char *uid,
196                     const CORBA_char *rid,
197                     CORBA_Environment *ev)
198 {
199         EDataCal *cal;
200         EDataCalPrivate *priv;
201
202         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
203         priv = cal->priv;
204
205         e_cal_backend_get_object (priv->backend, cal, uid, rid);
206 }
207
208 /* Cal::getObjectsInRange method */
209 static void
210 impl_Cal_getObjectList (PortableServer_Servant servant,
211                         const CORBA_char *query,
212                         CORBA_Environment *ev)
213 {
214         EDataCal *cal;
215         EDataCalPrivate *priv;
216         
217         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
218         priv = cal->priv;
219
220         e_cal_backend_get_object_list (priv->backend, cal, query);
221 }
222
223 /* Cal::getChanges method */
224 static void
225 impl_Cal_getChanges (PortableServer_Servant servant,
226                      const CORBA_char *change_id,
227                      CORBA_Environment *ev)
228 {
229        EDataCal *cal;
230        EDataCalPrivate *priv;
231
232        cal = E_DATA_CAL (bonobo_object_from_servant (servant));
233        priv = cal->priv;
234
235        e_cal_backend_get_changes (priv->backend, cal, change_id);
236 }
237
238 /* Cal::getFreeBusy method */
239 static void
240 impl_Cal_getFreeBusy (PortableServer_Servant servant,
241                       const GNOME_Evolution_Calendar_UserList *user_list,
242                       const GNOME_Evolution_Calendar_Time_t start,
243                       const GNOME_Evolution_Calendar_Time_t end,
244                       CORBA_Environment *ev)
245 {
246         EDataCal *cal;
247         EDataCalPrivate *priv;
248         GList *users = NULL;
249
250         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
251         priv = cal->priv;
252
253         /* convert the CORBA user list to a GList */
254         if (user_list) {
255                 int i;
256
257                 for (i = 0; i < user_list->_length; i++)
258                         users = g_list_append (users, user_list->_buffer[i]);
259         }
260
261         /* call the backend's get_free_busy method */
262         e_cal_backend_get_free_busy (priv->backend, cal, users, start, end);
263 }
264
265 /* Cal::discardAlarm method */
266 static void
267 impl_Cal_discardAlarm (PortableServer_Servant servant,
268                        const CORBA_char *uid,
269                        const CORBA_char *auid,
270                        CORBA_Environment *ev)
271 {
272         EDataCal *cal;
273         EDataCalPrivate *priv;
274
275         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
276         priv = cal->priv;
277
278         e_cal_backend_discard_alarm (priv->backend, cal, uid, auid);
279 }
280
281 static void
282 impl_Cal_createObject (PortableServer_Servant servant,
283                        const CORBA_char *calobj,
284                        CORBA_Environment *ev)
285 {
286         EDataCal *cal;
287         EDataCalPrivate *priv;
288
289         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
290         priv = cal->priv;
291
292         e_cal_backend_create_object (priv->backend, cal, calobj);
293 }
294
295 static void
296 impl_Cal_modifyObject (PortableServer_Servant servant,
297                        const CORBA_char *calobj,
298                        const GNOME_Evolution_Calendar_CalObjModType mod,
299                        CORBA_Environment *ev)
300 {
301         EDataCal *cal;
302         EDataCalPrivate *priv;
303
304         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
305         priv = cal->priv;
306
307         e_cal_backend_modify_object (priv->backend, cal, calobj, mod);
308 }
309
310 /* Cal::removeObject method */
311 static void
312 impl_Cal_removeObject (PortableServer_Servant servant,
313                        const CORBA_char *uid,
314                        const CORBA_char *rid,
315                        const GNOME_Evolution_Calendar_CalObjModType mod,
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_remove_object (priv->backend, cal, uid, rid, mod);
325 }
326
327 static void
328 impl_Cal_receiveObjects (PortableServer_Servant servant,
329                          const CORBA_char *calobj,
330                          CORBA_Environment *ev)
331 {
332         EDataCal *cal;
333         EDataCalPrivate *priv;
334
335         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
336         priv = cal->priv;
337
338         e_cal_backend_receive_objects (priv->backend, cal, calobj);
339 }
340
341 static void
342 impl_Cal_sendObjects (PortableServer_Servant servant,
343                       const CORBA_char *calobj,
344                       CORBA_Environment *ev)
345 {
346         EDataCal *cal;
347         EDataCalPrivate *priv;
348
349         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
350         priv = cal->priv;
351
352         e_cal_backend_send_objects (priv->backend, cal, calobj);
353 }
354
355 /* Cal::getQuery implementation */
356 static void
357 impl_Cal_getQuery (PortableServer_Servant servant,
358                    const CORBA_char *sexp,
359                    GNOME_Evolution_Calendar_CalViewListener ql,
360                    CORBA_Environment *ev)
361 {
362
363         EDataCal *cal;
364         EDataCalPrivate *priv;
365         EDataCalView *query;
366         ECalBackendSExp *obj_sexp;
367         
368         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
369         priv = cal->priv;
370
371         /* we handle this entirely here, since it doesn't require any
372            backend involvement now that we have pas_book_view_start to
373            actually kick off the search. */
374
375         obj_sexp = e_cal_backend_sexp_new (sexp);
376         if (!obj_sexp) {
377                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_InvalidQuery, NULL);
378
379                 return;
380         }
381
382         query = e_data_cal_view_new (priv->backend, ql, obj_sexp);
383         if (!query) {
384                 g_object_unref (obj_sexp);
385                 e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_OtherError, NULL);
386
387                 return;
388         }
389
390         e_cal_backend_add_query (priv->backend, query);
391
392         e_data_cal_notify_query (cal, GNOME_Evolution_Calendar_Success, query);
393
394         g_object_unref (query);
395 }
396
397
398 /* Cal::getTimezone method */
399 static void
400 impl_Cal_getTimezone (PortableServer_Servant servant,
401                       const CORBA_char *tzid,
402                       CORBA_Environment *ev)
403 {
404         EDataCal *cal;
405         EDataCalPrivate *priv;
406
407         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
408         priv = cal->priv;
409
410         e_cal_backend_get_timezone (priv->backend, cal, tzid);
411 }
412
413 /* Cal::addTimezone method */
414 static void
415 impl_Cal_addTimezone (PortableServer_Servant servant,
416                       const CORBA_char *tz,
417                       CORBA_Environment *ev)
418 {
419         EDataCal *cal;
420         EDataCalPrivate *priv;
421
422         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
423         priv = cal->priv;
424
425         e_cal_backend_add_timezone (priv->backend, cal, tz);
426 }
427
428 /* Cal::setDefaultTimezone method */
429 static void
430 impl_Cal_setDefaultTimezone (PortableServer_Servant servant,
431                              const CORBA_char *tzid,
432                              CORBA_Environment *ev)
433 {
434         EDataCal *cal;
435         EDataCalPrivate *priv;
436
437         cal = E_DATA_CAL (bonobo_object_from_servant (servant));
438         priv = cal->priv;
439
440         e_cal_backend_set_default_timezone (priv->backend, cal, tzid);
441 }
442
443 /**
444  * cal_construct:
445  * @cal: A calendar client interface.
446  * @corba_cal: CORBA object for the calendar.
447  * @backend: Calendar backend that this @cal presents an interface to.
448  * @listener: Calendar listener for notification.
449  *
450  * Constructs a calendar client interface object by binding the corresponding
451  * CORBA object to it.  The calendar interface is bound to the specified
452  * @backend, and will notify the @listener about changes to the calendar.
453  *
454  * Return value: The same object as the @cal argument.
455  **/
456 EDataCal *
457 e_data_cal_construct (EDataCal *cal,
458                       ECalBackend *backend,
459                       GNOME_Evolution_Calendar_CalListener listener)
460 {
461         EDataCalPrivate *priv;
462         CORBA_Environment ev;
463
464         g_return_val_if_fail (cal != NULL, NULL);
465         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
466         g_return_val_if_fail (backend != NULL, NULL);
467         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
468
469         priv = cal->priv;
470
471         CORBA_exception_init (&ev);
472         priv->listener = CORBA_Object_duplicate (listener, &ev);
473         if (BONOBO_EX (&ev)) {
474                 g_message ("cal_construct: could not duplicate the listener");
475                 priv->listener = CORBA_OBJECT_NIL;
476                 CORBA_exception_free (&ev);
477                 return NULL;
478         }
479
480         CORBA_exception_free (&ev);
481
482         priv->backend = backend;
483         
484         return cal;
485 }
486
487 /**
488  * cal_new:
489  * @backend: A calendar backend.
490  * @listener: A calendar listener.
491  *
492  * Creates a new calendar client interface object and binds it to the
493  * specified @backend and @listener objects.
494  *
495  * Return value: A newly-created #EDataCal calendar client interface
496  * object, or %NULL if its corresponding CORBA object could not be
497  * created.
498  **/
499 EDataCal *
500 e_data_cal_new (ECalBackend *backend, const char *uri, GNOME_Evolution_Calendar_CalListener listener)
501 {
502         EDataCal *cal, *retval;
503
504         g_return_val_if_fail (backend != NULL, NULL);
505         g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
506
507         cal = E_DATA_CAL (g_object_new (E_TYPE_DATA_CAL, 
508                                  "poa", bonobo_poa_get_threaded (ORBIT_THREAD_HINT_PER_REQUEST, NULL),
509                                  NULL));
510
511         retval = e_data_cal_construct (cal, backend, listener);
512         if (!retval) {
513                 g_message (G_STRLOC ": could not construct the calendar client interface");
514                 bonobo_object_unref (BONOBO_OBJECT (cal));
515                 return NULL;
516         }
517
518         return retval;
519 }
520
521 ECalBackend *
522 e_data_cal_get_backend (EDataCal *cal)
523 {
524         g_return_val_if_fail (cal != NULL, NULL);
525         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
526
527         return cal->priv->backend;
528 }
529
530 GNOME_Evolution_Calendar_CalListener
531 e_data_cal_get_listener (EDataCal *cal)
532 {
533         g_return_val_if_fail (cal != NULL, NULL);
534         g_return_val_if_fail (E_IS_DATA_CAL (cal), NULL);
535
536         return cal->priv->listener;
537 }
538
539 /* Destroy handler for the calendar */
540 static void
541 cal_finalize (GObject *object)
542 {
543         EDataCal *cal;
544         EDataCalPrivate *priv;
545         CORBA_Environment ev;
546
547         g_return_if_fail (object != NULL);
548         g_return_if_fail (E_IS_DATA_CAL (object));
549
550         cal = E_DATA_CAL (object);
551         priv = cal->priv;
552
553         priv->backend = NULL;
554         
555         CORBA_exception_init (&ev);
556         bonobo_object_release_unref (priv->listener, &ev);
557         if (BONOBO_EX (&ev))
558                 g_message (G_STRLOC ": could not release the listener");
559
560         priv->listener = NULL;
561         CORBA_exception_free (&ev);
562
563         g_free (priv);
564
565         if (G_OBJECT_CLASS (parent_class)->finalize)
566                 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
567 }
568
569 \f
570
571 /* Class initialization function for the calendar */
572 static void
573 e_data_cal_class_init (EDataCalClass *klass)
574 {
575         GObjectClass *object_class = (GObjectClass *) klass;
576         POA_GNOME_Evolution_Calendar_Cal__epv *epv = &klass->epv;
577
578         parent_class = g_type_class_peek_parent (klass);
579
580         /* Class method overrides */
581         object_class->finalize = cal_finalize;
582
583         /* Epv methods */
584         epv->_get_uri = impl_Cal_get_uri;
585         epv->open = impl_Cal_open;
586         epv->remove = impl_Cal_remove;
587         epv->isReadOnly = impl_Cal_isReadOnly;
588         epv->getCalAddress = impl_Cal_getCalAddress;
589         epv->getAlarmEmailAddress = impl_Cal_getAlarmEmailAddress;
590         epv->getLdapAttribute = impl_Cal_getLdapAttribute;
591         epv->getStaticCapabilities = impl_Cal_getStaticCapabilities;
592         epv->setMode = impl_Cal_setMode;
593         epv->getDefaultObject = impl_Cal_getDefaultObject;
594         epv->getObject = impl_Cal_getObject;
595         epv->getTimezone = impl_Cal_getTimezone;
596         epv->addTimezone = impl_Cal_addTimezone;
597         epv->setDefaultTimezone = impl_Cal_setDefaultTimezone;
598         epv->getObjectList = impl_Cal_getObjectList;
599         epv->getChanges = impl_Cal_getChanges;
600         epv->getFreeBusy = impl_Cal_getFreeBusy;
601         epv->discardAlarm = impl_Cal_discardAlarm;
602         epv->createObject = impl_Cal_createObject;
603         epv->modifyObject = impl_Cal_modifyObject;
604         epv->removeObject = impl_Cal_removeObject;
605         epv->receiveObjects = impl_Cal_receiveObjects;
606         epv->sendObjects = impl_Cal_sendObjects;
607         epv->getQuery = impl_Cal_getQuery;
608 }
609
610
611 /* Object initialization function for the calendar */
612 static void
613 e_data_cal_init (EDataCal *cal, EDataCalClass *klass)
614 {
615         EDataCalPrivate *priv;
616
617         priv = g_new0 (EDataCalPrivate, 1);
618         cal->priv = priv;
619
620         priv->listener = CORBA_OBJECT_NIL;
621 }
622
623 BONOBO_TYPE_FUNC_FULL (EDataCal, GNOME_Evolution_Calendar_Cal, PARENT_TYPE, e_data_cal);
624
625 void 
626 e_data_cal_notify_read_only (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, gboolean read_only)
627 {
628         EDataCalPrivate *priv;
629         CORBA_Environment ev;
630
631         g_return_if_fail (cal != NULL);
632         g_return_if_fail (E_IS_DATA_CAL (cal));
633
634         priv = cal->priv;
635         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
636
637         CORBA_exception_init (&ev);
638         GNOME_Evolution_Calendar_CalListener_notifyReadOnly (priv->listener, status, read_only, &ev);
639
640         if (BONOBO_EX (&ev))
641                 g_message (G_STRLOC ": could not notify the listener of read only");
642
643         CORBA_exception_free (&ev);     
644 }
645
646 void 
647 e_data_cal_notify_cal_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
648 {
649         EDataCalPrivate *priv;
650         CORBA_Environment ev;
651
652         g_return_if_fail (cal != NULL);
653         g_return_if_fail (E_IS_DATA_CAL (cal));
654
655         priv = cal->priv;
656         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
657
658         CORBA_exception_init (&ev);
659         GNOME_Evolution_Calendar_CalListener_notifyCalAddress (priv->listener, status, address ? address : "", &ev);
660
661         if (BONOBO_EX (&ev))
662                 g_message (G_STRLOC ": could not notify the listener of cal address");
663
664         CORBA_exception_free (&ev);     
665 }
666
667 void
668 e_data_cal_notify_alarm_email_address (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *address)
669 {
670         EDataCalPrivate *priv;
671         CORBA_Environment ev;
672
673         g_return_if_fail (cal != NULL);
674         g_return_if_fail (E_IS_DATA_CAL (cal));
675
676         priv = cal->priv;
677         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
678
679         CORBA_exception_init (&ev);
680         GNOME_Evolution_Calendar_CalListener_notifyAlarmEmailAddress (priv->listener, status, address ? address : "", &ev);
681
682         if (BONOBO_EX (&ev))
683                 g_message (G_STRLOC ": could not notify the listener of alarm address");
684
685         CORBA_exception_free (&ev);
686 }
687
688 void
689 e_data_cal_notify_ldap_attribute (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *attribute)
690 {
691         EDataCalPrivate *priv;
692         CORBA_Environment ev;
693
694         g_return_if_fail (cal != NULL);
695         g_return_if_fail (E_IS_DATA_CAL (cal));
696
697         priv = cal->priv;
698         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
699
700         CORBA_exception_init (&ev);
701         GNOME_Evolution_Calendar_CalListener_notifyLDAPAttribute (priv->listener, status, attribute ? attribute : "", &ev);
702
703         if (BONOBO_EX (&ev))
704                 g_message (G_STRLOC ": could not notify the listener of ldap attribute");
705
706         CORBA_exception_free (&ev);
707 }
708
709 void
710 e_data_cal_notify_static_capabilities (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *capabilities)
711 {
712         EDataCalPrivate *priv;
713         CORBA_Environment ev;
714
715         g_return_if_fail (cal != NULL);
716         g_return_if_fail (E_IS_DATA_CAL (cal));
717
718         priv = cal->priv;
719         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
720
721         CORBA_exception_init (&ev);
722         GNOME_Evolution_Calendar_CalListener_notifyStaticCapabilities (priv->listener, status,
723                                                                     capabilities ? capabilities : "", &ev);
724
725         if (BONOBO_EX (&ev))
726                 g_message (G_STRLOC ": could not notify the listener of static capabilities");
727
728         CORBA_exception_free (&ev);
729 }
730
731 void 
732 e_data_cal_notify_open (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
733 {
734         EDataCalPrivate *priv;
735         CORBA_Environment ev;
736
737         g_return_if_fail (cal != NULL);
738         g_return_if_fail (E_IS_DATA_CAL (cal));
739
740         priv = cal->priv;
741         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
742
743         CORBA_exception_init (&ev);
744         GNOME_Evolution_Calendar_CalListener_notifyCalOpened (priv->listener, status, &ev);
745
746         if (BONOBO_EX (&ev))
747                 g_message (G_STRLOC ": could not notify the listener of open");
748
749         CORBA_exception_free (&ev);
750 }
751
752 void
753 e_data_cal_notify_remove (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
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_notifyCalRemoved (priv->listener, status, &ev);
766
767         if (BONOBO_EX (&ev))
768                 g_message (G_STRLOC ": could not notify the listener of remove");
769
770         CORBA_exception_free (&ev);
771 }
772
773 void
774 e_data_cal_notify_object_created (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status,
775                                   const char *uid, const char *object)
776 {
777         EDataCalPrivate *priv;
778         CORBA_Environment ev;
779
780         g_return_if_fail (cal != NULL);
781         g_return_if_fail (E_IS_DATA_CAL (cal));
782
783         priv = cal->priv;
784         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
785
786         if (status == GNOME_Evolution_Calendar_Success)
787                 e_cal_backend_notify_object_created (priv->backend, object);
788
789         CORBA_exception_init (&ev);
790         GNOME_Evolution_Calendar_CalListener_notifyObjectCreated (priv->listener, status, uid ? uid : "", &ev);
791
792         if (BONOBO_EX (&ev))
793                 g_message (G_STRLOC ": could not notify the listener of object creation");
794
795         CORBA_exception_free (&ev);
796 }
797
798 void
799 e_data_cal_notify_object_modified (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
800                                    const char *old_object, const char *object)
801 {
802         EDataCalPrivate *priv;
803         CORBA_Environment ev;
804
805         g_return_if_fail (cal != NULL);
806         g_return_if_fail (E_IS_DATA_CAL (cal));
807
808         priv = cal->priv;
809         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
810
811         if (status == GNOME_Evolution_Calendar_Success)
812                 e_cal_backend_notify_object_modified (priv->backend, old_object, object);
813
814         CORBA_exception_init (&ev);
815         GNOME_Evolution_Calendar_CalListener_notifyObjectModified (priv->listener, status, &ev);
816
817         if (BONOBO_EX (&ev))
818                 g_message (G_STRLOC ": could not notify the listener of object creation");
819
820         CORBA_exception_free (&ev);
821 }
822
823 void
824 e_data_cal_notify_object_removed (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
825                                   const char *uid, const char *object)
826 {
827         EDataCalPrivate *priv;
828         CORBA_Environment ev;
829
830         g_return_if_fail (cal != NULL);
831         g_return_if_fail (E_IS_DATA_CAL (cal));
832
833         priv = cal->priv;
834         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
835
836         if (status == GNOME_Evolution_Calendar_Success)
837                 e_cal_backend_notify_object_removed (priv->backend, uid, object);
838
839         CORBA_exception_init (&ev);
840         GNOME_Evolution_Calendar_CalListener_notifyObjectRemoved (priv->listener, status, &ev);
841
842         if (BONOBO_EX (&ev))
843                 g_message (G_STRLOC ": could not notify the listener of object removal");
844
845         CORBA_exception_free (&ev);
846 }
847
848 void
849 e_data_cal_notify_objects_received (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
850 {
851         EDataCalPrivate *priv;
852         CORBA_Environment ev;
853
854         g_return_if_fail (cal != NULL);
855         g_return_if_fail (E_IS_DATA_CAL (cal));
856
857         priv = cal->priv;
858         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
859
860         CORBA_exception_init (&ev);
861         GNOME_Evolution_Calendar_CalListener_notifyObjectsReceived (priv->listener, status, &ev);
862
863         if (BONOBO_EX (&ev))
864                 g_message (G_STRLOC ": could not notify the listener of objects received");
865
866         CORBA_exception_free (&ev);
867 }
868
869 void
870 e_data_cal_notify_alarm_discarded (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
871 {
872         EDataCalPrivate *priv;
873         CORBA_Environment ev;
874
875         g_return_if_fail (cal != NULL);
876         g_return_if_fail (E_IS_DATA_CAL (cal));
877
878         priv = cal->priv;
879         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
880
881         CORBA_exception_init (&ev);
882         GNOME_Evolution_Calendar_CalListener_notifyAlarmDiscarded (priv->listener, status, &ev);
883
884         if (BONOBO_EX (&ev))
885                 g_message (G_STRLOC ": could not notify the listener of alarm discarded");
886
887         CORBA_exception_free (&ev);     
888 }
889
890 void
891 e_data_cal_notify_objects_sent (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *users, const char *calobj)
892 {
893         EDataCalPrivate *priv;
894         CORBA_Environment ev;
895         GNOME_Evolution_Calendar_UserList *corba_users;
896
897         g_return_if_fail (cal != NULL);
898         g_return_if_fail (E_IS_DATA_CAL (cal));
899
900         priv = cal->priv;
901         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
902
903         corba_users = GNOME_Evolution_Calendar_UserList__alloc ();
904         corba_users->_length = g_list_length (users);
905         if (users) {
906                 GList *l;
907                 int n;
908
909                 corba_users->_buffer = CORBA_sequence_GNOME_Evolution_Calendar_User_allocbuf (corba_users->_length);
910                 for (l = users, n = 0; l != NULL; l = l->next, n++)
911                         corba_users->_buffer[n] = CORBA_string_dup (l->data);
912         }
913
914         CORBA_exception_init (&ev);
915         GNOME_Evolution_Calendar_CalListener_notifyObjectsSent (priv->listener, status, corba_users,
916                                                                 calobj ? calobj : "", &ev);
917
918         if (BONOBO_EX (&ev))
919                 g_message (G_STRLOC ": could not notify the listener of objects sent");
920
921         CORBA_exception_free (&ev);
922         CORBA_free (corba_users);
923 }
924
925 void
926 e_data_cal_notify_default_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
927 {
928         EDataCalPrivate *priv;
929         CORBA_Environment ev;
930         
931         g_return_if_fail (cal != NULL);
932         g_return_if_fail (E_IS_DATA_CAL (cal));
933
934         priv = cal->priv;
935         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
936
937         CORBA_exception_init (&ev);
938
939         GNOME_Evolution_Calendar_CalListener_notifyDefaultObjectRequested (priv->listener, status, 
940                                                                            object ? object : "", &ev);
941
942         if (BONOBO_EX (&ev))
943                 g_message (G_STRLOC ": could not notify the listener of default object");
944
945         CORBA_exception_free (&ev);
946 }
947
948 void
949 e_data_cal_notify_object (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
950 {
951         EDataCalPrivate *priv;
952         CORBA_Environment ev;
953         
954         g_return_if_fail (cal != NULL);
955         g_return_if_fail (E_IS_DATA_CAL (cal));
956
957         priv = cal->priv;
958         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
959
960         CORBA_exception_init (&ev);
961
962         GNOME_Evolution_Calendar_CalListener_notifyObjectRequested (priv->listener, status,
963                                                                     object ? object : "", &ev);
964
965         if (BONOBO_EX (&ev))
966                 g_message (G_STRLOC ": could not notify the listener of object");
967
968         CORBA_exception_free (&ev);
969 }
970
971 void
972 e_data_cal_notify_object_list (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *objects)
973 {
974         EDataCalPrivate *priv;
975         CORBA_Environment ev;
976         GNOME_Evolution_Calendar_stringlist seq;
977         GList *l;
978         int i;
979         
980         g_return_if_fail (cal != NULL);
981         g_return_if_fail (E_IS_DATA_CAL (cal));
982
983         priv = cal->priv;
984         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
985
986         CORBA_exception_init (&ev);
987
988         seq._maximum = g_list_length (objects);
989         seq._length = 0;
990         seq._buffer = GNOME_Evolution_Calendar_stringlist_allocbuf (seq._maximum);
991
992         for (l = objects, i = 0; l; l = l->next, i++) {
993                 seq._buffer[i] = CORBA_string_dup (l->data);
994                 seq._length++;
995         }
996
997         GNOME_Evolution_Calendar_CalListener_notifyObjectListRequested (priv->listener, status, &seq, &ev);
998
999         if (BONOBO_EX (&ev))
1000                 g_message (G_STRLOC ": could not notify the listener of object list");
1001
1002         CORBA_exception_free (&ev);     
1003
1004         CORBA_free(seq._buffer);
1005 }
1006
1007 void
1008 e_data_cal_notify_query (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, EDataCalView *query)
1009 {
1010         EDataCalPrivate *priv;
1011         CORBA_Environment ev;
1012
1013         g_return_if_fail (cal != NULL);
1014         g_return_if_fail (E_IS_DATA_CAL (cal));
1015
1016         priv = cal->priv;
1017         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1018
1019         CORBA_exception_init (&ev);
1020         GNOME_Evolution_Calendar_CalListener_notifyQuery (priv->listener, status, BONOBO_OBJREF (query), &ev);
1021
1022         if (BONOBO_EX (&ev))
1023                 g_message (G_STRLOC ": could not notify the listener of query");
1024
1025         CORBA_exception_free (&ev);     
1026 }
1027
1028 void
1029 e_data_cal_notify_timezone_requested (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *object)
1030 {
1031         EDataCalPrivate *priv;
1032         CORBA_Environment ev;
1033
1034         g_return_if_fail (E_IS_DATA_CAL (cal));
1035
1036         priv = cal->priv;
1037         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1038
1039         CORBA_exception_init (&ev);
1040         GNOME_Evolution_Calendar_CalListener_notifyTimezoneRequested (priv->listener, status, object ? object : "", &ev);
1041
1042         if (BONOBO_EX (&ev))
1043                 g_warning (G_STRLOC ": could not notify the listener of timezone requested");
1044
1045         CORBA_exception_free (&ev);
1046 }
1047
1048 void
1049 e_data_cal_notify_timezone_added (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, const char *tzid)
1050 {
1051         EDataCalPrivate *priv;
1052         CORBA_Environment ev;
1053
1054         g_return_if_fail (E_IS_DATA_CAL (cal));
1055
1056         priv = cal->priv;
1057         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1058
1059         CORBA_exception_init (&ev);
1060         GNOME_Evolution_Calendar_CalListener_notifyTimezoneAdded (priv->listener, status, tzid ? tzid : "", &ev);
1061
1062         if (BONOBO_EX (&ev))
1063                 g_warning (G_STRLOC ": could not notify the listener of timezone added");
1064
1065         CORBA_exception_free (&ev);
1066 }
1067
1068 void
1069 e_data_cal_notify_default_timezone_set (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status)
1070 {
1071         EDataCalPrivate *priv;
1072         CORBA_Environment ev;
1073
1074         g_return_if_fail (E_IS_DATA_CAL (cal));
1075
1076         priv = cal->priv;
1077         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1078
1079         CORBA_exception_init (&ev);
1080         GNOME_Evolution_Calendar_CalListener_notifyDefaultTimezoneSet (priv->listener, status, &ev);
1081
1082         if (BONOBO_EX (&ev))
1083                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1084
1085         CORBA_exception_free (&ev);
1086 }
1087
1088 void
1089 e_data_cal_notify_changes (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, 
1090                            GList *adds, GList *modifies, GList *deletes)
1091 {
1092         EDataCalPrivate *priv;
1093         CORBA_Environment ev;
1094         GNOME_Evolution_Calendar_CalObjChangeSeq seq;
1095         GList *l;       
1096         int n, i;
1097
1098         g_return_if_fail (E_IS_DATA_CAL (cal));
1099
1100         priv = cal->priv;
1101         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1102
1103         n = g_list_length (adds) + g_list_length (modifies) + g_list_length (deletes);
1104         seq._maximum = n;
1105         seq._length = n;
1106         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObjChange_allocbuf (n);
1107
1108         i = 0;
1109         for (l = adds; l; i++, l = l->next) {
1110                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1111                 
1112                 change->calobj = CORBA_string_dup (l->data);
1113                 change->type = GNOME_Evolution_Calendar_ADDED;
1114         }
1115
1116         for (l = modifies; l; i++, l = l->next) {
1117                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1118
1119                 change->calobj = CORBA_string_dup (l->data);
1120                 change->type = GNOME_Evolution_Calendar_MODIFIED;
1121         }
1122
1123         for (l = deletes; l; i++, l = l->next) {
1124                 GNOME_Evolution_Calendar_CalObjChange *change = &seq._buffer[i];
1125
1126                 change->calobj = CORBA_string_dup (l->data);
1127                 change->type = GNOME_Evolution_Calendar_DELETED;
1128         }
1129         
1130         CORBA_exception_init (&ev);
1131         GNOME_Evolution_Calendar_CalListener_notifyChanges (priv->listener, status, &seq, &ev);
1132
1133         CORBA_free (seq._buffer);
1134
1135         if (BONOBO_EX (&ev))
1136                 g_warning (G_STRLOC ": could not notify the listener of default timezone set");
1137
1138         CORBA_exception_free (&ev);
1139 }
1140
1141 void
1142 e_data_cal_notify_free_busy (EDataCal *cal, GNOME_Evolution_Calendar_CallStatus status, GList *freebusy)
1143 {
1144         EDataCalPrivate *priv;
1145         CORBA_Environment ev;
1146         GNOME_Evolution_Calendar_CalObjSeq seq;
1147         GList *l;
1148         int n, i;
1149         
1150         g_return_if_fail (E_IS_DATA_CAL (cal));
1151
1152         priv = cal->priv;
1153         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1154
1155         n = g_list_length (freebusy);
1156         seq._maximum = n;
1157         seq._length = n;
1158         seq._buffer = CORBA_sequence_GNOME_Evolution_Calendar_CalObj_allocbuf (n);
1159
1160         for (i = 0, l = freebusy; l; i++, l = l->next)
1161                 seq._buffer[i] = CORBA_string_dup (l->data);
1162         
1163         CORBA_exception_init (&ev);
1164         GNOME_Evolution_Calendar_CalListener_notifyFreeBusy (priv->listener, status, &seq, &ev);
1165
1166         CORBA_free (seq._buffer);
1167
1168         if (BONOBO_EX (&ev))
1169                 g_warning (G_STRLOC ": could not notify the listener of freebusy");
1170
1171         CORBA_exception_free (&ev);
1172 }
1173
1174 /**
1175  * e_data_cal_notify_mode:
1176  * @cal: A calendar client interface.
1177  * @status: Status of the mode set.
1178  * @mode: The current mode.
1179  * 
1180  * Notifys the listener of the results of a setMode call.
1181  **/
1182 void
1183 e_data_cal_notify_mode (EDataCal *cal,
1184                         GNOME_Evolution_Calendar_CalListener_SetModeStatus status,
1185                         GNOME_Evolution_Calendar_CalMode mode)
1186 {
1187         EDataCalPrivate *priv;
1188         CORBA_Environment ev;
1189
1190         g_return_if_fail (cal != NULL);
1191         g_return_if_fail (E_IS_DATA_CAL (cal));
1192
1193         priv = cal->priv;
1194         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1195
1196         CORBA_exception_init (&ev);
1197         GNOME_Evolution_Calendar_CalListener_notifyCalSetMode (priv->listener, status, mode, &ev);
1198
1199         if (BONOBO_EX (&ev))
1200                 g_message ("e_data_cal_notify_mode(): could not notify the listener "
1201                            "about a mode change");
1202
1203         CORBA_exception_free (&ev);     
1204 }
1205
1206 /**
1207  * e_data_cal_notify_error
1208  * @cal: A calendar client interface.
1209  * @message: Error message.
1210  *
1211  * Notify a calendar client of an error occurred in the backend.
1212  */
1213 void
1214 e_data_cal_notify_error (EDataCal *cal, const char *message)
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         g_return_if_fail (message != NULL);
1222
1223         priv = cal->priv;
1224         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1225
1226         CORBA_exception_init (&ev);
1227         GNOME_Evolution_Calendar_CalListener_notifyErrorOccurred (priv->listener, (char *) message, &ev);
1228
1229         if (BONOBO_EX (&ev))
1230                 g_message ("e_data_cal_notify_remove(): could not notify the listener "
1231                            "about a removed object");
1232
1233         CORBA_exception_free (&ev);
1234 }
1235
1236 /**
1237  * e_data_cal_notify_categories_changed:
1238  * @cal: A calendar client interface.
1239  * @categories: List of categories.
1240  * 
1241  * Notifies a listener attached to a calendar client interface object about the
1242  * current set of categories in a calendar backend.
1243  **/
1244 void
1245 e_data_cal_notify_categories_changed (EDataCal *cal, GNOME_Evolution_Calendar_StringSeq *categories)
1246 {
1247         EDataCalPrivate *priv;
1248         CORBA_Environment ev;
1249
1250         g_return_if_fail (cal != NULL);
1251         g_return_if_fail (E_IS_DATA_CAL (cal));
1252         g_return_if_fail (categories != NULL);
1253
1254         priv = cal->priv;
1255         g_return_if_fail (priv->listener != CORBA_OBJECT_NIL);
1256
1257         CORBA_exception_init (&ev);
1258         GNOME_Evolution_Calendar_CalListener_notifyCategoriesChanged (priv->listener, categories, &ev);
1259
1260         if (BONOBO_EX (&ev))
1261                 g_message ("e_data_cal_notify_categories_changed(): Could not notify the listener "
1262                            "about the current set of categories");
1263
1264         CORBA_exception_free (&ev);
1265 }