aboutsummaryrefslogtreecommitdiffstats
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
parente6db1d3c9c0d141fa93a6ba023e322fb822f74ee (diff)
downloadgsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.gz
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.tar.zst
gsoc2013-evolution-042c0c5732a6d6144e9359ddb55f7c9e65f60010.zip
Use e_load_book_source_async() for all EBook loading.
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.c130
-rw-r--r--addressbook/gui/merging/eab-contact-compare.c66
-rw-r--r--addressbook/importers/evolution-csv-importer.c37
-rw-r--r--addressbook/importers/evolution-ldif-importer.c36
-rw-r--r--addressbook/importers/evolution-vcard-importer.c31
-rw-r--r--addressbook/util/Makefile.am2
-rw-r--r--addressbook/util/addressbook.c349
-rw-r--r--addressbook/util/addressbook.h31
-rw-r--r--modules/addressbook/addressbook-config.c1
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 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);
}
diff --git a/addressbook/importers/evolution-csv-importer.c b/addressbook/importers/evolution-csv-importer.c
index 9e15a58dee..69e82957d6 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 f5fe14bd6b..d78f29e0d7 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 1610337036..c9cc489f2b 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 6338e221fe..fe45b3d7e2 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/addressbook/util/addressbook.c b/addressbook/util/addressbook.c
deleted file mode 100644
index a6673fcda0..0000000000
--- a/addressbook/util/addressbook.c
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with the program; if not, see <http://www.gnu.org/licenses/>
- *
- *
- * Authors:
- * Chris Lahey <clahey@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
- */
-
-#include <config.h>
-
-#include <string.h>
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <libebook/e-book.h>
-#include <libedataserver/e-url.h>
-#include <libedataserverui/e-passwords.h>
-
-#include "e-util/e-alert-dialog.h"
-#include "shell/e-shell.h"
-#include "addressbook.h"
-
-#define d(x)
-
-static void addressbook_authenticate (EBook *book, gboolean previous_failure,
- ESource *source, EBookAsyncCallback cb, gpointer closure);
-static void auth_required_cb (EBook *book, gpointer data);
-
-typedef struct {
- EBookAsyncCallback cb;
- ESource *source;
- gpointer closure;
- guint cancelled : 1;
-} LoadSourceData;
-
-static void
-free_load_source_data (LoadSourceData *data)
-{
- if (data->source)
- g_object_unref (data->source);
- g_free (data);
-}
-
-/*this function removes of anything present after semicolon
-in uri*/
-
-static gchar *
-remove_parameters_from_uri (const gchar *uri)
-{
- gchar *euri_str;
- EUri *euri;
-
- euri = e_uri_new (uri);
- euri_str = e_uri_to_string (euri, FALSE);
- e_uri_free (euri);
- return euri_str;
-}
-
-static void
-load_source_auth_cb (EBook *book, const GError *error, gpointer closure)
-{
- LoadSourceData *data = closure;
- gboolean was_in = g_object_get_data (G_OBJECT (book), "authenticated") != NULL;
-
- g_object_set_data (G_OBJECT (book), "authenticated", NULL);
-
- if (data->cancelled) {
- free_load_source_data (data);
- return;
- }
-
- if (error) {
-
- /* the user clicked cancel in the password dialog */
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) {
-
- if (e_book_check_static_capability (book, "anon-access")) {
-
- GtkWidget *dialog;
-
- /* XXX "LDAP" has to be removed from the folowing message
- so that it wil valid for other servers which provide
- anonymous access*/
-
- dialog = gtk_message_dialog_new (
- NULL, 0,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "%s", _("Accessing LDAP Server anonymously"));
- g_signal_connect (
- dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
- gtk_widget_show (dialog);
- error = NULL;
-
- goto done;
- }
- } else if (g_error_matches (error, E_BOOK_ERROR,
- E_BOOK_ERROR_INVALID_SERVER_VERSION)) {
- e_alert_run_dialog_for_args (
- e_shell_get_active_window (NULL),
- "addressbook:server-version", NULL);
- error = NULL;
- goto done;
- } else if (g_error_matches (error, E_BOOK_ERROR,
- E_BOOK_ERROR_UNSUPPORTED_AUTHENTICATION_METHOD)) {
- goto done;
- } else {
- if (g_error_matches (error, E_BOOK_ERROR,
- E_BOOK_ERROR_AUTHENTICATION_FAILED)) {
- const gchar *uri = e_book_get_uri (book);
- gchar *stripped_uri = remove_parameters_from_uri (uri);
- const gchar *auth_domain = e_source_get_property (data->source, "auth-domain");
- const gchar *component_name;
-
- component_name = auth_domain ? auth_domain : "Addressbook";
-
- e_passwords_forget_password (component_name, stripped_uri);
-
- g_free (stripped_uri);
- } else if (was_in) {
- /* We already tried to authenticate to the server, and it failed with
- other reason than with E_BOOK_ERROR_AUTHENTICATION_FAILED, thus stop
- poking with the server and report error to the user. */
- goto done;
- }
-
- g_object_set_data (G_OBJECT (book), "authenticated", GINT_TO_POINTER (1));
- addressbook_authenticate (book, TRUE, data->source, load_source_auth_cb, closure);
- return;
- }
- }
-
-done:
- if (data->cb)
- data->cb (book, error, data->closure);
-
- free_load_source_data (data);
-}
-
-static gboolean
-get_remember_password (ESource *source)
-{
- const gchar *value;
-
- value = e_source_get_property (source, "remember_password");
- if (value && !g_ascii_strcasecmp (value, "true"))
- return TRUE;
-
- return FALSE;
-}
-
-static void
-set_remember_password (ESource *source, gboolean value)
-{
- e_source_set_property (source, "remember_password",
- value ? "true" : "false");
-}
-
-static void
-addressbook_authenticate (EBook *book, gboolean previous_failure, ESource *source,
- EBookAsyncCallback cb, gpointer closure)
-{
- const gchar *password = NULL;
- gchar *pass_dup = NULL;
- const gchar *auth;
- const gchar *user;
- gchar *uri = remove_parameters_from_uri (e_book_get_uri (book));
- const gchar *auth_domain = e_source_get_property (source, "auth-domain");
- const gchar *component_name;
-
- component_name = auth_domain ? auth_domain : "Addressbook";
-
- password = e_passwords_get_password (component_name, uri);
-
- auth = e_source_get_property (source, "auth");
-
- if (auth && !strcmp ("ldap/simple-binddn", auth)) {
- user = e_source_get_property (source, "binddn");
- }
- else if (auth && !strcmp ("plain/password", auth)) {
- user = e_source_get_property (source, "user");
- if (!user) {
- user = e_source_get_property (source, "username");
- }
- }
- else {
- user = e_source_get_property (source, "email_addr");
- }
- if (!user)
- user = "";
-
- if (!password) {
- gchar *prompt;
- gchar *password_prompt;
- gboolean remember;
- const gchar *failed_auth;
- guint32 flags = E_PASSWORDS_REMEMBER_FOREVER|E_PASSWORDS_SECRET|E_PASSWORDS_ONLINE;
-
- if (previous_failure) {
- failed_auth = _("Failed to authenticate.\n");
- flags |= E_PASSWORDS_REPROMPT;
- }
- else {
- failed_auth = "";
- }
-
- password_prompt = g_strdup_printf (_("Enter password for %s (user %s)"),
- e_source_peek_name (source), user);
-
- prompt = g_strconcat (failed_auth, password_prompt, NULL);
- g_free (password_prompt);
-
- remember = get_remember_password (source);
- pass_dup = e_passwords_ask_password (
- _("Enter password"), component_name,
- uri, prompt, flags, &remember, NULL);
- if (remember != get_remember_password (source))
- set_remember_password (source, remember);
-
- g_free (prompt);
- }
-
- if (password || pass_dup) {
- e_book_authenticate_user_async (book, user, password ? password : pass_dup,
- e_source_get_property (source, "auth"),
- cb, closure);
- g_free (pass_dup);
- }
- else {
- GError *error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED, _("Cancelled"));
-
- /* they hit cancel */
- cb (book, error, closure);
-
- g_error_free (error);
- }
-
- g_free (uri);
-}
-
-static void
-auth_required_cb (EBook *book, gpointer data)
-{
- LoadSourceData *load_source_data = g_new0 (LoadSourceData, 1);
-
- load_source_data->source = g_object_ref (g_object_ref (e_book_get_source (book)));
- load_source_data->cancelled = FALSE;
- addressbook_authenticate (book, FALSE, load_source_data->source,
- load_source_auth_cb, load_source_data);
-
-}
-static void
-load_source_cb (EBook *book, const GError *error, gpointer closure)
-{
- LoadSourceData *load_source_data = closure;
-
- if (load_source_data->cancelled) {
- free_load_source_data (load_source_data);
- return;
- }
-
- if (!error && book != NULL) {
- const gchar *auth;
-
- auth = e_source_get_property (load_source_data->source, "auth");
- if (auth && strcmp (auth, "none")) {
- g_signal_connect (book, "auth_required", G_CALLBACK(auth_required_cb), NULL);
-
- if (e_book_is_online (book)) {
- addressbook_authenticate (book, FALSE, load_source_data->source,
- load_source_auth_cb, closure);
- return;
- }
- }
- }
- load_source_data->cb (book, error, load_source_data->closure);
- free_load_source_data (load_source_data);
-}
-
-guint
-addressbook_load (EBook *book,
- EBookAsyncCallback cb, gpointer closure)
-{
- LoadSourceData *load_source_data = g_new0 (LoadSourceData, 1);
-
- load_source_data->cb = cb;
- load_source_data->closure = closure;
- load_source_data->source = g_object_ref (g_object_ref (e_book_get_source (book)));
- load_source_data->cancelled = FALSE;
-
- e_book_open_async (book, FALSE, load_source_cb, load_source_data);
-
- return GPOINTER_TO_UINT (load_source_data);
-}
-
-void
-addressbook_load_cancel (guint id)
-{
- LoadSourceData *load_source_data = GUINT_TO_POINTER (id);
-
- load_source_data->cancelled = TRUE;
-}
-
-static void
-default_book_cb (EBook *book, const GError *error, gpointer closure)
-{
- LoadSourceData *load_source_data = closure;
-
- if (!error)
- load_source_data->source = g_object_ref (e_book_get_source (book));
-
- load_source_cb (book, error, closure);
-}
-
-void
-addressbook_load_default_book (EBookAsyncCallback cb, gpointer closure)
-{
- LoadSourceData *load_source_data = g_new (LoadSourceData, 1);
- EBook *book;
- GError *error = NULL;
-
- load_source_data->cb = cb;
- load_source_data->source = NULL;
- load_source_data->closure = closure;
- load_source_data->cancelled = FALSE;
-
- book = e_book_new_default_addressbook (&error);
- if (!book) {
- load_source_cb (NULL, error, load_source_data);
- g_error_free (error);
- } else
- e_book_open_async (
- book, FALSE, default_book_cb, load_source_data);
-}
diff --git a/addressbook/util/addressbook.h b/addressbook/util/addressbook.h
deleted file mode 100644
index 84163786d8..0000000000
--- a/addressbook/util/addressbook.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with the program; if not, see <http://www.gnu.org/licenses/>
- *
- *
- * Authors:
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
- */
-
-#ifndef __ADDRESSBOOK_H__
-#define __ADDRESSBOOK_H__
-
-#include <libebook/e-book.h>
-
-guint addressbook_load (EBook *book, EBookAsyncCallback cb, gpointer closure);
-void addressbook_load_cancel (guint id);
-void addressbook_load_default_book (EBookAsyncCallback open_response, gpointer closure);
-
-#endif /* __ADDRESSBOOK_H__ */
diff --git a/modules/addressbook/addressbook-config.c b/modules/addressbook/addressbook-config.c
index 3066da022d..83154161e6 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"