Commit 64bfeab6 authored by Raphael Rosch's avatar Raphael Rosch Committed by David Faure
Browse files

Fifth revision of the konq sidebar code.

Summary:
Brings back the konqueror sidebar panel, with a few new features. Buttons for: home, root, fonts, bookmarks, places, settings, remote, and others.
Automatically detects and selects in the panel the current location of the active view (except for the places panel, for now).

Test Plan:
Press F9 to bring up the panel. Try multiple combinations of:
 having split window views
 toggling the panel on and off
 toggling the panel visibility on and off
 clicking on items in the panel listings
 navigating using the locationbar, history, or clicking inside the view itself
 selecting different active view, including those with loaded urls that match and don't match the panel button

Reviewers: dfaure

Reviewed By: dfaure

Differential Revision: https://phabricator.kde.org/D28527
parent b61086cf
......@@ -63,7 +63,7 @@ endif()
add_subdirectory( webenginepart )
add_subdirectory( pics )
#add_subdirectory( sidebar )
add_subdirectory( sidebar )
add_subdirectory( settings )
add_subdirectory( plugins )
......
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 )
......
########### 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)
/*
Copyright (C) 2019 Raphael Rosch <kde-dev@insaner.com>
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 <konq_events.h>
#include <KParts/PartActivateEvent>
#include <KLocalizedString>
#include <kpluginfactory.h>
#include <QAction>
#include <QIcon>
#include <QStandardItemModel>
#include <QTreeView>
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<KParts::ReadOnlyPart *>( static_cast<KParts::PartActivateEvent *>(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<QAction *> addNewActions(QObject *parent,
const QList<KConfigGroup> &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<QAction *>() << 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<KonqSidebarBookmarksPlugin>();)
// K_EXPORT_PLUGIN(KonqSidebarBookmarksPluginFactory())
#include "bookmarks_module.moc"
/*
Copyright (C) 2019 Raphael Rosch <kde-dev@insaner.com>
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 <konqsidebarplugin.h>
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
[Desktop Entry]
Type=Service
Icon=bookmark
Name=Bookmarks SideBar Module
Name[x-test]=xxBookmarks SideBar Modulexx
X-KDE-Library=konqsidebar_bookmarks
......@@ -6,4 +6,6 @@ install( FILES
remote.desktop
history.desktop
places.desktop
settings.desktop
fonts.desktop
DESTINATION ${KDE_INSTALL_DATADIR}/konqsidebartng/entries )
[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[xh]=Olu luluhlu lwamanqaku encwadi yakho, yonikezelo olukhawulezayo
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
[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
[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[xh]=Le yimbali yee URL obusandukuzindwendwela. Ungazibeka ngendlela ezin
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
......@@ -2,6 +2,10 @@
Type=Link
URL=~
Icon=user-home
Open=true
X-KDE-TreeModule=Directory
X-KDE-KonqSidebarModule=konqsidebar_tree
X-KDE-Weight=10
Name=Home Folder
Name[af]=Tuis Gids
Name[ar]=المجلد المنزلي
......@@ -185,7 +189,3 @@ Comment[xh]=Le ncwadi eneenkcukacha iqulathe iifayile zobuntu bakho
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
[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[wa]=Çouchal est l' djivêye des eplaeçmints.
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
[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[xh]=Umsebenzi womnatha
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
......@@ -2,6 +2,11 @@
Type=Link
URL=file:/
Icon=folder-red
#Icon=folder-orange
Open=true
X-KDE-TreeModule=Directory
X-KDE-KonqSidebarModule=konqsidebar_tree
X-KDE-Weight=11
Name=Root Folder
Name[af]=Basis Gids
Name[ar]=مجلد الجذر
......@@ -184,7 +189,3 @@ Comment[xh]=Le yingcambu yendlela yefayile
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
[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[xh]=Iinkonzo
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
[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
[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[wa]=Bår di costé
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
[default]
OpenViews=places.desktop
SingleWidgetMode=true
[filemanagement]
OpenViews=home.desktop
OpenViews=root.desktop
SingleWidgetMode=true
[webbrowsing]
......
[Desktop Entry]
Type=Service
Icon=folder-favorites
Name=Places SideBar Module
Name[ar]=وحدة الشريط الجانبي للأماكن
Name[ast]=Módulu de la barra llateral de Llugares
......
......@@ -28,6 +28,9 @@
#include <QAction>
#include <QKeyEvent>
// #include <QAbstractScrollArea>
KonqPlacesCustomPlacesView::KonqPlacesCustomPlacesView(QWidget *parent)
: KFilePlacesView(parent)
, m_mouseButtons(Qt::NoButton)
......@@ -66,7 +69,12 @@ KonqSideBarPlacesModule::KonqSideBarPlacesModule(QWidget *parent,
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)));
}
......
......@@ -32,8 +32,9 @@ KonqSidebarPart::KonqSidebarPart(QWidget *parentWidget, QObject *parent, const Q
: 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 @@ bool KonqSidebarPart::openUrl(const QUrl &url)
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);
}
......
......@@ -68,7 +68,7 @@ protected Q_SLOTS:
* application.
*
* @short Main Part
* @author Joseph WENNINGER <jowenn@bigfoot.com>
* @author Joseph WENNINGER <jowenn@kde.org>
* @version 0.1
*/
class KonqSidebarPart : public KParts::ReadOnlyPart
......
......@@ -5,6 +5,7 @@
copyright : (C) 2001 Joseph Wenninger
email : jowenn@kde.org
Copyright (c) 2009 David Faure <faure@kde.org>
Copyright (c) 2019 Raphael Rosch <kde-dev@insaner.com>
***************************************************************************/
/***************************************************************************
......@@ -30,6 +31,7 @@
#include <QStringList>
#include <QMenu>
#include <QMouseEvent>
#include <QApplication>
// KDE
#include <KLocalizedString>
......@@ -142,8 +144,6 @@ Sidebar_Widget::Sidebar_Widget(QWidget *parent, KParts::ReadOnlyPart *par, const
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 @@ void Sidebar_Widget::addWebSideBar(const QUrl &url, const QString &name)
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 @@ void Sidebar_Widget::slotSetName()
// 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());
......@@ -464,10 +463,14 @@ bool Sidebar_Widget::openUrl(const QUrl &url)
}
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;