Add plugin for taking photos on remote device

Summary: This plugin sends a request for a photo to the connected device. The device then sends the photo back, currently via the SharePlugin.

Test Plan:
kdeconnect-cli --photo
Check for photo in Downlaods folder

Reviewers: #kde_connect, broulik, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: sredman, albertvaka, apol, ngraham, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D18140
This commit is contained in:
Nicolas Fella 2019-03-04 23:53:30 +01:00
parent 9190c79203
commit dbccc641ed
6 changed files with 174 additions and 0 deletions

View file

@ -72,6 +72,7 @@ int main(int argc, char** argv)
parser.addOption(QCommandLineOption(QStringLiteral("execute-command"), i18n("Executes a remote command by id"), QStringLiteral("id"))); 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(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("my-id"), i18n("Display this device's id and exit")));
parser.addOption(QCommandLineOption(QStringLiteral("photo"), i18n("Open the connected device's camera and transfer the photo")));
about.setupCommandLine(&parser); about.setupCommandLine(&parser);
parser.addHelpOption(); parser.addHelpOption();
@ -228,6 +229,9 @@ int main(int argc, char** argv)
} else if(parser.isSet(QStringLiteral("ring"))) { } 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")); 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)); 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")) { } else if(parser.isSet("send-keys")) {
QString seq = parser.value("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"); QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device+"/remotekeyboard", "org.kde.kdeconnect.device.remotekeyboard", "sendKeyPress");

View file

@ -6,6 +6,7 @@ add_subdirectory(ping)
add_subdirectory(battery) add_subdirectory(battery)
add_subdirectory(sendnotifications) add_subdirectory(sendnotifications)
add_subdirectory(mpriscontrol) add_subdirectory(mpriscontrol)
add_subdirectory(photo)
if(NOT SAILFISHOS) if(NOT SAILFISHOS)
add_subdirectory(clipboard) add_subdirectory(clipboard)

View file

@ -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
)

View file

@ -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"
]
}

View file

@ -0,0 +1,76 @@
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* 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 "photoplugin.h"
#include <KLocalizedString>
#include <KPluginFactory>
#include <QDebug>
#include <QDBusConnection>
#include <QLoggingCategory>
#include <core/device.h>
#include <core/daemon.h>
#include <core/filetransferjob.h>
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"

View file

@ -0,0 +1,55 @@
/**
* Copyright 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* 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 PHOTOPLUGIN_H
#define PHOTOPLUGIN_H
#include <QObject>
#include <core/kdeconnectplugin.h>
#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