aboutsummaryrefslogtreecommitdiffstats
path: root/modules/addressbook
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-11-08 01:44:44 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-11-08 03:01:46 +0800
commit86ecfc50539ddef82205551c11a6a13b135bbab4 (patch)
treecc25ca582935748885a23d665a1d9e1bbc1d4d9c /modules/addressbook
parentaa66a17e401d73cbe394ed7f99bf73350e9b938b (diff)
downloadgsoc2013-evolution-86ecfc50539ddef82205551c11a6a13b135bbab4.tar.gz
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/addressbook')
-rw-r--r--modules/addressbook/e-book-shell-view-actions.c118
-rw-r--r--modules/addressbook/e-book-shell-view-private.h3
2 files changed, 119 insertions, 2 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"