]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/folders/folderspanel.cpp
folderspanel context-menu option "Limit to Home Directory" should be always visible
[dolphin.git] / src / panels / folders / folderspanel.cpp
index 8b759d813dac6b4fae4d5b2b27cda5a7ff09a2bb..add7f692b95cb22369b691890bda72ec1dde36cd 100644 (file)
 #include <views/draganddrophelper.h>
 
 #include "dolphindebug.h"
+#include "global.h"
 
 FoldersPanel::FoldersPanel(QWidget* parent) :
     Panel(parent),
     m_updateCurrentItem(false),
-    m_controller(0),
-    m_model(0)
+    m_controller(nullptr),
+    m_model(nullptr)
 {
     setLayoutDirection(Qt::LeftToRight);
 }
@@ -66,7 +67,7 @@ FoldersPanel::~FoldersPanel()
 
     if (m_controller) {
         KItemListView* view = m_controller->view();
-        m_controller->setView(0);
+        m_controller->setView(nullptr);
         delete view;
     }
 }
@@ -82,6 +83,17 @@ bool FoldersPanel::showHiddenFiles() const
     return FoldersPanelSettings::hiddenFilesShown();
 }
 
+void FoldersPanel::setLimitFoldersPanelToHome(bool enable)
+{
+    FoldersPanelSettings::setLimitFoldersPanelToHome(enable);
+    reloadTree();
+}
+
+bool FoldersPanel::limitFoldersPanelToHome() const
+{
+    return FoldersPanelSettings::limitFoldersPanelToHome();
+}
+
 void FoldersPanel::setAutoScrolling(bool enable)
 {
     // TODO: Not supported yet in Dolphin 2.0
@@ -122,6 +134,14 @@ bool FoldersPanel::urlChanged()
     return true;
 }
 
+void FoldersPanel::reloadTree()
+{
+    if (m_controller) {
+        loadTree(url(), true);
+    }
+}
+
+
 void FoldersPanel::showEvent(QShowEvent* event)
 {
     if (event->spontaneous()) {
@@ -296,33 +316,50 @@ void FoldersPanel::startFadeInAnimation()
     anim->setDuration(200);
 }
 
-void FoldersPanel::loadTree(const QUrl& url)
+void FoldersPanel::loadTree(const QUrl& url, bool allowJumpHome)
 {
     Q_ASSERT(m_controller);
 
     m_updateCurrentItem = false;
+    bool jumpHome = false;
 
     QUrl baseUrl;
-    if (url.isLocalFile()) {
-        // Use the root directory as base for local URLs (#150941)
-        baseUrl = QUrl::fromLocalFile(QDir::rootPath());
-    } else {
+    if (!url.isLocalFile()) {
         // Clear the path for non-local URLs and use it as base
         baseUrl = url;
         baseUrl.setPath(QString('/'));
+    } else if (Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url)) {
+        if (FoldersPanelSettings::limitFoldersPanelToHome() ) {
+            baseUrl = Dolphin::homeUrl();
+        } else {
+            // Use the root directory as base for local URLs (#150941)
+            baseUrl = QUrl::fromLocalFile(QDir::rootPath());
+        }
+    } else if (FoldersPanelSettings::limitFoldersPanelToHome() && allowJumpHome) {
+        baseUrl = Dolphin::homeUrl();
+        jumpHome = true;
+    } else {
+        // Use the root directory as base for local URLs (#150941)
+        baseUrl = QUrl::fromLocalFile(QDir::rootPath());
     }
 
-    if (m_model->directory() != baseUrl) {
+    if (m_model->directory() != baseUrl && !jumpHome) {
         m_updateCurrentItem = true;
         m_model->refreshDirectory(baseUrl);
     }
 
     const int index = m_model->index(url);
-    if (index >= 0) {
+    if (jumpHome == true) {
+      emit folderActivated(baseUrl);
+    } else if (index >= 0) {
         updateCurrentItem(index);
+    } else if (url == baseUrl) {
+        // clear the selection when visiting the base url
+        updateCurrentItem(-1);
     } else {
         m_updateCurrentItem = true;
         m_model->expandParentDirectories(url);
+
         // slotLoadingCompleted() will be invoked after the model has
         // expanded the url
     }