diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f3aa55e6..e50ff7f02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ set(SOURCES src/components/sound-player/SoundPlayer.cpp src/components/telephone-numbers/TelephoneNumbersModel.cpp src/components/timeline/TimelineModel.cpp + src/components/url-handlers/UrlHandlers.cpp src/externals/single-application/SingleApplication.cpp src/main.cpp src/utils/LinphoneUtils.cpp @@ -186,6 +187,7 @@ set(HEADERS src/components/sound-player/SoundPlayer.hpp src/components/telephone-numbers/TelephoneNumbersModel.hpp src/components/timeline/TimelineModel.hpp + src/components/url-handlers/UrlHandlers.hpp src/externals/single-application/SingleApplication.hpp src/externals/single-application/SingleApplicationPrivate.hpp src/utils/LinphoneUtils.hpp diff --git a/src/app/App.cpp b/src/app/App.cpp index 84d48a5bc..2ba86972d 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -357,6 +357,7 @@ void App::registerTypes () { registerSingletonType("OwnPresenceModel"); registerSingletonType("Presence"); registerSingletonType("TimelineModel"); + registerSingletonType("UrlHandlers"); registerSingletonType("VideoCodecsModel"); registerMetaType("ChatModel::EntryType"); diff --git a/src/app/App.hpp b/src/app/App.hpp index d3cc37f81..0f58825b6 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -33,9 +33,10 @@ // ============================================================================= +class QCommandLineParser; + class Cli; class DefaultTranslator; -class QCommandLineParser; class App : public SingleApplication { Q_OBJECT; diff --git a/src/components/Components.hpp b/src/components/Components.hpp index 57e107caa..8fa2ade4c 100644 --- a/src/components/Components.hpp +++ b/src/components/Components.hpp @@ -41,6 +41,7 @@ #include "sound-player/SoundPlayer.hpp" #include "telephone-numbers/TelephoneNumbersModel.hpp" #include "timeline/TimelineModel.hpp" +#include "url-handlers/UrlHandlers.hpp" #include "other/clipboard/Clipboard.hpp" #include "other/text-to-speech/TextToSpeech.hpp" diff --git a/src/components/sip-addresses/SipAddressesModel.cpp b/src/components/sip-addresses/SipAddressesModel.cpp index 44a5b2665..b692a8390 100644 --- a/src/components/sip-addresses/SipAddressesModel.cpp +++ b/src/components/sip-addresses/SipAddressesModel.cpp @@ -140,14 +140,6 @@ SipAddressObserver *SipAddressesModel::getSipAddressObserver (const QString &sip // ----------------------------------------------------------------------------- -QString SipAddressesModel::interpretUrl (const QString &sipAddress) const { - shared_ptr lAddress = CoreManager::getInstance()->getCore()->interpretUrl( - ::Utils::appStringToCoreString(sipAddress) - ); - - return lAddress ? ::Utils::coreStringToAppString(lAddress->asStringUriOnly()) : ""; -} - QString SipAddressesModel::getTransportFromSipAddress (const QString &sipAddress) const { const shared_ptr address = linphone::Factory::get()->createAddress( ::Utils::appStringToCoreString(sipAddress) @@ -176,13 +168,27 @@ QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress, ); if (!address) - return ""; + return QString(""); address->setTransport(LinphoneUtils::stringToTransportType(transport.toUpper())); return ::Utils::coreStringToAppString(address->asString()); } +// ----------------------------------------------------------------------------- + +QString SipAddressesModel::interpretUrl (const QString &sipAddress) { + shared_ptr lAddress = CoreManager::getInstance()->getCore()->interpretUrl( + ::Utils::appStringToCoreString(sipAddress) + ); + + return lAddress ? ::Utils::coreStringToAppString(lAddress->asStringUriOnly()) : ""; +} + +QString SipAddressesModel::interpretUrl (const QUrl &sipAddress) { + return sipAddress.toString(); +} + bool SipAddressesModel::sipAddressIsValid (const QString &sipAddress) { return !!linphone::Factory::get()->createAddress( ::Utils::appStringToCoreString(sipAddress) diff --git a/src/components/sip-addresses/SipAddressesModel.hpp b/src/components/sip-addresses/SipAddressesModel.hpp index f73acd479..c306e2d29 100644 --- a/src/components/sip-addresses/SipAddressesModel.hpp +++ b/src/components/sip-addresses/SipAddressesModel.hpp @@ -24,6 +24,7 @@ #define SIP_ADDRESSES_MODEL_H_ #include +#include #include "../chat/ChatModel.hpp" #include "../contact/ContactModel.hpp" @@ -55,11 +56,12 @@ public: // Sip addresses helpers. // --------------------------------------------------------------------------- - Q_INVOKABLE QString interpretUrl (const QString &sipAddress) const; - Q_INVOKABLE QString getTransportFromSipAddress (const QString &sipAddress) const; Q_INVOKABLE QString addTransportToSipAddress (const QString &sipAddress, const QString &transport) const; + Q_INVOKABLE static QString interpretUrl (const QString &sipAddress); + Q_INVOKABLE static QString interpretUrl (const QUrl &sipAddress); + Q_INVOKABLE static bool sipAddressIsValid (const QString &sipAddress); // --------------------------------------------------------------------------- diff --git a/src/components/url-handlers/UrlHandlers.cpp b/src/components/url-handlers/UrlHandlers.cpp new file mode 100644 index 000000000..4e5de6857 --- /dev/null +++ b/src/components/url-handlers/UrlHandlers.cpp @@ -0,0 +1,37 @@ +/* + * UrlHandlers.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 16, 2017 + * Author: Ronan Abhamon + */ + +#include + +#include "../sip-addresses/SipAddressesModel.hpp" + +#include "UrlHandlers.hpp" + +// ============================================================================= + +UrlHandlers::UrlHandlers (QObject *parent) : QObject(parent) { + QDesktopServices::setUrlHandler("sip", this, "handleSip"); +} + +void UrlHandlers::handleSip (const QUrl &url) { + emit sip(SipAddressesModel::interpretUrl(url)); +} diff --git a/src/components/url-handlers/UrlHandlers.hpp b/src/components/url-handlers/UrlHandlers.hpp new file mode 100644 index 000000000..84c7aa7c7 --- /dev/null +++ b/src/components/url-handlers/UrlHandlers.hpp @@ -0,0 +1,44 @@ +/* + * UrlHandlers.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 16, 2017 + * Author: Ronan Abhamon + */ + +#ifndef URL_HANDLERS_H_ +#define URL_HANDLERS_H_ + +#include + +// ============================================================================= + +class UrlHandlers : public QObject { + Q_OBJECT; + +public: + UrlHandlers (QObject *parent = Q_NULLPTR); + ~UrlHandlers () = default; + +public slots: + void handleSip (const QUrl &url); + +signals: + void sip (const QString &sipAddress); +}; + +#endif // URL_HANDLERS_H_ diff --git a/ui/views/App/Main/MainWindow.qml b/ui/views/App/Main/MainWindow.qml index efc615782..de2679fd8 100644 --- a/ui/views/App/Main/MainWindow.qml +++ b/ui/views/App/Main/MainWindow.qml @@ -262,4 +262,16 @@ ApplicationWindow { onClicked: CoreManager.forceRefreshRegisters() } + + // --------------------------------------------------------------------------- + // Url handlers. + // --------------------------------------------------------------------------- + + Connections { + target: UrlHandlers + + onSip: window.setView('Conversation', { + sipAddress: sipAddress + }) + } }