diff --git a/CMakeLists.txt b/CMakeLists.txt index 4efde154b..7604b3332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,6 @@ add_definitions(-DQT_NO_URL_CAST_FROM_STRING) include(GenerateExportHeader) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_subdirectory(telepathy-cm) - add_subdirectory(core) add_subdirectory(kcm) add_subdirectory(kcmplugin) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 88965df10..03e8a43cf 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -24,6 +24,9 @@ if(EXPERIMENTALAPP_ENABLED) add_subdirectory(remotecontrol) add_subdirectory(lockdevice) endif() +if (TelepathyQt5_FOUND AND TelepathyQt5Service_FOUND) + add_subdirectory(telepathy) +endif() #FIXME: If we split notifications in several files, they won't appear in the same group in the Notifications KCM install(FILES kdeconnect.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR}) diff --git a/plugins/telepathy/CMakeLists.txt b/plugins/telepathy/CMakeLists.txt new file mode 100644 index 000000000..ee7f33c53 --- /dev/null +++ b/plugins/telepathy/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package(KF5 REQUIRED COMPONENTS Notifications) + +include_directories(${CMAKE_BINARY_DIR}) + +add_subdirectory(telepathy-cm) + +qt5_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/telepathy-cm/protocol.h ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectinterface.xml) +qt5_add_dbus_interface(kdeconnect_telepathy_SRCS ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectinterface.xml kdeconnectinterface) + +kdeconnect_add_plugin(kdeconnect_telepathy JSON kdeconnect_telepathy.json + SOURCES telepathyplugin.cpp ${kdeconnect_telepathy_SRCS}) + +target_link_libraries(kdeconnect_telepathy + kdeconnectcore + KF5::I18n + KF5::Notifications + Qt5::DBus +) diff --git a/plugins/telepathy/kdeconnect_telepathy.json b/plugins/telepathy/kdeconnect_telepathy.json new file mode 100644 index 000000000..dadd95b75 --- /dev/null +++ b/plugins/telepathy/kdeconnect_telepathy.json @@ -0,0 +1,27 @@ +{ + "Encoding": "UTF-8", + "KPlugin": { + "Authors": [ + { + "Name": "David Edmundson", + "Email": "davidedmundson@kde.org", + } + ], + "Description": "Show notifications for calls and SMS (answering coming soon)", + "EnabledByDefault": true, + "Icon": "telepathy", + "Id": "kdeconnect_telepathy", + "License": "GPL", + "Name": "Telepathy service integration", + "ServiceTypes": [ "KdeConnect/Plugin" ], + "Version": "0.1", + "Website": "http://blog.davidedmundson.co.uk" + }, + "X-KdeConnect-OutgoingPackageType": [ + "kdeconnect.telephony.request", + "kdeconnect.sms.request" + ], + "X-KdeConnect-SupportedPackageType": [ + "kdeconnect.telephony" + ] +} diff --git a/telepathy-cm/CMakeLists.txt b/plugins/telepathy/telepathy-cm/CMakeLists.txt similarity index 100% rename from telepathy-cm/CMakeLists.txt rename to plugins/telepathy/telepathy-cm/CMakeLists.txt diff --git a/telepathy-cm/README b/plugins/telepathy/telepathy-cm/README similarity index 100% rename from telepathy-cm/README rename to plugins/telepathy/telepathy-cm/README diff --git a/telepathy-cm/connection.cpp b/plugins/telepathy/telepathy-cm/connection.cpp similarity index 100% rename from telepathy-cm/connection.cpp rename to plugins/telepathy/telepathy-cm/connection.cpp diff --git a/telepathy-cm/connection.h b/plugins/telepathy/telepathy-cm/connection.h similarity index 100% rename from telepathy-cm/connection.h rename to plugins/telepathy/telepathy-cm/connection.h diff --git a/telepathy-cm/kdeconnect.manager b/plugins/telepathy/telepathy-cm/kdeconnect.manager similarity index 100% rename from telepathy-cm/kdeconnect.manager rename to plugins/telepathy/telepathy-cm/kdeconnect.manager diff --git a/telepathy-cm/kdeconnecttelepathyprotocolfactory.cpp b/plugins/telepathy/telepathy-cm/kdeconnecttelepathyprotocolfactory.cpp similarity index 100% rename from telepathy-cm/kdeconnecttelepathyprotocolfactory.cpp rename to plugins/telepathy/telepathy-cm/kdeconnecttelepathyprotocolfactory.cpp diff --git a/telepathy-cm/kdeconnecttelepathyprotocolfactory.h b/plugins/telepathy/telepathy-cm/kdeconnecttelepathyprotocolfactory.h similarity index 100% rename from telepathy-cm/kdeconnecttelepathyprotocolfactory.h rename to plugins/telepathy/telepathy-cm/kdeconnecttelepathyprotocolfactory.h diff --git a/telepathy-cm/main.cpp b/plugins/telepathy/telepathy-cm/main.cpp similarity index 100% rename from telepathy-cm/main.cpp rename to plugins/telepathy/telepathy-cm/main.cpp diff --git a/telepathy-cm/protocol.cpp b/plugins/telepathy/telepathy-cm/protocol.cpp similarity index 100% rename from telepathy-cm/protocol.cpp rename to plugins/telepathy/telepathy-cm/protocol.cpp diff --git a/telepathy-cm/protocol.h b/plugins/telepathy/telepathy-cm/protocol.h similarity index 100% rename from telepathy-cm/protocol.h rename to plugins/telepathy/telepathy-cm/protocol.h diff --git a/telepathy-cm/textchannel.cpp b/plugins/telepathy/telepathy-cm/textchannel.cpp similarity index 100% rename from telepathy-cm/textchannel.cpp rename to plugins/telepathy/telepathy-cm/textchannel.cpp diff --git a/telepathy-cm/textchannel.h b/plugins/telepathy/telepathy-cm/textchannel.h similarity index 100% rename from telepathy-cm/textchannel.h rename to plugins/telepathy/telepathy-cm/textchannel.h diff --git a/plugins/telepathy/telepathyplugin.cpp b/plugins/telepathy/telepathyplugin.cpp new file mode 100644 index 000000000..ef4f0e1ac --- /dev/null +++ b/plugins/telepathy/telepathyplugin.cpp @@ -0,0 +1,63 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "telepathyplugin.h" + +#include +#include +#include + +#include + +K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_telepathy.json", registerPlugin< TelepathyPlugin >(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony") + +TelepathyPlugin::TelepathyPlugin(QObject *parent, const QVariantList &args) + : KdeConnectPlugin(parent, args) + , m_telepathyInterface(new OrgFreedesktopTelepathyConnectionManagerKdeconnectInterface("org.freedesktop.Telepathy.ConnectionManager.kdeconnect", "/kdeconnect", QDBusConnection::sessionBus(), this)) +{ + connect(m_telepathyInterface, SIGNAL(messageReceived(QString,QString)), SLOT(sendSms(QString,QString))); +} + +bool TelepathyPlugin::receivePackage(const NetworkPackage& np) +{ + if (np.get("event") == QLatin1String("sms")) { + const QString messageBody = np.get("messageBody",""); + const QString phoneNumber = np.get("phoneNumber", i18n("unknown number")); + const QString contactName = np.get("contactName", phoneNumber); + if (m_telepathyInterface->sendMessage(contactName, messageBody)) { + return true; + } + } + + return true; +} + +void TelepathyPlugin::sendSms(const QString& phoneNumber, const QString& messageBody) +{ + NetworkPackage np(PACKAGE_TYPE_SMS_REQUEST); + np.set("sendSms", true); + np.set("phoneNumber", phoneNumber); + np.set("messageBody", messageBody); + sendPackage(np); +} + +#include "telepathyplugin.moc" diff --git a/plugins/telepathy/telepathyplugin.h b/plugins/telepathy/telepathyplugin.h new file mode 100644 index 000000000..c8201f46c --- /dev/null +++ b/plugins/telepathy/telepathyplugin.h @@ -0,0 +1,57 @@ +/** + * Copyright 2013 Albert Vaca + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef TELEPHONYPLUGIN_H +#define TELEPHONYPLUGIN_H + +#include + +#include + +#include +#include "kdeconnectinterface.h" + +#define PACKAGE_TYPE_TELEPHONY_REQUEST QLatin1String("kdeconnect.telephony.request") +#define PACKAGE_TYPE_SMS_REQUEST QLatin1String("kdeconnect.sms.request") + +Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY) + +class TelepathyPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + +public: + explicit TelepathyPlugin(QObject *parent, const QVariantList &args); + void connected() override {} + +public Q_SLOTS: + virtual bool receivePackage(const NetworkPackage& np) override; + +private Q_SLOTS: + void sendSms(const QString& phoneNumber, const QString& messageBody); + +private: + KNotification* createNotification(const NetworkPackage& np); + + OrgFreedesktopTelepathyConnectionManagerKdeconnectInterface* m_telepathyInterface; +}; + +#endif diff --git a/plugins/telephony/CMakeLists.txt b/plugins/telephony/CMakeLists.txt index 583aa8f34..52418e348 100644 --- a/plugins/telephony/CMakeLists.txt +++ b/plugins/telephony/CMakeLists.txt @@ -2,15 +2,7 @@ find_package(KF5 REQUIRED COMPONENTS Notifications) include_directories(${CMAKE_BINARY_DIR}) -set(kdeconnect_telephony_SRCS - telephonyplugin.cpp - sendsmsdialog.cpp -) - -qt5_generate_dbus_interface(${CMAKE_SOURCE_DIR}/telepathy-cm/protocol.h ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectinterface.xml) -qt5_add_dbus_interface(kdeconnect_telephony_SRCS ${CMAKE_CURRENT_BINARY_DIR}/kdeconnectinterface.xml kdeconnectinterface) - -kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES ${kdeconnect_telephony_SRCS}) +kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES telephonyplugin.cpp sendsmsdialog.cpp) target_link_libraries(kdeconnect_telephony kdeconnectcore diff --git a/plugins/telephony/telephonyplugin.cpp b/plugins/telephony/telephonyplugin.cpp index 5015c6c42..84a3c309d 100644 --- a/plugins/telephony/telephonyplugin.cpp +++ b/plugins/telephony/telephonyplugin.cpp @@ -34,9 +34,7 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony") TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args) : KdeConnectPlugin(parent, args) - , m_telepathyInterface(new OrgFreedesktopTelepathyConnectionManagerKdeconnectInterface("org.freedesktop.Telepathy.ConnectionManager.kdeconnect", "/kdeconnect", QDBusConnection::sessionBus(), this)) { - connect(m_telepathyInterface, SIGNAL(messageReceived(QString,QString)), SLOT(sendSms(QString,QString))); } KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np) @@ -115,14 +113,6 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np) //TODO: Clear the old notification return true; } - if (np.get("event") == QLatin1String("sms")) { - const QString messageBody = np.get("messageBody",""); - const QString phoneNumber = np.get("phoneNumber", i18n("unknown number")); - const QString contactName = np.get("contactName", phoneNumber); - if (m_telepathyInterface->sendMessage(contactName, messageBody)) { - return true; - } - } KNotification* n = createNotification(np); if (n != nullptr) n->sendEvent(); diff --git a/plugins/telephony/telephonyplugin.h b/plugins/telephony/telephonyplugin.h index 58b9752ab..7992821d5 100644 --- a/plugins/telephony/telephonyplugin.h +++ b/plugins/telephony/telephonyplugin.h @@ -52,8 +52,6 @@ private Q_SLOTS: private: KNotification* createNotification(const NetworkPackage& np); - - OrgFreedesktopTelepathyConnectionManagerKdeconnectInterface* m_telepathyInterface; }; #endif