]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Merge remote-tracking branch 'fork/work/zakharafoniam/useful-groups'
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index 7c4b8ec8f6b7d917553d2879fbf997ce0c246dd1..13554d8c7fa1999dc62e8fd355c71967096ca9e5 100644 (file)
@@ -109,6 +109,8 @@ public:
 
     bool supportsDropping(int index) const override;
 
+    bool canEnterOnHover(int index) const override;
+
     QString roleDescription(const QByteArray &role) const override;
 
     QList<QPair<int, QVariant>> groups() const override;
@@ -182,14 +184,25 @@ public:
     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
@@ -198,6 +211,16 @@ public:
      */
     static QList<RoleInfo> rolesInformation();
 
+    /**
+     * @return Provides static information for all available grouping
+     *         behaviors supported by KFileItemModel but not directly
+     *         mapped to roles of KFileItemModel.
+     */
+    static QList<RoleInfo> 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
@@ -216,6 +239,11 @@ Q_SIGNALS:
      */
     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.
      */
@@ -244,7 +272,7 @@ Q_SIGNALS:
      * Is emitted if an error message (e.g. "Unknown location")
      * should be shown.
      */
-    void errorMessage(const QString &message);
+    void errorMessage(const QString &message, const int kioErrorCode);
 
     /**
      * Is emitted if a redirection from the current URL \a oldUrl
@@ -273,11 +301,13 @@ protected:
     void onGroupedSortingChanged(bool current) override;
     void onSortRoleChanged(const QByteArray &current, const QByteArray &previous, bool resortItems = true) override;
     void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
+    void onGroupRoleChanged(const QByteArray &current, const QByteArray &previous, bool resortItems = true) override;
+    void onGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override;
 
 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();
 
@@ -350,6 +380,15 @@ private:
         QHash<QByteArray, QVariant> values;
         ItemData *parent;
     };
+    
+    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 };
 
@@ -364,6 +403,12 @@ private:
      */
     QList<ItemData *> 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<ItemData *> &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
@@ -431,13 +476,29 @@ private:
      */
     int sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) 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<QDateTime(const ItemData *)> &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<QPair<int, QVariant>> nameRoleGroups() const;
     QList<QPair<int, QVariant>> sizeRoleGroups() 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>> typeRoleGroups() const;
     QList<QPair<int, QVariant>> genericStringRoleGroups(const QByteArray &typeForRole) const;
 
     /**
@@ -450,6 +511,8 @@ private:
      */
     bool isChildItem(int index) const;
 
+    void scheduleResortAllItems();
+
     /**
      * Is invoked by KFileItemModelRolesUpdater and results in emitting the
      * sortProgress signal with a percent-value of the progress.
@@ -481,6 +544,7 @@ private:
         const RoleType roleType;
         const KLazyLocalizedString roleTranslation;
         const KLazyLocalizedString groupTranslation;
+        const KLazyLocalizedString tooltipTranslation;
         const bool requiresBaloo;
         const bool requiresIndexer;
     };
@@ -525,6 +589,10 @@ private:
     bool m_sortHiddenLast;
 
     RoleType m_sortRole;
+    RoleType m_groupRole;
+    QByteArray m_sortExtraInfo;
+    QByteArray m_groupExtraInfo;
+
     int m_sortingProgressPercent; // Value of directorySortingProgress() signal
     QSet<QByteArray> m_roles;
 
@@ -571,7 +639,9 @@ inline bool KFileItemModel::isRoleValueNatural(RoleType roleType)
 
 inline bool KFileItemModel::nameLessThan(const ItemData *a, const ItemData *b)
 {
-    return a->item.text() < b->item.text();
+    // 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
@@ -583,4 +653,14 @@ inline bool KFileItemModel::isChildItem(int index) const
     }
 }
 
+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