Commit ce708923 authored by Julien Bonjean's avatar Julien Bonjean

Added support for asynchornous books open (first shot)

parent 30f489aa
......@@ -232,7 +232,6 @@ addressbook_config_fill_book_list()
}
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(book_tree_view)));
}
GtkWidget*
......
......@@ -48,6 +48,11 @@ typedef struct _Handler_And_Data
*/
static int pixbuf_size = 32;
/**
* Remaining books to open (asynchronous)
*/
int remaining_books_to_open;
/**
* Fields on which search will be performed
*/
......@@ -69,6 +74,15 @@ free_hit(Hit *h)
g_free(h);
}
/**
* Public way to know if we can perform a search
*/
gboolean
books_ready()
{
return (g_slist_length(books_data) == 0);
}
/**
* Get a specific book data by UID
*/
......@@ -124,10 +138,10 @@ split_query_string(const gchar *str)
return parts;
}
/**
* Create a query which looks for the specified string in a contact's full name, email addresses and
* nick name.
*/
/**
* Create a query which looks for the specified string in a contact's full name, email addresses and
* nick name.
*/
static EBookQuery*
create_query(const char* s)
{
......@@ -226,6 +240,34 @@ pixbuf_from_contact(EContact *contact)
return pixbuf;
}
/**
* Callback for asynchronous open of books
*/
static void
eds_async_open_callback(EBook *book, EBookStatus status, gpointer closure UNUSED)
{
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);
book_data->active = FALSE;
book_data->name = g_strdup(e_source_peek_name(e_book_get_source(book)));
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);
}
else
{
g_warning("Got error %d when opening book", status);
}
}
/**
* Initialize address book
*/
......@@ -234,15 +276,16 @@ init(void)
{
GSList *list, *l;
ESourceList *source_list;
book_data_t *book_data;
remaining_books_to_open = 0;
books_data = NULL;
source_list = e_source_list_new_for_gconf_default(
"/apps/evolution/addressbook/sources");
if (source_list == NULL)
{
return;
}
list = e_source_list_peek_groups(source_list);
for (l = list; l != NULL; l = l->next)
......@@ -256,27 +299,11 @@ init(void)
EBook *book = e_book_new(source, NULL);
if (book != NULL)
{
GError *error = NULL;
e_book_open(book, TRUE, &error);
// If we cannot open the book
if (error)
{
g_printerr("Cannot open address book: %s\n",
e_source_peek_name(source));
g_object_unref(book);
}
// Everything OK, we load ebook
else
{
book_data = g_new(book_data_t, 1);
book_data->active = FALSE;
book_data->name = g_strdup(e_source_peek_name(source));
book_data->uid = g_strdup(e_source_peek_uid(source));
book_data->ebook = book;
books_data = g_slist_prepend(books_data, book_data);
}
// Keep count of remaining books to open
remaining_books_to_open++;
// Asynchronous open
e_book_async_open(book, TRUE, eds_async_open_callback, NULL);
}
}
}
......@@ -435,7 +462,7 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler,
current_search_id++;
// If query is null
if (strlen(query) < 1)
if (strlen(query) < 1 || g_slist_length(books_data) == 0)
{
// If data displayed (from previous search), directly call callback
handler(NULL, user_data);
......@@ -471,7 +498,6 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler,
// If book view exists
if (book_view != NULL)
{
// Perform search
had->book_views_remaining++;
g_signal_connect (book_view, "contacts_added", (GCallback) view_contacts_added_cb, had);
......
......@@ -106,7 +106,12 @@ get_books(void);
book_data_t *
books_get_book_data_by_uid(gchar *uid);
/**
* Public way to know if we can perform a search
*/
gboolean
books_ready();
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