diff --git a/linphone-desktop/src/components/settings/SettingsModel.cpp b/linphone-desktop/src/components/settings/SettingsModel.cpp index e0e4134d4..57827b1c1 100644 --- a/linphone-desktop/src/components/settings/SettingsModel.cpp +++ b/linphone-desktop/src/components/settings/SettingsModel.cpp @@ -42,6 +42,34 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { // Chat & calls. // ============================================================================= +bool SettingsModel::getLimeIsSupported () const { + return CoreManager::getInstance()->getCore()->limeAvailable(); +} + +// ----------------------------------------------------------------------------- + +inline QVariant buildEncryptionDescription (SettingsModel::MediaEncryption encryption, const char *description) { + return QVariantList() << encryption << description; +} + +QVariantList SettingsModel::getSupportedMediaEncryptions () const { + shared_ptr core = CoreManager::getInstance()->getCore(); + QVariantList list; + + if (core->mediaEncryptionSupported(linphone::MediaEncryptionDTLS)) + list << buildEncryptionDescription(MediaEncryptionDtls, "DTLS"); + + if (core->mediaEncryptionSupported(linphone::MediaEncryptionSRTP)) + list << buildEncryptionDescription(MediaEncryptionSrtp, "SRTP"); + + if (core->mediaEncryptionSupported(linphone::MediaEncryptionZRTP)) + list << buildEncryptionDescription(MediaEncryptionZrtp, "ZRTP"); + + return list; +} + +// ----------------------------------------------------------------------------- + SettingsModel::MediaEncryption SettingsModel::getMediaEncryption () const { return static_cast( CoreManager::getInstance()->getCore()->getMediaEncryption() @@ -49,12 +77,41 @@ SettingsModel::MediaEncryption SettingsModel::getMediaEncryption () const { } void SettingsModel::setMediaEncryption (MediaEncryption encryption) { + if (encryption == getMediaEncryption()) + return; + + if (encryption != SettingsModel::MediaEncryptionZrtp) + setLimeState(SettingsModel::LimeStateDisabled); + CoreManager::getInstance()->getCore()->setMediaEncryption( static_cast(encryption) ); + emit mediaEncryptionChanged(encryption); } +// ----------------------------------------------------------------------------- + +SettingsModel::LimeState SettingsModel::getLimeState () const { + return static_cast( + CoreManager::getInstance()->getCore()->limeEnabled() + ); +} + +void SettingsModel::setLimeState (LimeState state) { + if (state == getLimeState()) + return; + + if (state != SettingsModel::LimeStateDisabled) + setMediaEncryption(SettingsModel::MediaEncryptionZrtp); + + CoreManager::getInstance()->getCore()->enableLime( + static_cast(state) + ); + + emit limeStateChanged(state); +} + // ============================================================================= // Network. // ============================================================================= diff --git a/linphone-desktop/src/components/settings/SettingsModel.hpp b/linphone-desktop/src/components/settings/SettingsModel.hpp index 800420f78..21c8a3a88 100644 --- a/linphone-desktop/src/components/settings/SettingsModel.hpp +++ b/linphone-desktop/src/components/settings/SettingsModel.hpp @@ -37,7 +37,11 @@ class SettingsModel : public QObject { // Chat & calls. ------------------------------------------------------------- + Q_PROPERTY(bool limeIsSupported READ getLimeIsSupported CONSTANT); + Q_PROPERTY(QVariantList supportedMediaEncryptions READ getSupportedMediaEncryptions CONSTANT); + Q_PROPERTY(MediaEncryption mediaEncryption READ getMediaEncryption WRITE setMediaEncryption NOTIFY mediaEncryptionChanged); + Q_PROPERTY(LimeState limeState READ getLimeState WRITE setLimeState NOTIFY limeStateChanged); // Network. ------------------------------------------------------------------ @@ -83,14 +87,22 @@ class SettingsModel : public QObject { public: enum MediaEncryption { - MediaEncryptionDtls = linphone::MediaEncryptionDTLS, MediaEncryptionNone = linphone::MediaEncryptionNone, + MediaEncryptionDtls = linphone::MediaEncryptionDTLS, MediaEncryptionSrtp = linphone::MediaEncryptionSRTP, MediaEncryptionZrtp = linphone::MediaEncryptionZRTP }; Q_ENUM(MediaEncryption); + enum LimeState { + LimeStateDisabled = linphone::LimeStateDisabled, + LimeStateMandatory = linphone::LimeStateMandatory, + LimeStatePreferred = linphone::LimeStatePreferred + }; + + Q_ENUM(LimeState); + SettingsModel (QObject *parent = Q_NULLPTR); // =========================================================================== @@ -99,9 +111,15 @@ public: // Chat & calls. ------------------------------------------------------------- + bool getLimeIsSupported () const; + QVariantList getSupportedMediaEncryptions () const; + MediaEncryption getMediaEncryption () const; void setMediaEncryption (MediaEncryption encryption); + LimeState getLimeState () const; + void setLimeState (LimeState state); + // Network. ------------------------------------------------------------------ bool getUseSipInfoForDtmfs () const; @@ -181,6 +199,7 @@ signals: // Chat & calls. ------------------------------------------------------------- void mediaEncryptionChanged (MediaEncryption encryption); + void limeStateChanged (LimeState state); // Network. ------------------------------------------------------------------ diff --git a/linphone-desktop/ui/views/App/Settings/SettingsCallsChat.qml b/linphone-desktop/ui/views/App/Settings/SettingsCallsChat.qml index 6e0c0c3a1..4836bc119 100644 --- a/linphone-desktop/ui/views/App/Settings/SettingsCallsChat.qml +++ b/linphone-desktop/ui/views/App/Settings/SettingsCallsChat.qml @@ -18,29 +18,34 @@ TabContainer { width: parent.width FormLine { + visible: !!encryption.encryptions.length + FormGroup { label: qsTr('encryptionLabel') ExclusiveButtons { - property var _resolveButton - texts: [ - qsTr('noEncryption'), // 0. - 'SRTP', // 1. - 'ZRTP', // 2. - 'DTLS' // 3. - ] + id: encryption - Component.onCompleted: { - var map = _resolveButton = {} - map[SettingsModel.MediaEncryptionNone] = 0 - map[SettingsModel.MediaEncryptionSrtp] = 1 - map[SettingsModel.MediaEncryptionZrtp] = 2 - map[SettingsModel.MediaEncryptionDtls] = 3 + property var encryptions: (function () { + var encryptions = SettingsModel.supportedMediaEncryptions + if (encryptions.length) { + encryptions.unshift([ SettingsModel.MediaEncryptionNone, qsTr('noEncryption') ]) + } - selectedButton = Utils.invert(map)[SettingsModel.mediaEncryption] + return encryptions + })() + + texts: encryptions.map(function (value) { + return value[1] + }) + + onClicked: SettingsModel.mediaEncryption = encryptions[button][0] + + Binding { + property: 'selectedButton' + target: encryption + value: SettingsModel.mediaEncryption } - - onClicked: SettingsModel.mediaEncryption = _resolveButton[button] } } } @@ -77,15 +82,31 @@ TabContainer { } FormLine { + visible: SettingsModel.limeIsSupported + FormGroup { label: qsTr('encryptWithLimeLabel') ExclusiveButtons { - texts: [ - qsTr('limeDisabled'), - qsTr('limeRequired'), - qsTr('limePreferred') - ] + id: lime + + property var limeStates: ([ + [ SettingsModel.LimeStateDisabled, qsTr('limeDisabled') ], + [ SettingsModel.LimeStateMandatory, qsTr('limeRequired') ], + [ SettingsModel.LimeStatePreferred, qsTr('limePreferred') ] + ]) + + texts: limeStates.map(function (value) { + return value[1] + }) + + onClicked: SettingsModel.limeState = limeStates[button][0] + + Binding { + property: 'selectedButton' + target: lime + value: SettingsModel.limeState + } } } } diff --git a/submodules/linphone b/submodules/linphone index e71c6a8c1..8599aec3e 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit e71c6a8c10b53bec9501eee689c7a37c27cc9ba7 +Subproject commit 8599aec3e5cf04afa3780885ffd78a3063abed22