Commit 94affc53 authored by Alexandre Savard's avatar Alexandre Savard

[#3218] Fix shortcuts in configuration

parent 2f6f1822
......@@ -168,6 +168,10 @@ void *threaded_clock_incrementer(void *pc) {
DEBUG("%s", res);
calltree_update_clock(call);
g_free(res);
sleep(1);
}
}
......
......@@ -318,7 +318,7 @@ row_single_click(GtkTreeView *tree_view UNUSED, void * data UNUSED)
}
}
static gboolean
static gboolean
button_pressed(GtkWidget* widget, GdkEventButton *event, gpointer user_data UNUSED)
{
if (event->button == 3 && event->type == GDK_BUTTON_PRESS){
......@@ -684,7 +684,7 @@ calltree_remove_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent)
DEBUG("Calltre remove call ended");
}
void
void
calltree_update_call (calltab_t* tab, callable_obj_t * c, GtkTreeIter *parent)
{
GdkPixbuf *pixbuf=NULL;
......@@ -1406,6 +1406,13 @@ void calltree_display (calltab_t *tab) {
}
void
calltree_update_clock(callable_obj_t *c) {
DEBUG("UPDATE CLOCK");
// TODO this make the whole thing crash...
// calltree_update_call(current_calls, c, NULL);
}
static void drag_begin_cb(GtkWidget *widget, GdkDragContext *dc, gpointer data)
......
......@@ -111,4 +111,7 @@ calltree_display (calltab_t *tab);
void
row_activated(GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, void *);
void
calltree_update_clock(callable_obj_t *c);
#endif
......@@ -120,6 +120,12 @@
#define REGISTRATION_STATE_CODE "Registration.code"
#define REGISTRATION_STATE_DESCRIPTION "Registration.description"
#define SHORTCUT_PICKUP "pickUp"
#define SHORTCUT_HANGUP "hangUp"
#define SHORTCUT_POPUP "popupWindow"
#define SHORTCUT_TOGGLEPICKUPHANGUP "togglePickupHangup"
#define SHORTCUT_TOGGLEHOLD "toggleHold"
/**
* Global logger
*/
......
......@@ -146,19 +146,19 @@ default_callback ()
static void*
get_action_callback (const gchar* action)
{
if (strcmp (action, "pick_up") == 0)
if (strcmp (action, SHORTCUT_PICKUP) == 0)
return pick_up_callback;
if (strcmp (action, "hang_up") == 0)
if (strcmp (action, SHORTCUT_HANGUP) == 0)
return hang_up_callback;
if (strcmp (action, "popup_window") == 0)
if (strcmp (action, SHORTCUT_POPUP) == 0)
return popup_window_callback;
if (strcmp (action, "toggle_pick_up_hang_up") == 0)
if (strcmp (action, SHORTCUT_TOGGLEPICKUPHANGUP) == 0)
return toggle_pick_up_hang_up_callback;
if (strcmp (action, "toggle_hold") == 0)
if (strcmp (action, SHORTCUT_TOGGLEHOLD) == 0)
return toggle_hold_callback;
return default_callback;
......
......@@ -289,6 +289,37 @@ void YamlEmitter::serializeAudioPreference(MappingNode *map)
}
void YamlEmitter::serializeShortcutPreference(MappingNode *map)
{
std::string preferencestr("shortcuts");
int preferenceid, preferencemapping;
_debug("YamlEmitter: Serialize shortcuts preferences");
if(map->getType() != MAPPING)
throw YamlEmitterException("Node type is not a mapping while writing preferences");
if((preferenceid = yaml_document_add_scalar(&document, NULL, (yaml_char_t *)preferencestr.c_str(), -1, YAML_PLAIN_SCALAR_STYLE)) == 0)
throw YamlEmitterException("Could not add scalar to document");
if((preferencemapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0)
throw YamlEmitterException("Could not add mapping to document");
if(!yaml_document_append_mapping_pair (&document, topLevelMapping, preferenceid, preferencemapping))
throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping();
Mapping::iterator iter = internalmap->begin();
while(iter != internalmap->end()) {
addMappingItem(preferencemapping, iter->first, iter->second);
iter++;
}
}
void YamlEmitter::addMappingItem(int mappingid, Key key, YamlNode *node)
{
......
......@@ -87,6 +87,8 @@ class YamlEmitter {
void serializeAudioPreference(MappingNode *map);
void serializeShortcutPreference(MappingNode *map);
void writeAudio();
void writeHooks();
......
......@@ -38,6 +38,13 @@
namespace Conf {
YamlParser::YamlParser(const char *file) : filename(file)
, accountSequence(NULL)
, preferenceSequence(NULL)
, addressbookSequence(NULL)
, audioSequence(NULL)
, hooksSequence(NULL)
, voiplinkSequence(NULL)
, shortcutSequence(NULL)
{
memset(buffer, 0, PARSER_BUFFERSIZE);
......@@ -431,6 +438,7 @@ void YamlParser::mainNativeDataMapping(MappingNode *map) {
Key hooks("hooks");
Key preferences("preferences");
Key voiplink("voipPreferences");
Key shortcuts("shortcuts");
while(iter != map->getMapping()->end()) {
......@@ -440,25 +448,29 @@ void YamlParser::mainNativeDataMapping(MappingNode *map) {
accountSequence = (SequenceNode *)(iter->second);
}
else if(addressbook.compare(iter->first) == 0) {
_debug("YamlParser: Adding voip addressbook preference");
_debug("YamlParser: Adding addressbook preference");
addressbookSequence = (SequenceNode *)(iter->second);
}
else if(audio.compare(iter->first) == 0) {
_debug("YamlParser: Adding voip audio preference");
_debug("YamlParser: Adding audio preference");
audioSequence = (SequenceNode *)(iter->second);
}
else if(hooks.compare(iter->first) == 0) {
_debug("YamlParser: Adding voip hooks preference");
_debug("YamlParser: Adding hooks preference");
hooksSequence = (SequenceNode *)(iter->second);
}
else if(preferences.compare(iter->first) == 0) {
_debug("YamlParser: Adding voip preference preference");
_debug("YamlParser: Adding preference preference");
preferenceSequence = (SequenceNode *)(iter->second);
}
else if(voiplink.compare(iter->first) == 0) {
_debug("YamlParser: Adding voip voip preference");
_debug("YamlParser: Adding voip preference");
voiplinkSequence = (SequenceNode *)(iter->second);
}
else if(shortcuts.compare(iter->first) == 0) {
_debug("YamlParser: Adding shortcut preference");
shortcutSequence = (SequenceNode *)(iter->second);
}
else
throw YamlParserException("Unknow map key in configuration");
......
......@@ -90,6 +90,8 @@ class YamlParser {
SequenceNode *getVoipPreferenceSequence(void) { return voiplinkSequence; }
SequenceNode *getShortcutSequence(void) { return shortcutSequence; }
private:
/**
......@@ -151,6 +153,8 @@ class YamlParser {
SequenceNode *voiplinkSequence;
SequenceNode *shortcutSequence;
};
}
......
......@@ -736,6 +736,8 @@ std::map<std::string, int32_t> ConfigurationManager::getShortcuts() {
shortcutsMap.insert(std::pair<std::string, int>(key, shortcut));
}
return Manager::instance().shortcutPreferences.getShortcuts();
return shortcutsMap;
}
......
......@@ -1438,6 +1438,7 @@ bool ManagerImpl::saveConfig (void) {
addressbookPreference.serialize(emitter);
hookPreference.serialize(emitter);
audioPreference.serialize(emitter);
shortcutPreferences.serialize(emitter);
emitter->serializeData();
......@@ -3579,6 +3580,7 @@ short ManagerImpl::loadAccountMap() {
addressbookPreference.unserialize((Conf::MappingNode *)(parser->getAddressbookSequence()));
hookPreference.unserialize((Conf::MappingNode *)(parser->getHookSequence()));
audioPreference.unserialize((Conf::MappingNode *)(parser->getAudioSequence()));
shortcutPreferences.unserialize((Conf::MappingNode *)(parser->getShortcutSequence()));
Conf::SequenceNode *seq = parser->getAccountSequence();
......
......@@ -114,16 +114,40 @@ class ManagerImpl {
ManagerImpl (void);
~ManagerImpl (void);
/**
* General preferences configuration
*/
Preferences preferences;
/**
* Voip related preferences
*/
VoipPreference voipPreferences;
/**
* Addressbook related preferences
*/
AddressbookPreference addressbookPreference;
/**
* Hook preferences
*/
HookPreference hookPreference;
/**
* Audio preferences
*/
AudioPreference audioPreference;
/**
* Shortcut preferences
*/
ShortcutPreferences shortcutPreferences;
/**
* Method to build preferences from configuration
*/
short buildConfiguration();
/**
......
......@@ -97,6 +97,9 @@ void Preferences::unserialize(Conf::MappingNode *map)
Conf::ScalarNode *val;
if(!map)
return;
val = (Conf::ScalarNode *)(map->getValue(orderKey));
if(val) { _accountOrder = val->getValue(); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(audioApiKey));
......@@ -170,6 +173,9 @@ void VoipPreference::unserialize(Conf::MappingNode *map)
Conf::ScalarNode *val = NULL;
if(!map)
return;
val = (Conf::ScalarNode *)(map->getValue(playDtmfKey));
if(val && !val->getValue().empty()) { _playDtmf = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(playTonesKey));
......@@ -233,6 +239,9 @@ void AddressbookPreference::unserialize(Conf::MappingNode *map)
Conf::ScalarNode *val = NULL;
if(!map)
return;
val = (Conf::ScalarNode *)(map->getValue(photoKey));
if(val && !(val->getValue().empty())) { _photo = (val->getValue() == "true") ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(enabledKey));
......@@ -292,6 +301,9 @@ void HookPreference::unserialize(Conf::MappingNode *map)
_debug("Hook: Unserialize preference");
if(!map)
return;
val = (Conf::ScalarNode *)(map->getValue(iax2EnabledKey));
if(val) { _iax2Enabled = (val->getValue() == "true") ? true : false; val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(numberAddPrefixKey));
......@@ -386,6 +398,9 @@ void AudioPreference::unserialize(Conf::MappingNode *map)
{
_debug("AudioPreference: Unserialize configuration");
if(!map)
return;
Conf::ScalarNode *val = NULL;
val = (Conf::ScalarNode *)(map->getValue(cardinKey));
......@@ -414,3 +429,122 @@ void AudioPreference::unserialize(Conf::MappingNode *map)
if(val) { _volumespkr = atoi(val->getValue().data()); val = NULL; }
}
ShortcutPreferences::ShortcutPreferences() : _hangup("")
, _pickup("")
, _popup("")
, _toggleHold("")
, _togglePickupHangup("")
{
}
ShortcutPreferences::~ShortcutPreferences() {}
std::map<std::string, int> ShortcutPreferences::getShortcuts()
{
std::map<std::string, int> shortcutsMap;
int shortcut;
shortcutsMap.insert(std::pair<std::string, int>(hangupShortKey, atoi(_hangup.data())));
shortcutsMap.insert(std::pair<std::string, int>(pickupShortKey, atoi(_pickup.data())));
shortcutsMap.insert(std::pair<std::string, int>(popupShortKey, atoi(_popup.data())));
shortcutsMap.insert(std::pair<std::string, int>(toggleHoldShortKey, atoi(_toggleHold.data())));
shortcutsMap.insert(std::pair<std::string, int>(togglePickupHangupShortKey, atoi(_togglePickupHangup.data())));
return shortcutsMap;
}
void ShortcutPreferences::setShortcuts(std::map<std::string, int> shortcut)
{
std::map<std::string, int> map_cpy = shortcut;
std::map<std::string, int>::iterator it;
it = map_cpy.find(hangupShortKey);
if (it != map_cpy.end()) {
std::stringstream hangupstr; hangupstr << it->second;
_hangup = hangupstr.str();
}
it = map_cpy.find(pickupShortKey);
if (it != map_cpy.end()) {
std::stringstream pickupstr; pickupstr << it->second;
_pickup = pickupstr.str();
}
it = map_cpy.find(popupShortKey);
if (it != map_cpy.end()) {
std::stringstream popupstr; popupstr << it->second;
_popup = popupstr.str();
}
it = map_cpy.find(toggleHoldShortKey);
if(it != map_cpy.end()) {
std::stringstream holdstr; holdstr << it->second;
_toggleHold = holdstr.str();
}
it = map_cpy.find(togglePickupHangupShortKey);
if(it != map_cpy.end()) {
std::stringstream togglestr; togglestr << it->second;
_togglePickupHangup = togglestr.str();
}
/*
for (int i = 0; i < (int)shortcutsKeys.size(); i++) {
std::string key = shortcutsKeys.at(i);
it = map_cpy.find(key);
if (it != shortcutsMap.end()) {
Manager::instance().setConfig("Shortcuts", key, it->second);
}
}
*/
}
void ShortcutPreferences::serialize(Conf::YamlEmitter *emitter)
{
_debug("ShortcutPreference: Serialize configuration");
Conf::MappingNode preferencemap(NULL);
Conf::ScalarNode hangup(_hangup);
Conf::ScalarNode pickup(_pickup);
Conf::ScalarNode popup(_popup);
Conf::ScalarNode toggleHold(_toggleHold);
Conf::ScalarNode togglePickupHangup(_togglePickupHangup);
preferencemap.setKeyValue(hangupShortKey, &hangup);
preferencemap.setKeyValue(pickupShortKey, &pickup);
preferencemap.setKeyValue(popupShortKey, &popup);
preferencemap.setKeyValue(toggleHoldShortKey, &toggleHold);
preferencemap.setKeyValue(togglePickupHangupShortKey, &togglePickupHangup);
emitter->serializeShortcutPreference(&preferencemap);
}
void ShortcutPreferences::unserialize(Conf::MappingNode *map)
{
_debug("ShortcutPreference: Unserialize configuration");
if(!map)
return;
Conf::ScalarNode *val = NULL;
val = (Conf::ScalarNode *)(map->getValue(hangupShortKey));
if(val) { _hangup = atoi(val->getValue().data()); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(pickupShortKey));
if(val) { _pickup = atoi(val->getValue().data()); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(popupShortKey));
if(val) { _popup = atoi(val->getValue().data()); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(toggleHoldShortKey));
if(val) { _toggleHold = atoi(val->getValue().data()); val = NULL; }
val = (Conf::ScalarNode *)(map->getValue(togglePickupHangupShortKey));
if(val) { _togglePickupHangup = atoi(val->getValue().data()); val = NULL; }
}
......@@ -87,6 +87,13 @@ const Conf::Key recordpathKey("recordpath");//: /home/msavard/Bureau
const Conf::Key volumemicKey("volumemic");//: 100
const Conf::Key volumespkrKey("volumespkr");//: 100
// shortcut preferences
const Conf::Key hangupShortKey("hangUp");
const Conf::Key pickupShortKey("pickUp");
const Conf::Key popupShortKey("popupWindow");
const Conf::Key toggleHoldShortKey("toggleHold");
const Conf::Key togglePickupHangupShortKey("togglePickupHangup");
class Preferences : public Serializable {
......@@ -355,4 +362,45 @@ class AudioPreference : public Serializable {
};
class ShortcutPreferences : public Serializable {
public:
ShortcutPreferences();
~ShortcutPreferences();
virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(Conf::MappingNode *map);
std::map<std::string, int> getShortcuts(void);
void setShortcuts(std::map<std::string, int> shortcut);
std::string getHangup(void) { return _hangup; }
void setHangup(std::string hangup) { _hangup = hangup; }
std::string getPickup(void) { return _pickup; }
void setPickup(std::string pickup) { _pickup = pickup; }
std::string getPopup(void) { return _popup; }
void setPopup(std::string popup) { _popup = popup; }
std::string getToggleHold(void) { return _toggleHold; }
void setToggleHold(std::string hold) { _toggleHold = hold; }
std::string getTogglePickupHangup(void) { return _togglePickupHangup; }
void setTogglePickupHangup(std::string toggle) { _togglePickupHangup = toggle; }
private:
std::string _hangup;
std::string _pickup;
std::string _popup;
std::string _toggleHold;
std::string _togglePickupHangup;
};
#endif
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