diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt
index 88c9ad6d3..06c546a38 100644
--- a/linphone-desktop/CMakeLists.txt
+++ b/linphone-desktop/CMakeLists.txt
@@ -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
)
diff --git a/linphone-desktop/assets/languages/en.ts b/linphone-desktop/assets/languages/en.ts
index 6cc93e96b..9cea97000 100644
--- a/linphone-desktop/assets/languages/en.ts
+++ b/linphone-desktop/assets/languages/en.ts
@@ -1402,6 +1402,10 @@ your friend's SIP address or username.
transportLabel
Transport
+
+ addOtherSipAccountError
+ Unable to add this account.
+
ZrtpTokenAuthentication
diff --git a/linphone-desktop/assets/languages/fr.ts b/linphone-desktop/assets/languages/fr.ts
index d416057a8..ece79bc0e 100644
--- a/linphone-desktop/assets/languages/fr.ts
+++ b/linphone-desktop/assets/languages/fr.ts
@@ -1401,6 +1401,10 @@ un chat ou ajouter un contact.
transportLabel
Transport
+
+ addOtherSipAccountError
+ Impossible d'ajouter ce compte.
+
ZrtpTokenAuthentication
diff --git a/linphone-desktop/src/LinphoneUtils.cpp b/linphone-desktop/src/LinphoneUtils.cpp
new file mode 100644
index 000000000..d8ec7a433
--- /dev/null
+++ b/linphone-desktop/src/LinphoneUtils.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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;
+}
diff --git a/linphone-desktop/src/LinphoneUtils.hpp b/linphone-desktop/src/LinphoneUtils.hpp
new file mode 100644
index 000000000..1de2e1c41
--- /dev/null
+++ b/linphone-desktop/src/LinphoneUtils.hpp
@@ -0,0 +1,35 @@
+/*
+ * 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
+#include
+
+// =============================================================================
+
+namespace LinphoneUtils {
+ linphone::TransportType stringToTransportType (const QString &transport);
+}
+
+#endif // ifndef LINPHONE_UTILS_H_
diff --git a/linphone-desktop/src/components/assistant/AssistantModel.cpp b/linphone-desktop/src/components/assistant/AssistantModel.cpp
index f2a853505..fb2bf95b9 100644
--- a/linphone-desktop/src/components/assistant/AssistantModel.cpp
+++ b/linphone-desktop/src/components/assistant/AssistantModel.cpp
@@ -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 factory = linphone::Factory::get();
+ shared_ptr core = coreManager->getCore();
+ shared_ptr 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 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 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());
}
diff --git a/linphone-desktop/src/components/assistant/AssistantModel.hpp b/linphone-desktop/src/components/assistant/AssistantModel.hpp
index d449a51e7..b8d01e096 100644
--- a/linphone-desktop/src/components/assistant/AssistantModel.hpp
+++ b/linphone-desktop/src/components/assistant/AssistantModel.hpp
@@ -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);
diff --git a/linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp b/linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp
index bed28bad9..9452e93fc 100644
--- a/linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp
+++ b/linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp
@@ -24,6 +24,7 @@
#include
#include
+#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());
}
diff --git a/linphone-desktop/ui/views/App/Main/Assistant/UseOtherSipAccount.qml b/linphone-desktop/ui/views/App/Main/Assistant/UseOtherSipAccount.qml
index c6022f833..368c84a09 100644
--- a/linphone-desktop/ui/views/App/Main/Assistant/UseOtherSipAccount.qml
+++ b/linphone-desktop/ui/views/App/Main/Assistant/UseOtherSipAccount.qml
@@ -1,11 +1,12 @@
+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
- TextField {
- id: username
+ FormLine {
+ FormGroup {
+ label: qsTr('usernameLabel')
+
+ TextField {
+ id: username
+ }
+ }
+
+ FormGroup {
+ label: qsTr('displayNameLabel')
+
+ TextField {
+ id: displayName
+ }
+ }
+ }
+
+ FormLine {
+ FormGroup {
+ label: qsTr('sipDomainLabel')
+
+ TextField {
+ id: sipDomain
+ }
+ }
+ }
+
+ FormLine {
+ FormGroup {
+ label: qsTr('passwordLabel')
+
+ PasswordField {
+ id: password
+ }
+ }
+ }
+
+ FormLine {
+ FormGroup {
+ label: qsTr('transportLabel')
+
+ ComboBox {
+ id: transport
+
+ model: [ 'UDP', 'TCP', 'TLS', 'DTLS' ]
+ }
}
}
}
- FormLine {
- FormGroup {
- label: qsTr('displayNameLabel')
+ RequestBlock {
+ id: requestBlock
- TextField {}
- }
- }
-
- FormLine {
- FormGroup {
- label: qsTr('sipDomainLabel')
-
- TextField {
- id: sipDomain
+ 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')
}
- }
- }
+ })
- FormLine {
- FormGroup {
- label: qsTr('passwordLabel')
-
- PasswordField {
- id: password
- }
- }
- }
-
- FormLine {
- FormGroup {
- label: qsTr('transportLabel')
-
- ExclusiveButtons {
- texts: [ 'UDP', 'TCP', 'TLS' ]
- }
- }
+ width: parent.width
}
}
+
+ AssistantModel {
+ id: assistantModel
+ }
}