Commit 22b9d3bd authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kio_recentlyused: port to KIO::WorkerBase

parent 419b8603
Pipeline #200156 passed with stage
in 2 minutes and 3 seconds
......@@ -23,8 +23,8 @@ endif()
ecm_qt_declare_logging_category(recentlyused
HEADER recentlyused-logsettings.h
IDENTIFIER KIO_RECENTLYUSED_LOG
CATEGORY_NAME kf.kio.slaves.recentlyused
OLD_CATEGORY_NAMES log_kio_recentlyused
CATEGORY_NAME kf.kio.workers.recentlyused
OLD_CATEGORY_NAMES log_kio_recentlyused kf.kio.slaves.recentlyused
DESCRIPTION "KIO recentlyused"
EXPORT KIO_EXTRAS
)
......
......@@ -32,21 +32,21 @@ using namespace KAStats::Terms;
class KIOPluginForMetaData : public QObject
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.kio.slave.recentlyused" FILE "recentlyused.json")
Q_PLUGIN_METADATA(IID "org.kde.kio.worker.recentlyused" FILE "recentlyused.json")
};
extern "C" int Q_DECL_EXPORT kdemain(int argc, char **argv)
{
// necessary to use other kio slaves
// necessary to use other kio workers
QCoreApplication app(argc, argv);
app.setApplicationName(QStringLiteral("kio_recentlyused"));
if (argc != 4) {
fprintf(stderr, "Usage: kio_recentlyused protocol domain-socket1 domain-socket2\n");
exit(-1);
}
// start the slave
RecentlyUsed slave(argv[2], argv[3]);
slave.dispatchLoop();
// start the worker
RecentlyUsed worker(argv[2], argv[3]);
worker.dispatchLoop();
return 0;
}
......@@ -57,7 +57,7 @@ static bool isRootUrl(const QUrl &url)
}
RecentlyUsed::RecentlyUsed(const QByteArray &pool, const QByteArray &app)
: SlaveBase("recentlyused", pool, app)
: WorkerBase("recentlyused", pool, app)
{
}
......@@ -190,13 +190,12 @@ KIO::UDSEntry RecentlyUsed::udsEntryFromResource(const QString &resource, const
return uds;
}
void RecentlyUsed::listDir(const QUrl &url)
KIO::WorkerResult RecentlyUsed::listDir(const QUrl &url)
{
if (!isRootUrl(url)) {
const auto path = url.path();
if (path != QStringLiteral("/files") && path != QStringLiteral("/locations") ) {
error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
return;
return KIO::WorkerResult::fail(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
}
}
......@@ -214,7 +213,8 @@ void RecentlyUsed::listDir(const QUrl &url)
}
listEntries(udslist);
finished();
return KIO::WorkerResult::pass();
}
KIO::UDSEntry RecentlyUsed::udsEntryForRoot(const QString &dirName, const QString &iconName)
......@@ -235,7 +235,7 @@ KIO::UDSEntry RecentlyUsed::udsEntryForRoot(const QString &dirName, const QStrin
return uds;
}
void RecentlyUsed::stat(const QUrl &url)
KIO::WorkerResult RecentlyUsed::stat(const QUrl &url)
{
qCDebug(KIO_RECENTLYUSED_LOG) << "stating" << " " << url;
......@@ -247,38 +247,36 @@ void RecentlyUsed::stat(const QUrl &url)
const QString dirName = i18n("Recent Documents");
statEntry(udsEntryForRoot(dirName, QStringLiteral("document-open-recent")));
finished();
} else {
return KIO::WorkerResult::pass();
}
const auto path = url.path();
if (path == QStringLiteral("/files")) {
const QString dirName = i18n("Recent Files");
statEntry(udsEntryForRoot(dirName, QStringLiteral("document-open-recent")));
finished();
} else if (path == QStringLiteral("/locations")) {
const QString dirName = i18n("Recent Locations");
statEntry(udsEntryForRoot(dirName, QStringLiteral("folder-open-recent")));
finished();
} else {
// only / /files and /locations paths are supported
error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
}
const auto path = url.path();
if (path == QStringLiteral("/files")) {
const QString dirName = i18n("Recent Files");
statEntry(udsEntryForRoot(dirName, QStringLiteral("document-open-recent")));
} else if (path == QStringLiteral("/locations")) {
const QString dirName = i18n("Recent Locations");
statEntry(udsEntryForRoot(dirName, QStringLiteral("folder-open-recent")));
} else {
// only / /files and /locations paths are supported
return KIO::WorkerResult::fail(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
}
return KIO::WorkerResult::pass();
}
void RecentlyUsed::mimetype(const QUrl &url)
KIO::WorkerResult RecentlyUsed::mimetype(const QUrl &url)
{
// the root url is always a folder
if (isRootUrl(url)) {
mimeType(QStringLiteral("inode/directory"));
finished();
} else {
// only the root path is supported
error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
return KIO::WorkerResult::pass();
}
// only the root path is supported
return KIO::WorkerResult::fail(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString());
}
void RecentlyUsed::special(const QByteArray &data) {
KIO::WorkerResult RecentlyUsed::special(const QByteArray &data) {
int id;
QDataStream stream(data);
......@@ -312,6 +310,8 @@ void RecentlyUsed::special(const QByteArray &data) {
default:
break;
}
return KIO::WorkerResult::pass();
}
// needed for JSON file embedding
......
......@@ -7,10 +7,10 @@
#ifndef RECENTLYUSED_H
#define RECENTLYUSED_H
#include <KIO/SlaveBase>
#include <KIO/WorkerBase>
/**
* Implements recentlyused:/ ioslave
* Implements recentlyused:/ KIO worker
* It uses KActivitiesStats as a backend (as kickoff/kicker do) to retrieve recently accessed
* files or folders.
* It supports filtering on mimetype (option type), path, date of access or date of access range, activity and agent (meaning application).
......@@ -76,18 +76,18 @@
* - recentlyused:/?type=video/*,audio/*&order=HighScoredFirst : recently used video or audio files ordered by their scoring descending
* - recentlyused:/?url=/home/meven/kde/src/*&type=text/plain : recently used text files located in a subdir of /home/meven/kde/src/
*
* @brief The RecentlyUsed implements an ioslave to access recently used files or directories
* @brief The RecentlyUsed implements an KIO worker to access recently used files or directories
*/
class RecentlyUsed : public KIO::SlaveBase
class RecentlyUsed : public KIO::WorkerBase
{
public:
RecentlyUsed(const QByteArray &pool, const QByteArray &app);
~RecentlyUsed() override;
protected:
void listDir(const QUrl &url) override;
void stat(const QUrl &url) override;
void mimetype(const QUrl &url) override;
KIO::WorkerResult listDir(const QUrl &url) override;
KIO::WorkerResult stat(const QUrl &url) override;
KIO::WorkerResult mimetype(const QUrl &url) override;
/**
* Implemention of the forget action
......@@ -102,7 +102,7 @@ protected:
* auto job = KIO::special(QUrl("recentlyused:/"), packedArgs);
* job->exec();
*/
void special(const QByteArray &data) override;
KIO::WorkerResult special(const QByteArray &data) override;
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