Check if there was an error before emitting shareReceived.

And change shareReceived arg from QUrl to QString so it works on DBus
This commit is contained in:
Albert Vaca 2017-08-01 23:57:50 +02:00
parent 88e43ada1e
commit 36c2e15fc7
3 changed files with 12 additions and 11 deletions

View file

@ -115,29 +115,30 @@ bool SharePlugin::receivePackage(const NetworkPackage& np)
tmpFile.write(text.toUtf8()); tmpFile.write(text.toUtf8());
tmpFile.close(); tmpFile.close();
const QUrl url = QUrl::fromLocalFile(tmpFile.fileName()); const QString fileName = tmpFile.fileName();
Q_EMIT shareReceived(url); Q_EMIT shareReceived(fileName);
QDesktopServices::openUrl(url); QDesktopServices::openUrl(QUrl::fromLocalFile(fileName));
} }
} else if (np.has(QStringLiteral("url"))) { } else if (np.has(QStringLiteral("url"))) {
QUrl url = QUrl::fromEncoded(np.get<QByteArray>(QStringLiteral("url"))); QUrl url = QUrl::fromEncoded(np.get<QByteArray>(QStringLiteral("url")));
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
Q_EMIT shareReceived(url); Q_EMIT shareReceived(url.toString());
} else { } else {
qCDebug(KDECONNECT_PLUGIN_SHARE) << "Error: Nothing attached!"; qCDebug(KDECONNECT_PLUGIN_SHARE) << "Error: Nothing attached!";
} }
return true; return true;
} }
void SharePlugin::finished(KJob* job) void SharePlugin::finished(KJob* job)
{ {
FileTransferJob* ftjob = qobject_cast<FileTransferJob*>(job); FileTransferJob* ftjob = qobject_cast<FileTransferJob*>(job);
if (ftjob) if (ftjob && !job->error()) {
Q_EMIT shareReceived(ftjob->destination()); Q_EMIT shareReceived(ftjob->destination().toString());
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination();
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished. Success:" << (!job->error()) << (ftjob ? ftjob->destination() : QUrl()); } else {
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer failed." << (ftjob ? ftjob->destination() : QUrl());
}
} }
void SharePlugin::openDestinationFolder() void SharePlugin::openDestinationFolder()

View file

@ -49,7 +49,7 @@ private Q_SLOTS:
void openDestinationFolder(); void openDestinationFolder();
Q_SIGNALS: Q_SIGNALS:
void shareReceived(const QUrl& url); void shareReceived(const QString& url);
private: private:
void shareUrl(const QUrl& url); void shareUrl(const QUrl& url);

View file

@ -76,7 +76,7 @@ class TestSendFile : public QObject
QVERIFY(plugin); QVERIFY(plugin);
plugin->metaObject()->invokeMethod(plugin, "shareUrl", Q_ARG(QString, QUrl::fromLocalFile(temp.fileName()).toString())); 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)); QVERIFY(spy.wait(2000));
QVariantList args = spy.takeFirst(); QVariantList args = spy.takeFirst();