File indexing completed on 2024-07-14 15:41:26

0001 /*
0002  *   SPDX-FileCopyrightText: 2013 Julien Borderie <frajibe@gmail.com>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #ifndef configurationmanager_h
0009 #define configurationmanager_h
0010 
0011 #include <QMutex>
0012 #include <QObject>
0013 
0014 #include <KConfigGroup>
0015 
0016 /**
0017  * @brief The ConfigurationManager class contains allows to access/edit the application configuration.
0018  */
0019 class ConfigurationManager : public QObject
0020 {
0021     Q_OBJECT
0022 
0023 protected:
0024     static const QString GENERAL_CONFIG_GROUP;
0025     static const QString SHOW_HIDDEN_ENTRIES_PROPERTY_NAME;
0026     static const QString SPLITTER_SIZES_PROPERTY_NAME;
0027 
0028     static ConfigurationManager *m_instance;
0029 
0030     KConfigGroup m_configGroup;
0031 
0032 public:
0033     /**
0034      * @brief Return the singleton instance.
0035      *
0036      * @return Instance.
0037      */
0038     static ConfigurationManager *getInstance()
0039     {
0040         static QMutex mutex;
0041         if (!m_instance) {
0042             mutex.lock();
0043             if (!m_instance) {
0044                 m_instance = new ConfigurationManager();
0045             }
0046             mutex.unlock();
0047         }
0048         return m_instance;
0049     }
0050 
0051     /**
0052      * @brief Determine if hidden entries must be visible or not.
0053      *
0054      * @return True to show hidden entries, false else.
0055      */
0056     bool hiddenEntriesVisible() const;
0057 
0058     /**
0059      * @brief Replace the hidden entries visibility by the new one.
0060      *
0061      * @param visible True to show hidden entries, false else.
0062      */
0063     void setHiddenEntriesVisible(bool visible);
0064 
0065     /**
0066      * @brief Get the splitter sizes.
0067      *
0068      * @return Splitter sizes.
0069      */
0070     QList<int> getSplitterSizes() const;
0071 
0072     /**
0073      * @brief Replace splitter sizes by the new ones.
0074      *
0075      * @param sizes Splitter sizes.
0076      */
0077     void setSplitterSizes(const QList<int> &sizes);
0078 
0079 protected:
0080     ConfigurationManager();
0081     ConfigurationManager(const ConfigurationManager &); // hide copy constructor
0082     ConfigurationManager &operator=(const ConfigurationManager &); // hide assign op
0083 };
0084 
0085 #endif