-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#ifndef KFILEITEMMODELROLESUPDATER_H
#define KFILEITEMMODELROLESUPDATER_H
-#include <config-baloo.h>
+#include "dolphin_export.h"
+#include "kitemviews/kitemmodelbase.h"
-#include <KFileItem>
-#include <kitemviews/kitemmodelbase.h>
+#include <list>
-#include <libdolphin_export.h>
+#include "config-dolphin.h"
+#include <KFileItem>
#include <QObject>
#include <QSet>
class KDirectoryContentsCounter;
class KFileItemModel;
-class KJob;
class QPixmap;
class QTimer;
+class KOverlayIconPlugin;
-namespace KIO {
- class PreviewJob;
+namespace KIO
+{
+class PreviewJob;
}
-#ifdef HAVE_BALOO
- namespace Baloo
- {
- class FileMonitor;
- }
+#if HAVE_BALOO
+namespace Baloo
+{
+class FileMonitor;
+}
+#include <Baloo/IndexerConfig>
#endif
/**
* 3. Finally, the entire process is repeated for any items that might have
* changed in the mean time.
*/
-class LIBDOLPHINPRIVATE_EXPORT KFileItemModelRolesUpdater : public QObject
+class DOLPHIN_EXPORT KFileItemModelRolesUpdater : public QObject
{
Q_OBJECT
public:
- explicit KFileItemModelRolesUpdater(KFileItemModel* model, QObject* parent = 0);
- virtual ~KFileItemModelRolesUpdater();
+ explicit KFileItemModelRolesUpdater(KFileItemModel *model, QObject *parent = nullptr);
+ ~KFileItemModelRolesUpdater() override;
- void setIconSize(const QSize& size);
+ 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.
/**
* Sets the roles that should be resolved asynchronously.
*/
- void setRoles(const QSet<QByteArray>& roles);
+ void setRoles(const QSet<QByteArray> &roles);
QSet<QByteArray> roles() const;
/**
* Per default all plugins enabled in the KConfigGroup "PreviewSettings"
* are used.
*
- * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
+ * For a list of available plugins, call KIO::PreviewJob::availableThumbnailerPlugins().
*
* @see enabledPlugins
*/
- void setEnabledPlugins(const QStringList& list);
+ void setEnabledPlugins(const QStringList &list);
/**
* Returns the list of enabled thumbnail plugins.
*/
QStringList enabledPlugins() const;
-private slots:
- void slotItemsInserted(const KItemRangeList& itemRanges);
- void slotItemsRemoved(const KItemRangeList& itemRanges);
- void slotItemsMoved(const KItemRange& itemRange, QList<int> movedToIndexes);
- void slotItemsChanged(const KItemRangeList& itemRanges,
- const QSet<QByteArray>& roles);
- void slotSortRoleChanged(const QByteArray& current,
- const QByteArray& previous);
+ /**
+ * Sets the maximum file size of local files for which
+ * previews will be generated (if enabled). A value of 0
+ * indicates no file size limit.
+ * Per default the value from KConfigGroup "PreviewSettings"
+ * MaximumSize is used, 0 otherwise.
+ * @param size
+ */
+ void setLocalFileSizePreviewLimit(qlonglong size);
+ qlonglong localFileSizePreviewLimit() const;
+
+ /**
+ * If set to true, directories contents are scanned to determine their size
+ * Default true
+ */
+ void setScanDirectories(bool enabled);
+ bool scanDirectories() const;
+
+ /**
+ * Notifies the updater of a change in the hover state on an item.
+ *
+ * This will trigger asynchronous loading of the next few thumb sequence images
+ * using a PreviewJob.
+ *
+ * @param item URL of the item that is hovered, or an empty URL if no item is hovered.
+ * @param seqIdx The current hover sequence index. While an item is hovered,
+ * this method will be called repeatedly with increasing values
+ * for this parameter.
+ */
+ void setHoverSequenceState(const QUrl &itemUrl, int seqIdx);
+
+Q_SIGNALS:
+ void previewJobFinished(); // For unit testing
+
+private Q_SLOTS:
+ 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 ¤t, const QByteArray &previous);
/**
* Is invoked after a preview has been received successfully.
+ *
+ * Note that this is not called for hover sequence previews.
+ *
* @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.
+ *
+ * Note that this is not called for hover sequence previews.
+ *
* @see startPreviewJob()
*/
- void slotPreviewFailed(const KFileItem& item);
+ void slotPreviewFailed(const KFileItem &item);
/**
* Is invoked when the preview job has been finished. Starts a new preview
* job if there are any interesting items without previews left, or updates
- * the changed items otherwise. *
+ * the changed items otherwise.
+ *
+ * Note that this is not called for hover sequence previews.
+ *
* @see startPreviewJob()
*/
void slotPreviewJobFinished();
+ /**
+ * Is invoked after a hover sequence preview has been received successfully.
+ */
+ void slotHoverSequenceGotPreview(const KFileItem &item, const QPixmap &pixmap);
+
+ /**
+ * Is invoked after generating a hover sequence preview has failed.
+ */
+ void slotHoverSequencePreviewFailed(const KFileItem &item);
+
+ /**
+ * Is invoked when a hover sequence preview job is finished. May start another
+ * job for the next sequence index right away by calling
+ * \a loadNextHoverSequencePreview().
+ *
+ * Note that a PreviewJob will only ever generate a single sequence image, due
+ * to limitations of the PreviewJob API.
+ */
+ void slotHoverSequencePreviewJobFinished();
+
+ /**
+ * Is invoked when one of the KOverlayIconPlugin emit the signal that an overlay has changed
+ */
+ void slotOverlaysChanged(const QUrl &url, const QStringList &);
+
/**
* Resolves the sort role of the next item in m_pendingSortRole, applies it
* to the model, and invokes itself if there are any pending items left. If
*/
void resolveRecentlyChangedItems();
- void applyChangedBalooRoles(const QString& file);
+ void applyChangedBalooRoles(const QString &file);
+ void applyChangedBalooRolesForItem(const KFileItem &file);
- void slotDirectoryContentsCountReceived(const QString& path, int count);
+ void slotDirectoryContentsCountReceived(const QString &path, int count, long long size);
private:
/**
*/
void startPreviewJob();
+ /**
+ * 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 QPixmap &pixmap);
+
+ /**
+ * Starts a PreviewJob for loading the next hover sequence image.
+ */
+ void loadNextHoverSequencePreview();
+
+ /**
+ * Aborts the currently running hover sequence PreviewJob (if any).
+ */
+ void killHoverSequencePreviewJob();
+
/**
* Ensures that icons, previews, and other roles are determined for any
* items that have been changed.
/**
* 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);
-
- /**
- * @return The number of items of the path \a path.
- */
- int subItemsCount(const QString& path) const;
+ QHash<QByteArray, QVariant> rolesData(const KFileItem &item, int index);
/**
* Must be invoked if a property has been changed that affects
QList<int> indexesToResolve() const;
+ 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;
// previews and other expensive roles are determined again.
QSet<KFileItem> m_finishedItems;
- KFileItemModel* m_model;
+ KFileItemModel *m_model;
QSize m_iconSize;
+ qreal m_devicePixelRatio;
int m_firstVisibleIndex;
int m_lastVisibleIndex;
int m_maximumVisibleItems;
QSet<QByteArray> m_roles;
QSet<QByteArray> m_resolvableRoles;
QStringList m_enabledPlugins;
+ qulonglong m_localFileSizePreviewLimit;
// Items for which the sort role still has to be determined.
QSet<KFileItem> m_pendingSortRoleItems;
// A new preview job will be started from them once the first one finishes.
KFileItemList m_pendingPreviewItems;
- KIO::PreviewJob* m_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::PreviewJob *m_hoverSequencePreviewJob;
+ int m_hoverSequenceNumSuccessiveFailures;
+ std::list<KFileItem> m_hoverSequenceLoadedItems;
// When downloading or copying large files, the slot slotItemsChanged()
// will be called periodically within a quite short delay. To prevent
// 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.
- QTimer* m_recentlyChangedItemsTimer;
+ QTimer *m_recentlyChangedItemsTimer;
QSet<KFileItem> m_recentlyChangedItems;
// Items which have not been changed repeatedly recently.
QSet<KFileItem> m_changedItems;
- KDirectoryContentsCounter* m_directoryContentsCounter;
+ KDirectoryContentsCounter *m_directoryContentsCounter;
-#ifdef HAVE_BALOO
- Baloo::FileMonitor* m_balooFileMonitor;
+ QList<KOverlayIconPlugin *> m_overlayIconsPlugin;
+
+#if HAVE_BALOO
+ Baloo::FileMonitor *m_balooFileMonitor;
+ Baloo::IndexerConfig m_balooConfig;
#endif
};
#endif
-
-