Diffstat (limited to 'libopie2/opiecore/oconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oconfig.cpp | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/libopie2/opiecore/oconfig.cpp b/libopie2/opiecore/oconfig.cpp new file mode 100644 index 0000000..40edbc7 --- a/dev/null +++ b/libopie2/opiecore/oconfig.cpp | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | Inspired by the config classes from the KDE Project which are | ||
6 | =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org> | ||
7 | .=l. | ||
8 | .>+-= | ||
9 | _;:, .> :=|. This program is free software; you can | ||
10 | .> <`_, > . <= redistribute it and/or modify it under | ||
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
12 | .="- .-=="i, .._ License as published by the Free Software | ||
13 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
14 | ._= =} : or (at your option) any later version. | ||
15 | .%`+i> _;_. | ||
16 | .i_,=:_. -<s. This program is distributed in the hope that | ||
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
18 | : .. .:, . . . without even the implied warranty of | ||
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
21 | ..}^=.= = ; Library General Public License for more | ||
22 | ++= -. .` .: details. | ||
23 | : = ...= . :.=- | ||
24 | -. .:....=;==+<; You should have received a copy of the GNU | ||
25 | -_. . . )=. = Library General Public License along with | ||
26 | -- :-=` this library; see the file COPYING.LIB. | ||
27 | If not, write to the Free Software Foundation, | ||
28 | Inc., 59 Temple Place - Suite 330, | ||
29 | Boston, MA 02111-1307, USA. | ||
30 | */ | ||
31 | |||
32 | /* QT */ | ||
33 | |||
34 | #include <qfont.h> | ||
35 | #include <qcolor.h> | ||
36 | |||
37 | /* OPIE */ | ||
38 | |||
39 | #include <opie2/oconfig.h> | ||
40 | |||
41 | OConfig::OConfig( const QString &name, Domain domain ) | ||
42 | :Config( name, domain ) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | OConfig::~OConfig() | ||
47 | { | ||
48 | } | ||
49 | |||
50 | QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const | ||
51 | { | ||
52 | QColor aRetColor; | ||
53 | int nRed = 0, nGreen = 0, nBlue = 0; | ||
54 | |||
55 | QString aValue = readEntry( key ); | ||
56 | if( !aValue.isEmpty() ) | ||
57 | { | ||
58 | if ( aValue.at(0) == '#' ) | ||
59 | { | ||
60 | aRetColor.setNamedColor(aValue); | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | bool bOK; | ||
65 | |||
66 | // find first part (red) | ||
67 | int nIndex = aValue.find( ',' ); | ||
68 | |||
69 | if( nIndex == -1 ) | ||
70 | { | ||
71 | // return a sensible default -- Bernd | ||
72 | if( pDefault ) | ||
73 | aRetColor = *pDefault; | ||
74 | return aRetColor; | ||
75 | } | ||
76 | |||
77 | nRed = aValue.left( nIndex ).toInt( &bOK ); | ||
78 | |||
79 | // find second part (green) | ||
80 | int nOldIndex = nIndex; | ||
81 | nIndex = aValue.find( ',', nOldIndex+1 ); | ||
82 | |||
83 | if( nIndex == -1 ) | ||
84 | { | ||
85 | // return a sensible default -- Bernd | ||
86 | if( pDefault ) | ||
87 | aRetColor = *pDefault; | ||
88 | return aRetColor; | ||
89 | } | ||
90 | nGreen = aValue.mid( nOldIndex+1, | ||
91 | nIndex-nOldIndex-1 ).toInt( &bOK ); | ||
92 | |||
93 | // find third part (blue) | ||
94 | nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK ); | ||
95 | |||
96 | aRetColor.setRgb( nRed, nGreen, nBlue ); | ||
97 | } | ||
98 | } | ||
99 | else { | ||
100 | |||
101 | if( pDefault ) | ||
102 | aRetColor = *pDefault; | ||
103 | } | ||
104 | |||
105 | return aRetColor; | ||
106 | } | ||
107 | |||
108 | // FIXME: The whole font handling has to be revised for Opie | ||
109 | |||
110 | QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const | ||
111 | { | ||
112 | /* | ||
113 | QFont aRetFont; | ||
114 | |||
115 | QString aValue = readEntry( key ); | ||
116 | if( !aValue.isNull() ) { | ||
117 | if ( aValue.contains( ',' ) > 5 ) { | ||
118 | // KDE3 and upwards entry | ||
119 | if ( !aRetFont.fromString( aValue ) && pDefault ) | ||
120 | aRetFont = *pDefault; | ||
121 | } | ||
122 | else { | ||
123 | // backward compatibility with older font formats | ||
124 | // ### remove KDE 3.1 ? | ||
125 | // find first part (font family) | ||
126 | int nIndex = aValue.find( ',' ); | ||
127 | if( nIndex == -1 ){ | ||
128 | if( pDefault ) | ||
129 | aRetFont = *pDefault; | ||
130 | return aRetFont; | ||
131 | } | ||
132 | aRetFont.setFamily( aValue.left( nIndex ) ); | ||
133 | |||
134 | // find second part (point size) | ||
135 | int nOldIndex = nIndex; | ||
136 | nIndex = aValue.find( ',', nOldIndex+1 ); | ||
137 | if( nIndex == -1 ){ | ||
138 | if( pDefault ) | ||
139 | aRetFont = *pDefault; | ||
140 | return aRetFont; | ||
141 | } | ||
142 | |||
143 | aRetFont.setPointSize( aValue.mid( nOldIndex+1, | ||
144 | nIndex-nOldIndex-1 ).toInt() ); | ||
145 | |||
146 | // find third part (style hint) | ||
147 | nOldIndex = nIndex; | ||
148 | nIndex = aValue.find( ',', nOldIndex+1 ); | ||
149 | |||
150 | if( nIndex == -1 ){ | ||
151 | if( pDefault ) | ||
152 | aRetFont = *pDefault; | ||
153 | return aRetFont; | ||
154 | } | ||
155 | |||
156 | aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); | ||
157 | |||
158 | // find fourth part (char set) | ||
159 | nOldIndex = nIndex; | ||
160 | nIndex = aValue.find( ',', nOldIndex+1 ); | ||
161 | |||
162 | if( nIndex == -1 ){ | ||
163 | if( pDefault ) | ||
164 | aRetFont = *pDefault; | ||
165 | return aRetFont; | ||
166 | } | ||
167 | |||
168 | QString chStr=aValue.mid( nOldIndex+1, | ||
169 | nIndex-nOldIndex-1 ); | ||
170 | // find fifth part (weight) | ||
171 | nOldIndex = nIndex; | ||
172 | nIndex = aValue.find( ',', nOldIndex+1 ); | ||
173 | |||
174 | if( nIndex == -1 ){ | ||
175 | if( pDefault ) | ||
176 | aRetFont = *pDefault; | ||
177 | return aRetFont; | ||
178 | } | ||
179 | |||
180 | aRetFont.setWeight( aValue.mid( nOldIndex+1, | ||
181 | nIndex-nOldIndex-1 ).toUInt() ); | ||
182 | |||
183 | // find sixth part (font bits) | ||
184 | uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt(); | ||
185 | |||
186 | aRetFont.setItalic( nFontBits & 0x01 ); | ||
187 | aRetFont.setUnderline( nFontBits & 0x02 ); | ||
188 | aRetFont.setStrikeOut( nFontBits & 0x04 ); | ||
189 | aRetFont.setFixedPitch( nFontBits & 0x08 ); | ||
190 | aRetFont.setRawMode( nFontBits & 0x20 ); | ||
191 | } | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | if( pDefault ) | ||
196 | aRetFont = *pDefault; | ||
197 | } | ||
198 | return aRetFont; | ||
199 | */ | ||
200 | return QFont("Helvetica",10); | ||
201 | } | ||