2
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Additional permission under GNU GPL version 3 section 7:
21
* If you modify this program, or any covered work, by linking or
22
* combining it with the OpenSSL project's OpenSSL library (or a
23
* modified version of that library), containing parts covered by the
24
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25
* grants you additional permission to convey the resulting work.
26
* Corresponding Source for a non-source form of such a combination
27
* shall include the source code for the parts of OpenSSL used as well
28
* as that of the covered work.
31
#include "preferences.h"
36
Preferences::Preferences() : _accountOrder ("")
37
, _audioApi (1) // 1 is pulseaudio, 0 alsa
39
, _historyMaxCalls (20)
40
, _notifyMails (false)
41
, _zoneToneChoice (DFT_ZONE) // DFT_ZONE
42
, _registrationExpire (180)
44
, _searchBarDisplay (true)
45
, _zeroConfenable (false)
51
Preferences::~Preferences() {}
54
void Preferences::serialize (Conf::YamlEmitter *emiter)
57
_debug ("Preference: Serialize configuration");
59
Conf::MappingNode preferencemap (NULL);
61
Conf::ScalarNode order (_accountOrder);
62
// std::stringstream audiostr;
63
// audiostr << _audioApi;
64
Conf::ScalarNode audioapi (_audioApi == 1 ? "pulseaudio" : "alsa");
65
std::stringstream histlimitstr;
66
histlimitstr << _historyLimit;
67
Conf::ScalarNode historyLimit (histlimitstr.str());
68
std::stringstream histmaxstr;
69
histmaxstr << _historyMaxCalls;
70
Conf::ScalarNode historyMaxCalls (histmaxstr.str());
71
Conf::ScalarNode notifyMails (_notifyMails ? "true" : "false");
72
Conf::ScalarNode zoneToneChoice (_zoneToneChoice);
73
std::stringstream expirestr;
74
expirestr << _registrationExpire;
75
Conf::ScalarNode registrationExpire (expirestr.str());
76
std::stringstream portstr;
78
Conf::ScalarNode portNum (portstr.str());
79
Conf::ScalarNode searchBarDisplay (_searchBarDisplay ? "true" : "false");
80
Conf::ScalarNode zeroConfenable (_zeroConfenable ? "true" : "false");
81
Conf::ScalarNode md5Hash (_md5Hash ? "true" : "false");
83
preferencemap.setKeyValue (orderKey, &order);
84
preferencemap.setKeyValue (audioApiKey, &audioapi);
85
preferencemap.setKeyValue (historyLimitKey, &historyLimit);
86
preferencemap.setKeyValue (historyMaxCallsKey, &historyMaxCalls);
87
preferencemap.setKeyValue (notifyMailsKey, ¬ifyMails);
88
preferencemap.setKeyValue (zoneToneChoiceKey, &zoneToneChoice);
89
preferencemap.setKeyValue (registrationExpireKey, ®istrationExpire);
90
preferencemap.setKeyValue (portNumKey, &portNum);
91
preferencemap.setKeyValue (searchBarDisplayKey, &searchBarDisplay);
92
preferencemap.setKeyValue (zeroConfenableKey, &zeroConfenable);
93
preferencemap.setKeyValue (md5HashKey, &md5Hash);
95
emiter->serializePreference (&preferencemap);
98
void Preferences::unserialize (Conf::MappingNode *map)
101
_debug ("Preference: Unserialize configuration");
103
Conf::ScalarNode *val;
106
_debug ("Preference: Did not find general preferences");
110
val = (Conf::ScalarNode *) (map->getValue (orderKey));
113
_accountOrder = val->getValue();
117
val = (Conf::ScalarNode *) (map->getValue (audioApiKey));
120
// 1 is pulseaudio, 0 is alsa
121
_audioApi = (val->getValue().compare ("pulseaudio") == 0) ? 1 : 0;
125
val = (Conf::ScalarNode *) (map->getValue (historyLimitKey));
128
_historyLimit = atoi (val->getValue().data());
132
val = (Conf::ScalarNode *) (map->getValue (historyMaxCallsKey));
135
_historyMaxCalls = atoi (val->getValue().data());
139
val = (Conf::ScalarNode *) (map->getValue (notifyMailsKey));
142
_notifyMails = atoi (val->getValue().data());
146
val = (Conf::ScalarNode *) (map->getValue (zoneToneChoiceKey));
149
_zoneToneChoice = val->getValue();
153
val = (Conf::ScalarNode *) (map->getValue (registrationExpireKey));
156
_registrationExpire = atoi (val->getValue().data());
160
val = (Conf::ScalarNode *) (map->getValue (portNumKey));
163
_portNum = atoi (val->getValue().data());
167
val = (Conf::ScalarNode *) (map->getValue (searchBarDisplayKey));
169
if (val && !val->getValue().empty()) {
170
_searchBarDisplay = (val->getValue().compare ("true") == 0) ? true : false;
174
val = (Conf::ScalarNode *) (map->getValue (zeroConfenableKey));
176
if (val && !val->getValue().empty()) {
177
_zeroConfenable = (val->getValue().compare ("true") == 0) ? true : false;
181
val = (Conf::ScalarNode *) (map->getValue (md5HashKey));
183
if (val && !val->getValue().empty()) {
184
_md5Hash = (val->getValue().compare ("true") == 0) ? true : false;
193
VoipPreference::VoipPreference() : _playDtmf (true)
195
, _pulseLength (atoi (DFT_PULSE_LENGTH_STR)) // DFT_PULSE_LENGTH_STR
196
, _symmetricRtp (true)
197
, _zidFile (ZRTP_ZIDFILE) // ZRTP_ZID_FILENAME
202
VoipPreference::~VoipPreference() {}
205
void VoipPreference::serialize (Conf::YamlEmitter *emitter)
207
_debug ("VoipPreference: Serialize configuration");
209
Conf::MappingNode preferencemap (NULL);
211
Conf::ScalarNode playDtmf (_playDtmf ? "true" : "false");
212
Conf::ScalarNode playTones (_playTones ? "true" : "false");
213
std::stringstream pulselengthstr;
214
pulselengthstr << _pulseLength;
215
Conf::ScalarNode pulseLength (pulselengthstr.str());
216
Conf::ScalarNode symmetricRtp (_symmetricRtp ? "true" : "false");
217
Conf::ScalarNode zidFile (_zidFile.c_str());
219
preferencemap.setKeyValue (playDtmfKey, &playDtmf);
220
preferencemap.setKeyValue (playTonesKey, &playTones);
221
preferencemap.setKeyValue (pulseLengthKey, &pulseLength);
222
preferencemap.setKeyValue (symmetricRtpKey, &symmetricRtp);
223
preferencemap.setKeyValue (zidFileKey, &zidFile);
225
emitter->serializeVoipPreference (&preferencemap);
228
void VoipPreference::unserialize (Conf::MappingNode *map)
231
_debug ("VoipPreference: Unserialize configuration");
233
Conf::ScalarNode *val = NULL;
236
_debug ("VoipPreference: Did not find voip preference");
240
val = (Conf::ScalarNode *) (map->getValue (playDtmfKey));
242
if (val && !val->getValue().empty()) {
243
_playDtmf = (val->getValue().compare ("true") == 0) ? true : false;
247
val = (Conf::ScalarNode *) (map->getValue (playTonesKey));
249
if (val && !val->getValue().empty()) {
250
_playTones = (val->getValue().compare ("true") == 0) ? true : false;
254
val = (Conf::ScalarNode *) (map->getValue (pulseLengthKey));
257
_pulseLength = atoi (val->getValue().data());
261
val = (Conf::ScalarNode *) (map->getValue (symmetricRtpKey));
263
if (val && !val->getValue().empty()) {
264
_symmetricRtp = (val->getValue().compare ("true") == 0) ? true : false;
268
val = (Conf::ScalarNode *) (map->getValue (zidFileKey));
271
_zidFile = val->getValue().c_str();
279
AddressbookPreference::AddressbookPreference() : _photo (true)
290
AddressbookPreference::~AddressbookPreference() {}
292
void AddressbookPreference::serialize (Conf::YamlEmitter *emitter)
294
_debug ("Addressbook: Serialize configuration");
296
Conf::MappingNode preferencemap (NULL);
298
Conf::ScalarNode photo (_photo ? "true" : "false");
299
Conf::ScalarNode enabled (_enabled ? "true" : "false");
300
Conf::ScalarNode list (_list);
301
std::stringstream maxresultstr;
302
maxresultstr << _maxResults;
303
Conf::ScalarNode maxResults (maxresultstr.str());
304
Conf::ScalarNode business (_business ? "true" : "false");
305
Conf::ScalarNode home (_home ? "true" : "false");
306
Conf::ScalarNode mobile (_mobile ? "true" : "false");
308
preferencemap.setKeyValue (photoKey, &photo);
309
preferencemap.setKeyValue (enabledKey, &enabled);
310
preferencemap.setKeyValue (listKey, &list);
311
preferencemap.setKeyValue (maxResultsKey, &maxResults);
312
preferencemap.setKeyValue (businessKey, &business);
313
preferencemap.setKeyValue (homeKey, &home);
314
preferencemap.setKeyValue (mobileKey, &mobile);
316
emitter->serializeAddressbookPreference (&preferencemap);
320
void AddressbookPreference::unserialize (Conf::MappingNode *map)
322
_debug ("Addressbook: Unserialize configuration");
324
Conf::ScalarNode *val = NULL;
327
_debug ("Addressbook: Did not find addressbook preferences");
331
val = (Conf::ScalarNode *) (map->getValue (photoKey));
333
if (val && ! (val->getValue().empty())) {
334
_photo = (val->getValue() == "true") ? true : false;
338
val = (Conf::ScalarNode *) (map->getValue (enabledKey));
340
if (val && !val->getValue().empty()) {
341
_enabled = (val->getValue() == "true") ? true : false;
345
val = (Conf::ScalarNode *) (map->getValue (listKey));
348
_list = val->getValue();
352
val = (Conf::ScalarNode *) (map->getValue (maxResultsKey));
355
_maxResults = atoi (val->getValue().data());
359
val = (Conf::ScalarNode *) (map->getValue (businessKey));
361
if (val && !val->getValue().empty()) {
362
_business = (val->getValue() == "true") ? true : false;
366
val = (Conf::ScalarNode *) (map->getValue (homeKey));
368
if (val && !val->getValue().empty()) {
369
_home = (val->getValue() == "true") ? true : false;
373
val = (Conf::ScalarNode *) (map->getValue (mobileKey));
375
if (val && !val->getValue().empty()) {
376
_mobile = (val->getValue() == "true") ? true : false;
383
HookPreference::HookPreference() : _iax2Enabled (false)
384
, _numberAddPrefix ("")
385
, _numberEnabled (false)
386
, _sipEnabled (false)
387
, _urlCommand ("x-www-browser")
388
, _urlSipField ("X-sflphone-url")
393
HookPreference::~HookPreference() {}
395
void HookPreference::serialize (Conf::YamlEmitter *emitter)
397
_debug ("Hook: Serialize configuration");
399
Conf::MappingNode preferencemap (NULL);
401
Conf::ScalarNode iax2Enabled (_iax2Enabled ? "true" : "false");
402
Conf::ScalarNode numberAddPrefix (_numberAddPrefix);
403
Conf::ScalarNode numberEnabled (_numberEnabled ? "true" : "false");
404
Conf::ScalarNode sipEnabled (_sipEnabled ? "true" : "false");
405
Conf::ScalarNode urlCommand (_urlCommand);
406
Conf::ScalarNode urlSipField (_urlSipField);
408
preferencemap.setKeyValue (iax2EnabledKey, &iax2Enabled);
409
preferencemap.setKeyValue (numberAddPrefixKey, &numberAddPrefix);
410
preferencemap.setKeyValue (numberEnabledKey, &numberEnabled);
411
preferencemap.setKeyValue (sipEnabledKey, &sipEnabled);
412
preferencemap.setKeyValue (urlCommandKey, &urlCommand);
413
preferencemap.setKeyValue (urlSipFieldKey, &urlSipField);
415
emitter->serializeHooksPreference (&preferencemap);
418
void HookPreference::unserialize (Conf::MappingNode *map)
420
Conf::ScalarNode *val = NULL;
422
_debug ("Hook: Unserialize preference");
425
_debug ("Hook: Did not find hook preference");
429
val = (Conf::ScalarNode *) (map->getValue (iax2EnabledKey));
432
_iax2Enabled = (val->getValue() == "true") ? true : false;
436
val = (Conf::ScalarNode *) (map->getValue (numberAddPrefixKey));
439
_numberAddPrefix = val->getValue();
443
val = (Conf::ScalarNode *) (map->getValue (numberEnabledKey));
446
_numberEnabled = (val->getValue() == "true") ? true : false;
450
val = (Conf::ScalarNode *) (map->getValue (sipEnabledKey));
453
_sipEnabled = (val->getValue() == "true") ? true : false;
457
val = (Conf::ScalarNode *) (map->getValue (urlCommandKey));
460
_urlCommand = val->getValue();
464
val = (Conf::ScalarNode *) (map->getValue (urlSipFieldKey));
467
_urlSipField = val->getValue();
476
AudioPreference::AudioPreference() : _cardin (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
477
, _cardout (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
478
, _cardring (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
479
, _framesize (atoi (DFT_FRAME_SIZE)) // DFT_FRAME_SIZE
480
, _plugin ("default") // PCM_DEFAULT
481
, _smplrate (44100) // DFT_SAMPLE_RATE
482
, _devicePlayback ("")
484
, _deviceRingtone ("")
485
, _recordpath ("") // DFT_RECORD_PATH
486
, _volumemic (atoi (DFT_VOL_SPKR_STR)) // DFT_VOL_SPKR_STR
487
, _volumespkr (atoi (DFT_VOL_MICRO_STR)) // DFT_VOL_MICRO_STR
488
, _noisereduce (true)
493
AudioPreference::~AudioPreference() {}
495
void AudioPreference::serialize (Conf::YamlEmitter *emitter)
497
_debug ("AudioPreference: Serialize configuration");
499
Conf::MappingNode preferencemap (NULL);
500
Conf::MappingNode alsapreferencemap (NULL);
501
Conf::MappingNode pulsepreferencemap (NULL);
504
std::stringstream instr;
506
Conf::ScalarNode cardin (instr.str()); // 0
507
std::stringstream outstr;
509
Conf::ScalarNode cardout (outstr.str()); // 0
510
std::stringstream ringstr;
511
ringstr << _cardring;
512
Conf::ScalarNode cardring (ringstr.str());// 0
513
std::stringstream framestr;
514
framestr << _framesize;
515
Conf::ScalarNode framesize (framestr.str()); // 20
516
Conf::ScalarNode plugin (_plugin); // default
517
std::stringstream ratestr;
518
ratestr << _smplrate;
519
Conf::ScalarNode smplrate (ratestr.str());// 44100
521
//pulseaudio preference
522
Conf::ScalarNode devicePlayback (_devicePlayback);//:
523
Conf::ScalarNode deviceRecord (_deviceRecord); //:
524
Conf::ScalarNode deviceRingtone (_deviceRingtone); //:
526
// general preference
527
Conf::ScalarNode recordpath (_recordpath); //: /home/msavard/Bureau
528
std::stringstream micstr;
529
micstr << _volumemic;
530
Conf::ScalarNode volumemic (micstr.str()); //: 100
531
std::stringstream spkrstr;
532
spkrstr << _volumespkr;
533
Conf::ScalarNode volumespkr (spkrstr.str()); //: 100
534
Conf::ScalarNode noise (_noisereduce ? "true":"false");
535
preferencemap.setKeyValue (recordpathKey, &recordpath);
536
preferencemap.setKeyValue (volumemicKey, &volumemic);
537
preferencemap.setKeyValue (volumespkrKey, &volumespkr);
539
preferencemap.setKeyValue (alsamapKey, &alsapreferencemap);
540
alsapreferencemap.setKeyValue (cardinKey, &cardin);
541
alsapreferencemap.setKeyValue (cardoutKey, &cardout);
542
alsapreferencemap.setKeyValue (cardringKey, &cardring);
543
alsapreferencemap.setKeyValue (framesizeKey, &framesize);
544
alsapreferencemap.setKeyValue (pluginKey, &plugin);
545
alsapreferencemap.setKeyValue (smplrateKey, &smplrate);
547
preferencemap.setKeyValue (pulsemapKey, &pulsepreferencemap);
548
pulsepreferencemap.setKeyValue (devicePlaybackKey, &devicePlayback);
549
pulsepreferencemap.setKeyValue (deviceRecordKey, &deviceRecord);
550
pulsepreferencemap.setKeyValue (deviceRingtoneKey, &deviceRingtone);
552
preferencemap.setKeyValue (noiseReduceKey, &noise);
554
emitter->serializeAudioPreference (&preferencemap);
558
void AudioPreference::unserialize (Conf::MappingNode *map)
560
_debug ("AudioPreference: Unserialize configuration");
563
_debug ("AudioPreference: Did not find audio preferences");
567
Conf::MappingNode *alsamap = NULL;
568
Conf::MappingNode *pulsemap = NULL;
570
Conf::ScalarNode *val = NULL;
573
val = (Conf::ScalarNode *) (map->getValue (recordpathKey));
576
_recordpath = val->getValue();
580
val = (Conf::ScalarNode *) (map->getValue (volumemicKey));
583
_volumemic = atoi (val->getValue().data());
587
val = (Conf::ScalarNode *) (map->getValue (volumespkrKey));
590
_volumespkr = atoi (val->getValue().data());
594
val = (Conf::ScalarNode *) (map->getValue (noiseReduceKey));
597
_noisereduce = (val->getValue() == "true");
601
alsamap = (Conf::MappingNode *) (map->getValue ("alsa"));
606
val = (Conf::ScalarNode *) (alsamap->getValue (cardinKey));
609
_cardin = atoi (val->getValue().data());
613
val = (Conf::ScalarNode *) (alsamap->getValue (cardoutKey));
616
_cardout = atoi (val->getValue().data());
620
val = (Conf::ScalarNode *) (alsamap->getValue (cardringKey));
623
_cardring = atoi (val->getValue().data());
627
val = (Conf::ScalarNode *) (alsamap->getValue (framesizeKey));
630
_framesize = atoi (val->getValue().data());
634
val = (Conf::ScalarNode *) (alsamap->getValue (smplrateKey));
637
_smplrate = atoi (val->getValue().data());
641
val = (Conf::ScalarNode *) (alsamap->getValue (pluginKey));
644
_plugin = val->getValue();
651
pulsemap = (Conf::MappingNode *) (map->getValue ("pulse"));
656
val = (Conf::ScalarNode *) (pulsemap->getValue (devicePlaybackKey));
659
_devicePlayback = val->getValue();
663
val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRecordKey));
666
_deviceRecord = val->getValue();
670
val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRingtoneKey));
673
_deviceRingtone = val->getValue();
683
ShortcutPreferences::ShortcutPreferences() : _hangup ("")
687
, _togglePickupHangup ("")
692
ShortcutPreferences::~ShortcutPreferences() {}
695
std::map<std::string, std::string> ShortcutPreferences::getShortcuts()
698
std::map<std::string, std::string> shortcutsMap;
700
shortcutsMap.insert (std::pair<std::string, std::string> (hangupShortKey, _hangup));
701
shortcutsMap.insert (std::pair<std::string, std::string> (pickupShortKey, _pickup));
702
shortcutsMap.insert (std::pair<std::string, std::string> (popupShortKey, _popup));
703
shortcutsMap.insert (std::pair<std::string, std::string> (toggleHoldShortKey, _toggleHold));
704
shortcutsMap.insert (std::pair<std::string, std::string> (togglePickupHangupShortKey, _togglePickupHangup));
710
void ShortcutPreferences::setShortcuts (std::map<std::string, std::string> map_cpy)
712
// std::map<std::string, int> map_cpy = shortcut;
713
std::map<std::string, std::string>::iterator it;
715
_debug ("ShortcutPreferences: Set shortcuts");
718
it = map_cpy.find (hangupShortKey);
720
if (it != map_cpy.end()) {
721
_hangup = it->second;
724
it = map_cpy.find (pickupShortKey);
726
if (it != map_cpy.end()) {
727
_pickup = it->second;
730
it = map_cpy.find (popupShortKey);
732
if (it != map_cpy.end()) {
736
it = map_cpy.find (toggleHoldShortKey);
738
if (it != map_cpy.end()) {
739
_toggleHold = it->second;
742
it = map_cpy.find (togglePickupHangupShortKey);
744
if (it != map_cpy.end()) {
745
_togglePickupHangup = it->second;
749
for (int i = 0; i < (int)shortcutsKeys.size(); i++) {
750
std::string key = shortcutsKeys.at(i);
751
it = map_cpy.find(key);
752
if (it != shortcutsMap.end()) {
753
Manager::instance().setConfig("Shortcuts", key, it->second);
760
void ShortcutPreferences::serialize (Conf::YamlEmitter *emitter)
763
_debug ("ShortcutPreference: Serialize configuration");
765
Conf::MappingNode preferencemap (NULL);
767
Conf::ScalarNode hangup (_hangup);
768
Conf::ScalarNode pickup (_pickup);
769
Conf::ScalarNode popup (_popup);
770
Conf::ScalarNode toggleHold (_toggleHold);
771
Conf::ScalarNode togglePickupHangup (_togglePickupHangup);
773
preferencemap.setKeyValue (hangupShortKey, &hangup);
774
preferencemap.setKeyValue (pickupShortKey, &pickup);
775
preferencemap.setKeyValue (popupShortKey, &popup);
776
preferencemap.setKeyValue (toggleHoldShortKey, &toggleHold);
777
preferencemap.setKeyValue (togglePickupHangupShortKey, &togglePickupHangup);
779
emitter->serializeShortcutPreference (&preferencemap);
782
void ShortcutPreferences::unserialize (Conf::MappingNode *map)
784
_debug ("ShortcutPreference: Unserialize shortcut");
787
_debug ("ShortcutPreference: Could not find shortcut preferences");
791
Conf::ScalarNode *val = NULL;
793
val = (Conf::ScalarNode *) (map->getValue (hangupShortKey));
796
_hangup = val->getValue();
800
val = (Conf::ScalarNode *) (map->getValue (pickupShortKey));
803
_pickup = val->getValue();
807
val = (Conf::ScalarNode *) (map->getValue (popupShortKey));
810
_popup = val->getValue();
814
val = (Conf::ScalarNode *) (map->getValue (toggleHoldShortKey));
817
_toggleHold = val->getValue();
821
val = (Conf::ScalarNode *) (map->getValue (togglePickupHangupShortKey));
824
_togglePickupHangup = val->getValue();