2 * e-source-mail-account.c
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
20 * SECTION: e-source-mail-account
21 * @include: libedataserver/e-source-mail-account.h
22 * @short_description: #ESource extension for an email account
24 * The #ESourceMailAccount extension identifies the #ESource as a
25 * mail account and also links to a default "mail identity" to use.
26 * See #ESourceMailIdentity for more information about identities.
28 * Access the extension as follows:
31 * #include <libedataserver/e-source-mail-account.h>
33 * ESourceMailAccount *extension;
35 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
39 #include "e-source-mail-account.h"
41 #include <libedataserver/e-source-enumtypes.h>
42 #include <libedataserver/e-source-mail-identity.h>
44 #define E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE(obj) \
45 (G_TYPE_INSTANCE_GET_PRIVATE \
46 ((obj), E_TYPE_SOURCE_MAIL_ACCOUNT, ESourceMailAccountPrivate))
48 struct _ESourceMailAccountPrivate {
49 GMutex *property_lock;
60 e_source_mail_account,
61 E_TYPE_SOURCE_BACKEND)
64 source_mail_account_set_property (GObject *object,
69 switch (property_id) {
70 case PROP_IDENTITY_UID:
71 e_source_mail_account_set_identity_uid (
72 E_SOURCE_MAIL_ACCOUNT (object),
73 g_value_get_string (value));
77 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
81 source_mail_account_get_property (GObject *object,
86 switch (property_id) {
87 case PROP_IDENTITY_UID:
90 e_source_mail_account_dup_identity_uid (
91 E_SOURCE_MAIL_ACCOUNT (object)));
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
99 source_mail_account_finalize (GObject *object)
101 ESourceMailAccountPrivate *priv;
103 priv = E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE (object);
105 g_mutex_free (priv->property_lock);
107 g_free (priv->identity_uid);
109 /* Chain up to parent's finalize() method. */
110 G_OBJECT_CLASS (e_source_mail_account_parent_class)->finalize (object);
114 e_source_mail_account_class_init (ESourceMailAccountClass *class)
116 GObjectClass *object_class;
117 ESourceExtensionClass *extension_class;
119 g_type_class_add_private (class, sizeof (ESourceMailAccountPrivate));
121 object_class = G_OBJECT_CLASS (class);
122 object_class->set_property = source_mail_account_set_property;
123 object_class->get_property = source_mail_account_get_property;
124 object_class->finalize = source_mail_account_finalize;
126 extension_class = E_SOURCE_EXTENSION_CLASS (class);
127 extension_class->name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
129 g_object_class_install_property (
132 g_param_spec_string (
135 "ESource UID of a Mail Identity",
139 G_PARAM_STATIC_STRINGS |
140 E_SOURCE_PARAM_SETTING));
144 e_source_mail_account_init (ESourceMailAccount *extension)
146 extension->priv = E_SOURCE_MAIL_ACCOUNT_GET_PRIVATE (extension);
147 extension->priv->property_lock = g_mutex_new ();
151 * e_source_mail_account_get_identity_uid:
152 * @extension: an #ESourceMailAccount
154 * Returns the #ESource:uid of the #ESource that describes the mail
155 * identity to be used for this account.
157 * Returns: the mail identity #ESource:uid
162 e_source_mail_account_get_identity_uid (ESourceMailAccount *extension)
164 g_return_val_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension), NULL);
166 return extension->priv->identity_uid;
170 * e_source_mail_account_dup_identity_uid:
171 * @extension: an #ESourceMailAccount
173 * Thread-safe variation of e_source_mail_account_get_identity_uid().
174 * Use this function when accessing @extension from multiple threads.
176 * The returned string should be freed with g_free() when no longer needed.
178 * Returns: a newly-allocated copy of #ESourceMailAccount:identity-uid
183 e_source_mail_account_dup_identity_uid (ESourceMailAccount *extension)
185 const gchar *protected;
188 g_return_val_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension), NULL);
190 g_mutex_lock (extension->priv->property_lock);
192 protected = e_source_mail_account_get_identity_uid (extension);
193 duplicate = g_strdup (protected);
195 g_mutex_unlock (extension->priv->property_lock);
201 * e_source_mail_account_set_identity_uid:
202 * @extension: an #ESourceMailAccount
203 * @identity_uid: (allow-none): the mail identity #ESource:uid, or %NULL
205 * Sets the #ESource:uid of the #ESource that describes the mail
206 * identity to be used for this account.
211 e_source_mail_account_set_identity_uid (ESourceMailAccount *extension,
212 const gchar *identity_uid)
214 g_return_if_fail (E_IS_SOURCE_MAIL_ACCOUNT (extension));
216 g_mutex_lock (extension->priv->property_lock);
218 g_free (extension->priv->identity_uid);
219 extension->priv->identity_uid = g_strdup (identity_uid);
221 g_mutex_unlock (extension->priv->property_lock);
223 g_object_notify (G_OBJECT (extension), "identity-uid");