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.
This commit is contained in:
Aleix Pol 2015-12-07 03:27:40 +01:00
parent 70f55d0ebc
commit 42110549f4
3 changed files with 10 additions and 6 deletions

View file

@ -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<QByteArray>("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<FileTransferJob*>(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

View file

@ -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);

View file

@ -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());