X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0f853681ab9ccfd2ca53483b490e136ba29cf27d..aba4462e0238d6075e8822d56a78372eacfa7d2e:/src/kitemviews/kfileitemmodelrolesupdater.h diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h index 409f098e8..a03ab513a 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -1,64 +1,41 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * 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 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #ifndef KFILEITEMMODELROLESUPDATER_H #define KFILEITEMMODELROLESUPDATER_H -#include +#include "dolphin_export.h" +#include "kitemviews/kitemmodelbase.h" -#include -#include +#include -#include +#include +#include #include #include #include #include -class KDirWatch; +class KDirectoryContentsCounter; class KFileItemModel; -class KJob; class QPixmap; class QTimer; +class KOverlayIconPlugin; -#ifdef HAVE_NEPOMUK - namespace Nepomuk2 - { - class ResourceWatcher; - class Resource; - namespace Types - { - class Property; - } - } -#else - // Required for the slot applyChangedNepomukRoles() that - // cannot be ifdefined due to moc. - namespace Nepomuk2 +namespace KIO { + class PreviewJob; +} + +#ifdef HAVE_BALOO + namespace Baloo { - class Resource; - namespace Types - { - class Property; - } + class FileMonitor; } + #include #endif /** @@ -100,13 +77,13 @@ class QTimer; * 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); QSize iconSize() const; @@ -166,10 +143,41 @@ public: */ QStringList enabledPlugins() const; -private slots: + /** + * 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); + +private Q_SLOTS: void slotItemsInserted(const KItemRangeList& itemRanges); void slotItemsRemoved(const KItemRangeList& itemRanges); - void slotItemsMoved(const KItemRange& itemRange, QList movedToIndexes); + void slotItemsMoved(const KItemRange& itemRange, const QList &movedToIndexes); void slotItemsChanged(const KItemRangeList& itemRanges, const QSet& roles); void slotSortRoleChanged(const QByteArray& current, @@ -177,12 +185,18 @@ private slots: /** * 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); /** * 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); @@ -190,11 +204,39 @@ private slots: /** * 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 @@ -216,14 +258,10 @@ private slots: */ void resolveRecentlyChangedItems(); - void applyChangedNepomukRoles(const Nepomuk2::Resource& resource, const Nepomuk2::Types::Property& property); + void applyChangedBalooRoles(const QString& file); + void applyChangedBalooRolesForItem(const KFileItem& file); - /** - * 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); + void slotDirectoryContentsCountReceived(const QString& path, int count, long size); private: /** @@ -249,6 +287,24 @@ private: */ void startPreviewJob(); + /** + * Transforms a raw preview image, applying scale and frame. + * + * @param pixmap A raw preview image from a PreviewJob. + * @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. @@ -266,13 +322,8 @@ private: ResolveFast, ResolveAll }; - bool applyResolvedRoles(const KFileItem& item, ResolveHint hint); - QHash rolesData(const KFileItem& item) const; - - /** - * @return The number of items of the path \a path. - */ - int subItemsCount(const QString& path) const; + bool applyResolvedRoles(int index, ResolveHint hint); + QHash rolesData(const KFileItem& item); /** * Must be invoked if a property has been changed that affects @@ -284,6 +335,8 @@ private: QList indexesToResolve() const; + void trimHoverSequenceLoadedItems(); + private: enum State { Idle, @@ -324,6 +377,8 @@ private: QSet m_roles; QSet m_resolvableRoles; QStringList m_enabledPlugins; + qulonglong m_localFileSizePreviewLimit; + bool m_scanDirectories; // Items for which the sort role still has to be determined. QSet m_pendingSortRoleItems; @@ -336,7 +391,15 @@ private: // A new preview job will be started from them once the first one finishes. KFileItemList m_pendingPreviewItems; - KJob* 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 m_hoverSequenceLoadedItems; // When downloading or copying large files, the slot slotItemsChanged() // will be called periodically within a quite short delay. To prevent @@ -349,15 +412,14 @@ private: // Items which have not been changed repeatedly recently. QSet m_changedItems; - KDirWatch* m_dirWatcher; - mutable QSet m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method - // to get all watched directories. -#ifdef HAVE_NEPOMUK - Nepomuk2::ResourceWatcher* m_nepomukResourceWatcher; - mutable QHash m_nepomukUriItems; + KDirectoryContentsCounter* m_directoryContentsCounter; + + QList m_overlayIconsPlugin; + +#ifdef HAVE_BALOO + Baloo::FileMonitor* m_balooFileMonitor; + Baloo::IndexerConfig m_balooConfig; #endif }; #endif - -