preferences.cpp 19.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
 *  Author: Alexandre Savard <alexandre.savard@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.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

#include "preferences.h"
#include <sstream>
33
#include "global.h"
34
#include "user_cfg.h"
35 36 37 38 39 40

Preferences::Preferences() :  _accountOrder("")
			   , _audioApi(0)
			   , _historyLimit(30)
			   , _historyMaxCalls(20)
			   , _notifyMails(false)
41
			   , _zoneToneChoice(DFT_ZONE) // DFT_ZONE
42 43 44 45 46 47 48 49 50 51 52 53
			   , _registrationExpire(180)
			   , _portNum(5060)
			   , _searchBarDisplay(true)
			   , _zeroConfenable(false)
                           , _md5Hash(false)
{

}

Preferences::~Preferences() {}


54
void Preferences::serialize(Conf::YamlEmitter *emiter) 
55 56
{

57 58
  _debug("Preference: Serialize configuration");

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  Conf::MappingNode preferencemap(NULL);
  
  Conf::ScalarNode order(_accountOrder);
  std::stringstream audiostr; audiostr << _audioApi; 
  Conf::ScalarNode audioapi(audiostr.str());
  std::stringstream histlimitstr; histlimitstr << _historyLimit;
  Conf::ScalarNode historyLimit(histlimitstr.str());
  std::stringstream histmaxstr; histmaxstr << _historyMaxCalls;
  Conf::ScalarNode historyMaxCalls(histmaxstr.str());
  Conf::ScalarNode notifyMails(_notifyMails ? "true" : "false");
  Conf::ScalarNode zoneToneChoice(_zoneToneChoice);
  std::stringstream expirestr; expirestr << _registrationExpire;
  Conf::ScalarNode registrationExpire(expirestr.str());
  std::stringstream portstr; portstr << _portNum;
  Conf::ScalarNode portNum(portstr.str());
  Conf::ScalarNode searchBarDisplay(_searchBarDisplay ? "true" : "false");
  Conf::ScalarNode zeroConfenable(_zeroConfenable ? "true" : "false");
  Conf::ScalarNode md5Hash(_md5Hash ? "true" : "false");

  preferencemap.setKeyValue(orderKey, &order);
  preferencemap.setKeyValue(audioApiKey, &audioapi);
  preferencemap.setKeyValue(historyLimitKey, &historyLimit);
  preferencemap.setKeyValue(historyMaxCallsKey, &historyMaxCalls);
  preferencemap.setKeyValue(notifyMailsKey, &notifyMails);
  preferencemap.setKeyValue(zoneToneChoiceKey, &zoneToneChoice);
  preferencemap.setKeyValue(registrationExpireKey, &registrationExpire);
  preferencemap.setKeyValue(portNumKey, &portNum);
  preferencemap.setKeyValue(searchBarDisplayKey, &searchBarDisplay);
  preferencemap.setKeyValue(zeroConfenableKey, &zeroConfenable);
  preferencemap.setKeyValue(md5HashKey, &md5Hash);

Alexandre Savard's avatar
Alexandre Savard committed
90
  emiter->serializePreference(&preferencemap);
91 92 93 94 95
}

void Preferences::unserialize(Conf::MappingNode *map)
{

96 97
  _debug("Preference: Unserialize configuration");

98 99
  Conf::ScalarNode *val;

100 101 102
  if(!map)
      return;

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  val = (Conf::ScalarNode *)(map->getValue(orderKey));
  if(val) { _accountOrder = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(audioApiKey));
  if(val) { _audioApi = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(historyLimitKey));
  if(val) { _historyLimit = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(historyMaxCallsKey));
  if(val) { _historyMaxCalls = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(notifyMailsKey));
  if(val) { _notifyMails = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(zoneToneChoiceKey));
  if(val) { _zoneToneChoice = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(registrationExpireKey));
  if(val) { _registrationExpire = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(portNumKey));
  if(val) { _portNum = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(searchBarDisplayKey));
120
  if(val && !val->getValue().empty()) { _searchBarDisplay = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
121
  val = (Conf::ScalarNode *)(map->getValue(zeroConfenableKey));
122
  if(val && !val->getValue().empty()) { _zeroConfenable = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
123
  val = (Conf::ScalarNode *)(map->getValue(md5HashKey));
124 125 126 127 128 129 130 131 132
  if(val && !val->getValue().empty()) { _md5Hash = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }


  
}


VoipPreference::VoipPreference() :  _playDtmf(true)
				 , _playTones(true)
133
				 , _pulseLength(atoi(DFT_PULSE_LENGTH_STR))// DFT_PULSE_LENGTH_STR   
134 135
				 , _sendDtmfAs(0)
				 , _symmetricRtp(true)
136
                                 , _zidFile(ZRTP_ZIDFILE)// ZRTP_ZID_FILENAME
137 138 139 140 141 142 143 144 145
{

}

VoipPreference::~VoipPreference() {}


void VoipPreference::serialize(Conf::YamlEmitter *emitter) 
{
146 147
  _debug("VoipPreference: Serialize configuration");

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  Conf::MappingNode preferencemap(NULL);

  Conf::ScalarNode playDtmf(_playDtmf ? "true" : "false");
  Conf::ScalarNode playTones(_playTones ? "true" : "false");
  std::stringstream pulselengthstr; pulselengthstr << _pulseLength;
  Conf::ScalarNode pulseLength(pulselengthstr.str());
  std::stringstream senddtmfstr; senddtmfstr << _sendDtmfAs;
  Conf::ScalarNode sendDtmfAs(senddtmfstr.str());
  Conf::ScalarNode symmetricRtp(_symmetricRtp ? "true" : "false");
  Conf::ScalarNode zidFile(_zidFile.c_str());

  preferencemap.setKeyValue(playDtmfKey, &playDtmf);
  preferencemap.setKeyValue(playTonesKey, &playTones);
  preferencemap.setKeyValue(pulseLengthKey, &pulseLength);
  preferencemap.setKeyValue(sendDtmfAsKey, &sendDtmfAs);
  preferencemap.setKeyValue(symmetricRtpKey, &symmetricRtp);
  preferencemap.setKeyValue(zidFileKey, &zidFile);

  emitter->serializeVoipPreference(&preferencemap);
}

void VoipPreference::unserialize(Conf::MappingNode *map) 
{

  _debug("VoipPreference: Unserialize configuration");
173

174
  Conf::ScalarNode *val = NULL;
175

176 177 178
  if(!map)
      return;

179 180 181 182 183 184 185 186 187 188 189 190
  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));
  if(val && !val->getValue().empty()) { _playTones = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(pulseLengthKey));
  if(val) { _pulseLength = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(sendDtmfAsKey));
  if(val) { _sendDtmfAs = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(symmetricRtpKey));
  if(val && !val->getValue().empty()) { _symmetricRtp = (val->getValue().compare("true") == 0) ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(zidFileKey));
  if(val) { _zidFile = val->getValue().c_str(); val = NULL; }
191
  
192
}
193 194 195



196
AddressbookPreference::AddressbookPreference() : _photo(true) 
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
					       , _enabled(true)
					       , _list("")
					       , _maxResults(25)
					       , _business(true)
					       , _home(true)
					       , _mobile(true)
{

}

AddressbookPreference::~AddressbookPreference() {}

void AddressbookPreference::serialize(Conf::YamlEmitter *emitter)
{
  _debug("Addressbook: Serialize configuration");
  
  Conf::MappingNode preferencemap(NULL);

  Conf::ScalarNode photo(_photo ? "true" : "false");
  Conf::ScalarNode enabled(_enabled ? "true" : "false");
  Conf::ScalarNode list(_list);
  std::stringstream maxresultstr; maxresultstr << _maxResults;
  Conf::ScalarNode maxResults(maxresultstr.str());
  Conf::ScalarNode business(_business ? "true" : "false");
  Conf::ScalarNode home(_home ? "true" : "false");
  Conf::ScalarNode mobile(_mobile ? "true" : "false");

  preferencemap.setKeyValue(photoKey, &photo);
  preferencemap.setKeyValue(enabledKey, &enabled);
  preferencemap.setKeyValue(listKey, &list);
  preferencemap.setKeyValue(maxResultsKey, &maxResults);
  preferencemap.setKeyValue(businessKey, &business);
  preferencemap.setKeyValue(homeKey, &home);
  preferencemap.setKeyValue(mobileKey, &mobile);

  emitter->serializeAddressbookPreference(&preferencemap);

}

void AddressbookPreference::unserialize(Conf::MappingNode *map)
{
  _debug("Addressbook: Unserialize configuration");

  Conf::ScalarNode *val = NULL;

242 243 244
  if(!map)
      return;

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
  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));
  if(val && !val->getValue().empty()) { _enabled = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(listKey));
  if(val) { _list = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(maxResultsKey));
  if(val) { _maxResults = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(businessKey));
  if(val && !val->getValue().empty()) { _business = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(homeKey));
  if(val && !val->getValue().empty()) { _home = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(mobileKey));
  if(val && !val->getValue().empty()) { _mobile = (val->getValue() == "true") ? true : false; val = NULL; }
  
}


HookPreference::HookPreference() : _iax2Enabled(false)
264
				 , _numberAddPrefix("")
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
				 , _numberEnabled(false)
				 , _sipEnabled(false)
				 , _urlCommand("x-www-browser")
				 , _urlSipField("X-sflphone-url")
{

}

HookPreference::~HookPreference() {}

void HookPreference::serialize(Conf::YamlEmitter *emitter) 
{
  _debug("Hook: Serialize configuration");

  Conf::MappingNode preferencemap(NULL);

  Conf::ScalarNode iax2Enabled(_iax2Enabled ? "true" : "false");
282
  Conf::ScalarNode numberAddPrefix(_numberAddPrefix);
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  Conf::ScalarNode numberEnabled(_numberEnabled ? "true" : "false");
  Conf::ScalarNode sipEnabled(_sipEnabled ? "true" : "false");
  Conf::ScalarNode urlCommand(_urlCommand);
  Conf::ScalarNode urlSipField(_urlSipField);

  preferencemap.setKeyValue(iax2EnabledKey, &iax2Enabled);
  preferencemap.setKeyValue(numberAddPrefixKey, &numberAddPrefix);
  preferencemap.setKeyValue(numberEnabledKey, &numberEnabled);
  preferencemap.setKeyValue(sipEnabledKey, &sipEnabled);
  preferencemap.setKeyValue(urlCommandKey, &urlCommand);
  preferencemap.setKeyValue(urlSipFieldKey, &urlSipField);

  emitter->serializeHooksPreference(&preferencemap);
}

void HookPreference::unserialize(Conf::MappingNode *map) 
{
  Conf::ScalarNode *val = NULL;

  _debug("Hook: Unserialize preference");

304 305 306
  if(!map)
      return;

307 308 309
  val = (Conf::ScalarNode *)(map->getValue(iax2EnabledKey));
  if(val) { _iax2Enabled = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(numberAddPrefixKey));
310
  if(val) { _numberAddPrefix = val->getValue(); val = NULL; }
311 312 313 314 315 316 317 318 319 320 321 322 323 324
  val = (Conf::ScalarNode *)(map->getValue(numberEnabledKey));
  if(val) { _numberEnabled = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(sipEnabledKey));
  if(val) { _sipEnabled = (val->getValue() == "true") ? true : false; val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(urlCommandKey));
  if(val) { _urlCommand = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(urlSipFieldKey));
  if(val) { _urlSipField = val->getValue(); val = NULL; }
  

}



325 326 327 328
AudioPreference::AudioPreference() : _cardin(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
				   , _cardout(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
				   , _cardring(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
				   , _framesize(atoi(DFT_FRAME_SIZE)) // DFT_FRAME_SIZE
329 330
				   , _plugin("default") // PCM_DEFAULT
				   , _smplrate(44100) // DFT_SAMPLE_RATE
331 332 333
				   , _devicePlayback("")
				   , _deviceRecord("")
				   , _deviceRingtone("")
334
				   , _recordpath("") // DFT_RECORD_PATH
335 336
				   , _volumemic(atoi(DFT_VOL_SPKR_STR)) // DFT_VOL_SPKR_STR
				   , _volumespkr(atoi(DFT_VOL_MICRO_STR)) // DFT_VOL_MICRO_STR
337 338 339 340 341 342 343 344
{

}

AudioPreference::~AudioPreference() {}

void AudioPreference::serialize(Conf::YamlEmitter *emitter) 
{
345 346
  _debug("AudioPreference: Serialize configuration");

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
  Conf::MappingNode preferencemap(NULL);
  Conf::MappingNode alsapreferencemap(NULL);
  Conf::MappingNode pulsepreferencemap(NULL);

    // alsa preference
  std::stringstream instr; instr << _cardin;
  Conf::ScalarNode cardin(instr.str()); // 0
  std::stringstream outstr; outstr << _cardout;
  Conf::ScalarNode cardout(outstr.str()); // 0
  std::stringstream ringstr; ringstr << _cardring;
  Conf::ScalarNode cardring(ringstr.str());// 0
  std::stringstream framestr; framestr << _framesize;
  Conf::ScalarNode framesize(framestr.str()); // 20
  Conf::ScalarNode plugin(_plugin); // default
  std::stringstream ratestr; ratestr << _smplrate;
  Conf::ScalarNode smplrate(ratestr.str());// 44100
   
  //pulseaudio preference
  Conf::ScalarNode devicePlayback(_devicePlayback);//:
  Conf::ScalarNode deviceRecord(_deviceRecord); //:
  Conf::ScalarNode deviceRingtone(_deviceRingtone); //:

  // general preference
  Conf::ScalarNode recordpath(_recordpath); //: /home/msavard/Bureau
  std::stringstream micstr; micstr << _volumemic;
  Conf::ScalarNode volumemic(micstr.str()); //:  100
  std::stringstream spkrstr; spkrstr << _volumespkr;
  Conf::ScalarNode volumespkr(spkrstr.str()); //: 100

  preferencemap.setKeyValue(recordpathKey, &recordpath);
  preferencemap.setKeyValue(volumemicKey, &volumemic);
  preferencemap.setKeyValue(volumespkrKey, &volumespkr);
  
  preferencemap.setKeyValue(alsamapKey, &alsapreferencemap);
  alsapreferencemap.setKeyValue(cardinKey, &cardin);
  alsapreferencemap.setKeyValue(cardoutKey, &cardout);
  alsapreferencemap.setKeyValue(cardringKey, &cardring);
  alsapreferencemap.setKeyValue(framesizeKey, &framesize);
  alsapreferencemap.setKeyValue(pluginKey, &plugin);
  alsapreferencemap.setKeyValue(smplrateKey, &smplrate);

  preferencemap.setKeyValue(pulsemapKey, &pulsepreferencemap);
  pulsepreferencemap.setKeyValue(devicePlaybackKey, &devicePlayback);
  pulsepreferencemap.setKeyValue(deviceRecordKey, &deviceRecord);
  pulsepreferencemap.setKeyValue(deviceRingtoneKey, &deviceRingtone);

  emitter->serializeAudioPreference(&preferencemap);
  
}

void AudioPreference::unserialize(Conf::MappingNode *map) 
{
399 400
  _debug("AudioPreference: Unserialize configuration");

401 402 403
  if(!map)
      return;

404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
  Conf::ScalarNode *val = NULL;

  val = (Conf::ScalarNode *)(map->getValue(cardinKey));
  if(val) { _cardin = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(cardoutKey));
  if(val) { _cardout = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(cardringKey));
  if(val) { _cardring = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(framesizeKey));
  if(val) { _framesize = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(smplrateKey));
  if(val) { _smplrate = atoi(val->getValue().data()); val = NULL; }

  val = (Conf::ScalarNode *)(map->getValue(devicePlaybackKey));
  if(val) { _devicePlayback = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(deviceRecordKey));
  if(val) { _deviceRecord = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(deviceRingtoneKey));
  if(val) { _deviceRingtone = val->getValue(); val = NULL; }

  val = (Conf::ScalarNode *)(map->getValue(recordpathKey));
  if(val) { _recordpath = val->getValue(); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(volumemicKey));
  if(val) { _volumemic = atoi(val->getValue().data()); val = NULL; }
  val = (Conf::ScalarNode *)(map->getValue(volumespkrKey));
  if(val) { _volumespkr = atoi(val->getValue().data()); val = NULL; }

}
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446



ShortcutPreferences::ShortcutPreferences() : _hangup("") 
					   , _pickup("")
					   , _popup("")
					   , _toggleHold("")
					   , _togglePickupHangup("")
{

}

ShortcutPreferences::~ShortcutPreferences() {}


Alexandre Savard's avatar
Alexandre Savard committed
447
std::map<std::string, std::string> ShortcutPreferences::getShortcuts()
448 449
{

450
  std::map<std::string, std::string> shortcutsMap;
451

Alexandre Savard's avatar
Alexandre Savard committed
452 453 454 455 456
  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));
457 458 459 460 461

  return shortcutsMap;
}


Alexandre Savard's avatar
Alexandre Savard committed
462
void ShortcutPreferences::setShortcuts(std::map<std::string, std::string> map_cpy)
463
{
Alexandre Savard's avatar
Alexandre Savard committed
464 465
  // std::map<std::string, int> map_cpy = shortcut;
  std::map<std::string, std::string>::iterator it;
466 467 468

  it = map_cpy.find(hangupShortKey);
  if (it != map_cpy.end()) {
Alexandre Savard's avatar
Alexandre Savard committed
469
    _hangup = it->second;
470 471 472 473
  }

  it = map_cpy.find(pickupShortKey);
  if (it != map_cpy.end()) {
Alexandre Savard's avatar
Alexandre Savard committed
474
    _pickup = it->second;
475 476 477 478
  }

  it = map_cpy.find(popupShortKey);
  if (it != map_cpy.end()) {
Alexandre Savard's avatar
Alexandre Savard committed
479
    _popup = it->second;
480 481 482 483
  }

  it = map_cpy.find(toggleHoldShortKey);
  if(it != map_cpy.end()) {
Alexandre Savard's avatar
Alexandre Savard committed
484
    _toggleHold = it->second;
485 486 487 488
  }

  it = map_cpy.find(togglePickupHangupShortKey);
  if(it != map_cpy.end()) {
Alexandre Savard's avatar
Alexandre Savard committed
489
    _togglePickupHangup = it->second;
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
  }
  /*
  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));
Alexandre Savard's avatar
Alexandre Savard committed
535
  if(val) { _hangup = val->getValue(); val = NULL; }
536
  val = (Conf::ScalarNode *)(map->getValue(pickupShortKey));
Alexandre Savard's avatar
Alexandre Savard committed
537
  if(val) { _pickup = val->getValue(); val = NULL; }
538
  val = (Conf::ScalarNode *)(map->getValue(popupShortKey));
Alexandre Savard's avatar
Alexandre Savard committed
539
  if(val) { _popup = val->getValue(); val = NULL; }
540
  val = (Conf::ScalarNode *)(map->getValue(toggleHoldShortKey));
Alexandre Savard's avatar
Alexandre Savard committed
541
  if(val) { _toggleHold = val->getValue(); val = NULL; }
542
  val = (Conf::ScalarNode *)(map->getValue(togglePickupHangupShortKey));
Alexandre Savard's avatar
Alexandre Savard committed
543
  if(val) { _togglePickupHangup = val->getValue(); val = NULL; }
544
}