From 94fab8c80ed60958043d13145aaf4c54412e052f Mon Sep 17 00:00:00 2001 From: Robert Hoffmann Date: Fri, 1 Sep 2017 10:15:03 +0200 Subject: Limit folder panel to home directory if inside home Summary: Added the option to limit the displayed folders in the folder panel (F7) to the tree below the user's home directory if the current URL is inside the home directory. This can be configured in the preferences General/Behaviour tab by checking the corresponding check box. Reviewers: #dolphin, elvisangelaccio, emmanuelp Reviewed By: #dolphin, elvisangelaccio, emmanuelp Subscribers: emmanuelp, elvisangelaccio, #konqueror, #dolphin Differential Revision: https://phabricator.kde.org/D7477 --- src/panels/folders/folderspanel.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/panels/folders/folderspanel.cpp') diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 8b759d813..cb35fd218 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -50,6 +50,7 @@ #include #include "dolphindebug.h" +#include "global.h" FoldersPanel::FoldersPanel(QWidget* parent) : Panel(parent), @@ -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()); + } +} + + void FoldersPanel::showEvent(QShowEvent* event) { if (event->spontaneous()) { @@ -304,8 +324,13 @@ void FoldersPanel::loadTree(const QUrl& url) QUrl baseUrl; if (url.isLocalFile()) { - // Use the root directory as base for local URLs (#150941) - baseUrl = QUrl::fromLocalFile(QDir::rootPath()); + const bool isInHomeFolder = Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url); + if (FoldersPanelSettings::limitFoldersPanelToHome() && isInHomeFolder) { + baseUrl = Dolphin::homeUrl(); + } else { + // Use the root directory as base for local URLs (#150941) + baseUrl = QUrl::fromLocalFile(QDir::rootPath()); + } } else { // Clear the path for non-local URLs and use it as base baseUrl = url; @@ -320,9 +345,13 @@ void FoldersPanel::loadTree(const QUrl& url) const int index = m_model->index(url); 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 } -- cgit v1.3