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