Bug #614480 - Avoid using G_TYPE_INSTANCE_GET_PRIVATE repeatedly
[platform/upstream/evolution-data-server.git] / calendar / libedata-cal / e-data-cal.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* Evolution calendar client interface object
3  *
4  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5  * Copyright (C) 2009 Intel Corporation
6  *
7  * Authors: Federico Mena-Quintero <federico@ximian.com>
8  *          Rodrigo Moya <rodrigo@ximian.com>
9  *          Ross Burton <ross@linux.intel.com>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of version 2 of the GNU Lesser General Public
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <libical/ical.h>
30 #include <glib/gi18n-lib.h>
31 #include <unistd.h>
32
33 #include <glib-object.h>
34 #include <libedataserver/e-debug-log.h>
35 #include <libedataserver/e-data-server-util.h>
36 #include "e-data-cal.h"
37 #include "e-data-cal-enumtypes.h"
38 #include "e-gdbus-egdbuscal.h"
39
40 G_DEFINE_TYPE (EDataCal, e_data_cal, G_TYPE_OBJECT);
41
42 #define EDC_ERROR(_code) e_data_cal_create_error (_code, NULL)
43 #define EDC_ERROR_EX(_code, _msg) e_data_cal_create_error (_code, _msg)
44
45 struct _EDataCalPrivate {
46         EGdbusCal *gdbus_object;
47         ECalBackend *backend;
48         ESource *source;
49         GHashTable *live_queries;
50 };
51
52 /* Create the EDataCal error quark */
53 GQuark
54 e_data_cal_error_quark (void)
55 {
56         #define ERR_PREFIX "org.gnome.evolution.dataserver.Calendar."
57
58         static const GDBusErrorEntry entries[] = {
59                 { Success,                              ERR_PREFIX "Success" },
60                 { RepositoryOffline,                    ERR_PREFIX "RepositoryOffline" },
61                 { PermissionDenied,                     ERR_PREFIX "PermissionDenied" },
62                 { InvalidRange,                         ERR_PREFIX "InvalidRange" },
63                 { ObjectNotFound,                       ERR_PREFIX "ObjectNotFound" },
64                 { InvalidObject,                        ERR_PREFIX "InvalidObject" },
65                 { ObjectIdAlreadyExists,                ERR_PREFIX "ObjectIdAlreadyExists" },
66                 { AuthenticationFailed,                 ERR_PREFIX "AuthenticationFailed" },
67                 { AuthenticationRequired,               ERR_PREFIX "AuthenticationRequired" },
68                 { UnsupportedField,                     ERR_PREFIX "UnsupportedField" },
69                 { UnsupportedMethod,                    ERR_PREFIX "UnsupportedMethod" },
70                 { UnsupportedAuthenticationMethod,      ERR_PREFIX "UnsupportedAuthenticationMethod" },
71                 { TLSNotAvailable,                      ERR_PREFIX "TLSNotAvailable" },
72                 { NoSuchCal,                            ERR_PREFIX "NoSuchCal" },
73                 { UnknownUser,                          ERR_PREFIX "UnknownUser" },
74                 { OfflineUnavailable,                   ERR_PREFIX "OfflineUnavailable" },
75                 { SearchSizeLimitExceeded,              ERR_PREFIX "SearchSizeLimitExceeded" },
76                 { SearchTimeLimitExceeded,              ERR_PREFIX "SearchTimeLimitExceeded" },
77                 { InvalidQuery,                         ERR_PREFIX "InvalidQuery" },
78                 { QueryRefused,                         ERR_PREFIX "QueryRefused" },
79                 { CouldNotCancel,                       ERR_PREFIX "CouldNotCancel" },
80                 { OtherError,                           ERR_PREFIX "OtherError" },
81                 { InvalidServerVersion,                 ERR_PREFIX "InvalidServerVersion" },
82                 { InvalidArg,                           ERR_PREFIX "InvalidArg" },
83                 { NotSupported,                         ERR_PREFIX "NotSupported" }
84         };
85
86         #undef ERR_PREFIX
87
88         static volatile gsize quark_volatile = 0;
89
90         g_dbus_error_register_error_domain ("e-data-cal-error", &quark_volatile, entries, G_N_ELEMENTS (entries));
91
92         return (GQuark) quark_volatile;
93 }
94
95 /**
96  * e_data_cal_status_to_string:
97  *
98  * Since: 2.32
99  **/
100 const gchar *
101 e_data_cal_status_to_string (EDataCalCallStatus status)
102 {
103         gint i;
104         static struct _statuses {
105                 EDataCalCallStatus status;
106                 const gchar *msg;
107         } statuses[] = {
108                 { Success,                              N_("Success") },
109                 { RepositoryOffline,                    N_("Repository offline") },
110                 { PermissionDenied,                     N_("Permission denied") },
111                 { InvalidRange,                         N_("Invalid range") },
112                 { ObjectNotFound,                       N_("Object not found") },
113                 { InvalidObject,                        N_("Invalid object") },
114                 { ObjectIdAlreadyExists,                N_("Object ID already exists") },
115                 { AuthenticationFailed,                 N_("Authentication Failed") },
116                 { AuthenticationRequired,               N_("Authentication Required") },
117                 { UnsupportedField,                     N_("Unsupported field") },
118                 { UnsupportedMethod,                    N_("Unsupported method") },
119                 { UnsupportedAuthenticationMethod,      N_("Unsupported authentication method") },
120                 { TLSNotAvailable,                      N_("TLS not available") },
121                 { NoSuchCal,                            N_("Calendar does not exist") },
122                 { UnknownUser,                          N_("Unknown user") },
123                 { OfflineUnavailable,                   N_("Not available in offline mode") },
124                 { SearchSizeLimitExceeded,              N_("Search size limit exceeded") },
125                 { SearchTimeLimitExceeded,              N_("Search time limit exceeded") },
126                 { InvalidQuery,                         N_("Invalid query") },
127                 { QueryRefused,                         N_("Query refused") },
128                 { CouldNotCancel,                       N_("Could not cancel") },
129                 /* { OtherError,                        N_("Other error") }, */
130                 { InvalidServerVersion,                 N_("Invalid server version") },
131                 { InvalidArg,                           N_("Invalid argument") },
132                 /* Translators: The string for NOT_SUPPORTED error */
133                 { NotSupported,                         N_("Not supported") }
134         };
135
136         for (i = 0; i < G_N_ELEMENTS (statuses); i++) {
137                 if (statuses[i].status == status)
138                         return _(statuses[i].msg);
139         }
140
141         return _("Other error");
142 }
143
144 /**
145  * e_data_cal_create_error:
146  *
147  * Since: 2.32
148  **/
149 GError *
150 e_data_cal_create_error (EDataCalCallStatus status, const gchar *custom_msg)
151 {
152         if (status == Success)
153                 return NULL;
154
155         return g_error_new_literal (E_DATA_CAL_ERROR, status, custom_msg ? custom_msg : e_data_cal_status_to_string (status));
156 }
157
158 /**
159  * e_data_cal_create_error_fmt:
160  *
161  * Since: 2.32
162  **/
163 GError *
164 e_data_cal_create_error_fmt (EDataCalCallStatus status, const gchar *custom_msg_fmt, ...)
165 {
166         GError *error;
167         gchar *custom_msg;
168         va_list ap;
169
170         if (!custom_msg_fmt)
171                 return e_data_cal_create_error (status, NULL);
172
173         va_start (ap, custom_msg_fmt);
174         custom_msg = g_strdup_vprintf (custom_msg_fmt, ap);
175         va_end (ap);
176
177         error = e_data_cal_create_error (status, custom_msg);
178
179         g_free (custom_msg);
180
181         return error;
182 }
183
184 static void
185 data_cal_return_error (GDBusMethodInvocation *invocation, const GError *perror, const gchar *error_fmt)
186 {
187         GError *error;
188
189         g_return_if_fail (perror != NULL);
190
191         error = g_error_new (E_DATA_CAL_ERROR, perror->code, error_fmt, perror->message);
192
193         g_dbus_method_invocation_return_gerror (invocation, error);
194
195         g_error_free (error);
196 }
197
198 /**
199  * e_data_cal_get_source:
200  * @cal: an #EDataCal
201  *
202  * Returns the #ESource for @cal.
203  *
204  * Returns: the #ESource for @cal
205  *
206  * Since: 2.30
207  **/
208 ESource*
209 e_data_cal_get_source (EDataCal *cal)
210 {
211   return cal->priv->source;
212 }
213
214 ECalBackend*
215 e_data_cal_get_backend (EDataCal *cal)
216 {
217   return cal->priv->backend;
218 }
219
220 /* EDataCal::getUri method */
221 static gboolean
222 impl_Cal_getUri (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
223 {
224         e_gdbus_cal_complete_get_uri (object, invocation, e_cal_backend_get_uri (cal->priv->backend));
225
226         return TRUE;
227 }
228
229 /* EDataCal::getCacheDir method */
230 static gboolean
231 impl_Cal_getCacheDir (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
232 {
233         e_gdbus_cal_complete_get_cache_dir (object, invocation, e_cal_backend_get_cache_dir (cal->priv->backend));
234
235         return TRUE;
236 }
237
238 /* EDataCal::open method */
239 static gboolean
240 impl_Cal_open (EGdbusCal *object, GDBusMethodInvocation *invocation, gboolean only_if_exists, const gchar *username, const gchar *password, EDataCal *cal)
241 {
242         e_cal_backend_open (cal->priv->backend, cal, invocation, only_if_exists, username, password);
243
244         return TRUE;
245 }
246
247 /* EDataCal::refresh method */
248 static gboolean
249 impl_Cal_refresh (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
250 {
251         e_cal_backend_refresh (cal->priv->backend, cal, invocation);
252
253         return TRUE;
254 }
255
256 /* EDataCal::close method */
257 static gboolean
258 impl_Cal_close (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
259 {
260         e_cal_backend_remove_client (cal->priv->backend, cal);
261         e_gdbus_cal_complete_close (object, invocation);
262
263         g_object_unref (cal);
264
265         return TRUE;
266 }
267
268 /* EDataCal::remove method */
269 static gboolean
270 impl_Cal_remove (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
271 {
272         e_cal_backend_remove (cal->priv->backend, cal, invocation);
273
274         return TRUE;
275 }
276
277 /* EDataCal::isReadOnly method */
278 static gboolean
279 impl_Cal_isReadOnly (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
280 {
281         e_cal_backend_is_read_only (cal->priv->backend, cal);
282         e_gdbus_cal_complete_is_read_only (object, invocation);
283
284         return TRUE;
285 }
286
287 /* EDataCal::getCalAddress method */
288 static gboolean
289 impl_Cal_getCalAddress (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
290 {
291         e_cal_backend_get_cal_address (cal->priv->backend, cal, invocation);
292
293         return TRUE;
294 }
295
296 /* EDataCal::getAlarmEmailAddress method */
297 static gboolean
298 impl_Cal_getAlarmEmailAddress (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
299 {
300         e_cal_backend_get_alarm_email_address (cal->priv->backend, cal, invocation);
301
302         return TRUE;
303 }
304
305 /* EDataCal::getLdapAttribute method */
306 static gboolean
307 impl_Cal_getLdapAttribute (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
308 {
309         e_cal_backend_get_ldap_attribute (cal->priv->backend, cal, invocation);
310
311         return TRUE;
312 }
313
314 /* EDataCal::getSchedulingInformation method */
315 static gboolean
316 impl_Cal_getSchedulingInformation (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
317 {
318         e_cal_backend_get_static_capabilities (cal->priv->backend, cal, invocation);
319
320         return TRUE;
321 }
322
323 /* EDataCal::setMode method */
324 static gboolean
325 impl_Cal_setMode (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCalMode mode, EDataCal *cal)
326 {
327         e_cal_backend_set_mode (cal->priv->backend, mode);
328         e_gdbus_cal_complete_set_mode (object, invocation);
329
330         return TRUE;
331 }
332
333 /* EDataCal::getDefaultObject method */
334 static gboolean
335 impl_Cal_getDefaultObject (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
336 {
337         e_cal_backend_get_default_object (cal->priv->backend, cal, invocation);
338
339         return TRUE;
340 }
341
342 /* EDataCal::getObject method */
343 static gboolean
344 impl_Cal_getObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCal *cal)
345 {
346         e_cal_backend_get_object (cal->priv->backend, cal, invocation, uid, rid);
347
348         return TRUE;
349 }
350
351 /* EDataCal::getObjectList method */
352 static gboolean
353 impl_Cal_getObjectList (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *sexp, EDataCal *cal)
354 {
355         e_cal_backend_get_object_list (cal->priv->backend, cal, invocation, sexp);
356
357         return TRUE;
358 }
359
360 /* EDataCal::getChanges method */
361 static gboolean
362 impl_Cal_getChanges (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *change_id, EDataCal *cal)
363 {
364         e_cal_backend_get_changes (cal->priv->backend, cal, invocation, change_id);
365
366         return TRUE;
367 }
368
369 /* EDataCal::getFreeBusy method */
370 static gboolean
371 impl_Cal_getFreeBusy (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar **user_list, guint start, guint end, EDataCal *cal)
372 {
373         GList *users = NULL;
374
375         if (user_list) {
376                 gint i;
377
378                 for (i = 0; user_list[i]; i++)
379                         users = g_list_append (users, (gpointer)user_list[i]);
380         }
381
382         /* call the backend's get_free_busy method */
383         e_cal_backend_get_free_busy (cal->priv->backend, cal, invocation, users, (time_t)start, (time_t)end);
384
385         return TRUE;
386 }
387
388 /* EDataCal::discardAlarm method */
389 static gboolean
390 impl_Cal_discardAlarm (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *auid, EDataCal *cal)
391 {
392         e_cal_backend_discard_alarm (cal->priv->backend, cal, invocation, uid, auid);
393
394         return TRUE;
395 }
396
397 /* EDataCal::createObject method */
398 static gboolean
399 impl_Cal_createObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
400 {
401         e_cal_backend_create_object (cal->priv->backend, cal, invocation, calobj);
402
403         return TRUE;
404 }
405
406 /* EDataCal::modifyObject method */
407 static gboolean
408 impl_Cal_modifyObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCalObjModType mod, EDataCal *cal)
409 {
410         e_cal_backend_modify_object (cal->priv->backend, cal, invocation, calobj, mod);
411
412         return TRUE;
413 }
414
415 /* EDataCal::removeObject method */
416 static gboolean
417 impl_Cal_removeObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCalObjModType mod, EDataCal *cal)
418 {
419         if (rid[0] == '\0')
420                 rid = NULL;
421
422         e_cal_backend_remove_object (cal->priv->backend, cal, invocation, uid, rid, mod);
423
424         return TRUE;
425 }
426
427 /* EDataCal::receiveObjects method */
428 static gboolean
429 impl_Cal_receiveObjects (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
430 {
431         e_cal_backend_receive_objects (cal->priv->backend, cal, invocation, calobj);
432
433         return TRUE;
434 }
435
436 /* EDataCal::sendObjects method */
437 static gboolean
438 impl_Cal_sendObjects (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
439 {
440         e_cal_backend_send_objects (cal->priv->backend, cal, invocation, calobj);
441
442         return TRUE;
443 }
444
445 /* EDataCal::getAttachmentList method */
446 static gboolean
447 impl_Cal_getAttachmentList (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCal *cal)
448 {
449         e_cal_backend_get_attachment_list (cal->priv->backend, cal, invocation, uid, rid);
450
451         return TRUE;
452 }
453
454 /* Function to get a new EDataCalView path, used by getQuery below */
455 static gchar *
456 construct_calview_path (void)
457 {
458         static guint counter = 1;
459         return g_strdup_printf ("/org/gnome/evolution/dataserver/CalendarView/%d/%d", getpid(), counter++);
460 }
461
462 /* EDataCal::getQuery method */
463 static gboolean
464 impl_Cal_getQuery (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *sexp, EDataCal *cal)
465 {
466         EDataCalView *query;
467         ECalBackendSExp *obj_sexp;
468         gchar *path;
469         GError *error = NULL;
470
471         /* we handle this entirely here, since it doesn't require any
472            backend involvement now that we have e_cal_view_start to
473            actually kick off the search. */
474
475         obj_sexp = e_cal_backend_sexp_new (sexp);
476         if (!obj_sexp) {
477                 e_data_cal_notify_query (cal, invocation, EDC_ERROR (InvalidQuery), NULL);
478                 return TRUE;
479         }
480
481         query = e_data_cal_view_new (cal->priv->backend, obj_sexp);
482         e_debug_log (FALSE, E_DEBUG_LOG_DOMAIN_CAL_QUERIES, "%p;%p;NEW;%s;%s", cal, query, sexp, G_OBJECT_TYPE_NAME (cal->priv->backend));
483         if (!query) {
484                 g_object_unref (obj_sexp);
485                 e_data_cal_notify_query (cal, invocation, EDC_ERROR (OtherError), NULL);
486                 return TRUE;
487         }
488
489         /* log query to evaluate cache performance */
490         e_debug_log (FALSE, E_DEBUG_LOG_DOMAIN_CAL_QUERIES, "%p;%p;REUSED;%s;%s", cal, query, sexp, G_OBJECT_TYPE_NAME (cal->priv->backend));
491
492         path = construct_calview_path ();
493         e_data_cal_view_register_gdbus_object (query, g_dbus_method_invocation_get_connection (invocation), path, &error);
494
495         if (error) {
496                 g_object_unref (query);
497                 e_data_cal_notify_query (cal, invocation, EDC_ERROR_EX (OtherError, error->message), NULL);
498                 g_error_free (error);
499                 g_free (path);
500
501                 return TRUE;
502         }
503
504         e_cal_backend_add_query (cal->priv->backend, query);
505
506         e_data_cal_notify_query (cal, invocation, EDC_ERROR (Success), path);
507
508         g_free (path);
509
510         return TRUE;
511 }
512
513 /* EDataCal::getTimezone method */
514 static gboolean
515 impl_Cal_getTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tzid, EDataCal *cal)
516 {
517         e_cal_backend_get_timezone (cal->priv->backend, cal, invocation, tzid);
518
519         return TRUE;
520 }
521
522 /* EDataCal::addTimezone method */
523 static gboolean
524 impl_Cal_addTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tz, EDataCal *cal)
525 {
526         e_cal_backend_add_timezone (cal->priv->backend, cal, invocation, tz);
527
528         return TRUE;
529 }
530
531 /* EDataCal::setDefaultTimezone method */
532 static gboolean
533 impl_Cal_setDefaultTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tz, EDataCal *cal)
534 {
535         e_cal_backend_set_default_zone (cal->priv->backend, cal, invocation, tz);
536
537         return TRUE;
538 }
539
540 /* free returned pointer with g_strfreev() */
541 static gchar **
542 create_str_array_from_glist (GList *lst)
543 {
544         gchar **seq;
545         GList *l;
546         gint i;
547
548         seq = g_new0 (gchar *, g_list_length (lst) + 1);
549         for (l = lst, i = 0; l; l = l->next, i++) {
550                 seq[i] = e_util_utf8_make_valid (l->data);
551         }
552
553         return seq;
554 }
555
556 /* free returned pointer with g_strfreev() */
557 static gchar **
558 create_str_array_from_gslist (GSList *lst)
559 {
560         gchar **seq;
561         GSList *l;
562         gint i;
563
564         seq = g_new0 (gchar *, g_slist_length (lst) + 1);
565         for (l = lst, i = 0; l; l = l->next, i++) {
566                 seq[i] = e_util_utf8_make_valid (l->data);
567         }
568
569         return seq;
570 }
571
572 /**
573  * e_data_cal_notify_read_only:
574  * @cal: A calendar client interface.
575  * @error: Operation error, if any, automatically freed if passed it.
576  * @read_only: Read only value.
577  *
578  * Notifies listeners of the completion of the is_read_only method call.
579  */
580 void
581 e_data_cal_notify_read_only (EDataCal *cal, GError *error, gboolean read_only)
582 {
583         g_return_if_fail (cal != NULL);
584         g_return_if_fail (E_IS_DATA_CAL (cal));
585
586         if (error) {
587                 e_data_cal_notify_error (cal, error->message);
588                 g_error_free (error);
589         } else {
590                 e_gdbus_cal_emit_readonly (cal->priv->gdbus_object, read_only);
591         }
592 }
593
594 /**
595  * e_data_cal_notify_cal_address:
596  * @cal: A calendar client interface.
597  * @error: Operation error, if any, automatically freed if passed it.
598  * @address: Calendar address.
599  *
600  * Notifies listeners of the completion of the get_cal_address method call.
601  */
602 void
603 e_data_cal_notify_cal_address (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *address)
604 {
605         GDBusMethodInvocation *invocation = context;
606         if (error) {
607                 /* Translators: The '%s' is replaced with a detailed error message */
608                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar address: %s"));
609                 g_error_free (error);
610         } else {
611                 gchar *gdbus_address = NULL;
612
613                 e_gdbus_cal_complete_get_cal_address (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (address, &gdbus_address));
614
615                 g_free (gdbus_address);
616         }
617 }
618
619 /**
620  * e_data_cal_notify_alarm_email_address:
621  * @cal: A calendar client interface.
622  * @error: Operation error, if any, automatically freed if passed it.
623  * @address: Alarm email address.
624  *
625  * Notifies listeners of the completion of the get_alarm_email_address method call.
626  */
627 void
628 e_data_cal_notify_alarm_email_address (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *address)
629 {
630         GDBusMethodInvocation *invocation = context;
631         if (error) {
632                 /* Translators: The '%s' is replaced with a detailed error message */
633                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar alarm e-mail address: %s"));
634                 g_error_free (error);
635         } else {
636                 gchar *gdbus_address = NULL;
637
638                 e_gdbus_cal_complete_get_alarm_email_address (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (address, &gdbus_address));
639
640                 g_free (gdbus_address);
641         }
642 }
643
644 /**
645  * e_data_cal_notify_ldap_attribute:
646  * @cal: A calendar client interface.
647  * @error: Operation error, if any, automatically freed if passed it.
648  * @attibute: LDAP attribute.
649  *
650  * Notifies listeners of the completion of the get_ldap_attribute method call.
651  */
652 void
653 e_data_cal_notify_ldap_attribute (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *attribute)
654 {
655         GDBusMethodInvocation *invocation = context;
656         if (error) {
657                 /* Translators: The '%s' is replaced with a detailed error message */
658                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar's LDAP attribute: %s"));
659                 g_error_free (error);
660         } else {
661                 gchar *gdbus_attribute = NULL;
662
663                 e_gdbus_cal_complete_get_ldap_attribute (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (attribute, &gdbus_attribute));
664
665                 g_free (gdbus_attribute);
666         }
667 }
668
669 /**
670  * e_data_cal_notify_static_capabilities:
671  * @cal: A calendar client interface.
672  * @error: Operation error, if any, automatically freed if passed it.
673  * @capabilities: Static capabilities from the backend.
674  *
675  * Notifies listeners of the completion of the get_static_capabilities method call.
676  */
677 void
678 e_data_cal_notify_static_capabilities (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *capabilities)
679 {
680         GDBusMethodInvocation *invocation = context;
681         if (error) {
682                 /* Translators: The '%s' is replaced with a detailed error message */
683                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar scheduling information: %s"));
684                 g_error_free (error);
685         } else {
686                 gchar *gdbus_capabilities = NULL;
687
688                 e_gdbus_cal_complete_get_scheduling_information (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (capabilities, &gdbus_capabilities));
689
690                 g_free (gdbus_capabilities);
691         }
692 }
693
694 /**
695  * e_data_cal_notify_open:
696  * @cal: A calendar client interface.
697  * @error: Operation error, if any, automatically freed if passed it.
698  *
699  * Notifies listeners of the completion of the open method call.
700  */
701 void
702 e_data_cal_notify_open (EDataCal *cal, EServerMethodContext context, GError *error)
703 {
704         GDBusMethodInvocation *invocation = context;
705         if (error) {
706                 /* Translators: The '%s' is replaced with a detailed error message */
707                 data_cal_return_error (invocation, error, _("Cannot open calendar: %s"));
708                 g_error_free (error);
709         } else
710                 e_gdbus_cal_complete_open (cal->priv->gdbus_object, invocation);
711 }
712
713 /**
714  * e_data_cal_notify_refresh:
715  * @cal: A calendar client interface.
716  * @error: Operation error, if any, automatically freed if passed it.
717  *
718  * Notifies listeners of the completion of the refresh method call.
719  *
720  * Since: 2.30
721  */
722 void
723 e_data_cal_notify_refresh (EDataCal *cal, EServerMethodContext context, GError *error)
724 {
725         GDBusMethodInvocation *invocation = context;
726         if (error) {
727                 /* Translators: The '%s' is replaced with a detailed error message */
728                 data_cal_return_error (invocation, error, _("Cannot refresh calendar: %s"));
729                 g_error_free (error);
730         } else
731                 e_gdbus_cal_complete_refresh (cal->priv->gdbus_object, invocation);
732 }
733
734 /**
735  * e_data_cal_notify_remove:
736  * @cal: A calendar client interface.
737  * @error: Operation error, if any, automatically freed if passed it.
738  *
739  * Notifies listeners of the completion of the remove method call.
740  */
741 void
742 e_data_cal_notify_remove (EDataCal *cal, EServerMethodContext context, GError *error)
743 {
744         GDBusMethodInvocation *invocation = context;
745         if (error) {
746                 /* Translators: The '%s' is replaced with a detailed error message */
747                 data_cal_return_error (invocation, error, _("Cannot remove calendar: %s"));
748                 g_error_free (error);
749         } else
750                 e_gdbus_cal_complete_remove (cal->priv->gdbus_object, invocation);
751 }
752
753 /**
754  * e_data_cal_notify_object_created:
755  * @cal: A calendar client interface.
756  * @error: Operation error, if any, automatically freed if passed it.
757  * @uid: UID of the object created.
758  * @object: The object created as an iCalendar string.
759  *
760  * Notifies listeners of the completion of the create_object method call.
761  */void
762 e_data_cal_notify_object_created (EDataCal *cal, EServerMethodContext context, GError *error,
763                                   const gchar *uid, const gchar *object)
764 {
765         GDBusMethodInvocation *invocation = context;
766         if (error) {
767                 /* Translators: The '%s' is replaced with a detailed error message */
768                 data_cal_return_error (invocation, error, _("Cannot create calendar object: %s"));
769                 g_error_free (error);
770         } else {
771                 gchar *gdbus_uid = NULL;
772
773                 e_cal_backend_notify_object_created (cal->priv->backend, object);
774                 e_gdbus_cal_complete_create_object (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (uid, &gdbus_uid));
775
776                 g_free (gdbus_uid);
777         }
778 }
779
780 /**
781  * e_data_cal_notify_object_modified:
782  * @cal: A calendar client interface.
783  * @error: Operation error, if any, automatically freed if passed it.
784  * @old_object: The old object as an iCalendar string.
785  * @object: The modified object as an iCalendar string.
786  *
787  * Notifies listeners of the completion of the modify_object method call.
788  */
789 void
790 e_data_cal_notify_object_modified (EDataCal *cal, EServerMethodContext context, GError *error,
791                                    const gchar *old_object, const gchar *object)
792 {
793         GDBusMethodInvocation *invocation = context;
794         if (error) {
795                 /* Translators: The '%s' is replaced with a detailed error message */
796                 data_cal_return_error (invocation, error, _("Cannot modify calendar object: %s"));
797                 g_error_free (error);
798         } else {
799                 e_cal_backend_notify_object_modified (cal->priv->backend, old_object, object);
800                 e_gdbus_cal_complete_modify_object (cal->priv->gdbus_object, invocation);
801         }
802 }
803
804 /**
805  * e_data_cal_notify_object_removed:
806  * @cal: A calendar client interface.
807  * @error: Operation error, if any, automatically freed if passed it.
808  * @uid: UID of the removed object.
809  * @old_object: The old object as an iCalendar string.
810  * @object: The new object as an iCalendar string. This will not be NULL only
811  * when removing instances of a recurring appointment.
812  *
813  * Notifies listeners of the completion of the remove_object method call.
814  */
815 void
816 e_data_cal_notify_object_removed (EDataCal *cal, EServerMethodContext context, GError *error,
817                                   const ECalComponentId *id, const gchar *old_object, const gchar *object)
818 {
819         GDBusMethodInvocation *invocation = context;
820         if (error) {
821                 /* Translators: The '%s' is replaced with a detailed error message */
822                 data_cal_return_error (invocation, error, _("Cannot remove calendar object: %s"));
823                 g_error_free (error);
824         } else {
825                 e_cal_backend_notify_object_removed (cal->priv->backend, id, old_object, object);
826                 e_gdbus_cal_complete_remove_object (cal->priv->gdbus_object, invocation);
827         }
828 }
829
830 /**
831  * e_data_cal_notify_objects_received:
832  * @cal: A calendar client interface.
833  * @error: Operation error, if any, automatically freed if passed it.
834  *
835  * Notifies listeners of the completion of the receive_objects method call.
836  */
837 void
838 e_data_cal_notify_objects_received (EDataCal *cal, EServerMethodContext context, GError *error)
839 {
840         GDBusMethodInvocation *invocation = context;
841         if (error) {
842                 /* Translators: The '%s' is replaced with a detailed error message */
843                 data_cal_return_error (invocation, error, _("Cannot receive calendar objects: %s"));
844                 g_error_free (error);
845         } else
846                 e_gdbus_cal_complete_receive_objects (cal->priv->gdbus_object, invocation);
847 }
848
849 /**
850  * e_data_cal_notify_alarm_discarded:
851  * @cal: A calendar client interface.
852  * @error: Operation error, if any, automatically freed if passed it.
853  *
854  * Notifies listeners of the completion of the discard_alarm method call.
855  */
856 void
857 e_data_cal_notify_alarm_discarded (EDataCal *cal, EServerMethodContext context, GError *error)
858 {
859         GDBusMethodInvocation *invocation = context;
860         if (error) {
861                 /* Translators: The '%s' is replaced with a detailed error message */
862                 data_cal_return_error (invocation, error, _("Cannot discard calendar alarm: %s"));
863                 g_error_free (error);
864         } else
865                 e_gdbus_cal_complete_discard_alarm (cal->priv->gdbus_object, invocation);
866 }
867
868 /**
869  * e_data_cal_notify_objects_sent:
870  * @cal: A calendar client interface.
871  * @error: Operation error, if any, automatically freed if passed it.
872  * @users: List of users.
873  * @calobj: An iCalendar string representing the object sent.
874  *
875  * Notifies listeners of the completion of the send_objects method call.
876  */
877 void
878 e_data_cal_notify_objects_sent (EDataCal *cal, EServerMethodContext context, GError *error, GList *users, const gchar *calobj)
879 {
880         GDBusMethodInvocation *invocation = context;
881         if (error) {
882                 /* Translators: The '%s' is replaced with a detailed error message */
883                 data_cal_return_error (invocation, error, _("Cannot send calendar objects: %s"));
884                 g_error_free (error);
885         } else {
886                 gchar **users_array = create_str_array_from_glist (users);
887                 gchar *gdbus_calobj = NULL;
888
889                 e_gdbus_cal_complete_send_objects (cal->priv->gdbus_object, invocation, (const gchar * const *) users_array, e_util_ensure_gdbus_string (calobj, &gdbus_calobj));
890
891                 g_free (gdbus_calobj);
892                 g_strfreev (users_array);
893         }
894 }
895
896 /**
897  * e_data_cal_notify_default_object:
898  * @cal: A calendar client interface.
899  * @error: Operation error, if any, automatically freed if passed it.
900  * @object: The default object as an iCalendar string.
901  *
902  * Notifies listeners of the completion of the get_default_object method call.
903  */
904 void
905 e_data_cal_notify_default_object (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
906 {
907         GDBusMethodInvocation *invocation = context;
908         if (error) {
909                 /* Translators: The '%s' is replaced with a detailed error message */
910                 data_cal_return_error (invocation, error, _("Cannot retrieve default calendar object path: %s"));
911                 g_error_free (error);
912         } else {
913                 gchar *gdbus_object = NULL;
914
915                 e_gdbus_cal_complete_get_default_object (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
916
917                 g_free (gdbus_object);
918         }
919 }
920
921 /**
922  * e_data_cal_notify_object:
923  * @cal: A calendar client interface.
924  * @error: Operation error, if any, automatically freed if passed it.
925  * @object: The object retrieved as an iCalendar string.
926  *
927  * Notifies listeners of the completion of the get_object method call.
928  */
929 void
930 e_data_cal_notify_object (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
931 {
932         GDBusMethodInvocation *invocation = context;
933         if (error) {
934                 /* Translators: The '%s' is replaced with a detailed error message */
935                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar object path: %s"));
936                 g_error_free (error);
937         } else {
938                 gchar *gdbus_object = NULL;
939
940                 e_gdbus_cal_complete_get_object (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
941
942                 g_free (gdbus_object);
943         }
944 }
945
946 /**
947  * e_data_cal_notify_object_list:
948  * @cal: A calendar client interface.
949  * @error: Operation error, if any, automatically freed if passed it.
950  * @objects: List of retrieved objects.
951  *
952  * Notifies listeners of the completion of the get_object_list method call.
953  */
954 void
955 e_data_cal_notify_object_list (EDataCal *cal, EServerMethodContext context, GError *error, GList *objects)
956 {
957         GDBusMethodInvocation *invocation = context;
958         if (error) {
959                 /* Translators: The '%s' is replaced with a detailed error message */
960                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar object list: %s"));
961                 g_error_free (error);
962         } else {
963                 gchar **seq = create_str_array_from_glist (objects);
964
965                 e_gdbus_cal_complete_get_object_list (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
966
967                 g_strfreev (seq);
968         }
969 }
970
971 /**
972  * e_data_cal_notify_attachment_list:
973  * @cal: A calendar client interface.
974  * @error: Operation error, if any, automatically freed if passed it.
975  * @attachments: List of retrieved attachment uri's.
976  *
977  * Notifies listeners of the completion of the get_attachment_list method call.+ */
978 void
979 e_data_cal_notify_attachment_list (EDataCal *cal, EServerMethodContext context, GError *error, GSList *attachments)
980 {
981         GDBusMethodInvocation *invocation = context;
982         gchar **seq;
983
984         seq = create_str_array_from_gslist (attachments);
985
986         if (error) {
987                 /* Translators: The '%s' is replaced with a detailed error message */
988                 data_cal_return_error (invocation, error, _("Could not retrieve attachment list: %s"));
989                 g_error_free (error);
990         } else
991                 e_gdbus_cal_complete_get_attachment_list (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
992
993         g_strfreev (seq);
994 }
995
996 /**
997  * e_data_cal_notify_query:
998  * @cal: A calendar client interface.
999  * @error: Operation error, if any, automatically freed if passed it.
1000  * @query: The new live query.
1001  *
1002  * Notifies listeners of the completion of the get_query method call.
1003  */
1004 void
1005 e_data_cal_notify_query (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *query)
1006 {
1007         /*
1008          * Only have a seperate notify function to follow suit with the rest of this
1009          * file - it'd be much easier to just do the return in the above function
1010          */
1011         GDBusMethodInvocation *invocation = context;
1012         if (error) {
1013                 /* Translators: The '%s' is replaced with a detailed error message */
1014                 data_cal_return_error (invocation, error, _("Could not complete calendar query: %s"));
1015                 g_error_free (error);
1016         } else {
1017                 gchar *gdbus_query = NULL;
1018
1019                 e_gdbus_cal_complete_get_query (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (query, &gdbus_query));
1020
1021                 g_free (gdbus_query);
1022         }
1023 }
1024
1025 /**
1026  * e_data_cal_notify_timezone_requested:
1027  * @cal: A calendar client interface.
1028  * @error: Operation error, if any, automatically freed if passed it.
1029  * @object: The requested timezone as an iCalendar string.
1030  *
1031  * Notifies listeners of the completion of the get_timezone method call.
1032  */
1033 void
1034 e_data_cal_notify_timezone_requested (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
1035 {
1036         GDBusMethodInvocation *invocation = context;
1037         if (error) {
1038                 /* Translators: The '%s' is replaced with a detailed error message */
1039                 data_cal_return_error (invocation, error, _("Could not retrieve calendar time zone: %s"));
1040                 g_error_free (error);
1041         } else {
1042                 gchar *gdbus_object = NULL;
1043
1044                 e_gdbus_cal_complete_get_timezone (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
1045
1046                 g_free (gdbus_object);
1047         }
1048 }
1049
1050 /**
1051  * e_data_cal_notify_timezone_added:
1052  * @cal: A calendar client interface.
1053  * @error: Operation error, if any, automatically freed if passed it.
1054  * @tzid: ID of the added timezone.
1055  *
1056  * Notifies listeners of the completion of the add_timezone method call.
1057  */
1058 void
1059 e_data_cal_notify_timezone_added (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *tzid)
1060 {
1061         GDBusMethodInvocation *invocation = context;
1062         if (error) {
1063                 /* Translators: The '%s' is replaced with a detailed error message */
1064                 data_cal_return_error (invocation, error, _("Could not add calendar time zone: %s"));
1065                 g_error_free (error);
1066         } else
1067                 e_gdbus_cal_complete_add_timezone (cal->priv->gdbus_object, invocation);
1068 }
1069
1070 /**
1071  * e_data_cal_notify_default_timezone_set:
1072  * @cal: A calendar client interface.
1073  * @error: Operation error, if any, automatically freed if passed it.
1074  *
1075  * Notifies listeners of the completion of the set_default_timezone method call.
1076  */
1077 void
1078 e_data_cal_notify_default_timezone_set (EDataCal *cal, EServerMethodContext context, GError *error)
1079 {
1080         GDBusMethodInvocation *invocation = context;
1081         if (error) {
1082                 /* Translators: The '%s' is replaced with a detailed error message */
1083                 data_cal_return_error (invocation, error, _("Could not set default calendar time zone: %s"));
1084                 g_error_free (error);
1085         } else
1086                 e_gdbus_cal_complete_set_default_timezone (cal->priv->gdbus_object, invocation);
1087 }
1088
1089 /**
1090  * e_data_cal_notify_changes:
1091  * @cal: A calendar client interface.
1092  * @error: Operation error, if any, automatically freed if passed it.
1093  * @adds: List of additions.
1094  * @modifies: List of modifications.
1095  * @deletes: List of removals.
1096  *
1097  * Notifies listeners of the completion of the get_changes method call.
1098  */
1099 void
1100 e_data_cal_notify_changes (EDataCal *cal, EServerMethodContext context, GError *error,
1101                            GList *adds, GList *modifies, GList *deletes)
1102 {
1103         GDBusMethodInvocation *invocation = context;
1104         if (error) {
1105                 /* Translators: The '%s' is replaced with a detailed error message */
1106                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar changes: %s"));
1107                 g_error_free (error);
1108         } else {
1109                 gchar **additions, **modifications, **removals;
1110
1111                 additions = create_str_array_from_glist (adds);
1112                 modifications = create_str_array_from_glist (modifies);
1113                 removals = create_str_array_from_glist (deletes);
1114
1115                 e_gdbus_cal_complete_get_changes (cal->priv->gdbus_object, invocation, (const gchar * const *) additions, (const gchar * const *) modifications, (const gchar * const *) removals);
1116
1117                 g_strfreev (additions);
1118                 g_strfreev (modifications);
1119                 g_strfreev (removals);
1120         }
1121 }
1122
1123 /**
1124  * e_data_cal_notify_free_busy:
1125  * @cal: A calendar client interface.
1126  * @error: Operation error, if any, automatically freed if passed it.
1127  * @freebusy: List of free/busy objects.
1128  *
1129  * Notifies listeners of the completion of the get_free_busy method call.
1130  */
1131 void
1132 e_data_cal_notify_free_busy (EDataCal *cal, EServerMethodContext context, GError *error, GList *freebusy)
1133 {
1134         GDBusMethodInvocation *invocation = context;
1135         if (error) {
1136                 /* Translators: The '%s' is replaced with a detailed error message */
1137                 data_cal_return_error (invocation, error, _("Cannot retrieve calendar free/busy list: %s"));
1138                 g_error_free (error);
1139         } else {
1140                 gchar **seq;
1141
1142                 seq = create_str_array_from_glist (freebusy);
1143
1144                 e_gdbus_cal_complete_get_free_busy (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
1145
1146                 g_strfreev (seq);
1147         }
1148 }
1149
1150 /**
1151  * e_data_cal_notify_mode:
1152  * @cal: A calendar client interface.
1153  * @status: Status of the mode set.
1154  * @mode: The current mode.
1155  *
1156  * Notifies the listener of the results of a set_mode call.
1157  **/
1158 void
1159 e_data_cal_notify_mode (EDataCal *cal,
1160                         EDataCalViewListenerSetModeStatus status,
1161                         EDataCalMode mode)
1162 {
1163         g_return_if_fail (cal != NULL);
1164         g_return_if_fail (E_IS_DATA_CAL (cal));
1165
1166         e_gdbus_cal_emit_mode (cal->priv->gdbus_object, mode);
1167 }
1168
1169 /**
1170  * e_data_cal_notify_auth_required:
1171  * @cal: A calendar client interface.
1172  *
1173  * Notifies listeners that authorization is required to open the calendar.
1174  */
1175 void
1176 e_data_cal_notify_auth_required (EDataCal *cal)
1177 {
1178         g_return_if_fail (cal != NULL);
1179         g_return_if_fail (E_IS_DATA_CAL (cal));
1180
1181         e_gdbus_cal_emit_auth_required (cal->priv->gdbus_object);
1182 }
1183
1184 /**
1185  * e_data_cal_notify_error
1186  * @cal: A calendar client interface.
1187  * @message: Error message.
1188  *
1189  * Notify a calendar client of an error occurred in the backend.
1190  */
1191 void
1192 e_data_cal_notify_error (EDataCal *cal, const gchar *message)
1193 {
1194         gchar *gdbus_message = NULL;
1195
1196         g_return_if_fail (cal != NULL);
1197         g_return_if_fail (E_IS_DATA_CAL (cal));
1198
1199         e_gdbus_cal_emit_backend_error (cal->priv->gdbus_object, e_util_ensure_gdbus_string (message, &gdbus_message));
1200
1201         g_free (gdbus_message);
1202 }
1203
1204 /* Instance init */
1205 static void
1206 e_data_cal_init (EDataCal *ecal)
1207 {
1208         EGdbusCal *gdbus_object;
1209
1210         ecal->priv = G_TYPE_INSTANCE_GET_PRIVATE (ecal, E_TYPE_DATA_CAL, EDataCalPrivate);
1211
1212         ecal->priv->gdbus_object = e_gdbus_cal_stub_new ();
1213
1214         gdbus_object = ecal->priv->gdbus_object;
1215         g_signal_connect (gdbus_object, "handle-get-uri", G_CALLBACK (impl_Cal_getUri), ecal);
1216         g_signal_connect (gdbus_object, "handle-get-cache-dir", G_CALLBACK (impl_Cal_getCacheDir), ecal);
1217         g_signal_connect (gdbus_object, "handle-open", G_CALLBACK (impl_Cal_open), ecal);
1218         g_signal_connect (gdbus_object, "handle-refresh", G_CALLBACK (impl_Cal_refresh), ecal);
1219         g_signal_connect (gdbus_object, "handle-close", G_CALLBACK (impl_Cal_close), ecal);
1220         g_signal_connect (gdbus_object, "handle-remove", G_CALLBACK (impl_Cal_remove), ecal);
1221         g_signal_connect (gdbus_object, "handle-is-read-only", G_CALLBACK (impl_Cal_isReadOnly), ecal);
1222         g_signal_connect (gdbus_object, "handle-get-cal-address", G_CALLBACK (impl_Cal_getCalAddress), ecal);
1223         g_signal_connect (gdbus_object, "handle-get-alarm-email-address", G_CALLBACK (impl_Cal_getAlarmEmailAddress), ecal);
1224         g_signal_connect (gdbus_object, "handle-get-ldap-attribute", G_CALLBACK (impl_Cal_getLdapAttribute), ecal);
1225         g_signal_connect (gdbus_object, "handle-get-scheduling-information", G_CALLBACK (impl_Cal_getSchedulingInformation), ecal);
1226         g_signal_connect (gdbus_object, "handle-set-mode", G_CALLBACK (impl_Cal_setMode), ecal);
1227         g_signal_connect (gdbus_object, "handle-get-default-object", G_CALLBACK (impl_Cal_getDefaultObject), ecal);
1228         g_signal_connect (gdbus_object, "handle-get-object", G_CALLBACK (impl_Cal_getObject), ecal);
1229         g_signal_connect (gdbus_object, "handle-get-object-list", G_CALLBACK (impl_Cal_getObjectList), ecal);
1230         g_signal_connect (gdbus_object, "handle-get-changes", G_CALLBACK (impl_Cal_getChanges), ecal);
1231         g_signal_connect (gdbus_object, "handle-get-free-busy", G_CALLBACK (impl_Cal_getFreeBusy), ecal);
1232         g_signal_connect (gdbus_object, "handle-discard-alarm", G_CALLBACK (impl_Cal_discardAlarm), ecal);
1233         g_signal_connect (gdbus_object, "handle-create-object", G_CALLBACK (impl_Cal_createObject), ecal);
1234         g_signal_connect (gdbus_object, "handle-modify-object", G_CALLBACK (impl_Cal_modifyObject), ecal);
1235         g_signal_connect (gdbus_object, "handle-remove-object", G_CALLBACK (impl_Cal_removeObject), ecal);
1236         g_signal_connect (gdbus_object, "handle-receive-objects", G_CALLBACK (impl_Cal_receiveObjects), ecal);
1237         g_signal_connect (gdbus_object, "handle-send-objects", G_CALLBACK (impl_Cal_sendObjects), ecal);
1238         g_signal_connect (gdbus_object, "handle-get-attachment-list", G_CALLBACK (impl_Cal_getAttachmentList), ecal);
1239         g_signal_connect (gdbus_object, "handle-get-query", G_CALLBACK (impl_Cal_getQuery), ecal);
1240         g_signal_connect (gdbus_object, "handle-get-timezone", G_CALLBACK (impl_Cal_getTimezone), ecal);
1241         g_signal_connect (gdbus_object, "handle-add-timezone", G_CALLBACK (impl_Cal_addTimezone), ecal);
1242         g_signal_connect (gdbus_object, "handle-set-default-timezone", G_CALLBACK (impl_Cal_setDefaultTimezone), ecal);
1243 }
1244
1245 static void
1246 e_data_cal_finalize (GObject *object)
1247 {
1248         EDataCal *cal = E_DATA_CAL (object);
1249
1250         g_return_if_fail (cal != NULL);
1251
1252         g_object_unref (cal->priv->gdbus_object);
1253
1254         /* Chain up to parent's finalize() method. */
1255         G_OBJECT_CLASS (e_data_cal_parent_class)->finalize (object);
1256 }
1257
1258 /* Class init */
1259 static void
1260 e_data_cal_class_init (EDataCalClass *klass)
1261 {
1262         GObjectClass *object_class;
1263
1264         g_type_class_add_private (klass, sizeof (EDataCalPrivate));
1265
1266         object_class = G_OBJECT_CLASS (klass);
1267         object_class->finalize = e_data_cal_finalize;
1268 }
1269
1270 EDataCal *
1271 e_data_cal_new (ECalBackend *backend, ESource *source)
1272 {
1273         EDataCal *cal;
1274         cal = g_object_new (E_TYPE_DATA_CAL, NULL);
1275         cal->priv->backend = backend;
1276         cal->priv->source = source;
1277         return cal;
1278 }
1279
1280 /**
1281  * e_data_cal_register_gdbus_object:
1282  *
1283  * Registers GDBus object of this EDataCal.
1284  *
1285  * Since: 2.32
1286  **/
1287 guint
1288 e_data_cal_register_gdbus_object (EDataCal *cal, GDBusConnection *connection, const gchar *object_path, GError **error)
1289 {
1290         g_return_val_if_fail (cal != NULL, 0);
1291         g_return_val_if_fail (E_IS_DATA_CAL (cal), 0);
1292         g_return_val_if_fail (connection != NULL, 0);
1293         g_return_val_if_fail (object_path != NULL, 0);
1294
1295         return e_gdbus_cal_register_object (cal->priv->gdbus_object, connection, object_path, error);
1296 }