Move all Telepathy bits into a Telepathy plugin
This commit is contained in:
parent
a465577005
commit
e6349524bc
21 changed files with 169 additions and 23 deletions
|
@ -36,8 +36,6 @@ add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
|
||||||
include(GenerateExportHeader)
|
include(GenerateExportHeader)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_subdirectory(telepathy-cm)
|
|
||||||
|
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(kcm)
|
add_subdirectory(kcm)
|
||||||
add_subdirectory(kcmplugin)
|
add_subdirectory(kcmplugin)
|
||||||
|
|
|
@ -24,6 +24,9 @@ if(EXPERIMENTALAPP_ENABLED)
|
||||||
add_subdirectory(remotecontrol)
|
add_subdirectory(remotecontrol)
|
||||||
add_subdirectory(lockdevice)
|
add_subdirectory(lockdevice)
|
||||||
endif()
|
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
|
#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})
|
install(FILES kdeconnect.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
|
||||||
|
|
18
plugins/telepathy/CMakeLists.txt
Normal file
18
plugins/telepathy/CMakeLists.txt
Normal file
|
@ -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
|
||||||
|
)
|
27
plugins/telepathy/kdeconnect_telepathy.json
Normal file
27
plugins/telepathy/kdeconnect_telepathy.json
Normal file
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
63
plugins/telepathy/telepathyplugin.cpp
Normal file
63
plugins/telepathy/telepathyplugin.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "telepathyplugin.h"
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <KPluginFactory>
|
||||||
|
|
||||||
|
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<QString>("event") == QLatin1String("sms")) {
|
||||||
|
const QString messageBody = np.get<QString>("messageBody","");
|
||||||
|
const QString phoneNumber = np.get<QString>("phoneNumber", i18n("unknown number"));
|
||||||
|
const QString contactName = np.get<QString>("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"
|
57
plugins/telepathy/telepathyplugin.h
Normal file
57
plugins/telepathy/telepathyplugin.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TELEPHONYPLUGIN_H
|
||||||
|
#define TELEPHONYPLUGIN_H
|
||||||
|
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
#include <KNotification>
|
||||||
|
|
||||||
|
#include <core/kdeconnectplugin.h>
|
||||||
|
#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
|
|
@ -2,15 +2,7 @@ find_package(KF5 REQUIRED COMPONENTS Notifications)
|
||||||
|
|
||||||
include_directories(${CMAKE_BINARY_DIR})
|
include_directories(${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
set(kdeconnect_telephony_SRCS
|
kdeconnect_add_plugin(kdeconnect_telephony JSON kdeconnect_telephony.json SOURCES telephonyplugin.cpp sendsmsdialog.cpp)
|
||||||
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})
|
|
||||||
|
|
||||||
target_link_libraries(kdeconnect_telephony
|
target_link_libraries(kdeconnect_telephony
|
||||||
kdeconnectcore
|
kdeconnectcore
|
||||||
|
|
|
@ -34,9 +34,7 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_TELEPHONY, "kdeconnect.plugin.telephony")
|
||||||
|
|
||||||
TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args)
|
TelephonyPlugin::TelephonyPlugin(QObject *parent, const QVariantList &args)
|
||||||
: KdeConnectPlugin(parent, 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)
|
KNotification* TelephonyPlugin::createNotification(const NetworkPackage& np)
|
||||||
|
@ -115,14 +113,6 @@ bool TelephonyPlugin::receivePackage(const NetworkPackage& np)
|
||||||
//TODO: Clear the old notification
|
//TODO: Clear the old notification
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (np.get<QString>("event") == QLatin1String("sms")) {
|
|
||||||
const QString messageBody = np.get<QString>("messageBody","");
|
|
||||||
const QString phoneNumber = np.get<QString>("phoneNumber", i18n("unknown number"));
|
|
||||||
const QString contactName = np.get<QString>("contactName", phoneNumber);
|
|
||||||
if (m_telepathyInterface->sendMessage(contactName, messageBody)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KNotification* n = createNotification(np);
|
KNotification* n = createNotification(np);
|
||||||
if (n != nullptr) n->sendEvent();
|
if (n != nullptr) n->sendEvent();
|
||||||
|
|
|
@ -52,8 +52,6 @@ private Q_SLOTS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KNotification* createNotification(const NetworkPackage& np);
|
KNotification* createNotification(const NetworkPackage& np);
|
||||||
|
|
||||||
OrgFreedesktopTelepathyConnectionManagerKdeconnectInterface* m_telepathyInterface;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue