diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,7 +63,7 @@
add_subdirectory( webenginepart )
add_subdirectory( pics )
-#add_subdirectory( sidebar )
+add_subdirectory( sidebar )
add_subdirectory( settings )
add_subdirectory( plugins )
diff --git a/doc/konqueror/index.docbook b/doc/konqueror/index.docbook
--- a/doc/konqueror/index.docbook
+++ b/doc/konqueror/index.docbook
@@ -2136,6 +2136,11 @@
To change the tab icon.
+
+Show Hidden Folders
+Toggle whether hidden folders (folders with names that start with a dot) should be shown in the treeview.
+
+
Remove
To remove the tab page from the Sidebar.
diff --git a/sidebar/CMakeLists.txt b/sidebar/CMakeLists.txt
--- a/sidebar/CMakeLists.txt
+++ b/sidebar/CMakeLists.txt
@@ -1,12 +1,13 @@
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
find_package(KF5 REQUIRED COMPONENTS JobWidgets)
-# TODO: rewrite to KDirModel
if (${QT_QT3SUPPORT_FOUND})
add_subdirectory( trees )
endif()
-add_subdirectory( web_module )
+add_subdirectory( bookmarks_module )
+add_subdirectory( tree_module )
+# add_subdirectory( web_module ) # requires refactoring away from KHtml
add_subdirectory( history_module )
add_subdirectory( places_module )
add_subdirectory( default_entries )
diff --git a/sidebar/bookmarks_module/CMakeLists.txt b/sidebar/bookmarks_module/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/sidebar/bookmarks_module/CMakeLists.txt
@@ -0,0 +1,15 @@
+########### konqsidebar_bookmark module ###############
+
+set(konqsidebar_bookmarks_SRCS
+ bookmarks_module.cpp
+)
+
+add_library(konqsidebar_bookmarks MODULE ${konqsidebar_bookmarks_SRCS})
+
+target_link_libraries(konqsidebar_bookmarks KF5::Parts KF5::Konq konqsidebarplugin )
+
+install(TARGETS konqsidebar_bookmarks DESTINATION ${KDE_INSTALL_PLUGINDIR})
+
+########### install files ###############
+
+install(FILES konqsidebar_bookmarks.desktop DESTINATION ${KDE_INSTALL_DATADIR}/konqsidebartng/plugins)
diff --git a/sidebar/bookmarks_module/bookmarks_module.h b/sidebar/bookmarks_module/bookmarks_module.h
new file mode 100644
--- /dev/null
+++ b/sidebar/bookmarks_module/bookmarks_module.h
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2019 Raphael Rosch
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2 of the License or ( at
+ your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ act as a proxy as in section 14 of the GPLv3 ), any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef BOOKMARKS_MODULE_H
+#define BOOKMARKS_MODULE_H
+
+#include
+class QTreeView;
+class QStandardItemModel;
+class QItemSelection;
+
+class KonqSideBarBookmarksModule : public KonqSidebarModule
+{
+ Q_OBJECT
+
+public:
+ KonqSideBarBookmarksModule(QWidget *parent,
+ const KConfigGroup &configGroup);
+ virtual ~KonqSideBarBookmarksModule();
+
+ virtual QWidget *getWidget() override;
+ void handleURL(const QUrl &hand_url) override;
+
+private slots:
+ void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+ void customEvent(QEvent *ev) override;
+
+private:
+ QTreeView *treeView;
+ QStandardItemModel *model;
+ QUrl m_lastURL;
+ QUrl m_initURL;
+};
+
+#endif
diff --git a/sidebar/bookmarks_module/bookmarks_module.cpp b/sidebar/bookmarks_module/bookmarks_module.cpp
new file mode 100644
--- /dev/null
+++ b/sidebar/bookmarks_module/bookmarks_module.cpp
@@ -0,0 +1,157 @@
+/*
+ Copyright (C) 2019 Raphael Rosch
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2 of the License or ( at
+ your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ act as a proxy as in section 14 of the GPLv3 ), any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#include "bookmarks_module.h"
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+KonqSideBarBookmarksModule::KonqSideBarBookmarksModule(QWidget *parent,
+ const KConfigGroup &configGroup)
+ : KonqSidebarModule(parent, configGroup)
+{
+ treeView = new QTreeView(parent);
+ treeView->setHeaderHidden(true);
+ model = new QStandardItemModel(this);
+
+ QStandardItem* item = new QStandardItem(QIcon::fromTheme(configGroup.readEntry("Icon", QString())), configGroup.readEntry("Name", QString()));
+ m_initURL = QUrl(configGroup.readPathEntry("URL", QString()));
+ item->setData(m_initURL);
+ item->setEditable(false);
+
+ model->appendRow(item);
+ treeView->setModel(model);
+
+ QItemSelectionModel *selectionModel = treeView->selectionModel();
+ connect(selectionModel, &QItemSelectionModel::selectionChanged,
+ this, &KonqSideBarBookmarksModule::slotSelectionChanged);
+}
+
+KonqSideBarBookmarksModule::~KonqSideBarBookmarksModule()
+{
+}
+
+QWidget *KonqSideBarBookmarksModule::getWidget()
+{
+ return treeView;
+}
+
+void KonqSideBarBookmarksModule::slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ QModelIndex index = treeView->selectionModel()->currentIndex();
+ QUrl urlFromIndex = model->itemFromIndex(index)->data().toUrl();
+
+ if (urlFromIndex != m_lastURL && urlFromIndex == m_initURL) {
+ emit openUrlRequest(m_initURL);
+ }
+ m_lastURL = urlFromIndex;
+}
+
+void KonqSideBarBookmarksModule::customEvent(QEvent *ev) // active view has changed
+{
+ if (KParts::PartActivateEvent::test(ev)) {
+ KParts::ReadOnlyPart* rpart = static_cast( static_cast(ev)->part() );
+ if (!rpart->url().isEmpty()) {
+ handleURL(rpart->url());
+ }
+ }
+}
+
+void KonqSideBarBookmarksModule::handleURL(const QUrl &thisURL)
+{
+ if (thisURL != m_lastURL) {
+ if (thisURL == m_initURL) {
+ treeView->setCurrentIndex(model->index(0, 0));
+ } else {
+ treeView->selectionModel()->clearSelection();
+ }
+ m_lastURL = thisURL;
+ }
+}
+
+
+
+class KonqSidebarBookmarksPlugin : public KonqSidebarPlugin
+{
+public:
+ KonqSidebarBookmarksPlugin(QObject *parent, const QVariantList &args)
+ : KonqSidebarPlugin(parent, args) {}
+ virtual ~KonqSidebarBookmarksPlugin() {}
+
+ KonqSidebarModule *createModule(QWidget *parent,
+ const KConfigGroup &configGroup,
+ const QString &desktopname,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(desktopname);
+ Q_UNUSED(unused);
+
+ return new KonqSideBarBookmarksModule(parent, configGroup);
+ }
+
+ QList addNewActions(QObject *parent,
+ const QList &existingModules,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(existingModules);
+ Q_UNUSED(unused);
+ QAction *action = new QAction(parent);
+ action->setText(i18nc("@action:inmenu Add", "Bookmarks Sidebar Module"));
+ action->setIcon(QIcon::fromTheme("bookmark"));
+ return QList() << action;
+ }
+
+ QString templateNameForNewModule(const QVariant &actionData,
+ const QVariant &unused) const override
+ {
+ Q_UNUSED(actionData);
+ Q_UNUSED(unused);
+ return QString::fromLatin1("treesidebarplugin%1.desktop");
+ }
+
+ bool createNewModule(const QVariant &actionData,
+ KConfigGroup &configGroup,
+ QWidget *parentWidget,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(actionData);
+ Q_UNUSED(parentWidget);
+ Q_UNUSED(unused);
+ configGroup.writeEntry("Type", "Link");
+ configGroup.writeEntry("Icon", "bookmark");
+ configGroup.writeEntry("Name", i18nc("@title:tab", "Bookmarks"));
+ configGroup.writeEntry("X-KDE-KonqSidebarModule", "konqsidebar_bookmarks");
+ return true;
+ }
+};
+
+K_PLUGIN_FACTORY(KonqSidebarBookmarksPluginFactory, registerPlugin();)
+// K_EXPORT_PLUGIN(KonqSidebarBookmarksPluginFactory())
+
+#include "bookmarks_module.moc"
+
diff --git a/sidebar/bookmarks_module/konqsidebar_bookmarks.desktop b/sidebar/bookmarks_module/konqsidebar_bookmarks.desktop
new file mode 100644
--- /dev/null
+++ b/sidebar/bookmarks_module/konqsidebar_bookmarks.desktop
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Type=Service
+Icon=bookmark
+Name=Bookmarks SideBar Module
+Name[x-test]=xxBookmarks SideBar Modulexx
+X-KDE-Library=konqsidebar_bookmarks
diff --git a/sidebar/default_entries/CMakeLists.txt b/sidebar/default_entries/CMakeLists.txt
--- a/sidebar/default_entries/CMakeLists.txt
+++ b/sidebar/default_entries/CMakeLists.txt
@@ -6,4 +6,6 @@
remote.desktop
history.desktop
places.desktop
+ settings.desktop
+ fonts.desktop
DESTINATION ${KDE_INSTALL_DATADIR}/konqsidebartng/entries )
diff --git a/sidebar/default_entries/bookmarks.desktop b/sidebar/default_entries/bookmarks.desktop
--- a/sidebar/default_entries/bookmarks.desktop
+++ b/sidebar/default_entries/bookmarks.desktop
@@ -1,7 +1,14 @@
[Desktop Entry]
Type=Link
-URL=
-Icon=bookmarks
+URL=bookmarks:
+Icon=bookmark
+Open=true
+#X-KDE-TreeModule=Bookmarks
+X-KDE-TreeModule=Virtual
+X-KDE-RelURL=bookmarks
+X-KDE-KonqSidebarModule=konqsidebar_bookmarks
+#X-KDE-SearchableTreeModule=true
+X-KDE-Weight=1
Name=Bookmarks
Name[af]=Boekmerke
Name[ar]=العلامات
@@ -185,8 +192,3 @@
Comment[x-test]=xxThis is the list of your bookmarks, for a faster accessxx
Comment[zh_CN]=这是您的书签列表,以便使得访问更加快速
Comment[zh_TW]=快速存取網站的書籤列表
-Open=false
-X-KDE-TreeModule=Bookmarks
-X-KDE-SearchableTreeModule=true
-X-KDE-KonqSidebarModule=konqsidebar_tree
-X-KDE-Weight=1
diff --git a/sidebar/default_entries/fonts.desktop b/sidebar/default_entries/fonts.desktop
new file mode 100644
--- /dev/null
+++ b/sidebar/default_entries/fonts.desktop
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Type=Link
+URL=fonts:/
+Icon=icon-fonts
+Open=true
+X-KDE-TreeModule=Virtual
+X-KDE-RelURL=fonts
+X-KDE-KonqSidebarModule=konqsidebar_tree
+#X-KDE-SearchableTreeModule=true
+X-KDE-Weight=16
+Name=Fonts
+Comment=Personal and System fonts list.
+# NOTE: this file needs translation
diff --git a/sidebar/default_entries/history.desktop b/sidebar/default_entries/history.desktop
--- a/sidebar/default_entries/history.desktop
+++ b/sidebar/default_entries/history.desktop
@@ -1,7 +1,10 @@
[Desktop Entry]
Type=Link
-URL=
-Icon=view-history
+Icon=history
+# Icon=view-history
+Open=false
+X-KDE-KonqSidebarModule=konqsidebar_history
+X-KDE-Weight=2
Name=History
Name[af]=Geskiedenis
Name[ar]=التاريخ
@@ -185,5 +188,3 @@
Comment[x-test]=xxThis is the history of the URLs you have recently visited. You can sort them in many ways.xx
Comment[zh_CN]=这是您曾经浏览过的 URL 历史。您可以以多种方式对其排序。
Comment[zh_TW]=這是您最近訪問的 URL 的歷史紀錄。您可以將它們以多種方式排序。
-X-KDE-KonqSidebarModule=konqsidebar_history
-X-KDE-Weight=2
diff --git a/sidebar/default_entries/home.desktop b/sidebar/default_entries/home.desktop
--- a/sidebar/default_entries/home.desktop
+++ b/sidebar/default_entries/home.desktop
@@ -2,6 +2,11 @@
Type=Link
URL=~
Icon=user-home
+Open=true
+ShowHiddenFolders=false
+X-KDE-TreeModule=Directory
+X-KDE-KonqSidebarModule=konqsidebar_tree
+X-KDE-Weight=10
Name=Home Folder
Name[af]=Tuis Gids
Name[ar]=المجلد المنزلي
@@ -185,7 +190,3 @@
Comment[x-test]=xxThis folder contains your personal filesxx
Comment[zh_CN]=这个文件夹包含了您的个人文件
Comment[zh_TW]=這個資料夾包含有您的個人文件
-Open=false
-X-KDE-TreeModule=Directory
-X-KDE-KonqSidebarModule=konqsidebar_tree
-X-KDE-Weight=10
diff --git a/sidebar/default_entries/places.desktop b/sidebar/default_entries/places.desktop
--- a/sidebar/default_entries/places.desktop
+++ b/sidebar/default_entries/places.desktop
@@ -1,6 +1,11 @@
[Desktop Entry]
Type=Link
-Icon=folder-favorites
+#Icon=folder-favorite
+#Icon=folder-favorites
+Icon=folder-templates
+Open=false
+X-KDE-KonqSidebarModule=konqsidebar_places
+X-KDE-Weight=5
Name=Places
Name[ar]=الأماكن
Name[ast]=Llugares
@@ -142,5 +147,3 @@
Comment[x-test]=xxThis is the list of places.xx
Comment[zh_CN]=这是位置列表。
Comment[zh_TW]=這是地方列表。
-X-KDE-KonqSidebarModule=konqsidebar_places
-X-KDE-Weight=5
diff --git a/sidebar/default_entries/remote.desktop b/sidebar/default_entries/remote.desktop
--- a/sidebar/default_entries/remote.desktop
+++ b/sidebar/default_entries/remote.desktop
@@ -1,5 +1,14 @@
[Desktop Entry]
-Name=Network
+Type=Link
+URL=remote:/
+Icon=folder-remote
+Open=true
+X-KDE-TreeModule=Virtual
+X-KDE-RelURL=remote
+X-KDE-KonqSidebarModule=konqsidebar_tree
+X-KDE-Weight=12
+# NOTE: this will include other "remote" connections, not just "network" ones, translations should be updated
+Name=Remote
Name[af]=Netwerk
Name[ar]=الشبكة
Name[as]=নে'টৱৰ্ক
@@ -91,9 +100,3 @@
Name[x-test]=xxNetworkxx
Name[zh_CN]=网络
Name[zh_TW]=網路
-Icon=folder-remote
-Open=false
-X-KDE-TreeModule=Virtual
-X-KDE-RelURL=remote
-X-KDE-KonqSidebarModule=konqsidebar_tree
-X-KDE-Weight=14
diff --git a/sidebar/default_entries/root.desktop b/sidebar/default_entries/root.desktop
--- a/sidebar/default_entries/root.desktop
+++ b/sidebar/default_entries/root.desktop
@@ -2,6 +2,12 @@
Type=Link
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
Name=Root Folder
Name[af]=Basis Gids
Name[ar]=مجلد الجذر
@@ -184,7 +190,3 @@
Comment[x-test]=xxThis is the root of the filesystemxx
Comment[zh_CN]=这是文件系统的根
Comment[zh_TW]=這是檔案系統的根目錄
-Open=false
-X-KDE-TreeModule=Directory
-X-KDE-KonqSidebarModule=konqsidebar_tree
-X-KDE-Weight=11
diff --git a/sidebar/default_entries/services.desktop b/sidebar/default_entries/services.desktop
--- a/sidebar/default_entries/services.desktop
+++ b/sidebar/default_entries/services.desktop
@@ -1,6 +1,12 @@
[Desktop Entry]
-URL=
+Type=Link
+URL=applications:/
Icon=services
+Open=true
+X-KDE-TreeModule=Virtual
+X-KDE-RelURL=services
+X-KDE-KonqSidebarModule=konqsidebar_tree
+X-KDE-Weight=14
Name=Services
Name[af]=Dienste
Name[ar]=الخدمات
@@ -93,8 +99,3 @@
Name[x-test]=xxServicesxx
Name[zh_CN]=服务
Name[zh_TW]=服務
-Open=false
-X-KDE-TreeModule=Virtual
-X-KDE-RelURL=services
-X-KDE-KonqSidebarModule=konqsidebar_tree
-X-KDE-Weight=12
diff --git a/sidebar/default_entries/settings.desktop b/sidebar/default_entries/settings.desktop
new file mode 100644
--- /dev/null
+++ b/sidebar/default_entries/settings.desktop
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Type=Link
+URL=settings:/
+Icon=icon-system-configuration
+Open=true
+X-KDE-TreeModule=Virtual
+X-KDE-RelURL=settings
+X-KDE-KonqSidebarModule=konqsidebar_tree
+#X-KDE-SearchableTreeModule=true
+X-KDE-Weight=15
+Name=Settings
+Comment=System settings options.
+# NOTE: this file needs translation
diff --git a/sidebar/konq_sidebartng.desktop b/sidebar/konq_sidebartng.desktop
--- a/sidebar/konq_sidebartng.desktop
+++ b/sidebar/konq_sidebartng.desktop
@@ -1,6 +1,18 @@
[Desktop Entry]
Type=Service
Icon=view-sidetree
+MimeType=inode/directory;
+X-KDE-ServiceTypes=KParts/ReadOnlyPart,Browser/View
+X-KDE-Library=konq_sidebar
+X-KDE-BrowserView-AllowAsDefault=false
+X-KDE-BrowserView-HideFromMenus=true
+X-KDE-BrowserView-PassiveMode=true
+X-KDE-BrowserView-Toggable=true
+X-KDE-BrowserView-ToggableView-Orientation=vertical
+X-KDE-BrowserView-HierarchicalView=true
+X-KDE-BrowserView-FollowActive=true
+X-KDE-BrowserView-LinkedView=false
+X-KDE-BrowserView-Built-Into=konqueror
Name=Sidebar
Name[ar]=شريط جانبي
Name[ast]=Barra llateral
@@ -71,15 +83,3 @@
Name[x-test]=xxSidebarxx
Name[zh_CN]=侧边栏
Name[zh_TW]=邊列
-MimeType=inode/directory;
-X-KDE-ServiceTypes=KParts/ReadOnlyPart,Browser/View
-X-KDE-Library=konq_sidebar
-X-KDE-BrowserView-AllowAsDefault=false
-X-KDE-BrowserView-HideFromMenus=true
-X-KDE-BrowserView-PassiveMode=true
-X-KDE-BrowserView-Toggable=true
-X-KDE-BrowserView-ToggableView-Orientation=vertical
-X-KDE-BrowserView-HierarchicalView=true
-X-KDE-BrowserView-FollowActive=true
-X-KDE-BrowserView-LinkedView=false
-X-KDE-BrowserView-Built-Into=konqueror
diff --git a/sidebar/konqsidebartngrc b/sidebar/konqsidebartngrc
--- a/sidebar/konqsidebartngrc
+++ b/sidebar/konqsidebartngrc
@@ -1,5 +1,9 @@
+[default]
+OpenViews=places.desktop
+SingleWidgetMode=true
+
[filemanagement]
-OpenViews=home.desktop
+OpenViews=root.desktop
SingleWidgetMode=true
[webbrowsing]
diff --git a/sidebar/module_manager.h b/sidebar/module_manager.h
--- a/sidebar/module_manager.h
+++ b/sidebar/module_manager.h
@@ -61,6 +61,7 @@
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/module_manager.cpp b/sidebar/module_manager.cpp
--- a/sidebar/module_manager.cpp
+++ b/sidebar/module_manager.cpp
@@ -149,6 +149,14 @@
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/places_module/konqsidebar_places.desktop b/sidebar/places_module/konqsidebar_places.desktop
--- a/sidebar/places_module/konqsidebar_places.desktop
+++ b/sidebar/places_module/konqsidebar_places.desktop
@@ -1,6 +1,5 @@
[Desktop Entry]
Type=Service
-Icon=folder-favorites
Name=Places SideBar Module
Name[ar]=وحدة الشريط الجانبي للأماكن
Name[ast]=Módulu de la barra llateral de Llugares
diff --git a/sidebar/places_module/places_module.cpp b/sidebar/places_module/places_module.cpp
--- a/sidebar/places_module/places_module.cpp
+++ b/sidebar/places_module/places_module.cpp
@@ -28,6 +28,9 @@
#include
#include
+
+// #include
+
KonqPlacesCustomPlacesView::KonqPlacesCustomPlacesView(QWidget *parent)
: KFilePlacesView(parent)
, m_mouseButtons(Qt::NoButton)
@@ -66,7 +69,12 @@
m_placesView->setModel(new KFilePlacesModel(m_placesView));
m_placesView->setShowAll(true);
m_placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
+
+ m_placesView->setAutoResizeItemsEnabled(false);
+ // m_placesView->setResizeMode(QListView::Fixed);
+ // m_placesView->setIconSize(QSize(16,16));
+ m_placesView->style()->pixelMetric(QStyle::PM_SmallIconSize); // this would best be done by detecting the size of icons for other widgets
+
connect(m_placesView, SIGNAL(urlChanged(QUrl,Qt::MouseButtons,Qt::KeyboardModifiers)),
this, SLOT(slotPlaceUrlChanged(QUrl,Qt::MouseButtons,Qt::KeyboardModifiers)));
}
diff --git a/sidebar/sidebar_part.h b/sidebar/sidebar_part.h
--- a/sidebar/sidebar_part.h
+++ b/sidebar/sidebar_part.h
@@ -68,7 +68,7 @@
* application.
*
* @short Main Part
- * @author Joseph WENNINGER
+ * @author Joseph WENNINGER
* @version 0.1
*/
class KonqSidebarPart : public KParts::ReadOnlyPart
diff --git a/sidebar/sidebar_part.cpp b/sidebar/sidebar_part.cpp
--- a/sidebar/sidebar_part.cpp
+++ b/sidebar/sidebar_part.cpp
@@ -32,8 +32,9 @@
: KParts::ReadOnlyPart(parent)
{
KAboutData aboutData("konqsidebartng", i18n("Extended Sidebar"), "0.2");
- aboutData.addAuthor(i18n("Joseph Wenninger"), "", "jowenn@bigfoot.com");
+ aboutData.addAuthor(i18n("Joseph Wenninger"), "", "jowenn@kde.org");
aboutData.addAuthor(i18n("David Faure"), "", "faure@kde.org");
+ aboutData.addAuthor(i18n("Raphael Rosch"), "", "kde-dev@insaner.com");
setComponentData(aboutData);
QString currentProfile = parentWidget->window()->property("currentProfile").toString();
@@ -69,7 +70,8 @@
void KonqSidebarPart::customEvent(QEvent *ev)
{
if (KonqFileSelectionEvent::test(ev) ||
- KonqFileMouseOverEvent::test(ev)) {
+ KonqFileMouseOverEvent::test(ev) ||
+ KParts::PartActivateEvent::test(ev)) {
// Forward the event to the widget
QApplication::sendEvent(widget(), ev);
}
diff --git a/sidebar/sidebar_widget.h b/sidebar/sidebar_widget.h
--- a/sidebar/sidebar_widget.h
+++ b/sidebar/sidebar_widget.h
@@ -4,6 +4,7 @@
begin : Sat June 2 16:25:27 CEST 2001
copyright : (C) 2001 Joseph Wenninger
email : jowenn@kde.org
+ Copyright (c) 2019 : Raphael Rosch
***************************************************************************/
/***************************************************************************
@@ -25,6 +26,7 @@
#include
#include
+#include
#include
#include "konqsidebarplugin.h"
@@ -46,12 +48,14 @@
}
ButtonInfo(const KSharedConfig::Ptr &configFile_,
const QString &file_,
- const QUrl &url_, const QString &lib,
- const QString &dispName_, const QString &iconName_)
+ const QUrl &url_,
+ const QString &lib,
+ const QString &dispName_,
+ const QString &iconName_)
: configFile(configFile_),
file(file_), dock(NULL),
module(NULL), m_plugin(NULL),
- URL(url_), libName(lib), displayName(dispName_), iconName(iconName_)
+ initURL(url_), libName(lib), displayName(dispName_), iconName(iconName_)
{
}
@@ -62,10 +66,14 @@
QPointer dock;
KonqSidebarModule *module;
KonqSidebarPlugin *m_plugin;
- QUrl URL; // TODO remove (after removing the place where it's used)
+
QString libName;
QString displayName;
QString iconName;
+ bool configOpen;
+ QUrl initURL;
+ bool canToggleShowHiddenFolders;
+ bool showHiddenFolders;
};
class Sidebar_Widget: public QWidget
@@ -87,7 +95,7 @@
void addWebSideBar(const QUrl &url, const QString &name);
protected:
- void customEvent(QEvent *ev);
+ void customEvent(QEvent *ev) override;
//void resizeEvent(QResizeEvent* ev);
virtual bool eventFilter(QObject *, QEvent *);
virtual void mousePressEvent(QMouseEvent *);
@@ -107,6 +115,7 @@
void slotSetName();
void slotSetURL();
void slotSetIcon();
+ void slotToggleShowHiddenFolders();
void slotRemove();
void slotUrlsDropped(const QList &urls);
@@ -131,6 +140,8 @@
private:
+ QUrl cleanupURL(const QString &url);
+ QUrl cleanupURL(const QUrl &url);
bool addButton(const QString &desktopFileName, int pos = -1);
bool createView(ButtonInfo &buttonInfo);
KonqSidebarModule *loadModule(QWidget *par, const QString &desktopName,
@@ -188,11 +199,12 @@
KConfigGroup *m_config;
QTimer m_configTimer;
- QUrl m_storedUrl;
+ QUrl m_storedCurViewUrl;
+ QUrl m_origURL;
+
int m_savedWidth;
int m_latestViewed;
- bool m_hasStoredUrl;
bool m_singleWidgetMode;
bool m_showTabsLeft;
bool m_hideTabs;
@@ -208,6 +220,8 @@
ModuleManager m_moduleManager;
+ bool m_urlBeforeInstanceFlag = false;
+
Q_SIGNALS:
void panelHasBeenExpanded(bool);
};
diff --git a/sidebar/sidebar_widget.cpp b/sidebar/sidebar_widget.cpp
--- a/sidebar/sidebar_widget.cpp
+++ b/sidebar/sidebar_widget.cpp
@@ -5,6 +5,7 @@
copyright : (C) 2001 Joseph Wenninger
email : jowenn@kde.org
Copyright (c) 2009 David Faure
+ Copyright (c) 2019 Raphael Rosch
***************************************************************************/
/***************************************************************************
@@ -30,6 +31,7 @@
#include
#include
#include
+#include
// KDE
#include
@@ -142,8 +144,6 @@
m_currentButtonIndex = -1;
m_activeModule = 0;
//m_userMovedSplitter = false;
- //kDebug() << "**** Sidebar_Widget:SidebarWidget()";
- m_hasStoredUrl = false;
m_latestViewed = -1;
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
@@ -225,7 +225,6 @@
KConfig _scf(file, KConfig::SimpleConfig);
KConfigGroup scf(&_scf, "Desktop Entry");
if (scf.readPathEntry("URL", QString()) == url.url()) {
- // We already have this one!
KMessageBox::information(this, i18n("This entry already exists."));
return;
}
@@ -305,7 +304,7 @@
// So this should move to the modules that need it.
void Sidebar_Widget::slotSetURL()
{
- KUrlRequesterDialog dlg(currentButtonInfo().URL, i18n("Enter a URL:"), this);
+ KUrlRequesterDialog dlg(currentButtonInfo().initURL, i18n("Enter a URL:"), this);
dlg.urlRequester()->setMode(KFile::Directory);
if (dlg.exec()) {
m_moduleManager.setModuleUrl(currentButtonInfo().file, dlg.selectedUrl());
@@ -334,6 +333,15 @@
}
}
+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;
@@ -408,7 +416,6 @@
delete button.dock;
}
m_buttonBar->removeTab(i);
-
}
m_buttons.clear();
@@ -464,10 +471,14 @@
}
return false;
}
-
- m_storedUrl = url;
- m_hasStoredUrl = true;
+
bool ret = false;
+ if (m_buttons.isEmpty()) { // special case, since KonqMainWindow uses openURL to launch sidebar before buttons exist
+ m_urlBeforeInstanceFlag = true;
+ }
+ m_storedCurViewUrl = cleanupURL(url);
+ m_origURL = m_storedCurViewUrl;
+
for (int i = 0; i < m_buttons.count(); i++) {
const ButtonInfo &button = m_buttons.at(i);
if (button.dock) {
@@ -480,6 +491,26 @@
return ret;
}
+QUrl Sidebar_Widget::cleanupURL(const QString &dirtyURL)
+{
+ return cleanupURL(QUrl(dirtyURL));
+}
+
+QUrl Sidebar_Widget::cleanupURL(const QUrl &dirtyURL)
+{
+ if (!dirtyURL.isValid()) {
+ return dirtyURL;
+ }
+ QUrl url = dirtyURL;
+ if (url.isRelative()) {
+ url.setScheme("file");
+ if (url.path() == "~") {
+ url.setPath(QDir::homePath());
+ }
+ }
+ return url;
+}
+
bool Sidebar_Widget::addButton(const QString &desktopFileName, int pos)
{
int lastbtn = m_buttons.count();
@@ -501,10 +532,14 @@
const QString comment = configGroup.readEntry("Comment", QString());
const QUrl url(configGroup.readPathEntry("URL", QString()));
const QString lib = configGroup.readEntry("X-KDE-KonqSidebarModule");
+ const QString configOpenStr = configGroup.readEntry("Open", QString()); // NOTE: is this redundant?
if (pos == -1) { // TODO handle insertion
m_buttonBar->appendTab(SmallIcon(icon), lastbtn, name);
- ButtonInfo buttonInfo(config, desktopFileName, url, lib, name, icon);
+ 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);
@@ -538,15 +573,19 @@
buttonPopup->addAction(QIcon::fromTheme("edit-rename"), i18n("Set Name..."), this, SLOT(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, SLOT(slotSetURL()));
buttonPopup->addAction(QIcon::fromTheme("preferences-desktop-icons"), i18n("Set Icon..."), this, SLOT(slotSetIcon()));
+ if (currentButtonInfo().canToggleShowHiddenFolders) {
+ QAction *toggleShowHiddenFolders = buttonPopup->addAction(i18n("Show Hidden Folders..."), this, SLOT(slotToggleShowHiddenFolders()));
+ toggleShowHiddenFolders->setCheckable(true);
+ toggleShowHiddenFolders->setChecked(currentButtonInfo().showHiddenFolders);
+ }
buttonPopup->addSeparator();
buttonPopup->addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"), this, SLOT(slotRemove()));
buttonPopup->addSeparator();
buttonPopup->addMenu(m_menu);
buttonPopup->exec(QCursor::pos());
delete buttonPopup;
}
return true;
-
}
}
return false;
@@ -601,6 +640,15 @@
Q_ASSERT(page >= 0);
Q_ASSERT(page < m_buttons.count());
ButtonInfo &buttonInfo = m_buttons[page];
+
+ auto buttonInfoHandleURL = [&] () {
+ buttonInfo.dock->show();
+ m_area->show();
+ openUrl(m_storedCurViewUrl); // also runs the buttonInfo.module->openUrl()
+ m_visibleViews << buttonInfo.file;
+ m_latestViewed = page;
+ };
+
if (!buttonInfo.dock) {
if (m_buttonBar->isTabRaised(page)) {
//SingleWidgetMode
@@ -618,24 +666,14 @@
m_buttonBar->setTab(page, true);
- connect(buttonInfo.module,
- SIGNAL(setIcon(QString)),
- m_buttonBar->tab(page),
- SLOT(setIcon(QString)));
+ connect(buttonInfo.module, SIGNAL(setIcon(QString)),
+ m_buttonBar->tab(page), SLOT(setIcon(QString)));
- connect(buttonInfo.module,
- SIGNAL(setCaption(QString)),
- m_buttonBar->tab(page),
- SLOT(setText(QString)));
+ connect(buttonInfo.module, SIGNAL(setCaption(QString)),
+ m_buttonBar->tab(page), SLOT(setText(QString)));
m_area->addWidget(buttonInfo.dock);
- buttonInfo.dock->show();
- m_area->show();
- if (m_hasStoredUrl) {
- buttonInfo.module->openUrl(m_storedUrl);
- }
- m_visibleViews << buttonInfo.file;
- m_latestViewed = page;
+ buttonInfoHandleURL();
}
} else {
if ((!buttonInfo.dock->isVisibleTo(this)) && (m_buttonBar->isTabRaised(page))) {
@@ -646,14 +684,7 @@
showHidePage(m_latestViewed);
}
}
-
- buttonInfo.dock->show();
- m_area->show();
- m_latestViewed = page;
- if (m_hasStoredUrl) {
- buttonInfo.module->openUrl(m_storedUrl);
- }
- m_visibleViews << buttonInfo.file;
+ buttonInfoHandleURL();
m_buttonBar->setTab(page, true);
} else {
m_buttonBar->setTab(page, false);
@@ -677,7 +708,7 @@
if (!parentWidget()) {
return; // Can happen during destruction
}
-
+
if (m_visibleViews.count() == 0) {
m_somethingVisible = false;
parentWidget()->setMaximumWidth(minimumSizeHint().width());
@@ -717,7 +748,11 @@
void Sidebar_Widget::openUrlRequest(const QUrl &url, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browserArgs)
{
+ if (m_storedCurViewUrl == url) { // don't pollute the history stack
+ return;
+ }
getExtension()->openUrlRequest(url, args, browserArgs);
+ m_storedCurViewUrl = url;
}
void Sidebar_Widget::createNewWindow(const QUrl &url, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browserArgs,
@@ -784,6 +819,31 @@
emit fileSelection(static_cast(ev)->selection());
} else if (KonqFileMouseOverEvent::test(ev)) {
emit fileMouseOver(static_cast(ev)->item());
+ } else if (KParts::PartActivateEvent::test(ev)) {
+ KParts::ReadOnlyPart* rpart = static_cast( static_cast(ev)->part() );
+
+ if (! rpart->url().isEmpty()) {
+ m_storedCurViewUrl = cleanupURL(rpart->url());
+ }
+
+ if (m_buttons.isEmpty()) { // special case when the event is received but the buttons have not been created yet
+ m_urlBeforeInstanceFlag = true;
+ m_origURL = m_storedCurViewUrl;
+ }
+
+ for (int i = 0; i < m_buttons.count(); i++) {
+ const ButtonInfo &button = m_buttons.at(i);
+ if (button.dock) {
+ if ((button.dock->isVisibleTo(this)) && (button.module)) {
+ // Forward the event to the widget
+ QApplication::sendEvent(button.module, ev);
+ break; // if you found the one you wanted.. exit. (Not sure how this would play out in a split-view sidepanel
+ }
+ }
+ }
+
+ // Forward the event to the widget
+ // QApplication::sendEvent(button(), ev);
}
}
diff --git a/sidebar/test/modulemanagertest.cpp b/sidebar/test/modulemanagertest.cpp
--- a/sidebar/test/modulemanagertest.cpp
+++ b/sidebar/test/modulemanagertest.cpp
@@ -83,7 +83,7 @@
QFile::remove(m_globalDir + "testModule.desktop");
//PORTING TODO setter for global dir
- //KGlobal::dirs()->addResourceDir("data", QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "sidebartest_global/"), true;
+ KGlobal::dirs()->addResourceDir("data", QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "sidebartest_global/"), true;
// Create a fake pre-installed plugin there.
KDesktopFile testModule(m_globalDir + "testModule.desktop");
diff --git a/sidebar/tree_module/CMakeLists.txt b/sidebar/tree_module/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/sidebar/tree_module/CMakeLists.txt
@@ -0,0 +1,15 @@
+########### konqsidebar_tree module ###############
+
+set(konqsidebar_tree_SRCS
+ tree_module.cpp
+)
+
+add_library(konqsidebar_tree MODULE ${konqsidebar_tree_SRCS})
+
+target_link_libraries(konqsidebar_tree KF5::Parts KF5::Konq konqsidebarplugin )
+
+install(TARGETS konqsidebar_tree DESTINATION ${KDE_INSTALL_PLUGINDIR})
+
+########### install files ###############
+
+install(FILES konqsidebar_tree.desktop DESTINATION ${KDE_INSTALL_DATADIR}/konqsidebartng/plugins)
diff --git a/sidebar/tree_module/konqsidebar_tree.desktop b/sidebar/tree_module/konqsidebar_tree.desktop
new file mode 100644
--- /dev/null
+++ b/sidebar/tree_module/konqsidebar_tree.desktop
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Type=Service
+Icon=folder-favorites
+Name=Tree SideBar Module
+Name[x-test]=xxTree SideBar Modulexx
+X-KDE-Library=konqsidebar_tree
diff --git a/sidebar/tree_module/tree_module.h b/sidebar/tree_module/tree_module.h
new file mode 100644
--- /dev/null
+++ b/sidebar/tree_module/tree_module.h
@@ -0,0 +1,77 @@
+/*
+ Copyright (C) 2019 Raphael Rosch
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2 of the License or ( at
+ your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ act as a proxy as in section 14 of the GPLv3 ), any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef TREE_MODULE_H
+#define TREE_MODULE_H
+
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+
+
+class KonqSideBarTreeModule : public KonqSidebarModule
+{
+ Q_OBJECT
+
+public:
+ KonqSideBarTreeModule(QWidget *parent,
+ const KConfigGroup &configGroup);
+ virtual ~KonqSideBarTreeModule();
+
+ virtual QWidget *getWidget() override;
+ void handleURL(const QUrl &hand_url) override;
+
+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;
+
+private:
+ void setSelection(const QUrl &target_url, bool do_openURLreq=true);
+ void setSelectionIndex(const QModelIndex &index);
+ QUrl getUrlFromIndex(const QModelIndex &index);
+ QModelIndex resolveIndex(const QModelIndex &index);
+ QModelIndex getIndexFromUrl(const QUrl &url) const;
+ QUrl cleanupURL(const QUrl &url);
+
+ QTreeView *treeView;
+ QUrl m_lastURL;
+ QUrl m_initURL;
+ bool m_ignoreHandle = false;
+
+ KDirModel *model;
+ KDirSortFilterProxyModel *sorted_model;
+};
+
+#endif
diff --git a/sidebar/tree_module/tree_module.cpp b/sidebar/tree_module/tree_module.cpp
new file mode 100644
--- /dev/null
+++ b/sidebar/tree_module/tree_module.cpp
@@ -0,0 +1,303 @@
+/*
+ Copyright (C) 2019 Raphael Rosch
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2 of the License or ( at
+ your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ act as a proxy as in section 14 of the GPLv3 ), any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/*
+
+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."
+ maybe: https://phabricator.kde.org/D23384 , or https://phabricator.kde.org/D15318
+-(konq bug) loading session from cmdline causes crash, but not when konq is loaded fresh
+
+*/
+
+
+
+#include "tree_module.h"
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include
+
+
+KonqSideBarTreeModule::KonqSideBarTreeModule(QWidget *parent,
+ const KConfigGroup &configGroup)
+ : KonqSidebarModule(parent, configGroup)
+{
+ m_initURL = cleanupURL(QUrl(configGroup.readPathEntry("URL", QString()))); // because the .desktop file url might be "~"
+ treeView = new QTreeView(parent);
+ treeView->setHeaderHidden(true);
+ treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ treeView->setTextElideMode(Qt::ElideMiddle);
+ treeView->setDragEnabled(true);
+
+ 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);
+
+ treeView->setModel(sorted_model);
+
+ for (int i = 1; i <= 6; i++) {
+ 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);
+
+ QItemSelectionModel *selectionModel = treeView->selectionModel();
+ connect(selectionModel, &QItemSelectionModel::selectionChanged,
+ this, &KonqSideBarTreeModule::slotSelectionChanged);
+}
+
+void KonqSideBarTreeModule::customEvent(QEvent *ev) // active view has changed
+{
+ if (KParts::PartActivateEvent::test(ev)) {
+ KParts::ReadOnlyPart* rpart = static_cast( static_cast(ev)->part() );
+ if (!rpart->url().isEmpty()) {
+ setSelection(rpart->url());
+ }
+ }
+}
+
+QUrl KonqSideBarTreeModule::cleanupURL(const QUrl &dirtyURL)
+{
+ if (!dirtyURL.isValid()) {
+ return dirtyURL;
+ }
+ QUrl url = dirtyURL;
+ if (url.isRelative()) {
+ url.setScheme("file");
+ if (url.path() == "~") {
+ const QString homePath = QDir::homePath();
+ if (!homePath.endsWith("/")) {
+ url.setPath(homePath + "/");
+ } else {
+ url.setPath(homePath);
+ }
+ }
+ }
+ return url;
+}
+
+KonqSideBarTreeModule::~KonqSideBarTreeModule()
+{
+}
+
+QWidget *KonqSideBarTreeModule::getWidget()
+{
+ return treeView;
+}
+
+void KonqSideBarTreeModule::handleURL(const QUrl &url)
+{
+ QUrl handleURL = url;
+
+ if (handleURL.scheme().isNull()) {
+ setSelectionIndex(QModelIndex());
+ m_lastURL = QUrl();
+ return;
+ }
+
+ m_lastURL = handleURL;
+ setSelection(handleURL);
+}
+
+void KonqSideBarTreeModule::setSelection(const QUrl &target_url, bool do_openURLreq) // do_openURLreq=true)
+{
+ QModelIndex index = sorted_model->mapFromSource(model->indexForUrl(target_url));
+
+ m_lastURL = target_url;
+
+ if (!index.isValid() && target_url.scheme() == m_initURL.scheme()) {
+ if (do_openURLreq) {
+ connect(model, &KDirModel::expand,
+ this, &KonqSideBarTreeModule::slotKDirExpand_setSelection );
+ model->expandToUrl(target_url); // KDirModel is async, we'll just have to wait for slotKDirExpand_setSelection()
+ }
+ }
+
+ setSelectionIndex(index);
+}
+
+void KonqSideBarTreeModule::setSelectionIndex(const QModelIndex &index)
+{
+ if (index == treeView->selectionModel()->currentIndex()) {
+ return;
+ }
+ treeView->expand(index);
+ treeView->scrollTo(index);
+ treeView->setCurrentIndex(index);
+}
+
+void KonqSideBarTreeModule::slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+{
+ QModelIndex index = treeView->selectionModel()->currentIndex();
+
+ QUrl urlFromIndex = getUrlFromIndex(index);
+ 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()
+{
+ QModelIndex index = getIndexFromUrl(m_initURL);
+ if (index.isValid()) {
+ disconnect(model, &KDirModel::expand,
+ this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex);
+ treeView->setRootIndex(index.parent());
+ treeView->expand(index);
+ }
+}
+
+void KonqSideBarTreeModule::slotKDirExpand_setSelection(const QModelIndex &index)
+{
+ QUrl urlFromIndex = getUrlFromIndex(index); // these are only going to be valid
+ if (urlFromIndex == m_lastURL) {
+ disconnect(model, &KDirModel::expand,
+ this, &KonqSideBarTreeModule::slotKDirExpand_setSelection);
+ setSelection(m_lastURL, false);
+ }
+ slotUpdateColWidth();
+}
+
+
+// resolves index to the correct model (due to use of KDirSortFilterProxyModel)
+QModelIndex KonqSideBarTreeModule::resolveIndex(const QModelIndex &index)
+{
+ if (index.isValid() && index.model() != model && model != nullptr) {
+ return static_cast(index.model())->mapToSource(index);
+ } else {
+ return index;
+ }
+}
+
+QUrl KonqSideBarTreeModule::getUrlFromIndex(const QModelIndex &index)
+{
+ QUrl resolvedUrl;
+
+ if (index.isValid()) {
+ KFileItem itemForIndex = model->itemForIndex(resolveIndex(index));
+ if (!itemForIndex.isNull()) {
+ resolvedUrl = itemForIndex.url();
+ }
+ }
+
+ return resolvedUrl;
+}
+
+QModelIndex KonqSideBarTreeModule::getIndexFromUrl(const QUrl &url) const
+{
+ return sorted_model->mapFromSource(model->indexForUrl(url));
+}
+
+
+class KonqSidebarTreePlugin : public KonqSidebarPlugin
+{
+public:
+ KonqSidebarTreePlugin(QObject *parent, const QVariantList &args)
+ : KonqSidebarPlugin(parent, args) {}
+ virtual ~KonqSidebarTreePlugin() {}
+
+ KonqSidebarModule *createModule(QWidget *parent,
+ const KConfigGroup &configGroup,
+ const QString &desktopname,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(desktopname);
+ Q_UNUSED(unused);
+
+ return new KonqSideBarTreeModule(parent, configGroup);
+ }
+
+ QList addNewActions(QObject *parent,
+ const QList &existingModules,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(existingModules);
+ Q_UNUSED(unused);
+ QAction *action = new QAction(parent);
+ action->setText(i18nc("@action:inmenu Add", "Tree Sidebar Module"));
+ action->setIcon(QIcon::fromTheme("folder-favorites"));
+ return QList() << action;
+ }
+
+ QString templateNameForNewModule(const QVariant &actionData,
+ const QVariant &unused) const override
+ {
+ Q_UNUSED(actionData);
+ Q_UNUSED(unused);
+ return QString::fromLatin1("treesidebarplugin%1.desktop");
+ }
+
+ bool createNewModule(const QVariant &actionData,
+ KConfigGroup &configGroup,
+ QWidget *parentWidget,
+ const QVariant &unused) override
+ {
+ Q_UNUSED(actionData);
+ Q_UNUSED(parentWidget);
+ Q_UNUSED(unused);
+ configGroup.writeEntry("Type", "Link");
+ configGroup.writeEntry("Icon", "folder-favorites");
+ configGroup.writeEntry("Name", i18nc("@title:tab", "Tree"));
+ configGroup.writeEntry("X-KDE-KonqSidebarModule", "konqsidebar_tree");
+ return true;
+ }
+};
+
+K_PLUGIN_FACTORY(KonqSidebarTreePluginFactory, registerPlugin();)
+// K_EXPORT_PLUGIN(KonqSidebarTreePluginFactory())
+
+#include "tree_module.moc"
diff --git a/src/konqmainwindow.h b/src/konqmainwindow.h
--- a/src/konqmainwindow.h
+++ b/src/konqmainwindow.h
@@ -33,6 +33,7 @@
#include
#include
+#include
#include
#include "konqcombo.h"
diff --git a/src/konqmainwindow.cpp b/src/konqmainwindow.cpp
--- a/src/konqmainwindow.cpp
+++ b/src/konqmainwindow.cpp
@@ -5453,15 +5453,17 @@
}
if (KonqFileSelectionEvent::test(e) ||
- KonqFileMouseOverEvent::test(e)) {
+ KonqFileMouseOverEvent::test(e) ||
+ KParts::PartActivateEvent::test(e)) {
// Forward the event to all views
MapViews::ConstIterator it = m_mapViews.constBegin();
MapViews::ConstIterator end = m_mapViews.constEnd();
for (; it != end; ++it) {
QApplication::sendEvent((*it)->part(), e);
}
return true;
}
+
if (KParts::OpenUrlEvent::test(e)) {
KParts::OpenUrlEvent *ev = static_cast(e);
diff --git a/src/konqviewmanager.cpp b/src/konqviewmanager.cpp
--- a/src/konqviewmanager.cpp
+++ b/src/konqviewmanager.cpp
@@ -1014,7 +1014,7 @@
// Send event to mainwindow - this is useful for plugins (like searchbar)
KParts::PartActivateEvent ev(true, newPart, newPart->widget());
QApplication::sendEvent(m_pMainWindow, &ev);
-
+
KonqView *view = m_pMainWindow->childView(static_cast(newPart));
if (view == nullptr) {
qCDebug(KONQUEROR_LOG) << "No view associated with this part";