]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodelrolesupdater.h
Merge remote-tracking branch 'origin/KDE/4.9'
[dolphin.git] / src / kitemviews / kfileitemmodelrolesupdater.h
index 47255b03fe3ef08991d58c462f760866da8d8944..68559d8dd7da7844e8f4a795981bd94dcb792d02 100644 (file)
 #define KFILEITEMMODELROLESUPDATER_H
 
 #include <config-nepomuk.h>
-#include <libdolphin_export.h>
 
 #include <KFileItem>
 #include <kitemviews/kitemmodelbase.h>
 
+#include <libdolphin_export.h>
+
 #include <QObject>
 #include <QSet>
 #include <QSize>
 #include <QStringList>
 
+class KDirWatch;
 class KFileItemModel;
 class KJob;
 class QPixmap;
 class QTimer;
 
+#ifdef HAVE_NEPOMUK
+    namespace Nepomuk2
+    {
+        class ResourceWatcher;
+        class Resource;
+    }
+#else
+    // Required for the slot applyChangedNepomukRoles() that
+    // cannot be ifdefined due to moc.
+    namespace Nepomuk2
+    {
+        class Resource;
+    }
+#endif
+
 /**
  * @brief Resolves expensive roles asynchronously and applies them to the KFileItemModel.
  *
@@ -65,8 +82,16 @@ public:
      * of the file. If \a show is false the MIME type icon will be used for the "iconPixmap"
      * role.
      */
-    void setPreviewShown(bool show);
-    bool isPreviewShown() const;
+    void setPreviewsShown(bool show);
+    bool previewsShown() const;
+
+    /**
+     * If enabled a small preview gets upscaled to the icon size in case where
+     * the icon size is larger than the preview. Per default enlarging is
+     * enabled.
+     */
+    void setEnlargeSmallPreviews(bool enlarge);
+    bool enlargeSmallPreviews() const;
 
     /**
      * If \a paused is set to true the asynchronous resolving of roles will be paused.
@@ -104,6 +129,8 @@ private slots:
     void slotItemsRemoved(const KItemRangeList& itemRanges);
     void slotItemsChanged(const KItemRangeList& itemRanges,
                           const QSet<QByteArray>& roles);
+    void slotSortRoleChanged(const QByteArray& current,
+                             const QByteArray& previous);
 
     /**
      * Is invoked after a preview has been received successfully.
@@ -133,6 +160,15 @@ private slots:
      */
     void resolveChangedItems();
 
+    void applyChangedNepomukRoles(const Nepomuk2::Resource& resource);
+
+    /**
+     * Is invoked if a directory watched by KDirWatch got dirty. Updates
+     * the "isExpandable"- and "size"-roles of the item that matches to
+     * the given path.
+     */
+    void slotDirWatchDirty(const QString& path);
+
 private:
     /**
      * Updates the roles for the given item ranges. The roles for the currently
@@ -154,6 +190,22 @@ private:
     void resetPendingRoles();
     void sortAndResolveAllRoles();
     void sortAndResolvePendingRoles();
+    void applySortProgressToModel();
+
+    /**
+     * Updates m_sortProgress to be 0 if the sort-role
+     * needs to get resolved asynchronously and hence a
+     * progress is required. Otherwise m_sortProgress
+     * will be set to -1 which means that no progress
+     * will be provided.
+     */
+    void updateSortProgress();
+
+    /**
+     * @return True, if at least one item from the model
+     *         has an unknown MIME-type.
+     */
+    bool hasUnknownMimeTypes() const;
 
     enum ResolveHint {
         ResolveFast,
@@ -169,6 +221,12 @@ private:
      */
     int subItemsCount(const QString& path) const;
 
+    /**
+     * Must be invoked if a property has been changed that affects
+     * the look of the preview. Takes care to update all previews.
+     */
+    void updateAllPreviews();
+
 private:
     // Property for setPaused()/isPaused().
     bool m_paused;
@@ -179,19 +237,25 @@ private:
     bool m_iconSizeChangedDuringPausing;
     bool m_rolesChangedDuringPausing;
 
-    // Property for setPreviewShown()/previewShown().
+    // Property for setPreviewsShown()/previewsShown().
     bool m_previewShown;
 
+    // Property for setEnlargeSmallPreviews()/enlargeSmallPreviews()
+    bool m_enlargeSmallPreviews;
+
     // True if the role "iconPixmap" should be cleared when resolving the next
     // role with resolveRole(). Is necessary if the preview gets disabled
     // during the roles-updater has been paused by setPaused().
     bool m_clearPreviews;
 
+    int m_sortingProgress;
+
     KFileItemModel* m_model;
     QSize m_iconSize;
     int m_firstVisibleIndex;
     int m_lastVisibleIndex;
     QSet<QByteArray> m_roles;
+    QSet<QByteArray> m_resolvableRoles;
     QStringList m_enabledPlugins;
 
     QSet<KFileItem> m_pendingVisibleItems;
@@ -206,12 +270,13 @@ private:
     QTimer* m_changedItemsTimer;
     QSet<KFileItem> m_changedItems;
 
+    KDirWatch* m_dirWatcher;
+    mutable QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method
+                                         // to get all watched directories.
 #ifdef HAVE_NEPOMUK
-    // True if roles must be resolved with the help of Nepomuk inside
-    // KFileItemModelRolesUpdater::rolesData().
-    bool m_resolveNepomukRoles;
+    Nepomuk2::ResourceWatcher* m_nepomukResourceWatcher;
+    mutable QHash<QUrl, KUrl> m_nepomukUriItems;
 #endif
-
 };
 
 #endif