2 * camel-local-settings.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/>
19 #include "camel-local-settings.h"
23 #define CAMEL_LOCAL_SETTINGS_GET_PRIVATE(obj) \
24 (G_TYPE_INSTANCE_GET_PRIVATE \
25 ((obj), CAMEL_TYPE_LOCAL_SETTINGS, CamelLocalSettingsPrivate))
27 struct _CamelLocalSettingsPrivate {
40 CAMEL_TYPE_STORE_SETTINGS)
43 local_settings_set_property (GObject *object,
48 switch (property_id) {
50 camel_local_settings_set_path (
51 CAMEL_LOCAL_SETTINGS (object),
52 g_value_get_string (value));
56 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
60 local_settings_get_property (GObject *object,
65 switch (property_id) {
69 camel_local_settings_dup_path (
70 CAMEL_LOCAL_SETTINGS (object)));
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
78 local_settings_finalize (GObject *object)
80 CamelLocalSettingsPrivate *priv;
82 priv = CAMEL_LOCAL_SETTINGS_GET_PRIVATE (object);
84 g_mutex_clear (&priv->property_lock);
88 /* Chain up to parent's finalize() method. */
89 G_OBJECT_CLASS (camel_local_settings_parent_class)->finalize (object);
93 camel_local_settings_class_init (CamelLocalSettingsClass *class)
95 GObjectClass *object_class;
97 g_type_class_add_private (class, sizeof (CamelLocalSettingsPrivate));
99 object_class = G_OBJECT_CLASS (class);
100 object_class->set_property = local_settings_set_property;
101 object_class->get_property = local_settings_get_property;
102 object_class->finalize = local_settings_finalize;
104 g_object_class_install_property (
107 g_param_spec_string (
110 "File path to the local store",
114 G_PARAM_STATIC_STRINGS));
118 camel_local_settings_init (CamelLocalSettings *settings)
120 settings->priv = CAMEL_LOCAL_SETTINGS_GET_PRIVATE (settings);
121 g_mutex_init (&settings->priv->property_lock);
125 * camel_local_settings_get_path:
126 * @settings: a #CamelLocalSettings
128 * Returns the file path to the root of the local mail store.
130 * Returns: the file path to the local store
135 camel_local_settings_get_path (CamelLocalSettings *settings)
137 g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), NULL);
139 return settings->priv->path;
143 * camel_local_settings_dup_path:
144 * @settings: a #CamelLocalSettings
146 * Thread-safe variation of camel_local_settings_get_path().
147 * Use this function when accessing @settings from multiple threads.
149 * The returned string should be freed with g_free() when no longer needed.
151 * Returns: a newly-allocated copy of #CamelLocalSettings:path
156 camel_local_settings_dup_path (CamelLocalSettings *settings)
158 const gchar *protected;
161 g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), NULL);
163 g_mutex_lock (&settings->priv->property_lock);
165 protected = camel_local_settings_get_path (settings);
166 duplicate = g_strdup (protected);
168 g_mutex_unlock (&settings->priv->property_lock);
174 * camel_local_settings_set_path:
175 * @settings: a #CamelLocalSettings
176 * @path: the file path to the local store
178 * Sets the file path to the root of the local mail store. Any
179 * trailing directory separator characters will be stripped off
180 * of the #CamelLocalSettings:path property.
185 camel_local_settings_set_path (CamelLocalSettings *settings,
191 g_return_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings));
193 /* Exclude trailing directory separators. */
195 length = strlen (path);
197 if (G_IS_DIR_SEPARATOR (path[length - 1]))
204 g_mutex_lock (&settings->priv->property_lock);
206 new_path = g_strndup (path, length);
208 if (g_strcmp0 (settings->priv->path, new_path) == 0) {
209 g_mutex_unlock (&settings->priv->property_lock);
214 g_free (settings->priv->path);
215 settings->priv->path = new_path;
217 g_mutex_unlock (&settings->priv->property_lock);
219 g_object_notify (G_OBJECT (settings), "path");