X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0429e5330e09f7a379f0a70372c262faeda2c5a6..50149d6abb8a0a978db3c6afb5238bc42a4a89c8:/src/kitemviews/kfileitemmodel.cpp diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index da15ccbdd..ef80b4edb 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -34,6 +34,7 @@ KFileItemModel::KFileItemModel(QObject* parent) : KItemModelBase("text", parent), m_dirLister(nullptr), m_sortDirsFirst(true), + m_sortHiddenLast(true), m_sortRole(NameRole), m_sortingProgressPercent(-1), m_roles(), @@ -212,6 +213,19 @@ bool KFileItemModel::sortDirectoriesFirst() const return m_sortDirsFirst; } +void KFileItemModel::setSortHiddenLast(bool hiddenLast) +{ + if (hiddenLast != m_sortHiddenLast) { + m_sortHiddenLast = hiddenLast; + resortAllItems(); + } +} + +bool KFileItemModel::sortHiddenLast() const +{ + return m_sortHiddenLast; +} + void KFileItemModel::setShowHiddenFiles(bool show) { m_dirLister->setShowingDotFiles(show); @@ -1015,6 +1029,8 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis // emitted during the maximum update interval. m_maximumUpdateIntervalTimer->start(); } + + Q_EMIT fileItemsChanged({KFileItem(directoryUrl)}); } void KFileItemModel::slotItemsDeleted(const KFileItemList& items) @@ -1023,6 +1039,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) QVector indexesToRemove; indexesToRemove.reserve(items.count()); + KFileItemList dirsChanged; for (const KFileItem& item : items) { const int indexForItem = index(item); @@ -1036,6 +1053,11 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) m_filteredItems.erase(it); } } + + QUrl parentUrl = item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); + if (dirsChanged.findByUrl(parentUrl).isNull()) { + dirsChanged << KFileItem(parentUrl); + } } std::sort(indexesToRemove.begin(), indexesToRemove.end()); @@ -1063,6 +1085,8 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) const KItemRangeList itemRanges = KItemRangeList::fromSortedContainer(indexesToRemove); removeFilteredChildren(itemRanges); removeItems(itemRanges, DeleteItemData); + + Q_EMIT fileItemsChanged(dirsChanged); } void KFileItemModel::slotRefreshItems(const QList >& items) @@ -1077,6 +1101,7 @@ void KFileItemModel::slotRefreshItems(const QList >& indexes.reserve(items.count()); QSet changedRoles; + KFileItemList changedFiles; QListIterator > it(items); while (it.hasNext()) { @@ -1102,6 +1127,7 @@ void KFileItemModel::slotRefreshItems(const QList >& m_items.remove(oldItem.url()); m_items.insert(newItem.url(), indexForItem); + changedFiles.append(newItem); indexes.append(indexForItem); } else { // Check if 'oldItem' is one of the filtered items. @@ -1130,6 +1156,8 @@ void KFileItemModel::slotRefreshItems(const QList >& std::sort(indexes.begin(), indexes.end()); const KItemRangeList itemRangeList = KItemRangeList::fromSortedContainer(indexes); emitItemsChangedAndTriggerResorting(itemRangeList, changedRoles); + + Q_EMIT fileItemsChanged(changedFiles); } void KFileItemModel::slotClear() @@ -1719,6 +1747,17 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla } } + // Show hidden files and folders last + if (m_sortHiddenLast) { + const bool isHiddenA = a->item.isHidden(); + const bool isHiddenB = b->item.isHidden(); + if (isHiddenA && !isHiddenB) { + return false; + } else if (!isHiddenA && isHiddenB) { + return true; + } + } + if (m_sortDirsFirst || (DetailsModeSettings::directorySizeCount() && m_sortRole == SizeRole)) { const bool isDirA = a->item.isDir(); const bool isDirB = b->item.isDir(); @@ -1775,17 +1814,25 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const auto valueB = b->values.value("count"); if (valueA.isNull()) { if (valueB.isNull()) { - return 0; + result = 0; + break; } else { - return -1; + result = -1; + break; } } else if (valueB.isNull()) { - return +1; + result = +1; + break; } else { if (valueA.toLongLong() < valueB.toLongLong()) { - return -1; + result = -1; + break; + } else if (valueA.toLongLong() > valueB.toLongLong()) { + result = +1; + break; } else { - return +1; + result = 0; + break; } } } @@ -2003,16 +2050,24 @@ QList > KFileItemModel::sizeRoleGroups() const } const KFileItem& item = m_itemData.at(i)->item; - const KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; + KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; QString newGroupValue; if (!item.isNull() && item.isDir()) { - newGroupValue = i18nc("@title:group Size", "Folders"); - } else if (fileSize < 5 * 1024 * 1024) { - newGroupValue = i18nc("@title:group Size", "Small"); - } else if (fileSize < 10 * 1024 * 1024) { - newGroupValue = i18nc("@title:group Size", "Medium"); - } else { - newGroupValue = i18nc("@title:group Size", "Big"); + if (DetailsModeSettings::directorySizeCount() || m_sortDirsFirst) { + newGroupValue = i18nc("@title:group Size", "Folders"); + } else { + fileSize = m_itemData.at(i)->values.value("size").toULongLong(); + } + } + + if (newGroupValue.isEmpty()) { + if (fileSize < 5 * 1024 * 1024) { // < 5 MB + newGroupValue = i18nc("@title:group Size", "Small"); + } else if (fileSize < 10 * 1024 * 1024) { // < 10 MB + newGroupValue = i18nc("@title:group Size", "Medium"); + } else { + newGroupValue = i18nc("@title:group Size", "Big"); + } } if (newGroupValue != groupValue) { @@ -2090,7 +2145,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< if (daysDistance == 1) { const KLocalizedString format = ki18nc("@title:group Date: " "MMMM is full month name in current locale, and yyyy is " - "full year number", "'Yesterday' (MMMM, yyyy)"); + "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Yesterday' (MMMM, yyyy)"); const QString translatedFormat = format.toString(); if (translatedFormat.count(QLatin1Char('\'')) == 2) { newGroupValue = fileTime.toString(translatedFormat); @@ -2105,7 +2160,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< } else if (daysDistance <= 7) { newGroupValue = fileTime.toString(i18nc("@title:group Date: " "The week day name: dddd, MMMM is full month name " - "in current locale, and yyyy is full year number", + "in current locale, and yyyy is full year number.", "dddd (MMMM, yyyy)")); newGroupValue = i18nc("Can be used to script translation of " "\"dddd (MMMM, yyyy)\" with context @title:group Date", @@ -2113,7 +2168,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< } else if (daysDistance <= 7 * 2) { const KLocalizedString format = ki18nc("@title:group Date: " "MMMM is full month name in current locale, and yyyy is " - "full year number", "'One Week Ago' (MMMM, yyyy)"); + "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'One Week Ago' (MMMM, yyyy)"); const QString translatedFormat = format.toString(); if (translatedFormat.count(QLatin1Char('\'')) == 2) { newGroupValue = fileTime.toString(translatedFormat); @@ -2128,7 +2183,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< } else if (daysDistance <= 7 * 3) { const KLocalizedString format = ki18nc("@title:group Date: " "MMMM is full month name in current locale, and yyyy is " - "full year number", "'Two Weeks Ago' (MMMM, yyyy)"); + "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Two Weeks Ago' (MMMM, yyyy)"); const QString translatedFormat = format.toString(); if (translatedFormat.count(QLatin1Char('\'')) == 2) { newGroupValue = fileTime.toString(translatedFormat); @@ -2143,7 +2198,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< } else if (daysDistance <= 7 * 4) { const KLocalizedString format = ki18nc("@title:group Date: " "MMMM is full month name in current locale, and yyyy is " - "full year number", "'Three Weeks Ago' (MMMM, yyyy)"); + "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Three Weeks Ago' (MMMM, yyyy)"); const QString translatedFormat = format.toString(); if (translatedFormat.count(QLatin1Char('\'')) == 2) { newGroupValue = fileTime.toString(translatedFormat); @@ -2158,7 +2213,7 @@ QList > KFileItemModel::timeRoleGroups(const std::function< } else { const KLocalizedString format = ki18nc("@title:group Date: " "MMMM is full month name in current locale, and yyyy is " - "full year number", "'Earlier on' MMMM, yyyy"); + "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Earlier on' MMMM, yyyy"); const QString translatedFormat = format.toString(); if (translatedFormat.count(QLatin1Char('\'')) == 2) { newGroupValue = fileTime.toString(translatedFormat);