2 * e-source-selectable.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-selectable
21 * @include: libedataserver/e-source-selectable.h
22 * @short_description: Base class for selectable data sources
23 * @see_also: #ESourceAddressBook, #ESourceCalendar, #ESourceMemoList,
26 * #ESourceSelectable is an abstract base class for data sources
27 * that can be selected in an #ESourceSelector or similar widget.
30 #include "e-source-selectable.h"
32 #include <libedataserver/e-data-server-util.h>
34 #define E_SOURCE_SELECTABLE_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE \
36 ((obj), E_TYPE_SOURCE_SELECTABLE, ESourceSelectablePrivate))
38 struct _ESourceSelectablePrivate {
39 GMutex *property_lock;
50 G_DEFINE_ABSTRACT_TYPE (
53 E_TYPE_SOURCE_BACKEND)
56 source_selectable_set_property (GObject *object,
61 switch (property_id) {
63 e_source_selectable_set_color (
64 E_SOURCE_SELECTABLE (object),
65 g_value_get_string (value));
69 e_source_selectable_set_selected (
70 E_SOURCE_SELECTABLE (object),
71 g_value_get_boolean (value));
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
79 source_selectable_get_property (GObject *object,
84 switch (property_id) {
88 e_source_selectable_dup_color (
89 E_SOURCE_SELECTABLE (object)));
95 e_source_selectable_get_selected (
96 E_SOURCE_SELECTABLE (object)));
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
104 source_selectable_finalize (GObject *object)
106 ESourceSelectablePrivate *priv;
108 priv = E_SOURCE_SELECTABLE_GET_PRIVATE (object);
110 g_mutex_free (priv->property_lock);
112 g_free (priv->color);
114 /* Chain up to parent's finalize() method. */
115 G_OBJECT_CLASS (e_source_selectable_parent_class)->finalize (object);
119 e_source_selectable_class_init (ESourceSelectableClass *class)
121 GObjectClass *object_class;
123 g_type_class_add_private (class, sizeof (ESourceSelectablePrivate));
125 object_class = G_OBJECT_CLASS (class);
126 object_class->set_property = source_selectable_set_property;
127 object_class->get_property = source_selectable_get_property;
128 object_class->finalize = source_selectable_finalize;
130 /* We do not provide an extension name,
131 * which is why the class is abstract. */
133 g_object_class_install_property (
136 g_param_spec_string (
139 "Textual specification of a color",
143 G_PARAM_STATIC_STRINGS |
144 E_SOURCE_PARAM_SETTING));
146 g_object_class_install_property (
149 g_param_spec_boolean (
152 "Whether the data source is selected",
156 G_PARAM_STATIC_STRINGS |
157 E_SOURCE_PARAM_SETTING));
161 e_source_selectable_init (ESourceSelectable *extension)
163 extension->priv = E_SOURCE_SELECTABLE_GET_PRIVATE (extension);
164 extension->priv->property_lock = g_mutex_new ();
168 * e_source_selectable_get_color:
169 * @extension: an #ESourceSelectable
171 * Returns the color specification for the #ESource to which @extension
172 * belongs. A colored block is often displayed next to the data source's
173 * display name in user interfaces.
175 * Returns: the color specification for the #ESource
180 e_source_selectable_get_color (ESourceSelectable *extension)
182 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), NULL);
184 return extension->priv->color;
188 * e_source_selectable_dup_color:
189 * @extension: an #ESourceSelectable
191 * Thread-safe variation of e_source_selectable_get_color().
192 * Use this function when accessing @extension from multiple threads.
194 * The returned string should be freed with g_free() when no longer needed.
196 * Returns: a newly-allocated copy of #ESourceSelectable:color
201 e_source_selectable_dup_color (ESourceSelectable *extension)
203 const gchar *protected;
206 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), NULL);
208 g_mutex_lock (extension->priv->property_lock);
210 protected = e_source_selectable_get_color (extension);
211 duplicate = g_strdup (protected);
213 g_mutex_unlock (extension->priv->property_lock);
219 * e_source_selectable_set_color:
220 * @extension: an #ESourceSelectable
221 * @color: (allow-none): a color specification, or %NULL
223 * Sets the color specification for the #ESource to which @extension
224 * belongs. A colored block is often displayed next to the data source's
225 * display name in user interfaces.
227 * The internal copy of @color is automatically stripped of leading and
228 * trailing whitespace. If the resulting string is empty, %NULL is set
234 e_source_selectable_set_color (ESourceSelectable *extension,
237 g_return_if_fail (E_IS_SOURCE_SELECTABLE (extension));
239 g_mutex_lock (extension->priv->property_lock);
241 g_free (extension->priv->color);
242 extension->priv->color = e_util_strdup_strip (color);
244 g_mutex_unlock (extension->priv->property_lock);
246 g_object_notify (G_OBJECT (extension), "color");
250 * e_source_selectable_get_selected:
251 * @extension: an #ESourceSelectable
253 * Returns the selected state of the #ESource to which @extension belongs.
254 * The selected state is often represented as a checkbox next to the data
255 * source's display name in user interfaces.
257 * Returns: the selected state for the #ESource
262 e_source_selectable_get_selected (ESourceSelectable *extension)
264 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), FALSE);
266 return extension->priv->selected;
270 * e_source_selectable_set_selected:
271 * @extension: an #ESourceSelectable
272 * @selected: selected state
274 * Sets the selected state for the #ESource to which @extension belongs.
275 * The selected state is often represented as a checkbox next to the data
276 * source's display name in user interfaces.
281 e_source_selectable_set_selected (ESourceSelectable *extension,
284 g_return_if_fail (E_IS_SOURCE_SELECTABLE (extension));
286 extension->priv->selected = selected;
288 g_object_notify (G_OBJECT (extension), "selected");