updated changelog
[platform/upstream/evolution-data-server.git] / libedataserver / e-source-offline.c
1 /*
2  * e-source-offline.c
3  *
4  * This library is free software you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 /**
19  * SECTION: e-source-offline
20  * @include: libedataserver/libedataserver.h
21  * @short_description: #ESource extension for offline settings
22  *
23  * The #ESourceOffline extension tracks whether data from a remote
24  * server should be cached locally for viewing while offline.
25  *
26  * Access the extension as follows:
27  *
28  * |[
29  *   #include <libedataserver/libedataserver.h>
30  *
31  *   ESourceOffline *extension;
32  *
33  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_OFFLINE);
34  * ]|
35  **/
36
37 #include "e-source-offline.h"
38
39 #define E_SOURCE_OFFLINE_GET_PRIVATE(obj) \
40         (G_TYPE_INSTANCE_GET_PRIVATE \
41         ((obj), E_TYPE_SOURCE_OFFLINE, ESourceOfflinePrivate))
42
43 struct _ESourceOfflinePrivate {
44         gboolean stay_synchronized;
45 };
46
47 enum {
48         PROP_0,
49         PROP_STAY_SYNCHRONIZED
50 };
51
52 G_DEFINE_TYPE (
53         ESourceOffline,
54         e_source_offline,
55         E_TYPE_SOURCE_EXTENSION)
56
57 static void
58 source_offline_set_property (GObject *object,
59                              guint property_id,
60                              const GValue *value,
61                              GParamSpec *pspec)
62 {
63         switch (property_id) {
64                 case PROP_STAY_SYNCHRONIZED:
65                         e_source_offline_set_stay_synchronized (
66                                 E_SOURCE_OFFLINE (object),
67                                 g_value_get_boolean (value));
68                         return;
69         }
70
71         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72 }
73
74 static void
75 source_offline_get_property (GObject *object,
76                              guint property_id,
77                              GValue *value,
78                              GParamSpec *pspec)
79 {
80         switch (property_id) {
81                 case PROP_STAY_SYNCHRONIZED:
82                         g_value_set_boolean (
83                                 value,
84                                 e_source_offline_get_stay_synchronized (
85                                 E_SOURCE_OFFLINE (object)));
86                         return;
87         }
88
89         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
90 }
91
92 static void
93 e_source_offline_class_init (ESourceOfflineClass *class)
94 {
95         GObjectClass *object_class;
96         ESourceExtensionClass *extension_class;
97
98         g_type_class_add_private (class, sizeof (ESourceOfflinePrivate));
99
100         object_class = G_OBJECT_CLASS (class);
101         object_class->set_property = source_offline_set_property;
102         object_class->get_property = source_offline_get_property;
103
104         extension_class = E_SOURCE_EXTENSION_CLASS (class);
105         extension_class->name = E_SOURCE_EXTENSION_OFFLINE;
106
107         g_object_class_install_property (
108                 object_class,
109                 PROP_STAY_SYNCHRONIZED,
110                 g_param_spec_boolean (
111                         "stay-synchronized",
112                         "StaySynchronized",
113                         "Keep remote content synchronized locally",
114                         FALSE,
115                         G_PARAM_READWRITE |
116                         G_PARAM_CONSTRUCT |
117                         G_PARAM_STATIC_STRINGS |
118                         E_SOURCE_PARAM_SETTING));
119 }
120
121 static void
122 e_source_offline_init (ESourceOffline *extension)
123 {
124         extension->priv = E_SOURCE_OFFLINE_GET_PRIVATE (extension);
125 }
126
127 /**
128  * e_source_offline_get_stay_synchronized:
129  * @extension: an #ESourceOffline
130  *
131  * Returns whether data from a remote server should be cached locally
132  * for viewing while offline.  Backends are responsible for implementing
133  * such caching.
134  *
135  * Returns: whether data should be cached for offline
136  *
137  * Since: 3.6
138  **/
139 gboolean
140 e_source_offline_get_stay_synchronized (ESourceOffline *extension)
141 {
142         g_return_val_if_fail (E_IS_SOURCE_OFFLINE (extension), FALSE);
143
144         return extension->priv->stay_synchronized;
145 }
146
147 /**
148  * e_source_offline_set_stay_synchronized:
149  * @extension: an #ESourceOffline
150  * @stay_synchronized: whether data should be cached for offline
151  *
152  * Sets whether data from a remote server should be cached locally for
153  * viewing while offline.  Backends are responsible for implementing
154  * such caching.
155  *
156  * Since: 3.6
157  **/
158 void
159 e_source_offline_set_stay_synchronized (ESourceOffline *extension,
160                                         gboolean stay_synchronized)
161 {
162         g_return_if_fail (E_IS_SOURCE_OFFLINE (extension));
163
164         if (extension->priv->stay_synchronized == stay_synchronized)
165                 return;
166
167         extension->priv->stay_synchronized = stay_synchronized;
168
169         g_object_notify (G_OBJECT (extension), "stay-synchronized");
170 }