systemsettings: get rid of BaseData

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-04 10:31:31 +03:00
parent 2bfdb90ae0
commit af7509ce3f
6 changed files with 5 additions and 157 deletions

View file

@ -36,7 +36,6 @@
#include <KActionCollection>
#include <KServiceTypeTrader>
#include "BaseData.h"
#include "ModuleView.h"
SettingsBase::SettingsBase( QWidget * parent )
@ -93,8 +92,6 @@ void SettingsBase::initApplication()
}
}
// Prepare the Base Data
BaseData::instance()->setMenuItem( rootModule );
// Load all possible views
const KService::List pluginObjects = KServiceTypeTrader::self()->query( "SystemSettingsView" );
const int nbPlugins = pluginObjects.count();
@ -104,7 +101,7 @@ void SettingsBase::initApplication()
BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error);
if( error.isEmpty() ) {
possibleViews.insert( activeService->library(), controller );
controller->init( activeService );
controller->init( rootModule, activeService );
connect(controller, SIGNAL(changeToolBarItems(BaseMode::ToolBarItems)), this, SLOT(changeToolBar(BaseMode::ToolBarItems)));
connect(controller, SIGNAL(actionsChanged()), this, SLOT(updateViewActions()));
connect(searchText, SIGNAL(textChanged(QString)), controller, SLOT(searchChanged(QString)));

View file

@ -1,65 +0,0 @@
/***************************************************************************
* Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org> *
* *
* 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 "BaseData.h"
#include "MenuItem.h"
#include <KConfigGroup>
class DataHelper {
public:
DataHelper() : object(0) {}
~DataHelper() {
delete object;
}
BaseData * object;
};
K_GLOBAL_STATIC(DataHelper, internalInstance)
BaseData::BaseData()
{
internalInstance->object = this;
}
BaseData::~BaseData()
{
}
BaseData *BaseData::instance()
{
if( !internalInstance->object ) {
new BaseData();
}
return internalInstance->object;
}
MenuItem * BaseData::menuItem()
{
return rootMenu;
}
void BaseData::setMenuItem( MenuItem * item )
{
rootMenu = item;
}
#include "moc_BaseData.cpp"

View file

@ -1,81 +0,0 @@
/***************************************************************************
* Copyright (C) 2009 Ben Cooksley <bcooksley@kde.org> *
* *
* 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 BASEDATA_H
#define BASEDATA_H
#include "systemsettingsview_export.h"
#include <QString>
#include <QObject>
class MenuItem;
class KConfigGroup;
/**
* @brief Provides a interface sharing common data between modules in System Settings
*
* BaseData is a standard interface in System Settings to retrieve information that is shared between all modules.
* It is a singleton, and will be automatically cleaned up.
*
* @author Ben Cooksley <bcooksley@kde.org>
*/
class SYSTEMSETTINGSVIEW_EXPORT BaseData : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(BaseData)
private:
explicit BaseData();
public:
/**
* Provides a pointer to access the shared BaseData instance in order to retrieve data.
*
* @returns Access to the shared instance of BaseData.
*/
static BaseData* instance();
/**
* Normal destructor that handles cleanup. Any objects created through BaseData must be assumed
* to be invalid afterwards.
*/
~BaseData();
/**
* Provides the shared MenuItem which lists all categories and modules, for use with MenuModel.
*
* @returns the shared MenuItem.
*/
MenuItem * menuItem();
/**
* Sets the MenuItem which the Singleton will return.
* For internal use only.
*
* @param item A pointer to the MenuItem object
*/
void setMenuItem( MenuItem * item );
private:
MenuItem * rootMenu;
};
#endif

View file

@ -28,12 +28,11 @@
#include <KServiceTypeTrader>
#include "MenuItem.h"
#include "BaseData.h"
#include "ModuleView.h"
class BaseMode::Private {
public:
Private() {}
Private() : rootItem(nullptr) {}
QList<QAction*> actionsList;
KService::Ptr service;
@ -52,9 +51,9 @@ BaseMode::~BaseMode()
delete d;
}
void BaseMode::init( const KService::Ptr modeService )
void BaseMode::init( MenuItem *rootItem, const KService::Ptr modeService )
{
d->rootItem = BaseData::instance()->menuItem();
d->rootItem = rootItem;
d->service = modeService;
d->config = KGlobal::config()->group( modeService->library() );
initEvent();

View file

@ -85,7 +85,7 @@ public:
*
* @param modeService Plugins service object, used for providing extra information to System Settings.
*/
void init( const KService::Ptr modeService );
void init( MenuItem *rootItem, const KService::Ptr modeService );
/**
* Prepares the BaseMode for use.\n

View file

@ -3,7 +3,6 @@ set(systemsettingsview_LIB_SRCS
MenuModel.cpp
MenuProxyModel.cpp
ModuleView.cpp
BaseData.cpp
BaseMode.cpp
ExternalAppModule.cpp
externalModule.ui
@ -14,7 +13,6 @@ set(systemsettingsview_LIB_HDRS
MenuItem.h
MenuModel.h
MenuProxyModel.h
BaseData.h
BaseMode.h
ModuleView.h
)