]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
Merge branch '4.9'
[dolphin.git] / src / panels / places / placespanel.cpp
index 429c5399a88d7eca195ba519950cbced0e951356..3c7f2bb9baf22a4bba776a01abcfc4cd324c90c1 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "placespanel.h"
 
+#include "dolphin_generalsettings.h"
+
 #include <KDebug>
 #include <KDirNotify>
 #include <KIcon>
@@ -33,7 +35,6 @@
 #include <kitemviews/kitemlistcontroller.h>
 #include <kitemviews/kitemlistselectionmanager.h>
 #include <kitemviews/kstandarditem.h>
-#include <kitemviews/kstandarditemlistview.h>
 #include <KMenu>
 #include <KMessageBox>
 #include <KNotification>
@@ -42,6 +43,7 @@
 #include "placesitemlistgroupheader.h"
 #include "placesitemlistwidget.h"
 #include "placesitemmodel.h"
+#include "placesview.h"
 #include <views/draganddrophelper.h>
 #include <QGraphicsSceneDragDropEvent>
 #include <QVBoxLayout>
@@ -52,7 +54,10 @@ PlacesPanel::PlacesPanel(QWidget* parent) :
     m_controller(0),
     m_model(0),
     m_storageSetupFailedUrl(),
-    m_triggerStorageSetupButton()
+    m_triggerStorageSetupButton(),
+    m_itemDropEventIndex(-1),
+    m_itemDropEventMimeData(0),
+    m_itemDropEvent(0)
 {
 }
 
@@ -62,9 +67,27 @@ PlacesPanel::~PlacesPanel()
 
 bool PlacesPanel::urlChanged()
 {
+    if (!url().isValid() || url().protocol().contains("search")) {
+        // Skip results shown by a search, as possible identical
+        // directory names are useless without parent-path information.
+        return false;
+    }
+
+    if (m_controller) {
+        selectClosestItem();
+    }
+
     return true;
 }
 
+void PlacesPanel::readSettings()
+{
+    if (m_controller) {
+       const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1;
+       m_controller->setAutoActivationDelay(delay);
+    }
+}
+
 void PlacesPanel::showEvent(QShowEvent* event)
 {
     if (event->spontaneous()) {
@@ -81,13 +104,16 @@ void PlacesPanel::showEvent(QShowEvent* event)
         connect(m_model, SIGNAL(errorMessage(QString)),
                 this, SIGNAL(errorMessage(QString)));
 
-        KStandardItemListView* view = new KStandardItemListView();
+        PlacesView* view = new PlacesView();
         view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
         view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>());
 
         m_controller = new KItemListController(m_model, view, this);
         m_controller->setSelectionBehavior(KItemListController::SingleSelection);
         m_controller->setSingleClickActivation(true);
+
+       readSettings();
+
         connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
         connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
         connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
@@ -258,6 +284,30 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
         return;
     }
 
+    if (m_model->storageSetupNeeded(index)) {
+        connect(m_model, SIGNAL(storageSetupDone(int,bool)),
+                this, SLOT(slotItemDropEventStorageSetupDone(int,bool)));
+
+        m_itemDropEventIndex = index;
+
+        // Make a full copy of the Mime-Data
+        m_itemDropEventMimeData = new QMimeData;
+        m_itemDropEventMimeData->setText(event->mimeData()->text());
+        m_itemDropEventMimeData->setHtml(event->mimeData()->html());
+        m_itemDropEventMimeData->setUrls(event->mimeData()->urls());
+        m_itemDropEventMimeData->setImageData(event->mimeData()->imageData());
+        m_itemDropEventMimeData->setColorData(event->mimeData()->colorData());
+
+        m_itemDropEvent = new QDropEvent(event->pos().toPoint(),
+                                         event->possibleActions(),
+                                         m_itemDropEventMimeData,
+                                         event->buttons(),
+                                         event->modifiers());
+
+        m_model->requestStorageSetup(index);
+        return;
+    }
+
     KUrl destUrl = m_model->placesItem(index)->url();
     QDropEvent dropEvent(event->pos().toPoint(),
                          event->possibleActions(),
@@ -268,6 +318,27 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
     DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent);
 }
 
+void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success)
+{
+    disconnect(m_model, SIGNAL(storageSetupDone(int,bool)),
+               this, SLOT(slotItemDropEventStorageSetupDone(int,bool)));
+
+    if ((index == m_itemDropEventIndex) && m_itemDropEvent && m_itemDropEventMimeData) {
+        if (success) {
+            KUrl destUrl = m_model->placesItem(index)->url();
+
+            DragAndDropHelper::dropUrls(KFileItem(), destUrl, m_itemDropEvent);
+        }
+
+        delete m_itemDropEventMimeData;
+        delete m_itemDropEvent;
+
+        m_itemDropEventIndex = -1;
+        m_itemDropEventMimeData = 0;
+        m_itemDropEvent = 0;
+    }
+}
+
 void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
     m_model->dropMimeDataBefore(index, event->mimeData());