]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placespanel.h
Port back to KFilePlacesView
[dolphin.git] / src / panels / places / placespanel.h
index 4156cfea09d966f36b701990dd8c5612a18819c8..fd6661c76fececbf67655000e3649aef9dd93042 100644 (file)
-/***************************************************************************
- *   Copyright (C) 2008-2012 by Peter Penz <peter.penz19@gmail.com>        *
- *   Copyright (C) 2010 by Christian Muehlhaeuser <muesli@gmail.com>       *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2008-2012 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2010 Christian Muehlhaeuser <muesli@gmail.com>
+ * SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #ifndef PLACESPANEL_H
 #define PLACESPANEL_H
 
-#include <config-nepomuk.h>
+#include "panels/panel.h"
 
-#include <KUrl>
-#include <panels/panel.h>
+#include <QUrl>
+#include <KFilePlacesView>
 
-class KItemListController;
-class PlacesItemEditDialog;
-class PlacesItem;
-class PlacesItemModel;
+#include <Solid/SolidNamespace> // Solid::ErrorType
 
-#ifdef HAVE_NEPOMUK
-    namespace Nepomuk
-    {
-        namespace Query
-        {
-            class Term;
-        }
-    }
-#endif
+class QTimer;
+namespace Solid
+{
+class StorageAccess;
+}
 
 /**
  * @brief Combines bookmarks and mounted devices as list.
  */
-class PlacesPanel : public Panel
+class PlacesPanel : public KFilePlacesView
 {
     Q_OBJECT
 
 public:
-    PlacesPanel(QWidget* parent);
-    virtual ~PlacesPanel();
+    explicit PlacesPanel(QWidget* parent);
+    ~PlacesPanel() override;
+
+    void setUrl(const QUrl &url); // override
+
+    // for compatibility with Panel, actions that are shown
+    // on the view's context menu
+    QList<QAction*> customContextMenuActions() const;
+    void setCustomContextMenuActions(const QList<QAction*>& actions);
+
+    void requestTearDown();
+    void proceedWithTearDown();
+
+public Q_SLOTS:
+    void readSettings();
 
-signals:
-    void placeActivated(const KUrl& url);
-    void placeMiddleClicked(const KUrl& url);
+Q_SIGNALS:
     void errorMessage(const QString& error);
+    void storageTearDownRequested(const QString& mountPath);
+    void storageTearDownExternallyRequested(const QString& mountPath);
+    void storageTearDownSuccessful();
 
 protected:
-    virtual bool urlChanged();
-    virtual void showEvent(QShowEvent* event);
-
-private slots:
-    void slotItemActivated(int index);
-    void slotItemMiddleClicked(int index);
-    void slotItemContextMenuRequested(int index, const QPointF& pos);
-    void slotViewContextMenuRequested(const QPointF& pos);
-    void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
-    void slotTrashUpdated(KJob* job);
+    void showEvent(QShowEvent* event) override;
+    void dragMoveEvent(QDragMoveEvent *event) override;
+    void dragLeaveEvent(QDragLeaveEvent *event) override;
+
+private Q_SLOTS:
+    void slotConfigureTrash();
+    void slotDragActivationTimeout();
+    void slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent);
+    void slotContextMenuAboutToShow(const QModelIndex &index, QMenu *menu);
+    void slotTearDownRequested(const QModelIndex &index);
+    void slotTearDownRequestedExternally(const QString &udi);
+    void slotTearDownDone(Solid::ErrorType error, const QVariant& errorData);
+    void slotRowsInserted(const QModelIndex &parent, int first, int last);
+    void slotRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
 
 private:
-    void emptyTrash();
-    void addEntry();
-    void editEntry(int index);
-
-    /**
-     * Selects the item that has the closest URL for the URL set
-     * for the panel (see Panel::setUrl()).
-     */
-    void selectClosestItem();
-
-    /**
-     * @return Converts the URL, which contains "virtual" URLs for system-items like
-     *         "search:/documents" into a Nepomuk-Query-URL that will be handled by
-     *         the corresponding IO-slave. Virtual URLs for bookmarks are used to
-     *         be independent from internal format changes.
-     */
-    static KUrl convertedUrl(const KUrl& url);
-
-    /**
-     * @return URL using the timeline-protocol for searching (see convertedUrl()).
-     */
-    static KUrl createTimelineUrl(const KUrl& url);
-
-    /**
-     * Helper method for createTimelineUrl().
-     * @return String that represents a date-path in the format that
-     *         the timeline-protocol expects.
-     */
-    static QString timelineDateString(int year, int month, int day = 0);
-
-    /**
-     * @return URL that can be listed by KIO and results in searching
-     *         for a given term. The URL \a url represents a places-internal
-     *         URL like e.g. "search:/documents" (see convertedUrl()).
-     */
-    static KUrl createSearchUrl(const KUrl& url);
-
-#ifdef HAVE_NEPOMUK
-    /**
-     * Helper method for createSearchUrl().
-     * @return URL that can be listed by KIO and results in searching
-     *         for the given term.
-     */
-    static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term);
-#endif
+    void connectDeviceSignals(const QModelIndex &idx);
 
-private:
-    KItemListController* m_controller;
-    PlacesItemModel* m_model;
+    QUrl m_url; // only used for initial setUrl
+    QList<QAction*> m_customContextMenuActions;
+
+    QTimer *m_dragActivationTimer = nullptr;
+    QPersistentModelIndex m_pendingDragActivation;
+
+    Solid::StorageAccess *m_deviceToTearDown = nullptr;
+
+    QAction *m_configureTrashAction;
+    QAction *m_lockPanelsAction;
 };
 
 #endif // PLACESPANEL_H