From 76fa379a7d6d3a42d85440d2f6469418dd456c3f Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Tue, 27 Jul 2010 14:11:02 -0400
Subject: [PATCH] [#3218] Fix shortcuts

---
 sflphone-client-gnome/src/dbus/dbus.c         |  1 +
 sflphone-client-gnome/src/shortcuts.c         | 15 +++----
 .../src/dbus/configurationmanager.cpp         |  5 +++
 sflphone-common/src/preferences.cpp           | 43 ++++++++-----------
 sflphone-common/src/preferences.h             |  2 +-
 5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c
index 2d66258774..6dd1183c99 100644
--- a/sflphone-client-gnome/src/dbus/dbus.c
+++ b/sflphone-client-gnome/src/dbus/dbus.c
@@ -2297,6 +2297,7 @@ dbus_get_shortcuts(void)
 {
   GError *error = NULL;
   GHashTable * shortcuts;
+
   if (!org_sflphone_SFLphone_ConfigurationManager_get_shortcuts(
       configurationManagerProxy, &shortcuts, &error))
     {
diff --git a/sflphone-client-gnome/src/shortcuts.c b/sflphone-client-gnome/src/shortcuts.c
index 652d4496ea..4e95667171 100644
--- a/sflphone-client-gnome/src/shortcuts.c
+++ b/sflphone-client-gnome/src/shortcuts.c
@@ -387,6 +387,8 @@ shortcuts_initialize_bindings ()
   gchar* action, *maskAndKey, *token1, *token2 = NULL;
   guint mask, key = 0;
 
+  DEBUG("Shortcuts: Initialize bindings");
+
   // get shortcuts stored in config through dbus
   shortcutsMap = dbus_get_shortcuts ();
 
@@ -402,7 +404,6 @@ shortcuts_initialize_bindings ()
       action = shortcutsKeysElement->data;
       maskAndKey = g_strdup (g_hash_table_lookup (shortcutsMap, action));
 
-      DEBUG("-------------------- maskAndKey %s", maskAndKey);
       token1 = strtok (maskAndKey, "x");
       token2 = strtok (NULL, "x");
 
@@ -411,7 +412,7 @@ shortcuts_initialize_bindings ()
 
       // Value not setted
       if (token1 && token2){
-	DEBUG("token1 %s, token2 %s", token1, token2);
+	DEBUG("Ahortcuts: token1 %s, token2 %s", token1, token2);
 	  
 	mask = atoi (token1);
 	key = atoi (token2);
@@ -465,17 +466,15 @@ filter_keys (const GdkXEvent *xevent, const GdkEvent *event, gpointer data)
   int i = 0;
 
   xev = (XEvent *) xevent;
-  if (xev->type != KeyPress)
-    {
-      return GDK_FILTER_CONTINUE;
-    }
+  if (xev->type != KeyPress) {
+    return GDK_FILTER_CONTINUE;
+  }
 
   key = (XKeyEvent *) xevent;
   keystate = key->state & ~(Mod2Mask | Mod5Mask | LockMask);
 
   // try to find corresponding action
-  while (accelerators_list[i].action != NULL)
-    {
+  while (accelerators_list[i].action != NULL) {
       if (accelerators_list[i].key == key->keycode && accelerators_list[i].mask
           == keystate)
         {
diff --git a/sflphone-common/src/dbus/configurationmanager.cpp b/sflphone-common/src/dbus/configurationmanager.cpp
index 8f0e2bd02d..e64a4edff4 100755
--- a/sflphone-common/src/dbus/configurationmanager.cpp
+++ b/sflphone-common/src/dbus/configurationmanager.cpp
@@ -733,6 +733,8 @@ std::map<std::string, std::string> ConfigurationManager::getShortcuts() {
 void ConfigurationManager::setShortcuts(
 		const std::map<std::string, std::string>& shortcutsMap) {
 
+        std::map<std::string, std::string> map_cpy = shortcutsMap;
+  /*
 	std::map<std::string, std::string> map_cpy = shortcutsMap;
 	std::map<std::string, std::string>::iterator it;
 
@@ -740,9 +742,12 @@ void ConfigurationManager::setShortcuts(
 		std::string key = shortcutsKeys.at(i);
 		it = map_cpy.find(key);
 		if (it != shortcutsMap.end()) {
+		         
 			Manager::instance().setConfig("Shortcuts", key, it->second);
 		}
 	}
+  */
+        Manager::instance().shortcutPreferences.setShortcuts(map_cpy);
 
 	Manager::instance().saveConfig();
 }
diff --git a/sflphone-common/src/preferences.cpp b/sflphone-common/src/preferences.cpp
index 70fb6eb740..23566f24d2 100644
--- a/sflphone-common/src/preferences.cpp
+++ b/sflphone-common/src/preferences.cpp
@@ -444,54 +444,49 @@ ShortcutPreferences::ShortcutPreferences() : _hangup("")
 ShortcutPreferences::~ShortcutPreferences() {}
 
 
-std::map<std::string, std::string> ShortcutPreferences::getShortcuts() 
+std::map<std::string, std::string> ShortcutPreferences::getShortcuts()
 {
 
   std::map<std::string, std::string> shortcutsMap;
 
-  shortcutsMap.insert(std::pair<std::string, std::string>(hangupShortKey, _hangup.data()));
-  shortcutsMap.insert(std::pair<std::string, std::string>(pickupShortKey, _pickup.data()));
-  shortcutsMap.insert(std::pair<std::string, std::string>(popupShortKey, _popup.data()));
-  shortcutsMap.insert(std::pair<std::string, std::string>(toggleHoldShortKey, _toggleHold.data()));
-  shortcutsMap.insert(std::pair<std::string, std::string>(togglePickupHangupShortKey, _togglePickupHangup.data()));
+  shortcutsMap.insert(std::pair<std::string, std::string>(hangupShortKey, _hangup));
+  shortcutsMap.insert(std::pair<std::string, std::string>(pickupShortKey, _pickup));
+  shortcutsMap.insert(std::pair<std::string, std::string>(popupShortKey, _popup));
+  shortcutsMap.insert(std::pair<std::string, std::string>(toggleHoldShortKey, _toggleHold));
+  shortcutsMap.insert(std::pair<std::string, std::string>(togglePickupHangupShortKey, _togglePickupHangup));
 
   return shortcutsMap;
 }
 
 
-void ShortcutPreferences::setShortcuts(std::map<std::string, int> shortcut)
+void ShortcutPreferences::setShortcuts(std::map<std::string, std::string> map_cpy)
 {
-  std::map<std::string, int> map_cpy = shortcut;
-  std::map<std::string, int>::iterator it;
+  // std::map<std::string, int> map_cpy = shortcut;
+  std::map<std::string, std::string>::iterator it;
 
   it = map_cpy.find(hangupShortKey);
   if (it != map_cpy.end()) {
-    std::stringstream hangupstr; hangupstr << it->second;
-    _hangup = hangupstr.str();
+    _hangup = it->second;
   }
 
   it = map_cpy.find(pickupShortKey);
   if (it != map_cpy.end()) {
-    std::stringstream pickupstr; pickupstr << it->second; 
-    _pickup = pickupstr.str();
+    _pickup = it->second;
   }
 
   it = map_cpy.find(popupShortKey);
   if (it != map_cpy.end()) {
-    std::stringstream popupstr; popupstr << it->second;
-    _popup = popupstr.str();
+    _popup = it->second;
   }
 
   it = map_cpy.find(toggleHoldShortKey);
   if(it != map_cpy.end()) {
-    std::stringstream holdstr; holdstr << it->second;
-    _toggleHold = holdstr.str();
+    _toggleHold = it->second;
   }
 
   it = map_cpy.find(togglePickupHangupShortKey);
   if(it != map_cpy.end()) {
-    std::stringstream togglestr; togglestr << it->second;
-    _togglePickupHangup = togglestr.str();
+    _togglePickupHangup = it->second;
   }
   /*
   for (int i = 0; i < (int)shortcutsKeys.size(); i++) {
@@ -537,13 +532,13 @@ void ShortcutPreferences::unserialize(Conf::MappingNode *map)
   Conf::ScalarNode *val = NULL;
 
   val = (Conf::ScalarNode *)(map->getValue(hangupShortKey));
-  if(val) { _hangup = atoi(val->getValue().data()); val = NULL; }
+  if(val) { _hangup = val->getValue(); val = NULL; }
   val = (Conf::ScalarNode *)(map->getValue(pickupShortKey));
-  if(val) { _pickup = atoi(val->getValue().data()); val = NULL; }
+  if(val) { _pickup = val->getValue(); val = NULL; }
   val = (Conf::ScalarNode *)(map->getValue(popupShortKey));
-  if(val) { _popup = atoi(val->getValue().data()); val = NULL; }
+  if(val) { _popup = val->getValue(); val = NULL; }
   val = (Conf::ScalarNode *)(map->getValue(toggleHoldShortKey));
-  if(val) { _toggleHold = atoi(val->getValue().data()); val = NULL; }
+  if(val) { _toggleHold = val->getValue(); val = NULL; }
   val = (Conf::ScalarNode *)(map->getValue(togglePickupHangupShortKey));
-  if(val) { _togglePickupHangup = atoi(val->getValue().data()); val = NULL; }
+  if(val) { _togglePickupHangup = val->getValue(); val = NULL; }
 }
diff --git a/sflphone-common/src/preferences.h b/sflphone-common/src/preferences.h
index 34b42f4227..cc3d8e3804 100755
--- a/sflphone-common/src/preferences.h
+++ b/sflphone-common/src/preferences.h
@@ -375,8 +375,8 @@ class ShortcutPreferences : public Serializable {
 
   virtual void unserialize(Conf::MappingNode *map);
 
+  void setShortcuts(std::map<std::string, std::string> shortcut);
   std::map<std::string, std::string> getShortcuts(void);
-  void setShortcuts(std::map<std::string, int> shortcut);
 
   std::string getHangup(void) { return _hangup; }
   void setHangup(std::string hangup) { _hangup = hangup; }
-- 
GitLab