From 36c2e15fc7a0b5a33066884b9d4b6e50fa7355e1 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Tue, 1 Aug 2017 23:57:50 +0200 Subject: [PATCH] Check if there was an error before emitting shareReceived. And change shareReceived arg from QUrl to QString so it works on DBus --- plugins/share/shareplugin.cpp | 19 ++++++++++--------- plugins/share/shareplugin.h | 2 +- tests/sendfiletest.cpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 0915e2db8..9080ce598 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -115,29 +115,30 @@ bool SharePlugin::receivePackage(const NetworkPackage& np) tmpFile.write(text.toUtf8()); tmpFile.close(); - const QUrl url = QUrl::fromLocalFile(tmpFile.fileName()); - Q_EMIT shareReceived(url); - QDesktopServices::openUrl(url); + const QString fileName = tmpFile.fileName(); + Q_EMIT shareReceived(fileName); + QDesktopServices::openUrl(QUrl::fromLocalFile(fileName)); } } else if (np.has(QStringLiteral("url"))) { QUrl url = QUrl::fromEncoded(np.get(QStringLiteral("url"))); QDesktopServices::openUrl(url); - Q_EMIT shareReceived(url); + Q_EMIT shareReceived(url.toString()); } else { qCDebug(KDECONNECT_PLUGIN_SHARE) << "Error: Nothing attached!"; } return true; - } void SharePlugin::finished(KJob* job) { FileTransferJob* ftjob = qobject_cast(job); - if (ftjob) - Q_EMIT shareReceived(ftjob->destination()); - - qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished. Success:" << (!job->error()) << (ftjob ? ftjob->destination() : QUrl()); + if (ftjob && !job->error()) { + Q_EMIT shareReceived(ftjob->destination().toString()); + qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination(); + } else { + qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer failed." << (ftjob ? ftjob->destination() : QUrl()); + } } void SharePlugin::openDestinationFolder() diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index 8eb0bca1f..201cbde7d 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -49,7 +49,7 @@ private Q_SLOTS: void openDestinationFolder(); Q_SIGNALS: - void shareReceived(const QUrl& url); + void shareReceived(const QString& url); private: void shareUrl(const QUrl& url); diff --git a/tests/sendfiletest.cpp b/tests/sendfiletest.cpp index 4d5063e77..a2f4329cd 100644 --- a/tests/sendfiletest.cpp +++ b/tests/sendfiletest.cpp @@ -76,7 +76,7 @@ class TestSendFile : public QObject QVERIFY(plugin); plugin->metaObject()->invokeMethod(plugin, "shareUrl", Q_ARG(QString, QUrl::fromLocalFile(temp.fileName()).toString())); - QSignalSpy spy(plugin, SIGNAL(shareReceived(QUrl))); + QSignalSpy spy(plugin, SIGNAL(shareReceived(QString))); QVERIFY(spy.wait(2000)); QVariantList args = spy.takeFirst();