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>
|
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_photo_debug.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <core/filetransferjob.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
|
|
|
|
2023-07-31 08:25:45 +01:00
|
|
|
void PhotoPlugin::receivePacket(const NetworkPacket &np)
|
2019-03-04 22:53:30 +00:00
|
|
|
{
|
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()) {
|
2023-07-31 08:25:45 +01:00
|
|
|
return;
|
2019-03-04 22:53:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 18:32:01 +01:00
|
|
|
const QString url = requestedFiles.takeFirst();
|
2022-09-10 22:23:52 +01:00
|
|
|
FileTransferJob *job = np.createPayloadTransferJob(QUrl(url));
|
2022-09-02 18:32:01 +01:00
|
|
|
connect(job, &FileTransferJob::result, this, [this, url] {
|
|
|
|
Q_EMIT photoReceived(url);
|
2019-03-04 22:53:30 +00:00
|
|
|
});
|
|
|
|
job->start();
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void PhotoPlugin::requestPhoto(const QString &url)
|
2019-03-04 22:53:30 +00:00
|
|
|
{
|
2022-09-02 18:32:01 +01:00
|
|
|
requestedFiles.append(url);
|
2019-03-04 22:53:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_photoplugin.cpp"
|
2019-03-04 22:53:30 +00:00
|
|
|
#include "photoplugin.moc"
|