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 ...@@ -133,6 +133,7 @@ set(SOURCES
src/components/timeline/TimelineModel.cpp src/components/timeline/TimelineModel.cpp
src/externals/single-application/SingleApplication.cpp src/externals/single-application/SingleApplication.cpp
src/main.cpp src/main.cpp
src/LinphoneUtils.cpp
src/Utils.cpp src/Utils.cpp
) )
...@@ -181,6 +182,7 @@ set(HEADERS ...@@ -181,6 +182,7 @@ set(HEADERS
src/components/timeline/TimelineModel.hpp src/components/timeline/TimelineModel.hpp
src/externals/single-application/SingleApplication.hpp src/externals/single-application/SingleApplication.hpp
src/externals/single-application/SingleApplicationPrivate.hpp src/externals/single-application/SingleApplicationPrivate.hpp
src/LinphoneUtils.hpp
src/Utils.hpp src/Utils.hpp
) )
......
...@@ -1402,6 +1402,10 @@ your friend&apos;s SIP address or username.</translation> ...@@ -1402,6 +1402,10 @@ your friend&apos;s SIP address or username.</translation>
<source>transportLabel</source> <source>transportLabel</source>
<translation>Transport</translation> <translation>Transport</translation>
</message> </message>
<message>
<source>addOtherSipAccountError</source>
<translation>Unable to add this account.</translation>
</message>
</context> </context>
<context> <context>
<name>ZrtpTokenAuthentication</name> <name>ZrtpTokenAuthentication</name>
......
...@@ -1401,6 +1401,10 @@ un chat ou ajouter un contact.</translation> ...@@ -1401,6 +1401,10 @@ un chat ou ajouter un contact.</translation>
<source>transportLabel</source> <source>transportLabel</source>
<translation>Transport</translation> <translation>Transport</translation>
</message> </message>
<message>
<source>addOtherSipAccountError</source>
<translation>Impossible d&apos;ajouter ce compte.</translation>
</message>
</context> </context>
<context> <context>
<name>ZrtpTokenAuthentication</name> <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 @@ ...@@ -21,6 +21,7 @@
*/ */
#include "../../app/paths/Paths.hpp" #include "../../app/paths/Paths.hpp"
#include "../../LinphoneUtils.hpp"
#include "../../Utils.hpp" #include "../../Utils.hpp"
#include "../core/CoreManager.hpp" #include "../core/CoreManager.hpp"
...@@ -184,6 +185,59 @@ void AssistantModel::reset () { ...@@ -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 { QString AssistantModel::getEmail () const {
return ::Utils::coreStringToAppString(mAccountCreator->getEmail()); return ::Utils::coreStringToAppString(mAccountCreator->getEmail());
} }
......
...@@ -51,6 +51,8 @@ public: ...@@ -51,6 +51,8 @@ public:
Q_INVOKABLE void reset (); Q_INVOKABLE void reset ();
Q_INVOKABLE bool addOtherSipAccount (const QVariantMap &map);
signals: signals:
void emailChanged (const QString &email, const QString &error); void emailChanged (const QString &email, const QString &error);
void passwordChanged (const QString &password, const QString &error); void passwordChanged (const QString &password, const QString &error);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <QSet> #include <QSet>
#include <QtDebug> #include <QtDebug>
#include "../../LinphoneUtils.hpp"
#include "../../Utils.hpp" #include "../../Utils.hpp"
#include "../chat/ChatModel.hpp" #include "../chat/ChatModel.hpp"
#include "../core/CoreManager.hpp" #include "../core/CoreManager.hpp"
...@@ -132,8 +133,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip ...@@ -132,8 +133,7 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip
const QString &sipAddress = model->getSipAddress(); const QString &sipAddress = model->getSipAddress();
if (mObservers.remove(sipAddress, model) == 0) if (mObservers.remove(sipAddress, model) == 0)
qWarning() << QStringLiteral("Unable to remove sip address `%1` from observers.").arg(sipAddress); qWarning() << QStringLiteral("Unable to remove sip address `%1` from observers.").arg(sipAddress);
} });
);
return model; return model;
} }
...@@ -178,15 +178,7 @@ QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress, ...@@ -178,15 +178,7 @@ QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress,
if (!address) if (!address)
return ""; return "";
QString transportStr = transport.toUpper(); address->setTransport(LinphoneUtils::stringToTransportType(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);
return ::Utils::coreStringToAppString(address->asString()); return ::Utils::coreStringToAppString(address->asString());
} }
......
import QtQuick 2.7
import Common 1.0 import Common 1.0
import Linphone 1.0
// ============================================================================= // =============================================================================
AssistantAbstractView { AssistantAbstractView {
mainAction: (function () { mainAction: requestBlock.execute
console.log('TODO')
})
mainActionEnabled: username.text.length && mainActionEnabled: username.text.length &&
sipDomain.text.length && sipDomain.text.length &&
...@@ -17,56 +18,88 @@ AssistantAbstractView { ...@@ -17,56 +18,88 @@ AssistantAbstractView {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
Form { Column {
anchors.fill: parent anchors.fill: parent
orientation: Qt.Vertical
FormLine { Form {
FormGroup { dealWithErrors: true
label: qsTr('usernameLabel') orientation: Qt.Vertical
width: parent.width
FormLine {
FormGroup {
label: qsTr('usernameLabel')
TextField { TextField {
id: username id: username
}
} }
}
}
FormLine { FormGroup {
FormGroup { label: qsTr('displayNameLabel')
label: qsTr('displayNameLabel')
TextField {} TextField {
id: displayName
}
}
} }
}
FormLine { FormLine {
FormGroup { FormGroup {
label: qsTr('sipDomainLabel') label: qsTr('sipDomainLabel')
TextField { TextField {
id: sipDomain id: sipDomain
}
} }
} }
}
FormLine { FormLine {
FormGroup { FormGroup {
label: qsTr('passwordLabel') label: qsTr('passwordLabel')
PasswordField { PasswordField {
id: password id: password
}
} }
} }
}
FormLine { FormLine {
FormGroup { FormGroup {
label: qsTr('transportLabel') label: qsTr('transportLabel')
ExclusiveButtons { ComboBox {
texts: [ 'UDP', 'TCP', 'TLS' ] 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