Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-offline-settings.c
1 /*
2  * camel-offline-settings.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 #include "camel-offline-settings.h"
20
21 #include <camel/camel-store-settings.h>
22
23 #define CAMEL_OFFLINE_SETTINGS_GET_PRIVATE(obj) \
24         (G_TYPE_INSTANCE_GET_PRIVATE \
25         ((obj), CAMEL_TYPE_OFFLINE_SETTINGS, CamelOfflineSettingsPrivate))
26
27 struct _CamelOfflineSettingsPrivate {
28         gboolean stay_synchronized;
29 };
30
31 enum {
32         PROP_0,
33         PROP_STAY_SYNCHRONIZED
34 };
35
36 G_DEFINE_TYPE (
37         CamelOfflineSettings,
38         camel_offline_settings,
39         CAMEL_TYPE_STORE_SETTINGS)
40
41 static void
42 offline_settings_set_property (GObject *object,
43                              guint property_id,
44                              const GValue *value,
45                              GParamSpec *pspec)
46 {
47         switch (property_id) {
48                 case PROP_STAY_SYNCHRONIZED:
49                         camel_offline_settings_set_stay_synchronized (
50                                 CAMEL_OFFLINE_SETTINGS (object),
51                                 g_value_get_boolean (value));
52                         return;
53         }
54
55         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
56 }
57
58 static void
59 offline_settings_get_property (GObject *object,
60                              guint property_id,
61                              GValue *value,
62                              GParamSpec *pspec)
63 {
64         switch (property_id) {
65                 case PROP_STAY_SYNCHRONIZED:
66                         g_value_set_boolean (
67                                 value,
68                                 camel_offline_settings_get_stay_synchronized (
69                                 CAMEL_OFFLINE_SETTINGS (object)));
70                         return;
71         }
72
73         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
74 }
75
76 static void
77 camel_offline_settings_class_init (CamelOfflineSettingsClass *class)
78 {
79         GObjectClass *object_class;
80
81         g_type_class_add_private (class, sizeof (CamelOfflineSettingsPrivate));
82
83         object_class = G_OBJECT_CLASS (class);
84         object_class->set_property = offline_settings_set_property;
85         object_class->get_property = offline_settings_get_property;
86
87         g_object_class_install_property (
88                 object_class,
89                 PROP_STAY_SYNCHRONIZED,
90                 g_param_spec_boolean (
91                         "stay-synchronized",
92                         "Stay Synchronized",
93                         "Stay synchronized with the remote server",
94                         FALSE,
95                         G_PARAM_READWRITE |
96                         G_PARAM_CONSTRUCT |
97                         G_PARAM_STATIC_STRINGS));
98 }
99
100 static void
101 camel_offline_settings_init (CamelOfflineSettings *settings)
102 {
103         settings->priv = CAMEL_OFFLINE_SETTINGS_GET_PRIVATE (settings);
104 }
105
106 /**
107  * camel_offline_settings_get_stay_synchronized:
108  * @settings: a #CamelOfflineSettings
109  *
110  * Returns whether to synchronize the local cache with the remote server
111  * before switching to offline mode, so the store's content can still be
112  * read while offline.
113  *
114  * Returns: whether to stay synchronized with the remote server
115  *
116  * Since: 3.2
117  **/
118 gboolean
119 camel_offline_settings_get_stay_synchronized (CamelOfflineSettings *settings)
120 {
121         g_return_val_if_fail (CAMEL_IS_OFFLINE_SETTINGS (settings), FALSE);
122
123         return settings->priv->stay_synchronized;
124 }
125
126 /**
127  * camel_offline_settings_set_stay_synchronized:
128  * @settings: a #CamelOfflineSettings
129  * @stay_synchronized: whether to stay synchronized with the remote server
130  *
131  * Sets whether to synchronize the local cache with the remote server before
132  * switching to offline mode, so the store's content can still be read while
133  * offline.
134  *
135  * Since: 3.2
136  **/
137 void
138 camel_offline_settings_set_stay_synchronized (CamelOfflineSettings *settings,
139                                               gboolean stay_synchronized)
140 {
141         g_return_if_fail (CAMEL_IS_OFFLINE_SETTINGS (settings));
142
143         if (settings->priv->stay_synchronized == stay_synchronized)
144                 return;
145
146         settings->priv->stay_synchronized = stay_synchronized;
147
148         g_object_notify (G_OBJECT (settings), "stay-synchronized");
149 }