49
48
#define CALENDAR_SOURCES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CALENDAR_TYPE_SOURCES, CalendarSourcesPrivate))
51
#define CALENDAR_SOURCES_EVO_DIR "/apps/evolution"
52
#define CALENDAR_SOURCES_APPOINTMENT_SOURCES_KEY CALENDAR_SOURCES_EVO_DIR "/calendar/sources"
53
#define CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_DIR CALENDAR_SOURCES_EVO_DIR "/calendar/display"
54
#define CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_KEY CALENDAR_SOURCES_SELECTED_APPOINTMENT_SOURCES_DIR "/selected_calendars"
55
#define CALENDAR_SOURCES_TASK_SOURCES_KEY CALENDAR_SOURCES_EVO_DIR "/tasks/sources"
56
#define CALENDAR_SOURCES_SELECTED_TASK_SOURCES_DIR CALENDAR_SOURCES_EVO_DIR "/calendar/tasks"
57
#define CALENDAR_SOURCES_SELECTED_TASK_SOURCES_KEY CALENDAR_SOURCES_SELECTED_TASK_SOURCES_DIR "/selected_tasks"
59
50
typedef struct _CalendarSourceData CalendarSourceData;
61
52
struct _CalendarSourceData
63
ECalSourceType source_type;
54
ECalClientSourceType client_type;
64
55
CalendarSources *sources;
65
56
guint changed_signal;
68
GSList *selected_sources;
69
ESourceList *esource_list;
71
guint selected_sources_listener;
72
char *selected_sources_dir;
59
ESourceSelector *esource_selector;
81
68
CalendarSourceData appointment_sources;
82
69
CalendarSourceData task_sources;
84
GConfClient *gconf_client;
71
ESourceRegistry *esource_registry;
87
74
static void calendar_sources_class_init (CalendarSourcesClass *klass);
88
75
static void calendar_sources_init (CalendarSources *sources);
89
76
static void calendar_sources_finalize (GObject *object);
91
static void backend_died_cb (ECal *client, CalendarSourceData *source_data);
92
static void calendar_sources_esource_list_changed (ESourceList *source_list,
93
CalendarSourceData *source_data);
78
static void backend_died_cb (ECalClient *client, CalendarSourceData *source_data);
79
static void calendar_sources_selection_changed_cb (ESourceSelector *selector, CalendarSourceData *source_data);
171
157
calendar_sources_init (CalendarSources *sources)
159
GError *error = NULL;
173
161
sources->priv = CALENDAR_SOURCES_GET_PRIVATE (sources);
175
sources->priv->appointment_sources.source_type = E_CAL_SOURCE_TYPE_EVENT;
163
sources->priv->appointment_sources.client_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
176
164
sources->priv->appointment_sources.sources = sources;
177
165
sources->priv->appointment_sources.changed_signal = signals [APPOINTMENT_SOURCES_CHANGED];
178
166
sources->priv->appointment_sources.timeout_id = 0;
180
sources->priv->task_sources.source_type = E_CAL_SOURCE_TYPE_TODO;
168
sources->priv->task_sources.client_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
181
169
sources->priv->task_sources.sources = sources;
182
170
sources->priv->task_sources.changed_signal = signals [TASK_SOURCES_CHANGED];
183
171
sources->priv->task_sources.timeout_id = 0;
185
sources->priv->gconf_client = gconf_client_get_default ();
173
sources->priv->esource_registry = e_source_registry_new_sync (NULL, &error);
176
g_warning ("%s: Failed to create ESourceRegistry: %s", G_STRFUNC, error->message);
177
g_clear_error (&error);
196
if (source_data->selected_sources_dir)
198
gconf_client_remove_dir (sources->priv->gconf_client,
199
source_data->selected_sources_dir,
202
g_free (source_data->selected_sources_dir);
203
source_data->selected_sources_dir = NULL;
206
if (source_data->selected_sources_listener)
208
gconf_client_notify_remove (sources->priv->gconf_client,
209
source_data->selected_sources_listener);
210
source_data->selected_sources_listener = 0;
213
189
for (l = source_data->clients; l; l = l->next)
215
191
g_signal_handlers_disconnect_by_func (G_OBJECT (l->data),
220
196
g_slist_free (source_data->clients);
221
197
source_data->clients = NULL;
223
if (source_data->esource_list)
199
if (source_data->esource_selector)
225
g_signal_handlers_disconnect_by_func (source_data->esource_list,
226
G_CALLBACK (calendar_sources_esource_list_changed),
201
g_signal_handlers_disconnect_by_func (source_data->esource_selector,
202
G_CALLBACK (calendar_sources_selection_changed_cb),
228
g_object_unref (source_data->esource_list);
204
g_object_unref (source_data->esource_selector);
230
source_data->esource_list = NULL;
232
for (l = source_data->selected_sources; l; l = l->next)
234
g_slist_free (source_data->selected_sources);
235
source_data->selected_sources = NULL;
206
source_data->esource_selector = NULL;
237
208
if (source_data->timeout_id != 0)
252
223
calendar_sources_finalize_source_data (sources, &sources->priv->appointment_sources);
253
224
calendar_sources_finalize_source_data (sources, &sources->priv->task_sources);
255
if (sources->priv->gconf_client)
256
g_object_unref (sources->priv->gconf_client);
257
sources->priv->gconf_client = NULL;
226
if (sources->priv->esource_registry)
227
g_object_unref (sources->priv->esource_registry);
228
sources->priv->esource_registry = NULL;
259
230
if (G_OBJECT_CLASS (parent_class)->finalize)
260
231
G_OBJECT_CLASS (parent_class)->finalize (object);
275
246
return calendar_sources_singleton;
279
is_source_selected (ESource *esource,
280
GSList *selected_sources)
285
uid = e_source_peek_uid (esource);
287
for (l = selected_sources; l; l = l->next)
289
const char *source = l->data;
291
if (!strcmp (source, uid))
299
auth_func_cb (ECal *ecal,
305
const gchar *auth_domain;
306
const gchar *component_name;
308
source = e_cal_get_source (ecal);
309
auth_domain = e_source_get_property (source, "auth-domain");
310
component_name = auth_domain ? auth_domain : "Calendar";
312
return e_passwords_get_password (component_name, key);
315
249
/* The clients are just created here but not loaded */
317
get_ecal_from_source (ESource *esource,
318
ECalSourceType source_type,
319
GSList *existing_clients)
251
get_ecal_from_source (ESource *esource,
252
ECalClientSourceType client_type,
253
GSList *existing_clients)
256
GError *error = NULL;
323
258
if (existing_clients)
340
retval = e_cal_new (esource, source_type);
275
retval = e_cal_client_new (esource, client_type, &error);
343
g_warning ("Could not load source '%s' from '%s'\n",
344
e_source_peek_name (esource),
345
e_source_peek_relative_uri (esource));
278
g_warning ("Could not load source '%s' from '%s': %s",
279
e_source_get_display_name (esource),
280
e_source_get_uid (esource),
281
error ? error->message : "Unknown error");
349
e_cal_set_auth_func (retval, auth_func_cb, NULL);
399
316
dprintf ("Loaded clients:\n");
400
317
for (l = ecal_list; l; l = l->next)
402
ECal *client = l->data;
403
ESource *source = e_cal_get_source (client);
319
ECalClient *client = l->data;
320
ESource *source = e_client_get_source (E_CLIENT (client));
405
dprintf (" %s %s %s\n",
406
e_source_peek_uid (source),
407
e_source_peek_name (source),
408
e_cal_get_uri (client));
323
e_source_get_uid (source),
324
e_source_get_display_name (source));
414
calendar_sources_load_esource_list (CalendarSourceData *source_data);
330
calendar_sources_load_esources (CalendarSourceData *source_data);
417
333
backend_restart (gpointer data)
419
335
CalendarSourceData *source_data = data;
421
calendar_sources_load_esource_list (source_data);
337
calendar_sources_load_esources (source_data);
423
339
source_data->timeout_id = 0;
453
calendar_sources_load_esource_list (CalendarSourceData *source_data)
369
calendar_sources_load_esources (CalendarSourceData *source_data)
455
371
GSList *clients = NULL;
457
373
gboolean emit_signal = FALSE;
459
g_return_if_fail (source_data->esource_list != NULL);
461
debug_dump_selected_sources (source_data->selected_sources);
463
dprintf ("Source groups:\n");
464
groups = e_source_list_peek_groups (source_data->esource_list);
465
for (l = groups; l; l = l->next)
375
g_return_if_fail (source_data->esource_selector != NULL);
377
dprintf ("Sources:\n");
378
sources = e_source_selector_get_selection (source_data->esource_selector);
379
for (s = sources; s; s = s->next)
467
GSList *esources, *s;
469
dprintf (" %s\n", e_source_group_peek_uid (l->data));
470
dprintf (" sources:\n");
472
esources = e_source_group_peek_sources (l->data);
473
for (s = esources; s; s = s->next)
475
ESource *esource = E_SOURCE (s->data);
478
dprintf (" type = '%s' uid = '%s', name = '%s', relative uri = '%s': \n",
479
source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task",
480
e_source_peek_uid (esource),
481
e_source_peek_name (esource),
482
e_source_peek_relative_uri (esource));
484
if (is_source_selected (esource, source_data->selected_sources) &&
485
(client = get_ecal_from_source (esource, source_data->source_type, source_data->clients)))
487
clients = g_slist_prepend (clients, client);
381
ESource *esource = E_SOURCE (s->data);
384
dprintf (" type = '%s' uid = '%s', name = '%s': \n",
385
source_data->client_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS ? "appointment" : "task",
386
e_source_get_uid (esource),
387
e_source_get_display_name (esource));
389
if ((client = get_ecal_from_source (esource, source_data->client_type, source_data->clients)) != NULL)
391
clients = g_slist_prepend (clients, client);
396
e_source_selector_free_selection (sources);
493
398
if (source_data->loaded &&
494
399
!compare_ecal_lists (source_data->clients, clients))
495
400
emit_signal = TRUE;
497
for (l = source_data->clients; l; l = l->next)
402
for (s = source_data->clients; s; s = s->next)
499
g_signal_handlers_disconnect_by_func (G_OBJECT (l->data),
404
g_signal_handlers_disconnect_by_func (G_OBJECT (s->data),
500
405
G_CALLBACK (backend_died_cb),
503
g_object_unref (l->data);
408
g_object_unref (s->data);
505
410
g_slist_free (source_data->clients);
506
411
source_data->clients = g_slist_reverse (clients);
508
413
/* connect to backend_died after we disconnected the previous signal
509
414
* handlers. If we do it before, we'll lose some handlers (for clients that
510
415
* were already there before) */
511
for (l = source_data->clients; l; l = l->next)
416
for (s = source_data->clients; s; s = s->next)
513
g_signal_connect (G_OBJECT (l->data), "backend_died",
418
g_signal_connect (G_OBJECT (s->data), "backend-died",
514
419
G_CALLBACK (backend_died_cb), source_data);
519
424
dprintf ("Emitting %s-sources-changed signal\n",
520
source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task");
425
source_data->client_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS ? "appointment" : "task");
521
426
g_signal_emit (source_data->sources, source_data->changed_signal, 0);
528
calendar_sources_esource_list_changed (ESourceList *source_list,
433
calendar_sources_selection_changed_cb (ESourceSelector *source_selector,
529
434
CalendarSourceData *source_data)
532
dprintf ("ESourceList changed, reloading\n");
534
calendar_sources_load_esource_list (source_data);
538
calendar_sources_selected_sources_notify (GConfClient *client,
541
CalendarSourceData *source_data)
546
entry->value->type != GCONF_VALUE_LIST ||
547
gconf_value_get_list_type (entry->value) != GCONF_VALUE_STRING)
550
dprintf ("Selected sources key (%s) changed, reloading\n", entry->key);
552
for (l = source_data->selected_sources; l; l = l->next)
554
source_data->selected_sources = NULL;
556
for (l = gconf_value_get_list (entry->value); l; l = l->next)
558
const char *source = gconf_value_get_string (l->data);
560
source_data->selected_sources =
561
g_slist_prepend (source_data->selected_sources,
564
source_data->selected_sources =
565
g_slist_reverse (source_data->selected_sources);
567
calendar_sources_load_esource_list (source_data);
437
dprintf ("ESourceSelector selection-changed, reloading\n");
439
calendar_sources_load_esources (source_data);
571
443
calendar_sources_load_sources (CalendarSources *sources,
572
444
CalendarSourceData *source_data,
573
const char *sources_key,
574
const char *selected_sources_key,
575
const char *selected_sources_dir)
445
const char *sources_extension)
577
GConfClient *gconf_client;
447
g_return_if_fail (sources->priv->esource_registry != NULL);
580
449
dprintf ("---------------------------\n");
581
450
dprintf ("Loading sources:\n");
582
dprintf (" sources_key: %s\n", sources_key);
583
dprintf (" selected_sources_key: %s\n", selected_sources_key);
584
dprintf (" selected_sources_dir: %s\n", selected_sources_dir);
586
gconf_client = sources->priv->gconf_client;
589
source_data->selected_sources = gconf_client_get_list (gconf_client,
590
selected_sources_key,
595
g_warning ("Failed to get selected sources from '%s': %s\n",
596
selected_sources_key,
598
g_error_free (error);
602
gconf_client_add_dir (gconf_client,
603
selected_sources_dir,
604
GCONF_CLIENT_PRELOAD_NONE,
606
source_data->selected_sources_dir = g_strdup (selected_sources_dir);
608
source_data->selected_sources_listener =
609
gconf_client_notify_add (gconf_client,
610
selected_sources_dir,
611
(GConfClientNotifyFunc) calendar_sources_selected_sources_notify,
612
source_data, NULL, NULL);
614
source_data->esource_list = e_source_list_new_for_gconf (gconf_client, sources_key);
615
g_signal_connect (source_data->esource_list, "changed",
616
G_CALLBACK (calendar_sources_esource_list_changed),
451
dprintf (" sources_extension: %s\n", sources_extension);
453
source_data->esource_selector = E_SOURCE_SELECTOR (e_source_selector_new (sources->priv->esource_registry, sources_extension));
454
g_signal_connect (source_data->esource_selector, "selection-changed",
455
G_CALLBACK (calendar_sources_selection_changed_cb),
619
calendar_sources_load_esource_list (source_data);
458
calendar_sources_load_esources (source_data);
621
460
source_data->loaded = TRUE;