aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
committerMilan Crha <mcrha@redhat.com>2011-06-14 14:54:20 +0800
commit38790d8478e906a5c59d0c4a5216f297f305bfeb (patch)
tree0f9a96db2765901f2a27b68c84815a491214ecc1 /addressbook/gui
parent08af0d1f81a4e983bb49d8fb8fe74e670adbb8f6 (diff)
downloadgsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.gz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.bz2
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.lz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.xz
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.tar.zst
gsoc2013-evolution-38790d8478e906a5c59d0c4a5216f297f305bfeb.zip
Do not use deprecated EBook/ECal API
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c382
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.h12
-rw-r--r--addressbook/gui/contact-editor/e-contact-quick-add.c80
-rw-r--r--addressbook/gui/contact-editor/eab-editor.h1
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-editor.c141
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-editor.h10
-rw-r--r--addressbook/gui/merging/eab-contact-compare.c88
-rw-r--r--addressbook/gui/merging/eab-contact-compare.h4
-rw-r--r--addressbook/gui/merging/eab-contact-merging.c141
-rw-r--r--addressbook/gui/merging/eab-contact-merging.h32
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c296
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.h16
-rw-r--r--addressbook/gui/widgets/e-addressbook-reflow-adapter.c21
-rw-r--r--addressbook/gui/widgets/e-addressbook-selector.c127
-rw-r--r--addressbook/gui/widgets/e-addressbook-table-adapter.c15
-rw-r--r--addressbook/gui/widgets/e-addressbook-table-adapter.h2
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c260
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.h6
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.c38
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.h4
-rw-r--r--addressbook/gui/widgets/e-minicard-view.c95
-rw-r--r--addressbook/gui/widgets/e-minicard-view.h8
-rw-r--r--addressbook/gui/widgets/e-minicard.c1
-rw-r--r--addressbook/gui/widgets/ea-minicard-view.c10
-rw-r--r--addressbook/gui/widgets/eab-gui-util.c204
-rw-r--r--addressbook/gui/widgets/eab-gui-util.h11
26 files changed, 1082 insertions, 923 deletions
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index b636190777..4088837f90 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -35,7 +35,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libebook/e-address-western.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-categories-dialog.h>
#include <libedataserverui/e-category-completion.h>
#include <libedataserverui/e-source-combo-box.h>
@@ -107,8 +107,8 @@ static EABEditorClass *parent_class = NULL;
/* The arguments we take */
enum {
PROP_0,
- PROP_SOURCE_BOOK,
- PROP_TARGET_BOOK,
+ PROP_SOURCE_CLIENT,
+ PROP_TARGET_CLIENT,
PROP_CONTACT,
PROP_IS_NEW_CONTACT,
PROP_EDITABLE,
@@ -213,7 +213,7 @@ e_contact_editor_contact_added (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error adding contact"), error);
@@ -227,7 +227,7 @@ e_contact_editor_contact_modified (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error modifying contact"), error);
@@ -241,7 +241,7 @@ e_contact_editor_contact_deleted (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error removing contact"), error);
@@ -305,22 +305,22 @@ e_contact_editor_class_init (EContactEditorClass *klass)
g_object_class_install_property (
object_class,
- PROP_SOURCE_BOOK,
+ PROP_SOURCE_CLIENT,
g_param_spec_object (
- "source_book",
- "Source Book",
+ "source_client",
+ "Source EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
- PROP_TARGET_BOOK,
+ PROP_TARGET_CLIENT,
g_param_spec_object (
- "target_book",
- "Target Book",
+ "target_client",
+ "Target EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (
@@ -346,21 +346,19 @@ e_contact_editor_class_init (EContactEditorClass *klass)
g_object_class_install_property (
object_class,
PROP_WRITABLE_FIELDS,
- g_param_spec_object (
+ g_param_spec_pointer (
"writable_fields",
"Writable Fields",
NULL,
- E_TYPE_LIST,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_REQUIRED_FIELDS,
- g_param_spec_object (
+ g_param_spec_pointer (
"required_fields",
"Required Fields",
NULL,
- E_TYPE_LIST,
G_PARAM_READWRITE));
g_object_class_install_property (
@@ -394,9 +392,8 @@ entry_activated (EContactEditor *editor)
static gboolean
is_field_supported (EContactEditor *editor, EContactField field_id)
{
- EList *fields;
+ GSList *fields, *iter;
const gchar *field;
- EIterator *iter;
fields = editor->writable_fields;
if (!fields)
@@ -406,10 +403,8 @@ is_field_supported (EContactEditor *editor, EContactField field_id)
if (!field)
return FALSE;
- for (iter = e_list_get_iterator (fields);
- e_iterator_is_valid (iter);
- e_iterator_next (iter)) {
- const gchar *this_field = e_iterator_get (iter);
+ for (iter = fields; iter; iter = iter->next) {
+ const gchar *this_field = iter->data;
if (!this_field)
continue;
@@ -692,7 +687,7 @@ fill_in_source_field (EContactEditor *editor)
{
GtkWidget *source_menu;
- if (!editor->target_book)
+ if (!editor->target_client)
return;
source_menu = e_builder_get_widget (
@@ -700,7 +695,7 @@ fill_in_source_field (EContactEditor *editor)
e_source_combo_box_set_active (
E_SOURCE_COMBO_BOX (source_menu),
- e_book_get_source (editor->target_book));
+ e_client_get_source (E_CLIENT (editor->target_client)));
}
static void
@@ -2976,25 +2971,27 @@ init_all (EContactEditor *editor)
}
static void
-contact_editor_book_loaded_cb (ESource *source,
+contact_editor_book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- EContactEditor *editor)
+ gpointer user_data)
{
- EBook *book;
+ ESource *source = E_SOURCE (source_object);
+ EContactEditor *editor = user_data;
+ EClient *client = NULL;
GError *error = NULL;
- book = e_load_book_source_finish (source, result, &error);
+ if (!e_client_utils_open_new_finish (source, result, &client, &error))
+ client = NULL;
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_warn_if_fail (book == NULL);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+ g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
+ g_warn_if_fail (client == NULL);
g_error_free (error);
- goto exit;
-
} else if (error != NULL) {
GtkWidget *source_combo_box;
GtkWindow *parent;
- g_warn_if_fail (book == NULL);
+ g_warn_if_fail (client == NULL);
parent = eab_editor_get_window (EAB_EDITOR (editor));
eab_load_error_dialog (GTK_WIDGET (parent), NULL, source, error);
@@ -3005,17 +3002,18 @@ contact_editor_book_loaded_cb (ESource *source,
E_SOURCE_COMBO_BOX (source_combo_box), source);
g_error_free (error);
- goto exit;
- }
+ } else {
+ EBookClient *book_client;
- g_return_if_fail (E_IS_BOOK (book));
+ book_client = E_BOOK_CLIENT (client);
+ g_return_if_fail (book_client != NULL);
- /* FIXME Write a private contact_editor_set_target_book(). */
- g_object_set (editor, "target_book", book, NULL);
+ /* FIXME Write a private contact_editor_set_target_client(). */
+ g_object_set (editor, "target_client", book_client, NULL);
- g_object_unref (book);
+ g_object_unref (book_client);
+ }
-exit:
g_object_unref (editor);
}
@@ -3034,20 +3032,19 @@ source_changed (ESourceComboBox *source_combo_box, EContactEditor *editor)
editor->cancellable = NULL;
}
- if (e_source_equal (e_book_get_source (editor->target_book), source))
+ if (e_source_equal (e_client_get_source (E_CLIENT (editor->target_client)), source))
return;
- if (e_source_equal (e_book_get_source (editor->source_book), source)) {
- g_object_set (editor, "target_book", editor->source_book, NULL);
+ if (e_source_equal (e_client_get_source (E_CLIENT (editor->source_client)), source)) {
+ g_object_set (editor, "target_client", editor->source_client, NULL);
return;
}
editor->cancellable = g_cancellable_new ();
- e_load_book_source_async (
- source, parent, editor->cancellable,
- (GAsyncReadyCallback) contact_editor_book_loaded_cb,
- g_object_ref (editor));
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, editor->cancellable,
+ e_client_utils_authenticate_handler, parent,
+ contact_editor_book_loaded_cb, g_object_ref (editor));
}
static void
@@ -3348,10 +3345,15 @@ typedef struct {
} EditorCloseStruct;
static void
-contact_moved_cb (EBook *book, const GError *error, EditorCloseStruct *ecs)
+contact_removed_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EditorCloseStruct *ecs = user_data;
EContactEditor *ce = ecs->ce;
gboolean should_close = ecs->should_close;
+ GError *error = NULL;
+
+ e_book_client_remove_contact_finish (book_client, result, &error);
gtk_widget_set_sensitive (ce->app, TRUE);
ce->in_async_call = FALSE;
@@ -3364,44 +3366,43 @@ contact_moved_cb (EBook *book, const GError *error, EditorCloseStruct *ecs)
if (should_close) {
eab_editor_close (EAB_EDITOR (ce));
- }
- else {
+ } else {
ce->changed = FALSE;
- g_object_ref (ce->target_book);
- g_object_unref (ce->source_book);
- ce->source_book = ce->target_book;
+ g_object_ref (ce->target_client);
+ g_object_unref (ce->source_client);
+ ce->source_client = ce->target_client;
sensitize_all (ce);
}
+ if (error)
+ g_error_free (error);
+
g_object_unref (ce);
g_free (ecs->new_id);
g_free (ecs);
}
static void
-contact_added_cb (EBook *book,
- const GError *error,
- const gchar *id,
- EditorCloseStruct *ecs)
+contact_added_cb (EBookClient *book_client, const GError *error, const gchar *id, gpointer closure)
{
+ EditorCloseStruct *ecs = closure;
EContactEditor *ce = ecs->ce;
gboolean should_close = ecs->should_close;
- if (ce->source_book != ce->target_book && e_book_is_writable (ce->source_book) &&
+ if (ce->source_client != ce->target_client && !e_client_is_readonly (E_CLIENT (ce->source_client)) &&
!error && ce->is_new_contact == FALSE) {
ecs->new_id = g_strdup (id);
- e_book_remove_contact_async (
- ce->source_book, ce->contact,
- (EBookAsyncCallback) contact_moved_cb, ecs);
+ e_book_client_remove_contact (
+ ce->source_client, ce->contact, NULL, contact_removed_cb, ecs);
return;
}
gtk_widget_set_sensitive (ce->app, TRUE);
ce->in_async_call = FALSE;
- e_contact_set (ce->contact, E_CONTACT_UID, (gchar *) id);
+ e_contact_set (ce->contact, E_CONTACT_UID, id);
eab_editor_contact_added (EAB_EDITOR (ce), error, ce->contact);
@@ -3410,8 +3411,7 @@ contact_added_cb (EBook *book,
if (should_close) {
eab_editor_close (EAB_EDITOR (ce));
- }
- else {
+ } else {
ce->changed = FALSE;
sensitize_all (ce);
}
@@ -3422,8 +3422,9 @@ contact_added_cb (EBook *book,
}
static void
-contact_modified_cb (EBook *book, const GError *error, EditorCloseStruct *ecs)
+contact_modified_cb (EBookClient *book_client, const GError *error, gpointer closure)
{
+ EditorCloseStruct *ecs = closure;
EContactEditor *ce = ecs->ce;
gboolean should_close = ecs->should_close;
@@ -3446,6 +3447,20 @@ contact_modified_cb (EBook *book, const GError *error, EditorCloseStruct *ecs)
g_free (ecs);
}
+static void
+contact_modified_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ GError *error = NULL;
+
+ e_book_client_modify_contact_finish (book_client, result, &error);
+
+ contact_modified_cb (book_client, error, user_data);
+
+ if (error)
+ g_error_free (error);
+}
+
/* Emits the signal to request saving a contact */
static void
real_save_contact (EContactEditor *ce, gboolean should_close)
@@ -3461,23 +3476,24 @@ real_save_contact (EContactEditor *ce, gboolean should_close)
gtk_widget_set_sensitive (ce->app, FALSE);
ce->in_async_call = TRUE;
- if (ce->source_book != ce->target_book) {
+ if (ce->source_client != ce->target_client) {
/* Two-step move; add to target, then remove from source */
eab_merging_book_add_contact (
- ce->target_book, ce->contact,
- (EBookIdAsyncCallback) contact_added_cb, ecs);
+ ce->target_client, ce->contact,
+ contact_added_cb, ecs);
} else {
if (ce->is_new_contact)
eab_merging_book_add_contact (
- ce->target_book, ce->contact,
- (EBookIdAsyncCallback) contact_added_cb, ecs);
+ ce->target_client, ce->contact,
+ contact_added_cb, ecs);
else if (ce->check_merge)
- eab_merging_book_commit_contact (
- ce->target_book, ce->contact,
- (EBookAsyncCallback) contact_modified_cb, ecs);
+ eab_merging_book_modify_contact (
+ ce->target_client, ce->contact,
+ contact_modified_cb, ecs);
else
- e_book_commit_contact_async (ce->target_book, ce->contact,
- (EBookAsyncCallback) contact_modified_cb, ecs);
+ e_book_client_modify_contact (
+ ce->target_client, ce->contact, NULL,
+ contact_modified_ready_cb, ecs);
}
}
@@ -3488,10 +3504,10 @@ save_contact (EContactEditor *ce, gboolean should_close)
const gchar *name_entry_string, *file_as_entry_string, *company_name_string;
GtkWidget *entry_fullname, *entry_file_as, *company_name;
- if (!ce->target_book)
+ if (!ce->target_client)
return;
- if (ce->target_editable && !e_book_is_writable (ce->source_book)) {
+ if (ce->target_editable && e_client_is_readonly (E_CLIENT (ce->source_client))) {
if (e_alert_run_dialog_for_args (
GTK_WINDOW (ce->app),
"addressbook:prompt-move",
@@ -3592,7 +3608,7 @@ e_contact_editor_is_valid (EABEditor *editor)
EContactEditor *ce = E_CONTACT_EDITOR (editor);
GtkWidget *widget;
gboolean validation_error = FALSE;
- EIterator *iter;
+ GSList *iter;
GString *errmsg = g_string_new (_("The contact data is invalid:\n\n"));
widget = e_builder_get_widget (ce->builder, "dateedit-birthday");
@@ -3610,11 +3626,8 @@ e_contact_editor_is_valid (EABEditor *editor)
validation_error = TRUE;
}
- iter = e_list_get_iterator (ce->required_fields);
- for (e_iterator_last (iter);
- e_iterator_is_valid (iter);
- e_iterator_prev (iter)) {
- const gchar *field_name = e_iterator_get (iter);
+ for (iter = ce->required_fields; iter; iter = iter->next) {
+ const gchar *field_name = iter->data;
EContactField field_id = e_contact_field_id (field_name);
if (is_non_string_field (field_id)) {
@@ -3967,11 +3980,11 @@ e_contact_editor_dispose (GObject *object)
}
if (e_contact_editor->writable_fields) {
- g_object_unref (e_contact_editor->writable_fields);
+ e_client_util_free_string_slist (e_contact_editor->writable_fields);
e_contact_editor->writable_fields = NULL;
}
if (e_contact_editor->required_fields) {
- g_object_unref (e_contact_editor->required_fields);
+ e_client_util_free_string_slist (e_contact_editor->required_fields);
e_contact_editor->required_fields = NULL;
}
if (e_contact_editor->contact) {
@@ -3979,17 +3992,17 @@ e_contact_editor_dispose (GObject *object)
e_contact_editor->contact = NULL;
}
- if (e_contact_editor->source_book) {
- g_object_unref (e_contact_editor->source_book);
- e_contact_editor->source_book = NULL;
+ if (e_contact_editor->source_client) {
+ g_object_unref (e_contact_editor->source_client);
+ e_contact_editor->source_client = NULL;
}
- if (e_contact_editor->target_book) {
+ if (e_contact_editor->target_client) {
g_signal_handler_disconnect (
- e_contact_editor->target_book,
+ e_contact_editor->target_client,
e_contact_editor->target_editable_id);
- g_object_unref (e_contact_editor->target_book);
- e_contact_editor->target_book = NULL;
+ g_object_unref (e_contact_editor->target_client);
+ e_contact_editor->target_client = NULL;
}
if (e_contact_editor->name) {
@@ -4012,46 +4025,78 @@ e_contact_editor_dispose (GObject *object)
}
static void
-supported_fields_cb (EBook *book,
- const GError *error,
- EList *fields,
- EContactEditor *ce)
+supported_fields_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EContactEditor *ce = user_data;
+ gchar *prop_value = NULL;
+ GSList *fields;
+ GError *error = NULL;
+
+ if (!e_client_get_backend_property_finish (E_CLIENT (book_client), result, &prop_value, &error))
+ prop_value = NULL;
+
+ if (error) {
+ g_debug ("%s: Failed to get supported fields: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
if (!g_slist_find (eab_editor_get_all_editors (), ce)) {
g_warning (
"supported_fields_cb called for book that's still "
"around, but contact editor that's been destroyed.");
+ g_free (prop_value);
return;
}
+ fields = e_client_util_parse_comma_strings (prop_value);
+
g_object_set (ce, "writable_fields", fields, NULL);
+ e_client_util_free_string_slist (fields);
+ g_free (prop_value);
+
eab_editor_show (EAB_EDITOR (ce));
sensitize_all (ce);
}
static void
-required_fields_cb (EBook *book,
- const GError *error,
- EList *fields,
- EContactEditor *ce)
+required_fields_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EContactEditor *ce = user_data;
+ gchar *prop_value = NULL;
+ GSList *fields;
+ GError *error = NULL;
+
+ if (!e_client_get_backend_property_finish (E_CLIENT (book_client), result, &prop_value, &error))
+ prop_value = NULL;
+
+ if (error) {
+ g_debug ("%s: Failed to get supported fields: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
if (!g_slist_find (eab_editor_get_all_editors (), ce)) {
g_warning (
"supported_fields_cb called for book that's still "
"around, but contact editor that's been destroyed.");
+ g_free (prop_value);
return;
}
+ fields = e_client_util_parse_comma_strings (prop_value);
+
g_object_set (ce, "required_fields", fields, NULL);
+ e_client_util_free_string_slist (fields);
+ g_free (prop_value);
}
EABEditor *
e_contact_editor_new (EShell *shell,
- EBook *book,
+ EBookClient *book_client,
EContact *contact,
gboolean is_new_contact,
gboolean editable)
@@ -4059,34 +4104,29 @@ e_contact_editor_new (EShell *shell,
EABEditor *editor;
g_return_val_if_fail (E_IS_SHELL (shell), NULL);
- g_return_val_if_fail (E_IS_BOOK (book), NULL);
+ g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
g_return_val_if_fail (E_IS_CONTACT (contact), NULL);
editor = g_object_new (E_TYPE_CONTACT_EDITOR, "shell", shell, NULL);
g_object_set (
editor,
- "source_book", book,
+ "source_client", book_client,
"contact", contact,
"is_new_contact", is_new_contact,
"editable", editable,
NULL);
- if (book)
- e_book_get_supported_fields_async (
- book, (EBookEListAsyncCallback)
- supported_fields_cb, editor);
-
return editor;
}
static void
-writable_changed (EBook *book, gboolean writable, EContactEditor *ce)
+notify_readonly_cb (EBookClient *book_client, EContactEditor *ce)
{
gint new_target_editable;
gboolean changed = FALSE;
- new_target_editable = e_book_is_writable (ce->target_book);
+ new_target_editable = !e_client_is_readonly (E_CLIENT (ce->target_client));
if (ce->target_editable != new_target_editable)
changed = TRUE;
@@ -4108,41 +4148,35 @@ e_contact_editor_set_property (GObject *object,
editor = E_CONTACT_EDITOR (object);
switch (prop_id) {
- case PROP_SOURCE_BOOK: {
+ case PROP_SOURCE_CLIENT: {
gboolean writable;
gboolean changed = FALSE;
- EBook *source_book;
+ EBookClient *source_client;
- source_book = E_BOOK (g_value_get_object (value));
+ source_client = E_BOOK_CLIENT (g_value_get_object (value));
- if (source_book == editor->source_book)
+ if (source_client == editor->source_client)
break;
- if (editor->source_book)
- g_object_unref (editor->source_book);
+ if (editor->source_client)
+ g_object_unref (editor->source_client);
- editor->source_book = source_book;
- g_object_ref (editor->source_book);
+ editor->source_client = source_client;
+ g_object_ref (editor->source_client);
- if (!editor->target_book) {
- editor->target_book = editor->source_book;
- g_object_ref (editor->target_book);
+ if (!editor->target_client) {
+ editor->target_client = editor->source_client;
+ g_object_ref (editor->target_client);
editor->target_editable_id = g_signal_connect (
- editor->target_book, "writable_status",
- G_CALLBACK (writable_changed), editor);
-
- e_book_get_supported_fields_async (
- editor->target_book,
- (EBookEListAsyncCallback)
- supported_fields_cb, editor);
- e_book_get_required_fields_async (
- editor->target_book,
- (EBookEListAsyncCallback)
- required_fields_cb, editor);
+ editor->target_client, "notify::readonly",
+ G_CALLBACK (notify_readonly_cb), editor);
+
+ e_client_get_backend_property (E_CLIENT (editor->target_client), BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS, NULL, supported_fields_cb, editor);
+ e_client_get_backend_property (E_CLIENT (editor->target_client), BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS, NULL, required_fields_cb, editor);
}
- writable = e_book_is_writable (editor->target_book);
+ writable = !e_client_is_readonly (E_CLIENT (editor->target_client));
if (writable != editor->target_editable) {
editor->target_editable = writable;
changed = TRUE;
@@ -4154,43 +4188,35 @@ e_contact_editor_set_property (GObject *object,
break;
}
- case PROP_TARGET_BOOK: {
+ case PROP_TARGET_CLIENT: {
gboolean writable;
gboolean changed = FALSE;
- EBook *target_book;
+ EBookClient *target_client;
- target_book = E_BOOK (g_value_get_object (value));
+ target_client = E_BOOK_CLIENT (g_value_get_object (value));
- if (target_book == editor->target_book)
+ if (target_client == editor->target_client)
break;
- if (editor->target_book) {
- g_signal_handler_disconnect (
- editor->target_book,
- editor->target_editable_id);
- g_object_unref (editor->target_book);
+ if (editor->target_client) {
+ g_signal_handler_disconnect (editor->target_client, editor->target_editable_id);
+ g_object_unref (editor->target_client);
}
- editor->target_book = target_book;
- g_object_ref (editor->target_book);
+ editor->target_client = target_client;
+ g_object_ref (editor->target_client);
editor->target_editable_id = g_signal_connect (
- editor->target_book, "writable_status",
- G_CALLBACK (writable_changed), editor);
-
- e_book_get_supported_fields_async (
- editor->target_book,
- (EBookEListAsyncCallback)
- supported_fields_cb, editor);
-
- e_book_get_required_fields_async (
- editor->target_book,
- (EBookEListAsyncCallback)
- required_fields_cb, editor);
+ editor->target_client, "notify::readonly",
+ G_CALLBACK (notify_readonly_cb), editor);
+
+ e_client_get_backend_property (E_CLIENT (editor->target_client), BOOK_BACKEND_PROPERTY_SUPPORTED_FIELDS, NULL, supported_fields_cb, editor);
+ e_client_get_backend_property (E_CLIENT (editor->target_client), BOOK_BACKEND_PROPERTY_REQUIRED_FIELDS, NULL, required_fields_cb, editor);
+
if (!editor->is_new_contact)
editor->changed = TRUE;
- writable = e_book_is_writable (editor->target_book);
+ writable = !e_client_is_readonly (E_CLIENT (editor->target_client));
if (writable != editor->target_editable) {
editor->target_editable = writable;
@@ -4238,24 +4264,16 @@ e_contact_editor_set_property (GObject *object,
}
case PROP_WRITABLE_FIELDS:
if (editor->writable_fields)
- g_object_unref (editor->writable_fields);
+ e_client_util_free_string_slist (editor->writable_fields);
- editor->writable_fields = g_value_get_object (value);
- if (editor->writable_fields)
- g_object_ref (editor->writable_fields);
- else
- editor->writable_fields = e_list_new (NULL, NULL, NULL);
+ editor->writable_fields = e_client_util_copy_string_slist (NULL, g_value_get_pointer (value));
sensitize_all (editor);
break;
case PROP_REQUIRED_FIELDS:
if (editor->required_fields)
- g_object_unref (editor->required_fields);
- editor->required_fields = g_value_get_object (value);
- if (editor->required_fields)
- g_object_ref (editor->required_fields);
- else
- editor->required_fields = e_list_new (NULL, NULL, NULL);
+ e_client_util_free_string_slist (editor->required_fields);
+ editor->required_fields = e_client_util_copy_string_slist (NULL, g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -4274,12 +4292,12 @@ e_contact_editor_get_property (GObject *object,
e_contact_editor = E_CONTACT_EDITOR (object);
switch (prop_id) {
- case PROP_SOURCE_BOOK:
- g_value_set_object (value, e_contact_editor->source_book);
+ case PROP_SOURCE_CLIENT:
+ g_value_set_object (value, e_contact_editor->source_client);
break;
- case PROP_TARGET_BOOK:
- g_value_set_object (value, e_contact_editor->target_book);
+ case PROP_TARGET_CLIENT:
+ g_value_set_object (value, e_contact_editor->target_client);
break;
case PROP_CONTACT:
@@ -4303,20 +4321,10 @@ e_contact_editor_get_property (GObject *object,
break;
case PROP_WRITABLE_FIELDS:
- if (e_contact_editor->writable_fields)
- g_value_set_object (
- value, e_list_duplicate (
- e_contact_editor->writable_fields));
- else
- g_value_set_object (value, NULL);
+ g_value_set_pointer (value, e_contact_editor->writable_fields);
break;
case PROP_REQUIRED_FIELDS:
- if (e_contact_editor->required_fields)
- g_value_set_object (
- value, e_list_duplicate (
- e_contact_editor->required_fields));
- else
- g_value_set_object (value, NULL);
+ g_value_set_pointer (value, e_contact_editor->required_fields);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h
index 2f00a12f67..7f39fe421e 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.h
+++ b/addressbook/gui/contact-editor/e-contact-editor.h
@@ -25,7 +25,7 @@
#include "addressbook/gui/contact-editor/eab-editor.h"
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-contact.h>
#include <gtk/gtk.h>
@@ -55,8 +55,8 @@ struct _EContactEditor
EABEditor object;
/* item specific fields */
- EBook *source_book;
- EBook *target_book;
+ EBookClient *source_client;
+ EBookClient *target_client;
EContact *contact;
GtkBuilder *builder;
@@ -90,9 +90,9 @@ struct _EContactEditor
/* Whether to try to reduce space used */
guint compress_ui : 1;
- EList *writable_fields;
+ GSList *writable_fields;
- EList *required_fields;
+ GSList *required_fields;
GCancellable *cancellable;
@@ -110,7 +110,7 @@ struct _EContactEditorClass
GType e_contact_editor_get_type (void);
EABEditor *e_contact_editor_new (EShell *shell,
- EBook *book,
+ EBookClient *book_client,
EContact *contact,
gboolean is_new_contact,
gboolean editable);
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index c7a42233c2..ac46c0ecfc 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -28,9 +28,9 @@
#include <string.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-contact.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-combo-box.h>
#include <addressbook/util/eab-book-util.h>
#include "e-contact-editor.h"
@@ -121,37 +121,42 @@ quick_add_set_vcard (QuickAdd *qa, const gchar *vcard)
}
static void
-merge_cb (ESource *source,
- GAsyncResult *result,
- QuickAdd *qa)
+merge_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EBook *book;
+ ESource *source = E_SOURCE (source_object);
+ QuickAdd *qa = user_data;
+ EClient *client = NULL;
GError *error = NULL;
- book = e_load_book_source_finish (source, result, &error);
+ if (!e_client_utils_open_new_finish (source, result, &client, &error))
+ client = NULL;
/* Ignore cancellations. */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+ g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
+ g_error_free (error);
return;
+ }
if (!error) {
- if (e_book_is_writable (book))
- eab_merging_book_add_contact (book, qa->contact, NULL, NULL);
+ if (!e_client_is_readonly (client))
+ eab_merging_book_add_contact (E_BOOK_CLIENT (client), qa->contact, NULL, NULL);
else
e_alert_run_dialog_for_args (e_shell_get_active_window (NULL),
"addressbook:error-read-only",
- e_source_peek_name (e_book_get_source (book)),
+ e_source_peek_name (e_client_get_source (client)),
NULL);
if (qa->cb)
qa->cb (qa->contact, qa->closure);
- g_object_unref (book);
+ g_object_unref (client);
} else {
/* Something went wrong. */
- if (book)
- g_object_unref (book);
+ if (client)
+ g_object_unref (client);
if (qa->cb)
qa->cb (NULL, qa->closure);
+ g_error_free (error);
}
quick_add_unref (qa);
@@ -167,9 +172,9 @@ quick_add_merge_contact (QuickAdd *qa)
qa->cancellable = g_cancellable_new ();
- e_load_book_source_async (
- qa->source, NULL, qa->cancellable,
- (GAsyncReadyCallback) merge_cb, qa);
+ e_client_utils_open_new (qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, qa->cancellable,
+ e_client_utils_authenticate_handler, NULL,
+ merge_cb, qa);
}
/* Raise a contact editor with all fields editable,
@@ -177,7 +182,7 @@ quick_add_merge_contact (QuickAdd *qa)
static void
contact_added_cb (EContactEditor *ce,
- EBookStatus status,
+ const GError *error,
EContact *contact,
gpointer closure)
{
@@ -204,7 +209,7 @@ editor_closed_cb (GtkWidget *w, gpointer closure)
}
static void
-ce_have_contact (EBook *book,
+ce_have_contact (EBookClient *book_client,
const GError *error,
EContact *contact,
gpointer closure)
@@ -212,8 +217,8 @@ ce_have_contact (EBook *book,
QuickAdd *qa = (QuickAdd *) closure;
if (error) {
- if (book)
- g_object_unref (book);
+ if (book_client)
+ g_object_unref (book_client);
g_warning (
"Failed to find contact, status %d (%s).",
error->code, error->message);
@@ -231,7 +236,7 @@ ce_have_contact (EBook *book,
shell = e_shell_get_default ();
contact_editor = e_contact_editor_new (
- shell, book, qa->contact, TRUE, TRUE /* XXX */);
+ shell, book_client, qa->contact, TRUE, TRUE /* XXX */);
/* Mark it as changed so the Save buttons are
* enabled when we bring up the dialog. */
@@ -256,31 +261,36 @@ ce_have_contact (EBook *book,
G_CALLBACK (editor_closed_cb),
NULL);
- g_object_unref (book);
+ g_object_unref (book_client);
}
}
static void
-ce_have_book (ESource *source,
- GAsyncResult *result,
- QuickAdd *qa)
+ce_have_book (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EBook *book;
+ ESource *source = E_SOURCE (source_object);
+ QuickAdd *qa = user_data;
+ EClient *client = NULL;
GError *error = NULL;
- book = e_load_book_source_finish (source, result, &error);
+ if (!e_client_utils_open_new_finish (source, result, &client, &error))
+ client = NULL;
/* Ignore cancellations. */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+ g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
+ g_error_free (error);
return;
+ }
if (error) {
- if (book)
- g_object_unref (book);
+ if (client)
+ g_object_unref (client);
g_warning ("Couldn't open local address book (%s).", error->message);
quick_add_unref (qa);
+ g_error_free (error);
} else {
- eab_merging_book_find_contact (book, qa->contact, ce_have_contact, qa);
+ eab_merging_book_find_contact (E_BOOK_CLIENT (client), qa->contact, ce_have_contact, qa);
}
}
@@ -294,9 +304,9 @@ edit_contact (QuickAdd *qa)
qa->cancellable = g_cancellable_new ();
- e_load_book_source_async (
- qa->source, NULL, qa->cancellable,
- (GAsyncReadyCallback) ce_have_book, qa);
+ e_client_utils_open_new (qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, qa->cancellable,
+ e_client_utils_authenticate_handler, NULL,
+ ce_have_book, qa);
}
#define QUICK_ADD_RESPONSE_EDIT_FULL 2
diff --git a/addressbook/gui/contact-editor/eab-editor.h b/addressbook/gui/contact-editor/eab-editor.h
index 5623aa5bd4..43e36e53a3 100644
--- a/addressbook/gui/contact-editor/eab-editor.h
+++ b/addressbook/gui/contact-editor/eab-editor.h
@@ -25,7 +25,6 @@
#define __EAB_EDITOR_H__
#include <gtk/gtk.h>
-#include <libebook/e-book.h>
#include <libebook/e-contact.h>
#include <shell/e-shell.h>
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 3fae1a2013..a4f30ca573 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
@@ -37,7 +37,7 @@
#include <gdk/gdkkeysyms.h>
#include <camel/camel.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-combo-box.h>
#include "e-util/e-util.h"
@@ -90,7 +90,7 @@
enum {
PROP_0,
- PROP_BOOK,
+ PROP_CLIENT,
PROP_CONTACT,
PROP_IS_NEW_LIST,
PROP_EDITABLE
@@ -103,7 +103,7 @@ typedef struct {
struct _EContactListEditorPrivate {
- EBook *book;
+ EBookClient *book_client;
EContact *contact;
GtkBuilder *builder;
@@ -208,17 +208,20 @@ contact_list_editor_add_email (EContactListEditor *editor)
}
static void
-contact_list_editor_book_loaded_cb (ESource *source,
+contact_list_editor_book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- EContactListEditor *editor)
+ gpointer user_data)
{
+ ESource *source = E_SOURCE (source_object);
+ EContactListEditor *editor = user_data;
EContactListEditorPrivate *priv = editor->priv;
EContactStore *contact_store;
ENameSelectorEntry *entry;
- EBook *book;
+ EClient *client = NULL;
+ EBookClient *book_client;
GError *error = NULL;
- book = e_load_book_source_finish (source, result, &error);
+ e_client_utils_open_new_finish (source, result, &client, &error);
if (error != NULL) {
GtkWindow *parent;
@@ -228,20 +231,21 @@ contact_list_editor_book_loaded_cb (ESource *source,
e_source_combo_box_set_active (
E_SOURCE_COMBO_BOX (WIDGET (SOURCE_MENU)),
- e_book_get_source (priv->book));
+ e_client_get_source (E_CLIENT (priv->book_client)));
g_error_free (error);
goto exit;
}
- g_return_if_fail (E_IS_BOOK (book));
+ book_client = E_BOOK_CLIENT (client);
+ g_return_if_fail (E_IS_BOOK_CLIENT (book_client));
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, book);
- e_contact_list_editor_set_book (editor, book);
+ e_contact_store_add_client (contact_store, book_client);
+ e_contact_list_editor_set_client (editor, book_client);
- g_object_unref (book);
+ g_object_unref (book_client);
exit:
g_object_unref (editor);
@@ -261,11 +265,12 @@ contact_list_editor_contact_exists (EContactListModel *model,
}
static void
-contact_list_editor_list_added_cb (EBook *book,
+contact_list_editor_list_added_cb (EBookClient *book_client,
const GError *error,
const gchar *id,
- EditorCloseStruct *ecs)
+ gpointer closure)
{
+ EditorCloseStruct *ecs = closure;
EContactListEditor *editor = ecs->editor;
EContactListEditorPrivate *priv = editor->priv;
gboolean should_close = ecs->should_close;
@@ -292,10 +297,11 @@ contact_list_editor_list_added_cb (EBook *book,
}
static void
-contact_list_editor_list_modified_cb (EBook *book,
+contact_list_editor_list_modified_cb (EBookClient *book_client,
const GError *error,
- EditorCloseStruct *ecs)
+ gpointer closure)
{
+ EditorCloseStruct *ecs = closure;
EContactListEditor *editor = ecs->editor;
EContactListEditorPrivate *priv = editor->priv;
gboolean should_close = ecs->should_close;
@@ -500,7 +506,7 @@ contact_list_editor_drag_data_received_cb (GtkWidget *widget,
gboolean changed = FALSE;
gboolean handled = FALSE;
const guchar *data;
- GList *list, *iter;
+ GSList *list, *iter;
GdkAtom target;
gint n_addresses = 0;
gchar *text;
@@ -546,8 +552,7 @@ contact_list_editor_drag_data_received_cb (GtkWidget *widget,
}
}
- g_list_foreach (list, (GFunc) g_object_unref, NULL);
- g_list_free (list);
+ e_client_util_free_object_slist (list);
contact_list_editor_scroll_to_end (editor);
@@ -894,21 +899,17 @@ void
contact_list_editor_source_menu_changed_cb (GtkWidget *widget)
{
EContactListEditor *editor;
- GtkWindow *parent;
ESource *source;
editor = contact_list_editor_extract (widget);
source = e_source_combo_box_get_active (E_SOURCE_COMBO_BOX (widget));
- if (e_source_equal (e_book_get_source (editor->priv->book), source))
+ if (e_source_equal (e_client_get_source (E_CLIENT (editor->priv->book_client)), source))
return;
- 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));
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, eab_editor_get_window (EAB_EDITOR (editor)),
+ contact_list_editor_book_loaded_cb, g_object_ref (editor));
}
gboolean
@@ -1097,7 +1098,7 @@ contact_list_editor_bottom_button_clicked_cb (GtkButton *button)
/******************** GtkBuilder Custom Widgets Functions ********************/
static gpointer
-contact_editor_fudge_new (EBook *book,
+contact_editor_fudge_new (EBookClient *book_client,
EContact *contact,
gboolean is_new,
gboolean editable)
@@ -1108,11 +1109,11 @@ contact_editor_fudge_new (EBook *book,
* was a terrible idea. Now we're stuck with it. */
return e_contact_editor_new (
- shell, book, contact, is_new, editable);
+ shell, book_client, contact, is_new, editable);
}
static gpointer
-contact_list_editor_fudge_new (EBook *book,
+contact_list_editor_fudge_new (EBookClient *book_client,
EContact *contact,
gboolean is_new,
gboolean editable)
@@ -1123,20 +1124,19 @@ contact_list_editor_fudge_new (EBook *book,
* was a terrible idea. Now we're stuck with it. */
return e_contact_list_editor_new (
- shell, book, contact, is_new, editable);
+ shell, book_client, contact, is_new, editable);
}
static void
setup_custom_widgets (EContactListEditor *editor)
{
- const gchar *key = "/apps/evolution/addressbook/sources";
GtkWidget *combo_box;
- GConfClient *client;
ESourceList *source_list;
ENameSelectorEntry *name_selector_entry;
ENameSelector *name_selector;
GtkWidget *old, *parent;
EContactListEditorPrivate *priv;
+ GError *error = NULL;
guint ba = 0, la = 0, ra = 0, ta = 0, xo = 0, xp = 0, yo = 0, yp = 0;
g_return_if_fail (editor != NULL);
@@ -1144,11 +1144,16 @@ setup_custom_widgets (EContactListEditor *editor)
priv = editor->priv;
combo_box = WIDGET (SOURCE_MENU);
- client = gconf_client_get_default ();
- source_list = e_source_list_new_for_gconf (client, key);
+ if (!e_book_client_get_sources (&source_list, &error))
+ source_list = NULL;
g_object_set (G_OBJECT (combo_box), "source-list", source_list, NULL);
- g_object_unref (source_list);
- g_object_unref (client);
+ if (source_list)
+ g_object_unref (source_list);
+
+ if (error) {
+ g_debug ("%s: Failed to get sources: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
g_signal_connect (
combo_box, "changed", G_CALLBACK (
@@ -1237,8 +1242,8 @@ contact_list_editor_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BOOK:
- e_contact_list_editor_set_book (
+ case PROP_CLIENT:
+ e_contact_list_editor_set_client (
E_CONTACT_LIST_EDITOR (object),
g_value_get_object (value));
return;
@@ -1272,10 +1277,10 @@ contact_list_editor_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BOOK:
+ case PROP_CLIENT:
g_value_set_object (
value,
- e_contact_list_editor_get_book (
+ e_contact_list_editor_get_client (
E_CONTACT_LIST_EDITOR (object)));
return;
@@ -1354,7 +1359,7 @@ contact_list_editor_save_contact (EABEditor *eab_editor,
contact = e_contact_list_editor_get_contact (editor);
- if (priv->book == NULL)
+ if (priv->book_client == NULL)
return;
ecs = g_new (EditorCloseStruct, 1);
@@ -1366,11 +1371,11 @@ contact_list_editor_save_contact (EABEditor *eab_editor,
if (priv->is_new_list)
eab_merging_book_add_contact (
- priv->book, contact, (EBookIdAsyncCallback)
+ priv->book_client, contact,
contact_list_editor_list_added_cb, ecs);
else
- eab_merging_book_commit_contact (
- priv->book, contact, (EBookAsyncCallback)
+ eab_merging_book_modify_contact (
+ priv->book_client, contact,
contact_list_editor_list_modified_cb, ecs);
priv->changed = FALSE;
@@ -1411,7 +1416,7 @@ contact_list_editor_contact_added (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error adding list"), error);
@@ -1425,7 +1430,7 @@ contact_list_editor_contact_modified (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error modifying list"), error);
@@ -1439,7 +1444,7 @@ contact_list_editor_contact_deleted (EABEditor *editor,
if (!error)
return;
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
return;
eab_error_dialog (NULL, _("Error removing list"), error);
@@ -1483,12 +1488,12 @@ contact_list_editor_class_init (EContactListEditorClass *class)
g_object_class_install_property (
object_class,
- PROP_BOOK,
+ PROP_CLIENT,
g_param_spec_object (
- "book",
- "Book",
+ "client",
+ "EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (
@@ -1615,7 +1620,7 @@ e_contact_list_editor_get_type (void)
EABEditor *
e_contact_list_editor_new (EShell *shell,
- EBook *book,
+ EBookClient *book_client,
EContact *list_contact,
gboolean is_new_list,
gboolean editable)
@@ -1629,7 +1634,7 @@ e_contact_list_editor_new (EShell *shell,
"shell", shell, NULL);
g_object_set (editor,
- "book", book,
+ "client", book_client,
"contact", list_contact,
"is_new_list", is_new_list,
"editable", editable,
@@ -1638,32 +1643,30 @@ e_contact_list_editor_new (EShell *shell,
return editor;
}
-EBook *
-e_contact_list_editor_get_book (EContactListEditor *editor)
+EBookClient *
+e_contact_list_editor_get_client (EContactListEditor *editor)
{
g_return_val_if_fail (E_IS_CONTACT_LIST_EDITOR (editor), NULL);
- return editor->priv->book;
+ return editor->priv->book_client;
}
void
-e_contact_list_editor_set_book (EContactListEditor *editor,
- EBook *book)
+e_contact_list_editor_set_client (EContactListEditor *editor,
+ EBookClient *book_client)
{
g_return_if_fail (E_IS_CONTACT_LIST_EDITOR (editor));
- g_return_if_fail (E_IS_BOOK (book));
+ g_return_if_fail (E_IS_BOOK_CLIENT (book_client));
- if (editor->priv->book != NULL)
- g_object_unref (editor->priv->book);
- editor->priv->book = g_object_ref (book);
+ if (editor->priv->book_client != NULL)
+ g_object_unref (editor->priv->book_client);
+ editor->priv->book_client = g_object_ref (book_client);
- editor->priv->allows_contact_lists =
- e_book_check_static_capability (
- editor->priv->book, "contact-lists");
+ editor->priv->allows_contact_lists = e_client_check_capability (E_CLIENT (editor->priv->book_client), "contact-lists");
contact_list_editor_update (editor);
- g_object_notify (G_OBJECT (editor), "book");
+ g_object_notify (G_OBJECT (editor), "client");
}
EContact *
@@ -1823,10 +1826,10 @@ e_contact_list_editor_set_contact (EContactListEditor *editor,
g_list_free (email_list);
}
- if (priv->book != NULL) {
+ if (priv->book_client != NULL) {
e_source_combo_box_set_active (
E_SOURCE_COMBO_BOX (WIDGET (SOURCE_MENU)),
- e_book_get_source (priv->book));
+ e_client_get_source (E_CLIENT (priv->book_client)));
gtk_widget_set_sensitive (
WIDGET (SOURCE_MENU), priv->is_new_list);
}
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.h b/addressbook/gui/contact-list-editor/e-contact-list-editor.h
index 11242b3dee..38713ba7ab 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.h
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.h
@@ -27,7 +27,7 @@
#include "addressbook/gui/contact-editor/eab-editor.h"
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-contact.h>
#include <libebook/e-destination.h>
@@ -68,13 +68,13 @@ struct _EContactListEditorClass
GType e_contact_list_editor_get_type (void);
EABEditor * e_contact_list_editor_new (EShell *shell,
- EBook *book,
+ EBookClient *book_client,
EContact *list_contact,
gboolean is_new_list,
gboolean editable);
-EBook * e_contact_list_editor_get_book (EContactListEditor *editor);
-void e_contact_list_editor_set_book (EContactListEditor *editor,
- EBook *book);
+EBookClient * e_contact_list_editor_get_client(EContactListEditor *editor);
+void e_contact_list_editor_set_client(EContactListEditor *editor,
+ EBookClient *book_client);
EContact * e_contact_list_editor_get_contact
(EContactListEditor *editor);
void e_contact_list_editor_set_contact
diff --git a/addressbook/gui/merging/eab-contact-compare.c b/addressbook/gui/merging/eab-contact-compare.c
index 4e226e798c..1ba9b3811f 100644
--- a/addressbook/gui/merging/eab-contact-compare.c
+++ b/addressbook/gui/merging/eab-contact-compare.c
@@ -27,7 +27,8 @@
#include <ctype.h>
#include <string.h>
-#include <libedataserverui/e-book-auth-util.h>
+#include <libebook/e-book-query.h>
+#include <libedataserverui/e-client-utils.h>
#include "addressbook/util/eab-book-util.h"
#include "eab-contact-compare.h"
@@ -572,24 +573,31 @@ match_search_info_free (MatchSearchInfo *info)
}
static void
-query_cb (EBook *book, const GError *error, GList *contacts, gpointer closure)
+query_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- /* XXX we need to free contacts */
- MatchSearchInfo *info = (MatchSearchInfo *) closure;
+ MatchSearchInfo *info = (MatchSearchInfo *) user_data;
EABContactMatchType best_match = EAB_CONTACT_MATCH_NONE;
EContact *best_contact = NULL;
- GList *remaining_contacts = NULL;
- const GList *i;
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ GSList *remaining_contacts = NULL;
+ GSList *contacts = NULL;
+ GError *error = NULL;
+ const GSList *ii;
+
+ if (result && !e_book_client_get_contacts_finish (book_client, result, &contacts, &error)) {
+ g_debug ("%s: Failed to get contacts: %s\n", G_STRFUNC, error ? error->message : "Unknown error");
+ if (error)
+ g_error_free (error);
- if (error) {
info->cb (info->contact, NULL, EAB_CONTACT_MATCH_NONE, info->closure);
match_search_info_free (info);
+ g_object_unref (book_client);
return;
}
/* remove the contacts we're to avoid from the list, if they're present */
- for (i = contacts; i != NULL; i = g_list_next (i)) {
- EContact *this_contact = E_CONTACT (i->data);
+ for (ii = contacts; ii != NULL; ii = g_slist_next (ii)) {
+ EContact *this_contact = E_CONTACT (ii->data);
const gchar *this_uid;
GList *iterator;
gboolean avoid = FALSE;
@@ -611,30 +619,36 @@ query_cb (EBook *book, const GError *error, GList *contacts, gpointer closure)
}
}
if (!avoid)
- remaining_contacts = g_list_prepend (remaining_contacts, this_contact);
+ remaining_contacts = g_slist_prepend (remaining_contacts, g_object_ref (this_contact));
}
- remaining_contacts = g_list_reverse (remaining_contacts);
+ remaining_contacts = g_slist_reverse (remaining_contacts);
- for (i = remaining_contacts; i != NULL; i = g_list_next (i)) {
- EContact *this_contact = E_CONTACT (i->data);
+ for (ii = remaining_contacts; ii != NULL; ii = g_slist_next (ii)) {
+ EContact *this_contact = E_CONTACT (ii->data);
EABContactMatchType this_match = eab_contact_compare (info->contact, this_contact);
if ((gint) this_match > (gint) best_match) {
best_match = this_match;
- best_contact = this_contact;
+ best_contact = this_contact;
}
}
- g_list_free (remaining_contacts);
+ if (best_contact)
+ best_contact = g_object_ref (best_contact);
+
+ e_client_util_free_object_slist (contacts);
+ e_client_util_free_object_slist (remaining_contacts);
info->cb (info->contact, best_contact, best_match, info->closure);
match_search_info_free (info);
+ g_object_unref (book_client);
+ g_object_unref (best_contact);
}
#define MAX_QUERY_PARTS 10
static void
-use_common_book (EBook *book,
- MatchSearchInfo *info)
+use_common_book_client (EBookClient *book_client,
+ MatchSearchInfo *info)
{
EContact *contact = info->contact;
EContactName *contact_name;
@@ -645,7 +659,7 @@ use_common_book (EBook *book,
EBookQuery *query = NULL;
gint i;
- if (book == NULL) {
+ if (book_client == NULL) {
info->cb (info->contact, NULL, EAB_CONTACT_MATCH_NONE, info->closure);
match_search_info_free (info);
return;
@@ -713,10 +727,14 @@ use_common_book (EBook *book,
query = NULL;
}
- if (query)
- e_book_get_contacts_async (book, query, query_cb, info);
- else
- query_cb (book, NULL, NULL, info);
+ if (query) {
+ gchar *query_str = e_book_query_to_string (query);
+
+ e_book_client_get_contacts (book_client, query_str, NULL, query_cb, info);
+
+ g_free (query_str);
+ } else
+ query_cb (G_OBJECT (book_client), NULL, info);
g_free (qj);
if (query)
@@ -724,14 +742,18 @@ use_common_book (EBook *book,
}
static void
-book_loaded_cb (ESource *source,
+book_loaded_cb (GObject *source_object,
GAsyncResult *result,
- MatchSearchInfo *info)
+ gpointer user_data)
{
- EBook *book;
+ ESource *source = E_SOURCE (source_object);
+ MatchSearchInfo *info = user_data;
+ EClient *client = NULL;
+
+ if (!e_client_utils_open_new_finish (source, result, &client, NULL))
+ client = NULL;
- book = e_load_book_source_finish (source, result, NULL);
- use_common_book (book, info);
+ use_common_book_client (client ? E_BOOK_CLIENT (client): NULL, info);
}
void
@@ -754,7 +776,7 @@ eab_contact_locate_match (EContact *contact,
* Look for the best match and return it using the EABContactMatchQueryCallback.
**/
void
-eab_contact_locate_match_full (EBook *book,
+eab_contact_locate_match_full (EBookClient *book_client,
EContact *contact,
GList *avoid,
EABContactMatchQueryCallback cb,
@@ -773,18 +795,18 @@ eab_contact_locate_match_full (EBook *book,
info->avoid = g_list_copy (avoid);
g_list_foreach (info->avoid, (GFunc) g_object_ref, NULL);
- if (book) {
- use_common_book (book, info);
+ if (book_client) {
+ use_common_book_client (g_object_ref (book_client), info);
return;
}
- if (!e_book_get_addressbooks (&info->source_list, NULL))
+ if (!e_book_client_get_sources (&info->source_list, NULL))
return;
source = e_source_list_peek_default_source (info->source_list);
- e_load_book_source_async (
- source, NULL, NULL, (GAsyncReadyCallback)
+ e_client_utils_open_new (source, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, NULL,
book_loaded_cb, info);
}
diff --git a/addressbook/gui/merging/eab-contact-compare.h b/addressbook/gui/merging/eab-contact-compare.h
index 4fc8ed1569..df67c5d752 100644
--- a/addressbook/gui/merging/eab-contact-compare.h
+++ b/addressbook/gui/merging/eab-contact-compare.h
@@ -26,7 +26,7 @@
#ifndef __EAB_CONTACT_COMPARE_H__
#define __EAB_CONTACT_COMPARE_H__
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-contact.h>
typedef enum {
@@ -64,7 +64,7 @@ EABContactMatchType eab_contact_compare_telephone (EContact *contact1, EContact
EABContactMatchType eab_contact_compare (EContact *contact1, EContact *contact2);
void eab_contact_locate_match (EContact *contact, EABContactMatchQueryCallback cb, gpointer closure);
-void eab_contact_locate_match_full (EBook *book, EContact *contact, GList *avoid, EABContactMatchQueryCallback cb, gpointer closure);
+void eab_contact_locate_match_full (EBookClient *book_client, EContact *contact, GList *avoid, EABContactMatchQueryCallback cb, gpointer closure);
#endif /* __E_CONTACT_COMPARE_H__ */
diff --git a/addressbook/gui/merging/eab-contact-merging.c b/addressbook/gui/merging/eab-contact-merging.c
index 49e9968074..99bb2d39fb 100644
--- a/addressbook/gui/merging/eab-contact-merging.c
+++ b/addressbook/gui/merging/eab-contact-merging.c
@@ -45,15 +45,15 @@ typedef enum {
typedef struct {
EContactMergingOpType op;
- EBook *book;
+ EBookClient *book_client;
/*contact is the new contact which the user has tried to add to the addressbook*/
EContact *contact;
/*match is the duplicate contact already existing in the addressbook*/
EContact *match;
GList *avoid;
- EBookIdAsyncCallback id_cb;
- EBookAsyncCallback cb;
- EBookContactAsyncCallback c_cb;
+ EABMergingAsyncCallback cb;
+ EABMergingIdAsyncCallback id_cb;
+ EABMergingContactAsyncCallback c_cb;
gpointer closure;
} EContactMergingLookup;
@@ -73,7 +73,7 @@ add_lookup (EContactMergingLookup *lookup)
{
if (running_merge_requests < SIMULTANEOUS_MERGING_REQUESTS) {
running_merge_requests++;
- eab_contact_locate_match_full (lookup->book, lookup->contact, lookup->avoid, match_query_callback, lookup);
+ eab_contact_locate_match_full (lookup->book_client, lookup->contact, lookup->avoid, match_query_callback, lookup);
}
else {
merging_queue = g_list_append (merging_queue, lookup);
@@ -96,14 +96,14 @@ finished_lookup (void)
merging_queue = g_list_remove_link (merging_queue, merging_queue);
running_merge_requests++;
- eab_contact_locate_match_full (lookup->book, lookup->contact, lookup->avoid, match_query_callback, lookup);
+ eab_contact_locate_match_full (lookup->book_client, lookup->contact, lookup->avoid, match_query_callback, lookup);
}
}
static void
free_lookup (EContactMergingLookup *lookup)
{
- g_object_unref (lookup->book);
+ g_object_unref (lookup->book_client);
g_object_unref (lookup->contact);
g_list_free (lookup->avoid);
if (lookup->match)
@@ -112,12 +112,12 @@ free_lookup (EContactMergingLookup *lookup)
}
static void
-final_id_cb (EBook *book, const GError *error, const gchar *id, gpointer closure)
+final_id_cb (EBookClient *book_client, const GError *error, const gchar *id, gpointer closure)
{
EContactMergingLookup *lookup = closure;
if (lookup->id_cb)
- lookup->id_cb (lookup->book, error, id, lookup->closure);
+ lookup->id_cb (lookup->book_client, error, id, lookup->closure);
free_lookup (lookup);
@@ -125,12 +125,12 @@ final_id_cb (EBook *book, const GError *error, const gchar *id, gpointer closure
}
static void
-final_cb_as_id (EBook *book, const GError *error, gpointer closure)
+final_cb_as_id (EBookClient *book_client, const GError *error, gpointer closure)
{
EContactMergingLookup *lookup = closure;
if (lookup->id_cb)
- lookup->id_cb (lookup->book, error, lookup->contact ? e_contact_get_const (lookup->contact, E_CONTACT_UID) : NULL, lookup->closure);
+ lookup->id_cb (lookup->book_client, error, lookup->contact ? e_contact_get_const (lookup->contact, E_CONTACT_UID) : NULL, lookup->closure);
free_lookup (lookup);
@@ -138,12 +138,12 @@ final_cb_as_id (EBook *book, const GError *error, gpointer closure)
}
static void
-final_cb (EBook *book, const GError *error, gpointer closure)
+final_cb (EBookClient *book_client, const GError *error, gpointer closure)
{
EContactMergingLookup *lookup = closure;
if (lookup->cb)
- lookup->cb (lookup->book, error, lookup->closure);
+ lookup->cb (lookup->book_client, error, lookup->closure);
free_lookup (lookup);
@@ -151,26 +151,67 @@ final_cb (EBook *book, const GError *error, gpointer closure)
}
static void
-doit (EContactMergingLookup *lookup, gboolean force_commit)
+modify_contact_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EContactMergingLookup *lookup = user_data;
+ GError *error = NULL;
+
+ g_return_if_fail (book_client != NULL);
+ g_return_if_fail (lookup != NULL);
+
+ e_book_client_modify_contact_finish (book_client, result, &error);
+
+ if (lookup->op == E_CONTACT_MERGING_ADD)
+ final_cb_as_id (book_client, error, lookup);
+ else
+ final_cb (book_client, error, lookup);
+
+ if (error)
+ g_error_free (error);
+}
+
+static void
+add_contact_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EContactMergingLookup *lookup = user_data;
+ gchar *uid = NULL;
+ GError *error = NULL;
+
+ g_return_if_fail (book_client != NULL);
+ g_return_if_fail (lookup != NULL);
+
+ if (!e_book_client_add_contact_finish (book_client, result, &uid, &error))
+ uid = NULL;
+
+ final_id_cb (book_client, error, uid, lookup);
+
+ if (error)
+ g_error_free (error);
+}
+
+static void
+doit (EContactMergingLookup *lookup, gboolean force_modify)
{
if (lookup->op == E_CONTACT_MERGING_ADD) {
- if (force_commit)
- e_book_commit_contact_async (lookup->book, lookup->contact, final_cb_as_id, lookup);
+ if (force_modify)
+ e_book_client_modify_contact (lookup->book_client, lookup->contact, NULL, modify_contact_ready_cb, lookup);
else
- e_book_add_contact_async (lookup->book, lookup->contact, final_id_cb, lookup);
+ e_book_client_add_contact (lookup->book_client, lookup->contact, NULL, add_contact_ready_cb, lookup);
} else if (lookup->op == E_CONTACT_MERGING_COMMIT)
- e_book_commit_contact_async (lookup->book, lookup->contact, final_cb, lookup);
+ e_book_client_modify_contact (lookup->book_client, lookup->contact, NULL, modify_contact_ready_cb, lookup);
}
static void
cancelit (EContactMergingLookup *lookup)
{
- GError *error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED, _("Cancelled"));
+ GError *error = e_client_error_create (E_CLIENT_ERROR_CANCELLED, NULL);
if (lookup->op == E_CONTACT_MERGING_ADD) {
- final_id_cb (lookup->book, error, NULL, lookup);
+ final_id_cb (lookup->book_client, error, NULL, lookup);
} else if (lookup->op == E_CONTACT_MERGING_COMMIT) {
- final_cb (lookup->book, error, lookup);
+ final_cb (lookup->book_client, error, lookup);
}
g_error_free (error);
@@ -209,6 +250,26 @@ dropdown_changed (GtkWidget *dropdown, dropdown_data *data)
return;
}
+static void
+remove_contact_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EContactMergingLookup *lookup = user_data;
+ GError *error = NULL;
+
+ g_return_if_fail (book_client != NULL);
+ g_return_if_fail (lookup != NULL);
+
+ e_book_client_remove_contact_finish (book_client, result, &error);
+
+ if (error) {
+ g_debug ("%s: Failed to remove contact: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ e_book_client_add_contact (book_client, lookup->contact, NULL, add_contact_ready_cb, lookup);
+}
+
static gint
mergeit (EContactMergingLookup *lookup)
{
@@ -373,12 +434,10 @@ mergeit (EContactMergingLookup *lookup)
gtk_widget_show_all ((GtkWidget *) table);
result = gtk_dialog_run (dialog);
- switch (result)
- {
+ switch (result) {
case GTK_RESPONSE_OK:
lookup->contact = lookup->match;
- e_book_remove_contact_async (lookup->book, lookup->match, NULL, lookup);
- e_book_add_contact_async (lookup->book, lookup->contact, final_id_cb, lookup);
+ e_book_client_remove_contact (lookup->book_client, lookup->match, NULL, remove_contact_ready_cb, lookup);
value = 1;
break;
case GTK_RESPONSE_CANCEL:
@@ -472,7 +531,7 @@ match_query_callback (EContact *contact, EContact *match, EABContactMatchType ty
if (lookup->op == E_CONTACT_MERGING_FIND) {
if (lookup->c_cb)
- lookup->c_cb (lookup->book, NULL, (gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE ? NULL : match, lookup->closure);
+ lookup->c_cb (lookup->book_client, NULL, (gint) type <= (gint) EAB_CONTACT_MATCH_VAGUE ? NULL : match, lookup->closure);
free_lookup (lookup);
finished_lookup ();
@@ -547,17 +606,17 @@ match_query_callback (EContact *contact, EContact *match, EABContactMatchType ty
}
gboolean
-eab_merging_book_add_contact (EBook *book,
- EContact *contact,
- EBookIdAsyncCallback cb,
- gpointer closure)
+eab_merging_book_add_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingIdAsyncCallback cb,
+ gpointer closure)
{
EContactMergingLookup *lookup;
lookup = g_new (EContactMergingLookup, 1);
lookup->op = E_CONTACT_MERGING_ADD;
- lookup->book = g_object_ref (book);
+ lookup->book_client = g_object_ref (book_client);
lookup->contact = g_object_ref (contact);
lookup->id_cb = cb;
lookup->closure = closure;
@@ -570,17 +629,17 @@ eab_merging_book_add_contact (EBook *book,
}
gboolean
-eab_merging_book_commit_contact (EBook *book,
- EContact *contact,
- EBookAsyncCallback cb,
- gpointer closure)
+eab_merging_book_modify_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingAsyncCallback cb,
+ gpointer closure)
{
EContactMergingLookup *lookup;
lookup = g_new (EContactMergingLookup, 1);
lookup->op = E_CONTACT_MERGING_COMMIT;
- lookup->book = g_object_ref (book);
+ lookup->book_client = g_object_ref (book_client);
lookup->contact = g_object_ref (contact);
lookup->cb = cb;
lookup->closure = closure;
@@ -593,17 +652,17 @@ eab_merging_book_commit_contact (EBook *book,
}
gboolean
-eab_merging_book_find_contact (EBook *book,
- EContact *contact,
- EBookContactAsyncCallback cb,
- gpointer closure)
+eab_merging_book_find_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingContactAsyncCallback cb,
+ gpointer closure)
{
EContactMergingLookup *lookup;
lookup = g_new (EContactMergingLookup, 1);
lookup->op = E_CONTACT_MERGING_FIND;
- lookup->book = g_object_ref (book);
+ lookup->book_client = g_object_ref (book_client);
lookup->contact = g_object_ref (contact);
lookup->c_cb = cb;
lookup->closure = closure;
diff --git a/addressbook/gui/merging/eab-contact-merging.h b/addressbook/gui/merging/eab-contact-merging.h
index 40d12a5a29..c8e2ddb3ef 100644
--- a/addressbook/gui/merging/eab-contact-merging.h
+++ b/addressbook/gui/merging/eab-contact-merging.h
@@ -26,22 +26,28 @@
#ifndef __E_CONTACT_MERGING_H__
#define __E_CONTACT_MERGING_H__
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
G_BEGIN_DECLS
-gboolean eab_merging_book_add_contact (EBook *book,
- EContact *contact,
- EBookIdAsyncCallback cb,
- gpointer closure);
-gboolean eab_merging_book_commit_contact (EBook *book,
- EContact *contact,
- EBookAsyncCallback cb,
- gpointer closure);
-gboolean eab_merging_book_find_contact (EBook *book,
- EContact *contact,
- EBookContactAsyncCallback cb,
- gpointer closure);
+typedef void (*EABMergingAsyncCallback) (EBookClient *book_client, const GError *error, gpointer closure);
+typedef void (*EABMergingIdAsyncCallback) (EBookClient *book_client, const GError *error, const gchar *id, gpointer closure);
+typedef void (*EABMergingContactAsyncCallback) (EBookClient *book_client, const GError *error, EContact *contact, gpointer closure);
+
+gboolean eab_merging_book_add_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingIdAsyncCallback cb,
+ gpointer closure);
+
+gboolean eab_merging_book_modify_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingAsyncCallback cb,
+ gpointer closure);
+
+gboolean eab_merging_book_find_contact (EBookClient *book_client,
+ EContact *contact,
+ EABMergingContactAsyncCallback cb,
+ gpointer closure);
G_END_DECLS
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index 30720513d0..497b8fe353 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -32,10 +32,10 @@
#include "eab-gui-util.h"
struct _EAddressbookModelPrivate {
- EBook *book;
- EBookQuery *query;
- EBookView *book_view;
- guint book_view_idle_id;
+ EBookClient *book_client;
+ gchar *query_str;
+ EBookClientView *client_view;
+ guint client_view_idle_id;
/* Query Results */
GPtrArray *contacts;
@@ -58,7 +58,7 @@ struct _EAddressbookModelPrivate {
enum {
PROP_0,
- PROP_BOOK,
+ PROP_CLIENT,
PROP_EDITABLE,
PROP_QUERY
};
@@ -94,25 +94,25 @@ free_data (EAddressbookModel *model)
static void
remove_book_view (EAddressbookModel *model)
{
- if (model->priv->book_view && model->priv->create_contact_id)
+ if (model->priv->client_view && model->priv->create_contact_id)
g_signal_handler_disconnect (
- model->priv->book_view,
+ model->priv->client_view,
model->priv->create_contact_id);
- if (model->priv->book_view && model->priv->remove_contact_id)
+ if (model->priv->client_view && model->priv->remove_contact_id)
g_signal_handler_disconnect (
- model->priv->book_view,
+ model->priv->client_view,
model->priv->remove_contact_id);
- if (model->priv->book_view && model->priv->modify_contact_id)
+ if (model->priv->client_view && model->priv->modify_contact_id)
g_signal_handler_disconnect (
- model->priv->book_view,
+ model->priv->client_view,
model->priv->modify_contact_id);
- if (model->priv->book_view && model->priv->status_message_id)
+ if (model->priv->client_view && model->priv->status_message_id)
g_signal_handler_disconnect (
- model->priv->book_view,
+ model->priv->client_view,
model->priv->status_message_id);
- if (model->priv->book_view && model->priv->view_complete_id)
+ if (model->priv->client_view && model->priv->view_complete_id)
g_signal_handler_disconnect (
- model->priv->book_view,
+ model->priv->client_view,
model->priv->view_complete_id);
if (model->priv->remove_status_id)
g_source_remove (model->priv->remove_status_id);
@@ -126,12 +126,19 @@ remove_book_view (EAddressbookModel *model)
model->priv->search_in_progress = FALSE;
- if (model->priv->book_view) {
- e_book_view_stop (model->priv->book_view);
- g_object_unref (model->priv->book_view);
- model->priv->book_view = NULL;
+ if (model->priv->client_view) {
+ GError *error = NULL;
- g_signal_emit (model, signals[STATUS_MESSAGE], 0, NULL);
+ e_book_client_view_stop (model->priv->client_view, &error);
+ if (error) {
+ g_debug ("%s: Failed to stop client view: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (model->priv->client_view);
+ model->priv->client_view = NULL;
+
+ g_signal_emit (model, signals[STATUS_MESSAGE], 0, NULL, -1);
}
}
@@ -159,9 +166,7 @@ update_folder_bar_message (EAddressbookModel *model)
}
static void
-create_contact (EBookView *book_view,
- const GList *contact_list,
- EAddressbookModel *model)
+view_create_contact_cb (EBookClientView *client_view, const GSList *contact_list, EAddressbookModel *model)
{
GPtrArray *array;
guint count;
@@ -193,12 +198,10 @@ sort_descending (gconstpointer ca,
}
static void
-remove_contact (EBookView *book_view,
- GList *ids,
- EAddressbookModel *model)
+view_remove_contact_cb (EBookClientView *client_view, const GSList *ids, EAddressbookModel *model)
{
/* XXX we should keep a hash around instead of this O(n*m) loop */
- GList *iter;
+ const GSList *iter;
GArray *indices;
GPtrArray *array;
gint ii;
@@ -249,9 +252,7 @@ remove_contact (EBookView *book_view,
}
static void
-modify_contact (EBookView *book_view,
- const GList *contact_list,
- EAddressbookModel *model)
+view_modify_contact_cb (EBookClientView *client_view, const GSList *contact_list, EAddressbookModel *model)
{
GPtrArray *array;
@@ -290,122 +291,109 @@ modify_contact (EBookView *book_view,
}
static void
-status_message (EBookView *book_view,
- gchar * status,
- EAddressbookModel *model)
+view_progress_cb (EBookClientView *client_view, guint percent, const gchar *message, EAddressbookModel *model)
{
if (model->priv->remove_status_id)
g_source_remove (model->priv->remove_status_id);
model->priv->remove_status_id = 0;
- g_signal_emit (model, signals[STATUS_MESSAGE], 0, status);
+ g_signal_emit (model, signals[STATUS_MESSAGE], 0, message, percent);
}
static void
-view_complete (EBookView *book_view,
- EBookViewStatus status,
- const gchar *error_msg,
- EAddressbookModel *model)
+view_complete_cb (EBookClientView *client_view, const GError *error, EAddressbookModel *model)
{
model->priv->search_in_progress = FALSE;
- status_message (book_view, NULL, model);
- g_signal_emit (model, signals[SEARCH_RESULT], 0, status, error_msg);
+ view_progress_cb (client_view, -1, NULL, model);
+ g_signal_emit (model, signals[SEARCH_RESULT], 0, error);
g_signal_emit (model, signals[STOP_STATE_CHANGED], 0);
}
static void
-writable_status (EBook *book,
- gboolean writable,
- EAddressbookModel *model)
+readonly_cb (EBookClient *book_client, EAddressbookModel *model)
{
if (!model->priv->editable_set) {
- model->priv->editable = writable;
+ model->priv->editable = !e_client_is_readonly (E_CLIENT (book_client));
- g_signal_emit (model, signals[WRITABLE_STATUS], 0, writable);
+ g_signal_emit (model, signals[WRITABLE_STATUS], 0, model->priv->editable);
}
}
static void
-backend_died (EBook *book,
- EAddressbookModel *model)
+backend_died_cb (EBookClient *book_client, EAddressbookModel *model)
{
g_signal_emit (model, signals[BACKEND_DIED], 0);
}
static void
-book_view_loaded (EBook *book,
- const GError *error,
- EBookView *book_view,
- gpointer closure)
+client_view_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EAddressbookModel *model = closure;
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ EBookClientView *client_view = NULL;
+ EAddressbookModel *model = user_data;
+ GError *error = NULL;
+
+ if (!e_book_client_get_view_finish (book_client, result, &client_view, &error))
+ client_view = NULL;
if (error) {
eab_error_dialog (NULL, _("Error getting book view"), error);
+ g_error_free (error);
return;
}
remove_book_view (model);
free_data (model);
- model->priv->book_view = book_view;
- if (model->priv->book_view)
- g_object_ref (model->priv->book_view);
-
- model->priv->create_contact_id = g_signal_connect (
- model->priv->book_view, "contacts-added",
- G_CALLBACK (create_contact), model);
- model->priv->remove_contact_id = g_signal_connect (
- model->priv->book_view, "contacts-removed",
- G_CALLBACK (remove_contact), model);
- model->priv->modify_contact_id = g_signal_connect (
- model->priv->book_view, "contacts-changed",
- G_CALLBACK (modify_contact), model);
- model->priv->status_message_id = g_signal_connect (
- model->priv->book_view, "status-message",
- G_CALLBACK (status_message), model);
- model->priv->view_complete_id = g_signal_connect (
- model->priv->book_view, "view-complete",
- G_CALLBACK (view_complete), model);
-
- model->priv->search_in_progress = TRUE;
+ model->priv->client_view = client_view;
+ if (model->priv->client_view) {
+ model->priv->create_contact_id = g_signal_connect (
+ model->priv->client_view, "objects-added",
+ G_CALLBACK (view_create_contact_cb), model);
+ model->priv->remove_contact_id = g_signal_connect (
+ model->priv->client_view, "objects-removed",
+ G_CALLBACK (view_remove_contact_cb), model);
+ model->priv->modify_contact_id = g_signal_connect (
+ model->priv->client_view, "objects-modified",
+ G_CALLBACK (view_modify_contact_cb), model);
+ model->priv->status_message_id = g_signal_connect (
+ model->priv->client_view, "progress",
+ G_CALLBACK (view_progress_cb), model);
+ model->priv->view_complete_id = g_signal_connect (
+ model->priv->client_view, "complete",
+ G_CALLBACK (view_complete_cb), model);
+
+ model->priv->search_in_progress = TRUE;
+ }
+
g_signal_emit (model, signals[MODEL_CHANGED], 0);
g_signal_emit (model, signals[SEARCH_STARTED], 0);
g_signal_emit (model, signals[STOP_STATE_CHANGED], 0);
- e_book_view_start (model->priv->book_view);
+ if (model->priv->client_view) {
+ e_book_client_view_start (model->priv->client_view, &error);
+ if (error) {
+ g_debug ("%s: Failed to start client view: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+ }
}
static gboolean
addressbook_model_idle_cb (EAddressbookModel *model)
{
- model->priv->book_view_idle_id = 0;
-
- if (model->priv->book && model->priv->query) {
- ESource *source;
- const gchar *limit_str;
- gint limit = -1;
-
- source = e_book_get_source (model->priv->book);
-
- limit_str = e_source_get_property (source, "limit");
- if (limit_str && *limit_str)
- limit = atoi (limit_str);
-
+ model->priv->client_view_idle_id = 0;
+
+ if (model->priv->book_client && model->priv->query_str) {
remove_book_view (model);
if (model->priv->first_get_view) {
- gboolean do_initial_query;
-
model->priv->first_get_view = FALSE;
- do_initial_query = e_book_check_static_capability (
- model->priv->book, "do-initial-query");
-
- if (do_initial_query) {
- e_book_get_book_view_async (
- model->priv->book, model->priv->query,
- NULL, limit, book_view_loaded, model);
+ if (e_client_check_capability (E_CLIENT (model->priv->book_client), "do-initial-query")) {
+ e_book_client_get_view (
+ model->priv->book_client, model->priv->query_str,
+ NULL, client_view_ready_cb, model);
} else {
free_data (model);
@@ -415,9 +403,9 @@ addressbook_model_idle_cb (EAddressbookModel *model)
model, signals[STOP_STATE_CHANGED], 0);
}
} else
- e_book_get_book_view_async (
- model->priv->book, model->priv->query,
- NULL, limit, book_view_loaded, model);
+ e_book_client_get_view (
+ model->priv->book_client, model->priv->query_str,
+ NULL, client_view_ready_cb, model);
}
@@ -434,7 +422,7 @@ remove_status_cb (gpointer data)
g_return_val_if_fail (model != NULL, FALSE);
g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), FALSE);
- g_signal_emit (model, signals[STATUS_MESSAGE], 0, NULL);
+ g_signal_emit (model, signals[STATUS_MESSAGE], 0, NULL, -1);
model->priv->remove_status_id = 0;
return FALSE;
@@ -447,8 +435,8 @@ addressbook_model_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BOOK:
- e_addressbook_model_set_book (
+ case PROP_CLIENT:
+ e_addressbook_model_set_client (
E_ADDRESSBOOK_MODEL (object),
g_value_get_object (value));
return;
@@ -477,9 +465,9 @@ addressbook_model_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BOOK:
+ case PROP_CLIENT:
g_value_set_object (
- value, e_addressbook_model_get_book (
+ value, e_addressbook_model_get_client (
E_ADDRESSBOOK_MODEL (object)));
return;
@@ -490,7 +478,7 @@ addressbook_model_get_property (GObject *object,
return;
case PROP_QUERY:
- g_value_take_string (
+ g_value_set_string (
value, e_addressbook_model_get_query (
E_ADDRESSBOOK_MODEL (object)));
return;
@@ -507,26 +495,26 @@ addressbook_model_dispose (GObject *object)
remove_book_view (model);
free_data (model);
- if (model->priv->book) {
+ if (model->priv->book_client) {
if (model->priv->writable_status_id)
g_signal_handler_disconnect (
- model->priv->book,
+ model->priv->book_client,
model->priv->writable_status_id);
model->priv->writable_status_id = 0;
if (model->priv->backend_died_id)
g_signal_handler_disconnect (
- model->priv->book,
+ model->priv->book_client,
model->priv->backend_died_id);
model->priv->backend_died_id = 0;
- g_object_unref (model->priv->book);
- model->priv->book = NULL;
+ g_object_unref (model->priv->book_client);
+ model->priv->book_client = NULL;
}
- if (model->priv->query) {
- e_book_query_unref (model->priv->query);
- model->priv->query = NULL;
+ if (model->priv->query_str) {
+ g_free (model->priv->query_str);
+ model->priv->query_str = NULL;
}
/* Chain up to parent's dispose() method. */
@@ -562,12 +550,12 @@ addressbook_model_class_init (EAddressbookModelClass *class)
g_object_class_install_property (
object_class,
- PROP_BOOK,
+ PROP_CLIENT,
g_param_spec_object (
- "book",
- "Book",
+ "client",
+ "EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (
@@ -607,9 +595,9 @@ addressbook_model_class_init (EAddressbookModelClass *class)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EAddressbookModelClass, status_message),
NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
+ e_marshal_VOID__STRING_INT,
G_TYPE_NONE,
- 1, G_TYPE_POINTER);
+ 2, G_TYPE_STRING, G_TYPE_INT);
signals[SEARCH_STARTED] =
g_signal_new ("search_started",
@@ -626,8 +614,8 @@ addressbook_model_class_init (EAddressbookModelClass *class)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EAddressbookModelClass, search_result),
NULL, NULL,
- e_marshal_VOID__UINT_STRING,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1, G_TYPE_ERROR);
signals[FOLDER_BAR_MESSAGE] =
g_signal_new ("folder_bar_message",
@@ -762,7 +750,7 @@ e_addressbook_model_stop (EAddressbookModel *model)
message = _("Search Interrupted");
g_signal_emit (model, signals[STOP_STATE_CHANGED], 0);
- g_signal_emit (model, signals[STATUS_MESSAGE], 0, message);
+ g_signal_emit (model, signals[STATUS_MESSAGE], 0, message, -1);
if (!model->priv->remove_status_id)
model->priv->remove_status_id =
@@ -828,64 +816,64 @@ e_addressbook_model_find (EAddressbookModel *model,
return -1;
}
-EBook *
-e_addressbook_model_get_book (EAddressbookModel *model)
+EBookClient *
+e_addressbook_model_get_client (EAddressbookModel *model)
{
g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), NULL);
- return model->priv->book;
+ return model->priv->book_client;
}
void
-e_addressbook_model_set_book (EAddressbookModel *model,
- EBook *book)
+e_addressbook_model_set_client (EAddressbookModel *model,
+ EBookClient *book_client)
{
g_return_if_fail (E_IS_ADDRESSBOOK_MODEL (model));
- g_return_if_fail (E_IS_BOOK (book));
+ g_return_if_fail (E_IS_BOOK_CLIENT (book_client));
- if (model->priv->book != NULL) {
- if (model->priv->book == book)
+ if (model->priv->book_client != NULL) {
+ if (model->priv->book_client == book_client)
return;
if (model->priv->writable_status_id != 0)
g_signal_handler_disconnect (
- model->priv->book,
+ model->priv->book_client,
model->priv->writable_status_id);
model->priv->writable_status_id = 0;
if (model->priv->backend_died_id != 0)
g_signal_handler_disconnect (
- model->priv->book,
+ model->priv->book_client,
model->priv->backend_died_id);
model->priv->backend_died_id = 0;
- g_object_unref (model->priv->book);
+ g_object_unref (model->priv->book_client);
}
- model->priv->book = g_object_ref (book);
+ model->priv->book_client = g_object_ref (book_client);
model->priv->first_get_view = TRUE;
model->priv->writable_status_id = g_signal_connect (
- book, "writable-status",
- G_CALLBACK (writable_status), model);
+ book_client, "notify::readonly",
+ G_CALLBACK (readonly_cb), model);
model->priv->backend_died_id = g_signal_connect (
- book, "backend-died",
- G_CALLBACK (backend_died), model);
+ book_client, "backend-died",
+ G_CALLBACK (backend_died_cb), model);
if (!model->priv->editable_set) {
- model->priv->editable = e_book_is_writable (book);
+ model->priv->editable = !e_client_is_readonly (E_CLIENT (book_client));
g_signal_emit (
model, signals[WRITABLE_STATUS], 0,
model->priv->editable);
}
- if (model->priv->book_view_idle_id == 0)
- model->priv->book_view_idle_id = g_idle_add (
+ if (model->priv->client_view_idle_id == 0)
+ model->priv->client_view_idle_id = g_idle_add (
(GSourceFunc) addressbook_model_idle_cb,
g_object_ref (model));
- g_object_notify (G_OBJECT (model), "book");
+ g_object_notify (G_OBJECT (model), "client");
}
gboolean
@@ -913,10 +901,7 @@ e_addressbook_model_get_query (EAddressbookModel *model)
{
g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), NULL);
- if (!model->priv->query)
- return NULL;
-
- return e_book_query_to_string (model->priv->query);
+ return model->priv->query_str;
}
void
@@ -932,31 +917,30 @@ e_addressbook_model_set_query (EAddressbookModel *model,
else
book_query = e_book_query_from_string (query);
+ /* also checks whether the query is a valid query string */
if (!book_query)
return;
- if (model->priv->query != NULL) {
- gchar *old_query, *new_query;
+ if (model->priv->query_str != NULL) {
+ gchar *new_query;
- old_query = e_book_query_to_string (model->priv->query);
new_query = e_book_query_to_string (book_query);
- if (old_query && new_query && g_str_equal (old_query, new_query)) {
- g_free (old_query);
+ if (new_query && g_str_equal (model->priv->query_str, new_query)) {
g_free (new_query);
e_book_query_unref (book_query);
return;
}
- g_free (old_query);
g_free (new_query);
- e_book_query_unref (model->priv->query);
}
- model->priv->query = book_query;
+ g_free (model->priv->query_str);
+ model->priv->query_str = e_book_query_to_string (book_query);
+ e_book_query_unref (book_query);
- if (model->priv->book_view_idle_id == 0)
- model->priv->book_view_idle_id = g_idle_add (
+ if (model->priv->client_view_idle_id == 0)
+ model->priv->client_view_idle_id = g_idle_add (
(GSourceFunc) addressbook_model_idle_cb,
g_object_ref (model));
diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h
index 44b22df4cd..13d23e92b0 100644
--- a/addressbook/gui/widgets/e-addressbook-model.h
+++ b/addressbook/gui/widgets/e-addressbook-model.h
@@ -21,9 +21,9 @@
#ifndef E_ADDRESSBOOK_MODEL_H
#define E_ADDRESSBOOK_MODEL_H
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
+#include <libebook/e-book-client-view.h>
#include <libebook/e-book-query.h>
-#include <libebook/e-book-view.h>
/* Standard GObject macros */
#define E_TYPE_ADDRESSBOOK_MODEL \
@@ -63,10 +63,10 @@ struct _EAddressbookModelClass {
gboolean writable);
void (*search_started) (EAddressbookModel *model);
void (*search_result) (EAddressbookModel *model,
- EBookViewStatus status,
- const gchar *error_msg);
+ const GError *error);
void (*status_message) (EAddressbookModel *model,
- const gchar *message);
+ const gchar *message,
+ gint percent);
void (*folder_bar_message) (EAddressbookModel *model,
const gchar *message);
void (*contact_added) (EAddressbookModel *model,
@@ -101,9 +101,9 @@ EContact * e_addressbook_model_contact_at (EAddressbookModel *model,
gint index);
gint e_addressbook_model_find (EAddressbookModel *model,
EContact *contact);
-EBook * e_addressbook_model_get_book (EAddressbookModel *model);
-void e_addressbook_model_set_book (EAddressbookModel *model,
- EBook *book);
+EBookClient * e_addressbook_model_get_client (EAddressbookModel *model);
+void e_addressbook_model_set_client (EAddressbookModel *model,
+ EBookClient *book_client);
gboolean e_addressbook_model_get_editable (EAddressbookModel *model);
void e_addressbook_model_set_editable (EAddressbookModel *model,
gboolean editable);
diff --git a/addressbook/gui/widgets/e-addressbook-reflow-adapter.c b/addressbook/gui/widgets/e-addressbook-reflow-adapter.c
index 0561b766b6..680a511d05 100644
--- a/addressbook/gui/widgets/e-addressbook-reflow-adapter.c
+++ b/addressbook/gui/widgets/e-addressbook-reflow-adapter.c
@@ -47,7 +47,7 @@ static EReflowModel *parent_class;
enum {
PROP_0,
- PROP_BOOK,
+ PROP_CLIENT,
PROP_QUERY,
PROP_EDITABLE,
PROP_MODEL
@@ -382,8 +382,7 @@ search_started (EAddressbookModel *model,
static void
search_result (EAddressbookModel *model,
- EBookViewStatus status,
- const gchar *error_msg,
+ const GError *error,
EAddressbookReflowAdapter *adapter)
{
EAddressbookReflowAdapterPrivate *priv = adapter->priv;
@@ -403,9 +402,9 @@ addressbook_set_property (GObject *object,
EAddressbookReflowAdapterPrivate *priv = adapter->priv;
switch (prop_id) {
- case PROP_BOOK:
+ case PROP_CLIENT:
g_object_set (priv->model,
- "book", g_value_get_object (value),
+ "client", g_value_get_object (value),
NULL);
break;
case PROP_QUERY:
@@ -434,9 +433,9 @@ addressbook_get_property (GObject *object,
EAddressbookReflowAdapterPrivate *priv = adapter->priv;
switch (prop_id) {
- case PROP_BOOK: {
+ case PROP_CLIENT: {
g_object_get_property (G_OBJECT (priv->model),
- "book", value);
+ "client", value);
break;
}
case PROP_QUERY: {
@@ -469,11 +468,11 @@ e_addressbook_reflow_adapter_class_init (GObjectClass *object_class)
object_class->get_property = addressbook_get_property;
object_class->dispose = addressbook_dispose;
- g_object_class_install_property (object_class, PROP_BOOK,
- g_param_spec_object ("book",
- "Book",
+ g_object_class_install_property (object_class, PROP_CLIENT,
+ g_param_spec_object ("client",
+ "EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_QUERY,
diff --git a/addressbook/gui/widgets/e-addressbook-selector.c b/addressbook/gui/widgets/e-addressbook-selector.c
index 76b0e98f74..954b1e19b9 100644
--- a/addressbook/gui/widgets/e-addressbook-selector.c
+++ b/addressbook/gui/widgets/e-addressbook-selector.c
@@ -25,6 +25,7 @@
#include "e-addressbook-selector.h"
#include <e-util/e-selection.h>
+#include <libedataserverui/e-client-utils.h>
#include <eab-book-util.h>
#include <eab-contact-merging.h>
@@ -36,11 +37,11 @@ struct _EAddressbookSelectorPrivate {
};
struct _MergeContext {
- EBook *source_book;
- EBook *target_book;
+ EBookClient *source_client;
+ EBookClient *target_client;
EContact *current_contact;
- GList *remaining_contacts;
+ GSList *remaining_contacts;
guint pending_removals;
gboolean pending_adds;
@@ -62,7 +63,7 @@ static gpointer parent_class;
static void
merge_context_next (MergeContext *merge_context)
{
- GList *list;
+ GSList *list;
merge_context->current_contact = NULL;
if (!merge_context->remaining_contacts)
@@ -70,20 +71,20 @@ merge_context_next (MergeContext *merge_context)
list = merge_context->remaining_contacts;
merge_context->current_contact = list->data;
- list = g_list_delete_link (list, list);
+ list = g_slist_delete_link (list, list);
merge_context->remaining_contacts = list;
}
static MergeContext *
-merge_context_new (EBook *source_book,
- EBook *target_book,
- GList *contact_list)
+merge_context_new (EBookClient *source_client,
+ EBookClient *target_client,
+ GSList *contact_list)
{
MergeContext *merge_context;
merge_context = g_slice_new0 (MergeContext);
- merge_context->source_book = source_book;
- merge_context->target_book = target_book;
+ merge_context->source_client = source_client;
+ merge_context->target_client = target_client;
merge_context->remaining_contacts = contact_list;
merge_context_next (merge_context);
@@ -93,20 +94,28 @@ merge_context_new (EBook *source_book,
static void
merge_context_free (MergeContext *merge_context)
{
- if (merge_context->source_book != NULL)
- g_object_unref (merge_context->source_book);
+ if (merge_context->source_client != NULL)
+ g_object_unref (merge_context->source_client);
- if (merge_context->target_book != NULL)
- g_object_unref (merge_context->target_book);
+ if (merge_context->target_client != NULL)
+ g_object_unref (merge_context->target_client);
g_slice_free (MergeContext, merge_context);
}
static void
-addressbook_selector_removed_cb (EBook *book,
- const GError *error,
- MergeContext *merge_context)
+addressbook_selector_removed_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ MergeContext *merge_context = user_data;
+ GError *error = NULL;
+
+ e_book_client_remove_contact_finish (book_client, result, &error);
+ if (error) {
+ g_debug ("%s: Failed to remove contact: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
merge_context->pending_removals--;
if (merge_context->pending_adds)
@@ -119,18 +128,19 @@ addressbook_selector_removed_cb (EBook *book,
}
static void
-addressbook_selector_merge_next_cb (EBook *book,
+addressbook_selector_merge_next_cb (EBookClient *book_client,
const GError *error,
const gchar *id,
- MergeContext *merge_context)
+ gpointer closure)
{
+ MergeContext *merge_context = closure;
+
if (merge_context->remove_from_source && !error) {
/* Remove previous contact from source. */
- e_book_remove_contact_async (
- merge_context->source_book,
- merge_context->current_contact,
- (EBookAsyncCallback) addressbook_selector_removed_cb,
- merge_context);
+ e_book_client_remove_contact (
+ merge_context->source_client,
+ merge_context->current_contact, NULL,
+ addressbook_selector_removed_cb, merge_context);
merge_context->pending_removals++;
}
@@ -139,10 +149,9 @@ addressbook_selector_merge_next_cb (EBook *book,
if (merge_context->remaining_contacts != NULL) {
merge_context_next (merge_context);
eab_merging_book_add_contact (
- merge_context->target_book,
+ merge_context->target_client,
merge_context->current_contact,
- (EBookIdAsyncCallback) addressbook_selector_merge_next_cb,
- merge_context);
+ addressbook_selector_merge_next_cb, merge_context);
} else if (merge_context->pending_removals == 0) {
merge_context_free (merge_context);
@@ -242,6 +251,39 @@ addressbook_selector_constructed (GObject *object)
G_OBJECT_CLASS (parent_class)->constructed (object);
}
+static void
+target_client_open_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ ESource *source = E_SOURCE (source_object);
+ MergeContext *merge_context = user_data;
+ EClient *client = NULL;
+ GError *error = NULL;
+
+ g_return_if_fail (merge_context != NULL);
+
+ if (!e_client_utils_open_new_finish (source, result, &client, &error))
+ client = NULL;
+
+ if (error) {
+ g_debug ("%s: Failed to open targer client: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ merge_context->target_client = client ? E_BOOK_CLIENT (client) : NULL;
+
+ if (!merge_context->target_client) {
+ g_slist_foreach (merge_context->remaining_contacts, (GFunc) g_object_unref, NULL);
+ g_slist_free (merge_context->remaining_contacts);
+
+ merge_context_free (merge_context);
+ return;
+ }
+
+ eab_merging_book_add_contact (
+ merge_context->target_client, merge_context->current_contact,
+ addressbook_selector_merge_next_cb, merge_context);
+}
+
static gboolean
addressbook_selector_data_dropped (ESourceSelector *selector,
GtkSelectionData *selection_data,
@@ -252,9 +294,8 @@ addressbook_selector_data_dropped (ESourceSelector *selector,
EAddressbookSelectorPrivate *priv;
MergeContext *merge_context;
EAddressbookModel *model;
- EBook *source_book;
- EBook *target_book;
- GList *list;
+ EBookClient *source_client = NULL;
+ GSList *list;
const gchar *string;
gboolean remove_from_source;
@@ -264,30 +305,26 @@ addressbook_selector_data_dropped (ESourceSelector *selector,
string = (const gchar *) gtk_selection_data_get_data (selection_data);
remove_from_source = (action == GDK_ACTION_MOVE);
- target_book = e_book_new (destination, NULL);
- if (target_book == NULL)
- return FALSE;
-
- e_book_open (target_book, FALSE, NULL);
-
/* XXX Function assumes both out arguments are provided. All we
- * care about is the contact list; source_book will be NULL. */
- eab_book_and_contact_list_from_string (string, &source_book, &list);
+ * care about is the contact list; source_client will be NULL. */
+ eab_book_and_contact_list_from_string (string, &source_client, &list);
+ if (source_client)
+ g_object_unref (source_client);
+
if (list == NULL)
return FALSE;
model = e_addressbook_view_get_model (priv->current_view);
- source_book = e_addressbook_model_get_book (model);
- g_return_val_if_fail (E_IS_BOOK (source_book), FALSE);
+ source_client = e_addressbook_model_get_client (model);
+ g_return_val_if_fail (E_IS_BOOK_CLIENT (source_client), FALSE);
- merge_context = merge_context_new (source_book, target_book, list);
+ merge_context = merge_context_new (g_object_ref (source_client), NULL, list);
merge_context->remove_from_source = remove_from_source;
merge_context->pending_adds = TRUE;
- eab_merging_book_add_contact (
- target_book, merge_context->current_contact,
- (EBookIdAsyncCallback) addressbook_selector_merge_next_cb,
- merge_context);
+ e_client_utils_open_new (destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, NULL,
+ target_client_open_ready_cb, merge_context);
return TRUE;
}
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c b/addressbook/gui/widgets/e-addressbook-table-adapter.c
index e246118d3a..e47b5bb186 100644
--- a/addressbook/gui/widgets/e-addressbook-table-adapter.c
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -25,6 +25,9 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
+
+#include <libebook/e-book-client.h>
+
#include "e-addressbook-model.h"
#include "e-addressbook-table-adapter.h"
#include "eab-contact-merging.h"
@@ -145,7 +148,7 @@ addressbook_value_at (ETableModel *etc, gint col, gint row)
/* This function sets the value at a particular point in our ETableModel. */
static void
-contact_modified_cb (EBook* book,
+contact_modified_cb (EBookClient *book_client,
const GError *error,
gpointer user_data)
{
@@ -182,8 +185,8 @@ addressbook_set_value_at (ETableModel *etc, gint col, gint row, gconstpointer va
}
e_contact_set (contact, col, (gpointer) val);
- eab_merging_book_commit_contact (
- e_addressbook_model_get_book (priv->model),
+ eab_merging_book_modify_contact (
+ e_addressbook_model_get_client (priv->model),
contact, contact_modified_cb, etc);
g_object_unref (contact);
@@ -227,7 +230,7 @@ addressbook_append_row (ETableModel *etm, ETableModel *source, gint row)
EAddressbookTableAdapter *adapter = EAB_TABLE_ADAPTER (etm);
EAddressbookTableAdapterPrivate *priv = adapter->priv;
EContact *contact;
- EBook *book;
+ EBookClient *book_client;
gint col;
contact = e_contact_new ();
@@ -237,8 +240,8 @@ addressbook_append_row (ETableModel *etm, ETableModel *source, gint row)
e_contact_set (contact, col, (gpointer) val);
}
- book = e_addressbook_model_get_book (priv->model);
- eab_merging_book_add_contact (book, contact, NULL, NULL);
+ book_client = e_addressbook_model_get_client (priv->model);
+ eab_merging_book_add_contact (book_client, contact, NULL, NULL);
g_object_unref (contact);
}
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.h b/addressbook/gui/widgets/e-addressbook-table-adapter.h
index 71999bd4d1..17cf4cfadb 100644
--- a/addressbook/gui/widgets/e-addressbook-table-adapter.h
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.h
@@ -22,8 +22,6 @@
#define _EAB_TABLE_ADAPTER_H_
#include <table/e-table-model.h>
-#include <libebook/e-book.h>
-#include <libebook/e-book-view.h>
#define E_TYPE_AB_TABLE_ADAPTER (eab_table_adapter_get_type ())
#define EAB_TABLE_ADAPTER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_AB_TABLE_ADAPTER, EAddressbookTableAdapter))
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 321a9fd949..00f106ea40 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -64,10 +64,9 @@
#define d(x)
static void status_message (EAddressbookView *view,
- const gchar *status);
+ const gchar *status, gint percent);
static void search_result (EAddressbookView *view,
- EBookViewStatus status,
- const gchar *error_msg);
+ const GError *error);
static void folder_bar_message (EAddressbookView *view,
const gchar *status);
static void stop_state_changed (GObject *object,
@@ -240,8 +239,8 @@ table_drag_data_get (ETable *table,
{
EAddressbookView *view = user_data;
EAddressbookModel *model;
- EBook *book;
- GList *contact_list;
+ EBookClient *book_client;
+ GSList *contact_list;
GdkAtom target;
gchar *value;
@@ -249,7 +248,7 @@ table_drag_data_get (ETable *table,
return;
model = e_addressbook_view_get_model (view);
- book = e_addressbook_model_get_book (model);
+ book_client = e_addressbook_model_get_client (model);
contact_list = e_addressbook_view_get_selected (view);
target = gtk_selection_data_get_target (selection_data);
@@ -267,7 +266,7 @@ table_drag_data_get (ETable *table,
case DND_TARGET_TYPE_SOURCE_VCARD:
value = eab_book_and_contact_list_to_string (
- book, contact_list);
+ book_client, contact_list);
gtk_selection_data_set (
selection_data, target, 8,
@@ -277,8 +276,7 @@ table_drag_data_get (ETable *table,
break;
}
- g_list_foreach (contact_list, (GFunc) g_object_unref, NULL);
- g_list_free (contact_list);
+ e_client_util_free_object_slist (contact_list);
}
static void
@@ -668,7 +666,7 @@ addressbook_view_copy_clipboard (ESelectable *selectable)
{
EAddressbookView *view;
GtkClipboard *clipboard;
- GList *contact_list;
+ GSList *contact_list;
gchar *string;
view = E_ADDRESSBOOK_VIEW (selectable);
@@ -680,18 +678,17 @@ addressbook_view_copy_clipboard (ESelectable *selectable)
e_clipboard_set_directory (clipboard, string, -1);
g_free (string);
- g_list_foreach (contact_list, (GFunc) g_object_unref, NULL);
- g_list_free (contact_list);
+ e_client_util_free_object_slist (contact_list);
}
static void
addressbook_view_paste_clipboard (ESelectable *selectable)
{
- EBook *book;
+ EBookClient *book_client;
EAddressbookView *view;
EAddressbookModel *model;
GtkClipboard *clipboard;
- GList *contact_list, *iter;
+ GSList *contact_list, *iter;
gchar *string;
view = E_ADDRESSBOOK_VIEW (selectable);
@@ -701,7 +698,7 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
return;
model = e_addressbook_view_get_model (view);
- book = e_addressbook_model_get_book (model);
+ book_client = e_addressbook_model_get_client (model);
string = e_clipboard_wait_for_directory (clipboard);
contact_list = eab_contact_list_from_string (string);
@@ -710,11 +707,10 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
for (iter = contact_list; iter != NULL; iter = iter->next) {
EContact *contact = iter->data;
- eab_merging_book_add_contact (book, contact, NULL, NULL);
+ eab_merging_book_add_contact (book_client, contact, NULL, NULL);
}
- g_list_foreach (contact_list, (GFunc) g_object_unref, NULL);
- g_list_free (contact_list);
+ e_client_util_free_object_slist (contact_list);
}
static void
@@ -979,14 +975,14 @@ e_addressbook_view_get_view_object (EAddressbookView *view)
static void
add_to_list (gint model_row, gpointer closure)
{
- GList **list = closure;
- *list = g_list_prepend (*list, GINT_TO_POINTER (model_row));
+ GSList **list = closure;
+ *list = g_slist_prepend (*list, GINT_TO_POINTER (model_row));
}
-GList *
+GSList *
e_addressbook_view_get_selected (EAddressbookView *view)
{
- GList *list, *iter;
+ GSList *list, *iter;
ESelectionModel *selection;
g_return_val_if_fail (E_IS_ADDRESSBOOK_VIEW (view), NULL);
@@ -998,9 +994,7 @@ e_addressbook_view_get_selected (EAddressbookView *view)
for (iter = list; iter != NULL; iter = iter->next)
iter->data = e_addressbook_model_get_contact (
view->priv->model, GPOINTER_TO_INT (iter->data));
- list = g_list_reverse (list);
-
- return list;
+ return g_slist_reverse (list);
}
ESelectionModel *
@@ -1064,8 +1058,7 @@ e_addressbook_view_get_paste_target_list (EAddressbookView *view)
}
static void
-status_message (EAddressbookView *view,
- const gchar *status)
+status_message (EAddressbookView *view, const gchar *status, gint percent)
{
EActivity *activity;
EShellView *shell_view;
@@ -1086,16 +1079,19 @@ status_message (EAddressbookView *view,
activity = e_activity_new ();
view->priv->activity = activity;
e_activity_set_text (activity, status);
+ if (percent >= 0)
+ e_activity_set_percent (activity, percent);
e_shell_backend_add_activity (shell_backend, activity);
-
- } else
+ } else {
e_activity_set_text (activity, status);
+ if (percent >= 0)
+ e_activity_set_percent (activity, percent);
+ }
}
static void
search_result (EAddressbookView *view,
- EBookViewStatus status,
- const gchar *error_msg)
+ const GError *error)
{
EShellView *shell_view;
EAlertSink *alert_sink;
@@ -1103,7 +1099,7 @@ search_result (EAddressbookView *view,
shell_view = e_addressbook_view_get_shell_view (view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
- eab_search_result_dialog (alert_sink, status, error_msg);
+ eab_search_result_dialog (alert_sink, error);
}
static void
@@ -1143,17 +1139,17 @@ backend_died (EAddressbookView *view)
EShellView *shell_view;
EAlertSink *alert_sink;
EAddressbookModel *model;
- EBook *book;
+ EBookClient *book_client;
shell_view = e_addressbook_view_get_shell_view (view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
model = e_addressbook_view_get_model (view);
- book = e_addressbook_model_get_book (model);
+ book_client = e_addressbook_model_get_client (model);
e_alert_submit (alert_sink,
"addressbook:backend-died",
- e_book_get_uri (book), NULL);
+ e_client_get_uri (E_CLIENT (book_client)), NULL);
}
static void
@@ -1215,31 +1211,29 @@ e_addressbook_view_print (EAddressbookView *view,
/* Print the selected contacts. */
if (GAL_IS_VIEW_MINICARD (gal_view) && selection_only) {
- GList *contact_list;
+ GSList *contact_list;
contact_list = e_addressbook_view_get_selected (view);
e_contact_print (NULL, NULL, contact_list, action);
- g_list_foreach (contact_list, (GFunc) g_object_unref, NULL);
- g_list_free (contact_list);
+ e_client_util_free_object_slist (contact_list);
/* Print the latest query results. */
} else if (GAL_IS_VIEW_MINICARD (gal_view)) {
EAddressbookModel *model;
- EBook *book;
+ EBookClient *book_client;
EBookQuery *query;
- gchar *query_string;
+ const gchar *query_string;
model = e_addressbook_view_get_model (view);
- book = e_addressbook_model_get_book (model);
+ book_client = e_addressbook_model_get_client (model);
query_string = e_addressbook_model_get_query (model);
if (query_string != NULL)
query = e_book_query_from_string (query_string);
else
query = NULL;
- g_free (query_string);
- e_contact_print (book, query, NULL, action);
+ e_contact_print (book_client, query, NULL, action);
if (query != NULL)
e_book_query_unref (query);
@@ -1259,26 +1253,51 @@ e_addressbook_view_print (EAddressbookView *view,
}
}
+static void
+report_and_free_error_if_any (GError *error)
+{
+ if (!error)
+ return;
+
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
+ g_error_free (error);
+ return;
+ }
+
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_PERMISSION_DENIED)) {
+ e_alert_run_dialog_for_args (e_shell_get_active_window (NULL),
+ "addressbook:contact-delete-error-perm",
+ NULL);
+ } else {
+ eab_error_dialog (NULL, _("Failed to delete contact"), error);
+ }
+
+ g_error_free (error);
+}
+
/* callback function to handle removal of contacts for
* which a user doesnt have write permission
*/
static void
-delete_contacts_cb (EBook *book, const GError *error, gpointer closure)
+remove_contacts_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- switch (error ? error->code : E_BOOK_ERROR_OK) {
- case E_BOOK_ERROR_OK :
- case E_BOOK_ERROR_CANCELLED :
- break;
- case E_BOOK_ERROR_PERMISSION_DENIED :
- e_alert_run_dialog_for_args (e_shell_get_active_window (NULL),
- "addressbook:contact-delete-error-perm",
- NULL);
- break;
- default :
- /* Unknown error */
- eab_error_dialog (NULL, _("Failed to delete contact"), error);
- break;
- }
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ GError *error = NULL;
+
+ e_book_client_remove_contacts_finish (book_client, result, &error);
+
+ report_and_free_error_if_any (error);
+}
+
+static void
+remove_contact_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ GError *error = NULL;
+
+ e_book_client_remove_contact_finish (book_client, result, &error);
+
+ report_and_free_error_if_any (error);
}
static gboolean
@@ -1340,12 +1359,12 @@ addressbook_view_confirm_delete (GtkWindow *parent,
void
e_addressbook_view_delete_selection (EAddressbookView *view, gboolean is_delete)
{
- GList *list, *l;
+ GSList *list, *l;
gboolean plural = FALSE, is_list = FALSE;
EContact *contact;
ETable *etable = NULL;
EAddressbookModel *model;
- EBook *book;
+ EBookClient *book_client;
ESelectionModel *selection_model = NULL;
GalViewInstance *view_instance;
GalView *gal_view;
@@ -1354,7 +1373,7 @@ e_addressbook_view_delete_selection (EAddressbookView *view, gboolean is_delete)
gint row = 0, select;
model = e_addressbook_view_get_model (view);
- book = e_addressbook_model_get_book (model);
+ book_client = e_addressbook_model_get_client (model);
view_instance = e_addressbook_view_get_view_instance (view);
gal_view = gal_view_instance_get_current_view (view_instance);
@@ -1362,7 +1381,7 @@ e_addressbook_view_delete_selection (EAddressbookView *view, gboolean is_delete)
list = e_addressbook_view_get_selected (view);
contact = list->data;
- if (g_list_next (list))
+ if (g_slist_next (list))
plural = TRUE;
else
name = e_contact_get (contact, E_CONTACT_FILE_AS);
@@ -1387,38 +1406,29 @@ e_addressbook_view_delete_selection (EAddressbookView *view, gboolean is_delete)
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
plural, is_list, name)) {
g_free (name);
- g_list_foreach (list, (GFunc) g_object_unref, NULL);
- g_list_free (list);
+ e_client_util_free_object_slist (list);
return;
}
- if (e_book_check_static_capability (book, "bulk-remove")) {
- GList *ids = NULL;
+ if (e_client_check_capability (E_CLIENT (book_client), "bulk-remove")) {
+ GSList *ids = NULL;
- for (l=list;l;l=g_list_next (l)) {
+ for (l = list; l; l = g_slist_next (l)) {
contact = l->data;
- ids = g_list_prepend (
- ids, (gchar *) e_contact_get_const (
- contact, E_CONTACT_UID));
+ ids = g_slist_prepend (ids, (gpointer) e_contact_get_const (contact, E_CONTACT_UID));
}
/* Remove the cards all at once. */
- e_book_remove_contacts_async (book,
- ids,
- delete_contacts_cb,
- NULL);
+ e_book_client_remove_contacts (book_client, ids, NULL, remove_contacts_cb, NULL);
- g_list_free (ids);
- }
- else {
- for (l=list;l;l=g_list_next (l)) {
+ g_slist_free (ids);
+ } else {
+ for (l = list; l; l = g_slist_next (l)) {
contact = l->data;
+
/* Remove the card. */
- e_book_remove_contact_async (book,
- contact,
- delete_contacts_cb,
- NULL);
+ e_book_client_remove_contact (book_client, contact, NULL, remove_contact_cb, NULL);
}
}
@@ -1449,21 +1459,20 @@ e_addressbook_view_delete_selection (EAddressbookView *view, gboolean is_delete)
row = e_table_view_to_model_row (E_TABLE (etable), select);
e_table_set_cursor_row (E_TABLE (etable), row);
}
- g_list_foreach (list, (GFunc) g_object_unref, NULL);
- g_list_free (list);
+ e_client_util_free_object_slist (list);
}
void
e_addressbook_view_view (EAddressbookView *view)
{
- GList *list, *iter;
+ GSList *list, *iter;
gint response;
guint length;
g_return_if_fail (E_IS_ADDRESSBOOK_VIEW (view));
list = e_addressbook_view_get_selected (view);
- length = g_list_length (list);
+ length = g_slist_length (list);
response = GTK_RESPONSE_YES;
if (length > 5) {
@@ -1495,8 +1504,7 @@ e_addressbook_view_view (EAddressbookView *view)
addressbook_view_emit_open_contact (
view, iter->data, FALSE);
- g_list_foreach (list, (GFunc) g_object_unref, NULL);
- g_list_free (list);
+ e_client_util_free_object_slist (list);
}
void
@@ -1515,42 +1523,78 @@ e_addressbook_view_stop (EAddressbookView *view)
e_addressbook_model_stop (view->priv->model);
}
+struct TransferContactsData
+{
+ gboolean delete_from_source;
+ EAddressbookView *view;
+};
+
static void
-view_transfer_contacts (EAddressbookView *view,
- gboolean delete_from_source,
- gboolean all)
+all_contacts_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EBook *book;
- GList *contacts = NULL;
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ struct TransferContactsData *tcd = user_data;
EShellView *shell_view;
EAlertSink *alert_sink;
+ GSList *contacts = NULL;
+ GError *error = NULL;
- book = e_addressbook_model_get_book (view->priv->model);
- shell_view = e_addressbook_view_get_shell_view (view);
+ g_return_if_fail (book_client != NULL);
+ g_return_if_fail (tcd != NULL);
+
+ if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error))
+ contacts = NULL;
+
+ shell_view = e_addressbook_view_get_shell_view (tcd->view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
+ if (error) {
+ e_alert_submit (
+ alert_sink, "addressbook:search-error",
+ error->message, NULL);
+ g_error_free (error);
+ } else if (contacts) {
+ eab_transfer_contacts (book_client, contacts, tcd->delete_from_source, alert_sink);
+ }
+
+ g_object_unref (tcd->view);
+ g_free (tcd);
+}
+
+static void
+view_transfer_contacts (EAddressbookView *view,
+ gboolean delete_from_source,
+ gboolean all)
+{
+ EBookClient *book_client;
+
+ book_client = e_addressbook_model_get_client (view->priv->model);
+
if (all) {
EBookQuery *query;
- GError *error = NULL;
+ gchar *query_str;
+ struct TransferContactsData *tcd;
query = e_book_query_any_field_contains ("");
- e_book_get_contacts (book, query, &contacts, &error);
+ query_str = e_book_query_to_string (query);
e_book_query_unref (query);
- if (error) {
- e_alert_submit (
- alert_sink, "addressbook:search-error",
- error->message, NULL);
- g_error_free (error);
- return;
- }
+ tcd = g_new0 (struct TransferContactsData, 1);
+ tcd->delete_from_source = delete_from_source;
+ tcd->view = g_object_ref (view);
+
+ e_book_client_get_contacts (book_client, query_str, NULL, all_contacts_ready_cb, tcd);
} else {
- contacts = e_addressbook_view_get_selected (view);
- }
+ GSList *contacts = NULL;
+ EShellView *shell_view;
+ EAlertSink *alert_sink;
- eab_transfer_contacts (book, contacts, delete_from_source, alert_sink);
+ shell_view = e_addressbook_view_get_shell_view (view);
+ alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
+ contacts = e_addressbook_view_get_selected (view);
- g_object_unref (book);
+ eab_transfer_contacts (book_client, contacts, delete_from_source, alert_sink);
+ }
}
void
diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h
index 4b85293cd5..1ccfba99b3 100644
--- a/addressbook/gui/widgets/e-addressbook-view.h
+++ b/addressbook/gui/widgets/e-addressbook-view.h
@@ -23,7 +23,7 @@
#ifndef E_ADDRESSBOOK_VIEW_H
#define E_ADDRESSBOOK_VIEW_H
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include <libebook/e-contact.h>
#include <menus/gal-view-instance.h>
@@ -73,8 +73,6 @@ struct _EAddressbookViewClass {
gboolean is_new_contact);
void (*popup_event) (EAddressbookView *view,
GdkEvent *event);
- void (*status_message) (EAddressbookView *view,
- const gchar *message);
void (*command_state_change) (EAddressbookView *view);
void (*selection_change) (EAddressbookView *view);
};
@@ -89,7 +87,7 @@ GalViewInstance *
(EAddressbookView *view);
GObject * e_addressbook_view_get_view_object
(EAddressbookView *view);
-GList * e_addressbook_view_get_selected (EAddressbookView *view);
+GSList * e_addressbook_view_get_selected (EAddressbookView *view);
ESelectionModel *
e_addressbook_view_get_selection_model
(EAddressbookView *view);
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.c b/addressbook/gui/widgets/e-minicard-view-widget.c
index 4421b1a739..65fa12d9f1 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.c
+++ b/addressbook/gui/widgets/e-minicard-view-widget.c
@@ -63,7 +63,7 @@ static gpointer parent_class;
/* The arguments we take */
enum {
PROP_0,
- PROP_BOOK,
+ PROP_CLIENT,
PROP_QUERY,
PROP_EDITABLE,
PROP_COLUMN_WIDTH
@@ -132,11 +132,11 @@ e_minicard_view_widget_class_init (EMinicardViewWidgetClass *class)
class->column_width_changed = NULL;
class->right_click = NULL;
- g_object_class_install_property (object_class, PROP_BOOK,
- g_param_spec_object ("book",
- "Book",
+ g_object_class_install_property (object_class, PROP_CLIENT,
+ g_param_spec_object ("client",
+ "EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_QUERY,
@@ -211,7 +211,7 @@ e_minicard_view_widget_init (EMinicardViewWidget *view)
{
view->emv = NULL;
- view->book = NULL;
+ view->book_client = NULL;
view->query = NULL;
view->editable = FALSE;
view->column_width = 225;
@@ -240,18 +240,18 @@ e_minicard_view_widget_set_property (GObject *object,
emvw = E_MINICARD_VIEW_WIDGET (object);
switch (prop_id) {
- case PROP_BOOK:
- if (emvw->book)
- g_object_unref (emvw->book);
+ case PROP_CLIENT:
+ if (emvw->book_client)
+ g_object_unref (emvw->book_client);
if (g_value_get_object (value)) {
- emvw->book = E_BOOK (g_value_get_object (value));
- if (emvw->book)
- g_object_ref (emvw->book);
+ emvw->book_client = E_BOOK_CLIENT (g_value_get_object (value));
+ if (emvw->book_client)
+ g_object_ref (emvw->book_client);
} else
- emvw->book = NULL;
+ emvw->book_client = NULL;
if (emvw->emv)
g_object_set (emvw->emv,
- "book", emvw->book,
+ "client", emvw->book_client,
NULL);
break;
case PROP_QUERY:
@@ -293,8 +293,8 @@ e_minicard_view_widget_get_property (GObject *object,
emvw = E_MINICARD_VIEW_WIDGET (object);
switch (prop_id) {
- case PROP_BOOK:
- g_value_set_object (value, emvw->book);
+ case PROP_CLIENT:
+ g_value_set_object (value, emvw->book_client);
break;
case PROP_QUERY:
g_value_set_string (value, emvw->query);
@@ -316,9 +316,9 @@ e_minicard_view_widget_dispose (GObject *object)
{
EMinicardViewWidget *view = E_MINICARD_VIEW_WIDGET (object);
- if (view->book) {
- g_object_unref (view->book);
- view->book = NULL;
+ if (view->book_client) {
+ g_object_unref (view->book_client);
+ view->book_client = NULL;
}
if (view->query) {
g_free (view->query);
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.h b/addressbook/gui/widgets/e-minicard-view-widget.h
index ab5bda2881..aea68bd5db 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.h
+++ b/addressbook/gui/widgets/e-minicard-view-widget.h
@@ -24,7 +24,7 @@
#define __E_MINICARD_VIEW_WIDGET_H__
#include <misc/e-canvas.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include "e-minicard-view.h"
G_BEGIN_DECLS
@@ -47,7 +47,7 @@ struct _EMinicardViewWidget
EAddressbookReflowAdapter *adapter;
- EBook *book;
+ EBookClient *book_client;
gchar *query;
guint editable : 1;
diff --git a/addressbook/gui/widgets/e-minicard-view.c b/addressbook/gui/widgets/e-minicard-view.c
index a00b03816c..91a4a12991 100644
--- a/addressbook/gui/widgets/e-minicard-view.c
+++ b/addressbook/gui/widgets/e-minicard-view.c
@@ -24,6 +24,8 @@
#include <config.h>
#endif
+#include <libebook/e-book-client.h>
+
#include "e-minicard-view.h"
#include "eab-gui-util.h"
@@ -52,7 +54,7 @@ static EReflowClass *parent_class = NULL;
enum {
PROP_0,
PROP_ADAPTER,
- PROP_BOOK,
+ PROP_CLIENT,
PROP_QUERY,
PROP_EDITABLE
};
@@ -105,15 +107,17 @@ e_minicard_view_drag_data_get (GtkWidget *widget,
break;
}
case DND_TARGET_TYPE_SOURCE_VCARD_LIST: {
- EBook *book;
+ EBookClient *book_client = NULL;
gchar *value;
- g_object_get (view->adapter, "book", &book, NULL);
- value = eab_book_and_contact_list_to_string (book, view->drag_list);
+ g_object_get (view->adapter, "book_client", &book_client, NULL);
+ value = eab_book_and_contact_list_to_string (book_client, view->drag_list);
gtk_selection_data_set (
selection_data, target, 8,
(guchar *) value, strlen (value));
+
+ g_object_unref (book_client);
g_free (value);
break;
}
@@ -123,8 +127,7 @@ e_minicard_view_drag_data_get (GtkWidget *widget,
static void
clear_drag_data (EMinicardView *view)
{
- g_list_foreach (view->drag_list, (GFunc) g_object_unref, NULL);
- g_list_free (view->drag_list);
+ e_client_util_free_object_slist (view->drag_list);
view->drag_list = NULL;
}
@@ -141,7 +144,7 @@ e_minicard_view_drag_begin (EAddressbookReflowAdapter *adapter,
view->drag_list = e_minicard_view_get_card_list (view);
- g_print ("dragging %d card(s)\n", g_list_length (view->drag_list));
+ g_print ("dragging %d card(s)\n", g_slist_length (view->drag_list));
target_list = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types));
@@ -163,21 +166,26 @@ set_empty_message (EMinicardView *view)
{
gchar *empty_message;
gboolean editable = FALSE, perform_initial_query = FALSE, searching = FALSE;
- EBook *book;
if (view->adapter) {
EAddressbookModel *model = NULL;
+ EBookClient *book_client = NULL;
g_object_get (view->adapter,
"editable", &editable,
"model", &model,
- "book", &book,
+ "client", &book_client,
NULL);
- if (book && !e_book_check_static_capability (book, "do-initial-query"))
+ if (book_client && !e_client_check_capability (E_CLIENT (book_client), "do-initial-query"))
perform_initial_query = TRUE;
searching = model && e_addressbook_model_can_stop (model);
+
+ if (book_client)
+ g_object_unref (book_client);
+ if (model)
+ g_object_unref (model);
}
if (searching) {
@@ -277,9 +285,9 @@ e_minicard_view_set_property (GObject *object,
}
break;
- case PROP_BOOK:
+ case PROP_CLIENT:
g_object_set (view->adapter,
- "book", g_value_get_object (value),
+ "client", g_value_get_object (value),
NULL);
set_empty_message (view);
break;
@@ -314,9 +322,9 @@ e_minicard_view_get_property (GObject *object,
case PROP_ADAPTER:
g_value_set_object (value, view->adapter);
break;
- case PROP_BOOK:
+ case PROP_CLIENT:
g_object_get_property (G_OBJECT (view->adapter),
- "book", value);
+ "client", value);
break;
case PROP_QUERY:
g_object_get_property (G_OBJECT (view->adapter),
@@ -455,33 +463,6 @@ e_minicard_view_selection_event (EReflow *reflow,
return return_val;
}
-typedef struct {
- EMinicardView *view;
- EBookAsyncCallback cb;
- gpointer closure;
-} ViewCbClosure;
-
-static void
-do_remove (gint i, gpointer user_data)
-{
- EBook *book;
- EContact *contact;
- ViewCbClosure *viewcbclosure = user_data;
- EMinicardView *view = viewcbclosure->view;
- EBookAsyncCallback cb = viewcbclosure->cb;
- gpointer closure = viewcbclosure->closure;
-
- g_object_get (view->adapter,
- "book", &book,
- NULL);
-
- contact = e_addressbook_reflow_adapter_get_contact (view->adapter, i);
-
- e_book_remove_contact_async (book, contact, cb, closure);
-
- g_object_unref (contact);
-}
-
#if 0
static gint
compare_to_utf_str (EMinicard *card, const gchar *utf_str)
@@ -532,11 +513,11 @@ e_minicard_view_class_init (EMinicardViewClass *klass)
E_TYPE_ADDRESSBOOK_REFLOW_ADAPTER,
G_PARAM_READWRITE));
- g_object_class_install_property (object_class, PROP_BOOK,
- g_param_spec_object ("book",
- "Book",
+ g_object_class_install_property (object_class, PROP_CLIENT,
+ g_param_spec_object ("client",
+ "EBookClient",
NULL,
- E_TYPE_BOOK,
+ E_TYPE_BOOK_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_QUERY,
@@ -625,21 +606,6 @@ e_minicard_view_get_type (void)
}
void
-e_minicard_view_remove_selection (EMinicardView *view,
- EBookAsyncCallback cb,
- gpointer closure)
-{
- ViewCbClosure viewcbclosure;
- viewcbclosure.view = view;
- viewcbclosure.cb = cb;
- viewcbclosure.closure = closure;
-
- e_selection_model_foreach (E_REFLOW (view)->selection,
- do_remove,
- &viewcbclosure);
-}
-
-void
e_minicard_view_jump_to_letter (EMinicardView *view,
gunichar letter)
{
@@ -654,7 +620,7 @@ e_minicard_view_jump_to_letter (EMinicardView *view,
}
typedef struct {
- GList *list;
+ GSList *list;
EAddressbookReflowAdapter *adapter;
} ModelAndList;
@@ -662,12 +628,12 @@ static void
add_to_list (gint index, gpointer closure)
{
ModelAndList *mal = closure;
- mal->list = g_list_prepend (
+ mal->list = g_slist_prepend (
mal->list, e_addressbook_reflow_adapter_get_contact (
mal->adapter, index));
}
-GList *
+GSList *
e_minicard_view_get_card_list (EMinicardView *view)
{
ModelAndList mal;
@@ -677,8 +643,7 @@ e_minicard_view_get_card_list (EMinicardView *view)
e_selection_model_foreach (E_REFLOW (view)->selection, add_to_list, &mal);
- mal.list = g_list_reverse (mal.list);
- return mal.list;
+ return g_slist_reverse (mal.list);
}
void
diff --git a/addressbook/gui/widgets/e-minicard-view.h b/addressbook/gui/widgets/e-minicard-view.h
index 8b37ba6df5..1024a85088 100644
--- a/addressbook/gui/widgets/e-minicard-view.h
+++ b/addressbook/gui/widgets/e-minicard-view.h
@@ -28,7 +28,6 @@
#include <text/e-reflow.h>
#include <misc/e-selection-model-simple.h>
-#include <libebook/e-book.h>
#include "e-addressbook-reflow-adapter.h"
G_BEGIN_DECLS
@@ -69,7 +68,7 @@ struct _EMinicardView
/* item specific fields */
- GList *drag_list;
+ GSList *drag_list;
guint canvas_drag_data_get_id;
guint writable_status_id;
@@ -84,12 +83,9 @@ struct _EMinicardViewClass
};
GType e_minicard_view_get_type (void);
-void e_minicard_view_remove_selection (EMinicardView *view,
- EBookAsyncCallback cb,
- gpointer closure);
void e_minicard_view_jump_to_letter (EMinicardView *view,
gunichar letter);
-GList *e_minicard_view_get_card_list (EMinicardView *view);
+GSList *e_minicard_view_get_card_list (EMinicardView *view);
void e_minicard_view_create_contact (EMinicardView *view);
void e_minicard_view_create_contact_list (EMinicardView *view);
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index 98cf1c2f98..352604984c 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -32,7 +32,6 @@
#include <e-util/e-util.h>
#include <misc/e-canvas-utils.h>
#include <misc/e-canvas.h>
-#include <libebook/e-book.h>
#include "eab-gui-util.h"
#include "e-minicard.h"
#include "e-minicard-label.h"
diff --git a/addressbook/gui/widgets/ea-minicard-view.c b/addressbook/gui/widgets/ea-minicard-view.c
index 6850813ca7..a61c6074a0 100644
--- a/addressbook/gui/widgets/ea-minicard-view.c
+++ b/addressbook/gui/widgets/ea-minicard-view.c
@@ -148,7 +148,7 @@ ea_minicard_view_get_name (AtkObject *accessible)
EReflow *reflow;
gchar *string;
EMinicardView *card_view;
- EBook *book = NULL;
+ EBookClient *book_client = NULL;
const gchar *source_name;
g_return_val_if_fail (EA_IS_MINICARD_VIEW (accessible), NULL);
@@ -161,9 +161,9 @@ ea_minicard_view_get_name (AtkObject *accessible)
/* Get the current name of minicard view*/
card_view = E_MINICARD_VIEW (reflow);
- g_object_get (card_view->adapter, "book", &book, NULL);
- g_return_val_if_fail (E_IS_BOOK (book), NULL);
- source_name = e_source_peek_name (e_book_get_source (book));
+ g_object_get (card_view->adapter, "client", &book_client, NULL);
+ g_return_val_if_fail (E_IS_BOOK_CLIENT (book_client), NULL);
+ source_name = e_source_peek_name (e_client_get_source (E_CLIENT (book_client)));
if (!source_name)
source_name="";
@@ -173,7 +173,7 @@ ea_minicard_view_get_name (AtkObject *accessible)
ATK_OBJECT_CLASS (parent_class)->set_name (accessible, string);
g_free (string);
- g_object_unref (book);
+ g_object_unref (book_client);
return accessible->name;
}
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 1ade6b143a..359c104c89 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -35,7 +35,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-client-utils.h>
#include <libedataserverui/e-source-selector.h>
#include <e-util/e-util.h>
#include "eab-gui-util.h"
@@ -108,7 +108,7 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
uri = e_source_get_uri (source);
- if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_OFFLINE_UNAVAILABLE)) {
+ if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_OFFLINE_UNAVAILABLE)) {
can_detail_error = FALSE;
label_string = _("This address book cannot be opened. This either means this "
"book is not marked for offline usage or not yet downloaded "
@@ -166,7 +166,7 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
if (can_detail_error) {
/* do not show repository offline message, it's kind of generic error */
- if (error && !g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_REPOSITORY_OFFLINE)) {
+ if (error && !g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE)) {
label = g_strconcat (label_string, "\n\n", _("Detailed error message:"), " ", error->message, NULL);
label_string = label;
}
@@ -187,46 +187,50 @@ eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *sourc
}
void
-eab_search_result_dialog (EAlertSink *alert_sink,
- EBookViewStatus status,
- const gchar *error_msg)
+eab_search_result_dialog (EAlertSink *alert_sink, const GError *error)
{
gchar *str = NULL;
- switch (status) {
- case E_BOOK_VIEW_STATUS_OK:
+ if (!error)
return;
- case E_BOOK_VIEW_STATUS_SIZE_LIMIT_EXCEEDED:
- str = _("More cards matched this query than either the server is \n"
- "configured to return or Evolution is configured to display.\n"
- "Please make your search more specific or raise the result limit in\n"
- "the directory server preferences for this address book.");
- str = g_strdup (str);
- break;
- case E_BOOK_VIEW_STATUS_TIME_LIMIT_EXCEEDED:
- str = _("The time to execute this query exceeded the server limit or the limit\n"
- "configured for this address book. Please make your search\n"
- "more specific or raise the time limit in the directory server\n"
- "preferences for this address book.");
- str = g_strdup (str);
- break;
- case E_BOOK_VIEW_ERROR_INVALID_QUERY:
- /* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
- str = _("The backend for this address book was unable to parse this query. %s");
- str = g_strdup_printf (str, error_msg ? error_msg : "");
- break;
- case E_BOOK_VIEW_ERROR_QUERY_REFUSED:
- /* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
- str = _("The backend for this address book refused to perform this query. %s");
- str = g_strdup_printf (str, error_msg ? error_msg : "");
- break;
- case E_BOOK_VIEW_ERROR_OTHER_ERROR:
+
+ if (error->domain == E_CLIENT_ERROR) {
+ switch (error->code) {
+ case E_CLIENT_ERROR_SEARCH_SIZE_LIMIT_EXCEEDED:
+ str = _("More cards matched this query than either the server is \n"
+ "configured to return or Evolution is configured to display.\n"
+ "Please make your search more specific or raise the result limit in\n"
+ "the directory server preferences for this address book.");
+ str = g_strdup (str);
+ break;
+ case E_CLIENT_ERROR_SEARCH_TIME_LIMIT_EXCEEDED:
+ str = _("The time to execute this query exceeded the server limit or the limit\n"
+ "configured for this address book. Please make your search\n"
+ "more specific or raise the time limit in the directory server\n"
+ "preferences for this address book.");
+ str = g_strdup (str);
+ break;
+ case E_CLIENT_ERROR_INVALID_QUERY:
+ /* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
+ str = _("The backend for this address book was unable to parse this query. %s");
+ str = g_strdup_printf (str, error->message);
+ break;
+ case E_CLIENT_ERROR_QUERY_REFUSED:
+ /* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
+ str = _("The backend for this address book refused to perform this query. %s");
+ str = g_strdup_printf (str, error->message);
+ break;
+ case E_CLIENT_ERROR_OTHER_ERROR:
+ default:
+ /* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
+ str = _("This query did not complete successfully. %s");
+ str = g_strdup_printf (str, error->message);
+ break;
+ }
+ } else {
/* Translators: %s is replaced with a detailed error message, or an empty string, if not provided */
str = _("This query did not complete successfully. %s");
- str = g_strdup_printf (str, error_msg ? error_msg : "");
- break;
- default:
- g_return_if_reached ();
+ str = g_strdup_printf (str, error->message);
}
e_alert_submit (alert_sink, "addressbook:search-error", str, NULL);
@@ -284,7 +288,7 @@ eab_select_source (ESource *except_source, const gchar *title, const gchar *mess
GtkWidget *scrolled_window;
gint response;
- if (!e_book_get_addressbooks (&source_list, NULL))
+ if (!e_book_client_get_sources (&source_list, NULL))
return NULL;
dialog = gtk_dialog_new_with_buttons (_("Select Address Book"), parent,
@@ -331,13 +335,13 @@ eab_select_source (ESource *except_source, const gchar *title, const gchar *mess
}
gchar *
-eab_suggest_filename (GList *contact_list)
+eab_suggest_filename (const GSList *contact_list)
{
gchar *res = NULL;
g_return_val_if_fail (contact_list != NULL, NULL);
- if (g_list_length (contact_list) == 1) {
+ if (!contact_list->next) {
EContact *contact = E_CONTACT (contact_list->data);
gchar *string;
@@ -357,36 +361,58 @@ eab_suggest_filename (GList *contact_list)
typedef struct ContactCopyProcess_ ContactCopyProcess;
-typedef void (*ContactCopyDone) (ContactCopyProcess *process);
-
struct ContactCopyProcess_ {
gint count;
gboolean book_status;
- GList *contacts;
- EBook *source;
- EBook *destination;
- ContactCopyDone done_cb;
+ GSList *contacts;
+ EBookClient *source;
+ EBookClient *destination;
+ gboolean delete_from_source;
EAlertSink *alert_sink;
};
+static void process_unref (ContactCopyProcess *process);
+
static void
-do_delete (gpointer data, gpointer user_data)
+remove_contact_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EBook *book = user_data;
+ EBookClient *book_client = E_BOOK_CLIENT (source_object);
+ ContactCopyProcess *process = user_data;
+ GError *error = NULL;
+
+ e_book_client_remove_contact_by_uid_finish (book_client, result, &error);
+
+ if (error) {
+ g_debug ("%s: Remove contact by uid failed: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ process_unref (process);
+}
+
+static void
+do_delete_from_source (gpointer data, gpointer user_data)
+{
+ ContactCopyProcess *process = user_data;
EContact *contact = data;
const gchar *id;
+ EBookClient *book_client = process->source;
id = e_contact_get_const (contact, E_CONTACT_UID);
- e_book_remove_contact (book, id, NULL);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (book_client != NULL);
+
+ process->count++;
+ e_book_client_remove_contact_by_uid (book_client, id, NULL, remove_contact_ready_cb, process);
}
static void
delete_contacts (ContactCopyProcess *process)
{
if (process->book_status == TRUE) {
- g_list_foreach (process->contacts,
- do_delete,
- process->source);
+ g_slist_foreach (process->contacts,
+ do_delete_from_source,
+ process);
}
}
@@ -395,12 +421,15 @@ process_unref (ContactCopyProcess *process)
{
process->count--;
if (process->count == 0) {
- if (process->done_cb)
- process->done_cb (process);
- g_list_foreach (
- process->contacts,
- (GFunc) g_object_unref, NULL);
- g_list_free (process->contacts);
+ if (process->delete_from_source) {
+ delete_contacts (process);
+ /* to not repeate this again */
+ process->delete_from_source = FALSE;
+
+ if (process->count > 0)
+ return;
+ }
+ e_client_util_free_object_slist (process->contacts);
g_object_unref (process->source);
g_object_unref (process->destination);
g_free (process);
@@ -408,58 +437,62 @@ process_unref (ContactCopyProcess *process)
}
static void
-contact_added_cb (EBook* book, const GError *error, const gchar *id, gpointer user_data)
+contact_added_cb (EBookClient *book_client, const GError *error, const gchar *id, gpointer user_data)
{
ContactCopyProcess *process = user_data;
- if (error && !g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) {
+ if (error && !g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
process->book_status = FALSE;
eab_error_dialog (process->alert_sink, _("Error adding contact"), error);
}
- else if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) {
+ else if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED)) {
process->book_status = FALSE;
}
else {
/* success */
process->book_status = TRUE;
}
+
process_unref (process);
}
static void
do_copy (gpointer data, gpointer user_data)
{
- EBook *book;
+ EBookClient *book_client;
EContact *contact;
ContactCopyProcess *process;
process = user_data;
contact = data;
- book = process->destination;
+ book_client = process->destination;
process->count++;
- eab_merging_book_add_contact (book, contact, contact_added_cb, process);
+ eab_merging_book_add_contact (book_client, contact, contact_added_cb, process);
}
static void
-book_loaded_cb (ESource *destination,
- GAsyncResult *result,
- ContactCopyProcess *process)
+book_loaded_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- EBook *book;
+ ESource *destination = E_SOURCE (source_object);
+ ContactCopyProcess *process = user_data;
+ EClient *client = NULL;
+ EBookClient *book_client;
GError *error = NULL;
- book = e_load_book_source_finish (destination, result, &error);
+ if (!e_client_utils_open_new_finish (destination, result, &client, &error))
+ client = NULL;
+
+ book_client = client ? E_BOOK_CLIENT (client) : NULL;
- if (book != NULL) {
+ if (book_client != NULL) {
g_warn_if_fail (error == NULL);
- process->destination = book;
+ process->destination = book_client;
process->book_status = TRUE;
- g_list_foreach (process->contacts, do_copy, process);
-
+ g_slist_foreach (process->contacts, do_copy, process);
} else if (error != NULL) {
- g_warning ("%s", error->message);
+ g_debug ("%s: Failed to open destination client: %s", G_STRFUNC, error->message);
g_error_free (error);
}
@@ -467,8 +500,8 @@ book_loaded_cb (ESource *destination,
}
void
-eab_transfer_contacts (EBook *source_book,
- GList *contacts /* adopted */,
+eab_transfer_contacts (EBookClient *source_client,
+ GSList *contacts /* adopted */,
gboolean delete_from_source,
EAlertSink *alert_sink)
{
@@ -478,7 +511,7 @@ eab_transfer_contacts (EBook *source_book,
gchar *desc;
GtkWindow *window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (alert_sink)));
- g_return_if_fail (E_IS_BOOK (source_book));
+ g_return_if_fail (E_IS_BOOK_CLIENT (source_client));
if (contacts == NULL)
return;
@@ -499,7 +532,7 @@ eab_transfer_contacts (EBook *source_book,
}
destination = eab_select_source (
- e_book_get_source (source_book),
+ e_client_get_source (E_CLIENT (source_client)),
desc, NULL, last_uid, window);
if (!destination)
@@ -513,19 +546,16 @@ eab_transfer_contacts (EBook *source_book,
process = g_new (ContactCopyProcess, 1);
process->count = 1;
process->book_status = FALSE;
- process->source = g_object_ref (source_book);
+ process->source = g_object_ref (source_client);
process->contacts = contacts;
process->destination = NULL;
process->alert_sink = alert_sink;
+ process->delete_from_source = delete_from_source;
- if (delete_from_source)
- process->done_cb = delete_contacts;
- else
- process->done_cb = NULL;
-
- e_load_book_source_async (
- destination, window, NULL,
- (GAsyncReadyCallback) book_loaded_cb, process);
+ e_client_utils_open_new (
+ destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
+ e_client_utils_authenticate_handler, window,
+ 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 b50df6de95..88a759b75b 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -25,7 +25,7 @@
#define __E_ADDRESSBOOK_UTIL_H__
#include <gtk/gtk.h>
-#include <libebook/e-book.h>
+#include <libebook/e-book-client.h>
#include "e-util/e-alert-sink.h"
G_BEGIN_DECLS
@@ -38,14 +38,13 @@ void eab_load_error_dialog (GtkWidget *parent,
ESource *source,
const GError *error);
void eab_search_result_dialog (EAlertSink *alert_sink,
- EBookViewStatus status,
- const gchar *error_msg);
+ const GError *error);
gint eab_prompt_save_dialog (GtkWindow *parent);
-void eab_transfer_contacts (EBook *source_book,
- GList *contacts, /* adopted */
+void eab_transfer_contacts (EBookClient *source_client,
+ GSList *contacts, /* adopted */
gboolean delete_from_source,
EAlertSink *alert_sink);
-gchar * eab_suggest_filename (GList *contact_list);
+gchar * eab_suggest_filename (const GSList *contact_list);
ESource * eab_select_source (ESource *except_source,
const gchar *title,
const gchar *message,