~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/preferences.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
 
3
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
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.
 
29
 */
 
30
 
 
31
#include "preferences.h"
 
32
#include <sstream>
 
33
#include "global.h"
 
34
#include "user_cfg.h"
 
35
 
 
36
Preferences::Preferences() :  _accountOrder ("")
 
37
    , _audioApi (1) // 1 is pulseaudio, 0 alsa
 
38
    , _historyLimit (30)
 
39
    , _historyMaxCalls (20)
 
40
    , _notifyMails (false)
 
41
    , _zoneToneChoice (DFT_ZONE) // DFT_ZONE
 
42
    , _registrationExpire (180)
 
43
    , _portNum (5060)
 
44
    , _searchBarDisplay (true)
 
45
    , _zeroConfenable (false)
 
46
    , _md5Hash (false)
 
47
{
 
48
 
 
49
}
 
50
 
 
51
Preferences::~Preferences() {}
 
52
 
 
53
 
 
54
void Preferences::serialize (Conf::YamlEmitter *emiter)
 
55
{
 
56
 
 
57
    _debug ("Preference: Serialize configuration");
 
58
 
 
59
    Conf::MappingNode preferencemap (NULL);
 
60
 
 
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;
 
77
    portstr << _portNum;
 
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");
 
82
 
 
83
    preferencemap.setKeyValue (orderKey, &order);
 
84
    preferencemap.setKeyValue (audioApiKey, &audioapi);
 
85
    preferencemap.setKeyValue (historyLimitKey, &historyLimit);
 
86
    preferencemap.setKeyValue (historyMaxCallsKey, &historyMaxCalls);
 
87
    preferencemap.setKeyValue (notifyMailsKey, &notifyMails);
 
88
    preferencemap.setKeyValue (zoneToneChoiceKey, &zoneToneChoice);
 
89
    preferencemap.setKeyValue (registrationExpireKey, &registrationExpire);
 
90
    preferencemap.setKeyValue (portNumKey, &portNum);
 
91
    preferencemap.setKeyValue (searchBarDisplayKey, &searchBarDisplay);
 
92
    preferencemap.setKeyValue (zeroConfenableKey, &zeroConfenable);
 
93
    preferencemap.setKeyValue (md5HashKey, &md5Hash);
 
94
 
 
95
    emiter->serializePreference (&preferencemap);
 
96
}
 
97
 
 
98
void Preferences::unserialize (Conf::MappingNode *map)
 
99
{
 
100
 
 
101
    _debug ("Preference: Unserialize configuration");
 
102
 
 
103
    Conf::ScalarNode *val;
 
104
 
 
105
    if (!map) {
 
106
        _debug ("Preference: Did not find general preferences");
 
107
        return;
 
108
    }
 
109
 
 
110
    val = (Conf::ScalarNode *) (map->getValue (orderKey));
 
111
 
 
112
    if (val) {
 
113
        _accountOrder = val->getValue();
 
114
        val = NULL;
 
115
    }
 
116
 
 
117
    val = (Conf::ScalarNode *) (map->getValue (audioApiKey));
 
118
 
 
119
    if (val) {
 
120
        // 1 is pulseaudio, 0 is alsa
 
121
        _audioApi = (val->getValue().compare ("pulseaudio") == 0) ? 1 : 0;
 
122
        val = NULL;
 
123
    }
 
124
 
 
125
    val = (Conf::ScalarNode *) (map->getValue (historyLimitKey));
 
126
 
 
127
    if (val) {
 
128
        _historyLimit = atoi (val->getValue().data());
 
129
        val = NULL;
 
130
    }
 
131
 
 
132
    val = (Conf::ScalarNode *) (map->getValue (historyMaxCallsKey));
 
133
 
 
134
    if (val) {
 
135
        _historyMaxCalls = atoi (val->getValue().data());
 
136
        val = NULL;
 
137
    }
 
138
 
 
139
    val = (Conf::ScalarNode *) (map->getValue (notifyMailsKey));
 
140
 
 
141
    if (val) {
 
142
        _notifyMails = atoi (val->getValue().data());
 
143
        val = NULL;
 
144
    }
 
145
 
 
146
    val = (Conf::ScalarNode *) (map->getValue (zoneToneChoiceKey));
 
147
 
 
148
    if (val) {
 
149
        _zoneToneChoice = val->getValue();
 
150
        val = NULL;
 
151
    }
 
152
 
 
153
    val = (Conf::ScalarNode *) (map->getValue (registrationExpireKey));
 
154
 
 
155
    if (val) {
 
156
        _registrationExpire = atoi (val->getValue().data());
 
157
        val = NULL;
 
158
    }
 
159
 
 
160
    val = (Conf::ScalarNode *) (map->getValue (portNumKey));
 
161
 
 
162
    if (val) {
 
163
        _portNum = atoi (val->getValue().data());
 
164
        val = NULL;
 
165
    }
 
166
 
 
167
    val = (Conf::ScalarNode *) (map->getValue (searchBarDisplayKey));
 
168
 
 
169
    if (val && !val->getValue().empty()) {
 
170
        _searchBarDisplay = (val->getValue().compare ("true") == 0) ? true : false;
 
171
        val = NULL;
 
172
    }
 
173
 
 
174
    val = (Conf::ScalarNode *) (map->getValue (zeroConfenableKey));
 
175
 
 
176
    if (val && !val->getValue().empty()) {
 
177
        _zeroConfenable = (val->getValue().compare ("true") == 0) ? true : false;
 
178
        val = NULL;
 
179
    }
 
180
 
 
181
    val = (Conf::ScalarNode *) (map->getValue (md5HashKey));
 
182
 
 
183
    if (val && !val->getValue().empty()) {
 
184
        _md5Hash = (val->getValue().compare ("true") == 0) ? true : false;
 
185
        val = NULL;
 
186
    }
 
187
 
 
188
 
 
189
 
 
190
}
 
191
 
 
192
 
 
193
VoipPreference::VoipPreference() :  _playDtmf (true)
 
194
    , _playTones (true)
 
195
    , _pulseLength (atoi (DFT_PULSE_LENGTH_STR)) // DFT_PULSE_LENGTH_STR
 
196
    , _symmetricRtp (true)
 
197
    , _zidFile (ZRTP_ZIDFILE) // ZRTP_ZID_FILENAME
 
198
{
 
199
 
 
200
}
 
201
 
 
202
VoipPreference::~VoipPreference() {}
 
203
 
 
204
 
 
205
void VoipPreference::serialize (Conf::YamlEmitter *emitter)
 
206
{
 
207
    _debug ("VoipPreference: Serialize configuration");
 
208
 
 
209
    Conf::MappingNode preferencemap (NULL);
 
210
 
 
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());
 
218
 
 
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);
 
224
 
 
225
    emitter->serializeVoipPreference (&preferencemap);
 
226
}
 
227
 
 
228
void VoipPreference::unserialize (Conf::MappingNode *map)
 
229
{
 
230
 
 
231
    _debug ("VoipPreference: Unserialize configuration");
 
232
 
 
233
    Conf::ScalarNode *val = NULL;
 
234
 
 
235
    if (!map) {
 
236
        _debug ("VoipPreference: Did not find voip preference");
 
237
        return;
 
238
    }
 
239
 
 
240
    val = (Conf::ScalarNode *) (map->getValue (playDtmfKey));
 
241
 
 
242
    if (val && !val->getValue().empty()) {
 
243
        _playDtmf = (val->getValue().compare ("true") == 0) ? true : false;
 
244
        val = NULL;
 
245
    }
 
246
 
 
247
    val = (Conf::ScalarNode *) (map->getValue (playTonesKey));
 
248
 
 
249
    if (val && !val->getValue().empty()) {
 
250
        _playTones = (val->getValue().compare ("true") == 0) ? true : false;
 
251
        val = NULL;
 
252
    }
 
253
 
 
254
    val = (Conf::ScalarNode *) (map->getValue (pulseLengthKey));
 
255
 
 
256
    if (val) {
 
257
        _pulseLength = atoi (val->getValue().data());
 
258
        val = NULL;
 
259
    }
 
260
 
 
261
    val = (Conf::ScalarNode *) (map->getValue (symmetricRtpKey));
 
262
 
 
263
    if (val && !val->getValue().empty()) {
 
264
        _symmetricRtp = (val->getValue().compare ("true") == 0) ? true : false;
 
265
        val = NULL;
 
266
    }
 
267
 
 
268
    val = (Conf::ScalarNode *) (map->getValue (zidFileKey));
 
269
 
 
270
    if (val) {
 
271
        _zidFile = val->getValue().c_str();
 
272
        val = NULL;
 
273
    }
 
274
 
 
275
}
 
276
 
 
277
 
 
278
 
 
279
AddressbookPreference::AddressbookPreference() : _photo (true)
 
280
    , _enabled (true)
 
281
    , _list ("")
 
282
    , _maxResults (25)
 
283
    , _business (true)
 
284
    , _home (true)
 
285
    , _mobile (true)
 
286
{
 
287
 
 
288
}
 
289
 
 
290
AddressbookPreference::~AddressbookPreference() {}
 
291
 
 
292
void AddressbookPreference::serialize (Conf::YamlEmitter *emitter)
 
293
{
 
294
    _debug ("Addressbook: Serialize configuration");
 
295
 
 
296
    Conf::MappingNode preferencemap (NULL);
 
297
 
 
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");
 
307
 
 
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);
 
315
 
 
316
    emitter->serializeAddressbookPreference (&preferencemap);
 
317
 
 
318
}
 
319
 
 
320
void AddressbookPreference::unserialize (Conf::MappingNode *map)
 
321
{
 
322
    _debug ("Addressbook: Unserialize configuration");
 
323
 
 
324
    Conf::ScalarNode *val = NULL;
 
325
 
 
326
    if (!map) {
 
327
        _debug ("Addressbook: Did not find addressbook preferences");
 
328
        return;
 
329
    }
 
330
 
 
331
    val = (Conf::ScalarNode *) (map->getValue (photoKey));
 
332
 
 
333
    if (val && ! (val->getValue().empty())) {
 
334
        _photo = (val->getValue() == "true") ? true : false;
 
335
        val = NULL;
 
336
    }
 
337
 
 
338
    val = (Conf::ScalarNode *) (map->getValue (enabledKey));
 
339
 
 
340
    if (val && !val->getValue().empty()) {
 
341
        _enabled = (val->getValue() == "true") ? true : false;
 
342
        val = NULL;
 
343
    }
 
344
 
 
345
    val = (Conf::ScalarNode *) (map->getValue (listKey));
 
346
 
 
347
    if (val) {
 
348
        _list = val->getValue();
 
349
        val = NULL;
 
350
    }
 
351
 
 
352
    val = (Conf::ScalarNode *) (map->getValue (maxResultsKey));
 
353
 
 
354
    if (val) {
 
355
        _maxResults = atoi (val->getValue().data());
 
356
        val = NULL;
 
357
    }
 
358
 
 
359
    val = (Conf::ScalarNode *) (map->getValue (businessKey));
 
360
 
 
361
    if (val && !val->getValue().empty()) {
 
362
        _business = (val->getValue() == "true") ? true : false;
 
363
        val = NULL;
 
364
    }
 
365
 
 
366
    val = (Conf::ScalarNode *) (map->getValue (homeKey));
 
367
 
 
368
    if (val && !val->getValue().empty()) {
 
369
        _home = (val->getValue() == "true") ? true : false;
 
370
        val = NULL;
 
371
    }
 
372
 
 
373
    val = (Conf::ScalarNode *) (map->getValue (mobileKey));
 
374
 
 
375
    if (val && !val->getValue().empty()) {
 
376
        _mobile = (val->getValue() == "true") ? true : false;
 
377
        val = NULL;
 
378
    }
 
379
 
 
380
}
 
381
 
 
382
 
 
383
HookPreference::HookPreference() : _iax2Enabled (false)
 
384
    , _numberAddPrefix ("")
 
385
    , _numberEnabled (false)
 
386
    , _sipEnabled (false)
 
387
    , _urlCommand ("x-www-browser")
 
388
    , _urlSipField ("X-sflphone-url")
 
389
{
 
390
 
 
391
}
 
392
 
 
393
HookPreference::~HookPreference() {}
 
394
 
 
395
void HookPreference::serialize (Conf::YamlEmitter *emitter)
 
396
{
 
397
    _debug ("Hook: Serialize configuration");
 
398
 
 
399
    Conf::MappingNode preferencemap (NULL);
 
400
 
 
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);
 
407
 
 
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);
 
414
 
 
415
    emitter->serializeHooksPreference (&preferencemap);
 
416
}
 
417
 
 
418
void HookPreference::unserialize (Conf::MappingNode *map)
 
419
{
 
420
    Conf::ScalarNode *val = NULL;
 
421
 
 
422
    _debug ("Hook: Unserialize preference");
 
423
 
 
424
    if (!map) {
 
425
        _debug ("Hook: Did not find hook preference");
 
426
        return;
 
427
    }
 
428
 
 
429
    val = (Conf::ScalarNode *) (map->getValue (iax2EnabledKey));
 
430
 
 
431
    if (val) {
 
432
        _iax2Enabled = (val->getValue() == "true") ? true : false;
 
433
        val = NULL;
 
434
    }
 
435
 
 
436
    val = (Conf::ScalarNode *) (map->getValue (numberAddPrefixKey));
 
437
 
 
438
    if (val) {
 
439
        _numberAddPrefix = val->getValue();
 
440
        val = NULL;
 
441
    }
 
442
 
 
443
    val = (Conf::ScalarNode *) (map->getValue (numberEnabledKey));
 
444
 
 
445
    if (val) {
 
446
        _numberEnabled = (val->getValue() == "true") ? true : false;
 
447
        val = NULL;
 
448
    }
 
449
 
 
450
    val = (Conf::ScalarNode *) (map->getValue (sipEnabledKey));
 
451
 
 
452
    if (val) {
 
453
        _sipEnabled = (val->getValue() == "true") ? true : false;
 
454
        val = NULL;
 
455
    }
 
456
 
 
457
    val = (Conf::ScalarNode *) (map->getValue (urlCommandKey));
 
458
 
 
459
    if (val) {
 
460
        _urlCommand = val->getValue();
 
461
        val = NULL;
 
462
    }
 
463
 
 
464
    val = (Conf::ScalarNode *) (map->getValue (urlSipFieldKey));
 
465
 
 
466
    if (val) {
 
467
        _urlSipField = val->getValue();
 
468
        val = NULL;
 
469
    }
 
470
 
 
471
 
 
472
}
 
473
 
 
474
 
 
475
 
 
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 ("")
 
483
    , _deviceRecord ("")
 
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)
 
489
{
 
490
 
 
491
}
 
492
 
 
493
AudioPreference::~AudioPreference() {}
 
494
 
 
495
void AudioPreference::serialize (Conf::YamlEmitter *emitter)
 
496
{
 
497
    _debug ("AudioPreference: Serialize configuration");
 
498
 
 
499
    Conf::MappingNode preferencemap (NULL);
 
500
    Conf::MappingNode alsapreferencemap (NULL);
 
501
    Conf::MappingNode pulsepreferencemap (NULL);
 
502
 
 
503
    // alsa preference
 
504
    std::stringstream instr;
 
505
    instr << _cardin;
 
506
    Conf::ScalarNode cardin (instr.str()); // 0
 
507
    std::stringstream outstr;
 
508
    outstr << _cardout;
 
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
 
520
 
 
521
    //pulseaudio preference
 
522
    Conf::ScalarNode devicePlayback (_devicePlayback);//:
 
523
    Conf::ScalarNode deviceRecord (_deviceRecord); //:
 
524
    Conf::ScalarNode deviceRingtone (_deviceRingtone); //:
 
525
 
 
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);
 
538
 
 
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);
 
546
 
 
547
    preferencemap.setKeyValue (pulsemapKey, &pulsepreferencemap);
 
548
    pulsepreferencemap.setKeyValue (devicePlaybackKey, &devicePlayback);
 
549
    pulsepreferencemap.setKeyValue (deviceRecordKey, &deviceRecord);
 
550
    pulsepreferencemap.setKeyValue (deviceRingtoneKey, &deviceRingtone);
 
551
 
 
552
    preferencemap.setKeyValue (noiseReduceKey, &noise);
 
553
 
 
554
    emitter->serializeAudioPreference (&preferencemap);
 
555
 
 
556
}
 
557
 
 
558
void AudioPreference::unserialize (Conf::MappingNode *map)
 
559
{
 
560
    _debug ("AudioPreference: Unserialize configuration");
 
561
 
 
562
    if (!map) {
 
563
        _debug ("AudioPreference: Did not find audio preferences");
 
564
        return;
 
565
    }
 
566
 
 
567
    Conf::MappingNode *alsamap = NULL;
 
568
    Conf::MappingNode *pulsemap = NULL;
 
569
 
 
570
    Conf::ScalarNode *val = NULL;
 
571
 
 
572
 
 
573
    val = (Conf::ScalarNode *) (map->getValue (recordpathKey));
 
574
 
 
575
    if (val) {
 
576
        _recordpath = val->getValue();
 
577
        val = NULL;
 
578
    }
 
579
 
 
580
    val = (Conf::ScalarNode *) (map->getValue (volumemicKey));
 
581
 
 
582
    if (val) {
 
583
        _volumemic = atoi (val->getValue().data());
 
584
        val = NULL;
 
585
    }
 
586
 
 
587
    val = (Conf::ScalarNode *) (map->getValue (volumespkrKey));
 
588
 
 
589
    if (val) {
 
590
        _volumespkr = atoi (val->getValue().data());
 
591
        val = NULL;
 
592
    }
 
593
 
 
594
    val = (Conf::ScalarNode *) (map->getValue (noiseReduceKey));
 
595
 
 
596
    if (val) {
 
597
        _noisereduce = (val->getValue() == "true");
 
598
        val = NULL;
 
599
    }
 
600
 
 
601
    alsamap = (Conf::MappingNode *) (map->getValue ("alsa"));
 
602
 
 
603
    // did found alsa
 
604
    if (alsamap) {
 
605
 
 
606
        val = (Conf::ScalarNode *) (alsamap->getValue (cardinKey));
 
607
 
 
608
        if (val) {
 
609
            _cardin = atoi (val->getValue().data());
 
610
            val = NULL;
 
611
        }
 
612
 
 
613
        val = (Conf::ScalarNode *) (alsamap->getValue (cardoutKey));
 
614
 
 
615
        if (val) {
 
616
            _cardout = atoi (val->getValue().data());
 
617
            val = NULL;
 
618
        }
 
619
 
 
620
        val = (Conf::ScalarNode *) (alsamap->getValue (cardringKey));
 
621
 
 
622
        if (val) {
 
623
            _cardring = atoi (val->getValue().data());
 
624
            val = NULL;
 
625
        }
 
626
 
 
627
        val = (Conf::ScalarNode *) (alsamap->getValue (framesizeKey));
 
628
 
 
629
        if (val) {
 
630
            _framesize = atoi (val->getValue().data());
 
631
            val = NULL;
 
632
        }
 
633
 
 
634
        val = (Conf::ScalarNode *) (alsamap->getValue (smplrateKey));
 
635
 
 
636
        if (val) {
 
637
            _smplrate = atoi (val->getValue().data());
 
638
            val = NULL;
 
639
        }
 
640
 
 
641
        val = (Conf::ScalarNode *) (alsamap->getValue (pluginKey));
 
642
 
 
643
        if (val) {
 
644
            _plugin = val->getValue();
 
645
            val = NULL;
 
646
        }
 
647
 
 
648
    }
 
649
 
 
650
 
 
651
    pulsemap = (Conf::MappingNode *) (map->getValue ("pulse"));
 
652
 
 
653
 
 
654
    if (pulsemap) {
 
655
 
 
656
        val = (Conf::ScalarNode *) (pulsemap->getValue (devicePlaybackKey));
 
657
 
 
658
        if (val) {
 
659
            _devicePlayback = val->getValue();
 
660
            val = NULL;
 
661
        }
 
662
 
 
663
        val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRecordKey));
 
664
 
 
665
        if (val) {
 
666
            _deviceRecord = val->getValue();
 
667
            val = NULL;
 
668
        }
 
669
 
 
670
        val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRingtoneKey));
 
671
 
 
672
        if (val) {
 
673
            _deviceRingtone = val->getValue();
 
674
            val = NULL;
 
675
        }
 
676
 
 
677
    }
 
678
 
 
679
}
 
680
 
 
681
 
 
682
 
 
683
ShortcutPreferences::ShortcutPreferences() : _hangup ("")
 
684
    , _pickup ("")
 
685
    , _popup ("")
 
686
    , _toggleHold ("")
 
687
    , _togglePickupHangup ("")
 
688
{
 
689
 
 
690
}
 
691
 
 
692
ShortcutPreferences::~ShortcutPreferences() {}
 
693
 
 
694
 
 
695
std::map<std::string, std::string> ShortcutPreferences::getShortcuts()
 
696
{
 
697
 
 
698
    std::map<std::string, std::string> shortcutsMap;
 
699
 
 
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));
 
705
 
 
706
    return shortcutsMap;
 
707
}
 
708
 
 
709
 
 
710
void ShortcutPreferences::setShortcuts (std::map<std::string, std::string> map_cpy)
 
711
{
 
712
    // std::map<std::string, int> map_cpy = shortcut;
 
713
    std::map<std::string, std::string>::iterator it;
 
714
 
 
715
    _debug ("ShortcutPreferences: Set shortcuts");
 
716
 
 
717
 
 
718
    it = map_cpy.find (hangupShortKey);
 
719
 
 
720
    if (it != map_cpy.end()) {
 
721
        _hangup = it->second;
 
722
    }
 
723
 
 
724
    it = map_cpy.find (pickupShortKey);
 
725
 
 
726
    if (it != map_cpy.end()) {
 
727
        _pickup = it->second;
 
728
    }
 
729
 
 
730
    it = map_cpy.find (popupShortKey);
 
731
 
 
732
    if (it != map_cpy.end()) {
 
733
        _popup = it->second;
 
734
    }
 
735
 
 
736
    it = map_cpy.find (toggleHoldShortKey);
 
737
 
 
738
    if (it != map_cpy.end()) {
 
739
        _toggleHold = it->second;
 
740
    }
 
741
 
 
742
    it = map_cpy.find (togglePickupHangupShortKey);
 
743
 
 
744
    if (it != map_cpy.end()) {
 
745
        _togglePickupHangup = it->second;
 
746
    }
 
747
 
 
748
    /*
 
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);
 
754
      }
 
755
    }
 
756
    */
 
757
}
 
758
 
 
759
 
 
760
void ShortcutPreferences::serialize (Conf::YamlEmitter *emitter)
 
761
{
 
762
 
 
763
    _debug ("ShortcutPreference: Serialize configuration");
 
764
 
 
765
    Conf::MappingNode preferencemap (NULL);
 
766
 
 
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);
 
772
 
 
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);
 
778
 
 
779
    emitter->serializeShortcutPreference (&preferencemap);
 
780
}
 
781
 
 
782
void ShortcutPreferences::unserialize (Conf::MappingNode *map)
 
783
{
 
784
    _debug ("ShortcutPreference: Unserialize shortcut");
 
785
 
 
786
    if (!map) {
 
787
        _debug ("ShortcutPreference: Could not find shortcut preferences");
 
788
        return;
 
789
    }
 
790
 
 
791
    Conf::ScalarNode *val = NULL;
 
792
 
 
793
    val = (Conf::ScalarNode *) (map->getValue (hangupShortKey));
 
794
 
 
795
    if (val) {
 
796
        _hangup = val->getValue();
 
797
        val = NULL;
 
798
    }
 
799
 
 
800
    val = (Conf::ScalarNode *) (map->getValue (pickupShortKey));
 
801
 
 
802
    if (val) {
 
803
        _pickup = val->getValue();
 
804
        val = NULL;
 
805
    }
 
806
 
 
807
    val = (Conf::ScalarNode *) (map->getValue (popupShortKey));
 
808
 
 
809
    if (val) {
 
810
        _popup = val->getValue();
 
811
        val = NULL;
 
812
    }
 
813
 
 
814
    val = (Conf::ScalarNode *) (map->getValue (toggleHoldShortKey));
 
815
 
 
816
    if (val) {
 
817
        _toggleHold = val->getValue();
 
818
        val = NULL;
 
819
    }
 
820
 
 
821
    val = (Conf::ScalarNode *) (map->getValue (togglePickupHangupShortKey));
 
822
 
 
823
    if (val) {
 
824
        _togglePickupHangup = val->getValue();
 
825
        val = NULL;
 
826
    }
 
827
 
 
828
}