Changeset View
Changeset View
Standalone View
Standalone View
recentlyused/recentlyused.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
87 | ResultModel *runQuery(const QUrl &url) | 87 | ResultModel *runQuery(const QUrl &url) | ||
88 | { | 88 | { | ||
89 | qCDebug(KIO_RECENTLYUSED_LOG) << "runQuery for url" << url.toString(); | 89 | qCDebug(KIO_RECENTLYUSED_LOG) << "runQuery for url" << url.toString(); | ||
90 | 90 | | |||
91 | auto query = UsedResources | 91 | auto query = UsedResources | ||
92 | | Limit(30); | 92 | | Limit(30); | ||
93 | 93 | | |||
94 | // Parse url query parameter | 94 | // Parse url query parameter | ||
95 | auto urlQuery = QUrlQuery(url); | 95 | const auto urlQuery = QUrlQuery(url); | ||
96 | 96 | | |||
97 | // handles type aka mimetype | 97 | const auto path = url.path(); | ||
98 | if (path == QStringLiteral("/files")) { | ||||
99 | query.setTypes(Type::files()); | ||||
100 | } else if (path == QStringLiteral("/locations")) { | ||||
101 | query.setTypes(QStringLiteral("inode/directory")); | ||||
102 | } else { | ||||
103 | // handles type parameter aka mimetype | ||||
98 | if (urlQuery.hasQueryItem(QStringLiteral("type"))) { | 104 | if (urlQuery.hasQueryItem(QStringLiteral("type"))) { | ||
meven: Should we allow the filtering through type with /files path ?
I am thinking I should change… | |||||
ngraham: Sure, sounds like a neat bonus feature. | |||||
99 | const auto typeValue = urlQuery.queryItemValue(QStringLiteral("type")); | 105 | const auto typeValue = urlQuery.queryItemValue(QStringLiteral("type")); | ||
100 | const auto types = typeValue.split(QLatin1Char(',')); | 106 | const auto types = typeValue.split(QLatin1Char(',')); | ||
101 | query.setTypes(types); | 107 | query.setTypes(types); | ||
102 | } | 108 | } | ||
109 | } | ||||
103 | 110 | | |||
104 | // limit parameter | 111 | // limit parameter | ||
105 | if (urlQuery.hasQueryItem(QStringLiteral("limit"))) { | 112 | if (urlQuery.hasQueryItem(QStringLiteral("limit"))) { | ||
106 | const auto limitValue = urlQuery.queryItemValue(QStringLiteral("limit")); | 113 | const auto limitValue = urlQuery.queryItemValue(QStringLiteral("limit")); | ||
107 | bool parseOk; | 114 | bool parseOk; | ||
108 | const auto limitInt = limitValue.toInt(&parseOk); | 115 | const auto limitInt = limitValue.toInt(&parseOk); | ||
109 | if (parseOk) { | 116 | if (parseOk) { | ||
110 | query.setLimit(limitInt); | 117 | query.setLimit(limitInt); | ||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 186 | { | |||
193 | } | 200 | } | ||
194 | uds.fastInsert(KIO::UDSEntry::UDS_URL, resourceUrl.toString()); | 201 | uds.fastInsert(KIO::UDSEntry::UDS_URL, resourceUrl.toString()); | ||
195 | return uds; | 202 | return uds; | ||
196 | } | 203 | } | ||
197 | 204 | | |||
198 | void RecentlyUsed::listDir(const QUrl &url) | 205 | void RecentlyUsed::listDir(const QUrl &url) | ||
199 | { | 206 | { | ||
200 | if (!isRootUrl(url)) { | 207 | if (!isRootUrl(url)) { | ||
208 | const auto path = url.path(); | ||||
209 | if (path != QStringLiteral("/files") && path != QStringLiteral("/locations") ){ | ||||
201 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | 210 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | ||
202 | return; | 211 | return; | ||
203 | } | 212 | } | ||
213 | } | ||||
204 | 214 | | |||
205 | auto model = runQuery(url); | 215 | auto model = runQuery(url); | ||
206 | 216 | | |||
207 | KIO::UDSEntryList udslist; | 217 | KIO::UDSEntryList udslist; | ||
208 | udslist.reserve(model->rowCount()); | 218 | udslist.reserve(model->rowCount()); | ||
209 | 219 | | |||
210 | for (int r = 0; r < model->rowCount(); ++r) { | 220 | for (int r = 0; r < model->rowCount(); ++r) { | ||
211 | QModelIndex index = model->index(r, 0); | 221 | QModelIndex index = model->index(r, 0); | ||
212 | QString resource = model->data(index, ResultModel::ResourceRole).toString(); | 222 | QString resource = model->data(index, ResultModel::ResourceRole).toString(); | ||
213 | 223 | | |||
214 | udslist << udsEntryFromResource(resource); | 224 | udslist << udsEntryFromResource(resource); | ||
215 | } | 225 | } | ||
216 | 226 | | |||
217 | listEntries(udslist); | 227 | listEntries(udslist); | ||
218 | finished(); | 228 | finished(); | ||
219 | } | 229 | } | ||
220 | 230 | | |||
221 | void RecentlyUsed::stat(const QUrl &url) | 231 | KIO::UDSEntry RecentlyUsed::udsEntryForRoot(const QString &dirName) | ||
222 | { | 232 | { | ||
223 | qCDebug(KIO_RECENTLYUSED_LOG) << "stating" << " " << url; | | |||
224 | | ||||
225 | if (isRootUrl(url)) { | | |||
226 | // | | |||
227 | // stat the root path | | |||
228 | // | | |||
229 | | ||||
230 | QString dirName = i18n("Recent Documents"); | | |||
231 | KIO::UDSEntry uds; | 233 | KIO::UDSEntry uds; | ||
232 | uds.reserve(6); | 234 | uds.reserve(6); | ||
233 | uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName); | 235 | uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName); | ||
234 | uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName); | 236 | uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName); | ||
235 | uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName); | 237 | uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName); | ||
236 | uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("document-open-recent")); | 238 | uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("document-open-recent")); | ||
237 | uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); | 239 | uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); | ||
238 | uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory")); | 240 | uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory")); | ||
241 | return uds; | ||||
242 | } | ||||
243 | | ||||
244 | void RecentlyUsed::stat(const QUrl &url) | ||||
245 | { | ||||
246 | qCDebug(KIO_RECENTLYUSED_LOG) << "stating" << " " << url; | ||||
247 | | ||||
248 | if (isRootUrl(url)) { | ||||
249 | // | ||||
250 | // stat the root path | ||||
251 | // | ||||
252 | | ||||
253 | const QString dirName = i18n("Recent Documents"); | ||||
239 | 254 | | |||
240 | statEntry(uds); | 255 | statEntry(udsEntryForRoot(dirName)); | ||
256 | finished(); | ||||
257 | } else { | ||||
258 | | ||||
259 | const auto path = url.path(); | ||||
260 | if (path == QStringLiteral("/files")) { | ||||
261 | const QString dirName = i18n("Recent Files"); | ||||
262 | statEntry(udsEntryForRoot(dirName)); | ||||
263 | finished(); | ||||
264 | } else if (path == QStringLiteral("/locations")) { | ||||
265 | const QString dirName = i18n("Recent Locations"); | ||||
266 | statEntry(udsEntryForRoot(dirName)); | ||||
241 | finished(); | 267 | finished(); | ||
242 | } else { | 268 | } else { | ||
243 | // only the root path is supported | 269 | // only the root path is supported | ||
244 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | 270 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | ||
245 | } | 271 | } | ||
246 | } | 272 | } | ||
273 | } | ||||
247 | 274 | | |||
248 | void RecentlyUsed::mimetype(const QUrl &url) | 275 | void RecentlyUsed::mimetype(const QUrl &url) | ||
249 | { | 276 | { | ||
250 | // the root url is always a folder | 277 | // the root url is always a folder | ||
251 | if (isRootUrl(url)) { | 278 | if (isRootUrl(url)) { | ||
252 | mimeType(QStringLiteral("inode/directory")); | 279 | mimeType(QStringLiteral("inode/directory")); | ||
253 | finished(); | 280 | finished(); | ||
254 | } else { | 281 | } else { | ||
255 | // only the root path is supported | 282 | // only the root path is supported | ||
256 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | 283 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | ||
257 | } | 284 | } | ||
258 | } | 285 | } | ||
259 | 286 | | |||
260 | // needed for JSON file embedding | 287 | // needed for JSON file embedding | ||
261 | #include "recentlyused.moc" | 288 | #include "recentlyused.moc" |
Should we allow the filtering through type with /files path ?
I am thinking I should change that.