From 14287d8a1faa35d31053a1f03b001f1a949a7eb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?=
 <rafael.carre@savoirfairelinux.com>
Date: Mon, 12 Sep 2011 11:58:23 -0400
Subject: [PATCH] * #5695: addressbook: simplify

---
 gnome/src/actions.c                         |   2 +-
 gnome/src/contacts/calllist.c               |   2 +-
 plugins/addressbook/evolution/addressbook.c |  58 +--
 plugins/addressbook/evolution/addressbook.h |   6 +-
 plugins/addressbook/evolution/eds.c         | 537 ++++----------------
 plugins/addressbook/evolution/eds.h         |  16 -
 plugins/configure.ac                        |   7 +-
 7 files changed, 128 insertions(+), 500 deletions(-)

diff --git a/gnome/src/actions.c b/gnome/src/actions.c
index 717c4ded7d..3836d2bbe6 100644
--- a/gnome/src/actions.c
+++ b/gnome/src/actions.c
@@ -138,7 +138,7 @@ sflphone_notify_voice_mail (const gchar* accountID , guint count)
 
 static gboolean _is_direct_call (callable_obj_t * c)
 {
-    if (g_strcasecmp (c->_accountID, EMPTY_ENTRY) == 0) {
+    if (g_strcasecmp (c->_accountID, "empty") == 0) {
         if (!g_str_has_prefix (c->_peer_number, "sip:")) {
             gchar * new_number = g_strconcat ("sip:", c->_peer_number, NULL);
             g_free (c->_peer_number);
diff --git a/gnome/src/contacts/calllist.c b/gnome/src/contacts/calllist.c
index 99da37e44f..9f849048b6 100644
--- a/gnome/src/contacts/calllist.c
+++ b/gnome/src/contacts/calllist.c
@@ -47,7 +47,7 @@ gint is_callID_callstruct(gconstpointer a, gconstpointer b)
 void calllist_add_contact (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo)
 {
     /* Check if the information is valid */
-    if (g_strcasecmp (contact_phone, "empty") == 0)
+    if (!contact_phone)
         return;
 
     callable_obj_t *new_call = create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone);
diff --git a/plugins/addressbook/evolution/addressbook.c b/plugins/addressbook/evolution/addressbook.c
index f9aad74d12..f9ae969f09 100644
--- a/plugins/addressbook/evolution/addressbook.c
+++ b/plugins/addressbook/evolution/addressbook.c
@@ -39,10 +39,10 @@
 void
 addressbook_search (void (*search_cb)(GList *, gpointer), GtkEntry* entry, AddressBook_Config *addressbook_config)
 {
-    const gchar* query = gtk_entry_get_text (GTK_ENTRY (entry));
-    printf("Addressbook: Search %s\n", query);
-
-    search_async_by_contacts (gtk_entry_get_text (GTK_ENTRY (entry)), addressbook_config->max_results, search_cb, addressbook_config);
+    search_async_by_contacts (gtk_entry_get_text(entry), 
+        addressbook_config->max_results,
+        search_cb,
+        addressbook_config);
 }
 
 /**
@@ -69,25 +69,10 @@ addressbook_is_active()
 static void
 addressbook_config_books(gchar **book_list)
 {
-    gchar **config_book_uid;
-    book_data_t *book_data;
-
-    if (book_list == NULL) {
-        printf("Addresbook: Error: Book list is NULL (%s:%d)\n", __FILE__, __LINE__);
-        return;
-    }
-
-    for (config_book_uid = book_list; *config_book_uid; config_book_uid++) {
-
-        // Get corresponding book data
-        book_data = books_get_book_data_by_uid (*config_book_uid);
-
-        // If book_data exists
-        if (book_data == NULL) {
-            printf("Addressbook: Error: Could not open book (%s:%d)\n", __FILE__, __LINE__);
-        } else {
+    for (gchar **book = book_list; book && *book; book++) {
+        book_data_t *book_data = books_get_book_data_by_uid(*book);
+        if (book_data)
             book_data->active = TRUE;
-        }
     }
 }
 
@@ -97,9 +82,6 @@ addressbook_config_books(gchar **book_list)
 GSList *
 addressbook_get_books_data(gchar **book_list)
 {
-    printf("Addressbook: Get books data\n");
-
-    // fill_books_data();
     addressbook_config_books(book_list);
     determine_default_addressbook();
 
@@ -119,8 +101,6 @@ addressbook_get_book_data_by_uid(gchar *uid)
 void
 addressbook_init(gchar **book_list)
 {
-    printf("Addressbook: Initialize addressbook\n");
-
     fill_books_data();
     addressbook_config_books(book_list);
     determine_default_addressbook();
@@ -130,20 +110,16 @@ addressbook_init(gchar **book_list)
 }
 
 void addressbook_set_search_type(AddrbookSearchType searchType) {
-    switch(searchType) {
-    case ABOOK_QUERY_IS:
-	set_current_addressbook_test(E_BOOK_QUERY_IS);
-	break;
-    case ABOOK_QUERY_BEGINS_WITH:
-	set_current_addressbook_test(E_BOOK_QUERY_BEGINS_WITH);
-	break;
-    case ABOOK_QUERY_CONTAINS:
-	set_current_addressbook_test(E_BOOK_QUERY_CONTAINS);
-	break;
-    default:
-	printf("Addressbook: Error: Unsupported search type");
-    	break;
-    }
+    if (searchType > ABOOK_QUERY_CONTAINS)
+        return;
+
+    static const EBookQueryTest map[] = {
+        [ABOOK_QUERY_IS]            = E_BOOK_QUERY_IS,
+        [ABOOK_QUERY_BEGINS_WITH]   = E_BOOK_QUERY_BEGINS_WITH,
+        [ABOOK_QUERY_CONTAINS]      = E_BOOK_QUERY_CONTAINS
+    };
+
+    set_current_addressbook_test(map[searchType]);
 }
 
 void addressbook_set_current_book(gchar *current) {
diff --git a/plugins/addressbook/evolution/addressbook.h b/plugins/addressbook/evolution/addressbook.h
index 5fc3b563b6..f268760cf7 100644
--- a/plugins/addressbook/evolution/addressbook.h
+++ b/plugins/addressbook/evolution/addressbook.h
@@ -40,7 +40,11 @@
 
 #include <gtk/gtk.h>
 
-typedef enum {ABOOK_QUERY_IS, ABOOK_QUERY_BEGINS_WITH, ABOOK_QUERY_CONTAINS} AddrbookSearchType;
+typedef enum {
+    ABOOK_QUERY_IS,
+    ABOOK_QUERY_BEGINS_WITH,
+    ABOOK_QUERY_CONTAINS
+} AddrbookSearchType;
 
 /**
  * Represent a contact entry
diff --git a/plugins/addressbook/evolution/eds.c b/plugins/addressbook/evolution/eds.c
index 8008fda360..ca036ea4d4 100644
--- a/plugins/addressbook/evolution/eds.c
+++ b/plugins/addressbook/evolution/eds.c
@@ -57,20 +57,12 @@ typedef struct _Search_Handler_And_Data {
     EBookQuery *equery;
 } Search_Handler_And_Data;
 
-static void
-authenticate_source (EBook *);
-
 /**
  * The global addressbook list
  */
-GSList *books_data = NULL;
+static GSList *books_data = NULL;
 static GStaticMutex books_data_mutex = G_STATIC_MUTEX_INIT;
 
-/**
- * Size of image that will be displayed in contact list
- */
-static const int pixbuf_size = 32;
-
 /**
  * Current selected addressbook's uri and uid, initialized with default
  */
@@ -80,43 +72,19 @@ static gchar *current_name = "Default";
 
 static EBookQueryTest current_test = E_BOOK_QUERY_BEGINS_WITH;
 
-
-/**
- * Prototypes
- */
-void empty_books_data();
-
-
-/**
- * Free a book data
- */
-void
-free_book_data (book_data_t *data)
-{
-    g_free (data->name);
-    g_free (data->uid);
-    g_free (data->uri);
-}
-
 /**
  * Public way to know if we can perform a search
  */
 gboolean
 books_ready()
 {
-    gboolean returnValue;
-
     g_static_mutex_lock(&books_data_mutex);
 
-    if (books_data == NULL) {
-        g_static_mutex_unlock(&books_data_mutex);
-        return FALSE;
-    }
+    gboolean ret = books_data && g_slist_length (books_data) > 0;
 
-    returnValue = (g_slist_length (books_data) > 0);
     g_static_mutex_unlock(&books_data_mutex);
 
-    return returnValue;
+    return ret ;
 }
 
 /**
@@ -125,32 +93,19 @@ books_ready()
 gboolean
 books_active()
 {
-    GSList *book_list_iterator;
-    book_data_t *book_data;
+    gboolean ret = FALSE;
 
     g_static_mutex_lock(&books_data_mutex);
 
-    if (books_data == NULL) {
-        printf("Addressbook: No books data (%s:%d)\n", __FILE__, __LINE__); 
-        g_static_mutex_unlock(&books_data_mutex);
-        return FALSE;
-    }
-
-    // Iterate throw the list
-    for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator
-            = book_list_iterator->next) {
-        book_data = (book_data_t *) book_list_iterator->data;
-
-        if (book_data->active) {
-            g_static_mutex_unlock(&books_data_mutex);
-            return TRUE;
+    for (GSList *iter = books_data; iter; iter = iter->next)
+        if (((book_data_t *) iter->data)->active) {
+            ret = TRUE;
+            break;
         }
-    }
 
     g_static_mutex_unlock(&books_data_mutex);
 
-    // If no result
-    return FALSE;
+    return ret;
 }
 /**
  * Get a specific book data by UID
@@ -158,36 +113,19 @@ books_active()
 book_data_t *
 books_get_book_data_by_uid (gchar *uid)
 {
-    GSList *book_list_iterator;
-    book_data_t *book_data;
+    book_data_t *ret = NULL;
 
     g_static_mutex_lock(&books_data_mutex);
 
-    if (books_data == NULL) {
-        printf("Addressbook: No books data (%s:%d)\n", __FILE__, __LINE__);
-        g_static_mutex_unlock(&books_data_mutex);
-        return NULL;
-    }
-
-    printf("Addressbook: Get book data by uid: %s\n", uid);
-
-    // Iterate throw the list
-    for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator
-            = book_list_iterator->next) {
-        book_data = (book_data_t *) book_list_iterator->data;
-
-        if (strcmp (book_data->uid, uid) == 0) {
-            printf("Addressbook: Book %s found\n", uid);
-            g_static_mutex_unlock(&books_data_mutex);
-            return book_data;
+    for (GSList *iter = books_data; iter != NULL; iter = iter->next)
+        if (!strcmp (((book_data_t *)iter->data)->uid, uid) ) {
+            ret = iter->data;
+            break;
         }
-    }
 
     g_static_mutex_unlock(&books_data_mutex);
 
-    printf("Addressbook: Could not found Book %s\n", uid);
-    // If no result
-    return NULL;
+    return ret;
 }
 
 
@@ -198,31 +136,21 @@ books_get_book_data_by_uid (gchar *uid)
 static EBookQuery*
 create_query (const char* s, EBookQueryTest test, AddressBook_Config *conf)
 {
-
-    EBookQuery *equery;
     EBookQuery *queries[4];
-
-    // Create the query
     int cpt = 0;
 
-    // We could also use E_BOOK_QUERY_IS or E_BOOK_QUERY_BEGINS_WITH instead of E_BOOK_QUERY_CONTAINS
     queries[cpt++] = e_book_query_field_test (E_CONTACT_FULL_NAME, test, s);
 
-    if (conf->search_phone_home) {
+    if (conf->search_phone_home)
         queries[cpt++] = e_book_query_field_test (E_CONTACT_PHONE_HOME, test, s);
-    }
 
-    if (conf->search_phone_business) {
+    if (conf->search_phone_business)
         queries[cpt++] = e_book_query_field_test (E_CONTACT_PHONE_BUSINESS, test, s);
-    }
 
-    if (conf->search_phone_mobile) {
+    if (conf->search_phone_mobile)
         queries[cpt++] = e_book_query_field_test (E_CONTACT_PHONE_MOBILE, test, s);
-    }
-
-    equery = e_book_query_or (cpt, queries, TRUE);
 
-    return equery;
+    return e_book_query_or (cpt, queries, TRUE);
 }
 
 /**
@@ -231,43 +159,37 @@ create_query (const char* s, EBookQueryTest test, AddressBook_Config *conf)
 static GdkPixbuf*
 pixbuf_from_contact (EContact *contact)
 {
-
     GdkPixbuf *pixbuf = NULL;
     EContactPhoto *photo = e_contact_get (contact, E_CONTACT_PHOTO);
 
-    if (photo) {
-        GdkPixbufLoader *loader;
+    if (!photo)
+        return NULL;
 
-        loader = gdk_pixbuf_loader_new();
+    GdkPixbufLoader *loader;
 
-        if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
-            if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL)) {
-                pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-            }
+    loader = gdk_pixbuf_loader_new();
+
+    if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
+        if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL)) {
+            pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
         }
+    }
 
-        // If pixbuf has been found, check size and resize if needed
-        if (pixbuf) {
-            GdkPixbuf *tmp;
-            gint width = gdk_pixbuf_get_width (pixbuf);
-            gint height = gdk_pixbuf_get_height (pixbuf);
-            double scale = 1.0;
-
-            if (height > width) {
-                scale = pixbuf_size / (double) height;
-            } else {
-                scale = pixbuf_size / (double) width;
-            }
+    e_contact_photo_free (photo);
 
-            if (scale < 1.0) {
-                tmp = gdk_pixbuf_scale_simple (pixbuf, width * scale, height
-                                               * scale, GDK_INTERP_BILINEAR);
-                g_object_unref (pixbuf);
-                pixbuf = tmp;
-            }
-        }
+    if (!pixbuf)
+        return NULL;
 
-        e_contact_photo_free (photo);
+    // check size and resize if needed
+    gint width = gdk_pixbuf_get_width (pixbuf);
+    gint height = gdk_pixbuf_get_height (pixbuf);
+    double scale = 32 / (double) ((height > width) ? height : width);
+
+    if (scale < 1.0) {
+        GdkPixbuf *tmp = gdk_pixbuf_scale_simple (pixbuf, width * scale, height
+                                       * scale, GDK_INTERP_BILINEAR);
+        g_object_unref (pixbuf);
+        pixbuf = tmp;
     }
 
     return pixbuf;
@@ -285,8 +207,6 @@ view_finish_callback (EBookView *book_view, Search_Handler_And_Data *had)
 
     g_free (had);
 
-    printf("Addressbook: View finish, all book have beem processed\n"); 
-
     if (book_view != NULL)
         g_object_unref (book_view);
 
@@ -294,75 +214,47 @@ view_finish_callback (EBookView *book_view, Search_Handler_And_Data *had)
     had_handler (had_hits, had_user_data);
 }
 
-
 /**
  * Callback called after a contact have been found in EDS by search_async_by_contacts.
  */
 #ifdef LIBEDATASERVER_VERSION_2_32
-void
+static void
 eds_query_result_cb (EBook *book, const GError *error, GList *contacts, gpointer user_data)
 {
-    printf("Addressbook: Search Result callback called\n");
-    if (error) {
-        printf("Addressbook: Error: %s\n", error->message);
+    if (error)
         return;
-    }
 #else
 static void
 eds_query_result_cb (EBook *book, EBookStatus status, GList *contacts, gpointer user_data)
 {
-    printf("Addressbook: Search Result callback called\n");
-
-    if (status != E_BOOK_ERROR_OK) {
-        printf("Addressbook: Error: ");
+    if (status != E_BOOK_ERROR_OK)
         return;
-    }
 #endif
 
     Search_Handler_And_Data *had = (Search_Handler_And_Data *) user_data;
 
     if (contacts == NULL) {
-        printf("Addressbook: No contact found\n");
         had->search_handler (NULL, user_data);
         return;
     }
 
-    GList *l = NULL;
-
     // make sure we have a new list of hits
     had->hits = NULL;
 
-    l = contacts;
-
-    while (l) {
-
+    for (GList *l = contacts; l; l = g_list_next (l)) {
         Hit *hit = g_new (Hit, 1);
+        EContact *contact = E_CONTACT(l->data);
 
-        if (hit) {
+        hit->photo = pixbuf_from_contact(contact);
+        hit->phone_business = g_strdup((char*)e_contact_get_const(contact, E_CONTACT_PHONE_BUSINESS));
+        hit->phone_home     = g_strdup((char*)e_contact_get_const(contact, E_CONTACT_PHONE_HOME));
+        hit->phone_mobile   = g_strdup((char*)e_contact_get_const(contact, E_CONTACT_PHONE_MOBILE));
+        hit->name           = g_strdup((char*)e_contact_get_const(contact, E_CONTACT_NAME_OR_ORG));
 
-            // Get the photo contact
-            hit->photo = pixbuf_from_contact (E_CONTACT (l->data));
-            fetch_information_from_contact (E_CONTACT (l->data), E_CONTACT_PHONE_BUSINESS, &hit->phone_business);
-            fetch_information_from_contact (E_CONTACT (l->data), E_CONTACT_PHONE_HOME, &hit->phone_home);
-            fetch_information_from_contact (E_CONTACT (l->data), E_CONTACT_PHONE_MOBILE, &hit->phone_mobile);
-            hit->name = g_strdup ( (char *) e_contact_get_const (E_CONTACT (l->data), E_CONTACT_NAME_OR_ORG));
-
-            if (!hit->name) {
-                hit->name = "";
-            }
-
-            if (hit) {
-                had->hits = g_list_append (had->hits, hit);
-            }
-
-            had->max_results_remaining--;
-            if (had->max_results_remaining <= 0) {
-              break;
-            }
-        }
-
-        l = g_list_next (l);
+        had->hits = g_list_append (had->hits, hit);
 
+        if (--had->max_results_remaining <= 0)
+            break;
     }
 
     view_finish_callback (NULL, had);
@@ -379,52 +271,26 @@ eds_query_result_cb (EBook *book, EBookStatus status, GList *contacts, gpointer
 void
 eds_async_open_callback (EBook *book, const GError *error, gpointer closure)
 {
-    printf("Addressbook: Open book callback\n");
-
-    ESource *source;
-    const gchar *uri;
-
-    if(error) {
-        printf("Addressbook: Error: %s\n", error->message);
+    if(error)
         return;
-    }
 #else
 static void
 eds_async_open_callback (EBook *book, EBookStatus status, gpointer closure)
 {
-    ESource *source;
-    const gchar *uri;
-
-    if(status == E_BOOK_ERROR_OK) {
-        printf("Addressbook: Error\n");
+    if(status == E_BOOK_ERROR_OK)
         return;
-    }
 
 #endif
 
     Search_Handler_And_Data *had = (Search_Handler_And_Data *) closure;
 
-    if (! (source = e_book_get_source (book))) {
-        printf("Addressbook: Error: while getting source\n");
-    }
-
-    if (! (uri = e_book_get_uri (book))) {
-        printf("Addressbook: Error while getting URI\n");
-    }
-
-    authenticate_source (book);
-
-    if (!e_book_is_opened (book)) {
-        // We must open the addressbook
+    if (!e_book_is_opened (book))
         e_book_open (book, FALSE, NULL);
-    }
 
 #ifdef LIBEDATASERVER_VERSION_2_32
-    if (!e_book_get_contacts_async (book, had->equery, eds_query_result_cb, had))
-        printf("Addressbook: Error: While querying addressbook\n");
+    e_book_get_contacts_async (book, had->equery, eds_query_result_cb, had);
 #else
-    if (e_book_async_get_contacts (book, had->equery, eds_query_result_cb, had))
-        printf("Addressbook: Error: While querying addressbook\n");
+    e_book_async_get_contacts (book, had->equery, eds_query_result_cb, had);
 #endif
 
 }
@@ -435,30 +301,10 @@ eds_async_open_callback (EBook *book, EBookStatus status, gpointer closure)
 void
 init_eds ()
 {
-    GSList *book_list_iterator;
-    book_data_t *book_data;
-
-    printf ("Addressbook: Init evolution data server\n");
-
     g_static_mutex_lock(&books_data_mutex);
 
-    if (books_data == NULL) {
-        printf ("Addressbook: No books data (%s:%d)\n", __FILE__, __LINE__);
-        g_static_mutex_unlock(&books_data_mutex);
-        return;
-    }
-
-    // init current with first addressbook if no default addressbook set
-    book_list_iterator = books_data;
-    book_data = (book_data_t *) book_list_iterator->data;
-    current_uri = book_data->uri;
-    current_uid = book_data->uid;
-    current_name = book_data->name;
-
-    // Iterate through list to find default addressbook
-    for (book_list_iterator = books_data; book_list_iterator != NULL;
-            book_list_iterator = book_list_iterator->next) {
-        book_data = (book_data_t *) book_list_iterator->data;
+    for (GSList *iter = books_data; iter != NULL; iter = iter->next) {
+        book_data_t *book_data = (book_data_t *) iter->data;
 
         if (book_data->isdefault) {
             current_uri = book_data->uri;
@@ -467,115 +313,42 @@ init_eds ()
         }
     }
 
-    printf("END EVOLUTION INIT %s, %s, %s\n", current_uri, current_uid, current_name);
-
     g_static_mutex_unlock(&books_data_mutex);
 }
 
-/**
- * Authenticate this addressbook
- */
-static void
-authenticate_source (EBook *book)
-{
-    (void) book; /* unused */
-    /*
-    const gchar *auth_domain;
-    const gchar *password = NULL;
-    const gchar *component_name;
-    const gchar *user = NULL;
-    const gchar *auth;
-    GError *err = NULL;
-    const gchar *uri;
-    ESource *source;
-
-    if ((source = e_book_get_source (book)) == NULL) {
-        DEBUG ("Addressbook: Error while getting source");
-    }
-
-    if ((uri = e_book_get_uri (book)) == NULL) {
-        DEBUG ("Addressbook: Error while getting URI");
-    }
-
-    auth_domain = e_source_get_property (source, "auth-domain");
-
-    auth = e_source_get_property (source, "auth");
-
-    if (auth && !strcmp ("ldap/simple-binddn", auth)) {
-        user = e_source_get_property (source, "binddn");
-    }
-    else if (auth && !strcmp ("plain/password", auth)) {
-        user = e_source_get_property (source, "user");
-
-        if (!user) {
-            user = e_source_get_property (source, "username");
-        }
-    } else {
-        user = e_source_get_property (source, "email_addr");
-    }
-
-    if (!user) {
-        user = "";
-    }
-
-    if (auth) {
-        component_name = auth_domain ? auth_domain : "Addressbook";
-
-        password = e_passwords_get_password (component_name, uri);
-
-        if (e_book_authenticate_user (book, user, password, auth, &err)) {
-            DEBUG ("Addressbook: authentication successfull");
-        }
-        else {
-            ERROR ("Addressbook: authentication error");
-        }
-
-    }
-*/
-}
-
 /**
  * Fill book data
  */
 void
 fill_books_data ()
 {
-    GSList *list, *l;
-    ESourceList *source_list = NULL;
-
-    printf ("Addressbook: Fill books data\n");
-
-    source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources");
+    ESourceList *source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources");
 
-    if (source_list == NULL) {
-        printf ("Addressbook: Error could not initialize source list for addressbook (%s:%d)\n", __FILE__, __LINE__);
+    if (source_list == NULL)
         return;
-    }
 
-    list = e_source_list_peek_groups (source_list);
+    GSList *list = e_source_list_peek_groups (source_list);
 
     if (list == NULL) {
-        printf ("Addressbook: Address Book source groups are missing (%s:%d)! Check your GConf setup.\n", __FILE__, __LINE__);
+        g_object_unref (source_list);
         return;
     }
 
     g_static_mutex_lock(&books_data_mutex);
 
-    if (books_data != NULL) {
-        empty_books_data();
-        books_data = NULL;
-    }
+    for (GSList *iter = books_data; iter != NULL; iter = iter->next) {
+        book_data_t *book_data = (book_data_t *) iter->data;
 
-    for (l = list; l != NULL; l = l->next) {
+        g_free (book_data->name);
+        g_free (book_data->uid);
+        g_free (book_data->uri);
+    }
+    books_data = NULL;
 
+    for (GSList *l = list; l != NULL; l = l->next) {
         ESourceGroup *group = l->data;
-        GSList *sources = NULL, *m;
-        gchar *absuri = g_strdup (e_source_group_peek_base_uri (group));
-
-        sources = e_source_group_peek_sources (group);
-
-        for (m = sources; m != NULL; m = m->next) {
 
+        for (GSList *m = e_source_group_peek_sources (group); m != NULL; m = m->next) {
             ESource *source = m->data;
 
             book_data_t *book_data = g_new (book_data_t, 1);
@@ -583,28 +356,12 @@ fill_books_data ()
             book_data->name = g_strdup (e_source_peek_name (source));
             book_data->uid = g_strdup (e_source_peek_uid (source));
 
-            const gchar *property_name = "default";
-            const gchar *prop = e_source_get_property (source, property_name);
-
-            if (prop) {
-                if (strcmp (prop, "true") == 0) {
-                    book_data->isdefault = TRUE;
-                } else {
-                    book_data->isdefault = FALSE;
-                }
-            } else {
-                book_data->isdefault = FALSE;
-            }
-
-            book_data->uri = g_strjoin ("", absuri, e_source_peek_relative_uri (source), NULL);
-
-            // authenticate_source (book_data, source);
+            const gchar *prop = e_source_get_property (source, "default");
+            book_data->isdefault = (prop && !strcmp(prop, "true"));
+            book_data->uri = g_strconcat(e_source_group_peek_base_uri (group), e_source_peek_relative_uri (source), NULL);
 
             books_data = g_slist_prepend (books_data, book_data);
-
         }
-
-        g_free (absuri);
     }
 
     g_static_mutex_unlock(&books_data_mutex);
@@ -617,73 +374,40 @@ determine_default_addressbook()
 {
     g_static_mutex_lock(&books_data_mutex);
 
-    GSList *list_element = books_data;
     gboolean default_found = FALSE;
 
-    while (list_element && !default_found) {
-        book_data_t *book_data = list_element->data;
+    for (GSList *elm = books_data; elm ; elm = g_slist_next (elm)) {
+        book_data_t *book_data = elm->data;
 
         if (book_data->isdefault) {
-            default_found = TRUE;
             current_uri = book_data->uri;
             current_uid = book_data->uid;
             current_name = book_data->name;
+            default_found = TRUE;
+            break;
         }
-
-        list_element = g_slist_next (list_element);
     }
 
-    // reset loop
-    list_element = books_data;
+    if (!default_found)
+        for (GSList *elm = books_data; elm ; elm = g_slist_next (elm)) {
+            book_data_t *book_data = elm->data;
 
-    while (list_element && !default_found) {
-        book_data_t *book_data = list_element->data;
-
-        if (book_data->active) {
-            default_found = TRUE;
-            book_data->isdefault = TRUE;
-            current_uri = book_data->uri;
-            current_uid = book_data->uid;
-            current_name = book_data->name;
-            printf ("Addressbook: No default addressbook found, using %s addressbook as default\n", book_data->name);
+            if (book_data->active) {
+                book_data->isdefault = TRUE;
+                current_uri = book_data->uri;
+                current_uid = book_data->uid;
+                current_name = book_data->name;
+                break;
+            }
         }
 
-        list_element = g_slist_next (list_element);
-    }
-
     g_static_mutex_unlock(&books_data_mutex);
 }
 
-void
-empty_books_data()
-{
-    GSList *book_list_iterator;
-    book_data_t *book_data;
-
-    if (books_data == NULL) {
-        printf ("Addressbook: No books data (%s:%d)\n", __FILE__, __LINE__);
-        return;
-    }
-
-    // Iterate throw the list
-    for (book_list_iterator = books_data; book_list_iterator != NULL;
-            book_list_iterator = book_list_iterator->next) {
-        book_data = (book_data_t *) book_list_iterator->data;
-
-        free_book_data (book_data);
-    }
-}
-
 void
 search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler handler, gpointer user_data)
 {
-    GError *err = NULL;
-    EBook *book = NULL;
-
-    printf ("Addressbook: New search by contacts: %s, max_results %d\n", query, max_results);
-
-    if (strlen (query) < 1) {
-        printf ("Addressbook: Query is empty\n");
+    if (!*query) {
         handler (NULL, user_data);
         return;
     }
@@ -697,75 +421,27 @@ search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler
     had->max_results_remaining = max_results;
     had->equery = create_query (query, current_test, (AddressBook_Config *) (user_data));
 
-    if (!current_uri) {
-        printf ("Addressbook: Error: Current addressbook uri not specified\n");
-    }
-
-    printf ("Addressbook: Opening addressbook: uri: %s\n", current_uri);
-    printf ("Addressbook: Opening addressbook: name: %s\n", current_name);
-
-    book = e_book_new_from_uri(current_uri, &err);
-
-    if (err) {
-        printf ("Addressbook: Error: Could not open new book: %s\n", err->message);
-    }
-
-    if (book) {
-        printf ("Addressbook: Created empty book successfully\n");
+    EBook *book = e_book_new_from_uri(current_uri, NULL);
+    if (!book)
+        return;
 
 #ifdef LIBEDATASERVER_VERSION_2_32
-        e_book_open_async (book, TRUE, eds_async_open_callback, had);
+    e_book_open_async (book, TRUE, eds_async_open_callback, had);
 #else
-        // Asynchronous open
-        e_book_async_open(book, TRUE, eds_async_open_callback, had);
+    e_book_async_open(book, TRUE, eds_async_open_callback, had);
 #endif
-
-    } else {
-        printf ("Addressbook: Error: No book available\n");
-    }
-
-}
-
-/**
- * Fetch information for a specific contact
- */
-void
-fetch_information_from_contact (EContact *contact, EContactField field, gchar **info)
-{
-    gchar *to_fetch;
-
-    to_fetch = g_strdup ( (char*) e_contact_get_const (contact, field));
-
-    if (!to_fetch) {
-        to_fetch = g_strdup ("empty");
-    }
-
-    *info = g_strdup (to_fetch);
 }
 
 void
 set_current_addressbook (const gchar *name)
 {
-
-    GSList *book_list_iterator;
-    book_data_t *book_data;
-
     if(name == NULL)
         return;
 
     g_static_mutex_lock(&books_data_mutex);
 
-    if (!books_data) {
-        printf ("Addressbook: No books data (%s:%d)\n", __FILE__, __LINE__);
-        g_static_mutex_unlock(&books_data_mutex);
-        return;
-    }
-
-    // Iterate throw the list
-    for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator
-            = book_list_iterator->next) {
-        book_data = (book_data_t *) book_list_iterator->data;
-
+    for (GSList *iter = books_data; iter != NULL; iter = iter->next) {
+        book_data_t *book_data = (book_data_t *) iter->data;
         if (strcmp (book_data->name, name) == 0) {
             current_uri = book_data->uri;
             current_uid = book_data->uid;
@@ -773,31 +449,16 @@ set_current_addressbook (const gchar *name)
         }
     }
 
-    printf("Addressbook: Set current addressbook %s, %s, %s\n", current_uri, current_uid, current_name);
-
     g_static_mutex_unlock(&books_data_mutex);
 }
 
 
-const gchar *
-get_current_addressbook (void)
-{
-    return current_name;
-}
-
-
 void
 set_current_addressbook_test (EBookQueryTest test)
 {
     current_test = test;
 }
 
-EBookQueryTest
-get_current_addressbook_test (void)
-{
-    return current_test;
-}
-
 GSList *
 get_books_data()
 {
diff --git a/plugins/addressbook/evolution/eds.h b/plugins/addressbook/evolution/eds.h
index 8e86a70129..362b653959 100644
--- a/plugins/addressbook/evolution/eds.h
+++ b/plugins/addressbook/evolution/eds.h
@@ -72,13 +72,6 @@ fill_books_data (void);
 void
 search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler handler, gpointer user_data);
 
-/**
- * Retrieve the specified information from the contact
- */
-void
-fetch_information_from_contact (EContact *contact, EContactField field,
-                                gchar **info);
-
 GSList*
 get_books (void);
 
@@ -109,18 +102,9 @@ addressbook_get_books_data();
 void
 set_current_addressbook (const gchar *name);
 
-/**
- * Return current addressbook name
- */
-const gchar *
-get_current_addressbook (void);
-
 void
 set_current_addressbook_test (EBookQueryTest test);
 
-EBookQueryTest
-get_current_addressbook_test (void);
-
 GSList *
 get_books_data();
 
diff --git a/plugins/configure.ac b/plugins/configure.ac
index fdabd36ede..4717c2d61b 100644
--- a/plugins/configure.ac
+++ b/plugins/configure.ac
@@ -21,7 +21,7 @@ else
 	CFLAGS="$CFLAGS -Wall -Wextra"
 fi
 
-AC_PROG_CC
+AC_PROG_CC_C99
 AC_PROG_INSTALL
 AC_HEADER_STDC
 LT_INIT
@@ -32,7 +32,10 @@ AM_GCONF_SOURCE_2
 PKG_CHECK_MODULES(SFLGTK, gtk+-2.0 > 2.2)
 PKG_CHECK_MODULES(SFLGLIB, glib-2.0 >= 2.2)
 PKG_CHECK_MODULES(LIBEBOOK, libebook-1.2 >= 1.4)
-PKG_CHECK_MODULES([LIBEDATASERVER], [libedataserver-1.2 >= 2.32], [AC_DEFINE([LIBEDATASERVER_VERSION_2_32], [], [Using libedataserver-1.2 version 2.32 or higher])],[PKG_CHECK_MODULES([LIBEDATASERVER], [libedataserver-1.2 >= 1.4])])
+PKG_CHECK_MODULES([LIBEDATASERVER], [libedataserver-1.2 >= 2.32],
+        [AC_DEFINE([LIBEDATASERVER_VERSION_2_32], [], [Using libedataserver-1.2 version 2.32 or higher])],
+        [PKG_CHECK_MODULES([LIBEDATASERVER], [libedataserver-1.2 >= 1.4])]
+        )
 
 AC_CONFIG_FILES([
 Makefile 
-- 
GitLab