-rw-r--r-- | libopie2/opiecore/oconfig.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libopie2/opiecore/oconfig.h b/libopie2/opiecore/oconfig.h index 8c3060c..ab95dc3 100644 --- a/libopie2/opiecore/oconfig.h +++ b/libopie2/opiecore/oconfig.h | |||
@@ -1,154 +1,163 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | |||
5 | Inspired by the config classes from the KDE Project which are | 6 | Inspired by the config classes from the KDE Project which are |
6 | =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org> | 7 | =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org> |
7 | .=l. | 8 | .=l. |
8 | .>+-= | 9 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 16 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 24 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
30 | */ | 31 | */ |
31 | 32 | ||
32 | #ifndef OCONFIG_H | 33 | #ifndef OCONFIG_H |
33 | #define OCONFIG_H | 34 | #define OCONFIG_H |
34 | 35 | ||
35 | //FIXME: Implement for X11 or reuse libqpe/Config there also? | 36 | //FIXME: Implement for X11 or reuse libqpe/Config there also? |
36 | //FIXME: Or rather use QSettings also for libqpe? | 37 | //FIXME: Or rather use QSettings also for libqpe? |
37 | 38 | ||
38 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
39 | 40 | ||
40 | class QColor; | 41 | class QColor; |
41 | class QFont; | 42 | class QFont; |
42 | 43 | ||
43 | namespace Opie { | 44 | namespace Opie { |
44 | namespace Core { | 45 | namespace Core { |
45 | 46 | ||
46 | /** | 47 | /** |
47 | * A Configuration class based on the Qtopia @ref Config class | 48 | * A Configuration class based on the Qtopia @ref Config class |
48 | * featuring additional handling of color and font entries | 49 | * featuring additional handling of color and font entries |
49 | */ | 50 | */ |
50 | 51 | ||
51 | class OConfig : public Config | 52 | class OConfig : public Config |
52 | { | 53 | { |
53 | public: | 54 | public: |
54 | /** | 55 | /** |
55 | * Constructs a OConfig object with a @a name. | 56 | * Constructs a OConfig object with a @a name. |
56 | */ | 57 | */ |
57 | OConfig( const QString &name, Domain domain = User ); | 58 | OConfig( const QString &name, Domain domain = User ); |
58 | /** | 59 | /** |
59 | * Destructs the OConfig object. | 60 | * Destructs the OConfig object. |
60 | * | 61 | * |
61 | * Writes back any dirty configuration entries, and destroys | 62 | * Writes back any dirty configuration entries, and destroys |
62 | * dynamically created objects. | 63 | * dynamically created objects. |
63 | */ | 64 | */ |
64 | virtual ~OConfig(); | 65 | virtual ~OConfig(); |
65 | /** | 66 | /** |
66 | * @returns the name of the current group. | 67 | * @returns the name of the current group. |
67 | * The current group is used for searching keys and accessing entries. | 68 | * The current group is used for searching keys and accessing entries. |
68 | * @todo make const | 69 | * @todo make const |
69 | */ | 70 | */ |
70 | const QString& group()const { return git.key(); }; | 71 | const QString& group()const { return git.key(); }; |
71 | /** | 72 | /** |
72 | * @returns a @ref QColor entry or a @a default value if the key is not found. | 73 | * @returns a @ref QColor entry or a @a default value if the key is not found. |
73 | */ | 74 | */ |
74 | QColor readColorEntry( const QString& key, const QColor* pDefault ) const; | 75 | QColor readColorEntry( const QString& key, const QColor* pDefault ) const; |
75 | /** | 76 | /** |
76 | * @returns a @ref QFont value or a @a default value if the key is not found. | 77 | * @returns a @ref QFont value or a @a default value if the key is not found. |
77 | */ | 78 | */ |
78 | QFont readFontEntry( const QString& key, const QFont* pDefault ) const; | 79 | QFont readFontEntry( const QString& key, const QFont* pDefault ) const; |
79 | 80 | ||
80 | private: | 81 | private: |
81 | class Private; | 82 | class Private; |
82 | Private *d; | 83 | Private *d; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * @brief Helper class for easier use of OConfig groups. | 87 | * @brief Helper class for easier use of OConfig groups. |
87 | * | 88 | * |
88 | * Careful programmers always set the group of a | 89 | * Careful programmers always set the group of a |
89 | * @ref OConfig object to the group they want to read from | 90 | * @ref OConfig object to the group they want to read from |
90 | * and set it back to the old one of afterwards. This is usually | 91 | * and set it back to the old one of afterwards. This is usually |
91 | * written as: | 92 | * written as: |
92 | * <pre> | 93 | * <pre> |
93 | * | 94 | * |
94 | * QString oldgroup config()->group(); | 95 | * QString oldgroup config()->group(); |
95 | * config()->setGroup( "TheGroupThatIWant" ); | 96 | * config()->setGroup( "TheGroupThatIWant" ); |
96 | * ... | 97 | * ... |
97 | * config()->writeEntry( "Blah", "Blubb" ); | 98 | * config()->writeEntry( "Blah", "Blubb" ); |
98 | * | 99 | * |
99 | * config()->setGroup( oldgroup ); | 100 | * config()->setGroup( oldgroup ); |
100 | * </pre> | 101 | * </pre> |
101 | * | 102 | * |
102 | * In order to facilitate this task, you can use | 103 | * In order to facilitate this task, you can use |
103 | * OConfigGroupSaver. Simply construct such an object ON THE STACK | 104 | * OConfigGroupSaver. Simply construct such an object ON THE STACK |
104 | * when you want to switch to a new group. Then, when the object goes | 105 | * when you want to switch to a new group. Then, when the object goes |
105 | * out of scope, the group will automatically be restored. If you | 106 | * out of scope, the group will automatically be restored. If you |
106 | * want to use several different groups within a function or method, | 107 | * want to use several different groups within a function or method, |
107 | * you can still use OConfigGroupSaver: Simply enclose all work with | 108 | * you can still use OConfigGroupSaver: Simply enclose all work with |
108 | * one group (including the creation of the OConfigGroupSaver object) | 109 | * one group (including the creation of the OConfigGroupSaver object) |
109 | * in one block. | 110 | * in one block. |
110 | * | 111 | * |
112 | * \code | ||
113 | * OConfigGroupSaver saver(cfg,"TheGroupThatInWhat"); | ||
114 | * \endcode | ||
115 | * | ||
116 | * Note that OConfigGroupSaver (cfg,"TheGroupThatInWhat"); would get imediately | ||
117 | * destructed after created and that you would save in the old group which | ||
118 | * is unwished. | ||
119 | * | ||
111 | * @author Matthias Kalle Dalheimer <Kalle@kde.org> | 120 | * @author Matthias Kalle Dalheimer <Kalle@kde.org> |
112 | * @version $Id$ | 121 | * @version $Id$ |
113 | * @see OConfig | 122 | * @see OConfig |
114 | */ | 123 | */ |
115 | 124 | ||
116 | class OConfigGroupSaver | 125 | class OConfigGroupSaver |
117 | { | 126 | { |
118 | public: | 127 | public: |
119 | /** | 128 | /** |
120 | * Constructor. | 129 | * Constructor. |
121 | * Create the object giving a @config object and a @a group to become | 130 | * Create the object giving a @config object and a @a group to become |
122 | * the current group. | 131 | * the current group. |
123 | */ | 132 | */ |
124 | OConfigGroupSaver( OConfig* config, QString group ) :_config(config), _oldgroup(config->group() ) | 133 | OConfigGroupSaver( OConfig* config, QString group ) :_config(config), _oldgroup(config->group() ) |
125 | { _config->setGroup( group ); } | 134 | { _config->setGroup( group ); } |
126 | 135 | ||
127 | OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group()) | 136 | OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group()) |
128 | { _config->setGroup( group ); } | 137 | { _config->setGroup( group ); } |
129 | 138 | ||
130 | OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group()) | 139 | OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group()) |
131 | { _config->setGroup( group ); } | 140 | { _config->setGroup( group ); } |
132 | /** | 141 | /** |
133 | * Destructor. | 142 | * Destructor. |
134 | * Restores the last current group. | 143 | * Restores the last current group. |
135 | * @todo make it not inline for bc reasons. See KDE BC guide | 144 | * @todo make it not inline for bc reasons. See KDE BC guide |
136 | */ | 145 | */ |
137 | ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); } | 146 | ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); } |
138 | 147 | ||
139 | OConfig* config() { return _config; }; | 148 | OConfig* config() { return _config; }; |
140 | 149 | ||
141 | private: | 150 | private: |
142 | OConfig* _config; | 151 | OConfig* _config; |
143 | QString _oldgroup; | 152 | QString _oldgroup; |
144 | 153 | ||
145 | OConfigGroupSaver( const OConfigGroupSaver& ); | 154 | OConfigGroupSaver( const OConfigGroupSaver& ); |
146 | OConfigGroupSaver& operator=( const OConfigGroupSaver& ); | 155 | OConfigGroupSaver& operator=( const OConfigGroupSaver& ); |
147 | 156 | ||
148 | class Private; | 157 | class Private; |
149 | Private *d; | 158 | Private *d; |
150 | }; | 159 | }; |
151 | } | 160 | } |
152 | } | 161 | } |
153 | 162 | ||
154 | #endif // OCONFIG_H | 163 | #endif // OCONFIG_H |