Commit aa316079 authored by Emmanuel Milou's avatar Emmanuel Milou

address book configuration panel, interaction with through D-BUS done

parent 52d9c302
......@@ -19,6 +19,8 @@
#include "addressbook-config.h"
AddressBook_Config *addressbook_config;
void addressbook_load_parameters (AddressBook_Config **settings) {
GHashTable *_params = NULL;
......@@ -38,53 +40,64 @@ void addressbook_load_parameters (AddressBook_Config **settings) {
_settings->search_phone_mobile = 1;
}
else {
_settings->max_results = (guint)(g_hash_table_lookup (_params, "ADDRESSBOOK_MAX_RESULTS"));
_settings->display_contact_photo = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO"));
_settings->search_phone_business = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_BUSINESS"));
_settings->search_phone_home = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_HOME"));
_settings->search_phone_mobile = (guint) (g_hash_table_lookup (_params, "ADDRESSBOOK_SEARCH_PHONE_MOBILE"));
_settings->max_results = (guint)(g_hash_table_lookup (_params, ADDRESSBOOK_MAX_RESULTS));
_settings->display_contact_photo = (guint) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO));
_settings->search_phone_business = (guint) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS));
_settings->search_phone_home = (guint) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_HOME));
_settings->search_phone_mobile = (guint) (g_hash_table_lookup (_params, ADDRESSBOOK_DISPLAY_PHONE_MOBILE));
}
*settings = _settings;
}
void addressbook_save_parameters (void) {
GHashTable *params = NULL;
params = g_hash_table_new (NULL, g_str_equal);
g_hash_table_replace (params, (gpointer)ADDRESSBOOK_MAX_RESULTS, (gpointer)addressbook_config->max_results);
g_hash_table_replace (params, (gpointer)ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, (gpointer)addressbook_config->display_contact_photo);
g_hash_table_replace (params, (gpointer)ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, (gpointer)addressbook_config->search_phone_business);
g_hash_table_replace (params, (gpointer)ADDRESSBOOK_DISPLAY_PHONE_HOME, (gpointer)addressbook_config->search_phone_home);
g_hash_table_replace (params, (gpointer)ADDRESSBOOK_DISPLAY_PHONE_MOBILE, (gpointer)addressbook_config->search_phone_mobile);
dbus_set_addressbook_settings (params);
// Decrement the reference count
g_hash_table_unref (params);
}
static void max_results_cb (GtkRange* scale, gpointer user_data) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->max_results = (guint) gtk_range_get_value (GTK_RANGE (scale));
addressbook_config->max_results = (guint) gtk_range_get_value (GTK_RANGE (scale));
}
static void display_contact_photo_cb (GtkWidget *widget, gpointer user_data) {
static void display_contact_photo_cb (GtkWidget *widget) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->display_contact_photo = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
addressbook_config->display_contact_photo = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
static void search_phone_business_cb (GtkWidget *widget, gpointer user_data) {
static void search_phone_business_cb (GtkWidget *widget) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->search_phone_business = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
addressbook_config->search_phone_business = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
static void search_phone_home_cb (GtkWidget *widget, gpointer user_data) {
static void search_phone_home_cb (GtkWidget *widget) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->search_phone_home = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
addressbook_config->search_phone_home = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
static void search_phone_mobile_cb (GtkWidget *widget, gpointer user_data) {
static void search_phone_mobile_cb (GtkWidget *widget) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->search_phone_mobile = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
addressbook_config->search_phone_mobile = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
GtkWidget* create_addressbook_settings () {
GtkWidget *ret, *result_frame, *box, *value, *label, *photo, *item;
AddressBook_Config *settings;
// Load the user value
addressbook_load_parameters (&settings);
addressbook_load_parameters (&addressbook_config);
ret = gtk_vbox_new(FALSE, 10);
gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
......@@ -104,32 +117,32 @@ GtkWidget* create_addressbook_settings () {
gtk_label_set_mnemonic_widget (GTK_LABEL (label), value);
gtk_scale_set_digits (GTK_SCALE(value) , 0);
gtk_scale_set_value_pos (GTK_SCALE(value) , GTK_POS_RIGHT);
gtk_range_set_value (GTK_RANGE( value ) , settings->max_results);
gtk_range_set_value (GTK_RANGE( value ) , addressbook_config->max_results);
gtk_box_pack_start (GTK_BOX(box) , value , TRUE , TRUE , 0);
g_signal_connect (G_OBJECT (value) , "value-changed" , G_CALLBACK(max_results_cb) , settings);
g_signal_connect (G_OBJECT (value) , "value-changed" , G_CALLBACK(max_results_cb), NULL );
// PHOTO DISPLAY
photo = gtk_check_button_new_with_mnemonic( _("_Display contact photo if available"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(photo), settings->display_contact_photo);
g_signal_connect (G_OBJECT(photo) , "clicked" , G_CALLBACK (display_contact_photo_cb) , settings);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(photo), addressbook_config->display_contact_photo);
g_signal_connect (G_OBJECT(photo) , "clicked" , G_CALLBACK (display_contact_photo_cb), NULL);
gtk_box_pack_start (GTK_BOX(box) , photo , TRUE , TRUE , 1);
label = gtk_label_new (_("Search for and display: "));
gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1);
item = gtk_check_button_new_with_mnemonic( _("_Business phone"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_business);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_business_cb) , settings);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), addressbook_config->search_phone_business);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_business_cb) , NULL);
gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
item = gtk_check_button_new_with_mnemonic( _("_Home phone"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_home);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_home_cb) , settings);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), addressbook_config->search_phone_home);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_home_cb) , NULL);
gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
item = gtk_check_button_new_with_mnemonic( _("_Mobile phone"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), settings->search_phone_mobile);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_mobile_cb) , settings);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item), addressbook_config->search_phone_mobile);
g_signal_connect (G_OBJECT(item) , "clicked" , G_CALLBACK (search_phone_mobile_cb) , NULL);
gtk_box_pack_start (GTK_BOX(box) , item , TRUE , TRUE , 1);
gtk_widget_show_all(ret);
......@@ -137,3 +150,25 @@ GtkWidget* create_addressbook_settings () {
return ret;
}
gboolean addressbook_display (AddressBook_Config *settings, const gchar *field) {
gboolean display = FALSE;
if (g_strcasecmp (field, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO) == 0)
display = (settings->display_contact_photo == 1)? TRUE : FALSE;
else if (g_strcasecmp (field, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS) == 0)
display = (settings->search_phone_business == 1)? TRUE : FALSE;
else if (g_strcasecmp (field, ADDRESSBOOK_DISPLAY_PHONE_HOME) == 0)
display = (settings->search_phone_home == 1)? TRUE : FALSE;
else if (g_strcasecmp (field, ADDRESSBOOK_DISPLAY_PHONE_MOBILE) == 0)
display = (settings->search_phone_mobile == 1)? TRUE : FALSE;
else
display = FALSE;
return display;
}
......@@ -27,6 +27,12 @@
G_BEGIN_DECLS
#define ADDRESSBOOK_MAX_RESULTS "ADDRESSBOOK_MAX_RESULTS"
#define ADDRESSBOOK_DISPLAY_CONTACT_PHOTO "ADDRESSBOOK_DISPLAY_CONTACT_PHOTO"
#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 {
guint max_results;
guint display_contact_photo;
......@@ -35,13 +41,22 @@ typedef struct _AddressBook_Config {
guint search_phone_mobile;
} AddressBook_Config;
void set_addressbook_config (AddressBook_Config);
/**
* Save the parameters through D-BUS
*/
void addressbook_save_parameters (void);
/**
* Initialize the address book structure, and retrieve the saved parameters through D-Bus
*
* @param settings The addressbook structure
*/
void addressbook_load_parameters (AddressBook_Config **settings);
AddressBook_Config get_addressbook_config (void);
gboolean addressbook_display (AddressBook_Config *settings, const gchar *field);
GtkWidget* create_addressbook_settings ();
G_END_DECLS
#endif // _ADDRESS_BOOK_CONFIG
......@@ -28,7 +28,7 @@
#include <menus.h>
#include <dbus.h>
#include <contactlist/eds.h>
#include "addressbook-config.h"
GtkWidget * toolbar;
GtkToolItem * pickupButton;
......@@ -229,7 +229,11 @@ handler_async_search (GList *hits, gpointer user_data) {
GtkTreeSelection *sel;
GList *i;
GdkPixbuf *photo;
GdkPixbuf *photo = NULL;
AddressBook_Config *addressbook_config;
// Load the parameters
addressbook_load_parameters (&addressbook_config);
for (i = hits; i != NULL; i = i->next)
{
......@@ -238,12 +242,16 @@ handler_async_search (GList *hits, gpointer user_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))
create_new_entry_in_contactlist (entry->name, entry->phone_business, CONTACT_PHONE_BUSINESS, photo);
/* Create entry for home phone information */
if (addressbook_display (addressbook_config, ADDRESSBOOK_DISPLAY_PHONE_HOME))
create_new_entry_in_contactlist (entry->name, entry->phone_home, CONTACT_PHONE_HOME, photo);
/* Create entry for mobile phone information */
if (addressbook_display (addressbook_config, ADDRESSBOOK_DISPLAY_PHONE_MOBILE))
create_new_entry_in_contactlist (entry->name, entry->phone_mobile, CONTACT_PHONE_MOBILE, photo);
}
free_hit(entry);
......
......@@ -2263,6 +2263,43 @@ org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_async (DBusG
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "getAddressbookSettings", org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_async_callback, stuff, g_free, G_TYPE_INVALID);
}
static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings (DBusGProxy *proxy, const GHashTable* IN_settings, GError **error)
{
return dbus_g_proxy_call (proxy, "setAddressbookSettings", error, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_INT), IN_settings, G_TYPE_INVALID, G_TYPE_INVALID);
}
typedef void (*org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
static void
org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
{
DBusGAsyncData *data = (DBusGAsyncData*) user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
(*(org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_reply)data->cb) (proxy, error, data->userdata);
return;
}
static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_async (DBusGProxy *proxy, const GHashTable* IN_settings, org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_reply callback, gpointer userdata)
{
DBusGAsyncData *stuff;
stuff = g_new (DBusGAsyncData, 1);
stuff->cb = G_CALLBACK (callback);
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "setAddressbookSettings", org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings_async_callback, stuff, g_free, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_INT), IN_settings, G_TYPE_INVALID);
}
#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_org_sflphone_SFLphone_ConfigurationManager */
G_END_DECLS
......@@ -739,6 +739,7 @@ show_config_window ()
GtkDialog * dialog;
GtkWidget * notebook;
GtkWidget * tab;
guint result;
dialogOpen = TRUE;
......@@ -782,7 +783,9 @@ show_config_window ()
gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook) , 1);
gtk_dialog_run(dialog);
result = gtk_dialog_run(dialog);
save_configuration_parameters ();
dialogOpen = FALSE;
......@@ -849,3 +852,9 @@ void config_window_set_stun_visible()
{
gtk_widget_set_sensitive( GTK_WIDGET(stunFrame), TRUE );
}
void save_configuration_parameters (void) {
addressbook_save_parameters ();
}
......@@ -116,4 +116,6 @@ void show_accounts_window();
void config_window_set_stun_visible();
void save_configuration_parameters (void);
#endif
......@@ -1467,7 +1467,17 @@ GHashTable* dbus_get_addressbook_settings (void) {
return results;
}
void dbus_set_addressbook_settings (GHashTable * settings){
GError *error = NULL;
g_print ("Calling org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings\n");
org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings (configurationManagerProxy, settings, &error);
if (error){
g_print ("Error calling org_sflphone_SFLphone_ConfigurationManager_set_addressbook_settings\n");
g_error_free (error);
}
}
......@@ -448,9 +448,17 @@ gchar* dbus_get_record_path (void);
/**
* Encapsulate all the address book-related configuration
* Get the configuration
*/
GHashTable* dbus_get_addressbook_settings (void);
/**
* Encapsulate all the address book-related configuration
* Set the configuration
*/
void dbus_set_addressbook_settings (GHashTable *);
#endif
......@@ -80,6 +80,7 @@ public:
register_method(ConfigurationManager_adaptor, enableStun, _enableStun_stub);
register_method(ConfigurationManager_adaptor, isStunEnabled, _isStunEnabled_stub);
register_method(ConfigurationManager_adaptor, getAddressbookSettings, _getAddressbookSettings_stub);
register_method(ConfigurationManager_adaptor, setAddressbookSettings, _setAddressbookSettings_stub);
}
::DBus::IntrospectedInterface *const introspect() const
......@@ -379,6 +380,11 @@ public:
{ "settings", "a{si}", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setAddressbookSettings_args[] =
{
{ "settings", "a{si}", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument parametersChanged_args[] =
{
{ "list", "a{ss}", false },
......@@ -455,6 +461,7 @@ public:
{ "enableStun", enableStun_args },
{ "isStunEnabled", isStunEnabled_args },
{ "getAddressbookSettings", getAddressbookSettings_args },
{ "setAddressbookSettings", setAddressbookSettings_args },
{ 0, 0 }
};
static ::DBus::IntrospectedMethod ConfigurationManager_adaptor_signals[] =
......@@ -549,6 +556,7 @@ public:
virtual void enableStun() = 0;
virtual int32_t isStunEnabled() = 0;
virtual std::map< std::string, int32_t > getAddressbookSettings() = 0;
virtual void setAddressbookSettings(const std::map< std::string, int32_t >& settings) = 0;
public:
......@@ -1148,6 +1156,15 @@ private:
wi << argout1;
return reply;
}
::DBus::Message _setAddressbookSettings_stub(const ::DBus::CallMessage &call)
{
::DBus::MessageIter ri = call.reader();
std::map< std::string, int32_t > argin1; ri >> argin1;
setAddressbookSettings(argin1);
::DBus::ReturnMessage reply(call);
return reply;
}
};
} } }
......
......@@ -247,6 +247,10 @@
<arg type="a{si}" name="settings" direction="out"/>
</method>
<method name="setAddressbookSettings">
<arg type="a{si}" name="settings" direction="in"/>
</method>
<!-- ///////////////////////////// -->
<signal name="parametersChanged">
<arg type="a{ss}" name="list" direction="out"/>
......
......@@ -429,3 +429,7 @@ int32_t ConfigurationManager::isStunEnabled (void)
std::map<std::string, int32_t> ConfigurationManager::getAddressbookSettings (void) {
return Manager::instance().getAddressbookSettings ();
}
void ConfigurationManager::setAddressbookSettings (const std::map<std::string, int32_t>& settings) {
Manager::instance().setAddressbookSettings (settings);
}
......@@ -105,6 +105,7 @@ public:
int32_t isStunEnabled (void);
std::map<std::string, int32_t> getAddressbookSettings (void);
void setAddressbookSettings (const std::map<std::string, int32_t>& settings);
};
......
......@@ -1068,10 +1068,10 @@ ManagerImpl::initConfigFile ( bool load_user_value )
section = ADDRESSBOOK;
fill_config_int (ADDRESSBOOK_MAX_RESULTS, "25");
fill_config_int (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, YES_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, NO_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_BUSINESS, YES_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_HOME, YES_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_MOBILE, YES_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_HOME, NO_STR);
fill_config_int (ADDRESSBOOK_DISPLAY_PHONE_MOBILE, NO_STR);
// Loads config from ~/.sflphone/sflphonedrc or so..
if (createSettingsPath() == 1 && load_user_value) {
......@@ -2398,6 +2398,18 @@ std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () {
return settings;
}
void ManagerImpl::setAddressbookSettings (const std::map<std::string, int32_t>& settings){
setConfig(ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS, (*settings.find("ADDRESSBOOK_MAX_RESULTS")).second);
setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO , (*settings.find("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO")).second);
setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_BUSINESS , (*settings.find("ADDRESSBOOK_DISPLAY_PHONE_BUSINESS")).second);
setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_HOME , (*settings.find("ADDRESSBOOK_DISPLAY_PHONE_HOME")).second);
setConfig(ADDRESSBOOK, ADDRESSBOOK_DISPLAY_PHONE_MOBILE , (*settings.find("ADDRESSBOOK_DISPLAY_PHONE_MOBILE")).second);
// Write it to the configuration file
saveConfig ();
}
#ifdef TEST
/**
......
......@@ -559,6 +559,11 @@ class ManagerImpl {
*/
std::map<std::string, int32_t> getAddressbookSettings (void);
/**
* Addressbook configuration
*/
void setAddressbookSettings (const std::map<std::string, int32_t>& settings);
/**
* Get the audio manager
* @return int The audio manager
......
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