]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Forgot to modify the code for category selection. Fixed.
[dolphin.git] / src / dolphinview.cpp
index 0b8fe5883dfb7c2b836fca40fdd6657abacddebb..dcabe8329ebd0f8096f4c09a4ec7f5f26528df0d 100644 (file)
@@ -39,6 +39,7 @@
 #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>
@@ -75,7 +76,8 @@ DolphinView::DolphinView(QWidget* parent,
     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);
@@ -128,6 +130,10 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
+    if (m_previewJob != 0) {
+        m_previewJob->kill();
+        m_previewJob = 0;
+    }
 }
 
 const KUrl& DolphinView::url() const
@@ -147,6 +153,7 @@ void DolphinView::setActive(bool active)
     }
 
     m_active = active;
+    m_selectionModel->clearSelection();
 
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (active) {
@@ -567,17 +574,25 @@ void DolphinView::triggerItem(const KFileItem& item)
 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());
-    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;
     }
@@ -816,7 +831,7 @@ void DolphinView::updateCutItems()
 
 void DolphinView::showHoverInformation(const KFileItem& item)
 {
-    if (hasSelection()) {
+    if (hasSelection() || !m_active) {
         return;
     }
 
@@ -825,7 +840,9 @@ void DolphinView::showHoverInformation(const KFileItem& item)
 
 void DolphinView::clearHoverInformation()
 {
-    emit requestItemInfo(KFileItem());
+    if (m_active) {
+        emit requestItemInfo(KFileItem());
+    }
 }
 
 
@@ -867,7 +884,9 @@ void DolphinView::createView()
         m_selectionModel = view->selectionModel();
     }
 
-    m_selectionModel->setParent(this);  //Reparent the selection model.  We do not want it to be deleted when we delete the model
+    // reparent the selection model, as it should not be deleted
+    // when deleting the model
+    m_selectionModel->setParent(this);
 
     view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
@@ -1104,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();