Commit f53dadaf authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port to new KIO worker API

parent 34da0ad9
Pipeline #228253 passed with stage
in 7 minutes and 51 seconds
......@@ -12,7 +12,7 @@ if (SAILFISHOS)
set(KF5_MIN_VERSION "5.36.0")
set(QT_MIN_VERSION "5.6.0")
else()
set(KF5_MIN_VERSION "5.95.0")
set(KF5_MIN_VERSION "5.96.0")
set(QT_MIN_VERSION "5.15.2")
set(KDE_COMPILERSETTINGS_LEVEL "5.84.0")
endif()
......
......@@ -33,8 +33,8 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char** argv)
exit(-1);
}
KioKdeconnect slave(argv[2], argv[3]);
slave.dispatchLoop();
KioKdeconnect worker(argv[2], argv[3]);
worker.dispatchLoop();
return 0;
}
......@@ -57,25 +57,24 @@ KIO::Error toKioError(const QDBusError::ErrorType type)
};
template <typename T>
bool handleDBusError(QDBusReply<T>& reply, KIO::SlaveBase* slave)
KIO::WorkerResult handleDBusError(QDBusReply<T>& reply)
{
if (!reply.isValid())
{
qCDebug(KDECONNECT_KIO) << "Error in DBus request:" << reply.error();
slave->error(toKioError(reply.error().type()),reply.error().message());
return true;
return KIO::WorkerResult::fail(toKioError(reply.error().type()), reply.error().message());
}
return false;
return KIO::WorkerResult::pass();
}
KioKdeconnect::KioKdeconnect(const QByteArray& pool, const QByteArray& app)
: SlaveBase("kdeconnect", pool, app),
: WorkerBase("kdeconnect", pool, app),
m_dbusInterface(new DaemonDbusInterface(this))
{
}
void KioKdeconnect::listAllDevices()
KIO::WorkerResult KioKdeconnect::listAllDevices()
{
infoMessage(i18n("Listing devices..."));
......@@ -117,10 +116,10 @@ void KioKdeconnect::listAllDevices()
listEntry(entry);
infoMessage(QLatin1String(""));
finished();
return KIO::WorkerResult::pass();
}
void KioKdeconnect::listDevice(const QString& device)
KIO::WorkerResult KioKdeconnect::listDevice(const QString& device)
{
infoMessage(i18n("Accessing device..."));
......@@ -138,41 +137,36 @@ void KioKdeconnect::listDevice(const QString& device)
devsRepl.waitForFinished();
if (!devsRepl.value().contains(device)) {
error(KIO::ERR_SLAVE_DEFINED, i18n("No such device: %0").arg(device));
return;
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("No such device: %0").arg(device));
}
DeviceDbusInterface dev(device);
if (!dev.isTrusted()) {
error(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not paired").arg(dev.name()));
return;
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not paired").arg(dev.name()));
}
if (!dev.isReachable()) {
error(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not connected").arg(dev.name()));
return;
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 is not connected").arg(dev.name()));
}
if (!dev.hasPlugin(QStringLiteral("kdeconnect_sftp"))) {
error(KIO::ERR_SLAVE_DEFINED, i18n("%0 has no Remote Filesystem plugin").arg(dev.name()));
return;
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, i18n("%0 has no Remote Filesystem plugin").arg(dev.name()));
}
}
if (handleDBusError(mountreply, this)) {
return;
if (auto result = handleDBusError(mountreply); !result.success()) {
return result;
}
if (!mountreply.value()) {
error(KIO::ERR_SLAVE_DEFINED, interface.getMountError());
return;
return KIO::WorkerResult::fail(KIO::ERR_SLAVE_DEFINED, interface.getMountError());
}
QDBusReply< QVariantMap > urlreply = interface.getDirectories();
if (handleDBusError(urlreply, this)) {
return;
if (auto result = handleDBusError(urlreply); !result.success()) {
return result;
}
QVariantMap urls = urlreply.value();
......@@ -209,32 +203,29 @@ void KioKdeconnect::listDevice(const QString& device)
listEntry(entry);
infoMessage(QLatin1String(""));
finished();
return KIO::WorkerResult::pass();
}
void KioKdeconnect::listDir(const QUrl& url)
KIO::WorkerResult KioKdeconnect::listDir(const QUrl& url)
{
qCDebug(KDECONNECT_KIO) << "Listing..." << url;
if (!m_dbusInterface->isValid()) {
infoMessage(i18n("Could not contact background service."));
finished();
return;
return KIO::WorkerResult::fail(KIO::Error::ERR_SLAVE_DEFINED, i18n("Could not contact background service."));
}
QString currentDevice = url.host();
if (currentDevice.isEmpty()) {
listAllDevices();
return listAllDevices();
} else {
listDevice(currentDevice);
return listDevice(currentDevice);
}
}
void KioKdeconnect::stat(const QUrl& url)
KIO::WorkerResult KioKdeconnect::stat(const QUrl& url)
{
qCDebug(KDECONNECT_KIO) << "Stat: " << url;
......@@ -256,14 +247,14 @@ void KioKdeconnect::stat(const QUrl& url)
statEntry(entry);
finished();
return KIO::WorkerResult::pass();
}
void KioKdeconnect::get(const QUrl& url)
KIO::WorkerResult KioKdeconnect::get(const QUrl& url)
{
qCDebug(KDECONNECT_KIO) << "Get: " << url;
mimeType(QLatin1String(""));
finished();
return KIO::WorkerResult::pass();
}
//needed for JSON file embedding
......
......@@ -9,23 +9,23 @@
#include <QObject>
#include <kio/slavebase.h>
#include <KIO/WorkerBase>
#include "dbusinterfaces.h"
class KioKdeconnect : public QObject, public KIO::SlaveBase
class KioKdeconnect : public QObject, public KIO::WorkerBase
{
Q_OBJECT
public:
KioKdeconnect(const QByteArray& pool, const QByteArray& app);
void get(const QUrl& url) override;
void listDir(const QUrl& url) override;
void stat(const QUrl& url) override;
KIO::WorkerResult get(const QUrl& url) override;
KIO::WorkerResult listDir(const QUrl& url) override;
KIO::WorkerResult stat(const QUrl& url) override;
void listAllDevices(); //List all devices exported by m_dbusInterface
void listDevice(const QString& device); //List m_currentDevice
KIO::WorkerResult listAllDevices(); //List all devices exported by m_dbusInterface
KIO::WorkerResult listDevice(const QString& device); //List m_currentDevice
private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment