[evolution/webkit] Use e_load_book_source_async() for all EBook loading.
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit] Use e_load_book_source_async() for all EBook loading.
- Date: Mon, 11 Jul 2011 14:03:19 +0000 (UTC)
commit 68d5c1dd005982e2de80b2ea62f782b08e799197
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Jan 21 16:31:09 2011 -0500
Use e_load_book_source_async() for all EBook loading.
.../gui/contact-editor/e-contact-quick-add.c | 130 ++++----
addressbook/gui/merging/eab-contact-compare.c | 66 +++--
addressbook/importers/evolution-csv-importer.c | 37 +--
addressbook/importers/evolution-ldif-importer.c | 36 +--
addressbook/importers/evolution-vcard-importer.c | 31 +-
addressbook/util/Makefile.am | 2 -
addressbook/util/addressbook.c | 349 --------------------
addressbook/util/addressbook.h | 31 --
modules/addressbook/addressbook-config.c | 1 -
9 files changed, 154 insertions(+), 529 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index 032f4ac..ca4fb6f 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 d5ba1a5..db92649 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);
}
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 9e15a58..69e8295 100644
--- a/addressbook/importers/evolution-csv-importer.c
+++ b/addressbook/importers/evolution-csv-importer.c
@@ -32,12 +32,12 @@
#include <glib/gstdio.h>
#include <libebook/e-book.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-selector.h>
#include <libebook/e-destination.h>
#include "e-util/e-import.h"
-#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
@@ -828,24 +828,25 @@ csv_import_done (CSVImporter *gci)
}
static void
-book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ CSVImporter *gci)
{
- CSVImporter *gci = closure;
+ gci->book = e_load_book_source_finish (source, result, NULL);
- g_return_if_fail (gci != NULL);
- g_return_if_fail (gci->book == book);
-
- if (error)
+ if (gci->book == NULL) {
csv_import_done (gci);
- else
- gci->idle_id = g_idle_add (csv_import_contacts, gci);
+ return;
+ }
+
+ gci->idle_id = g_idle_add (csv_import_contacts, gci);
}
static void
csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
CSVImporter *gci;
- EBook *book;
+ ESource *source;
gchar *filename;
FILE *file;
EImportTargetURI *s = (EImportTargetURI *) target;
@@ -856,20 +857,11 @@ csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
return;
}
- book = e_book_new(g_datalist_get_data(&target->data, "csv-source"), NULL);
- if (book == NULL) {
- g_message("Couldn't Create EBook");
- e_import_complete (ei, target);
- g_free (filename);
- return;
- }
-
file = g_fopen (filename, "r");
g_free (filename);
if (file == NULL) {
g_message("Can't open .csv file");
e_import_complete (ei, target);
- g_object_unref (book);
return;
}
@@ -877,7 +869,6 @@ csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
g_datalist_set_data(&target->data, "csv-data", gci);
gci->import = g_object_ref (ei);
gci->target = target;
- gci->book = book;
gci->file = file;
gci->fields_map = NULL;
gci->count = 0;
@@ -885,7 +876,11 @@ csv_import (EImport *ei, EImportTarget *target, EImportImporter *im)
gci->size = ftell (file);
fseek (file, 0, SEEK_SET);
- addressbook_load (gci->book, book_loaded_cb, gci);
+ source = g_datalist_get_data (&target->data, "csv-source");
+
+ e_load_book_source_async (
+ source, NULL, NULL, (GAsyncReadyCallback)
+ book_loaded_cb, gci);
}
static void
diff --git a/addressbook/importers/evolution-ldif-importer.c b/addressbook/importers/evolution-ldif-importer.c
index f5fe14b..d78f29e 100644
--- a/addressbook/importers/evolution-ldif-importer.c
+++ b/addressbook/importers/evolution-ldif-importer.c
@@ -42,12 +42,12 @@
#include <glib/gstdio.h>
#include <libebook/e-book.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-selector.h>
#include <libebook/e-destination.h>
#include "e-util/e-import.h"
-#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
@@ -622,35 +622,29 @@ ldif_import_done (LDIFImporter *gci)
}
static void
-book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ LDIFImporter *gci)
{
- LDIFImporter *gci = closure;
+ gci->book = e_load_book_source_finish (source, result, NULL);
- g_return_if_fail (gci != NULL);
- g_return_if_fail (gci->book == book);
-
- if (error)
+ if (gci->book == NULL) {
ldif_import_done (gci);
- else
- gci->idle_id = g_idle_add (ldif_import_contacts, gci);
+ return;
+ }
+
+ gci->idle_id = g_idle_add (ldif_import_contacts, gci);
}
static void
ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
LDIFImporter *gci;
- EBook *book;
+ ESource *source;
FILE *file = NULL;
EImportTargetURI *s = (EImportTargetURI *)target;
gchar *filename;
- book = e_book_new(g_datalist_get_data(&target->data, "ldif-source"), NULL);
- if (book == NULL) {
- g_message(G_STRLOC ":Couldn't create EBook.");
- e_import_complete (ei, target);
- return;
- }
-
filename = g_filename_from_uri (s->uri_src, NULL, NULL);
if (filename != NULL) {
file = g_fopen(filename, "r");
@@ -659,7 +653,6 @@ ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
if (file == NULL) {
g_message(G_STRLOC ":Can't open .ldif file");
e_import_complete (ei, target);
- g_object_unref (book);
return;
}
@@ -667,7 +660,6 @@ ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
g_datalist_set_data(&target->data, "ldif-data", gci);
gci->import = g_object_ref (ei);
gci->target = target;
- gci->book = book;
gci->file = file;
fseek (file, 0, SEEK_END);
gci->size = ftell (file);
@@ -677,7 +669,11 @@ ldif_import (EImport *ei, EImportTarget *target, EImportImporter *im)
(GDestroyNotify) g_free,
(GDestroyNotify) NULL);
- addressbook_load (gci->book, book_loaded_cb, gci);
+ source = g_datalist_get_data (&target->data, "ldif-source");
+
+ e_load_book_source_async (
+ source, NULL, NULL, (GAsyncReadyCallback)
+ book_loaded_cb, gci);
}
static void
diff --git a/addressbook/importers/evolution-vcard-importer.c b/addressbook/importers/evolution-vcard-importer.c
index 1610337..c9cc489 100644
--- a/addressbook/importers/evolution-vcard-importer.c
+++ b/addressbook/importers/evolution-vcard-importer.c
@@ -36,6 +36,7 @@
#include <glib/gstdio.h>
#include <libebook/e-book.h>
+#include <libedataserverui/e-book-auth-util.h>
#include <libedataserverui/e-source-selector.h>
#include <util/eab-book-util.h>
@@ -44,7 +45,6 @@
#include "e-util/e-import.h"
#include "e-util/e-datetime-format.h"
#include "misc/e-web-view-preview.h"
-#include "util/addressbook.h"
#include "evolution-addressbook-importers.h"
@@ -475,14 +475,13 @@ vcard_import_done (VCardImporter *gci)
}
static void
-book_loaded_cb (EBook *book, const GError *error, gpointer closure)
+book_loaded_cb (ESource *source,
+ GAsyncResult *result,
+ VCardImporter *gci)
{
- VCardImporter *gci = closure;
+ gci->book = e_load_book_source_finish (source, result, NULL);
- g_return_if_fail (gci != NULL);
- g_return_if_fail (gci->book == book);
-
- if (error) {
+ if (gci->book == NULL) {
vcard_import_done (gci);
return;
}
@@ -517,7 +516,7 @@ static void
vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
{
VCardImporter *gci;
- EBook *book;
+ ESource *source;
EImportTargetURI *s = (EImportTargetURI *)target;
gchar *filename;
gchar *contents;
@@ -538,19 +537,10 @@ vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
return;
}
- book = e_book_new(g_datalist_get_data(&target->data, "vcard-source"), NULL);
- if (book == NULL) {
- g_message(G_STRLOC ":Couldn't create EBook.");
- g_free (filename);
- e_import_complete (ei, target);
- return;
- }
-
if (!g_file_get_contents (filename, &contents, NULL, NULL)) {
g_message (G_STRLOC ":Couldn't read file.");
g_free (filename);
e_import_complete (ei, target);
- g_object_unref (book);
return;
}
@@ -559,11 +549,14 @@ vcard_import (EImport *ei, EImportTarget *target, EImportImporter *im)
g_datalist_set_data(&target->data, "vcard-data", gci);
gci->import = g_object_ref (ei);
gci->target = target;
- gci->book = book;
gci->encoding = encoding;
gci->contents = contents;
- addressbook_load (book, book_loaded_cb, gci);
+ source = g_datalist_get_data (&target->data, "vcard-source");
+
+ e_load_book_source_async (
+ source, NULL, NULL, (GAsyncReadyCallback)
+ book_loaded_cb, gci);
}
static void
diff --git a/addressbook/util/Makefile.am b/addressbook/util/Makefile.am
index 6338e22..fe45b3d 100644
--- a/addressbook/util/Makefile.am
+++ b/addressbook/util/Makefile.am
@@ -15,8 +15,6 @@ libeabutil_la_CPPFLAGS = \
$(EVOLUTION_ADDRESSBOOK_CFLAGS)
libeabutil_la_SOURCES = \
- addressbook.c \
- addressbook.h \
eab-book-util.c \
eab-book-util.h
diff --git a/modules/addressbook/addressbook-config.c b/modules/addressbook/addressbook-config.c
index 3066da0..8315416 100644
--- a/modules/addressbook/addressbook-config.c
+++ b/modules/addressbook/addressbook-config.c
@@ -41,7 +41,6 @@
#undef DATADIR
#endif
-#include "addressbook.h"
#include "addressbook-config.h"
#include "e-util/e-util.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]