diff --git a/cli/kdeconnect-cli.cpp b/cli/kdeconnect-cli.cpp --- a/cli/kdeconnect-cli.cpp +++ b/cli/kdeconnect-cli.cpp @@ -72,6 +72,7 @@ parser.addOption(QCommandLineOption(QStringLiteral("execute-command"), i18n("Executes a remote command by id"), QStringLiteral("id"))); parser.addOption(QCommandLineOption(QStringList{QStringLiteral("k"), QStringLiteral("send-keys")}, i18n("Sends keys to a said device"))); parser.addOption(QCommandLineOption(QStringLiteral("my-id"), i18n("Display this device's id and exit"))); + parser.addOption(QCommandLineOption(QStringLiteral("photo"), i18n("Use the connected device to take a photo"))); about.setupCommandLine(&parser); parser.addHelpOption(); @@ -228,6 +229,9 @@ } else if(parser.isSet(QStringLiteral("ring"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/findmyphone", QStringLiteral("org.kde.kdeconnect.device.findmyphone"), QStringLiteral("ring")); blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); + } else if(parser.isSet(QStringLiteral("photo"))) { + QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/photo", QStringLiteral("org.kde.kdeconnect.device.photo"), QStringLiteral("requestPhoto")); + blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); } else if(parser.isSet("send-keys")) { QString seq = parser.value("send-keys"); QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/remotekeyboard", "org.kde.kdeconnect.device.remotekeyboard", "sendKeyPress"); diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(battery) add_subdirectory(sendnotifications) add_subdirectory(mpriscontrol) +add_subdirectory(photo) if(NOT SAILFISHOS) add_subdirectory(clipboard) diff --git a/plugins/photo/CMakeLists.txt b/plugins/photo/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plugins/photo/CMakeLists.txt @@ -0,0 +1,11 @@ +set(kdeconnect_photo_SRCS + photoplugin.cpp +) + +kdeconnect_add_plugin(kdeconnect_photo JSON kdeconnect_photo.json SOURCES ${kdeconnect_photo_SRCS}) + +target_link_libraries(kdeconnect_photo + kdeconnectcore + Qt5::DBus + KF5::I18n +) diff --git a/plugins/photo/kdeconnect_photo.json b/plugins/photo/kdeconnect_photo.json new file mode 100644 --- /dev/null +++ b/plugins/photo/kdeconnect_photo.json @@ -0,0 +1,27 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "nicolas.fella@gmx.de", + "Name": "Nicolas Fella" + } + ], + "Description": "Use a connected device to take a photo", + "EnabledByDefault": true, + "Icon": "camera-photo", + "Id": "kdeconnect_photo", + "License": "GPL", + "Name": "Photo", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1", + "Website": "http://nicolasfella.wordpress.com" + }, + "X-KdeConnect-OutgoingPacketType": [ + "kdeconnect.photo.request" + ], + "X-KdeConnect-SupportedPacketType": [ + "kdeconnect.photo" + ] +} diff --git a/plugins/photo/photoplugin.h b/plugins/photo/photoplugin.h new file mode 100644 --- /dev/null +++ b/plugins/photo/photoplugin.h @@ -0,0 +1,55 @@ +/** + * Copyright 2019 Nicolas Fella + * + * 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 PHOTOPLUGIN_H +#define PHOTOPLUGIN_H + +#include + +#include + +#define PACKET_TYPE_PHOTO_REQUEST QStringLiteral("kdeconnect.photo.request") +#define PACKET_TYPE_PHOTO QStringLiteral("kdeconnect.photo") + +class Q_DECL_EXPORT PhotoPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.photo") + +public: + explicit PhotoPlugin(QObject* parent, const QVariantList& args); + ~PhotoPlugin() override; + + Q_SCRIPTABLE void requestPhoto(const QString& fileName); + + bool receivePacket(const NetworkPacket& np) override; + void connected() override {} + + QString dbusPath() const override; + +Q_SIGNALS: + Q_SCRIPTABLE void photoReceived(const QString& fileName); + +private: + QStringList requestedFiles; +}; + +#endif diff --git a/plugins/photo/photoplugin.cpp b/plugins/photo/photoplugin.cpp new file mode 100644 --- /dev/null +++ b/plugins/photo/photoplugin.cpp @@ -0,0 +1,76 @@ +/** + * Copyright 2019 Nicolas Fella + * + * 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 "photoplugin.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_photo.json", registerPlugin< PhotoPlugin >(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PHOTO, "kdeconnect.plugin.photo") + +PhotoPlugin::PhotoPlugin(QObject* parent, const QVariantList& args) + : KdeConnectPlugin(parent, args) +{ +} + +PhotoPlugin::~PhotoPlugin() +{ +} + +bool PhotoPlugin::receivePacket(const NetworkPacket& np) +{ + + if (requestedFiles.isEmpty() || !np.hasPayload()) { + return true; + } + + const QString& fileName = requestedFiles.takeFirst(); + FileTransferJob* job = np.createPayloadTransferJob(QUrl::fromLocalFile(fileName)); + connect(job, &FileTransferJob::result, this, [this, fileName] { + Q_EMIT photoReceived(fileName); + }); + job->start(); + return true; +} + +void PhotoPlugin::requestPhoto(const QString& fileName) +{ + requestedFiles.append(fileName); + NetworkPacket np(PACKET_TYPE_PHOTO_REQUEST); + sendPacket(np); +} + +QString PhotoPlugin::dbusPath() const +{ + return "/modules/kdeconnect/devices/" + device()->id() + "/photo"; +} + +#include "photoplugin.moc" +