Commit f344b6cd authored by Emmanuel Milou's avatar Emmanuel Milou

Add configuration panel for the address book, communication through dbus to retrieve the parameters

parent 01abacdc
......@@ -38,11 +38,12 @@ sflphone_gtk_SOURCES = \
$(STATUSICON_SOURCE) \
codeclist.c \
timestamp.c \
reqaccount.c
reqaccount.c \
addressbook-config.c
noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h audioconf.h codeclist.h assistant.h \
callmanager-glue.h errors.h sflphone_const.h configurationmanager-glue.h instance-glue.h menus.h calltab.h calltree.h configwindow.h \
accountlist.h accountwindow.h marshaller.h sliders.h $(STATUSICON_HEADER) timestamp.h historyfilter.c reqaccount.h
accountlist.h accountwindow.h marshaller.h sliders.h $(STATUSICON_HEADER) timestamp.h historyfilter.c reqaccount.h addressbook-config.h
EXTRA_DIST = marshaller.list
......
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "addressbook-config.h"
void addressbook_load_parameters (AddressBook_Config **settings) {
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) {
_settings->max_results = 30;
_settings->display_contact_photo = 0;
}
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 = _settings;
}
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));
}
static void display_contact_photo_cb (GtkWidget *widget, gpointer user_data) {
AddressBook_Config *settings = (AddressBook_Config*)user_data;
settings->display_contact_photo = (guint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
}
GtkWidget* create_addressbook_settings () {
GtkWidget *ret, *result_frame, *box, *value, *label, *photo;
AddressBook_Config *settings;
// Load the user value
addressbook_load_parameters (&settings);
ret = gtk_vbox_new(FALSE, 10);
gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
result_frame = gtk_frame_new(_("Search Parameters"));
gtk_box_pack_start(GTK_BOX(ret), result_frame, FALSE, FALSE, 0);
gtk_widget_show (result_frame);
box = gtk_vbox_new( FALSE , 1);
gtk_widget_show (box);
gtk_container_add (GTK_CONTAINER(result_frame) , box);
// SCALE BUTTON - NUMBER OF RESULTS
label = gtk_label_new (_("Maximum result number for a request: "));
gtk_box_pack_start (GTK_BOX(box) , label , FALSE , FALSE , 1);
value = gtk_hscale_new_with_range (0.0 , 50.0 , 5.0);
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_box_pack_start (GTK_BOX(box) , value , TRUE , TRUE , 0);
g_signal_connect (G_OBJECT (value) , "value-changed" , G_CALLBACK(max_results_cb) , settings);
// 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_box_pack_start (GTK_BOX(box) , photo , TRUE , TRUE , 1);
gtk_widget_show_all(ret);
return ret;
}
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ADDRESS_BOOK_CONFIG
#define _ADDRESS_BOOK_CONFIG
#include <gtk/gtk.h>
#include <glib/gtypes.h>
#include "actions.h"
G_BEGIN_DECLS
typedef struct _AddressBook_Config {
guint max_results;
guint display_contact_photo;
} AddressBook_Config;
void set_addressbook_config (AddressBook_Config);
AddressBook_Config get_addressbook_config (void);
GtkWidget* create_addressbook_settings ();
G_END_DECLS
#endif // _ADDRESS_BOOK_CONFIG
......@@ -229,6 +229,7 @@ handler_async_search (GList *hits, gpointer user_data) {
GtkTreeSelection *sel;
GList *i;
GdkPixbuf *photo;
for (i = hits; i != NULL; i = i->next)
{
......@@ -236,12 +237,14 @@ handler_async_search (GList *hits, gpointer user_data) {
entry = i->data;
if (entry)
{
/* Get the photo */
photo = entry->photo;
/* Create entry for business phone information */
create_new_entry_in_contactlist (entry->name, entry->phone_business, CONTACT_PHONE_BUSINESS);
create_new_entry_in_contactlist (entry->name, entry->phone_business, CONTACT_PHONE_BUSINESS, photo);
/* Create entry for home phone information */
create_new_entry_in_contactlist (entry->name, entry->phone_home, CONTACT_PHONE_HOME);
create_new_entry_in_contactlist (entry->name, entry->phone_home, CONTACT_PHONE_HOME, photo);
/* Create entry for mobile phone information */
create_new_entry_in_contactlist (entry->name, entry->phone_mobile, CONTACT_PHONE_MOBILE);
create_new_entry_in_contactlist (entry->name, entry->phone_mobile, CONTACT_PHONE_MOBILE, photo);
}
free_hit(entry);
}
......@@ -287,7 +290,7 @@ show_contacts_tab(GtkToggleToolButton *toggle_tool_button UNUSED,
search_async (gtk_entry_get_text (GTK_ENTRY (filter_entry)), 50, &handler_async_search, NULL);
}
void create_new_entry_in_contactlist (gchar *contact_name, gchar *contact_phone, contact_type_t type){
void create_new_entry_in_contactlist (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo){
gchar *from;
call_t *new_call;
......
......@@ -80,6 +80,6 @@ void switch_tab( calltab_t* tab );
void refresh_tab( calltab_t* tab );
void create_new_entry_in_contactlist (gchar *contact_name, gchar *contact_phone, contact_type_t type);
void create_new_entry_in_contactlist (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo);
#endif
......@@ -2225,6 +2225,44 @@ org_sflphone_SFLphone_ConfigurationManager_is_stun_enabled_async (DBusGProxy *pr
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "isStunEnabled", org_sflphone_SFLphone_ConfigurationManager_is_stun_enabled_async_callback, stuff, g_free, G_TYPE_INVALID);
}
static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings (DBusGProxy *proxy, GHashTable** OUT_settings, GError **error)
{
return dbus_g_proxy_call (proxy, "getAddressbookSettings", error, G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_INT), OUT_settings, G_TYPE_INVALID);
}
typedef void (*org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_reply) (DBusGProxy *proxy, GHashTable *OUT_settings, GError *error, gpointer userdata);
static void
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
{
DBusGAsyncData *data = (DBusGAsyncData*) user_data;
GError *error = NULL;
GHashTable* OUT_settings;
dbus_g_proxy_end_call (proxy, call, &error, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_INT), &OUT_settings, G_TYPE_INVALID);
(*(org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_reply)data->cb) (proxy, OUT_settings, error, data->userdata);
return;
}
static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_async (DBusGProxy *proxy, org_sflphone_SFLphone_ConfigurationManager_get_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, "getAddressbookSettings", org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings_async_callback, stuff, g_free, G_TYPE_INVALID);
}
#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_org_sflphone_SFLphone_ConfigurationManager */
G_END_DECLS
......@@ -28,6 +28,7 @@
#include <dbus.h>
#include <mainwindow.h>
#include <audioconf.h>
#include <addressbook-config.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -774,6 +775,11 @@ show_config_window ()
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Record")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
// Addressbook tab
tab = create_addressbook_settings();
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), tab, gtk_label_new(_("Address Book")));
gtk_notebook_page_num(GTK_NOTEBOOK(notebook), tab);
gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook) , 1);
gtk_dialog_run(dialog);
......
......@@ -39,6 +39,7 @@ typedef struct _Handler_And_Data {
} Handler_And_Data;
static GSList *books = NULL;
static int pixbuf_size = 16;
static EContactField search_fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_PHONE_BUSINESS, E_CONTACT_NICKNAME, 0 };
static int n_search_fields = G_N_ELEMENTS (search_fields) - 1;
......@@ -120,6 +121,44 @@ create_query (const char* s)
return query;
}
static GdkPixbuf*
pixbuf_from_contact (EContact *contact)
{
GdkPixbuf *pixbuf = NULL;
EContactPhoto *photo = e_contact_get (contact, E_CONTACT_PHOTO);
if (photo) {
GdkPixbufLoader *loader;
loader = gdk_pixbuf_loader_new ();
if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL))
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
}
if (pixbuf) {
GdkPixbuf *tmp;
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
double scale = 1.0;
if (height > width) {
scale = pixbuf_size / (double) height;
} else {
scale = pixbuf_size / (double) width;
}
if (scale < 1.0) {
tmp = gdk_pixbuf_scale_simple (pixbuf, width * scale, height * scale, GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = tmp;
}
}
e_contact_photo_free (photo);
}
return pixbuf;
}
/**
* Initialize address book
*/
......@@ -240,7 +279,9 @@ view_contacts_added_cb (EBookView *book_view, GList *contacts, gpointer user_dat
contact = E_CONTACT (contacts->data);
hit = g_new (Hit, 1);
//hit->pixbuf = pixbuf_from_contact (contact);
/* Get the photo contact */
hit->photo = pixbuf_from_contact (contact);
/* Get business phone information */
fetch_information_from_contact (contact, E_CONTACT_PHONE_BUSINESS, &number);
hit->phone_business = g_strdup (number);
......
......@@ -28,6 +28,7 @@
#define __EDS_H__
#include <glib/gtypes.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libebook/e-book.h>
#define EMPTY_ENTRY "empty"
......@@ -36,10 +37,11 @@ G_BEGIN_DECLS
typedef struct _Hit
{
gchar *name;
gchar *phone_business;
gchar *phone_home;
gchar *phone_mobile;
gchar *name;
GdkPixbuf *photo;
gchar *phone_business;
gchar *phone_home;
gchar *phone_mobile;
} Hit;
void free_hit (Hit *h);
......
......@@ -1448,3 +1448,26 @@ void dbus_enable_stun (void)
g_error_free(error);
}
}
GHashTable* dbus_get_addressbook_settings (void) {
GError *error = NULL;
GHashTable *results = NULL;
g_print ("Calling org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n");
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings (configurationManagerProxy, &results, &error);
if (error){
g_print ("Error calling org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n");
g_error_free (error);
}
g_print ("Called org_sflphone_SFLphone_ConfigurationManager_get_addressbook_settings\n");
return results;
}
......@@ -446,4 +446,11 @@ void dbus_set_record (const call_t * c);
void dbus_set_record_path (const gchar *path);
gchar* dbus_get_record_path (void);
/**
* Encapsulate all the address book-related configuration
*/
GHashTable* dbus_get_addressbook_settings (void);
#endif
......@@ -79,6 +79,7 @@ public:
register_method(ConfigurationManager_adaptor, getStunServer, _getStunServer_stub);
register_method(ConfigurationManager_adaptor, enableStun, _enableStun_stub);
register_method(ConfigurationManager_adaptor, isStunEnabled, _isStunEnabled_stub);
register_method(ConfigurationManager_adaptor, getAddressbookSettings, _getAddressbookSettings_stub);
}
::DBus::IntrospectedInterface *const introspect() const
......@@ -373,6 +374,11 @@ public:
{ "state", "i", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getAddressbookSettings_args[] =
{
{ "settings", "a{si}", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument parametersChanged_args[] =
{
{ "list", "a{ss}", false },
......@@ -448,6 +454,7 @@ public:
{ "getStunServer", getStunServer_args },
{ "enableStun", enableStun_args },
{ "isStunEnabled", isStunEnabled_args },
{ "getAddressbookSettings", getAddressbookSettings_args },
{ 0, 0 }
};
static ::DBus::IntrospectedMethod ConfigurationManager_adaptor_signals[] =
......@@ -541,6 +548,7 @@ public:
virtual std::string getStunServer() = 0;
virtual void enableStun() = 0;
virtual int32_t isStunEnabled() = 0;
virtual std::map< std::string, int32_t > getAddressbookSettings() = 0;
public:
......@@ -1130,6 +1138,16 @@ private:
wi << argout1;
return reply;
}
::DBus::Message _getAddressbookSettings_stub(const ::DBus::CallMessage &call)
{
::DBus::MessageIter ri = call.reader();
std::map< std::string, int32_t > argout1 = getAddressbookSettings();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
};
} } }
......
......@@ -242,6 +242,11 @@
<arg type="i" name="state" direction="out"/>
</method>
<!-- Addressbook configuration -->
<method name="getAddressbookSettings">
<arg type="a{si}" name="settings" direction="out"/>
</method>
<!-- ///////////////////////////// -->
<signal name="parametersChanged">
<arg type="a{ss}" name="list" direction="out"/>
......
......@@ -425,3 +425,7 @@ int32_t ConfigurationManager::isStunEnabled (void)
{
return Manager::instance().isStunEnabled();
}
std::map<std::string, int32_t> ConfigurationManager::getAddressbookSettings (void) {
return Manager::instance().getAddressbookSettings ();
}
......@@ -104,6 +104,8 @@ public:
void enableStun (void);
int32_t isStunEnabled (void);
std::map<std::string, int32_t> getAddressbookSettings (void);
};
......
......@@ -1066,6 +1066,10 @@ ManagerImpl::initConfigFile ( bool load_user_value )
fill_config_int(CONFIG_PA_VOLUME_CTRL , YES_STR);
fill_config_int(CONFIG_SIP_PORT, DFT_SIP_PORT);
section = ADDRESSBOOK;
fill_config_int (ADDRESSBOOK_MAX_RESULTS, "25");
fill_config_int (ADDRESSBOOK_DISPLAY_CONTACT_PHOTO, YES_STR);
// Loads config from ~/.sflphone/sflphonedrc or so..
if (createSettingsPath() == 1 && load_user_value) {
_exist = _config.populateFromFile(_path);
......@@ -2377,6 +2381,18 @@ void ManagerImpl::registerCurSIPAccounts(VoIPLink *link)
}
}
std::map<std::string, int32_t> ManagerImpl::getAddressbookSettings () {
std::map<std::string, int32_t> settings;
settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_MAX_RESULTS", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_MAX_RESULTS)) );
settings.insert (std::pair<std::string, int32_t> ("ADDRESSBOOK_DISPLAY_CONTACT_PHOTO", getConfigInt (ADDRESSBOOK, ADDRESSBOOK_DISPLAY_CONTACT_PHOTO)));
return settings;
}
#ifdef TEST
/**
* Test accountMap
......
......@@ -553,6 +553,12 @@ class ManagerImpl {
*/
void setMailNotify( void );
/**
* Addressbook configuration
*/
std::map<std::string, int32_t> getAddressbookSettings (void);
/**
* Get the audio manager
* @return int The audio manager
......
......@@ -73,6 +73,10 @@
#define STUN_ENABLE "STUN.enable"
#define STUN_SERVER "STUN.server"
#define ADDRESSBOOK "Addressbook" /** Address book section */
#define ADDRESSBOOK_MAX_RESULTS "Addressbook.max_results"
#define ADDRESSBOOK_DISPLAY_CONTACT_PHOTO "Addressbook.contact_photo"
#define EMPTY_FIELD "" /** Default value for empty field */
#define DFT_STUN_SERVER "stun.fwdnet.net:3478" /** Default STUN server address */
#define YES_STR "1" /** Default YES value */
......
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