Skip to content
Snippets Groups Projects
Commit fd7b1329 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Use max_results info, clean up

parent 314f4084
No related branches found
No related tags found
No related merge requests found
...@@ -113,7 +113,7 @@ GtkWidget* create_addressbook_settings () { ...@@ -113,7 +113,7 @@ GtkWidget* create_addressbook_settings () {
// SCALE BUTTON - NUMBER OF RESULTS // SCALE BUTTON - NUMBER OF RESULTS
label = gtk_label_new (_("Maximum result number for a request: ")); label = gtk_label_new (_("Maximum result number for a request: "));
gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1); gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1);
value = gtk_hscale_new_with_range (0.0 , 50.0 , 5.0); value = gtk_hscale_new_with_range (25.0 , 50.0 , 5.0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), value); gtk_label_set_mnemonic_widget (GTK_LABEL (label), value);
gtk_scale_set_digits (GTK_SCALE(value) , 0); gtk_scale_set_digits (GTK_SCALE(value) , 0);
gtk_scale_set_value_pos (GTK_SCALE(value) , GTK_POS_RIGHT); gtk_scale_set_value_pos (GTK_SCALE(value) , GTK_POS_RIGHT);
......
...@@ -191,60 +191,6 @@ init (void) ...@@ -191,60 +191,6 @@ init (void)
g_object_unref (source_list); g_object_unref (source_list);
} }
/**
* Do a synchronized search in EDS address book
*/
GList *
search_sync (const char *query,
int max_results)
{
GSList *iter = NULL;
GList *contacts = NULL;
GList *hits = NULL;
EBookQuery* book_query = create_query (query);
for (iter = books; iter != NULL; iter = iter->next) {
if (max_results <= 0) {
break;
}
EBook *book = (EBook *) iter->data;
e_book_get_contacts (book, book_query, &contacts, NULL);
for (; contacts != NULL; contacts = g_list_next (contacts)) {
EContact *contact;
Hit *hit;
gchar *number;
contact = E_CONTACT (contacts->data);
hit = g_new0 (Hit, 1);
/* Get business phone information */
fetch_information_from_contact (contact, E_CONTACT_PHONE_BUSINESS, &number);
hit->phone_business = g_strdup (number);
/* Get home phone information */
fetch_information_from_contact (contact, E_CONTACT_PHONE_HOME, &number);
hit->phone_home = g_strdup (number);
/* Get mobile phone information */
fetch_information_from_contact (contact, E_CONTACT_PHONE_MOBILE, &number);
hit->phone_mobile = g_strdup (number);
hit->name = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG));
if(! hit->name)
hit->name = "";
hits = g_list_append (hits, hit);
max_results--;
if (max_results <= 0) {
break;
}
}
}
e_book_query_unref (book_query);
return hits;
}
static void static void
view_finish (EBookView *book_view, Handler_And_Data *had) view_finish (EBookView *book_view, Handler_And_Data *had)
{ {
......
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* Reprsent a contact entry
*/
typedef struct _Hit typedef struct _Hit
{ {
gchar *name; gchar *name;
...@@ -44,19 +47,33 @@ typedef struct _Hit ...@@ -44,19 +47,33 @@ typedef struct _Hit
gchar *phone_mobile; gchar *phone_mobile;
} Hit; } Hit;
/**
* Free a contact entry
*/
void free_hit (Hit *h); void free_hit (Hit *h);
/**
* Template callback function for the asynchronous search
*/
typedef void (* SearchAsyncHandler) (GList *hits, gpointer user_data); typedef void (* SearchAsyncHandler) (GList *hits, gpointer user_data);
/**
* Initialize the address book.
* Connection to evolution data server
*/
void init (void); void init (void);
/**
* Asynchronous search function
*/
void search_async (const char *query, void search_async (const char *query,
int max_results, int max_results,
SearchAsyncHandler handler, SearchAsyncHandler handler,
gpointer user_data); gpointer user_data);
GList * search_sync (const char *query, int max_results); /**
* Retrieve the specified information from the contact
*/
void fetch_information_from_contact (EContact *contact, EContactField field, gchar **info); void fetch_information_from_contact (EContact *contact, EContactField field, gchar **info);
G_END_DECLS G_END_DECLS
......
...@@ -1454,7 +1454,7 @@ GHashTable* dbus_get_addressbook_settings (void) { ...@@ -1454,7 +1454,7 @@ GHashTable* dbus_get_addressbook_settings (void) {
GError *error = NULL; GError *error = NULL;
GHashTable *results = NULL; GHashTable *results = NULL;
g_print ("Calling org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n"); //g_print ("Calling org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n");
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings (configurationManagerProxy, &results, &error); org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings (configurationManagerProxy, &results, &error);
if (error){ if (error){
...@@ -1462,8 +1462,6 @@ GHashTable* dbus_get_addressbook_settings (void) { ...@@ -1462,8 +1462,6 @@ GHashTable* dbus_get_addressbook_settings (void) {
g_error_free (error); g_error_free (error);
} }
g_print ("Called org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n");
return results; return results;
} }
......
...@@ -61,22 +61,22 @@ gboolean is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSE ...@@ -61,22 +61,22 @@ gboolean is_visible (GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSE
} }
static void handler_async_search (GList *hits, gpointer user_data UNUSED) { static void handler_async_search (GList *hits, gpointer user_data) {
GList *i; GList *i;
GdkPixbuf *photo = NULL; GdkPixbuf *photo = NULL;
AddressBook_Config *addressbook_config; AddressBook_Config *addressbook_config;
call_t *j; call_t *j;
// Load the parameters
addressbook_load_parameters (&addressbook_config);
// freeing calls // freeing calls
while((j = (call_t *)g_queue_pop_tail (contacts->callQueue)) != NULL) while((j = (call_t *)g_queue_pop_tail (contacts->callQueue)) != NULL)
{ {
free_call_t(j); free_call_t(j);
} }
// Retrieve the address book parameters
addressbook_config = (AddressBook_Config*) user_data;
// reset previous results // reset previous results
reset_call_tree(contacts); reset_call_tree(contacts);
call_list_reset(contacts); call_list_reset(contacts);
...@@ -108,11 +108,20 @@ static void handler_async_search (GList *hits, gpointer user_data UNUSED) { ...@@ -108,11 +108,20 @@ static void handler_async_search (GList *hits, gpointer user_data UNUSED) {
void filter_entry_changed (GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpointer data UNUSED) { void filter_entry_changed (GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpointer data UNUSED) {
AddressBook_Config *addressbook_config;
/* Switch to the address book when the focus is on the search bar */
if (active_calltree == current_calls) if (active_calltree == current_calls)
display_calltree (contacts); display_calltree (contacts);
if (active_calltree == contacts)
search_async (gtk_entry_get_text (GTK_ENTRY (filter_entry)), 50, &handler_async_search, NULL); /* We want to search in the contact list */
if (active_calltree == contacts) {
// Load the address book parameters
addressbook_load_parameters (&addressbook_config);
// Start the asynchronous search as soon as we have an entry */
search_async (gtk_entry_get_text (GTK_ENTRY (filter_entry)), addressbook_config->max_results, &handler_async_search, addressbook_config);
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment