X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5f02a3e9cec038aa25aa60a7b1041ec8218155ea..b4e80645e8e39ef7fcc1545136bad06ab3dd5f3e:/src/kitemviews/kfileitemmodel.h diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 07634655c..13554d8c7 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -1,92 +1,119 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * 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 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #ifndef KFILEITEMMODEL_H #define KFILEITEMMODEL_H -#include -#include -#include -#include -#include +#include "dolphin_export.h" +#include "kitemviews/kitemmodelbase.h" +#include "kitemviews/private/kfileitemmodelfilter.h" + +#include +#include +#include #include +#include +#include + +#include class KDirLister; + class QTimer; +namespace KIO +{ +class Job; +} + /** * @brief KItemModelBase implementation for KFileItems. * - * KFileItemModel is connected with one KDirLister. Each time the KDirLister - * emits new items, removes items or changes items the model gets synchronized. - * - * KFileItemModel supports sorting and grouping of items. Additional roles that - * are not part of KFileItem can be added with KFileItemModel::setData(). + * Allows to load items of a directory. Sorting and grouping of + * items are supported. Roles that are not part of KFileItem can + * be added with KFileItemModel::setData(). * - * Also the recursive expansion of sub-directories is supported by + * Recursive expansion of sub-directories is supported by * KFileItemModel::setExpanded(). - * - * TODO: In the longterm instead of passing a KDirLister just an URL should - * be passed and a KDirLister used internally. This solves the following issues: - * - The user of the API does not need to decide whether he listens to KDirLister - * or KFileItemModel. - * - It resolves minor conceptual differences between KDirLister and KFileItemModel. - * E.g. there is no way for KFileItemModel to check whether a completed() signal - * will be emitted after newItems() will be send by KDirLister or not (in the case - * of setShowingDotFiles() no completed() signal will get emitted). */ -class LIBDOLPHINPRIVATE_EXPORT KFileItemModel : public KItemModelBase +class DOLPHIN_EXPORT KFileItemModel : public KItemModelBase { Q_OBJECT public: - explicit KFileItemModel(KDirLister* dirLister, QObject* parent = 0); - virtual ~KFileItemModel(); + explicit KFileItemModel(QObject *parent = nullptr); + ~KFileItemModel() override; - virtual int count() const; - virtual QHash data(int index) const; - virtual bool setData(int index, const QHash& values); + /** + * Loads the directory specified by \a url. The signals + * directoryLoadingStarted(), directoryLoadingProgress() and directoryLoadingCompleted() + * indicate the current state of the loading process. The items + * of the directory are added after the loading has been completed. + */ + void loadDirectory(const QUrl &url); + + /** + * Throws away all currently loaded items and refreshes the directory + * by reloading all items again. + */ + void refreshDirectory(const QUrl &url); + + /** + * @return Parent directory of the items that are shown. In case + * if a directory tree is shown, KFileItemModel::dir() returns + * the root-parent of all items. + * @see rootItem() + */ + QUrl directory() const override; /** - * Sets a separate sorting with folders first (true) or a mixed sorting of files and folders (false). + * Cancels the loading of a directory which has been started by either + * loadDirectory() or refreshDirectory(). */ - void setSortFoldersFirst(bool foldersFirst); - bool sortFoldersFirst() const; + void cancelDirectoryLoading(); + + int count() const override; + QHash data(int index) const override; + bool setData(int index, const QHash &values) override; + + /** + * Sets a separate sorting with directories first (true) or a mixed + * sorting of files and directories (false). + */ + 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; - /** @reimp */ - virtual QMimeData* createMimeData(const QSet& indexes) const; + /** + * If set to true, only directories are shown as items of the model. Files + * are ignored. + */ + void setShowDirectoriesOnly(bool enabled); + bool showDirectoriesOnly() const; + + QMimeData *createMimeData(const KItemSet &indexes) const override; + + int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const override; - /** @reimp */ - virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const; + bool supportsDropping(int index) const override; - /** @reimp */ - virtual bool supportsDropping(int index) const; + bool canEnterOnHover(int index) const override; - /** @reimp */ - virtual QString roleDescription(const QByteArray& role) const; + QString roleDescription(const QByteArray &role) const override; - /** @reimp */ - virtual QList > groups() const; + QList> groups() const override; /** * @return The file-item for the index \a index. If the index is in a valid @@ -100,23 +127,24 @@ public: * URL is found KFileItem::isNull() will be true for the returned * file-item. The runtime complexity of this call is O(1). */ - KFileItem fileItem(const KUrl& url) const; + KFileItem fileItem(const QUrl &url) const; /** * @return The index for the file-item \a item. -1 is returned if no file-item - * is found or if the file-item is null. The runtime + * is found or if the file-item is null. The amortized runtime * complexity of this call is O(1). */ - int index(const KFileItem& item) const; + int index(const KFileItem &item) const; /** * @return The index for the URL \a url. -1 is returned if no file-item - * is found. The runtime complexity of this call is O(1). + * is found. The amortized runtime complexity of this call is O(1). */ - int index(const KUrl& url) const; + int index(const QUrl &url) const; /** - * @return Root item of all items. + * @return Root item of all items representing the item + * for KFileItemModel::dir(). */ KFileItem rootItem() const; @@ -125,32 +153,83 @@ public: */ void clear(); - // TODO: "name" + "isDir" is default in ctor - void setRoles(const QSet& roles); + /** + * Sets the roles that should be shown for each item. + */ + void setRoles(const QSet &roles); QSet roles() const; - virtual bool setExpanded(int index, bool expanded); - virtual bool isExpanded(int index) const; - virtual bool isExpandable(int index) const; + bool setExpanded(int index, bool expanded) override; + bool isExpanded(int index) const override; + bool isExpandable(int index) const override; + int expandedParentsCount(int index) const override; - QSet expandedUrls() const; + QSet expandedDirectories() const; /** - * Marks the URLs in \a urls as subfolders which were expanded previously. - * They are re-expanded one by one each time the KDirLister's completed() signal is received. - * Note that a manual triggering of the KDirLister is required. + * Marks the URLs in \a urls as sub-directories which were expanded previously. + * After calling loadDirectory() or refreshDirectory() the marked sub-directories + * will be expanded step-by-step. */ - void restoreExpandedUrls(const QSet& urls); + void restoreExpandedDirectories(const QSet &urls); /** - * Expands all parent-items of each URL given by \a urls. + * Expands all parent-directories of the item \a url. */ - void setExpanded(const QSet& urls); + void expandParentDirectories(const QUrl &url); - void setNameFilter(const QString& nameFilter); + void setNameFilter(const QString &nameFilter); QString nameFilter() const; -signals: + void setMimeTypeFilters(const QStringList &filters); + QStringList mimeTypeFilters() const; + + void setExcludeMimeTypeFilter(const QStringList &filters); + QStringList excludeMimeTypeFilter() const; + + struct RoleInfo { + QByteArray role; + QString translation; + QString group; + QString tooltip; + bool requiresBaloo; + bool requiresIndexer; + }; + + /** + * @return Provides static information for a role that is supported + * by KFileItemModel. Some roles can only be determined if + * Baloo is enabled and/or the Baloo indexing is enabled. + */ + static RoleInfo roleInformation(const QByteArray &role); + + /** + * @return Provides static information for all available roles that + * are supported by KFileItemModel. Some roles can only be + * determined if Baloo is enabled and/or the Baloo + * indexing is enabled. + */ + static QList rolesInformation(); + + /** + * @return Provides static information for all available grouping + * behaviors supported by KFileItemModel but not directly + * mapped to roles of KFileItemModel. + */ + static QList extraGroupingInformation(); + + /** set to true to hide application/x-trash files */ + void setShowTrashMime(bool show); + +Q_SIGNALS: + /** + * Is emitted if the loading of a directory has been started. It is + * assured that a signal directoryLoadingCompleted() will be send after + * the loading has been finished. For tracking the loading progress + * the signal directoryLoadingProgress() gets emitted in between. + */ + void directoryLoadingStarted(); + /** * Is emitted after the loading of a directory has been completed or new * items have been inserted to an already loaded directory. Usually @@ -158,144 +237,269 @@ signals: * (the only exception is loading an empty directory, where only a * loadingCompleted() signal gets emitted). */ - void loadingCompleted(); + void directoryLoadingCompleted(); + + /** + * Is emitted when the model is being refreshed (F5 key press) + */ + void directoryRefreshing(); + + /** + * Is emitted after the loading of a directory has been canceled. + */ + void directoryLoadingCanceled(); + + /** + * Informs about the progress in percent when loading a directory. It is assured + * that the signal directoryLoadingStarted() has been emitted before. + */ + void directoryLoadingProgress(int percent); + + /** + * Is emitted if the sort-role gets resolved asynchronously and provides + * the progress-information of the sorting in percent. It is assured + * that the last sortProgress-signal contains 100 as value. + */ + void directorySortingProgress(int percent); + + /** + * Is emitted if an information message (e.g. "Connecting to host...") + * should be shown. + */ + void infoMessage(const QString &message); + + /** + * Is emitted if an error message (e.g. "Unknown location") + * should be shown. + */ + void errorMessage(const QString &message, const int kioErrorCode); + + /** + * Is emitted if a redirection from the current URL \a oldUrl + * to the new URL \a newUrl has been done. + */ + void directoryRedirection(const QUrl &oldUrl, const QUrl &newUrl); + + /** + * Is emitted when the URL passed by KFileItemModel::setUrl() represents a file. + * In this case no signal errorMessage() will be emitted. + */ + 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); + + /** + * It is emitted when the parent directory was removed. + */ + void currentDirectoryRemoved(); protected: - virtual void onGroupedSortingChanged(bool current); - virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous); - virtual void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); + void onGroupedSortingChanged(bool current) override; + void onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems = true) override; + void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override; + void onGroupRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems = true) override; + void onGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override; -private slots: +private Q_SLOTS: /** - * Resorts all items dependent on the set sortRole(), sortOrder() - * and foldersFirst() settings. + * Resorts all items dependent on the set sortRole(), sortOrder(), + * groupRole(), groupOrder() and foldersFirst() settings. */ void resortAllItems(); - + void slotCompleted(); void slotCanceled(); - void slotNewItems(const KFileItemList& items); - void slotItemsDeleted(const KFileItemList& items); - void slotRefreshItems(const QList >& items); + void slotItemsAdded(const QUrl &directoryUrl, const KFileItemList &items); + void slotItemsDeleted(const KFileItemList &items); + void slotRefreshItems(const QList> &items); void slotClear(); - void slotClear(const KUrl& url); + void slotSortingChoiceChanged(); + void slotListerError(KIO::Job *job); void dispatchPendingItemsToInsert(); private: - enum Role { + enum RoleType { + // User visible roles: NoRole, NameRole, SizeRole, - DateRole, + ModificationTimeRole, + CreationTimeRole, + AccessTimeRole, PermissionsRole, OwnerRole, GroupRole, TypeRole, + ExtensionRole, DestinationRole, PathRole, + DeletionTimeRole, + // User visible roles available with Baloo: CommentRole, TagsRole, RatingRole, + DimensionsRole, + WidthRole, + HeightRole, + ImageDateTimeRole, + OrientationRole, + PublisherRole, + PageCountRole, + WordCountRole, + TitleRole, + AuthorRole, + LineCountRole, + ArtistRole, + GenreRole, + AlbumRole, + DurationRole, + TrackRole, + ReleaseYearRole, + BitrateRole, + OriginUrlRole, + AspectRatioRole, + FrameRateRole, + // Non-visible roles: IsDirRole, + IsLinkRole, + IsHiddenRole, IsExpandedRole, IsExpandableRole, - ExpansionLevelRole, - RolesCount // Mandatory last entry + ExpandedParentsCountRole, + // Mandatory last entry: + RolesCount }; - struct ItemData - { + struct ItemData { KFileItem item; QHash values; - ItemData* parent; + ItemData *parent; }; - void insertItems(const KFileItemList& items); - void removeItems(const KFileItemList& items); - + struct ItemGroupInfo { + int comparable; + QString text; + + bool operator==(const ItemGroupInfo &other) const; + bool operator!=(const ItemGroupInfo &other) const; + bool operator<(const ItemGroupInfo &other) const; + }; + + enum RemoveItemsBehavior { KeepItemData, DeleteItemData, DeleteItemDataIfUnfiltered }; + + void insertItems(QList &items); + void removeItems(const KItemRangeList &itemRanges, RemoveItemsBehavior behavior); + /** * Helper method for insertItems() and removeItems(): Creates * a list of ItemData elements based on the given items. * Note that the ItemData instances are created dynamically and * must be deleted by the caller. */ - QList createItemDataList(const KFileItemList& items) const; + QList createItemDataList(const QUrl &parentUrl, const KFileItemList &items) const; + + /** + * Helper method for prepareItemsForSorting(). + * For a set role, fills 'values' of ItemData non-lazily. + */ + void prepareItemsWithRole(QList &itemDataList, RoleType roleType); + + /** + * Prepares the items for sorting. Normally, the hash 'values' in ItemData is filled + * lazily to save time and memory, but for some sort roles, it is expected that the + * sort role data is stored in 'values'. + */ + void prepareItemsForSorting(QList &itemDataList); + + static int expandedParentsCount(const ItemData *data); void removeExpandedItems(); + /** + * This function is called by setData() and slotRefreshItems(). It emits + * the itemsChanged() signal, checks if the sort order is still correct, + * and starts m_resortAllItemsTimer if that is not the case. + */ + void emitItemsChangedAndTriggerResorting(const KItemRangeList &itemRanges, const QSet &changedRoles); + /** * Resets all values from m_requestRole to false. */ void resetRoles(); - Role roleIndex(const QByteArray& role) const; + /** + * @return Role-type for the given role. + * Runtime complexity is O(1). + */ + RoleType typeForRole(const QByteArray &role) const; - QHash retrieveData(const KFileItem& item) const; - /** - * @return True if the item-data \a a should be ordered before the item-data - * \b. The item-data may have different parent-items. + * @return Role-byte-array for the given role-type. + * Runtime complexity is O(1). */ - bool lessThan(const ItemData* a, const ItemData* b) const; + QByteArray roleForType(RoleType roleType) const; + + QHash retrieveData(const KFileItem &item, const ItemData *parent) const; /** - * Helper method for lessThan() and expansionLevelsCompare(): Compares - * the passed item-data using m_sortRole as criteria. Both items must - * have the same parent item, otherwise the comparison will be wrong. + * @return True if role values benefit from natural or case insensitive sorting. */ - int sortRoleCompare(const ItemData* a, const ItemData* b) const; - + static bool isRoleValueNatural(const RoleType roleType); + /** - * Sorts the items by using lessThan() as comparison criteria. - * The merge sort algorithm is used to assure a worst-case - * of O(n * log(n)) and to keep the number of comparisons low. + * @return True if \a a has a KFileItem whose text is 'less than' the one + * of \a b according to QString::operator<(const QString&). */ - void sort(QList::iterator begin, QList::iterator end); - - /** Helper method for sort(). */ - void merge(QList::iterator begin, - QList::iterator pivot, - QList::iterator end); - - /** Helper method for sort(). */ - QList::iterator lowerBound(QList::iterator begin, - QList::iterator end, - const ItemData* value); - - /** Helper method for sort(). */ - QList::iterator upperBound(QList::iterator begin, - QList::iterator end, - const ItemData* value); - /** Helper method for sort(). */ - void reverse(QList::iterator begin, QList::iterator end); - - int stringCompare(const QString& a, const QString& b) const; + static bool nameLessThan(const ItemData *a, const ItemData *b); /** - * Compares the expansion level of both items. The "expansion level" is defined - * by the number of parent directories. However simply comparing just the numbers - * is not sufficient, it is also important to check the hierarchy for having - * a correct order like shown in a tree. + * @return True if the item-data \a a should be ordered before the item-data + * \b. The item-data may have different parent-items. */ - int expansionLevelsCompare(const ItemData* a, const ItemData* b) const; + bool lessThan(const ItemData *a, const ItemData *b, const QCollator &collator) const; /** - * Helper method for expansionLevelCompare(). + * Sorts the items between \a begin and \a end using the comparison + * function lessThan(). */ - QString subPath(const KFileItem& item, - const QString& itemPath, - int start, - bool* isDir) const; + void sort(const QList::iterator &begin, const QList::iterator &end) const; - bool useMaximumUpdateInterval() const; + /** + * Helper method for lessThan() and expandedParentsCountCompare(): Compares + * the passed item-data using m_sortRole as criteria. Both items must + * have the same parent item, otherwise the comparison will be wrong. + */ + int sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const; - QList > nameRoleGroups() const; - QList > sizeRoleGroups() const; - QList > dateRoleGroups() const; - QList > permissionRoleGroups() const; - QList > ratingRoleGroups() const; - QList > genericStringRoleGroups(const QByteArray& role) const; + /** + * Helper method for lessThan() and expandedParentsCountCompare(): Compares + * the passed item-data using m_groupRole as criteria. Both items must + * have the same parent item, otherwise the comparison will be wrong. + */ + int groupRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const; + + int stringCompare(const QString &a, const QString &b, const QCollator &collator) const; + + ItemGroupInfo nameRoleGroup(const ItemData *itemData, bool withString = true) const; + ItemGroupInfo sizeRoleGroup(const ItemData *itemData, bool withString = true) const; + ItemGroupInfo timeRoleGroup(const std::function &fileTimeCb, const ItemData *itemData, bool withString = true) const; + ItemGroupInfo permissionRoleGroup(const ItemData *itemData, bool withString = true) const; + ItemGroupInfo ratingRoleGroup(const ItemData *itemData, bool withString = true) const; + ItemGroupInfo typeRoleGroup(const ItemData *itemData) const; + ItemGroupInfo genericStringRoleGroup(const QByteArray &role, const ItemData *itemData) const; + + QList> nameRoleGroups() const; + QList> sizeRoleGroups() const; + QList> timeRoleGroups(const std::function &fileTimeCb) const; + QList> permissionRoleGroups() const; + QList> ratingRoleGroups() const; + QList> typeRoleGroups() const; + QList> genericStringRoleGroups(const QByteArray &typeForRole) const; /** * Helper method for all xxxRoleGroups() methods to check whether the @@ -307,68 +511,156 @@ private: */ bool isChildItem(int index) const; + void scheduleResortAllItems(); + /** - * @return Recursive list of child items that have \a item as upper most parent. + * Is invoked by KFileItemModelRolesUpdater and results in emitting the + * sortProgress signal with a percent-value of the progress. */ - KFileItemList childItems(const KFileItem& item) const; + void emitSortProgress(int resolvedCount); + + /** + * Applies the filters set through @ref setNameFilter and @ref setMimeTypeFilters. + */ + void applyFilters(); + + /** + * Removes filtered items whose expanded parents have been deleted + * or collapsed via setExpanded(parentIndex, false). + */ + void removeFilteredChildren(const KItemRangeList &parents); + + /** + * Loads the selected choice of sorting method from Dolphin General Settings + */ + void loadSortingSettings(); + + /** + * Maps the QByteArray-roles to RoleTypes and provides translation- and + * group-contexts. + */ + struct RoleInfoMap { + const char *const role; + const RoleType roleType; + const KLazyLocalizedString roleTranslation; + const KLazyLocalizedString groupTranslation; + const KLazyLocalizedString tooltipTranslation; + const bool requiresBaloo; + const bool requiresIndexer; + }; + + /** + * @return Map of user visible roles that are accessible by KFileItemModel::rolesInformation(). + */ + static const RoleInfoMap *rolesInfoMap(int &count); + + /** + * Determines the MIME-types of all items that can be done within + * the given timeout. + */ + static void determineMimeTypes(const KFileItemList &items, int timeout); + + /** + * @return Returns a copy of \a value that is implicitly shared + * with other users to save memory. + */ + static QByteArray sharedValue(const QByteArray &value); + + /** + * Checks if the model's internal data structures are consistent. + */ + 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 &parentsToEnsureVisible = QSet()); private: - QWeakPointer m_dirLister; + KDirLister *m_dirLister = nullptr; + QCollator m_collator; bool m_naturalSorting; - bool m_sortFoldersFirst; + bool m_sortDirsFirst; + bool m_sortHiddenLast; + + RoleType m_sortRole; + RoleType m_groupRole; + QByteArray m_sortExtraInfo; + QByteArray m_groupExtraInfo; - Role m_sortRole; + int m_sortingProgressPercent; // Value of directorySortingProgress() signal QSet m_roles; - Qt::CaseSensitivity m_caseSensitivity; - - QList m_itemData; - QHash m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item) + + QList m_itemData; + + // m_items is a cache for the method index(const QUrl&). If it contains N + // entries, it is guaranteed that these correspond to the first N items in + // the model, i.e., that (for every i between 0 and N - 1) + // m_items.value(fileItem(i).url()) == i + mutable QHash m_items; KFileItemModelFilter m_filter; - QSet m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() + QHash m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() bool m_requestRole[RolesCount]; - QTimer* m_minimumUpdateIntervalTimer; - QTimer* m_maximumUpdateIntervalTimer; - QTimer* m_resortAllItemsTimer; - KFileItemList m_pendingItemsToInsert; - bool m_pendingEmitLoadingCompleted; + QTimer *m_maximumUpdateIntervalTimer; + QTimer *m_resortAllItemsTimer; + QList m_pendingItemsToInsert; // Cache for KFileItemModel::groups() - mutable QList > m_groups; - - // Stores the smallest expansion level of the root-URL. Is required to calculate - // the "expansionLevel" role in an efficient way. A value < 0 indicates a - // special meaning: - enum RootExpansionLevelTypes - { - // m_rootExpansionLevel is uninitialized and must be determined by checking - // the root URL from the KDirLister. - UninitializedRootExpansionLevel = -1, - // All items should be forced to get an expansion level of 0 even if they - // represent child items. This is useful for slaves that provide no parent items - // for child items like e.g. the search IO slaves. - ForceRootExpansionLevel = -2 - }; - mutable int m_rootExpansionLevel; + mutable QList> m_groups; - // Stores the URLs of the expanded folders. - QSet m_expandedUrls; + // Stores the URLs (key: target url, value: url) of the expanded directories. + QHash m_expandedDirs; // URLs that must be expanded. The expanding is initially triggered in setExpanded() // and done step after step in slotCompleted(). - QSet m_urlsToExpand; + QSet m_urlsToExpand; + friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method friend class KFileItemModelTest; // For unit testing + friend class KFileItemModelBenchmark; // For unit testing + friend class KFileItemListViewTest; // For unit testing + friend class DolphinPart; // Accesses m_dirLister }; +inline bool KFileItemModel::isRoleValueNatural(RoleType roleType) +{ + return (roleType == TypeRole || roleType == ExtensionRole || 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) +{ + // Split extension, taking into account it can be empty + constexpr QString::SectionFlags flags = QString::SectionSkipEmpty | QString::SectionIncludeLeadingSep; + return a->item.text().section('.', 0, 0, flags) < b->item.text().section('.', 0, 0, flags); +} + inline bool KFileItemModel::isChildItem(int index) const { - return m_requestRole[ExpansionLevelRole] && m_itemData.at(index)->values.value("expansionLevel").toInt() > 0; + if (m_itemData.at(index)->parent) { + return true; + } else { + return false; + } } -#endif +inline bool KFileItemModel::ItemGroupInfo::operator==(const ItemGroupInfo &other) const +{ + return comparable == other.comparable && text == other.text; +} +inline bool KFileItemModel::ItemGroupInfo::operator!=(const ItemGroupInfo &other) const +{ + return comparable != other.comparable || text != other.text; +} +#endif