Commit 74311876 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/views/App/Settings/SettingsSipAccounts): can add or update sip account

parent 5689d885
......@@ -64,7 +64,7 @@ void AccountSettingsModel::removeProxyConfig (const shared_ptr<linphone::ProxyCo
emit accountSettingsUpdated();
}
void AccountSettingsModel::addOrUpdateProxyConfig (
bool AccountSettingsModel::addOrUpdateProxyConfig (
const std::shared_ptr<linphone::ProxyConfig> &proxy_config,
const QVariantMap &data
) {
......@@ -78,7 +78,7 @@ void AccountSettingsModel::addOrUpdateProxyConfig (
);
if (!address) {
qWarning() << QStringLiteral("Unable to create sip address object from: `%1`.").arg(literal);
return;
return false;
}
proxy_config->setIdentityAddress(address);
......@@ -86,28 +86,11 @@ void AccountSettingsModel::addOrUpdateProxyConfig (
// Server address.
{
QString q_server_address = data["serverAddress"].toString();
string s_server_address = ::Utils::qStringToLinphoneString(q_server_address);
if (!proxy_config->setServerAddr(s_server_address)) {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(s_server_address);
if (!address) {
qWarning() << QStringLiteral("Unable to add server address: `%1`.").arg(q_server_address);
return;
}
QString transport = data["transport"].toString();
if (transport == "TCP")
address->setTransport(linphone::TransportType::TransportTypeTcp);
else if (transport == "UDP")
address->setTransport(linphone::TransportType::TransportTypeTcp);
else
address->setTransport(linphone::TransportType::TransportTypeTls);
if (!proxy_config->setServerAddr(address->asString())) {
qWarning() << QStringLiteral("Unable to add server address: `%1`.").arg(q_server_address);
return;
}
QString server_address = data["serverAddress"].toString();
if (proxy_config->setServerAddr(::Utils::qStringToLinphoneString(server_address))) {
qWarning() << QStringLiteral("Unable to add server address: `%1`.").arg(server_address);
return false;
}
}
......@@ -126,43 +109,22 @@ void AccountSettingsModel::addOrUpdateProxyConfig (
if (find(proxy_configs.cbegin(), proxy_configs.cend(), proxy_config) != proxy_configs.cend()) {
if (proxy_config->done() == -1) {
qWarning() << QStringLiteral("Unable to update proxy config: `%1`.").arg(literal);
return;
return false;
}
} else if (core->addProxyConfig(proxy_config) == -1) {
qWarning() << QStringLiteral("Unable to add proxy config: `%1`.").arg(literal);
return;
return false;
}
emit accountSettingsUpdated();
return true;
}
std::shared_ptr<linphone::ProxyConfig> AccountSettingsModel::createProxyConfig () {
return CoreManager::getInstance()->getCore()->createProxyConfig();
}
QString AccountSettingsModel::getTransportFromServerAddress (const QString &server_address) {
const shared_ptr<const linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(server_address)
);
if (!address)
return QStringLiteral("");
switch (address->getTransport()) {
case linphone::TransportTypeUdp:
return QStringLiteral("UDP");
case linphone::TransportTypeTcp:
return QStringLiteral("TCP");
case linphone::TransportTypeTls:
return QStringLiteral("TLS");
case linphone::TransportTypeDtls:
break;
}
return QStringLiteral("");
}
// -----------------------------------------------------------------------------
QString AccountSettingsModel::getUsername () const {
......
......@@ -47,13 +47,11 @@ public:
Q_INVOKABLE void setDefaultProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
Q_INVOKABLE void addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config, const QVariantMap &data);
Q_INVOKABLE bool addOrUpdateProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config, const QVariantMap &data);
Q_INVOKABLE void removeProxyConfig (const std::shared_ptr<linphone::ProxyConfig> &proxy_config);
Q_INVOKABLE std::shared_ptr<linphone::ProxyConfig> createProxyConfig ();
Q_INVOKABLE QString getTransportFromServerAddress (const QString &server_address);
signals:
void accountSettingsUpdated ();
......
......@@ -140,6 +140,57 @@ QString SipAddressesModel::interpretUrl (const QString &sip_address) const {
return l_address ? ::Utils::linphoneStringToQString(l_address->asStringUriOnly()) : "";
}
QString SipAddressesModel::getTransportFromSipAddress (const QString &sip_address) const {
const shared_ptr<const linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(sip_address)
);
if (!address)
return QStringLiteral("");
switch (address->getTransport()) {
case linphone::TransportTypeUdp:
return QStringLiteral("UDP");
case linphone::TransportTypeTcp:
return QStringLiteral("TCP");
case linphone::TransportTypeTls:
return QStringLiteral("TLS");
case linphone::TransportTypeDtls:
return QStringLiteral("DTLS");
}
return QStringLiteral("");
}
QString SipAddressesModel::addTransportToSipAddress (const QString &sip_address, const QString &transport) const {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(sip_address)
);
if (!address)
return "";
QString _transport = transport.toUpper();
if (_transport == "TCP")
address->setTransport(linphone::TransportType::TransportTypeTcp);
else if (_transport == "UDP")
address->setTransport(linphone::TransportType::TransportTypeUdp);
else if (_transport == "TLS")
address->setTransport(linphone::TransportType::TransportTypeTls);
else
address->setTransport(linphone::TransportType::TransportTypeDtls);
return ::Utils::linphoneStringToQString(address->asString());
}
bool SipAddressesModel::sipAddressIsValid (const QString &sip_address) const {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(sip_address)
);
return !!address;
}
// -----------------------------------------------------------------------------
bool SipAddressesModel::removeRow (int row, const QModelIndex &parent) {
......@@ -309,9 +360,7 @@ void SipAddressesModel::addOrUpdateSipAddress (QVariantMap &map, const shared_pt
}
void SipAddressesModel::addOrUpdateSipAddress (QVariantMap &map, const shared_ptr<linphone::ChatMessage> &message) {
// FIXME: Bug in the core, count is incremented after this function call.
// So... +1!
int count = message->getChatRoom()->getUnreadMessagesCount() + 1;
int count = message->getChatRoom()->getUnreadMessagesCount();
map["timestamp"] = QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000);
map["unreadMessagesCount"] = count;
......
......@@ -50,8 +50,18 @@ public:
Q_INVOKABLE ContactModel *mapSipAddressToContact (const QString &sip_address) const;
Q_INVOKABLE SipAddressObserver *getSipAddressObserver (const QString &sip_address);
// ---------------------------------------------------------------------------
// Sip addresses helpers.
// ---------------------------------------------------------------------------
Q_INVOKABLE QString interpretUrl (const QString &sip_address) const;
Q_INVOKABLE QString getTransportFromSipAddress (const QString &sip_address) const;
Q_INVOKABLE QString addTransportToSipAddress (const QString &sip_address, const QString &transport) const;
Q_INVOKABLE bool sipAddressIsValid (const QString &sip_address) const;
// ---------------------------------------------------------------------------
private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
......
......@@ -36,20 +36,23 @@ function initForm (account) {
registerEnabled.checked = config.registerEnabled
publishPresence.checked = config.publishPresence
avpfEnabled.checked = config.avpfEnabled
}
function handleServerAddressChanged (address) {
var newTransport = Linphone.AccountSettingsModel.getTransportFromServerAddress(address)
if (newTransport.length > 0) {
transport.currentIndex = Utils.findIndex(transport.model, function (value) {
return value === newTransport
})
if (account) {
dialog._sipAddressOk = true
dialog._serverAddressOk = true
}
dialog._routeOk = true
}
function formIsValid () {
return dialog._sipAddressOk && dialog._serverAddressOk && dialog._routeOk
}
// -----------------------------------------------------------------------------
function validProxyConfig () {
// TODO: Display errors on the form (if necessary).
Linphone.AccountSettingsModel.addOrUpdateProxyConfig(proxyConfig, {
if (Linphone.AccountSettingsModel.addOrUpdateProxyConfig(proxyConfig, {
sipAddress: sipAddress.text,
serverAddress: serverAddress.text,
registrationDuration: registrationDuration.text,
......@@ -60,5 +63,48 @@ function validProxyConfig () {
registerEnabled: registerEnabled.checked,
publishPresence: publishPresence.checked,
avpfEnabled: avpfEnabled.checked
})
})) {
dialog.exit(1)
} else {
// TODO: Display errors on the form (if necessary).
}
}
// -----------------------------------------------------------------------------
function handleRouteChanged (route) {
dialog._routeOk = route.length === 0 || Linphone.SipAddressesModel.sipAddressIsValid(route)
}
function handleServerAddressChanged (address) {
if (address.length === 0) {
dialog._serverAddressOk = false
return
}
var newTransport = Linphone.SipAddressesModel.getTransportFromSipAddress(address)
if (newTransport.length > 0) {
transport.currentIndex = Utils.findIndex(transport.model, function (value) {
return value === newTransport
})
dialog._serverAddressOk = true
} else {
dialog._serverAddressOk = false
}
}
function handleSipAddressChanged (address) {
dialog._sipAddressOk = address.length > 0 &&
Linphone.SipAddressesModel.sipAddressIsValid(address)
}
function handleTransportChanged (transport) {
var newServerAddress = Linphone.SipAddressesModel.addTransportToSipAddress(serverAddress.text, transport)
if (newServerAddress.length > 0) {
serverAddress.text = newServerAddress
dialog._serverAddressOk = true
} else {
dialog._serverAddressOk = false
}
}
import QtQuick 2.7
import Common 1.0
import Linphone 1.0
import Utils 1.0
import App.Styles 1.0
......@@ -15,6 +13,10 @@ DialogPlus {
property var account // Optional.
property bool _sipAddressOk: false
property bool _serverAddressOk: false
property bool _routeOk: false
buttons: [
TextButtonA {
text: qsTr('cancel')
......@@ -22,13 +24,10 @@ DialogPlus {
onClicked: exit(0)
},
TextButtonB {
enabled: sipAddress.length > 0 && serverAddress.length > 0
enabled: Logic.formIsValid()
text: qsTr('confirm')
onClicked: {
Logic.validProxyConfig()
exit(1)
}
onClicked: Logic.validProxyConfig()
}
]
......@@ -57,6 +56,8 @@ DialogPlus {
TextField {
id: sipAddress
onTextChanged: Logic.handleSipAddressChanged(text)
}
}
}
......@@ -90,7 +91,10 @@ DialogPlus {
ComboBox {
id: transport
model: [ 'UDP', 'TCP', 'TLS' ]
enabled: dialog._serverAddressOk
model: [ 'UDP', 'TCP', 'TLS', 'DTLS' ]
onActivated: Logic.handleTransportChanged(model[index])
}
}
}
......@@ -101,6 +105,8 @@ DialogPlus {
TextField {
id: route
onTextChanged: Logic.handleRouteChanged(text)
}
}
}
......
belle-sip @ fd7a289c
Subproject commit 3bd0d610e68c6282a470339b82e1e75d937e050d
Subproject commit fd7a289c80d3285684ac7bdfd6528d93f94d895f
linphone @ 5e02b53e
Subproject commit f40bc26db4e92e61e617517c672f9a92e62f21a6
Subproject commit 5e02b53ee66b73e64bfc41e6ac2ed74296f42f60
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