mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 00:11:21 +00:00
Try to do at least a "fast" icon loading for all items
If all icons for the visible items could be loaded in 200 ms, we continue loading icons without mime type determination for all items until the 200 ms are over. This reduces the risk that the user ever sees "unknown" icons. REVIEW: 111011
This commit is contained in:
parent
0c0c86f220
commit
eda483436b
|
@ -88,6 +88,8 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
|
||||||
m_resolvableRoles(),
|
m_resolvableRoles(),
|
||||||
m_enabledPlugins(),
|
m_enabledPlugins(),
|
||||||
m_pendingSortRoleItems(),
|
m_pendingSortRoleItems(),
|
||||||
|
m_hasUnknownIcons(false),
|
||||||
|
m_firstIndexWithoutIcon(0),
|
||||||
m_pendingIndexes(),
|
m_pendingIndexes(),
|
||||||
m_pendingPreviewItems(),
|
m_pendingPreviewItems(),
|
||||||
m_previewJob(),
|
m_previewJob(),
|
||||||
|
@ -328,6 +330,10 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRan
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
|
const int firstInsertedIndex = itemRanges.first().index;
|
||||||
|
m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstInsertedIndex);
|
||||||
|
m_hasUnknownIcons = true;
|
||||||
|
|
||||||
// Determine the sort role synchronously for as many items as possible.
|
// Determine the sort role synchronously for as many items as possible.
|
||||||
if (m_resolvableRoles.contains(m_model->sortRole())) {
|
if (m_resolvableRoles.contains(m_model->sortRole())) {
|
||||||
int insertedCount = 0;
|
int insertedCount = 0;
|
||||||
|
@ -364,6 +370,11 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
|
||||||
|
|
||||||
const bool allItemsRemoved = (m_model->count() == 0);
|
const bool allItemsRemoved = (m_model->count() == 0);
|
||||||
|
|
||||||
|
if (m_hasUnknownIcons) {
|
||||||
|
const int firstRemovedIndex = itemRanges.first().index;
|
||||||
|
m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstRemovedIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_watchedDirs.isEmpty()) {
|
if (!m_watchedDirs.isEmpty()) {
|
||||||
// Don't let KDirWatch watch for removed items
|
// Don't let KDirWatch watch for removed items
|
||||||
if (allItemsRemoved) {
|
if (allItemsRemoved) {
|
||||||
|
@ -445,6 +456,11 @@ void KFileItemModelRolesUpdater::slotItemsMoved(const KItemRange& itemRange, QLi
|
||||||
Q_UNUSED(itemRange);
|
Q_UNUSED(itemRange);
|
||||||
Q_UNUSED(movedToIndexes);
|
Q_UNUSED(movedToIndexes);
|
||||||
|
|
||||||
|
if (m_hasUnknownIcons) {
|
||||||
|
const int firstMovedIndex = itemRange.index;
|
||||||
|
m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstMovedIndex);
|
||||||
|
}
|
||||||
|
|
||||||
// The visible items might have changed.
|
// The visible items might have changed.
|
||||||
startUpdating();
|
startUpdating();
|
||||||
}
|
}
|
||||||
|
@ -812,6 +828,13 @@ void KFileItemModelRolesUpdater::startUpdating()
|
||||||
// Determine the icons for the visible items synchronously.
|
// Determine the icons for the visible items synchronously.
|
||||||
updateVisibleIcons();
|
updateVisibleIcons();
|
||||||
|
|
||||||
|
// Try to do at least a fast icon loading (without determining the
|
||||||
|
// mime type) for all items, to reduce the risk that the user sees
|
||||||
|
// "unknown" icons when scrolling.
|
||||||
|
if (m_hasUnknownIcons) {
|
||||||
|
updateAllIconsFast(MaxBlockTimeout - timer.elapsed());
|
||||||
|
}
|
||||||
|
|
||||||
// A detailed update of the items in and near the visible area
|
// A detailed update of the items in and near the visible area
|
||||||
// only makes sense if sorting is finished.
|
// only makes sense if sorting is finished.
|
||||||
if (m_state == ResolvingSortRole) {
|
if (m_state == ResolvingSortRole) {
|
||||||
|
@ -886,6 +909,37 @@ void KFileItemModelRolesUpdater::updateVisibleIcons()
|
||||||
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
|
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KFileItemModelRolesUpdater::updateAllIconsFast(int timeout)
|
||||||
|
{
|
||||||
|
if (timeout <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QElapsedTimer timer;
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
|
||||||
|
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
|
||||||
|
|
||||||
|
const int count = m_model->count();
|
||||||
|
while (m_firstIndexWithoutIcon < count && timer.elapsed() < timeout) {
|
||||||
|
if (!m_model->data(m_firstIndexWithoutIcon).contains("iconName")) {
|
||||||
|
const KFileItem item = m_model->fileItem(m_firstIndexWithoutIcon);
|
||||||
|
QHash<QByteArray, QVariant> data;
|
||||||
|
data.insert("iconName", item.iconName());
|
||||||
|
m_model->setData(m_firstIndexWithoutIcon, data);
|
||||||
|
}
|
||||||
|
++m_firstIndexWithoutIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_firstIndexWithoutIcon == count) {
|
||||||
|
m_hasUnknownIcons = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
|
||||||
|
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
|
||||||
|
}
|
||||||
|
|
||||||
void KFileItemModelRolesUpdater::startPreviewJob()
|
void KFileItemModelRolesUpdater::startPreviewJob()
|
||||||
{
|
{
|
||||||
m_state = PreviewJobRunning;
|
m_state = PreviewJobRunning;
|
||||||
|
|
|
@ -232,6 +232,12 @@ private:
|
||||||
*/
|
*/
|
||||||
void updateVisibleIcons();
|
void updateVisibleIcons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to load at least preliminary icons (without determining the
|
||||||
|
* mime type) for all items for \a timeout milliseconds.
|
||||||
|
*/
|
||||||
|
void updateAllIconsFast(int timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates previews for the items starting from the first item in
|
* Creates previews for the items starting from the first item in
|
||||||
* m_pendingPreviewItems.
|
* m_pendingPreviewItems.
|
||||||
|
@ -320,6 +326,11 @@ private:
|
||||||
// Items for which the sort role still has to be determined.
|
// Items for which the sort role still has to be determined.
|
||||||
QSet<KFileItem> m_pendingSortRoleItems;
|
QSet<KFileItem> m_pendingSortRoleItems;
|
||||||
|
|
||||||
|
// Determines if the next call of startUpdating() will try to do a fast
|
||||||
|
// icon loading (i.e., without determining the mime type) for all items.
|
||||||
|
bool m_hasUnknownIcons;
|
||||||
|
int m_firstIndexWithoutIcon;
|
||||||
|
|
||||||
// Indexes of items which still have to be handled by
|
// Indexes of items which still have to be handled by
|
||||||
// resolveNextPendingRoles().
|
// resolveNextPendingRoles().
|
||||||
QList<int> m_pendingIndexes;
|
QList<int> m_pendingIndexes;
|
||||||
|
|
Loading…
Reference in a new issue