Skip to content
Snippets Groups Projects
Commit 75d8e108 authored by Julien Bonjean's avatar Julien Bonjean
Browse files

Added some comments

parent db54f70a
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
static void static void
handler_async_search(GList *, gpointer); handler_async_search(GList *, gpointer);
/**
* Perform a search on address book
*/
void void
addressbook_search(GtkEntry* entry) addressbook_search(GtkEntry* entry)
{ {
...@@ -53,8 +56,10 @@ addressbook_init() ...@@ -53,8 +56,10 @@ addressbook_init()
gchar **config_book_uid; gchar **config_book_uid;
book_data_t *book_data; book_data_t *book_data;
// Call books initialization
init(); init();
// Retrieve list of books
list = (gchar **) dbus_get_addressbook_list(); list = (gchar **) dbus_get_addressbook_list();
if (list) if (list)
...@@ -72,6 +77,9 @@ addressbook_init() ...@@ -72,6 +77,9 @@ addressbook_init()
} }
} }
/**
* Callback called after all book have been processed
*/
static void static void
handler_async_search(GList *hits, gpointer user_data) handler_async_search(GList *hits, gpointer user_data)
{ {
...@@ -100,21 +108,21 @@ handler_async_search(GList *hits, gpointer user_data) ...@@ -100,21 +108,21 @@ handler_async_search(GList *hits, gpointer user_data)
entry = i->data; entry = i->data;
if (entry) if (entry)
{ {
/* Get the photo */ // Get the photo
if (addressbook_display(addressbook_config, if (addressbook_display(addressbook_config,
ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)) ADDRESSBOOK_DISPLAY_CONTACT_PHOTO))
photo = entry->photo; photo = entry->photo;
/* Create entry for business phone information */ // Create entry for business phone information
if (addressbook_display(addressbook_config, if (addressbook_display(addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_BUSINESS)) ADDRESSBOOK_DISPLAY_PHONE_BUSINESS))
calllist_add_contact(entry->name, entry->phone_business, calllist_add_contact(entry->name, entry->phone_business,
CONTACT_PHONE_BUSINESS, photo); CONTACT_PHONE_BUSINESS, photo);
/* Create entry for home phone information */ // Create entry for home phone information
if (addressbook_display(addressbook_config, if (addressbook_display(addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_HOME)) ADDRESSBOOK_DISPLAY_PHONE_HOME))
calllist_add_contact(entry->name, entry->phone_home, calllist_add_contact(entry->name, entry->phone_home,
CONTACT_PHONE_HOME, photo); CONTACT_PHONE_HOME, photo);
/* Create entry for mobile phone information */ // Create entry for mobile phone information
if (addressbook_display(addressbook_config, if (addressbook_display(addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_MOBILE)) ADDRESSBOOK_DISPLAY_PHONE_MOBILE))
calllist_add_contact(entry->name, entry->phone_mobile, calllist_add_contact(entry->name, entry->phone_mobile,
...@@ -127,3 +135,4 @@ handler_async_search(GList *hits, gpointer user_data) ...@@ -127,3 +135,4 @@ handler_async_search(GList *hits, gpointer user_data)
// Deactivate waiting image // Deactivate waiting image
deactivateWaitingLayer(); deactivateWaitingLayer();
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <addressbook/eds.h> #include <addressbook/eds.h>
/** /**
* Execute a search in addressbook * Perform a search in addressbook
*/ */
void void
addressbook_search(GtkEntry*); addressbook_search(GtkEntry*);
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#include <pango/pango.h> #include <pango/pango.h>
#include "eds.h" #include "eds.h"
/**
* Structure used to store search and callback data
*/
typedef struct _Handler_And_Data typedef struct _Handler_And_Data
{ {
int search_id; int search_id;
...@@ -40,12 +43,22 @@ typedef struct _Handler_And_Data ...@@ -40,12 +43,22 @@ typedef struct _Handler_And_Data
int book_views_remaining; int book_views_remaining;
} Handler_And_Data; } Handler_And_Data;
/**
* Size of image that will be displayed in contact list
*/
static int pixbuf_size = 32; static int pixbuf_size = 32;
/**
* Fields on which search will be performed
*/
static EContactField search_fields[] = static EContactField search_fields[] =
{ E_CONTACT_FULL_NAME, E_CONTACT_PHONE_BUSINESS, E_CONTACT_NICKNAME, 0 }; { E_CONTACT_FULL_NAME, E_CONTACT_PHONE_BUSINESS, E_CONTACT_NICKNAME, 0 };
static int n_search_fields = G_N_ELEMENTS (search_fields) - 1; static int n_search_fields = G_N_ELEMENTS (search_fields) - 1;
/**
* Freeing a hit instance
*/
void void
free_hit(Hit *h) free_hit(Hit *h)
{ {
...@@ -56,12 +69,16 @@ free_hit(Hit *h) ...@@ -56,12 +69,16 @@ free_hit(Hit *h)
g_free(h); g_free(h);
} }
/**
* Get a specific book data by UID
*/
book_data_t * book_data_t *
books_get_book_data_by_uid(gchar *uid) books_get_book_data_by_uid(gchar *uid)
{ {
GSList *book_list_iterator; GSList *book_list_iterator;
book_data_t *book_data; book_data_t *book_data;
// Iterate throw the list
for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator
= book_list_iterator->next) = book_list_iterator->next)
{ {
...@@ -69,6 +86,8 @@ books_get_book_data_by_uid(gchar *uid) ...@@ -69,6 +86,8 @@ books_get_book_data_by_uid(gchar *uid)
if (strcmp(book_data->uid, uid) == 0) if (strcmp(book_data->uid, uid) == 0)
return book_data; return book_data;
} }
// If no result
return NULL; return NULL;
} }
...@@ -154,6 +173,9 @@ create_query(const char* s) ...@@ -154,6 +173,9 @@ create_query(const char* s)
return query; return query;
} }
/**
* Retrieve the contact's picture
*/
static GdkPixbuf* static GdkPixbuf*
pixbuf_from_contact(EContact *contact) pixbuf_from_contact(EContact *contact)
{ {
...@@ -174,6 +196,7 @@ pixbuf_from_contact(EContact *contact) ...@@ -174,6 +196,7 @@ pixbuf_from_contact(EContact *contact)
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
} }
// If pixbuf has been found, check size and resize if needed
if (pixbuf) if (pixbuf)
{ {
GdkPixbuf *tmp; GdkPixbuf *tmp;
...@@ -312,22 +335,28 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts, ...@@ -312,22 +335,28 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts,
Handler_And_Data *had = (Handler_And_Data *) user_data; Handler_And_Data *had = (Handler_And_Data *) user_data;
// If it's not the last search launched, stop it
if (had->search_id != current_search_id) if (had->search_id != current_search_id)
{ {
e_book_view_stop(book_view); e_book_view_stop(book_view);
return; return;
} }
// If we reached max results
if (had->max_results_remaining <= 0) if (had->max_results_remaining <= 0)
{ {
e_book_view_stop(book_view); e_book_view_stop(book_view);
had->book_views_remaining--; had->book_views_remaining--;
// All books have been computed
if (had->book_views_remaining == 0) if (had->book_views_remaining == 0)
{ {
view_finish(book_view, had); view_finish(book_view, had);
return; return;
} }
} }
// For each contact
for (; contacts != NULL; contacts = g_list_next (contacts)) for (; contacts != NULL; contacts = g_list_next (contacts))
{ {
EContact *contact; EContact *contact;
...@@ -337,19 +366,19 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts, ...@@ -337,19 +366,19 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts,
contact = E_CONTACT (contacts->data); contact = E_CONTACT (contacts->data);
hit = g_new (Hit, 1); hit = g_new (Hit, 1);
/* Get the photo contact */ // Get the photo contact
photo = pixbuf_from_contact(contact); photo = pixbuf_from_contact(contact);
hit->photo = photo; hit->photo = photo;
/* Get business phone information */ // Get business phone information
fetch_information_from_contact(contact, E_CONTACT_PHONE_BUSINESS, &number); fetch_information_from_contact(contact, E_CONTACT_PHONE_BUSINESS, &number);
hit->phone_business = g_strdup(number); hit->phone_business = g_strdup(number);
/* Get home phone information */ // Get home phone information
fetch_information_from_contact(contact, E_CONTACT_PHONE_HOME, &number); fetch_information_from_contact(contact, E_CONTACT_PHONE_HOME, &number);
hit->phone_home = g_strdup(number); hit->phone_home = g_strdup(number);
/* Get mobile phone information */ // Get mobile phone information
fetch_information_from_contact(contact, E_CONTACT_PHONE_MOBILE, &number); fetch_information_from_contact(contact, E_CONTACT_PHONE_MOBILE, &number);
hit->phone_mobile = g_strdup(number); hit->phone_mobile = g_strdup(number);
...@@ -358,8 +387,11 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts, ...@@ -358,8 +387,11 @@ view_contacts_added_cb(EBookView *book_view, GList *contacts,
if (!hit->name) if (!hit->name)
hit->name = ""; hit->name = "";
// Append list of contacts
had->hits = g_list_append(had->hits, hit); had->hits = g_list_append(had->hits, hit);
had->max_results_remaining--; had->max_results_remaining--;
// If we reached max results
if (had->max_results_remaining <= 0) if (had->max_results_remaining <= 0)
{ {
e_book_view_stop(book_view); e_book_view_stop(book_view);
...@@ -383,8 +415,11 @@ gpointer user_data) ...@@ -383,8 +415,11 @@ gpointer user_data)
{ {
Handler_And_Data *had = (Handler_And_Data *) user_data; Handler_And_Data *had = (Handler_And_Data *) user_data;
had->book_views_remaining--; had->book_views_remaining--;
// All books have been prcessed
if (had->book_views_remaining == 0) if (had->book_views_remaining == 0)
{ {
// Call finish function
view_finish(book_view, had); view_finish(book_view, had);
} }
} }
...@@ -413,23 +448,31 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler, ...@@ -413,23 +448,31 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler,
Handler_And_Data *had = g_new (Handler_And_Data, 1); Handler_And_Data *had = g_new (Handler_And_Data, 1);
int search_count = 0; int search_count = 0;
// Initialize search data
had->search_id = current_search_id; had->search_id = current_search_id;
had->handler = handler; had->handler = handler;
had->user_data = user_data; had->user_data = user_data;
had->hits = NULL; had->hits = NULL;
had->max_results_remaining = max_results; had->max_results_remaining = max_results;
had->book_views_remaining = 0; had->book_views_remaining = 0;
// Iterate throw books data
for (iter = books_data; iter != NULL; iter = iter->next) for (iter = books_data; iter != NULL; iter = iter->next)
{ {
book_data_t *book_data = (book_data_t *) iter->data; book_data_t *book_data = (book_data_t *) iter->data;
// If book is active
if (book_data->active) if (book_data->active)
{ {
EBookView *book_view = NULL; EBookView *book_view = NULL;
e_book_get_book_view(book_data->ebook, book_query, NULL, max_results, e_book_get_book_view(book_data->ebook, book_query, NULL, max_results,
&book_view, NULL); &book_view, NULL);
// If book view exists
if (book_view != NULL) if (book_view != NULL)
{ {
// Perform search
had->book_views_remaining++; had->book_views_remaining++;
g_signal_connect (book_view, "contacts_added", (GCallback) view_contacts_added_cb, had); g_signal_connect (book_view, "contacts_added", (GCallback) view_contacts_added_cb, had);
g_signal_connect (book_view, "sequence_complete", (GCallback) view_completed_cb, had); g_signal_connect (book_view, "sequence_complete", (GCallback) view_completed_cb, had);
...@@ -466,3 +509,4 @@ fetch_information_from_contact(EContact *contact, EContactField field, ...@@ -466,3 +509,4 @@ fetch_information_from_contact(EContact *contact, EContactField field,
*info = g_strdup(to_fetch); *info = g_strdup(to_fetch);
} }
...@@ -36,10 +36,14 @@ ...@@ -36,10 +36,14 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* Current search id used to prevent processing
* of previous search
*/
int current_search_id; int current_search_id;
/** /**
* Reprsent a contact entry * Represent a contact entry
*/ */
typedef struct _Hit typedef struct _Hit
{ {
...@@ -105,3 +109,4 @@ books_get_book_data_by_uid(gchar *uid); ...@@ -105,3 +109,4 @@ books_get_book_data_by_uid(gchar *uid);
G_END_DECLS G_END_DECLS
#endif /* __EDS_H__ */ #endif /* __EDS_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment