]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodelrolesupdater.h
Merge remote-tracking branch 'fork/work/zakharafoniam/useful-groups'
[dolphin.git] / src / kitemviews / kfileitemmodelrolesupdater.h
index b0177b9f8eda1651e3ae8c5e2fe4146999b9d8a0..73e42cf17f2e76eaba9173c0bd3ad5199e2ec8e6 100644 (file)
@@ -12,8 +12,8 @@
 
 #include <list>
 
-#include <KFileItem>
 #include "config-dolphin.h"
+#include <KFileItem>
 
 #include <QObject>
 #include <QSet>
@@ -26,16 +26,17 @@ class QPixmap;
 class QTimer;
 class KOverlayIconPlugin;
 
-namespace KIO {
-    class PreviewJob;
+namespace KIO
+{
+class PreviewJob;
 }
 
 #if HAVE_BALOO
-    namespace Baloo
-    {
-        class FileMonitor;
-    }
-    #include <Baloo/IndexerConfig>
+namespace Baloo
+{
+class FileMonitor;
+}
+#include <Baloo/IndexerConfig>
 #endif
 
 /**
@@ -82,12 +83,15 @@ class DOLPHIN_EXPORT KFileItemModelRolesUpdater : public QObject
     Q_OBJECT
 
 public:
-    explicit KFileItemModelRolesUpdater(KFileItemModel* model, QObject* parent = nullptr);
+    explicit KFileItemModelRolesUpdater(KFileItemModel *model, QObject *parent = nullptr);
     ~KFileItemModelRolesUpdater() override;
 
-    void setIconSize(const QSizesize);
+    void setIconSize(const QSize &size);
     QSize iconSize() const;
 
+    void setDevicePixelRatio(qreal devicePixelRatio);
+    qreal devicePixelRatio() const;
+
     /**
      * Sets the range of items that are visible currently. The roles
      * of visible items are resolved first.
@@ -123,7 +127,7 @@ public:
     /**
      * Sets the roles that should be resolved asynchronously.
      */
-    void setRoles(const QSet<QByteArray>roles);
+    void setRoles(const QSet<QByteArray> &roles);
     QSet<QByteArray> roles() const;
 
     /**
@@ -135,7 +139,7 @@ public:
      *
      * @see enabledPlugins
      */
-    void setEnabledPlugins(const QStringListlist);
+    void setEnabledPlugins(const QStringList &list);
 
     /**
      * Returns the list of enabled thumbnail plugins.
@@ -172,16 +176,17 @@ public:
      *               this method will be called repeatedly with increasing values
      *               for this parameter.
      */
-    void setHoverSequenceState(const QUrl& itemUrl, int seqIdx);
+    void setHoverSequenceState(const QUrl &itemUrl, int seqIdx);
+
+Q_SIGNALS:
+    void previewJobFinished(); // For unit testing
 
 private Q_SLOTS:
-    void slotItemsInserted(const KItemRangeListitemRanges);
-    void slotItemsRemoved(const KItemRangeListitemRanges);
+    void slotItemsInserted(const KItemRangeList &itemRanges);
+    void slotItemsRemoved(const KItemRangeList &itemRanges);
     void slotItemsMoved(KItemRange itemRange, const QList<int> &movedToIndexes);
-    void slotItemsChanged(const KItemRangeList& itemRanges,
-                          const QSet<QByteArray>& roles);
-    void slotSortRoleChanged(const QByteArray& current,
-                             const QByteArray& previous);
+    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.
@@ -190,7 +195,7 @@ private Q_SLOTS:
      *
      * @see startPreviewJob()
      */
-    void slotGotPreview(const KFileItem& item, const QPixmap& pixmap);
+    void slotGotPreview(const KFileItem &item, const QPixmap &pixmap);
 
     /**
      * Is invoked after generating a preview has failed.
@@ -199,7 +204,7 @@ private Q_SLOTS:
      *
      * @see startPreviewJob()
      */
-    void slotPreviewFailed(const KFileItemitem);
+    void slotPreviewFailed(const KFileItem &item);
 
     /**
      * Is invoked when the preview job has been finished. Starts a new preview
@@ -215,12 +220,12 @@ private Q_SLOTS:
     /**
      * Is invoked after a hover sequence preview has been received successfully.
      */
-    void slotHoverSequenceGotPreview(const KFileItem& item, const QPixmap& pixmap);
+    void slotHoverSequenceGotPreview(const KFileItem &item, const QPixmap &pixmap);
 
     /**
      * Is invoked after generating a hover sequence preview has failed.
      */
-    void slotHoverSequencePreviewFailed(const KFileItemitem);
+    void slotHoverSequencePreviewFailed(const KFileItem &item);
 
     /**
      * Is invoked when a hover sequence preview job is finished. May start another
@@ -235,7 +240,7 @@ private Q_SLOTS:
     /**
      * Is invoked when one of the KOverlayIconPlugin emit the signal that an overlay has changed
      */
-    void slotOverlaysChanged(const QUrl& url, const QStringList&);
+    void slotOverlaysChanged(const QUrl &url, const QStringList &);
 
     /**
      * Resolves the sort role of the next item in m_pendingSortRole, applies it
@@ -258,10 +263,10 @@ private Q_SLOTS:
      */
     void resolveRecentlyChangedItems();
 
-    void applyChangedBalooRoles(const QStringfile);
-    void applyChangedBalooRolesForItem(const KFileItemfile);
+    void applyChangedBalooRoles(const QString &file);
+    void applyChangedBalooRolesForItem(const KFileItem &file);
 
-    void slotDirectoryContentsCountReceived(const QString& path, int count, long size);
+    void slotDirectoryContentsCountReceived(const QString &path, int count, long long size);
 
 private:
     /**
@@ -291,9 +296,10 @@ private:
      * Transforms a raw preview image, applying scale and frame.
      *
      * @param pixmap A raw preview image from a PreviewJob.
+     * @param overlays the overlays to add to the pixmap
      * @return The scaled and decorated preview image.
      */
-    QPixmap transformPreviewPixmap(const QPixmappixmap);
+    QPixmap transformPreviewPixmap(const QPixmap &pixmap);
 
     /**
      * Starts a PreviewJob for loading the next hover sequence image.
@@ -313,17 +319,16 @@ private:
 
     /**
      * Resolves the sort role of the item and applies it to the model.
+     * Despite the name, this handles both sorting and grouping, as 
+     * regrouping never happens without resorting at the same time.
      */
     void applySortRole(int index);
 
     void applySortProgressToModel();
 
-    enum ResolveHint {
-        ResolveFast,
-        ResolveAll
-    };
+    enum ResolveHint { ResolveFast, ResolveAll };
     bool applyResolvedRoles(int index, ResolveHint hint);
-    QHash<QByteArray, QVariant> rolesData(const KFileItem& item);
+    QHash<QByteArray, QVariant> rolesData(const KFileItem &item, int index);
 
     /**
      * Must be invoked if a property has been changed that affects
@@ -337,14 +342,18 @@ private:
 
     void trimHoverSequenceLoadedItems();
 
+    void resetSizeData(const int index, const int size = 0);
+
+    void recountDirectoryItems(const QList<QUrl> directories);
+
 private:
-    enum State {
-        Idle,
-        Paused,
-        ResolvingSortRole,
-        ResolvingAllRoles,
-        PreviewJobRunning
-    };
+    QSize cacheSize();
+    /**
+     * enqueue directory size counting for KFileItem item at index
+     */
+    void startDirectorySizeCounting(const KFileItem &item, int index);
+
+    enum State { Idle, Paused, ResolvingSortRole, ResolvingAllRoles, PreviewJobRunning };
 
     State m_state;
 
@@ -369,8 +378,9 @@ private:
     // previews and other expensive roles are determined again.
     QSet<KFileItem> m_finishedItems;
 
-    KFileItemModelm_model;
+    KFileItemModel *m_model;
     QSize m_iconSize;
+    qreal m_devicePixelRatio;
     int m_firstVisibleIndex;
     int m_lastVisibleIndex;
     int m_maximumVisibleItems;
@@ -378,7 +388,6 @@ private:
     QSet<QByteArray> m_resolvableRoles;
     QStringList m_enabledPlugins;
     qulonglong m_localFileSizePreviewLimit;
-    bool m_scanDirectories;
 
     // Items for which the sort role still has to be determined.
     QSet<KFileItem> m_pendingSortRoleItems;
@@ -391,13 +400,13 @@ private:
     // A new preview job will be started from them once the first one finishes.
     KFileItemList m_pendingPreviewItems;
 
-    KIO::PreviewJobm_previewJob;
+    KIO::PreviewJob *m_previewJob;
 
     // Info about the item that the user currently hovers, and the current sequence
     // index for thumb generation.
     KFileItem m_hoverSequenceItem;
     int m_hoverSequenceIndex;
-    KIO::PreviewJobm_hoverSequencePreviewJob;
+    KIO::PreviewJob *m_hoverSequencePreviewJob;
     int m_hoverSequenceNumSuccessiveFailures;
     std::list<KFileItem> m_hoverSequenceLoadedItems;
 
@@ -406,18 +415,18 @@ private:
     // a high CPU-load by generating e.g. previews for each notification, the update
     // will be postponed until no file change has been done within a longer period
     // of time.
-    QTimerm_recentlyChangedItemsTimer;
+    QTimer *m_recentlyChangedItemsTimer;
     QSet<KFileItem> m_recentlyChangedItems;
 
     // Items which have not been changed repeatedly recently.
     QSet<KFileItem> m_changedItems;
 
-    KDirectoryContentsCounterm_directoryContentsCounter;
+    KDirectoryContentsCounter *m_directoryContentsCounter;
 
-    QList<KOverlayIconPlugin*> m_overlayIconsPlugin;
+    QList<KOverlayIconPlugin *> m_overlayIconsPlugin;
 
 #if HAVE_BALOO
-    Baloo::FileMonitorm_balooFileMonitor;
+    Baloo::FileMonitor *m_balooFileMonitor;
     Baloo::IndexerConfig m_balooConfig;
 #endif
 };