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/libedataserver.h
22 * @short_description: Base class for selectable data sources
23 * @see_also: #ESourceCalendar, #ESourceMemoList, #ESourceTaskList
25 * #ESourceSelectable is an abstract base class for data sources
26 * that can be selected in an #ESourceSelector or similar widget.
29 #include "e-source-selectable.h"
31 #include <libedataserver/e-data-server-util.h>
33 #define E_SOURCE_SELECTABLE_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE \
35 ((obj), E_TYPE_SOURCE_SELECTABLE, ESourceSelectablePrivate))
37 struct _ESourceSelectablePrivate {
49 G_DEFINE_ABSTRACT_TYPE (
52 E_TYPE_SOURCE_BACKEND)
55 source_selectable_set_property (GObject *object,
60 switch (property_id) {
62 e_source_selectable_set_color (
63 E_SOURCE_SELECTABLE (object),
64 g_value_get_string (value));
68 e_source_selectable_set_selected (
69 E_SOURCE_SELECTABLE (object),
70 g_value_get_boolean (value));
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
78 source_selectable_get_property (GObject *object,
83 switch (property_id) {
87 e_source_selectable_dup_color (
88 E_SOURCE_SELECTABLE (object)));
94 e_source_selectable_get_selected (
95 E_SOURCE_SELECTABLE (object)));
99 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
103 source_selectable_finalize (GObject *object)
105 ESourceSelectablePrivate *priv;
107 priv = E_SOURCE_SELECTABLE_GET_PRIVATE (object);
109 g_mutex_clear (&priv->property_lock);
111 g_free (priv->color);
113 /* Chain up to parent's finalize() method. */
114 G_OBJECT_CLASS (e_source_selectable_parent_class)->finalize (object);
118 e_source_selectable_class_init (ESourceSelectableClass *class)
120 GObjectClass *object_class;
122 g_type_class_add_private (class, sizeof (ESourceSelectablePrivate));
124 object_class = G_OBJECT_CLASS (class);
125 object_class->set_property = source_selectable_set_property;
126 object_class->get_property = source_selectable_get_property;
127 object_class->finalize = source_selectable_finalize;
129 /* We do not provide an extension name,
130 * which is why the class is abstract. */
132 g_object_class_install_property (
135 g_param_spec_string (
138 "Textual specification of a color",
142 G_PARAM_STATIC_STRINGS |
143 E_SOURCE_PARAM_SETTING));
145 g_object_class_install_property (
148 g_param_spec_boolean (
151 "Whether the data source is selected",
155 G_PARAM_STATIC_STRINGS |
156 E_SOURCE_PARAM_SETTING));
160 e_source_selectable_init (ESourceSelectable *extension)
162 extension->priv = E_SOURCE_SELECTABLE_GET_PRIVATE (extension);
163 g_mutex_init (&extension->priv->property_lock);
167 * e_source_selectable_get_color:
168 * @extension: an #ESourceSelectable
170 * Returns the color specification for the #ESource to which @extension
171 * belongs. A colored block is often displayed next to the data source's
172 * display name in user interfaces.
174 * Returns: the color specification for the #ESource
179 e_source_selectable_get_color (ESourceSelectable *extension)
181 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), NULL);
183 return extension->priv->color;
187 * e_source_selectable_dup_color:
188 * @extension: an #ESourceSelectable
190 * Thread-safe variation of e_source_selectable_get_color().
191 * Use this function when accessing @extension from multiple threads.
193 * The returned string should be freed with g_free() when no longer needed.
195 * Returns: a newly-allocated copy of #ESourceSelectable:color
200 e_source_selectable_dup_color (ESourceSelectable *extension)
202 const gchar *protected;
205 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), NULL);
207 g_mutex_lock (&extension->priv->property_lock);
209 protected = e_source_selectable_get_color (extension);
210 duplicate = g_strdup (protected);
212 g_mutex_unlock (&extension->priv->property_lock);
218 * e_source_selectable_set_color:
219 * @extension: an #ESourceSelectable
220 * @color: (allow-none): a color specification, or %NULL
222 * Sets the color specification for the #ESource to which @extension
223 * belongs. A colored block is often displayed next to the data source's
224 * display name in user interfaces.
226 * The internal copy of @color is automatically stripped of leading and
227 * trailing whitespace. If the resulting string is empty, %NULL is set
233 e_source_selectable_set_color (ESourceSelectable *extension,
236 g_return_if_fail (E_IS_SOURCE_SELECTABLE (extension));
238 g_mutex_lock (&extension->priv->property_lock);
240 if (g_strcmp0 (extension->priv->color, color) == 0) {
241 g_mutex_unlock (&extension->priv->property_lock);
245 g_free (extension->priv->color);
246 extension->priv->color = e_util_strdup_strip (color);
248 g_mutex_unlock (&extension->priv->property_lock);
250 g_object_notify (G_OBJECT (extension), "color");
254 * e_source_selectable_get_selected:
255 * @extension: an #ESourceSelectable
257 * Returns the selected state of the #ESource to which @extension belongs.
258 * The selected state is often represented as a checkbox next to the data
259 * source's display name in user interfaces.
261 * Returns: the selected state for the #ESource
266 e_source_selectable_get_selected (ESourceSelectable *extension)
268 g_return_val_if_fail (E_IS_SOURCE_SELECTABLE (extension), FALSE);
270 return extension->priv->selected;
274 * e_source_selectable_set_selected:
275 * @extension: an #ESourceSelectable
276 * @selected: selected state
278 * Sets the selected state for the #ESource to which @extension belongs.
279 * The selected state is often represented as a checkbox next to the data
280 * source's display name in user interfaces.
285 e_source_selectable_set_selected (ESourceSelectable *extension,
288 g_return_if_fail (E_IS_SOURCE_SELECTABLE (extension));
290 if (extension->priv->selected == selected)
293 extension->priv->selected = selected;
295 g_object_notify (G_OBJECT (extension), "selected");