#include <libdolphin_export.h>
#include <KFileItemList>
#include <KUrl>
+#include <kitemviews/kfileitemmodelfilter_p.h>
#include <kitemviews/kitemmodelbase.h>
#include <QHash>
*
* 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
{
void setSortFoldersFirst(bool foldersFirst);
bool sortFoldersFirst() const;
+ void setShowHiddenFiles(bool show);
+ bool showHiddenFiles() const;
+
/** @reimp */
virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
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:
RatingRole,
IsDirRole,
IsExpandedRole,
+ IsExpandableRole,
ExpansionLevelRole,
RolesCount // Mandatory last entry
};
{
KFileItem item;
QHash<QByteArray, QVariant> values;
+ ItemData* parent;
};
void insertItems(const KFileItemList& items);
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.
* 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().
*/
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;
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;
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.