]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.h
Use sub-menus for the "Sort By"- and "Additional Information"-menu
[dolphin.git] / src / kitemviews / kfileitemmodel.h
index ff816c85ca0e5ce5835b427df9424cc8d6a4fc6b..d48f600dfcf2a0a92a732b72ba6138af1269a06d 100644 (file)
@@ -90,7 +90,7 @@ public:
     virtual bool supportsDropping(int index) const;
 
     /** @reimp */
-    virtual QString roleDescription(const QByteArray& role) const;
+    virtual QString roleDescription(const QByteArray& typeForRole) const;
 
     /** @reimp */
     virtual QList<QPair<int, QVariant> > groups() const;
@@ -139,6 +139,7 @@ public:
     virtual bool setExpanded(int index, bool expanded);
     virtual bool isExpanded(int index) const;
     virtual bool isExpandable(int index) const;
+    virtual int expandedParentsCount(int index) const;
 
     QSet<KUrl> expandedUrls() const;
 
@@ -150,13 +151,21 @@ public:
     void restoreExpandedUrls(const QSet<KUrl>& urls);
 
     /**
-     * Expands all parent-items of each URL given by \a urls.
+     * Expands all parent-items of \a url.
      */
-    void setExpanded(const QSet<KUrl>& urls);
+    void expandParentItems(const KUrl& url);
 
     void setNameFilter(const QString& nameFilter);
     QString nameFilter() const;
 
+    struct RoleInfo
+    {   QByteArray role;
+        QString translation;
+        QString group;
+    };
+
+    static QList<RoleInfo> rolesInformation();
+
 signals:
     /**
      * Is emitted after the loading of a directory has been completed or new
@@ -178,7 +187,7 @@ private slots:
      * and foldersFirst() settings.
      */
     void resortAllItems();
-    
+
     void slotCompleted();
     void slotCanceled();
     void slotNewItems(const KFileItemList& items);
@@ -191,25 +200,18 @@ private slots:
     void dispatchPendingItemsToInsert();
 
 private:
-    enum Role {
-        NoRole,
-        NameRole,
-        SizeRole,
-        DateRole,
-        PermissionsRole,
-        OwnerRole,
-        GroupRole,
-        TypeRole,
-        DestinationRole,
-        PathRole,
-        CommentRole,
-        TagsRole,
-        RatingRole,
-        IsDirRole,
-        IsExpandedRole,
-        IsExpandableRole,
-        ExpansionLevelRole,
-        RolesCount // Mandatory last entry
+    enum RoleType {
+        // User visible roles:
+        NoRole, NameRole, SizeRole, DateRole, PermissionsRole, OwnerRole,
+        GroupRole, TypeRole, DestinationRole, PathRole,
+        // User visible roles available with Nepomuk:
+        CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole,
+        WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
+        CopiedFromRole,
+        // Non-visible roles:
+        IsDirRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
+        // Mandatory last entry:
+        RolesCount
     };
 
     struct ItemData
@@ -218,10 +220,10 @@ private:
         QHash<QByteArray, QVariant> values;
         ItemData* parent;
     };
-    
+
     void insertItems(const KFileItemList& items);
     void removeItems(const KFileItemList& items);
-    
+
     /**
      * Helper method for insertItems() and removeItems(): Creates
      * a list of ItemData elements based on the given items.
@@ -238,19 +240,19 @@ private:
     void resetRoles();
 
     /**
-     * @return Role-index for the given role byte-array.
+     * @return Role-type for the given role.
      *         Runtime complexity is O(1).
      */
-    Role roleIndex(const QByteArray& role) const;
-    
+    RoleType typeForRole(const QByteArray& role) const;
+
     /**
-     * @return Role-byte-array for the given role-index.
+     * @return Role-byte-array for the given role-type.
      *         Runtime complexity is O(1).
      */
-    QByteArray roleByteArray(Role role) const;
+    QByteArray roleForType(RoleType roleType) const;
 
     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.
@@ -258,19 +260,19 @@ private:
     bool lessThan(const ItemData* a, const ItemData* b) const;
 
     /**
-     * Helper method for lessThan() and expansionLevelsCompare(): Compares
+     * 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;
-    
+
     /**
      * 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.
      */
     void sort(QList<ItemData*>::iterator begin, QList<ItemData*>::iterator end);
-    
+
     /** Helper method for sort(). */
     void merge(QList<ItemData*>::iterator begin,
                QList<ItemData*>::iterator pivot,
@@ -280,14 +282,14 @@ private:
     QList<ItemData*>::iterator lowerBound(QList<ItemData*>::iterator begin,
                                           QList<ItemData*>::iterator end,
                                           const ItemData* value);
-    
+
     /** Helper method for sort(). */
     QList<ItemData*>::iterator upperBound(QList<ItemData*>::iterator begin,
                                           QList<ItemData*>::iterator end,
                                           const ItemData* value);
     /** Helper method for sort(). */
     void reverse(QList<ItemData*>::iterator begin, QList<ItemData*>::iterator end);
-    
+
     int stringCompare(const QString& a, const QString& b) const;
 
     /**
@@ -296,10 +298,10 @@ 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 ItemData* a, const ItemData* b) const;
+    int expandedParentsCountCompare(const ItemData* a, const ItemData* b) const;
 
     /**
-     * Helper method for expansionLevelCompare().
+     * Helper method for expandedParentsCountCompare().
      */
     QString subPath(const KFileItem& item,
                     const QString& itemPath,
@@ -313,7 +315,7 @@ private:
     QList<QPair<int, QVariant> > dateRoleGroups() const;
     QList<QPair<int, QVariant> > permissionRoleGroups() const;
     QList<QPair<int, QVariant> > ratingRoleGroups() const;
-    QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& role) const;
+    QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const;
 
     /**
      * Helper method for all xxxRoleGroups() methods to check whether the
@@ -330,16 +332,35 @@ private:
      */
     KFileItemList childItems(const KFileItem& item) const;
 
+    /**
+     * Maps the QByteArray-roles to RoleTypes and provides translation- and
+     * group-contexts.
+     */
+    struct RoleInfoMap
+    {
+        const char* const role;
+        const RoleType roleType;
+        const char* const roleTranslationContext;
+        const char* const roleTranslation;
+        const char* const groupTranslationContext;
+        const char* const groupTranslation;
+    };
+
+    /**
+     * @return Map of user visible roles that are accessible by KFileItemModel::rolesInformation().
+     */
+    static const RoleInfoMap* rolesInfoMap(int& count);
+
 private:
     QWeakPointer<KDirLister> m_dirLister;
 
     bool m_naturalSorting;
     bool m_sortFoldersFirst;
 
-    Role m_sortRole;
+    RoleType m_sortRole;
     QSet<QByteArray> m_roles;
     Qt::CaseSensitivity m_caseSensitivity;
-        
+
     QList<ItemData*> m_itemData;
     QHash<KUrl, int> m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item)
 
@@ -358,19 +379,19 @@ 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 a
+    // the "expandedParentsCount" role in an efficient way. A value < 0 indicates a
     // special meaning:
-    enum RootExpansionLevelTypes
+    enum ExpandedParentsCountRootTypes
     {
-        // m_rootExpansionLevel is uninitialized and must be determined by checking
+        // m_expandedParentsCountRoot 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
+        UninitializedExpandedParentsCountRoot = -1,
+        // All items should be forced to get an expanded parents count 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
+        ForceExpandedParentsCountRoot = -2
     };
-    mutable int m_rootExpansionLevel;
+    mutable int m_expandedParentsCountRoot;
 
     // Stores the URLs of the expanded folders.
     QSet<KUrl> m_expandedUrls;
@@ -384,7 +405,7 @@ private:
 
 inline bool KFileItemModel::isChildItem(int index) const
 {
-    return m_requestRole[ExpansionLevelRole] && m_itemData.at(index)->values.value("expansionLevel").toInt() > 0;
+    return m_requestRole[ExpandedParentsCountRole] && m_itemData.at(index)->values.value("expandedParentsCount").toInt() > 0;
 }
 
 #endif