SettingsManager.h 3.32 KB
Newer Older
Clement CHAVANCE's avatar
Clement CHAVANCE committed
1
2
3
/*****************************************************************************
 * SettingsManager.h: Backend settings manager
 *****************************************************************************
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
4
 * Copyright (C) 2008-2009 VideoLAN
Clement CHAVANCE's avatar
Clement CHAVANCE committed
5
 *
6
 * Authors: Clement CHAVANCE <chavance.c@gmail.com>
Clement CHAVANCE's avatar
Clement CHAVANCE committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * 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 SETTINGSMANAGER_H
#define SETTINGSMANAGER_H

26
#include <Singleton.hpp>
27

28
#include <QString>
Clement CHAVANCE's avatar
Clement CHAVANCE committed
29
#include <QHash>
30
#include <QObject>
Clement CHAVANCE's avatar
Clement CHAVANCE committed
31
32
33
#include <QReadWriteLock>
#include <QVariant>

34
35
36
37
class SettingValue;
class QXmlStreamWriter;
class QDomElement;
class SettingValue;
38

39
class   SettingsManager : public QObject, public Singleton<SettingsManager>
Clement CHAVANCE's avatar
Clement CHAVANCE committed
40
{
41
    Q_OBJECT
42
    Q_DISABLE_COPY( SettingsManager )
43
    public:
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        typedef QHash<QString, SettingValue*>    SettingHash;
        enum Type
        {
            XML,
            QSett,
            All
        };

        void                        setValue( const QString &key,
                                                    const QVariant &value,
                                                    SettingsManager::Type type = QSett);
        void                        setImmediateValue( const QString &key,
                                         const QVariant &value,
                                         SettingsManager::Type = QSett);
        QVariant                    value( const QString &key,
                                           const QVariant &defaultValue = QVariant(),
                                           SettingsManager::Type type = QSett );
        QHash<QString, QVariant>    group( const QString &groupName,
                                           SettingsManager::Type type = QSett );

        bool                        watchValue( const QString &key,
                                                QObject* receiver,
                                                const char *method,
                                                SettingsManager::Type type );
        void          save() const;
        void          save( QXmlStreamWriter &stream ) const;
        bool          load( QDomElement &element );

        bool          commit( SettingsManager::Type type );
        void          flush();
Clement CHAVANCE's avatar
Clement CHAVANCE committed
74

75
    private:
76
77
        friend class Singleton<SettingsManager>;
        SettingsManager();
78
        ~SettingsManager();
Clement CHAVANCE's avatar
Clement CHAVANCE committed
79

80
81
        SettingHash                 m_classicSettings;
        SettingHash                 m_xmlSettings;
82

83
84
        SettingHash                 m_tmpClassicSettings;
        SettingHash                 m_tmpXmlSettings;
85

86
        mutable QReadWriteLock      m_rwLock;
87
};
Clement CHAVANCE's avatar
Clement CHAVANCE committed
88
89

#endif