Commit 0603e18c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Port back to KFilePlacesView

This removes the custom-view engine version of the places panel
and replaces it with the upstream `KFilePlacesView` from KIO.
parent 3abc4cfc
......@@ -8,7 +8,7 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE
project(Dolphin VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.90.0")
set(KF5_MIN_VERSION "5.91.0")
# ECM setup
find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
......
......@@ -223,12 +223,6 @@ target_sources(dolphinstatic PRIVATE
trash/dolphintrash.cpp
filterbar/filterbar.cpp
panels/places/placespanel.cpp
panels/places/placesitem.cpp
panels/places/placesitemlistgroupheader.cpp
panels/places/placesitemlistwidget.cpp
panels/places/placesitemmodel.cpp
panels/places/placesitemsignalhandler.cpp
panels/places/placesview.cpp
panels/panel.cpp
panels/folders/foldersitemlistwidget.cpp
panels/folders/treeviewcontextmenu.cpp
......
......@@ -13,8 +13,6 @@
#include "dolphinplacesmodelsingleton.h"
#include "dolphinremoveaction.h"
#include "dolphinviewcontainer.h"
#include "panels/places/placesitem.h"
#include "panels/places/placesitemmodel.h"
#include "trash/dolphintrash.h"
#include "views/dolphinview.h"
#include "views/viewmodecontroller.h"
......
......@@ -17,12 +17,12 @@
#include "dolphinnavigatorswidgetaction.h"
#include "dolphinnewfilemenu.h"
#include "dolphinrecenttabsmenu.h"
#include "dolphinplacesmodelsingleton.h"
#include "dolphinurlnavigatorscontroller.h"
#include "dolphinviewcontainer.h"
#include "dolphintabpage.h"
#include "middleclickactioneventfilter.h"
#include "panels/folders/folderspanel.h"
#include "panels/places/placesitemmodel.h"
#include "panels/places/placespanel.h"
#include "panels/terminal/terminalpanel.h"
#include "settings/dolphinsettingsdialog.h"
......@@ -429,14 +429,13 @@ void DolphinMainWindow::addToPlaces()
name = dirToAdd.name();
}
if (url.isValid()) {
PlacesItemModel model;
QString icon;
if (m_activeViewContainer->isSearchModeEnabled()) {
icon = QStringLiteral("folder-saved-search-symbolic");
} else {
icon = KIO::iconNameForUrl(url);
}
model.createPlacesItem(name, url, icon);
DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name, url, icon);
}
}
......@@ -1954,10 +1953,13 @@ void DolphinMainWindow::setupDockWidgets()
addDockWidget(Qt::LeftDockWidgetArea, placesDock);
connect(m_placesPanel, &PlacesPanel::placeActivated,
this, &DolphinMainWindow::slotPlaceActivated);
connect(m_placesPanel, &PlacesPanel::placeActivatedInNewTab,
connect(m_placesPanel, &PlacesPanel::tabRequested,
this, &DolphinMainWindow::openNewTab);
connect(m_placesPanel, &PlacesPanel::placeActivatedInNewActiveTab,
connect(m_placesPanel, &PlacesPanel::activeTabRequested,
this, &DolphinMainWindow::openNewTabAndActivate);
connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
Dolphin::openNewWindow({url}, this);
});
connect(m_placesPanel, &PlacesPanel::errorMessage,
this, &DolphinMainWindow::showErrorMessage);
connect(this, &DolphinMainWindow::urlChanged,
......@@ -1980,14 +1982,9 @@ void DolphinMainWindow::setupDockWidgets()
"appear semi-transparent unless you uncheck their hide property."));
connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
m_placesPanel->showHiddenEntries(checked);
m_placesPanel->setShowAll(checked);
});
connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){
actionShowAllPlaces->setChecked(checked);
actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
});
connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
actionCollection()->action(QStringLiteral("show_places_panel"))
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
......@@ -2025,7 +2022,7 @@ void DolphinMainWindow::setupDockWidgets()
panelsMenu->addAction(lockLayoutAction);
connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount());
actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
});
}
......
......@@ -5,12 +5,61 @@
*/
#include "dolphinplacesmodelsingleton.h"
#include "trash/dolphintrash.h"
#include <KAboutData>
#include <KFilePlacesModel>
#include <QIcon>
DolphinPlacesModel::DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent)
: KFilePlacesModel(alternativeApplicationName, parent)
{
connect(&Trash::instance(), &Trash::emptinessChanged, this, &DolphinPlacesModel::slotTrashEmptinessChanged);
}
DolphinPlacesModel::~DolphinPlacesModel() = default;
QVariant DolphinPlacesModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DecorationRole) {
if (isTrash(index)) {
if (m_isEmpty) {
return QIcon::fromTheme(QStringLiteral("user-trash"));
} else {
return QIcon::fromTheme(QStringLiteral("user-trash-full"));
}
}
}
return KFilePlacesModel::data(index, role);
}
void DolphinPlacesModel::slotTrashEmptinessChanged(bool isEmpty)
{
if (m_isEmpty == isEmpty) {
return;
}
// NOTE Trash::isEmpty() reads the config file whereas emptinessChanged is
// hooked up to whether a dirlister in trash:/ has any files and they disagree...
m_isEmpty = isEmpty;
for (int i = 0; i < rowCount(); ++i) {
const QModelIndex index = this->index(i, 0);
if (isTrash(index)) {
Q_EMIT dataChanged(index, index, {Qt::DecorationRole});
}
}
}
bool DolphinPlacesModel::isTrash(const QModelIndex &index) const
{
return url(index) == QUrl(QStringLiteral("trash:/"));
}
DolphinPlacesModelSingleton::DolphinPlacesModelSingleton()
: m_placesModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
: m_placesModel(new DolphinPlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
{
}
......
......@@ -10,7 +10,33 @@
#include <QString>
#include <QScopedPointer>
class KFilePlacesModel;
#include <KFilePlacesModel>
/**
* @brief Dolphin's special-cased KFilePlacesModel
*
* It returns the trash's icon based on whether
* it is full or not.
*/
class DolphinPlacesModel : public KFilePlacesModel
{
Q_OBJECT
public:
explicit DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent = nullptr);
~DolphinPlacesModel() override;
protected:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
private Q_SLOTS:
void slotTrashEmptinessChanged(bool isEmpty);
private:
bool isTrash(const QModelIndex &index) const;
bool m_isEmpty = false;
};
/**
* @brief Provides a global KFilePlacesModel instance.
......
......@@ -8,7 +8,7 @@
<kcfgfile name="dolphinrc"/>
<group name="PlacesPanel">
<entry name="IconSize" type="Int">
<label>Size of icons in the Places Panel (-1 means "use the style's small size")</label>
<label>Size of icons in the Places Panel (-1 means "automatic")</label>
<default code="true">KIconLoader::SizeSmallMedium</default>
</entry>
</group>
......
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
* SPDX-FileCopyrightText: 2018 Elvis Angelaccio <elvis.angelaccio@kde.org>
*
* Based on KFilePlacesItem from kdelibs:
* SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "placesitem.h"
#include "trash/dolphintrash.h"
#include "dolphindebug.h"
#include "placesitemsignalhandler.h"
#include <KDirLister>
#include <KLocalizedString>
#include <Solid/Block>
PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) :
KStandardItem(parent),
m_device(),
m_access(),
m_volume(),
m_disc(),
m_player(),
m_signalHandler(nullptr),
m_bookmark()
{
m_signalHandler = new PlacesItemSignalHandler(this);
setBookmark(bookmark);
}
PlacesItem::~PlacesItem()
{
delete m_signalHandler;
}
void PlacesItem::setUrl(const QUrl &url)
{
// The default check in KStandardItem::setDataValue()
// for equal values does not work with a custom value
// like QUrl. Hence do a manual check to prevent that
// setting an equal URL results in an itemsChanged()
// signal.
if (dataValue("url").toUrl() != url) {
if (url.scheme() == QLatin1String("trash")) {
QObject::connect(&Trash::instance(), &Trash::emptinessChanged, m_signalHandler.data(), &PlacesItemSignalHandler::onTrashEmptinessChanged);
}
setDataValue("url", url);
}
}
QUrl PlacesItem::url() const
{
return dataValue("url").toUrl();
}
void PlacesItem::setUdi(const QString& udi)
{
setDataValue("udi", udi);
}
QString PlacesItem::udi() const
{
return dataValue("udi").toString();
}
void PlacesItem::setApplicationName(const QString &applicationName)
{
setDataValue("applicationName", applicationName);
}
QString PlacesItem::applicationName() const
{
return dataValue("applicationName").toString();
}
void PlacesItem::setHidden(bool hidden)
{
setDataValue("isHidden", hidden);
}
bool PlacesItem::isHidden() const
{
return dataValue("isHidden").toBool();
}
bool PlacesItem::isGroupHidden() const
{
return dataValue("isGroupHidden").toBool();
}
void PlacesItem::setGroupHidden(bool hidden)
{
setDataValue("isGroupHidden", hidden);
}
void PlacesItem::setSystemItem(bool isSystemItem)
{
setDataValue("isSystemItem", isSystemItem);
}
bool PlacesItem::isSystemItem() const
{
return dataValue("isSystemItem").toBool();
}
Solid::Device PlacesItem::device() const
{
return m_device;
}
void PlacesItem::setBookmark(const KBookmark& bookmark)
{
const bool bookmarkDataChanged = !(bookmark == m_bookmark);
// bookmark object must be updated to keep in sync with source model
m_bookmark = bookmark;
if (!bookmarkDataChanged) {
return;
}
delete m_access;
delete m_volume;
delete m_disc;
delete m_player;
const QString udi = bookmark.metaDataItem(QStringLiteral("UDI"));
if (udi.isEmpty()) {
setIcon(bookmark.icon());
setText(i18ndc("kio5", "KFile System Bookmarks", bookmark.text().toUtf8().constData()));
setUrl(bookmark.url());
setSystemItem(bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true"));
} else {
initializeDevice(udi);
}
setHidden(bookmark.metaDataItem(QStringLiteral("IsHidden")) == QLatin1String("true"));
}
KBookmark PlacesItem::bookmark() const
{
return m_bookmark;
}
bool PlacesItem::storageSetupNeeded() const
{
return m_access ? !m_access->isAccessible() : false;
}
bool PlacesItem::isSearchOrTimelineUrl() const
{
const QString urlScheme = url().scheme();
return (urlScheme.contains("search") || urlScheme.contains("timeline"));
}
void PlacesItem::onDataValueChanged(const QByteArray& role,
const QVariant& current,
const QVariant& previous)
{
Q_UNUSED(current)
Q_UNUSED(previous)
if (!m_bookmark.isNull()) {
updateBookmarkForRole(role);
}
}
void PlacesItem::onDataChanged(const QHash<QByteArray, QVariant>& current,
const QHash<QByteArray, QVariant>& previous)
{
Q_UNUSED(previous)
if (!m_bookmark.isNull()) {
QHashIterator<QByteArray, QVariant> it(current);
while (it.hasNext()) {
it.next();
updateBookmarkForRole(it.key());
}
}
}
void PlacesItem::initializeDevice(const QString& udi)
{
m_device = Solid::Device(udi);
if (!m_device.isValid()) {
return;
}
m_access = m_device.as<Solid::StorageAccess>();
m_volume = m_device.as<Solid::StorageVolume>();
m_disc = m_device.as<Solid::OpticalDisc>();
m_player = m_device.as<Solid::PortableMediaPlayer>();
setText(m_device.displayName());
setIcon(m_device.icon());
setIconOverlays(m_device.emblems());
setUdi(udi);
if (m_access) {
setUrl(QUrl::fromLocalFile(m_access->filePath()));
QObject::connect(m_access.data(), &Solid::StorageAccess::accessibilityChanged,
m_signalHandler.data(), &PlacesItemSignalHandler::onAccessibilityChanged);
QObject::connect(m_access.data(), &Solid::StorageAccess::teardownRequested,
m_signalHandler.data(), &PlacesItemSignalHandler::onTearDownRequested);
} else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) {
Solid::Block *block = m_device.as<Solid::Block>();
if (block) {
const QString device = block->device();
setUrl(QUrl(QStringLiteral("audiocd:/?device=%1").arg(device)));
} else {
setUrl(QUrl(QStringLiteral("audiocd:/")));
}
} else if (m_player) {
const QStringList protocols = m_player->supportedProtocols();
if (!protocols.isEmpty()) {
setUrl(QUrl(QStringLiteral("%1:udi=%2").arg(protocols.first(), m_device.udi())));
}
}
}
void PlacesItem::onAccessibilityChanged()
{
setIconOverlays(m_device.emblems());
setUrl(QUrl::fromLocalFile(m_access->filePath()));
}
void PlacesItem::updateBookmarkForRole(const QByteArray& role)
{
Q_ASSERT(!m_bookmark.isNull());
if (role == "iconName") {
m_bookmark.setIcon(icon());
} else if (role == "text") {
// Only store the text in the KBookmark if it is not the translation of
// the current text. This makes sure that the text is re-translated if
// the user chooses another language, or the translation itself changes.
//
// NOTE: It is important to use "KFile System Bookmarks" as context
// (see PlacesItemModel::createSystemBookmarks()).
if (text() != i18ndc("kio5", "KFile System Bookmarks", m_bookmark.text().toUtf8().data())) {
m_bookmark.setFullText(text());
}
} else if (role == "url") {
m_bookmark.setUrl(url());
} else if (role == "udi") {
m_bookmark.setMetaDataItem(QStringLiteral("UDI"), udi());
} else if (role == "applicationName") {
m_bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), applicationName());
} else if (role == "isSystemItem") {
m_bookmark.setMetaDataItem(QStringLiteral("isSystemItem"), isSystemItem() ? QStringLiteral("true") : QStringLiteral("false"));
} else if (role == "isHidden") {
m_bookmark.setMetaDataItem(QStringLiteral("IsHidden"), isHidden() ? QStringLiteral("true") : QStringLiteral("false"));
}
}
QString PlacesItem::generateNewId()
{
// The ID-generation must be different as done in KFilePlacesItem from kdelibs
// to prevent identical IDs, because 'count' is of course not shared. We append a
// " (V2)" to indicate that the ID has been generated by
// a new version of the places view.
static int count = 0;
return QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()) +
'/' + QString::number(count++) + " (V2)";
}
PlacesItemSignalHandler *PlacesItem::signalHandler() const
{
return m_signalHandler.data();
}
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef PLACESITEM_H
#define PLACESITEM_H
#include "kitemviews/kstandarditem.h"
#include <KBookmark>
#include <Solid/Device>
#include <Solid/OpticalDisc>
#include <Solid/PortableMediaPlayer>
#include <Solid/StorageAccess>
#include <Solid/StorageVolume>
#include <QPointer>
#include <QUrl>
class KDirLister;
class PlacesItemSignalHandler;
/**
* @brief Extends KStandardItem by places-specific properties.
*/
class PlacesItem : public KStandardItem
{
public:
explicit PlacesItem(const KBookmark& bookmark, PlacesItem* parent = nullptr);
~PlacesItem() override;
void setUrl(const QUrl& url);
QUrl url() const;
void setUdi(const QString& udi);
QString udi() const;
void setApplicationName(const QString& applicationName);
QString applicationName() const;
void setHidden(bool hidden);
bool isHidden() const;
void setGroupHidden(bool hidden);
bool isGroupHidden() const;
void setSystemItem(bool isSystemItem);
bool isSystemItem() const;
Solid::Device device() const;
void setBookmark(const KBookmark& bookmark);
KBookmark bookmark() const;
bool storageSetupNeeded() const;
bool isSearchOrTimelineUrl() const;
PlacesItemSignalHandler* signalHandler() const;
protected:
void onDataValueChanged(const QByteArray& role,
const QVariant& current,
const QVariant& previous) override;
void onDataChanged(const QHash<QByteArray, QVariant>& current,
const QHash<QByteArray, QVariant>& previous) override;
private:
PlacesItem(const PlacesItem& item);
void initializeDevice(const QString& udi);
/**
* Is invoked if the accessibility of the storage access
* m_access has been changed and updates the emblem.
*/
void onAccessibilityChanged();
/**
* Applies the data-value from the role to m_bookmark.
*/
void updateBookmarkForRole(const QByteArray& role);
static QString generateNewId();
private:
Solid::Device m_device;
QPointer<Solid::StorageAccess> m_access;
QPointer<Solid::StorageVolume> m_volume;
QPointer<Solid::OpticalDisc> m_disc;
QPointer<Solid::PortableMediaPlayer> m_player;
QPointer<PlacesItemSignalHandler> m_signalHandler;
KBookmark m_bookmark;
friend class PlacesItemSignalHandler; // Calls onAccessibilityChanged()
};
#endif
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* Based on the Itemviews NG project from Trolltech Labs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "placesitemlistgroupheader.h"
PlacesItemListGroupHeader::PlacesItemListGroupHeader(QGraphicsWidget* parent) :
KStandardItemListGroupHeader(parent)
{
}