]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Kill any running preview jobs before starting a new one
authorFrank Reininghaus <frank78ac@googlemail.com>
Mon, 6 Jan 2014 19:15:02 +0000 (20:15 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Mon, 6 Jan 2014 19:15:11 +0000 (20:15 +0100)
If loading a preview takes long, it was possible before this commit
that a preview for a new item was requested before the first preview
was shown. In that case, there was a race condition, and the first
preview to arrive stayed in the Information Panel.

This commit fixes this by keeping a pointer to the preview job and
killing it before starting a new one.

BUG: 250787
FIXED-IN: 4.12.1
REVIEW: 114561

src/panels/information/informationpanelcontent.cpp
src/panels/information/informationpanelcontent.h

index d63f23b13f2b65ef079ed237eb43142bb2e9e765..f2f7378d7f675a0f4afc386056b332b94a83f5e9 100644 (file)
@@ -64,7 +64,7 @@
 InformationPanelContent::InformationPanelContent(QWidget* parent) :
     QWidget(parent),
     m_item(),
-    m_pendingPreview(false),
+    m_previewJob(0),
     m_outdatedPreviewTimer(0),
     m_preview(0),
     m_phononWidget(0),
@@ -159,7 +159,11 @@ InformationPanelContent::~InformationPanelContent()
 
 void InformationPanelContent::showItem(const KFileItem& item)
 {
-    m_pendingPreview = false;
+    // If there is a preview job, kill it to prevent that we have jobs for
+    // multiple items running, and thus a race condition (bug 250787).
+    if (m_previewJob) {
+        m_previewJob->kill();
+    }
 
     const KUrl itemUrl = item.url();
     const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty();
@@ -175,7 +179,6 @@ void InformationPanelContent::showItem(const KFileItem& item)
             m_preview->setPixmap(icon);
         } else {
             // try to get a preview pixmap from the item...
-            m_pendingPreview = true;
 
             // Mark the currently shown preview as outdated. This is done
             // with a small delay to prevent a flickering when the next preview
@@ -186,16 +189,16 @@ void InformationPanelContent::showItem(const KFileItem& item)
                 m_outdatedPreviewTimer->start();
             }
 
-            KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
-            job->setScaleType(KIO::PreviewJob::Unscaled);
-            job->setIgnoreMaximumSize(item.isLocalFile());
-            if (job->ui()) {
-                job->ui()->setWindow(this);
+            m_previewJob = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
+            m_previewJob->setScaleType(KIO::PreviewJob::Unscaled);
+            m_previewJob->setIgnoreMaximumSize(item.isLocalFile());
+            if (m_previewJob->ui()) {
+                m_previewJob->ui()->setWindow(this);
             }
 
-            connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
+            connect(m_previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
                     this, SLOT(showPreview(KFileItem,QPixmap)));
-            connect(job, SIGNAL(failed(KFileItem)),
+            connect(m_previewJob, SIGNAL(failed(KFileItem)),
                     this, SLOT(showIcon(KFileItem)));
         }
     }
@@ -227,7 +230,11 @@ void InformationPanelContent::showItem(const KFileItem& item)
 
 void InformationPanelContent::showItems(const KFileItemList& items)
 {
-    m_pendingPreview = false;
+    // If there is a preview job, kill it to prevent that we have jobs for
+    // multiple items running, and thus a race condition (bug 250787).
+    if (m_previewJob) {
+        m_previewJob->kill();
+    }
 
     KIconLoader iconLoader;
     QPixmap icon = iconLoader.loadIcon("dialog-information",
@@ -315,7 +322,6 @@ void InformationPanelContent::configureSettings(const QList<QAction*>& customCon
 void InformationPanelContent::showIcon(const KFileItem& item)
 {
     m_outdatedPreviewTimer->stop();
-    m_pendingPreview = false;
     if (!applyPlace(item.targetUrl())) {
         KIcon icon(item.iconName(), KIconLoader::global(), item.overlays());
         m_preview->setPixmap(icon.pixmap(KIconLoader::SizeEnormous));
@@ -327,12 +333,10 @@ void InformationPanelContent::showPreview(const KFileItem& item,
 {
     m_outdatedPreviewTimer->stop();
     Q_UNUSED(item);
-    if (m_pendingPreview) {
-        QPixmap p = pixmap;
-        KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop);
-        m_preview->setPixmap(p);
-        m_pendingPreview = false;
-    }
+
+    QPixmap p = pixmap;
+    KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop);
+    m_preview->setPixmap(p);
 }
 
 void InformationPanelContent::markOutdatedPreview()
index ed9200aef4cd0d1dbb175a6b769c1678ae3e96e8..cad6b51b0f64b098296b09df7764473d938a6310 100644 (file)
@@ -26,6 +26,8 @@
 #include <KUrl>
 #include <KVBox>
 
+#include <QPointer>
+
 class KFileItemList;
 class PhononWidget;
 class PixmapViewer;
@@ -35,6 +37,10 @@ class QString;
 class QLabel;
 class QScrollArea;
 
+namespace KIO {
+    class PreviewJob;
+}
+
 #ifndef HAVE_NEPOMUK
 class KFileMetaDataWidget;
 #else
@@ -135,7 +141,7 @@ private:
 private:
     KFileItem m_item;
 
-    bool m_pendingPreview;
+    QPointer<KIO::PreviewJob> m_previewJob;
     QTimer* m_outdatedPreviewTimer;
 
     PixmapViewer* m_preview;