]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.cpp
Add 'Mount' option to context menu of unmounted device in Places
[dolphin.git] / src / panels / places / placespanel.cpp
index f7ca7d010dea5487c91d4fdc9e17dd3c711dd3de..8d7f29384e76a12cacfb76c02e1440e0ff98e52c 100644 (file)
 #include "placespanel.h"
 
 #include "dolphin_generalsettings.h"
-
 #include "global.h"
-#include <KFileItem>
-#include "dolphindebug.h"
-#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 <QGraphicsSceneDragDropEvent>
-#include <QVBoxLayout>
-#include <QShowEvent>
+#include <QIcon>
+#include <QMenu>
 #include <QMimeData>
+#include <QVBoxLayout>
 
 PlacesPanel::PlacesPanel(QWidget* parent) :
     Panel(parent),
@@ -175,8 +169,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"));
@@ -193,7 +186,11 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
             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 {
@@ -211,7 +208,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
     }
 
     if (!isDevice) {
-        editAction = menu.addAction(QIcon::fromTheme("document-properties"), i18nc("@item:inmenu", "Edit..."));
+        editAction = menu.addAction(QIcon::fromTheme("edit-entry"), i18nc("@item:inmenu", "Edit..."));
     }
 
     QAction* removeAction = nullptr;
@@ -228,7 +225,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.
@@ -251,6 +248,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) {
@@ -294,7 +293,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) {
@@ -427,15 +426,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,
@@ -455,17 +445,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();