]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
Allow compiling Dolphin with KF5
[dolphin.git] / src / panels / places / placespanel.cpp
index e23732c97817f69b4a673bafe4d43cb3b6061b77..1f4d3d4b72a598b6f6e0a3b58364cc155a931de9 100644 (file)
@@ -30,7 +30,9 @@
 #include <KIcon>
 #include <KIO/Job>
 #include <KIO/JobUiDelegate>
+#include <KJobWidgets>
 #include <KLocale>
+#include <KIconLoader>
 #include <kitemviews/kitemlistcontainer.h>
 #include <kitemviews/kitemlistcontroller.h>
 #include <kitemviews/kitemlistselectionmanager.h>
@@ -48,6 +50,7 @@
 #include <QGraphicsSceneDragDropEvent>
 #include <QVBoxLayout>
 #include <QShowEvent>
+#include <QMimeData>
 
 PlacesPanel::PlacesPanel(QWidget* parent) :
     Panel(parent),
@@ -262,23 +265,34 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
             emptyTrash();
         } else if (action == addAction) {
             addEntry();
-        } else if (action == editAction) {
-            editEntry(index);
-        } else if (action == removeAction) {
-            m_model->removeItem(index);
-        } else if (action == hideAction) {
-            item->setHidden(hideAction->isChecked());
-        } else if (action == openInNewTabAction) {
-            const KUrl url = m_model->item(index)->dataValue("url").value<KUrl>();
-            emit placeMiddleClicked(url);
         } else if (action == showAllAction) {
             m_model->setHiddenItemsShown(showAllAction->isChecked());
-        } else if (action == teardownAction) {
-            m_model->requestTeardown(index);
-        } else if (action == ejectAction) {
-            m_model->requestEject(index);
         } else if (iconSizeActionMap.contains(action)) {
             m_view->setIconSize(iconSizeActionMap.value(action));
+        } else {
+            // The index might have changed if devices were added/removed while
+            // the context menu was open.
+            index = m_model->index(item);
+            if (index < 0) {
+                // The item is not in the model any more, probably because it was an
+                // external device that has been removed while the context menu was open.
+                return;
+            }
+
+            if (action == editAction) {
+                editEntry(index);
+            } else if (action == removeAction) {
+                m_model->removeItem(index);
+            } else if (action == hideAction) {
+                item->setHidden(hideAction->isChecked());
+            } else if (action == openInNewTabAction) {
+                const KUrl url = m_model->item(index)->dataValue("url").value<KUrl>();
+                emit placeMiddleClicked(url);
+            } else if (action == teardownAction) {
+                m_model->requestTeardown(index);
+            } else if (action == ejectAction) {
+                m_model->requestEject(index);
+            }
         }
     }
 
@@ -321,6 +335,12 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
         return;
     }
 
+    const PlacesItem* destItem = m_model->placesItem(index);
+    const PlacesItem::GroupType group = destItem->groupType();
+    if (group == PlacesItem::SearchForType || group == PlacesItem::RecentlyAccessedType) {
+        return;
+    }
+
     if (m_model->storageSetupNeeded(index)) {
         connect(m_model, SIGNAL(storageSetupDone(int,bool)),
                 this, SLOT(slotItemDropEventStorageSetupDone(int,bool)));
@@ -345,7 +365,7 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
         return;
     }
 
-    KUrl destUrl = m_model->placesItem(index)->url();
+    KUrl destUrl = destItem->url();
     QDropEvent dropEvent(event->pos().toPoint(),
                          event->possibleActions(),
                          event->mimeData(),
@@ -405,7 +425,7 @@ void PlacesPanel::slotTrashUpdated(KJob* job)
     if (job->error()) {
         emit errorMessage(job->errorString());
     }
-    org::kde::KDirNotify::emitFilesAdded("trash:/");
+    org::kde::KDirNotify::emitFilesAdded(QUrl("trash:/"));
 }
 
 void PlacesPanel::slotStorageSetupDone(int index, bool success)
@@ -442,7 +462,7 @@ void PlacesPanel::emptyTrash()
         stream << int(1);
         KIO::Job *job = KIO::special(KUrl("trash:/"), packedArgs);
         KNotification::event("Trash: emptied", QString() , QPixmap() , 0, KNotification::DefaultEvent);
-        job->ui()->setWindow(parentWidget());
+        KJobWidgets::setWindow(job, parentWidget());
         connect(job, SIGNAL(result(KJob*)), SLOT(slotTrashUpdated(KJob*)));
     }
 }