preferences.h 12.6 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2019 Savoir-faire Linux Inc.
3
 *
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5
 *  Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 *  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
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
20 21 22 23 24 25
 */

#ifndef __PREFERENCE_H__
#define __PREFERENCE_H__

#include "config/serializable.h"
26
#include "client/ring_signal.h"
27 28
#include <string>
#include <map>
29
#include <vector>
30

31 32 33 34 35
namespace YAML {
    class Emitter;
    class Node;
}

36 37
struct pjsip_msg;

Adrien Béraud's avatar
Adrien Béraud committed
38
namespace jami {
39 40 41

class AudioLayer;

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

Julien Bonjean's avatar
Julien Bonjean committed
47 48
        Preferences();

49 50
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
Julien Bonjean's avatar
Julien Bonjean committed
51

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

56 57 58
        // flush invalid accountIDs from account order
        void verifyAccountOrder(const std::vector<std::string> &accounts);

59
        void addAccount(const std::string &acc);
60
        void removeAccount(const std::string &acc);
61

62
        void setAccountOrder(const std::string &ord) {
63
            accountOrder_ = ord;
Julien Bonjean's avatar
Julien Bonjean committed
64 65
        }

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

70
        void setHistoryLimit(int lim) {
71
            historyLimit_ = lim;
Julien Bonjean's avatar
Julien Bonjean committed
72 73
        }

74 75 76 77 78 79 80 81
        int getRingingTimeout() const {
            return ringingTimeout_;
        }

        void setRingingTimeout(int timeout) {
            ringingTimeout_ = timeout;
        }

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

86
        void setHistoryMaxCalls(int max) {
87
            historyMaxCalls_ = max;
Julien Bonjean's avatar
Julien Bonjean committed
88 89
        }

90 91
        std::string getZoneToneChoice() const {
            return zoneToneChoice_;
Julien Bonjean's avatar
Julien Bonjean committed
92
        }
93

94
        void setZoneToneChoice(const std::string &str) {
95
            zoneToneChoice_ = str;
Julien Bonjean's avatar
Julien Bonjean committed
96 97
        }

98 99
        int getRegistrationExpire() const {
            return registrationExpire_;
Julien Bonjean's avatar
Julien Bonjean committed
100
        }
101

102
        void setRegistrationExpire(int exp) {
103
            registrationExpire_ = exp;
Julien Bonjean's avatar
Julien Bonjean committed
104 105
        }

106 107
        int getPortNum() const {
            return portNum_;
Julien Bonjean's avatar
Julien Bonjean committed
108
        }
109

110
        void setPortNum(int port) {
111
            portNum_ = port;
Julien Bonjean's avatar
Julien Bonjean committed
112 113
        }

114 115
        bool getSearchBarDisplay() const {
            return searchBarDisplay_;
Julien Bonjean's avatar
Julien Bonjean committed
116
        }
117

118
        void setSearchBarDisplay(bool search) {
119
            searchBarDisplay_ = search;
Julien Bonjean's avatar
Julien Bonjean committed
120 121
        }

122 123
        bool getMd5Hash() const {
            return md5Hash_;
Julien Bonjean's avatar
Julien Bonjean committed
124
        }
125
        void setMd5Hash(bool md5) {
126
            md5Hash_ = md5;
Julien Bonjean's avatar
Julien Bonjean committed
127 128 129
        }

    private:
130 131 132
        std::string accountOrder_;
        int historyLimit_;
        int historyMaxCalls_;
133
        int ringingTimeout_;
134 135 136 137 138
        std::string zoneToneChoice_;
        int registrationExpire_;
        int portNum_;
        bool searchBarDisplay_;
        bool md5Hash_;
139
        constexpr static const char * const CONFIG_LABEL = "preferences";
140 141
};

142
class VoipPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
143 144
    public:
        VoipPreference();
145

146 147
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
148

149 150
        bool getPlayDtmf() const {
            return playDtmf_;
Julien Bonjean's avatar
Julien Bonjean committed
151
        }
152

153
        void setPlayDtmf(bool dtmf) {
154
            playDtmf_ = dtmf;
Julien Bonjean's avatar
Julien Bonjean committed
155
        }
156

157 158
        bool getPlayTones() const {
            return playTones_;
Julien Bonjean's avatar
Julien Bonjean committed
159
        }
160

161
        void setPlayTones(bool tone) {
162
            playTones_ = tone;
Julien Bonjean's avatar
Julien Bonjean committed
163
        }
164

165 166
        int getPulseLength() const {
            return pulseLength_;
Julien Bonjean's avatar
Julien Bonjean committed
167
        }
168

169
        void setPulseLength(int length) {
170
            pulseLength_ = length;
Julien Bonjean's avatar
Julien Bonjean committed
171
        }
172

173 174
        bool getSymmetricRtp() const {
            return symmetricRtp_;
Julien Bonjean's avatar
Julien Bonjean committed
175
        }
176
        void setSymmetricRtp(bool sym) {
177
            symmetricRtp_ = sym;
Julien Bonjean's avatar
Julien Bonjean committed
178
        }
179

180 181
        std::string getZidFile() const {
            return zidFile_;
Julien Bonjean's avatar
Julien Bonjean committed
182
        }
183
        void setZidFile(const std::string &file) {
184
            zidFile_ = file;
Julien Bonjean's avatar
Julien Bonjean committed
185
        }
186

Julien Bonjean's avatar
Julien Bonjean committed
187
    private:
188 189 190 191 192
        bool playDtmf_;
        bool playTones_;
        int pulseLength_;
        bool symmetricRtp_;
        std::string zidFile_;
193
        constexpr static const char * const CONFIG_LABEL = "voipPreferences";
194 195
};

196
class HookPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
197 198
    public:
        HookPreference();
199
        HookPreference(const std::map<std::string, std::string> &settings);
200

201 202
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
203

204
        std::string getNumberAddPrefix() const {
205 206 207 208
            if (numberEnabled_)
                return numberAddPrefix_;
            else
                return "";
Julien Bonjean's avatar
Julien Bonjean committed
209
        }
210

211 212
        const std::string & getUrlCommand() const { return urlCommand_; }

213
        std::map<std::string, std::string> toMap() const;
214
        void runHook(pjsip_msg *msg);
215

Julien Bonjean's avatar
Julien Bonjean committed
216
    private:
217 218 219 220 221
        std::string numberAddPrefix_;
        bool numberEnabled_;
        bool sipEnabled_;
        std::string urlCommand_;
        std::string urlSipField_;
222
        constexpr static const char * const CONFIG_LABEL = "hooks";
223 224
};

225
class AudioPreference : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
226 227
    public:
        AudioPreference();
228 229
        AudioLayer *createAudioLayer();
        AudioLayer *switchAndCreateAudioLayer();
230

231 232
        std::string getAudioApi() const {
            return audioApi_;
233 234
        }

235
        void setAudioApi(const std::string &api) {
236
            audioApi_ = api;
237
        }
238

239 240
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
Julien Bonjean's avatar
Julien Bonjean committed
241 242

        // alsa preference
243 244
        int getAlsaCardin() const {
            return alsaCardin_;
Julien Bonjean's avatar
Julien Bonjean committed
245
        }
246 247
        void setAlsaCardin(int c) {
            alsaCardin_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
248 249
        }

250 251
        int getAlsaCardout() const {
            return alsaCardout_;
Julien Bonjean's avatar
Julien Bonjean committed
252
        }
253

254 255
        void setAlsaCardout(int c) {
            alsaCardout_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
256 257
        }

258 259
        int getAlsaCardring() const {
            return alsaCardring_;
Julien Bonjean's avatar
Julien Bonjean committed
260
        }
261

262 263
        void setAlsaCardring(int c) {
            alsaCardring_ = c;
Julien Bonjean's avatar
Julien Bonjean committed
264 265
        }

266 267
        std::string getAlsaPlugin() const {
            return alsaPlugin_;
Julien Bonjean's avatar
Julien Bonjean committed
268
        }
269

270 271
        void setAlsaPlugin(const std::string &p) {
            alsaPlugin_ = p;
Julien Bonjean's avatar
Julien Bonjean committed
272 273
        }

274 275
        int getAlsaSmplrate() const {
            return alsaSmplrate_;
Julien Bonjean's avatar
Julien Bonjean committed
276
        }
277 278
        void setAlsaSmplrate(int r) {
            alsaSmplrate_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
279 280 281
        }

        //pulseaudio preference
282 283
        std::string getPulseDevicePlayback() const {
            return pulseDevicePlayback_;
Julien Bonjean's avatar
Julien Bonjean committed
284
        }
285

286 287
        void setPulseDevicePlayback(const std::string &p) {
            pulseDevicePlayback_ = p;
Julien Bonjean's avatar
Julien Bonjean committed
288 289
        }

290 291
        std::string getPulseDeviceRecord() const {
            return pulseDeviceRecord_;
Julien Bonjean's avatar
Julien Bonjean committed
292
        }
293 294
        void setPulseDeviceRecord(const std::string &r) {
            pulseDeviceRecord_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
295 296
        }

297 298
        std::string getPulseDeviceRingtone() const {
            return pulseDeviceRingtone_;
Julien Bonjean's avatar
Julien Bonjean committed
299
        }
300

301 302
        void setPulseDeviceRingtone(const std::string &r) {
            pulseDeviceRingtone_ = r;
Julien Bonjean's avatar
Julien Bonjean committed
303 304 305
        }

        // general preference
306
        std::string getRecordPath() const {
307
            return recordpath_;
Julien Bonjean's avatar
Julien Bonjean committed
308
        }
309 310 311

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

313 314
        bool getIsAlwaysRecording() const {
            return alwaysRecording_;
315 316 317
        }

        void setIsAlwaysRecording(bool rec) {
318
            alwaysRecording_ = rec;
319 320
        }

321
        double getVolumemic() const {
322
            return volumemic_;
Julien Bonjean's avatar
Julien Bonjean committed
323
        }
324
        void setVolumemic(double m) {
325
            volumemic_ = m;
Julien Bonjean's avatar
Julien Bonjean committed
326 327
        }

328
        double getVolumespkr() const {
329
            return volumespkr_;
Julien Bonjean's avatar
Julien Bonjean committed
330
        }
331
        void setVolumespkr(double s) {
332
            volumespkr_ = s;
Julien Bonjean's avatar
Julien Bonjean committed
333 334
        }

335 336 337 338
        bool isAGCEnabled() const {
            return agcEnabled_;
        }

339
        void setAGCState(bool enabled) {
340 341 342
            agcEnabled_ = enabled;
        }

343
        bool getNoiseReduce() const {
344
            return denoise_;
345 346
        }

347 348
        void setNoiseReduce(bool enabled) {
            denoise_ = enabled;
349 350
        }

351 352 353 354 355 356 357 358
        bool getCaptureMuted() const {
            return captureMuted_;
        }

        void setCaptureMuted(bool muted) {
            captureMuted_ = muted;
        }

359 360 361 362 363 364 365 366
        bool getPlaybackMuted() const {
            return playbackMuted_;
        }

        void setPlaybackMuted(bool muted) {
            playbackMuted_= muted;
        }

Julien Bonjean's avatar
Julien Bonjean committed
367
    private:
368
        std::string audioApi_;
Julien Bonjean's avatar
Julien Bonjean committed
369 370

        // alsa preference
371 372 373 374 375
        int alsaCardin_;
        int alsaCardout_;
        int alsaCardring_;
        std::string alsaPlugin_;
        int alsaSmplrate_;
Julien Bonjean's avatar
Julien Bonjean committed
376 377

        //pulseaudio preference
378 379 380
        std::string pulseDevicePlayback_;
        std::string pulseDeviceRecord_;
        std::string pulseDeviceRingtone_;
Julien Bonjean's avatar
Julien Bonjean committed
381 382

        // general preference
383 384
        std::string recordpath_; //: /home/msavard/Bureau
        bool alwaysRecording_;
385 386
        double volumemic_;
        double volumespkr_;
387

388 389
        bool denoise_;
        bool agcEnabled_;
390
        bool captureMuted_;
391
        bool playbackMuted_;
392
        constexpr static const char * const CONFIG_LABEL = "audio";
393 394
};

395
class ShortcutPreferences : public Serializable {
Julien Bonjean's avatar
Julien Bonjean committed
396
    public:
397
        ShortcutPreferences();
398 399
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
400

401
        void setShortcuts(std::map<std::string, std::string> shortcuts);
402
        std::map<std::string, std::string> getShortcuts() const;
403

404 405
        std::string getHangup() const {
            return hangup_;
Julien Bonjean's avatar
Julien Bonjean committed
406
        }
407

408
        void setHangup(const std::string &hangup) {
409
            hangup_ = hangup;
Julien Bonjean's avatar
Julien Bonjean committed
410
        }
411

412 413
        std::string getPickup() const {
            return pickup_;
Julien Bonjean's avatar
Julien Bonjean committed
414
        }
415

416
        void setPickup(const std::string &pickup) {
417
            pickup_ = pickup;
Julien Bonjean's avatar
Julien Bonjean committed
418
        }
419

420 421
        std::string getPopup() const {
            return popup_;
Julien Bonjean's avatar
Julien Bonjean committed
422
        }
423

424
        void setPopup(const std::string &popup) {
425
            popup_ = popup;
Julien Bonjean's avatar
Julien Bonjean committed
426
        }
427

428 429
        std::string getToggleHold() const {
            return toggleHold_;
Julien Bonjean's avatar
Julien Bonjean committed
430
        }
431

432
        void setToggleHold(const std::string &hold) {
433
            toggleHold_ = hold;
Julien Bonjean's avatar
Julien Bonjean committed
434
        }
435

436 437
        std::string getTogglePickupHangup() const {
            return togglePickupHangup_;
Julien Bonjean's avatar
Julien Bonjean committed
438
        }
439

440
        void setTogglePickupHangup(const std::string &toggle) {
441
            togglePickupHangup_ = toggle;
Julien Bonjean's avatar
Julien Bonjean committed
442
        }
443

Julien Bonjean's avatar
Julien Bonjean committed
444
    private:
445 446 447 448 449
        std::string hangup_;
        std::string pickup_;
        std::string popup_;
        std::string toggleHold_;
        std::string togglePickupHangup_;
450
        constexpr static const char * const CONFIG_LABEL = "shortcuts";
451 452
};

Adrien Béraud's avatar
Adrien Béraud committed
453
#ifdef ENABLE_VIDEO
454 455 456 457
class VideoPreferences : public Serializable {
    public:
        VideoPreferences();

458 459
        void serialize(YAML::Emitter &out) const override;
        void unserialize(const YAML::Node &in) override;
460 461 462 463 464 465 466

        bool getDecodingAccelerated() const {
            return decodingAccelerated_;
        }

        void setDecodingAccelerated(bool decodingAccelerated) {
            decodingAccelerated_ = decodingAccelerated;
467
            emitSignal<DRing::ConfigurationSignal::HardwareDecodingChanged>(decodingAccelerated_);
468 469
        }

470 471 472 473 474 475 476 477 478
        bool getEncodingAccelerated() const {
            return encodingAccelerated_;
        }

        void setEncodingAccelerated(bool encodingAccelerated) {
            encodingAccelerated_ = encodingAccelerated;
            emitSignal<DRing::ConfigurationSignal::HardwareEncodingChanged>(encodingAccelerated_);
        }

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
        bool getRecordPreview() const {
            return recordPreview_;
        }

        void setRecordPreview(bool rec) {
            recordPreview_ = rec;
        }

        int getRecordQuality() const {
            return recordQuality_;
        }

        void setRecordQuality(int rec) {
            recordQuality_ = rec;
        }

495 496
    private:
        bool decodingAccelerated_;
497
        bool encodingAccelerated_;
498 499
        bool recordPreview_;
        int recordQuality_;
500 501
        constexpr static const char* const CONFIG_LABEL = "video";
};
Adrien Béraud's avatar
Adrien Béraud committed
502
#endif // ENABLE_VIDEO
503

Adrien Béraud's avatar
Adrien Béraud committed
504
} // namespace jami
505

506
#endif