-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#ifndef KFILEITEMMODEL_H
#define KFILEITEMMODEL_H
#include "dolphin_export.h"
+#include "kitemviews/kitemmodelbase.h"
+#include "kitemviews/private/kfileitemmodelfilter.h"
+
#include <KFileItem>
-#include <QUrl>
-#include <kitemviews/kitemmodelbase.h>
-#include <kitemviews/private/kfileitemmodelfilter.h>
+#include <KLazyLocalizedString>
#include <QCollator>
#include <QHash>
#include <QSet>
+#include <QUrl>
#include <functional>
-class KFileItemModelDirLister;
+class KDirLister;
+
class QTimer;
+namespace KIO {
+ class Job;
+}
+
/**
* @brief KItemModelBase implementation for KFileItems.
*
void setSortDirectoriesFirst(bool dirsFirst);
bool sortDirectoriesFirst() const;
+ /**
+ * Sets a separate sorting with hidden files and folders last (true) or not (false).
+ */
+ void setSortHiddenLast(bool hiddenLast);
+ bool sortHiddenLast() const;
+
void setShowHiddenFiles(bool show);
bool showHiddenFiles() const;
*/
static QList<RoleInfo> rolesInformation();
-signals:
+Q_SIGNALS:
/**
* Is emitted if the loading of a directory has been started. It is
* assured that a signal directoryLoadingCompleted() will be send after
*/
void urlIsFileError(const QUrl& url);
+ /**
+ * It is emitted for files when they change and
+ * for dirs when files are added or removed.
+ */
+ void fileItemsChanged(const KFileItemList &changedFileItems);
+
protected:
void onGroupedSortingChanged(bool current) override;
- void onSortRoleChanged(const QByteArray& current, const QByteArray& previous) override;
+ void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true) override;
void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
-private slots:
+private Q_SLOTS:
/**
* Resorts all items dependent on the set sortRole(), sortOrder()
* and foldersFirst() settings.
void slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items);
void slotClear();
void slotSortingChoiceChanged();
+ void slotListerError(KIO::Job *job);
void dispatchPendingItemsToInsert();
NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole,
GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole,
// User visible roles available with Baloo:
- CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
+ CommentRole, TagsRole, RatingRole, DimensionsRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole,
WordCountRole, TitleRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole,
- BitrateRole, OriginUrlRole,
+ BitrateRole, OriginUrlRole, AspectRatioRole, FrameRateRole,
// Non-visible roles:
IsDirRole, IsLinkRole, IsHiddenRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
// Mandatory last entry:
enum RemoveItemsBehavior {
KeepItemData,
- DeleteItemData
+ DeleteItemData,
+ DeleteItemDataIfUnfiltered
};
void insertItems(QList<ItemData*>& items);
QHash<QByteArray, QVariant> retrieveData(const KFileItem& item, const ItemData* parent) const;
+ /**
+ * @return True if role values benefit from natural or case insensitive sorting.
+ */
+ static bool isRoleValueNatural(const RoleType roleType);
+
/**
* @return True if \a a has a KFileItem whose text is 'less than' the one
* of \a b according to QString::operator<(const QString&).
* Sorts the items between \a begin and \a end using the comparison
* function lessThan().
*/
- void sort(QList<ItemData*>::iterator begin, QList<ItemData*>::iterator end) const;
+ void sort(const QList<ItemData*>::iterator &begin, const QList<ItemData*>::iterator &end) const;
/**
* Helper method for lessThan() and expandedParentsCountCompare(): Compares
int stringCompare(const QString& a, const QString& b, const QCollator& collator) const;
- bool useMaximumUpdateInterval() const;
-
QList<QPair<int, QVariant> > nameRoleGroups() const;
QList<QPair<int, QVariant> > sizeRoleGroups() const;
- QList<QPair<int, QVariant> > timeRoleGroups(std::function<QDateTime(const ItemData *)> fileTimeCb) const;
+ QList<QPair<int, QVariant> > timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const;
QList<QPair<int, QVariant> > permissionRoleGroups() const;
QList<QPair<int, QVariant> > ratingRoleGroups() const;
QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const;
{
const char* const role;
const RoleType roleType;
- const char* const roleTranslationContext;
- const char* const roleTranslation;
- const char* const groupTranslationContext;
- const char* const groupTranslation;
+ const KLazyLocalizedString roleTranslation;
+ const KLazyLocalizedString groupTranslation;
const bool requiresBaloo;
const bool requiresIndexer;
};
*/
bool isConsistent() const;
+ /**
+ * Filters out the expanded folders that don't pass the filter themselves and don't have any filter-passing children.
+ * Will update the removedItemRanges arguments to include the parents that have been filtered.
+ * @returns the number of parents that have been filtered.
+ * @param removedItemRanges The ranges of items being deleted/filtered, will get updated
+ * @param parentsToEnsureVisible Parents that must be visible no matter what due to being ancestors of newly visible items
+ */
+ int filterChildlessParents(KItemRangeList &removedItemRanges, const QSet<ItemData *> &parentsToEnsureVisible = QSet<ItemData *>());
+
private:
- KFileItemModelDirLister* m_dirLister;
+ KDirLister *m_dirLister = nullptr;
QCollator m_collator;
bool m_naturalSorting;
bool m_sortDirsFirst;
+ bool m_sortHiddenLast;
RoleType m_sortRole;
int m_sortingProgressPercent; // Value of directorySortingProgress() signal
// and done step after step in slotCompleted().
QSet<QUrl> m_urlsToExpand;
- friend class KFileItemModelLessThan; // Accesses lessThan() method
friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method
friend class KFileItemModelTest; // For unit testing
friend class KFileItemModelBenchmark; // For unit testing
friend class DolphinPart; // Accesses m_dirLister
};
+inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
+{
+ return (roleType == TypeRole ||
+ roleType == TagsRole ||
+ roleType == CommentRole ||
+ roleType == TitleRole ||
+ roleType == ArtistRole ||
+ roleType == GenreRole ||
+ roleType == AlbumRole ||
+ roleType == PathRole ||
+ roleType == DestinationRole ||
+ roleType == OriginUrlRole ||
+ roleType == OwnerRole ||
+ roleType == GroupRole);
+}
+
inline bool KFileItemModel::nameLessThan(const ItemData* a, const ItemData* b)
{
return a->item.text() < b->item.text();
}
-
inline bool KFileItemModel::isChildItem(int index) const
{
if (m_itemData.at(index)->parent) {