diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index 50bc65dc3..0892b4e60 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -42,6 +42,7 @@ if(NOT WIN32) -Wall \ -Wcast-align \ -Wconversion \ +-Werror=return-type \ -Wextra \ -Wfloat-equal \ -Winit-self \ diff --git a/linphone-desktop/src/components/core/CoreHandlers.cpp b/linphone-desktop/src/components/core/CoreHandlers.cpp index 0691e70a1..fa61d956a 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.cpp +++ b/linphone-desktop/src/components/core/CoreHandlers.cpp @@ -78,17 +78,17 @@ void CoreHandlers::onNotifyPresenceReceivedForUriOrTel ( } void CoreHandlers::onNotifyPresenceReceived ( - const std::shared_ptr &, - const std::shared_ptr &linphone_friend + const shared_ptr &, + const shared_ptr &linphone_friend ) { linphone_friend->getData("contact-model").refreshPresence(); } void CoreHandlers::onRegistrationStateChanged ( - const shared_ptr &core, - const shared_ptr &config, + const shared_ptr &, + const shared_ptr &proxy_config, linphone::RegistrationState state, - const string &message + const string & ) { - // TODO. + emit registrationStateChanged(proxy_config, state); } diff --git a/linphone-desktop/src/components/core/CoreHandlers.hpp b/linphone-desktop/src/components/core/CoreHandlers.hpp index 68f1d8254..5e5a51b0f 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.hpp +++ b/linphone-desktop/src/components/core/CoreHandlers.hpp @@ -37,6 +37,7 @@ signals: void callStateChanged (const std::shared_ptr &call, linphone::CallState state); void messageReceived (const std::shared_ptr &message); void presenceReceived (const QString &sip_address, const std::shared_ptr &presence_model); + void registrationStateChanged (const std::shared_ptr &proxy_config, linphone::RegistrationState state); private: void onAuthenticationRequested ( @@ -72,7 +73,7 @@ private: void onRegistrationStateChanged ( const std::shared_ptr &core, - const std::shared_ptr &config, + const std::shared_ptr &proxy_config, linphone::RegistrationState state, const std::string &message ) override; diff --git a/linphone-desktop/src/components/settings/AccountSettingsModel.cpp b/linphone-desktop/src/components/settings/AccountSettingsModel.cpp index 3af3a3467..7015304fc 100644 --- a/linphone-desktop/src/components/settings/AccountSettingsModel.cpp +++ b/linphone-desktop/src/components/settings/AccountSettingsModel.cpp @@ -31,6 +31,34 @@ using namespace std; // ============================================================================= +inline AccountSettingsModel::RegistrationState mapLinphoneRegistrationStateToUi (linphone::RegistrationState state) { + switch (state) { + case linphone::RegistrationStateNone: + case linphone::RegistrationStateCleared: + case linphone::RegistrationStateFailed: + return AccountSettingsModel::RegistrationStateNotRegistered; + + case linphone::RegistrationStateProgress: + return AccountSettingsModel::RegistrationStateInProgress; + + case linphone::RegistrationStateOk: + break; + } + + return AccountSettingsModel::RegistrationStateRegistered; +} + +// ----------------------------------------------------------------------------- + +AccountSettingsModel::AccountSettingsModel (QObject *parent) : QObject(parent) { + QObject::connect( + &(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::registrationStateChanged, + this, &AccountSettingsModel::handleRegistrationStateChanged + ); +} + +// ----------------------------------------------------------------------------- + bool AccountSettingsModel::addOrUpdateProxyConfig (const shared_ptr &proxy_config) { shared_ptr core = CoreManager::getInstance()->getCore(); @@ -73,6 +101,7 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr
  • registerEnabled(); map["publishPresence"] = proxy_config->publishEnabled(); map["avpfEnabled"] = proxy_config->getAvpfMode() == linphone::AVPFMode::AVPFModeEnabled; + map["registrationState"] = mapLinphoneRegistrationStateToUi(proxy_config->getState()); return map; } @@ -163,6 +192,11 @@ QString AccountSettingsModel::getSipAddress () const { return ::Utils::linphoneStringToQString(getUsedSipAddress()->asStringUriOnly()); } +AccountSettingsModel::RegistrationState AccountSettingsModel::getRegistrationState () const { + shared_ptr proxy_config = CoreManager::getInstance()->getCore()->getDefaultProxyConfig(); + return proxy_config ? mapLinphoneRegistrationStateToUi(proxy_config->getState()) : RegistrationStateNotRegistered; +} + // ----------------------------------------------------------------------------- QString AccountSettingsModel::getPrimaryUsername () const { @@ -243,3 +277,12 @@ shared_ptr AccountSettingsModel::getUsedSipAddress () c return proxy_config ? proxy_config->getIdentityAddress() : core->getPrimaryContactParsed(); } + +// ----------------------------------------------------------------------------- + +void AccountSettingsModel::handleRegistrationStateChanged ( + const shared_ptr &, + linphone::RegistrationState +) { + emit accountSettingsUpdated(); +} diff --git a/linphone-desktop/src/components/settings/AccountSettingsModel.hpp b/linphone-desktop/src/components/settings/AccountSettingsModel.hpp index 0a1b3023e..d9d5d970f 100644 --- a/linphone-desktop/src/components/settings/AccountSettingsModel.hpp +++ b/linphone-desktop/src/components/settings/AccountSettingsModel.hpp @@ -31,9 +31,12 @@ class AccountSettingsModel : public QObject { Q_OBJECT; + // Selected proxy config. Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY accountSettingsUpdated); Q_PROPERTY(QString sipAddress READ getSipAddress NOTIFY accountSettingsUpdated); + Q_PROPERTY(RegistrationState registrationState READ getRegistrationState NOTIFY accountSettingsUpdated); + // Default info. Q_PROPERTY(QString primaryDisplayname READ getPrimaryDisplayname WRITE setPrimaryDisplayname NOTIFY accountSettingsUpdated); Q_PROPERTY(QString primaryUsername READ getPrimaryUsername WRITE setPrimaryUsername NOTIFY accountSettingsUpdated); Q_PROPERTY(QString primarySipAddress READ getPrimarySipAddress NOTIFY accountSettingsUpdated); @@ -41,7 +44,16 @@ class AccountSettingsModel : public QObject { Q_PROPERTY(QVariantList accounts READ getAccounts NOTIFY accountSettingsUpdated); public: - AccountSettingsModel (QObject *parent = Q_NULLPTR) : QObject(parent) {} + enum RegistrationState { + RegistrationStateRegistered, + RegistrationStateNotRegistered, + RegistrationStateInProgress + }; + + Q_ENUM(RegistrationState); + + AccountSettingsModel (QObject *parent = Q_NULLPTR); + ~AccountSettingsModel () = default; bool addOrUpdateProxyConfig (const std::shared_ptr &proxy_config); @@ -63,6 +75,10 @@ private: QString getSipAddress () const; + RegistrationState getRegistrationState () const; + + // --------------------------------------------------------------------------- + QString getPrimaryUsername () const; void setPrimaryUsername (const QString &username); @@ -71,10 +87,19 @@ private: QString getPrimarySipAddress () const; + // --------------------------------------------------------------------------- + QVariantList getAccounts () const; void setUsedSipAddress (const std::shared_ptr &address); std::shared_ptr getUsedSipAddress () const; + + // --------------------------------------------------------------------------- + + void handleRegistrationStateChanged ( + const std::shared_ptr &proxy_config, + linphone::RegistrationState state + ); }; Q_DECLARE_METATYPE(std::shared_ptr ); diff --git a/linphone-desktop/ui/modules/Linphone/Account/AccountStatus.qml b/linphone-desktop/ui/modules/Linphone/Account/AccountStatus.qml index c2f8e6eb7..4c522c9cc 100644 --- a/linphone-desktop/ui/modules/Linphone/Account/AccountStatus.qml +++ b/linphone-desktop/ui/modules/Linphone/Account/AccountStatus.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 +import Common 1.0 import Linphone 1.0 import Linphone.Styles 1.0 @@ -11,8 +12,6 @@ Item { // --------------------------------------------------------------------------- - readonly property var _account: AccountSettingsModel - signal clicked // --------------------------------------------------------------------------- @@ -25,12 +24,28 @@ Item { spacing: AccountStatusStyle.horizontalSpacing width: parent.width - PresenceLevel { + Item { Layout.alignment: Qt.AlignBottom Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin Layout.preferredHeight: AccountStatusStyle.presenceLevel.size Layout.preferredWidth: AccountStatusStyle.presenceLevel.size - level: OwnPresenceModel.presenceLevel + + PresenceLevel { + anchors.fill: parent + level: OwnPresenceModel.presenceLevel + visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateRegistered + } + + BusyIndicator { + anchors.fill: parent + running: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateInProgress + } + + Icon { + iconSize: parent.width + icon: 'generic_error' + visible: AccountSettingsModel.registrationState === AccountSettingsModel.RegistrationStateNotRegistered + } } Text { @@ -40,7 +55,7 @@ Item { elide: Text.ElideRight font.bold: true font.pointSize: AccountStatusStyle.username.fontSize - text: accountStatus._account.username + text: AccountSettingsModel.username verticalAlignment: Text.AlignBottom } } @@ -50,7 +65,7 @@ Item { elide: Text.ElideRight font.pointSize: AccountStatusStyle.sipAddress.fontSize height: parent.height / 2 - text: accountStatus._account.sipAddress + text: AccountSettingsModel.sipAddress verticalAlignment: Text.AlignTop width: parent.width }