Changeset View
Changeset View
Standalone View
Standalone View
plugins/systemvolume/gconfitem.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2009 Nokia Corporation. | ||||
3 | * Copyright (C) 2016 David Edmundson <davidedmundson@kde.org> | ||||
4 | * | ||||
5 | * Contact: Marius Vollmer <marius.vollmer@nokia.com> | ||||
6 | * | ||||
7 | * This library is free software; you can redistribute it and/or | ||||
8 | * modify it under the terms of the GNU Lesser General Public License | ||||
9 | * version 2.1 as published by the Free Software Foundation. | ||||
10 | * | ||||
11 | * This library is distributed in the hope that it will be useful, but | ||||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
14 | * Lesser General Public License for more details. | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU Lesser General Public | ||||
17 | * License along with this library; if not, write to the Free Software | ||||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||||
19 | * 02110-1301 USA | ||||
20 | * | ||||
21 | */ | ||||
22 | | ||||
23 | #ifndef GCONFITEM_H | ||||
24 | #define GCONFITEM_H | ||||
25 | | ||||
26 | #include <QVariant> | ||||
27 | #include <QStringList> | ||||
28 | #include <QObject> | ||||
29 | | ||||
30 | /*! | ||||
31 | | ||||
32 | \brief GConfItem is a simple C++ wrapper for GConf. | ||||
33 | | ||||
34 | Creating a GConfItem instance gives you access to a single GConf | ||||
35 | key. You can get and set its value, and connect to its | ||||
36 | valueChanged() signal to be notified about changes. | ||||
37 | | ||||
38 | The value of a GConf key is returned to you as a QVariant, and you | ||||
39 | pass in a QVariant when setting the value. GConfItem converts | ||||
40 | between a QVariant and GConf values as needed, and according to the | ||||
41 | following rules: | ||||
42 | | ||||
43 | - A QVariant of type QVariant::Invalid denotes an unset GConf key. | ||||
44 | | ||||
45 | - QVariant::Int, QVariant::Double, QVariant::Bool are converted to | ||||
46 | and from the obvious equivalents. | ||||
47 | | ||||
48 | - QVariant::String is converted to/from a GConf string and always | ||||
49 | uses the UTF-8 encoding. No other encoding is supported. | ||||
50 | | ||||
51 | - QVariant::StringList is converted to a list of UTF-8 strings. | ||||
52 | | ||||
53 | - QVariant::List (which denotes a QList<QVariant>) is converted | ||||
54 | to/from a GConf list. All elements of such a list must have the | ||||
55 | same type, and that type must be one of QVariant::Int, | ||||
56 | QVariant::Double, QVariant::Bool, or QVariant::String. (A list of | ||||
57 | strings is returned as a QVariant::StringList, however, when you | ||||
58 | get it back.) | ||||
59 | | ||||
60 | - Any other QVariant or GConf value is essentially ignored. | ||||
61 | | ||||
62 | - This is fored by Dave from libqtgconf to really reduce the amount of QObjects needed | ||||
63 | to manipulate various items in a tree. | ||||
64 | | ||||
65 | | ||||
66 | \warning GConfItem is as thread-safe as GConf. | ||||
67 | | ||||
68 | */ | ||||
69 | | ||||
70 | | ||||
71 | class GConfItem : public QObject | ||||
72 | { | ||||
73 | Q_OBJECT | ||||
74 | | ||||
75 | public: | ||||
76 | /*! Initializes a GConfItem to access the GConf key denoted by | ||||
77 | \a key. Key names should follow the normal GConf conventions | ||||
78 | like "/myapp/settings/first". | ||||
79 | | ||||
80 | \param key The name of the key. | ||||
81 | \param parent Parent object | ||||
82 | */ | ||||
83 | explicit GConfItem(const QString &keyRoot, QObject *parent = 0); | ||||
84 | | ||||
85 | /*! Finalizes a GConfItem. | ||||
86 | */ | ||||
87 | virtual ~GConfItem(); | ||||
88 | | ||||
89 | /*! Returns the root of this item, as given to the constructor. | ||||
90 | */ | ||||
91 | QString root() const; | ||||
92 | | ||||
93 | /*! Returns the current value of this item, as a QVariant. | ||||
94 | * subkey is realtive to the provided root. | ||||
95 | */ | ||||
96 | QVariant value(const QString &subKey) const; | ||||
97 | | ||||
98 | /*! Returns the current value of this item, as a QVariant. If | ||||
99 | * there is no value for this item, return \a def instead. | ||||
100 | | ||||
101 | */ | ||||
102 | void set(const QString &subKey, const QVariant &val); | ||||
103 | | ||||
104 | /*! Return a list of the directories below this item. The | ||||
105 | returned strings are absolute key names like | ||||
106 | "/myapp/settings". | ||||
107 | | ||||
108 | A directory is a key that has children. The same key might | ||||
109 | also have a value, but that is confusing and best avoided. | ||||
110 | */ | ||||
111 | QList<QString> listDirs() const; | ||||
112 | | ||||
113 | /*! Return a list of entries below this item. The returned | ||||
114 | strings are absolute key names like "/myapp/settings/first". | ||||
115 | | ||||
116 | A entry is a key that has a value. The same key might also | ||||
117 | have children, but that is confusing and is best avoided. | ||||
118 | */ | ||||
119 | QList<QString> listEntries() const; | ||||
120 | | ||||
121 | Q_SIGNALS: | ||||
122 | /*! Emitted when some value in subtree of this item changes | ||||
123 | */ | ||||
124 | | ||||
125 | void subtreeChanged(const QString& key, const QVariant& value); | ||||
126 | | ||||
127 | private: | ||||
128 | friend struct GConfItemPrivate; | ||||
129 | struct GConfItemPrivate *priv; | ||||
130 | | ||||
131 | void update_value(bool emit_signal, const QString& key, const QVariant& value); | ||||
132 | }; | ||||
133 | | ||||
134 | #endif // GCONFITEM_H |