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
|
/*
* e-cal-source-config.c
*
* This program 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; either
* version 2 of the License, or (at your option) version 3.
*
* This program 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 the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include "e-cal-source-config.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <libedataserver/e-source-calendar.h>
#include <libedataserver/e-source-offline.h>
#include <e-util/e-util.h>
#define E_CAL_SOURCE_CONFIG_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_CAL_SOURCE_CONFIG, ECalSourceConfigPrivate))
struct _ECalSourceConfigPrivate {
ECalClientSourceType source_type;
GtkWidget *color_button;
GtkWidget *default_button;
};
enum {
PROP_0,
PROP_SOURCE_TYPE
};
G_DEFINE_TYPE (
ECalSourceConfig,
e_cal_source_config,
E_TYPE_SOURCE_CONFIG)
static ESource *
cal_source_config_get_default (ESourceConfig *config)
{
ECalSourceConfigPrivate *priv;
ESourceRegistry *registry;
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (config);
registry = e_source_config_get_registry (config);
if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS)
return e_source_registry_get_default_calendar (registry);
else if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_MEMOS)
return e_source_registry_get_default_memo_list (registry);
else if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_TASKS)
return e_source_registry_get_default_task_list (registry);
g_return_val_if_reached (NULL);
}
static void
cal_source_config_set_default (ESourceConfig *config,
ESource *source)
{
ECalSourceConfigPrivate *priv;
ESourceRegistry *registry;
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (config);
registry = e_source_config_get_registry (config);
if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS)
e_source_registry_set_default_calendar (registry, source);
else if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_MEMOS)
e_source_registry_set_default_memo_list (registry, source);
else if (priv->source_type == E_CAL_CLIENT_SOURCE_TYPE_TASKS)
e_source_registry_set_default_task_list (registry, source);
}
static void
cal_source_config_set_source_type (ECalSourceConfig *config,
ECalClientSourceType source_type)
{
config->priv->source_type = source_type;
}
static void
cal_source_config_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SOURCE_TYPE:
cal_source_config_set_source_type (
E_CAL_SOURCE_CONFIG (object),
g_value_get_enum (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cal_source_config_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SOURCE_TYPE:
g_value_set_enum (
value,
e_cal_source_config_get_source_type (
E_CAL_SOURCE_CONFIG (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cal_source_config_dispose (GObject *object)
{
ECalSourceConfigPrivate *priv;
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (object);
if (priv->color_button != NULL) {
g_object_unref (priv->color_button);
priv->color_button = NULL;
}
if (priv->default_button != NULL) {
g_object_unref (priv->default_button);
priv->default_button = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_cal_source_config_parent_class)->dispose (object);
}
static void
cal_source_config_constructed (GObject *object)
{
ECalSourceConfigPrivate *priv;
ESource *default_source;
ESource *original_source;
ESourceConfig *config;
GObjectClass *class;
GtkWidget *widget;
const gchar *label;
/* Chain up to parent's constructed() method. */
class = G_OBJECT_CLASS (e_cal_source_config_parent_class);
class->constructed (object);
config = E_SOURCE_CONFIG (object);
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (object);
widget = gtk_color_button_new ();
priv->color_button = g_object_ref_sink (widget);
gtk_widget_show (widget);
switch (priv->source_type) {
case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
label = _("Mark as default calendar");
break;
case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
label = _("Mark as default task list");
break;
case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
label = _("Mark as default memo list");
break;
default:
/* No need to translate this string. */
label = "Invalid ECalSourceType value";
g_warn_if_reached ();
}
widget = gtk_check_button_new_with_label (label);
priv->default_button = g_object_ref_sink (widget);
gtk_widget_show (widget);
default_source = cal_source_config_get_default (config);
original_source = e_source_config_get_original_source (config);
if (original_source != NULL) {
gboolean active;
active = e_source_equal (original_source, default_source);
g_object_set (priv->default_button, "active", active, NULL);
}
e_source_config_insert_widget (
config, NULL, _("Color:"), priv->color_button);
e_source_config_insert_widget (
config, NULL, NULL, priv->default_button);
}
static const gchar *
cal_source_config_get_backend_extension_name (ESourceConfig *config)
{
ECalSourceConfig *cal_config;
const gchar *extension_name;
cal_config = E_CAL_SOURCE_CONFIG (config);
switch (e_cal_source_config_get_source_type (cal_config)) {
case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
extension_name = E_SOURCE_EXTENSION_CALENDAR;
break;
case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
extension_name = E_SOURCE_EXTENSION_TASK_LIST;
break;
case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
break;
default:
g_return_val_if_reached (NULL);
}
return extension_name;
}
static void
cal_source_config_init_candidate (ESourceConfig *config,
ESource *scratch_source)
{
ECalSourceConfigPrivate *priv;
ESourceConfigClass *class;
ESourceExtension *extension;
const gchar *extension_name;
/* Chain up to parent's init_candidate() method. */
class = E_SOURCE_CONFIG_CLASS (e_cal_source_config_parent_class);
class->init_candidate (config, scratch_source);
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (config);
extension_name = e_source_config_get_backend_extension_name (config);
extension = e_source_get_extension (scratch_source, extension_name);
g_object_bind_property_full (
extension, "color",
priv->color_button, "color",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE,
e_binding_transform_string_to_color,
e_binding_transform_color_to_string,
NULL, (GDestroyNotify) NULL);
}
static void
cal_source_config_commit_changes (ESourceConfig *config,
ESource *scratch_source)
{
ECalSourceConfigPrivate *priv;
GtkToggleButton *toggle_button;
ESourceConfigClass *class;
ESource *default_source;
priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (config);
toggle_button = GTK_TOGGLE_BUTTON (priv->default_button);
/* Chain up to parent's commit_changes() method. */
class = E_SOURCE_CONFIG_CLASS (e_cal_source_config_parent_class);
class->commit_changes (config, scratch_source);
default_source = cal_source_config_get_default (config);
/* The default setting is a little tricky to get right. If
* the toggle button is active, this ESource is now the default.
* That much is simple. But if the toggle button is NOT active,
* then we have to inspect the old default. If this ESource WAS
* the default, reset the default to 'system'. If this ESource
* WAS NOT the old default, leave it alone. */
if (gtk_toggle_button_get_active (toggle_button))
cal_source_config_set_default (config, scratch_source);
else if (e_source_equal (scratch_source, default_source))
cal_source_config_set_default (config, NULL);
}
static void
e_cal_source_config_class_init (ECalSourceConfigClass *class)
{
GObjectClass *object_class;
ESourceConfigClass *source_config_class;
g_type_class_add_private (class, sizeof (ECalSourceConfigPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = cal_source_config_set_property;
object_class->get_property = cal_source_config_get_property;
object_class->dispose = cal_source_config_dispose;
object_class->constructed = cal_source_config_constructed;
source_config_class = E_SOURCE_CONFIG_CLASS (class);
source_config_class->get_backend_extension_name =
cal_source_config_get_backend_extension_name;
source_config_class->init_candidate = cal_source_config_init_candidate;
source_config_class->commit_changes = cal_source_config_commit_changes;
g_object_class_install_property (
object_class,
PROP_SOURCE_TYPE,
g_param_spec_enum (
"source-type",
"Source Type",
"The iCalendar object type",
E_TYPE_CAL_CLIENT_SOURCE_TYPE,
E_CAL_CLIENT_SOURCE_TYPE_EVENTS,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
static void
e_cal_source_config_init (ECalSourceConfig *config)
{
config->priv = E_CAL_SOURCE_CONFIG_GET_PRIVATE (config);
}
GtkWidget *
e_cal_source_config_new (ESourceRegistry *registry,
ESource *original_source,
ECalClientSourceType source_type)
{
g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
if (original_source != NULL)
g_return_val_if_fail (E_IS_SOURCE (original_source), NULL);
return g_object_new (
E_TYPE_CAL_SOURCE_CONFIG, "registry", registry,
"original-source", original_source, "source-type",
source_type, NULL);
}
ECalClientSourceType
e_cal_source_config_get_source_type (ECalSourceConfig *config)
{
g_return_val_if_fail (E_IS_CAL_SOURCE_CONFIG (config), 0);
return config->priv->source_type;
}
void
e_cal_source_config_add_offline_toggle (ECalSourceConfig *config,
ESource *scratch_source)
{
GtkWidget *widget;
ESourceExtension *extension;
const gchar *extension_name;
const gchar *label;
g_return_if_fail (E_IS_CAL_SOURCE_CONFIG (config));
g_return_if_fail (E_IS_SOURCE (scratch_source));
extension_name = E_SOURCE_EXTENSION_OFFLINE;
extension = e_source_get_extension (scratch_source, extension_name);
switch (e_cal_source_config_get_source_type (config)) {
case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
label = _("Copy calendar contents locally "
"for offline operation");
break;
case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
label = _("Copy task list contents locally "
"for offline operation");
break;
case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
label = _("Copy memo list contents locally "
"for offline operation");
break;
default:
g_return_if_reached ();
}
widget = gtk_check_button_new_with_label (label);
e_source_config_insert_widget (
E_SOURCE_CONFIG (config), scratch_source, NULL, widget);
gtk_widget_show (widget);
g_object_bind_property (
extension, "stay-synchronized",
widget, "active",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
}
|