]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Added the Trash KCM to Dolphin, it's visible in the Settings Dialog, in the 'Trash...
[dolphin.git] / src / dolphinview.cpp
index cfe447e37c4042cfaff22db233d1f1c7c4db39ac..4fc3248c81a5085ee2e58224ba10f557ff3f6d5b 100644 (file)
@@ -103,7 +103,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_toolTipManager(0),
     m_rootUrl(),
     m_currentItemUrl(),
-    m_expandedViews()
+    m_expandedDragSource(0)
 {
     m_topLayout = new QVBoxLayout(this);
     m_topLayout->setSpacing(0);
@@ -117,8 +117,8 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_controller, SIGNAL(requestUrlChange(const KUrl&)),
             this, SLOT(slotRequestUrlChange(const KUrl&)));
 
-    connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
-            this, SLOT(openContextMenu(const QPoint&)));
+    connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
+            this, SLOT(openContextMenu(const QPoint&, const QList<QAction*>&)));
     connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
             this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
     connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
@@ -149,7 +149,9 @@ DolphinView::DolphinView(QWidget* parent,
 
 DolphinView::~DolphinView()
 {
-    deleteExpandedViews();
+    kDebug() << "Deleted view " << m_expandedDragSource;
+    delete m_expandedDragSource;
+    m_expandedDragSource = 0;
 }
 
 const KUrl& DolphinView::url() const
@@ -847,13 +849,16 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::MouseButtonPress:
-        if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 0)) {
+        kDebug() << "m_expandedDragSource = " << m_expandedDragSource;
+        if ((watched == itemView()->viewport()) && (m_expandedDragSource != 0)) {
             // Listening to a mousebutton press event to delete expanded views is a
             // workaround, as it seems impossible for the FolderExpander to know when
             // a dragging outside a view has been finished. However it works quite well:
             // A mousebutton press event indicates that a drag operation must be
             // finished already.
-            deleteExpandedViews();
+            kDebug() << "Deleted view " << m_expandedDragSource;
+            m_expandedDragSource->deleteLater();
+            m_expandedDragSource = 0;
         }
         break;
 
@@ -906,7 +911,8 @@ void DolphinView::emitSelectionChangedSignal()
     emit selectionChanged(DolphinView::selectedItems());
 }
 
-void DolphinView::openContextMenu(const QPoint& pos)
+void DolphinView::openContextMenu(const QPoint& pos,
+                                  const QList<QAction*>& customActions)
 {
     KFileItem item;
     if (isColumnViewActive()) {
@@ -924,7 +930,7 @@ void DolphinView::openContextMenu(const QPoint& pos)
     }
 
     m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192
-    emit requestContextMenu(item, url());
+    emit requestContextMenu(item, url(), customActions);
     m_isContextMenuOpen = false;
 }
 
@@ -1061,6 +1067,29 @@ bool DolphinView::itemsExpandable() const
     return (m_detailsView != 0) && m_detailsView->itemsExpandable();
 }
 
+void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
+{
+    if (view == 0)
+        return;
+
+    if (DragAndDropHelper::instance().isDragSource(view)) {
+        kDebug() << "Is current drag source";
+        // We must store for later deletion.
+        if (m_expandedDragSource != 0) {
+            // The old stored view is obviously not the drag source anymore.
+            kDebug() << "Deleted old view " << m_expandedDragSource;
+            m_expandedDragSource->deleteLater();
+            m_expandedDragSource = 0;
+        }
+        view->hide();
+        m_expandedDragSource = view;
+    }
+    else {
+        kDebug() << "Deleted new view " << view;
+        view->deleteLater();
+    }
+}
+
 void DolphinView::emitContentsMoved()
 {
     // only emit the contents moved signal if:
@@ -1113,16 +1142,6 @@ void DolphinView::restoreCurrentItem()
     }
 }
 
-void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view)
-{
-    // Deleting a view that is the root of a drag operation is not allowed, otherwise
-    // the dragging gets automatically cancelled by Qt. So before entering a new
-    // directory, the current view is remembered in m_expandedViews and deleted
-    // later when the drag operation has been finished (see DolphinView::eventFilter()).
-    m_expandedViews.append(view);
-    m_controller->triggerItem(index);
-}
-
 void DolphinView::loadDirectory(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
@@ -1285,8 +1304,13 @@ void DolphinView::createView()
 
         FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
         folderExpander->setEnabled(enabled);
-        connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)),
-                this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*)));
+        connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
+                m_controller, SLOT(triggerItem(const QModelIndex&)));
+    }
+    else {
+        // Listen out for requests to delete the current column.
+        connect(m_columnView, SIGNAL(requestColumnDeletion(QAbstractItemView*)),
+                this, SLOT(deleteWhenNotDragSource(QAbstractItemView*)));
     }
 
     m_controller->setItemView(view);
@@ -1342,29 +1366,18 @@ void DolphinView::deleteView()
         m_topLayout->removeWidget(view);
         view->close();
 
+        // m_previewGenerator's parent is not always destroyed, and we
+        // don't want two active at once - manually delete.
+        delete m_previewGenerator;
+        m_previewGenerator = 0;
+
         disconnect(view);
         m_controller->disconnect(view);
         view->disconnect();
 
-        bool deleteView = true;
-        foreach (const QAbstractItemView* expandedView, m_expandedViews) {
-            if (view == expandedView) {
-                // the current view got already expanded and must stay alive
-                // until the dragging has been completed
-                deleteView = false;
-                break;
-            }
-        }
-        if (deleteView) {
-            view->deleteLater();
-        }
+        deleteWhenNotDragSource(view);
         view = 0;
 
-        // m_previewGenerator's parent is not always destroyed, and we
-        // don't want two active at once - manually delete.
-        delete m_previewGenerator;
-        m_previewGenerator = 0;
-
         m_iconsView = 0;
         m_detailsView = 0;
         m_columnView = 0;
@@ -1434,17 +1447,6 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const
     return list;
 }
 
-void DolphinView::deleteExpandedViews()
-{
-    const QAbstractItemView* view = itemView();
-    foreach (QAbstractItemView* expandedView, m_expandedViews) {
-        if (expandedView != view) {
-            expandedView->deleteLater();
-        }
-    }
-    m_expandedViews.clear();
-}
-
 QMimeData* DolphinView::selectionMimeData() const
 {
     if (isColumnViewActive()) {