aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-01-22 05:31:09 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:41:21 +0800
commit042c0c5732a6d6144e9359ddb55f7c9e65f60010 (patch)
tree175b65e4f815b94de5372bf40da75321b55e9e6e /addressbook/gui
parente6db1d3c9c0d141fa93a6ba023e322fb822f74ee (diff)
downloadgsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.gz
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.bz2
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.lz
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.xz
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.zst
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.zip
Use e_load_book_source_async() for all EBook loading.
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.c130
-rw-r--r--addressbook/gui/merging/eab-contact-compare.c66
2 files changed, 110 insertions, 86 deletions
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index 032f4ac475..ca4fb6f01b 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -27,8 +27,8 @@
#include <glib/gi18n.h>
#include <libebook/e-book.h>
#include <libebook/e-contact.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-combo-box.h>
-#include <addressbook/util/addressbook.h>
#include <addressbook/util/eab-book-util.h>
#include "e-contact-editor.h"
#include "e-contact-quick-add.h"
@@ -41,7 +41,9 @@ struct _QuickAdd {
gchar *email;
gchar *vcard;
EContact *contact;
- EBook *book;
+ GCancellable *cancellable;
+ ESourceList *source_list;
+ ESource *source;
EContactQuickAddCallback cb;
gpointer closure;
@@ -60,27 +62,22 @@ quick_add_new (void)
{
QuickAdd *qa = g_new0 (QuickAdd, 1);
qa->contact = e_contact_new ();
- qa->book = NULL;
qa->refs = 1;
return qa;
}
-#if 0
-static void
-quick_add_ref (QuickAdd *qa)
-{
- if (qa) {
- ++qa->refs;
- }
-}
-#endif
-
static void
quick_add_unref (QuickAdd *qa)
{
if (qa) {
--qa->refs;
if (qa->refs == 0) {
+ if (qa->cancellable != NULL) {
+ g_cancellable_cancel (qa->cancellable);
+ g_object_unref (qa->cancellable);
+ }
+ if (qa->source_list != NULL)
+ g_object_unref (qa->source_list);
g_free (qa->name);
g_free (qa->email);
g_free (qa->vcard);
@@ -121,9 +118,18 @@ quick_add_set_vcard (QuickAdd *qa, const gchar *vcard)
}
static void
-merge_cb (EBook *book, const GError *error, gpointer closure)
+merge_cb (ESource *source,
+ GAsyncResult *result,
+ QuickAdd *qa)
{
- QuickAdd *qa = (QuickAdd *) closure;
+ EBook *book;
+ GError *error = NULL;
+
+ book = e_load_book_source_finish (source, result, &error);
+
+ /* Ignore cancellations. */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ return;
if (!error) {
if (e_book_is_writable (book))
@@ -151,7 +157,16 @@ merge_cb (EBook *book, const GError *error, gpointer closure)
static void
quick_add_merge_contact (QuickAdd *qa)
{
- addressbook_load (qa->book, merge_cb, qa);
+ if (qa->cancellable != NULL) {
+ g_cancellable_cancel (qa->cancellable);
+ g_object_unref (qa->cancellable);
+ }
+
+ qa->cancellable = g_cancellable_new ();
+
+ e_load_book_source_async (
+ qa->source, NULL, qa->cancellable,
+ (GAsyncReadyCallback) merge_cb, qa);
}
/*
@@ -235,9 +250,18 @@ ce_have_contact (EBook *book, const GError *error, EContact *contact, gpointer c
}
static void
-ce_have_book (EBook *book, const GError *error, gpointer closure)
+ce_have_book (ESource *source,
+ GAsyncResult *result,
+ QuickAdd *qa)
{
- QuickAdd *qa = (QuickAdd *) closure;
+ EBook *book;
+ GError *error = NULL;
+
+ book = e_load_book_source_finish (source, result, &error);
+
+ /* Ignore cancellations. */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ return;
if (error) {
if (book)
@@ -252,7 +276,16 @@ ce_have_book (EBook *book, const GError *error, gpointer closure)
static void
edit_contact (QuickAdd *qa)
{
- addressbook_load (qa->book, ce_have_book, qa);
+ if (qa->cancellable != NULL) {
+ g_cancellable_cancel (qa->cancellable);
+ g_object_unref (qa->cancellable);
+ }
+
+ qa->cancellable = g_cancellable_new ();
+
+ e_load_book_source_async (
+ qa->source, NULL, qa->cancellable,
+ (GAsyncReadyCallback) ce_have_book, qa);
}
#define QUICK_ADD_RESPONSE_EDIT_FULL 2
@@ -313,11 +346,14 @@ sanitize_widgets (QuickAdd *qa)
g_return_if_fail (qa != NULL);
g_return_if_fail (qa->dialog != NULL);
- /* do not call here e_book_is_writable (qa->book), because it requires opened book, which takes time for remote books */
- enabled = qa->book != NULL && e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->combo_box));
+ enabled = (e_source_combo_box_get_active_uid (
+ E_SOURCE_COMBO_BOX (qa->combo_box)) != NULL);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (qa->dialog), QUICK_ADD_RESPONSE_EDIT_FULL, enabled);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (qa->dialog), GTK_RESPONSE_OK, enabled);
+ gtk_dialog_set_response_sensitive (
+ GTK_DIALOG (qa->dialog),
+ QUICK_ADD_RESPONSE_EDIT_FULL, enabled);
+ gtk_dialog_set_response_sensitive (
+ GTK_DIALOG (qa->dialog), GTK_RESPONSE_OK, enabled);
}
static void
@@ -327,11 +363,9 @@ source_changed (ESourceComboBox *source_combo_box, QuickAdd *qa)
source = e_source_combo_box_get_active (source_combo_box);
if (source != NULL) {
- if (qa->book) {
- g_object_unref (qa->book);
- qa->book = NULL;
- }
- qa->book = e_book_new (source, NULL);
+ if (qa->source != NULL)
+ g_object_unref (qa->source);
+ qa->source = g_object_ref (source);
}
sanitize_widgets (qa);
@@ -340,13 +374,12 @@ source_changed (ESourceComboBox *source_combo_box, QuickAdd *qa)
static GtkWidget *
build_quick_add_dialog (QuickAdd *qa)
{
- ESourceList *source_list;
GConfClient *gconf_client;
GtkWidget *container;
GtkWidget *dialog;
GtkWidget *label;
GtkTable *table;
- EBook *book;
+ ESource *source;
const gint xpad=0, ypad=0;
g_return_val_if_fail (qa != NULL, NULL);
@@ -386,46 +419,19 @@ build_quick_add_dialog (QuickAdd *qa)
}
gconf_client = gconf_client_get_default ();
- source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/addressbook/sources");
+ qa->source_list = e_source_list_new_for_gconf (
+ gconf_client, "/apps/evolution/addressbook/sources");
+ source = e_source_list_peek_default_source (qa->source_list);
g_object_unref (gconf_client);
- qa->combo_box = e_source_combo_box_new (source_list);
- book = e_book_new_default_addressbook (NULL);
+ qa->combo_box = e_source_combo_box_new (qa->source_list);
e_source_combo_box_set_active (
- E_SOURCE_COMBO_BOX (qa->combo_box),
- e_book_get_source (book));
-
- if (!e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->combo_box))) {
- /* this means the e_book_new_default_addressbook didn't find any "default" nor "system" source,
- and created new one for us. That is wrong, choose one from combo instead. */
+ E_SOURCE_COMBO_BOX (qa->combo_box), source);
- if (book) {
- g_object_unref (book);
- book = NULL;
- }
-
- book = e_book_new (e_source_list_peek_source_any (source_list), NULL);
- e_source_combo_box_set_active (E_SOURCE_COMBO_BOX (qa->combo_box), e_book_get_source (book));
-
- if (!e_source_combo_box_get_active_uid (E_SOURCE_COMBO_BOX (qa->combo_box))) {
- /* Does it failed again? What is going on? */
- if (book)
- g_object_unref (book);
- book = NULL;
- }
- }
-
- if (qa->book) {
- g_object_unref (qa->book);
- qa->book = NULL;
- }
- qa->book = book;
source_changed (E_SOURCE_COMBO_BOX (qa->combo_box), qa);
g_signal_connect (
qa->combo_box, "changed",
G_CALLBACK (source_changed), qa);
- g_object_unref (source_list);
-
table = GTK_TABLE (gtk_table_new (3, 2, FALSE));
gtk_table_set_row_spacings (table, 6);
gtk_table_set_col_spacings (table, 12);
diff --git a/addressbook/gui/merging/eab-contact-compare.c b/addressbook/gui/merging/eab-contact-compare.c
index d5ba1a5f84..db92649f6d 100644
--- a/addressbook/gui/merging/eab-contact-compare.c
+++ b/addressbook/gui/merging/eab-contact-compare.c
@@ -24,7 +24,7 @@
#include <config.h>
#include <ctype.h>
#include <string.h>
-#include "addressbook/util/addressbook.h"
+#include <libedataserverui/e-book-auth-util.h>
#include "addressbook/util/eab-book-util.h"
#include "eab-contact-compare.h"
@@ -541,6 +541,7 @@ eab_contact_compare (EContact *contact1, EContact *contact2)
typedef struct _MatchSearchInfo MatchSearchInfo;
struct _MatchSearchInfo {
+ ESourceList *source_list;
EContact *contact;
GList *avoid;
EABContactMatchQueryCallback cb;
@@ -551,6 +552,9 @@ static void
match_search_info_free (MatchSearchInfo *info)
{
if (info) {
+ if (info->source_list != NULL)
+ g_object_unref (info->source_list);
+
g_object_unref (info->contact);
/* This should already have been deallocated, but just in case... */
@@ -626,9 +630,9 @@ query_cb (EBook *book, const GError *error, GList *contacts, gpointer closure)
#define MAX_QUERY_PARTS 10
static void
-use_common_book_cb (EBook *book, const GError *error, gpointer closure)
+use_common_book (EBook *book,
+ MatchSearchInfo *info)
{
- MatchSearchInfo *info = (MatchSearchInfo *) closure;
EContact *contact = info->contact;
EContactName *contact_name;
GList *contact_email;
@@ -716,22 +720,23 @@ use_common_book_cb (EBook *book, const GError *error, gpointer closure)
e_book_query_unref (query);
}
-void
-eab_contact_locate_match (EContact *contact, EABContactMatchQueryCallback cb, gpointer closure)
+static void
+book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ MatchSearchInfo *info)
{
- MatchSearchInfo *info;
+ EBook *book;
- g_return_if_fail (contact && E_IS_CONTACT (contact));
- g_return_if_fail (cb != NULL);
-
- info = g_new (MatchSearchInfo, 1);
- info->contact = contact;
- g_object_ref (contact);
- info->cb = cb;
- info->closure = closure;
- info->avoid = NULL;
+ book = e_load_book_source_finish (source, result, NULL);
+ use_common_book (book, info);
+}
- addressbook_load_default_book ((EBookAsyncCallback) use_common_book_cb, info);
+void
+eab_contact_locate_match (EContact *contact,
+ EABContactMatchQueryCallback cb,
+ gpointer closure)
+{
+ eab_contact_locate_match_full (NULL, contact, NULL, cb, closure);
}
/**
@@ -746,24 +751,37 @@ eab_contact_locate_match (EContact *contact, EABContactMatchQueryCallback cb, gp
* Look for the best match and return it using the EABContactMatchQueryCallback.
**/
void
-eab_contact_locate_match_full (EBook *book, EContact *contact, GList *avoid, EABContactMatchQueryCallback cb, gpointer closure)
+eab_contact_locate_match_full (EBook *book,
+ EContact *contact,
+ GList *avoid,
+ EABContactMatchQueryCallback cb,
+ gpointer closure)
{
MatchSearchInfo *info;
+ ESource *source;
- g_return_if_fail (contact && E_IS_CONTACT (contact));
+ g_return_if_fail (E_IS_CONTACT (contact));
g_return_if_fail (cb != NULL);
info = g_new (MatchSearchInfo, 1);
- info->contact = contact;
- g_object_ref (contact);
+ info->contact = g_object_ref (contact);
info->cb = cb;
info->closure = closure;
info->avoid = g_list_copy (avoid);
g_list_foreach (info->avoid, (GFunc) g_object_ref, NULL);
- if (book)
- use_common_book_cb (book, NULL, info);
- else
- addressbook_load_default_book ((EBookAsyncCallback) use_common_book_cb, info);
+ if (book) {
+ use_common_book (book, info);
+ return;
+ }
+
+ if (!e_book_get_addressbooks (&info->source_list, NULL))
+ return;
+
+ source = e_source_list_peek_default_source (info->source_list);
+
+ e_load_book_source_async (
+ source, NULL, NULL, (GAsyncReadyCallback)
+ book_loaded_cb, info);
}