diff --git a/sflphone-client-gnome/src/contacts/addressbook.c b/sflphone-client-gnome/src/contacts/addressbook.c index 5a8c3b999d5e7b170b8cfcc2d4ec0c4cf0f0a94f..b1cf61e067b1d2e3b6d92dd852fbb5c9d652dc3d 100644 --- a/sflphone-client-gnome/src/contacts/addressbook.c +++ b/sflphone-client-gnome/src/contacts/addressbook.c @@ -146,12 +146,14 @@ addressbook_init() { DEBUG ("Addressbook: Initialize addressbook"); + init_eds_mutex(); + fill_books_data(); addressbook_config_books(); determine_default_addressbook(); // Call books initialization - init (); + init_eds(); } /** diff --git a/sflphone-client-gnome/src/contacts/addressbook/eds.c b/sflphone-client-gnome/src/contacts/addressbook/eds.c index 616460e50ba8282c5207d15bfc34ba844f14b31a..fc965d85bb01b78d0a6c54c44b1ffb369bc92a23 100644 --- a/sflphone-client-gnome/src/contacts/addressbook/eds.c +++ b/sflphone-client-gnome/src/contacts/addressbook/eds.c @@ -62,6 +62,7 @@ authenticate_source (EBook *); * The global addressbook list */ GSList *books_data = NULL; +GMutex *books_data_mutex = NULL; /** * Size of image that will be displayed in contact list @@ -114,10 +115,19 @@ free_book_data (book_data_t *data) gboolean books_ready() { - if (books_data == NULL) - return 0; + gboolean returnValue; - return (g_slist_length (books_data) > 0); + g_mutex_lock(books_data_mutex); + + if (books_data == NULL) { + g_mutex_unlock(books_data_mutex); + return FALSE; + } + + returnValue = (g_slist_length (books_data) > 0); + g_mutex_unlock(books_data_mutex); + + return returnValue; } /** @@ -129,8 +139,11 @@ books_active() GSList *book_list_iterator; book_data_t *book_data; + g_mutex_lock(books_data_mutex); + if (books_data == NULL) { DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__); + g_mutex_unlock(books_data_mutex); return FALSE; } @@ -139,10 +152,14 @@ books_active() = book_list_iterator->next) { book_data = (book_data_t *) book_list_iterator->data; - if (book_data->active) + if (book_data->active) { + g_mutex_unlock(books_data_mutex); return TRUE; + } } + g_mutex_unlock(books_data_mutex); + // If no result return FALSE; } @@ -155,8 +172,11 @@ books_get_book_data_by_uid (gchar *uid) GSList *book_list_iterator; book_data_t *book_data; + g_mutex_lock(books_data_mutex); + if (books_data == NULL) { DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__); + g_mutex_unlock(books_data_mutex); return NULL; } @@ -169,10 +189,13 @@ books_get_book_data_by_uid (gchar *uid) if (strcmp (book_data->uid, uid) == 0) { DEBUG ("Addressbook: Book %s found", uid); + g_mutex_unlock(books_data_mutex); return book_data; } } + g_mutex_unlock(books_data_mutex); + DEBUG ("Addressbook: Could not found Book %s", uid); // If no result return NULL; @@ -392,19 +415,29 @@ eds_async_open_callback (EBook *book, const GError *error, gpointer closure) * Initialize address book */ void -init () +init_eds () { GSList *book_list_iterator; book_data_t *book_data; - DEBUG ("Addressbook: Init default addressbook"); + DEBUG ("Addressbook: Init evolution data server"); + + g_mutex_lock(books_data_mutex); if (books_data == NULL) { DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__); + g_mutex_unlock(books_data_mutex); return; } - // Iterate throw the list + // 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; @@ -415,6 +448,16 @@ init () current_name = book_data->name; } } + + DEBUG("END EVOLUTION %s, %s, %s", current_uri, current_uid, current_name); + + g_mutex_unlock(books_data_mutex); +} + +void +init_eds_mutex() { + + books_data_mutex = g_mutex_new(); } /** @@ -490,22 +533,25 @@ fill_books_data () source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources"); if (source_list == NULL) { - DEBUG ("Addressbook: Error could not initialize source list for addressbook (%s:%d)", __FILE__, __LINE__); + ERROR ("Addressbook: Error could not initialize source list for addressbook (%s:%d)", __FILE__, __LINE__); return; } list = e_source_list_peek_groups (source_list); - if (!list) { - DEBUG ("Addressbook: Address Book source groups are missing (%s:%d)! Check your GConf setup.", __FILE__, __LINE__); + if (list == NULL) { + ERROR ("Addressbook: Address Book source groups are missing (%s:%d)! Check your GConf setup.", __FILE__, __LINE__); return; } + g_mutex_lock(books_data_mutex); + if (books_data != NULL) { empty_books_data(); books_data = NULL; } + // in case default property is not set for any addressbook default_found = FALSE; @@ -515,8 +561,6 @@ fill_books_data () GSList *sources = NULL, *m; gchar *absuri = g_strdup (e_source_group_peek_base_uri (group)); - DEBUG("ADDRESSBOOK: GROUP: %s", absuri); - sources = e_source_group_peek_sources (group); for (m = sources; m != NULL; m = m->next) { @@ -528,9 +572,6 @@ fill_books_data () book_data->name = g_strdup (e_source_peek_name (source)); book_data->uid = g_strdup (e_source_peek_uid (source)); - DEBUG("ADDRESSBOOK: NAME: %s", book_data->name); - DEBUG("ADDRESSBOOK: UID: %s", book_data->uid); - const gchar *property_name = "default"; const gchar *prop = e_source_get_property (source, property_name); @@ -545,12 +586,8 @@ fill_books_data () book_data->isdefault = FALSE; } - DEBUG("ADDRESSBOOK: absolute: %s", absuri); - DEBUG("ADDRESSBOOK: relative: %s", e_source_peek_relative_uri (source)); book_data->uri = g_strjoin ("", absuri, e_source_peek_relative_uri (source), NULL); - DEBUG("ADDRESSBOOK: URI: %s", book_data->uri); - book_data->source = e_source_copy(source); // authenticate_source (book_data, source); books_data = g_slist_prepend (books_data, book_data); @@ -560,12 +597,16 @@ fill_books_data () g_free (absuri); } + g_mutex_unlock(books_data_mutex); + g_object_unref (source_list); } void determine_default_addressbook() { + g_mutex_lock(books_data_mutex); + GSList *list_element = books_data; gboolean default_found = FALSE; @@ -592,6 +633,8 @@ determine_default_addressbook() list_element = g_slist_next (list_element); } + + g_mutex_unlock(books_data_mutex); } void @@ -646,11 +689,6 @@ search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler DEBUG ("Addressbook: Opening addressbook: uri: %s", current_uri); DEBUG ("Addressbook: Opening addressbook: name: %s", current_name); - -// ESource *source = e_source_new_with_absolute_uri(current_name, current_uri); -// -// book = e_book_new(source, &err); - book = e_book_new_from_uri(current_uri, &err); if (err) { @@ -692,8 +730,11 @@ set_current_addressbook (const gchar *name) GSList *book_list_iterator; book_data_t *book_data; + g_mutex_lock(books_data_mutex); + if (!books_data) { DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__); + g_mutex_unlock(books_data_mutex); return; } @@ -709,6 +750,8 @@ set_current_addressbook (const gchar *name) current_book = book_data; } } + + g_mutex_unlock(books_data_mutex); } diff --git a/sflphone-client-gnome/src/contacts/addressbook/eds.h b/sflphone-client-gnome/src/contacts/addressbook/eds.h index f82de597fe40af4ccb693ba97a5ebd245e107b47..73f033852d8466a94753ede9f8eae505d197b44a 100644 --- a/sflphone-client-gnome/src/contacts/addressbook/eds.h +++ b/sflphone-client-gnome/src/contacts/addressbook/eds.h @@ -72,7 +72,6 @@ typedef struct { gchar *uid; gchar *uri; gchar *name; - ESource *source; gboolean active; gboolean isdefault; } book_data_t; @@ -101,7 +100,14 @@ typedef void * Connection to evolution data server */ void -init (); +init_eds (); + +/** + * We need to initialize multi-threading capabilities + * due to asynchronous callbacks + */ +void +init_eds_mutex(void); /** * Fill list of addressbooks diff --git a/sflphone-client-gnome/src/contacts/searchbar.c b/sflphone-client-gnome/src/contacts/searchbar.c index 86a629fa42f3fabcf283edd0e5dfe44310871cc8..afa69670c891cf727650449d32f3a73d7627d340 100644 --- a/sflphone-client-gnome/src/contacts/searchbar.c +++ b/sflphone-client-gnome/src/contacts/searchbar.c @@ -284,11 +284,18 @@ focus_on_searchbar_in() void searchbar_init (calltab_t *tab) { if (g_strcasecmp (tab->_name, CONTACTS) == 0) { - addressbook_init(); - } else if (g_strcasecmp (tab->_name, HISTORY) == 0) { + } + else if (g_strcasecmp (tab->_name, HISTORY) == 0) { history_init(); - } else + } + else { ERROR ("searchbar.c - searchbar_init should not happen within this widget\n"); + } +} + +void addressbook_searchbar_update() +{ + } GtkWidget* history_searchbar_new (void) @@ -383,6 +390,7 @@ GtkWidget* contacts_searchbar_new () liststore = gtk_list_store_new (1,G_TYPE_STRING); // Create combo box to select current addressbook + addressbook_init(); GSList *book_list_iterator; book_data_t *book_data;