aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/merging
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/merging
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/merging')
-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
4 files changed, 176 insertions, 89 deletions
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