File indexing completed on 2024-05-12 05:39:05

0001 /*
0002  *   SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef BASEDATA_H
0008 #define BASEDATA_H
0009 
0010 #include <QObject>
0011 
0012 #include "systemsettingsview_export.h"
0013 
0014 class QQmlEngine;
0015 class QString;
0016 class MenuItem;
0017 class KConfigGroup;
0018 
0019 /**
0020  * @brief Provides a interface sharing common data between modules in System Settings
0021  *
0022  * BaseData is a standard interface in System Settings to retrieve information that is shared between all modules.
0023  * It is a singleton, and will be automatically cleaned up.
0024  *
0025  * @author Ben Cooksley <bcooksley@kde.org>
0026  */
0027 class SYSTEMSETTINGSVIEW_EXPORT BaseData : public QObject
0028 {
0029     Q_OBJECT
0030     Q_DISABLE_COPY(BaseData)
0031 
0032 private:
0033     explicit BaseData();
0034 
0035 public:
0036     /**
0037      * Provides a pointer to access the shared BaseData instance in order to retrieve data.
0038      *
0039      * @returns Access to the shared instance of BaseData.
0040      */
0041     static BaseData *instance();
0042 
0043     /**
0044      * Normal destructor that handles cleanup. Any objects created through BaseData must be assumed
0045      * to be invalid afterwards.
0046      */
0047     ~BaseData() override;
0048 
0049     /**
0050      * Provides the shared MenuItem which lists all categories and modules, for use with MenuModel.
0051      *
0052      * @returns the shared MenuItem.
0053      */
0054     MenuItem *menuItem();
0055 
0056     /**
0057      * Sets the MenuItem which the Singleton will return.
0058      * For internal use only.
0059      *
0060      * @param item A pointer to the MenuItem object
0061      */
0062     void setMenuItem(MenuItem *item);
0063 
0064     /**
0065      * Provides the shared MenuItem that corresponds to a KCM which should be used as startup page.
0066      *
0067      * @returns the shared MenuItem. It may be nullptr.
0068      */
0069     MenuItem *homeItem();
0070 
0071     /**
0072      * Sets the homescreen MenuItem which the Singleton will return.
0073      * For internal use only.
0074      *
0075      * @param item A pointer to the MenuItem object
0076      */
0077     void setHomeItem(MenuItem *item);
0078 
0079     /**
0080      * Returns the configuration group by the name provided in the current applications configuration file.
0081      *
0082      * @param pluginName the name of the group that is required.
0083      * @returns The configuration group that is required.
0084      */
0085     KConfigGroup configGroup(const QString &pluginName);
0086 
0087     std::shared_ptr<QQmlEngine> qmlEngine();
0088 
0089 private:
0090     MenuItem *rootMenu;
0091     MenuItem *m_homeItem;
0092     std::shared_ptr<QQmlEngine> m_engine;
0093 };
0094 
0095 #endif