|
1 /* * This file is part of libgq * |
|
2 * |
|
3 * Copyright (C) 2009 Nokia Corporation. |
|
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 \warning GConfItem is as thread-safe as GConf. |
|
63 |
|
64 */ |
|
65 |
|
66 class GConfItem : public QObject |
|
67 { |
|
68 Q_OBJECT |
|
69 |
|
70 public: |
|
71 /*! Initializes a GConfItem to access the GConf key denoted by |
|
72 \a key. Key names should follow the normal GConf conventions |
|
73 like "/myapp/settings/first". |
|
74 |
|
75 \param key The name of the key. |
|
76 \param parent Parent object |
|
77 */ |
|
78 explicit GConfItem(const QString &key, QObject *parent = 0); |
|
79 |
|
80 /*! Finalizes a GConfItem. |
|
81 */ |
|
82 virtual ~GConfItem(); |
|
83 |
|
84 /*! Returns the key of this item, as given to the constructor. |
|
85 */ |
|
86 QString key() const; |
|
87 |
|
88 /*! Returns the current value of this item, as a QVariant. |
|
89 */ |
|
90 QVariant value() const; |
|
91 |
|
92 /*! Returns the current value of this item, as a QVariant. If |
|
93 * there is no value for this item, return \a def instead. |
|
94 */ |
|
95 QVariant value(const QVariant &def) const; |
|
96 |
|
97 /*! Set the value of this item to \a val. If \a val can not be |
|
98 represented in GConf or GConf refuses to accept it for other |
|
99 reasons, the current value is not changed and nothing happens. |
|
100 |
|
101 When the new value is different from the old value, the |
|
102 changedValue() signal is emitted on this GConfItem as part |
|
103 of calling set(), but other GConfItem:s for the same key do |
|
104 only receive a notification once the main loop runs. |
|
105 |
|
106 \param val The new value. |
|
107 */ |
|
108 void set(const QVariant &val); |
|
109 |
|
110 /*! Unset this item. This is equivalent to |
|
111 |
|
112 \code |
|
113 item.set(QVariant(QVariant::Invalid)); |
|
114 \endcode |
|
115 */ |
|
116 void unset(); |
|
117 |
|
118 /*! Return a list of the directories below this item. The |
|
119 returned strings are absolute key names like |
|
120 "/myapp/settings". |
|
121 |
|
122 A directory is a key that has children. The same key might |
|
123 also have a value, but that is confusing and best avoided. |
|
124 */ |
|
125 QList<QString> listDirs() const; |
|
126 |
|
127 /*! Return a list of entries below this item. The returned |
|
128 strings are absolute key names like "/myapp/settings/first". |
|
129 |
|
130 A entry is a key that has a value. The same key might also |
|
131 have children, but that is confusing and is best avoided. |
|
132 */ |
|
133 QList<QString> listEntries() const; |
|
134 |
|
135 signals: |
|
136 /*! Emitted when the value of this item has changed. |
|
137 */ |
|
138 void valueChanged(); |
|
139 |
|
140 private: |
|
141 friend struct GConfItemPrivate; |
|
142 struct GConfItemPrivate *priv; |
|
143 |
|
144 void update_value(bool emit_signal); |
|
145 }; |
|
146 |
|
147 #endif // GCONFITEM_H |