summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-03-21 11:08:59 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-03-21 11:12:01 (GMT)
commitef2ef83d762f4c2bdd0c13eb87759c58b1609957 (patch)
tree8c839b349dd6f1c8e58cedc660fe27e85b28f4ed
parent7120e0166dc886e0a7fcbe03b8b5fb46137b5e75 (diff)
Prevent flickering when updating items
When downloading images from e.g. the camera-IO-slave the files will be downloaded as *.part files and renamed afterwards. The renaming results in an undetermined mimetype and hence the probably already available preview or icon gets replaced by a dummy icon. The patch fixes this by keeping the old values as long until they have been resolved by KFileItemModelRolesUpdater.
-rw-r--r--dolphin/src/kitemviews/kfileitemmodel.cpp11
-rw-r--r--dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp7
2 files changed, 13 insertions, 5 deletions
diff --git a/dolphin/src/kitemviews/kfileitemmodel.cpp b/dolphin/src/kitemviews/kfileitemmodel.cpp
index b40255f..d8cbece 100644
--- a/dolphin/src/kitemviews/kfileitemmodel.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodel.cpp
@@ -776,7 +776,15 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
const int index = m_items.value(oldItem.url(), -1);
if (index >= 0) {
m_itemData[index]->item = newItem;
- m_itemData[index]->values = retrieveData(newItem);
+
+ // Keep old values as long as possible if they could not retrieved synchronously yet.
+ // The update of the values will be done asynchronously by KFileItemModelRolesUpdater.
+ QHashIterator<QByteArray, QVariant> it(retrieveData(newItem));
+ while (it.hasNext()) {
+ it.next();
+ m_itemData[index]->values.insert(it.key(), it.value());
+ }
+
m_items.remove(oldItem.url());
m_items.insert(newItem.url(), index);
indexes.append(index);
@@ -1137,7 +1145,6 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item)
// KFileItem::iconName() can be very expensive if the MIME-type is unknown
// and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
QHash<QByteArray, QVariant> data;
- data.insert("iconPixmap", QPixmap());
data.insert("url", item.url());
const bool isDir = item.isDir();
diff --git a/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp b/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
index 06749f9..7b0d75d 100644
--- a/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
+++ b/dolphin/src/kitemviews/kfileitemmodelrolesupdater.cpp
@@ -91,9 +91,9 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
// Use a timer to prevent that each call of slotItemsChanged() results in a synchronous
- // resolving of the roles. Postpone the resolving until no update has been done for 2 seconds.
+ // resolving of the roles. Postpone the resolving until no update has been done for 1 second.
m_changedItemsTimer = new QTimer(this);
- m_changedItemsTimer->setInterval(2000);
+ m_changedItemsTimer->setInterval(1000);
m_changedItemsTimer->setSingleShot(true);
connect(m_changedItemsTimer, SIGNAL(timeout()), this, SLOT(resolveChangedItems()));
}
@@ -418,6 +418,7 @@ void KFileItemModelRolesUpdater::resolveChangedItems()
itemRanges.append(KItemRange(index, 1));
}
}
+ m_changedItems.clear();
startUpdating(itemRanges);
}
@@ -711,7 +712,7 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(const KFileItem& item, Resol
data.insert("iconName", item.iconName());
if (m_clearPreviews) {
- data.insert("iconPixmap", QString());
+ data.insert("iconPixmap", QPixmap());
}
disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),