- if (m_pendingSortRoleItems.count() != m_pendingSortRoleIndexes.count()) {
- // The indexes with missing sort role have to be updated.
- m_pendingSortRoleIndexes.clear();
- foreach (const KFileItem& item, m_pendingSortRoleItems) {
- const int index = m_model->index(item);
- if (index < 0) {
- m_pendingSortRoleItems.remove(item);
- } else {
- m_pendingSortRoleIndexes.append(index);
- }
+ QHash<QByteArray, QVariant> data = m_model->data(index);
+ QVector<QPixmap> pixmaps = data["hoverSequencePixmaps"].value<QVector<QPixmap>>();
+ const int loadedIndex = pixmaps.size();
+
+ float wap = m_hoverSequencePreviewJob->sequenceIndexWraparoundPoint();
+ if (!m_hoverSequencePreviewJob->handlesSequences()) {
+ wap = 1.0f;
+ }
+ if (wap >= 0.0f) {
+ data["hoverSequenceWraparoundPoint"] = wap;
+ m_model->setData(index, data);
+ }
+
+ // For hover sequence previews we never load index 0, because that's just the regular preview
+ // in "iconPixmap". But that means we'll load index 1 even for thumbnailers that don't support
+ // sequences, in which case we can just throw away the preview because it's the same as for
+ // index 0. Unfortunately we can't find it out earlier :(
+ if (wap < 0.0f || loadedIndex < static_cast<int>(wap)) {
+ // Add the preview to the model data
+
+ const QPixmap scaledPixmap = transformPreviewPixmap(pixmap);
+
+ pixmaps.append(scaledPixmap);
+ data["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps);
+
+ m_model->setData(index, data);
+
+ const auto loadedIt = std::find(m_hoverSequenceLoadedItems.begin(), m_hoverSequenceLoadedItems.end(), item);
+ if (loadedIt == m_hoverSequenceLoadedItems.end()) {
+ m_hoverSequenceLoadedItems.push_back(item);
+ trimHoverSequenceLoadedItems();
+ }
+ }
+
+ m_hoverSequenceNumSuccessiveFailures = 0;
+}
+
+void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem &item)
+{
+ const int index = m_model->index(item);
+ if (index < 0) {
+ return;
+ }
+
+ static const int numRetries = 2;
+
+ QHash<QByteArray, QVariant> data = m_model->data(index);
+ QVector<QPixmap> pixmaps = data["hoverSequencePixmaps"].value<QVector<QPixmap>>();
+
+ qCDebug(DolphinDebug).nospace() << "Failed to generate hover sequence preview #" << pixmaps.size() << " for file " << item.url().toString() << " (attempt "
+ << (m_hoverSequenceNumSuccessiveFailures + 1) << "/" << (numRetries + 1) << ")";
+
+ if (m_hoverSequenceNumSuccessiveFailures >= numRetries) {
+ // Give up and simply duplicate the previous sequence image (if any)
+
+ pixmaps.append(pixmaps.empty() ? QPixmap() : pixmaps.last());
+ data["hoverSequencePixmaps"] = QVariant::fromValue(pixmaps);
+
+ if (!data.contains("hoverSequenceWraparoundPoint")) {
+ // hoverSequenceWraparoundPoint is only available when PreviewJob succeeds, so unless
+ // it has previously succeeded, it's best to assume that it just doesn't handle
+ // sequences instead of trying to load the next image indefinitely.
+ data["hoverSequenceWraparoundPoint"] = 1.0f;