Commit d00b77d5 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/assistant/AssistantModel): supports non-linphone account

parent a76b0089
......@@ -133,6 +133,7 @@ set(SOURCES
src/components/timeline/TimelineModel.cpp
src/externals/single-application/SingleApplication.cpp
src/main.cpp
src/LinphoneUtils.cpp
src/Utils.cpp
)
......@@ -181,6 +182,7 @@ set(HEADERS
src/components/timeline/TimelineModel.hpp
src/externals/single-application/SingleApplication.hpp
src/externals/single-application/SingleApplicationPrivate.hpp
src/LinphoneUtils.hpp
src/Utils.hpp
)
......
......@@ -1402,6 +1402,10 @@ your friend&apos;s SIP address or username.</translation>
<source>transportLabel</source>
<translation>Transport</translation>
</message>
<message>
<source>addOtherSipAccountError</source>
<translation>Unable to add this account.</translation>
</message>
</context>
<context>
<name>ZrtpTokenAuthentication</name>
......
......@@ -1401,6 +1401,10 @@ un chat ou ajouter un contact.</translation>
<source>transportLabel</source>
<translation>Transport</translation>
</message>
<message>
<source>addOtherSipAccountError</source>
<translation>Impossible d&apos;ajouter ce compte.</translation>
</message>
</context>
<context>
<name>ZrtpTokenAuthentication</name>
......
/*
* LinphoneUtils.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: June 2, 2017
* Author: Ronan Abhamon
*/
#include "LinphoneUtils.hpp"
// =============================================================================
linphone::TransportType LinphoneUtils::stringToTransportType (const QString &transport) {
if (transport == "TCP")
return linphone::TransportType::TransportTypeTcp;
if (transport == "UDP")
return linphone::TransportType::TransportTypeUdp;
if (transport == "TLS")
return linphone::TransportType::TransportTypeTls;
return linphone::TransportType::TransportTypeDtls;
}
/*
* LinphoneUtils.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: June 2, 2017
* Author: Ronan Abhamon
*/
#ifndef LINPHONE_UTILS_H_
#define LINPHONE_UTILS_H_
#include <linphone++/linphone.hh>
#include <QString>
// =============================================================================
namespace LinphoneUtils {
linphone::TransportType stringToTransportType (const QString &transport);
}
#endif // ifndef LINPHONE_UTILS_H_
......@@ -21,6 +21,7 @@
*/
#include "../../app/paths/Paths.hpp"
#include "../../LinphoneUtils.hpp"
#include "../../Utils.hpp"
#include "../core/CoreManager.hpp"
......@@ -184,6 +185,59 @@ void AssistantModel::reset () {
// -----------------------------------------------------------------------------
bool AssistantModel::addOtherSipAccount (const QVariantMap &map) {
CoreManager *coreManager = CoreManager::getInstance();
shared_ptr<linphone::Factory> factory = linphone::Factory::get();
shared_ptr<linphone::Core> core = coreManager->getCore();
shared_ptr<linphone::ProxyConfig> proxyConfig = core->createProxyConfig();
const QString &domain = map["sipDomain"].toString();
QString sipAddress = QStringLiteral("sip:%1@%2")
.arg(map["username"].toString()).arg(domain);
// Server address.
{
shared_ptr<linphone::Address> address = factory->createAddress(
::Utils::appStringToCoreString(QStringLiteral("sip:%1").arg(domain))
);
address->setTransport(LinphoneUtils::stringToTransportType(map["transport"].toString()));
if (proxyConfig->setServerAddr(address->asString())) {
qWarning() << QStringLiteral("Unable to add server address: `%1`.")
.arg(::Utils::coreStringToAppString(address->asString()));
return false;
}
}
// Sip Address.
shared_ptr<linphone::Address> address = factory->createAddress(::Utils::appStringToCoreString(sipAddress));
if (!address) {
qWarning() << QStringLiteral("Unable to create sip address object from: `%1`.").arg(sipAddress);
return false;
}
address->setDisplayName(::Utils::appStringToCoreString(map["displayName"].toString()));
proxyConfig->setIdentityAddress(address);
// AuthInfo.
core->addAuthInfo(
factory->createAuthInfo(
address->getUsername(), // Username.
"", // User ID.
::Utils::appStringToCoreString(map["password"].toString()), // Password.
"", // HA1.
"", // Realm.
address->getDomain() // Domain.
)
);
return coreManager->getAccountSettingsModel()->addOrUpdateProxyConfig(proxyConfig);
}
// -----------------------------------------------------------------------------
QString AssistantModel::getEmail () const {
return ::Utils::coreStringToAppString(mAccountCreator->getEmail());
}
......
......@@ -51,6 +51,8 @@ public:
Q_INVOKABLE void reset ();
Q_INVOKABLE bool addOtherSipAccount (const QVariantMap &map);
signals:
void emailChanged (const QString &email, const QString &error);
void passwordChanged (const QString &password, const QString &error);
......
......@@ -24,6 +24,7 @@
#include <QSet>
#include <QtDebug>
#include "../../LinphoneUtils.hpp"
#include "../../Utils.hpp"
#include "../chat/ChatModel.hpp"
#include "../core/CoreManager.hpp"
......@@ -132,8 +133,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip
const QString &sipAddress = model->getSipAddress();
if (mObservers.remove(sipAddress, model) == 0)
qWarning() << QStringLiteral("Unable to remove sip address `%1` from observers.").arg(sipAddress);
}
);
});
return model;
}
......@@ -178,15 +178,7 @@ QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress,
if (!address)
return "";
QString transportStr = transport.toUpper();
if (transportStr == "TCP")
address->setTransport(linphone::TransportType::TransportTypeTcp);
else if (transportStr == "UDP")
address->setTransport(linphone::TransportType::TransportTypeUdp);
else if (transportStr == "TLS")
address->setTransport(linphone::TransportType::TransportTypeTls);
else
address->setTransport(linphone::TransportType::TransportTypeDtls);
address->setTransport(LinphoneUtils::stringToTransportType(transport.toUpper()));
return ::Utils::coreStringToAppString(address->asString());
}
......
import QtQuick 2.7
import Common 1.0
import Linphone 1.0
// =============================================================================
AssistantAbstractView {
mainAction: (function () {
console.log('TODO')
})
mainAction: requestBlock.execute
mainActionEnabled: username.text.length &&
sipDomain.text.length &&
......@@ -17,56 +18,88 @@ AssistantAbstractView {
// ---------------------------------------------------------------------------
Form {
Column {
anchors.fill: parent
orientation: Qt.Vertical
FormLine {
FormGroup {
label: qsTr('usernameLabel')
Form {
dealWithErrors: true
orientation: Qt.Vertical
width: parent.width
FormLine {
FormGroup {
label: qsTr('usernameLabel')
TextField {
id: username
TextField {
id: username
}
}
}
}
FormLine {
FormGroup {
label: qsTr('displayNameLabel')
FormGroup {
label: qsTr('displayNameLabel')
TextField {}
TextField {
id: displayName
}
}
}
}
FormLine {
FormGroup {
label: qsTr('sipDomainLabel')
FormLine {
FormGroup {
label: qsTr('sipDomainLabel')
TextField {
id: sipDomain
TextField {
id: sipDomain
}
}
}
}
FormLine {
FormGroup {
label: qsTr('passwordLabel')
FormLine {
FormGroup {
label: qsTr('passwordLabel')
PasswordField {
id: password
PasswordField {
id: password
}
}
}
}
FormLine {
FormGroup {
label: qsTr('transportLabel')
FormLine {
FormGroup {
label: qsTr('transportLabel')
ExclusiveButtons {
texts: [ 'UDP', 'TCP', 'TLS' ]
ComboBox {
id: transport
model: [ 'UDP', 'TCP', 'TLS', 'DTLS' ]
}
}
}
}
RequestBlock {
id: requestBlock
action: (function () {
if (!assistantModel.addOtherSipAccount({
username: username.text,
displayName: displayName.text,
sipDomain: sipDomain.text,
password: password.text,
transport: transport.model[transport.currentIndex]
})) {
requestBlock.stop(qsTr('addOtherSipAccountError'))
} else {
requestBlock.stop('')
window.setView('Home')
}
})
width: parent.width
}
}
AssistantModel {
id: assistantModel
}
}
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