1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
/*
* camel-local-settings.c
*
* This library is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "camel-local-settings.h"
#include <string.h>
struct _CamelLocalSettingsPrivate {
GMutex property_lock;
gchar *path;
gboolean filter_all;
gboolean filter_junk;
gboolean maildir_alt_flag_sep;
};
enum {
PROP_0,
PROP_FILTER_ALL,
PROP_FILTER_JUNK,
PROP_MAILDIR_ALT_FLAG_SEP,
PROP_PATH
};
G_DEFINE_TYPE_WITH_PRIVATE (
CamelLocalSettings,
camel_local_settings,
CAMEL_TYPE_STORE_SETTINGS)
static void
local_settings_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_FILTER_ALL:
camel_local_settings_set_filter_all (
CAMEL_LOCAL_SETTINGS (object),
g_value_get_boolean (value));
return;
case PROP_FILTER_JUNK:
camel_local_settings_set_filter_junk (
CAMEL_LOCAL_SETTINGS (object),
g_value_get_boolean (value));
return;
case PROP_MAILDIR_ALT_FLAG_SEP:
camel_local_settings_set_maildir_alt_flag_sep (
CAMEL_LOCAL_SETTINGS (object),
g_value_get_boolean (value));
return;
case PROP_PATH:
camel_local_settings_set_path (
CAMEL_LOCAL_SETTINGS (object),
g_value_get_string (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
local_settings_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_FILTER_ALL:
g_value_set_boolean (
value,
camel_local_settings_get_filter_all (
CAMEL_LOCAL_SETTINGS (object)));
return;
case PROP_FILTER_JUNK:
g_value_set_boolean (
value,
camel_local_settings_get_filter_junk (
CAMEL_LOCAL_SETTINGS (object)));
return;
case PROP_MAILDIR_ALT_FLAG_SEP:
g_value_set_boolean (
value,
camel_local_settings_get_maildir_alt_flag_sep (
CAMEL_LOCAL_SETTINGS (object)));
return;
case PROP_PATH:
g_value_take_string (
value,
camel_local_settings_dup_path (
CAMEL_LOCAL_SETTINGS (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
local_settings_finalize (GObject *object)
{
CamelLocalSettingsPrivate *priv;
priv = CAMEL_LOCAL_SETTINGS (object)->priv;
g_mutex_clear (&priv->property_lock);
g_free (priv->path);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (camel_local_settings_parent_class)->finalize (object);
}
static void
camel_local_settings_class_init (CamelLocalSettingsClass *class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (class);
object_class->set_property = local_settings_set_property;
object_class->get_property = local_settings_get_property;
object_class->finalize = local_settings_finalize;
g_object_class_install_property (
object_class,
PROP_PATH,
g_param_spec_string (
"path",
"Path",
"File path to the local store",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_FILTER_ALL,
g_param_spec_boolean (
"filter-all",
"Filter All",
"Whether to apply filters in all folders",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_FILTER_JUNK,
g_param_spec_boolean (
"filter-junk",
"Filter Junk",
"Whether to check new messages for junk",
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_MAILDIR_ALT_FLAG_SEP,
g_param_spec_boolean (
"maildir-alt-flag-sep",
"Maildir Alt Flag Sep",
"Whether to use alternative flag separator in Maildir file name",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));
}
static void
camel_local_settings_init (CamelLocalSettings *settings)
{
settings->priv = camel_local_settings_get_instance_private (settings);
g_mutex_init (&settings->priv->property_lock);
}
/**
* camel_local_settings_get_path:
* @settings: a #CamelLocalSettings
*
* Returns the file path to the root of the local mail store.
*
* Returns: the file path to the local store
*
* Since: 3.4
**/
const gchar *
camel_local_settings_get_path (CamelLocalSettings *settings)
{
g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), NULL);
return settings->priv->path;
}
/**
* camel_local_settings_dup_path:
* @settings: a #CamelLocalSettings
*
* Thread-safe variation of camel_local_settings_get_path().
* Use this function when accessing @settings from multiple threads.
*
* The returned string should be freed with g_free() when no longer needed.
*
* Returns: a newly-allocated copy of #CamelLocalSettings:path
*
* Since: 3.4
**/
gchar *
camel_local_settings_dup_path (CamelLocalSettings *settings)
{
const gchar *protected;
gchar *duplicate;
g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), NULL);
g_mutex_lock (&settings->priv->property_lock);
protected = camel_local_settings_get_path (settings);
duplicate = g_strdup (protected);
g_mutex_unlock (&settings->priv->property_lock);
return duplicate;
}
/**
* camel_local_settings_set_path:
* @settings: a #CamelLocalSettings
* @path: the file path to the local store
*
* Sets the file path to the root of the local mail store. Any
* trailing directory separator characters will be stripped off
* of the #CamelLocalSettings:path property.
*
* Since: 3.4
**/
void
camel_local_settings_set_path (CamelLocalSettings *settings,
const gchar *path)
{
gsize length = 0;
gchar *new_path;
g_return_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings));
/* Exclude trailing directory separators. */
if (path != NULL) {
length = strlen (path);
while (length > 0) {
if (G_IS_DIR_SEPARATOR (path[length - 1]))
length--;
else
break;
}
}
g_mutex_lock (&settings->priv->property_lock);
new_path = g_strndup (path, length);
if (g_strcmp0 (settings->priv->path, new_path) == 0) {
g_mutex_unlock (&settings->priv->property_lock);
g_free (new_path);
return;
}
g_free (settings->priv->path);
settings->priv->path = new_path;
g_mutex_unlock (&settings->priv->property_lock);
g_object_notify (G_OBJECT (settings), "path");
}
/**
* camel_local_settings_get_filter_all:
* @settings: a #CamelLocalSettings
*
* Returns whether apply filters in all folders.
*
* Returns: whether to apply filters in all folders
*
* Since: 3.24
**/
gboolean
camel_local_settings_get_filter_all (CamelLocalSettings *settings)
{
g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), FALSE);
return settings->priv->filter_all;
}
/**
* camel_local_settings_set_filter_all:
* @settings: a #CamelLocalSettings
* @filter_all: whether to apply filters in all folders
*
* Sets whether to apply filters in all folders.
*
* Since: 3.24
**/
void
camel_local_settings_set_filter_all (CamelLocalSettings *settings,
gboolean filter_all)
{
g_return_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings));
if (settings->priv->filter_all == filter_all)
return;
settings->priv->filter_all = filter_all;
g_object_notify (G_OBJECT (settings), "filter-all");
}
/**
* camel_local_settings_get_filter_junk:
* @settings: a #CamelLocalSettings
*
* Returns whether to check new messages for junk.
*
* Returns: whether to check new messages for junk
*
* Since: 3.24
**/
gboolean
camel_local_settings_get_filter_junk (CamelLocalSettings *settings)
{
g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), FALSE);
return settings->priv->filter_junk;
}
/**
* camel_local_settings_set_filter_junk:
* @settings: a #CamelLocalSettings
* @filter_junk: whether to check new messages for junk
*
* Sets whether to check new messages for junk.
*
* Since: 3.24
**/
void
camel_local_settings_set_filter_junk (CamelLocalSettings *settings,
gboolean filter_junk)
{
g_return_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings));
if (settings->priv->filter_junk == filter_junk)
return;
settings->priv->filter_junk = filter_junk;
g_object_notify (G_OBJECT (settings), "filter-junk");
}
/**
* camel_local_settings_get_maildir_alt_flag_sep:
* @settings: a #CamelLocalSettings
*
* Returns, whether the Maildir provider should use alternative
* flag separator in the file name. When %TRUE, uses an exclamation
* mark (!), when %FALSE, uses the colon (:). The default
* is %FALSE, to be consistent with the Maildir specification.
* The flag separator is flipped on the Windows build.
*
* Returns: whether the Maildir provider should use an alternative flag separator
*
* Since: 3.40
**/
gboolean
camel_local_settings_get_maildir_alt_flag_sep (CamelLocalSettings *settings)
{
g_return_val_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings), FALSE);
return settings->priv->maildir_alt_flag_sep;
}
/**
* camel_local_settings_set_maildir_alt_flag_sep:
* @settings: a #CamelLocalSettings
* @maildir_alt_flag_sep: value to set
*
* Sets whether Maildir should use alternative flag separator.
* See camel_local_settings_get_maildir_alt_flag_sep() for more
* information on what it means.
*
* Note: Change to this setting takes effect only for newly created
* Maildir stores.
*
* Since: 3.40
**/
void
camel_local_settings_set_maildir_alt_flag_sep (CamelLocalSettings *settings,
gboolean maildir_alt_flag_sep)
{
g_return_if_fail (CAMEL_IS_LOCAL_SETTINGS (settings));
if ((settings->priv->maildir_alt_flag_sep ? 1 : 0) == (maildir_alt_flag_sep ? 1 : 0))
return;
settings->priv->maildir_alt_flag_sep = maildir_alt_flag_sep;
g_object_notify (G_OBJECT (settings), "maildir-alt-flag-sep");
}
|