]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fixed issue that turning off the preview during the preview job still was active...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 11 Dec 2007 19:19:44 +0000 (19:19 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 11 Dec 2007 19:19:44 +0000 (19:19 +0000)
TODO for 4.1: provide a preview helper class which can be shared between DolphinView and the special use case of DolphinColumnViewWidget

BUG: 153816

svn path=/trunk/KDE/kdebase/apps/; revision=747348

src/dolphincolumnwidget.cpp
src/dolphincolumnwidget.h
src/dolphinview.cpp
src/dolphinview.h

index ad18f03bb8ac0b4f5b03f673a4501bbec58beacb..8872dea3842bfda7e7db284805a0db89c48bf1a9 100644 (file)
@@ -35,6 +35,7 @@
 #include <kfileitem.h>
 #include <kio/previewjob.h>
 #include <kiconeffect.h>
 #include <kfileitem.h>
 #include <kio/previewjob.h>
 #include <kiconeffect.h>
+#include <kjob.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 
@@ -60,6 +61,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     m_dirLister(0),
     m_dolphinModel(0),
     m_proxyModel(0),
     m_dirLister(0),
     m_dolphinModel(0),
     m_proxyModel(0),
+    m_previewJob(0),
     m_dragging(false),
     m_dropRect()
 {
     m_dragging(false),
     m_dropRect()
 {
@@ -132,6 +134,11 @@ DolphinColumnWidget::~DolphinColumnWidget()
     delete m_dolphinModel;
     m_dolphinModel = 0;
     m_dirLister = 0; // deleted by m_dolphinModel
     delete m_dolphinModel;
     m_dolphinModel = 0;
     m_dirLister = 0; // deleted by m_dolphinModel
+
+    if (m_previewJob != 0) {
+        m_previewJob->kill();
+        m_previewJob = 0;
+    }
 }
 
 void DolphinColumnWidget::setDecorationSize(const QSize& size)
 }
 
 void DolphinColumnWidget::setDecorationSize(const QSize& size)
@@ -356,19 +363,27 @@ void DolphinColumnWidget::generatePreviews(const KFileItemList& items)
     // for generatePreviews(), showPreview() and isCutItem()
 
     if (m_view->m_controller->dolphinView()->showPreview()) {
     // for generatePreviews(), showPreview() and isCutItem()
 
     if (m_view->m_controller->dolphinView()->showPreview()) {
-        KIO::PreviewJob* job = KIO::filePreview(items, 128);
-        connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
-                this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
+        if (m_previewJob != 0) {
+            m_previewJob->kill();
+            m_previewJob = 0;
+        }
+
+        m_previewJob = KIO::filePreview(items, 128);
+        connect(m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
+                this, SLOT(replaceIcon(const KFileItem&, const QPixmap&)));
+        connect(m_previewJob, SIGNAL(finished(KJob*)),
+                this, SLOT(slotPreviewJobFinished(KJob*)));
     }
 }
 
     }
 }
 
-void DolphinColumnWidget::showPreview(const KFileItem& item, const QPixmap& pixmap)
+void DolphinColumnWidget::replaceIcon(const KFileItem& item, const QPixmap& pixmap)
 {
     // TODO: same implementation as in DolphinView; create helper class
     // for generatePreviews(), showPreview() and isCutItem()
 
     Q_ASSERT(!item.isNull());
 {
     // TODO: same implementation as in DolphinView; create helper class
     // for generatePreviews(), showPreview() and isCutItem()
 
     Q_ASSERT(!item.isNull());
-    if (item.url().directory() != m_dirLister->url().path()) {
+    const bool showPreview = m_view->m_controller->dolphinView()->showPreview();
+    if (!showPreview || (item.url().directory() != m_dirLister->url().path())) {
         // the preview job is still working on items of an older URL, hence
         // the item is not part of the directory model anymore
         return;
         // the preview job is still working on items of an older URL, hence
         // the item is not part of the directory model anymore
         return;
@@ -394,6 +409,12 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index)
     m_view->m_controller->emitItemEntered(item);
 }
 
     m_view->m_controller->emitItemEntered(item);
 }
 
+void DolphinColumnWidget::slotPreviewJobFinished(KJob* job)
+{
+    Q_ASSERT(job == m_previewJob);
+    m_previewJob = 0;
+}
+
 void DolphinColumnWidget::activate()
 {
     setFocus(Qt::OtherFocusReason);
 void DolphinColumnWidget::activate()
 {
     setFocus(Qt::OtherFocusReason);
index 5cb7e1168d3576c353c0654ac755e95da7b8c6d3..87024626942b034fe637e0831c50b28f586ca884 100644 (file)
@@ -31,9 +31,14 @@ class DolphinColumnView;
 class DolphinModel;
 class DolphinSortFilterProxyModel;
 class KDirLister;
 class DolphinModel;
 class DolphinSortFilterProxyModel;
 class KDirLister;
+class KJob;
 class KFileItem;
 class KFileItemList;
 class QPixmap;
 class KFileItem;
 class KFileItemList;
 class QPixmap;
+namespace KIO
+{
+    class PreviewJob;
+}
 
 /**
  * Represents one column inside the DolphinColumnView and has been
 
 /**
  * Represents one column inside the DolphinColumnView and has been
@@ -124,10 +129,16 @@ private slots:
      * Replaces the icon of the item \a item by the preview pixmap
      * \a pixmap.
      */
      * Replaces the icon of the item \a item by the preview pixmap
      * \a pixmap.
      */
-    void showPreview(const KFileItem& item, const QPixmap& pixmap);
+    void replaceIcon(const KFileItem& item, const QPixmap& pixmap);
 
     void slotEntered(const QModelIndex& index);
 
 
     void slotEntered(const QModelIndex& index);
 
+    /**
+     * Is invoked when the preview job has been finished and
+     * set m_previewJob to 0.
+     */
+    void slotPreviewJobFinished(KJob* job);
+
 private:
     /** Used by DolphinColumnWidget::setActive(). */
     void activate();
 private:
     /** Used by DolphinColumnWidget::setActive(). */
     void activate();
@@ -157,6 +168,8 @@ private:
     DolphinModel* m_dolphinModel;
     DolphinSortFilterProxyModel* m_proxyModel;
 
     DolphinModel* m_dolphinModel;
     DolphinSortFilterProxyModel* m_proxyModel;
 
+    KIO::PreviewJob* m_previewJob;
+
     bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
     QRect m_dropRect;  // TODO: remove this property when the issue #160611 is solved in Qt 4.4
 };
     bool m_dragging;   // TODO: remove this property when the issue #160611 is solved in Qt 4.4
     QRect m_dropRect;  // TODO: remove this property when the issue #160611 is solved in Qt 4.4
 };
index d4609d3828d3619172195cb46afd3bf862fbadb7..dcabe8329ebd0f8096f4c09a4ec7f5f26528df0d 100644 (file)
@@ -39,6 +39,7 @@
 #include <kio/deletejob.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
 #include <kio/deletejob.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
+#include <kjob.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
@@ -75,7 +76,8 @@ DolphinView::DolphinView(QWidget* parent,
     m_selectionModel(0),
     m_dolphinModel(dolphinModel),
     m_dirLister(dirLister),
     m_selectionModel(0),
     m_dolphinModel(dolphinModel),
     m_dirLister(dirLister),
-    m_proxyModel(proxyModel)
+    m_proxyModel(proxyModel),
+    m_previewJob(0)
 {
     setFocusPolicy(Qt::StrongFocus);
     m_topLayout = new QVBoxLayout(this);
 {
     setFocusPolicy(Qt::StrongFocus);
     m_topLayout = new QVBoxLayout(this);
@@ -128,6 +130,10 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
 
 DolphinView::~DolphinView()
 {
+    if (m_previewJob != 0) {
+        m_previewJob->kill();
+        m_previewJob = 0;
+    }
 }
 
 const KUrl& DolphinView::url() const
 }
 
 const KUrl& DolphinView::url() const
@@ -568,17 +574,25 @@ void DolphinView::triggerItem(const KFileItem& item)
 void DolphinView::generatePreviews(const KFileItemList& items)
 {
     if (m_controller->dolphinView()->showPreview()) {
 void DolphinView::generatePreviews(const KFileItemList& items)
 {
     if (m_controller->dolphinView()->showPreview()) {
-        KIO::PreviewJob* job = KIO::filePreview(items, 128);
-        connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
-                this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
+        if (m_previewJob != 0) {
+            m_previewJob->kill();
+            m_previewJob = 0;
+        }
+
+        m_previewJob = KIO::filePreview(items, 128);
+        connect(m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
+                this, SLOT(replaceIcon(const KFileItem&, const QPixmap&)));
+        connect(m_previewJob, SIGNAL(finished(KJob*)),
+                this, SLOT(slotPreviewJobFinished(KJob*)));
     }
 }
 
     }
 }
 
-void DolphinView::showPreview(const KFileItem& item, const QPixmap& pixmap)
+void DolphinView::replaceIcon(const KFileItem& item, const QPixmap& pixmap)
 {
     Q_ASSERT(!item.isNull());
 {
     Q_ASSERT(!item.isNull());
-    if (item.url().directory() != m_dirLister->url().path()) {
-        // the preview job is still working on items of an older URL, hence
+    if (!m_showPreview || (item.url().directory() != m_dirLister->url().path())) {
+        // the preview has been deactivated in the meanwhile or the preview
+        // job is still working on items of an older URL, hence
         // the item is not part of the directory model anymore
         return;
     }
         // the item is not part of the directory model anymore
         return;
     }
@@ -1109,6 +1123,12 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
     }
 }
 
+void DolphinView::slotPreviewJobFinished(KJob* job)
+{
+    Q_ASSERT(job == m_previewJob);
+    m_previewJob = 0;
+}
+
 void DolphinView::cutSelectedItems()
 {
     QMimeData* mimeData = new QMimeData();
 void DolphinView::cutSelectedItems()
 {
     QMimeData* mimeData = new QMimeData();
index 508862e9c5ba1fffa87d3456b7ccaddf97ed9998..3cd7860f1d83b0c576b01659c8ed97aaa451f62f 100644 (file)
@@ -52,6 +52,10 @@ class DolphinMainWindow;
 class DolphinSortFilterProxyModel;
 class QModelIndex;
 class ViewProperties;
 class DolphinSortFilterProxyModel;
 class QModelIndex;
 class ViewProperties;
+namespace KIO
+{
+    class PreviewJob;
+}
 
 /**
  * @short Represents a view for the directory content.
 
 /**
  * @short Represents a view for the directory content.
@@ -541,7 +545,7 @@ private slots:
      * Replaces the icon of the item \a item by the preview pixmap
      * \a pixmap.
      */
      * Replaces the icon of the item \a item by the preview pixmap
      * \a pixmap.
      */
-    void showPreview(const KFileItem& item, const QPixmap& pixmap);
+    void replaceIcon(const KFileItem& item, const QPixmap& pixmap);
 
     void emitSelectionChangedSignal();
 
 
     void emitSelectionChangedSignal();
 
@@ -614,6 +618,12 @@ private slots:
      */
     void slotDeleteFileFinished(KJob* job);
 
      */
     void slotDeleteFileFinished(KJob* job);
 
+    /**
+     * Is invoked when the preview job has been finished and
+     * set m_previewJob to 0.
+     */
+    void slotPreviewJobFinished(KJob* job);
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
@@ -696,6 +706,8 @@ private:
     KDirLister* m_dirLister;
     DolphinSortFilterProxyModel* m_proxyModel;
 
     KDirLister* m_dirLister;
     DolphinSortFilterProxyModel* m_proxyModel;
 
+    KIO::PreviewJob* m_previewJob;
+
     QList<CutItem> m_cutItemsCache;
 
     KUrl m_rootUrl;
     QList<CutItem> m_cutItemsCache;
 
     KUrl m_rootUrl;