]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Give visual feedback when dragging with the cursor also. If you are not able to drop...
[dolphin.git] / src / dolphinview.cpp
index c2ea5ff2847dcbc71b3292327eceee0d3dc08c40..8502bfd2268be7bb3d0ab27d967905b74341c91e 100644 (file)
@@ -29,7 +29,6 @@
 #include <QBoxLayout>
 #include <QTimer>
 #include <QScrollBar>
-#include <QClipboard>
 
 #include <kcolorscheme.h>
 #include <kdirlister.h>
 #include <kio/deletejob.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
+#include <kjob.h>
+#include <kmenu.h>
 #include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
 #include <kurl.h>
 
+#include "dolphindropcontroller.h"
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
@@ -75,7 +77,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 +131,10 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
+    if (m_previewJob != 0) {
+        m_previewJob->kill();
+        m_previewJob = 0;
+    }
 }
 
 const KUrl& DolphinView::url() const
@@ -313,7 +320,13 @@ bool DolphinView::supportsCategorizedSorting() const
 
 void DolphinView::selectAll()
 {
-    itemView()->selectAll();
+    QAbstractItemView* view = itemView();
+    // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
+    // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
+    // selection instead of selecting all items. This is bypassed for KDE 4.0
+    // by invoking clearSelection() first.
+    view->clearSelection();
+    view->selectAll();
 }
 
 void DolphinView::invertSelection()
@@ -568,17 +581,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;
     }
@@ -737,6 +758,7 @@ void DolphinView::dropUrls(const KUrl::List& urls,
                            const KUrl& destPath,
                            const KFileItem& destItem)
 {
+    Q_ASSERT(!urls.isEmpty());
     const KUrl& destination = !destItem.isNull() && destItem.isDir() ?
                               destItem.url() : destPath;
     const KUrl sourceDir = KUrl(urls.first().directory());
@@ -748,7 +770,11 @@ void DolphinView::dropUrls(const KUrl::List& urls,
 void DolphinView::dropUrls(const KUrl::List& urls,
                            const KUrl& destination)
 {
-    emit urlsDropped(urls, destination);
+    DolphinDropController dropController(this);
+    // forward doingOperation signal up to the mainwindow
+    connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
+            this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)));
+    dropController.dropUrls(urls, destination);
 }
 
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
@@ -870,7 +896,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);
 
@@ -1107,6 +1135,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();