2019-03-04 22:53:30 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
|
2019-03-04 22:53:30 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-03-04 22:53:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "photoplugin.h"
|
|
|
|
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <core/filetransferjob.h>
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_photo_debug.h"
|
2019-03-04 22:53:30 +00:00
|
|
|
|
2019-06-12 21:16:54 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(PhotoPlugin, "kdeconnect_photo.json")
|
2019-03-04 22:53:30 +00:00
|
|
|
|
|
|
|
PhotoPlugin::PhotoPlugin(QObject* parent, const QVariantList& args)
|
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoPlugin::~PhotoPlugin()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhotoPlugin::receivePacket(const NetworkPacket& np)
|
|
|
|
{
|
|
|
|
|
2019-07-20 14:42:50 +01:00
|
|
|
if (np.get<bool>(QStringLiteral("cancel"))) {
|
|
|
|
requestedFiles.takeFirst();
|
|
|
|
}
|
|
|
|
|
2019-03-04 22:53:30 +00:00
|
|
|
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
|
|
|
|
{
|
2019-06-10 15:40:28 +01:00
|
|
|
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/photo");
|
2019-03-04 22:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "photoplugin.moc"
|
|
|
|
|