diff options
author | Milan Crha <mcrha@redhat.com> | 2011-06-14 14:54:20 +0800 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2011-06-30 00:42:27 +0800 |
commit | 84339b3be5a771406fcd5898bbd21dc1c5b98c82 (patch) | |
tree | 15a9cfd61451b56d6b35541b1b1e966a34b17faf /addressbook/gui/widgets | |
parent | fa4289a2f3c26112c907f283a1fd8ab3fb4f26d6 (diff) | |
download | gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.gz gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.bz2 gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.lz gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.xz gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.tar.zst gsoc2013-evolution-84339b3be5a771406fcd5898bbd21dc1c5b98c82.zip |
Do not use deprecated EBook/ECal API
Diffstat (limited to 'addressbook/gui/widgets')
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-model.c | 296 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-model.h | 16 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-reflow-adapter.c | 21 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-selector.c | 127 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-table-adapter.c | 15 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-table-adapter.h | 2 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.c | 260 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.h | 6 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view-widget.c | 38 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view-widget.h | 4 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.c | 95 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard-view.h | 8 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-minicard.c | 1 | ||||
-rw-r--r-- | addressbook/gui/widgets/ea-minicard-view.c | 10 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.c | 204 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.h | 11 |
16 files changed, 583 insertions, 531 deletions
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, |