From 7c1ec3723ad7367449c93e8559c27158b24a51dd Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 20 Aug 2010 13:25:21 -0400 Subject: Add e_load_cal_source_async(). Similar to e_load_book_source_async() in libedataserverui (and may wind up there eventually). This replaces e_auth_new_cal_from_source(). void e_load_cal_source_async (ESource *source, ECalSourceType source_type, icaltimezone *default_zone, GtkWindow *parent, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); ECal * e_load_cal_source_finish (ESource *source, GAsyncResult *result, GError **error); --- modules/calendar/e-task-shell-backend.c | 99 +++++++++++++++++---------------- 1 file changed, 51 insertions(+), 48 deletions(-) (limited to 'modules/calendar/e-task-shell-backend.c') diff --git a/modules/calendar/e-task-shell-backend.c b/modules/calendar/e-task-shell-backend.c index cdd4dcc608..be085afa8d 100644 --- a/modules/calendar/e-task-shell-backend.c +++ b/modules/calendar/e-task-shell-backend.c @@ -153,19 +153,18 @@ task_shell_backend_ensure_sources (EShellBackend *shell_backend) } static void -task_shell_backend_task_new_cb (ECal *cal, - const GError *error, - EShell *shell) +task_shell_backend_new_task (ESource *source, + GAsyncResult *result, + EShell *shell, + CompEditorFlags flags) { + ECal *cal; ECalComponent *comp; CompEditor *editor; - CompEditorFlags flags = 0; /* XXX Handle errors better. */ - if (error) - return; - - flags |= COMP_EDITOR_NEW_ITEM; + cal = e_load_cal_source_finish (source, result, NULL); + g_return_if_fail (E_IS_CAL (cal)); editor = task_editor_new (cal, shell, flags); comp = cal_comp_task_new_with_defaults (cal); @@ -178,41 +177,45 @@ task_shell_backend_task_new_cb (ECal *cal, } static void -task_shell_backend_task_assigned_new_cb (ECal *cal, - const GError *error, - EShell *shell) +task_shell_backend_task_new_cb (ESource *source, + GAsyncResult *result, + EShell *shell) { - ECalComponent *comp; - CompEditor *editor; CompEditorFlags flags = 0; - /* XXX Handle errors better. */ - if (error) - return; + flags |= COMP_EDITOR_NEW_ITEM; + + task_shell_backend_new_task (source, result, shell, flags); + + g_object_unref (shell); +} + +static void +task_shell_backend_task_assigned_new_cb (ESource *source, + GAsyncResult *result, + EShell *shell) +{ + CompEditorFlags flags = 0; flags |= COMP_EDITOR_NEW_ITEM; flags |= COMP_EDITOR_IS_ASSIGNED; flags |= COMP_EDITOR_USER_ORG; - editor = task_editor_new (cal, shell, flags); - comp = cal_comp_task_new_with_defaults (cal); - comp_editor_edit_comp (editor, comp); + task_shell_backend_new_task (source, result, shell, flags); - gtk_window_present (GTK_WINDOW (editor)); - - g_object_unref (comp); - g_object_unref (cal); + g_object_unref (shell); } static void action_task_new_cb (GtkAction *action, EShellWindow *shell_window) { - ECal *cal = NULL; - ECalSourceType source_type; - ESourceList *source_list; - EShellSettings *shell_settings; EShell *shell; + EShellBackend *shell_backend; + EShellSettings *shell_settings; + ESource *source = NULL; + ESourceList *source_list; + ECalSourceType source_type; const gchar *action_name; gchar *uid; @@ -222,43 +225,43 @@ action_task_new_cb (GtkAction *action, shell = e_shell_window_get_shell (shell_window); shell_settings = e_shell_get_shell_settings (shell); + shell_backend = e_shell_get_backend_by_name (shell, "tasks"); - if (!e_cal_get_sources (&source_list, source_type, NULL)) { - g_warning ("Could not get task sources from GConf!"); - return; - } + g_object_get (shell_backend, "source-list", &source_list, NULL); + g_return_if_fail (E_IS_SOURCE_LIST (source_list)); uid = e_shell_settings_get_string ( shell_settings, "cal-primary-task-list"); if (uid != NULL) { - ESource *source; - source = e_source_list_peek_source_by_uid (source_list, uid); - if (source != NULL) - cal = e_auth_new_cal_from_source (source, source_type); g_free (uid); } - if (cal == NULL) - cal = e_auth_new_cal_from_default (source_type); + if (source == NULL) + source = e_source_list_peek_default_source (source_list); - g_return_if_fail (cal != NULL); + g_return_if_fail (E_IS_SOURCE (source)); - /* Connect the appropriate signal handler. */ + /* Use a callback function appropriate for the action. + * FIXME Need to obtain a better default time zone. */ action_name = gtk_action_get_name (action); if (strcmp (action_name, "task-assigned-new") == 0) - g_signal_connect ( - cal, "cal-opened-ex", - G_CALLBACK (task_shell_backend_task_assigned_new_cb), - shell); + e_load_cal_source_async ( + source, source_type, NULL, + GTK_WINDOW (shell_window), + NULL, (GAsyncReadyCallback) + task_shell_backend_task_assigned_new_cb, + g_object_ref (shell)); else - g_signal_connect ( - cal, "cal-opened-ex", - G_CALLBACK (task_shell_backend_task_new_cb), - shell); + e_load_cal_source_async ( + source, source_type, NULL, + GTK_WINDOW (shell_window), + NULL, (GAsyncReadyCallback) + task_shell_backend_task_new_cb, + g_object_ref (shell)); - e_cal_open_async (cal, FALSE); + g_object_unref (source_list); } static void -- cgit