Support "Deletion Time" role in Trash

This allows to sort by and show (both as additional data in icon view and column in column
view) deletion date of files in Trash.

CHANGELOG: It is now possible to view and sort by "Deletion Time" in Trash

BUG: 153492
FIXED-IN: 17.08.0

Differential Revision: https://phabricator.kde.org/D6269
This commit is contained in:
Kai Uwe Broulik 2017-06-20 11:32:29 +02:00
parent 96eff55e75
commit 0d2f86de18
3 changed files with 43 additions and 7 deletions

View file

@ -80,7 +80,7 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
const KIO::filesize_t size = roleValue.value<KIO::filesize_t>(); const KIO::filesize_t size = roleValue.value<KIO::filesize_t>();
text = KFormat().formatByteSize(size); text = KFormat().formatByteSize(size);
} }
} else if (role == "modificationtime" || role == "accesstime") { } else if (role == "modificationtime" || role == "accesstime" || role == "deletiontime") {
const QDateTime dateTime = roleValue.toDateTime(); const QDateTime dateTime = roleValue.toDateTime();
text = QLocale().toString(dateTime, QLocale::ShortFormat); text = QLocale().toString(dateTime, QLocale::ShortFormat);
} else { } else {

View file

@ -329,8 +329,21 @@ QList<QPair<int, QVariant> > KFileItemModel::groups() const
switch (typeForRole(sortRole())) { switch (typeForRole(sortRole())) {
case NameRole: m_groups = nameRoleGroups(); break; case NameRole: m_groups = nameRoleGroups(); break;
case SizeRole: m_groups = sizeRoleGroups(); break; case SizeRole: m_groups = sizeRoleGroups(); break;
case ModificationTimeRole: m_groups = timeRoleGroups(KFileItem::ModificationTime); break; case ModificationTimeRole:
case AccessTimeRole: m_groups = timeRoleGroups(KFileItem::AccessTime); break; m_groups = timeRoleGroups([](const ItemData *item) {
return item->item.time(KFileItem::ModificationTime);
});
break;
case AccessTimeRole:
m_groups = timeRoleGroups([](const ItemData *item) {
return item->item.time(KFileItem::AccessTime);
});
break;
case DeletionTimeRole:
m_groups = timeRoleGroups([](const ItemData *item) {
return item->values.value("deletiontime").toDateTime();
});
break;
case PermissionsRole: m_groups = permissionRoleGroups(); break; case PermissionsRole: m_groups = permissionRoleGroups(); break;
case RatingRole: m_groups = ratingRoleGroups(); break; case RatingRole: m_groups = ratingRoleGroups(); break;
default: m_groups = genericStringRoleGroups(sortRole()); break; default: m_groups = genericStringRoleGroups(sortRole()); break;
@ -1321,6 +1334,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList)
case GroupRole: case GroupRole:
case DestinationRole: case DestinationRole:
case PathRole: case PathRole:
case DeletionTimeRole:
// These roles can be determined with retrieveData, and they have to be stored // These roles can be determined with retrieveData, and they have to be stored
// in the QHash "values" for the sorting. // in the QHash "values" for the sorting.
foreach (ItemData* itemData, itemDataList) { foreach (ItemData* itemData, itemDataList) {
@ -1599,6 +1613,14 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
data.insert(sharedValue("path"), path); data.insert(sharedValue("path"), path);
} }
if (m_requestRole[DeletionTimeRole]) {
QDateTime deletionTime;
if (item.url().scheme() == QLatin1String("trash")) {
deletionTime = QDateTime::fromString(item.entry().stringValue(KIO::UDSEntry::UDS_EXTRA + 1), Qt::ISODate);
}
data.insert(sharedValue("deletiontime"), deletionTime);
}
if (m_requestRole[IsExpandableRole] && isDir) { if (m_requestRole[IsExpandableRole] && isDir) {
data.insert(sharedValue("isExpandable"), true); data.insert(sharedValue("isExpandable"), true);
} }
@ -1789,6 +1811,17 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
break; break;
} }
case DeletionTimeRole: {
const QDateTime dateTimeA = a->values.value("deletiontime").toDateTime();
const QDateTime dateTimeB = b->values.value("deletiontime").toDateTime();
if (dateTimeA < dateTimeB) {
result = -1;
} else if (dateTimeA > dateTimeB) {
result = +1;
}
break;
}
case RatingRole: { case RatingRole: {
result = a->values.value("rating").toInt() - b->values.value("rating").toInt(); result = a->values.value("rating").toInt() - b->values.value("rating").toInt();
break; break;
@ -1958,7 +1991,7 @@ QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const
return groups; return groups;
} }
QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(KFileItem::FileTimes which) const QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(std::function<QDateTime(const ItemData *)> fileTimeCb) const
{ {
Q_ASSERT(!m_itemData.isEmpty()); Q_ASSERT(!m_itemData.isEmpty());
@ -1974,7 +2007,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(KFileItem::FileTimes
continue; continue;
} }
const QDateTime fileTime = m_itemData.at(i)->item.time(which); const QDateTime fileTime = fileTimeCb(m_itemData.at(i));
const QDate fileDate = fileTime.date(); const QDate fileDate = fileTime.date();
if (fileDate == previousFileDate) { if (fileDate == previousFileDate) {
// The current item is in the same group as the previous item // The current item is in the same group as the previous item
@ -2253,6 +2286,7 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count)
{ "duration", DurationRole, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, { "duration", DurationRole, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true },
{ "track", TrackRole, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, { "track", TrackRole, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true },
{ "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, { "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false },
{ "deletiontime",DeletionTimeRole,I18N_NOOP2_NOSTRIP("@label", "Deletion Time"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false },
{ "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, { "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false },
{ "originUrl", OriginUrlRole, I18N_NOOP2_NOSTRIP("@label", "Downloaded From"), I18N_NOOP2_NOSTRIP("@label", "Other"), true, false }, { "originUrl", OriginUrlRole, I18N_NOOP2_NOSTRIP("@label", "Downloaded From"), I18N_NOOP2_NOSTRIP("@label", "Other"), true, false },
{ "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, { "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false },

View file

@ -30,6 +30,8 @@
#include <QHash> #include <QHash>
#include <QSet> #include <QSet>
#include <functional>
class KFileItemModelDirLister; class KFileItemModelDirLister;
class QTimer; class QTimer;
@ -281,7 +283,7 @@ private:
enum RoleType { enum RoleType {
// User visible roles: // User visible roles:
NoRole, NameRole, SizeRole, ModificationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole, NoRole, NameRole, SizeRole, ModificationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole,
GroupRole, TypeRole, DestinationRole, PathRole, GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole,
// User visible roles available with Baloo: // User visible roles available with Baloo:
CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole, CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
WordCountRole, TitleRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole, WordCountRole, TitleRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
@ -383,7 +385,7 @@ private:
QList<QPair<int, QVariant> > nameRoleGroups() const; QList<QPair<int, QVariant> > nameRoleGroups() const;
QList<QPair<int, QVariant> > sizeRoleGroups() const; QList<QPair<int, QVariant> > sizeRoleGroups() const;
QList<QPair<int, QVariant> > timeRoleGroups(KFileItem::FileTimes which) const; QList<QPair<int, QVariant> > timeRoleGroups(std::function<QDateTime(const ItemData *)> fileTimeCb) const;
QList<QPair<int, QVariant> > permissionRoleGroups() const; QList<QPair<int, QVariant> > permissionRoleGroups() const;
QList<QPair<int, QVariant> > ratingRoleGroups() const; QList<QPair<int, QVariant> > ratingRoleGroups() const;
QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const; QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const;