2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "kfileitemmodelrolesupdater.h"
9 #include "dolphindebug.h"
10 #include "kfileitemmodel.h"
11 #include "private/kdirectorycontentscounter.h"
12 #include "private/kpixmapmodifier.h"
15 #include <KConfigGroup>
16 #include <KIO/PreviewJob>
17 #include <KIconLoader>
18 #include <KJobWidgets>
19 #include <KOverlayIconPlugin>
20 #include <KPluginMetaData>
21 #include <KSharedConfig>
24 #include "private/kbaloorolesprovider.h"
26 #include <Baloo/FileMonitor>
29 #include <QApplication>
30 #include <QElapsedTimer>
33 #include <QPluginLoader>
37 using namespace std::chrono_literals
;
39 // #define KFILEITEMMODELROLESUPDATER_DEBUG
43 // Maximum time in ms that the KFileItemModelRolesUpdater
44 // may perform a blocking operation
45 const int MaxBlockTimeout
= 200;
47 // If the number of items is smaller than ResolveAllItemsLimit,
48 // the roles of all items will be resolved.
49 const int ResolveAllItemsLimit
= 500;
51 // Not only the visible area, but up to ReadAheadPages before and after
52 // this area will be resolved.
53 const int ReadAheadPages
= 5;
56 KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel
*model
, QObject
*parent
)
59 , m_previewChangedDuringPausing(false)
60 , m_iconSizeChangedDuringPausing(false)
61 , m_rolesChangedDuringPausing(false)
62 , m_previewShown(false)
63 , m_enlargeSmallPreviews(true)
64 , m_clearPreviews(false)
68 , m_firstVisibleIndex(0)
69 , m_lastVisibleIndex(-1)
70 , m_maximumVisibleItems(50)
74 , m_localFileSizePreviewLimit(0)
75 , m_scanDirectories(true)
76 , m_pendingSortRoleItems()
78 , m_pendingPreviewItems()
80 , m_hoverSequenceItem()
81 , m_hoverSequenceIndex(0)
82 , m_hoverSequencePreviewJob(nullptr)
83 , m_hoverSequenceNumSuccessiveFailures(0)
84 , m_recentlyChangedItemsTimer(nullptr)
85 , m_recentlyChangedItems()
87 , m_directoryContentsCounter(nullptr)
89 , m_balooFileMonitor(nullptr)
94 const KConfigGroup
globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
95 m_enabledPlugins
= globalConfig
.readEntry("Plugins", KIO::PreviewJob::defaultPlugins());
96 m_localFileSizePreviewLimit
= static_cast<qulonglong
>(globalConfig
.readEntry("MaximumSize", 0));
98 connect(m_model
, &KFileItemModel::itemsInserted
, this, &KFileItemModelRolesUpdater::slotItemsInserted
);
99 connect(m_model
, &KFileItemModel::itemsRemoved
, this, &KFileItemModelRolesUpdater::slotItemsRemoved
);
100 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
101 connect(m_model
, &KFileItemModel::itemsMoved
, this, &KFileItemModelRolesUpdater::slotItemsMoved
);
102 connect(m_model
, &KFileItemModel::sortRoleChanged
, this, &KFileItemModelRolesUpdater::slotSortRoleChanged
);
104 // Use a timer to prevent that each call of slotItemsChanged() results in a synchronous
105 // resolving of the roles. Postpone the resolving until no update has been done for 100 ms.
106 m_recentlyChangedItemsTimer
= new QTimer(this);
107 m_recentlyChangedItemsTimer
->setInterval(100ms
);
108 m_recentlyChangedItemsTimer
->setSingleShot(true);
109 connect(m_recentlyChangedItemsTimer
, &QTimer::timeout
, this, &KFileItemModelRolesUpdater::resolveRecentlyChangedItems
);
111 m_resolvableRoles
.insert("size");
112 m_resolvableRoles
.insert("type");
113 m_resolvableRoles
.insert("isExpandable");
115 m_resolvableRoles
+= KBalooRolesProvider::instance().roles();
118 m_directoryContentsCounter
= new KDirectoryContentsCounter(m_model
, this);
119 connect(m_directoryContentsCounter
, &KDirectoryContentsCounter::result
, this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived
);
121 const QString pluginNamespace
= QStringLiteral("kf" QT_STRINGIFY(QT_MAJOR_VERSION
)) + QStringLiteral("/overlayicon");
122 const auto plugins
= KPluginMetaData::findPlugins(pluginNamespace
, {}, KPluginMetaData::AllowEmptyMetaData
);
123 for (const KPluginMetaData
&data
: plugins
) {
124 auto instance
= QPluginLoader(data
.fileName()).instance();
125 auto plugin
= qobject_cast
<KOverlayIconPlugin
*>(instance
);
127 m_overlayIconsPlugin
.append(plugin
);
128 connect(plugin
, &KOverlayIconPlugin::overlaysChanged
, this, &KFileItemModelRolesUpdater::slotOverlaysChanged
);
130 // not our/valid plugin, so delete the created object
136 KFileItemModelRolesUpdater::~KFileItemModelRolesUpdater()
141 void KFileItemModelRolesUpdater::setIconSize(const QSize
&size
)
143 if (size
!= m_iconSize
) {
145 if (m_state
== Paused
) {
146 m_iconSizeChangedDuringPausing
= true;
147 } else if (m_previewShown
) {
148 // An icon size change requires the regenerating of
150 m_finishedItems
.clear();
156 QSize
KFileItemModelRolesUpdater::iconSize() const
161 void KFileItemModelRolesUpdater::setVisibleIndexRange(int index
, int count
)
170 if (index
== m_firstVisibleIndex
&& count
== m_lastVisibleIndex
- m_firstVisibleIndex
+ 1) {
171 // The range has not been changed
175 m_firstVisibleIndex
= index
;
176 m_lastVisibleIndex
= qMin(index
+ count
- 1, m_model
->count() - 1);
181 void KFileItemModelRolesUpdater::setMaximumVisibleItems(int count
)
183 m_maximumVisibleItems
= count
;
186 void KFileItemModelRolesUpdater::setPreviewsShown(bool show
)
188 if (show
== m_previewShown
) {
192 m_previewShown
= show
;
194 m_clearPreviews
= true;
200 bool KFileItemModelRolesUpdater::previewsShown() const
202 return m_previewShown
;
205 void KFileItemModelRolesUpdater::setEnlargeSmallPreviews(bool enlarge
)
207 if (enlarge
!= m_enlargeSmallPreviews
) {
208 m_enlargeSmallPreviews
= enlarge
;
209 if (m_previewShown
) {
215 bool KFileItemModelRolesUpdater::enlargeSmallPreviews() const
217 return m_enlargeSmallPreviews
;
220 void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList
&list
)
222 if (m_enabledPlugins
!= list
) {
223 m_enabledPlugins
= list
;
224 if (m_previewShown
) {
230 void KFileItemModelRolesUpdater::setPaused(bool paused
)
232 if (paused
== (m_state
== Paused
)) {
240 const bool updatePreviews
= (m_iconSizeChangedDuringPausing
&& m_previewShown
) || m_previewChangedDuringPausing
;
241 const bool resolveAll
= updatePreviews
|| m_rolesChangedDuringPausing
;
243 m_finishedItems
.clear();
246 m_iconSizeChangedDuringPausing
= false;
247 m_previewChangedDuringPausing
= false;
248 m_rolesChangedDuringPausing
= false;
250 if (!m_pendingSortRoleItems
.isEmpty()) {
251 m_state
= ResolvingSortRole
;
252 resolveNextSortRole();
261 void KFileItemModelRolesUpdater::setRoles(const QSet
<QByteArray
> &roles
)
263 if (m_roles
!= roles
) {
267 // Check whether there is at least one role that must be resolved
268 // with the help of Baloo. If this is the case, a (quite expensive)
269 // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
270 // the role gets watched for changes.
271 const KBalooRolesProvider
&rolesProvider
= KBalooRolesProvider::instance();
272 bool hasBalooRole
= false;
273 QSetIterator
<QByteArray
> it(roles
);
274 while (it
.hasNext()) {
275 const QByteArray
&role
= it
.next();
276 if (rolesProvider
.roles().contains(role
)) {
282 if (hasBalooRole
&& m_balooConfig
.fileIndexingEnabled() && !m_balooFileMonitor
) {
283 m_balooFileMonitor
= new Baloo::FileMonitor(this);
284 connect(m_balooFileMonitor
, &Baloo::FileMonitor::fileMetaDataChanged
, this, &KFileItemModelRolesUpdater::applyChangedBalooRoles
);
285 } else if (!hasBalooRole
&& m_balooFileMonitor
) {
286 delete m_balooFileMonitor
;
287 m_balooFileMonitor
= nullptr;
291 if (m_state
== Paused
) {
292 m_rolesChangedDuringPausing
= true;
299 QSet
<QByteArray
> KFileItemModelRolesUpdater::roles() const
304 bool KFileItemModelRolesUpdater::isPaused() const
306 return m_state
== Paused
;
309 QStringList
KFileItemModelRolesUpdater::enabledPlugins() const
311 return m_enabledPlugins
;
314 void KFileItemModelRolesUpdater::setLocalFileSizePreviewLimit(const qlonglong size
)
316 m_localFileSizePreviewLimit
= size
;
319 qlonglong
KFileItemModelRolesUpdater::localFileSizePreviewLimit() const
321 return m_localFileSizePreviewLimit
;
324 void KFileItemModelRolesUpdater::setScanDirectories(bool enabled
)
326 m_scanDirectories
= enabled
;
329 bool KFileItemModelRolesUpdater::scanDirectories() const
331 return m_scanDirectories
;
334 void KFileItemModelRolesUpdater::setHoverSequenceState(const QUrl
&itemUrl
, int seqIdx
)
336 const KFileItem item
= m_model
->fileItem(itemUrl
);
338 if (item
!= m_hoverSequenceItem
) {
339 killHoverSequencePreviewJob();
342 m_hoverSequenceItem
= item
;
343 m_hoverSequenceIndex
= seqIdx
;
345 if (!m_previewShown
) {
349 m_hoverSequenceNumSuccessiveFailures
= 0;
351 loadNextHoverSequencePreview();
354 void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList
&itemRanges
)
359 // Determine the sort role synchronously for as many items as possible.
360 if (m_resolvableRoles
.contains(m_model
->sortRole())) {
361 int insertedCount
= 0;
362 for (const KItemRange
&range
: itemRanges
) {
363 const int lastIndex
= insertedCount
+ range
.index
+ range
.count
- 1;
364 for (int i
= insertedCount
+ range
.index
; i
<= lastIndex
; ++i
) {
365 if (timer
.elapsed() < MaxBlockTimeout
) {
368 m_pendingSortRoleItems
.insert(m_model
->fileItem(i
));
371 insertedCount
+= range
.count
;
374 applySortProgressToModel();
376 // If there are still items whose sort role is unknown, check if the
377 // asynchronous determination of the sort role is already in progress,
378 // and start it if that is not the case.
379 if (!m_pendingSortRoleItems
.isEmpty() && m_state
!= ResolvingSortRole
) {
381 m_state
= ResolvingSortRole
;
382 resolveNextSortRole();
389 void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList
&itemRanges
)
393 const bool allItemsRemoved
= (m_model
->count() == 0);
396 if (m_balooFileMonitor
) {
397 // Don't let the FileWatcher watch for removed items
398 if (allItemsRemoved
) {
399 m_balooFileMonitor
->clear();
401 QStringList newFileList
;
402 const QStringList oldFileList
= m_balooFileMonitor
->files();
403 for (const QString
&file
: oldFileList
) {
404 if (m_model
->index(QUrl::fromLocalFile(file
)) >= 0) {
405 newFileList
.append(file
);
408 m_balooFileMonitor
->setFiles(newFileList
);
413 if (allItemsRemoved
) {
416 m_finishedItems
.clear();
417 m_pendingSortRoleItems
.clear();
418 m_pendingIndexes
.clear();
419 m_pendingPreviewItems
.clear();
420 m_recentlyChangedItems
.clear();
421 m_recentlyChangedItemsTimer
->stop();
422 m_changedItems
.clear();
423 m_hoverSequenceLoadedItems
.clear();
427 if (m_scanDirectories
) {
428 m_directoryContentsCounter
->stopWorker();
431 // Only remove the items from m_finishedItems. They will be removed
432 // from the other sets later on.
433 QSet
<KFileItem
>::iterator it
= m_finishedItems
.begin();
434 while (it
!= m_finishedItems
.end()) {
435 if (m_model
->index(*it
) < 0) {
436 it
= m_finishedItems
.erase(it
);
442 // Removed items won't have hover previews loaded anymore.
443 for (const KItemRange
&itemRange
: itemRanges
) {
444 int index
= itemRange
.index
;
445 for (int count
= itemRange
.count
; count
> 0; --count
) {
446 const KFileItem item
= m_model
->fileItem(index
);
447 m_hoverSequenceLoadedItems
.remove(item
);
452 // The visible items might have changed.
457 void KFileItemModelRolesUpdater::slotItemsMoved(KItemRange itemRange
, const QList
<int> &movedToIndexes
)
460 Q_UNUSED(movedToIndexes
)
462 // The visible items might have changed.
466 void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList
&itemRanges
, const QSet
<QByteArray
> &roles
)
470 // Find out if slotItemsChanged() has been done recently. If that is the
471 // case, resolving the roles is postponed until a timer has exceeded
472 // to prevent expensive repeated updates if files are updated frequently.
473 const bool itemsChangedRecently
= m_recentlyChangedItemsTimer
->isActive();
475 QSet
<KFileItem
> &targetSet
= itemsChangedRecently
? m_recentlyChangedItems
: m_changedItems
;
477 for (const KItemRange
&itemRange
: itemRanges
) {
478 int index
= itemRange
.index
;
479 for (int count
= itemRange
.count
; count
> 0; --count
) {
480 const KFileItem item
= m_model
->fileItem(index
);
481 targetSet
.insert(item
);
486 m_recentlyChangedItemsTimer
->start();
488 if (!itemsChangedRecently
) {
489 updateChangedItems();
493 void KFileItemModelRolesUpdater::slotSortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
)
498 if (m_resolvableRoles
.contains(current
)) {
499 m_pendingSortRoleItems
.clear();
500 m_finishedItems
.clear();
502 const int count
= m_model
->count();
506 // Determine the sort role synchronously for as many items as possible.
507 for (int index
= 0; index
< count
; ++index
) {
508 if (timer
.elapsed() < MaxBlockTimeout
) {
509 applySortRole(index
);
511 m_pendingSortRoleItems
.insert(m_model
->fileItem(index
));
515 applySortProgressToModel();
517 if (!m_pendingSortRoleItems
.isEmpty()) {
518 // Trigger the asynchronous determination of the sort role.
520 m_state
= ResolvingSortRole
;
521 resolveNextSortRole();
525 m_pendingSortRoleItems
.clear();
526 applySortProgressToModel();
530 void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem
&item
, const QPixmap
&pixmap
)
532 if (m_state
!= PreviewJobRunning
) {
536 m_changedItems
.remove(item
);
538 const int index
= m_model
->index(item
);
543 QPixmap scaledPixmap
= transformPreviewPixmap(pixmap
);
545 QHash
<QByteArray
, QVariant
> data
= rolesData(item
, index
);
547 const QStringList overlays
= data
["iconOverlays"].toStringList();
548 // Strangely KFileItem::overlays() returns empty string-values, so
549 // we need to check first whether an overlay must be drawn at all.
550 // It is more efficient to do it here, as KIconLoader::drawOverlays()
551 // assumes that an overlay will be drawn and has some additional
553 if (!scaledPixmap
.isNull()) {
554 for (const QString
&overlay
: overlays
) {
555 if (!overlay
.isEmpty()) {
556 // There is at least one overlay, draw all overlays above m_pixmap
557 // and cancel the check
558 KIconLoader::global()->drawOverlays(overlays
, scaledPixmap
, KIconLoader::Desktop
);
564 data
.insert("iconPixmap", scaledPixmap
);
566 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
567 m_model
->setData(index
, data
);
568 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
570 m_finishedItems
.insert(item
);
573 void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem
&item
)
575 if (m_state
!= PreviewJobRunning
) {
579 m_changedItems
.remove(item
);
581 const int index
= m_model
->index(item
);
583 QHash
<QByteArray
, QVariant
> data
;
584 data
.insert("iconPixmap", QPixmap());
586 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
587 m_model
->setData(index
, data
);
588 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
590 applyResolvedRoles(index
, ResolveAll
);
591 m_finishedItems
.insert(item
);
595 void KFileItemModelRolesUpdater::slotPreviewJobFinished()
597 m_previewJob
= nullptr;
599 if (m_state
!= PreviewJobRunning
) {
605 if (!m_pendingPreviewItems
.isEmpty()) {
608 if (!m_changedItems
.isEmpty()) {
609 updateChangedItems();
614 void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem
&item
, const QPixmap
&pixmap
)
616 const int index
= m_model
->index(item
);
621 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
622 QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
623 const int loadedIndex
= pixmaps
.size();
625 float wap
= m_hoverSequencePreviewJob
->sequenceIndexWraparoundPoint();
626 if (!m_hoverSequencePreviewJob
->handlesSequences()) {
630 data
["hoverSequenceWraparoundPoint"] = wap
;
631 m_model
->setData(index
, data
);
634 // For hover sequence previews we never load index 0, because that's just the regular preview
635 // in "iconPixmap". But that means we'll load index 1 even for thumbnailers that don't support
636 // sequences, in which case we can just throw away the preview because it's the same as for
637 // index 0. Unfortunately we can't find it out earlier :(
638 if (wap
< 0.0f
|| loadedIndex
< static_cast<int>(wap
)) {
639 // Add the preview to the model data
641 const QPixmap scaledPixmap
= transformPreviewPixmap(pixmap
);
643 pixmaps
.append(scaledPixmap
);
644 data
["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps
);
646 m_model
->setData(index
, data
);
648 const auto loadedIt
= std::find(m_hoverSequenceLoadedItems
.begin(), m_hoverSequenceLoadedItems
.end(), item
);
649 if (loadedIt
== m_hoverSequenceLoadedItems
.end()) {
650 m_hoverSequenceLoadedItems
.push_back(item
);
651 trimHoverSequenceLoadedItems();
655 m_hoverSequenceNumSuccessiveFailures
= 0;
658 void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem
&item
)
660 const int index
= m_model
->index(item
);
665 static const int numRetries
= 2;
667 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
668 QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
670 qCDebug(DolphinDebug
).nospace() << "Failed to generate hover sequence preview #" << pixmaps
.size() << " for file " << item
.url().toString() << " (attempt "
671 << (m_hoverSequenceNumSuccessiveFailures
+ 1) << "/" << (numRetries
+ 1) << ")";
673 if (m_hoverSequenceNumSuccessiveFailures
>= numRetries
) {
674 // Give up and simply duplicate the previous sequence image (if any)
676 pixmaps
.append(pixmaps
.empty() ? QPixmap() : pixmaps
.last());
677 data
["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps
);
679 if (!data
.contains("hoverSequenceWraparoundPoint")) {
680 // hoverSequenceWraparoundPoint is only available when PreviewJob succeeds, so unless
681 // it has previously succeeded, it's best to assume that it just doesn't handle
682 // sequences instead of trying to load the next image indefinitely.
683 data
["hoverSequenceWraparoundPoint"] = 1.0f
;
686 m_model
->setData(index
, data
);
688 m_hoverSequenceNumSuccessiveFailures
= 0;
692 m_hoverSequenceNumSuccessiveFailures
++;
695 // Next image in the sequence (or same one if the retry limit wasn't reached yet) will be
696 // loaded automatically, because slotHoverSequencePreviewJobFinished() will be triggered
697 // even when PreviewJob fails.
700 void KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished()
702 const int index
= m_model
->index(m_hoverSequenceItem
);
704 m_hoverSequencePreviewJob
= nullptr;
708 // Since a PreviewJob can only have one associated sequence index, we can only generate
709 // one sequence image per job, so we have to start another one for the next index.
711 // Load the next image in the sequence
712 m_hoverSequencePreviewJob
= nullptr;
713 loadNextHoverSequencePreview();
716 void KFileItemModelRolesUpdater::resolveNextSortRole()
718 if (m_state
!= ResolvingSortRole
) {
722 QSet
<KFileItem
>::iterator it
= m_pendingSortRoleItems
.begin();
723 while (it
!= m_pendingSortRoleItems
.end()) {
724 const KFileItem item
= *it
;
725 const int index
= m_model
->index(item
);
727 // Continue if the sort role has already been determined for the
728 // item, and the item has not been changed recently.
729 if (!m_changedItems
.contains(item
) && m_model
->data(index
).contains(m_model
->sortRole())) {
730 it
= m_pendingSortRoleItems
.erase(it
);
734 applySortRole(index
);
735 m_pendingSortRoleItems
.erase(it
);
739 if (!m_pendingSortRoleItems
.isEmpty()) {
740 applySortProgressToModel();
741 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole
);
745 // Prevent that we try to update the items twice.
746 disconnect(m_model
, &KFileItemModel::itemsMoved
, this, &KFileItemModelRolesUpdater::slotItemsMoved
);
747 applySortProgressToModel();
748 connect(m_model
, &KFileItemModel::itemsMoved
, this, &KFileItemModelRolesUpdater::slotItemsMoved
);
753 void KFileItemModelRolesUpdater::resolveNextPendingRoles()
755 if (m_state
!= ResolvingAllRoles
) {
759 while (!m_pendingIndexes
.isEmpty()) {
760 const int index
= m_pendingIndexes
.takeFirst();
761 const KFileItem item
= m_model
->fileItem(index
);
763 if (m_finishedItems
.contains(item
)) {
767 applyResolvedRoles(index
, ResolveAll
);
768 m_finishedItems
.insert(item
);
769 m_changedItems
.remove(item
);
773 if (!m_pendingIndexes
.isEmpty()) {
774 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
778 if (m_clearPreviews
) {
779 // Only go through the list if there are items which might still have previews.
780 if (m_finishedItems
.count() != m_model
->count()) {
781 QHash
<QByteArray
, QVariant
> data
;
782 data
.insert("iconPixmap", QPixmap());
783 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>()));
785 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
786 for (int index
= 0; index
<= m_model
->count(); ++index
) {
787 if (m_model
->data(index
).contains("iconPixmap") || m_model
->data(index
).contains("hoverSequencePixmaps")) {
788 m_model
->setData(index
, data
);
791 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
793 m_clearPreviews
= false;
796 if (!m_changedItems
.isEmpty()) {
797 updateChangedItems();
802 void KFileItemModelRolesUpdater::resolveRecentlyChangedItems()
804 m_changedItems
+= m_recentlyChangedItems
;
805 m_recentlyChangedItems
.clear();
806 updateChangedItems();
809 void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString
&file
)
812 const KFileItem item
= m_model
->fileItem(QUrl::fromLocalFile(file
));
815 // itemUrl is not in the model anymore, probably because
816 // the corresponding file has been deleted in the meantime.
819 applyChangedBalooRolesForItem(item
);
825 void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem
&item
)
828 Baloo::File
file(item
.localPath());
831 const KBalooRolesProvider
&rolesProvider
= KBalooRolesProvider::instance();
832 QHash
<QByteArray
, QVariant
> data
;
834 const auto roles
= rolesProvider
.roles();
835 for (const QByteArray
&role
: roles
) {
836 // Overwrite all the role values with an empty QVariant, because the roles
837 // provider doesn't overwrite it when the property value list is empty.
839 data
.insert(role
, QVariant());
842 QHashIterator
<QByteArray
, QVariant
> it(rolesProvider
.roleValues(file
, m_roles
));
843 while (it
.hasNext()) {
845 data
.insert(it
.key(), it
.value());
848 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
849 const int index
= m_model
->index(item
);
850 m_model
->setData(index
, data
);
851 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
859 void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString
&path
, int count
, long size
)
861 const bool getSizeRole
= m_roles
.contains("size");
862 const bool getIsExpandableRole
= m_roles
.contains("isExpandable");
864 if (getSizeRole
|| getIsExpandableRole
) {
865 const int index
= m_model
->index(QUrl::fromLocalFile(path
));
867 QHash
<QByteArray
, QVariant
> data
;
870 data
.insert("count", count
);
871 data
.insert("size", QVariant::fromValue(size
));
873 if (getIsExpandableRole
) {
874 data
.insert("isExpandable", count
> 0);
877 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
878 m_model
->setData(index
, data
);
879 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
884 void KFileItemModelRolesUpdater::startUpdating()
886 if (m_state
== Paused
) {
890 if (m_finishedItems
.count() == m_model
->count()) {
891 // All roles have been resolved already.
896 // Terminate all updates that are currently active.
898 m_pendingIndexes
.clear();
903 // Determine the icons for the visible items synchronously.
904 updateVisibleIcons();
906 // A detailed update of the items in and near the visible area
907 // only makes sense if sorting is finished.
908 if (m_state
== ResolvingSortRole
) {
912 // Start the preview job or the asynchronous resolving of all roles.
913 QList
<int> indexes
= indexesToResolve();
915 if (m_previewShown
) {
916 m_pendingPreviewItems
.clear();
917 m_pendingPreviewItems
.reserve(indexes
.count());
919 for (int index
: qAsConst(indexes
)) {
920 const KFileItem item
= m_model
->fileItem(index
);
921 if (!m_finishedItems
.contains(item
)) {
922 m_pendingPreviewItems
.append(item
);
928 m_pendingIndexes
= indexes
;
929 // Trigger the asynchronous resolving of all roles.
930 m_state
= ResolvingAllRoles
;
931 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
935 void KFileItemModelRolesUpdater::updateVisibleIcons()
937 int lastVisibleIndex
= m_lastVisibleIndex
;
938 if (lastVisibleIndex
<= 0) {
939 // Guess a reasonable value for the last visible index if the view
940 // has not told us about the real value yet.
941 lastVisibleIndex
= qMin(m_firstVisibleIndex
+ m_maximumVisibleItems
, m_model
->count() - 1);
942 if (lastVisibleIndex
<= 0) {
943 lastVisibleIndex
= qMin(200, m_model
->count() - 1);
950 // Try to determine the final icons for all visible items.
952 for (index
= m_firstVisibleIndex
; index
<= lastVisibleIndex
&& timer
.elapsed() < MaxBlockTimeout
; ++index
) {
953 applyResolvedRoles(index
, ResolveFast
);
956 // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load
957 // preliminary icons (i.e., without mime type determination) for the
961 void KFileItemModelRolesUpdater::startPreviewJob()
963 m_state
= PreviewJobRunning
;
965 if (m_pendingPreviewItems
.isEmpty()) {
966 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
970 // PreviewJob internally caches items always with the size of
971 // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
972 // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
973 // do a downscaling anyhow because of the frame, so in this case only the provided
974 // cache sizes are requested.
975 const QSize cacheSize
= (m_iconSize
.width() > 128) || (m_iconSize
.height() > 128) ? QSize(256, 256) : QSize(128, 128);
977 // KIO::filePreview() will request the MIME-type of all passed items, which (in the
978 // worst case) might block the application for several seconds. To prevent such
979 // a blocking, we only pass items with known mime type to the preview job.
980 const int count
= m_pendingPreviewItems
.count();
981 KFileItemList itemSubSet
;
982 itemSubSet
.reserve(count
);
984 if (m_pendingPreviewItems
.first().isMimeTypeKnown()) {
985 // Some mime types are known already, probably because they were
986 // determined when loading the icons for the visible items. Start
987 // a preview job for all items at the beginning of the list which
988 // have a known mime type.
990 itemSubSet
.append(m_pendingPreviewItems
.takeFirst());
991 } while (!m_pendingPreviewItems
.isEmpty() && m_pendingPreviewItems
.first().isMimeTypeKnown());
993 // Determine mime types for MaxBlockTimeout ms, and start a preview
994 // job for the corresponding items.
999 const KFileItem item
= m_pendingPreviewItems
.takeFirst();
1000 item
.determineMimeType();
1001 itemSubSet
.append(item
);
1002 } while (!m_pendingPreviewItems
.isEmpty() && timer
.elapsed() < MaxBlockTimeout
);
1005 KIO::PreviewJob
*job
= new KIO::PreviewJob(itemSubSet
, cacheSize
, &m_enabledPlugins
);
1007 job
->setIgnoreMaximumSize(itemSubSet
.first().isLocalFile() && !itemSubSet
.first().isSlow() && m_localFileSizePreviewLimit
<= 0);
1008 if (job
->uiDelegate()) {
1009 KJobWidgets::setWindow(job
, qApp
->activeWindow());
1012 connect(job
, &KIO::PreviewJob::gotPreview
, this, &KFileItemModelRolesUpdater::slotGotPreview
);
1013 connect(job
, &KIO::PreviewJob::failed
, this, &KFileItemModelRolesUpdater::slotPreviewFailed
);
1014 connect(job
, &KIO::PreviewJob::finished
, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
1019 QPixmap
KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap
&pixmap
)
1021 QPixmap scaledPixmap
= pixmap
;
1023 if (!pixmap
.hasAlpha() && !pixmap
.isNull() && m_iconSize
.width() > KIconLoader::SizeSmallMedium
&& m_iconSize
.height() > KIconLoader::SizeSmallMedium
) {
1024 if (m_enlargeSmallPreviews
) {
1025 KPixmapModifier::applyFrame(scaledPixmap
, m_iconSize
);
1027 // Assure that small previews don't get enlarged. Instead they
1028 // should be shown centered within the frame.
1029 const QSize contentSize
= KPixmapModifier::sizeInsideFrame(m_iconSize
);
1030 const bool enlargingRequired
= scaledPixmap
.width() < contentSize
.width() && scaledPixmap
.height() < contentSize
.height();
1031 if (enlargingRequired
) {
1032 QSize frameSize
= scaledPixmap
.size() / scaledPixmap
.devicePixelRatio();
1033 frameSize
.scale(m_iconSize
, Qt::KeepAspectRatio
);
1035 QPixmap
largeFrame(frameSize
);
1036 largeFrame
.fill(Qt::transparent
);
1038 KPixmapModifier::applyFrame(largeFrame
, frameSize
);
1040 QPainter
painter(&largeFrame
);
1041 painter
.drawPixmap((largeFrame
.width() - scaledPixmap
.width() / scaledPixmap
.devicePixelRatio()) / 2,
1042 (largeFrame
.height() - scaledPixmap
.height() / scaledPixmap
.devicePixelRatio()) / 2,
1044 scaledPixmap
= largeFrame
;
1046 // The image must be shrunk as it is too large to fit into
1047 // the available icon size
1048 KPixmapModifier::applyFrame(scaledPixmap
, m_iconSize
);
1051 } else if (!pixmap
.isNull()) {
1052 KPixmapModifier::scale(scaledPixmap
, m_iconSize
* qApp
->devicePixelRatio());
1053 scaledPixmap
.setDevicePixelRatio(qApp
->devicePixelRatio());
1056 return scaledPixmap
;
1059 void KFileItemModelRolesUpdater::loadNextHoverSequencePreview()
1061 if (m_hoverSequenceItem
.isNull() || m_hoverSequencePreviewJob
) {
1065 const int index
= m_model
->index(m_hoverSequenceItem
);
1070 // We generate the next few sequence indices in advance (buffering)
1071 const int maxSeqIdx
= m_hoverSequenceIndex
+ 5;
1073 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1075 if (!data
.contains("hoverSequencePixmaps")) {
1076 // The pixmap at index 0 isn't used ("iconPixmap" will be used instead)
1077 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>() << QPixmap()));
1078 m_model
->setData(index
, data
);
1081 const QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
1083 const int loadSeqIdx
= pixmaps
.size();
1086 if (data
.contains("hoverSequenceWraparoundPoint")) {
1087 wap
= data
["hoverSequenceWraparoundPoint"].toFloat();
1089 if (wap
>= 1.0f
&& loadSeqIdx
>= static_cast<int>(wap
)) {
1090 // Reached the wraparound point -> no more previews to load.
1094 if (loadSeqIdx
> maxSeqIdx
) {
1095 // Wait until setHoverSequenceState() is called with a higher sequence index.
1099 // PreviewJob internally caches items always with the size of
1100 // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
1101 // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
1102 // do a downscaling anyhow because of the frame, so in this case only the provided
1103 // cache sizes are requested.
1104 const QSize cacheSize
= (m_iconSize
.width() > 128) || (m_iconSize
.height() > 128) ? QSize(256, 256) : QSize(128, 128);
1106 KIO::PreviewJob
*job
= new KIO::PreviewJob({m_hoverSequenceItem
}, cacheSize
, &m_enabledPlugins
);
1108 job
->setSequenceIndex(loadSeqIdx
);
1109 job
->setIgnoreMaximumSize(m_hoverSequenceItem
.isLocalFile() && !m_hoverSequenceItem
.isSlow() && m_localFileSizePreviewLimit
<= 0);
1110 if (job
->uiDelegate()) {
1111 KJobWidgets::setWindow(job
, qApp
->activeWindow());
1114 connect(job
, &KIO::PreviewJob::gotPreview
, this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview
);
1115 connect(job
, &KIO::PreviewJob::failed
, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed
);
1116 connect(job
, &KIO::PreviewJob::finished
, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished
);
1118 m_hoverSequencePreviewJob
= job
;
1121 void KFileItemModelRolesUpdater::killHoverSequencePreviewJob()
1123 if (m_hoverSequencePreviewJob
) {
1124 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::gotPreview
, this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview
);
1125 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::failed
, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed
);
1126 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::finished
, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished
);
1127 m_hoverSequencePreviewJob
->kill();
1128 m_hoverSequencePreviewJob
= nullptr;
1132 void KFileItemModelRolesUpdater::updateChangedItems()
1134 if (m_state
== Paused
) {
1138 if (m_changedItems
.isEmpty()) {
1142 m_finishedItems
-= m_changedItems
;
1144 if (m_resolvableRoles
.contains(m_model
->sortRole())) {
1145 m_pendingSortRoleItems
+= m_changedItems
;
1147 if (m_state
!= ResolvingSortRole
) {
1148 // Stop the preview job if necessary, and trigger the
1149 // asynchronous determination of the sort role.
1151 m_state
= ResolvingSortRole
;
1152 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole
);
1158 QList
<int> visibleChangedIndexes
;
1159 QList
<int> invisibleChangedIndexes
;
1160 visibleChangedIndexes
.reserve(m_changedItems
.size());
1161 invisibleChangedIndexes
.reserve(m_changedItems
.size());
1163 auto changedItemsIt
= m_changedItems
.begin();
1164 while (changedItemsIt
!= m_changedItems
.end()) {
1165 const auto &item
= *changedItemsIt
;
1166 const int index
= m_model
->index(item
);
1169 changedItemsIt
= m_changedItems
.erase(changedItemsIt
);
1174 if (index
>= m_firstVisibleIndex
&& index
<= m_lastVisibleIndex
) {
1175 visibleChangedIndexes
.append(index
);
1177 invisibleChangedIndexes
.append(index
);
1181 std::sort(visibleChangedIndexes
.begin(), visibleChangedIndexes
.end());
1183 if (m_previewShown
) {
1184 for (int index
: qAsConst(visibleChangedIndexes
)) {
1185 m_pendingPreviewItems
.append(m_model
->fileItem(index
));
1188 for (int index
: qAsConst(invisibleChangedIndexes
)) {
1189 m_pendingPreviewItems
.append(m_model
->fileItem(index
));
1192 if (!m_previewJob
) {
1196 const bool resolvingInProgress
= !m_pendingIndexes
.isEmpty();
1197 m_pendingIndexes
= visibleChangedIndexes
+ m_pendingIndexes
+ invisibleChangedIndexes
;
1198 if (!resolvingInProgress
) {
1199 // Trigger the asynchronous resolving of the changed roles.
1200 m_state
= ResolvingAllRoles
;
1201 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
1206 void KFileItemModelRolesUpdater::applySortRole(int index
)
1208 QHash
<QByteArray
, QVariant
> data
;
1209 const KFileItem item
= m_model
->fileItem(index
);
1211 if (m_model
->sortRole() == "type") {
1212 if (!item
.isMimeTypeKnown()) {
1213 item
.determineMimeType();
1216 data
.insert("type", item
.mimeComment());
1217 } else if (m_model
->sortRole() == "size" && item
.isLocalFile() && item
.isDir()) {
1218 startDirectorySizeCounting(item
, index
);
1221 // Probably the sort role is a baloo role - just determine all roles.
1222 data
= rolesData(item
, index
);
1225 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1226 m_model
->setData(index
, data
);
1227 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1230 void KFileItemModelRolesUpdater::applySortProgressToModel()
1232 // Inform the model about the progress of the resolved items,
1233 // so that it can give an indication when the sorting has been finished.
1234 const int resolvedCount
= m_model
->count() - m_pendingSortRoleItems
.count();
1235 m_model
->emitSortProgress(resolvedCount
);
1238 bool KFileItemModelRolesUpdater::applyResolvedRoles(int index
, ResolveHint hint
)
1240 const KFileItem item
= m_model
->fileItem(index
);
1241 const bool resolveAll
= (hint
== ResolveAll
);
1243 bool iconChanged
= false;
1244 if (!item
.isMimeTypeKnown() || !item
.isFinalIconKnown()) {
1245 item
.determineMimeType();
1247 } else if (!m_model
->data(index
).contains("iconName")) {
1251 if (iconChanged
|| resolveAll
|| m_clearPreviews
) {
1256 QHash
<QByteArray
, QVariant
> data
;
1258 data
= rolesData(item
, index
);
1261 if (!item
.iconName().isEmpty()) {
1262 data
.insert("iconName", item
.iconName());
1265 if (m_clearPreviews
) {
1266 data
.insert("iconPixmap", QPixmap());
1267 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>()));
1270 disconnect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1271 m_model
->setData(index
, data
);
1272 connect(m_model
, &KFileItemModel::itemsChanged
, this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1279 void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem
&item
, int index
)
1281 if (item
.isSlow()) {
1285 // Tell m_directoryContentsCounter that we want to count the items
1286 // inside the directory. The result will be received in slotDirectoryContentsCountReceived.
1287 if (m_scanDirectories
&& item
.isLocalFile()) {
1288 const QString path
= item
.localPath();
1289 const auto priority
= index
>= m_firstVisibleIndex
&& index
<= m_lastVisibleIndex
? KDirectoryContentsCounter::PathCountPriority::High
1290 : KDirectoryContentsCounter::PathCountPriority::Normal
;
1291 m_directoryContentsCounter
->scanDirectory(path
, priority
);
1295 QHash
<QByteArray
, QVariant
> KFileItemModelRolesUpdater::rolesData(const KFileItem
&item
, int index
)
1297 QHash
<QByteArray
, QVariant
> data
;
1299 const bool getSizeRole
= m_roles
.contains("size");
1300 const bool getIsExpandableRole
= m_roles
.contains("isExpandable");
1302 if ((getSizeRole
|| getIsExpandableRole
) && item
.isDir()) {
1303 startDirectorySizeCounting(item
, index
);
1306 if (m_roles
.contains("extension")) {
1307 data
.insert("extension", QFileInfo(item
.name()).suffix());
1310 if (m_roles
.contains("type")) {
1311 data
.insert("type", item
.mimeComment());
1314 QStringList overlays
= item
.overlays();
1315 for (KOverlayIconPlugin
*it
: qAsConst(m_overlayIconsPlugin
)) {
1316 overlays
.append(it
->getOverlays(item
.url()));
1318 if (!overlays
.isEmpty()) {
1319 data
.insert("iconOverlays", overlays
);
1323 if (m_balooFileMonitor
) {
1324 m_balooFileMonitor
->addFile(item
.localPath());
1325 applyChangedBalooRolesForItem(item
);
1331 void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl
&url
, const QStringList
&)
1333 const KFileItem item
= m_model
->fileItem(url
);
1334 if (item
.isNull()) {
1337 const int index
= m_model
->index(item
);
1338 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1339 QStringList overlays
= item
.overlays();
1340 for (KOverlayIconPlugin
*it
: qAsConst(m_overlayIconsPlugin
)) {
1341 overlays
.append(it
->getOverlays(url
));
1343 data
.insert("iconOverlays", overlays
);
1344 m_model
->setData(index
, data
);
1347 void KFileItemModelRolesUpdater::updateAllPreviews()
1349 if (m_state
== Paused
) {
1350 m_previewChangedDuringPausing
= true;
1352 m_finishedItems
.clear();
1357 void KFileItemModelRolesUpdater::killPreviewJob()
1360 disconnect(m_previewJob
, &KIO::PreviewJob::gotPreview
, this, &KFileItemModelRolesUpdater::slotGotPreview
);
1361 disconnect(m_previewJob
, &KIO::PreviewJob::failed
, this, &KFileItemModelRolesUpdater::slotPreviewFailed
);
1362 disconnect(m_previewJob
, &KIO::PreviewJob::finished
, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
1363 m_previewJob
->kill();
1364 m_previewJob
= nullptr;
1365 m_pendingPreviewItems
.clear();
1369 QList
<int> KFileItemModelRolesUpdater::indexesToResolve() const
1371 const int count
= m_model
->count();
1374 result
.reserve(qMin(count
, (m_lastVisibleIndex
- m_firstVisibleIndex
+ 1) + ResolveAllItemsLimit
+ (2 * m_maximumVisibleItems
)));
1376 // Add visible items.
1377 // Resolve files first, their previews are quicker.
1378 QList
<int> visibleDirs
;
1379 for (int i
= m_firstVisibleIndex
; i
<= m_lastVisibleIndex
; ++i
) {
1380 const KFileItem item
= m_model
->fileItem(i
);
1382 visibleDirs
.append(i
);
1388 result
.append(visibleDirs
);
1390 // We need a reasonable upper limit for number of items to resolve after
1391 // and before the visible range. m_maximumVisibleItems can be quite large
1392 // when using Compact View.
1393 const int readAheadItems
= qMin(ReadAheadPages
* m_maximumVisibleItems
, ResolveAllItemsLimit
/ 2);
1395 // Add items after the visible range.
1396 const int endExtendedVisibleRange
= qMin(m_lastVisibleIndex
+ readAheadItems
, count
- 1);
1397 for (int i
= m_lastVisibleIndex
+ 1; i
<= endExtendedVisibleRange
; ++i
) {
1401 // Add items before the visible range in reverse order.
1402 const int beginExtendedVisibleRange
= qMax(0, m_firstVisibleIndex
- readAheadItems
);
1403 for (int i
= m_firstVisibleIndex
- 1; i
>= beginExtendedVisibleRange
; --i
) {
1407 // Add items on the last page.
1408 const int beginLastPage
= qMax(endExtendedVisibleRange
+ 1, count
- m_maximumVisibleItems
);
1409 for (int i
= beginLastPage
; i
< count
; ++i
) {
1413 // Add items on the first page.
1414 const int endFirstPage
= qMin(beginExtendedVisibleRange
, m_maximumVisibleItems
);
1415 for (int i
= 0; i
< endFirstPage
; ++i
) {
1419 // Continue adding items until ResolveAllItemsLimit is reached.
1420 int remainingItems
= ResolveAllItemsLimit
- result
.count();
1422 for (int i
= endExtendedVisibleRange
+ 1; i
< beginLastPage
&& remainingItems
> 0; ++i
) {
1427 for (int i
= beginExtendedVisibleRange
- 1; i
>= endFirstPage
&& remainingItems
> 0; --i
) {
1435 void KFileItemModelRolesUpdater::trimHoverSequenceLoadedItems()
1437 static const size_t maxLoadedItems
= 20;
1439 size_t loadedItems
= m_hoverSequenceLoadedItems
.size();
1440 while (loadedItems
> maxLoadedItems
) {
1441 const KFileItem item
= m_hoverSequenceLoadedItems
.front();
1443 m_hoverSequenceLoadedItems
.pop_front();
1446 const int index
= m_model
->index(item
);
1448 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1449 data
["hoverSequencePixmaps"] = QVariant::fromValue(QVector
<QPixmap
>() << QPixmap());
1450 m_model
->setData(index
, data
);