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
dolphinviewcontainer.cpp
dolphincontextmenu.cpp
dolphintabbar.cpp
+ dolphinplacesmodelsingleton.cpp
dolphinrecenttabsmenu.cpp
dolphintabpage.cpp
dolphintabwidget.cpp
#include "dolphindockwidget.h"
#include "dolphincontextmenu.h"
#include "dolphinnewfilemenu.h"
+#include "dolphinplacesmodelsingleton.h"
#include "dolphinrecenttabsmenu.h"
#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
{
- static KFilePlacesModel s_placesModel;
-
QString schemePrefix;
if (!url.isLocalFile()) {
schemePrefix.append(url.scheme() + " - ");
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;
}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2018 Kai Uwe Broulik <kde@privat.broulik.de> *
+ * *
+ * 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");
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2018 Kai Uwe Broulik <kde@privat.broulik.de> *
+ * *
+ * 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
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
+#include "dolphinplacesmodelsingleton.h"
#include "dolphindebug.h"
#include "filterbar/filterbar.h"
#include "global.h"
#include "views/viewproperties.h"
#include <KFileItemActions>
-#include <KFilePlacesModel>
#include <KIO/PreviewJob>
#include <KLocalizedString>
#include <KMessageWidget>
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,
#include "dolphin_generalsettings.h"
#include "dolphindebug.h"
+#include "dolphinplacesmodelsingleton.h"
#include "placesitem.h"
#include "placesitemsignalhandler.h"
#include "views/dolphinview.h"
#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")),
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()
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 {
QHash<QObject*, int> m_storageSetupInProgress;
- QScopedPointer<KFilePlacesModel> m_sourceModel;
+ KFilePlacesModel *m_sourceModel;
QVector<QPersistentModelIndex> m_indexMap;
};