diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-11-08 01:44:44 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-11-08 03:01:46 +0800 |
commit | 86ecfc50539ddef82205551c11a6a13b135bbab4 (patch) | |
tree | cc25ca582935748885a23d665a1d9e1bbc1d4d9c /modules | |
parent | aa66a17e401d73cbe394ed7f99bf73350e9b938b (diff) | |
download | gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.gz gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.bz2 gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.lz gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.xz gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.zst gsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.zip |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/addressbook/e-book-shell-view-actions.c | 118 | ||||
-rw-r--r-- | modules/addressbook/e-book-shell-view-private.h | 3 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-actions.c | 32 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-memopad.c | 31 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-private.h | 2 | ||||
-rw-r--r-- | modules/calendar/e-cal-shell-view-taskpad.c | 29 | ||||
-rw-r--r-- | modules/calendar/e-memo-shell-view-actions.c | 29 | ||||
-rw-r--r-- | modules/calendar/e-memo-shell-view-private.h | 2 | ||||
-rw-r--r-- | modules/calendar/e-task-shell-view-actions.c | 30 | ||||
-rw-r--r-- | modules/calendar/e-task-shell-view-private.h | 2 |
10 files changed, 238 insertions, 40 deletions
diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c index c680c64ede..6882f29e6e 100644 --- a/modules/addressbook/e-book-shell-view-actions.c +++ b/modules/addressbook/e-book-shell-view-actions.c @@ -192,14 +192,75 @@ static void action_address_book_save_as_cb (GtkAction *action, EBookShellView *book_shell_view) { + EShell *shell; + EShellView *shell_view; + EShellWindow *shell_window; + EShellBackend *shell_backend; EBookShellContent *book_shell_content; + EAddressbookModel *model; EAddressbookView *view; + EActivity *activity; + EBookQuery *query; + EBook *book; + GList *list = NULL; + GFile *file; + gchar *string; + + shell_view = E_SHELL_VIEW (book_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); book_shell_content = book_shell_view->priv->book_shell_content; view = e_book_shell_content_get_current_view (book_shell_content); g_return_if_fail (view != NULL); - e_addressbook_view_save_as (view, TRUE); + model = e_addressbook_view_get_model (view); + book = e_addressbook_model_get_book (model); + + query = e_book_query_any_field_contains (""); + e_book_get_contacts (book, query, &list, NULL); + e_book_query_unref (query); + + if (list == NULL) + goto exit; + + file = e_shell_run_save_dialog ( + shell, _("Save as vCard"), + (GtkCallback) eab_suggest_filename, list); + if (file == NULL) + goto exit; + + string = eab_contact_list_to_string (list); + if (string == NULL) { + g_warning ("Could not convert contact list to a string"); + g_object_unref (file); + goto exit; + } + + /* XXX No callback means errors are discarded. + * + * There's an EError for this which I'm not using + * until I figure out a better way to display errors: + * + * "addressbook:save-error" + */ + 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_object_unref (file); + +exit: + g_list_foreach (list, (GFunc) g_object_unref, NULL); + g_list_free (list); } static void @@ -454,14 +515,67 @@ static void action_contact_save_as_cb (GtkAction *action, EBookShellView *book_shell_view) { + EShell *shell; + EShellView *shell_view; + EShellWindow *shell_window; + EShellBackend *shell_backend; EBookShellContent *book_shell_content; EAddressbookView *view; + EActivity *activity; + GList *list; + GFile *file; + gchar *string; + + shell_view = E_SHELL_VIEW (book_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); book_shell_content = book_shell_view->priv->book_shell_content; view = e_book_shell_content_get_current_view (book_shell_content); g_return_if_fail (view != NULL); - e_addressbook_view_save_as (view, FALSE); + list = e_addressbook_view_get_selected (view); + + if (list == NULL) + goto exit; + + file = e_shell_run_save_dialog ( + shell, _("Save as vCard"), + (GtkCallback) eab_suggest_filename, list); + if (file == NULL) + goto exit; + + string = eab_contact_list_to_string (list); + if (string == NULL) { + g_warning ("Could not convert contact list to a string"); + g_object_unref (file); + goto exit; + } + + /* XXX No callback means errors are discarded. + * + * There an EError for this which I'm not using + * until I figure out a better way to display errors: + * + * "addressbook:save-error" + */ + 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_object_unref (file); + +exit: + g_list_foreach (list, (GFunc) g_object_unref, NULL); + g_list_free (list); } static void diff --git a/modules/addressbook/e-book-shell-view-private.h b/modules/addressbook/e-book-shell-view-private.h index fa8624692a..c1aa300739 100644 --- a/modules/addressbook/e-book-shell-view-private.h +++ b/modules/addressbook/e-book-shell-view-private.h @@ -34,11 +34,14 @@ #include "e-util/e-util.h" #include "e-util/e-binding.h" +#include "e-util/e-file-utils.h" #include "e-util/gconf-bridge.h" #include "shell/e-shell-content.h" #include "shell/e-shell-sidebar.h" +#include "shell/e-shell-utils.h" #include "misc/e-popup-action.h" +#include "addressbook/util/eab-book-util.h" #include "addressbook/gui/contact-editor/e-contact-editor.h" #include "addressbook/gui/contact-list-editor/e-contact-list-editor.h" #include "addressbook/gui/widgets/eab-gui-util.h" diff --git a/modules/calendar/e-cal-shell-view-actions.c b/modules/calendar/e-cal-shell-view-actions.c index 408d02ffc3..4fa8b07eae 100644 --- a/modules/calendar/e-cal-shell-view-actions.c +++ b/modules/calendar/e-cal-shell-view-actions.c @@ -1065,8 +1065,10 @@ static void action_event_save_as_cb (GtkAction *action, ECalShellView *cal_shell_view) { + EShell *shell; EShellView *shell_view; EShellWindow *shell_window; + EShellBackend *shell_backend; ECalShellContent *cal_shell_content; GnomeCalendarViewType view_type; GnomeCalendar *calendar; @@ -1074,12 +1076,15 @@ action_event_save_as_cb (GtkAction *action, ECalendarViewEvent *event; ECal *client; icalcomponent *icalcomp; + EActivity *activity; GList *selected; - gchar *filename = NULL; + GFile *file; gchar *string = NULL; shell_view = E_SHELL_VIEW (cal_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); cal_shell_content = cal_shell_view->priv->cal_shell_content; calendar = e_cal_shell_content_get_calendar (cal_shell_content); @@ -1093,10 +1098,10 @@ action_event_save_as_cb (GtkAction *action, client = event->comp_data->client; icalcomp = event->comp_data->icalcomp; - filename = e_file_dialog_save ( - GTK_WINDOW (shell_window), _("Save As..."), NULL); - if (filename == NULL) - goto exit; + file = e_shell_run_save_dialog ( + shell, _("Save as iCalendar"), NULL, NULL); + if (file == NULL) + return; string = e_cal_get_component_as_string (client, icalcomp); if (string == NULL) { @@ -1104,11 +1109,20 @@ action_event_save_as_cb (GtkAction *action, goto exit; } - e_write_file_uri (filename, string); + /* XXX No callbacks 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); exit: - g_free (filename); - g_free (string); + g_object_unref (file); g_list_free (selected); } @@ -1372,7 +1386,7 @@ static GtkActionEntry calendar_entries[] = { { "event-save-as", GTK_STOCK_SAVE_AS, - NULL, + N_("Save as iCalendar..."), NULL, NULL, /* XXX Add a tooltip! */ G_CALLBACK (action_event_save_as_cb) }, diff --git a/modules/calendar/e-cal-shell-view-memopad.c b/modules/calendar/e-cal-shell-view-memopad.c index 7d4c1a501f..88cb53ff54 100644 --- a/modules/calendar/e-cal-shell-view-memopad.c +++ b/modules/calendar/e-cal-shell-view-memopad.c @@ -233,17 +233,22 @@ static void action_calendar_memopad_save_as_cb (GtkAction *action, ECalShellView *cal_shell_view) { + EShell *shell; EShellView *shell_view; EShellWindow *shell_window; + EShellBackend *shell_backend; ECalShellContent *cal_shell_content; EMemoTable *memo_table; ECalModelComponent *comp_data; + EActivity *activity; GSList *list; - gchar *filename; + GFile *file; gchar *string; shell_view = E_SHELL_VIEW (cal_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); cal_shell_content = cal_shell_view->priv->cal_shell_content; memo_table = e_cal_shell_content_get_memo_table (cal_shell_content); @@ -253,9 +258,9 @@ action_calendar_memopad_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. */ @@ -263,13 +268,23 @@ action_calendar_memopad_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 GtkActionEntry calendar_memopad_entries[] = { @@ -332,7 +347,7 @@ static GtkActionEntry calendar_memopad_entries[] = { { "calendar-memopad-save-as", GTK_STOCK_SAVE_AS, - NULL, + N_("Save as iCalendar..."), NULL, NULL, /* XXX Add a tooltip! */ G_CALLBACK (action_calendar_memopad_save_as_cb) } diff --git a/modules/calendar/e-cal-shell-view-private.h b/modules/calendar/e-cal-shell-view-private.h index 690031198e..2ee0cff6a4 100644 --- a/modules/calendar/e-cal-shell-view-private.h +++ b/modules/calendar/e-cal-shell-view-private.h @@ -33,8 +33,10 @@ #include "e-util/e-binding.h" #include "e-util/e-dialog-utils.h" +#include "e-util/e-file-utils.h" #include "e-util/e-error.h" #include "e-util/e-util.h" +#include "shell/e-shell-utils.h" #include "widgets/misc/e-popup-action.h" #include "calendar/common/authentication.h" diff --git a/modules/calendar/e-cal-shell-view-taskpad.c b/modules/calendar/e-cal-shell-view-taskpad.c index 3e83e04fcc..5f2fd3ad0f 100644 --- a/modules/calendar/e-cal-shell-view-taskpad.c +++ b/modules/calendar/e-cal-shell-view-taskpad.c @@ -301,17 +301,22 @@ static void action_calendar_taskpad_save_as_cb (GtkAction *action, ECalShellView *cal_shell_view) { + EShell *shell; EShellView *shell_view; EShellWindow *shell_window; + EShellBackend *shell_backend; ECalShellContent *cal_shell_content; ECalendarTable *task_table; ECalModelComponent *comp_data; + EActivity *activity; GSList *list; - gchar *filename; + GFile *file; gchar *string; shell_view = E_SHELL_VIEW (cal_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); cal_shell_content = cal_shell_view->priv->cal_shell_content; task_table = e_cal_shell_content_get_task_table (cal_shell_content); @@ -321,22 +326,32 @@ action_calendar_taskpad_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; string = e_cal_get_component_as_string ( comp_data->client, comp_data->icalcomp); if (string == NULL) { g_warning ("Could not convert task 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 GtkActionEntry calendar_taskpad_entries[] = { 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 diff --git a/modules/calendar/e-memo-shell-view-private.h b/modules/calendar/e-memo-shell-view-private.h index 276e6e5d30..37556943f2 100644 --- a/modules/calendar/e-memo-shell-view-private.h +++ b/modules/calendar/e-memo-shell-view-private.h @@ -31,9 +31,11 @@ #include "e-util/e-binding.h" #include "e-util/e-dialog-utils.h" +#include "e-util/e-file-utils.h" #include "e-util/e-error.h" #include "e-util/e-util.h" #include "e-util/gconf-bridge.h" +#include "shell/e-shell-utils.h" #include "widgets/misc/e-popup-action.h" #include "calendar/gui/comp-util.h" diff --git a/modules/calendar/e-task-shell-view-actions.c b/modules/calendar/e-task-shell-view-actions.c index fb7b89b049..282d5a3e75 100644 --- a/modules/calendar/e-task-shell-view-actions.c +++ b/modules/calendar/e-task-shell-view-actions.c @@ -598,17 +598,22 @@ static void action_task_save_as_cb (GtkAction *action, ETaskShellView *task_shell_view) { + EShell *shell; EShellView *shell_view; EShellWindow *shell_window; + EShellBackend *shell_backend; ETaskShellContent *task_shell_content; ECalendarTable *task_table; ECalModelComponent *comp_data; + EActivity *activity; GSList *list; - gchar *filename; + GFile *file; gchar *string; shell_view = E_SHELL_VIEW (task_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); task_shell_content = task_shell_view->priv->task_shell_content; task_table = e_task_shell_content_get_task_table (task_shell_content); @@ -618,22 +623,33 @@ action_task_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 task. */ string = e_cal_get_component_as_string ( comp_data->client, comp_data->icalcomp); if (string == NULL) { g_warning ("Could not convert task 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 diff --git a/modules/calendar/e-task-shell-view-private.h b/modules/calendar/e-task-shell-view-private.h index b369b4c948..38b03ae359 100644 --- a/modules/calendar/e-task-shell-view-private.h +++ b/modules/calendar/e-task-shell-view-private.h @@ -32,9 +32,11 @@ #include "e-util/e-binding.h" #include "e-util/e-dialog-utils.h" +#include "e-util/e-file-utils.h" #include "e-util/e-error.h" #include "e-util/e-util.h" #include "e-util/gconf-bridge.h" +#include "shell/e-shell-utils.h" #include "widgets/misc/e-popup-action.h" #include "calendar/common/authentication.h" |