Commit a199a0a3 authored by Julien Bonjean's avatar Julien Bonjean

Improved async open books

parent ce708923
......@@ -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)));
......
......@@ -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
*/
......
......@@ -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
......
......@@ -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__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment