Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/recentusagemodel.cpp
Show All 24 Lines | |||||
25 | #include <kio_version.h> | 25 | #include <kio_version.h> | ||
26 | 26 | | |||
27 | #include <config-X11.h> | 27 | #include <config-X11.h> | ||
28 | 28 | | |||
29 | #include <QIcon> | 29 | #include <QIcon> | ||
30 | #include <QMimeDatabase> | 30 | #include <QMimeDatabase> | ||
31 | #include <QQmlEngine> | 31 | #include <QQmlEngine> | ||
32 | #include <QTimer> | 32 | #include <QTimer> | ||
33 | #include <QDir> | ||||
33 | #if HAVE_X11 | 34 | #if HAVE_X11 | ||
34 | #include <QX11Info> | 35 | #include <QX11Info> | ||
35 | #endif | 36 | #endif | ||
36 | 37 | | |||
37 | #include <KActivities/ResourceInstance> | 38 | #include <KActivities/ResourceInstance> | ||
38 | #include <KFileItem> | 39 | #include <KFileItem> | ||
39 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
40 | #include <KMimeTypeTrader> | 41 | #include <KMimeTypeTrader> | ||
41 | #include <KRun> | 42 | #include <KRun> | ||
42 | #include <KService> | 43 | #include <KService> | ||
43 | #include <KStartupInfo> | 44 | #include <KStartupInfo> | ||
45 | #include <KIO/OpenFileManagerWindowJob> | ||||
44 | 46 | | |||
45 | #include <KActivities/Stats/Cleaning> | 47 | #include <KActivities/Stats/Cleaning> | ||
46 | #include <KActivities/Stats/ResultModel> | 48 | #include <KActivities/Stats/ResultModel> | ||
47 | #include <KActivities/Stats/Terms> | 49 | #include <KActivities/Stats/Terms> | ||
48 | 50 | | |||
49 | namespace KAStats = KActivities::Stats; | 51 | namespace KAStats = KActivities::Stats; | ||
50 | 52 | | |||
51 | using namespace KAStats; | 53 | using namespace KAStats; | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 112 | { | |||
122 | return (left.row() < right.row()); | 124 | return (left.row() < right.row()); | ||
123 | } | 125 | } | ||
124 | 126 | | |||
125 | RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage, int ordering) | 127 | RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage, int ordering) | ||
126 | : ForwardingModel(parent) | 128 | : ForwardingModel(parent) | ||
127 | , m_usage(usage) | 129 | , m_usage(usage) | ||
128 | , m_ordering((Ordering)ordering) | 130 | , m_ordering((Ordering)ordering) | ||
129 | , m_complete(false) | 131 | , m_complete(false) | ||
132 | , m_placesModel(new KFilePlacesModel(this)) | ||||
130 | { | 133 | { | ||
131 | refresh(); | 134 | refresh(); | ||
132 | } | 135 | } | ||
133 | 136 | | |||
134 | RecentUsageModel::~RecentUsageModel() | 137 | RecentUsageModel::~RecentUsageModel() | ||
135 | { | 138 | { | ||
136 | } | 139 | } | ||
137 | 140 | | |||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 253 | #else | |||
251 | const KFileItem fileItem(url); | 254 | const KFileItem fileItem(url); | ||
252 | #endif | 255 | #endif | ||
253 | 256 | | |||
254 | if (!url.isValid()) { | 257 | if (!url.isValid()) { | ||
255 | return QVariant(); | 258 | return QVariant(); | ||
256 | } | 259 | } | ||
257 | 260 | | |||
258 | if (role == Qt::DisplayRole) { | 261 | if (role == Qt::DisplayRole) { | ||
262 | const auto index = m_placesModel->closestItem(fileItem.url()); | ||||
263 | if (index.isValid()) { | ||||
264 | const auto parentUrl = m_placesModel->url(index); | ||||
265 | if (parentUrl == fileItem.url()) { | ||||
266 | return m_placesModel->text(index); | ||||
267 | } | ||||
268 | } | ||||
259 | return fileItem.text(); | 269 | return fileItem.text(); | ||
260 | } else if (role == Qt::DecorationRole) { | 270 | } else if (role == Qt::DecorationRole) { | ||
261 | return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme(QStringLiteral("unknown"))); | 271 | return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme(QStringLiteral("unknown"))); | ||
262 | } else if (role == Kicker::GroupRole) { | 272 | } else if (role == Kicker::GroupRole) { | ||
263 | return i18n("Documents"); | 273 | return i18n("Documents"); | ||
264 | } else if (role == Kicker::FavoriteIdRole || role == Kicker::UrlRole) { | 274 | } else if (role == Kicker::FavoriteIdRole || role == Kicker::UrlRole) { | ||
265 | return url.toString(); | 275 | return url.toString(); | ||
276 | } else if (role == Kicker::DescriptionRole) { | ||||
277 | QString desc = fileItem.localPath(); | ||||
278 | | ||||
broulik: Can you use the "~" for HOME like the runners do please | |||||
I am thinking about adding this utility feature to KCoreAddons and avoid more duplication. meven: I am thinking about adding this utility feature to KCoreAddons and avoid more duplication. | |||||
meven: https://phabricator.kde.org/D26122 | |||||
279 | const auto index = m_placesModel->closestItem(fileItem.url()); | ||||
280 | if (index.isValid()) { | ||||
281 | // the current file has a parent in placesModel | ||||
282 | const auto parentUrl = m_placesModel->url(index); | ||||
283 | if (parentUrl == fileItem.url()) { | ||||
284 | // if the current item is a place | ||||
285 | return QString(); | ||||
286 | } | ||||
287 | desc.truncate(desc.lastIndexOf(QChar('/'))); | ||||
288 | const auto text = m_placesModel->text(index); | ||||
289 | desc.replace(0, parentUrl.path().length(), text); | ||||
290 | } else { | ||||
291 | // remove filename | ||||
292 | desc.truncate(desc.lastIndexOf(QChar('/'))); | ||||
293 | } | ||||
294 | return desc; | ||||
266 | } else if (role == Kicker::UrlRole) { | 295 | } else if (role == Kicker::UrlRole) { | ||
267 | return url; | 296 | return url; | ||
268 | } else if (role == Kicker::HasActionListRole) { | 297 | } else if (role == Kicker::HasActionListRole) { | ||
269 | return true; | 298 | return true; | ||
270 | } else if (role == Kicker::ActionListRole) { | 299 | } else if (role == Kicker::ActionListRole) { | ||
271 | QVariantList actionList = Kicker::createActionListForFileItem(fileItem); | 300 | QVariantList actionList = Kicker::createActionListForFileItem(fileItem); | ||
272 | 301 | | |||
273 | actionList << Kicker::createSeparatorActionItem(); | 302 | actionList << Kicker::createSeparatorActionItem(); | ||
274 | 303 | | |||
304 | const QVariantMap &openParentFolder = Kicker::createActionItem(i18n("Open Containing Folder"), QStringLiteral("openParentFolder")); | ||||
305 | actionList << openParentFolder; | ||||
306 | | ||||
275 | const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Document"), QStringLiteral("forget")); | 307 | const QVariantMap &forgetAction = Kicker::createActionItem(i18n("Forget Document"), QStringLiteral("forget")); | ||
276 | actionList << forgetAction; | 308 | actionList << forgetAction; | ||
277 | 309 | | |||
278 | const QVariantMap &forgetAllAction = Kicker::createActionItem(forgetAllActionName(), QStringLiteral("forgetAll")); | 310 | const QVariantMap &forgetAllAction = Kicker::createActionItem(forgetAllActionName(), QStringLiteral("forgetAll")); | ||
279 | actionList << forgetAllAction; | 311 | actionList << forgetAllAction; | ||
280 | 312 | | |||
281 | return actionList; | 313 | return actionList; | ||
282 | } | 314 | } | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 373 | while (sourceProxy) { | |||
342 | idx = sourceProxy->mapToSource(idx); | 374 | idx = sourceProxy->mapToSource(idx); | ||
343 | sourceProxy = qobject_cast<QSortFilterProxyModel *>(sourceProxy->sourceModel()); | 375 | sourceProxy = qobject_cast<QSortFilterProxyModel *>(sourceProxy->sourceModel()); | ||
344 | } | 376 | } | ||
345 | 377 | | |||
346 | static_cast<ResultModel *>(m_activitiesModel.data())->forgetResource(idx.row()); | 378 | static_cast<ResultModel *>(m_activitiesModel.data())->forgetResource(idx.row()); | ||
347 | } | 379 | } | ||
348 | 380 | | |||
349 | return false; | 381 | return false; | ||
382 | } else if (actionId == QLatin1String("openParentFolder") && withinBounds) { | ||||
383 | const auto url = QUrl::fromUserInput(resourceAt(row)); | ||||
384 | KIO::highlightInFileManager({url}); | ||||
Probably worth just doing this in a single line rather than defining a variable used only once ngraham: Probably worth just doing this in a single line rather than defining a variable used only once | |||||
I did this for readability, I think we should keep this. KIO::highlightInFileManager({QUrl::fromUserInput(resourceAt(row))}); meven: I did this for readability, I think we should keep this.
The alternative is a little convoluted… | |||||
350 | } else if (actionId == QLatin1String("forgetAll")) { | 385 | } else if (actionId == QLatin1String("forgetAll")) { | ||
351 | if (m_activitiesModel) { | 386 | if (m_activitiesModel) { | ||
352 | static_cast<ResultModel *>(m_activitiesModel.data())->forgetAllResources(); | 387 | static_cast<ResultModel *>(m_activitiesModel.data())->forgetAllResources(); | ||
353 | } | 388 | } | ||
354 | 389 | | |||
355 | return false; | 390 | return false; | ||
356 | } else if (withinBounds) { | 391 | } else if (withinBounds) { | ||
357 | const QString &resource = resourceAt(row); | 392 | const QString &resource = resourceAt(row); | ||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |
Can you use the "~" for HOME like the runners do please