diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -202,6 +202,7 @@ dolphinviewcontainer.cpp dolphincontextmenu.cpp dolphintabbar.cpp + dolphinplacesmodelsingleton.cpp dolphinrecenttabsmenu.cpp dolphintabpage.cpp dolphintabwidget.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- 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::setUrlAsCaption(const QUrl& url) { - static KFilePlacesModel s_placesModel; - QString schemePrefix; if (!url.isLocalFile()) { schemePrefix.append(url.scheme() + " - "); @@ -1009,10 +1008,11 @@ 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.h b/src/dolphinplacesmodelsingleton.h new file mode 100644 --- /dev/null +++ b/src/dolphinplacesmodelsingleton.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2018 Kai Uwe Broulik * + * * + * 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 +#include + +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 m_placesModel; +}; + +#endif // DOLPHINPLACESMODELSINGLETON_H diff --git a/src/dolphinplacesmodelsingleton.cpp b/src/dolphinplacesmodelsingleton.cpp new file mode 100644 --- /dev/null +++ b/src/dolphinplacesmodelsingleton.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2018 Kai Uwe Broulik * + * * + * 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 +#include + +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/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp --- 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 -#include #include #include #include @@ -77,7 +77,7 @@ 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.h b/src/panels/places/placesitemmodel.h --- a/src/panels/places/placesitemmodel.h +++ b/src/panels/places/placesitemmodel.h @@ -228,7 +228,7 @@ QHash m_storageSetupInProgress; - QScopedPointer m_sourceModel; + KFilePlacesModel *m_sourceModel; QVector m_indexMap; }; diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp --- 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 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 balooURLs = { QUrl(QStringLiteral("timeline:/today")), QUrl(QStringLiteral("timeline:/yesterday")), @@ -62,18 +60,18 @@ 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 @@ 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 {