]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
[PlacesItemModelTest] Try to use an event loop instead of an hardcoded timeout
[dolphin.git] / src / panels / places / placespanel.cpp
index e2bdeaafa2007ee657bdcf30a1ba8efc6db7ffea..8a8fa8a7da5bbf3463b2e43add1b215bfdf1a854 100644 (file)
 #include "placespanel.h"
 
 #include "dolphin_generalsettings.h"
-
 #include "global.h"
-#include <KFileItem>
-#include <KDirNotify>
-#include <QIcon>
-#include <KIO/Job>
-#include <KIO/DropJob>
-#include <KIO/EmptyTrashJob>
-#include <KIO/JobUiDelegate>
-#include <KFilePlacesModel>
-#include <KJobWidgets>
-#include <KLocalizedString>
-#include <KIconLoader>
-#include <kitemviews/kitemlistcontainer.h>
-#include <kitemviews/kitemlistcontroller.h>
-#include <kitemviews/kitemlistselectionmanager.h>
-#include <kitemviews/kstandarditem.h>
-#include <QMenu>
-#include <KMessageBox>
-#include <KNotification>
+#include "kitemviews/kitemlistcontainer.h"
+#include "kitemviews/kitemlistcontroller.h"
+#include "kitemviews/kitemlistselectionmanager.h"
+#include "kitemviews/kstandarditem.h"
 #include "placesitem.h"
 #include "placesitemeditdialog.h"
 #include "placesitemlistgroupheader.h"
 #include "placesitemlistwidget.h"
 #include "placesitemmodel.h"
 #include "placesview.h"
-#include <views/draganddrophelper.h>
+#include "trash/dolphintrash.h"
+#include "views/draganddrophelper.h"
+
+#include <KFilePlacesModel>
+#include <KIO/DropJob>
+#include <KIO/EmptyTrashJob>
+#include <KIO/Job>
+#include <KIconLoader>
+#include <KLocalizedString>
+#include <KMountPoint>
+
 #include <QGraphicsSceneDragDropEvent>
+#include <QIcon>
+#include <QMenu>
+#include <QMimeData>
 #include <QVBoxLayout>
 
 PlacesPanel::PlacesPanel(QWidget* parent) :
@@ -172,8 +170,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
     QAction* editAction = nullptr;
     QAction* teardownAction = nullptr;
     QAction* ejectAction = nullptr;
-
-    const QString label = item->text();
+    QAction* mountAction = nullptr;
 
     const bool isDevice = !item->udi().isEmpty();
     const bool isTrash = (item->url().scheme() == QLatin1String("trash"));
@@ -186,11 +183,25 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
 
         teardownAction = m_model->teardownAction(index);
         if (teardownAction) {
+            // Disable teardown option for root and home partitions
+            bool teardownEnabled = item->url() != QUrl::fromLocalFile(QDir::rootPath());
+            if (teardownEnabled) {
+                KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(QDir::homePath());
+                if (mountPoint && item->url() == QUrl::fromLocalFile(mountPoint->mountPoint())) {
+                    teardownEnabled = false;
+                }
+            }
+            teardownAction->setEnabled(teardownEnabled);
+
             teardownAction->setParent(&menu);
             menu.addAction(teardownAction);
         }
 
-        if (teardownAction || ejectAction) {
+        if (item->storageSetupNeeded()) {
+            mountAction = menu.addAction(QIcon::fromTheme(QStringLiteral("media-mount")), i18nc("@action:inmenu", "Mount"));
+        }
+
+        if (teardownAction || ejectAction || mountAction) {
             menu.addSeparator();
         }
     } else {
@@ -201,14 +212,14 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
         }
     }
 
-    QAction* openInNewWindowAction = menu.addAction(QIcon::fromTheme("window-new"), i18nc("@item:inmenu", "Open in New Window"));
-    QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@item:inmenu", "Open in New Tab"));
+    QAction* openInNewWindowAction = menu.addAction(QIcon::fromTheme(QStringLiteral("window-new")), i18nc("@item:inmenu", "Open in New Window"));
+    QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@item:inmenu", "Open in New Tab"));
     if (!isDevice && !isTrash) {
         menu.addSeparator();
     }
 
     if (!isDevice) {
-        editAction = menu.addAction(QIcon::fromTheme("document-properties"), i18nc("@item:inmenu", "Edit..."));
+        editAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-entry")), i18nc("@item:inmenu", "Edit..."));
     }
 
     QAction* removeAction = nullptr;
@@ -216,7 +227,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
         removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove"));
     }
 
-    QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide"));
+    QAction* hideAction = menu.addAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Hide"));
     hideAction->setCheckable(true);
     hideAction->setChecked(item->isHidden());
 
@@ -225,7 +236,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
     QAction* action = menu.exec(pos.toPoint());
     if (action) {
         if (action == emptyTrashAction) {
-            emptyTrash();
+            Trash::empty(this);
         } else {
             // The index might have changed if devices were added/removed while
             // the context menu was open.
@@ -248,6 +259,8 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
                 // TriggerItem does set up the storage first and then it will
                 // emit the slotItemMiddleClicked signal, because of Qt::MiddleButton.
                 triggerItem(index, Qt::MiddleButton);
+            } else if (action == mountAction) {
+                m_model->requestStorageSetup(index);
             } else if (action == teardownAction) {
                 m_model->requestTearDown(index);
             } else if (action == ejectAction) {
@@ -267,7 +280,7 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
 
     QAction* showAllAction = nullptr;
     if (m_model->hiddenCount() > 0) {
-        showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
+        showAllAction = menu.addAction(QIcon::fromTheme(QStringLiteral("visibility")), i18nc("@item:inmenu", "Show All Entries"));
         showAllAction->setCheckable(true);
         showAllAction->setChecked(m_model->hiddenItemsShown());
     }
@@ -291,7 +304,7 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
         {KIconLoader::SizeLarge,        I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")}
     };
 
-    QMap<QAction*, int> iconSizeActionMap;
+    QHash<QAction*, int> iconSizeActionMap;
     QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu);
 
     for (int i = 0; i < iconSizeCount; ++i) {
@@ -334,7 +347,7 @@ QAction *PlacesPanel::buildGroupContextMenu(QMenu *menu, int index)
     }
 
     KFilePlacesModel::GroupType groupType = m_model->groupType(index);
-    QAction *hideGroupAction = menu->addAction(i18nc("@item:inmenu", "Hide Section '%1'", m_model->item(index)->group()));
+    QAction *hideGroupAction = menu->addAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Hide Section '%1'", m_model->item(index)->group()));
     hideGroupAction->setCheckable(true);
     hideGroupAction->setChecked(m_model->isGroupHidden(groupType));
 
@@ -424,15 +437,6 @@ void PlacesPanel::slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget*
     }
 }
 
-void PlacesPanel::slotTrashUpdated(KJob* job)
-{
-    if (job->error()) {
-        emit errorMessage(job->errorString());
-    }
-    // as long as KIO doesn't do this, do it ourselves
-    KNotification::event(QStringLiteral("Trash: emptied"), QString(), QPixmap(), nullptr, KNotification::DefaultEvent);
-}
-
 void PlacesPanel::slotStorageSetupDone(int index, bool success)
 {
     disconnect(m_model, &PlacesItemModel::storageSetupDone,
@@ -452,17 +456,6 @@ void PlacesPanel::slotStorageSetupDone(int index, bool success)
     }
 }
 
-void PlacesPanel::emptyTrash()
-{
-    KIO::JobUiDelegate uiDelegate;
-    uiDelegate.setWindow(window());
-    if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
-        KIO::Job* job = KIO::emptyTrash();
-        KJobWidgets::setWindow(job, window());
-        connect(job, &KIO::Job::result, this, &PlacesPanel::slotTrashUpdated);
-    }
-}
-
 void PlacesPanel::addEntry()
 {
     const int index = m_controller->selectionManager()->currentItem();