1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* Evolution calendar client interface object
4 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5 * Copyright (C) 2009 Intel Corporation
7 * Authors: Federico Mena-Quintero <federico@ximian.com>
8 * Rodrigo Moya <rodrigo@ximian.com>
9 * Ross Burton <ross@linux.intel.com>
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.
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.
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.
29 #include <libical/ical.h>
30 #include <glib/gi18n-lib.h>
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"
40 G_DEFINE_TYPE (EDataCal, e_data_cal, G_TYPE_OBJECT);
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)
45 struct _EDataCalPrivate {
46 EGdbusCal *gdbus_object;
49 GHashTable *live_queries;
52 /* Create the EDataCal error quark */
54 e_data_cal_error_quark (void)
56 #define ERR_PREFIX "org.gnome.evolution.dataserver.Calendar."
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" }
88 static volatile gsize quark_volatile = 0;
90 g_dbus_error_register_error_domain ("e-data-cal-error", &quark_volatile, entries, G_N_ELEMENTS (entries));
92 return (GQuark) quark_volatile;
96 * e_data_cal_status_to_string:
101 e_data_cal_status_to_string (EDataCalCallStatus status)
104 static struct _statuses {
105 EDataCalCallStatus status;
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") }
136 for (i = 0; i < G_N_ELEMENTS (statuses); i++) {
137 if (statuses[i].status == status)
138 return _(statuses[i].msg);
141 return _("Other error");
145 * e_data_cal_create_error:
150 e_data_cal_create_error (EDataCalCallStatus status, const gchar *custom_msg)
152 if (status == Success)
155 return g_error_new_literal (E_DATA_CAL_ERROR, status, custom_msg ? custom_msg : e_data_cal_status_to_string (status));
159 * e_data_cal_create_error_fmt:
164 e_data_cal_create_error_fmt (EDataCalCallStatus status, const gchar *custom_msg_fmt, ...)
171 return e_data_cal_create_error (status, NULL);
173 va_start (ap, custom_msg_fmt);
174 custom_msg = g_strdup_vprintf (custom_msg_fmt, ap);
177 error = e_data_cal_create_error (status, custom_msg);
185 data_cal_return_error (GDBusMethodInvocation *invocation, const GError *perror, const gchar *error_fmt)
189 g_return_if_fail (perror != NULL);
191 error = g_error_new (E_DATA_CAL_ERROR, perror->code, error_fmt, perror->message);
193 g_dbus_method_invocation_return_gerror (invocation, error);
195 g_error_free (error);
199 * e_data_cal_get_source:
202 * Returns the #ESource for @cal.
204 * Returns: the #ESource for @cal
209 e_data_cal_get_source (EDataCal *cal)
211 return cal->priv->source;
215 e_data_cal_get_backend (EDataCal *cal)
217 return cal->priv->backend;
220 /* EDataCal::getUri method */
222 impl_Cal_getUri (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
224 e_gdbus_cal_complete_get_uri (object, invocation, e_cal_backend_get_uri (cal->priv->backend));
229 /* EDataCal::getCacheDir method */
231 impl_Cal_getCacheDir (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
233 e_gdbus_cal_complete_get_cache_dir (object, invocation, e_cal_backend_get_cache_dir (cal->priv->backend));
238 /* EDataCal::open method */
240 impl_Cal_open (EGdbusCal *object, GDBusMethodInvocation *invocation, gboolean only_if_exists, const gchar *username, const gchar *password, EDataCal *cal)
242 e_cal_backend_open (cal->priv->backend, cal, invocation, only_if_exists, username, password);
247 /* EDataCal::refresh method */
249 impl_Cal_refresh (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
251 e_cal_backend_refresh (cal->priv->backend, cal, invocation);
256 /* EDataCal::close method */
258 impl_Cal_close (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
260 e_cal_backend_remove_client (cal->priv->backend, cal);
261 e_gdbus_cal_complete_close (object, invocation);
263 g_object_unref (cal);
268 /* EDataCal::remove method */
270 impl_Cal_remove (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
272 e_cal_backend_remove (cal->priv->backend, cal, invocation);
277 /* EDataCal::isReadOnly method */
279 impl_Cal_isReadOnly (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
281 e_cal_backend_is_read_only (cal->priv->backend, cal);
282 e_gdbus_cal_complete_is_read_only (object, invocation);
287 /* EDataCal::getCalAddress method */
289 impl_Cal_getCalAddress (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
291 e_cal_backend_get_cal_address (cal->priv->backend, cal, invocation);
296 /* EDataCal::getAlarmEmailAddress method */
298 impl_Cal_getAlarmEmailAddress (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
300 e_cal_backend_get_alarm_email_address (cal->priv->backend, cal, invocation);
305 /* EDataCal::getLdapAttribute method */
307 impl_Cal_getLdapAttribute (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
309 e_cal_backend_get_ldap_attribute (cal->priv->backend, cal, invocation);
314 /* EDataCal::getSchedulingInformation method */
316 impl_Cal_getSchedulingInformation (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
318 e_cal_backend_get_static_capabilities (cal->priv->backend, cal, invocation);
323 /* EDataCal::setMode method */
325 impl_Cal_setMode (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCalMode mode, EDataCal *cal)
327 e_cal_backend_set_mode (cal->priv->backend, mode);
328 e_gdbus_cal_complete_set_mode (object, invocation);
333 /* EDataCal::getDefaultObject method */
335 impl_Cal_getDefaultObject (EGdbusCal *object, GDBusMethodInvocation *invocation, EDataCal *cal)
337 e_cal_backend_get_default_object (cal->priv->backend, cal, invocation);
342 /* EDataCal::getObject method */
344 impl_Cal_getObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCal *cal)
346 e_cal_backend_get_object (cal->priv->backend, cal, invocation, uid, rid);
351 /* EDataCal::getObjectList method */
353 impl_Cal_getObjectList (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *sexp, EDataCal *cal)
355 e_cal_backend_get_object_list (cal->priv->backend, cal, invocation, sexp);
360 /* EDataCal::getChanges method */
362 impl_Cal_getChanges (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *change_id, EDataCal *cal)
364 e_cal_backend_get_changes (cal->priv->backend, cal, invocation, change_id);
369 /* EDataCal::getFreeBusy method */
371 impl_Cal_getFreeBusy (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar **user_list, guint start, guint end, EDataCal *cal)
378 for (i = 0; user_list[i]; i++)
379 users = g_list_append (users, (gpointer)user_list[i]);
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);
388 /* EDataCal::discardAlarm method */
390 impl_Cal_discardAlarm (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *auid, EDataCal *cal)
392 e_cal_backend_discard_alarm (cal->priv->backend, cal, invocation, uid, auid);
397 /* EDataCal::createObject method */
399 impl_Cal_createObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
401 e_cal_backend_create_object (cal->priv->backend, cal, invocation, calobj);
406 /* EDataCal::modifyObject method */
408 impl_Cal_modifyObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCalObjModType mod, EDataCal *cal)
410 e_cal_backend_modify_object (cal->priv->backend, cal, invocation, calobj, mod);
415 /* EDataCal::removeObject method */
417 impl_Cal_removeObject (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCalObjModType mod, EDataCal *cal)
422 e_cal_backend_remove_object (cal->priv->backend, cal, invocation, uid, rid, mod);
427 /* EDataCal::receiveObjects method */
429 impl_Cal_receiveObjects (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
431 e_cal_backend_receive_objects (cal->priv->backend, cal, invocation, calobj);
436 /* EDataCal::sendObjects method */
438 impl_Cal_sendObjects (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *calobj, EDataCal *cal)
440 e_cal_backend_send_objects (cal->priv->backend, cal, invocation, calobj);
445 /* EDataCal::getAttachmentList method */
447 impl_Cal_getAttachmentList (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *uid, const gchar *rid, EDataCal *cal)
449 e_cal_backend_get_attachment_list (cal->priv->backend, cal, invocation, uid, rid);
454 /* Function to get a new EDataCalView path, used by getQuery below */
456 construct_calview_path (void)
458 static guint counter = 1;
459 return g_strdup_printf ("/org/gnome/evolution/dataserver/CalendarView/%d/%d", getpid(), counter++);
462 /* EDataCal::getQuery method */
464 impl_Cal_getQuery (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *sexp, EDataCal *cal)
467 ECalBackendSExp *obj_sexp;
469 GError *error = NULL;
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. */
475 obj_sexp = e_cal_backend_sexp_new (sexp);
477 e_data_cal_notify_query (cal, invocation, EDC_ERROR (InvalidQuery), NULL);
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));
484 g_object_unref (obj_sexp);
485 e_data_cal_notify_query (cal, invocation, EDC_ERROR (OtherError), NULL);
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));
492 path = construct_calview_path ();
493 e_data_cal_view_register_gdbus_object (query, g_dbus_method_invocation_get_connection (invocation), path, &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);
504 e_cal_backend_add_query (cal->priv->backend, query);
506 e_data_cal_notify_query (cal, invocation, EDC_ERROR (Success), path);
513 /* EDataCal::getTimezone method */
515 impl_Cal_getTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tzid, EDataCal *cal)
517 e_cal_backend_get_timezone (cal->priv->backend, cal, invocation, tzid);
522 /* EDataCal::addTimezone method */
524 impl_Cal_addTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tz, EDataCal *cal)
526 e_cal_backend_add_timezone (cal->priv->backend, cal, invocation, tz);
531 /* EDataCal::setDefaultTimezone method */
533 impl_Cal_setDefaultTimezone (EGdbusCal *object, GDBusMethodInvocation *invocation, const gchar *tz, EDataCal *cal)
535 e_cal_backend_set_default_zone (cal->priv->backend, cal, invocation, tz);
540 /* free returned pointer with g_strfreev() */
542 create_str_array_from_glist (GList *lst)
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);
556 /* free returned pointer with g_strfreev() */
558 create_str_array_from_gslist (GSList *lst)
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);
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.
578 * Notifies listeners of the completion of the is_read_only method call.
581 e_data_cal_notify_read_only (EDataCal *cal, GError *error, gboolean read_only)
583 g_return_if_fail (cal != NULL);
584 g_return_if_fail (E_IS_DATA_CAL (cal));
587 e_data_cal_notify_error (cal, error->message);
588 g_error_free (error);
590 e_gdbus_cal_emit_readonly (cal->priv->gdbus_object, read_only);
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.
600 * Notifies listeners of the completion of the get_cal_address method call.
603 e_data_cal_notify_cal_address (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *address)
605 GDBusMethodInvocation *invocation = context;
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);
611 gchar *gdbus_address = NULL;
613 e_gdbus_cal_complete_get_cal_address (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (address, &gdbus_address));
615 g_free (gdbus_address);
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.
625 * Notifies listeners of the completion of the get_alarm_email_address method call.
628 e_data_cal_notify_alarm_email_address (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *address)
630 GDBusMethodInvocation *invocation = context;
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);
636 gchar *gdbus_address = NULL;
638 e_gdbus_cal_complete_get_alarm_email_address (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (address, &gdbus_address));
640 g_free (gdbus_address);
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.
650 * Notifies listeners of the completion of the get_ldap_attribute method call.
653 e_data_cal_notify_ldap_attribute (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *attribute)
655 GDBusMethodInvocation *invocation = context;
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);
661 gchar *gdbus_attribute = NULL;
663 e_gdbus_cal_complete_get_ldap_attribute (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (attribute, &gdbus_attribute));
665 g_free (gdbus_attribute);
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.
675 * Notifies listeners of the completion of the get_static_capabilities method call.
678 e_data_cal_notify_static_capabilities (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *capabilities)
680 GDBusMethodInvocation *invocation = context;
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);
686 gchar *gdbus_capabilities = NULL;
688 e_gdbus_cal_complete_get_scheduling_information (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (capabilities, &gdbus_capabilities));
690 g_free (gdbus_capabilities);
695 * e_data_cal_notify_open:
696 * @cal: A calendar client interface.
697 * @error: Operation error, if any, automatically freed if passed it.
699 * Notifies listeners of the completion of the open method call.
702 e_data_cal_notify_open (EDataCal *cal, EServerMethodContext context, GError *error)
704 GDBusMethodInvocation *invocation = context;
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);
710 e_gdbus_cal_complete_open (cal->priv->gdbus_object, invocation);
714 * e_data_cal_notify_refresh:
715 * @cal: A calendar client interface.
716 * @error: Operation error, if any, automatically freed if passed it.
718 * Notifies listeners of the completion of the refresh method call.
723 e_data_cal_notify_refresh (EDataCal *cal, EServerMethodContext context, GError *error)
725 GDBusMethodInvocation *invocation = context;
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);
731 e_gdbus_cal_complete_refresh (cal->priv->gdbus_object, invocation);
735 * e_data_cal_notify_remove:
736 * @cal: A calendar client interface.
737 * @error: Operation error, if any, automatically freed if passed it.
739 * Notifies listeners of the completion of the remove method call.
742 e_data_cal_notify_remove (EDataCal *cal, EServerMethodContext context, GError *error)
744 GDBusMethodInvocation *invocation = context;
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);
750 e_gdbus_cal_complete_remove (cal->priv->gdbus_object, invocation);
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.
760 * Notifies listeners of the completion of the create_object method call.
762 e_data_cal_notify_object_created (EDataCal *cal, EServerMethodContext context, GError *error,
763 const gchar *uid, const gchar *object)
765 GDBusMethodInvocation *invocation = context;
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);
771 gchar *gdbus_uid = NULL;
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));
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.
787 * Notifies listeners of the completion of the modify_object method call.
790 e_data_cal_notify_object_modified (EDataCal *cal, EServerMethodContext context, GError *error,
791 const gchar *old_object, const gchar *object)
793 GDBusMethodInvocation *invocation = context;
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);
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);
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.
813 * Notifies listeners of the completion of the remove_object method call.
816 e_data_cal_notify_object_removed (EDataCal *cal, EServerMethodContext context, GError *error,
817 const ECalComponentId *id, const gchar *old_object, const gchar *object)
819 GDBusMethodInvocation *invocation = context;
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);
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);
831 * e_data_cal_notify_objects_received:
832 * @cal: A calendar client interface.
833 * @error: Operation error, if any, automatically freed if passed it.
835 * Notifies listeners of the completion of the receive_objects method call.
838 e_data_cal_notify_objects_received (EDataCal *cal, EServerMethodContext context, GError *error)
840 GDBusMethodInvocation *invocation = context;
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);
846 e_gdbus_cal_complete_receive_objects (cal->priv->gdbus_object, invocation);
850 * e_data_cal_notify_alarm_discarded:
851 * @cal: A calendar client interface.
852 * @error: Operation error, if any, automatically freed if passed it.
854 * Notifies listeners of the completion of the discard_alarm method call.
857 e_data_cal_notify_alarm_discarded (EDataCal *cal, EServerMethodContext context, GError *error)
859 GDBusMethodInvocation *invocation = context;
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);
865 e_gdbus_cal_complete_discard_alarm (cal->priv->gdbus_object, invocation);
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.
875 * Notifies listeners of the completion of the send_objects method call.
878 e_data_cal_notify_objects_sent (EDataCal *cal, EServerMethodContext context, GError *error, GList *users, const gchar *calobj)
880 GDBusMethodInvocation *invocation = context;
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);
886 gchar **users_array = create_str_array_from_glist (users);
887 gchar *gdbus_calobj = NULL;
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));
891 g_free (gdbus_calobj);
892 g_strfreev (users_array);
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.
902 * Notifies listeners of the completion of the get_default_object method call.
905 e_data_cal_notify_default_object (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
907 GDBusMethodInvocation *invocation = context;
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);
913 gchar *gdbus_object = NULL;
915 e_gdbus_cal_complete_get_default_object (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
917 g_free (gdbus_object);
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.
927 * Notifies listeners of the completion of the get_object method call.
930 e_data_cal_notify_object (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
932 GDBusMethodInvocation *invocation = context;
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);
938 gchar *gdbus_object = NULL;
940 e_gdbus_cal_complete_get_object (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
942 g_free (gdbus_object);
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.
952 * Notifies listeners of the completion of the get_object_list method call.
955 e_data_cal_notify_object_list (EDataCal *cal, EServerMethodContext context, GError *error, GList *objects)
957 GDBusMethodInvocation *invocation = context;
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);
963 gchar **seq = create_str_array_from_glist (objects);
965 e_gdbus_cal_complete_get_object_list (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
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.
977 * Notifies listeners of the completion of the get_attachment_list method call.+ */
979 e_data_cal_notify_attachment_list (EDataCal *cal, EServerMethodContext context, GError *error, GSList *attachments)
981 GDBusMethodInvocation *invocation = context;
984 seq = create_str_array_from_gslist (attachments);
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);
991 e_gdbus_cal_complete_get_attachment_list (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
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.
1002 * Notifies listeners of the completion of the get_query method call.
1005 e_data_cal_notify_query (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *query)
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
1011 GDBusMethodInvocation *invocation = context;
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);
1017 gchar *gdbus_query = NULL;
1019 e_gdbus_cal_complete_get_query (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (query, &gdbus_query));
1021 g_free (gdbus_query);
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.
1031 * Notifies listeners of the completion of the get_timezone method call.
1034 e_data_cal_notify_timezone_requested (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *object)
1036 GDBusMethodInvocation *invocation = context;
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);
1042 gchar *gdbus_object = NULL;
1044 e_gdbus_cal_complete_get_timezone (cal->priv->gdbus_object, invocation, e_util_ensure_gdbus_string (object, &gdbus_object));
1046 g_free (gdbus_object);
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.
1056 * Notifies listeners of the completion of the add_timezone method call.
1059 e_data_cal_notify_timezone_added (EDataCal *cal, EServerMethodContext context, GError *error, const gchar *tzid)
1061 GDBusMethodInvocation *invocation = context;
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);
1067 e_gdbus_cal_complete_add_timezone (cal->priv->gdbus_object, invocation);
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.
1075 * Notifies listeners of the completion of the set_default_timezone method call.
1078 e_data_cal_notify_default_timezone_set (EDataCal *cal, EServerMethodContext context, GError *error)
1080 GDBusMethodInvocation *invocation = context;
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);
1086 e_gdbus_cal_complete_set_default_timezone (cal->priv->gdbus_object, invocation);
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.
1097 * Notifies listeners of the completion of the get_changes method call.
1100 e_data_cal_notify_changes (EDataCal *cal, EServerMethodContext context, GError *error,
1101 GList *adds, GList *modifies, GList *deletes)
1103 GDBusMethodInvocation *invocation = context;
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);
1109 gchar **additions, **modifications, **removals;
1111 additions = create_str_array_from_glist (adds);
1112 modifications = create_str_array_from_glist (modifies);
1113 removals = create_str_array_from_glist (deletes);
1115 e_gdbus_cal_complete_get_changes (cal->priv->gdbus_object, invocation, (const gchar * const *) additions, (const gchar * const *) modifications, (const gchar * const *) removals);
1117 g_strfreev (additions);
1118 g_strfreev (modifications);
1119 g_strfreev (removals);
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.
1129 * Notifies listeners of the completion of the get_free_busy method call.
1132 e_data_cal_notify_free_busy (EDataCal *cal, EServerMethodContext context, GError *error, GList *freebusy)
1134 GDBusMethodInvocation *invocation = context;
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);
1142 seq = create_str_array_from_glist (freebusy);
1144 e_gdbus_cal_complete_get_free_busy (cal->priv->gdbus_object, invocation, (const gchar * const *) seq);
1151 * e_data_cal_notify_mode:
1152 * @cal: A calendar client interface.
1153 * @status: Status of the mode set.
1154 * @mode: The current mode.
1156 * Notifies the listener of the results of a set_mode call.
1159 e_data_cal_notify_mode (EDataCal *cal,
1160 EDataCalViewListenerSetModeStatus status,
1163 g_return_if_fail (cal != NULL);
1164 g_return_if_fail (E_IS_DATA_CAL (cal));
1166 e_gdbus_cal_emit_mode (cal->priv->gdbus_object, mode);
1170 * e_data_cal_notify_auth_required:
1171 * @cal: A calendar client interface.
1173 * Notifies listeners that authorization is required to open the calendar.
1176 e_data_cal_notify_auth_required (EDataCal *cal)
1178 g_return_if_fail (cal != NULL);
1179 g_return_if_fail (E_IS_DATA_CAL (cal));
1181 e_gdbus_cal_emit_auth_required (cal->priv->gdbus_object);
1185 * e_data_cal_notify_error
1186 * @cal: A calendar client interface.
1187 * @message: Error message.
1189 * Notify a calendar client of an error occurred in the backend.
1192 e_data_cal_notify_error (EDataCal *cal, const gchar *message)
1194 gchar *gdbus_message = NULL;
1196 g_return_if_fail (cal != NULL);
1197 g_return_if_fail (E_IS_DATA_CAL (cal));
1199 e_gdbus_cal_emit_backend_error (cal->priv->gdbus_object, e_util_ensure_gdbus_string (message, &gdbus_message));
1201 g_free (gdbus_message);
1206 e_data_cal_init (EDataCal *ecal)
1208 EGdbusCal *gdbus_object;
1210 ecal->priv = G_TYPE_INSTANCE_GET_PRIVATE (ecal, E_TYPE_DATA_CAL, EDataCalPrivate);
1212 ecal->priv->gdbus_object = e_gdbus_cal_stub_new ();
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);
1246 e_data_cal_finalize (GObject *object)
1248 EDataCal *cal = E_DATA_CAL (object);
1250 g_return_if_fail (cal != NULL);
1252 g_object_unref (cal->priv->gdbus_object);
1254 /* Chain up to parent's finalize() method. */
1255 G_OBJECT_CLASS (e_data_cal_parent_class)->finalize (object);
1260 e_data_cal_class_init (EDataCalClass *klass)
1262 GObjectClass *object_class;
1264 g_type_class_add_private (klass, sizeof (EDataCalPrivate));
1266 object_class = G_OBJECT_CLASS (klass);
1267 object_class->finalize = e_data_cal_finalize;
1271 e_data_cal_new (ECalBackend *backend, ESource *source)
1274 cal = g_object_new (E_TYPE_DATA_CAL, NULL);
1275 cal->priv->backend = backend;
1276 cal->priv->source = source;
1281 * e_data_cal_register_gdbus_object:
1283 * Registers GDBus object of this EDataCal.
1288 e_data_cal_register_gdbus_object (EDataCal *cal, GDBusConnection *connection, const gchar *object_path, GError **error)
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);
1295 return e_gdbus_cal_register_object (cal->priv->gdbus_object, connection, object_path, error);