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.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<QByteArray>(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<FileTransferJob*>(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()

View file

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

View file

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