┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2018-03-19 09:57:24 +0100
committerKai Uwe Broulik <[email protected]>2018-03-19 09:57:24 +0100
commit7cee23157f099837fffc22380b85ac33a2006a49 (patch)
tree7db6d1f55e74f9d518b94a1147f1cd8699a72ea9
parent6f05c66cc0d2416a21fd8eaff0ec6e7a9161d59c (diff)
Introduce singleton for KFilePlacesModel
There are various places where Dolphin created a new KFilePlacesModel which would then query all storage devices and do other expensive work. Differential Revision: https://phabricator.kde.org/D11283
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/dolphinmainwindow.cpp8
-rw-r--r--src/dolphinplacesmodelsingleton.cpp45
-rw-r--r--src/dolphinplacesmodelsingleton.h51
-rw-r--r--src/dolphinviewcontainer.cpp4
-rw-r--r--src/panels/places/placesitemmodel.cpp20
-rw-r--r--src/panels/places/placesitemmodel.h2
7 files changed, 113 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 58af19ebd..7b7037003 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -202,6 +202,7 @@ set(dolphinstatic_SRCS
dolphinviewcontainer.cpp
dolphincontextmenu.cpp
dolphintabbar.cpp
+ dolphinplacesmodelsingleton.cpp
dolphinrecenttabsmenu.cpp
dolphintabpage.cpp
dolphintabwidget.cpp
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index b09d7deef..d112007bc 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -25,6 +25,7 @@
#include "dolphindockwidget.h"
#include "dolphincontextmenu.h"
#include "dolphinnewfilemenu.h"
+#include "dolphinplacesmodelsingleton.h"
#include "dolphinrecenttabsmenu.h"
#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
@@ -993,8 +994,6 @@ void DolphinMainWindow::tabCountChanged(int count)
void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
{
- static KFilePlacesModel s_placesModel;
-
QString schemePrefix;
if (!url.isLocalFile()) {
schemePrefix.append(url.scheme() + " - ");
@@ -1009,10 +1008,11 @@ void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
return;
}
- const auto& matchedPlaces = s_placesModel.match(s_placesModel.index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
+ KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
+ const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
if (!matchedPlaces.isEmpty()) {
- setWindowTitle(s_placesModel.text(matchedPlaces.first()));
+ setWindowTitle(placesModel->text(matchedPlaces.first()));
return;
}
diff --git a/src/dolphinplacesmodelsingleton.cpp b/src/dolphinplacesmodelsingleton.cpp
new file mode 100644
index 000000000..1020ba186
--- /dev/null
+++ b/src/dolphinplacesmodelsingleton.cpp
@@ -0,0 +1,45 @@
+/***************************************************************************
+ * Copyright (C) 2018 Kai Uwe Broulik <[email protected]> *
+ * *
+ * 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 "dolphinplacesmodelsingleton.h"
+
+#include <KAboutData>
+#include <KFilePlacesModel>
+
+DolphinPlacesModelSingleton::DolphinPlacesModelSingleton()
+ : m_placesModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
+{
+
+}
+
+DolphinPlacesModelSingleton &DolphinPlacesModelSingleton::instance()
+{
+ static DolphinPlacesModelSingleton s_self;
+ return s_self;
+}
+
+KFilePlacesModel *DolphinPlacesModelSingleton::placesModel() const
+{
+ return m_placesModel.data();
+}
+
+QString DolphinPlacesModelSingleton::applicationNameSuffix()
+{
+ return QStringLiteral("-places-panel");
+}
diff --git a/src/dolphinplacesmodelsingleton.h b/src/dolphinplacesmodelsingleton.h
new file mode 100644
index 000000000..6bce25d16
--- /dev/null
+++ b/src/dolphinplacesmodelsingleton.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2018 Kai Uwe Broulik <[email protected]> *
+ * *
+ * 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 DOLPHINPLACESMODELSINGLETON_H
+#define DOLPHINPLACESMODELSINGLETON_H
+
+#include <QString>
+#include <QScopedPointer>
+
+class KFilePlacesModel;
+
+/**
+ * @brief Provides a global KFilePlacesModel instance.
+ */
+class DolphinPlacesModelSingleton
+{
+
+public:
+ static DolphinPlacesModelSingleton& instance();
+
+ KFilePlacesModel *placesModel() const;
+ /** A suffix to the application-name of the stored bookmarks is
+ added, which is only read by PlacesItemModel. */
+ static QString applicationNameSuffix();
+
+ DolphinPlacesModelSingleton(const DolphinPlacesModelSingleton&) = delete;
+ DolphinPlacesModelSingleton& operator=(const DolphinPlacesModelSingleton&) = delete;
+
+private:
+ DolphinPlacesModelSingleton();
+
+ QScopedPointer<KFilePlacesModel> m_placesModel;
+};
+
+#endif // DOLPHINPLACESMODELSINGLETON_H
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp
index 2b829f4e0..dc9b4538f 100644
--- a/src/dolphinviewcontainer.cpp
+++ b/src/dolphinviewcontainer.cpp
@@ -20,6 +20,7 @@
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
+#include "dolphinplacesmodelsingleton.h"
#include "dolphindebug.h"
#include "filterbar/filterbar.h"
#include "global.h"
@@ -30,7 +31,6 @@
#include "views/viewproperties.h"
#include <KFileItemActions>
-#include <KFilePlacesModel>
#include <KIO/PreviewJob>
#include <KLocalizedString>
#include <KMessageWidget>
@@ -77,7 +77,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
navigatorLayout->setSpacing(0);
navigatorLayout->setMargin(0);
- m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
+ m_urlNavigator = new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, this);
connect(m_urlNavigator, &KUrlNavigator::activated,
this, &DolphinViewContainer::activate);
connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged,
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index 207a98271..444ad29ea 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -25,6 +25,7 @@
#include "dolphin_generalsettings.h"
#include "dolphindebug.h"
+#include "dolphinplacesmodelsingleton.h"
#include "placesitem.h"
#include "placesitemsignalhandler.h"
#include "views/dolphinview.h"
@@ -42,9 +43,6 @@
#include <QTimer>
namespace {
- // A suffix to the application-name of the stored bookmarks is
- // added, which is only read by PlacesItemModel.
- const QString AppNameSuffix = QStringLiteral("-places-panel");
static QList<QUrl> balooURLs = {
QUrl(QStringLiteral("timeline:/today")),
QUrl(QStringLiteral("timeline:/yesterday")),
@@ -62,18 +60,18 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
m_hiddenItemsShown(false),
m_deviceToTearDown(nullptr),
m_storageSetupInProgress(),
- m_sourceModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + AppNameSuffix, this))
+ m_sourceModel(DolphinPlacesModelSingleton::instance().placesModel())
{
cleanupBookmarks();
loadBookmarks();
initializeDefaultViewProperties();
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved);
- connect(m_sourceModel.data(), &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged);
+ connect(m_sourceModel, &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted);
+ connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved);
+ connect(m_sourceModel, &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged);
+ connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved);
+ connect(m_sourceModel, &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved);
+ connect(m_sourceModel, &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged);
}
PlacesItemModel::~PlacesItemModel()
@@ -622,7 +620,7 @@ void PlacesItemModel::cleanupBookmarks()
const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp"));
if ((appName == KAboutData::applicationData().componentName() ||
- appName == KAboutData::applicationData().componentName() + AppNameSuffix) && balooURLs.contains(url)) {
+ appName == KAboutData::applicationData().componentName() + DolphinPlacesModelSingleton::applicationNameSuffix()) && balooURLs.contains(url)) {
qCDebug(DolphinDebug) << "Removing old baloo url:" << url;
m_sourceModel->removePlace(sourceIndex);
} else {
diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h
index 1aa31facd..a2086efc5 100644
--- a/src/panels/places/placesitemmodel.h
+++ b/src/panels/places/placesitemmodel.h
@@ -228,7 +228,7 @@ private:
QHash<QObject*, int> m_storageSetupInProgress;
- QScopedPointer<KFilePlacesModel> m_sourceModel;
+ KFilePlacesModel *m_sourceModel;
QVector<QPersistentModelIndex> m_indexMap;
};