aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/tasks-component.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/tasks-component.c')
-rw-r--r--calendar/gui/tasks-component.c90
1 files changed, 69 insertions, 21 deletions
diff --git a/calendar/gui/tasks-component.c b/calendar/gui/tasks-component.c
index e548326b3a..95ebd55304 100644
--- a/calendar/gui/tasks-component.c
+++ b/calendar/gui/tasks-component.c
@@ -117,6 +117,26 @@ is_in_uids (GSList *uids, ESource *source)
return FALSE;
}
+static ESource *
+find_first_source (ESourceList *source_list)
+{
+ GSList *groups, *sources, *l, *m;
+
+ groups = e_source_list_peek_groups (source_list);
+ for (l = groups; l; l = l->next) {
+ ESourceGroup *group = l->data;
+
+ sources = e_source_group_peek_sources (group);
+ for (m = sources; m; m = m->next) {
+ ESource *source = m->data;
+
+ return source;
+ }
+ }
+
+ return NULL;
+}
+
static void
update_uris_for_selection (TasksComponent *component)
{
@@ -150,6 +170,28 @@ update_uris_for_selection (TasksComponent *component)
}
static void
+update_uri_for_primary_selection (TasksComponent *component)
+{
+ TasksComponentPrivate *priv;
+ ESource *source;
+ char *uri;
+
+ priv = component->priv;
+
+ source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (priv->source_selector));
+ if (!source)
+ return;
+
+ /* Set the default */
+ uri = e_source_get_uri (source);
+ e_tasks_set_default_uri (priv->tasks, uri);
+ g_free (uri);
+
+ /* Save the selection for next time we start up */
+ calendar_config_set_primary_tasks (e_source_peek_uid (source));
+}
+
+static void
update_selection (TasksComponent *task_component)
{
TasksComponentPrivate *priv;
@@ -186,6 +228,31 @@ update_selection (TasksComponent *task_component)
g_slist_free (uids_selected);
}
+static void
+update_primary_selection (TasksComponent *component)
+{
+ TasksComponentPrivate *priv;
+ ESource *source;
+ char *uid;
+
+ priv = component->priv;
+
+ uid = calendar_config_get_primary_tasks ();
+ if (uid) {
+ source = e_source_list_peek_source_by_uid (priv->source_list, uid);
+ g_free (uid);
+
+ e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->source_selector), source);
+ } else {
+ ESource *source;
+
+ /* Try to create a default if there isn't one */
+ source = find_first_source (priv->source_list);
+ if (source)
+ e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (priv->source_selector), source);
+ }
+}
+
/* FIXME This is duplicated from comp-editor-factory.c, should it go in comp-util? */
static ECalComponent *
get_default_task (ECal *ecal)
@@ -325,27 +392,7 @@ source_selection_changed_cb (ESourceSelector *selector, TasksComponent *componen
static void
primary_source_selection_changed_cb (ESourceSelector *selector, TasksComponent *component)
{
- TasksComponentPrivate *priv;
- ESource *source;
- ECal *client;
- char *uri;
- ECalModel *model;
-
- priv = component->priv;
-
- source = e_source_selector_peek_primary_selection (selector);
- if (!source)
- return;
-
- /* Set the default */
- uri = e_source_get_uri (source);
- model = e_calendar_table_get_model (e_tasks_get_calendar_table (E_TASKS (priv->tasks)));
- client = e_cal_model_get_client_for_uri (model, uri);
- if (client)
- e_cal_model_set_default_client (model, client);
-
- g_free (uri);
-
+ update_uri_for_primary_selection (component);
}
static void
@@ -461,6 +508,7 @@ impl_createControls (PortableServer_Servant servant,
/* Load the selection from the last run */
update_selection (component);
+ update_primary_selection (component);
/* If it gets fiddled with, ie from another evolution window, update it */
priv->selected_not = calendar_config_add_notification_calendars_selected (config_selection_changed_cb,