From 42110549f48994fa7b6070660ef4fc99f862a400 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 7 Dec 2015 03:27:40 +0100 Subject: [PATCH] Improve SharePlugin share notification method Make the share received notification explicitly internal. Fix runtime warning about how QUrl cannot be exported. Notify about all shares, not exclusively transferred files. --- plugins/share/shareplugin.cpp | 10 +++++++--- plugins/share/shareplugin.h | 2 +- tests/sendfiletest.cpp | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 44e52e2ca..ecefba4c7 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -114,11 +114,15 @@ bool SharePlugin::receivePackage(const NetworkPackage& np) tmpFile.open(); tmpFile.write(text.toUtf8()); tmpFile.close(); - QDesktopServices::openUrl(QUrl::fromLocalFile(tmpFile.fileName())); + + const QUrl url = QUrl::fromLocalFile(tmpFile.fileName()); + Q_EMIT shareReceived(url); + QDesktopServices::openUrl(url); } } else if (np.has("url")) { QUrl url = QUrl::fromEncoded(np.get("url")); QDesktopServices::openUrl(url); + Q_EMIT shareReceived(url); } else { qCDebug(KDECONNECT_PLUGIN_SHARE) << "Error: Nothing attached!"; } @@ -131,7 +135,7 @@ void SharePlugin::finished(KJob* job) { FileTransferJob* ftjob = qobject_cast(job); if (ftjob) - fileReceived(ftjob->destination()); + Q_EMIT shareReceived(ftjob->destination()); qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished. Success:" << (!job->error()) << (ftjob ? ftjob->destination() : QUrl()); } @@ -156,7 +160,7 @@ void SharePlugin::shareUrl(const QUrl& url) void SharePlugin::connected() { - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); + QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents); } QString SharePlugin::dbusPath() const diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index 13b012b64..4149e21d1 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -48,7 +48,7 @@ private Q_SLOTS: void openDestinationFolder(); Q_SIGNALS: - void fileReceived(const QUrl& url); + void shareReceived(const QUrl& url); private: void shareUrl(const QUrl& url); diff --git a/tests/sendfiletest.cpp b/tests/sendfiletest.cpp index 015818b36..4a400181a 100644 --- a/tests/sendfiletest.cpp +++ b/tests/sendfiletest.cpp @@ -97,11 +97,11 @@ class TestSendFile : public QObject QVERIFY(plugin); plugin->metaObject()->invokeMethod(plugin, "shareUrl", Q_ARG(QString, QUrl::fromLocalFile(temp.fileName()).toString())); - QSignalSpy spy(plugin, SIGNAL(fileReceived(QUrl))); + QSignalSpy spy(plugin, SIGNAL(shareReceived(QUrl))); QVERIFY(spy.wait(2000)); QVariantList args = spy.takeFirst(); - QUrl sentFile = args.first().toUrl(); + QUrl sentFile(args.first().toUrl()); QFile file(sentFile.toLocalFile()); QCOMPARE(file.size(), content.size());