2 * e-source-mail-account.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-mail-account
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for an email account
23 * The #ESourceMailAccount extension identifies the #ESource as a
24 * mail account and also links to a default "mail identity" to use.
25 * See #ESourceMailIdentity for more information about identities.
27 * Access the extension as follows:
30 * #include <libedataserver/libedataserver.h>
32 * ESourceMailAccount *extension;
34 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
38 #include "e-source-mail-account.h"
40 #include <libedataserver/e-source-enumtypes.h>
41 #include <libedataserver/e-source-mail-identity.h>
43 #define E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE(obj) \
44 (G_TYPE_INSTANCE_GET_PRIVATE \
45 ((obj), E_TYPE_SOURCE_MAIL_ACCOUNT, ESourceMailAccountPrivate))
47 struct _ESourceMailAccountPrivate {
59 e_source_mail_account,
60 E_TYPE_SOURCE_BACKEND)
63 source_mail_account_set_property (GObject *object,
68 switch (property_id) {
69 case PROP_IDENTITY_UID:
70 e_source_mail_account_set_identity_uid (
71 E_SOURCE_MAIL_ACCOUNT (object),
72 g_value_get_string (value));
76 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
80 source_mail_account_get_property (GObject *object,
85 switch (property_id) {
86 case PROP_IDENTITY_UID:
89 e_source_mail_account_dup_identity_uid (
90 E_SOURCE_MAIL_ACCOUNT (object)));
94 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98 source_mail_account_finalize (GObject *object)
100 ESourceMailAccountPrivate *priv;
102 priv = E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE (object);
104 g_mutex_clear (&priv->property_lock);
106 g_free (priv->identity_uid);
108 /* Chain up to parent's finalize() method. */
109 G_OBJECT_CLASS (e_source_mail_account_parent_class)->finalize (object);
113 e_source_mail_account_class_init (ESourceMailAccountClass *class)
115 GObjectClass *object_class;
116 ESourceExtensionClass *extension_class;
118 g_type_class_add_private (class, sizeof (ESourceMailAccountPrivate));
120 object_class = G_OBJECT_CLASS (class);
121 object_class->set_property = source_mail_account_set_property;
122 object_class->get_property = source_mail_account_get_property;
123 object_class->finalize = source_mail_account_finalize;
125 extension_class = E_SOURCE_EXTENSION_CLASS (class);
126 extension_class->name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
128 g_object_class_install_property (
131 g_param_spec_string (
134 "ESource UID of a Mail Identity",
138 G_PARAM_STATIC_STRINGS |
139 E_SOURCE_PARAM_SETTING));
143 e_source_mail_account_init (ESourceMailAccount *extension)
145 extension->priv = E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE (extension);
146 g_mutex_init (&extension->priv->property_lock);
150 * e_source_mail_account_get_identity_uid:
151 * @extension: an #ESourceMailAccount
153 * Returns the #ESource:uid of the #ESource that describes the mail
154 * identity to be used for this account.
156 * Returns: the mail identity #ESource:uid
161 e_source_mail_account_get_identity_uid (ESourceMailAccount *extension)
163 g_return_val_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension), NULL);
165 return extension->priv->identity_uid;
169 * e_source_mail_account_dup_identity_uid:
170 * @extension: an #ESourceMailAccount
172 * Thread-safe variation of e_source_mail_account_get_identity_uid().
173 * Use this function when accessing @extension from multiple threads.
175 * The returned string should be freed with g_free() when no longer needed.
177 * Returns: a newly-allocated copy of #ESourceMailAccount:identity-uid
182 e_source_mail_account_dup_identity_uid (ESourceMailAccount *extension)
184 const gchar *protected;
187 g_return_val_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension), NULL);
189 g_mutex_lock (&extension->priv->property_lock);
191 protected = e_source_mail_account_get_identity_uid (extension);
192 duplicate = g_strdup (protected);
194 g_mutex_unlock (&extension->priv->property_lock);
200 * e_source_mail_account_set_identity_uid:
201 * @extension: an #ESourceMailAccount
202 * @identity_uid: (allow-none): the mail identity #ESource:uid, or %NULL
204 * Sets the #ESource:uid of the #ESource that describes the mail
205 * identity to be used for this account.
210 e_source_mail_account_set_identity_uid (ESourceMailAccount *extension,
211 const gchar *identity_uid)
213 g_return_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension));
215 g_mutex_lock (&extension->priv->property_lock);
217 if (g_strcmp0 (extension->priv->identity_uid, identity_uid) == 0) {
218 g_mutex_unlock (&extension->priv->property_lock);
222 g_free (extension->priv->identity_uid);
223 extension->priv->identity_uid = g_strdup (identity_uid);
225 g_mutex_unlock (&extension->priv->property_lock);
227 g_object_notify (G_OBJECT (extension), "identity-uid");