]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Hide "Places" section header when panels are unlocked
authorKai Uwe Broulik <kde@privat.broulik.de>
Fri, 28 Jan 2022 18:40:11 +0000 (19:40 +0100)
committerKai Uwe Broulik <kde@privat.broulik.de>
Sat, 5 Feb 2022 22:18:28 +0000 (22:18 +0000)
Avoids showing "Places" twice.

src/dolphinmainwindow.cpp
src/dolphinplacesmodelsingleton.cpp
src/dolphinplacesmodelsingleton.h

index 9b4ac64c9829d63e601914a12137754ec6584233..166091ca7e9ef70cf909952a365d141d02894ab1 100644 (file)
@@ -912,6 +912,8 @@ void DolphinMainWindow::togglePanelLockState()
         }
     }
 
+    DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState);
+
     GeneralSettings::setLockPanels(newLockState);
 }
 
@@ -1814,6 +1816,8 @@ void DolphinMainWindow::setupDockWidgets()
 {
     const bool lock = GeneralSettings::lockPanels();
 
+    DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
+
     KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
     lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
     lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
index 02fbf05d089ebd4c42e8f17934b7b514de0c3c25..c31ffc4c3cd1c0c4afeb676ecc25606f3f91e901 100644 (file)
@@ -20,9 +20,37 @@ DolphinPlacesModel::DolphinPlacesModel(const QString &alternativeApplicationName
 
 DolphinPlacesModel::~DolphinPlacesModel() = default;
 
+bool DolphinPlacesModel::panelsLocked() const
+{
+    return m_panelsLocked;
+}
+
+void DolphinPlacesModel::setPanelsLocked(bool locked)
+{
+    if (m_panelsLocked == locked) {
+        return;
+    }
+
+    m_panelsLocked = locked;
+
+    if (rowCount() > 0) {
+        int lastPlace = rowCount() - 1;
+
+        for (int i = 0; i < rowCount(); ++i) {
+            if (KFilePlacesModel::groupType(index(i, 0)) != KFilePlacesModel::PlacesType) {
+                lastPlace = i - 1;
+                break;
+            }
+        }
+
+        Q_EMIT dataChanged(index(0, 0), index(lastPlace, 0), {KFilePlacesModel::GroupRole});
+    }
+}
+
 QVariant DolphinPlacesModel::data(const QModelIndex &index, int role) const
 {
-    if (role == Qt::DecorationRole) {
+    switch (role) {
+    case Qt::DecorationRole:
         if (isTrash(index)) {
             if (m_isEmpty) {
                 return QIcon::fromTheme(QStringLiteral("user-trash"));
@@ -30,6 +58,18 @@ QVariant DolphinPlacesModel::data(const QModelIndex &index, int role) const
                 return QIcon::fromTheme(QStringLiteral("user-trash-full"));
             }
         }
+        break;
+    case KFilePlacesModel::GroupRole: {
+        // When panels are unlocked, avoid a double "Places" heading,
+        // one from the panel title bar, one from the places view section.
+        if (!m_panelsLocked) {
+            const auto groupType = KFilePlacesModel::groupType(index);
+            if (groupType == KFilePlacesModel::PlacesType) {
+                return QString();
+            }
+        }
+        break;
+    }
     }
 
     return KFilePlacesModel::data(index, role);
index 84151fa8cbf0f8d921a18b0201be66a0e10eb9bb..996f9de78fb559a00101ec21e4bd99c4cf4e21eb 100644 (file)
@@ -26,6 +26,9 @@ public:
     explicit DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent = nullptr);
     ~DolphinPlacesModel() override;
 
+    bool panelsLocked() const;
+    void setPanelsLocked(bool locked);
+
 protected:
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
 
@@ -36,6 +39,7 @@ private:
     bool isTrash(const QModelIndex &index) const;
 
     bool m_isEmpty = false;
+    bool m_panelsLocked = true; // common-case, panels are locked
 };
 
 /**