Commit fa567d31 authored by Alexandre Savard's avatar Alexandre Savard

#5979: Implement codec full addressbook search from plugin

parent 8d745116
......@@ -67,8 +67,8 @@ addressbook_config_load_parameters (AddressBook_Config **settings)
_settings->search_phone_business = 1;
_settings->search_phone_home = 1;
_settings->search_phone_mobile = 1;
} else {
}
else {
_settings->enable = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_ENABLE));
_settings->max_results = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_MAX_RESULTS));
_settings->display_contact_photo = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO));
......@@ -207,6 +207,7 @@ addressbook_config_book_active_toggled (
GtkTreePath *treePath;
GtkTreeModel *model;
gboolean active;
book_data_t *book_data;
gchar* name;
gchar* uid;
......@@ -239,10 +240,20 @@ addressbook_config_book_active_toggled (
gtk_tree_path_free (treePath);
// Update current memory stored books data
// factory->addrbook->get_book_data_by_uid (uid)->active = active;
book_data = factory->addrbook->get_book_data_by_uid(uid);
if(book_data == NULL) {
ERROR("Addressbook: Error: Could not find addressbook %s", uid);
}
book_data->active = active;
// Save data
if(active) {
DEBUG("-------------------------------------------- SET ADDRESSBOOK %s AS ACTIVE", book_data->name);
}
else {
DEBUG("-------------------------------------------- SET ADDRESSBOOK %s AS INACTIVE", book_data->name);
}
// Save data
gboolean valid;
// Initiate double array char list for one string
......@@ -286,6 +297,7 @@ addressbook_config_fill_book_list()
GSList *book_list_iterator;
GtkListStore *store;
book_data_t *book_data;
gchar **book_list;
if(!abookfactory_is_addressbook_loaded()) {
return;
......@@ -293,7 +305,8 @@ addressbook_config_fill_book_list()
AddrBookFactory *factory = abookfactory_get_factory();
GSList *books_data = factory->addrbook->get_books_data();
book_list = dbus_get_addressbook_list();
GSList *books_data = factory->addrbook->get_books_data(book_list);
if (!books_data) {
DEBUG ("Addressbook: No valid books data (%s:%d)", __FILE__, __LINE__);
......@@ -312,6 +325,7 @@ addressbook_config_fill_book_list()
= book_list_iterator->next) {
book_data = (book_data_t *) book_list_iterator->data;
gtk_list_store_append (store, &list_store_iterator);
DEBUG("-----------------------------------: %s, %s", book_data->name, book_data->active ? "active" : "not-active");
gtk_list_store_set (store, &list_store_iterator, COLUMN_BOOK_ACTIVE,
book_data->active, COLUMN_BOOK_UID, book_data->uid, COLUMN_BOOK_NAME,
book_data->name, -1);
......
......@@ -34,6 +34,7 @@
#include <gtk/gtk.h>
#include <glib/gtypes.h>
#include "addressbook.h"
#include "actions.h"
#include "utils.h"
......@@ -45,7 +46,7 @@ G_BEGIN_DECLS
#define ADDRESSBOOK_DISPLAY_PHONE_BUSINESS "ADDRESSBOOK_DISPLAY_PHONE_BUSINESS"
#define ADDRESSBOOK_DISPLAY_PHONE_HOME "ADDRESSBOOK_DISPLAY_PHONE_HOME"
#define ADDRESSBOOK_DISPLAY_PHONE_MOBILE "ADDRESSBOOK_DISPLAY_PHONE_MOBILE"
/*
typedef struct _AddressBook_Config {
// gint64: a signed integer guaranteed to be 64 bits on all platforms
// To print or scan values of this type, use G_GINT64_MODIFIER and/or G_GINT64_FORMAT
......@@ -56,6 +57,8 @@ typedef struct _AddressBook_Config {
gint search_phone_business;
gint search_phone_mobile;
} AddressBook_Config;
*/
/**
* Save the parameters through D-BUS
......
......@@ -4,6 +4,7 @@
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
......@@ -29,10 +29,14 @@
*/
#include "addrbookfactory.h"
#include "addressbook-config.h"
#include <glib.h>
#include <dlfcn.h>
static void handler_async_search(GList *hits, gpointer user_data);
AddrBookFactory addressbookFactory = {NULL};
AddrBookFactory *abookfactory_get_factory(void) {
......@@ -111,6 +115,86 @@ void abookfactory_load_module(AddrBookFactory *factory) {
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_set_search_type");
}
ab->search_cb = handler_async_search;
DEBUG("AddressbookFactory: Loading done");
factory->addrbook = ab;
}
void
free_hit (Hit *h)
{
g_free (h->name);
g_free (h->phone_business);
g_free (h->phone_home);
g_free (h->phone_mobile);
g_free (h);
}
/**
* Callback called after all book have been processed
*/
static void
handler_async_search (GList *hits, gpointer user_data)
{
GList *i;
GdkPixbuf *photo = NULL;
AddressBook_Config *addressbook_config;
callable_obj_t *j;
printf("Addressbook: callback async search\n");
// freeing calls
while ( (j = (callable_obj_t *) g_queue_pop_tail (contacts->callQueue)) != NULL) {
free_callable_obj_t (j);
}
// Retrieve the address book parameters
addressbook_config = (AddressBook_Config*) user_data;
// reset previous results
calltree_reset (contacts);
calllist_reset (contacts);
for (i = hits; i != NULL; i = i->next) {
Hit *entry;
entry = i->data;
if (entry) {
// Get the photo
if (addressbook_display (addressbook_config,
ADDRESSBOOK_DISPLAY_CONTACT_PHOTO))
photo = entry->photo;
// Create entry for business phone information
if (addressbook_display (addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_BUSINESS))
calllist_add_contact (entry->name, entry->phone_business,
CONTACT_PHONE_BUSINESS, photo);
// Create entry for home phone information
if (addressbook_display (addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_HOME))
calllist_add_contact (entry->name, entry->phone_home,
CONTACT_PHONE_HOME, photo);
// Create entry for mobile phone iddnformation
if (addressbook_display (addressbook_config,
ADDRESSBOOK_DISPLAY_PHONE_MOBILE))
calllist_add_contact (entry->name, entry->phone_mobile,
CONTACT_PHONE_MOBILE, photo);
}
free_hit (entry);
}
g_list_free (hits);
// Deactivate waiting image
// deactivateWaitingLayer();
gtk_widget_grab_focus (GTK_WIDGET (contacts->view));
}
......@@ -52,4 +52,5 @@ void abookfactory_scan_directory(AddrBookFactory *);
void abookfactory_load_module(AddrBookFactory *);
void free_hit(Hit *);
#endif
......@@ -43,22 +43,36 @@
typedef enum {ABOOK_QUERY_IS, ABOOK_QUERY_BEGINS_WITH, ABOOK_QUERY_CONTAINS} AddrbookSearchType;
typedef struct _addrbookhandle {
void (*init) (void);
typedef struct _AddressBook_Config {
// gint64: a signed integer guaranteed to be 64 bits on all platforms
// To print or scan values of this type, use G_GINT64_MODIFIER and/or G_GINT64_FORMAT
gint enable;
gint max_results;
gint display_contact_photo;
gint search_phone_home;
gint search_phone_business;
gint search_phone_mobile;
} AddressBook_Config;
typedef struct AddrBookHandle AddrBookHandle;
struct AddrBookHandle {
void (*init) (gchar **);
gboolean (*is_ready) (void);
gboolean (*is_enabled) (void);
gboolean (*is_active) (void);
void (*search) (GtkEntry*);
GSList *(*get_books_data)(void);
void (*search) (AddrBookHandle *, GtkEntry *, AddressBook_Config *);
book_data_t *(*get_books_data)(gchar **);
GSList *(*get_book_data_by_uid)(gchar *);
void (*set_current_book)(gchar *);
void (*set_search_type)(AddrbookSearchType);
} AddrBookHandle;
void (*search_cb)(GList *, gpointer);
};
/**
* Initialize addressbook
*/
void addressbook_init();
void addressbook_init(gchar **book_list);
/**
* Return addressbook state
......@@ -79,16 +93,16 @@ gboolean addressbook_is_active();
/**
* Perform a search in addressbook
*/
void addressbook_search (GtkEntry*);
void addressbook_search (AddrBookHandle *, GtkEntry *, AddressBook_Config *);
/**
* Get a list of addressbook
* Get a list of addressbook book
*/
GSList *addressbook_get_books_data(void);
GSList *addressbook_get_books_data(gchar **book_list);
GSList *addressbook_get_book_data_by_uid(gchar *);
book_data_t *addressbook_get_book_data_by_uid(gchar *);
void addressbook_set_current_book(void);
void addressbook_set_current_book(gchar *);
void addressbook_set_search_type(AddrbookSearchType);
......
......@@ -34,26 +34,27 @@
#include "searchbar.h"
#include "addressbook-config.h"
static void
handler_async_search (GList *, gpointer);
// static void
// handler_async_search (GList *, gpointer);
/**
* Perform a search on address book
*/
void
addressbook_search (GtkEntry* entry)
addressbook_search (AddrBookHandle *handle, GtkEntry* entry, AddressBook_Config *addressbook_config)
{
printf("Addressbook: Search");
const gchar* query = gtk_entry_get_text (GTK_ENTRY (entry));
printf("Addressbook: Search %s\n", query);
AddressBook_Config *addressbook_config;
// AddressBook_Config *addressbook_config;
activateWaitingLayer();
// activateWaitingLayer();
// addressbook_config_load_parameters (&addressbook_config);
search_async_by_contacts (gtk_entry_get_text (GTK_ENTRY (entry)), addressbook_config->max_results, &handler_async_search, addressbook_config);
search_async_by_contacts (gtk_entry_get_text (GTK_ENTRY (entry)), addressbook_config->max_results, handle->search_cb, addressbook_config);
}
......@@ -98,14 +99,12 @@ addressbook_is_active()
* Get active addressbook from config.
*/
static void
addressbook_config_books()
addressbook_config_books(gchar **book_list)
{
gchar **config_book_uid;
book_data_t *book_data;
gchar **list;
// Retrieve list of books
// list = (gchar **) dbus_get_addressbook_list();
......@@ -134,20 +133,21 @@ addressbook_config_books()
* Good method to get books_data
*/
GSList *
addressbook_get_books_data()
addressbook_get_books_data(gchar **book_list)
{
printf("Addressbook: Get books data\n");
fill_books_data();
addressbook_config_books();
// fill_books_data();
addressbook_config_books(book_list);
determine_default_addressbook();
return get_books_data();
}
GSList *
book_data_t *
addressbook_get_book_data_by_uid(gchar *uid)
{
return books_get_book_data_by_uid (uid);
}
/**
......@@ -155,14 +155,14 @@ addressbook_get_book_data_by_uid(gchar *uid)
* Set active/inactive status depending on config.
*/
void
addressbook_init()
addressbook_init(gchar **book_list)
{
printf("Addressbook: Initialize addressbook\n");
init_eds_mutex();
fill_books_data();
addressbook_config_books();
addressbook_config_books(book_list);
determine_default_addressbook();
// Call books initialization
......@@ -172,6 +172,7 @@ addressbook_init()
/**
* Callback called after all book have been processed
*/
/*
static void
handler_async_search (GList *hits, gpointer user_data)
{
......@@ -231,12 +232,17 @@ handler_async_search (GList *hits, gpointer user_data)
g_list_free (hits);
// Deactivate waiting image
deactivateWaitingLayer();
// deactivateWaitingLayer();
gtk_widget_grab_focus (GTK_WIDGET (contacts->view));
}
*/
void addressbook_set_search_type(AddrbookSearchType searchType) {
}
void addressbook_set_current_book(gchar *current) {
}
......@@ -86,18 +86,6 @@ static EBookQueryTest current_test = E_BOOK_QUERY_BEGINS_WITH;
*/
void empty_books_data();
/**
* Freeing a hit instance
*/
void
free_hit (Hit *h)
{
g_free (h->name);
g_free (h->phone_business);
g_free (h->phone_home);
g_free (h->phone_mobile);
g_free (h);
}
/**
* Free a book data
......@@ -690,8 +678,6 @@ empty_books_data()
free_book_data (book_data);
}
}
void
......@@ -722,7 +708,7 @@ search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler
}
printf ("Addressbook: Opening addressbook: uri: %s\n", current_uri);
pinrtf ("Addressbook: Opening addressbook: name: %s\n", current_name);
printf ("Addressbook: Opening addressbook: name: %s\n", current_name);
book = e_book_new_from_uri(current_uri, &err);
......@@ -740,7 +726,6 @@ search_async_by_contacts (const char *query, int max_results, SearchAsyncHandler
e_book_async_open(book, TRUE, eds_async_open_callback, had);
#endif
} else {
printf ("Addressbook: Error: No book available\n");
}
......
......@@ -33,6 +33,8 @@
#include <searchbar.h>
#include <calltree.h>
#include <config/addressbook-config.h>
#include <contacts/addressbook.h>
#include <contacts/addressbook/eds.h>
#include <contacts/addrbookfactory.h>
......@@ -60,7 +62,9 @@ void searchbar_addressbook_activated (GtkEntry *entry, gchar *arg1 UNUSED, gpoin
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
factory->addrbook->search(entry);
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);
factory->addrbook->search(factory->addrbook, entry, addressbook_config);
}
}
......@@ -87,7 +91,9 @@ static void cbox_changed_cb (GtkWidget *widget, gpointer user_data UNUSED)
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
factory->addrbook->set_current_book (name);
factory->addrbook->search(GTK_ENTRY(addressbookentry));
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);
factory->addrbook->search(factory->addrbook, GTK_ENTRY(addressbookentry), addressbook_config);
}
}
......@@ -105,16 +111,18 @@ void update_searchbar_addressbook_list()
GSList *book_list_iterator;
book_data_t *book_data;
GSList *books_data = NULL;
gchar **book_list;
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
books_data = factory->addrbook->get_books_data();
book_list = dbus_get_addressbook_list();
books_data = factory->addrbook->get_books_data(book_list);
}
if(books_data == NULL) {
ERROR("Searchbar: No books data found");
return;
}
DEBUG ("Searchbar: Update addressbook list");
// we must disconnect signal from teh cbox while updating its content
......@@ -122,7 +130,6 @@ void update_searchbar_addressbook_list()
// store the current active text
activeText = g_strdup (gtk_combo_box_get_active_text (GTK_COMBO_BOX (cbox)));
if(activeText == NULL) {
activeText = g_strdup ("");
......@@ -153,6 +160,8 @@ void update_searchbar_addressbook_list()
}
}
DEBUG("OK");
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
if (activeIsSet) {
......@@ -165,6 +174,7 @@ void update_searchbar_addressbook_list()
factory->addrbook->set_current_book(gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox)));
}
}
DEBUG("OK");
g_free (activeText);
cboxSignalId = gtk_signal_connect (GTK_OBJECT (cbox), "changed", G_CALLBACK (cbox_changed_cb), NULL);
......@@ -192,8 +202,10 @@ static void select_search_type (GtkWidget *item, GtkEntry *entry UNUSED)
else if (strcmp ("Search contains", gtk_menu_item_get_label (GTK_MENU_ITEM (item))) == 0) {
factory->addrbook->set_search_type(ABOOK_QUERY_CONTAINS);
}
factory->addrbook->search (GTK_ENTRY (addressbookentry));
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);
factory->addrbook->search (factory->addrbook, GTK_ENTRY (addressbookentry), addressbook_config);
}
}
......@@ -410,6 +422,7 @@ GtkWidget* contacts_searchbar_new ()
int count, cbox_height, cbox_width;
GtkTreeIter iter, activeIter;
GtkCellRenderer *cell;
gchar **book_list;
// gchar *current_addressbook = NULL;
DEBUG ("Addressbook: Create addressbook search bar");
......@@ -423,13 +436,15 @@ GtkWidget* contacts_searchbar_new ()
return NULL;
}
book_list = dbus_get_addressbook_list();
AddrBookFactory *factory = abookfactory_get_factory();
factory->addrbook->init();
factory->addrbook->init(book_list);
GSList *book_list_iterator;
book_data_t *book_data;
GSList *books_data = factory->addrbook->get_books_data();
GSList *books_data = factory->addrbook->get_books_data(book_list);
// Populate menu
count = 0;
......
......@@ -4372,10 +4372,10 @@ void ManagerImpl::setAddressbookList (const std::vector<std::string>& list)
_debug ("Manager: Set addressbook list");
std::string s = serialize (list);
_debug("Manager: New addressbook list: %s", s.c_str());
addressbookPreference.setList (s);
saveConfig();
}
std::vector<std::string> ManagerImpl::getAddressbookList (void)
......
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