Commit 85ad9736 authored by Tristan Matthews's avatar Tristan Matthews
Browse files
parents 7ba2bd7b 8ec8d772
......@@ -63,9 +63,10 @@ YamlParser::YamlParser (const char *file) : filename (file)
YamlParser::~YamlParser()
{
if (fd) {
fclose (fd);
yaml_parser_delete (&parser);
}
for (int i = 0; i < eventNumber; i++)
yaml_event_delete (&events[i]);
......
......@@ -98,7 +98,7 @@ void ManagerImpl::init (std::string config_file)
_debug ("Manager: configuration file path: %s", _path.c_str());
Conf::YamlParser *parser;
Conf::YamlParser *parser = NULL;
try {
parser = new Conf::YamlParser (_path.c_str());
......@@ -107,6 +107,7 @@ void ManagerImpl::init (std::string config_file)
parser->constructNativeData();
} catch (Conf::YamlParserException &e) {
_error ("Manager: %s", e.what());
fflush(stderr);
delete parser;
parser = NULL;
}
......
......@@ -31,7 +31,6 @@
<listOptionValue builtIn="false" value="/usr/include/libgnome-2.0"/>
<listOptionValue builtIn="false" value="/usr/include/libgnomeui-2.0"/>
<listOptionValue builtIn="false" value="/usr/include"/>
<listOptionValue builtIn="false" value="/usr/include/evolution-data-server-2.30"/>
</option>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.1676995808" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="&quot;ICONS_DIR=&quot;/usr/share/sflphone\&quot;"/>
......
......@@ -138,7 +138,7 @@ sflphone_notify_voice_mail (const gchar* accountID , guint count)
static gboolean _is_direct_call (callable_obj_t * c)
{
if (g_strcasecmp (c->_accountID, EMPTY_ENTRY) == 0) {
if (g_strcasecmp (c->_accountID, "empty") == 0) {
if (!g_str_has_prefix (c->_peer_number, "sip:")) {
gchar * new_number = g_strconcat ("sip:", c->_peer_number, NULL);
g_free (c->_peer_number);
......@@ -333,7 +333,7 @@ gboolean sflphone_init (GError **error)
if (!dbus_connect (error) || !dbus_register (getpid (), "Gtk+ Client", error))
return FALSE;
abookfactory_init_factory();
abook_init();
// Init icons factory
init_icon_factory ();
......
......@@ -31,7 +31,6 @@
#include "addressbook-config.h"
#include "searchbar.h"
#include "contacts/addrbookfactory.h"
// #include "contacts/addressbook/eds.h"
#include <string.h>
#include <stdlib.h>
......@@ -44,44 +43,33 @@ enum {
COLUMN_BOOK_ACTIVE, COLUMN_BOOK_NAME, COLUMN_BOOK_UID
};
void
addressbook_config_load_parameters (AddressBook_Config **settings)
AddressBook_Config *addressbook_config_load_parameters ()
{
GHashTable *_params = NULL;
AddressBook_Config *_settings;
// Allocate a struct
_settings = g_new0 (AddressBook_Config, 1);
// Fetch the settings from D-Bus
_params = (GHashTable*) dbus_get_addressbook_settings();
if (_params == NULL) {
DEBUG ("Addressbook: No parameters received, use default");
_settings->enable = 1;
_settings->max_results = 30;
_settings->display_contact_photo = 0;
_settings->search_phone_business = 1;
_settings->search_phone_home = 1;
_settings->search_phone_mobile = 1;
AddressBook_Config *config = g_new0 (AddressBook_Config, 1);
GHashTable *params = dbus_get_addressbook_settings();
if (params == NULL) {
config->enable = 1;
config->max_results = 30;
config->display_contact_photo = 0;
config->search_phone_business = 1;
config->search_phone_home = 1;
config->search_phone_mobile = 1;
}
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));
_settings->search_phone_business = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS));
_settings->search_phone_home = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_HOME));
_settings->search_phone_mobile = (size_t) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_MOBILE));
config->enable = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_ENABLE));
config->max_results = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_MAX_RESULTS));
config->display_contact_photo = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO));
config->search_phone_business = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS));
config->search_phone_home = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_HOME));
config->search_phone_mobile = (size_t) (g_hash_table_lookup (params, ADDRESSBOOK_DISPLAY_PHONE_MOBILE));
}
DEBUG ("Addressbook: Settings: enabled %d, max_result %d, photo %d, business %d, home %d, mobile %d",
_settings->enable, _settings->max_results, _settings->display_contact_photo,
_settings->search_phone_business, _settings->search_phone_home, _settings->search_phone_mobile);
config->enable, config->max_results, config->display_contact_photo,
config->search_phone_business, config->search_phone_home, config->search_phone_mobile);
*settings = _settings;
return config;
}
void
......@@ -211,9 +199,8 @@ addressbook_config_book_active_toggled (
gchar* name;
gchar* uid;
if(!abookfactory_is_addressbook_loaded()) {
if(!addrbook)
return;
}
// Get path of clicked book active toggle box
treePath = gtk_tree_path_new_from_string (path);
......@@ -223,8 +210,6 @@ addressbook_config_book_active_toggled (
return;
}
AddrBookFactory *factory = abookfactory_get_factory();
gtk_tree_model_get_iter (model, &iter, treePath);
// Get active value at iteration
......@@ -240,7 +225,7 @@ addressbook_config_book_active_toggled (
gtk_tree_path_free (treePath);
// Update current memory stored books data
book_data = factory->addrbook->get_book_data_by_uid(uid);
book_data = addrbook->get_book_data_by_uid(uid);
if(book_data == NULL) {
ERROR("Addressbook: Error: Could not find addressbook %s", uid);
}
......@@ -292,14 +277,11 @@ addressbook_config_fill_book_list()
book_data_t *book_data;
gchar **book_list;
if(!abookfactory_is_addressbook_loaded()) {
if(!addrbook)
return;
}
AddrBookFactory *factory = abookfactory_get_factory();
book_list = dbus_get_addressbook_list();
GSList *books_data = factory->addrbook->get_books_data(book_list);
GSList *books_data = addrbook->get_books_data(book_list);
if (!books_data) {
DEBUG ("Addressbook: No valid books data (%s:%d)", __FILE__, __LINE__);
......@@ -338,7 +320,7 @@ create_addressbook_settings()
GtkTreeViewColumn *tree_view_column;
// Load the user value
addressbook_config_load_parameters (&addressbook_config);
addressbook_config = addressbook_config_load_parameters();
ret = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (ret), 10);
......
......@@ -67,12 +67,9 @@ void
addressbook_config_save_parameters (void);
/**
* Initialize the address book structure, and retrieve the saved parameters through D-Bus
*
* @param settings The addressbook structure
* Return the saved parameters through D-Bus
*/
void
addressbook_config_load_parameters (AddressBook_Config **settings);
AddressBook_Config *addressbook_config_load_parameters();
gboolean
addressbook_display (AddressBook_Config *settings, const gchar *field);
......
......@@ -285,7 +285,7 @@ create_general_settings ()
void
save_configuration_parameters (void)
{
if(abookfactory_is_addressbook_loaded()) {
if (addrbook) {
// Address book config
addressbook_config_save_parameters ();
}
......@@ -410,7 +410,7 @@ show_preferences_dialog ()
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), tab, gtk_label_new (_ ("Shortcuts")));
gtk_notebook_page_num (GTK_NOTEBOOK (notebook), tab);
if(abookfactory_is_addressbook_loaded()) {
if(addrbook) {
// Addressbook tab
tab = create_addressbook_settings ();
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), tab, gtk_label_new (_ ("Address Book")));
......@@ -451,7 +451,7 @@ GtkTreeModel* createModel()
GError *error = NULL;
gint i, nb_entries;
nb_entries = abookfactory_is_addressbook_loaded() ? 5 : 4;
nb_entries = addrbook ? 5 : 4;
store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
GtkIconTheme* theme = gtk_icon_theme_get_default();
......
......@@ -37,93 +37,8 @@
#include <glib.h>
#include <dlfcn.h>
static void handler_async_search(GList *hits, gpointer user_data);
AddrBookHandle *addrbook = NULL;
AddrBookFactory addressbookFactory = { .addrbook = NULL };
AddrBookFactory *abookfactory_get_factory(void) {
return &addressbookFactory;
}
gboolean abookfactory_is_addressbook_loaded(void) {
return (addressbookFactory.addrbook != NULL) ? TRUE : FALSE;
}
void abookfactory_init_factory() {
abookfactory_load_module(&addressbookFactory);
}
void abookfactory_scan_directory(AddrBookFactory *factory UNUSED) {
}
void abookfactory_load_module(AddrBookFactory *factory)
{
gchar *plugindir = PLUGINS_DIR;
gchar *pluginpath = g_strdup_printf("%s/libevladdrbook.so", plugindir);
DEBUG("AddressbookFactory: Loading addressbook: %s", pluginpath);
void *handle = dlopen(pluginpath, RTLD_LAZY);
g_free(pluginpath);
if(handle == NULL) {
ERROR("AddressbookFactory: Error: Could not load addressbook");
return;
}
AddrBookHandle *ab = g_malloc(sizeof(AddrBookHandle));
ab->init = dlsym(handle, "addressbook_init");
if(ab->init == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook_init function");
ab->is_ready = dlsym(handle, "addressbook_is_ready");
if(ab->is_ready == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_ready function");
ab->is_enabled = dlsym(handle, "addressbook_is_enabled");
if(ab->is_enabled == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_enabled function");
ab->is_active = dlsym(handle, "addressbook_is_active");
if(ab->is_active == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_is_active function");
ab->search = dlsym(handle, "addressbook_search");
if(ab->search == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_search function");
ab->get_books_data = dlsym(handle, "addressbook_get_books_data");
if(ab->get_books_data == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_get_books_data function");
ab->get_book_data_by_uid = dlsym(handle, "addressbook_get_book_data_by_uid");
if(ab->get_book_data_by_uid == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_get_books_data_by_uid function");
ab->set_current_book = dlsym(handle, "addressbook_set_current_book");
if(ab->set_current_book == NULL)
ERROR("AddressbookFactory: Error: Could not load addressbook addressbook_ser_current_book");
ab->set_search_type = dlsym(handle, "addressbook_set_search_type");
if(ab->set_search_type == NULL)
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
......@@ -131,52 +46,73 @@ free_hit (Hit *h)
static void
handler_async_search (GList *hits, gpointer user_data)
{
GList *i;
// 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) {
for (GList *i = hits; i != NULL; i = i->next) {
GdkPixbuf *photo = NULL;
Hit *entry = i->data;
if (!entry)
continue;
// 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_free (entry->name);
g_free (entry->phone_business);
g_free (entry->phone_home);
g_free (entry->phone_mobile);
g_free (entry);
}
g_list_free (hits);
gtk_widget_grab_focus(GTK_WIDGET (contacts->view));
}
void abook_init()
{
void *handle = dlopen(PLUGINS_DIR"/libevladdrbook.so", RTLD_LAZY);
if(handle == NULL) {
ERROR("Addressbook: Error: Could not load addressbook");
return;
}
addrbook = g_malloc(sizeof(AddrBookHandle));
#define LOAD(func) do { \
addrbook-> func = dlsym(handle, "addressbook_" #func); \
if (addrbook-> func == NULL) \
ERROR("Addressbook: Couldn't load " # func); \
} while(0)
// Deactivate waiting image
// deactivateWaitingLayer();
LOAD(init);
LOAD(is_ready);
LOAD(is_active);
LOAD(search);
LOAD(get_books_data);
LOAD(get_book_data_by_uid);
LOAD(set_current_book);
LOAD(set_search_type);
gtk_widget_grab_focus (GTK_WIDGET (contacts->view));
addrbook->search_cb = handler_async_search;
}
......@@ -32,24 +32,10 @@
#ifndef __ADDRBOOKFACTORY_H__
#define __ADDRBOOKFACTORY_H__
#include <dlfcn.h>
#include <gtk/gtk.h>
#include "addressbook.h"
typedef struct _addrbookfactory {
gboolean is_loaded;
AddrBookHandle *addrbook;
} AddrBookFactory;
void abook_init();
void abookfactory_init_factory();
extern AddrBookHandle *addrbook;
AddrBookFactory *abookfactory_get_factory(void);
gboolean abookfactory_is_addressbook_loaded(void);
void abookfactory_scan_directory(AddrBookFactory *);
void abookfactory_load_module(AddrBookFactory *);
void free_hit(Hit *);
#endif
......@@ -39,10 +39,6 @@
#define __ADDRESSBOOK_H__
#include <gtk/gtk.h>
// #include <addressbook/eds.h>
#define EMPTY_ENTRY "empty"
typedef enum {ABOOK_QUERY_IS, ABOOK_QUERY_BEGINS_WITH, ABOOK_QUERY_CONTAINS} AddrbookSearchType;
......@@ -84,9 +80,8 @@ typedef struct AddrBookHandle AddrBookHandle;
struct AddrBookHandle {
void (*init) (gchar **);
gboolean (*is_ready) (void);
gboolean (*is_enabled) (void);
gboolean (*is_active) (void);
void (*search) (AddrBookHandle *, GtkEntry *, AddressBook_Config *);
void (*search) (void (*search_cb)(GList *, gpointer), GtkEntry *, AddressBook_Config *);
GSList *(*get_books_data)(gchar **);
book_data_t *(*get_book_data_by_uid)(gchar *);
void (*set_current_book)(gchar *);
......@@ -94,41 +89,4 @@ struct AddrBookHandle {
void (*search_cb)(GList *, gpointer);
};
/**
* Initialize addressbook
*/
void addressbook_init(gchar **book_list);
/**
* Return addressbook state
*/
gboolean addressbook_is_ready();
/**
* Return addressbook state
*/
gboolean addressbook_is_enabled();
/**
* Return if at least one addressbook is active
*/
gboolean addressbook_is_active();
/**
* Perform a search in addressbook
*/
void addressbook_search (AddrBookHandle *, GtkEntry *, AddressBook_Config *);
/**
* Get a list of addressbook book
*/
GSList *addressbook_get_books_data(gchar **book_list);
book_data_t *addressbook_get_book_data_by_uid(gchar *);
void addressbook_set_current_book(gchar *);
void addressbook_set_search_type(AddrbookSearchType);
#endif
......@@ -47,7 +47,7 @@ gint is_callID_callstruct(gconstpointer a, gconstpointer b)
void calllist_add_contact (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo)
{
/* Check if the information is valid */
if (g_strcasecmp (contact_phone, EMPTY_ENTRY) == 0)
if (!contact_phone)
return;
callable_obj_t *new_call = create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone);
......
......@@ -58,14 +58,8 @@ GdkPixbuf *missed_pixbuf = NULL;
void searchbar_addressbook_activated (GtkEntry *entry, gchar *arg1 UNUSED, gpointer data UNUSED)
{
DEBUG ("Searchbar: Entry activated");
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);
factory->addrbook->search(factory->addrbook, entry, addressbook_config);
}
if(addrbook)
addrbook->search(addrbook->search_cb, entry, addressbook_config_load_parameters());
}
void searchbar_entry_changed (GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpointer data UNUSED)
......@@ -82,14 +76,12 @@ void searchbar_entry_changed (GtkEntry* entry UNUSED, gchar* arg1 UNUSED, gpoint
static void cbox_changed_cb (GtkWidget *widget, gpointer user_data UNUSED)
{
if(abookfactory_is_addressbook_loaded()) {
DEBUG("Searchbar: Set new addressbook");
AddrBookFactory *factory = abookfactory_get_factory();
factory->addrbook->set_current_book (gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)));
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);
factory->addrbook->search(factory->addrbook, GTK_ENTRY(addressbookentry), addressbook_config);
}
if(!addrbook)
return;
addrbook->set_current_book (gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)));
AddressBook_Config *addressbook_config = addressbook_config_load_parameters();
addrbook->search(addrbook->search_cb, GTK_ENTRY(addressbookentry), addressbook_config);
}
void set_focus_on_addressbook_searchbar ()
......@@ -105,10 +97,8 @@ void update_searchbar_addressbook_list()
book_data_t *book_data;
GSList *books_data = NULL;
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
books_data = factory->addrbook->get_books_data(dbus_get_addressbook_list());
}
if (addrbook)
books_data = addrbook->get_books_data(dbus_get_addressbook_list());
if(books_data == NULL) {
ERROR("Searchbar: No books data found");
......@@ -148,16 +138,15 @@ void update_searchbar_addressbook_list()
}
}
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
if(addrbook) {
if (activeIsSet) {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (cbox), &activeIter);
factory->addrbook->set_current_book(activeText);
addrbook->set_current_book(activeText);
}
else {
gtk_combo_box_set_active (GTK_COMBO_BOX (cbox), 0);
gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox));
factory->addrbook->set_current_book(gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox)));
addrbook->set_current_book(gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox)));
}
}
......@@ -169,9 +158,7 @@ void update_searchbar_addressbook_list()
static void select_search_type (GtkWidget *item, GtkEntry *entry UNUSED)
{
if(abookfactory_is_addressbook_loaded()) {
AddrBookFactory *factory = abookfactory_get_factory();
if(addrbook) {
DEBUG ("Searchbar: %s", gtk_menu_item_get_label (GTK_MENU_ITEM (item)));
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (addressbookentry), GTK_ENTRY_ICON_PRIMARY,
......@@ -179,18 +166,17 @@ static void select_search_type (GtkWidget *item, GtkEntry *entry UNUSED)
if (g_strcmp0 ("Search is", gtk_menu_item_get_label (GTK_MENU_ITEM (item))) == 0) {
factory->addrbook->set_search_type(ABOOK_QUERY_IS);
addrbook->set_search_type(ABOOK_QUERY_IS);
}
else if (g_strcmp0 ("Search begins with", gtk_menu_item_get_label (GTK_MENU_ITEM (item))) == 0) {
factory->addrbook->set_search_type(ABOOK_QUERY_BEGINS_WITH);
addrbook->set_search_type(ABOOK_QUERY_BEGINS_WITH);
}
else if (g_strcmp0 ("Search contains", gtk_menu_item_get_label (GTK_MENU_ITEM (item))) == 0) {
factory->addrbook->set_search_type(ABOOK_QUERY_CONTAINS);
addrbook->set_search_type(ABOOK_QUERY_CONTAINS);
}
AddressBook_Config *addressbook_config;
addressbook_config_load_parameters(&addressbook_config);