From 28aef9afc71eb2d2606171bbc94d72dfa325ed07 Mon Sep 17 00:00:00 2001 From: 8 Date: Wed, 19 Nov 2003 03:55:31 +0000 Subject: add protos 2003-11-18 * gui/calendar-config.h: add protos * gui/calendar-config.c (calendar_config_get_primary_calendar): get the primary calendar (calendar_config_set_primary_calendar): set it (calendar_config_add_notification_primary_calendar): set notifications for it (calendar_config_get_primary_tasks): get the primary task list (calendar_config_set_primary_tasks): set it (calendar_config_add_notification_primary_tasks): set notifications for it * gui/calendar-config-keys.h: add primary keys * gui/calendar-component.c (find_first_source): find any source (update_uri_for_primary_selection): set the default uri and save the source uid (update_primary_selection): set the primary selection (primary_source_selection_changed_cb): use above (impl_createControls): set the primary selection * gui/tasks-component.c: as above svn path=/trunk/; revision=23434 --- calendar/gui/tasks-component.c | 90 ++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 21 deletions(-) (limited to 'calendar/gui/tasks-component.c') 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) { @@ -149,6 +169,28 @@ update_uris_for_selection (TasksComponent *component) g_slist_free (uids_selected); } +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) { @@ -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, -- cgit v1.2.3