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/>
21 * @short_description: an abstract base class for backends
22 * @include: libebackend/e-backend.h
24 * An #EBackend is paired with an #ESource to facilitate performing
25 * actions on the local or remote resource described by the #ESource.
27 * In other words, whereas a certain backend type knows how to talk to a
28 * certain type of server or data store, the #ESource fills in configuration
29 * details such as host name, user name, resource path, etc.
31 * All #EBackend instances are created by an #EBackendFactory.
34 #include "e-backend.h"
39 #define E_BACKEND_GET_PRIVATE(obj) \
40 (G_TYPE_INSTANCE_GET_PRIVATE \
41 ((obj), E_TYPE_BACKEND, EBackendPrivate))
43 struct _EBackendPrivate {
54 G_DEFINE_ABSTRACT_TYPE (EBackend, e_backend, G_TYPE_OBJECT)
57 backend_set_source (EBackend *backend,
60 g_return_if_fail (E_IS_SOURCE (source));
61 g_return_if_fail (backend->priv->source == NULL);
63 backend->priv->source = g_object_ref (source);
67 backend_set_property (GObject *object,
72 switch (property_id) {
74 e_backend_set_online (
76 g_value_get_boolean (value));
82 g_value_get_object (value));
86 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
90 backend_get_property (GObject *object,
95 switch (property_id) {
98 value, e_backend_get_online (
104 value, e_backend_get_source (
105 E_BACKEND (object)));
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113 backend_dispose (GObject *object)
115 EBackendPrivate *priv;
117 priv = E_BACKEND_GET_PRIVATE (object);
119 if (priv->source != NULL) {
120 g_object_unref (priv->source);
124 /* Chain up to parent's dispose() method. */
125 G_OBJECT_CLASS (e_backend_parent_class)->dispose (object);
129 backend_constructed (GObject *object)
131 GNetworkMonitor *monitor;
133 /* Chain up to parent's constructed() method. */
134 G_OBJECT_CLASS (e_backend_parent_class)->constructed (object);
136 /* Synchronize network monitoring. */
138 monitor = g_network_monitor_get_default ();
140 g_object_bind_property (
141 monitor, "network-available",
143 G_BINDING_SYNC_CREATE);
147 e_backend_class_init (EBackendClass *class)
149 GObjectClass *object_class;
151 g_type_class_add_private (class, sizeof (EBackendPrivate));
153 object_class = G_OBJECT_CLASS (class);
154 object_class->set_property = backend_set_property;
155 object_class->get_property = backend_get_property;
156 object_class->dispose = backend_dispose;
157 object_class->constructed = backend_constructed;
159 g_object_class_install_property (
162 g_param_spec_boolean (
165 "Whether the backend is online",
169 G_PARAM_STATIC_STRINGS));
171 g_object_class_install_property (
174 g_param_spec_object (
177 "The data source being acted upon",
180 G_PARAM_CONSTRUCT_ONLY |
181 G_PARAM_STATIC_STRINGS));
185 e_backend_init (EBackend *backend)
187 backend->priv = E_BACKEND_GET_PRIVATE (backend);
191 * e_backend_get_online:
192 * @backend: an #EBackend
194 * Returns the online state of @backend: %TRUE if @backend is online,
195 * %FALSE if offline. The online state of each backend is bound to the
196 * online state of the #EDataFactory that created it.
198 * Returns: the online state
203 e_backend_get_online (EBackend *backend)
205 g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
207 return backend->priv->online;
211 * e_backend_set_online:
212 * @backend: an #EBackend
213 * @online: the online state
215 * Sets the online state of @backend: %TRUE if @backend is online,
216 * @FALSE if offline. The online state of each backend is bound to
217 * the online state of the #EDataFactory that created it.
222 e_backend_set_online (EBackend *backend,
225 g_return_if_fail (E_IS_BACKEND (backend));
227 /* Avoid unnecessary "notify" signals. */
228 if (online == backend->priv->online)
231 backend->priv->online = online;
233 g_object_notify (G_OBJECT (backend), "online");
237 * e_backend_get_source:
238 * @backend: an #EBackend
240 * Returns the #ESource to which @backend is paired.
242 * Returns: the #ESource to which @backend is paired
247 e_backend_get_source (EBackend *backend)
249 g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
251 return backend->priv->source;