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/JobUiDelegate>
17 #include <KIO/PreviewJob>
18 #include <KIconLoader>
19 #include <KJobWidgets>
20 #include <KOverlayIconPlugin>
21 #include <KPluginMetaData>
22 #include <KSharedConfig>
25 #include "private/kbaloorolesprovider.h"
27 #include <Baloo/FileMonitor>
30 #include <QApplication>
34 #include <QPluginLoader>
35 #include <QElapsedTimer>
38 // #define KFILEITEMMODELROLESUPDATER_DEBUG
41 // Maximum time in ms that the KFileItemModelRolesUpdater
42 // may perform a blocking operation
43 const int MaxBlockTimeout
= 200;
45 // If the number of items is smaller than ResolveAllItemsLimit,
46 // the roles of all items will be resolved.
47 const int ResolveAllItemsLimit
= 500;
49 // Not only the visible area, but up to ReadAheadPages before and after
50 // this area will be resolved.
51 const int ReadAheadPages
= 5;
54 KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel
* model
, QObject
* parent
) :
57 m_previewChangedDuringPausing(false),
58 m_iconSizeChangedDuringPausing(false),
59 m_rolesChangedDuringPausing(false),
60 m_previewShown(false),
61 m_enlargeSmallPreviews(true),
62 m_clearPreviews(false),
66 m_firstVisibleIndex(0),
67 m_lastVisibleIndex(-1),
68 m_maximumVisibleItems(50),
72 m_localFileSizePreviewLimit(0),
73 m_scanDirectories(true),
74 m_pendingSortRoleItems(),
76 m_pendingPreviewItems(),
78 m_hoverSequenceItem(),
79 m_hoverSequenceIndex(0),
80 m_hoverSequencePreviewJob(nullptr),
81 m_hoverSequenceNumSuccessiveFailures(0),
82 m_recentlyChangedItemsTimer(nullptr),
83 m_recentlyChangedItems(),
85 m_directoryContentsCounter(nullptr)
87 , m_balooFileMonitor(nullptr)
92 const KConfigGroup
globalConfig(KSharedConfig::openConfig(), "PreviewSettings");
93 m_enabledPlugins
= globalConfig
.readEntry("Plugins", KIO::PreviewJob::defaultPlugins());
94 m_localFileSizePreviewLimit
= static_cast<qulonglong
>(globalConfig
.readEntry("MaximumSize", 0));
96 connect(m_model
, &KFileItemModel::itemsInserted
,
97 this, &KFileItemModelRolesUpdater::slotItemsInserted
);
98 connect(m_model
, &KFileItemModel::itemsRemoved
,
99 this, &KFileItemModelRolesUpdater::slotItemsRemoved
);
100 connect(m_model
, &KFileItemModel::itemsChanged
,
101 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
102 connect(m_model
, &KFileItemModel::itemsMoved
,
103 this, &KFileItemModelRolesUpdater::slotItemsMoved
);
104 connect(m_model
, &KFileItemModel::sortRoleChanged
,
105 this, &KFileItemModelRolesUpdater::slotSortRoleChanged
);
107 // Use a timer to prevent that each call of slotItemsChanged() results in a synchronous
108 // resolving of the roles. Postpone the resolving until no update has been done for 100 ms.
109 m_recentlyChangedItemsTimer
= new QTimer(this);
110 m_recentlyChangedItemsTimer
->setInterval(100);
111 m_recentlyChangedItemsTimer
->setSingleShot(true);
112 connect(m_recentlyChangedItemsTimer
, &QTimer::timeout
, this, &KFileItemModelRolesUpdater::resolveRecentlyChangedItems
);
114 m_resolvableRoles
.insert("size");
115 m_resolvableRoles
.insert("type");
116 m_resolvableRoles
.insert("isExpandable");
118 m_resolvableRoles
+= KBalooRolesProvider::instance().roles();
121 m_directoryContentsCounter
= new KDirectoryContentsCounter(m_model
, this);
122 connect(m_directoryContentsCounter
, &KDirectoryContentsCounter::result
,
123 this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived
);
125 const auto plugins
= KPluginMetaData::findPlugins(QStringLiteral("kf" QT_STRINGIFY(QT_VERSION_MAJOR
)) + QStringLiteral("/overlayicon"));
126 for (const KPluginMetaData
&data
: plugins
) {
127 auto instance
= QPluginLoader(data
.fileName()).instance();
128 auto plugin
= qobject_cast
<KOverlayIconPlugin
*>(instance
);
130 m_overlayIconsPlugin
.append(plugin
);
131 connect(plugin
, &KOverlayIconPlugin::overlaysChanged
, this, &KFileItemModelRolesUpdater::slotOverlaysChanged
);
133 // not our/valid plugin, so delete the created object
139 KFileItemModelRolesUpdater::~KFileItemModelRolesUpdater()
144 void KFileItemModelRolesUpdater::setIconSize(const QSize
& size
)
146 if (size
!= m_iconSize
) {
148 if (m_state
== Paused
) {
149 m_iconSizeChangedDuringPausing
= true;
150 } else if (m_previewShown
) {
151 // An icon size change requires the regenerating of
153 m_finishedItems
.clear();
159 QSize
KFileItemModelRolesUpdater::iconSize() const
164 void KFileItemModelRolesUpdater::setVisibleIndexRange(int index
, int count
)
173 if (index
== m_firstVisibleIndex
&& count
== m_lastVisibleIndex
- m_firstVisibleIndex
+ 1) {
174 // The range has not been changed
178 m_firstVisibleIndex
= index
;
179 m_lastVisibleIndex
= qMin(index
+ count
- 1, m_model
->count() - 1);
184 void KFileItemModelRolesUpdater::setMaximumVisibleItems(int count
)
186 m_maximumVisibleItems
= count
;
189 void KFileItemModelRolesUpdater::setPreviewsShown(bool show
)
191 if (show
== m_previewShown
) {
195 m_previewShown
= show
;
197 m_clearPreviews
= true;
203 bool KFileItemModelRolesUpdater::previewsShown() const
205 return m_previewShown
;
208 void KFileItemModelRolesUpdater::setEnlargeSmallPreviews(bool enlarge
)
210 if (enlarge
!= m_enlargeSmallPreviews
) {
211 m_enlargeSmallPreviews
= enlarge
;
212 if (m_previewShown
) {
218 bool KFileItemModelRolesUpdater::enlargeSmallPreviews() const
220 return m_enlargeSmallPreviews
;
223 void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList
& list
)
225 if (m_enabledPlugins
!= list
) {
226 m_enabledPlugins
= list
;
227 if (m_previewShown
) {
233 void KFileItemModelRolesUpdater::setPaused(bool paused
)
235 if (paused
== (m_state
== Paused
)) {
243 const bool updatePreviews
= (m_iconSizeChangedDuringPausing
&& m_previewShown
) ||
244 m_previewChangedDuringPausing
;
245 const bool resolveAll
= updatePreviews
|| m_rolesChangedDuringPausing
;
247 m_finishedItems
.clear();
250 m_iconSizeChangedDuringPausing
= false;
251 m_previewChangedDuringPausing
= false;
252 m_rolesChangedDuringPausing
= false;
254 if (!m_pendingSortRoleItems
.isEmpty()) {
255 m_state
= ResolvingSortRole
;
256 resolveNextSortRole();
265 void KFileItemModelRolesUpdater::setRoles(const QSet
<QByteArray
>& roles
)
267 if (m_roles
!= roles
) {
271 // Check whether there is at least one role that must be resolved
272 // with the help of Baloo. If this is the case, a (quite expensive)
273 // resolving will be done in KFileItemModelRolesUpdater::rolesData() and
274 // the role gets watched for changes.
275 const KBalooRolesProvider
& rolesProvider
= KBalooRolesProvider::instance();
276 bool hasBalooRole
= false;
277 QSetIterator
<QByteArray
> it(roles
);
278 while (it
.hasNext()) {
279 const QByteArray
& role
= it
.next();
280 if (rolesProvider
.roles().contains(role
)) {
286 if (hasBalooRole
&& m_balooConfig
.fileIndexingEnabled() && !m_balooFileMonitor
) {
287 m_balooFileMonitor
= new Baloo::FileMonitor(this);
288 connect(m_balooFileMonitor
, &Baloo::FileMonitor::fileMetaDataChanged
,
289 this, &KFileItemModelRolesUpdater::applyChangedBalooRoles
);
290 } else if (!hasBalooRole
&& m_balooFileMonitor
) {
291 delete m_balooFileMonitor
;
292 m_balooFileMonitor
= nullptr;
296 if (m_state
== Paused
) {
297 m_rolesChangedDuringPausing
= true;
304 QSet
<QByteArray
> KFileItemModelRolesUpdater::roles() const
309 bool KFileItemModelRolesUpdater::isPaused() const
311 return m_state
== Paused
;
314 QStringList
KFileItemModelRolesUpdater::enabledPlugins() const
316 return m_enabledPlugins
;
319 void KFileItemModelRolesUpdater::setLocalFileSizePreviewLimit(const qlonglong size
)
321 m_localFileSizePreviewLimit
= size
;
324 qlonglong
KFileItemModelRolesUpdater::localFileSizePreviewLimit() const
326 return m_localFileSizePreviewLimit
;
329 void KFileItemModelRolesUpdater::setScanDirectories(bool enabled
)
331 m_scanDirectories
= enabled
;
334 bool KFileItemModelRolesUpdater::scanDirectories() const
336 return m_scanDirectories
;
339 void KFileItemModelRolesUpdater::setHoverSequenceState(const QUrl
& itemUrl
, int seqIdx
)
341 const KFileItem item
= m_model
->fileItem(itemUrl
);
343 if (item
!= m_hoverSequenceItem
) {
344 killHoverSequencePreviewJob();
347 m_hoverSequenceItem
= item
;
348 m_hoverSequenceIndex
= seqIdx
;
350 if (!m_previewShown
) {
354 m_hoverSequenceNumSuccessiveFailures
= 0;
356 loadNextHoverSequencePreview();
359 void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList
& itemRanges
)
364 // Determine the sort role synchronously for as many items as possible.
365 if (m_resolvableRoles
.contains(m_model
->sortRole())) {
366 int insertedCount
= 0;
367 for (const KItemRange
& range
: itemRanges
) {
368 const int lastIndex
= insertedCount
+ range
.index
+ range
.count
- 1;
369 for (int i
= insertedCount
+ range
.index
; i
<= lastIndex
; ++i
) {
370 if (timer
.elapsed() < MaxBlockTimeout
) {
373 m_pendingSortRoleItems
.insert(m_model
->fileItem(i
));
376 insertedCount
+= range
.count
;
379 applySortProgressToModel();
381 // If there are still items whose sort role is unknown, check if the
382 // asynchronous determination of the sort role is already in progress,
383 // and start it if that is not the case.
384 if (!m_pendingSortRoleItems
.isEmpty() && m_state
!= ResolvingSortRole
) {
386 m_state
= ResolvingSortRole
;
387 resolveNextSortRole();
394 void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList
& itemRanges
)
398 const bool allItemsRemoved
= (m_model
->count() == 0);
401 if (m_balooFileMonitor
) {
402 // Don't let the FileWatcher watch for removed items
403 if (allItemsRemoved
) {
404 m_balooFileMonitor
->clear();
406 QStringList newFileList
;
407 const QStringList oldFileList
= m_balooFileMonitor
->files();
408 for (const QString
& file
: oldFileList
) {
409 if (m_model
->index(QUrl::fromLocalFile(file
)) >= 0) {
410 newFileList
.append(file
);
413 m_balooFileMonitor
->setFiles(newFileList
);
418 if (allItemsRemoved
) {
421 m_finishedItems
.clear();
422 m_pendingSortRoleItems
.clear();
423 m_pendingIndexes
.clear();
424 m_pendingPreviewItems
.clear();
425 m_recentlyChangedItems
.clear();
426 m_recentlyChangedItemsTimer
->stop();
427 m_changedItems
.clear();
428 m_hoverSequenceLoadedItems
.clear();
432 // Only remove the items from m_finishedItems. They will be removed
433 // from the other sets later on.
434 QSet
<KFileItem
>::iterator it
= m_finishedItems
.begin();
435 while (it
!= m_finishedItems
.end()) {
436 if (m_model
->index(*it
) < 0) {
437 it
= m_finishedItems
.erase(it
);
443 // Removed items won't have hover previews loaded anymore.
444 for (const KItemRange
& itemRange
: itemRanges
) {
445 int index
= itemRange
.index
;
446 for (int count
= itemRange
.count
; count
> 0; --count
) {
447 const KFileItem item
= m_model
->fileItem(index
);
448 m_hoverSequenceLoadedItems
.remove(item
);
453 // The visible items might have changed.
458 void KFileItemModelRolesUpdater::slotItemsMoved(const KItemRange
& itemRange
, const QList
<int> &movedToIndexes
)
461 Q_UNUSED(movedToIndexes
)
463 // The visible items might have changed.
467 void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList
& itemRanges
,
468 const QSet
<QByteArray
>& roles
)
472 // Find out if slotItemsChanged() has been done recently. If that is the
473 // case, resolving the roles is postponed until a timer has exceeded
474 // to prevent expensive repeated updates if files are updated frequently.
475 const bool itemsChangedRecently
= m_recentlyChangedItemsTimer
->isActive();
477 QSet
<KFileItem
>& targetSet
= itemsChangedRecently
? m_recentlyChangedItems
: m_changedItems
;
479 for (const KItemRange
& itemRange
: itemRanges
) {
480 int index
= itemRange
.index
;
481 for (int count
= itemRange
.count
; count
> 0; --count
) {
482 const KFileItem item
= m_model
->fileItem(index
);
483 targetSet
.insert(item
);
488 m_recentlyChangedItemsTimer
->start();
490 if (!itemsChangedRecently
) {
491 updateChangedItems();
495 void KFileItemModelRolesUpdater::slotSortRoleChanged(const QByteArray
& current
,
496 const QByteArray
& previous
)
501 if (m_resolvableRoles
.contains(current
)) {
502 m_pendingSortRoleItems
.clear();
503 m_finishedItems
.clear();
505 const int count
= m_model
->count();
509 // Determine the sort role synchronously for as many items as possible.
510 for (int index
= 0; index
< count
; ++index
) {
511 if (timer
.elapsed() < MaxBlockTimeout
) {
512 applySortRole(index
);
514 m_pendingSortRoleItems
.insert(m_model
->fileItem(index
));
518 applySortProgressToModel();
520 if (!m_pendingSortRoleItems
.isEmpty()) {
521 // Trigger the asynchronous determination of the sort role.
523 m_state
= ResolvingSortRole
;
524 resolveNextSortRole();
528 m_pendingSortRoleItems
.clear();
529 applySortProgressToModel();
533 void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
535 if (m_state
!= PreviewJobRunning
) {
539 m_changedItems
.remove(item
);
541 const int index
= m_model
->index(item
);
546 QPixmap scaledPixmap
= transformPreviewPixmap(pixmap
);
548 QHash
<QByteArray
, QVariant
> data
= rolesData(item
);
550 const QStringList overlays
= data
["iconOverlays"].toStringList();
551 // Strangely KFileItem::overlays() returns empty string-values, so
552 // we need to check first whether an overlay must be drawn at all.
553 // It is more efficient to do it here, as KIconLoader::drawOverlays()
554 // assumes that an overlay will be drawn and has some additional
556 if (!scaledPixmap
.isNull()) {
557 for (const QString
& overlay
: overlays
) {
558 if (!overlay
.isEmpty()) {
559 // There is at least one overlay, draw all overlays above m_pixmap
560 // and cancel the check
561 KIconLoader::global()->drawOverlays(overlays
, scaledPixmap
, KIconLoader::Desktop
);
567 data
.insert("iconPixmap", scaledPixmap
);
569 disconnect(m_model
, &KFileItemModel::itemsChanged
,
570 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
571 m_model
->setData(index
, data
);
572 connect(m_model
, &KFileItemModel::itemsChanged
,
573 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
575 m_finishedItems
.insert(item
);
578 void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem
& item
)
580 if (m_state
!= PreviewJobRunning
) {
584 m_changedItems
.remove(item
);
586 const int index
= m_model
->index(item
);
588 QHash
<QByteArray
, QVariant
> data
;
589 data
.insert("iconPixmap", QPixmap());
591 disconnect(m_model
, &KFileItemModel::itemsChanged
,
592 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
593 m_model
->setData(index
, data
);
594 connect(m_model
, &KFileItemModel::itemsChanged
,
595 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
597 applyResolvedRoles(index
, ResolveAll
);
598 m_finishedItems
.insert(item
);
602 void KFileItemModelRolesUpdater::slotPreviewJobFinished()
604 m_previewJob
= nullptr;
606 if (m_state
!= PreviewJobRunning
) {
612 if (!m_pendingPreviewItems
.isEmpty()) {
615 if (!m_changedItems
.isEmpty()) {
616 updateChangedItems();
621 void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
623 const int index
= m_model
->index(item
);
628 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
629 QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
630 const int loadedIndex
= pixmaps
.size();
632 float wap
= m_hoverSequencePreviewJob
->sequenceIndexWraparoundPoint();
633 if (!m_hoverSequencePreviewJob
->handlesSequences()) {
637 data
["hoverSequenceWraparoundPoint"] = wap
;
638 m_model
->setData(index
, data
);
641 // For hover sequence previews we never load index 0, because that's just the regular preview
642 // in "iconPixmap". But that means we'll load index 1 even for thumbnailers that don't support
643 // sequences, in which case we can just throw away the preview because it's the same as for
644 // index 0. Unfortunately we can't find it out earlier :(
645 if (wap
< 0.0f
|| loadedIndex
< static_cast<int>(wap
)) {
646 // Add the preview to the model data
648 const QPixmap scaledPixmap
= transformPreviewPixmap(pixmap
);
650 pixmaps
.append(scaledPixmap
);
651 data
["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps
);
653 m_model
->setData(index
, data
);
655 const auto loadedIt
= std::find(m_hoverSequenceLoadedItems
.begin(),
656 m_hoverSequenceLoadedItems
.end(), item
);
657 if (loadedIt
== m_hoverSequenceLoadedItems
.end()) {
658 m_hoverSequenceLoadedItems
.push_back(item
);
659 trimHoverSequenceLoadedItems();
663 m_hoverSequenceNumSuccessiveFailures
= 0;
666 void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem
& item
)
668 const int index
= m_model
->index(item
);
673 static const int numRetries
= 2;
675 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
676 QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
678 qCDebug(DolphinDebug
).nospace()
679 << "Failed to generate hover sequence preview #" << pixmaps
.size()
680 << " for file " << item
.url().toString()
681 << " (attempt " << (m_hoverSequenceNumSuccessiveFailures
+1)
682 << "/" << (numRetries
+1) << ")";
684 if (m_hoverSequenceNumSuccessiveFailures
>= numRetries
) {
685 // Give up and simply duplicate the previous sequence image (if any)
687 pixmaps
.append(pixmaps
.empty() ? QPixmap() : pixmaps
.last());
688 data
["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps
);
690 if (!data
.contains("hoverSequenceWraparoundPoint")) {
691 // hoverSequenceWraparoundPoint is only available when PreviewJob succeeds, so unless
692 // it has previously succeeded, it's best to assume that it just doesn't handle
693 // sequences instead of trying to load the next image indefinitely.
694 data
["hoverSequenceWraparoundPoint"] = 1.0f
;
697 m_model
->setData(index
, data
);
699 m_hoverSequenceNumSuccessiveFailures
= 0;
703 m_hoverSequenceNumSuccessiveFailures
++;
706 // Next image in the sequence (or same one if the retry limit wasn't reached yet) will be
707 // loaded automatically, because slotHoverSequencePreviewJobFinished() will be triggered
708 // even when PreviewJob fails.
711 void KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished()
713 const int index
= m_model
->index(m_hoverSequenceItem
);
715 m_hoverSequencePreviewJob
= nullptr;
719 // Since a PreviewJob can only have one associated sequence index, we can only generate
720 // one sequence image per job, so we have to start another one for the next index.
722 // Load the next image in the sequence
723 m_hoverSequencePreviewJob
= nullptr;
724 loadNextHoverSequencePreview();
727 void KFileItemModelRolesUpdater::resolveNextSortRole()
729 if (m_state
!= ResolvingSortRole
) {
733 QSet
<KFileItem
>::iterator it
= m_pendingSortRoleItems
.begin();
734 while (it
!= m_pendingSortRoleItems
.end()) {
735 const KFileItem item
= *it
;
736 const int index
= m_model
->index(item
);
738 // Continue if the sort role has already been determined for the
739 // item, and the item has not been changed recently.
740 if (!m_changedItems
.contains(item
) && m_model
->data(index
).contains(m_model
->sortRole())) {
741 it
= m_pendingSortRoleItems
.erase(it
);
745 applySortRole(index
);
746 m_pendingSortRoleItems
.erase(it
);
750 if (!m_pendingSortRoleItems
.isEmpty()) {
751 applySortProgressToModel();
752 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole
);
756 // Prevent that we try to update the items twice.
757 disconnect(m_model
, &KFileItemModel::itemsMoved
,
758 this, &KFileItemModelRolesUpdater::slotItemsMoved
);
759 applySortProgressToModel();
760 connect(m_model
, &KFileItemModel::itemsMoved
,
761 this, &KFileItemModelRolesUpdater::slotItemsMoved
);
766 void KFileItemModelRolesUpdater::resolveNextPendingRoles()
768 if (m_state
!= ResolvingAllRoles
) {
772 while (!m_pendingIndexes
.isEmpty()) {
773 const int index
= m_pendingIndexes
.takeFirst();
774 const KFileItem item
= m_model
->fileItem(index
);
776 if (m_finishedItems
.contains(item
)) {
780 applyResolvedRoles(index
, ResolveAll
);
781 m_finishedItems
.insert(item
);
782 m_changedItems
.remove(item
);
786 if (!m_pendingIndexes
.isEmpty()) {
787 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
791 if (m_clearPreviews
) {
792 // Only go through the list if there are items which might still have previews.
793 if (m_finishedItems
.count() != m_model
->count()) {
794 QHash
<QByteArray
, QVariant
> data
;
795 data
.insert("iconPixmap", QPixmap());
796 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>()));
798 disconnect(m_model
, &KFileItemModel::itemsChanged
,
799 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
800 for (int index
= 0; index
<= m_model
->count(); ++index
) {
801 if (m_model
->data(index
).contains("iconPixmap") ||
802 m_model
->data(index
).contains("hoverSequencePixmaps"))
804 m_model
->setData(index
, data
);
807 connect(m_model
, &KFileItemModel::itemsChanged
,
808 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
811 m_clearPreviews
= false;
814 if (!m_changedItems
.isEmpty()) {
815 updateChangedItems();
820 void KFileItemModelRolesUpdater::resolveRecentlyChangedItems()
822 m_changedItems
+= m_recentlyChangedItems
;
823 m_recentlyChangedItems
.clear();
824 updateChangedItems();
827 void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString
& file
)
830 const KFileItem item
= m_model
->fileItem(QUrl::fromLocalFile(file
));
833 // itemUrl is not in the model anymore, probably because
834 // the corresponding file has been deleted in the meantime.
837 applyChangedBalooRolesForItem(item
);
843 void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem
&item
)
846 Baloo::File
file(item
.localPath());
849 const KBalooRolesProvider
& rolesProvider
= KBalooRolesProvider::instance();
850 QHash
<QByteArray
, QVariant
> data
;
852 const auto roles
= rolesProvider
.roles();
853 for (const QByteArray
& role
: roles
) {
854 // Overwrite all the role values with an empty QVariant, because the roles
855 // provider doesn't overwrite it when the property value list is empty.
857 data
.insert(role
, QVariant());
860 QHashIterator
<QByteArray
, QVariant
> it(rolesProvider
.roleValues(file
, m_roles
));
861 while (it
.hasNext()) {
863 data
.insert(it
.key(), it
.value());
866 disconnect(m_model
, &KFileItemModel::itemsChanged
,
867 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
868 const int index
= m_model
->index(item
);
869 m_model
->setData(index
, data
);
870 connect(m_model
, &KFileItemModel::itemsChanged
,
871 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
879 void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString
& path
, int count
, long size
)
881 const bool getSizeRole
= m_roles
.contains("size");
882 const bool getIsExpandableRole
= m_roles
.contains("isExpandable");
884 if (getSizeRole
|| getIsExpandableRole
) {
885 const int index
= m_model
->index(QUrl::fromLocalFile(path
));
887 QHash
<QByteArray
, QVariant
> data
;
890 data
.insert("count", count
);
891 data
.insert("size", QVariant::fromValue(size
));
893 if (getIsExpandableRole
) {
894 data
.insert("isExpandable", count
> 0);
897 disconnect(m_model
, &KFileItemModel::itemsChanged
,
898 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
899 m_model
->setData(index
, data
);
900 connect(m_model
, &KFileItemModel::itemsChanged
,
901 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
906 void KFileItemModelRolesUpdater::startUpdating()
908 if (m_state
== Paused
) {
912 if (m_finishedItems
.count() == m_model
->count()) {
913 // All roles have been resolved already.
918 // Terminate all updates that are currently active.
920 m_pendingIndexes
.clear();
925 // Determine the icons for the visible items synchronously.
926 updateVisibleIcons();
928 // A detailed update of the items in and near the visible area
929 // only makes sense if sorting is finished.
930 if (m_state
== ResolvingSortRole
) {
934 // Start the preview job or the asynchronous resolving of all roles.
935 QList
<int> indexes
= indexesToResolve();
937 if (m_previewShown
) {
938 m_pendingPreviewItems
.clear();
939 m_pendingPreviewItems
.reserve(indexes
.count());
941 for (int index
: qAsConst(indexes
)) {
942 const KFileItem item
= m_model
->fileItem(index
);
943 if (!m_finishedItems
.contains(item
)) {
944 m_pendingPreviewItems
.append(item
);
950 m_pendingIndexes
= indexes
;
951 // Trigger the asynchronous resolving of all roles.
952 m_state
= ResolvingAllRoles
;
953 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
957 void KFileItemModelRolesUpdater::updateVisibleIcons()
959 int lastVisibleIndex
= m_lastVisibleIndex
;
960 if (lastVisibleIndex
<= 0) {
961 // Guess a reasonable value for the last visible index if the view
962 // has not told us about the real value yet.
963 lastVisibleIndex
= qMin(m_firstVisibleIndex
+ m_maximumVisibleItems
, m_model
->count() - 1);
964 if (lastVisibleIndex
<= 0) {
965 lastVisibleIndex
= qMin(200, m_model
->count() - 1);
972 // Try to determine the final icons for all visible items.
974 for (index
= m_firstVisibleIndex
; index
<= lastVisibleIndex
&& timer
.elapsed() < MaxBlockTimeout
; ++index
) {
975 applyResolvedRoles(index
, ResolveFast
);
978 // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load
979 // preliminary icons (i.e., without mime type determination) for the
983 void KFileItemModelRolesUpdater::startPreviewJob()
985 m_state
= PreviewJobRunning
;
987 if (m_pendingPreviewItems
.isEmpty()) {
988 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
992 // PreviewJob internally caches items always with the size of
993 // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
994 // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
995 // do a downscaling anyhow because of the frame, so in this case only the provided
996 // cache sizes are requested.
997 const QSize cacheSize
= (m_iconSize
.width() > 128) || (m_iconSize
.height() > 128)
998 ? QSize(256, 256) : QSize(128, 128);
1000 // KIO::filePreview() will request the MIME-type of all passed items, which (in the
1001 // worst case) might block the application for several seconds. To prevent such
1002 // a blocking, we only pass items with known mime type to the preview job.
1003 const int count
= m_pendingPreviewItems
.count();
1004 KFileItemList itemSubSet
;
1005 itemSubSet
.reserve(count
);
1007 if (m_pendingPreviewItems
.first().isMimeTypeKnown()) {
1008 // Some mime types are known already, probably because they were
1009 // determined when loading the icons for the visible items. Start
1010 // a preview job for all items at the beginning of the list which
1011 // have a known mime type.
1013 itemSubSet
.append(m_pendingPreviewItems
.takeFirst());
1014 } while (!m_pendingPreviewItems
.isEmpty() && m_pendingPreviewItems
.first().isMimeTypeKnown());
1016 // Determine mime types for MaxBlockTimeout ms, and start a preview
1017 // job for the corresponding items.
1018 QElapsedTimer timer
;
1022 const KFileItem item
= m_pendingPreviewItems
.takeFirst();
1023 item
.determineMimeType();
1024 itemSubSet
.append(item
);
1025 } while (!m_pendingPreviewItems
.isEmpty() && timer
.elapsed() < MaxBlockTimeout
);
1028 KIO::PreviewJob
* job
= new KIO::PreviewJob(itemSubSet
, cacheSize
, &m_enabledPlugins
);
1030 job
->setIgnoreMaximumSize(itemSubSet
.first().isLocalFile() && !itemSubSet
.first().isSlow() && m_localFileSizePreviewLimit
<= 0);
1031 if (job
->uiDelegate()) {
1032 KJobWidgets::setWindow(job
, qApp
->activeWindow());
1035 connect(job
, &KIO::PreviewJob::gotPreview
,
1036 this, &KFileItemModelRolesUpdater::slotGotPreview
);
1037 connect(job
, &KIO::PreviewJob::failed
,
1038 this, &KFileItemModelRolesUpdater::slotPreviewFailed
);
1039 connect(job
, &KIO::PreviewJob::finished
,
1040 this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
1045 QPixmap
KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap
& pixmap
)
1047 QPixmap scaledPixmap
= pixmap
;
1049 if (!pixmap
.hasAlpha() && !pixmap
.isNull()
1050 && m_iconSize
.width() > KIconLoader::SizeSmallMedium
1051 && m_iconSize
.height() > KIconLoader::SizeSmallMedium
) {
1052 if (m_enlargeSmallPreviews
) {
1053 KPixmapModifier::applyFrame(scaledPixmap
, m_iconSize
);
1055 // Assure that small previews don't get enlarged. Instead they
1056 // should be shown centered within the frame.
1057 const QSize contentSize
= KPixmapModifier::sizeInsideFrame(m_iconSize
);
1058 const bool enlargingRequired
= scaledPixmap
.width() < contentSize
.width() &&
1059 scaledPixmap
.height() < contentSize
.height();
1060 if (enlargingRequired
) {
1061 QSize frameSize
= scaledPixmap
.size() / scaledPixmap
.devicePixelRatio();
1062 frameSize
.scale(m_iconSize
, Qt::KeepAspectRatio
);
1064 QPixmap
largeFrame(frameSize
);
1065 largeFrame
.fill(Qt::transparent
);
1067 KPixmapModifier::applyFrame(largeFrame
, frameSize
);
1069 QPainter
painter(&largeFrame
);
1070 painter
.drawPixmap((largeFrame
.width() - scaledPixmap
.width() / scaledPixmap
.devicePixelRatio()) / 2,
1071 (largeFrame
.height() - scaledPixmap
.height() / scaledPixmap
.devicePixelRatio()) / 2,
1073 scaledPixmap
= largeFrame
;
1075 // The image must be shrunk as it is too large to fit into
1076 // the available icon size
1077 KPixmapModifier::applyFrame(scaledPixmap
, m_iconSize
);
1080 } else if (!pixmap
.isNull()) {
1081 KPixmapModifier::scale(scaledPixmap
, m_iconSize
* qApp
->devicePixelRatio());
1082 scaledPixmap
.setDevicePixelRatio(qApp
->devicePixelRatio());
1085 return scaledPixmap
;
1088 void KFileItemModelRolesUpdater::loadNextHoverSequencePreview()
1090 if (m_hoverSequenceItem
.isNull() || m_hoverSequencePreviewJob
) {
1094 const int index
= m_model
->index(m_hoverSequenceItem
);
1099 // We generate the next few sequence indices in advance (buffering)
1100 const int maxSeqIdx
= m_hoverSequenceIndex
+5;
1102 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1104 if (!data
.contains("hoverSequencePixmaps")) {
1105 // The pixmap at index 0 isn't used ("iconPixmap" will be used instead)
1106 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>() << QPixmap()));
1107 m_model
->setData(index
, data
);
1110 const QVector
<QPixmap
> pixmaps
= data
["hoverSequencePixmaps"].value
<QVector
<QPixmap
>>();
1112 const int loadSeqIdx
= pixmaps
.size();
1115 if (data
.contains("hoverSequenceWraparoundPoint")) {
1116 wap
= data
["hoverSequenceWraparoundPoint"].toFloat();
1118 if (wap
>= 1.0f
&& loadSeqIdx
>= static_cast<int>(wap
)) {
1119 // Reached the wraparound point -> no more previews to load.
1123 if (loadSeqIdx
> maxSeqIdx
) {
1124 // Wait until setHoverSequenceState() is called with a higher sequence index.
1128 // PreviewJob internally caches items always with the size of
1129 // 128 x 128 pixels or 256 x 256 pixels. A (slow) downscaling is done
1130 // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must
1131 // do a downscaling anyhow because of the frame, so in this case only the provided
1132 // cache sizes are requested.
1133 const QSize cacheSize
= (m_iconSize
.width() > 128) || (m_iconSize
.height() > 128)
1134 ? QSize(256, 256) : QSize(128, 128);
1136 KIO::PreviewJob
* job
= new KIO::PreviewJob({m_hoverSequenceItem
}, cacheSize
, &m_enabledPlugins
);
1138 job
->setSequenceIndex(loadSeqIdx
);
1139 job
->setIgnoreMaximumSize(m_hoverSequenceItem
.isLocalFile() && !m_hoverSequenceItem
.isSlow() && m_localFileSizePreviewLimit
<= 0);
1140 if (job
->uiDelegate()) {
1141 KJobWidgets::setWindow(job
, qApp
->activeWindow());
1144 connect(job
, &KIO::PreviewJob::gotPreview
,
1145 this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview
);
1146 connect(job
, &KIO::PreviewJob::failed
,
1147 this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed
);
1148 connect(job
, &KIO::PreviewJob::finished
,
1149 this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished
);
1151 m_hoverSequencePreviewJob
= job
;
1154 void KFileItemModelRolesUpdater::killHoverSequencePreviewJob()
1156 if (m_hoverSequencePreviewJob
) {
1157 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::gotPreview
,
1158 this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview
);
1159 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::failed
,
1160 this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed
);
1161 disconnect(m_hoverSequencePreviewJob
, &KIO::PreviewJob::finished
,
1162 this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished
);
1163 m_hoverSequencePreviewJob
->kill();
1164 m_hoverSequencePreviewJob
= nullptr;
1168 void KFileItemModelRolesUpdater::updateChangedItems()
1170 if (m_state
== Paused
) {
1174 if (m_changedItems
.isEmpty()) {
1178 m_finishedItems
-= m_changedItems
;
1180 if (m_resolvableRoles
.contains(m_model
->sortRole())) {
1181 m_pendingSortRoleItems
+= m_changedItems
;
1183 if (m_state
!= ResolvingSortRole
) {
1184 // Stop the preview job if necessary, and trigger the
1185 // asynchronous determination of the sort role.
1187 m_state
= ResolvingSortRole
;
1188 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole
);
1194 QList
<int> visibleChangedIndexes
;
1195 QList
<int> invisibleChangedIndexes
;
1196 visibleChangedIndexes
.reserve(m_changedItems
.size());
1197 invisibleChangedIndexes
.reserve(m_changedItems
.size());
1199 auto changedItemsIt
= m_changedItems
.begin();
1200 while (changedItemsIt
!= m_changedItems
.end()) {
1201 const auto& item
= *changedItemsIt
;
1202 const int index
= m_model
->index(item
);
1205 changedItemsIt
= m_changedItems
.erase(changedItemsIt
);
1210 if (index
>= m_firstVisibleIndex
&& index
<= m_lastVisibleIndex
) {
1211 visibleChangedIndexes
.append(index
);
1213 invisibleChangedIndexes
.append(index
);
1217 std::sort(visibleChangedIndexes
.begin(), visibleChangedIndexes
.end());
1219 if (m_previewShown
) {
1220 for (int index
: qAsConst(visibleChangedIndexes
)) {
1221 m_pendingPreviewItems
.append(m_model
->fileItem(index
));
1224 for (int index
: qAsConst(invisibleChangedIndexes
)) {
1225 m_pendingPreviewItems
.append(m_model
->fileItem(index
));
1228 if (!m_previewJob
) {
1232 const bool resolvingInProgress
= !m_pendingIndexes
.isEmpty();
1233 m_pendingIndexes
= visibleChangedIndexes
+ m_pendingIndexes
+ invisibleChangedIndexes
;
1234 if (!resolvingInProgress
) {
1235 // Trigger the asynchronous resolving of the changed roles.
1236 m_state
= ResolvingAllRoles
;
1237 QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles
);
1242 void KFileItemModelRolesUpdater::applySortRole(int index
)
1244 QHash
<QByteArray
, QVariant
> data
;
1245 const KFileItem item
= m_model
->fileItem(index
);
1247 if (m_model
->sortRole() == "type") {
1248 if (!item
.isMimeTypeKnown()) {
1249 item
.determineMimeType();
1252 data
.insert("type", item
.mimeComment());
1253 } else if (m_model
->sortRole() == "size" && item
.isLocalFile() && item
.isDir()) {
1254 const QString path
= item
.localPath();
1255 if (m_scanDirectories
) {
1256 m_directoryContentsCounter
->scanDirectory(path
);
1259 // Probably the sort role is a baloo role - just determine all roles.
1260 data
= rolesData(item
);
1263 disconnect(m_model
, &KFileItemModel::itemsChanged
,
1264 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1265 m_model
->setData(index
, data
);
1266 connect(m_model
, &KFileItemModel::itemsChanged
,
1267 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1270 void KFileItemModelRolesUpdater::applySortProgressToModel()
1272 // Inform the model about the progress of the resolved items,
1273 // so that it can give an indication when the sorting has been finished.
1274 const int resolvedCount
= m_model
->count() - m_pendingSortRoleItems
.count();
1275 m_model
->emitSortProgress(resolvedCount
);
1278 bool KFileItemModelRolesUpdater::applyResolvedRoles(int index
, ResolveHint hint
)
1280 const KFileItem item
= m_model
->fileItem(index
);
1281 const bool resolveAll
= (hint
== ResolveAll
);
1283 bool iconChanged
= false;
1284 if (!item
.isMimeTypeKnown() || !item
.isFinalIconKnown()) {
1285 item
.determineMimeType();
1287 } else if (!m_model
->data(index
).contains("iconName")) {
1291 if (iconChanged
|| resolveAll
|| m_clearPreviews
) {
1296 QHash
<QByteArray
, QVariant
> data
;
1298 data
= rolesData(item
);
1301 if (!item
.iconName().isEmpty()) {
1302 data
.insert("iconName", item
.iconName());
1305 if (m_clearPreviews
) {
1306 data
.insert("iconPixmap", QPixmap());
1307 data
.insert("hoverSequencePixmaps", QVariant::fromValue(QVector
<QPixmap
>()));
1310 disconnect(m_model
, &KFileItemModel::itemsChanged
,
1311 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1312 m_model
->setData(index
, data
);
1313 connect(m_model
, &KFileItemModel::itemsChanged
,
1314 this, &KFileItemModelRolesUpdater::slotItemsChanged
);
1321 QHash
<QByteArray
, QVariant
> KFileItemModelRolesUpdater::rolesData(const KFileItem
& item
)
1323 QHash
<QByteArray
, QVariant
> data
;
1325 const bool getSizeRole
= m_roles
.contains("size");
1326 const bool getIsExpandableRole
= m_roles
.contains("isExpandable");
1328 if ((getSizeRole
|| getIsExpandableRole
) && item
.isDir()) {
1329 if (item
.isLocalFile()) {
1330 // Tell m_directoryContentsCounter that we want to count the items
1331 // inside the directory. The result will be received in slotDirectoryContentsCountReceived.
1332 if (m_scanDirectories
) {
1333 const QString path
= item
.localPath();
1334 m_directoryContentsCounter
->scanDirectory(path
);
1336 } else if (getSizeRole
) {
1337 data
.insert("size", -1); // -1 indicates an unknown number of items
1341 if (m_roles
.contains("extension")) {
1342 data
.insert("extension", QFileInfo(item
.name()).suffix());
1345 if (m_roles
.contains("type")) {
1346 data
.insert("type", item
.mimeComment());
1349 QStringList overlays
= item
.overlays();
1350 for (KOverlayIconPlugin
*it
: qAsConst(m_overlayIconsPlugin
)) {
1351 overlays
.append(it
->getOverlays(item
.url()));
1353 data
.insert("iconOverlays", overlays
);
1356 if (m_balooFileMonitor
) {
1357 m_balooFileMonitor
->addFile(item
.localPath());
1358 applyChangedBalooRolesForItem(item
);
1364 void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl
& url
, const QStringList
&)
1366 const KFileItem item
= m_model
->fileItem(url
);
1367 if (item
.isNull()) {
1370 const int index
= m_model
->index(item
);
1371 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1372 QStringList overlays
= item
.overlays();
1373 for (KOverlayIconPlugin
*it
: qAsConst(m_overlayIconsPlugin
)) {
1374 overlays
.append(it
->getOverlays(url
));
1376 data
.insert("iconOverlays", overlays
);
1377 m_model
->setData(index
, data
);
1380 void KFileItemModelRolesUpdater::updateAllPreviews()
1382 if (m_state
== Paused
) {
1383 m_previewChangedDuringPausing
= true;
1385 m_finishedItems
.clear();
1390 void KFileItemModelRolesUpdater::killPreviewJob()
1393 disconnect(m_previewJob
, &KIO::PreviewJob::gotPreview
,
1394 this, &KFileItemModelRolesUpdater::slotGotPreview
);
1395 disconnect(m_previewJob
, &KIO::PreviewJob::failed
,
1396 this, &KFileItemModelRolesUpdater::slotPreviewFailed
);
1397 disconnect(m_previewJob
, &KIO::PreviewJob::finished
,
1398 this, &KFileItemModelRolesUpdater::slotPreviewJobFinished
);
1399 m_previewJob
->kill();
1400 m_previewJob
= nullptr;
1401 m_pendingPreviewItems
.clear();
1405 QList
<int> KFileItemModelRolesUpdater::indexesToResolve() const
1407 const int count
= m_model
->count();
1410 result
.reserve(qMin(count
, (m_lastVisibleIndex
- m_firstVisibleIndex
+ 1) +
1411 ResolveAllItemsLimit
+
1412 (2 * m_maximumVisibleItems
)));
1414 // Add visible items.
1415 // Resolve files first, their previews are quicker.
1416 QList
<int> visibleDirs
;
1417 for (int i
= m_firstVisibleIndex
; i
<= m_lastVisibleIndex
; ++i
) {
1418 const KFileItem item
= m_model
->fileItem(i
);
1420 visibleDirs
.append(i
);
1426 result
.append(visibleDirs
);
1428 // We need a reasonable upper limit for number of items to resolve after
1429 // and before the visible range. m_maximumVisibleItems can be quite large
1430 // when using Compact View.
1431 const int readAheadItems
= qMin(ReadAheadPages
* m_maximumVisibleItems
, ResolveAllItemsLimit
/ 2);
1433 // Add items after the visible range.
1434 const int endExtendedVisibleRange
= qMin(m_lastVisibleIndex
+ readAheadItems
, count
- 1);
1435 for (int i
= m_lastVisibleIndex
+ 1; i
<= endExtendedVisibleRange
; ++i
) {
1439 // Add items before the visible range in reverse order.
1440 const int beginExtendedVisibleRange
= qMax(0, m_firstVisibleIndex
- readAheadItems
);
1441 for (int i
= m_firstVisibleIndex
- 1; i
>= beginExtendedVisibleRange
; --i
) {
1445 // Add items on the last page.
1446 const int beginLastPage
= qMax(endExtendedVisibleRange
+ 1, count
- m_maximumVisibleItems
);
1447 for (int i
= beginLastPage
; i
< count
; ++i
) {
1451 // Add items on the first page.
1452 const int endFirstPage
= qMin(beginExtendedVisibleRange
, m_maximumVisibleItems
);
1453 for (int i
= 0; i
< endFirstPage
; ++i
) {
1457 // Continue adding items until ResolveAllItemsLimit is reached.
1458 int remainingItems
= ResolveAllItemsLimit
- result
.count();
1460 for (int i
= endExtendedVisibleRange
+ 1; i
< beginLastPage
&& remainingItems
> 0; ++i
) {
1465 for (int i
= beginExtendedVisibleRange
- 1; i
>= endFirstPage
&& remainingItems
> 0; --i
) {
1473 void KFileItemModelRolesUpdater::trimHoverSequenceLoadedItems()
1475 static const size_t maxLoadedItems
= 20;
1477 size_t loadedItems
= m_hoverSequenceLoadedItems
.size();
1478 while (loadedItems
> maxLoadedItems
) {
1479 const KFileItem item
= m_hoverSequenceLoadedItems
.front();
1481 m_hoverSequenceLoadedItems
.pop_front();
1484 const int index
= m_model
->index(item
);
1486 QHash
<QByteArray
, QVariant
> data
= m_model
->data(index
);
1487 data
["hoverSequencePixmaps"] = QVariant::fromValue(QVector
<QPixmap
>() << QPixmap());
1488 m_model
->setData(index
, data
);