aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-08-19 03:49:49 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-08-19 03:49:49 +0800
commita536d74906984acd16902606ac574db676344194 (patch)
treea300caed7474f6e1939c3a6c1fffa2eed51977f4 /addressbook
parenta5604d436c8dc133231c60ae75fb35e96816371d (diff)
downloadgsoc2013-evolution-a536d74906984acd16902606ac574db676344194.tar.gz
gsoc2013-evolution-a536d74906984acd16902606ac574db676344194.tar.zst
gsoc2013-evolution-a536d74906984acd16902606ac574db676344194.zip
Use the new e_load_book_source_async() where possible.
It's easier to use than addressbook_load() but requires starting with an ESource rather than an EBook, and there's a couple places left where that's not so easy. I'll spend more time on it later.
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c84
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.h4
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-editor.c68
-rw-r--r--addressbook/gui/widgets/eab-gui-util.c56
-rw-r--r--addressbook/gui/widgets/eab-gui-util.h38
5 files changed, 132 insertions, 118 deletions
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index c7388ea3e8..12431e4633 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -28,17 +28,16 @@
#include <string.h>
#include <time.h>
#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
-
+#include <gdk/gdkkeysyms.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <libedataserverui/e-categories-dialog.h>
#include <libebook/e-address-western.h>
+#include <libedataserverui/e-book-auth-util.h>
+#include <libedataserverui/e-categories-dialog.h>
#include <libedataserverui/e-category-completion.h>
#include <libedataserverui/e-source-combo-box.h>
-#include "addressbook/util/addressbook.h"
#include "addressbook/printing/e-contact-print.h"
#include "addressbook/gui/widgets/eab-gui-util.h"
#include "e-util/e-util.h"
@@ -2691,51 +2690,63 @@ init_all (EContactEditor *editor)
}
static void
-new_target_cb (EBook *new_book, const GError *error, EContactEditor *editor)
+contact_editor_book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ EContactEditor *editor)
{
- editor->load_source_id = 0;
- editor->load_book = NULL;
+ EBook *book;
+ GError *error = NULL;
- if (error || new_book == NULL) {
+ book = e_load_book_source_finish (source, result, &error);
+
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_warn_if_fail (book == NULL);
+ g_error_free (error);
+ goto exit;
+
+ } else if (error != NULL) {
GtkWidget *source_combo_box;
+ GtkWindow *parent;
+
+ g_warn_if_fail (book == NULL);
- eab_load_error_dialog (NULL, e_book_get_source (new_book), error);
+ parent = eab_editor_get_window (EAB_EDITOR (editor));
+ eab_load_error_dialog (GTK_WIDGET (parent), source, error);
source_combo_box = e_builder_get_widget (
editor->builder, "source-combo-box-source");
e_source_combo_box_set_active (
- E_SOURCE_COMBO_BOX (source_combo_box),
- e_book_get_source (editor->target_book));
+ E_SOURCE_COMBO_BOX (source_combo_box), source);
- if (new_book)
- g_object_unref (new_book);
- return;
+ g_error_free (error);
+ goto exit;
}
- g_object_set (editor, "target_book", new_book, NULL);
- g_object_unref (new_book);
-}
+ g_return_if_fail (E_IS_BOOK (book));
-static void
-cancel_load (EContactEditor *editor)
-{
- if (editor->load_source_id) {
- addressbook_load_cancel (editor->load_source_id);
- editor->load_source_id = 0;
+ /* FIXME Write a private contact_editor_set_target_book(). */
+ g_object_set (editor, "target_book", book, NULL);
- g_object_unref (editor->load_book);
- editor->load_book = NULL;
- }
+ g_object_unref (book);
+
+exit:
+ g_object_unref (editor);
}
static void
source_changed (ESourceComboBox *source_combo_box, EContactEditor *editor)
{
ESource *source;
+ GtkWindow *parent;
source = e_source_combo_box_get_active (source_combo_box);
+ parent = eab_editor_get_window (EAB_EDITOR (editor));
- cancel_load (editor);
+ if (editor->cancellable != NULL) {
+ g_cancellable_cancel (editor->cancellable);
+ g_object_unref (editor->cancellable);
+ editor->cancellable = NULL;
+ }
if (e_source_equal (e_book_get_source (editor->target_book), source))
return;
@@ -2745,9 +2756,12 @@ source_changed (ESourceComboBox *source_combo_box, EContactEditor *editor)
return;
}
- editor->load_book = e_book_new (source, NULL);
- editor->load_source_id = addressbook_load (editor->load_book,
- (EBookAsyncCallback) new_target_cb, editor);
+ editor->cancellable = g_cancellable_new ();
+
+ e_load_book_source_async (
+ source, parent, editor->cancellable,
+ (GAsyncReadyCallback) contact_editor_book_loaded_cb,
+ g_object_ref (editor));
}
static void
@@ -3520,9 +3534,6 @@ e_contact_editor_init (EContactEditor *e_contact_editor)
e_contact_editor->categories_dialog = NULL;
e_contact_editor->compress_ui = e_shell_get_express_mode (shell);
- e_contact_editor->load_source_id = 0;
- e_contact_editor->load_book = NULL;
-
builder = gtk_builder_new ();
e_load_ui_builder_definition (builder, "contact-editor.ui");
@@ -3634,7 +3645,10 @@ e_contact_editor_dispose (GObject *object)
e_contact_editor->builder = NULL;
}
- cancel_load (e_contact_editor);
+ if (e_contact_editor->cancellable != NULL) {
+ g_object_unref (e_contact_editor->cancellable);
+ e_contact_editor->cancellable = NULL;
+ }
if (G_OBJECT_CLASS (parent_class)->dispose)
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
@@ -3808,8 +3822,6 @@ e_contact_editor_set_property (GObject *object, guint prop_id, const GValue *val
if (changed)
sensitize_all (editor);
- /* If we're trying to load a new target book, cancel that here. */
- cancel_load (editor);
break;
}
diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h
index b41324c270..81b39d1e85 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.h
+++ b/addressbook/gui/contact-editor/e-contact-editor.h
@@ -91,9 +91,7 @@ struct _EContactEditor
EList *required_fields;
- /* ID for async load_source call */
- guint load_source_id;
- EBook *load_book;
+ GCancellable *cancellable;
/* signal ids for "writable_status" */
gint target_editable_id;
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.c b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
index 52c15ea8e0..af68ee0c8e 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
@@ -36,11 +36,11 @@
#include <gdk/gdkkeysyms.h>
#include <camel/camel.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-combo-box.h>
#include "e-util/e-util.h"
#include "addressbook/gui/widgets/eab-gui-util.h"
-#include "addressbook/util/addressbook.h"
#include "addressbook/util/eab-book-util.h"
#include "eab-editor.h"
@@ -124,10 +124,6 @@ struct _EContactListEditorPrivate {
/* Whether an async wombat call is in progress. */
guint in_async_call : 1;
-
- /* ID for async load_source call */
- guint load_source_id;
- EBook *load_book;
};
static gpointer parent_class;
@@ -207,48 +203,43 @@ contact_list_editor_add_email (EContactListEditor *editor)
}
static void
-contact_list_editor_book_loaded (EBook *new_book,
- const GError *error,
- EContactListEditor *editor)
+contact_list_editor_book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ EContactListEditor *editor)
{
EContactListEditorPrivate *priv = editor->priv;
EContactStore *contact_store;
ENameSelectorEntry *entry;
+ EBook *book;
+ GError *error = NULL;
- priv->load_source_id = 0;
- priv->load_book = NULL;
+ book = e_load_book_source_finish (source, result, &error);
+
+ if (error != NULL) {
+ GtkWindow *parent;
+
+ parent = eab_editor_get_window (EAB_EDITOR (editor));
+ eab_load_error_dialog (GTK_WIDGET (parent), source, error);
- if (error || new_book == NULL) {
- eab_load_error_dialog (
- NULL, e_book_get_source (new_book), error);
e_source_combo_box_set_active (
E_SOURCE_COMBO_BOX (WIDGET (SOURCE_MENU)),
e_book_get_source (priv->book));
- if (new_book)
- g_object_unref (new_book);
- return;
+
+ g_error_free (error);
+ goto exit;
}
+ g_return_if_fail (E_IS_BOOK (book));
+
entry = E_NAME_SELECTOR_ENTRY (WIDGET (EMAIL_ENTRY));
contact_store = e_name_selector_entry_peek_contact_store (entry);
- e_contact_store_add_book (contact_store, new_book);
- e_contact_list_editor_set_book (editor, new_book);
- g_object_unref (new_book);
-}
+ e_contact_store_add_book (contact_store, book);
+ e_contact_list_editor_set_book (editor, book);
-static void
-contact_list_editor_cancel_load (EContactListEditor *editor)
-{
- EContactListEditorPrivate *priv = editor->priv;
-
- if (priv->load_source_id == 0)
- return;
+ g_object_unref (book);
- addressbook_load_cancel (priv->load_source_id);
- priv->load_source_id = 0;
-
- g_object_unref (priv->load_book);
- priv->load_book = NULL;
+exit:
+ g_object_unref (editor);
}
static gboolean
@@ -808,6 +799,7 @@ void
contact_list_editor_source_menu_changed_cb (GtkWidget *widget)
{
EContactListEditor *editor;
+ GtkWindow *parent;
ESource *source;
editor = contact_list_editor_extract (widget);
@@ -816,10 +808,12 @@ contact_list_editor_source_menu_changed_cb (GtkWidget *widget)
if (e_source_equal (e_book_get_source (editor->priv->book), source))
return;
- editor->priv->load_book = e_book_new (source, NULL);
- editor->priv->load_source_id = addressbook_load (
- editor->priv->load_book, (EBookAsyncCallback)
- contact_list_editor_book_loaded, editor);
+ parent = eab_editor_get_window (EAB_EDITOR (editor));
+
+ e_load_book_source_async (
+ source, parent, NULL, (GAsyncReadyCallback)
+ contact_list_editor_book_loaded_cb,
+ g_object_ref (editor));
}
gboolean
@@ -1057,8 +1051,6 @@ contact_list_editor_dispose (GObject *object)
EContactListEditor *editor = E_CONTACT_LIST_EDITOR (object);
EContactListEditorPrivate *priv = editor->priv;
- contact_list_editor_cancel_load (editor);
-
if (priv->name_selector) {
g_object_unref (priv->name_selector);
priv->name_selector = NULL;
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 8e3a6a4e38..9ca8033291 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -30,6 +30,7 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libedataserver/e-data-server-util.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-selector.h>
#include <e-util/e-util.h>
#include "eab-gui-util.h"
@@ -45,8 +46,6 @@
/* we link to camel for decoding quoted printable email addresses */
#include <camel/camel.h>
-#include "addressbook/util/addressbook.h"
-
void
eab_error_dialog (const gchar *msg, const GError *error)
{
@@ -379,30 +378,42 @@ do_copy (gpointer data, gpointer user_data)
}
static void
-got_book_cb (EBook *book, const GError *error, gpointer closure)
+book_loaded_cb (ESource *destination,
+ GAsyncResult *result,
+ ContactCopyProcess *process)
{
- ContactCopyProcess *process;
- process = closure;
- if (!error) {
+ EBook *book;
+ GError *error = NULL;
+
+ book = e_load_book_source_finish (destination, result, &error);
+
+ if (book != NULL) {
+ g_warn_if_fail (error == NULL);
process->destination = book;
process->book_status = TRUE;
- g_object_ref (book);
- g_list_foreach (process->contacts,
- do_copy,
- process);
+ g_list_foreach (process->contacts, do_copy, process);
+
+ } else if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+
process_unref (process);
}
void
-eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean delete_from_source, GtkWindow *parent_window)
+eab_transfer_contacts (EBook *source_book,
+ GList *contacts /* adopted */,
+ gboolean delete_from_source,
+ GtkWindow *parent_window)
{
- EBook *dest;
- ESource *destination_source;
+ ESource *destination;
static gchar *last_uid = NULL;
ContactCopyProcess *process;
gchar *desc;
+ g_return_if_fail (E_IS_BOOK (source_book));
+
if (contacts == NULL)
return;
@@ -421,22 +432,22 @@ eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean de
desc = _("Copy contacts to");
}
- destination_source = eab_select_source (e_book_get_source (source), desc, NULL,
- last_uid, parent_window);
+ destination = eab_select_source (
+ e_book_get_source (source_book),
+ desc, NULL, last_uid, parent_window);
- if (!destination_source)
+ if (!destination)
return;
- if (strcmp (last_uid, e_source_peek_uid (destination_source)) != 0) {
+ if (strcmp (last_uid, e_source_peek_uid (destination)) != 0) {
g_free (last_uid);
- last_uid = g_strdup (e_source_peek_uid (destination_source));
+ last_uid = g_strdup (e_source_peek_uid (destination));
}
process = g_new (ContactCopyProcess, 1);
process->count = 1;
process->book_status = FALSE;
- process->source = source;
- g_object_ref (source);
+ process->source = g_object_ref (source_book);
process->contacts = contacts;
process->destination = NULL;
@@ -445,8 +456,9 @@ eab_transfer_contacts (EBook *source, GList *contacts /* adopted */, gboolean de
else
process->done_cb = NULL;
- dest = e_book_new (destination_source, NULL);
- addressbook_load (dest, got_book_cb, process);
+ e_load_book_source_async (
+ destination, parent_window, NULL,
+ (GAsyncReadyCallback) book_loaded_cb, process);
}
/* To parse something like...
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 5f8890feb2..e1fd43fdf3 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -29,25 +29,25 @@
G_BEGIN_DECLS
-void eab_error_dialog (const gchar *msg,
- const GError *error);
-void eab_load_error_dialog (GtkWidget *parent,
- ESource *source,
- const GError *error);
-void eab_search_result_dialog (GtkWidget *parent,
- EBookViewStatus status,
- const gchar *error_msg);
-gint eab_prompt_save_dialog (GtkWindow *parent);
-
-void eab_transfer_contacts (EBook *source,
- GList *contacts, /* adopted */
- gboolean delete_from_source,
- GtkWindow *parent_window);
-
-gchar * eab_suggest_filename (GList *contact_list);
-
-ESource *eab_select_source (ESource *except_source, const gchar *title, const gchar *message,
- const gchar *select_uid, GtkWindow *parent);
+void eab_error_dialog (const gchar *msg,
+ const GError *error);
+void eab_load_error_dialog (GtkWidget *parent,
+ ESource *source,
+ const GError *error);
+void eab_search_result_dialog (GtkWidget *parent,
+ EBookViewStatus status,
+ const gchar *error_msg);
+gint eab_prompt_save_dialog (GtkWindow *parent);
+void eab_transfer_contacts (EBook *source_book,
+ GList *contacts, /* adopted */
+ gboolean delete_from_source,
+ GtkWindow *parent_window);
+gchar * eab_suggest_filename (GList *contact_list);
+ESource * eab_select_source (ESource *except_source,
+ const gchar *title,
+ const gchar *message,
+ const gchar *select_uid,
+ GtkWindow *parent);
/* To parse quoted printable address & return email & name fields */
gboolean eab_parse_qp_email (const gchar *string,