Add new ESource classes.
[platform/upstream/evolution-data-server.git] / libedataserver / e-source-offline.c
1 /*
2  * e-source-offline.c
3  *
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.
8  *
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.
13  *
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/>
16  *
17  */
18
19 /**
20  * SECTION: e-source-offline
21  * @include: libedataserver/e-source-offline.h
22  * @short_description: #ESource extension for offline settings
23  *
24  * The #ESourceOffline extension tracks whether data from a remote
25  * server should be cached locally for viewing while offline.
26  *
27  * Access the extension as follows:
28  *
29  * |[
30  *   #include <libedataserver/e-source-offline.h>
31  *
32  *   ESourceOffline *extension;
33  *
34  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_OFFLINE);
35  * ]|
36  **/
37
38 #include "e-source-offline.h"
39
40 #define E_SOURCE_OFFLINE_GET_PRIVATE(obj) \
41         (G_TYPE_INSTANCE_GET_PRIVATE \
42         ((obj), E_TYPE_SOURCE_OFFLINE, ESourceOfflinePrivate))
43
44 struct _ESourceOfflinePrivate {
45         gboolean stay_synchronized;
46 };
47
48 enum {
49         PROP_0,
50         PROP_STAY_SYNCHRONIZED
51 };
52
53 G_DEFINE_TYPE (
54         ESourceOffline,
55         e_source_offline,
56         E_TYPE_SOURCE_EXTENSION)
57
58 static void
59 source_offline_set_property (GObject *object,
60                              guint property_id,
61                              const GValue *value,
62                              GParamSpec *pspec)
63 {
64         switch (property_id) {
65                 case PROP_STAY_SYNCHRONIZED:
66                         e_source_offline_set_stay_synchronized (
67                                 E_SOURCE_OFFLINE (object),
68                                 g_value_get_boolean (value));
69                         return;
70         }
71
72         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
73 }
74
75 static void
76 source_offline_get_property (GObject *object,
77                              guint property_id,
78                              GValue *value,
79                              GParamSpec *pspec)
80 {
81         switch (property_id) {
82                 case PROP_STAY_SYNCHRONIZED:
83                         g_value_set_boolean (
84                                 value,
85                                 e_source_offline_get_stay_synchronized (
86                                 E_SOURCE_OFFLINE (object)));
87                         return;
88         }
89
90         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
91 }
92
93 static void
94 e_source_offline_class_init (ESourceOfflineClass *class)
95 {
96         GObjectClass *object_class;
97         ESourceExtensionClass *extension_class;
98
99         g_type_class_add_private (class, sizeof (ESourceOfflinePrivate));
100
101         object_class = G_OBJECT_CLASS (class);
102         object_class->set_property = source_offline_set_property;
103         object_class->get_property = source_offline_get_property;
104
105         extension_class = E_SOURCE_EXTENSION_CLASS (class);
106         extension_class->name = E_SOURCE_EXTENSION_OFFLINE;
107
108         g_object_class_install_property (
109                 object_class,
110                 PROP_STAY_SYNCHRONIZED,
111                 g_param_spec_boolean (
112                         "stay-synchronized",
113                         "StaySynchronized",
114                         "Keep remote content synchronized locally",
115                         FALSE,
116                         G_PARAM_READWRITE |
117                         G_PARAM_CONSTRUCT |
118                         G_PARAM_STATIC_STRINGS |
119                         E_SOURCE_PARAM_SETTING));
120 }
121
122 static void
123 e_source_offline_init (ESourceOffline *extension)
124 {
125         extension->priv = E_SOURCE_OFFLINE_GET_PRIVATE (extension);
126 }
127
128 /**
129  * e_source_offline_get_stay_synchronized:
130  * @extension: an #ESourceOffline
131  *
132  * Returns whether data from a remote server should be cached locally
133  * for viewing while offline.  Backends are responsible for implementing
134  * such caching.
135  *
136  * Returns: whether data should be cached for offline
137  *
138  * Since: 3.6
139  **/
140 gboolean
141 e_source_offline_get_stay_synchronized (ESourceOffline *extension)
142 {
143         g_return_val_if_fail (E_IS_SOURCE_OFFLINE (extension), FALSE);
144
145         return extension->priv->stay_synchronized;
146 }
147
148 /**
149  * e_source_offline_set_stay_synchronized:
150  * @extension: an #ESourceOffline
151  * @stay_synchronized: whether data should be cached for offline
152  *
153  * Sets whether data from a remote server should be cached locally for
154  * viewing while offline.  Backends are responsible for implementing
155  * such caching.
156  *
157  * Since: 3.6
158  **/
159 void
160 e_source_offline_set_stay_synchronized (ESourceOffline *extension,
161                                         gboolean stay_synchronized)
162 {
163         g_return_if_fail (E_IS_SOURCE_OFFLINE (extension));
164
165         extension->priv->stay_synchronized = stay_synchronized;
166
167         g_object_notify (G_OBJECT (extension), "stay-synchronized");
168 }