From 86ecfc50539ddef82205551c11a6a13b135bbab4 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 7 Nov 2009 12:44:44 -0500 Subject: Convert some "Save As" actions to run asynchronously. This introduces e-shell-utils for miscellaneous utility functions that integrate with the shell or shell settings. First function is e_shell_run_save_dialog(), which automatically remembers the selected folder in the file chooser dialog. Also, kill some redundant save dialog functions, as well as some write-this-string-to-disk functions that block. --- modules/calendar/e-memo-shell-view-actions.c | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'modules/calendar/e-memo-shell-view-actions.c') diff --git a/modules/calendar/e-memo-shell-view-actions.c b/modules/calendar/e-memo-shell-view-actions.c index ab8be53d04..31f12b3962 100644 --- a/modules/calendar/e-memo-shell-view-actions.c +++ b/modules/calendar/e-memo-shell-view-actions.c @@ -471,17 +471,22 @@ static void action_memo_save_as_cb (GtkAction *action, EMemoShellView *memo_shell_view) { + EShell *shell; EShellView *shell_view; EShellWindow *shell_window; + EShellBackend *shell_backend; EMemoShellContent *memo_shell_content; EMemoTable *memo_table; ECalModelComponent *comp_data; + EActivity *activity; GSList *list; - gchar *filename; + GFile *file; gchar *string; shell_view = E_SHELL_VIEW (memo_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); + shell_backend = e_shell_view_get_shell_backend (shell_view); + shell = e_shell_window_get_shell (shell_window); memo_shell_content = memo_shell_view->priv->memo_shell_content; memo_table = e_memo_shell_content_get_memo_table (memo_shell_content); @@ -491,9 +496,9 @@ action_memo_save_as_cb (GtkAction *action, comp_data = list->data; g_slist_free (list); - filename = e_file_dialog_save ( - GTK_WINDOW (shell_window), _("Save as..."), NULL); - if (filename == NULL) + file = e_shell_run_save_dialog ( + shell, _("Save as iCalendar"), NULL, NULL); + if (file == NULL) return; /* XXX We only save the first selected memo. */ @@ -501,13 +506,23 @@ action_memo_save_as_cb (GtkAction *action, comp_data->client, comp_data->icalcomp); if (string == NULL) { g_warning ("Could not convert memo to a string"); + g_object_unref (file); return; } - e_write_file_uri (filename, string); + /* XXX No callback means errors are discarded. */ + activity = e_file_replace_contents_async ( + file, string, strlen (string), NULL, FALSE, + G_FILE_CREATE_NONE, (GAsyncReadyCallback) NULL, NULL); + e_shell_backend_add_activity (shell_backend, activity); + + /* Free the string when the activity is finalized. */ + g_object_set_data_full ( + G_OBJECT (activity), + "file-content", string, + (GDestroyNotify) g_free); - g_free (filename); - g_free (string); + g_object_unref (file); } static void -- cgit v1.2.3