diff --git a/assets/languages/en.ts b/assets/languages/en.ts index 247d44e24..36d9a4c37 100644 --- a/assets/languages/en.ts +++ b/assets/languages/en.ts @@ -1240,6 +1240,22 @@ your friend's SIP address or username. enableAdaptiveRateControlLabel Enable adaptive rate control + + presenceTitle + Presence + + + rlsUriLabel + Use RLS URI + + + rlsUriAuto + AUTO + + + rlsUriDisabled + NEVER + SettingsSipAccounts diff --git a/assets/languages/fr.ts b/assets/languages/fr.ts index 7d858f22b..7017c1cb7 100644 --- a/assets/languages/fr.ts +++ b/assets/languages/fr.ts @@ -1238,6 +1238,22 @@ Cliquez ici : <a href="%1">%1</a> enableAdaptiveRateControlLabel Activer le contrôle de débit adaptif + + presenceTitle + Présence + + + rlsUriLabel + Utiliser l'URI RLS + + + rlsUriAuto + AUTO + + + rlsUriDisabled + JAMAIS + SettingsSipAccounts diff --git a/src/app/paths/Paths.cpp b/src/app/paths/Paths.cpp index 45b89ad2b..75725ce48 100644 --- a/src/app/paths/Paths.cpp +++ b/src/app/paths/Paths.cpp @@ -48,10 +48,6 @@ #define PATH_MESSAGE_HISTORY_LIST "/message-history.db" #define PATH_ZRTP_SECRETS "/zidcache" -#ifndef RLS_URI - #define RLS_URI "sips:rls@sip.linphone.org" -#endif // ifndef RLS_URI - using namespace std; // ============================================================================= @@ -271,14 +267,6 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new } } -inline void setRlsUri (const QString &configPath) { - shared_ptr config = linphone::Config::newWithFactory(::Utils::appStringToCoreString(configPath), ""); - if (config->getString("sip", "rls_uri", "").empty()) { - config->setString("sip", "rls_uri", RLS_URI); - config->sync(); - } -} - void Paths::migrate () { QString newPath = ::getAppConfigFilePath(); QString oldBaseDir = QSysInfo::productType() == "windows" @@ -286,11 +274,8 @@ void Paths::migrate () { : QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QString oldPath = oldBaseDir + "/.linphonerc"; - if (!::filePathExists(newPath) && ::filePathExists(oldPath)) { + if (!::filePathExists(newPath) && ::filePathExists(oldPath)) ::migrateConfigurationFile(oldPath, newPath); - /* Define RLS uri so that presence switches from peer-to-peer mode to list mode. */ - ::setRlsUri(newPath); - } newPath = ::getAppCallHistoryFilePath(); oldPath = oldBaseDir + "/.linphone-call-history.db"; diff --git a/src/components/assistant/AssistantModel.cpp b/src/components/assistant/AssistantModel.cpp index 7715bf909..1364f782c 100644 --- a/src/components/assistant/AssistantModel.cpp +++ b/src/components/assistant/AssistantModel.cpp @@ -40,6 +40,12 @@ public: } private: + void createProxyConfig (const shared_ptr &creator) { + shared_ptr proxyConfig = creator->createProxyConfig(); + Q_CHECK_PTR(proxyConfig); + CoreManager::getInstance()->getSettingsModel()->configureRlsUri(proxyConfig); + } + void onCreateAccount ( const shared_ptr &, linphone::AccountCreatorStatus status, @@ -63,9 +69,7 @@ private: const string & ) override { if (status == linphone::AccountCreatorStatusAccountExist || status == linphone::AccountCreatorStatusAccountExistWithAlias) { - shared_ptr proxyConfig = creator->createProxyConfig(); - Q_CHECK_PTR(proxyConfig); - + createProxyConfig(creator); emit mAssistant->loginStatusChanged(QString("")); } else { if (status == linphone::AccountCreatorStatusRequestFailed) @@ -84,10 +88,8 @@ private: status == linphone::AccountCreatorStatusAccountActivated || status == linphone::AccountCreatorStatusAccountAlreadyActivated ) { - if (creator->getEmail().empty()) { - shared_ptr proxyConfig = creator->createProxyConfig(); - Q_CHECK_PTR(proxyConfig); - } + if (creator->getEmail().empty()) + createProxyConfig(creator); emit mAssistant->activateStatusChanged(QString("")); } else { @@ -104,9 +106,7 @@ private: const string & ) override { if (status == linphone::AccountCreatorStatusAccountActivated) { - shared_ptr proxyConfig = creator->createProxyConfig(); - Q_CHECK_PTR(proxyConfig); - + createProxyConfig(creator); emit mAssistant->activateStatusChanged(QString("")); } else { if (status == linphone::AccountCreatorStatusRequestFailed) diff --git a/src/components/settings/AccountSettingsModel.cpp b/src/components/settings/AccountSettingsModel.cpp index af1dc735e..344f36bb4 100644 --- a/src/components/settings/AccountSettingsModel.cpp +++ b/src/components/settings/AccountSettingsModel.cpp @@ -61,7 +61,8 @@ AccountSettingsModel::AccountSettingsModel (QObject *parent) : QObject(parent) { bool AccountSettingsModel::addOrUpdateProxyConfig (const shared_ptr &proxyConfig) { Q_CHECK_PTR(proxyConfig); - shared_ptr core = CoreManager::getInstance()->getCore(); + CoreManager *coreManager = CoreManager::getInstance(); + shared_ptr core = coreManager->getCore(); list > proxyConfigs = core->getProxyConfigList(); if (find(proxyConfigs.cbegin(), proxyConfigs.cend(), proxyConfig) != proxyConfigs.cend()) { @@ -70,12 +71,15 @@ bool AccountSettingsModel::addOrUpdateProxyConfig (const shared_ptrgetIdentityAddress()->asString())); return false; } - } else if (core->addProxyConfig(proxyConfig) == -1) { - qWarning() << QStringLiteral("Unable to add proxy config: `%1`.") - .arg(::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); - return false; + coreManager->getSettingsModel()->configureRlsUri(); + } else { + if (core->addProxyConfig(proxyConfig) == -1) { + qWarning() << QStringLiteral("Unable to add proxy config: `%1`.") + .arg(::Utils::coreStringToAppString(proxyConfig->getIdentityAddress()->asString())); + return false; + } + coreManager->getSettingsModel()->configureRlsUri(proxyConfig); } - emit accountSettingsUpdated(); return true; @@ -115,7 +119,10 @@ void AccountSettingsModel::setDefaultProxyConfig (const shared_ptr &proxyConfig) { Q_CHECK_PTR(proxyConfig); - CoreManager::getInstance()->getCore()->removeProxyConfig(proxyConfig); + CoreManager *coreManager = CoreManager::getInstance(); + coreManager->getCore()->removeProxyConfig(proxyConfig); + coreManager->getSettingsModel()->configureRlsUri(); + emit accountSettingsUpdated(); } diff --git a/src/components/settings/SettingsModel.cpp b/src/components/settings/SettingsModel.cpp index f243df470..a8c1b1887 100644 --- a/src/components/settings/SettingsModel.cpp +++ b/src/components/settings/SettingsModel.cpp @@ -29,6 +29,10 @@ #include "SettingsModel.hpp" +#ifndef DEFAULT_RLS_URI + #define DEFAULT_RLS_URI "sips:rls@sip.linphone.org" +#endif // ifndef RLS_URI + using namespace std; // ============================================================================= @@ -37,6 +41,7 @@ const string SettingsModel::UI_SECTION("ui"); SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { mConfig = CoreManager::getInstance()->getCore()->getConfig(); + configureRlsUri(); } // ============================================================================= @@ -647,6 +652,62 @@ void SettingsModel::setDscpVideo (int dscp) { emit dscpVideoChanged(dscp); } +// ----------------------------------------------------------------------------- + +bool SettingsModel::getRlsUriEnabled () const { + return !!mConfig->getInt(UI_SECTION, "rls_uri_enabled", true); +} + +void SettingsModel::setRlsUriEnabled (bool status) { + mConfig->setInt(UI_SECTION, "rls_uri_enabled", status); + mConfig->setString("sip", "rls_uri", status ? DEFAULT_RLS_URI : ""); + emit rlsUriEnabledChanged(status); +} + +static string getRlsUriDomain () { + static string domain; + if (!domain.empty()) + return domain; + + shared_ptr linphoneAddress = CoreManager::getInstance()->getCore()->createAddress(DEFAULT_RLS_URI); + Q_CHECK_PTR(linphoneAddress); + domain = linphoneAddress->getDomain(); + return domain; +} + +void SettingsModel::configureRlsUri () { + // Ensure rls uri is empty. + if (!getRlsUriEnabled()) { + mConfig->setString("sip", "rls_uri", ""); + return; + } + + // Set rls uri if necessary. + const string domain = getRlsUriDomain(); + for (const auto &proxyConfig : CoreManager::getInstance()->getCore()->getProxyConfigList()) + if (proxyConfig->getDomain() == domain) { + mConfig->setString("sip", "rls_uri", DEFAULT_RLS_URI); + return; + } + + mConfig->setString("sip", "rls_uri", ""); +} + +void SettingsModel::configureRlsUri (const shared_ptr &proxyConfig) { + if (!getRlsUriEnabled()) { + mConfig->setString("sip", "rls_uri", ""); + return; + } + + const string domain = getRlsUriDomain(); + if (proxyConfig->getDomain() == domain) { + mConfig->setString("sip", "rls_uri", DEFAULT_RLS_URI); + return; + } + + mConfig->setString("sip", "rls_uri", ""); +} + // ============================================================================= // UI. // ============================================================================= diff --git a/src/components/settings/SettingsModel.hpp b/src/components/settings/SettingsModel.hpp index f6aaf2ccf..686da9a41 100644 --- a/src/components/settings/SettingsModel.hpp +++ b/src/components/settings/SettingsModel.hpp @@ -111,6 +111,8 @@ class SettingsModel : public QObject { Q_PROPERTY(int dscpAudio READ getDscpAudio WRITE setDscpAudio NOTIFY dscpAudioChanged); Q_PROPERTY(int dscpVideo READ getDscpVideo WRITE setDscpVideo NOTIFY dscpVideoChanged); + Q_PROPERTY(bool rlsUriEnabled READ getRlsUriEnabled WRITE setRlsUriEnabled NOTIFY rlsUriEnabledChanged); + // UI. ----------------------------------------------------------------------- Q_PROPERTY(QString remoteProvisioning READ getRemoteProvisioning WRITE setRemoteProvisioning NOTIFY remoteProvisioningChanged); @@ -272,6 +274,12 @@ public: int getDscpVideo () const; void setDscpVideo (int dscp); + bool getRlsUriEnabled () const; + void setRlsUriEnabled (bool status); + + void configureRlsUri (); + void configureRlsUri (const std::shared_ptr &proxyConfig); + // UI. ----------------------------------------------------------------------- QString getSavedScreenshotsFolder () const; @@ -375,6 +383,8 @@ signals: void dscpAudioChanged (int dscp); void dscpVideoChanged (int dscp); + void rlsUriEnabledChanged (bool status); + // UI. ----------------------------------------------------------------------- void savedScreenshotsFolderChanged (const QString &folder); diff --git a/ui/views/App/Settings/SettingsNetwork.qml b/ui/views/App/Settings/SettingsNetwork.qml index 0dbc92a6d..fedef2068 100644 --- a/ui/views/App/Settings/SettingsNetwork.qml +++ b/ui/views/App/Settings/SettingsNetwork.qml @@ -96,6 +96,31 @@ TabContainer { } } + // ------------------------------------------------------------------------- + // Presence. + // ------------------------------------------------------------------------- + + Form { + title: qsTr('presenceTitle') + width: parent.width + + FormLine { + FormGroup { + label: qsTr('rlsUriLabel') + + ExclusiveButtons { + selectedButton: Number(!SettingsModel.rlsUriEnabled) + texts: [ + qsTr('rlsUriAuto'), + qsTr('rlsUriDisabled') + ] + + onClicked: SettingsModel.rlsUriEnabled = !button + } + } + } + } + // ------------------------------------------------------------------------- // Network protocol and ports. // -------------------------------------------------------------------------