2 * e-source-collection.c
4 * This library is free software you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * SECTION: e-source-collection
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for grouping related resources
23 * The #ESourceCollection extension identifies the #ESource as the root
24 * of a data source collection.
26 * Access the extension as follows:
29 * #include <libedataserver/libedataserver.h>
31 * ESourceCollection *extension;
33 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_COLLECTION);
37 #include "e-source-collection.h"
40 #include <glib/gi18n-lib.h>
42 /* Private D-Bus classes. */
43 #include <e-dbus-source.h>
45 #include <libedataserver/e-data-server-util.h>
47 #define E_SOURCE_COLLECTION_GET_PRIVATE(obj) \
48 (G_TYPE_INSTANCE_GET_PRIVATE \
49 ((obj), E_TYPE_SOURCE_COLLECTION, ESourceCollectionPrivate))
51 struct _ESourceCollectionPrivate {
54 gboolean calendar_enabled;
55 gboolean contacts_enabled;
56 gboolean mail_enabled;
61 PROP_CALENDAR_ENABLED,
62 PROP_CONTACTS_ENABLED,
70 E_TYPE_SOURCE_BACKEND)
73 source_collection_set_property (GObject *object,
78 switch (property_id) {
79 case PROP_CALENDAR_ENABLED:
80 e_source_collection_set_calendar_enabled (
81 E_SOURCE_COLLECTION (object),
82 g_value_get_boolean (value));
85 case PROP_CONTACTS_ENABLED:
86 e_source_collection_set_contacts_enabled (
87 E_SOURCE_COLLECTION (object),
88 g_value_get_boolean (value));
92 e_source_collection_set_identity (
93 E_SOURCE_COLLECTION (object),
94 g_value_get_string (value));
97 case PROP_MAIL_ENABLED:
98 e_source_collection_set_mail_enabled (
99 E_SOURCE_COLLECTION (object),
100 g_value_get_boolean (value));
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 source_collection_get_property (GObject *object,
113 switch (property_id) {
114 case PROP_CALENDAR_ENABLED:
115 g_value_set_boolean (
117 e_source_collection_get_calendar_enabled (
118 E_SOURCE_COLLECTION (object)));
121 case PROP_CONTACTS_ENABLED:
122 g_value_set_boolean (
124 e_source_collection_get_contacts_enabled (
125 E_SOURCE_COLLECTION (object)));
129 g_value_take_string (
131 e_source_collection_dup_identity (
132 E_SOURCE_COLLECTION (object)));
135 case PROP_MAIL_ENABLED:
136 g_value_set_boolean (
138 e_source_collection_get_mail_enabled (
139 E_SOURCE_COLLECTION (object)));
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
147 source_collection_finalize (GObject *object)
149 ESourceCollectionPrivate *priv;
151 priv = E_SOURCE_COLLECTION_GET_PRIVATE (object);
153 g_mutex_clear (&priv->property_lock);
155 g_free (priv->identity);
157 /* Chain up to parent's finalize() method. */
158 G_OBJECT_CLASS (e_source_collection_parent_class)->finalize (object);
162 e_source_collection_class_init (ESourceCollectionClass *class)
164 GObjectClass *object_class;
165 ESourceExtensionClass *extension_class;
167 g_type_class_add_private (class, sizeof (ESourceCollectionPrivate));
169 object_class = G_OBJECT_CLASS (class);
170 object_class->set_property = source_collection_set_property;
171 object_class->get_property = source_collection_get_property;
172 object_class->finalize = source_collection_finalize;
174 extension_class = E_SOURCE_EXTENSION_CLASS (class);
175 extension_class->name = E_SOURCE_EXTENSION_COLLECTION;
177 g_object_class_install_property (
179 PROP_CALENDAR_ENABLED,
180 g_param_spec_boolean (
183 "Whether calendar resources are enabled",
187 G_PARAM_STATIC_STRINGS |
188 E_SOURCE_PARAM_SETTING));
190 g_object_class_install_property (
192 PROP_CONTACTS_ENABLED,
193 g_param_spec_boolean (
196 "Whether contact resources are enabled",
200 G_PARAM_STATIC_STRINGS |
201 E_SOURCE_PARAM_SETTING));
203 g_object_class_install_property (
206 g_param_spec_string (
209 "Uniquely identifies the account "
210 "at the service provider",
214 G_PARAM_STATIC_STRINGS |
215 E_SOURCE_PARAM_SETTING));
217 g_object_class_install_property (
220 g_param_spec_boolean (
223 "Whether mail resources are enabled",
227 G_PARAM_STATIC_STRINGS |
228 E_SOURCE_PARAM_SETTING));
232 e_source_collection_init (ESourceCollection *extension)
234 extension->priv = E_SOURCE_COLLECTION_GET_PRIVATE (extension);
235 g_mutex_init (&extension->priv->property_lock);
239 * e_source_collection_get_identity:
240 * @extension: an #ESourceCollection
242 * Returns the string used to uniquely identify the user account at
243 * the service provider. Often this is an email address or user name.
245 * Returns: the collection identity
250 e_source_collection_get_identity (ESourceCollection *extension)
252 g_return_val_if_fail (E_IS_SOURCE_COLLECTION (extension), NULL);
254 return extension->priv->identity;
258 * e_source_collection_dup_identity:
259 * @extension: an #ESourceCollection
261 * Thread-safe variation of e_source_collection_get_identity().
262 * Use this function when accessing @extension from multiple threads.
264 * The returned string should be freed with g_free() when no longer needed.
266 * Returns: a newly-allocated copy of #ESourceCollection:identity
271 e_source_collection_dup_identity (ESourceCollection *extension)
273 const gchar *protected;
276 g_return_val_if_fail (E_IS_SOURCE_COLLECTION (extension), NULL);
278 g_mutex_lock (&extension->priv->property_lock);
280 protected = e_source_collection_get_identity (extension);
281 duplicate = g_strdup (protected);
283 g_mutex_unlock (&extension->priv->property_lock);
289 * e_source_collection_set_identity:
290 * @extension: an #ESourceCollection
291 * @identity: (allow-none): the collection identity, or %NULL
293 * Sets the string used to uniquely identify the user account at the
294 * service provider. Often this is an email address or user name.
296 * The internal copy of @identity is automatically stripped of leading
297 * and trailing whitespace. If the resulting string is empty, %NULL is
303 e_source_collection_set_identity (ESourceCollection *extension,
304 const gchar *identity)
306 g_return_if_fail (E_IS_SOURCE_COLLECTION (extension));
308 g_mutex_lock (&extension->priv->property_lock);
310 if (g_strcmp0 (extension->priv->identity, identity) == 0) {
311 g_mutex_unlock (&extension->priv->property_lock);
315 g_free (extension->priv->identity);
316 extension->priv->identity = e_util_strdup_strip (identity);
318 g_mutex_unlock (&extension->priv->property_lock);
320 g_object_notify (G_OBJECT (extension), "identity");
324 * e_source_collection_get_calendar_enabled:
325 * @extension: an #ESourceCollection
327 * Returns whether calendar sources within the collection should be
330 * An #ECollectionBackend running within the registry D-Bus service will
331 * automatically synchronize any calendar sources it maintains with the
332 * #ESourceCollection:calendar-enabled property.
334 * Returns: whether calendar sources should be enabled
339 e_source_collection_get_calendar_enabled (ESourceCollection *extension)
341 g_return_val_if_fail (E_IS_SOURCE_COLLECTION (extension), FALSE);
343 return extension->priv->calendar_enabled;
347 * e_source_collection_set_calendar_enabled:
348 * @extension: an #ESourceCollection
349 * @calendar_enabled: whether calendar sources should be enabled
351 * Sets whether calendar sources within the collection should be enabled.
353 * An #ECollectionBackend running within the registry D-Bus service will
354 * automatically synchronize any calendar sources it maintains with the
355 * #ESourceCollection:calendar-enabled property.
357 * Calling this function from a registry service client has no effect until
358 * the change is submitted to the registry service through e_source_write(),
359 * but there should rarely be any need for clients to call this.
364 e_source_collection_set_calendar_enabled (ESourceCollection *extension,
365 gboolean calendar_enabled)
367 g_return_if_fail (E_IS_SOURCE_COLLECTION (extension));
369 if (extension->priv->calendar_enabled == calendar_enabled)
372 extension->priv->calendar_enabled = calendar_enabled;
374 g_object_notify (G_OBJECT (extension), "calendar-enabled");
378 * e_source_collection_get_contacts_enabled:
379 * @extension: an #ESourceCollection
381 * Returns whether address book sources within the collection should be
384 * An #ECollectionBackend running within the registry D-Bus service will
385 * automatically synchronize any address book sources it maintains with
386 * the #ESourceCollection:contacts-enabled property.
388 * Returns: whether address book sources should be enabled
393 e_source_collection_get_contacts_enabled (ESourceCollection *extension)
395 g_return_val_if_fail (E_IS_SOURCE_COLLECTION (extension), FALSE);
397 return extension->priv->contacts_enabled;
401 * e_source_collection_set_contacts_enabled:
402 * @extension: an #ESourceCollection
403 * @contacts_enabled: whether address book sources should be enabled
405 * Sets whether address book sources within the collection should be enabled.
407 * An #ECollectionBackend running within the registry D-Bus service will
408 * automatically synchronize any address book sources it maintains with
409 * the #ESourceCollection:contacts-enabled property.
411 * Calling this function from a registry service client has no effect until
412 * the change is submitted to the registry service through e_source_write(),
413 * but there should rarely be any need for clients to call this.
418 e_source_collection_set_contacts_enabled (ESourceCollection *extension,
419 gboolean contacts_enabled)
421 g_return_if_fail (E_IS_SOURCE_COLLECTION (extension));
423 if (extension->priv->contacts_enabled == contacts_enabled)
426 extension->priv->contacts_enabled = contacts_enabled;
428 g_object_notify (G_OBJECT (extension), "contacts-enabled");
432 * e_source_collection_get_mail_enabled:
433 * @extension: an #ESourceCollection
435 * Returns whether mail sources within the collection should be enabled.
437 * An #ECollectionBackend running within the registry D-Bus service will
438 * automatically synchronize any mail sources it maintains with the
439 * #ESourceCollection:mail-enabled property.
441 * Returns: whether mail sources should be enabled
446 e_source_collection_get_mail_enabled (ESourceCollection *extension)
448 g_return_val_if_fail (E_IS_SOURCE_COLLECTION (extension), FALSE);
450 return extension->priv->mail_enabled;
454 * e_source_collection_set_mail_enabled:
455 * @extension: an #ESourceCollection
456 * @mail_enabled: whether mail sources should be enabled
458 * Sets whether mail sources within the collection should be enabled.
460 * An #ECollectionBackend running within the registry D-Bus service will
461 * automatically synchronize any mail sources it maintains with the
462 * #ESourceCollection:mail-enabled property.
464 * Calling this function from a registry service client has no effect until
465 * the changes is submitted to the registry service through e_source_write(),
466 * but there should rarely be any need for clients to call this.
471 e_source_collection_set_mail_enabled (ESourceCollection *extension,
472 gboolean mail_enabled)
474 g_return_if_fail (E_IS_SOURCE_COLLECTION (extension));
476 if (extension->priv->mail_enabled == mail_enabled)
479 extension->priv->mail_enabled = mail_enabled;
481 g_object_notify (G_OBJECT (extension), "mail-enabled");