#include "dolphin_generalsettings.h"
#include "dolphindebug.h"
#include "private/kfileitemmodelsortalgorithm.h"
+#include "views/draganddrophelper.h"
#include <KDirLister>
#include <KIO/Job>
+#include <KIO/ListJob>
#include <KLocalizedString>
#include <KUrlMimeData>
#include <QRecursiveMutex>
#include <QTimer>
#include <QWidget>
-#include <algorithm>
#include <klazylocalizedstring.h>
Q_GLOBAL_STATIC(QRecursiveMutex, s_collatorMutex)
// for a lot of items within a quite small timeslot. To prevent expensive resortings the
// resorting is postponed until the timer has been exceeded.
m_resortAllItemsTimer = new QTimer(this);
- m_resortAllItemsTimer->setInterval(500);
+ m_resortAllItemsTimer->setInterval(100); // 100 is a middle ground between sorting too frequently which makes the view unreadable
+ // and sorting too infrequently which leads to users seeing an outdated sort order.
m_resortAllItemsTimer->setSingleShot(true);
connect(m_resortAllItemsTimer, &QTimer::timeout, this, &KFileItemModel::resortAllItems);
connect(GeneralSettings::self(), &GeneralSettings::sortingChoiceChanged, this, &KFileItemModel::slotSortingChoiceChanged);
- setShowTrashMime(m_dirLister->showHiddenFiles());
+ setShowTrashMime(m_dirLister->showHiddenFiles() || !GeneralSettings::hideXTrashFile());
}
KFileItemModel::~KFileItemModel()
return m_sortHiddenLast;
}
-void KFileItemModel::setShowTrashMime(bool show)
+void KFileItemModel::setShowTrashMime(bool showTrashMime)
{
const auto trashMime = QStringLiteral("application/x-trash");
QStringList excludeFilter = m_filter.excludeMimeTypes();
- bool wasShown = !excludeFilter.contains(trashMime);
- if (show) {
- if (!wasShown) {
- excludeFilter.removeAll(trashMime);
- }
- } else {
- if (wasShown) {
- excludeFilter.append(trashMime);
- }
+ if (showTrashMime) {
+ excludeFilter.removeAll(trashMime);
+ } else if (!excludeFilter.contains(trashMime)) {
+ excludeFilter.append(trashMime);
}
- if (wasShown != show) {
- setExcludeMimeTypeFilter(excludeFilter);
+ setExcludeMimeTypeFilter(excludeFilter);
+}
+
+void KFileItemModel::scheduleResortAllItems()
+{
+ if (!m_resortAllItemsTimer->isActive()) {
+ m_resortAllItemsTimer->start();
}
}
void KFileItemModel::setShowHiddenFiles(bool show)
{
m_dirLister->setShowHiddenFiles(show);
- setShowTrashMime(show);
+ setShowTrashMime(show || !GeneralSettings::hideXTrashFile());
m_dirLister->emitChanges();
if (show) {
dispatchPendingItemsToInsert();
} else {
item = fileItem(index);
}
- return !item.isNull() && ((item.isDir() && item.isWritable()) || item.isDesktopFile());
+ return !item.isNull() && DragAndDropHelper::supportsDropping(item);
}
QString KFileItemModel::roleDescription(const QByteArray &role) const
// been moved because of the resorting.
QList<QUrl> oldUrls;
oldUrls.reserve(itemCount);
- for (const ItemData *itemData : qAsConst(m_itemData)) {
+ for (const ItemData *itemData : std::as_const(m_itemData)) {
oldUrls.append(itemData->item.url());
}
indexesToRemoveWithChildren.reserve(m_itemData.count());
const int itemCount = m_itemData.count();
- for (int index : qAsConst(indexesToRemove)) {
+ for (int index : std::as_const(indexesToRemove)) {
indexesToRemoveWithChildren.append(index);
const int parentLevel = expandedParentsCount(index);
case DeletionTimeRole:
// These roles can be determined with retrieveData, and they have to be stored
// in the QHash "values" for the sorting.
- for (ItemData *itemData : qAsConst(itemDataList)) {
+ for (ItemData *itemData : std::as_const(itemDataList)) {
if (itemData->values.isEmpty()) {
itemData->values = retrieveData(itemData->item, itemData->parent);
}
case TypeRole:
// At least store the data including the file type for items with known MIME type.
- for (ItemData *itemData : qAsConst(itemDataList)) {
+ for (ItemData *itemData : std::as_const(itemDataList)) {
if (itemData->values.isEmpty()) {
const KFileItem item = itemData->item;
if (item.isDir() || item.isMimeTypeKnown()) {
// Trigger a resorting if necessary. Note that this can happen even if the sort
// role has not changed at all because the file name can be used as a fallback.
- if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) {
+ if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))
+ || (changedRoles.contains("count") && sortRole() == "size")) { // "count" is used in the "size" sort role, so this might require a resorting.
for (const KItemRange &range : itemRanges) {
bool needsResorting = false;
}
if (needsResorting) {
- m_resortAllItemsTimer->start();
+ scheduleResortAllItems();
return;
}
}