[network/konqueror] /: Enable option to show hidden folders in sidebar, plus small sidebar code fixes (eg: scrollbar display)

David Faure null at kde.org
Fri Sep 11 13:12:50 BST 2020


Git commit cd6364a2c8a5362c49145204de4eebeff1e4185c by David Faure, on behalf of Raphael Rosch.
Committed on 11/09/2020 at 12:11.
Pushed by dfaure into branch 'master'.

Enable option to show hidden folders in sidebar, plus small sidebar code fixes (eg: scrollbar display)

Adds option to use the "ShowHiddenFolders" option in .desktop files for sidebar
buttons, as well as a context menu entry to toggle it when the option is present
in the .desktop file.

Included is a small fix for the width of the column display, which now allows
for the scrollbar to be displayed properly when the tree does not fit the
horizontal area. This is still not perfect though.

Reviewed By: dfaure

Differential Revision: https://phabricator.kde.org/D29871

M  +5    -0    doc/konqueror/index.docbook
M  +1    -0    sidebar/default_entries/home.desktop
M  +1    -0    sidebar/default_entries/root.desktop
M  +8    -0    sidebar/module_manager.cpp
M  +1    -0    sidebar/module_manager.h
M  +16   -1    sidebar/sidebar_widget.cpp
M  +10   -8    sidebar/sidebar_widget.h
M  +22   -3    sidebar/tree_module/tree_module.cpp
M  +2    -1    sidebar/tree_module/tree_module.h

https://invent.kde.org/network/konqueror/commit/cd6364a2c8a5362c49145204de4eebeff1e4185c

diff --git a/doc/konqueror/index.docbook b/doc/konqueror/index.docbook
index a156e34e6..f96590900 100644
--- a/doc/konqueror/index.docbook
+++ b/doc/konqueror/index.docbook
@@ -2136,6 +2136,11 @@ change the &URL; (path) of the folder viewed in that page.</para></listitem>
 <listitem><para>To change the tab icon.</para></listitem>
 </varlistentry>
 
+<varlistentry>
+<term><guimenuitem>Show Hidden Folders</guimenuitem></term>
+<listitem><para>Toggle whether hidden folders (folders with names that start with a dot) should be shown in the treeview.</para></listitem>
+</varlistentry>
+
 <varlistentry>
 <term><guimenuitem>Remove</guimenuitem></term>
 <listitem><para>To remove the tab page from the Sidebar.</para>
diff --git a/sidebar/default_entries/home.desktop b/sidebar/default_entries/home.desktop
index bdb82fd0a..4aa60e99d 100644
--- a/sidebar/default_entries/home.desktop
+++ b/sidebar/default_entries/home.desktop
@@ -3,6 +3,7 @@ Type=Link
 URL=~
 Icon=user-home
 Open=true
+ShowHiddenFolders=false
 X-KDE-TreeModule=Directory
 X-KDE-KonqSidebarModule=konqsidebar_tree
 X-KDE-Weight=10
diff --git a/sidebar/default_entries/root.desktop b/sidebar/default_entries/root.desktop
index 42b4ded20..05290ca17 100644
--- a/sidebar/default_entries/root.desktop
+++ b/sidebar/default_entries/root.desktop
@@ -4,6 +4,7 @@ URL=file:/
 Icon=folder-red
 #Icon=folder-orange
 Open=true
+ShowHiddenFolders=false
 X-KDE-TreeModule=Directory
 X-KDE-KonqSidebarModule=konqsidebar_tree
 X-KDE-Weight=11
diff --git a/sidebar/module_manager.cpp b/sidebar/module_manager.cpp
index f7c8ef919..a8d3cbd80 100644
--- a/sidebar/module_manager.cpp
+++ b/sidebar/module_manager.cpp
@@ -154,6 +154,14 @@ void ModuleManager::setModuleIcon(const QString &fileName, const QString &icon)
     ksc.sync();
 }
 
+void ModuleManager::setShowHiddenFolders(const QString &fileName, const bool &newState)
+{
+    KConfig desktopFile(m_localPath + fileName, KConfig::SimpleConfig);
+    KConfigGroup ksc(&desktopFile, "Desktop Entry");
+    ksc.writeEntry("ShowHiddenFolders", newState);
+    ksc.sync();
+}
+
 void ModuleManager::removeModule(const QString &fileName)
 {
     // Remove the local file (if it exists)
diff --git a/sidebar/module_manager.h b/sidebar/module_manager.h
index 54b8d4c49..35f6a25e2 100644
--- a/sidebar/module_manager.h
+++ b/sidebar/module_manager.h
@@ -61,6 +61,7 @@ public:
     void setModuleName(const QString &fileName, const QString &moduleName);
     void setModuleUrl(const QString &fileName, const QUrl &url);
     void setModuleIcon(const QString &fileName, const QString &icon);
+    void setShowHiddenFolders(const QString &fileName, const bool &newState);
 
     /// Find a unique filename for a new module, based on a template name
     /// like "dirtree%1.desktop".
diff --git a/sidebar/sidebar_widget.cpp b/sidebar/sidebar_widget.cpp
index e10456962..9f78635f6 100644
--- a/sidebar/sidebar_widget.cpp
+++ b/sidebar/sidebar_widget.cpp
@@ -328,6 +328,15 @@ void Sidebar_Widget::slotRemove()
     }
 }
 
+void Sidebar_Widget::slotToggleShowHiddenFolders()
+{
+    Q_ASSERT(currentButtonInfo().canToggleShowHiddenFolders);
+    bool newToggleState = !currentButtonInfo().showHiddenFolders;
+    m_moduleManager.setShowHiddenFolders(currentButtonInfo().file, newToggleState);
+    // TODO: update THAT button only.
+    QTimer::singleShot(0, this, SLOT(updateButtons()));
+}
+
 void Sidebar_Widget::slotMultipleViews()
 {
     m_singleWidgetMode = !m_singleWidgetMode;
@@ -402,7 +411,6 @@ void Sidebar_Widget::updateButtons()
             delete button.dock;
         }
         m_buttonBar->removeTab(i);
-
     }
     m_buttons.clear();
 
@@ -531,6 +539,8 @@ bool Sidebar_Widget::addButton(const QString &desktopFileName, int pos)
         m_buttonBar->appendTab(QIcon::fromTheme(icon), lastbtn, name);
         ButtonInfo buttonInfo(config, desktopFileName, cleanupURL(url), lib, name, icon);
         buttonInfo.configOpen = configGroup.readEntry("Open", false);
+        buttonInfo.canToggleShowHiddenFolders = (configGroup.readEntry("X-KDE-KonqSidebarModule", QString()) == "konqsidebar_tree");
+        buttonInfo.showHiddenFolders = configGroup.readEntry("ShowHiddenFolders", false);
         m_buttons.insert(lastbtn, buttonInfo);
         KMultiTabBarTab *tab = m_buttonBar->tab(lastbtn);
         tab->installEventFilter(this);
@@ -565,6 +575,11 @@ bool Sidebar_Widget::eventFilter(QObject *obj, QEvent *ev)
                 buttonPopup->addAction(QIcon::fromTheme("edit-rename"), i18n("Set Name..."), this, &Sidebar_Widget::slotSetName); // Item to open a dialog to change the name of the sidebar item (by Pupeno)
                 buttonPopup->addAction(QIcon::fromTheme("internet-web-browser"), i18n("Set URL..."), this, &Sidebar_Widget::slotSetURL);
                 buttonPopup->addAction(QIcon::fromTheme("preferences-desktop-icons"), i18n("Set Icon..."), this, &Sidebar_Widget::slotSetIcon);
+                if (currentButtonInfo().canToggleShowHiddenFolders) {
+                    QAction *toggleShowHiddenFolders = buttonPopup->addAction(i18n("Show Hidden Folders..."), this, &Sidebar_Widget::slotToggleShowHiddenFolders);
+                    toggleShowHiddenFolders->setCheckable(true);
+                    toggleShowHiddenFolders->setChecked(currentButtonInfo().showHiddenFolders);
+                }
                 buttonPopup->addSeparator();
                 buttonPopup->addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"), this, &Sidebar_Widget::slotRemove);
                 buttonPopup->addSeparator();
diff --git a/sidebar/sidebar_widget.h b/sidebar/sidebar_widget.h
index 48e01e97d..c1be47f29 100644
--- a/sidebar/sidebar_widget.h
+++ b/sidebar/sidebar_widget.h
@@ -43,7 +43,6 @@ class ButtonInfo
 {
 public:
     ButtonInfo()
-        : module(NULL), m_plugin(NULL)
     {
     }
     ButtonInfo(const KSharedConfig::Ptr &configFile_,
@@ -52,10 +51,9 @@ public:
                const QString &lib,
                const QString &dispName_,
                const QString &iconName_)
-        : configFile(configFile_),
-          file(file_), dock(NULL),
-          module(NULL), m_plugin(NULL),
-          initURL(url_), libName(lib), displayName(dispName_), iconName(iconName_)
+        : configFile(configFile_), file(file_),
+          libName(lib), displayName(dispName_),
+          iconName(iconName_), initURL(url_)
     {
     }
 
@@ -64,14 +62,17 @@ public:
     KSharedConfig::Ptr configFile;
     QString file;
     QPointer<QWidget> dock;
-    KonqSidebarModule *module;
-    KonqSidebarPlugin *m_plugin;
+    KonqSidebarModule *module = nullptr;
+    KonqSidebarPlugin *m_plugin = nullptr;
 
     QString libName;
     QString displayName;
     QString iconName;
-    bool configOpen;
     QUrl initURL;
+
+    bool configOpen = false;
+    bool canToggleShowHiddenFolders = false;
+    bool showHiddenFolders = false;
 };
 
 class Sidebar_Widget: public QWidget
@@ -113,6 +114,7 @@ protected Q_SLOTS:
     void slotSetName();
     void slotSetURL();
     void slotSetIcon();
+    void slotToggleShowHiddenFolders();
     void slotRemove();
 
     void slotUrlsDropped(const QList<QUrl> &urls);
diff --git a/sidebar/tree_module/tree_module.cpp b/sidebar/tree_module/tree_module.cpp
index 7afbcc845..21d2e05e6 100644
--- a/sidebar/tree_module/tree_module.cpp
+++ b/sidebar/tree_module/tree_module.cpp
@@ -21,8 +21,14 @@
 /*
 
 TODO:
+-sidepanel not triggering changes in session properly
+-"Configure sidebar" > "Add new" has no option to actually add anything there
 -places panel does not respond to view location changes 
 -detect icon size for places panel
+-doubleclick on image (to open kuickview) causes sidebar to deselect
+
+-"View mode" to "sidebar" causes crash and ruins session -- cannot undo
+
 
 BUGS:
 -(konq bug) sftp cannot save file being edited, because: "A file named sftp://hostname/path/to/file already exists."
@@ -53,14 +59,15 @@ KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent,
     m_initURL = cleanupURL(QUrl(configGroup.readPathEntry("URL", QString()))); // because the .desktop file url might be "~"
     treeView = new QTreeView(parent);
     treeView->setHeaderHidden(true);
-    treeView->header()->setStretchLastSection(false);
-    treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+    treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+    treeView->setTextElideMode(Qt::ElideMiddle);
 
     model = new KDirModel(this);
     sorted_model = new KDirSortFilterProxyModel(this);
     sorted_model->setSortFoldersFirst(true);
     sorted_model->setSourceModel(model); 
     model->dirLister()->setDirOnlyMode(true);
+    model->dirLister()->setShowingDotFiles(configGroup.readEntry("ShowHiddenFolders", false));
 
     model->openUrl(m_initURL, KDirModel::ShowRoot);
 
@@ -70,6 +77,11 @@ KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent,
         treeView->setColumnHidden(i, true);
     }
 
+    connect(treeView, &QTreeView::expanded,
+            this, &KonqSideBarTreeModule::slotUpdateColWidth);
+    connect(treeView, &QTreeView::collapsed,
+            this, &KonqSideBarTreeModule::slotUpdateColWidth);
+
     model->expandToUrl(m_initURL); // KDirModel is async, we'll just have to wait for slotKDirCompleted()
     connect(model, &KDirModel::expand,
             this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex);
@@ -167,8 +179,14 @@ void KonqSideBarTreeModule::slotSelectionChanged(const QItemSelection &selected,
     if (index.isValid() && m_lastURL != urlFromIndex) {
         emit openUrlRequest(urlFromIndex);
     }
+    slotUpdateColWidth();
 }
 
+// needed because when there is only one column, QTreeView does not trigger resize
+void KonqSideBarTreeModule::slotUpdateColWidth()
+{
+    treeView->resizeColumnToContents(0);
+}
 
 // needed because KDirModel is async
 void KonqSideBarTreeModule::slotKDirExpand_setRootIndex()
@@ -190,6 +208,7 @@ void KonqSideBarTreeModule::slotKDirExpand_setSelection(const QModelIndex &index
             this, &KonqSideBarTreeModule::slotKDirExpand_setSelection);
         setSelection(m_lastURL, false);
     }
+    slotUpdateColWidth();
 }
 
 
@@ -217,7 +236,7 @@ QUrl KonqSideBarTreeModule::getUrlFromIndex(const QModelIndex &index)
     return resolvedUrl;
 }
 
-const QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url)
+QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const
 {
     return sorted_model->mapFromSource(model->indexForUrl(url));
 }
diff --git a/sidebar/tree_module/tree_module.h b/sidebar/tree_module/tree_module.h
index ce93bcffe..945a19390 100644
--- a/sidebar/tree_module/tree_module.h
+++ b/sidebar/tree_module/tree_module.h
@@ -52,6 +52,7 @@ public:
 
 private slots:
     void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+    void slotUpdateColWidth();
     void slotKDirExpand_setRootIndex();
     void slotKDirExpand_setSelection(const QModelIndex &index);
     void customEvent(QEvent *ev) override;
@@ -61,7 +62,7 @@ private:
     void setSelectionIndex(const QModelIndex &index);
     QUrl getUrlFromIndex(const QModelIndex &index);
     QModelIndex resolveIndex(const QModelIndex &index);
-    const QModelIndex getIndexFromUrl(const QUrl &url);
+    QModelIndex getIndexFromUrl(const QUrl &url) const;
     QUrl cleanupURL(const QUrl &url);
 
     QTreeView *treeView;


More information about the kde-doc-english mailing list