Commit 30d8de51 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): account settings & settings in progress.

parent 3415e100
......@@ -9,6 +9,7 @@
#include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/core/CoreManager.hpp"
#include "../components/settings/AccountSettingsModel.hpp"
#include "../components/settings/SettingsModel.hpp"
#include "../components/timeline/TimelineModel.hpp"
#include "../components/smart-search-bar/SmartSearchBarModel.hpp"
......@@ -143,6 +144,13 @@ void App::registerTypes () {
}
);
qmlRegisterSingletonType<SettingsModel>(
"Linphone", 1, 0, "SettingsModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
return new SettingsModel();
}
);
qmlRegisterSingletonType<TimelineModel>(
"Linphone", 1, 0, "TimelineModel",
[](QQmlEngine *, QJSEngine *) -> QObject *{
......
#ifndef PRESENCE_H_
#define PRESENCE_H_
#include <linphone++/linphone.hh>
#include <QObject>
// =============================================================================
......
#include <QtDebug>
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
#include "AccountSettingsModel.hpp"
// ===================================================================
// =============================================================================
AccountSettingsModel::AccountSettingsModel (QObject *parent) :
QObject(parent) {}
AccountSettingsModel::AccountSettingsModel (QObject *parent) : QObject(parent) {
m_default_proxy = CoreManager::getInstance()->getCore()->getDefaultProxyConfig();
}
QString AccountSettingsModel::getUsername () const {
return "Edward Miller ";
shared_ptr<linphone::Address> address = getDefaultSipAddress();
const string &display_name = address->getDisplayName();
return ::Utils::linphoneStringToQString(
display_name.empty() ? address->getUsername() : display_name
);
}
void AccountSettingsModel::setUsername (const QString &username) {
// NOTHING TODO.
(void) username;
shared_ptr<linphone::Address> address = getDefaultSipAddress();
if (address->setDisplayName(::Utils::qStringToLinphoneString(username)))
qWarning() << QStringLiteral("Unable to set displayName on sip address: `%1`.")
.arg(::Utils::linphoneStringToQString(address->asStringUriOnly()));
emit accountUpdated();
}
Presence::PresenceLevel AccountSettingsModel::getPresenceLevel () const {
......@@ -23,22 +39,14 @@ Presence::PresenceStatus AccountSettingsModel::getPresenceStatus () const {
}
QString AccountSettingsModel::getSipAddress () const {
return QString("e.miller@sip-linphone.org");
}
bool AccountSettingsModel::getAutoAnswerStatus () const {
return true;
return ::Utils::linphoneStringToQString(getDefaultSipAddress()->asStringUriOnly());
}
// TODO: TMP
/*
shared_ptr<linphone::ProxyConfig> cfg = m_core->getDefaultProxyConfig();
shared_ptr<linphone::Address> address = cfg->getIdentityAddress();
shared_ptr<linphone::AuthInfo> auth_info = m_core->findAuthInfo("", address->getUsername(), cfg->getDomain());
// -----------------------------------------------------------------------------
if (auth_info)
qDebug() << "OK";
else
qDebug() << "FAIL";
shared_ptr<linphone::Address> AccountSettingsModel::getDefaultSipAddress () const {
if (m_default_proxy)
return m_default_proxy->getIdentityAddress();
*/
return CoreManager::getInstance()->getCore()->getPrimaryContactParsed();
}
......@@ -10,18 +10,8 @@
class AccountSettingsModel : public QObject {
Q_OBJECT;
Q_PROPERTY(
QString username
READ getUsername
// WRITE setUsername
CONSTANT // TODO: TMP
);
Q_PROPERTY(
QString sipAddress
READ getSipAddress
CONSTANT
);
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY accountUpdated);
Q_PROPERTY(QString sipAddress READ getSipAddress NOTIFY accountUpdated);
Q_PROPERTY(
Presence::PresenceLevel presenceLevel
......@@ -35,15 +25,12 @@ class AccountSettingsModel : public QObject {
CONSTANT
);
Q_PROPERTY(
bool autoAnswerStatus
READ getAutoAnswerStatus
CONSTANT
);
public:
AccountSettingsModel (QObject *parent = Q_NULLPTR);
signals:
void accountUpdated ();
private:
QString getUsername () const;
void setUsername (const QString &username);
......@@ -53,7 +40,9 @@ private:
QString getSipAddress () const;
bool getAutoAnswerStatus () const;
std::shared_ptr<linphone::Address> getDefaultSipAddress () const;
std::shared_ptr<linphone::ProxyConfig> m_default_proxy;
};
#endif // ACCOUNT_SETTINGS_MODEL_H_
#include "../core/CoreManager.hpp"
#include "SettingsModel.hpp"
// ===================================================================
using namespace std;
// =============================================================================
const string SettingsModel::UI_SECTION("ui");
SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
// TODO: Uncomment when `getConfig` will be available.
// m_config = CoreManager::getInstance()->getCore()->getConfig();
}
bool SettingsModel::getAutoAnswerStatus () const {
return true; // TODO: See above.
return !!m_config->getInt(UI_SECTION, "auto_answer", 0);
}
SettingsModel::SettingsModel (QObject *parent) :
QObject(parent) {
bool SettingsModel::setAutoAnswerStatus (bool status) {
m_config->setInt(UI_SECTION, "auto_answer", status);
emit autoAnswerStatusChanged(status);
}
#ifndef SETTINGS_MODEL_H_
#define SETTINGS_MODEL_H_
#include <linphone++/linphone.hh>
#include <QObject>
#include "AccountSettingsModel.hpp"
// ===================================================================
// =============================================================================
class SettingsModel : public QObject {
Q_OBJECT;
Q_PROPERTY(bool autoAnswerStatus READ getAutoAnswerStatus WRITE setAutoAnswerStatus NOTIFY autoAnswerStatusChanged);
public:
SettingsModel (QObject *parent = Q_NULLPTR);
signals:
void autoAnswerStatusChanged (bool status);
private:
QList<AccountSettingsModel *> accountsSettings;
bool getAutoAnswerStatus () const;
bool setAutoAnswerStatus (bool status);
std::shared_ptr<linphone::Config> m_config;
static const std::string UI_SECTION;
};
#endif // SETTINGS_MODEL_H_
......@@ -11,6 +11,8 @@ Item {
// ---------------------------------------------------------------------------
property var account
signal clicked
// ---------------------------------------------------------------------------
......@@ -29,7 +31,7 @@ Item {
Layout.preferredHeight: AccountStatusStyle.presenceLevel.size
Layout.preferredWidth: AccountStatusStyle.presenceLevel.size
icon: 'chevron'
level: AccountSettingsModel.presenceLevel
level: account.presenceLevel
}
Text {
......@@ -39,7 +41,7 @@ Item {
elide: Text.ElideRight
font.bold: true
font.pointSize: AccountStatusStyle.username.fontSize
text: AccountSettingsModel.username
text: account.username
verticalAlignment: Text.AlignBottom
}
}
......@@ -49,7 +51,7 @@ Item {
elide: Text.ElideRight
font.pointSize: AccountStatusStyle.sipAddress.fontSize
height: parent.height / 2
text: AccountSettingsModel.sipAddress
text: account.sipAddress
verticalAlignment: Text.AlignTop
width: parent.width
}
......
......@@ -113,6 +113,8 @@ ApplicationWindow {
Layout.fillHeight: parent.height
Layout.preferredWidth: MainWindowStyle.accountStatus.width
account: AccountSettingsModel
onClicked: Utils.openWindow('ManageAccounts', window)
}
......@@ -120,7 +122,7 @@ ApplicationWindow {
width: MainWindowStyle.autoAnswerStatus.width
Icon {
icon: AccountSettingsModel.autoAnswerStatus
icon: SettingsModel.autoAnswerStatus
? 'auto_answer'
: ''
iconSize: MainWindowStyle.autoAnswerStatus.iconSize
......
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