preferences.h 10.5 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 *  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
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 *
 *  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.
 */

#ifndef __PREFERENCE_H__
#define __PREFERENCE_H__

#include "config/serializable.h"
35
36
#include <string>
#include <map>
37

38
class AudioLayer;
Julien Bonjean's avatar
Julien Bonjean committed
39

40
class Preferences : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
41
    public:
42
        static const char * const DFT_ZONE;
43
        static const char * const REGISTRATION_EXPIRE_KEY;
44

Julien Bonjean's avatar
Julien Bonjean committed
45
46
        Preferences();

47
        virtual void serialize(Conf::YamlEmitter &emitter);
48
        virtual void unserialize(const Conf::YamlNode &map);
Julien Bonjean's avatar
Julien Bonjean committed
49

50
51
        std::string getAccountOrder() const {
            return accountOrder_;
Julien Bonjean's avatar
Julien Bonjean committed
52
        }
53

54
        void setAccountOrder(const std::string &ord) {
55
            accountOrder_ = ord;
Julien Bonjean's avatar
Julien Bonjean committed
56
57
        }

58
59
        int getHistoryLimit() const {
            return historyLimit_;
Julien Bonjean's avatar
Julien Bonjean committed
60
        }
61

62
        void setHistoryLimit(int lim) {
63
            historyLimit_ = lim;
Julien Bonjean's avatar
Julien Bonjean committed
64
65
        }

66
67
        int getHistoryMaxCalls() const {
            return historyMaxCalls_;
Julien Bonjean's avatar
Julien Bonjean committed
68
        }
69

70
        void setHistoryMaxCalls(int max) {
71
            historyMaxCalls_ = max;
Julien Bonjean's avatar
Julien Bonjean committed
72
73
        }

74
75
        std::string getZoneToneChoice() const {
            return zoneToneChoice_;
Julien Bonjean's avatar
Julien Bonjean committed
76
        }
77

78
        void setZoneToneChoice(const std::string &str) {
79
            zoneToneChoice_ = str;
Julien Bonjean's avatar
Julien Bonjean committed
80
81
        }

82
83
        int getRegistrationExpire() const {
            return registrationExpire_;
Julien Bonjean's avatar
Julien Bonjean committed
84
        }
85

86
        void setRegistrationExpire(int exp) {
87
            registrationExpire_ = exp;
Julien Bonjean's avatar
Julien Bonjean committed
88
89
        }

90
91
        int getPortNum() const {
            return portNum_;
Julien Bonjean's avatar
Julien Bonjean committed
92
        }
93

94
        void setPortNum(int port) {
95
            portNum_ = port;
Julien Bonjean's avatar
Julien Bonjean committed
96
97
        }

98
99
        bool getSearchBarDisplay() const {
            return searchBarDisplay_;
Julien Bonjean's avatar
Julien Bonjean committed
100
        }
101

102
        void setSearchBarDisplay(bool search) {
103
            searchBarDisplay_ = search;
Julien Bonjean's avatar
Julien Bonjean committed
104
105
        }

106
107
        bool getZeroConfenable() const {
            return zeroConfenable_;
Julien Bonjean's avatar
Julien Bonjean committed
108
        }
109
        void setZeroConfenable(bool enable) {
110
            zeroConfenable_ = enable;
Julien Bonjean's avatar
Julien Bonjean committed
111
112
        }

113
114
        bool getMd5Hash() const {
            return md5Hash_;
Julien Bonjean's avatar
Julien Bonjean committed
115
        }
116
        void setMd5Hash(bool md5) {
117
            md5Hash_ = md5;
Julien Bonjean's avatar
Julien Bonjean committed
118
119
120
        }

    private:
121
122
123
124
125
126
127
128
129
        std::string accountOrder_;
        int historyLimit_;
        int historyMaxCalls_;
        std::string zoneToneChoice_;
        int registrationExpire_;
        int portNum_;
        bool searchBarDisplay_;
        bool zeroConfenable_;
        bool md5Hash_;
130
131
};

132
class VoipPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
133
134
    public:
        VoipPreference();
Alexandre Savard's avatar
Alexandre Savard committed
135

136
        virtual void serialize(Conf::YamlEmitter &emitter);
137
        virtual void unserialize(const Conf::YamlNode &map);
Alexandre Savard's avatar
Alexandre Savard committed
138

139
140
        bool getPlayDtmf() const {
            return playDtmf_;
Julien Bonjean's avatar
Julien Bonjean committed
141
        }
142

143
        void setPlayDtmf(bool dtmf) {
144
            playDtmf_ = dtmf;
Julien Bonjean's avatar
Julien Bonjean committed
145
        }
Alexandre Savard's avatar
Alexandre Savard committed
146

147
148
        bool getPlayTones() const {
            return playTones_;
Julien Bonjean's avatar
Julien Bonjean committed
149
        }
150

151
        void setPlayTones(bool tone) {
152
            playTones_ = tone;
Julien Bonjean's avatar
Julien Bonjean committed
153
        }
Alexandre Savard's avatar
Alexandre Savard committed
154

155
156
        int getPulseLength() const {
            return pulseLength_;
Julien Bonjean's avatar
Julien Bonjean committed
157
        }
158

159
        void setPulseLength(int length) {
160
            pulseLength_ = length;
Julien Bonjean's avatar
Julien Bonjean committed
161
        }
Alexandre Savard's avatar
Alexandre Savard committed
162

163
164
        bool getSymmetricRtp() const {
            return symmetricRtp_;
Julien Bonjean's avatar
Julien Bonjean committed
165
        }
166
        void setSymmetricRtp(bool sym) {
167
            symmetricRtp_ = sym;
Julien Bonjean's avatar
Julien Bonjean committed
168
        }
Alexandre Savard's avatar
Alexandre Savard committed
169

170
171
        std::string getZidFile() const {
            return zidFile_;
Julien Bonjean's avatar
Julien Bonjean committed
172
        }
173
        void setZidFile(const std::string &file) {
174
            zidFile_ = file;
Julien Bonjean's avatar
Julien Bonjean committed
175
        }
Alexandre Savard's avatar
Alexandre Savard committed
176

Julien Bonjean's avatar
Julien Bonjean committed
177
    private:
Alexandre Savard's avatar
Alexandre Savard committed
178

179
180
181
182
183
        bool playDtmf_;
        bool playTones_;
        int pulseLength_;
        bool symmetricRtp_;
        std::string zidFile_;
Alexandre Savard's avatar
Alexandre Savard committed
184
185
};

186
struct pjsip_msg;
Tristan Matthews's avatar
Tristan Matthews committed
187

188
class HookPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
189
190
    public:
        HookPreference();
191
        HookPreference(const std::map<std::string, std::string> &settings);
192

193
        virtual void serialize(Conf::YamlEmitter &emitter);
194
        virtual void unserialize(const Conf::YamlNode &map);
195

196
        std::string getNumberAddPrefix() const {
197
198
199
200
            if (numberEnabled_)
                return numberAddPrefix_;
            else
                return "";
Julien Bonjean's avatar
Julien Bonjean committed
201
        }
202

203
        std::map<std::string, std::string> toMap() const;
Tristan Matthews's avatar
Tristan Matthews committed
204
        void runHook(pjsip_msg *msg);
205

Julien Bonjean's avatar
Julien Bonjean committed
206
    private:
207
208
209
210
211
212
        bool iax2Enabled_;
        std::string numberAddPrefix_;
        bool numberEnabled_;
        bool sipEnabled_;
        std::string urlCommand_;
        std::string urlSipField_;
213
214
};

215
class AudioPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
216
217
    public:
        AudioPreference();
218
219
220
        AudioLayer *createAudioLayer();
        AudioLayer *switchAndCreateAudioLayer();

221
222
        std::string getAudioApi() const {
            return audioApi_;
223
224
        }

225
        void setAudioApi(const std::string &api) {
226
            audioApi_ = api;
227
        }
228

229
        virtual void serialize(Conf::YamlEmitter &emitter);
230
        virtual void unserialize(const Conf::YamlNode &map);
Julien Bonjean's avatar
Julien Bonjean committed
231
232

        // alsa preference
233
234
        int getAlsaCardin() const {
            return alsaCardin_;
Julien Bonjean's avatar
Julien Bonjean committed
235
        }
236
237
        void setAlsaCardin(int c) {
            alsaCardin_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
238
239
        }

240
241
        int getAlsaCardout() const {
            return alsaCardout_;
Julien Bonjean's avatar
Julien Bonjean committed
242
        }
243

244
245
        void setAlsaCardout(int c) {
            alsaCardout_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
246
247
        }

248
249
        int getAlsaCardring() const {
            return alsaCardring_;
Julien Bonjean's avatar
Julien Bonjean committed
250
        }
251

252
253
        void setAlsaCardring(int c) {
            alsaCardring_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
254
255
        }

256
257
        std::string getAlsaPlugin() const {
            return alsaPlugin_;
Julien Bonjean's avatar
Julien Bonjean committed
258
        }
259

260
261
        void setAlsaPlugin(const std::string &p) {
            alsaPlugin_ = p;
Julien Bonjean's avatar
Julien Bonjean committed
262
263
        }

264
265
        int getAlsaSmplrate() const {
            return alsaSmplrate_;
Julien Bonjean's avatar
Julien Bonjean committed
266
        }
267
268
        void setAlsaSmplrate(int r) {
            alsaSmplrate_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
269
270
271
        }

        //pulseaudio preference
272
273
        std::string getPulseDevicePlayback() const {
            return pulseDevicePlayback_;
Julien Bonjean's avatar
Julien Bonjean committed
274
        }
275

276
277
        void setPulseDevicePlayback(const std::string &p) {
            pulseDevicePlayback_ = p;
Julien Bonjean's avatar
Julien Bonjean committed
278
279
        }

280
281
        std::string getPulseDeviceRecord() const {
            return pulseDeviceRecord_;
Julien Bonjean's avatar
Julien Bonjean committed
282
        }
283
284
        void setPulseDeviceRecord(const std::string &r) {
            pulseDeviceRecord_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
285
286
        }

287
288
        std::string getPulseDeviceRingtone() const {
            return pulseDeviceRingtone_;
Julien Bonjean's avatar
Julien Bonjean committed
289
        }
290

291
292
        void setPulseDeviceRingtone(const std::string &r) {
            pulseDeviceRingtone_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
293
294
295
        }

        // general preference
296
        std::string getRecordPath() const {
297
            return recordpath_;
Julien Bonjean's avatar
Julien Bonjean committed
298
        }
299
300
301

        // Returns true if directory is writeable
        bool setRecordPath(const std::string &r);
Julien Bonjean's avatar
Julien Bonjean committed
302

303
304
        bool getIsAlwaysRecording() const {
            return alwaysRecording_;
305
306
307
        }

        void setIsAlwaysRecording(bool rec) {
308
            alwaysRecording_ = rec;
309
310
        }

311
        double getVolumemic() const {
312
            return volumemic_;
Julien Bonjean's avatar
Julien Bonjean committed
313
        }
314
        void setVolumemic(double m) {
315
            volumemic_ = m;
Julien Bonjean's avatar
Julien Bonjean committed
316
317
        }

318
        double getVolumespkr() const {
319
            return volumespkr_;
Julien Bonjean's avatar
Julien Bonjean committed
320
        }
321
        void setVolumespkr(double s) {
322
            volumespkr_ = s;
Julien Bonjean's avatar
Julien Bonjean committed
323
324
        }

325
326
        bool getNoiseReduce() const {
            return noisereduce_;
327
328
        }

329
        void setNoiseReduce(bool noise) {
330
            noisereduce_ = noise;
331
332
        }

333
334
        bool getEchoCancel() const {
            return echocancel_;
335
336
337
        }

        void setEchoCancel(bool echo) {
338
            echocancel_ = echo;
339
340
        }

Julien Bonjean's avatar
Julien Bonjean committed
341
    private:
342
        std::string audioApi_;
Julien Bonjean's avatar
Julien Bonjean committed
343
344

        // alsa preference
345
346
347
348
349
        int alsaCardin_;
        int alsaCardout_;
        int alsaCardring_;
        std::string alsaPlugin_;
        int alsaSmplrate_;
Julien Bonjean's avatar
Julien Bonjean committed
350
351

        //pulseaudio preference
352
353
354
        std::string pulseDevicePlayback_;
        std::string pulseDeviceRecord_;
        std::string pulseDeviceRingtone_;
Julien Bonjean's avatar
Julien Bonjean committed
355
356

        // general preference
357
358
359
360
361
362
363
        std::string recordpath_; //: /home/msavard/Bureau
        bool alwaysRecording_;
        int volumemic_;
        int volumespkr_;

        bool noisereduce_;
        bool echocancel_;
364
365
};

366
class ShortcutPreferences : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
367
    public:
368
        ShortcutPreferences();
369
        virtual void serialize(Conf::YamlEmitter &emitter);
370
        virtual void unserialize(const Conf::YamlNode &map);
371

372
        void setShortcuts(std::map<std::string, std::string> shortcuts);
373
        std::map<std::string, std::string> getShortcuts() const;
374

375
376
        std::string getHangup() const {
            return hangup_;
Julien Bonjean's avatar
Julien Bonjean committed
377
        }
378

379
        void setHangup(const std::string &hangup) {
380
            hangup_ = hangup;
Julien Bonjean's avatar
Julien Bonjean committed
381
        }
382

383
384
        std::string getPickup() const {
            return pickup_;
Julien Bonjean's avatar
Julien Bonjean committed
385
        }
386

387
        void setPickup(const std::string &pickup) {
388
            pickup_ = pickup;
Julien Bonjean's avatar
Julien Bonjean committed
389
        }
390

391
392
        std::string getPopup() const {
            return popup_;
Julien Bonjean's avatar
Julien Bonjean committed
393
        }
394

395
        void setPopup(const std::string &popup) {
396
            popup_ = popup;
Julien Bonjean's avatar
Julien Bonjean committed
397
        }
398

399
400
        std::string getToggleHold() const {
            return toggleHold_;
Julien Bonjean's avatar
Julien Bonjean committed
401
        }
402

403
        void setToggleHold(const std::string &hold) {
404
            toggleHold_ = hold;
Julien Bonjean's avatar
Julien Bonjean committed
405
        }
406

407
408
        std::string getTogglePickupHangup() const {
            return togglePickupHangup_;
Julien Bonjean's avatar
Julien Bonjean committed
409
        }
410

411
        void setTogglePickupHangup(const std::string &toggle) {
412
            togglePickupHangup_ = toggle;
Julien Bonjean's avatar
Julien Bonjean committed
413
        }
414

Julien Bonjean's avatar
Julien Bonjean committed
415
    private:
416
417
418
419
420
        std::string hangup_;
        std::string pickup_;
        std::string popup_;
        std::string toggleHold_;
        std::string togglePickupHangup_;
421
422
};

423
#endif