diff --git a/src/dolphindockwidget.cpp b/src/dolphindockwidget.cpp index 726338377..32d25702a 100644 --- a/src/dolphindockwidget.cpp +++ b/src/dolphindockwidget.cpp @@ -1,96 +1,88 @@ /*************************************************************************** * Copyright (C) 2010 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "dolphindockwidget.h" #include namespace { // Disable the 'Floatable' feature, i.e., the possibility to drag the // dock widget out of the main window. This works around problems like // https://bugs.kde.org/show_bug.cgi?id=288629 // https://bugs.kde.org/show_bug.cgi?id=322299 const QDockWidget::DockWidgetFeatures DefaultDockWidgetFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable; } // Empty titlebar for the dock widgets when "Lock Layout" has been activated. class DolphinDockTitleBar : public QWidget { Q_OBJECT public: explicit DolphinDockTitleBar(QWidget* parent = nullptr) : QWidget(parent) {} ~DolphinDockTitleBar() override {} QSize minimumSizeHint() const override { const int border = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin); return QSize(border, border); } QSize sizeHint() const override { return minimumSizeHint(); } }; DolphinDockWidget::DolphinDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags) : QDockWidget(title, parent, flags), m_locked(false), m_dockTitleBar(nullptr) { setFeatures(DefaultDockWidgetFeatures); } -DolphinDockWidget::DolphinDockWidget(QWidget* parent, Qt::WindowFlags flags) : - QDockWidget(parent, flags), - m_locked(false), - m_dockTitleBar(nullptr) -{ - setFeatures(DefaultDockWidgetFeatures); -} - DolphinDockWidget::~DolphinDockWidget() { } void DolphinDockWidget::setLocked(bool lock) { if (lock != m_locked) { m_locked = lock; if (lock) { if (!m_dockTitleBar) { m_dockTitleBar = new DolphinDockTitleBar(this); } setTitleBarWidget(m_dockTitleBar); setFeatures(QDockWidget::NoDockWidgetFeatures); } else { setTitleBarWidget(nullptr); setFeatures(DefaultDockWidgetFeatures); } } } bool DolphinDockWidget::isLocked() const { return m_locked; } #include "dolphindockwidget.moc" diff --git a/src/dolphindockwidget.h b/src/dolphindockwidget.h index c4fcbf753..0b745f083 100644 --- a/src/dolphindockwidget.h +++ b/src/dolphindockwidget.h @@ -1,49 +1,48 @@ /*************************************************************************** * Copyright (C) 2010 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef DOLPHIN_DOCK_WIDGET_H #define DOLPHIN_DOCK_WIDGET_H #include /** * @brief Extends QDockWidget to be able to get locked. */ class DolphinDockWidget : public QDockWidget { Q_OBJECT public: - explicit DolphinDockWidget(const QString& title, QWidget* parent = nullptr, Qt::WindowFlags flags = nullptr); - explicit DolphinDockWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = nullptr); + explicit DolphinDockWidget(const QString& title = QString(), QWidget* parent = nullptr, Qt::WindowFlags flags = nullptr); ~DolphinDockWidget() override; /** * @param lock If \a lock is true, the title bar of the dock-widget will get hidden so * that it is not possible for the user anymore to move or undock the dock-widget. */ void setLocked(bool lock); bool isLocked() const; private: bool m_locked; QWidget* m_dockTitleBar; }; #endif diff --git a/src/panels/panel.cpp b/src/panels/panel.cpp index 30cff509d..40f816158 100644 --- a/src/panels/panel.cpp +++ b/src/panels/panel.cpp @@ -1,77 +1,76 @@ /*************************************************************************** * Copyright (C) 2006 by Cvetoslav Ludmiloff * * Copyright (C) 2006-2010 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "panel.h" Panel::Panel(QWidget* parent) : QWidget(parent), m_url(), m_customContextMenuActions() { } Panel::~Panel() { } QUrl Panel::url() const { return m_url; } void Panel::setCustomContextMenuActions(const QList& actions) { m_customContextMenuActions = actions; } QList Panel::customContextMenuActions() const { return m_customContextMenuActions; } QSize Panel::sizeHint() const { // The size hint will be requested already when starting Dolphin even // if the panel is invisible. For performance reasons most panels delay // the creation and initialization of widgets until a showEvent() is called. // Because of this the size-hint of the embedded widgets cannot be used // and a default size is provided: return QSize(180, 180); } void Panel::setUrl(const QUrl& url) { if (url.matches(m_url, QUrl::StripTrailingSlash)) { return; } const QUrl oldUrl = m_url; m_url = url; - const bool accepted = urlChanged(); - if (!accepted) { + if (!urlChanged()) { m_url = oldUrl; } } void Panel::readSettings() { } diff --git a/src/panels/places/placesitem.cpp b/src/panels/places/placesitem.cpp index 10b87086c..9f9041bfa 100644 --- a/src/panels/places/placesitem.cpp +++ b/src/panels/places/placesitem.cpp @@ -1,274 +1,271 @@ /*************************************************************************** * Copyright (C) 2012 by Peter Penz * * * * Based on KFilePlacesItem from kdelibs: * * Copyright (C) 2007 Kevin Ottens * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "placesitem.h" #include "trash/dolphintrash.h" #include "dolphindebug.h" #include "placesitemsignalhandler.h" #include #include #include PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) : KStandardItem(parent), m_device(), m_access(), m_volume(), m_disc(), m_mtp(), m_signalHandler(nullptr), - m_trashDirLister(nullptr), m_bookmark() { m_signalHandler = new PlacesItemSignalHandler(this); setBookmark(bookmark); } PlacesItem::~PlacesItem() { delete m_signalHandler; - delete m_trashDirLister; } 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) { - delete m_trashDirLister; 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::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_mtp; 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& current, const QHash& previous) { Q_UNUSED(previous); if (!m_bookmark.isNull()) { QHashIterator 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(); m_volume = m_device.as(); m_disc = m_device.as(); m_mtp = m_device.as(); setText(m_device.description()); 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(); if (block) { const QString device = block->device(); setUrl(QUrl(QStringLiteral("audiocd:/?device=%1").arg(device))); } else { setUrl(QUrl(QStringLiteral("audiocd:/"))); } } else if (m_mtp) { setUrl(QUrl(QStringLiteral("mtp:udi=%1").arg(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 == "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().toTime_t()) + '/' + QString::number(count++) + " (V2)"; } PlacesItemSignalHandler *PlacesItem::signalHandler() const { return m_signalHandler.data(); } diff --git a/src/panels/places/placesitem.h b/src/panels/places/placesitem.h index 3de626983..1677cca19 100644 --- a/src/panels/places/placesitem.h +++ b/src/panels/places/placesitem.h @@ -1,116 +1,115 @@ /*************************************************************************** * Copyright (C) 2012 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef PLACESITEM_H #define PLACESITEM_H #include "kitemviews/kstandarditem.h" #include #include #include #include #include #include #include #include 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 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& current, const QHash& 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 m_access; QPointer m_volume; QPointer m_disc; QPointer m_mtp; QPointer m_signalHandler; - QPointer m_trashDirLister; KBookmark m_bookmark; friend class PlacesItemSignalHandler; // Calls onAccessibilityChanged() }; #endif diff --git a/src/panels/places/placesitemsignalhandler.cpp b/src/panels/places/placesitemsignalhandler.cpp index b313f838f..1341b7413 100644 --- a/src/panels/places/placesitemsignalhandler.cpp +++ b/src/panels/places/placesitemsignalhandler.cpp @@ -1,60 +1,59 @@ /*************************************************************************** * Copyright (C) 2012 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "placesitemsignalhandler.h" #include "placesitem.h" PlacesItemSignalHandler::PlacesItemSignalHandler(PlacesItem* item, QObject* parent) : QObject(parent), m_item(item) { } PlacesItemSignalHandler::~PlacesItemSignalHandler() { } void PlacesItemSignalHandler::onAccessibilityChanged() { if (m_item) { m_item->onAccessibilityChanged(); } } void PlacesItemSignalHandler::onTearDownRequested(const QString& udi) { Q_UNUSED(udi) if (m_item) { Solid::StorageAccess *tmp = m_item->device().as(); if (tmp) { - QString mountPath = tmp->filePath(); - emit tearDownExternallyRequested(mountPath); + emit tearDownExternallyRequested(tmp->filePath()); } } } void PlacesItemSignalHandler::onTrashEmptinessChanged(bool isTrashEmpty) { if (m_item) { m_item->setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full")); } }