diff --git a/recentlyused/recentlyused.h b/recentlyused/recentlyused.h --- a/recentlyused/recentlyused.h +++ b/recentlyused/recentlyused.h @@ -27,7 +27,16 @@ /** * Implements recentlyused:/ ioslave - * It uses KActivitiesStats as a backend (as kickoff/kicker do). + * 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). + * There are also an order and limit options. + * + * There only three path allowed : / /files and /locations. + * / does not do anything special + * /files returns only files whose mimetype is known to the KActivity backend + * /locations returns only folders + * When /files or /locations are used the option ?type, described below, cannot be used. * * It supports options to filter what is returned through url parameters: * @@ -99,6 +108,7 @@ private: KIO::UDSEntry udsEntryFromResource(const QString &resource); + KIO::UDSEntry udsEntryForRoot(const QString &dirName); }; #endif diff --git a/recentlyused/recentlyused.cpp b/recentlyused/recentlyused.cpp --- a/recentlyused/recentlyused.cpp +++ b/recentlyused/recentlyused.cpp @@ -92,13 +92,20 @@ | Limit(30); // Parse url query parameter - auto urlQuery = QUrlQuery(url); + const auto urlQuery = QUrlQuery(url); - // handles type aka mimetype - if (urlQuery.hasQueryItem(QStringLiteral("type"))) { - const auto typeValue = urlQuery.queryItemValue(QStringLiteral("type")); - const auto types = typeValue.split(QLatin1Char(',')); - query.setTypes(types); + const auto path = url.path(); + if (path == QStringLiteral("/files")) { + query.setTypes(Type::files()); + } else if (path == QStringLiteral("/locations")) { + query.setTypes(QStringLiteral("inode/directory")); + } else { + // handles type parameter aka mimetype + if (urlQuery.hasQueryItem(QStringLiteral("type"))) { + const auto typeValue = urlQuery.queryItemValue(QStringLiteral("type")); + const auto types = typeValue.split(QLatin1Char(',')); + query.setTypes(types); + } } // limit parameter @@ -198,8 +205,11 @@ void RecentlyUsed::listDir(const QUrl &url) { if (!isRootUrl(url)) { - error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); - return; + const auto path = url.path(); + if (path != QStringLiteral("/files") && path != QStringLiteral("/locations") ){ + error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); + return; + } } auto model = runQuery(url); @@ -218,6 +228,19 @@ finished(); } +KIO::UDSEntry RecentlyUsed::udsEntryForRoot(const QString &dirName) +{ + KIO::UDSEntry uds; + uds.reserve(6); + uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName); + uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName); + uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName); + uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("document-open-recent")); + uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); + uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory")); + return uds; +} + void RecentlyUsed::stat(const QUrl &url) { qCDebug(KIO_RECENTLYUSED_LOG) << "stating" << " " << url; @@ -227,21 +250,25 @@ // stat the root path // - QString dirName = i18n("Recent Documents"); - KIO::UDSEntry uds; - uds.reserve(6); - uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName); - uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName); - uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName); - uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("document-open-recent")); - uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); - uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory")); - - statEntry(uds); + const QString dirName = i18n("Recent Documents"); + + statEntry(udsEntryForRoot(dirName)); finished(); } else { - // only the root path is 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)); + finished(); + } else if (path == QStringLiteral("/locations")) { + const QString dirName = i18n("Recent Locations"); + statEntry(udsEntryForRoot(dirName)); + finished(); + } else { + // only the root path is supported + error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); + } } }