[Photo Plugin] Make photo plugin use QUrl instead of a local path

This is a companion merge request for !476,

this way it can be accessed directly from QML's FileDialog
This commit is contained in:
Kareem Abduljaleel 2022-09-02 17:32:01 +00:00 committed by Aleix Pol Gonzalez
parent 5639905b8d
commit 186526c0bb
3 changed files with 9 additions and 9 deletions

View file

@ -295,7 +295,7 @@ int main(int argc, char** argv)
const QString fileName = parser.value(QStringLiteral("photo"));
if (!fileName.isEmpty()) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), QStringLiteral("/modules/kdeconnect/devices/") + device + QStringLiteral("/photo"), QStringLiteral("org.kde.kdeconnect.device.photo"), QStringLiteral("requestPhoto"));
msg.setArguments({fileName});
msg.setArguments({QUrl::fromLocalFile(fileName).toString()});
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
} else {
QTextStream(stderr) << i18n("Please specify a filename for the photo") << endl;

View file

@ -35,18 +35,18 @@ bool PhotoPlugin::receivePacket(const NetworkPacket& np)
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);
const QString url = requestedFiles.takeFirst();
FileTransferJob* job = np.createPayloadTransferJob(QUrl(url));
connect(job, &FileTransferJob::result, this, [this, url] {
Q_EMIT photoReceived(url);
});
job->start();
return true;
}
void PhotoPlugin::requestPhoto(const QString& fileName)
void PhotoPlugin::requestPhoto(const QString& url)
{
requestedFiles.append(fileName);
requestedFiles.append(url);
NetworkPacket np(PACKET_TYPE_PHOTO_REQUEST);
sendPacket(np);
}

View file

@ -24,7 +24,7 @@ public:
explicit PhotoPlugin(QObject* parent, const QVariantList& args);
~PhotoPlugin() override;
Q_SCRIPTABLE void requestPhoto(const QString& fileName);
Q_SCRIPTABLE void requestPhoto(const QString& url);
bool receivePacket(const NetworkPacket& np) override;
void connected() override {}
@ -32,7 +32,7 @@ public:
QString dbusPath() const override;
Q_SIGNALS:
Q_SCRIPTABLE void photoReceived(const QString& fileName);
Q_SCRIPTABLE void photoReceived(const QString& url);
private:
QStringList requestedFiles;