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