]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Introduce "isExpandable" role
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index a049f6766efa713629a9e10c6b5f4c382de0a70f..07634655ca4d409976e2799426106150091af1f2 100644 (file)
@@ -23,6 +23,7 @@
 #include <libdolphin_export.h>
 #include <KFileItemList>
 #include <KUrl>
+#include <kitemviews/kfileitemmodelfilter_p.h>
 #include <kitemviews/kitemmodelbase.h>
 
 #include <QHash>
@@ -41,6 +42,15 @@ class QTimer;
  *
  * Also the 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
 {
@@ -60,6 +70,9 @@ public:
     void setSortFoldersFirst(bool foldersFirst);
     bool sortFoldersFirst() const;
 
+    void setShowHiddenFiles(bool show);
+    bool showHiddenFiles() const;
+
     /** @reimp */
     virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
 
@@ -116,17 +129,35 @@ public:
     void setRoles(const QSet<QByteArray>& roles);
     QSet<QByteArray> roles() const;
 
-    bool setExpanded(int index, bool expanded);
-    bool isExpanded(int index) const;
-    bool isExpandable(int index) const;
+    virtual bool setExpanded(int index, bool expanded);
+    virtual bool isExpanded(int index) const;
+    virtual bool isExpandable(int index) const;
+
     QSet<KUrl> expandedUrls() 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.
+     */
+    void restoreExpandedUrls(const QSet<KUrl>& urls);
+
     /**
      * Expands all parent-items of each URL given by \a urls.
      */
     void setExpanded(const QSet<KUrl>& urls);
 
+    void setNameFilter(const QString& nameFilter);
+    QString nameFilter() const;
+
 signals:
+    /**
+     * Is emitted after the loading of a directory has been completed or new
+     * items have been inserted to an already loaded directory. Usually
+     * one or more itemsInserted() signals are emitted before loadingCompleted()
+     * (the only exception is loading an empty directory, where only a
+     * loadingCompleted() signal gets emitted).
+     */
     void loadingCompleted();
 
 protected:
@@ -168,6 +199,7 @@ private:
         RatingRole,
         IsDirRole,
         IsExpandedRole,
+        IsExpandableRole,
         ExpansionLevelRole,
         RolesCount // Mandatory last entry
     };
@@ -176,6 +208,7 @@ private:
     {
         KFileItem item;
         QHash<QByteArray, QVariant> values;
+        ItemData* parent;
     };
     
     void insertItems(const KFileItemList& items);
@@ -200,7 +233,18 @@ private:
 
     QHash<QByteArray, QVariant> 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.
+     */
     bool lessThan(const ItemData* a, const ItemData* b) 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.
+     */
+    int sortRoleCompare(const ItemData* a, const ItemData* b) const;
     
     /**
      * Sorts the items by using lessThan() as comparison criteria.
@@ -234,7 +278,7 @@ private:
      * is not sufficient, it is also important to check the hierarchy for having
      * a correct order like shown in a tree.
      */
-    int expansionLevelsCompare(const KFileItem& a, const KFileItem& b) const;
+    int expansionLevelsCompare(const ItemData* a, const ItemData* b) const;
 
     /**
      * Helper method for expansionLevelCompare().
@@ -263,6 +307,11 @@ private:
      */
     bool isChildItem(int index) const;
 
+    /**
+     * @return Recursive list of child items that have \a item as upper most parent.
+     */
+    KFileItemList childItems(const KFileItem& item) const;
+
 private:
     QWeakPointer<KDirLister> m_dirLister;
 
@@ -276,6 +325,9 @@ private:
     QList<ItemData*> m_itemData;
     QHash<KUrl, int> m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item)
 
+    KFileItemModelFilter m_filter;
+    QSet<KFileItem> m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter()
+
     bool m_requestRole[RolesCount];
 
     QTimer* m_minimumUpdateIntervalTimer;
@@ -288,8 +340,18 @@ private:
     mutable QList<QPair<int, QVariant> > 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 that
-    // it has not been initialized yet.
+    // 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;
 
     // Stores the URLs of the expanded folders.