Commit 8d5e9a82 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/Account/AccountStatus): handle registration state

parent 873f9df4
...@@ -42,6 +42,7 @@ if(NOT WIN32) ...@@ -42,6 +42,7 @@ if(NOT WIN32)
-Wall \ -Wall \
-Wcast-align \ -Wcast-align \
-Wconversion \ -Wconversion \
-Werror=return-type \
-Wextra \ -Wextra \
-Wfloat-equal \ -Wfloat-equal \
-Winit-self \ -Winit-self \
......
...@@ -78,17 +78,17 @@ void CoreHandlers::onNotifyPresenceReceivedForUriOrTel ( ...@@ -78,17 +78,17 @@ void CoreHandlers::onNotifyPresenceReceivedForUriOrTel (
} }
void CoreHandlers::onNotifyPresenceReceived ( void CoreHandlers::onNotifyPresenceReceived (
const std::shared_ptr<linphone::Core> &, const shared_ptr<linphone::Core> &,
const std::shared_ptr<linphone::Friend> &linphone_friend const shared_ptr<linphone::Friend> &linphone_friend
) { ) {
linphone_friend->getData<ContactModel>("contact-model").refreshPresence(); linphone_friend->getData<ContactModel>("contact-model").refreshPresence();
} }
void CoreHandlers::onRegistrationStateChanged ( void CoreHandlers::onRegistrationStateChanged (
const shared_ptr<linphone::Core> &core, const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::ProxyConfig> &config, const shared_ptr<linphone::ProxyConfig> &proxy_config,
linphone::RegistrationState state, linphone::RegistrationState state,
const string &message const string &
) { ) {
// TODO. emit registrationStateChanged(proxy_config, state);
} }
...@@ -37,6 +37,7 @@ signals: ...@@ -37,6 +37,7 @@ signals:
void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state); void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void messageReceived (const std::shared_ptr<linphone::ChatMessage> &message); void messageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
void presenceReceived (const QString &sip_address, const std::shared_ptr<const linphone::PresenceModel> &presence_model); void presenceReceived (const QString &sip_address, const std::shared_ptr<const linphone::PresenceModel> &presence_model);
void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxy_config, linphone::RegistrationState state);
private: private:
void onAuthenticationRequested ( void onAuthenticationRequested (
...@@ -72,7 +73,7 @@ private: ...@@ -72,7 +73,7 @@ private:
void onRegistrationStateChanged ( void onRegistrationStateChanged (
const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::ProxyConfig> &config, const std::shared_ptr<linphone::ProxyConfig> &proxy_config,
linphone::RegistrationState state, linphone::RegistrationState state,
const std::string &message const std::string &message
) override; ) override;
......
...@@ -31,6 +31,34 @@ using namespace std; ...@@ -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<linphone::ProxyConfig> &proxy_config) { bool AccountSettingsModel::addOrUpdateProxyConfig (const shared_ptr<linphone::ProxyConfig> &proxy_config) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
...@@ -73,6 +101,7 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr<li ...@@ -73,6 +101,7 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr<li
map["registerEnabled"] = proxy_config->registerEnabled(); map["registerEnabled"] = proxy_config->registerEnabled();
map["publishPresence"] = proxy_config->publishEnabled(); map["publishPresence"] = proxy_config->publishEnabled();
map["avpfEnabled"] = proxy_config->getAvpfMode() == linphone::AVPFMode::AVPFModeEnabled; map["avpfEnabled"] = proxy_config->getAvpfMode() == linphone::AVPFMode::AVPFModeEnabled;
map["registrationState"] = mapLinphoneRegistrationStateToUi(proxy_config->getState());
return map; return map;
} }
...@@ -163,6 +192,11 @@ QString AccountSettingsModel::getSipAddress () const { ...@@ -163,6 +192,11 @@ QString AccountSettingsModel::getSipAddress () const {
return ::Utils::linphoneStringToQString(getUsedSipAddress()->asStringUriOnly()); return ::Utils::linphoneStringToQString(getUsedSipAddress()->asStringUriOnly());
} }
AccountSettingsModel::RegistrationState AccountSettingsModel::getRegistrationState () const {
shared_ptr<linphone::ProxyConfig> proxy_config = CoreManager::getInstance()->getCore()->getDefaultProxyConfig();
return proxy_config ? mapLinphoneRegistrationStateToUi(proxy_config->getState()) : RegistrationStateNotRegistered;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QString AccountSettingsModel::getPrimaryUsername () const { QString AccountSettingsModel::getPrimaryUsername () const {
...@@ -243,3 +277,12 @@ shared_ptr<const linphone::Address> AccountSettingsModel::getUsedSipAddress () c ...@@ -243,3 +277,12 @@ shared_ptr<const linphone::Address> AccountSettingsModel::getUsedSipAddress () c
return proxy_config ? proxy_config->getIdentityAddress() : core->getPrimaryContactParsed(); return proxy_config ? proxy_config->getIdentityAddress() : core->getPrimaryContactParsed();
} }
// -----------------------------------------------------------------------------
void AccountSettingsModel::handleRegistrationStateChanged (
const shared_ptr<linphone::ProxyConfig> &,
linphone::RegistrationState
) {
emit accountSettingsUpdated();
}
...@@ -31,9 +31,12 @@ ...@@ -31,9 +31,12 @@
class AccountSettingsModel : public QObject { class AccountSettingsModel : public QObject {
Q_OBJECT; Q_OBJECT;
// Selected proxy config.
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY accountSettingsUpdated); Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY accountSettingsUpdated);
Q_PROPERTY(QString sipAddress READ getSipAddress 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 primaryDisplayname READ getPrimaryDisplayname WRITE setPrimaryDisplayname NOTIFY accountSettingsUpdated);
Q_PROPERTY(QString primaryUsername READ getPrimaryUsername WRITE setPrimaryUsername NOTIFY accountSettingsUpdated); Q_PROPERTY(QString primaryUsername READ getPrimaryUsername WRITE setPrimaryUsername NOTIFY accountSettingsUpdated);
Q_PROPERTY(QString primarySipAddress READ getPrimarySipAddress NOTIFY accountSettingsUpdated); Q_PROPERTY(QString primarySipAddress READ getPrimarySipAddress NOTIFY accountSettingsUpdated);
...@@ -41,7 +44,16 @@ class AccountSettingsModel : public QObject { ...@@ -41,7 +44,16 @@ class AccountSettingsModel : public QObject {
Q_PROPERTY(QVariantList accounts READ getAccounts NOTIFY accountSettingsUpdated); Q_PROPERTY(QVariantList accounts READ getAccounts NOTIFY accountSettingsUpdated);
public: 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<linphone::ProxyConfig> &proxy_config); bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
...@@ -63,6 +75,10 @@ private: ...@@ -63,6 +75,10 @@ private:
QString getSipAddress () const; QString getSipAddress () const;
RegistrationState getRegistrationState () const;
// ---------------------------------------------------------------------------
QString getPrimaryUsername () const; QString getPrimaryUsername () const;
void setPrimaryUsername (const QString &username); void setPrimaryUsername (const QString &username);
...@@ -71,10 +87,19 @@ private: ...@@ -71,10 +87,19 @@ private:
QString getPrimarySipAddress () const; QString getPrimarySipAddress () const;
// ---------------------------------------------------------------------------
QVariantList getAccounts () const; QVariantList getAccounts () const;
void setUsedSipAddress (const std::shared_ptr<const linphone::Address> &address); void setUsedSipAddress (const std::shared_ptr<const linphone::Address> &address);
std::shared_ptr<const linphone::Address> getUsedSipAddress () const; std::shared_ptr<const linphone::Address> getUsedSipAddress () const;
// ---------------------------------------------------------------------------
void handleRegistrationStateChanged (
const std::shared_ptr<linphone::ProxyConfig> &proxy_config,
linphone::RegistrationState state
);
}; };
Q_DECLARE_METATYPE(std::shared_ptr<linphone::ProxyConfig> ); Q_DECLARE_METATYPE(std::shared_ptr<linphone::ProxyConfig> );
......
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import Common 1.0
import Linphone 1.0 import Linphone 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
...@@ -11,8 +12,6 @@ Item { ...@@ -11,8 +12,6 @@ Item {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
readonly property var _account: AccountSettingsModel
signal clicked signal clicked
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -25,12 +24,28 @@ Item { ...@@ -25,12 +24,28 @@ Item {
spacing: AccountStatusStyle.horizontalSpacing spacing: AccountStatusStyle.horizontalSpacing
width: parent.width width: parent.width
PresenceLevel { Item {
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin Layout.bottomMargin: AccountStatusStyle.presenceLevel.bottomMargin
Layout.preferredHeight: AccountStatusStyle.presenceLevel.size Layout.preferredHeight: AccountStatusStyle.presenceLevel.size
Layout.preferredWidth: 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 { Text {
...@@ -40,7 +55,7 @@ Item { ...@@ -40,7 +55,7 @@ Item {
elide: Text.ElideRight elide: Text.ElideRight
font.bold: true font.bold: true
font.pointSize: AccountStatusStyle.username.fontSize font.pointSize: AccountStatusStyle.username.fontSize
text: accountStatus._account.username text: AccountSettingsModel.username
verticalAlignment: Text.AlignBottom verticalAlignment: Text.AlignBottom
} }
} }
...@@ -50,7 +65,7 @@ Item { ...@@ -50,7 +65,7 @@ Item {
elide: Text.ElideRight elide: Text.ElideRight
font.pointSize: AccountStatusStyle.sipAddress.fontSize font.pointSize: AccountStatusStyle.sipAddress.fontSize
height: parent.height / 2 height: parent.height / 2
text: accountStatus._account.sipAddress text: AccountSettingsModel.sipAddress
verticalAlignment: Text.AlignTop verticalAlignment: Text.AlignTop
width: parent.width width: parent.width
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment