diff --git a/sflphone-gtk/src/config/addressbook-config.c b/sflphone-gtk/src/config/addressbook-config.c index fd6468af0bbc8bccb67fe0b18947566445037efd..d1b71d1bb9aace01576e89e838d82a34bb383af1 100644 --- a/sflphone-gtk/src/config/addressbook-config.c +++ b/sflphone-gtk/src/config/addressbook-config.c @@ -215,6 +215,7 @@ addressbook_config_fill_book_list() GSList *book_list_iterator; GtkListStore *store; book_data_t *book_data; + GSList *books_data = addressbook_get_books_data(); // Get model of view and clear it store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(book_tree_view))); diff --git a/sflphone-gtk/src/contacts/addressbook.c b/sflphone-gtk/src/contacts/addressbook.c index aa5e2acb56494d3c39f1f19a5150dae688d18a14..dfb71109cbb2f8da8f455cfef69ec50c3e4d06d3 100644 --- a/sflphone-gtk/src/contacts/addressbook.c +++ b/sflphone-gtk/src/contacts/addressbook.c @@ -46,18 +46,15 @@ addressbook_search(GtkEntry* entry) } /** - * Initialize books. - * Set active/inactive status depending on config. + * Asynchronous open callback. + * Used to handle activation of books. */ -void -addressbook_init() +static void +addressbook_config_books() { - gchar **list; gchar **config_book_uid; book_data_t *book_data; - - // Call books initialization - init(); + gchar **list; // Retrieve list of books list = (gchar **) dbus_get_addressbook_list(); @@ -70,13 +67,37 @@ addressbook_init() book_data = books_get_book_data_by_uid(*config_book_uid); // If book_data exists - if(book_data != NULL) - book_data->active = TRUE; + if (book_data != NULL) + { + printf("activating %s\n", *config_book_uid); + book_data->active = TRUE; + } } g_strfreev(list); } } +/** + * Good method to get books_data + */ +GSList * +addressbook_get_books_data() +{ + addressbook_config_books(); + return books_data; +} + +/** + * Initialize books. + * Set active/inactive status depending on config. + */ +void +addressbook_init() +{ + // Call books initialization + init(&addressbook_config_books); +} + /** * Callback called after all book have been processed */ diff --git a/sflphone-gtk/src/contacts/addressbook/eds.c b/sflphone-gtk/src/contacts/addressbook/eds.c index 45551f94550330285b4bae97a9b8e472fcf457a2..cb212e8630771a6416895061550d32c419102a2a 100644 --- a/sflphone-gtk/src/contacts/addressbook/eds.c +++ b/sflphone-gtk/src/contacts/addressbook/eds.c @@ -31,9 +31,9 @@ #include "eds.h" /** - * Structure used to store search and callback data + * Structure used to store search callback and data */ -typedef struct _Handler_And_Data +typedef struct _Search_Handler_And_Data { int search_id; SearchAsyncHandler handler; @@ -41,7 +41,15 @@ typedef struct _Handler_And_Data GList *hits; int max_results_remaining; int book_views_remaining; -} Handler_And_Data; +} Search_Handler_And_Data; + +/** + * Structure used to store open callback and data + */ +typedef struct _Open_Handler_And_Data +{ + OpenAsyncHandler handler; +} Open_Handler_And_Data; /** * Size of image that will be displayed in contact list @@ -244,15 +252,14 @@ pixbuf_from_contact(EContact *contact) * Callback for asynchronous open of books */ static void -eds_async_open_callback(EBook *book, EBookStatus status, gpointer closure UNUSED) +eds_async_open_callback(EBook *book, EBookStatus status, gpointer closure) { + Open_Handler_And_Data *had = (Open_Handler_And_Data *) closure; + remaining_books_to_open--; printf("async open !\n"); - //ContactsData *data = closure; - //EBookQuery *query; - if (status == E_BOOK_ERROR_OK) { book_data_t *book_data = g_new(book_data_t, 1); @@ -261,6 +268,7 @@ eds_async_open_callback(EBook *book, EBookStatus status, gpointer closure UNUSED book_data->uid = g_strdup(e_source_peek_uid(e_book_get_source(book))); book_data->ebook = book; books_data = g_slist_prepend(books_data, book_data); + had->handler(); } else { @@ -272,7 +280,7 @@ eds_async_open_callback(EBook *book, EBookStatus status, gpointer closure UNUSED * Initialize address book */ void -init(void) +init(OpenAsyncHandler callback) { GSList *list, *l; ESourceList *source_list; @@ -288,6 +296,9 @@ init(void) list = e_source_list_peek_groups(source_list); + Open_Handler_And_Data *had = g_new (Open_Handler_And_Data, 1); + had->handler = callback; + for (l = list; l != NULL; l = l->next) { ESourceGroup *group = l->data; @@ -303,7 +314,7 @@ init(void) remaining_books_to_open++; // Asynchronous open - e_book_async_open(book, TRUE, eds_async_open_callback, NULL); + e_book_async_open(book, TRUE, eds_async_open_callback, had); } } } @@ -316,7 +327,7 @@ init(void) * Final callback after all books have been processed. */ static void -view_finish(EBookView *book_view, Handler_And_Data *had) +view_finish(EBookView *book_view, Search_Handler_And_Data *had) { GList *i; SearchAsyncHandler had_handler = had->handler; @@ -360,7 +371,7 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts, { GdkPixbuf *photo; - Handler_And_Data *had = (Handler_And_Data *) user_data; + Search_Handler_And_Data *had = (Search_Handler_And_Data *) user_data; // If it's not the last search launched, stop it if (had->search_id != current_search_id) @@ -440,7 +451,7 @@ static void view_completed_cb(EBookView *book_view, EBookViewStatus status UNUSED, gpointer user_data) { - Handler_And_Data *had = (Handler_And_Data *) user_data; + Search_Handler_And_Data *had = (Search_Handler_And_Data *) user_data; had->book_views_remaining--; // All books have been prcessed @@ -472,7 +483,7 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler, GSList *iter; EBookQuery* book_query = create_query(query); - Handler_And_Data *had = g_new (Handler_And_Data, 1); + Search_Handler_And_Data *had = g_new (Search_Handler_And_Data, 1); int search_count = 0; // Initialize search data diff --git a/sflphone-gtk/src/contacts/addressbook/eds.h b/sflphone-gtk/src/contacts/addressbook/eds.h index e6d5f0497cf45b110bef1af2d71a3553c6e99eb3..7248c2c3a0f481b21e053b0810910904d37843c3 100644 --- a/sflphone-gtk/src/contacts/addressbook/eds.h +++ b/sflphone-gtk/src/contacts/addressbook/eds.h @@ -79,12 +79,18 @@ free_hit(Hit *h); typedef void (* SearchAsyncHandler)(GList *hits, gpointer user_data); +/** + * Template callback function for the asynchronous open + */ +typedef void +(* OpenAsyncHandler)(); + /** * Initialize the address book. * Connection to evolution data server */ void -init(void); +init(OpenAsyncHandler); /** * Asynchronous search function @@ -112,6 +118,12 @@ books_get_book_data_by_uid(gchar *uid); gboolean books_ready(); +/** + * Good method to retrieve books_data (handle async) + */ +GSList * +addressbook_get_books_data(); + G_END_DECLS #endif /* __EDS_H__ */