36 files changed, 212 insertions, 490 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp index 27b0e53..f3e2cfb 100644 --- a/libopie2/opiecore/device/odevice.cpp +++ b/libopie2/opiecore/device/odevice.cpp | |||
@@ -1,382 +1,382 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_ipaq.h" | 30 | #include "odevice_ipaq.h" |
31 | #include "odevice_jornada.h" | 31 | #include "odevice_jornada.h" |
32 | #include "odevice_ramses.h" | 32 | #include "odevice_ramses.h" |
33 | #include "odevice_simpad.h" | 33 | #include "odevice_simpad.h" |
34 | #include "odevice_yopy.h" | 34 | #include "odevice_yopy.h" |
35 | #include "odevice_zaurus.h" | 35 | #include "odevice_zaurus.h" |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qapplication.h> | 38 | #include <qapplication.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
41 | #include <qwindowsystem_qws.h> | 41 | #include <qwindowsystem_qws.h> |
42 | 42 | ||
43 | /* OPIE */ | 43 | /* OPIE */ |
44 | #include <qpe/config.h> | 44 | #include <qpe/config.h> |
45 | #include <qpe/resource.h> | 45 | #include <qpe/resource.h> |
46 | #include <qpe/sound.h> | 46 | #include <qpe/sound.h> |
47 | #include <qpe/qcopenvelope_qws.h> | 47 | #include <qpe/qcopenvelope_qws.h> |
48 | 48 | ||
49 | /* STD */ | 49 | /* STD */ |
50 | #include <fcntl.h> | 50 | #include <fcntl.h> |
51 | #include <math.h> | 51 | #include <math.h> |
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | #include <signal.h> | 53 | #include <signal.h> |
54 | #include <sys/ioctl.h> | 54 | #include <sys/ioctl.h> |
55 | #include <sys/time.h> | 55 | #include <sys/time.h> |
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | #ifndef QT_NO_SOUND | 57 | #ifndef QT_NO_SOUND |
58 | #include <linux/soundcard.h> | 58 | #include <linux/soundcard.h> |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; | 61 | const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; |
62 | 62 | ||
63 | using namespace Opie; | 63 | using namespace Opie::Core; |
64 | 64 | ||
65 | ODevice *ODevice::inst() | 65 | ODevice *ODevice::inst() |
66 | { | 66 | { |
67 | static ODevice *dev = 0; | 67 | static ODevice *dev = 0; |
68 | 68 | ||
69 | // rewrite this to only use /proc/cpuinfo or so | 69 | // rewrite this to only use /proc/cpuinfo or so |
70 | 70 | ||
71 | if ( !dev ) | 71 | if ( !dev ) |
72 | { | 72 | { |
73 | QFile f( PATH_PROC_CPUINFO ); | 73 | QFile f( PATH_PROC_CPUINFO ); |
74 | if ( f.open( IO_ReadOnly ) ) | 74 | if ( f.open( IO_ReadOnly ) ) |
75 | { | 75 | { |
76 | QTextStream s( &f ); | 76 | QTextStream s( &f ); |
77 | while ( !s.atEnd() ) | 77 | while ( !s.atEnd() ) |
78 | { | 78 | { |
79 | QString line; | 79 | QString line; |
80 | line = s.readLine(); | 80 | line = s.readLine(); |
81 | if ( line.startsWith( "Hardware" ) ) | 81 | if ( line.startsWith( "Hardware" ) ) |
82 | { | 82 | { |
83 | qDebug( "ODevice() - found '%s'", (const char*) line ); | 83 | qDebug( "ODevice() - found '%s'", (const char*) line ); |
84 | if ( line.contains( "sharp", false ) ) dev = new Zaurus(); | 84 | if ( line.contains( "sharp", false ) ) dev = new Private::Zaurus(); |
85 | else if ( line.contains( "ipaq", false ) ) dev = new iPAQ(); | 85 | else if ( line.contains( "ipaq", false ) ) dev = new Private::iPAQ(); |
86 | else if ( line.contains( "simpad", false ) ) dev = new SIMpad(); | 86 | else if ( line.contains( "simpad", false ) ) dev = new Private::SIMpad(); |
87 | else if ( line.contains( "jornada", false ) ) dev = new Jornada(); | 87 | else if ( line.contains( "jornada", false ) ) dev = new Private::Jornada(); |
88 | else if ( line.contains( "ramses", false ) ) dev = new Ramses(); | 88 | else if ( line.contains( "ramses", false ) ) dev = new Private::Ramses(); |
89 | else qWarning( "ODevice() - unknown hardware - using default." ); | 89 | else qWarning( "ODevice() - unknown hardware - using default." ); |
90 | break; | 90 | break; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | } | 93 | } |
94 | else | 94 | else |
95 | { | 95 | { |
96 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default." ); | 96 | qWarning( "ODevice() - can't open '%s' - unknown hardware - using default." ); |
97 | } | 97 | } |
98 | if ( !dev ) dev = new ODevice(); | 98 | if ( !dev ) dev = new ODevice(); |
99 | dev->init(); | 99 | dev->init(); |
100 | } | 100 | } |
101 | return dev; | 101 | return dev; |
102 | } | 102 | } |
103 | 103 | ||
104 | ODevice::ODevice() | 104 | ODevice::ODevice() |
105 | { | 105 | { |
106 | d = new ODeviceData; | 106 | d = new ODeviceData; |
107 | 107 | ||
108 | d->m_modelstr = "Unknown"; | 108 | d->m_modelstr = "Unknown"; |
109 | d->m_model = Model_Unknown; | 109 | d->m_model = Model_Unknown; |
110 | d->m_vendorstr = "Unknown"; | 110 | d->m_vendorstr = "Unknown"; |
111 | d->m_vendor = Vendor_Unknown; | 111 | d->m_vendor = Vendor_Unknown; |
112 | d->m_systemstr = "Unknown"; | 112 | d->m_systemstr = "Unknown"; |
113 | d->m_system = System_Unknown; | 113 | d->m_system = System_Unknown; |
114 | d->m_sysverstr = "0.0"; | 114 | d->m_sysverstr = "0.0"; |
115 | d->m_rotation = Rot0; | 115 | d->m_rotation = Rot0; |
116 | d->m_direction = CW; | 116 | d->m_direction = CW; |
117 | 117 | ||
118 | d->m_holdtime = 1000; // 1000ms | 118 | d->m_holdtime = 1000; // 1000ms |
119 | d->m_buttons = 0; | 119 | d->m_buttons = 0; |
120 | d->m_cpu_frequencies = new QStrList; | 120 | d->m_cpu_frequencies = new QStrList; |
121 | } | 121 | } |
122 | 122 | ||
123 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | 123 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) |
124 | { | 124 | { |
125 | if ( msg == "deviceButtonMappingChanged()" ) { | 125 | if ( msg == "deviceButtonMappingChanged()" ) { |
126 | reloadButtonMapping(); | 126 | reloadButtonMapping(); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | void ODevice::init() | 130 | void ODevice::init() |
131 | { | 131 | { |
132 | } | 132 | } |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * This method initialises the button mapping | 135 | * This method initialises the button mapping |
136 | */ | 136 | */ |
137 | void ODevice::initButtons() | 137 | void ODevice::initButtons() |
138 | { | 138 | { |
139 | if ( d->m_buttons ) | 139 | if ( d->m_buttons ) |
140 | return; | 140 | return; |
141 | 141 | ||
142 | qDebug ( "init Buttons" ); | 142 | qDebug ( "init Buttons" ); |
143 | d->m_buttons = new QValueList <ODeviceButton>; | 143 | d->m_buttons = new QValueList <ODeviceButton>; |
144 | 144 | ||
145 | reloadButtonMapping(); | 145 | reloadButtonMapping(); |
146 | 146 | ||
147 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 147 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
148 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | 148 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); |
149 | } | 149 | } |
150 | 150 | ||
151 | ODevice::~ODevice() | 151 | ODevice::~ODevice() |
152 | { | 152 | { |
153 | // we leak m_devicebuttons and m_cpu_frequency | 153 | // we leak m_devicebuttons and m_cpu_frequency |
154 | // but it's a singleton and it is not so importantant | 154 | // but it's a singleton and it is not so importantant |
155 | // -zecke | 155 | // -zecke |
156 | delete d; | 156 | delete d; |
157 | } | 157 | } |
158 | 158 | ||
159 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 159 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
160 | { | 160 | { |
161 | return false; | 161 | return false; |
162 | } | 162 | } |
163 | 163 | ||
164 | //#include <linux/apm_bios.h> | 164 | //#include <linux/apm_bios.h> |
165 | 165 | ||
166 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 166 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * This method will try to suspend the device | 169 | * This method will try to suspend the device |
170 | * It only works if the user is the QWS Server and the apm application | 170 | * It only works if the user is the QWS Server and the apm application |
171 | * is installed. | 171 | * is installed. |
172 | * It tries to suspend and then waits some time cause some distributions | 172 | * It tries to suspend and then waits some time cause some distributions |
173 | * do have asynchronus apm implementations. | 173 | * do have asynchronus apm implementations. |
174 | * This method will either fail and return false or it'll suspend the | 174 | * This method will either fail and return false or it'll suspend the |
175 | * device and return once the device got woken up | 175 | * device and return once the device got woken up |
176 | * | 176 | * |
177 | * @return if the device got suspended | 177 | * @return if the device got suspended |
178 | */ | 178 | */ |
179 | bool ODevice::suspend() | 179 | bool ODevice::suspend() |
180 | { | 180 | { |
181 | qDebug("ODevice::suspend"); | 181 | qDebug("ODevice::suspend"); |
182 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend | 182 | if ( !isQWS( ) ) // only qwsserver is allowed to suspend |
183 | return false; | 183 | return false; |
184 | 184 | ||
185 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 185 | if ( d->m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
186 | return false; | 186 | return false; |
187 | 187 | ||
188 | bool res = false; | 188 | bool res = false; |
189 | ODevice::sendSuspendmsg(); | 189 | ODevice::sendSuspendmsg(); |
190 | 190 | ||
191 | struct timeval tvs, tvn; | 191 | struct timeval tvs, tvn; |
192 | ::gettimeofday ( &tvs, 0 ); | 192 | ::gettimeofday ( &tvs, 0 ); |
193 | 193 | ||
194 | ::sync(); // flush fs caches | 194 | ::sync(); // flush fs caches |
195 | res = ( ::system ( "apm --suspend" ) == 0 ); | 195 | res = ( ::system ( "apm --suspend" ) == 0 ); |
196 | 196 | ||
197 | // This is needed because the iPAQ apm implementation is asynchronous and we | 197 | // This is needed because the iPAQ apm implementation is asynchronous and we |
198 | // can not be sure when exactly the device is really suspended | 198 | // can not be sure when exactly the device is really suspended |
199 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | 199 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. |
200 | 200 | ||
201 | if ( res ) { | 201 | if ( res ) { |
202 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 202 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
203 | ::usleep ( 200 * 1000 ); | 203 | ::usleep ( 200 * 1000 ); |
204 | ::gettimeofday ( &tvn, 0 ); | 204 | ::gettimeofday ( &tvn, 0 ); |
205 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 205 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
206 | } | 206 | } |
207 | 207 | ||
208 | return res; | 208 | return res; |
209 | } | 209 | } |
210 | 210 | ||
211 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | 211 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... |
212 | 212 | ||
213 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 | 213 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 |
214 | 214 | ||
215 | /* VESA Blanking Levels */ | 215 | /* VESA Blanking Levels */ |
216 | #define VESA_NO_BLANKING 0 | 216 | #define VESA_NO_BLANKING 0 |
217 | #define VESA_VSYNC_SUSPEND 1 | 217 | #define VESA_VSYNC_SUSPEND 1 |
218 | #define VESA_HSYNC_SUSPEND 2 | 218 | #define VESA_HSYNC_SUSPEND 2 |
219 | #define VESA_POWERDOWN 3 | 219 | #define VESA_POWERDOWN 3 |
220 | 220 | ||
221 | /** | 221 | /** |
222 | * This sets the display on or off | 222 | * This sets the display on or off |
223 | */ | 223 | */ |
224 | bool ODevice::setDisplayStatus ( bool on ) | 224 | bool ODevice::setDisplayStatus ( bool on ) |
225 | { | 225 | { |
226 | qDebug("ODevice::setDisplayStatus(%d)", on); | 226 | qDebug("ODevice::setDisplayStatus(%d)", on); |
227 | 227 | ||
228 | if ( d->m_model == Model_Unknown ) | 228 | if ( d->m_model == Model_Unknown ) |
229 | return false; | 229 | return false; |
230 | 230 | ||
231 | bool res = false; | 231 | bool res = false; |
232 | int fd; | 232 | int fd; |
233 | 233 | ||
234 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | 234 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { |
235 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | 235 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); |
236 | ::close ( fd ); | 236 | ::close ( fd ); |
237 | } | 237 | } |
238 | return res; | 238 | return res; |
239 | } | 239 | } |
240 | 240 | ||
241 | /** | 241 | /** |
242 | * This sets the display brightness | 242 | * This sets the display brightness |
243 | * | 243 | * |
244 | * @param p The brightness to be set on a scale from 0 to 255 | 244 | * @param p The brightness to be set on a scale from 0 to 255 |
245 | * @return success or failure | 245 | * @return success or failure |
246 | */ | 246 | */ |
247 | bool ODevice::setDisplayBrightness ( int p) | 247 | bool ODevice::setDisplayBrightness ( int p) |
248 | { | 248 | { |
249 | Q_UNUSED( p ) | 249 | Q_UNUSED( p ) |
250 | return false; | 250 | return false; |
251 | } | 251 | } |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * @return returns the number of steppings on the brightness slider | 254 | * @return returns the number of steppings on the brightness slider |
255 | * in the Light-'n-Power settings. | 255 | * in the Light-'n-Power settings. |
256 | */ | 256 | */ |
257 | int ODevice::displayBrightnessResolution() const | 257 | int ODevice::displayBrightnessResolution() const |
258 | { | 258 | { |
259 | return 16; | 259 | return 16; |
260 | } | 260 | } |
261 | 261 | ||
262 | /** | 262 | /** |
263 | * This sets the display contrast | 263 | * This sets the display contrast |
264 | * @param p The contrast to be set on a scale from 0 to 255 | 264 | * @param p The contrast to be set on a scale from 0 to 255 |
265 | * @return success or failure | 265 | * @return success or failure |
266 | */ | 266 | */ |
267 | bool ODevice::setDisplayContrast ( int p) | 267 | bool ODevice::setDisplayContrast ( int p) |
268 | { | 268 | { |
269 | Q_UNUSED( p ) | 269 | Q_UNUSED( p ) |
270 | return false; | 270 | return false; |
271 | } | 271 | } |
272 | 272 | ||
273 | /** | 273 | /** |
274 | * @return return the max value for the brightness settings slider | 274 | * @return return the max value for the brightness settings slider |
275 | * or 0 if the device doesn't support setting of a contrast | 275 | * or 0 if the device doesn't support setting of a contrast |
276 | */ | 276 | */ |
277 | int ODevice::displayContrastResolution() const | 277 | int ODevice::displayContrastResolution() const |
278 | { | 278 | { |
279 | return 0; | 279 | return 0; |
280 | } | 280 | } |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * This returns the vendor as string | 283 | * This returns the vendor as string |
284 | * @return Vendor as QString | 284 | * @return Vendor as QString |
285 | */ | 285 | */ |
286 | QString ODevice::vendorString() const | 286 | QString ODevice::vendorString() const |
287 | { | 287 | { |
288 | return d->m_vendorstr; | 288 | return d->m_vendorstr; |
289 | } | 289 | } |
290 | 290 | ||
291 | /** | 291 | /** |
292 | * This returns the vendor as one of the values of OVendor | 292 | * This returns the vendor as one of the values of OVendor |
293 | * @return OVendor | 293 | * @return OVendor |
294 | */ | 294 | */ |
295 | OVendor ODevice::vendor() const | 295 | OVendor ODevice::vendor() const |
296 | { | 296 | { |
297 | return d->m_vendor; | 297 | return d->m_vendor; |
298 | } | 298 | } |
299 | 299 | ||
300 | /** | 300 | /** |
301 | * This returns the model as a string | 301 | * This returns the model as a string |
302 | * @return A string representing the model | 302 | * @return A string representing the model |
303 | */ | 303 | */ |
304 | QString ODevice::modelString() const | 304 | QString ODevice::modelString() const |
305 | { | 305 | { |
306 | return d->m_modelstr; | 306 | return d->m_modelstr; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * This does return the OModel used | 310 | * This does return the OModel used |
311 | */ | 311 | */ |
312 | OModel ODevice::model() const | 312 | OModel ODevice::model() const |
313 | { | 313 | { |
314 | return d->m_model; | 314 | return d->m_model; |
315 | } | 315 | } |
316 | 316 | ||
317 | /** | 317 | /** |
318 | * This does return the systen name | 318 | * This does return the systen name |
319 | */ | 319 | */ |
320 | QString ODevice::systemString() const | 320 | QString ODevice::systemString() const |
321 | { | 321 | { |
322 | return d->m_systemstr; | 322 | return d->m_systemstr; |
323 | } | 323 | } |
324 | 324 | ||
325 | /** | 325 | /** |
326 | * Return System as OSystem value | 326 | * Return System as OSystem value |
327 | */ | 327 | */ |
328 | OSystem ODevice::system() const | 328 | OSystem ODevice::system() const |
329 | { | 329 | { |
330 | return d->m_system; | 330 | return d->m_system; |
331 | } | 331 | } |
332 | 332 | ||
333 | /** | 333 | /** |
334 | * @return the version string of the base system | 334 | * @return the version string of the base system |
335 | */ | 335 | */ |
336 | QString ODevice::systemVersionString() const | 336 | QString ODevice::systemVersionString() const |
337 | { | 337 | { |
338 | return d->m_sysverstr; | 338 | return d->m_sysverstr; |
339 | } | 339 | } |
340 | 340 | ||
341 | /** | 341 | /** |
342 | * @return the current Transformation | 342 | * @return the current Transformation |
343 | */ | 343 | */ |
344 | Transformation ODevice::rotation() const | 344 | Transformation ODevice::rotation() const |
345 | { | 345 | { |
346 | return d->m_rotation; | 346 | return d->m_rotation; |
347 | } | 347 | } |
348 | 348 | ||
349 | /** | 349 | /** |
350 | * @return the current rotation direction | 350 | * @return the current rotation direction |
351 | */ | 351 | */ |
352 | ODirection ODevice::direction() const | 352 | ODirection ODevice::direction() const |
353 | { | 353 | { |
354 | return d->m_direction; | 354 | return d->m_direction; |
355 | } | 355 | } |
356 | 356 | ||
357 | /** | 357 | /** |
358 | * This plays an alarm sound | 358 | * This plays an alarm sound |
359 | */ | 359 | */ |
360 | void ODevice::playAlarmSound() | 360 | void ODevice::playAlarmSound() |
361 | { | 361 | { |
362 | #ifndef QT_NO_SOUND | 362 | #ifndef QT_NO_SOUND |
363 | static Sound snd ( "alarm" ); | 363 | static Sound snd ( "alarm" ); |
364 | 364 | ||
365 | if ( snd. isFinished()) | 365 | if ( snd. isFinished()) |
366 | snd. play(); | 366 | snd. play(); |
367 | #endif | 367 | #endif |
368 | } | 368 | } |
369 | 369 | ||
370 | /** | 370 | /** |
371 | * This plays a key sound | 371 | * This plays a key sound |
372 | */ | 372 | */ |
373 | void ODevice::playKeySound() | 373 | void ODevice::playKeySound() |
374 | { | 374 | { |
375 | #ifndef QT_NO_SOUND | 375 | #ifndef QT_NO_SOUND |
376 | static Sound snd ( "keysound" ); | 376 | static Sound snd ( "keysound" ); |
377 | 377 | ||
378 | if ( snd. isFinished()) | 378 | if ( snd. isFinished()) |
379 | snd. play(); | 379 | snd. play(); |
380 | #endif | 380 | #endif |
381 | } | 381 | } |
382 | 382 | ||
@@ -435,194 +435,197 @@ bool ODevice::setLedState ( OLed which, OLedState st ) | |||
435 | /** | 435 | /** |
436 | * @return if the device has a light sensor | 436 | * @return if the device has a light sensor |
437 | */ | 437 | */ |
438 | bool ODevice::hasLightSensor() const | 438 | bool ODevice::hasLightSensor() const |
439 | { | 439 | { |
440 | return false; | 440 | return false; |
441 | } | 441 | } |
442 | 442 | ||
443 | /** | 443 | /** |
444 | * @return a value from the light sensor | 444 | * @return a value from the light sensor |
445 | */ | 445 | */ |
446 | int ODevice::readLightSensor() | 446 | int ODevice::readLightSensor() |
447 | { | 447 | { |
448 | return -1; | 448 | return -1; |
449 | } | 449 | } |
450 | 450 | ||
451 | /** | 451 | /** |
452 | * @return the light sensor resolution | 452 | * @return the light sensor resolution |
453 | */ | 453 | */ |
454 | int ODevice::lightSensorResolution() const | 454 | int ODevice::lightSensorResolution() const |
455 | { | 455 | { |
456 | return 0; | 456 | return 0; |
457 | } | 457 | } |
458 | 458 | ||
459 | /** | 459 | /** |
460 | * @return if the device has a hinge sensor | 460 | * @return if the device has a hinge sensor |
461 | */ | 461 | */ |
462 | bool ODevice::hasHingeSensor() const | 462 | bool ODevice::hasHingeSensor() const |
463 | { | 463 | { |
464 | return false; | 464 | return false; |
465 | } | 465 | } |
466 | 466 | ||
467 | /** | 467 | /** |
468 | * @return a value from the hinge sensor | 468 | * @return a value from the hinge sensor |
469 | */ | 469 | */ |
470 | OHingeStatus ODevice::readHingeSensor() | 470 | OHingeStatus ODevice::readHingeSensor() |
471 | { | 471 | { |
472 | return CASE_UNKNOWN; | 472 | return CASE_UNKNOWN; |
473 | } | 473 | } |
474 | 474 | ||
475 | /** | 475 | /** |
476 | * @return a list with CPU frequencies supported by the hardware | 476 | * @return a list with CPU frequencies supported by the hardware |
477 | */ | 477 | */ |
478 | const QStrList &ODevice::allowedCpuFrequencies() const | 478 | const QStrList &ODevice::allowedCpuFrequencies() const |
479 | { | 479 | { |
480 | return *d->m_cpu_frequencies; | 480 | return *d->m_cpu_frequencies; |
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | /** | 484 | /** |
485 | * Set desired CPU frequency | 485 | * Set desired CPU frequency |
486 | * | 486 | * |
487 | * @param index index into d->m_cpu_frequencies of the frequency to be set | 487 | * @param index index into d->m_cpu_frequencies of the frequency to be set |
488 | */ | 488 | */ |
489 | bool ODevice::setCurrentCpuFrequency(uint index) | 489 | bool ODevice::setCurrentCpuFrequency(uint index) |
490 | { | 490 | { |
491 | if (index >= d->m_cpu_frequencies->count()) | 491 | if (index >= d->m_cpu_frequencies->count()) |
492 | return false; | 492 | return false; |
493 | 493 | ||
494 | char *freq = d->m_cpu_frequencies->at(index); | 494 | char *freq = d->m_cpu_frequencies->at(index); |
495 | qWarning("set freq to %s", freq); | 495 | qWarning("set freq to %s", freq); |
496 | 496 | ||
497 | int fd; | 497 | int fd; |
498 | 498 | ||
499 | if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { | 499 | if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { |
500 | char writeCommand[50]; | 500 | char writeCommand[50]; |
501 | const int count = sprintf(writeCommand, "%s\n", freq); | 501 | const int count = sprintf(writeCommand, "%s\n", freq); |
502 | int res = (::write(fd, writeCommand, count) != -1); | 502 | int res = (::write(fd, writeCommand, count) != -1); |
503 | ::close(fd); | 503 | ::close(fd); |
504 | return res; | 504 | return res; |
505 | } | 505 | } |
506 | 506 | ||
507 | return false; | 507 | return false; |
508 | } | 508 | } |
509 | 509 | ||
510 | 510 | ||
511 | /** | 511 | /** |
512 | * @return a list of hardware buttons | 512 | * @return a list of hardware buttons |
513 | */ | 513 | */ |
514 | const QValueList <ODeviceButton> &ODevice::buttons() | 514 | const QValueList <ODeviceButton> &ODevice::buttons() |
515 | { | 515 | { |
516 | initButtons(); | 516 | initButtons(); |
517 | 517 | ||
518 | return *d->m_buttons; | 518 | return *d->m_buttons; |
519 | } | 519 | } |
520 | 520 | ||
521 | /** | 521 | /** |
522 | * @return The amount of time that would count as a hold | 522 | * @return The amount of time that would count as a hold |
523 | */ | 523 | */ |
524 | uint ODevice::buttonHoldTime() const | 524 | uint ODevice::buttonHoldTime() const |
525 | { | 525 | { |
526 | return d->m_holdtime; | 526 | return d->m_holdtime; |
527 | } | 527 | } |
528 | 528 | ||
529 | /** | 529 | /** |
530 | * This method return a ODeviceButton for a key code | 530 | * This method return a ODeviceButton for a key code |
531 | * or 0 if no special hardware button is available for the device | 531 | * or 0 if no special hardware button is available for the device |
532 | * | 532 | * |
533 | * @return The devicebutton or 0l | 533 | * @return The devicebutton or 0l |
534 | * @see ODeviceButton | 534 | * @see ODeviceButton |
535 | */ | 535 | */ |
536 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | 536 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) |
537 | { | 537 | { |
538 | initButtons(); | 538 | initButtons(); |
539 | 539 | ||
540 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { | 540 | for ( QValueListConstIterator<ODeviceButton> it = d->m_buttons->begin(); it != d->m_buttons->end(); ++it ) { |
541 | if ( (*it). keycode() == code ) | 541 | if ( (*it). keycode() == code ) |
542 | return &(*it); | 542 | return &(*it); |
543 | } | 543 | } |
544 | return 0; | 544 | return 0; |
545 | } | 545 | } |
546 | 546 | ||
547 | void ODevice::reloadButtonMapping() | 547 | void ODevice::reloadButtonMapping() |
548 | { | 548 | { |
549 | initButtons(); | 549 | initButtons(); |
550 | 550 | ||
551 | Config cfg ( "ButtonSettings" ); | 551 | Config cfg ( "ButtonSettings" ); |
552 | 552 | ||
553 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { | 553 | for ( uint i = 0; i < d->m_buttons->count(); i++ ) { |
554 | ODeviceButton &b = ( *d->m_buttons ) [i]; | 554 | ODeviceButton &b = ( *d->m_buttons ) [i]; |
555 | QString group = "Button" + QString::number ( i ); | 555 | QString group = "Button" + QString::number ( i ); |
556 | 556 | ||
557 | QCString pch, hch; | 557 | QCString pch, hch; |
558 | QCString pm, hm; | 558 | QCString pm, hm; |
559 | QByteArray pdata, hdata; | 559 | QByteArray pdata, hdata; |
560 | 560 | ||
561 | if ( cfg. hasGroup ( group )) { | 561 | if ( cfg. hasGroup ( group )) { |
562 | cfg. setGroup ( group ); | 562 | cfg. setGroup ( group ); |
563 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); | 563 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1(); |
564 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); | 564 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1(); |
565 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | 565 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); |
566 | 566 | ||
567 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); | 567 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1(); |
568 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); | 568 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1(); |
569 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | 569 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); |
570 | } | 570 | } |
571 | 571 | ||
572 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | 572 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); |
573 | 573 | ||
574 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | 574 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); |
575 | } | 575 | } |
576 | } | 576 | } |
577 | 577 | ||
578 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | 578 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) |
579 | { | 579 | { |
580 | initButtons(); | 580 | initButtons(); |
581 | 581 | ||
582 | QString mb_chan; | 582 | QString mb_chan; |
583 | 583 | ||
584 | if ( button >= (int) d->m_buttons->count()) | 584 | if ( button >= (int) d->m_buttons->count()) |
585 | return; | 585 | return; |
586 | 586 | ||
587 | ODeviceButton &b = ( *d->m_buttons ) [button]; | 587 | ODeviceButton &b = ( *d->m_buttons ) [button]; |
588 | b. setPressedAction ( action ); | 588 | b. setPressedAction ( action ); |
589 | 589 | ||
590 | mb_chan=b. pressedAction(). channel(); | 590 | mb_chan=b. pressedAction(). channel(); |
591 | 591 | ||
592 | Config buttonFile ( "ButtonSettings" ); | 592 | Config buttonFile ( "ButtonSettings" ); |
593 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 593 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
594 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | 594 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); |
595 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); | 595 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction(). message()); |
596 | 596 | ||
597 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); | 597 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction(). data())); |
598 | 598 | ||
599 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 599 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
600 | } | 600 | } |
601 | 601 | ||
602 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) | 602 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) |
603 | { | 603 | { |
604 | initButtons(); | 604 | initButtons(); |
605 | 605 | ||
606 | if ( button >= (int) d->m_buttons->count()) | 606 | if ( button >= (int) d->m_buttons->count()) |
607 | return; | 607 | return; |
608 | 608 | ||
609 | ODeviceButton &b = ( *d->m_buttons ) [button]; | 609 | ODeviceButton &b = ( *d->m_buttons ) [button]; |
610 | b. setHeldAction ( action ); | 610 | b. setHeldAction ( action ); |
611 | 611 | ||
612 | Config buttonFile ( "ButtonSettings" ); | 612 | Config buttonFile ( "ButtonSettings" ); |
613 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 613 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
614 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); | 614 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction(). channel()); |
615 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); | 615 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction(). message()); |
616 | 616 | ||
617 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); | 617 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction(). data())); |
618 | 618 | ||
619 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 619 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
620 | } | 620 | } |
621 | void ODevice::virtual_hook(int, void* ){ | 621 | void ODevice::virtual_hook(int, void* ){ |
622 | 622 | ||
623 | } | 623 | } |
624 | 624 | ||
625 | void ODevice::sendSuspendmsg() | 625 | void ODevice::sendSuspendmsg() |
626 | { | 626 | { |
627 | if ( isQWS() ) | ||
628 | return; | ||
629 | |||
627 | QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); | 630 | QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); |
628 | } | 631 | } |
diff --git a/libopie2/opiecore/device/odevice.h b/libopie2/opiecore/device/odevice.h index bccb449..5ee9cca 100644 --- a/libopie2/opiecore/device/odevice.h +++ b/libopie2/opiecore/device/odevice.h | |||
@@ -1,332 +1,335 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_H_ | 30 | #ifndef ODEVICE_H_ |
31 | #define ODEVICE_H_ | 31 | #define ODEVICE_H_ |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odevicebutton.h> | 34 | #include <opie2/odevicebutton.h> |
35 | #include <qpe/qpeapplication.h> /* for Transformation enum.. */ | 35 | #include <qpe/qpeapplication.h> /* for Transformation enum.. */ |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qnamespace.h> | 38 | #include <qnamespace.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | #include <qstring.h> | 40 | #include <qstring.h> |
41 | #include <qstrlist.h> | 41 | #include <qstrlist.h> |
42 | 42 | ||
43 | namespace Opie | 43 | namespace Opie{ |
44 | { | 44 | namespace Core{ |
45 | |||
45 | class ODeviceData; | 46 | class ODeviceData; |
46 | /** | 47 | /** |
47 | * The available devices | 48 | * The available devices |
48 | */ | 49 | */ |
49 | enum OModel { | 50 | enum OModel { |
50 | Model_Unknown, // = 0 | 51 | Model_Unknown, // = 0 |
51 | 52 | ||
52 | Model_Series_Mask = 0xff000000, | 53 | Model_Series_Mask = 0xff000000, |
53 | 54 | ||
54 | Model_iPAQ = ( 1 << 24 ), | 55 | Model_iPAQ = ( 1 << 24 ), |
55 | 56 | ||
56 | Model_iPAQ_All = ( Model_iPAQ | 0xffffff ), | 57 | Model_iPAQ_All = ( Model_iPAQ | 0xffffff ), |
57 | Model_iPAQ_H31xx = ( Model_iPAQ | 0x000001 ), | 58 | Model_iPAQ_H31xx = ( Model_iPAQ | 0x000001 ), |
58 | Model_iPAQ_H36xx = ( Model_iPAQ | 0x000002 ), | 59 | Model_iPAQ_H36xx = ( Model_iPAQ | 0x000002 ), |
59 | Model_iPAQ_H37xx = ( Model_iPAQ | 0x000004 ), | 60 | Model_iPAQ_H37xx = ( Model_iPAQ | 0x000004 ), |
60 | Model_iPAQ_H38xx = ( Model_iPAQ | 0x000008 ), | 61 | Model_iPAQ_H38xx = ( Model_iPAQ | 0x000008 ), |
61 | Model_iPAQ_H39xx = ( Model_iPAQ | 0x000010 ), | 62 | Model_iPAQ_H39xx = ( Model_iPAQ | 0x000010 ), |
62 | Model_iPAQ_H5xxx = ( Model_iPAQ | 0x000011 ), | 63 | Model_iPAQ_H5xxx = ( Model_iPAQ | 0x000011 ), |
63 | 64 | ||
64 | Model_Jornada = ( 6 << 24 ), | 65 | Model_Jornada = ( 6 << 24 ), |
65 | Model_Jornada_56x = ( Model_Jornada | 0x000001 ), | 66 | Model_Jornada_56x = ( Model_Jornada | 0x000001 ), |
66 | 67 | ||
67 | Model_Zaurus = ( 2 << 24 ), | 68 | Model_Zaurus = ( 2 << 24 ), |
68 | 69 | ||
69 | Model_Zaurus_SL5000 = ( Model_Zaurus | 0x000001 ), | 70 | Model_Zaurus_SL5000 = ( Model_Zaurus | 0x000001 ), |
70 | Model_Zaurus_SL5500 = ( Model_Zaurus | 0x000002 ), | 71 | Model_Zaurus_SL5500 = ( Model_Zaurus | 0x000002 ), |
71 | Model_Zaurus_SLA300 = ( Model_Zaurus | 0x000003 ), | 72 | Model_Zaurus_SLA300 = ( Model_Zaurus | 0x000003 ), |
72 | Model_Zaurus_SLB600 = ( Model_Zaurus | 0x000004 ), | 73 | Model_Zaurus_SLB600 = ( Model_Zaurus | 0x000004 ), |
73 | Model_Zaurus_SLC7x0 = ( Model_Zaurus | 0x000005 ), | 74 | Model_Zaurus_SLC7x0 = ( Model_Zaurus | 0x000005 ), |
74 | 75 | ||
75 | Model_SIMpad = ( 3 << 24 ), | 76 | Model_SIMpad = ( 3 << 24 ), |
76 | 77 | ||
77 | Model_SIMpad_All = ( Model_SIMpad | 0xffffff ), | 78 | Model_SIMpad_All = ( Model_SIMpad | 0xffffff ), |
78 | Model_SIMpad_CL4 = ( Model_SIMpad | 0x000001 ), | 79 | Model_SIMpad_CL4 = ( Model_SIMpad | 0x000001 ), |
79 | Model_SIMpad_SL4 = ( Model_SIMpad | 0x000002 ), | 80 | Model_SIMpad_SL4 = ( Model_SIMpad | 0x000002 ), |
80 | Model_SIMpad_SLC = ( Model_SIMpad | 0x000004 ), | 81 | Model_SIMpad_SLC = ( Model_SIMpad | 0x000004 ), |
81 | Model_SIMpad_TSinus = ( Model_SIMpad | 0x000008 ), | 82 | Model_SIMpad_TSinus = ( Model_SIMpad | 0x000008 ), |
82 | 83 | ||
83 | Model_Ramses = ( 4 << 24 ), | 84 | Model_Ramses = ( 4 << 24 ), |
84 | 85 | ||
85 | Model_Ramses_All = ( Model_Ramses | 0xffffff ), | 86 | Model_Ramses_All = ( Model_Ramses | 0xffffff ), |
86 | Model_Ramses_MNCI = ( Model_Ramses | 0x000001 ), | 87 | Model_Ramses_MNCI = ( Model_Ramses | 0x000001 ), |
87 | 88 | ||
88 | Model_Yopy = ( 5 << 24 ), | 89 | Model_Yopy = ( 5 << 24 ), |
89 | 90 | ||
90 | Model_Yopy_All = ( Model_Yopy | 0xffffff ), | 91 | Model_Yopy_All = ( Model_Yopy | 0xffffff ), |
91 | Model_Yopy_3000 = ( Model_Yopy | 0x000001 ), | 92 | Model_Yopy_3000 = ( Model_Yopy | 0x000001 ), |
92 | Model_Yopy_3500 = ( Model_Yopy | 0x000002 ), | 93 | Model_Yopy_3500 = ( Model_Yopy | 0x000002 ), |
93 | Model_Yopy_3700 = ( Model_Yopy | 0x000003 ), | 94 | Model_Yopy_3700 = ( Model_Yopy | 0x000003 ), |
94 | 95 | ||
95 | }; | 96 | }; |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * The vendor of the device | 99 | * The vendor of the device |
99 | */ | 100 | */ |
100 | enum OVendor { | 101 | enum OVendor { |
101 | Vendor_Unknown, | 102 | Vendor_Unknown, |
102 | 103 | ||
103 | Vendor_HP, | 104 | Vendor_HP, |
104 | Vendor_Sharp, | 105 | Vendor_Sharp, |
105 | Vendor_SIEMENS, | 106 | Vendor_SIEMENS, |
106 | Vendor_MundN, | 107 | Vendor_MundN, |
107 | Vendor_GMate, | 108 | Vendor_GMate, |
108 | }; | 109 | }; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * The System used | 112 | * The System used |
112 | */ | 113 | */ |
113 | enum OSystem { | 114 | enum OSystem { |
114 | System_Unknown, | 115 | System_Unknown, |
115 | 116 | ||
116 | System_Familiar, | 117 | System_Familiar, |
117 | System_Zaurus, | 118 | System_Zaurus, |
118 | System_OpenZaurus, | 119 | System_OpenZaurus, |
119 | System_Linupy, | 120 | System_Linupy, |
120 | }; | 121 | }; |
121 | 122 | ||
122 | enum OLedState { | 123 | enum OLedState { |
123 | Led_Off, | 124 | Led_Off, |
124 | Led_On, | 125 | Led_On, |
125 | Led_BlinkSlow, | 126 | Led_BlinkSlow, |
126 | Led_BlinkFast | 127 | Led_BlinkFast |
127 | }; | 128 | }; |
128 | 129 | ||
129 | enum OLed { | 130 | enum OLed { |
130 | Led_Mail, | 131 | Led_Mail, |
131 | Led_Power, | 132 | Led_Power, |
132 | Led_BlueTooth | 133 | Led_BlueTooth |
133 | }; | 134 | }; |
134 | 135 | ||
135 | enum OHardKey { | 136 | enum OHardKey { |
136 | HardKey_Datebook = Qt::Key_F9, | 137 | HardKey_Datebook = Qt::Key_F9, |
137 | HardKey_Contacts = Qt::Key_F10, | 138 | HardKey_Contacts = Qt::Key_F10, |
138 | HardKey_Menu = Qt::Key_F11, | 139 | HardKey_Menu = Qt::Key_F11, |
139 | HardKey_Home = Qt::Key_F12, | 140 | HardKey_Home = Qt::Key_F12, |
140 | HardKey_Mail = Qt::Key_F13, | 141 | HardKey_Mail = Qt::Key_F13, |
141 | HardKey_Record = Qt::Key_F24, | 142 | HardKey_Record = Qt::Key_F24, |
142 | HardKey_Suspend = Qt::Key_F34, | 143 | HardKey_Suspend = Qt::Key_F34, |
143 | HardKey_Backlight = Qt::Key_F35, | 144 | HardKey_Backlight = Qt::Key_F35, |
144 | HardKey_Action = Qt::Key_F10, | 145 | HardKey_Action = Qt::Key_F10, |
145 | HardKey_OK = Qt::Key_F11, | 146 | HardKey_OK = Qt::Key_F11, |
146 | HardKey_End = Qt::Key_F12, | 147 | HardKey_End = Qt::Key_F12, |
147 | }; | 148 | }; |
148 | 149 | ||
149 | enum ODirection { | 150 | enum ODirection { |
150 | CW = 0, | 151 | CW = 0, |
151 | CCW = 1, | 152 | CCW = 1, |
152 | Flip = 2, | 153 | Flip = 2, |
153 | }; | 154 | }; |
154 | 155 | ||
155 | enum OHingeStatus { | 156 | enum OHingeStatus { |
156 | CASE_CLOSED = 3, | 157 | CASE_CLOSED = 3, |
157 | CASE_PORTRAIT = 2, | 158 | CASE_PORTRAIT = 2, |
158 | CASE_LANDSCAPE = 0, | 159 | CASE_LANDSCAPE = 0, |
159 | CASE_UNKNOWN = 1, | 160 | CASE_UNKNOWN = 1, |
160 | }; | 161 | }; |
161 | 162 | ||
162 | /** | 163 | /** |
163 | * A singleton which gives informations about device specefic option | 164 | * A singleton which gives informations about device specefic option |
164 | * like the Hardware used, LEDs, the Base Distribution and | 165 | * like the Hardware used, LEDs, the Base Distribution and |
165 | * hardware key mappings. | 166 | * hardware key mappings. |
166 | * | 167 | * |
167 | * @short A small class for device specefic options | 168 | * @short A small class for device specefic options |
168 | * @see QObject | 169 | * @see QObject |
169 | * @author Robert Griebl | 170 | * @author Robert Griebl |
170 | * @version 1.0 | 171 | * @version 1.0 |
171 | */ | 172 | */ |
172 | class ODevice : public QObject | 173 | class ODevice : public QObject |
173 | { | 174 | { |
174 | Q_OBJECT | 175 | Q_OBJECT |
175 | 176 | ||
176 | private: | 177 | private: |
177 | /* disable copy */ | 178 | /* disable copy */ |
178 | ODevice ( const ODevice & ); | 179 | ODevice ( const ODevice & ); |
179 | 180 | ||
180 | protected: | 181 | protected: |
181 | ODevice(); | 182 | ODevice(); |
182 | virtual void init(); | 183 | virtual void init(); |
183 | virtual void initButtons(); | 184 | virtual void initButtons(); |
184 | static void sendSuspendmsg(); | 185 | static void sendSuspendmsg(); |
185 | 186 | ||
186 | ODeviceData *d; | 187 | ODeviceData *d; |
187 | 188 | ||
188 | public: | 189 | public: |
189 | // sandman do we want to allow destructions? -zecke? | 190 | // sandman do we want to allow destructions? -zecke? |
190 | virtual ~ODevice(); | 191 | virtual ~ODevice(); |
191 | 192 | ||
192 | static ODevice *inst(); | 193 | static ODevice *inst(); |
193 | 194 | ||
194 | // information | 195 | // information |
195 | 196 | ||
196 | QString modelString() const; | 197 | QString modelString() const; |
197 | OModel model() const; | 198 | OModel model() const; |
198 | inline OModel series() const { return (OModel) ( model() & Model_Series_Mask ); } | 199 | inline OModel series() const { return (OModel) ( model() & Model_Series_Mask ); } |
199 | 200 | ||
200 | QString vendorString() const; | 201 | QString vendorString() const; |
201 | OVendor vendor() const; | 202 | OVendor vendor() const; |
202 | 203 | ||
203 | QString systemString() const; | 204 | QString systemString() const; |
204 | OSystem system() const; | 205 | OSystem system() const; |
205 | 206 | ||
206 | QString systemVersionString() const; | 207 | QString systemVersionString() const; |
207 | 208 | ||
208 | virtual Transformation rotation() const; | 209 | virtual Transformation rotation() const; |
209 | virtual ODirection direction() const; | 210 | virtual ODirection direction() const; |
210 | 211 | ||
211 | // system | 212 | // system |
212 | 213 | ||
213 | virtual bool setSoftSuspend ( bool on ); | 214 | virtual bool setSoftSuspend ( bool on ); |
214 | virtual bool suspend(); | 215 | virtual bool suspend(); |
215 | 216 | ||
216 | virtual bool setDisplayStatus ( bool on ); | 217 | virtual bool setDisplayStatus ( bool on ); |
217 | virtual bool setDisplayBrightness ( int brightness ); | 218 | virtual bool setDisplayBrightness ( int brightness ); |
218 | virtual int displayBrightnessResolution() const; | 219 | virtual int displayBrightnessResolution() const; |
219 | virtual bool setDisplayContrast ( int contrast ); | 220 | virtual bool setDisplayContrast ( int contrast ); |
220 | virtual int displayContrastResolution() const; | 221 | virtual int displayContrastResolution() const; |
221 | 222 | ||
222 | // don't add new virtual methods, use this: | 223 | // don't add new virtual methods, use this: |
223 | ///*virtual */ void boo(int i ) { return virtual_hook(1,&i); }; | 224 | ///*virtual */ void boo(int i ) { return virtual_hook(1,&i); }; |
224 | // and in your subclass do do overwrite | 225 | // and in your subclass do do overwrite |
225 | //protected virtual int virtual_hook(int, void *) | 226 | //protected virtual int virtual_hook(int, void *) |
226 | // which is defined below | 227 | // which is defined below |
227 | 228 | ||
228 | // input / output | 229 | // input / output |
229 | virtual void playAlarmSound(); | 230 | virtual void playAlarmSound(); |
230 | virtual void playKeySound(); | 231 | virtual void playKeySound(); |
231 | virtual void playTouchSound(); | 232 | virtual void playTouchSound(); |
232 | 233 | ||
233 | virtual QValueList <OLed> ledList() const; | 234 | virtual QValueList <OLed> ledList() const; |
234 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 235 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
235 | virtual OLedState ledState ( OLed led ) const; | 236 | virtual OLedState ledState ( OLed led ) const; |
236 | virtual bool setLedState ( OLed led, OLedState st ); | 237 | virtual bool setLedState ( OLed led, OLedState st ); |
237 | 238 | ||
238 | virtual bool hasLightSensor() const; | 239 | virtual bool hasLightSensor() const; |
239 | virtual int readLightSensor(); | 240 | virtual int readLightSensor(); |
240 | virtual int lightSensorResolution() const; | 241 | virtual int lightSensorResolution() const; |
241 | 242 | ||
242 | virtual bool hasHingeSensor() const; | 243 | virtual bool hasHingeSensor() const; |
243 | virtual OHingeStatus readHingeSensor(); | 244 | virtual OHingeStatus readHingeSensor(); |
244 | 245 | ||
245 | const QStrList &allowedCpuFrequencies() const; | 246 | const QStrList &allowedCpuFrequencies() const; |
246 | bool setCurrentCpuFrequency(uint index); | 247 | bool setCurrentCpuFrequency(uint index); |
247 | 248 | ||
248 | /** | 249 | /** |
249 | * Returns the available buttons on this device. The number and location | 250 | * Returns the available buttons on this device. The number and location |
250 | * of buttons will vary depending on the device. Button numbers will be assigned | 251 | * of buttons will vary depending on the device. Button numbers will be assigned |
251 | * by the device manufacturer and will be from most preferred button to least preffered | 252 | * by the device manufacturer and will be from most preferred button to least preffered |
252 | * button. Note that this list only contains "user mappable" buttons. | 253 | * button. Note that this list only contains "user mappable" buttons. |
253 | * | 254 | * |
254 | * @todo Make method const and take care of calling initButtons or make that const too | 255 | * @todo Make method const and take care of calling initButtons or make that const too |
255 | * | 256 | * |
256 | */ | 257 | */ |
257 | const QValueList<ODeviceButton> &buttons(); | 258 | const QValueList<ODeviceButton> &buttons(); |
258 | 259 | ||
259 | /** | 260 | /** |
260 | * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it | 261 | * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it |
261 | * returns 0L | 262 | * returns 0L |
262 | */ | 263 | */ |
263 | const ODeviceButton *buttonForKeycode ( ushort keyCode ); | 264 | const ODeviceButton *buttonForKeycode ( ushort keyCode ); |
264 | 265 | ||
265 | /** | 266 | /** |
266 | * Reassigns the pressed action for \a button. To return to the factory | 267 | * Reassigns the pressed action for \a button. To return to the factory |
267 | * default pass an empty string as \a qcopMessage. | 268 | * default pass an empty string as \a qcopMessage. |
268 | */ | 269 | */ |
269 | void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); | 270 | void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); |
270 | 271 | ||
271 | /** | 272 | /** |
272 | * Reassigns the held action for \a button. To return to the factory | 273 | * Reassigns the held action for \a button. To return to the factory |
273 | * default pass an empty string as \a qcopMessage. | 274 | * default pass an empty string as \a qcopMessage. |
274 | */ | 275 | */ |
275 | void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); | 276 | void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); |
276 | 277 | ||
277 | /** | 278 | /** |
278 | * How long (in ms) you have to press a button for a "hold" action | 279 | * How long (in ms) you have to press a button for a "hold" action |
279 | */ | 280 | */ |
280 | uint buttonHoldTime() const; | 281 | uint buttonHoldTime() const; |
281 | 282 | ||
282 | signals: | 283 | signals: |
283 | void buttonMappingChanged(); | 284 | void buttonMappingChanged(); |
284 | 285 | ||
285 | private slots: | 286 | private slots: |
286 | void systemMessage ( const QCString &, const QByteArray & ); | 287 | void systemMessage ( const QCString &, const QByteArray & ); |
287 | 288 | ||
288 | protected: | 289 | protected: |
289 | void reloadButtonMapping(); | 290 | void reloadButtonMapping(); |
290 | /* ugly virtual hook */ | 291 | /* ugly virtual hook */ |
291 | virtual void virtual_hook( int id, void* data ); | 292 | virtual void virtual_hook( int id, void* data ); |
292 | }; | 293 | }; |
293 | 294 | ||
294 | class ODeviceData { | 295 | class ODeviceData { |
295 | 296 | ||
296 | public: | 297 | public: |
297 | QString m_vendorstr; | 298 | QString m_vendorstr; |
298 | OVendor m_vendor; | 299 | OVendor m_vendor; |
299 | 300 | ||
300 | QString m_modelstr; | 301 | QString m_modelstr; |
301 | OModel m_model; | 302 | OModel m_model; |
302 | 303 | ||
303 | QString m_systemstr; | 304 | QString m_systemstr; |
304 | OSystem m_system; | 305 | OSystem m_system; |
305 | 306 | ||
306 | QString m_sysverstr; | 307 | QString m_sysverstr; |
307 | 308 | ||
308 | Transformation m_rotation; | 309 | Transformation m_rotation; |
309 | ODirection m_direction; | 310 | ODirection m_direction; |
310 | 311 | ||
311 | QValueList <ODeviceButton> *m_buttons; | 312 | QValueList <ODeviceButton> *m_buttons; |
312 | uint m_holdtime; | 313 | uint m_holdtime; |
313 | QStrList *m_cpu_frequencies; | 314 | QStrList *m_cpu_frequencies; |
314 | }; | 315 | }; |
315 | 316 | ||
316 | } | 317 | } |
318 | } | ||
317 | 319 | ||
318 | static inline bool isQWS() | 320 | static inline bool isQWS() |
319 | { | 321 | { |
320 | return qApp ? ( qApp->type() == QApplication::GuiServer ) : false; | 322 | return qApp ? ( qApp->type() == QApplication::GuiServer ) : false; |
321 | } | 323 | } |
322 | 324 | ||
323 | static QCString makeChannel ( const char *str ) | 325 | static QCString makeChannel ( const char *str ) |
324 | { | 326 | { |
325 | if ( str && !::strchr ( str, '/' )) | 327 | if ( str && !::strchr ( str, '/' )) |
326 | return QCString ( "QPE/Application/" ) + str; | 328 | return QCString ( "QPE/Application/" ) + str; |
327 | else | 329 | else |
328 | return str; | 330 | return str; |
329 | } | 331 | } |
330 | 332 | ||
333 | |||
331 | #endif | 334 | #endif |
332 | 335 | ||
diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 8ecea1b..177fd4c 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp | |||
@@ -1,247 +1,251 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_ipaq.h" | 30 | #include "odevice_ipaq.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | |||
57 | using namespace Opie::Core; | ||
58 | using namespace Opie::Core::Private; | ||
59 | |||
56 | /* KERNEL */ | 60 | /* KERNEL */ |
57 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 61 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
58 | 62 | ||
59 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 63 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
60 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 64 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
61 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 65 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
62 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 66 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
63 | 67 | ||
64 | typedef struct { | 68 | typedef struct { |
65 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 69 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
66 | unsigned char TotalTime; /* Units of 5 seconds */ | 70 | unsigned char TotalTime; /* Units of 5 seconds */ |
67 | unsigned char OnTime; /* units of 100m/s */ | 71 | unsigned char OnTime; /* units of 100m/s */ |
68 | unsigned char OffTime; /* units of 100m/s */ | 72 | unsigned char OffTime; /* units of 100m/s */ |
69 | } LED_IN; | 73 | } LED_IN; |
70 | 74 | ||
71 | typedef struct { | 75 | typedef struct { |
72 | unsigned char mode; | 76 | unsigned char mode; |
73 | unsigned char pwr; | 77 | unsigned char pwr; |
74 | unsigned char brightness; | 78 | unsigned char brightness; |
75 | } FLITE_IN; | 79 | } FLITE_IN; |
76 | 80 | ||
77 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 81 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
78 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 82 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
79 | 83 | ||
80 | struct i_button ipaq_buttons [] = { | 84 | struct i_button ipaq_buttons [] = { |
81 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 85 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
82 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 86 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
83 | "devicebuttons/ipaq_calendar", | 87 | "devicebuttons/ipaq_calendar", |
84 | "datebook", "nextView()", | 88 | "datebook", "nextView()", |
85 | "today", "raise()" }, | 89 | "today", "raise()" }, |
86 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 90 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
87 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 91 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
88 | "devicebuttons/ipaq_contact", | 92 | "devicebuttons/ipaq_contact", |
89 | "addressbook", "raise()", | 93 | "addressbook", "raise()", |
90 | "addressbook", "beamBusinessCard()" }, | 94 | "addressbook", "beamBusinessCard()" }, |
91 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, | 95 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, |
92 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 96 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
93 | "devicebuttons/ipaq_menu", | 97 | "devicebuttons/ipaq_menu", |
94 | "QPE/TaskBar", "toggleMenu()", | 98 | "QPE/TaskBar", "toggleMenu()", |
95 | "QPE/TaskBar", "toggleStartMenu()" }, | 99 | "QPE/TaskBar", "toggleStartMenu()" }, |
96 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 100 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
97 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 101 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
98 | "devicebuttons/ipaq_mail", | 102 | "devicebuttons/ipaq_mail", |
99 | "mail", "raise()", | 103 | "mail", "raise()", |
100 | "mail", "newMail()" }, | 104 | "mail", "newMail()" }, |
101 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 105 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
102 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 106 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
103 | "devicebuttons/ipaq_home", | 107 | "devicebuttons/ipaq_home", |
104 | "QPE/Launcher", "home()", | 108 | "QPE/Launcher", "home()", |
105 | "buttonsettings", "raise()" }, | 109 | "buttonsettings", "raise()" }, |
106 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, | 110 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, |
107 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 111 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
108 | "devicebuttons/ipaq_record", | 112 | "devicebuttons/ipaq_record", |
109 | "QPE/VMemo", "toggleRecord()", | 113 | "QPE/VMemo", "toggleRecord()", |
110 | "sound", "raise()" }, | 114 | "sound", "raise()" }, |
111 | }; | 115 | }; |
112 | 116 | ||
113 | void iPAQ::init() | 117 | void iPAQ::init() |
114 | { | 118 | { |
115 | d->m_vendorstr = "HP"; | 119 | d->m_vendorstr = "HP"; |
116 | d->m_vendor = Vendor_HP; | 120 | d->m_vendor = Vendor_HP; |
117 | 121 | ||
118 | QFile f ( "/proc/hal/model" ); | 122 | QFile f ( "/proc/hal/model" ); |
119 | 123 | ||
120 | if ( f. open ( IO_ReadOnly )) { | 124 | if ( f. open ( IO_ReadOnly )) { |
121 | QTextStream ts ( &f ); | 125 | QTextStream ts ( &f ); |
122 | 126 | ||
123 | d->m_modelstr = "H" + ts. readLine(); | 127 | d->m_modelstr = "H" + ts. readLine(); |
124 | 128 | ||
125 | if ( d->m_modelstr == "H3100" ) | 129 | if ( d->m_modelstr == "H3100" ) |
126 | d->m_model = Model_iPAQ_H31xx; | 130 | d->m_model = Model_iPAQ_H31xx; |
127 | else if ( d->m_modelstr == "H3600" ) | 131 | else if ( d->m_modelstr == "H3600" ) |
128 | d->m_model = Model_iPAQ_H36xx; | 132 | d->m_model = Model_iPAQ_H36xx; |
129 | else if ( d->m_modelstr == "H3700" ) | 133 | else if ( d->m_modelstr == "H3700" ) |
130 | d->m_model = Model_iPAQ_H37xx; | 134 | d->m_model = Model_iPAQ_H37xx; |
131 | else if ( d->m_modelstr == "H3800" ) | 135 | else if ( d->m_modelstr == "H3800" ) |
132 | d->m_model = Model_iPAQ_H38xx; | 136 | d->m_model = Model_iPAQ_H38xx; |
133 | else if ( d->m_modelstr == "H3900" ) | 137 | else if ( d->m_modelstr == "H3900" ) |
134 | d->m_model = Model_iPAQ_H39xx; | 138 | d->m_model = Model_iPAQ_H39xx; |
135 | else if ( d->m_modelstr == "H5400" ) | 139 | else if ( d->m_modelstr == "H5400" ) |
136 | d->m_model = Model_iPAQ_H5xxx; | 140 | d->m_model = Model_iPAQ_H5xxx; |
137 | else | 141 | else |
138 | d->m_model = Model_Unknown; | 142 | d->m_model = Model_Unknown; |
139 | 143 | ||
140 | f. close(); | 144 | f. close(); |
141 | } | 145 | } |
142 | 146 | ||
143 | switch ( d->m_model ) { | 147 | switch ( d->m_model ) { |
144 | case Model_iPAQ_H31xx: | 148 | case Model_iPAQ_H31xx: |
145 | case Model_iPAQ_H38xx: | 149 | case Model_iPAQ_H38xx: |
146 | d->m_rotation = Rot90; | 150 | d->m_rotation = Rot90; |
147 | break; | 151 | break; |
148 | case Model_iPAQ_H36xx: | 152 | case Model_iPAQ_H36xx: |
149 | case Model_iPAQ_H37xx: | 153 | case Model_iPAQ_H37xx: |
150 | case Model_iPAQ_H39xx: | 154 | case Model_iPAQ_H39xx: |
151 | 155 | ||
152 | default: | 156 | default: |
153 | d->m_rotation = Rot270; | 157 | d->m_rotation = Rot270; |
154 | break; | 158 | break; |
155 | case Model_iPAQ_H5xxx: | 159 | case Model_iPAQ_H5xxx: |
156 | d->m_rotation = Rot0; | 160 | d->m_rotation = Rot0; |
157 | } | 161 | } |
158 | 162 | ||
159 | f. setName ( "/etc/familiar-version" ); | 163 | f. setName ( "/etc/familiar-version" ); |
160 | if ( f. open ( IO_ReadOnly )) { | 164 | if ( f. open ( IO_ReadOnly )) { |
161 | d->m_systemstr = "Familiar"; | 165 | d->m_systemstr = "Familiar"; |
162 | d->m_system = System_Familiar; | 166 | d->m_system = System_Familiar; |
163 | 167 | ||
164 | QTextStream ts ( &f ); | 168 | QTextStream ts ( &f ); |
165 | d->m_sysverstr = ts. readLine(). mid ( 10 ); | 169 | d->m_sysverstr = ts. readLine(). mid ( 10 ); |
166 | 170 | ||
167 | f. close(); | 171 | f. close(); |
168 | } else { | 172 | } else { |
169 | f. setName ( "/etc/oz_version" ); | 173 | f. setName ( "/etc/oz_version" ); |
170 | 174 | ||
171 | if ( f. open ( IO_ReadOnly )) { | 175 | if ( f. open ( IO_ReadOnly )) { |
172 | d->m_systemstr = "OpenEmbedded/iPaq"; | 176 | d->m_systemstr = "OpenEmbedded/iPaq"; |
173 | d->m_system = System_Familiar; | 177 | d->m_system = System_Familiar; |
174 | 178 | ||
175 | QTextStream ts ( &f ); | 179 | QTextStream ts ( &f ); |
176 | ts.setDevice ( &f ); | 180 | ts.setDevice ( &f ); |
177 | d->m_sysverstr = ts. readLine(); | 181 | d->m_sysverstr = ts. readLine(); |
178 | f. close(); | 182 | f. close(); |
179 | } | 183 | } |
180 | } | 184 | } |
181 | 185 | ||
182 | m_leds [0] = m_leds [1] = Led_Off; | 186 | m_leds [0] = m_leds [1] = Led_Off; |
183 | 187 | ||
184 | m_power_timer = 0; | 188 | m_power_timer = 0; |
185 | 189 | ||
186 | } | 190 | } |
187 | 191 | ||
188 | void iPAQ::initButtons() | 192 | void iPAQ::initButtons() |
189 | { | 193 | { |
190 | if ( d->m_buttons ) | 194 | if ( d->m_buttons ) |
191 | return; | 195 | return; |
192 | 196 | ||
193 | if ( isQWS( ) ) | 197 | if ( isQWS( ) ) |
194 | QWSServer::setKeyboardFilter ( this ); | 198 | QWSServer::setKeyboardFilter ( this ); |
195 | 199 | ||
196 | d->m_buttons = new QValueList <ODeviceButton>; | 200 | d->m_buttons = new QValueList <ODeviceButton>; |
197 | 201 | ||
198 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 202 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
199 | i_button *ib = ipaq_buttons + i; | 203 | i_button *ib = ipaq_buttons + i; |
200 | ODeviceButton b; | 204 | ODeviceButton b; |
201 | 205 | ||
202 | if (( ib->model & d->m_model ) == d->m_model ) { | 206 | if (( ib->model & d->m_model ) == d->m_model ) { |
203 | b. setKeycode ( ib->code ); | 207 | b. setKeycode ( ib->code ); |
204 | b. setUserText ( QObject::tr ( "Button", ib->utext )); | 208 | b. setUserText ( QObject::tr ( "Button", ib->utext )); |
205 | b. setPixmap ( Resource::loadPixmap ( ib->pix )); | 209 | b. setPixmap ( Resource::loadPixmap ( ib->pix )); |
206 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); | 210 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib->fpressedservice ), ib->fpressedaction )); |
207 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); | 211 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib->fheldservice ), ib->fheldaction )); |
208 | 212 | ||
209 | d->m_buttons->append ( b ); | 213 | d->m_buttons->append ( b ); |
210 | } | 214 | } |
211 | } | 215 | } |
212 | reloadButtonMapping(); | 216 | reloadButtonMapping(); |
213 | 217 | ||
214 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 218 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
215 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | 219 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); |
216 | } | 220 | } |
217 | 221 | ||
218 | QValueList <OLed> iPAQ::ledList() const | 222 | QValueList <OLed> iPAQ::ledList() const |
219 | { | 223 | { |
220 | QValueList <OLed> vl; | 224 | QValueList <OLed> vl; |
221 | vl << Led_Power; | 225 | vl << Led_Power; |
222 | 226 | ||
223 | if ( d->m_model == Model_iPAQ_H38xx ) | 227 | if ( d->m_model == Model_iPAQ_H38xx ) |
224 | vl << Led_BlueTooth; | 228 | vl << Led_BlueTooth; |
225 | return vl; | 229 | return vl; |
226 | } | 230 | } |
227 | 231 | ||
228 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | 232 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const |
229 | { | 233 | { |
230 | QValueList <OLedState> vl; | 234 | QValueList <OLedState> vl; |
231 | 235 | ||
232 | if ( l == Led_Power ) | 236 | if ( l == Led_Power ) |
233 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | 237 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; |
234 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) | 238 | else if ( l == Led_BlueTooth && d->m_model == Model_iPAQ_H38xx ) |
235 | vl << Led_Off; // << Led_On << ??? | 239 | vl << Led_Off; // << Led_On << ??? |
236 | 240 | ||
237 | return vl; | 241 | return vl; |
238 | } | 242 | } |
239 | 243 | ||
240 | OLedState iPAQ::ledState ( OLed l ) const | 244 | OLedState iPAQ::ledState ( OLed l ) const |
241 | { | 245 | { |
242 | switch ( l ) { | 246 | switch ( l ) { |
243 | case Led_Power: | 247 | case Led_Power: |
244 | return m_leds [0]; | 248 | return m_leds [0]; |
245 | case Led_BlueTooth: | 249 | case Led_BlueTooth: |
246 | return m_leds [1]; | 250 | return m_leds [1]; |
247 | default: | 251 | default: |
diff --git a/libopie2/opiecore/device/odevice_ipaq.h b/libopie2/opiecore/device/odevice_ipaq.h index f512344..4f4af46 100644 --- a/libopie2/opiecore/device/odevice_ipaq.h +++ b/libopie2/opiecore/device/odevice_ipaq.h | |||
@@ -1,84 +1,90 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_IPAQ | 30 | #ifndef ODEVICE_IPAQ |
31 | #define ODEVICE_IPAQ | 31 | #define ODEVICE_IPAQ |
32 | 32 | ||
33 | #include "odevice.h" | 33 | #include "odevice.h" |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | using namespace Opie; | 38 | namespace Opie { |
39 | namespace Core { | ||
40 | namespace Private { | ||
39 | 41 | ||
40 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter | 42 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter |
41 | { | 43 | { |
42 | 44 | ||
43 | protected: | 45 | protected: |
44 | virtual void init(); | 46 | virtual void init(); |
45 | virtual void initButtons(); | 47 | virtual void initButtons(); |
46 | 48 | ||
47 | public: | 49 | public: |
48 | virtual bool setSoftSuspend( bool soft ); | 50 | virtual bool setSoftSuspend( bool soft ); |
49 | 51 | ||
50 | virtual bool setDisplayBrightness( int b ); | 52 | virtual bool setDisplayBrightness( int b ); |
51 | virtual int displayBrightnessResolution() const; | 53 | virtual int displayBrightnessResolution() const; |
52 | 54 | ||
53 | virtual void playAlarmSound(); | 55 | virtual void playAlarmSound(); |
54 | 56 | ||
55 | virtual QValueList <OLed> ledList() const; | 57 | virtual QValueList <OLed> ledList() const; |
56 | virtual QValueList <OLedState> ledStateList( OLed led ) const; | 58 | virtual QValueList <OLedState> ledStateList( OLed led ) const; |
57 | virtual OLedState ledState( OLed led ) const; | 59 | virtual OLedState ledState( OLed led ) const; |
58 | virtual bool setLedState( OLed led, OLedState st ); | 60 | virtual bool setLedState( OLed led, OLedState st ); |
59 | 61 | ||
60 | virtual bool hasLightSensor() const; | 62 | virtual bool hasLightSensor() const; |
61 | virtual int readLightSensor(); | 63 | virtual int readLightSensor(); |
62 | virtual int lightSensorResolution() const; | 64 | virtual int lightSensorResolution() const; |
63 | 65 | ||
64 | protected: | 66 | protected: |
65 | virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 67 | virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
66 | virtual void timerEvent( QTimerEvent *te ); | 68 | virtual void timerEvent( QTimerEvent *te ); |
67 | 69 | ||
68 | int m_power_timer; | 70 | int m_power_timer; |
69 | 71 | ||
70 | OLedState m_leds [2]; | 72 | OLedState m_leds [2]; |
71 | }; | 73 | }; |
72 | 74 | ||
73 | struct i_button { | 75 | struct i_button { |
74 | uint model; | 76 | uint model; |
75 | Qt::Key code; | 77 | Qt::Key code; |
76 | char *utext; | 78 | char *utext; |
77 | char *pix; | 79 | char *pix; |
78 | char *fpressedservice; | 80 | char *fpressedservice; |
79 | char *fpressedaction; | 81 | char *fpressedaction; |
80 | char *fheldservice; | 82 | char *fheldservice; |
81 | char *fheldaction; | 83 | char *fheldaction; |
82 | }; | 84 | }; |
83 | 85 | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
84 | #endif | 90 | #endif |
diff --git a/libopie2/opiecore/device/odevice_jornada.cpp b/libopie2/opiecore/device/odevice_jornada.cpp index 37bd6e9..b79b0b5 100644 --- a/libopie2/opiecore/device/odevice_jornada.cpp +++ b/libopie2/opiecore/device/odevice_jornada.cpp | |||
@@ -1,150 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_jornada.h" | 30 | #include "odevice_jornada.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | /* KERNEL */ | 56 | /* KERNEL */ |
57 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 57 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
58 | 58 | ||
59 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 59 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
60 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 60 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
61 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 61 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
62 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 62 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
63 | 63 | ||
64 | typedef struct { | 64 | typedef struct { |
65 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 65 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
66 | unsigned char TotalTime; /* Units of 5 seconds */ | 66 | unsigned char TotalTime; /* Units of 5 seconds */ |
67 | unsigned char OnTime; /* units of 100m/s */ | 67 | unsigned char OnTime; /* units of 100m/s */ |
68 | unsigned char OffTime; /* units of 100m/s */ | 68 | unsigned char OffTime; /* units of 100m/s */ |
69 | } LED_IN; | 69 | } LED_IN; |
70 | 70 | ||
71 | typedef struct { | 71 | typedef struct { |
72 | unsigned char mode; | 72 | unsigned char mode; |
73 | unsigned char pwr; | 73 | unsigned char pwr; |
74 | unsigned char brightness; | 74 | unsigned char brightness; |
75 | } FLITE_IN; | 75 | } FLITE_IN; |
76 | 76 | ||
77 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 77 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
78 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 78 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
79 | 79 | ||
80 | using namespace Opie; | 80 | using namespace Opie::Core::Private; |
81 | 81 | ||
82 | void Jornada::init() | 82 | void Jornada::init() |
83 | { | 83 | { |
84 | d->m_vendorstr = "HP"; | 84 | d->m_vendorstr = "HP"; |
85 | d->m_vendor = Vendor_HP; | 85 | d->m_vendor = Vendor_HP; |
86 | d->m_modelstr = "Jornada 56x"; | 86 | d->m_modelstr = "Jornada 56x"; |
87 | d->m_model = Model_Jornada_56x; | 87 | d->m_model = Model_Jornada_56x; |
88 | d->m_systemstr = "Familiar"; | 88 | d->m_systemstr = "Familiar"; |
89 | d->m_system = System_Familiar; | 89 | d->m_system = System_Familiar; |
90 | d->m_rotation = Rot0; | 90 | d->m_rotation = Rot0; |
91 | 91 | ||
92 | QFile f ( "/etc/familiar-version" ); | 92 | QFile f ( "/etc/familiar-version" ); |
93 | f.setName ( "/etc/familiar-version" ); | 93 | f.setName ( "/etc/familiar-version" ); |
94 | if ( f.open ( IO_ReadOnly )) { | 94 | if ( f.open ( IO_ReadOnly )) { |
95 | 95 | ||
96 | QTextStream ts ( &f ); | 96 | QTextStream ts ( &f ); |
97 | d->m_sysverstr = ts.readLine().mid( 10 ); | 97 | d->m_sysverstr = ts.readLine().mid( 10 ); |
98 | 98 | ||
99 | f. close(); | 99 | f. close(); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | int Jornada::displayBrightnessResolution() const | 104 | int Jornada::displayBrightnessResolution() const |
105 | { | 105 | { |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | bool Jornada::setDisplayBrightness( int bright ) | 110 | bool Jornada::setDisplayBrightness( int bright ) |
111 | { | 111 | { |
112 | bool res = false; | 112 | bool res = false; |
113 | int fd; | 113 | int fd; |
114 | 114 | ||
115 | if ( bright > 255 ) | 115 | if ( bright > 255 ) |
116 | bright = 255; | 116 | bright = 255; |
117 | if ( bright < 0 ) | 117 | if ( bright < 0 ) |
118 | bright = 0; | 118 | bright = 0; |
119 | 119 | ||
120 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { | 120 | if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { |
121 | FLITE_IN bl; | 121 | FLITE_IN bl; |
122 | bl. mode = 1; | 122 | bl. mode = 1; |
123 | bl. pwr = bright ? 1 : 0; | 123 | bl. pwr = bright ? 1 : 0; |
124 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; | 124 | bl. brightness = ( bright * ( displayBrightnessResolution() - 1 ) + 127 ) / 255; |
125 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); | 125 | res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); |
126 | ::close ( fd ); | 126 | ::close ( fd ); |
127 | } | 127 | } |
128 | return res; | 128 | return res; |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | bool Jornada::setSoftSuspend( bool soft ) | 132 | bool Jornada::setSoftSuspend( bool soft ) |
133 | { | 133 | { |
134 | bool res = false; | 134 | bool res = false; |
135 | int fd; | 135 | int fd; |
136 | 136 | ||
137 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { | 137 | if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { |
138 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) | 138 | if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) |
139 | res = true; | 139 | res = true; |
140 | else | 140 | else |
141 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); | 141 | ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); |
142 | 142 | ||
143 | ::close ( fd ); | 143 | ::close ( fd ); |
144 | } | 144 | } |
145 | else | 145 | else |
146 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); | 146 | ::perror ( "/proc/sys/ts/suspend_button_mode" ); |
147 | 147 | ||
148 | return res; | 148 | return res; |
149 | } | 149 | } |
150 | 150 | ||
diff --git a/libopie2/opiecore/device/odevice_jornada.h b/libopie2/opiecore/device/odevice_jornada.h index 59be8da..c37d75e 100644 --- a/libopie2/opiecore/device/odevice_jornada.h +++ b/libopie2/opiecore/device/odevice_jornada.h | |||
@@ -1,50 +1,53 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_JORNADA | 30 | #ifndef ODEVICE_JORNADA |
31 | #define ODEVICE_JORNADA | 31 | #define ODEVICE_JORNADA |
32 | 32 | ||
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | 34 | ||
35 | using namespace Opie; | 35 | namespace Opie { |
36 | 36 | namespace Core { | |
37 | namespace Private { | ||
37 | class Jornada : public ODevice | 38 | class Jornada : public ODevice |
38 | { | 39 | { |
39 | 40 | ||
40 | protected: | 41 | protected: |
41 | virtual void init(); | 42 | virtual void init(); |
42 | 43 | ||
43 | public: | 44 | public: |
44 | virtual bool setSoftSuspend ( bool soft ); | 45 | virtual bool setSoftSuspend ( bool soft ); |
45 | virtual bool setDisplayBrightness ( int b ); | 46 | virtual bool setDisplayBrightness ( int b ); |
46 | virtual int displayBrightnessResolution() const; | 47 | virtual int displayBrightnessResolution() const; |
47 | }; | 48 | }; |
48 | 49 | } | |
50 | } | ||
51 | } | ||
49 | #endif | 52 | #endif |
50 | 53 | ||
diff --git a/libopie2/opiecore/device/odevice_ramses.cpp b/libopie2/opiecore/device/odevice_ramses.cpp index 5bcf6a9..77de8c5 100644 --- a/libopie2/opiecore/device/odevice_ramses.cpp +++ b/libopie2/opiecore/device/odevice_ramses.cpp | |||
@@ -1,247 +1,250 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_ramses.h" | 30 | #include "odevice_ramses.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | using namespace Opie::Core; | ||
57 | using namespace Opie::Core::Private; | ||
58 | |||
56 | struct r_button ramses_buttons [] = { | 59 | struct r_button ramses_buttons [] = { |
57 | { Model_Ramses_MNCI, | 60 | { Model_Ramses_MNCI, |
58 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 61 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
59 | "devicebuttons/z_menu", | 62 | "devicebuttons/z_menu", |
60 | "QPE/TaskBar", "toggleMenu()", | 63 | "QPE/TaskBar", "toggleMenu()", |
61 | "QPE/TaskBar", "toggleStartMenu()" }, | 64 | "QPE/TaskBar", "toggleStartMenu()" }, |
62 | { Model_Ramses_MNCI, | 65 | { Model_Ramses_MNCI, |
63 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 66 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
64 | "devicebuttons/ipaq_home", | 67 | "devicebuttons/ipaq_home", |
65 | "QPE/Launcher", "home()", | 68 | "QPE/Launcher", "home()", |
66 | "buttonsettings", "raise()" }, | 69 | "buttonsettings", "raise()" }, |
67 | }; | 70 | }; |
68 | 71 | ||
69 | void Ramses::init() | 72 | void Ramses::init() |
70 | { | 73 | { |
71 | d->m_vendorstr = "M und N"; | 74 | d->m_vendorstr = "M und N"; |
72 | d->m_vendor = Vendor_MundN; | 75 | d->m_vendor = Vendor_MundN; |
73 | 76 | ||
74 | QFile f("/proc/sys/board/ramses"); | 77 | QFile f("/proc/sys/board/ramses"); |
75 | 78 | ||
76 | d->m_modelstr = "Ramses"; | 79 | d->m_modelstr = "Ramses"; |
77 | d->m_model = Model_Ramses_MNCI; | 80 | d->m_model = Model_Ramses_MNCI; |
78 | 81 | ||
79 | d->m_rotation = Rot0; | 82 | d->m_rotation = Rot0; |
80 | d->m_holdtime = 1000; | 83 | d->m_holdtime = 1000; |
81 | 84 | ||
82 | f.setName("/etc/oz_version"); | 85 | f.setName("/etc/oz_version"); |
83 | 86 | ||
84 | if (f.open(IO_ReadOnly)) { | 87 | if (f.open(IO_ReadOnly)) { |
85 | d->m_systemstr = "OpenEmbedded/Ramses"; | 88 | d->m_systemstr = "OpenEmbedded/Ramses"; |
86 | d->m_system = System_OpenZaurus; | 89 | d->m_system = System_OpenZaurus; |
87 | 90 | ||
88 | QTextStream ts(&f); | 91 | QTextStream ts(&f); |
89 | ts.setDevice(&f); | 92 | ts.setDevice(&f); |
90 | d->m_sysverstr = ts.readLine(); | 93 | d->m_sysverstr = ts.readLine(); |
91 | f.close(); | 94 | f.close(); |
92 | } | 95 | } |
93 | 96 | ||
94 | m_power_timer = 0; | 97 | m_power_timer = 0; |
95 | 98 | ||
96 | #ifdef QT_QWS_ALLOW_OVERCLOCK | 99 | #ifdef QT_QWS_ALLOW_OVERCLOCK |
97 | #warning *** Overclocking enabled - this may fry your hardware - you have been warned *** | 100 | #warning *** Overclocking enabled - this may fry your hardware - you have been warned *** |
98 | #define OC(x...) x | 101 | #define OC(x...) x |
99 | #else | 102 | #else |
100 | #define OC(x...) | 103 | #define OC(x...) |
101 | #endif | 104 | #endif |
102 | 105 | ||
103 | // This table is true for a Intel XScale PXA 255 | 106 | // This table is true for a Intel XScale PXA 255 |
104 | 107 | ||
105 | d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 | 108 | d->m_cpu_frequencies->append("99000"); // mem= 99, run= 99, turbo= 99, PXbus= 50 |
106 | OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem | 109 | OC(d->m_cpu_frequencies->append("118000"); ) // mem=118, run=118, turbo=118, PXbus= 59 OC'd mem |
107 | d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 | 110 | d->m_cpu_frequencies->append("199100"); // mem= 99, run=199, turbo=199, PXbus= 99 |
108 | OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem | 111 | OC(d->m_cpu_frequencies->append("236000"); ) // mem=118, run=236, turbo=236, PXbus=118 OC'd mem |
109 | d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 | 112 | d->m_cpu_frequencies->append("298600"); // mem= 99, run=199, turbo=298, PXbus= 99 |
110 | OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem | 113 | OC(d->m_cpu_frequencies->append("354000"); ) // mem=118, run=236, turbo=354, PXbus=118 OC'd mem |
111 | d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 | 114 | d->m_cpu_frequencies->append("398099"); // mem= 99, run=199, turbo=398, PXbus= 99 |
112 | d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 | 115 | d->m_cpu_frequencies->append("398100"); // mem= 99, run=398, turbo=398, PXbus=196 |
113 | OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus | 116 | OC(d->m_cpu_frequencies->append("471000"); ) // mem=118, run=471, turbo=471, PXbus=236 OC'd mem/core/bus |
114 | 117 | ||
115 | } | 118 | } |
116 | 119 | ||
117 | bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) | 120 | bool Ramses::filter(int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat) |
118 | { | 121 | { |
119 | Q_UNUSED( keycode ); | 122 | Q_UNUSED( keycode ); |
120 | Q_UNUSED( modifiers ); | 123 | Q_UNUSED( modifiers ); |
121 | Q_UNUSED( isPress ); | 124 | Q_UNUSED( isPress ); |
122 | Q_UNUSED( autoRepeat ); | 125 | Q_UNUSED( autoRepeat ); |
123 | return false; | 126 | return false; |
124 | } | 127 | } |
125 | 128 | ||
126 | void Ramses::timerEvent(QTimerEvent *) | 129 | void Ramses::timerEvent(QTimerEvent *) |
127 | { | 130 | { |
128 | killTimer(m_power_timer); | 131 | killTimer(m_power_timer); |
129 | m_power_timer = 0; | 132 | m_power_timer = 0; |
130 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); | 133 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, true, false); |
131 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); | 134 | QWSServer::sendKeyEvent(-1, HardKey_Backlight, 0, false, false); |
132 | } | 135 | } |
133 | 136 | ||
134 | 137 | ||
135 | bool Ramses::setSoftSuspend(bool soft) | 138 | bool Ramses::setSoftSuspend(bool soft) |
136 | { | 139 | { |
137 | qDebug("Ramses::setSoftSuspend(%d)", soft); | 140 | qDebug("Ramses::setSoftSuspend(%d)", soft); |
138 | #if 0 | 141 | #if 0 |
139 | bool res = false; | 142 | bool res = false; |
140 | int fd; | 143 | int fd; |
141 | 144 | ||
142 | if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) || | 145 | if (((fd = ::open("/dev/apm_bios", O_RDWR)) >= 0) || |
143 | ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) { | 146 | ((fd = ::open("/dev/misc/apm_bios",O_RDWR)) >= 0)) { |
144 | 147 | ||
145 | int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources | 148 | int sources = ::ioctl(fd, APM_IOCGEVTSRC, 0); // get current event sources |
146 | 149 | ||
147 | if (sources >= 0) { | 150 | if (sources >= 0) { |
148 | if (soft) | 151 | if (soft) |
149 | sources &= ~APM_EVT_POWER_BUTTON; | 152 | sources &= ~APM_EVT_POWER_BUTTON; |
150 | else | 153 | else |
151 | sources |= APM_EVT_POWER_BUTTON; | 154 | sources |= APM_EVT_POWER_BUTTON; |
152 | 155 | ||
153 | if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources | 156 | if (::ioctl(fd, APM_IOCSEVTSRC, sources) >= 0) // set new event sources |
154 | res = true; | 157 | res = true; |
155 | else | 158 | else |
156 | perror("APM_IOCGEVTSRC"); | 159 | perror("APM_IOCGEVTSRC"); |
157 | } | 160 | } |
158 | else | 161 | else |
159 | perror("APM_IOCGEVTSRC"); | 162 | perror("APM_IOCGEVTSRC"); |
160 | 163 | ||
161 | ::close(fd); | 164 | ::close(fd); |
162 | } | 165 | } |
163 | else | 166 | else |
164 | perror("/dev/apm_bios or /dev/misc/apm_bios"); | 167 | perror("/dev/apm_bios or /dev/misc/apm_bios"); |
165 | 168 | ||
166 | return res; | 169 | return res; |
167 | #else | 170 | #else |
168 | return true; | 171 | return true; |
169 | #endif | 172 | #endif |
170 | } | 173 | } |
171 | 174 | ||
172 | bool Ramses::suspend() | 175 | bool Ramses::suspend() |
173 | { | 176 | { |
174 | qDebug("Ramses::suspend"); | 177 | qDebug("Ramses::suspend"); |
175 | return false; | 178 | return false; |
176 | } | 179 | } |
177 | 180 | ||
178 | /** | 181 | /** |
179 | * This sets the display on or off | 182 | * This sets the display on or off |
180 | */ | 183 | */ |
181 | bool Ramses::setDisplayStatus(bool on) | 184 | bool Ramses::setDisplayStatus(bool on) |
182 | { | 185 | { |
183 | qDebug("Ramses::setDisplayStatus(%d)", on); | 186 | qDebug("Ramses::setDisplayStatus(%d)", on); |
184 | #if 0 | 187 | #if 0 |
185 | bool res = false; | 188 | bool res = false; |
186 | int fd; | 189 | int fd; |
187 | 190 | ||
188 | if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { | 191 | if ((fd = ::open ("/dev/fb/0", O_RDWR)) >= 0) { |
189 | res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); | 192 | res = (::ioctl(fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN) == 0); |
190 | ::close(fd); | 193 | ::close(fd); |
191 | } | 194 | } |
192 | return res; | 195 | return res; |
193 | #else | 196 | #else |
194 | return true; | 197 | return true; |
195 | #endif | 198 | #endif |
196 | } | 199 | } |
197 | 200 | ||
198 | 201 | ||
199 | /* | 202 | /* |
200 | * We get something between 0..255 into us | 203 | * We get something between 0..255 into us |
201 | */ | 204 | */ |
202 | bool Ramses::setDisplayBrightness(int bright) | 205 | bool Ramses::setDisplayBrightness(int bright) |
203 | { | 206 | { |
204 | qDebug("Ramses::setDisplayBrightness(%d)", bright); | 207 | qDebug("Ramses::setDisplayBrightness(%d)", bright); |
205 | bool res = false; | 208 | bool res = false; |
206 | int fd; | 209 | int fd; |
207 | 210 | ||
208 | // pwm1 brighness: 20 steps 500..0 (dunkel->hell) | 211 | // pwm1 brighness: 20 steps 500..0 (dunkel->hell) |
209 | 212 | ||
210 | if (bright > 255 ) | 213 | if (bright > 255 ) |
211 | bright = 255; | 214 | bright = 255; |
212 | if (bright < 0) | 215 | if (bright < 0) |
213 | bright = 0; | 216 | bright = 0; |
214 | 217 | ||
215 | // Turn backlight completely off | 218 | // Turn backlight completely off |
216 | if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { | 219 | if ((fd = ::open("/proc/sys/board/lcd_backlight", O_WRONLY)) >= 0) { |
217 | char writeCommand[10]; | 220 | char writeCommand[10]; |
218 | const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); | 221 | const int count = sprintf(writeCommand, "%d\n", bright ? 1 : 0); |
219 | res = (::write(fd, writeCommand, count) != -1); | 222 | res = (::write(fd, writeCommand, count) != -1); |
220 | ::close(fd); | 223 | ::close(fd); |
221 | } | 224 | } |
222 | 225 | ||
223 | // scale backlight brightness to hardware | 226 | // scale backlight brightness to hardware |
224 | bright = 500-(bright * 500 / 255); | 227 | bright = 500-(bright * 500 / 255); |
225 | if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { | 228 | if ((fd = ::open("/proc/sys/board/pwm1", O_WRONLY)) >= 0) { |
226 | qDebug(" %d ->pwm1", bright); | 229 | qDebug(" %d ->pwm1", bright); |
227 | char writeCommand[100]; | 230 | char writeCommand[100]; |
228 | const int count = sprintf(writeCommand, "%d\n", bright); | 231 | const int count = sprintf(writeCommand, "%d\n", bright); |
229 | res = (::write(fd, writeCommand, count) != -1); | 232 | res = (::write(fd, writeCommand, count) != -1); |
230 | ::close(fd); | 233 | ::close(fd); |
231 | } | 234 | } |
232 | return res; | 235 | return res; |
233 | } | 236 | } |
234 | 237 | ||
235 | 238 | ||
236 | int Ramses::displayBrightnessResolution() const | 239 | int Ramses::displayBrightnessResolution() const |
237 | { | 240 | { |
238 | return 32; | 241 | return 32; |
239 | } | 242 | } |
240 | 243 | ||
241 | bool Ramses::setDisplayContrast(int contr) | 244 | bool Ramses::setDisplayContrast(int contr) |
242 | { | 245 | { |
243 | qDebug("Ramses::setDisplayContrast(%d)", contr); | 246 | qDebug("Ramses::setDisplayContrast(%d)", contr); |
244 | bool res = false; | 247 | bool res = false; |
245 | int fd; | 248 | int fd; |
246 | 249 | ||
247 | // pwm0 contrast: 20 steps 79..90 (dunkel->hell) | 250 | // pwm0 contrast: 20 steps 79..90 (dunkel->hell) |
diff --git a/libopie2/opiecore/device/odevice_ramses.h b/libopie2/opiecore/device/odevice_ramses.h index 1b660ab..e673b1a 100644 --- a/libopie2/opiecore/device/odevice_ramses.h +++ b/libopie2/opiecore/device/odevice_ramses.h | |||
@@ -1,72 +1,77 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_RAMSES | 30 | #ifndef ODEVICE_RAMSES |
31 | #define ODEVICE_RAMSES | 31 | #define ODEVICE_RAMSES |
32 | 32 | ||
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | /* QT */ | 34 | /* QT */ |
35 | #include <qwindowsystem_qws.h> | 35 | #include <qwindowsystem_qws.h> |
36 | 36 | ||
37 | using namespace Opie; | 37 | namespace Opie { |
38 | namespace Core { | ||
39 | namespace Private { | ||
38 | 40 | ||
39 | class Ramses : public ODevice, public QWSServer::KeyboardFilter | 41 | class Ramses : public ODevice, public QWSServer::KeyboardFilter |
40 | { | 42 | { |
41 | protected: | 43 | protected: |
42 | virtual void init(); | 44 | virtual void init(); |
43 | 45 | ||
44 | public: | 46 | public: |
45 | virtual bool setSoftSuspend( bool soft ); | 47 | virtual bool setSoftSuspend( bool soft ); |
46 | virtual bool suspend(); | 48 | virtual bool suspend(); |
47 | 49 | ||
48 | virtual bool setDisplayStatus( bool on ); | 50 | virtual bool setDisplayStatus( bool on ); |
49 | virtual bool setDisplayBrightness( int b ); | 51 | virtual bool setDisplayBrightness( int b ); |
50 | virtual int displayBrightnessResolution() const; | 52 | virtual int displayBrightnessResolution() const; |
51 | virtual bool setDisplayContrast( int b ); | 53 | virtual bool setDisplayContrast( int b ); |
52 | virtual int displayContrastResolution() const; | 54 | virtual int displayContrastResolution() const; |
53 | 55 | ||
54 | protected: | 56 | protected: |
55 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 57 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
56 | virtual void timerEvent ( QTimerEvent *te ); | 58 | virtual void timerEvent ( QTimerEvent *te ); |
57 | 59 | ||
58 | int m_power_timer; | 60 | int m_power_timer; |
59 | }; | 61 | }; |
60 | 62 | ||
61 | struct r_button { | 63 | struct r_button { |
62 | uint model; | 64 | uint model; |
63 | Qt::Key code; | 65 | Qt::Key code; |
64 | char *utext; | 66 | char *utext; |
65 | char *pix; | 67 | char *pix; |
66 | char *fpressedservice; | 68 | char *fpressedservice; |
67 | char *fpressedaction; | 69 | char *fpressedaction; |
68 | char *fheldservice; | 70 | char *fheldservice; |
69 | char *fheldaction; | 71 | char *fheldaction; |
70 | }; | 72 | }; |
73 | } | ||
74 | } | ||
75 | } | ||
71 | 76 | ||
72 | #endif | 77 | #endif |
diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index 90aca2f..80d40a3 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp | |||
@@ -1,248 +1,249 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_simpad.h" | 30 | #include "odevice_simpad.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | using namespace Opie; | 56 | using namespace Opie::Core; |
57 | using namespace Opie::Core::Private; | ||
57 | 58 | ||
58 | struct s_button simpad_buttons [] = { | 59 | struct s_button simpad_buttons [] = { |
59 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 60 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
60 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), | 61 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), |
61 | "devicebuttons/simpad_lower_up", | 62 | "devicebuttons/simpad_lower_up", |
62 | "datebook", "nextView()", | 63 | "datebook", "nextView()", |
63 | "today", "raise()" }, | 64 | "today", "raise()" }, |
64 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 65 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
65 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), | 66 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), |
66 | "devicebuttons/simpad_lower_down", | 67 | "devicebuttons/simpad_lower_down", |
67 | "addressbook", "raise()", | 68 | "addressbook", "raise()", |
68 | "addressbook", "beamBusinessCard()" }, | 69 | "addressbook", "beamBusinessCard()" }, |
69 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 70 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
70 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), | 71 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), |
71 | "devicebuttons/simpad_lower_right", | 72 | "devicebuttons/simpad_lower_right", |
72 | "QPE/TaskBar", "toggleMenu()", | 73 | "QPE/TaskBar", "toggleMenu()", |
73 | "QPE/TaskBar", "toggleStartMenu()" }, | 74 | "QPE/TaskBar", "toggleStartMenu()" }, |
74 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 75 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
75 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), | 76 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), |
76 | "devicebuttons/simpad_lower_left", | 77 | "devicebuttons/simpad_lower_left", |
77 | "mail", "raise()", | 78 | "mail", "raise()", |
78 | "mail", "newMail()" }, | 79 | "mail", "newMail()" }, |
79 | 80 | ||
80 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 81 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
81 | Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), | 82 | Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), |
82 | "devicebuttons/simpad_upper_up", | 83 | "devicebuttons/simpad_upper_up", |
83 | "QPE/Launcher", "home()", | 84 | "QPE/Launcher", "home()", |
84 | "buttonsettings", "raise()" }, | 85 | "buttonsettings", "raise()" }, |
85 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 86 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
86 | Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), | 87 | Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), |
87 | "devicebuttons/simpad_upper_down", | 88 | "devicebuttons/simpad_upper_down", |
88 | "addressbook", "raise()", | 89 | "addressbook", "raise()", |
89 | "addressbook", "beamBusinessCard()" }, | 90 | "addressbook", "beamBusinessCard()" }, |
90 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 91 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
91 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), | 92 | Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), |
92 | "devicebuttons/simpad_upper_right", | 93 | "devicebuttons/simpad_upper_right", |
93 | "QPE/TaskBar", "toggleMenu()", | 94 | "QPE/TaskBar", "toggleMenu()", |
94 | "QPE/TaskBar", "toggleStartMenu()" }, | 95 | "QPE/TaskBar", "toggleStartMenu()" }, |
95 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 96 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
96 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), | 97 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), |
97 | "devicebuttons/simpad_upper_left", | 98 | "devicebuttons/simpad_upper_left", |
98 | "QPE/Rotation", "flip()", | 99 | "QPE/Rotation", "flip()", |
99 | "QPE/Rotation", "flip()" }, | 100 | "QPE/Rotation", "flip()" }, |
100 | /* | 101 | /* |
101 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 102 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
102 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | 103 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), |
103 | "devicebuttons/simpad_lower_upper", | 104 | "devicebuttons/simpad_lower_upper", |
104 | "QPE/Launcher", "home()", | 105 | "QPE/Launcher", "home()", |
105 | "buttonsettings", "raise()" }, | 106 | "buttonsettings", "raise()" }, |
106 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, | 107 | { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, |
107 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), | 108 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), |
108 | "devicebuttons/simpad_upper_lower", | 109 | "devicebuttons/simpad_upper_lower", |
109 | "QPE/Launcher", "home()", | 110 | "QPE/Launcher", "home()", |
110 | "buttonsettings", "raise()" }, | 111 | "buttonsettings", "raise()" }, |
111 | */ | 112 | */ |
112 | }; | 113 | }; |
113 | 114 | ||
114 | void SIMpad::init() | 115 | void SIMpad::init() |
115 | { | 116 | { |
116 | d->m_vendorstr = "SIEMENS"; | 117 | d->m_vendorstr = "SIEMENS"; |
117 | d->m_vendor = Vendor_SIEMENS; | 118 | d->m_vendor = Vendor_SIEMENS; |
118 | 119 | ||
119 | QFile f ( "/proc/hal/model" ); | 120 | QFile f ( "/proc/hal/model" ); |
120 | 121 | ||
121 | //TODO Implement model checking | 122 | //TODO Implement model checking |
122 | //FIXME For now we assume an SL4 | 123 | //FIXME For now we assume an SL4 |
123 | 124 | ||
124 | d->m_modelstr = "SL4"; | 125 | d->m_modelstr = "SL4"; |
125 | d->m_model = Model_SIMpad_SL4; | 126 | d->m_model = Model_SIMpad_SL4; |
126 | 127 | ||
127 | switch ( d->m_model ) { | 128 | switch ( d->m_model ) { |
128 | default: | 129 | default: |
129 | d->m_rotation = Rot0; | 130 | d->m_rotation = Rot0; |
130 | d->m_direction = CCW; | 131 | d->m_direction = CCW; |
131 | d->m_holdtime = 1000; // 1000ms | 132 | d->m_holdtime = 1000; // 1000ms |
132 | 133 | ||
133 | break; | 134 | break; |
134 | } | 135 | } |
135 | 136 | ||
136 | f. setName ( "/etc/familiar-version" ); | 137 | f. setName ( "/etc/familiar-version" ); |
137 | if ( f. open ( IO_ReadOnly )) { | 138 | if ( f. open ( IO_ReadOnly )) { |
138 | d->m_systemstr = "Familiar"; | 139 | d->m_systemstr = "Familiar"; |
139 | d->m_system = System_Familiar; | 140 | d->m_system = System_Familiar; |
140 | 141 | ||
141 | QTextStream ts ( &f ); | 142 | QTextStream ts ( &f ); |
142 | d->m_sysverstr = ts. readLine(). mid ( 10 ); | 143 | d->m_sysverstr = ts. readLine(). mid ( 10 ); |
143 | 144 | ||
144 | f. close(); | 145 | f. close(); |
145 | } else { | 146 | } else { |
146 | f. setName ( "/etc/oz_version" ); | 147 | f. setName ( "/etc/oz_version" ); |
147 | 148 | ||
148 | if ( f. open ( IO_ReadOnly )) { | 149 | if ( f. open ( IO_ReadOnly )) { |
149 | d->m_systemstr = "OpenEmbedded/SIMpad"; | 150 | d->m_systemstr = "OpenEmbedded/SIMpad"; |
150 | d->m_system = System_OpenZaurus; | 151 | d->m_system = System_OpenZaurus; |
151 | 152 | ||
152 | QTextStream ts ( &f ); | 153 | QTextStream ts ( &f ); |
153 | ts.setDevice ( &f ); | 154 | ts.setDevice ( &f ); |
154 | d->m_sysverstr = ts. readLine(); | 155 | d->m_sysverstr = ts. readLine(); |
155 | f. close(); | 156 | f. close(); |
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
159 | m_leds [0] = m_leds [1] = Led_Off; | 160 | m_leds [0] = m_leds [1] = Led_Off; |
160 | 161 | ||
161 | m_power_timer = 0; | 162 | m_power_timer = 0; |
162 | 163 | ||
163 | } | 164 | } |
164 | 165 | ||
165 | void SIMpad::initButtons() | 166 | void SIMpad::initButtons() |
166 | { | 167 | { |
167 | if ( d->m_buttons ) | 168 | if ( d->m_buttons ) |
168 | return; | 169 | return; |
169 | 170 | ||
170 | if ( isQWS( ) ) | 171 | if ( isQWS( ) ) |
171 | QWSServer::setKeyboardFilter ( this ); | 172 | QWSServer::setKeyboardFilter ( this ); |
172 | 173 | ||
173 | d->m_buttons = new QValueList <ODeviceButton>; | 174 | d->m_buttons = new QValueList <ODeviceButton>; |
174 | 175 | ||
175 | for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { | 176 | for ( uint i = 0; i < ( sizeof( simpad_buttons ) / sizeof( s_button )); i++ ) { |
176 | s_button *sb = simpad_buttons + i; | 177 | s_button *sb = simpad_buttons + i; |
177 | ODeviceButton b; | 178 | ODeviceButton b; |
178 | 179 | ||
179 | if (( sb->model & d->m_model ) == d->m_model ) { | 180 | if (( sb->model & d->m_model ) == d->m_model ) { |
180 | b. setKeycode ( sb->code ); | 181 | b. setKeycode ( sb->code ); |
181 | b. setUserText ( QObject::tr ( "Button", sb->utext )); | 182 | b. setUserText ( QObject::tr ( "Button", sb->utext )); |
182 | b. setPixmap ( Resource::loadPixmap ( sb->pix )); | 183 | b. setPixmap ( Resource::loadPixmap ( sb->pix )); |
183 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); | 184 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( sb->fpressedservice ), sb->fpressedaction )); |
184 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); | 185 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( sb->fheldservice ), sb->fheldaction )); |
185 | 186 | ||
186 | d->m_buttons->append ( b ); | 187 | d->m_buttons->append ( b ); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | reloadButtonMapping(); | 190 | reloadButtonMapping(); |
190 | 191 | ||
191 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 192 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
192 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); | 193 | connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); |
193 | } | 194 | } |
194 | 195 | ||
195 | // SIMpad boardcontrol register CS3 | 196 | // SIMpad boardcontrol register CS3 |
196 | #define SIMPAD_BOARDCONTROL "/proc/cs3" | 197 | #define SIMPAD_BOARDCONTROL "/proc/cs3" |
197 | #define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA | 198 | #define SIMPAD_VCC_5V_EN 0x0001 // For 5V PCMCIA |
198 | #define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA | 199 | #define SIMPAD_VCC_3V_EN 0x0002 // FOR 3.3V PCMCIA |
199 | #define SIMPAD_EN1 0x0004 // This is only for EPROM's | 200 | #define SIMPAD_EN1 0x0004 // This is only for EPROM's |
200 | #define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V | 201 | #define SIMPAD_EN0 0x0008 // Both should be enable for 3.3V or 5V |
201 | #define SIMPAD_DISPLAY_ON 0x0010 | 202 | #define SIMPAD_DISPLAY_ON 0x0010 |
202 | #define SIMPAD_PCMCIA_BUFF_DIS 0x0020 | 203 | #define SIMPAD_PCMCIA_BUFF_DIS 0x0020 |
203 | #define SIMPAD_MQ_RESET 0x0040 | 204 | #define SIMPAD_MQ_RESET 0x0040 |
204 | #define SIMPAD_PCMCIA_RESET 0x0080 | 205 | #define SIMPAD_PCMCIA_RESET 0x0080 |
205 | #define SIMPAD_DECT_POWER_ON 0x0100 | 206 | #define SIMPAD_DECT_POWER_ON 0x0100 |
206 | #define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave | 207 | #define SIMPAD_IRDA_SD 0x0200 // Shutdown for powersave |
207 | #define SIMPAD_RS232_ON 0x0400 | 208 | #define SIMPAD_RS232_ON 0x0400 |
208 | #define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave | 209 | #define SIMPAD_SD_MEDIAQ 0x0800 // Shutdown for powersave |
209 | #define SIMPAD_LED2_ON 0x1000 | 210 | #define SIMPAD_LED2_ON 0x1000 |
210 | #define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode | 211 | #define SIMPAD_IRDA_MODE 0x2000 // Fast/Slow IrDA mode |
211 | #define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit | 212 | #define SIMPAD_ENABLE_5V 0x4000 // Enable 5V circuit |
212 | #define SIMPAD_RESET_SIMCARD 0x8000 | 213 | #define SIMPAD_RESET_SIMCARD 0x8000 |
213 | 214 | ||
214 | //SIMpad touchscreen backlight strength control | 215 | //SIMpad touchscreen backlight strength control |
215 | #define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" | 216 | #define SIMPAD_BACKLIGHT_CONTROL "/proc/driver/mq200/registers/PWM_CONTROL" |
216 | #define SIMPAD_BACKLIGHT_MASK 0x00a10044 | 217 | #define SIMPAD_BACKLIGHT_MASK 0x00a10044 |
217 | 218 | ||
218 | QValueList <OLed> SIMpad::ledList() const | 219 | QValueList <OLed> SIMpad::ledList() const |
219 | { | 220 | { |
220 | QValueList <OLed> vl; | 221 | QValueList <OLed> vl; |
221 | vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? | 222 | vl << Led_Power; //FIXME which LED is LED2 ? The green one or the amber one? |
222 | //vl << Led_Mail; //TODO find out if LED1 is accessible anyway | 223 | //vl << Led_Mail; //TODO find out if LED1 is accessible anyway |
223 | return vl; | 224 | return vl; |
224 | } | 225 | } |
225 | 226 | ||
226 | QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const | 227 | QValueList <OLedState> SIMpad::ledStateList ( OLed l ) const |
227 | { | 228 | { |
228 | QValueList <OLedState> vl; | 229 | QValueList <OLedState> vl; |
229 | 230 | ||
230 | if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? | 231 | if ( l == Led_Power ) //FIXME which LED is LED2 ? The green one or the amber one? |
231 | vl << Led_Off << Led_On; | 232 | vl << Led_Off << Led_On; |
232 | //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway | 233 | //else if ( l == Led_Mail ) //TODO find out if LED1 is accessible anyway |
233 | //vl << Led_Off; | 234 | //vl << Led_Off; |
234 | return vl; | 235 | return vl; |
235 | } | 236 | } |
236 | 237 | ||
237 | OLedState SIMpad::ledState ( OLed l ) const | 238 | OLedState SIMpad::ledState ( OLed l ) const |
238 | { | 239 | { |
239 | switch ( l ) { | 240 | switch ( l ) { |
240 | case Led_Power: | 241 | case Led_Power: |
241 | return m_leds [0]; | 242 | return m_leds [0]; |
242 | //case Led_Mail: | 243 | //case Led_Mail: |
243 | //return m_leds [1]; | 244 | //return m_leds [1]; |
244 | default: | 245 | default: |
245 | return Led_Off; | 246 | return Led_Off; |
246 | } | 247 | } |
247 | } | 248 | } |
248 | 249 | ||
diff --git a/libopie2/opiecore/device/odevice_simpad.h b/libopie2/opiecore/device/odevice_simpad.h index 3287ee8..1848151 100644 --- a/libopie2/opiecore/device/odevice_simpad.h +++ b/libopie2/opiecore/device/odevice_simpad.h | |||
@@ -1,81 +1,87 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_SIMPAD | 30 | #ifndef ODEVICE_SIMPAD |
31 | #define ODEVICE_SIMPAD | 31 | #define ODEVICE_SIMPAD |
32 | 32 | ||
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | using namespace Opie; | 38 | namespace Opie { |
39 | namespace Core { | ||
40 | namespace Private { | ||
39 | 41 | ||
40 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter | 42 | class SIMpad : public ODevice, public QWSServer::KeyboardFilter |
41 | { | 43 | { |
42 | protected: | 44 | protected: |
43 | virtual void init(); | 45 | virtual void init(); |
44 | virtual void initButtons(); | 46 | virtual void initButtons(); |
45 | 47 | ||
46 | public: | 48 | public: |
47 | virtual bool setSoftSuspend( bool soft ); | 49 | virtual bool setSoftSuspend( bool soft ); |
48 | virtual bool suspend(); | 50 | virtual bool suspend(); |
49 | 51 | ||
50 | virtual bool setDisplayStatus( bool on ); | 52 | virtual bool setDisplayStatus( bool on ); |
51 | virtual bool setDisplayBrightness( int b ); | 53 | virtual bool setDisplayBrightness( int b ); |
52 | virtual int displayBrightnessResolution() const; | 54 | virtual int displayBrightnessResolution() const; |
53 | 55 | ||
54 | virtual void playAlarmSound(); | 56 | virtual void playAlarmSound(); |
55 | 57 | ||
56 | virtual QValueList <OLed> ledList() const; | 58 | virtual QValueList <OLed> ledList() const; |
57 | virtual QValueList <OLedState> ledStateList( OLed led ) const; | 59 | virtual QValueList <OLedState> ledStateList( OLed led ) const; |
58 | virtual OLedState ledState( OLed led ) const; | 60 | virtual OLedState ledState( OLed led ) const; |
59 | virtual bool setLedState( OLed led, OLedState st ); | 61 | virtual bool setLedState( OLed led, OLedState st ); |
60 | 62 | ||
61 | protected: | 63 | protected: |
62 | virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 64 | virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
63 | virtual void timerEvent( QTimerEvent *te ); | 65 | virtual void timerEvent( QTimerEvent *te ); |
64 | 66 | ||
65 | int m_power_timer; | 67 | int m_power_timer; |
66 | 68 | ||
67 | OLedState m_leds [1]; | 69 | OLedState m_leds [1]; |
68 | }; | 70 | }; |
69 | 71 | ||
70 | struct s_button { | 72 | struct s_button { |
71 | uint model; | 73 | uint model; |
72 | Qt::Key code; | 74 | Qt::Key code; |
73 | char *utext; | 75 | char *utext; |
74 | char *pix; | 76 | char *pix; |
75 | char *fpressedservice; | 77 | char *fpressedservice; |
76 | char *fpressedaction; | 78 | char *fpressedaction; |
77 | char *fheldservice; | 79 | char *fheldservice; |
78 | char *fheldaction; | 80 | char *fheldaction; |
79 | }; | 81 | }; |
80 | 82 | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
81 | #endif | 87 | #endif |
diff --git a/libopie2/opiecore/device/odevice_yopy.cpp b/libopie2/opiecore/device/odevice_yopy.cpp index d241db8..f7a4025 100644 --- a/libopie2/opiecore/device/odevice_yopy.cpp +++ b/libopie2/opiecore/device/odevice_yopy.cpp | |||
@@ -1,163 +1,164 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_yopy.h" | 30 | #include "odevice_yopy.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | using namespace Opie; | 56 | using namespace Opie::Core; |
57 | using namespace Opie::Core::Private; | ||
57 | 58 | ||
58 | struct yopy_button yopy_buttons [] = { | 59 | struct yopy_button yopy_buttons [] = { |
59 | { Qt::Key_F10, QT_TRANSLATE_NOOP( "Button", "Action Button" ), | 60 | { Qt::Key_F10, QT_TRANSLATE_NOOP( "Button", "Action Button" ), |
60 | "devicebuttons/yopy_action", | 61 | "devicebuttons/yopy_action", |
61 | "datebook", "nextView()", | 62 | "datebook", "nextView()", |
62 | "today", "raise()" }, | 63 | "today", "raise()" }, |
63 | { Qt::Key_F11, QT_TRANSLATE_NOOP( "Button", "OK Button" ), | 64 | { Qt::Key_F11, QT_TRANSLATE_NOOP( "Button", "OK Button" ), |
64 | "devicebuttons/yopy_ok", | 65 | "devicebuttons/yopy_ok", |
65 | "addressbook", "raise()", | 66 | "addressbook", "raise()", |
66 | "addressbook", "beamBusinessCard()" }, | 67 | "addressbook", "beamBusinessCard()" }, |
67 | { Qt::Key_F12, QT_TRANSLATE_NOOP( "Button", "End Button" ), | 68 | { Qt::Key_F12, QT_TRANSLATE_NOOP( "Button", "End Button" ), |
68 | "devicebuttons/yopy_end", | 69 | "devicebuttons/yopy_end", |
69 | "QPE/Launcher", "home()", | 70 | "QPE/Launcher", "home()", |
70 | "buttonsettings", "raise()" }, | 71 | "buttonsettings", "raise()" }, |
71 | }; | 72 | }; |
72 | 73 | ||
73 | void Yopy::init() | 74 | void Yopy::init() |
74 | { | 75 | { |
75 | d->m_vendorstr = "G.Mate"; | 76 | d->m_vendorstr = "G.Mate"; |
76 | d->m_vendor = Vendor_GMate; | 77 | d->m_vendor = Vendor_GMate; |
77 | d->m_modelstr = "Yopy3700"; | 78 | d->m_modelstr = "Yopy3700"; |
78 | d->m_model = Model_Yopy_3700; | 79 | d->m_model = Model_Yopy_3700; |
79 | d->m_rotation = Rot0; | 80 | d->m_rotation = Rot0; |
80 | 81 | ||
81 | d->m_systemstr = "Linupy"; | 82 | d->m_systemstr = "Linupy"; |
82 | d->m_system = System_Linupy; | 83 | d->m_system = System_Linupy; |
83 | 84 | ||
84 | QFile f ( "/etc/issue" ); | 85 | QFile f ( "/etc/issue" ); |
85 | if ( f. open ( IO_ReadOnly ) ) | 86 | if ( f. open ( IO_ReadOnly ) ) |
86 | { | 87 | { |
87 | QTextStream ts ( &f ); | 88 | QTextStream ts ( &f ); |
88 | ts.readLine(); | 89 | ts.readLine(); |
89 | d->m_sysverstr = ts. readLine(); | 90 | d->m_sysverstr = ts. readLine(); |
90 | f. close(); | 91 | f. close(); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
95 | void Yopy::initButtons() | 96 | void Yopy::initButtons() |
96 | { | 97 | { |
97 | if ( d->m_buttons ) | 98 | if ( d->m_buttons ) |
98 | return ; | 99 | return ; |
99 | 100 | ||
100 | d->m_buttons = new QValueList <ODeviceButton>; | 101 | d->m_buttons = new QValueList <ODeviceButton>; |
101 | 102 | ||
102 | for ( uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof( yopy_button ) ); i++ ) | 103 | for ( uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof( yopy_button ) ); i++ ) |
103 | { | 104 | { |
104 | 105 | ||
105 | yopy_button *ib = yopy_buttons + i; | 106 | yopy_button *ib = yopy_buttons + i; |
106 | 107 | ||
107 | ODeviceButton b; | 108 | ODeviceButton b; |
108 | 109 | ||
109 | b. setKeycode ( ib->code ); | 110 | b. setKeycode ( ib->code ); |
110 | b. setUserText ( QObject::tr ( "Button", ib->utext ) ); | 111 | b. setUserText ( QObject::tr ( "Button", ib->utext ) ); |
111 | b. setPixmap ( Resource::loadPixmap ( ib->pix ) ); | 112 | b. setPixmap ( Resource::loadPixmap ( ib->pix ) ); |
112 | b. setFactoryPresetPressedAction | 113 | b. setFactoryPresetPressedAction |
113 | ( OQCopMessage( makeChannel( ib->fpressedservice ), ib->fpressedaction ) ); | 114 | ( OQCopMessage( makeChannel( ib->fpressedservice ), ib->fpressedaction ) ); |
114 | b. setFactoryPresetHeldAction | 115 | b. setFactoryPresetHeldAction |
115 | ( OQCopMessage( makeChannel( ib->fheldservice ), ib->fheldaction ) ); | 116 | ( OQCopMessage( makeChannel( ib->fheldservice ), ib->fheldaction ) ); |
116 | 117 | ||
117 | d->m_buttons->append ( b ); | 118 | d->m_buttons->append ( b ); |
118 | } | 119 | } |
119 | reloadButtonMapping(); | 120 | reloadButtonMapping(); |
120 | 121 | ||
121 | QCopChannel *sysch = new QCopChannel( "QPE/System", this ); | 122 | QCopChannel *sysch = new QCopChannel( "QPE/System", this ); |
122 | connect( sysch, SIGNAL( received(const QCString&,const QByteArray&) ), | 123 | connect( sysch, SIGNAL( received(const QCString&,const QByteArray&) ), |
123 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); | 124 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); |
124 | } | 125 | } |
125 | 126 | ||
126 | 127 | ||
127 | bool Yopy::suspend() | 128 | bool Yopy::suspend() |
128 | { | 129 | { |
129 | /* Opie for Yopy does not implement its own power management at the | 130 | /* Opie for Yopy does not implement its own power management at the |
130 | moment. The public version runs parallel to X, and relies on the | 131 | moment. The public version runs parallel to X, and relies on the |
131 | existing power management features. */ | 132 | existing power management features. */ |
132 | return false; | 133 | return false; |
133 | } | 134 | } |
134 | 135 | ||
135 | 136 | ||
136 | bool Yopy::setDisplayBrightness( int bright ) | 137 | bool Yopy::setDisplayBrightness( int bright ) |
137 | { | 138 | { |
138 | /* The code here works, but is disabled as the current version runs | 139 | /* The code here works, but is disabled as the current version runs |
139 | parallel to X, and relies on the existing backlight demon. */ | 140 | parallel to X, and relies on the existing backlight demon. */ |
140 | #if 0 | 141 | #if 0 |
141 | if ( QFile::exists( "/proc/sys/pm/light" ) ) | 142 | if ( QFile::exists( "/proc/sys/pm/light" ) ) |
142 | { | 143 | { |
143 | int fd = ::open( "/proc/sys/pm/light", O_WRONLY ); | 144 | int fd = ::open( "/proc/sys/pm/light", O_WRONLY ); |
144 | if ( fd >= 0 ) | 145 | if ( fd >= 0 ) |
145 | { | 146 | { |
146 | if ( bright ) | 147 | if ( bright ) |
147 | ::write( fd, "1\n", 2 ); | 148 | ::write( fd, "1\n", 2 ); |
148 | else | 149 | else |
149 | ::write( fd, "0\n", 2 ); | 150 | ::write( fd, "0\n", 2 ); |
150 | ::close( fd ); | 151 | ::close( fd ); |
151 | return true; | 152 | return true; |
152 | } | 153 | } |
153 | } | 154 | } |
154 | #endif | 155 | #endif |
155 | return false; | 156 | return false; |
156 | } | 157 | } |
157 | 158 | ||
158 | 159 | ||
159 | int Yopy::displayBrightnessResolution() const | 160 | int Yopy::displayBrightnessResolution() const |
160 | { | 161 | { |
161 | return 2; | 162 | return 2; |
162 | } | 163 | } |
163 | 164 | ||
diff --git a/libopie2/opiecore/device/odevice_yopy.h b/libopie2/opiecore/device/odevice_yopy.h index be8f62c..7d85479 100644 --- a/libopie2/opiecore/device/odevice_yopy.h +++ b/libopie2/opiecore/device/odevice_yopy.h | |||
@@ -1,62 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_YOPY | 30 | #ifndef ODEVICE_YOPY |
31 | #define ODEVICE_YOPY | 31 | #define ODEVICE_YOPY |
32 | 32 | ||
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | 34 | ||
35 | using namespace Opie; | 35 | namespace Opie { |
36 | 36 | namespace Core { | |
37 | namespace Private { | ||
37 | class Yopy : public ODevice | 38 | class Yopy : public ODevice |
38 | { | 39 | { |
39 | protected: | 40 | protected: |
40 | 41 | ||
41 | virtual void init(); | 42 | virtual void init(); |
42 | virtual void initButtons(); | 43 | virtual void initButtons(); |
43 | 44 | ||
44 | public: | 45 | public: |
45 | virtual bool suspend(); | 46 | virtual bool suspend(); |
46 | 47 | ||
47 | virtual bool setDisplayBrightness ( int b ); | 48 | virtual bool setDisplayBrightness ( int b ); |
48 | virtual int displayBrightnessResolution() const; | 49 | virtual int displayBrightnessResolution() const; |
49 | }; | 50 | }; |
50 | 51 | ||
51 | struct yopy_button | 52 | struct yopy_button |
52 | { | 53 | { |
53 | Qt::Key code; | 54 | Qt::Key code; |
54 | char *utext; | 55 | char *utext; |
55 | char *pix; | 56 | char *pix; |
56 | char *fpressedservice; | 57 | char *fpressedservice; |
57 | char *fpressedaction; | 58 | char *fpressedaction; |
58 | char *fheldservice; | 59 | char *fheldservice; |
59 | char *fheldaction; | 60 | char *fheldaction; |
60 | }; | 61 | }; |
61 | 62 | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
62 | #endif | 67 | #endif |
diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp index 8ab3cbe..0d21f26 100644 --- a/libopie2/opiecore/device/odevice_zaurus.cpp +++ b/libopie2/opiecore/device/odevice_zaurus.cpp | |||
@@ -1,248 +1,249 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "odevice_zaurus.h" | 30 | #include "odevice_zaurus.h" |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qwindowsystem_qws.h> | 36 | #include <qwindowsystem_qws.h> |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | #include <qpe/sound.h> | 41 | #include <qpe/sound.h> |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <math.h> | 46 | #include <math.h> |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> |
48 | #include <signal.h> | 48 | #include <signal.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | 50 | #include <sys/time.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #ifndef QT_NO_SOUND | 52 | #ifndef QT_NO_SOUND |
53 | #include <linux/soundcard.h> | 53 | #include <linux/soundcard.h> |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | using namespace Opie; | 56 | using namespace Opie::Core; |
57 | using namespace Opie::Core::Private; | ||
57 | 58 | ||
58 | struct z_button z_buttons [] = { | 59 | struct z_button z_buttons [] = { |
59 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 60 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
60 | "devicebuttons/z_calendar", | 61 | "devicebuttons/z_calendar", |
61 | "datebook", "nextView()", | 62 | "datebook", "nextView()", |
62 | "today", "raise()" }, | 63 | "today", "raise()" }, |
63 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 64 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
64 | "devicebuttons/z_contact", | 65 | "devicebuttons/z_contact", |
65 | "addressbook", "raise()", | 66 | "addressbook", "raise()", |
66 | "addressbook", "beamBusinessCard()" }, | 67 | "addressbook", "beamBusinessCard()" }, |
67 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 68 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
68 | "devicebuttons/z_home", | 69 | "devicebuttons/z_home", |
69 | "QPE/Launcher", "home()", | 70 | "QPE/Launcher", "home()", |
70 | "buttonsettings", "raise()" }, | 71 | "buttonsettings", "raise()" }, |
71 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 72 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
72 | "devicebuttons/z_menu", | 73 | "devicebuttons/z_menu", |
73 | "QPE/TaskBar", "toggleMenu()", | 74 | "QPE/TaskBar", "toggleMenu()", |
74 | "QPE/TaskBar", "toggleStartMenu()" }, | 75 | "QPE/TaskBar", "toggleStartMenu()" }, |
75 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 76 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
76 | "devicebuttons/z_mail", | 77 | "devicebuttons/z_mail", |
77 | "mail", "raise()", | 78 | "mail", "raise()", |
78 | "mail", "newMail()" }, | 79 | "mail", "newMail()" }, |
79 | }; | 80 | }; |
80 | 81 | ||
81 | struct z_button z_buttons_c700 [] = { | 82 | struct z_button z_buttons_c700 [] = { |
82 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 83 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
83 | "devicebuttons/z_calendar", | 84 | "devicebuttons/z_calendar", |
84 | "datebook", "nextView()", | 85 | "datebook", "nextView()", |
85 | "today", "raise()" }, | 86 | "today", "raise()" }, |
86 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 87 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
87 | "devicebuttons/z_contact", | 88 | "devicebuttons/z_contact", |
88 | "addressbook", "raise()", | 89 | "addressbook", "raise()", |
89 | "addressbook", "beamBusinessCard()" }, | 90 | "addressbook", "beamBusinessCard()" }, |
90 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 91 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
91 | "devicebuttons/z_home", | 92 | "devicebuttons/z_home", |
92 | "QPE/Launcher", "home()", | 93 | "QPE/Launcher", "home()", |
93 | "buttonsettings", "raise()" }, | 94 | "buttonsettings", "raise()" }, |
94 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 95 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
95 | "devicebuttons/z_menu", | 96 | "devicebuttons/z_menu", |
96 | "QPE/TaskBar", "toggleMenu()", | 97 | "QPE/TaskBar", "toggleMenu()", |
97 | "QPE/TaskBar", "toggleStartMenu()" }, | 98 | "QPE/TaskBar", "toggleStartMenu()" }, |
98 | { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), | 99 | { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), |
99 | "devicebuttons/z_hinge", | 100 | "devicebuttons/z_hinge", |
100 | "QPE/Rotation", "rotateDefault()", | 101 | "QPE/Rotation", "rotateDefault()", |
101 | "QPE/Dummy", "doNothing()" }, | 102 | "QPE/Dummy", "doNothing()" }, |
102 | }; | 103 | }; |
103 | 104 | ||
104 | // FIXME This gets unnecessary complicated. We should think about splitting the Zaurus | 105 | // FIXME This gets unnecessary complicated. We should think about splitting the Zaurus |
105 | // class up into individual classes. We need three classes | 106 | // class up into individual classes. We need three classes |
106 | // | 107 | // |
107 | // Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) | 108 | // Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) |
108 | // Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) | 109 | // Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) |
109 | // Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) | 110 | // Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) |
110 | // | 111 | // |
111 | // Only question right now is: Do we really need to do it? Because as soon | 112 | // Only question right now is: Do we really need to do it? Because as soon |
112 | // as the OpenZaurus kernel is ready, there will be a unified interface for all | 113 | // as the OpenZaurus kernel is ready, there will be a unified interface for all |
113 | // Zaurus models (concerning apm, backlight, buttons, etc.) | 114 | // Zaurus models (concerning apm, backlight, buttons, etc.) |
114 | // | 115 | // |
115 | // Comments? - mickeyl. | 116 | // Comments? - mickeyl. |
116 | 117 | ||
117 | void Zaurus::init() | 118 | void Zaurus::init() |
118 | { | 119 | { |
119 | d->m_vendorstr = "Sharp"; | 120 | d->m_vendorstr = "Sharp"; |
120 | d->m_vendor = Vendor_Sharp; | 121 | d->m_vendor = Vendor_Sharp; |
121 | m_embedix = true; // Not openzaurus means: It has an embedix kernel ! | 122 | m_embedix = true; // Not openzaurus means: It has an embedix kernel ! |
122 | 123 | ||
123 | // QFile f ( "/proc/filesystems" ); | 124 | // QFile f ( "/proc/filesystems" ); |
124 | QString model; | 125 | QString model; |
125 | 126 | ||
126 | // It isn't a good idea to check the system configuration to | 127 | // It isn't a good idea to check the system configuration to |
127 | // detect the distribution ! | 128 | // detect the distribution ! |
128 | // Otherwise it may happen that any other distribution is detected as openzaurus, just | 129 | // Otherwise it may happen that any other distribution is detected as openzaurus, just |
129 | // because it uses a jffs2 filesystem.. | 130 | // because it uses a jffs2 filesystem.. |
130 | // (eilers) | 131 | // (eilers) |
131 | // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read(). find ( "\tjffs2\n" ) >= 0 )) { | 132 | // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read(). find ( "\tjffs2\n" ) >= 0 )) { |
132 | QFile f ("/etc/oz_version"); | 133 | QFile f ("/etc/oz_version"); |
133 | if ( f.exists() ){ | 134 | if ( f.exists() ){ |
134 | d->m_vendorstr = "OpenZaurus Team"; | 135 | d->m_vendorstr = "OpenZaurus Team"; |
135 | d->m_systemstr = "OpenZaurus"; | 136 | d->m_systemstr = "OpenZaurus"; |
136 | d->m_system = System_OpenZaurus; | 137 | d->m_system = System_OpenZaurus; |
137 | 138 | ||
138 | if ( f. open ( IO_ReadOnly )) { | 139 | if ( f. open ( IO_ReadOnly )) { |
139 | QTextStream ts ( &f ); | 140 | QTextStream ts ( &f ); |
140 | d->m_sysverstr = ts. readLine();//. mid ( 10 ); | 141 | d->m_sysverstr = ts. readLine();//. mid ( 10 ); |
141 | f. close(); | 142 | f. close(); |
142 | } | 143 | } |
143 | 144 | ||
144 | // Openzaurus sometimes uses the embedix kernel! | 145 | // Openzaurus sometimes uses the embedix kernel! |
145 | // => Check whether this is an embedix kernel | 146 | // => Check whether this is an embedix kernel |
146 | FILE *uname = popen("uname -r", "r"); | 147 | FILE *uname = popen("uname -r", "r"); |
147 | QString line; | 148 | QString line; |
148 | if ( f.open(IO_ReadOnly, uname) ) { | 149 | if ( f.open(IO_ReadOnly, uname) ) { |
149 | QTextStream ts ( &f ); | 150 | QTextStream ts ( &f ); |
150 | line = ts. readLine(); | 151 | line = ts. readLine(); |
151 | int loc = line. find ( "embedix" ); | 152 | int loc = line. find ( "embedix" ); |
152 | if ( loc != -1 ) | 153 | if ( loc != -1 ) |
153 | m_embedix = true; | 154 | m_embedix = true; |
154 | else | 155 | else |
155 | m_embedix = false; | 156 | m_embedix = false; |
156 | f. close(); | 157 | f. close(); |
157 | } | 158 | } |
158 | pclose(uname); | 159 | pclose(uname); |
159 | } | 160 | } |
160 | else { | 161 | else { |
161 | d->m_systemstr = "Zaurus"; | 162 | d->m_systemstr = "Zaurus"; |
162 | d->m_system = System_Zaurus; | 163 | d->m_system = System_Zaurus; |
163 | } | 164 | } |
164 | 165 | ||
165 | f. setName ( "/proc/cpuinfo" ); | 166 | f. setName ( "/proc/cpuinfo" ); |
166 | if ( f. open ( IO_ReadOnly ) ) { | 167 | if ( f. open ( IO_ReadOnly ) ) { |
167 | QTextStream ts ( &f ); | 168 | QTextStream ts ( &f ); |
168 | QString line; | 169 | QString line; |
169 | while( line = ts. readLine() ) { | 170 | while( line = ts. readLine() ) { |
170 | if ( line. left ( 8 ) == "Hardware" ) | 171 | if ( line. left ( 8 ) == "Hardware" ) |
171 | break; | 172 | break; |
172 | } | 173 | } |
173 | int loc = line. find ( ":" ); | 174 | int loc = line. find ( ":" ); |
174 | if ( loc != -1 ) | 175 | if ( loc != -1 ) |
175 | model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); | 176 | model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); |
176 | } | 177 | } |
177 | 178 | ||
178 | if ( model == "SHARP Corgi" ) { | 179 | if ( model == "SHARP Corgi" ) { |
179 | d->m_model = Model_Zaurus_SLC7x0; | 180 | d->m_model = Model_Zaurus_SLC7x0; |
180 | d->m_modelstr = "Zaurus SL-C700"; | 181 | d->m_modelstr = "Zaurus SL-C700"; |
181 | } else if ( model == "SHARP Shepherd" ) { | 182 | } else if ( model == "SHARP Shepherd" ) { |
182 | d->m_model = Model_Zaurus_SLC7x0; | 183 | d->m_model = Model_Zaurus_SLC7x0; |
183 | d->m_modelstr = "Zaurus SL-C750"; | 184 | d->m_modelstr = "Zaurus SL-C750"; |
184 | } else if ( model == "SHARP Husky" ) { | 185 | } else if ( model == "SHARP Husky" ) { |
185 | d->m_model = Model_Zaurus_SLC7x0; | 186 | d->m_model = Model_Zaurus_SLC7x0; |
186 | d->m_modelstr = "Zaurus SL-C760"; | 187 | d->m_modelstr = "Zaurus SL-C760"; |
187 | } else if ( model == "SHARP Poodle" ) { | 188 | } else if ( model == "SHARP Poodle" ) { |
188 | d->m_model = Model_Zaurus_SLB600; | 189 | d->m_model = Model_Zaurus_SLB600; |
189 | d->m_modelstr = "Zaurus SL-B500 or SL-5600"; | 190 | d->m_modelstr = "Zaurus SL-B500 or SL-5600"; |
190 | } else if ( model == "Sharp-Collie" || model == "Collie" ) { | 191 | } else if ( model == "Sharp-Collie" || model == "Collie" ) { |
191 | d->m_model = Model_Zaurus_SL5500; | 192 | d->m_model = Model_Zaurus_SL5500; |
192 | d->m_modelstr = "Zaurus SL-5500 or SL-5000d"; | 193 | d->m_modelstr = "Zaurus SL-5500 or SL-5000d"; |
193 | } else { | 194 | } else { |
194 | d->m_model = Model_Zaurus_SL5500; | 195 | d->m_model = Model_Zaurus_SL5500; |
195 | d->m_modelstr = "Zaurus (Model unknown)"; | 196 | d->m_modelstr = "Zaurus (Model unknown)"; |
196 | } | 197 | } |
197 | 198 | ||
198 | bool flipstate = false; | 199 | bool flipstate = false; |
199 | switch ( d->m_model ) { | 200 | switch ( d->m_model ) { |
200 | case Model_Zaurus_SLA300: | 201 | case Model_Zaurus_SLA300: |
201 | d->m_rotation = Rot0; | 202 | d->m_rotation = Rot0; |
202 | break; | 203 | break; |
203 | case Model_Zaurus_SLC7x0: | 204 | case Model_Zaurus_SLC7x0: |
204 | d->m_rotation = rotation(); | 205 | d->m_rotation = rotation(); |
205 | d->m_direction = direction(); | 206 | d->m_direction = direction(); |
206 | break; | 207 | break; |
207 | case Model_Zaurus_SLB600: | 208 | case Model_Zaurus_SLB600: |
208 | case Model_Zaurus_SL5500: | 209 | case Model_Zaurus_SL5500: |
209 | case Model_Zaurus_SL5000: | 210 | case Model_Zaurus_SL5000: |
210 | default: | 211 | default: |
211 | d->m_rotation = Rot270; | 212 | d->m_rotation = Rot270; |
212 | break; | 213 | break; |
213 | } | 214 | } |
214 | m_leds [0] = Led_Off; | 215 | m_leds [0] = Led_Off; |
215 | } | 216 | } |
216 | 217 | ||
217 | void Zaurus::initButtons() | 218 | void Zaurus::initButtons() |
218 | { | 219 | { |
219 | if ( d->m_buttons ) | 220 | if ( d->m_buttons ) |
220 | return; | 221 | return; |
221 | 222 | ||
222 | d->m_buttons = new QValueList <ODeviceButton>; | 223 | d->m_buttons = new QValueList <ODeviceButton>; |
223 | 224 | ||
224 | struct z_button * pz_buttons; | 225 | struct z_button * pz_buttons; |
225 | int buttoncount; | 226 | int buttoncount; |
226 | switch ( d->m_model ) { | 227 | switch ( d->m_model ) { |
227 | case Model_Zaurus_SLC7x0: | 228 | case Model_Zaurus_SLC7x0: |
228 | pz_buttons = z_buttons_c700; | 229 | pz_buttons = z_buttons_c700; |
229 | buttoncount = ARRAY_SIZE(z_buttons_c700); | 230 | buttoncount = ARRAY_SIZE(z_buttons_c700); |
230 | break; | 231 | break; |
231 | default: | 232 | default: |
232 | pz_buttons = z_buttons; | 233 | pz_buttons = z_buttons; |
233 | buttoncount = ARRAY_SIZE(z_buttons); | 234 | buttoncount = ARRAY_SIZE(z_buttons); |
234 | break; | 235 | break; |
235 | } | 236 | } |
236 | 237 | ||
237 | for ( int i = 0; i < buttoncount; i++ ) { | 238 | for ( int i = 0; i < buttoncount; i++ ) { |
238 | struct z_button *zb = pz_buttons + i; | 239 | struct z_button *zb = pz_buttons + i; |
239 | ODeviceButton b; | 240 | ODeviceButton b; |
240 | 241 | ||
241 | b. setKeycode ( zb->code ); | 242 | b. setKeycode ( zb->code ); |
242 | b. setUserText ( QObject::tr ( "Button", zb->utext )); | 243 | b. setUserText ( QObject::tr ( "Button", zb->utext )); |
243 | b. setPixmap ( Resource::loadPixmap ( zb->pix )); | 244 | b. setPixmap ( Resource::loadPixmap ( zb->pix )); |
244 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb->fpressedservice ), | 245 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb->fpressedservice ), |
245 | zb->fpressedaction )); | 246 | zb->fpressedaction )); |
246 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb->fheldservice ), | 247 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb->fheldservice ), |
247 | zb->fheldaction )); | 248 | zb->fheldaction )); |
248 | 249 | ||
diff --git a/libopie2/opiecore/device/odevice_zaurus.h b/libopie2/opiecore/device/odevice_zaurus.h index f5c5172..ffb648f 100644 --- a/libopie2/opiecore/device/odevice_zaurus.h +++ b/libopie2/opiecore/device/odevice_zaurus.h | |||
@@ -1,96 +1,100 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef ODEVICE_ZAURUS | 30 | #ifndef ODEVICE_ZAURUS |
31 | #define ODEVICE_ZAURUS | 31 | #define ODEVICE_ZAURUS |
32 | 32 | ||
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | 34 | ||
35 | #ifndef ARRAY_SIZE | 35 | #ifndef ARRAY_SIZE |
36 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | 36 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | // _IO and friends are only defined in kernel headers ... | 39 | // _IO and friends are only defined in kernel headers ... |
40 | 40 | ||
41 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 41 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
42 | 42 | ||
43 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 43 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
44 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 44 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
45 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 45 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
46 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 46 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
47 | 47 | ||
48 | using namespace Opie; | ||
49 | 48 | ||
49 | namespace Opie { | ||
50 | namespace Core { | ||
51 | namespace Private { | ||
50 | class Zaurus : public ODevice | 52 | class Zaurus : public ODevice |
51 | { | 53 | { |
52 | 54 | ||
53 | protected: | 55 | protected: |
54 | virtual void init(); | 56 | virtual void init(); |
55 | virtual void initButtons(); | 57 | virtual void initButtons(); |
56 | 58 | ||
57 | public: | 59 | public: |
58 | virtual bool setSoftSuspend ( bool soft ); | 60 | virtual bool setSoftSuspend ( bool soft ); |
59 | 61 | ||
60 | virtual bool setDisplayBrightness ( int b ); | 62 | virtual bool setDisplayBrightness ( int b ); |
61 | virtual int displayBrightnessResolution() const; | 63 | virtual int displayBrightnessResolution() const; |
62 | 64 | ||
63 | virtual void playAlarmSound(); | 65 | virtual void playAlarmSound(); |
64 | virtual void playKeySound(); | 66 | virtual void playKeySound(); |
65 | virtual void playTouchSound(); | 67 | virtual void playTouchSound(); |
66 | 68 | ||
67 | virtual QValueList <OLed> ledList() const; | 69 | virtual QValueList <OLed> ledList() const; |
68 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 70 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
69 | virtual OLedState ledState( OLed led ) const; | 71 | virtual OLedState ledState( OLed led ) const; |
70 | virtual bool setLedState( OLed led, OLedState st ); | 72 | virtual bool setLedState( OLed led, OLedState st ); |
71 | 73 | ||
72 | virtual bool hasHingeSensor() const; | 74 | virtual bool hasHingeSensor() const; |
73 | virtual OHingeStatus readHingeSensor(); | 75 | virtual OHingeStatus readHingeSensor(); |
74 | 76 | ||
75 | virtual bool suspend(); | 77 | virtual bool suspend(); |
76 | virtual Transformation rotation() const; | 78 | virtual Transformation rotation() const; |
77 | virtual ODirection direction() const; | 79 | virtual ODirection direction() const; |
78 | 80 | ||
79 | protected: | 81 | protected: |
80 | virtual void buzzer ( int snd ); | 82 | virtual void buzzer ( int snd ); |
81 | 83 | ||
82 | OLedState m_leds [1]; | 84 | OLedState m_leds [1]; |
83 | bool m_embedix; | 85 | bool m_embedix; |
84 | }; | 86 | }; |
85 | 87 | ||
86 | struct z_button { | 88 | struct z_button { |
87 | Qt::Key code; | 89 | Qt::Key code; |
88 | char *utext; | 90 | char *utext; |
89 | char *pix; | 91 | char *pix; |
90 | char *fpressedservice; | 92 | char *fpressedservice; |
91 | char *fpressedaction; | 93 | char *fpressedaction; |
92 | char *fheldservice; | 94 | char *fheldservice; |
93 | char *fheldaction; | 95 | char *fheldaction; |
94 | }; | 96 | }; |
95 | 97 | } | |
98 | } | ||
99 | } | ||
96 | #endif | 100 | #endif |
diff --git a/libopie2/opiecore/device/odevicebutton.cpp b/libopie2/opiecore/device/odevicebutton.cpp index 0b593d5..a081b7f 100644 --- a/libopie2/opiecore/device/odevicebutton.cpp +++ b/libopie2/opiecore/device/odevicebutton.cpp | |||
@@ -1,246 +1,255 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 3 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <qpixmap.h> | 30 | #include <qpixmap.h> |
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | 32 | ||
33 | #include <qpe/qcopenvelope_qws.h> | 33 | #include <qpe/qcopenvelope_qws.h> |
34 | #include <opie2/odevicebutton.h> | 34 | #include <opie2/odevicebutton.h> |
35 | 35 | ||
36 | using namespace Opie; | 36 | |
37 | namespace Opie { | ||
38 | namespace Core { | ||
39 | namespace Private { | ||
37 | 40 | ||
38 | class OQCopMessageData | 41 | class OQCopMessageData |
39 | { | 42 | { |
40 | public: | 43 | public: |
41 | QCString m_channel; | 44 | QCString m_channel; |
42 | QCString m_message; | 45 | QCString m_message; |
43 | QByteArray m_data; | 46 | QByteArray m_data; |
44 | }; | 47 | }; |
48 | } | ||
45 | 49 | ||
50 | using namespace Opie::Core; | ||
51 | using namespace Opie::Core::Private; | ||
46 | 52 | ||
47 | OQCopMessage::OQCopMessage() | 53 | OQCopMessage::OQCopMessage() |
48 | : d ( 0 ) | 54 | : d ( 0 ) |
49 | { | 55 | { |
50 | init ( QCString(), QCString(), QByteArray()); | 56 | init ( QCString(), QCString(), QByteArray()); |
51 | } | 57 | } |
52 | 58 | ||
53 | OQCopMessage::OQCopMessage ( const OQCopMessage © ) | 59 | OQCopMessage::OQCopMessage ( const OQCopMessage © ) |
54 | : d ( 0 ) | 60 | : d ( 0 ) |
55 | { | 61 | { |
56 | init ( copy. channel(), copy. message(), copy. data()); | 62 | init ( copy. channel(), copy. message(), copy. data()); |
57 | } | 63 | } |
58 | 64 | ||
59 | OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) | 65 | OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) |
60 | { | 66 | { |
61 | init ( assign. channel(), assign. message(), assign. data()); | 67 | init ( assign. channel(), assign. message(), assign. data()); |
62 | return *this; | 68 | return *this; |
63 | } | 69 | } |
64 | 70 | ||
65 | OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) | 71 | OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) |
66 | : d ( 0 ) | 72 | : d ( 0 ) |
67 | { | 73 | { |
68 | init ( ch, m, arg ); | 74 | init ( ch, m, arg ); |
69 | } | 75 | } |
70 | 76 | ||
71 | void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg ) | 77 | void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg ) |
72 | { | 78 | { |
73 | if ( !d ) | 79 | if ( !d ) |
74 | d = new OQCopMessageData(); | 80 | d = new OQCopMessageData(); |
75 | d->m_channel = ch; | 81 | d->m_channel = ch; |
76 | d->m_message = m; | 82 | d->m_message = m; |
77 | d->m_data = arg; | 83 | d->m_data = arg; |
78 | } | 84 | } |
79 | 85 | ||
80 | bool OQCopMessage::send() | 86 | bool OQCopMessage::send() |
81 | { | 87 | { |
82 | if ( d->m_channel. isEmpty() || d->m_message. isEmpty() ) | 88 | if ( d->m_channel. isEmpty() || d->m_message. isEmpty() ) |
83 | return false; | 89 | return false; |
84 | 90 | ||
85 | QCopEnvelope e ( d->m_channel, d->m_message ); | 91 | QCopEnvelope e ( d->m_channel, d->m_message ); |
86 | 92 | ||
87 | if ( d->m_data. size()) | 93 | if ( d->m_data. size()) |
88 | e. writeRawBytes ( d->m_data. data(), d->m_data. size()); | 94 | e. writeRawBytes ( d->m_data. data(), d->m_data. size()); |
89 | 95 | ||
90 | return true; | 96 | return true; |
91 | } | 97 | } |
92 | 98 | ||
93 | QCString OQCopMessage::channel() const | 99 | QCString OQCopMessage::channel() const |
94 | { | 100 | { |
95 | return d->m_channel; | 101 | return d->m_channel; |
96 | } | 102 | } |
97 | 103 | ||
98 | QCString OQCopMessage::message() const | 104 | QCString OQCopMessage::message() const |
99 | { | 105 | { |
100 | return d->m_message; | 106 | return d->m_message; |
101 | } | 107 | } |
102 | 108 | ||
103 | QByteArray OQCopMessage::data() const | 109 | QByteArray OQCopMessage::data() const |
104 | { | 110 | { |
105 | return d->m_data; | 111 | return d->m_data; |
106 | } | 112 | } |
107 | 113 | ||
108 | bool OQCopMessage::isNull() const | 114 | bool OQCopMessage::isNull() const |
109 | { | 115 | { |
110 | return d->m_message.isNull() || d->m_channel.isNull(); | 116 | return d->m_message.isNull() || d->m_channel.isNull(); |
111 | } | 117 | } |
112 | void OQCopMessage::setChannel ( const QCString &ch ) | 118 | void OQCopMessage::setChannel ( const QCString &ch ) |
113 | { | 119 | { |
114 | d->m_channel = ch; | 120 | d->m_channel = ch; |
115 | } | 121 | } |
116 | 122 | ||
117 | void OQCopMessage::setMessage ( const QCString &m ) | 123 | void OQCopMessage::setMessage ( const QCString &m ) |
118 | { | 124 | { |
119 | d->m_message = m; | 125 | d->m_message = m; |
120 | } | 126 | } |
121 | 127 | ||
122 | void OQCopMessage::setData ( const QByteArray &data ) | 128 | void OQCopMessage::setData ( const QByteArray &data ) |
123 | { | 129 | { |
124 | d->m_data = data; | 130 | d->m_data = data; |
125 | } | 131 | } |
126 | 132 | ||
127 | /*! \class Opie::ODeviceButton | 133 | /*! \class Opie::Core::ODeviceButton |
128 | \brief The Opie::ODeviceButton class represents a physical user mappable button on a Qtopia device. | 134 | \brief The Opie::Core::ODeviceButton class represents a physical user mappable button on a Qtopia device. |
129 | 135 | ||
130 | This class represents a physical button on a Qtopia device. A | 136 | This class represents a physical button on a Qtopia device. A |
131 | device may have "user programmable" buttons. | 137 | device may have "user programmable" buttons. |
132 | The location and number of buttons will vary from device to | 138 | The location and number of buttons will vary from device to |
133 | device. userText() and pixmap() may be used to describe this button | 139 | device. userText() and pixmap() may be used to describe this button |
134 | to the user in help documentation. | 140 | to the user in help documentation. |
135 | 141 | ||
136 | \ingroup qtopiaemb | 142 | \ingroup qtopiaemb |
137 | \internal | 143 | \internal |
138 | */ | 144 | */ |
139 | 145 | ||
140 | ODeviceButton::ODeviceButton() | 146 | ODeviceButton::ODeviceButton() |
141 | {} | 147 | {} |
142 | 148 | ||
143 | ODeviceButton::~ODeviceButton() | 149 | ODeviceButton::~ODeviceButton() |
144 | {} | 150 | {} |
145 | 151 | ||
146 | /*! | 152 | /*! |
147 | Returns the button's keycode. | 153 | Returns the button's keycode. |
148 | */ | 154 | */ |
149 | ushort ODeviceButton::keycode() const | 155 | ushort ODeviceButton::keycode() const |
150 | { | 156 | { |
151 | return m_Keycode; | 157 | return m_Keycode; |
152 | } | 158 | } |
153 | 159 | ||
154 | 160 | ||
155 | /*! | 161 | /*! |
156 | This function returns a human readable, translated description of the button. | 162 | This function returns a human readable, translated description of the button. |
157 | */ | 163 | */ |
158 | QString ODeviceButton::userText() const | 164 | QString ODeviceButton::userText() const |
159 | { | 165 | { |
160 | return m_UserText; | 166 | return m_UserText; |
161 | } | 167 | } |
162 | 168 | ||
163 | /*! | 169 | /*! |
164 | This function returns the pixmap for this button. If there isn't one | 170 | This function returns the pixmap for this button. If there isn't one |
165 | it will return an empty (null) pixmap. | 171 | it will return an empty (null) pixmap. |
166 | */ | 172 | */ |
167 | QPixmap ODeviceButton::pixmap() const | 173 | QPixmap ODeviceButton::pixmap() const |
168 | { | 174 | { |
169 | return m_Pixmap; | 175 | return m_Pixmap; |
170 | } | 176 | } |
171 | 177 | ||
172 | /*! | 178 | /*! |
173 | This function returns the factory preset (default) action for when this button | 179 | This function returns the factory preset (default) action for when this button |
174 | is pressed. The return value is a legal QCop message. | 180 | is pressed. The return value is a legal QCop message. |
175 | */ | 181 | */ |
176 | OQCopMessage ODeviceButton::factoryPresetPressedAction() const | 182 | OQCopMessage ODeviceButton::factoryPresetPressedAction() const |
177 | { | 183 | { |
178 | return m_FactoryPresetPressedAction; | 184 | return m_FactoryPresetPressedAction; |
179 | } | 185 | } |
180 | 186 | ||
181 | /*! | 187 | /*! |
182 | This function returns the user assigned action for when this button is pressed. | 188 | This function returns the user assigned action for when this button is pressed. |
183 | If no action is assigned, factoryPresetAction() is returned. | 189 | If no action is assigned, factoryPresetAction() is returned. |
184 | */ | 190 | */ |
185 | OQCopMessage ODeviceButton::pressedAction() const | 191 | OQCopMessage ODeviceButton::pressedAction() const |
186 | { | 192 | { |
187 | if (m_PressedAction.channel().isEmpty()) | 193 | if (m_PressedAction.channel().isEmpty()) |
188 | return factoryPresetPressedAction(); | 194 | return factoryPresetPressedAction(); |
189 | return m_PressedAction; | 195 | return m_PressedAction; |
190 | } | 196 | } |
191 | 197 | ||
192 | /*! | 198 | /*! |
193 | This function returns the factory preset (default) action for when this button | 199 | This function returns the factory preset (default) action for when this button |
194 | is pressed and held. The return value is a legal QCop message. | 200 | is pressed and held. The return value is a legal QCop message. |
195 | */ | 201 | */ |
196 | OQCopMessage ODeviceButton::factoryPresetHeldAction() const | 202 | OQCopMessage ODeviceButton::factoryPresetHeldAction() const |
197 | { | 203 | { |
198 | return m_FactoryPresetHeldAction; | 204 | return m_FactoryPresetHeldAction; |
199 | } | 205 | } |
200 | 206 | ||
201 | /*! | 207 | /*! |
202 | This function returns the user assigned action for when this button is pressed | 208 | This function returns the user assigned action for when this button is pressed |
203 | and held. If no action is assigned, factoryPresetAction() is returned. | 209 | and held. If no action is assigned, factoryPresetAction() is returned. |
204 | */ | 210 | */ |
205 | OQCopMessage ODeviceButton::heldAction() const | 211 | OQCopMessage ODeviceButton::heldAction() const |
206 | { | 212 | { |
207 | if (m_HeldAction.channel().isEmpty()) | 213 | if (m_HeldAction.channel().isEmpty()) |
208 | return factoryPresetHeldAction(); | 214 | return factoryPresetHeldAction(); |
209 | return m_HeldAction; | 215 | return m_HeldAction; |
210 | } | 216 | } |
211 | 217 | ||
212 | void ODeviceButton::setKeycode(ushort keycode) | 218 | void ODeviceButton::setKeycode(ushort keycode) |
213 | { | 219 | { |
214 | m_Keycode = keycode; | 220 | m_Keycode = keycode; |
215 | } | 221 | } |
216 | 222 | ||
217 | void ODeviceButton::setUserText(const QString& text) | 223 | void ODeviceButton::setUserText(const QString& text) |
218 | { | 224 | { |
219 | m_UserText = text; | 225 | m_UserText = text; |
220 | } | 226 | } |
221 | 227 | ||
222 | void ODeviceButton::setPixmap(const QPixmap& picture) | 228 | void ODeviceButton::setPixmap(const QPixmap& picture) |
223 | { | 229 | { |
224 | m_Pixmap = picture; | 230 | m_Pixmap = picture; |
225 | } | 231 | } |
226 | 232 | ||
227 | void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) | 233 | void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) |
228 | { | 234 | { |
229 | m_FactoryPresetPressedAction = action; | 235 | m_FactoryPresetPressedAction = action; |
230 | } | 236 | } |
231 | 237 | ||
232 | 238 | ||
233 | void ODeviceButton::setPressedAction(const OQCopMessage& action) | 239 | void ODeviceButton::setPressedAction(const OQCopMessage& action) |
234 | { | 240 | { |
235 | m_PressedAction = action; | 241 | m_PressedAction = action; |
236 | } | 242 | } |
237 | 243 | ||
238 | void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) | 244 | void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) |
239 | { | 245 | { |
240 | m_FactoryPresetHeldAction = action; | 246 | m_FactoryPresetHeldAction = action; |
241 | } | 247 | } |
242 | 248 | ||
243 | void ODeviceButton::setHeldAction(const OQCopMessage& action) | 249 | void ODeviceButton::setHeldAction(const OQCopMessage& action) |
244 | { | 250 | { |
245 | m_HeldAction = action; | 251 | m_HeldAction = action; |
246 | } | 252 | } |
253 | |||
254 | } | ||
255 | } | ||
diff --git a/libopie2/opiecore/device/odevicebutton.h b/libopie2/opiecore/device/odevicebutton.h index a66b88f..4000144 100644 --- a/libopie2/opiecore/device/odevicebutton.h +++ b/libopie2/opiecore/device/odevicebutton.h | |||
@@ -1,108 +1,111 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef DEVICE_BUTTON_H | 20 | #ifndef DEVICE_BUTTON_H |
21 | #define DEVICE_BUTTON_H | 21 | #define DEVICE_BUTTON_H |
22 | 22 | ||
23 | #include <qpixmap.h> | 23 | #include <qpixmap.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | class OQCopMessageData; | ||
27 | 26 | ||
28 | namespace Opie | 27 | namespace Opie{ |
29 | { | 28 | namespace Core{ |
29 | namespace Private { | ||
30 | class OQCopMessageData; | ||
31 | } | ||
30 | 32 | ||
31 | class OQCopMessage | 33 | class OQCopMessage |
32 | { | 34 | { |
33 | public: | 35 | public: |
34 | OQCopMessage ( ); | 36 | OQCopMessage ( ); |
35 | OQCopMessage ( const OQCopMessage © ); | 37 | OQCopMessage ( const OQCopMessage © ); |
36 | OQCopMessage ( const QCString &m_channel, const QCString &message, const QByteArray &args = QByteArray ( )); | 38 | OQCopMessage ( const QCString &m_channel, const QCString &message, const QByteArray &args = QByteArray ( )); |
37 | 39 | ||
38 | OQCopMessage &operator = ( const OQCopMessage &assign ); | 40 | OQCopMessage &operator = ( const OQCopMessage &assign ); |
39 | 41 | ||
40 | void setChannel ( const QCString &channel ); | 42 | void setChannel ( const QCString &channel ); |
41 | void setMessage ( const QCString &message ); | 43 | void setMessage ( const QCString &message ); |
42 | void setData ( const QByteArray &ba ); | 44 | void setData ( const QByteArray &ba ); |
43 | 45 | ||
44 | QCString channel ( ) const; | 46 | QCString channel ( ) const; |
45 | QCString message ( ) const; | 47 | QCString message ( ) const; |
46 | QByteArray data ( ) const; | 48 | QByteArray data ( ) const; |
47 | 49 | ||
48 | bool isNull()const; | 50 | bool isNull()const; |
49 | 51 | ||
50 | bool send ( ); | 52 | bool send ( ); |
51 | 53 | ||
52 | private: | 54 | private: |
53 | void init ( const QCString &m_channel, const QCString &message, const QByteArray &args ); | 55 | void init ( const QCString &m_channel, const QCString &message, const QByteArray &args ); |
54 | 56 | ||
55 | OQCopMessageData *d; | 57 | Private::OQCopMessageData *d; |
56 | class Private; | 58 | class Private; |
57 | Private* m_data; | 59 | Private* m_data; |
58 | }; | 60 | }; |
59 | 61 | ||
60 | 62 | ||
61 | /** | 63 | /** |
62 | * This class represents a physical button on a Qtopia device. A device may | 64 | * This class represents a physical button on a Qtopia device. A device may |
63 | * have n "user programmable" buttons, which are number 1..n. The location | 65 | * have n "user programmable" buttons, which are number 1..n. The location |
64 | * and number of buttons will vary from device to device. userText() and pixmap() | 66 | * and number of buttons will vary from device to device. userText() and pixmap() |
65 | * may be used to describe this button to the user in help documentation. | 67 | * may be used to describe this button to the user in help documentation. |
66 | * | 68 | * |
67 | * @version 1.0 | 69 | * @version 1.0 |
68 | * @author Trolltech | 70 | * @author Trolltech |
69 | * @short A representation of buttons | 71 | * @short A representation of buttons |
70 | */ | 72 | */ |
71 | 73 | ||
72 | class ODeviceButton | 74 | class ODeviceButton |
73 | { | 75 | { |
74 | public: | 76 | public: |
75 | ODeviceButton(); | 77 | ODeviceButton(); |
76 | virtual ~ODeviceButton(); | 78 | virtual ~ODeviceButton(); |
77 | 79 | ||
78 | ushort keycode ( ) const; | 80 | ushort keycode ( ) const; |
79 | QString userText ( ) const; | 81 | QString userText ( ) const; |
80 | QPixmap pixmap ( ) const; | 82 | QPixmap pixmap ( ) const; |
81 | OQCopMessage factoryPresetPressedAction ( ) const; | 83 | OQCopMessage factoryPresetPressedAction ( ) const; |
82 | OQCopMessage pressedAction ( ) const; | 84 | OQCopMessage pressedAction ( ) const; |
83 | OQCopMessage factoryPresetHeldAction ( ) const; | 85 | OQCopMessage factoryPresetHeldAction ( ) const; |
84 | OQCopMessage heldAction ( ) const; | 86 | OQCopMessage heldAction ( ) const; |
85 | 87 | ||
86 | void setKeycode ( ushort keycode ); | 88 | void setKeycode ( ushort keycode ); |
87 | void setUserText ( const QString& text ); | 89 | void setUserText ( const QString& text ); |
88 | void setPixmap ( const QPixmap& picture ); | 90 | void setPixmap ( const QPixmap& picture ); |
89 | void setFactoryPresetPressedAction ( const OQCopMessage& qcopMessage ); | 91 | void setFactoryPresetPressedAction ( const OQCopMessage& qcopMessage ); |
90 | void setPressedAction ( const OQCopMessage& qcopMessage ); | 92 | void setPressedAction ( const OQCopMessage& qcopMessage ); |
91 | void setFactoryPresetHeldAction ( const OQCopMessage& qcopMessage ); | 93 | void setFactoryPresetHeldAction ( const OQCopMessage& qcopMessage ); |
92 | void setHeldAction ( const OQCopMessage& qcopMessage ); | 94 | void setHeldAction ( const OQCopMessage& qcopMessage ); |
93 | 95 | ||
94 | private: | 96 | private: |
95 | ushort m_Keycode; | 97 | ushort m_Keycode; |
96 | QString m_UserText; | 98 | QString m_UserText; |
97 | QPixmap m_Pixmap; | 99 | QPixmap m_Pixmap; |
98 | OQCopMessage m_FactoryPresetPressedAction; | 100 | OQCopMessage m_FactoryPresetPressedAction; |
99 | OQCopMessage m_PressedAction; | 101 | OQCopMessage m_PressedAction; |
100 | OQCopMessage m_FactoryPresetHeldAction; | 102 | OQCopMessage m_FactoryPresetHeldAction; |
101 | OQCopMessage m_HeldAction; | 103 | OQCopMessage m_HeldAction; |
102 | class Private; | 104 | class Private; |
103 | Private *d; | 105 | Private *d; |
104 | }; | 106 | }; |
105 | 107 | ||
106 | } | 108 | } |
109 | } | ||
107 | 110 | ||
108 | #endif | 111 | #endif |
diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp index d340c0e..e2f6e82 100644 --- a/libopie2/opiecore/oapplication.cpp +++ b/libopie2/opiecore/oapplication.cpp | |||
@@ -1,127 +1,136 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oapplication.h> | 30 | #include <opie2/oapplication.h> |
31 | #include <opie2/oconfig.h> | 31 | #include <opie2/oconfig.h> |
32 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | 33 | ||
34 | #include <signal.h> | 34 | #include <signal.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | using namespace Opie::Core; | ||
38 | |||
39 | |||
37 | OApplication* OApplication::_instance = 0; | 40 | OApplication* OApplication::_instance = 0; |
38 | 41 | ||
39 | /************************************************************************************************** | 42 | /************************************************************************************************** |
40 | * OApplicationPrivate | 43 | * OApplicationPrivate |
41 | **************************************************************************************************/ | 44 | **************************************************************************************************/ |
42 | 45 | ||
46 | namespace Opie { | ||
47 | namespace Core { | ||
48 | namespace Private { | ||
43 | class OApplicationPrivate | 49 | class OApplicationPrivate |
44 | { | 50 | { |
45 | public: | 51 | public: |
46 | OApplicationPrivate() {}; | 52 | OApplicationPrivate() {}; |
47 | ~OApplicationPrivate() {}; | 53 | ~OApplicationPrivate() {}; |
48 | }; | 54 | }; |
55 | } | ||
49 | 56 | ||
50 | /************************************************************************************************** | 57 | /************************************************************************************************** |
51 | * OApplication | 58 | * OApplication |
52 | **************************************************************************************************/ | 59 | **************************************************************************************************/ |
53 | 60 | ||
54 | 61 | ||
55 | OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) | 62 | OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) |
56 | :QPEApplication( argc, argv ), | 63 | :QPEApplication( argc, argv ), |
57 | _appname( rAppName ), | 64 | _appname( rAppName ), |
58 | _config( 0 ) | 65 | _config( 0 ) |
59 | { | 66 | { |
60 | init(); | 67 | init(); |
61 | } | 68 | } |
62 | 69 | ||
63 | 70 | ||
64 | OApplication::~OApplication() | 71 | OApplication::~OApplication() |
65 | { | 72 | { |
66 | delete d; | 73 | delete d; |
67 | if ( _config ) | 74 | if ( _config ) |
68 | delete _config; | 75 | delete _config; |
69 | OApplication::_instance = 0; | 76 | OApplication::_instance = 0; |
70 | // after deconstruction of the one-and-only application object, | 77 | // after deconstruction of the one-and-only application object, |
71 | // the construction of another object is allowed | 78 | // the construction of another object is allowed |
72 | } | 79 | } |
73 | 80 | ||
74 | 81 | ||
75 | OConfig* OApplication::config() | 82 | OConfig* OApplication::config() |
76 | { | 83 | { |
77 | if ( !_config ) | 84 | if ( !_config ) |
78 | { | 85 | { |
79 | _config = new OConfig( _appname ); | 86 | _config = new OConfig( _appname ); |
80 | } | 87 | } |
81 | return _config; | 88 | return _config; |
82 | } | 89 | } |
83 | 90 | ||
84 | 91 | ||
85 | void OApplication::init() | 92 | void OApplication::init() |
86 | { | 93 | { |
87 | d = new OApplicationPrivate(); | 94 | d = new Private::OApplicationPrivate(); |
88 | if ( !OApplication::_instance ) | 95 | if ( !OApplication::_instance ) |
89 | { | 96 | { |
90 | OApplication::_instance = this; | 97 | OApplication::_instance = this; |
91 | 98 | ||
92 | /* register SIGSEGV handler to give programs an option | 99 | /* register SIGSEGV handler to give programs an option |
93 | * to exit gracefully, e.g. save or close devices or files. | 100 | * to exit gracefully, e.g. save or close devices or files. |
94 | struct sigaction sa; | 101 | struct sigaction sa; |
95 | sa.sa_handler = ( void (*)(int) ) &segv_handler; | 102 | sa.sa_handler = ( void (*)(int) ) &segv_handler; |
96 | sa.sa_flags = SA_SIGINFO | SA_RESTART; | 103 | sa.sa_flags = SA_SIGINFO | SA_RESTART; |
97 | sigemptyset(&sa.sa_mask); | 104 | sigemptyset(&sa.sa_mask); |
98 | sigaction(SIGSEGV, &sa, NULL); | 105 | sigaction(SIGSEGV, &sa, NULL); |
99 | */ | 106 | */ |
100 | } | 107 | } |
101 | else | 108 | else |
102 | { | 109 | { |
103 | ofatal << "OApplication: Can't create more than one OApplication object. Aborting." << oendl; | 110 | ofatal << "OApplication: Can't create more than one OApplication object. Aborting." << oendl; |
104 | //FIXME exit gracefully ? | 111 | //FIXME exit gracefully ? |
105 | ::exit( -1 ); | 112 | ::exit( -1 ); |
106 | } | 113 | } |
107 | } | 114 | } |
108 | 115 | ||
109 | 116 | ||
110 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) | 117 | void OApplication::showMainWidget( QWidget* widget, bool nomax ) |
111 | { | 118 | { |
112 | QPEApplication::showMainWidget( widget, nomax ); | 119 | QPEApplication::showMainWidget( widget, nomax ); |
113 | widget->setCaption( _appname ); | 120 | widget->setCaption( _appname ); |
114 | } | 121 | } |
115 | 122 | ||
116 | 123 | ||
117 | void OApplication::setTitle( const QString& title ) const | 124 | void OApplication::setTitle( const QString& title ) const |
118 | { | 125 | { |
119 | if ( mainWidget() ) | 126 | if ( mainWidget() ) |
120 | { | 127 | { |
121 | if ( !title.isNull() ) | 128 | if ( !title.isNull() ) |
122 | mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title ); | 129 | mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title ); |
123 | else | 130 | else |
124 | mainWidget()->setCaption( _appname ); | 131 | mainWidget()->setCaption( _appname ); |
125 | } | 132 | } |
126 | } | 133 | } |
127 | 134 | ||
135 | } | ||
136 | } | ||
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h index cc506a2..c1e32a6 100644 --- a/libopie2/opiecore/oapplication.h +++ b/libopie2/opiecore/oapplication.h | |||
@@ -1,104 +1,111 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef OAPPLICATION_H | 30 | #ifndef OAPPLICATION_H |
31 | #define OAPPLICATION_H | 31 | #define OAPPLICATION_H |
32 | 32 | ||
33 | #define oApp OApplication::oApplication() | 33 | #define oApp Opie::Core::OApplication::oApplication() |
34 | 34 | ||
35 | 35 | ||
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | 37 | ||
38 | 38 | namespace Opie { | |
39 | namespace Core { | ||
40 | namespace Private { | ||
39 | class OApplicationPrivate; | 41 | class OApplicationPrivate; |
42 | } // private class | ||
43 | |||
40 | class OConfig; | 44 | class OConfig; |
41 | 45 | ||
42 | 46 | ||
43 | class OApplication : public QPEApplication | 47 | class OApplication : public QPEApplication |
44 | { | 48 | { |
45 | Q_OBJECT | 49 | Q_OBJECT |
46 | 50 | ||
47 | public: | 51 | public: |
48 | /** | 52 | /** |
49 | * Constructor. Parses command-line arguments and sets the window caption. | 53 | * Constructor. Parses command-line arguments and sets the window caption. |
50 | * | 54 | * |
51 | * @param rAppName application name. Will be used for finding the | 55 | * @param rAppName application name. Will be used for finding the |
52 | * associated message, icon and configuration files | 56 | * associated message, icon and configuration files |
53 | * | 57 | * |
54 | */ | 58 | */ |
55 | OApplication( int& argc, char** argv, const QCString& rAppName ); | 59 | OApplication( int& argc, char** argv, const QCString& rAppName ); |
56 | /** | 60 | /** |
57 | * Destructor. Destroys the application object and its children. | 61 | * Destructor. Destroys the application object and its children. |
58 | */ | 62 | */ |
59 | virtual ~OApplication(); | 63 | virtual ~OApplication(); |
60 | /** | 64 | /** |
61 | * @returns the process-wide application object | 65 | * @returns the process-wide application object |
62 | * | 66 | * |
63 | * This is similar to the global @ref QApplication pointer qApp. It | 67 | * This is similar to the global @ref QApplication pointer qApp. It |
64 | * allows access to the single global OApplication object, since | 68 | * allows access to the single global OApplication object, since |
65 | * more than one cannot be created in the same application. It | 69 | * more than one cannot be created in the same application. It |
66 | * saves you the trouble of having to pass the pointer explicitly | 70 | * saves you the trouble of having to pass the pointer explicitly |
67 | * to every function that may require it. | 71 | * to every function that may require it. |
68 | */ | 72 | */ |
69 | static OApplication* oApplication() { return _instance; }; | 73 | static OApplication* oApplication() { return _instance; }; |
70 | /** | 74 | /** |
71 | * Returns the application name as given during creation. | 75 | * Returns the application name as given during creation. |
72 | * | 76 | * |
73 | * @returns a reference to the application name | 77 | * @returns a reference to the application name |
74 | */ | 78 | */ |
75 | const QCString& appName() const { return _appname; }; | 79 | const QCString& appName() const { return _appname; }; |
76 | /** | 80 | /** |
77 | * @returns the application session config object. | 81 | * @returns the application session config object. |
78 | * | 82 | * |
79 | * @see OConfig | 83 | * @see OConfig |
80 | */ | 84 | */ |
81 | OConfig* config(); | 85 | OConfig* config(); |
82 | /** | 86 | /** |
83 | * Shows the main @a widget and sets the name of the application as window caption. | 87 | * Shows the main @a widget and sets the name of the application as window caption. |
84 | */ | 88 | */ |
85 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); | 89 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); |
86 | /** | 90 | /** |
87 | * Set the application title. The application title will be concatenated | 91 | * Set the application title. The application title will be concatenated |
88 | * to the application name given in the constructor. | 92 | * to the application name given in the constructor. |
89 | * | 93 | * |
90 | * @param title the title. If not given, resets caption to appname | 94 | * @param title the title. If not given, resets caption to appname |
91 | */ | 95 | */ |
92 | virtual void setTitle( const QString& title = QString::null ) const; | 96 | virtual void setTitle( const QString& title = QString::null ) const; |
93 | 97 | ||
94 | protected: | 98 | protected: |
95 | void init(); | 99 | void init(); |
96 | 100 | ||
97 | private: | 101 | private: |
98 | const QCString _appname; | 102 | const QCString _appname; |
99 | static OApplication* _instance; | 103 | static OApplication* _instance; |
100 | OConfig* _config; | 104 | OConfig* _config; |
101 | OApplicationPrivate* d; | 105 | Private::OApplicationPrivate* d; |
102 | }; | 106 | }; |
103 | 107 | ||
108 | } // Core | ||
109 | } // Opie | ||
110 | |||
104 | #endif // OAPPLICATION_H | 111 | #endif // OAPPLICATION_H |
diff --git a/libopie2/opiecore/oconfig.cpp b/libopie2/opiecore/oconfig.cpp index fb5eabb..05d8070 100644 --- a/libopie2/opiecore/oconfig.cpp +++ b/libopie2/opiecore/oconfig.cpp | |||
@@ -1,203 +1,205 @@ | |||
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 Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | (C) 2003 Michael 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 | /* QT */ | 32 | /* QT */ |
33 | 33 | ||
34 | #include <qfont.h> | 34 | #include <qfont.h> |
35 | #include <qcolor.h> | 35 | #include <qcolor.h> |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | 38 | ||
39 | #include <opie2/oconfig.h> | 39 | #include <opie2/oconfig.h> |
40 | 40 | ||
41 | using namespace Opie::Core; | ||
42 | |||
41 | OConfig::OConfig( const QString &name, Domain domain ) | 43 | OConfig::OConfig( const QString &name, Domain domain ) |
42 | :Config( name, domain ) | 44 | :Config( name, domain ) |
43 | { | 45 | { |
44 | qDebug( "OConfig::OConfig()" ); | 46 | qDebug( "OConfig::OConfig()" ); |
45 | } | 47 | } |
46 | 48 | ||
47 | OConfig::~OConfig() | 49 | OConfig::~OConfig() |
48 | { | 50 | { |
49 | qDebug( "OConfig::~OConfig()" ); | 51 | qDebug( "OConfig::~OConfig()" ); |
50 | } | 52 | } |
51 | 53 | ||
52 | QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const | 54 | QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const |
53 | { | 55 | { |
54 | QColor aRetColor; | 56 | QColor aRetColor; |
55 | int nRed = 0, nGreen = 0, nBlue = 0; | 57 | int nRed = 0, nGreen = 0, nBlue = 0; |
56 | 58 | ||
57 | QString aValue = readEntry( key ); | 59 | QString aValue = readEntry( key ); |
58 | if( !aValue.isEmpty() ) | 60 | if( !aValue.isEmpty() ) |
59 | { | 61 | { |
60 | if ( aValue.at(0) == '#' ) | 62 | if ( aValue.at(0) == '#' ) |
61 | { | 63 | { |
62 | aRetColor.setNamedColor(aValue); | 64 | aRetColor.setNamedColor(aValue); |
63 | } | 65 | } |
64 | else | 66 | else |
65 | { | 67 | { |
66 | bool bOK; | 68 | bool bOK; |
67 | 69 | ||
68 | // find first part (red) | 70 | // find first part (red) |
69 | int nIndex = aValue.find( ',' ); | 71 | int nIndex = aValue.find( ',' ); |
70 | 72 | ||
71 | if( nIndex == -1 ) | 73 | if( nIndex == -1 ) |
72 | { | 74 | { |
73 | // return a sensible default -- Bernd | 75 | // return a sensible default -- Bernd |
74 | if( pDefault ) | 76 | if( pDefault ) |
75 | aRetColor = *pDefault; | 77 | aRetColor = *pDefault; |
76 | return aRetColor; | 78 | return aRetColor; |
77 | } | 79 | } |
78 | 80 | ||
79 | nRed = aValue.left( nIndex ).toInt( &bOK ); | 81 | nRed = aValue.left( nIndex ).toInt( &bOK ); |
80 | 82 | ||
81 | // find second part (green) | 83 | // find second part (green) |
82 | int nOldIndex = nIndex; | 84 | int nOldIndex = nIndex; |
83 | nIndex = aValue.find( ',', nOldIndex+1 ); | 85 | nIndex = aValue.find( ',', nOldIndex+1 ); |
84 | 86 | ||
85 | if( nIndex == -1 ) | 87 | if( nIndex == -1 ) |
86 | { | 88 | { |
87 | // return a sensible default -- Bernd | 89 | // return a sensible default -- Bernd |
88 | if( pDefault ) | 90 | if( pDefault ) |
89 | aRetColor = *pDefault; | 91 | aRetColor = *pDefault; |
90 | return aRetColor; | 92 | return aRetColor; |
91 | } | 93 | } |
92 | nGreen = aValue.mid( nOldIndex+1, | 94 | nGreen = aValue.mid( nOldIndex+1, |
93 | nIndex-nOldIndex-1 ).toInt( &bOK ); | 95 | nIndex-nOldIndex-1 ).toInt( &bOK ); |
94 | 96 | ||
95 | // find third part (blue) | 97 | // find third part (blue) |
96 | nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK ); | 98 | nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK ); |
97 | 99 | ||
98 | aRetColor.setRgb( nRed, nGreen, nBlue ); | 100 | aRetColor.setRgb( nRed, nGreen, nBlue ); |
99 | } | 101 | } |
100 | } | 102 | } |
101 | else { | 103 | else { |
102 | 104 | ||
103 | if( pDefault ) | 105 | if( pDefault ) |
104 | aRetColor = *pDefault; | 106 | aRetColor = *pDefault; |
105 | } | 107 | } |
106 | 108 | ||
107 | return aRetColor; | 109 | return aRetColor; |
108 | } | 110 | } |
109 | 111 | ||
110 | // FIXME: The whole font handling has to be revised for Opie | 112 | // FIXME: The whole font handling has to be revised for Opie |
111 | 113 | ||
112 | QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const | 114 | QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const |
113 | { | 115 | { |
114 | /* | 116 | /* |
115 | QFont aRetFont; | 117 | QFont aRetFont; |
116 | 118 | ||
117 | QString aValue = readEntry( key ); | 119 | QString aValue = readEntry( key ); |
118 | if( !aValue.isNull() ) { | 120 | if( !aValue.isNull() ) { |
119 | if ( aValue.contains( ',' ) > 5 ) { | 121 | if ( aValue.contains( ',' ) > 5 ) { |
120 | // KDE3 and upwards entry | 122 | // KDE3 and upwards entry |
121 | if ( !aRetFont.fromString( aValue ) && pDefault ) | 123 | if ( !aRetFont.fromString( aValue ) && pDefault ) |
122 | aRetFont = *pDefault; | 124 | aRetFont = *pDefault; |
123 | } | 125 | } |
124 | else { | 126 | else { |
125 | // backward compatibility with older font formats | 127 | // backward compatibility with older font formats |
126 | // ### remove KDE 3.1 ? | 128 | // ### remove KDE 3.1 ? |
127 | // find first part (font family) | 129 | // find first part (font family) |
128 | int nIndex = aValue.find( ',' ); | 130 | int nIndex = aValue.find( ',' ); |
129 | if( nIndex == -1 ){ | 131 | if( nIndex == -1 ){ |
130 | if( pDefault ) | 132 | if( pDefault ) |
131 | aRetFont = *pDefault; | 133 | aRetFont = *pDefault; |
132 | return aRetFont; | 134 | return aRetFont; |
133 | } | 135 | } |
134 | aRetFont.setFamily( aValue.left( nIndex ) ); | 136 | aRetFont.setFamily( aValue.left( nIndex ) ); |
135 | 137 | ||
136 | // find second part (point size) | 138 | // find second part (point size) |
137 | int nOldIndex = nIndex; | 139 | int nOldIndex = nIndex; |
138 | nIndex = aValue.find( ',', nOldIndex+1 ); | 140 | nIndex = aValue.find( ',', nOldIndex+1 ); |
139 | if( nIndex == -1 ){ | 141 | if( nIndex == -1 ){ |
140 | if( pDefault ) | 142 | if( pDefault ) |
141 | aRetFont = *pDefault; | 143 | aRetFont = *pDefault; |
142 | return aRetFont; | 144 | return aRetFont; |
143 | } | 145 | } |
144 | 146 | ||
145 | aRetFont.setPointSize( aValue.mid( nOldIndex+1, | 147 | aRetFont.setPointSize( aValue.mid( nOldIndex+1, |
146 | nIndex-nOldIndex-1 ).toInt() ); | 148 | nIndex-nOldIndex-1 ).toInt() ); |
147 | 149 | ||
148 | // find third part (style hint) | 150 | // find third part (style hint) |
149 | nOldIndex = nIndex; | 151 | nOldIndex = nIndex; |
150 | nIndex = aValue.find( ',', nOldIndex+1 ); | 152 | nIndex = aValue.find( ',', nOldIndex+1 ); |
151 | 153 | ||
152 | if( nIndex == -1 ){ | 154 | if( nIndex == -1 ){ |
153 | if( pDefault ) | 155 | if( pDefault ) |
154 | aRetFont = *pDefault; | 156 | aRetFont = *pDefault; |
155 | return aRetFont; | 157 | return aRetFont; |
156 | } | 158 | } |
157 | 159 | ||
158 | aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); | 160 | aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); |
159 | 161 | ||
160 | // find fourth part (char set) | 162 | // find fourth part (char set) |
161 | nOldIndex = nIndex; | 163 | nOldIndex = nIndex; |
162 | nIndex = aValue.find( ',', nOldIndex+1 ); | 164 | nIndex = aValue.find( ',', nOldIndex+1 ); |
163 | 165 | ||
164 | if( nIndex == -1 ){ | 166 | if( nIndex == -1 ){ |
165 | if( pDefault ) | 167 | if( pDefault ) |
166 | aRetFont = *pDefault; | 168 | aRetFont = *pDefault; |
167 | return aRetFont; | 169 | return aRetFont; |
168 | } | 170 | } |
169 | 171 | ||
170 | QString chStr=aValue.mid( nOldIndex+1, | 172 | QString chStr=aValue.mid( nOldIndex+1, |
171 | nIndex-nOldIndex-1 ); | 173 | nIndex-nOldIndex-1 ); |
172 | // find fifth part (weight) | 174 | // find fifth part (weight) |
173 | nOldIndex = nIndex; | 175 | nOldIndex = nIndex; |
174 | nIndex = aValue.find( ',', nOldIndex+1 ); | 176 | nIndex = aValue.find( ',', nOldIndex+1 ); |
175 | 177 | ||
176 | if( nIndex == -1 ){ | 178 | if( nIndex == -1 ){ |
177 | if( pDefault ) | 179 | if( pDefault ) |
178 | aRetFont = *pDefault; | 180 | aRetFont = *pDefault; |
179 | return aRetFont; | 181 | return aRetFont; |
180 | } | 182 | } |
181 | 183 | ||
182 | aRetFont.setWeight( aValue.mid( nOldIndex+1, | 184 | aRetFont.setWeight( aValue.mid( nOldIndex+1, |
183 | nIndex-nOldIndex-1 ).toUInt() ); | 185 | nIndex-nOldIndex-1 ).toUInt() ); |
184 | 186 | ||
185 | // find sixth part (font bits) | 187 | // find sixth part (font bits) |
186 | uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt(); | 188 | uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt(); |
187 | 189 | ||
188 | aRetFont.setItalic( nFontBits & 0x01 ); | 190 | aRetFont.setItalic( nFontBits & 0x01 ); |
189 | aRetFont.setUnderline( nFontBits & 0x02 ); | 191 | aRetFont.setUnderline( nFontBits & 0x02 ); |
190 | aRetFont.setStrikeOut( nFontBits & 0x04 ); | 192 | aRetFont.setStrikeOut( nFontBits & 0x04 ); |
191 | aRetFont.setFixedPitch( nFontBits & 0x08 ); | 193 | aRetFont.setFixedPitch( nFontBits & 0x08 ); |
192 | aRetFont.setRawMode( nFontBits & 0x20 ); | 194 | aRetFont.setRawMode( nFontBits & 0x20 ); |
193 | } | 195 | } |
194 | } | 196 | } |
195 | else | 197 | else |
196 | { | 198 | { |
197 | if( pDefault ) | 199 | if( pDefault ) |
198 | aRetFont = *pDefault; | 200 | aRetFont = *pDefault; |
199 | } | 201 | } |
200 | return aRetFont; | 202 | return aRetFont; |
201 | */ | 203 | */ |
202 | return QFont("Helvetica",10); | 204 | return QFont("Helvetica",10); |
203 | } | 205 | } |
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 |
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp index a40ef53..cac985b 100644 --- a/libopie2/opiecore/odebug.cpp +++ b/libopie2/opiecore/odebug.cpp | |||
@@ -1,260 +1,261 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) | 3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) |
4 | (C) 2002 Holger Freyther (freyther@kde.org) | 4 | (C) 2002 Holger Freyther (freyther@kde.org) |
5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) | 5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) |
6 | =. | 6 | =. |
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 | // Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo | 32 | // Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo |
33 | // functions inlined to noops (which would then conflict with their definition here). | 33 | // functions inlined to noops (which would then conflict with their definition here). |
34 | 34 | ||
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | 36 | ||
37 | #ifdef OPIE_NO_DEBUG | 37 | #ifdef OPIE_NO_DEBUG |
38 | #undef odDebug | 38 | #undef odDebug |
39 | #undef odBacktrace | 39 | #undef odBacktrace |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | /* OPIE */ | 42 | /* OPIE */ |
43 | 43 | ||
44 | #include <opie2/oapplication.h> | 44 | #include <opie2/oapplication.h> |
45 | #include <opie2/oglobalsettings.h> | 45 | #include <opie2/oglobalsettings.h> |
46 | #include <opie2/oconfig.h> | 46 | #include <opie2/oconfig.h> |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | 49 | ||
50 | #include <qfile.h> | 50 | #include <qfile.h> |
51 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
52 | #include <qsocketdevice.h> | 52 | #include <qsocketdevice.h> |
53 | 53 | ||
54 | /* UNIX */ | 54 | /* UNIX */ |
55 | 55 | ||
56 | #include <stdlib.h> // abort | 56 | #include <stdlib.h> // abort |
57 | #include <unistd.h> // getpid | 57 | #include <unistd.h> // getpid |
58 | #include <stdarg.h> // vararg stuff | 58 | #include <stdarg.h> // vararg stuff |
59 | #include <ctype.h> // isprint | 59 | #include <ctype.h> // isprint |
60 | #include <syslog.h> | 60 | #include <syslog.h> |
61 | #include <errno.h> | 61 | #include <errno.h> |
62 | #include <string.h> | 62 | #include <string.h> |
63 | 63 | ||
64 | #ifndef OPIE_NO_BACKTRACE | 64 | #ifndef OPIE_NO_BACKTRACE |
65 | #include <execinfo.h> | 65 | #include <execinfo.h> |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | 68 | namespace Opie { | |
69 | namespace Core { | ||
69 | /*====================================================================================== | 70 | /*====================================================================================== |
70 | * debug levels | 71 | * debug levels |
71 | *======================================================================================*/ | 72 | *======================================================================================*/ |
72 | 73 | ||
73 | enum DebugLevels { | 74 | enum DebugLevels { |
74 | ODEBUG_INFO = 0, | 75 | ODEBUG_INFO = 0, |
75 | ODEBUG_WARN = 1, | 76 | ODEBUG_WARN = 1, |
76 | ODEBUG_ERROR = 2, | 77 | ODEBUG_ERROR = 2, |
77 | ODEBUG_FATAL = 3 | 78 | ODEBUG_FATAL = 3 |
78 | }; | 79 | }; |
79 | 80 | ||
80 | /*====================================================================================== | 81 | /*====================================================================================== |
81 | * oDebug private data | 82 | * oDebug private data |
82 | *======================================================================================*/ | 83 | *======================================================================================*/ |
83 | 84 | ||
84 | /*====================================================================================== | 85 | /*====================================================================================== |
85 | * the main debug function | 86 | * the main debug function |
86 | *======================================================================================*/ | 87 | *======================================================================================*/ |
87 | 88 | ||
88 | static void oDebugBackend( unsigned short level, unsigned int area, const char *data) | 89 | static void oDebugBackend( unsigned short level, unsigned int area, const char *data) |
89 | { | 90 | { |
90 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); | 91 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); |
91 | 92 | ||
92 | // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an | 93 | // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an |
93 | // ML: example use. I think it's not necessary to implement such a strategy here. | 94 | // ML: example use. I think it's not necessary to implement such a strategy here. |
94 | // ML: Comments? | 95 | // ML: Comments? |
95 | 96 | ||
96 | int priority = 0; | 97 | int priority = 0; |
97 | QString caption; | 98 | QString caption; |
98 | QString lev; | 99 | QString lev; |
99 | switch( level ) | 100 | switch( level ) |
100 | { | 101 | { |
101 | case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; | 102 | case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; |
102 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; | 103 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; |
103 | case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; | 104 | case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; |
104 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); | 105 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); |
105 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; | 106 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; |
106 | } | 107 | } |
107 | 108 | ||
108 | short output = OGlobalSettings::debugMode(); | 109 | short output = OGlobalSettings::debugMode(); |
109 | if (!oApp && (output == 1)) | 110 | if (!oApp && (output == 1)) |
110 | { | 111 | { |
111 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); | 112 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); |
112 | output = 2; // need an application object to use MsgBox | 113 | output = 2; // need an application object to use MsgBox |
113 | } | 114 | } |
114 | 115 | ||
115 | // gcc 2.9x is dumb and sucks... can you hear it? | 116 | // gcc 2.9x is dumb and sucks... can you hear it? |
116 | //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; | 117 | //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; |
117 | QString areaName; | 118 | QString areaName; |
118 | if ( oApp ) areaName = oApp->appName(); | 119 | if ( oApp ) areaName = oApp->appName(); |
119 | else areaName = "<unknown>"; | 120 | else areaName = "<unknown>"; |
120 | 121 | ||
121 | // Output | 122 | // Output |
122 | switch( output ) | 123 | switch( output ) |
123 | { | 124 | { |
124 | case -1: // ignore | 125 | case -1: // ignore |
125 | { | 126 | { |
126 | return; | 127 | return; |
127 | } | 128 | } |
128 | case 0: // File | 129 | case 0: // File |
129 | { | 130 | { |
130 | QString outputFilename = OGlobalSettings::debugOutput(); | 131 | QString outputFilename = OGlobalSettings::debugOutput(); |
131 | 132 | ||
132 | const int BUFSIZE = 4096; | 133 | const int BUFSIZE = 4096; |
133 | char buf[BUFSIZE] = ""; | 134 | char buf[BUFSIZE] = ""; |
134 | buf[BUFSIZE-1] = '\0'; | 135 | buf[BUFSIZE-1] = '\0'; |
135 | int nSize; | 136 | int nSize; |
136 | 137 | ||
137 | nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); | 138 | nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); |
138 | 139 | ||
139 | QFile outputFile( outputFilename ); | 140 | QFile outputFile( outputFilename ); |
140 | if ( outputFile.open( IO_WriteOnly | IO_Append ) ) | 141 | if ( outputFile.open( IO_WriteOnly | IO_Append ) ) |
141 | { | 142 | { |
142 | if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) | 143 | if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) |
143 | { | 144 | { |
144 | outputFile.writeBlock( buf, BUFSIZE-1 ); | 145 | outputFile.writeBlock( buf, BUFSIZE-1 ); |
145 | } | 146 | } |
146 | else | 147 | else |
147 | { | 148 | { |
148 | outputFile.writeBlock( buf, nSize ); | 149 | outputFile.writeBlock( buf, nSize ); |
149 | } | 150 | } |
150 | } | 151 | } |
151 | else | 152 | else |
152 | { | 153 | { |
153 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); | 154 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); |
154 | } | 155 | } |
155 | break; | 156 | break; |
156 | } // automatic close of file here | 157 | } // automatic close of file here |
157 | 158 | ||
158 | case 1: // Message Box | 159 | case 1: // Message Box |
159 | { | 160 | { |
160 | // Since we are in opiecore here, we cannot use OMsgBox and use | 161 | // Since we are in opiecore here, we cannot use OMsgBox and use |
161 | // QMessageBox instead | 162 | // QMessageBox instead |
162 | 163 | ||
163 | caption += QString("(") + areaName + ")"; | 164 | caption += QString("(") + areaName + ")"; |
164 | QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? | 165 | QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? |
165 | break; | 166 | break; |
166 | } | 167 | } |
167 | 168 | ||
168 | case 2: // Shell | 169 | case 2: // Shell |
169 | { | 170 | { |
170 | FILE *output = stderr; | 171 | FILE *output = stderr; |
171 | fprintf( output, "%s: ", (const char*) areaName ); | 172 | fprintf( output, "%s: ", (const char*) areaName ); |
172 | fputs( data, output); | 173 | fputs( data, output); |
173 | break; | 174 | break; |
174 | } | 175 | } |
175 | 176 | ||
176 | case 3: // syslog | 177 | case 3: // syslog |
177 | { | 178 | { |
178 | syslog( priority, "%s", data); | 179 | syslog( priority, "%s", data); |
179 | break; | 180 | break; |
180 | } | 181 | } |
181 | 182 | ||
182 | case 4: // socket | 183 | case 4: // socket |
183 | { | 184 | { |
184 | QString destination = OGlobalSettings::debugOutput(); | 185 | QString destination = OGlobalSettings::debugOutput(); |
185 | if ( destination && destination.find(":") != -1 ) | 186 | if ( destination && destination.find(":") != -1 ) |
186 | { | 187 | { |
187 | QString host = destination.left( destination.find(":") ); | 188 | QString host = destination.left( destination.find(":") ); |
188 | QString port = destination.right( destination.length()-host.length()-1 ); | 189 | QString port = destination.right( destination.length()-host.length()-1 ); |
189 | QHostAddress addr; | 190 | QHostAddress addr; |
190 | addr.setAddress( host ); | 191 | addr.setAddress( host ); |
191 | // TODO: sanity check the address | 192 | // TODO: sanity check the address |
192 | QString line; | 193 | QString line; |
193 | line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); | 194 | line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); |
194 | QSocketDevice s( QSocketDevice::Datagram ); | 195 | QSocketDevice s( QSocketDevice::Datagram ); |
195 | int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); | 196 | int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); |
196 | if ( result == -1 ) | 197 | if ( result == -1 ) |
197 | { | 198 | { |
198 | qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); | 199 | qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); |
199 | } | 200 | } |
200 | } | 201 | } |
201 | break; | 202 | break; |
202 | } | 203 | } |
203 | } | 204 | } |
204 | 205 | ||
205 | // check if we should abort | 206 | // check if we should abort |
206 | 207 | ||
207 | /* | 208 | /* |
208 | 209 | ||
209 | if( ( nLevel == ODEBUG_FATAL ) | 210 | if( ( nLevel == ODEBUG_FATAL ) |
210 | && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) | 211 | && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) |
211 | abort(); | 212 | abort(); |
212 | 213 | ||
213 | */ | 214 | */ |
214 | } | 215 | } |
215 | 216 | ||
216 | /*====================================================================================== | 217 | /*====================================================================================== |
217 | * odbgstream | 218 | * odbgstream |
218 | *======================================================================================*/ | 219 | *======================================================================================*/ |
219 | 220 | ||
220 | odbgstream& perror( odbgstream &s) | 221 | odbgstream& perror( odbgstream &s) |
221 | { | 222 | { |
222 | return s << QString::fromLocal8Bit(strerror(errno)); | 223 | return s << QString::fromLocal8Bit(strerror(errno)); |
223 | } | 224 | } |
224 | 225 | ||
225 | odbgstream odDebug(int area) | 226 | odbgstream odDebug(int area) |
226 | { | 227 | { |
227 | return odbgstream(area, ODEBUG_INFO); | 228 | return odbgstream(area, ODEBUG_INFO); |
228 | } | 229 | } |
229 | odbgstream odDebug(bool cond, int area) | 230 | odbgstream odDebug(bool cond, int area) |
230 | { | 231 | { |
231 | if (cond) return odbgstream(area, ODEBUG_INFO); | 232 | if (cond) return odbgstream(area, ODEBUG_INFO); |
232 | else return odbgstream(0, 0, false); | 233 | else return odbgstream(0, 0, false); |
233 | } | 234 | } |
234 | 235 | ||
235 | odbgstream odError(int area) | 236 | odbgstream odError(int area) |
236 | { | 237 | { |
237 | return odbgstream("ERROR: ", area, ODEBUG_ERROR); | 238 | return odbgstream("ERROR: ", area, ODEBUG_ERROR); |
238 | } | 239 | } |
239 | 240 | ||
240 | odbgstream odError(bool cond, int area) | 241 | odbgstream odError(bool cond, int area) |
241 | { | 242 | { |
242 | if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); | 243 | if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); |
243 | } | 244 | } |
244 | 245 | ||
245 | odbgstream odWarning(int area) | 246 | odbgstream odWarning(int area) |
246 | { | 247 | { |
247 | return odbgstream("WARNING: ", area, ODEBUG_WARN); | 248 | return odbgstream("WARNING: ", area, ODEBUG_WARN); |
248 | } | 249 | } |
249 | 250 | ||
250 | odbgstream odWarning(bool cond, int area) | 251 | odbgstream odWarning(bool cond, int area) |
251 | { | 252 | { |
252 | if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); | 253 | if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); |
253 | } | 254 | } |
254 | 255 | ||
255 | odbgstream odFatal(int area) | 256 | odbgstream odFatal(int area) |
256 | { | 257 | { |
257 | return odbgstream("FATAL: ", area, ODEBUG_FATAL); | 258 | return odbgstream("FATAL: ", area, ODEBUG_FATAL); |
258 | } | 259 | } |
259 | 260 | ||
260 | odbgstream odFatal(bool cond, int area) | 261 | odbgstream odFatal(bool cond, int area) |
@@ -425,196 +426,200 @@ odbgstream::~odbgstream() | |||
425 | if (!output.isEmpty()) | 426 | if (!output.isEmpty()) |
426 | { | 427 | { |
427 | fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); | 428 | fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); |
428 | *this << "\n"; | 429 | *this << "\n"; |
429 | } | 430 | } |
430 | } | 431 | } |
431 | 432 | ||
432 | odbgstream& odbgstream::operator<<(char ch) | 433 | odbgstream& odbgstream::operator<<(char ch) |
433 | { | 434 | { |
434 | if (!print) return *this; | 435 | if (!print) return *this; |
435 | if (!isprint(ch)) | 436 | if (!isprint(ch)) |
436 | { | 437 | { |
437 | output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); | 438 | output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); |
438 | } | 439 | } |
439 | else | 440 | else |
440 | { | 441 | { |
441 | output += ch; | 442 | output += ch; |
442 | if (ch == '\n') flush(); | 443 | if (ch == '\n') flush(); |
443 | } | 444 | } |
444 | return *this; | 445 | return *this; |
445 | } | 446 | } |
446 | 447 | ||
447 | odbgstream& odbgstream::operator<<( QWidget* widget ) | 448 | odbgstream& odbgstream::operator<<( QWidget* widget ) |
448 | { | 449 | { |
449 | QString string, temp; | 450 | QString string, temp; |
450 | // ----- | 451 | // ----- |
451 | if(widget==0) | 452 | if(widget==0) |
452 | { | 453 | { |
453 | string=(QString)"[Null pointer]"; | 454 | string=(QString)"[Null pointer]"; |
454 | } else | 455 | } else |
455 | { | 456 | { |
456 | temp.setNum((ulong)widget, 16); | 457 | temp.setNum((ulong)widget, 16); |
457 | string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; | 458 | string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; |
458 | if(widget->name(0)==0) | 459 | if(widget->name(0)==0) |
459 | { | 460 | { |
460 | string += " to unnamed widget, "; | 461 | string += " to unnamed widget, "; |
461 | } else | 462 | } else |
462 | { | 463 | { |
463 | string += (QString)" to widget " + widget->name() + ", "; | 464 | string += (QString)" to widget " + widget->name() + ", "; |
464 | } | 465 | } |
465 | string += "geometry=" | 466 | string += "geometry=" |
466 | + QString().setNum(widget->width()) | 467 | + QString().setNum(widget->width()) |
467 | + "x"+QString().setNum(widget->height()) | 468 | + "x"+QString().setNum(widget->height()) |
468 | + "+"+QString().setNum(widget->x()) | 469 | + "+"+QString().setNum(widget->x()) |
469 | + "+"+QString().setNum(widget->y()) | 470 | + "+"+QString().setNum(widget->y()) |
470 | + "]"; | 471 | + "]"; |
471 | } | 472 | } |
472 | if (!print) return *this; | 473 | if (!print) return *this; |
473 | 474 | ||
474 | output += string; | 475 | output += string; |
475 | if (output.at(output.length()-1) == '\n') | 476 | if (output.at(output.length()-1) == '\n') |
476 | { | 477 | { |
477 | flush(); | 478 | flush(); |
478 | } | 479 | } |
479 | return *this; | 480 | return *this; |
480 | } | 481 | } |
481 | 482 | ||
482 | /* | 483 | /* |
483 | * either use 'output' directly and do the flush if needed | 484 | * either use 'output' directly and do the flush if needed |
484 | * or use the QString operator which calls the char* operator | 485 | * or use the QString operator which calls the char* operator |
485 | * | 486 | * |
486 | */ | 487 | */ |
487 | odbgstream& odbgstream::operator<<( const QDateTime& time) | 488 | odbgstream& odbgstream::operator<<( const QDateTime& time) |
488 | { | 489 | { |
489 | *this << time.toString(); | 490 | *this << time.toString(); |
490 | return *this; | 491 | return *this; |
491 | } | 492 | } |
492 | 493 | ||
493 | 494 | ||
494 | odbgstream& odbgstream::operator<<( const QDate& date) | 495 | odbgstream& odbgstream::operator<<( const QDate& date) |
495 | { | 496 | { |
496 | *this << date.toString(); | 497 | *this << date.toString(); |
497 | 498 | ||
498 | return *this; | 499 | return *this; |
499 | } | 500 | } |
500 | 501 | ||
501 | 502 | ||
502 | odbgstream& odbgstream::operator<<( const QTime& time ) | 503 | odbgstream& odbgstream::operator<<( const QTime& time ) |
503 | { | 504 | { |
504 | *this << time.toString(); | 505 | *this << time.toString(); |
505 | return *this; | 506 | return *this; |
506 | } | 507 | } |
507 | 508 | ||
508 | 509 | ||
509 | odbgstream& odbgstream::operator<<( const QPoint& p ) | 510 | odbgstream& odbgstream::operator<<( const QPoint& p ) |
510 | { | 511 | { |
511 | *this << "(" << p.x() << ", " << p.y() << ")"; | 512 | *this << "(" << p.x() << ", " << p.y() << ")"; |
512 | return *this; | 513 | return *this; |
513 | } | 514 | } |
514 | 515 | ||
515 | 516 | ||
516 | odbgstream& odbgstream::operator<<( const QSize& s ) | 517 | odbgstream& odbgstream::operator<<( const QSize& s ) |
517 | { | 518 | { |
518 | *this << "[" << s.width() << "x" << s.height() << "]"; | 519 | *this << "[" << s.width() << "x" << s.height() << "]"; |
519 | return *this; | 520 | return *this; |
520 | } | 521 | } |
521 | 522 | ||
522 | 523 | ||
523 | odbgstream& odbgstream::operator<<( const QRect& r ) | 524 | odbgstream& odbgstream::operator<<( const QRect& r ) |
524 | { | 525 | { |
525 | *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; | 526 | *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; |
526 | return *this; | 527 | return *this; |
527 | } | 528 | } |
528 | 529 | ||
529 | 530 | ||
530 | odbgstream& odbgstream::operator<<( const QRegion& reg ) | 531 | odbgstream& odbgstream::operator<<( const QRegion& reg ) |
531 | { | 532 | { |
532 | /* Qt2 doesn't have a QMemArray... :( | 533 | /* Qt2 doesn't have a QMemArray... :( |
533 | *this << "[ "; | 534 | *this << "[ "; |
534 | QMemArray<QRect>rs=reg.rects(); | 535 | QMemArray<QRect>rs=reg.rects(); |
535 | for (uint i=0;i<rs.size();++i) | 536 | for (uint i=0;i<rs.size();++i) |
536 | *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; | 537 | *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; |
537 | *this <<"]"; | 538 | *this <<"]"; |
538 | */ | 539 | */ |
539 | return *this; | 540 | return *this; |
540 | } | 541 | } |
541 | 542 | ||
542 | 543 | ||
543 | odbgstream& odbgstream::operator<<( const QStringList& l ) | 544 | odbgstream& odbgstream::operator<<( const QStringList& l ) |
544 | { | 545 | { |
545 | *this << "("; | 546 | *this << "("; |
546 | *this << l.join(","); | 547 | *this << l.join(","); |
547 | *this << ")"; | 548 | *this << ")"; |
548 | 549 | ||
549 | return *this; | 550 | return *this; |
550 | } | 551 | } |
551 | 552 | ||
552 | 553 | ||
553 | odbgstream& odbgstream::operator<<( const QColor& c ) | 554 | odbgstream& odbgstream::operator<<( const QColor& c ) |
554 | { | 555 | { |
555 | if ( c.isValid() ) | 556 | if ( c.isValid() ) |
556 | *this << c.name(); | 557 | *this << c.name(); |
557 | else | 558 | else |
558 | *this << "(invalid/default)"; | 559 | *this << "(invalid/default)"; |
559 | return *this; | 560 | return *this; |
560 | } | 561 | } |
561 | 562 | ||
562 | 563 | ||
563 | odbgstream& odbgstream::operator<<( const QBrush& b) | 564 | odbgstream& odbgstream::operator<<( const QBrush& b) |
564 | { | 565 | { |
565 | static const char* const s_brushStyles[] = { | 566 | static const char* const s_brushStyles[] = { |
566 | "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", | 567 | "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", |
567 | "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", | 568 | "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", |
568 | "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", | 569 | "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", |
569 | "DiagCrossPattern" }; | 570 | "DiagCrossPattern" }; |
570 | 571 | ||
571 | *this <<"[ style: "; | 572 | *this <<"[ style: "; |
572 | *this <<s_brushStyles[ b.style() ]; | 573 | *this <<s_brushStyles[ b.style() ]; |
573 | *this <<" color: "; | 574 | *this <<" color: "; |
574 | // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) | 575 | // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) |
575 | if ( b.color().isValid() ) | 576 | if ( b.color().isValid() ) |
576 | *this <<b.color().name() ; | 577 | *this <<b.color().name() ; |
577 | else | 578 | else |
578 | *this <<"(invalid/default)"; | 579 | *this <<"(invalid/default)"; |
579 | if ( b.pixmap() ) | 580 | if ( b.pixmap() ) |
580 | *this <<" has a pixmap"; | 581 | *this <<" has a pixmap"; |
581 | *this <<" ]"; | 582 | *this <<" ]"; |
582 | return *this; | 583 | return *this; |
583 | } | 584 | } |
584 | 585 | ||
585 | 586 | ||
586 | 587 | ||
587 | QString odBacktrace( int levels ) | 588 | QString odBacktrace( int levels ) |
588 | { | 589 | { |
589 | QString s; | 590 | QString s; |
590 | #ifndef OPIE_NO_BACKTRACE | 591 | #ifndef OPIE_NO_BACKTRACE |
591 | void* trace[256]; | 592 | void* trace[256]; |
592 | int n = backtrace(trace, 256); | 593 | int n = backtrace(trace, 256); |
593 | char** strings = backtrace_symbols (trace, n); | 594 | char** strings = backtrace_symbols (trace, n); |
594 | 595 | ||
595 | if ( levels != -1 ) | 596 | if ( levels != -1 ) |
596 | n = QMIN( n, levels ); | 597 | n = QMIN( n, levels ); |
597 | s = "[\n"; | 598 | s = "[\n"; |
598 | 599 | ||
599 | for (int i = 0; i < n; ++i) | 600 | for (int i = 0; i < n; ++i) |
600 | s += QString::number(i) + | 601 | s += QString::number(i) + |
601 | QString::fromLatin1(": ") + | 602 | QString::fromLatin1(": ") + |
602 | QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); | 603 | QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); |
603 | s += "]\n"; | 604 | s += "]\n"; |
604 | free (strings); | 605 | free (strings); |
605 | #endif | 606 | #endif |
606 | return s; | 607 | return s; |
607 | } | 608 | } |
608 | 609 | ||
609 | void odClearDebugConfig() | 610 | void odClearDebugConfig() |
610 | { | 611 | { |
611 | /* | 612 | /* |
612 | delete oDebug_data->config; | 613 | delete oDebug_data->config; |
613 | oDebug_data->config = 0; | 614 | oDebug_data->config = 0; |
614 | */ | 615 | */ |
615 | } | 616 | } |
616 | 617 | ||
618 | |||
617 | #ifdef OPIE_NO_DEBUG | 619 | #ifdef OPIE_NO_DEBUG |
618 | #define odDebug ondDebug | 620 | #define odDebug ondDebug |
619 | #define odBacktrace ondBacktrace | 621 | #define odBacktrace ondBacktrace |
620 | #endif | 622 | #endif |
623 | |||
624 | } | ||
625 | } \ No newline at end of file | ||
diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h index 85941fd..a5c9ded 100644 --- a/libopie2/opiecore/odebug.h +++ b/libopie2/opiecore/odebug.h | |||
@@ -1,474 +1,483 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) | 3 | (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) |
4 | Inspired by the KDE debug classes, which are | 4 | Inspired by the KDE debug classes, which are |
5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) | 5 | (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) |
6 | (C) 2002 Holger Freyther (freyther@kde.org) | 6 | (C) 2002 Holger Freyther (freyther@kde.org) |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #ifndef ODEBUG_H | 33 | #ifndef ODEBUG_H |
34 | #define ODEBUG_H | 34 | #define ODEBUG_H |
35 | 35 | ||
36 | #include <qstring.h> | 36 | #include <qstring.h> |
37 | 37 | ||
38 | class QWidget; | 38 | class QWidget; |
39 | class QDateTime; | 39 | class QDateTime; |
40 | class QDate; | 40 | class QDate; |
41 | class QTime; | 41 | class QTime; |
42 | class QPoint; | 42 | class QPoint; |
43 | class QSize; | 43 | class QSize; |
44 | class QRect; | 44 | class QRect; |
45 | class QRegion; | 45 | class QRegion; |
46 | class QStringList; | 46 | class QStringList; |
47 | class QColor; | 47 | class QColor; |
48 | class QBrush; | 48 | class QBrush; |
49 | 49 | ||
50 | namespace Opie { | ||
51 | namespace Core { | ||
52 | |||
50 | class odbgstream; | 53 | class odbgstream; |
51 | class ondbgstream; | 54 | class ondbgstream; |
52 | 55 | ||
53 | #ifdef __GNUC__ | 56 | #ifdef __GNUC__ |
54 | #define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] " | 57 | #define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] " |
55 | #else | 58 | #else |
56 | #define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] " | 59 | #define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] " |
57 | #endif | 60 | #endif |
58 | 61 | ||
59 | #define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] " | 62 | #define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] " |
60 | 63 | ||
61 | #define owarn odWarning() | 64 | #define owarn odWarning() |
62 | #define oerr odError() | 65 | #define oerr odError() |
63 | #define odebug odDebug() | 66 | #define odebug odDebug() |
64 | #define ofatal odFatal() | 67 | #define ofatal odFatal() |
65 | #define oendl "\n" | 68 | #define oendl "\n" |
66 | 69 | ||
67 | class odbgstreamprivate; | 70 | class odbgstreamprivate; |
68 | /** | 71 | /** |
69 | * odbgstream is a text stream that allows you to print debug messages. | 72 | * odbgstream is a text stream that allows you to print debug messages. |
70 | * Using the overloaded "<<" operator you can send messages. Usually | 73 | * Using the overloaded "<<" operator you can send messages. Usually |
71 | * you do not create the odbgstream yourself, but use @ref odDebug() (odebug) | 74 | * you do not create the odbgstream yourself, but use @ref odDebug() (odebug) |
72 | * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one. | 75 | * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one. |
73 | * | 76 | * |
74 | * Example: | 77 | * Example: |
75 | * <pre> | 78 | * <pre> |
76 | * int i = 5; | 79 | * int i = 5; |
77 | * odebug << "The value of i is " << i << oendl; | 80 | * odebug << "The value of i is " << i << oendl; |
78 | * </pre> | 81 | * </pre> |
79 | * @see odbgstream | 82 | * @see odbgstream |
80 | */ | 83 | */ |
81 | 84 | ||
82 | /*====================================================================================== | 85 | /*====================================================================================== |
83 | * odbgstream | 86 | * odbgstream |
84 | *======================================================================================*/ | 87 | *======================================================================================*/ |
85 | 88 | ||
86 | class odbgstream | 89 | class odbgstream |
87 | { | 90 | { |
88 | public: | 91 | public: |
89 | /** | 92 | /** |
90 | * @internal | 93 | * @internal |
91 | */ | 94 | */ |
92 | odbgstream(unsigned int _area, unsigned int _level, bool _print = true); | 95 | odbgstream(unsigned int _area, unsigned int _level, bool _print = true); |
93 | odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true); | 96 | odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true); |
94 | odbgstream(odbgstream &str); | 97 | odbgstream(odbgstream &str); |
95 | odbgstream(const odbgstream &str); | 98 | odbgstream(const odbgstream &str); |
96 | virtual ~odbgstream(); | 99 | virtual ~odbgstream(); |
97 | 100 | ||
98 | /** | 101 | /** |
99 | * Prints the given value. | 102 | * Prints the given value. |
100 | * @param i the boolean to print (as "true" or "false") | 103 | * @param i the boolean to print (as "true" or "false") |
101 | * @return this stream | 104 | * @return this stream |
102 | */ | 105 | */ |
103 | odbgstream &operator<<(bool i); | 106 | odbgstream &operator<<(bool i); |
104 | /** | 107 | /** |
105 | * Prints the given value. | 108 | * Prints the given value. |
106 | * @param i the short to print | 109 | * @param i the short to print |
107 | * @return this stream | 110 | * @return this stream |
108 | */ | 111 | */ |
109 | odbgstream &operator<<(short i); | 112 | odbgstream &operator<<(short i); |
110 | /** | 113 | /** |
111 | * Prints the given value. | 114 | * Prints the given value. |
112 | * @param i the unsigned short to print | 115 | * @param i the unsigned short to print |
113 | * @return this stream | 116 | * @return this stream |
114 | */ | 117 | */ |
115 | odbgstream &operator<<(unsigned short i); | 118 | odbgstream &operator<<(unsigned short i); |
116 | /** | 119 | /** |
117 | * Prints the given value. | 120 | * Prints the given value. |
118 | * @param i the char to print | 121 | * @param i the char to print |
119 | * @return this stream | 122 | * @return this stream |
120 | */ | 123 | */ |
121 | odbgstream &operator<<(char i); | 124 | odbgstream &operator<<(char i); |
122 | /** | 125 | /** |
123 | * Prints the given value. | 126 | * Prints the given value. |
124 | * @param i the unsigned char to print | 127 | * @param i the unsigned char to print |
125 | * @return this stream | 128 | * @return this stream |
126 | */ | 129 | */ |
127 | odbgstream &operator<<(unsigned char i); | 130 | odbgstream &operator<<(unsigned char i); |
128 | /** | 131 | /** |
129 | * Prints the given value. | 132 | * Prints the given value. |
130 | * @param i the int to print | 133 | * @param i the int to print |
131 | * @return this stream | 134 | * @return this stream |
132 | */ | 135 | */ |
133 | odbgstream &operator<<(int i); | 136 | odbgstream &operator<<(int i); |
134 | /** | 137 | /** |
135 | * Prints the given value. | 138 | * Prints the given value. |
136 | * @param i the unsigned int to print | 139 | * @param i the unsigned int to print |
137 | * @return this stream | 140 | * @return this stream |
138 | */ | 141 | */ |
139 | odbgstream &operator<<(unsigned int i); | 142 | odbgstream &operator<<(unsigned int i); |
140 | /** | 143 | /** |
141 | * Prints the given value. | 144 | * Prints the given value. |
142 | * @param i the long to print | 145 | * @param i the long to print |
143 | * @return this stream | 146 | * @return this stream |
144 | */ | 147 | */ |
145 | odbgstream &operator<<(long i); | 148 | odbgstream &operator<<(long i); |
146 | /** | 149 | /** |
147 | * Prints the given value. | 150 | * Prints the given value. |
148 | * @param i the unsigned long to print | 151 | * @param i the unsigned long to print |
149 | * @return this stream | 152 | * @return this stream |
150 | */ | 153 | */ |
151 | odbgstream &operator<<(unsigned long i); | 154 | odbgstream &operator<<(unsigned long i); |
152 | /** | 155 | /** |
153 | * Flushes the output. | 156 | * Flushes the output. |
154 | */ | 157 | */ |
155 | virtual void flush(); | 158 | virtual void flush(); |
156 | /** | 159 | /** |
157 | * Prints the given value. | 160 | * Prints the given value. |
158 | * @param string the string to print | 161 | * @param string the string to print |
159 | * @return this stream | 162 | * @return this stream |
160 | */ | 163 | */ |
161 | odbgstream &operator<<(const QString& string); | 164 | odbgstream &operator<<(const QString& string); |
162 | /** | 165 | /** |
163 | * Prints the given value. | 166 | * Prints the given value. |
164 | * @param string the string to print | 167 | * @param string the string to print |
165 | * @return this stream | 168 | * @return this stream |
166 | */ | 169 | */ |
167 | odbgstream &operator<<(const char *string); | 170 | odbgstream &operator<<(const char *string); |
168 | /** | 171 | /** |
169 | * Prints the given value. | 172 | * Prints the given value. |
170 | * @param string the string to print | 173 | * @param string the string to print |
171 | * @return this stream | 174 | * @return this stream |
172 | */ | 175 | */ |
173 | odbgstream &operator<<(const QCString& string); | 176 | odbgstream &operator<<(const QCString& string); |
174 | /** | 177 | /** |
175 | * Prints the given value. | 178 | * Prints the given value. |
176 | * @param p a pointer to print (in number form) | 179 | * @param p a pointer to print (in number form) |
177 | * @return this stream | 180 | * @return this stream |
178 | */ | 181 | */ |
179 | odbgstream& operator<<(const void * p); | 182 | odbgstream& operator<<(const void * p); |
180 | /** | 183 | /** |
181 | * Prints the given value. | 184 | * Prints the given value. |
182 | * @param d the double to print | 185 | * @param d the double to print |
183 | * @return this stream | 186 | * @return this stream |
184 | */ | 187 | */ |
185 | odbgstream& operator<<(double d); | 188 | odbgstream& operator<<(double d); |
186 | /** | 189 | /** |
187 | * Prints the string @p format which can contain | 190 | * Prints the string @p format which can contain |
188 | * printf-style formatted values. | 191 | * printf-style formatted values. |
189 | * @param format the printf-style format | 192 | * @param format the printf-style format |
190 | * @return this stream | 193 | * @return this stream |
191 | */ | 194 | */ |
192 | odbgstream &form(const char *format, ...); | 195 | odbgstream &form(const char *format, ...); |
193 | /** Operator to print out basic information about a QWidget. | 196 | /** Operator to print out basic information about a QWidget. |
194 | * Output of class names only works if the class is moc'ified. | 197 | * Output of class names only works if the class is moc'ified. |
195 | * @param widget the widget to print | 198 | * @param widget the widget to print |
196 | * @return this stream | 199 | * @return this stream |
197 | */ | 200 | */ |
198 | odbgstream& operator<< (QWidget* widget); | 201 | odbgstream& operator<< (QWidget* widget); |
199 | 202 | ||
200 | /** | 203 | /** |
201 | * Prints the given value. | 204 | * Prints the given value. |
202 | * @param dateTime the datetime to print | 205 | * @param dateTime the datetime to print |
203 | * @return this stream | 206 | * @return this stream |
204 | */ | 207 | */ |
205 | odbgstream& operator<< ( const QDateTime& dateTime ); | 208 | odbgstream& operator<< ( const QDateTime& dateTime ); |
206 | 209 | ||
207 | /** | 210 | /** |
208 | * Prints the given value. | 211 | * Prints the given value. |
209 | * @param date the date to print | 212 | * @param date the date to print |
210 | * @return this stream | 213 | * @return this stream |
211 | */ | 214 | */ |
212 | odbgstream& operator<< ( const QDate& date ); | 215 | odbgstream& operator<< ( const QDate& date ); |
213 | 216 | ||
214 | /** | 217 | /** |
215 | * Prints the given value. | 218 | * Prints the given value. |
216 | * @param time the time to print | 219 | * @param time the time to print |
217 | * @return this stream | 220 | * @return this stream |
218 | */ | 221 | */ |
219 | odbgstream& operator<< ( const QTime& time ); | 222 | odbgstream& operator<< ( const QTime& time ); |
220 | 223 | ||
221 | /** | 224 | /** |
222 | * Prints the given value. | 225 | * Prints the given value. |
223 | * @param point the point to print | 226 | * @param point the point to print |
224 | * @return this stream | 227 | * @return this stream |
225 | */ | 228 | */ |
226 | odbgstream& operator<< ( const QPoint& point ); | 229 | odbgstream& operator<< ( const QPoint& point ); |
227 | 230 | ||
228 | /** | 231 | /** |
229 | * Prints the given value. | 232 | * Prints the given value. |
230 | * @param size the QSize to print | 233 | * @param size the QSize to print |
231 | * @return this stream | 234 | * @return this stream |
232 | */ | 235 | */ |
233 | odbgstream& operator<< ( const QSize& size ); | 236 | odbgstream& operator<< ( const QSize& size ); |
234 | 237 | ||
235 | /** | 238 | /** |
236 | * Prints the given value. | 239 | * Prints the given value. |
237 | * @param rect the QRect to print | 240 | * @param rect the QRect to print |
238 | * @return this stream | 241 | * @return this stream |
239 | */ | 242 | */ |
240 | odbgstream& operator<< ( const QRect& rect); | 243 | odbgstream& operator<< ( const QRect& rect); |
241 | 244 | ||
242 | /** | 245 | /** |
243 | * Prints the given value. | 246 | * Prints the given value. |
244 | * @param region the QRegion to print | 247 | * @param region the QRegion to print |
245 | * @return this stream | 248 | * @return this stream |
246 | */ | 249 | */ |
247 | odbgstream& operator<< ( const QRegion& region); | 250 | odbgstream& operator<< ( const QRegion& region); |
248 | 251 | ||
249 | /** | 252 | /** |
250 | * Prints the given value. | 253 | * Prints the given value. |
251 | * @param list the stringlist to print | 254 | * @param list the stringlist to print |
252 | * @return this stream | 255 | * @return this stream |
253 | */ | 256 | */ |
254 | odbgstream& operator<< ( const QStringList& list); | 257 | odbgstream& operator<< ( const QStringList& list); |
255 | 258 | ||
256 | /** | 259 | /** |
257 | * Prints the given value. | 260 | * Prints the given value. |
258 | * @param color the color to print | 261 | * @param color the color to print |
259 | * @return this stream | 262 | * @return this stream |
260 | */ | 263 | */ |
261 | odbgstream& operator<< ( const QColor& color); | 264 | odbgstream& operator<< ( const QColor& color); |
262 | 265 | ||
263 | /** | 266 | /** |
264 | * Prints the given value. | 267 | * Prints the given value. |
265 | * @param brush the brush to print | 268 | * @param brush the brush to print |
266 | * @return this stream | 269 | * @return this stream |
267 | */ | 270 | */ |
268 | odbgstream& operator<< ( const QBrush& brush ); | 271 | odbgstream& operator<< ( const QBrush& brush ); |
269 | 272 | ||
270 | private: | 273 | private: |
271 | QString output; | 274 | QString output; |
272 | unsigned int area, level; | 275 | unsigned int area, level; |
273 | bool print; | 276 | bool print; |
274 | odbgstreamprivate* d; | 277 | odbgstreamprivate* d; |
275 | }; | 278 | }; |
276 | 279 | ||
277 | /** | 280 | /** |
278 | * Prints an "\n". | 281 | * Prints an "\n". |
279 | * @param s the debug stream to write to | 282 | * @param s the debug stream to write to |
280 | * @return the debug stream (@p s) | 283 | * @return the debug stream (@p s) |
281 | */ | 284 | */ |
282 | inline odbgstream& endl( odbgstream &s) { s << "\n"; return s; } | 285 | inline odbgstream& endl( odbgstream &s) { s << "\n"; return s; } |
283 | /** | 286 | /** |
284 | * Flushes the stream. | 287 | * Flushes the stream. |
285 | * @param s the debug stream to write to | 288 | * @param s the debug stream to write to |
286 | * @return the debug stream (@p s) | 289 | * @return the debug stream (@p s) |
287 | */ | 290 | */ |
288 | inline odbgstream& flush( odbgstream &s) { s.flush(); return s; } | 291 | inline odbgstream& flush( odbgstream &s) { s.flush(); return s; } |
289 | 292 | ||
290 | odbgstream &perror( odbgstream &s); | 293 | odbgstream &perror( odbgstream &s); |
291 | 294 | ||
292 | /** | 295 | /** |
293 | * ondbgstream is a dummy variant of @ref odbgstream. All functions do | 296 | * ondbgstream is a dummy variant of @ref odbgstream. All functions do |
294 | * nothing. | 297 | * nothing. |
295 | * @see ondDebug() | 298 | * @see ondDebug() |
296 | */ | 299 | */ |
297 | class ondbgstream { | 300 | class ondbgstream { |
298 | public: | 301 | public: |
299 | /// Empty constructor. | 302 | /// Empty constructor. |
300 | ondbgstream() {} | 303 | ondbgstream() {} |
301 | ~ondbgstream() {} | 304 | ~ondbgstream() {} |
302 | /** | 305 | /** |
303 | * Does nothing. | 306 | * Does nothing. |
304 | * @return this stream | 307 | * @return this stream |
305 | */ | 308 | */ |
306 | ondbgstream &operator<<(short int ) { return *this; } | 309 | ondbgstream &operator<<(short int ) { return *this; } |
307 | /** | 310 | /** |
308 | * Does nothing. | 311 | * Does nothing. |
309 | * @return this stream | 312 | * @return this stream |
310 | */ | 313 | */ |
311 | ondbgstream &operator<<(unsigned short int ) { return *this; } | 314 | ondbgstream &operator<<(unsigned short int ) { return *this; } |
312 | /** | 315 | /** |
313 | * Does nothing. | 316 | * Does nothing. |
314 | * @return this stream | 317 | * @return this stream |
315 | */ | 318 | */ |
316 | ondbgstream &operator<<(char ) { return *this; } | 319 | ondbgstream &operator<<(char ) { return *this; } |
317 | /** | 320 | /** |
318 | * Does nothing. | 321 | * Does nothing. |
319 | * @return this stream | 322 | * @return this stream |
320 | */ | 323 | */ |
321 | ondbgstream &operator<<(unsigned char ) { return *this; } | 324 | ondbgstream &operator<<(unsigned char ) { return *this; } |
322 | /** | 325 | /** |
323 | * Does nothing. | 326 | * Does nothing. |
324 | * @return this stream | 327 | * @return this stream |
325 | */ | 328 | */ |
326 | ondbgstream &operator<<(int ) { return *this; } | 329 | ondbgstream &operator<<(int ) { return *this; } |
327 | /** | 330 | /** |
328 | * Does nothing. | 331 | * Does nothing. |
329 | * @return this stream | 332 | * @return this stream |
330 | */ | 333 | */ |
331 | ondbgstream &operator<<(unsigned int ) { return *this; } | 334 | ondbgstream &operator<<(unsigned int ) { return *this; } |
332 | /** | 335 | /** |
333 | * Does nothing. | 336 | * Does nothing. |
334 | */ | 337 | */ |
335 | void flush() {} | 338 | void flush() {} |
336 | /** | 339 | /** |
337 | * Does nothing. | 340 | * Does nothing. |
338 | * @return this stream | 341 | * @return this stream |
339 | */ | 342 | */ |
340 | ondbgstream &operator<<(const QString& ) { return *this; } | 343 | ondbgstream &operator<<(const QString& ) { return *this; } |
341 | /** | 344 | /** |
342 | * Does nothing. | 345 | * Does nothing. |
343 | * @return this stream | 346 | * @return this stream |
344 | */ | 347 | */ |
345 | ondbgstream &operator<<(const QCString& ) { return *this; } | 348 | ondbgstream &operator<<(const QCString& ) { return *this; } |
346 | /** | 349 | /** |
347 | * Does nothing. | 350 | * Does nothing. |
348 | * @return this stream | 351 | * @return this stream |
349 | */ | 352 | */ |
350 | ondbgstream &operator<<(const char *) { return *this; } | 353 | ondbgstream &operator<<(const char *) { return *this; } |
351 | /** | 354 | /** |
352 | * Does nothing. | 355 | * Does nothing. |
353 | * @return this stream | 356 | * @return this stream |
354 | */ | 357 | */ |
355 | ondbgstream& operator<<(const void *) { return *this; } | 358 | ondbgstream& operator<<(const void *) { return *this; } |
356 | /** | 359 | /** |
357 | * Does nothing. | 360 | * Does nothing. |
358 | * @return this stream | 361 | * @return this stream |
359 | */ | 362 | */ |
360 | ondbgstream& operator<<(void *) { return *this; } | 363 | ondbgstream& operator<<(void *) { return *this; } |
361 | /** | 364 | /** |
362 | * Does nothing. | 365 | * Does nothing. |
363 | * @return this stream | 366 | * @return this stream |
364 | */ | 367 | */ |
365 | ondbgstream& operator<<(double) { return *this; } | 368 | ondbgstream& operator<<(double) { return *this; } |
366 | /** | 369 | /** |
367 | * Does nothing. | 370 | * Does nothing. |
368 | * @return this stream | 371 | * @return this stream |
369 | */ | 372 | */ |
370 | ondbgstream& operator<<(long) { return *this; } | 373 | ondbgstream& operator<<(long) { return *this; } |
371 | /** | 374 | /** |
372 | * Does nothing. | 375 | * Does nothing. |
373 | * @return this stream | 376 | * @return this stream |
374 | */ | 377 | */ |
375 | ondbgstream& operator<<(unsigned long) { return *this; } | 378 | ondbgstream& operator<<(unsigned long) { return *this; } |
376 | /** | 379 | /** |
377 | * Does nothing. | 380 | * Does nothing. |
378 | * @return this stream | 381 | * @return this stream |
379 | */ | 382 | */ |
380 | ondbgstream& operator << (QWidget*) { return *this; } | 383 | ondbgstream& operator << (QWidget*) { return *this; } |
381 | /** | 384 | /** |
382 | * Does nothing. | 385 | * Does nothing. |
383 | * @return this stream | 386 | * @return this stream |
384 | */ | 387 | */ |
385 | ondbgstream &form(const char *, ...) { return *this; } | 388 | ondbgstream &form(const char *, ...) { return *this; } |
386 | 389 | ||
387 | ondbgstream& operator<<( const QDateTime& ) { return *this; } | 390 | ondbgstream& operator<<( const QDateTime& ) { return *this; } |
388 | ondbgstream& operator<<( const QDate& ) { return *this; } | 391 | ondbgstream& operator<<( const QDate& ) { return *this; } |
389 | ondbgstream& operator<<( const QTime& ) { return *this; } | 392 | ondbgstream& operator<<( const QTime& ) { return *this; } |
390 | ondbgstream& operator<<( const QPoint & ) { return *this; } | 393 | ondbgstream& operator<<( const QPoint & ) { return *this; } |
391 | ondbgstream& operator<<( const QSize & ) { return *this; } | 394 | ondbgstream& operator<<( const QSize & ) { return *this; } |
392 | ondbgstream& operator<<( const QRect & ) { return *this; } | 395 | ondbgstream& operator<<( const QRect & ) { return *this; } |
393 | ondbgstream& operator<<( const QRegion & ) { return *this; } | 396 | ondbgstream& operator<<( const QRegion & ) { return *this; } |
394 | ondbgstream& operator<<( const QStringList & ) { return *this; } | 397 | ondbgstream& operator<<( const QStringList & ) { return *this; } |
395 | ondbgstream& operator<<( const QColor & ) { return *this; } | 398 | ondbgstream& operator<<( const QColor & ) { return *this; } |
396 | ondbgstream& operator<<( const QBrush & ) { return *this; } | 399 | ondbgstream& operator<<( const QBrush & ) { return *this; } |
400 | |||
401 | private: | ||
402 | class Private; | ||
403 | Private *d; | ||
397 | }; | 404 | }; |
398 | 405 | ||
399 | /*====================================================================================== | 406 | /*====================================================================================== |
400 | * related functions | 407 | * related functions |
401 | *======================================================================================*/ | 408 | *======================================================================================*/ |
402 | 409 | ||
403 | /** | 410 | /** |
404 | * Does nothing. | 411 | * Does nothing. |
405 | * @param a stream | 412 | * @param a stream |
406 | * @return the given @p s | 413 | * @return the given @p s |
407 | */ | 414 | */ |
408 | inline ondbgstream& endl( ondbgstream & s) { return s; } | 415 | inline ondbgstream& endl( ondbgstream & s) { return s; } |
409 | /** | 416 | /** |
410 | * Does nothing. | 417 | * Does nothing. |
411 | * @param a stream | 418 | * @param a stream |
412 | * @return the given @p s | 419 | * @return the given @p s |
413 | */ | 420 | */ |
414 | inline ondbgstream& flush( ondbgstream & s) { return s; } | 421 | inline ondbgstream& flush( ondbgstream & s) { return s; } |
415 | inline ondbgstream& perror( ondbgstream & s) { return s; } | 422 | inline ondbgstream& perror( ondbgstream & s) { return s; } |
416 | 423 | ||
417 | /** | 424 | /** |
418 | * Returns a debug stream. You can use it to print debug | 425 | * Returns a debug stream. You can use it to print debug |
419 | * information. | 426 | * information. |
420 | * @param area an id to identify the output, 0 for default | 427 | * @param area an id to identify the output, 0 for default |
421 | */ | 428 | */ |
422 | odbgstream odDebug(int area = 0); | 429 | odbgstream odDebug(int area = 0); |
423 | odbgstream odDebug(bool cond, int area = 0); | 430 | odbgstream odDebug(bool cond, int area = 0); |
424 | /** | 431 | /** |
425 | * Returns a backtrace. | 432 | * Returns a backtrace. |
426 | * @param levels the number of levels (-1 for unlimited) of the backtrace | 433 | * @param levels the number of levels (-1 for unlimited) of the backtrace |
427 | * @return a backtrace | 434 | * @return a backtrace |
428 | */ | 435 | */ |
429 | QString odBacktrace(int levels = -1); | 436 | QString odBacktrace(int levels = -1); |
430 | /** | 437 | /** |
431 | * Returns a dummy debug stream. The stream does not print anything. | 438 | * Returns a dummy debug stream. The stream does not print anything. |
432 | * @param area an id to identify the output, 0 for default | 439 | * @param area an id to identify the output, 0 for default |
433 | * @see odDebug() | 440 | * @see odDebug() |
434 | */ | 441 | */ |
435 | inline ondbgstream ondDebug(int = 0) { return ondbgstream(); } | 442 | inline ondbgstream ondDebug(int = 0) { return ondbgstream(); } |
436 | inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); } | 443 | inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); } |
437 | inline QString ondBacktrace() { return QString::null; } | 444 | inline QString ondBacktrace() { return QString::null; } |
438 | inline QString ondBacktrace(int) { return QString::null; } | 445 | inline QString ondBacktrace(int) { return QString::null; } |
439 | 446 | ||
440 | /** | 447 | /** |
441 | * Returns a warning stream. You can use it to print warning | 448 | * Returns a warning stream. You can use it to print warning |
442 | * information. | 449 | * information. |
443 | * @param area an id to identify the output, 0 for default | 450 | * @param area an id to identify the output, 0 for default |
444 | */ | 451 | */ |
445 | odbgstream odWarning(int area = 0); | 452 | odbgstream odWarning(int area = 0); |
446 | odbgstream odWarning(bool cond, int area = 0); | 453 | odbgstream odWarning(bool cond, int area = 0); |
447 | /** | 454 | /** |
448 | * Returns an error stream. You can use it to print error | 455 | * Returns an error stream. You can use it to print error |
449 | * information. | 456 | * information. |
450 | * @param area an id to identify the output, 0 for default | 457 | * @param area an id to identify the output, 0 for default |
451 | */ | 458 | */ |
452 | odbgstream odError(int area = 0); | 459 | odbgstream odError(int area = 0); |
453 | odbgstream odError(bool cond, int area = 0); | 460 | odbgstream odError(bool cond, int area = 0); |
454 | /** | 461 | /** |
455 | * Returns a fatal error stream. You can use it to print fatal error | 462 | * Returns a fatal error stream. You can use it to print fatal error |
456 | * information. | 463 | * information. |
457 | * @param area an id to identify the output, 0 for default | 464 | * @param area an id to identify the output, 0 for default |
458 | */ | 465 | */ |
459 | odbgstream odFatal(int area = 0); | 466 | odbgstream odFatal(int area = 0); |
460 | odbgstream odFatal(bool cond, int area = 0); | 467 | odbgstream odFatal(bool cond, int area = 0); |
461 | 468 | ||
462 | /** | 469 | /** |
463 | * Deletes the odebugrc cache and therefore forces KDebug to reread the | 470 | * Deletes the odebugrc cache and therefore forces KDebug to reread the |
464 | * config file | 471 | * config file |
465 | */ | 472 | */ |
466 | void odClearDebugConfig(); | 473 | void odClearDebugConfig(); |
467 | 474 | ||
468 | #ifdef OPIE_NO_DEBUG | 475 | #ifdef OPIE_NO_DEBUG |
469 | #define odDebug ondDebug | 476 | #define odDebug ondDebug |
470 | #define odBacktrace ondBacktrace | 477 | #define odBacktrace ondBacktrace |
471 | #endif | 478 | #endif |
472 | 479 | ||
473 | #endif | 480 | #endif |
474 | 481 | ||
482 | } | ||
483 | } | ||
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index 1aa206e..ea02058 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp | |||
@@ -1,410 +1,412 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oglobal.h> | 30 | #include <opie2/oglobal.h> |
31 | 31 | ||
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qdir.h> | 33 | #include <qdir.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/storage.h> | 36 | #include <qpe/storage.h> |
37 | 37 | ||
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <sys/types.h> | 39 | #include <sys/types.h> |
40 | 40 | ||
41 | using namespace Opie::Core; | ||
42 | |||
41 | static const char Base64EncMap[64] = | 43 | static const char Base64EncMap[64] = |
42 | { | 44 | { |
43 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | 45 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
44 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, | 46 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, |
45 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | 47 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
46 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, | 48 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, |
47 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, | 49 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, |
48 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, | 50 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, |
49 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, | 51 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, |
50 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F | 52 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F |
51 | }; | 53 | }; |
52 | 54 | ||
53 | static char Base64DecMap[128] = | 55 | static char Base64DecMap[128] = |
54 | { | 56 | { |
55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
60 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, | 62 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, |
61 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, | 63 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, |
62 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 64 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
63 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, | 65 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
64 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, | 66 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, |
65 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | 67 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, |
66 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, | 68 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, |
67 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, | 69 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, |
68 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | 70 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
69 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, | 71 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, |
70 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 | 72 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 |
71 | }; | 73 | }; |
72 | 74 | ||
73 | 75 | ||
74 | OConfig* OGlobal::_config = 0; | 76 | OConfig* OGlobal::_config = 0; |
75 | OConfig* OGlobal::_qpe_config = 0; | 77 | OConfig* OGlobal::_qpe_config = 0; |
76 | 78 | ||
77 | OConfig* OGlobal::config() | 79 | OConfig* OGlobal::config() |
78 | { | 80 | { |
79 | if ( !OGlobal::_config ) | 81 | if ( !OGlobal::_config ) |
80 | { | 82 | { |
81 | // odebug classes are reading config, so can't use them here! | 83 | // odebug classes are reading config, so can't use them here! |
82 | qDebug( "OGlobal::creating global configuration instance." ); | 84 | qDebug( "OGlobal::creating global configuration instance." ); |
83 | OGlobal::_config = new OConfig( "global" ); | 85 | OGlobal::_config = new OConfig( "global" ); |
84 | } | 86 | } |
85 | return OGlobal::_config; | 87 | return OGlobal::_config; |
86 | } | 88 | } |
87 | 89 | ||
88 | 90 | ||
89 | /** | 91 | /** |
90 | * Return the internal builtin Global::Command object | 92 | * Return the internal builtin Global::Command object |
91 | * | 93 | * |
92 | */ | 94 | */ |
93 | Global::Command* OGlobal::builtinCommands() { | 95 | Global::Command* OGlobal::builtinCommands() { |
94 | return builtin; | 96 | return builtin; |
95 | } | 97 | } |
96 | 98 | ||
97 | 99 | ||
98 | /** | 100 | /** |
99 | * Return the internal builtin QGuardedPtr<QWidget> object | 101 | * Return the internal builtin QGuardedPtr<QWidget> object |
100 | */ | 102 | */ |
101 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { | 103 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { |
102 | return running; | 104 | return running; |
103 | } | 105 | } |
104 | 106 | ||
105 | 107 | ||
106 | /** | 108 | /** |
107 | * \brief generate a new UUID as QString | 109 | * \brief generate a new UUID as QString |
108 | * Return a new UUID as QString. UUID are global unique | 110 | * Return a new UUID as QString. UUID are global unique |
109 | * | 111 | * |
110 | * | 112 | * |
111 | * @return the UUID or QString::null | 113 | * @return the UUID or QString::null |
112 | */ | 114 | */ |
113 | QString OGlobal::generateUuid() { | 115 | QString OGlobal::generateUuid() { |
114 | QFile file( "/proc/sys/kernel/random/uuid" ); | 116 | QFile file( "/proc/sys/kernel/random/uuid" ); |
115 | if (!file.open(IO_ReadOnly ) ) | 117 | if (!file.open(IO_ReadOnly ) ) |
116 | return QString::null; | 118 | return QString::null; |
117 | 119 | ||
118 | QTextStream stream(&file); | 120 | QTextStream stream(&file); |
119 | 121 | ||
120 | return "{" + stream.read().stripWhiteSpace() + "}"; | 122 | return "{" + stream.read().stripWhiteSpace() + "}"; |
121 | } | 123 | } |
122 | 124 | ||
123 | 125 | ||
124 | /** | 126 | /** |
125 | * \brief Encode a QByteArray in base64 | 127 | * \brief Encode a QByteArray in base64 |
126 | * | 128 | * |
127 | * An Implementation of the RF1521 base64 encoding. | 129 | * An Implementation of the RF1521 base64 encoding. |
128 | * | 130 | * |
129 | * The boolean argument determines if the encoded data is | 131 | * The boolean argument determines if the encoded data is |
130 | * going to be restricted to 76 characters or less per line | 132 | * going to be restricted to 76 characters or less per line |
131 | * as specified by RFC 2045. If @p insertLFs is true, then | 133 | * as specified by RFC 2045. If @p insertLFs is true, then |
132 | * there will be 76 characters or less per line. | 134 | * there will be 76 characters or less per line. |
133 | * | 135 | * |
134 | * If you use this to create a QCString remember that it is null terminated! | 136 | * If you use this to create a QCString remember that it is null terminated! |
135 | * \code | 137 | * \code |
136 | * QByteArray ar = OGlobal::encodeBase64(&array); | 138 | * QByteArray ar = OGlobal::encodeBase64(&array); |
137 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end | 139 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end |
138 | * | 140 | * |
139 | * \endcode | 141 | * \endcode |
140 | * | 142 | * |
141 | * @param in The QByteArray to encode | 143 | * @param in The QByteArray to encode |
142 | * @param insertLFs Limit number of characters per line | 144 | * @param insertLFs Limit number of characters per line |
143 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() | 145 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() |
144 | * @see QByteArray | 146 | * @see QByteArray |
145 | * @see QArray | 147 | * @see QArray |
146 | * @see QMemArray | 148 | * @see QMemArray |
147 | * @see QCString | 149 | * @see QCString |
148 | */ | 150 | */ |
149 | /* | 151 | /* |
150 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp | 152 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp |
151 | */ | 153 | */ |
152 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { | 154 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { |
153 | if ( in.isEmpty() ) | 155 | if ( in.isEmpty() ) |
154 | return QByteArray(); | 156 | return QByteArray(); |
155 | 157 | ||
156 | unsigned int sidx = 0; | 158 | unsigned int sidx = 0; |
157 | unsigned int didx = 0; | 159 | unsigned int didx = 0; |
158 | const char* data = in.data(); | 160 | const char* data = in.data(); |
159 | const unsigned int len = in.size(); | 161 | const unsigned int len = in.size(); |
160 | 162 | ||
161 | unsigned int out_len = ((len+2)/3)*4; | 163 | unsigned int out_len = ((len+2)/3)*4; |
162 | 164 | ||
163 | // Deal with the 76 characters or less per | 165 | // Deal with the 76 characters or less per |
164 | // line limit specified in RFC 2045 on a | 166 | // line limit specified in RFC 2045 on a |
165 | // pre request basis. | 167 | // pre request basis. |
166 | insertLFs = (insertLFs && out_len > 76); | 168 | insertLFs = (insertLFs && out_len > 76); |
167 | if ( insertLFs ) | 169 | if ( insertLFs ) |
168 | out_len += ((out_len-1)/76); | 170 | out_len += ((out_len-1)/76); |
169 | 171 | ||
170 | int count = 0; | 172 | int count = 0; |
171 | QByteArray out( out_len ); | 173 | QByteArray out( out_len ); |
172 | 174 | ||
173 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 175 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
174 | if ( len > 1 ) | 176 | if ( len > 1 ) |
175 | { | 177 | { |
176 | while (sidx < len-2) | 178 | while (sidx < len-2) |
177 | { | 179 | { |
178 | if ( insertLFs ) | 180 | if ( insertLFs ) |
179 | { | 181 | { |
180 | if ( count && (count%76) == 0 ) | 182 | if ( count && (count%76) == 0 ) |
181 | out[didx++] = '\n'; | 183 | out[didx++] = '\n'; |
182 | count += 4; | 184 | count += 4; |
183 | } | 185 | } |
184 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 186 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
185 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 187 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
186 | (data[sidx] << 4) & 077]; | 188 | (data[sidx] << 4) & 077]; |
187 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | | 189 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | |
188 | (data[sidx+1] << 2) & 077]; | 190 | (data[sidx+1] << 2) & 077]; |
189 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; | 191 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; |
190 | sidx += 3; | 192 | sidx += 3; |
191 | } | 193 | } |
192 | } | 194 | } |
193 | 195 | ||
194 | if (sidx < len) | 196 | if (sidx < len) |
195 | { | 197 | { |
196 | if ( insertLFs && (count > 0) && (count%76) == 0 ) | 198 | if ( insertLFs && (count > 0) && (count%76) == 0 ) |
197 | out[didx++] = '\n'; | 199 | out[didx++] = '\n'; |
198 | 200 | ||
199 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 201 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
200 | if (sidx < len-1) | 202 | if (sidx < len-1) |
201 | { | 203 | { |
202 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 204 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
203 | (data[sidx] << 4) & 077]; | 205 | (data[sidx] << 4) & 077]; |
204 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; | 206 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; |
205 | } | 207 | } |
206 | else | 208 | else |
207 | { | 209 | { |
208 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; | 210 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; |
209 | } | 211 | } |
210 | } | 212 | } |
211 | 213 | ||
212 | // Add padding | 214 | // Add padding |
213 | while (didx < out.size()) | 215 | while (didx < out.size()) |
214 | { | 216 | { |
215 | out[didx] = '='; | 217 | out[didx] = '='; |
216 | didx++; | 218 | didx++; |
217 | } | 219 | } |
218 | 220 | ||
219 | return out; | 221 | return out; |
220 | } | 222 | } |
221 | 223 | ||
222 | /** | 224 | /** |
223 | * Decodes the given data that was encoded with the base64 | 225 | * Decodes the given data that was encoded with the base64 |
224 | * algorithm. | 226 | * algorithm. |
225 | * | 227 | * |
226 | * | 228 | * |
227 | * @param in the encoded data to be decoded. | 229 | * @param in the encoded data to be decoded. |
228 | * @return the decoded QByteArray or QByteArray() in case of failure | 230 | * @return the decoded QByteArray or QByteArray() in case of failure |
229 | * @see OGlobal::encodeBase64 | 231 | * @see OGlobal::encodeBase64 |
230 | */ | 232 | */ |
231 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { | 233 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { |
232 | if ( in.isEmpty() ) | 234 | if ( in.isEmpty() ) |
233 | return QByteArray(); | 235 | return QByteArray(); |
234 | 236 | ||
235 | QByteArray out; | 237 | QByteArray out; |
236 | unsigned int count = 0; | 238 | unsigned int count = 0; |
237 | unsigned int len = in.size(), tail = len; | 239 | unsigned int len = in.size(), tail = len; |
238 | const char* data = in.data(); | 240 | const char* data = in.data(); |
239 | 241 | ||
240 | // Deal with possible *nix "BEGIN" marker!! | 242 | // Deal with possible *nix "BEGIN" marker!! |
241 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || | 243 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || |
242 | data[count] == '\t' || data[count] == ' ') ) | 244 | data[count] == '\t' || data[count] == ' ') ) |
243 | count++; | 245 | count++; |
244 | 246 | ||
245 | if ( strncasecmp(data+count, "begin", 5) == 0 ) | 247 | if ( strncasecmp(data+count, "begin", 5) == 0 ) |
246 | { | 248 | { |
247 | count += 5; | 249 | count += 5; |
248 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) | 250 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) |
249 | count++; | 251 | count++; |
250 | 252 | ||
251 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) | 253 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) |
252 | count ++; | 254 | count ++; |
253 | 255 | ||
254 | data += count; | 256 | data += count; |
255 | tail = (len -= count); | 257 | tail = (len -= count); |
256 | } | 258 | } |
257 | 259 | ||
258 | // Find the tail end of the actual encoded data even if | 260 | // Find the tail end of the actual encoded data even if |
259 | // there is/are trailing CR and/or LF. | 261 | // there is/are trailing CR and/or LF. |
260 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || | 262 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || |
261 | data[tail-1] == '\r' ) | 263 | data[tail-1] == '\r' ) |
262 | if ( data[--tail] != '=' ) len = tail; | 264 | if ( data[--tail] != '=' ) len = tail; |
263 | 265 | ||
264 | unsigned int outIdx = 0; | 266 | unsigned int outIdx = 0; |
265 | out.resize( (count=len) ); | 267 | out.resize( (count=len) ); |
266 | for (unsigned int idx = 0; idx < count; idx++) | 268 | for (unsigned int idx = 0; idx < count; idx++) |
267 | { | 269 | { |
268 | // Adhere to RFC 2045 and ignore characters | 270 | // Adhere to RFC 2045 and ignore characters |
269 | // that are not part of the encoding table. | 271 | // that are not part of the encoding table. |
270 | unsigned char ch = data[idx]; | 272 | unsigned char ch = data[idx]; |
271 | if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || | 273 | if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || |
272 | (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') | 274 | (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') |
273 | { | 275 | { |
274 | out[outIdx++] = Base64DecMap[ch]; | 276 | out[outIdx++] = Base64DecMap[ch]; |
275 | } | 277 | } |
276 | else | 278 | else |
277 | { | 279 | { |
278 | len--; | 280 | len--; |
279 | tail--; | 281 | tail--; |
280 | } | 282 | } |
281 | } | 283 | } |
282 | 284 | ||
283 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; | 285 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; |
284 | 286 | ||
285 | // 4-byte to 3-byte conversion | 287 | // 4-byte to 3-byte conversion |
286 | len = (tail>(len/4)) ? tail-(len/4) : 0; | 288 | len = (tail>(len/4)) ? tail-(len/4) : 0; |
287 | unsigned int sidx = 0, didx = 0; | 289 | unsigned int sidx = 0, didx = 0; |
288 | if ( len > 1 ) | 290 | if ( len > 1 ) |
289 | { | 291 | { |
290 | while (didx < len-2) | 292 | while (didx < len-2) |
291 | { | 293 | { |
292 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); | 294 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
293 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); | 295 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
294 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); | 296 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); |
295 | sidx += 4; | 297 | sidx += 4; |
296 | didx += 3; | 298 | didx += 3; |
297 | } | 299 | } |
298 | } | 300 | } |
299 | 301 | ||
300 | if (didx < len) | 302 | if (didx < len) |
301 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); | 303 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
302 | 304 | ||
303 | if (++didx < len ) | 305 | if (++didx < len ) |
304 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); | 306 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
305 | 307 | ||
306 | // Resize the output buffer | 308 | // Resize the output buffer |
307 | if ( len == 0 || len < out.size() ) | 309 | if ( len == 0 || len < out.size() ) |
308 | out.resize(len); | 310 | out.resize(len); |
309 | 311 | ||
310 | return out; | 312 | return out; |
311 | } | 313 | } |
312 | 314 | ||
313 | bool OGlobal::isAppLnkFileName( const QString& str ) | 315 | bool OGlobal::isAppLnkFileName( const QString& str ) |
314 | { | 316 | { |
315 | if (str.length()==0||str.at(str.length()-1)==QDir::separator()) return false; | 317 | if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; |
316 | return str.startsWith(MimeType::appsFolderName()+QDir::separator()); | 318 | return str.startsWith(MimeType::appsFolderName()+QDir::separator()); |
317 | } | 319 | } |
318 | 320 | ||
319 | /* ToDo: | 321 | /* ToDo: |
320 | * This fun should check the document-path value for the mounted media | 322 | * This fun should check the document-path value for the mounted media |
321 | * which has to be implemented later. this moment we just check for a | 323 | * which has to be implemented later. this moment we just check for a |
322 | * mounted media name. | 324 | * mounted media name. |
323 | */ | 325 | */ |
324 | bool OGlobal::isDocumentFileName( const QString& file ) | 326 | bool OGlobal::isDocumentFileName( const QString& file ) |
325 | { | 327 | { |
326 | if (file.length()==0||file.at(file.length()-1)==QDir::separator()) return false; | 328 | if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; |
327 | if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; | 329 | if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; |
328 | StorageInfo si; | 330 | StorageInfo si; |
329 | QList< FileSystem > fl = si.fileSystems(); | 331 | QList< FileSystem > fl = si.fileSystems(); |
330 | FileSystem*fs; | 332 | FileSystem*fs; |
331 | for (fs = fl.first();fs!=0;fs=fl.next()) { | 333 | for (fs = fl.first();fs!=0;fs=fl.next()) { |
332 | if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) | 334 | if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) |
333 | return true; | 335 | return true; |
334 | } | 336 | } |
335 | if (file.startsWith(homeDirPath())+"/Documents/") return true; | 337 | if (file.startsWith(homeDirPath())+"/Documents/") return true; |
336 | return false; | 338 | return false; |
337 | } | 339 | } |
338 | 340 | ||
339 | QString OGlobal::tempDirPath() | 341 | QString OGlobal::tempDirPath() |
340 | { | 342 | { |
341 | static QString defstring="/tmp"; | 343 | static QString defstring="/tmp"; |
342 | char * tmpp = 0; | 344 | char * tmpp = 0; |
343 | if ( (tmpp=getenv("TEMP"))) { | 345 | if ( (tmpp=getenv("TEMP"))) { |
344 | return tmpp; | 346 | return tmpp; |
345 | } | 347 | } |
346 | return defstring; | 348 | return defstring; |
347 | } | 349 | } |
348 | 350 | ||
349 | QString OGlobal::homeDirPath() | 351 | QString OGlobal::homeDirPath() |
350 | { | 352 | { |
351 | char * tmpp = getenv("HOME"); | 353 | char * tmpp = getenv("HOME"); |
352 | return (tmpp?tmpp:"/"); | 354 | return (tmpp?tmpp:"/"); |
353 | } | 355 | } |
354 | 356 | ||
355 | bool OGlobal::weekStartsOnMonday() | 357 | bool OGlobal::weekStartsOnMonday() |
356 | { | 358 | { |
357 | OConfig*conf=OGlobal::qpe_config(); | 359 | OConfig*conf=OGlobal::qpe_config(); |
358 | if (!conf)return false; | 360 | if (!conf)return false; |
359 | conf->setGroup("Time"); | 361 | conf->setGroup("Time"); |
360 | return conf->readBoolEntry("MONDAY",true); | 362 | return conf->readBoolEntry("MONDAY",true); |
361 | } | 363 | } |
362 | 364 | ||
363 | void OGlobal::setWeekStartsOnMonday( bool what) | 365 | void OGlobal::setWeekStartsOnMonday( bool what) |
364 | { | 366 | { |
365 | OConfig*conf=OGlobal::qpe_config(); | 367 | OConfig*conf=OGlobal::qpe_config(); |
366 | if (!conf)return; | 368 | if (!conf)return; |
367 | conf->setGroup("Time"); | 369 | conf->setGroup("Time"); |
368 | return conf->writeEntry("MONDAY",what); | 370 | return conf->writeEntry("MONDAY",what); |
369 | } | 371 | } |
370 | 372 | ||
371 | bool OGlobal::useAMPM() | 373 | bool OGlobal::useAMPM() |
372 | { | 374 | { |
373 | OConfig*conf=OGlobal::qpe_config(); | 375 | OConfig*conf=OGlobal::qpe_config(); |
374 | if (!conf)return false; | 376 | if (!conf)return false; |
375 | conf->setGroup("Time"); | 377 | conf->setGroup("Time"); |
376 | return conf->readBoolEntry("AMPM",false); | 378 | return conf->readBoolEntry("AMPM",false); |
377 | } | 379 | } |
378 | 380 | ||
379 | void OGlobal::setUseAMPM( bool what) | 381 | void OGlobal::setUseAMPM( bool what) |
380 | { | 382 | { |
381 | OConfig*conf=OGlobal::qpe_config(); | 383 | OConfig*conf=OGlobal::qpe_config(); |
382 | if (!conf)return; | 384 | if (!conf)return; |
383 | conf->setGroup("Time"); | 385 | conf->setGroup("Time"); |
384 | return conf->writeEntry("AMPM",what); | 386 | return conf->writeEntry("AMPM",what); |
385 | } | 387 | } |
386 | 388 | ||
387 | OConfig* OGlobal::qpe_config() | 389 | OConfig* OGlobal::qpe_config() |
388 | { | 390 | { |
389 | if ( !OGlobal::_qpe_config ) { | 391 | if ( !OGlobal::_qpe_config ) { |
390 | OGlobal::_qpe_config = new OConfig( "qpe" ); | 392 | OGlobal::_qpe_config = new OConfig( "qpe" ); |
391 | } | 393 | } |
392 | return OGlobal::_qpe_config; | 394 | return OGlobal::_qpe_config; |
393 | } | 395 | } |
394 | 396 | ||
395 | bool OGlobal::truncateFile( QFile &f, off_t size ) | 397 | bool OGlobal::truncateFile( QFile &f, off_t size ) |
396 | { | 398 | { |
397 | /* or should we let enlarge Files? then remove this | 399 | /* or should we let enlarge Files? then remove this |
398 | f.size()< part! - Alwin | 400 | f.size()< part! - Alwin |
399 | */ | 401 | */ |
400 | if (!f.exists()||f.size()<(unsigned)size) return false; | 402 | if (!f.exists()||f.size()<(unsigned)size) return false; |
401 | bool closeit=false; | 403 | bool closeit=false; |
402 | if (!f.isOpen()) { | 404 | if (!f.isOpen()) { |
403 | closeit=true; | 405 | closeit=true; |
404 | f.open(IO_Raw | IO_ReadWrite | IO_Append); | 406 | f.open(IO_Raw | IO_ReadWrite | IO_Append); |
405 | } | 407 | } |
406 | if (!f.isOpen()) { return false; } | 408 | if (!f.isOpen()) { return false; } |
407 | int r = ftruncate(f.handle(),size); | 409 | int r = ftruncate(f.handle(),size); |
408 | if (closeit) f.close(); | 410 | if (closeit) f.close(); |
409 | return r==0; | 411 | return r==0; |
410 | } | 412 | } |
diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h index aeee75e..e6a6c46 100644 --- a/libopie2/opiecore/oglobal.h +++ b/libopie2/opiecore/oglobal.h | |||
@@ -1,151 +1,159 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef OGLOBAL_H | 30 | #ifndef OGLOBAL_H |
31 | #define OGLOBAL_H | 31 | #define OGLOBAL_H |
32 | 32 | ||
33 | 33 | ||
34 | #include <opie2/oconfig.h> | 34 | #include <opie2/oconfig.h> |
35 | 35 | ||
36 | #ifndef private | 36 | #ifndef private |
37 | #define HACK_DEFINED | 37 | #define HACK_DEFINED |
38 | #define private protected | 38 | #define private protected |
39 | #endif | 39 | #endif |
40 | #include <qpe/global.h> | 40 | #include <qpe/global.h> |
41 | #ifdef HACK_DEFINED | 41 | #ifdef HACK_DEFINED |
42 | #undef private | 42 | #undef private |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | 46 | ||
47 | //FIXME Is it wise or even necessary to inherit OGlobal from Global? | 47 | //FIXME Is it wise or even necessary to inherit OGlobal from Global? |
48 | // once we totally skip libqpe it should ideally swallow Global -zecke | 48 | // once we totally skip libqpe it should ideally swallow Global -zecke |
49 | // You're right. I deleted global as the base class. -mickeyl | 49 | // You're right. I deleted global as the base class. -mickeyl |
50 | 50 | ||
51 | 51 | ||
52 | class QFile; | 52 | class QFile; |
53 | class QString; | 53 | class QString; |
54 | class DateFormat; | 54 | class DateFormat; |
55 | |||
56 | |||
57 | |||
58 | namespace Opie { | ||
59 | namespace Core { | ||
55 | /** | 60 | /** |
56 | *\brief OGlobal contains a list of generic functions | 61 | *\brief OGlobal contains a list of generic functions |
57 | * | 62 | * |
58 | * The class OGlobal contains small utility functions | 63 | * The class OGlobal contains small utility functions |
59 | * which might be useful for other applications to use. It features access | 64 | * which might be useful for other applications to use. It features access |
60 | * to the global device config and specialized functions to get information | 65 | * to the global device config and specialized functions to get information |
61 | * out of this config like Weekstart or Owner name. | 66 | * out of this config like Weekstart or Owner name. |
62 | * | 67 | * |
63 | * @todo ODP implement the things from Global which are good | 68 | * @todo ODP implement the things from Global which are good |
64 | * @author mickey,alwin,zecke | 69 | * @author mickey,alwin,zecke |
65 | * @version 0.1 | 70 | * @version 0.1 |
66 | */ | 71 | */ |
67 | class OGlobal : public Global | 72 | class OGlobal : public Global |
68 | { | 73 | { |
69 | public: | 74 | public: |
70 | 75 | ||
71 | // how do they relate to our Document Idea | 76 | // how do they relate to our Document Idea |
72 | /** @name Document System related functions | 77 | /** @name Document System related functions |
73 | * | 78 | * |
74 | */ | 79 | */ |
75 | //@{ | 80 | //@{ |
76 | static bool isAppLnkFileName( const QString& str ); | 81 | static bool isAppLnkFileName( const QString& str ); |
77 | static bool isDocumentFileName( const QString& file ); | 82 | static bool isDocumentFileName( const QString& file ); |
78 | //@} | 83 | //@} |
79 | 84 | ||
80 | /** @name File Operations | 85 | /** @name File Operations |
81 | * File operations provided by OGlobal | 86 | * File operations provided by OGlobal |
82 | */ | 87 | */ |
83 | //@{ | 88 | //@{ |
84 | /** the content of TEMP | 89 | /** the content of TEMP |
85 | * reads the environment variable TEMP and returns the content. | 90 | * reads the environment variable TEMP and returns the content. |
86 | * if not set returns "/tmp" | 91 | * if not set returns "/tmp" |
87 | * @return a string containing a dir without trailing slash! | 92 | * @return a string containing a dir without trailing slash! |
88 | */ | 93 | */ |
89 | static QString tempDirPath(); | 94 | static QString tempDirPath(); |
90 | /** the content of HOME | 95 | /** the content of HOME |
91 | * reads the environment variable HOME and returns the content. | 96 | * reads the environment variable HOME and returns the content. |
92 | * if not set returns "/" | 97 | * if not set returns "/" |
93 | * @return a string containing a dir without trailing slash! | 98 | * @return a string containing a dir without trailing slash! |
94 | */ | 99 | */ |
95 | static QString homeDirPath(); | 100 | static QString homeDirPath(); |
96 | static QString tempFileName( const QString& ); | 101 | static QString tempFileName( const QString& ); |
97 | static bool renameFile( const QString& from, const QString& to ); | 102 | static bool renameFile( const QString& from, const QString& to ); |
98 | static bool truncateFile( QFile &f, off_t size ); | 103 | static bool truncateFile( QFile &f, off_t size ); |
99 | //@} | 104 | //@} |
100 | 105 | ||
101 | 106 | ||
102 | static QString generateUuid(); | 107 | static QString generateUuid(); |
103 | 108 | ||
104 | /** @name Convert Content | 109 | /** @name Convert Content |
105 | * Convert Content of a QByteArray | 110 | * Convert Content of a QByteArray |
106 | */ | 111 | */ |
107 | //@{ | 112 | //@{ |
108 | static QByteArray encodeBase64(const QByteArray&, bool insertLF = false ); | 113 | static QByteArray encodeBase64(const QByteArray&, bool insertLF = false ); |
109 | static QByteArray decodeBase64(const QByteArray& ); | 114 | static QByteArray decodeBase64(const QByteArray& ); |
110 | //@} | 115 | //@} |
111 | 116 | ||
112 | //FIXME Do we want to put that into OApplication as in KApplication? -zecke | 117 | //FIXME Do we want to put that into OApplication as in KApplication? -zecke |
113 | // We already have a per-application config in OApplication | 118 | // We already have a per-application config in OApplication |
114 | // ( accessed through oApp->config() ), but this one is the global one! -mickeyl | 119 | // ( accessed through oApp->config() ), but this one is the global one! -mickeyl |
115 | /** @name Config and Owner related Information | 120 | /** @name Config and Owner related Information |
116 | * | 121 | * |
117 | */ | 122 | */ |
118 | //@{ | 123 | //@{ |
119 | static OConfig* config(); | 124 | static OConfig* config(); |
120 | static OConfig* qpe_config(); | 125 | static OConfig* qpe_config(); |
121 | static QString ownerName(); | 126 | static QString ownerName(); |
122 | static bool weekStartsOnMonday(); | 127 | static bool weekStartsOnMonday(); |
123 | static bool useAMPM(); | 128 | static bool useAMPM(); |
124 | #ifdef ODP | 129 | #ifdef ODP |
125 | #error "Fix dateFormat" | 130 | #error "Fix dateFormat" |
126 | /** | 131 | /** |
127 | * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat) | 132 | * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat) |
128 | * See if we need to use the function with String in it | 133 | * See if we need to use the function with String in it |
129 | * Anyway this is the future | 134 | * Anyway this is the future |
130 | * for now still use TimeString! | 135 | * for now still use TimeString! |
131 | */ | 136 | */ |
132 | #endif | 137 | #endif |
133 | static DateFormat dateFormat(); | 138 | static DateFormat dateFormat(); |
134 | static void setDateFormat( const DateFormat& ); | 139 | static void setDateFormat( const DateFormat& ); |
135 | 140 | ||
136 | 141 | ||
137 | static void setWeekStartsOnMonday( bool ); | 142 | static void setWeekStartsOnMonday( bool ); |
138 | static void setUseAMPM( bool ); | 143 | static void setUseAMPM( bool ); |
139 | //@} | 144 | //@} |
140 | 145 | ||
141 | //@{ | 146 | //@{ |
142 | static Global::Command* builtinCommands(); | 147 | static Global::Command* builtinCommands(); |
143 | static QGuardedPtr<QWidget>* builtinRunning(); | 148 | static QGuardedPtr<QWidget>* builtinRunning(); |
144 | //@} | 149 | //@} |
145 | 150 | ||
146 | private: | 151 | private: |
147 | static OConfig* _config; | 152 | static OConfig* _config; |
148 | static OConfig* _qpe_config; | 153 | static OConfig* _qpe_config; |
154 | class Private; | ||
155 | Private *d; | ||
149 | }; | 156 | }; |
150 | 157 | } | |
158 | } | ||
151 | #endif // OGLOBAL_H | 159 | #endif // OGLOBAL_H |
diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp index 192e55b..f34c531 100644 --- a/libopie2/opiecore/oglobalsettings.cpp +++ b/libopie2/opiecore/oglobalsettings.cpp | |||
@@ -1,238 +1,241 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | Inspired by the KDE globalsettings which are | 5 | Inspired by the KDE globalsettings which are |
6 | Copyright (C) 2000 David Faure <faure@kde.org> | 6 | Copyright (C) 2000 David Faure <faure@kde.org> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | 34 | ||
35 | #include <opie2/oglobalsettings.h> | 35 | #include <opie2/oglobalsettings.h> |
36 | #include <opie2/oconfig.h> | 36 | #include <opie2/oconfig.h> |
37 | #include <opie2/oglobal.h> | 37 | #include <opie2/oglobal.h> |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | 40 | ||
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | 46 | ||
47 | |||
48 | using namespace Opie::Core; | ||
49 | |||
47 | QString* OGlobalSettings::s_desktopPath = 0; | 50 | QString* OGlobalSettings::s_desktopPath = 0; |
48 | QString* OGlobalSettings::s_autostartPath = 0; | 51 | QString* OGlobalSettings::s_autostartPath = 0; |
49 | QString* OGlobalSettings::s_trashPath = 0; | 52 | QString* OGlobalSettings::s_trashPath = 0; |
50 | QString* OGlobalSettings::s_documentPath = 0; | 53 | QString* OGlobalSettings::s_documentPath = 0; |
51 | QFont *OGlobalSettings::_generalFont = 0; | 54 | QFont *OGlobalSettings::_generalFont = 0; |
52 | QFont *OGlobalSettings::_fixedFont = 0; | 55 | QFont *OGlobalSettings::_fixedFont = 0; |
53 | QFont *OGlobalSettings::_toolBarFont = 0; | 56 | QFont *OGlobalSettings::_toolBarFont = 0; |
54 | QFont *OGlobalSettings::_menuFont = 0; | 57 | QFont *OGlobalSettings::_menuFont = 0; |
55 | QFont *OGlobalSettings::_windowTitleFont = 0; | 58 | QFont *OGlobalSettings::_windowTitleFont = 0; |
56 | QFont *OGlobalSettings::_taskbarFont = 0; | 59 | QFont *OGlobalSettings::_taskbarFont = 0; |
57 | 60 | ||
58 | QColor *OGlobalSettings::OpieGray = 0; | 61 | QColor *OGlobalSettings::OpieGray = 0; |
59 | QColor *OGlobalSettings::OpieHighlight = 0; | 62 | QColor *OGlobalSettings::OpieHighlight = 0; |
60 | QColor *OGlobalSettings::OpieAlternate = 0; | 63 | QColor *OGlobalSettings::OpieAlternate = 0; |
61 | 64 | ||
62 | OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0; | 65 | OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0; |
63 | 66 | ||
64 | //FIXME: Add manipulators to the accessors | 67 | //FIXME: Add manipulators to the accessors |
65 | 68 | ||
66 | int OGlobalSettings::dndEventDelay() | 69 | int OGlobalSettings::dndEventDelay() |
67 | { | 70 | { |
68 | OConfig *c = OGlobal::config(); | 71 | OConfig *c = OGlobal::config(); |
69 | OConfigGroupSaver cgs( c, "General" ); | 72 | OConfigGroupSaver cgs( c, "General" ); |
70 | return c->readNumEntry("DndDelay", 2); | 73 | return c->readNumEntry("DndDelay", 2); |
71 | } | 74 | } |
72 | 75 | ||
73 | bool OGlobalSettings::singleClick() | 76 | bool OGlobalSettings::singleClick() |
74 | { | 77 | { |
75 | OConfig *c = OGlobal::config(); | 78 | OConfig *c = OGlobal::config(); |
76 | OConfigGroupSaver cgs( c, "OPIE" ); | 79 | OConfigGroupSaver cgs( c, "OPIE" ); |
77 | return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK); | 80 | return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK); |
78 | } | 81 | } |
79 | 82 | ||
80 | bool OGlobalSettings::insertTearOffHandle() | 83 | bool OGlobalSettings::insertTearOffHandle() |
81 | { | 84 | { |
82 | OConfig *c = OGlobal::config(); | 85 | OConfig *c = OGlobal::config(); |
83 | OConfigGroupSaver cgs( c, "OPIE" ); | 86 | OConfigGroupSaver cgs( c, "OPIE" ); |
84 | return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES); | 87 | return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES); |
85 | } | 88 | } |
86 | 89 | ||
87 | bool OGlobalSettings::changeCursorOverIcon() | 90 | bool OGlobalSettings::changeCursorOverIcon() |
88 | { | 91 | { |
89 | OConfig *c = OGlobal::config(); | 92 | OConfig *c = OGlobal::config(); |
90 | OConfigGroupSaver cgs( c, "OPIE" ); | 93 | OConfigGroupSaver cgs( c, "OPIE" ); |
91 | return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR); | 94 | return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR); |
92 | } | 95 | } |
93 | 96 | ||
94 | bool OGlobalSettings::visualActivate() | 97 | bool OGlobalSettings::visualActivate() |
95 | { | 98 | { |
96 | OConfig *c = OGlobal::config(); | 99 | OConfig *c = OGlobal::config(); |
97 | OConfigGroupSaver cgs( c, "OPIE" ); | 100 | OConfigGroupSaver cgs( c, "OPIE" ); |
98 | return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE); | 101 | return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE); |
99 | } | 102 | } |
100 | 103 | ||
101 | unsigned int OGlobalSettings::visualActivateSpeed() | 104 | unsigned int OGlobalSettings::visualActivateSpeed() |
102 | { | 105 | { |
103 | OConfig *c = OGlobal::config(); | 106 | OConfig *c = OGlobal::config(); |
104 | OConfigGroupSaver cgs( c, "OPIE" ); | 107 | OConfigGroupSaver cgs( c, "OPIE" ); |
105 | return | 108 | return |
106 | c->readNumEntry( | 109 | c->readNumEntry( |
107 | "VisualActivateSpeed", | 110 | "VisualActivateSpeed", |
108 | OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED | 111 | OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED |
109 | ); | 112 | ); |
110 | } | 113 | } |
111 | 114 | ||
112 | int OGlobalSettings::autoSelectDelay() | 115 | int OGlobalSettings::autoSelectDelay() |
113 | { | 116 | { |
114 | OConfig *c = OGlobal::config(); | 117 | OConfig *c = OGlobal::config(); |
115 | OConfigGroupSaver cgs( c, "OPIE" ); | 118 | OConfigGroupSaver cgs( c, "OPIE" ); |
116 | return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY); | 119 | return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY); |
117 | } | 120 | } |
118 | 121 | ||
119 | OGlobalSettings::Completion OGlobalSettings::completionMode() | 122 | OGlobalSettings::Completion OGlobalSettings::completionMode() |
120 | { | 123 | { |
121 | int completion; | 124 | int completion; |
122 | OConfig *c = OGlobal::config(); | 125 | OConfig *c = OGlobal::config(); |
123 | OConfigGroupSaver cgs( c, "General" ); | 126 | OConfigGroupSaver cgs( c, "General" ); |
124 | completion = c->readNumEntry("completionMode", -1); | 127 | completion = c->readNumEntry("completionMode", -1); |
125 | if ((completion < (int) CompletionNone) || | 128 | if ((completion < (int) CompletionNone) || |
126 | (completion > (int) CompletionPopupAuto)) | 129 | (completion > (int) CompletionPopupAuto)) |
127 | { | 130 | { |
128 | completion = (int) CompletionPopup; // Default | 131 | completion = (int) CompletionPopup; // Default |
129 | } | 132 | } |
130 | return (Completion) completion; | 133 | return (Completion) completion; |
131 | } | 134 | } |
132 | 135 | ||
133 | 136 | ||
134 | bool OGlobalSettings::showContextMenusOnPress () | 137 | bool OGlobalSettings::showContextMenusOnPress () |
135 | { | 138 | { |
136 | OConfig *c = OGlobal::config(); | 139 | OConfig *c = OGlobal::config(); |
137 | OConfigGroupSaver cgs (c, "ContextMenus"); | 140 | OConfigGroupSaver cgs (c, "ContextMenus"); |
138 | 141 | ||
139 | return cgs.config()->readBoolEntry("ShowOnPress", true); | 142 | return cgs.config()->readBoolEntry("ShowOnPress", true); |
140 | } | 143 | } |
141 | 144 | ||
142 | 145 | ||
143 | int OGlobalSettings::contextMenuKey () | 146 | int OGlobalSettings::contextMenuKey () |
144 | { | 147 | { |
145 | OConfig *c = OGlobal::config(); | 148 | OConfig *c = OGlobal::config(); |
146 | OConfigGroupSaver cgs (c, "Shortcuts"); | 149 | OConfigGroupSaver cgs (c, "Shortcuts"); |
147 | 150 | ||
148 | //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu")); | 151 | //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu")); |
149 | //return cut.keyCodeQt(); | 152 | //return cut.keyCodeQt(); |
150 | 153 | ||
151 | return 0; // FIXME | 154 | return 0; // FIXME |
152 | } | 155 | } |
153 | 156 | ||
154 | 157 | ||
155 | OGlobalSettings::Debug OGlobalSettings::debugMode() | 158 | OGlobalSettings::Debug OGlobalSettings::debugMode() |
156 | { | 159 | { |
157 | OConfig *c = OGlobal::config(); | 160 | OConfig *c = OGlobal::config(); |
158 | OConfigGroupSaver cgs( c, "General" ); | 161 | OConfigGroupSaver cgs( c, "General" ); |
159 | int debug = c->readNumEntry( "debugMode", -1 ); | 162 | int debug = c->readNumEntry( "debugMode", -1 ); |
160 | if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) ) | 163 | if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) ) |
161 | { | 164 | { |
162 | debug = (int) DebugStdErr; // Default | 165 | debug = (int) DebugStdErr; // Default |
163 | } | 166 | } |
164 | return (Debug) debug; | 167 | return (Debug) debug; |
165 | } | 168 | } |
166 | 169 | ||
167 | 170 | ||
168 | QString OGlobalSettings::debugOutput() | 171 | QString OGlobalSettings::debugOutput() |
169 | { | 172 | { |
170 | OConfig *c = OGlobal::config(); | 173 | OConfig *c = OGlobal::config(); |
171 | OConfigGroupSaver cgs( c, "General" ); | 174 | OConfigGroupSaver cgs( c, "General" ); |
172 | QString deflt = QString::null; | 175 | QString deflt = QString::null; |
173 | switch( debugMode() ) | 176 | switch( debugMode() ) |
174 | { | 177 | { |
175 | case DebugNone: break; // no additional information needed | 178 | case DebugNone: break; // no additional information needed |
176 | case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in | 179 | case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in |
177 | case DebugMsgBox: break; // no additional information needed | 180 | case DebugMsgBox: break; // no additional information needed |
178 | case DebugStdErr: break; // no additional information needed | 181 | case DebugStdErr: break; // no additional information needed |
179 | case DebugSysLog: break; // no additional information needed | 182 | case DebugSysLog: break; // no additional information needed |
180 | case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to | 183 | case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to |
181 | } | 184 | } |
182 | 185 | ||
183 | return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt ); | 186 | return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt ); |
184 | } | 187 | } |
185 | 188 | ||
186 | 189 | ||
187 | QColor OGlobalSettings::toolBarHighlightColor() | 190 | QColor OGlobalSettings::toolBarHighlightColor() |
188 | { | 191 | { |
189 | initColors(); | 192 | initColors(); |
190 | OConfig *c = OGlobal::config(); | 193 | OConfig *c = OGlobal::config(); |
191 | OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") ); | 194 | OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") ); |
192 | return c->readColorEntry("HighlightColor", OpieHighlight); | 195 | return c->readColorEntry("HighlightColor", OpieHighlight); |
193 | } | 196 | } |
194 | 197 | ||
195 | QColor OGlobalSettings::inactiveTitleColor() | 198 | QColor OGlobalSettings::inactiveTitleColor() |
196 | { | 199 | { |
197 | if (!OpieGray) OpieGray = new QColor(220, 220, 220); | 200 | if (!OpieGray) OpieGray = new QColor(220, 220, 220); |
198 | OConfig *c = OGlobal::config(); | 201 | OConfig *c = OGlobal::config(); |
199 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); | 202 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); |
200 | return c->readColorEntry( "inactiveBackground", OpieGray ); | 203 | return c->readColorEntry( "inactiveBackground", OpieGray ); |
201 | } | 204 | } |
202 | 205 | ||
203 | QColor OGlobalSettings::inactiveTextColor() | 206 | QColor OGlobalSettings::inactiveTextColor() |
204 | { | 207 | { |
205 | OConfig *c = OGlobal::config(); | 208 | OConfig *c = OGlobal::config(); |
206 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); | 209 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); |
207 | return c->readColorEntry( "inactiveForeground", &Qt::darkGray ); | 210 | return c->readColorEntry( "inactiveForeground", &Qt::darkGray ); |
208 | } | 211 | } |
209 | 212 | ||
210 | QColor OGlobalSettings::activeTitleColor() | 213 | QColor OGlobalSettings::activeTitleColor() |
211 | { | 214 | { |
212 | initColors(); | 215 | initColors(); |
213 | OConfig *c = OGlobal::config(); | 216 | OConfig *c = OGlobal::config(); |
214 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); | 217 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); |
215 | return c->readColorEntry( "activeBackground", OpieHighlight); | 218 | return c->readColorEntry( "activeBackground", OpieHighlight); |
216 | } | 219 | } |
217 | 220 | ||
218 | QColor OGlobalSettings::activeTextColor() | 221 | QColor OGlobalSettings::activeTextColor() |
219 | { | 222 | { |
220 | OConfig *c = OGlobal::config(); | 223 | OConfig *c = OGlobal::config(); |
221 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); | 224 | OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); |
222 | return c->readColorEntry( "activeForeground", &Qt::white ); | 225 | return c->readColorEntry( "activeForeground", &Qt::white ); |
223 | } | 226 | } |
224 | 227 | ||
225 | int OGlobalSettings::contrast() | 228 | int OGlobalSettings::contrast() |
226 | { | 229 | { |
227 | OConfig *c = OGlobal::config(); | 230 | OConfig *c = OGlobal::config(); |
228 | OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") ); | 231 | OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") ); |
229 | return c->readNumEntry( "contrast", 7 ); | 232 | return c->readNumEntry( "contrast", 7 ); |
230 | } | 233 | } |
231 | 234 | ||
232 | // following functions should work in OPIE - how to sync with appearance changes? | 235 | // following functions should work in OPIE - how to sync with appearance changes? |
233 | 236 | ||
234 | QColor OGlobalSettings::baseColor() | 237 | QColor OGlobalSettings::baseColor() |
235 | { | 238 | { |
236 | OConfig *c = OGlobal::config(); | 239 | OConfig *c = OGlobal::config(); |
237 | OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); | 240 | OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); |
238 | return c->readColorEntry( "Base", &Qt::white ); | 241 | return c->readColorEntry( "Base", &Qt::white ); |
diff --git a/libopie2/opiecore/oglobalsettings.h b/libopie2/opiecore/oglobalsettings.h index e3ac148..8eea709 100644 --- a/libopie2/opiecore/oglobalsettings.h +++ b/libopie2/opiecore/oglobalsettings.h | |||
@@ -1,373 +1,385 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> | 3 | Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> |
4 | Inspired by KDE OGlobalSettings | 4 | Inspired by KDE OGlobalSettings |
5 | Copyright (C) 2000 David Faure <faure@kde.org> | 5 | Copyright (C) 2000 David Faure <faure@kde.org> |
6 | =. | 6 | =. |
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 OGLOBALSETTINGS_H | 32 | #ifndef OGLOBALSETTINGS_H |
33 | #define OGLOBALSETTINGS_H | 33 | #define OGLOBALSETTINGS_H |
34 | 34 | ||
35 | #include <qstring.h> | 35 | #include <qstring.h> |
36 | #include <qcolor.h> | 36 | #include <qcolor.h> |
37 | #include <qfont.h> | 37 | #include <qfont.h> |
38 | 38 | ||
39 | /** | ||
40 | * \todo make real const values | ||
41 | */ | ||
39 | #define OPIE_DEFAULT_SINGLECLICK true | 42 | #define OPIE_DEFAULT_SINGLECLICK true |
40 | #define OPIE_DEFAULT_INSERTTEAROFFHANDLES true | 43 | #define OPIE_DEFAULT_INSERTTEAROFFHANDLES true |
41 | #define OPIE_DEFAULT_AUTOSELECTDELAY -1 | 44 | #define OPIE_DEFAULT_AUTOSELECTDELAY -1 |
42 | #define OPIE_DEFAULT_CHANGECURSOR true | 45 | #define OPIE_DEFAULT_CHANGECURSOR true |
43 | #define OPIE_DEFAULT_LARGE_CURSOR false | 46 | #define OPIE_DEFAULT_LARGE_CURSOR false |
44 | #define OPIE_DEFAULT_VISUAL_ACTIVATE true | 47 | #define OPIE_DEFAULT_VISUAL_ACTIVATE true |
45 | #define OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED 50 | 48 | #define OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED 50 |
46 | 49 | ||
47 | //FIXME: There's still a whole lot of stuff in here which has to be revised | 50 | //FIXME: There's still a whole lot of stuff in here which has to be revised |
48 | //FIXME: before public usage... lack of time to do it at once - so it will | 51 | //FIXME: before public usage... lack of time to do it at once - so it will |
49 | //FIXME: happen step-by-step. ML. | 52 | //FIXME: happen step-by-step. ML. |
50 | // we should not habe too much configure options!!!!!! -zecke | 53 | // we should not habe too much configure options!!!!!! -zecke |
51 | 54 | ||
55 | namespace Opie { | ||
56 | namespace Core { | ||
57 | |||
52 | /** | 58 | /** |
53 | * Access the OPIE global configuration settings. | 59 | * Access the OPIE global configuration settings. |
54 | * | 60 | * |
55 | */ | 61 | */ |
56 | class OGlobalSettings | 62 | class OGlobalSettings |
57 | { | 63 | { |
58 | public: | 64 | public: |
59 | 65 | ||
60 | /** | 66 | /** |
61 | * Returns a threshold in pixels for drag & drop operations. | 67 | * Returns a threshold in pixels for drag & drop operations. |
62 | * As long as the mouse movement has not exceeded this number | 68 | * As long as the mouse movement has not exceeded this number |
63 | * of pixels in either X or Y direction no drag operation may | 69 | * of pixels in either X or Y direction no drag operation may |
64 | * be started. This prevents spurious drags when the user intended | 70 | * be started. This prevents spurious drags when the user intended |
65 | * to click on something but moved the mouse a bit while doing so. | 71 | * to click on something but moved the mouse a bit while doing so. |
66 | * | 72 | * |
67 | * For this to work you must save the position of the mouse (oldPos) | 73 | * For this to work you must save the position of the mouse (oldPos) |
68 | * in the @ref QWidget::mousePressEvent(). | 74 | * in the @ref QWidget::mousePressEvent(). |
69 | * When the position of the mouse (newPos) | 75 | * When the position of the mouse (newPos) |
70 | * in a @ref QWidget::mouseMoveEvent() exceeds this threshold | 76 | * in a @ref QWidget::mouseMoveEvent() exceeds this threshold |
71 | * you may start a drag | 77 | * you may start a drag |
72 | * which should originate from oldPos. | 78 | * which should originate from oldPos. |
73 | * | 79 | * |
74 | * Example code: | 80 | * Example code: |
75 | * <pre> | 81 | * <pre> |
76 | * void OColorCells::mousePressEvent( QMouseEvent *e ) | 82 | * void OColorCells::mousePressEvent( QMouseEvent *e ) |
77 | * { | 83 | * { |
78 | * mOldPos = e->pos(); | 84 | * mOldPos = e->pos(); |
79 | * } | 85 | * } |
80 | * | 86 | * |
81 | * void OColorCells::mouseMoveEvent( QMouseEvent *e ) | 87 | * void OColorCells::mouseMoveEvent( QMouseEvent *e ) |
82 | * { | 88 | * { |
83 | * if( !(e->state() && LeftButton)) return; | 89 | * if( !(e->state() && LeftButton)) return; |
84 | * | 90 | * |
85 | * int delay = OGlobalSettings::dndEventDelay(); | 91 | * int delay = OGlobalSettings::dndEventDelay(); |
86 | * QPoint newPos = e->pos(); | 92 | * QPoint newPos = e->pos(); |
87 | * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay || | 93 | * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay || |
88 | * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay) | 94 | * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay) |
89 | * { | 95 | * { |
90 | * // Drag color object | 96 | * // Drag color object |
91 | * int cell = posToCell(mOldPos); // Find color at mOldPos | 97 | * int cell = posToCell(mOldPos); // Find color at mOldPos |
92 | * if ((cell != -1) && colors[cell].isValid()) | 98 | * if ((cell != -1) && colors[cell].isValid()) |
93 | * { | 99 | * { |
94 | * OColorDrag *d = OColorDrag::makeDrag( colors[cell], this); | 100 | * OColorDrag *d = OColorDrag::makeDrag( colors[cell], this); |
95 | * d->dragCopy(); | 101 | * d->dragCopy(); |
96 | * } | 102 | * } |
97 | * } | 103 | * } |
98 | * } | 104 | * } |
99 | * </pre> | 105 | * </pre> |
100 | * | 106 | * |
101 | */ | 107 | */ |
102 | 108 | ||
103 | // we do not support DND at the momemt -zecke | 109 | // we do not support DND at the momemt -zecke |
104 | static int dndEventDelay(); | 110 | static int dndEventDelay(); |
105 | 111 | ||
106 | /** | 112 | /** |
107 | * Returns whether OPIE runs in single (default) or double click | 113 | * Returns whether OPIE runs in single (default) or double click |
108 | * mode. | 114 | * mode. |
109 | * | 115 | * |
110 | * @return @p true if single click mode, or @p false if double click mode. | 116 | * @return @p true if single click mode, or @p false if double click mode. |
111 | * | 117 | * |
112 | * see @ref http://opie.handhelds.org/documentation/standards/opie/style/mouse/index.html | 118 | * see @ref http://opie.handhelds.org/documentation/standards/opie/style/mouse/index.html |
113 | **/ | 119 | **/ |
114 | static bool singleClick(); | 120 | static bool singleClick(); |
115 | 121 | ||
116 | /** | 122 | /** |
117 | * Returns whether tear-off handles are inserted in OPopupMenus. | 123 | * Returns whether tear-off handles are inserted in OPopupMenus. |
118 | **/ | 124 | **/ |
119 | // would clutter the small screen -zecke | 125 | // would clutter the small screen -zecke |
120 | static bool insertTearOffHandle(); | 126 | static bool insertTearOffHandle(); |
121 | 127 | ||
122 | /** | 128 | /** |
123 | * @return the OPIE setting for "change cursor over icon" | 129 | * @return the OPIE setting for "change cursor over icon" |
124 | */ | 130 | */ |
125 | static bool changeCursorOverIcon(); | 131 | static bool changeCursorOverIcon(); |
126 | 132 | ||
127 | /** | 133 | /** |
128 | * @return whether to show some feedback when an item (specifically an | 134 | * @return whether to show some feedback when an item (specifically an |
129 | * icon) is activated. | 135 | * icon) is activated. |
130 | */ | 136 | */ |
131 | static bool visualActivate(); | 137 | static bool visualActivate(); |
132 | static unsigned int visualActivateSpeed(); | 138 | static unsigned int visualActivateSpeed(); |
133 | 139 | ||
134 | /** | 140 | /** |
135 | * Returns the OPIE setting for the auto-select option | 141 | * Returns the OPIE setting for the auto-select option |
136 | * | 142 | * |
137 | * @return the auto-select delay or -1 if auto-select is disabled. | 143 | * @return the auto-select delay or -1 if auto-select is disabled. |
138 | */ | 144 | */ |
139 | static int autoSelectDelay(); | 145 | static int autoSelectDelay(); |
140 | 146 | ||
141 | /** | 147 | /** |
142 | * Returns the OPIE setting for the shortcut key to open | 148 | * Returns the OPIE setting for the shortcut key to open |
143 | * context menus. | 149 | * context menus. |
144 | * | 150 | * |
145 | * @return the key that pops up context menus. | 151 | * @return the key that pops up context menus. |
146 | */ | 152 | */ |
147 | static int contextMenuKey(); | 153 | static int contextMenuKey(); |
148 | 154 | ||
149 | /** | 155 | /** |
150 | * Returns the OPIE setting for context menus. | 156 | * Returns the OPIE setting for context menus. |
151 | * | 157 | * |
152 | * @return whether context menus should be shown on button press | 158 | * @return whether context menus should be shown on button press |
153 | * or button release (click). | 159 | * or button release (click). |
154 | */ | 160 | */ |
155 | static bool showContextMenusOnPress (); | 161 | static bool showContextMenusOnPress (); |
156 | 162 | ||
157 | /** | 163 | /** |
158 | * This enum describes the completion mode used for by the @ref OCompletion class. | 164 | * This enum describes the completion mode used for by the @ref OCompletion class. |
159 | * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/keys/completion.html"> | 165 | * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/keys/completion.html"> |
160 | * the styleguide</a>. | 166 | * the styleguide</a>. |
161 | **/ | 167 | **/ |
162 | enum Completion { | 168 | enum Completion { |
163 | /** | 169 | /** |
164 | * No completion is used. | 170 | * No completion is used. |
165 | */ | 171 | */ |
166 | CompletionNone=1, | 172 | CompletionNone=1, |
167 | /** | 173 | /** |
168 | * Text is automatically filled in whenever possible. | 174 | * Text is automatically filled in whenever possible. |
169 | */ | 175 | */ |
170 | CompletionAuto, | 176 | CompletionAuto, |
171 | /** | 177 | /** |
172 | * Same as automatic except shortest match is used for completion. | 178 | * Same as automatic except shortest match is used for completion. |
173 | */ | 179 | */ |
174 | CompletionMan, | 180 | CompletionMan, |
175 | /** | 181 | /** |
176 | * Complete text much in the same way as a typical *nix shell would. | 182 | * Complete text much in the same way as a typical *nix shell would. |
177 | */ | 183 | */ |
178 | CompletionShell, | 184 | CompletionShell, |
179 | /** | 185 | /** |
180 | * Lists all possible matches in a popup list-box to choose from. | 186 | * Lists all possible matches in a popup list-box to choose from. |
181 | */ | 187 | */ |
182 | CompletionPopup, | 188 | CompletionPopup, |
183 | /** | 189 | /** |
184 | * Lists all possible matches in a popup list-box to choose from, and automatically | 190 | * Lists all possible matches in a popup list-box to choose from, and automatically |
185 | * fill the result whenever possible. | 191 | * fill the result whenever possible. |
186 | */ | 192 | */ |
187 | CompletionPopupAuto | 193 | CompletionPopupAuto |
188 | }; | 194 | }; |
189 | /** | 195 | /** |
190 | * Returns the preferred completion mode setting. | 196 | * Returns the preferred completion mode setting. |
191 | * | 197 | * |
192 | * @return @ref Completion. Default is @p CompletionPopup. | 198 | * @return @ref Completion. Default is @p CompletionPopup. |
193 | */ | 199 | */ |
194 | static Completion completionMode(); | 200 | static Completion completionMode(); |
195 | 201 | ||
196 | /** | 202 | /** |
197 | * This enum describes the debug mode used for by the @ref odbgstream class. | 203 | * This enum describes the debug mode used for by the @ref odbgstream class. |
198 | * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/debug/debug.html"> | 204 | * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/debug/debug.html"> |
199 | * the styleguide</a>. | 205 | * the styleguide</a>. |
200 | **/ | 206 | **/ |
201 | enum Debug { | 207 | enum Debug { |
202 | /** | 208 | /** |
203 | * Debug messages are ignored. | 209 | * Debug messages are ignored. |
204 | */ | 210 | */ |
205 | DebugNone=-1, | 211 | DebugNone=-1, |
206 | /** | 212 | /** |
207 | * Debug output is sent to files /var/log/. | 213 | * Debug output is sent to files /var/log/. |
208 | */ | 214 | */ |
209 | DebugFiles=0, | 215 | DebugFiles=0, |
210 | /** | 216 | /** |
211 | * Debug output is written in a QMessageBox. | 217 | * Debug output is written in a QMessageBox. |
212 | */ | 218 | */ |
213 | DebugMsgBox=1, | 219 | DebugMsgBox=1, |
214 | /** | 220 | /** |
215 | * Debug output is sent to stderr. | 221 | * Debug output is sent to stderr. |
216 | */ | 222 | */ |
217 | DebugStdErr=2, | 223 | DebugStdErr=2, |
218 | /** | 224 | /** |
219 | * Debug output is sent to syslog. | 225 | * Debug output is sent to syslog. |
220 | */ | 226 | */ |
221 | DebugSysLog=3, | 227 | DebugSysLog=3, |
222 | /** | 228 | /** |
223 | * Debug output is sent via udp over a socket. | 229 | * Debug output is sent via udp over a socket. |
224 | */ | 230 | */ |
225 | DebugSocket=4 | 231 | DebugSocket=4 |
226 | }; | 232 | }; |
227 | /** | 233 | /** |
228 | * Returns the preferred debug mode setting. | 234 | * Returns the preferred debug mode setting. |
229 | * | 235 | * |
230 | * @return @ref Debug. Default is @p DebugStdErr. | 236 | * @return @ref Debug. Default is @p DebugStdErr. |
231 | */ | 237 | */ |
232 | static Debug debugMode(); | 238 | static Debug debugMode(); |
233 | 239 | ||
234 | /** | 240 | /** |
235 | * Returns additional information for debug output (dependent on the debug mode). | 241 | * Returns additional information for debug output (dependent on the debug mode). |
236 | * | 242 | * |
237 | * @return Additional debug output information. | 243 | * @return Additional debug output information. |
238 | */ | 244 | */ |
239 | static QString debugOutput(); | 245 | static QString debugOutput(); |
240 | /** | 246 | /** |
241 | * This is a structure containing the possible mouse settings. | 247 | * This is a structure containing the possible mouse settings. |
242 | */ | 248 | */ |
243 | struct OMouseSettings | 249 | struct OMouseSettings |
244 | { | 250 | { |
245 | enum { RightHanded = 0, LeftHanded = 1 }; | 251 | enum { RightHanded = 0, LeftHanded = 1 }; |
246 | int handed; // left or right | 252 | int handed; // left or right |
247 | }; | 253 | }; |
248 | 254 | ||
249 | /** | 255 | /** |
250 | * This returns the current mouse settings. | 256 | * This returns the current mouse settings. |
251 | */ | 257 | */ |
252 | static OMouseSettings & mouseSettings(); | 258 | static OMouseSettings & mouseSettings(); |
253 | 259 | ||
254 | /** | 260 | /** |
255 | * The path to the desktop directory of the current user. | 261 | * The path to the desktop directory of the current user. |
256 | */ | 262 | */ |
257 | // below handled by Global stuff and QPEApplication | 263 | // below handled by Global stuff and QPEApplication |
258 | static QString desktopPath() { initStatic(); return *s_desktopPath; } | 264 | static QString desktopPath() { initStatic(); return *s_desktopPath; } |
259 | 265 | ||
260 | /** | 266 | /** |
261 | * The path to the autostart directory of the current user. | 267 | * The path to the autostart directory of the current user. |
262 | */ | 268 | */ |
263 | static QString autostartPath() { initStatic(); return *s_autostartPath; } | 269 | static QString autostartPath() { initStatic(); return *s_autostartPath; } |
264 | 270 | ||
265 | /** | 271 | /** |
266 | * The path to the trash directory of the current user. | 272 | * The path to the trash directory of the current user. |
267 | */ | 273 | */ |
268 | // we do not have that concept -zecke | 274 | // we do not have that concept -zecke |
269 | static QString trashPath() { initStatic(); return *s_trashPath; } | 275 | static QString trashPath() { initStatic(); return *s_trashPath; } |
270 | 276 | ||
271 | /** | 277 | /** |
272 | * The path where documents are stored of the current user. | 278 | * The path where documents are stored of the current user. |
273 | */ | 279 | */ |
274 | static QString documentPath() { initStatic(); return *s_documentPath; } | 280 | static QString documentPath() { initStatic(); return *s_documentPath; } |
275 | 281 | ||
276 | 282 | ||
277 | /** | 283 | /** |
278 | * The default color to use when highlighting toolbar buttons | 284 | * The default color to use when highlighting toolbar buttons |
279 | */ | 285 | */ |
280 | static QColor toolBarHighlightColor(); | 286 | static QColor toolBarHighlightColor(); |
281 | static QColor inactiveTitleColor(); | 287 | static QColor inactiveTitleColor(); |
282 | static QColor inactiveTextColor(); | 288 | static QColor inactiveTextColor(); |
283 | static QColor activeTitleColor(); | 289 | static QColor activeTitleColor(); |
284 | static QColor activeTextColor(); | 290 | static QColor activeTextColor(); |
285 | static int contrast(); | 291 | static int contrast(); |
286 | 292 | ||
287 | /** | 293 | /** |
288 | * The default colors to use for text and links. | 294 | * The default colors to use for text and links. |
289 | */ | 295 | */ |
290 | static QColor baseColor(); // Similair to QColorGroup::base() | 296 | static QColor baseColor(); // Similair to QColorGroup::base() |
291 | static QColor textColor(); // Similair to QColorGroup::text() | 297 | static QColor textColor(); // Similair to QColorGroup::text() |
292 | static QColor linkColor(); | 298 | static QColor linkColor(); |
293 | static QColor visitedLinkColor(); | 299 | static QColor visitedLinkColor(); |
294 | static QColor highlightedTextColor(); // Similair to QColorGroup::hightlightedText() | 300 | static QColor highlightedTextColor(); // Similair to QColorGroup::hightlightedText() |
295 | static QColor highlightColor(); // Similair to QColorGroup::highlight() | 301 | static QColor highlightColor(); // Similair to QColorGroup::highlight() |
296 | 302 | ||
297 | /** | 303 | /** |
298 | * Returns the alternate background color used by @ref OListView with | 304 | * Returns the alternate background color used by @ref OListView with |
299 | * @ref OListViewItem. Any other list that uses alternating background | 305 | * @ref OListViewItem. Any other list that uses alternating background |
300 | * colors should use this too, to obey to the user's preferences. Returns | 306 | * colors should use this too, to obey to the user's preferences. Returns |
301 | * an invalid color if the user doesn't want alternating backgrounds. | 307 | * an invalid color if the user doesn't want alternating backgrounds. |
302 | * @see #calculateAlternateBackgroundColor | 308 | * @see #calculateAlternateBackgroundColor |
303 | */ | 309 | */ |
304 | static QColor alternateBackgroundColor(); | 310 | static QColor alternateBackgroundColor(); |
305 | /** | 311 | /** |
306 | * Calculates a color based on @p base to be used as alternating | 312 | * Calculates a color based on @p base to be used as alternating |
307 | * color for e.g. listviews. | 313 | * color for e.g. listviews. |
308 | * @see #alternateBackgroundColor | 314 | * @see #alternateBackgroundColor |
309 | */ | 315 | */ |
310 | static QColor calculateAlternateBackgroundColor(const QColor& base); | 316 | static QColor calculateAlternateBackgroundColor(const QColor& base); |
311 | 317 | ||
312 | 318 | ||
313 | static QFont generalFont(); | 319 | static QFont generalFont(); |
314 | static QFont fixedFont(); | 320 | static QFont fixedFont(); |
315 | static QFont toolBarFont(); | 321 | static QFont toolBarFont(); |
316 | static QFont menuFont(); | 322 | static QFont menuFont(); |
317 | static QFont windowTitleFont(); | 323 | static QFont windowTitleFont(); |
318 | static QFont taskbarFont(); | 324 | static QFont taskbarFont(); |
319 | 325 | ||
320 | /** | 326 | /** |
321 | * Returns if the user specified multihead. In case the display | 327 | * Returns if the user specified multihead. In case the display |
322 | * has multiple screens, the return value of this function specifies | 328 | * has multiple screens, the return value of this function specifies |
323 | * if the user wants OPIE to run on all of them or just on the primary | 329 | * if the user wants OPIE to run on all of them or just on the primary |
324 | */ | 330 | */ |
325 | static bool isMultiHead(); | 331 | static bool isMultiHead(); |
326 | 332 | ||
327 | private: | 333 | private: |
328 | /** | 334 | /** |
329 | * reads in all paths from kdeglobals | 335 | * reads in all paths from kdeglobals |
330 | */ | 336 | */ |
331 | static void initStatic(); | 337 | static void initStatic(); |
332 | /** | 338 | /** |
333 | * initialise kde2Blue | 339 | * initialise kde2Blue |
334 | */ | 340 | */ |
335 | static void initColors(); | 341 | static void initColors(); |
336 | /** | 342 | /** |
337 | * drop cached values for fonts (called by OApplication) | 343 | * drop cached values for fonts (called by OApplication) |
338 | */ | 344 | */ |
339 | static void rereadFontSettings(); | 345 | static void rereadFontSettings(); |
340 | /** | 346 | /** |
341 | * drop cached values for paths (called by OApplication) | 347 | * drop cached values for paths (called by OApplication) |
342 | */ | 348 | */ |
343 | static void rereadPathSettings(); | 349 | static void rereadPathSettings(); |
344 | /** | 350 | /** |
345 | * drop cached values for mouse settings (called by OApplication) | 351 | * drop cached values for mouse settings (called by OApplication) |
346 | */ | 352 | */ |
347 | static void rereadMouseSettings(); | 353 | static void rereadMouseSettings(); |
348 | 354 | ||
349 | 355 | ||
350 | static QString* s_desktopPath; | 356 | static QString* s_desktopPath; |
351 | static QString* s_autostartPath; | 357 | static QString* s_autostartPath; |
352 | static QString* s_trashPath; | 358 | static QString* s_trashPath; |
353 | static QString* s_documentPath; | 359 | static QString* s_documentPath; |
354 | static QFont *_generalFont; | 360 | static QFont *_generalFont; |
355 | static QFont *_fixedFont; | 361 | static QFont *_fixedFont; |
356 | static QFont *_toolBarFont; | 362 | static QFont *_toolBarFont; |
357 | static QFont *_menuFont; | 363 | static QFont *_menuFont; |
358 | static QFont *_windowTitleFont; | 364 | static QFont *_windowTitleFont; |
359 | static QFont *_taskbarFont; | 365 | static QFont *_taskbarFont; |
360 | static QColor * kde2Gray; | 366 | static QColor * kde2Gray; |
361 | static QColor * kde2Blue; | 367 | static QColor * kde2Blue; |
362 | static QColor * kde2AlternateColor; | 368 | static QColor * kde2AlternateColor; |
363 | static OMouseSettings *s_mouseSettings; | 369 | static OMouseSettings *s_mouseSettings; |
364 | 370 | ||
365 | static QColor * OpieGray; | 371 | static QColor * OpieGray; |
366 | static QColor * OpieBlue; | 372 | static QColor * OpieBlue; |
367 | static QColor * OpieAlternate; | 373 | static QColor * OpieAlternate; |
368 | static QColor * OpieHighlight; | 374 | static QColor * OpieHighlight; |
369 | 375 | ||
370 | friend class OApplication; | 376 | friend class OApplication; |
377 | private: | ||
378 | class Private; | ||
379 | Private *d; | ||
371 | }; | 380 | }; |
372 | 381 | ||
382 | } | ||
383 | } | ||
384 | |||
373 | #endif | 385 | #endif |
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index 523d6a7..ff3c036 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro | |||
@@ -1,41 +1,39 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = oapplication.h \ | 4 | HEADERS = oapplication.h \ |
5 | oconfig.h \ | 5 | oconfig.h \ |
6 | odebug.h \ | 6 | odebug.h \ |
7 | oglobal.h \ | 7 | oglobal.h \ |
8 | oglobalsettings.h \ | 8 | oglobalsettings.h \ |
9 | oprocess.h \ | 9 | oprocess.h \ |
10 | oprocctrl.h \ | 10 | oprocctrl.h \ |
11 | osmartpointer.h \ | 11 | osmartpointer.h \ |
12 | ostorageinfo.h \ | 12 | ostorageinfo.h |
13 | xmltree.h | ||
14 | 13 | ||
15 | SOURCES = oapplication.cpp \ | 14 | SOURCES = oapplication.cpp \ |
16 | oconfig.cpp \ | 15 | oconfig.cpp \ |
17 | odebug.cpp \ | 16 | odebug.cpp \ |
18 | oglobal.cpp \ | 17 | oglobal.cpp \ |
19 | oglobalsettings.cpp \ | 18 | oglobalsettings.cpp \ |
20 | oprocess.cpp \ | 19 | oprocess.cpp \ |
21 | oprocctrl.cpp \ | 20 | oprocctrl.cpp \ |
22 | ostorageinfo.cpp \ | 21 | ostorageinfo.cpp |
23 | xmltree.cc | ||
24 | 22 | ||
25 | include ( device/device.pro ) | 23 | include ( device/device.pro ) |
26 | 24 | ||
27 | INTERFACES = | 25 | INTERFACES = |
28 | TARGET = opiecore2 | 26 | TARGET = opiecore2 |
29 | VERSION = 1.8.5 | 27 | VERSION = 1.9.0 |
30 | INCLUDEPATH += $(OPIEDIR)/include | 28 | INCLUDEPATH += $(OPIEDIR)/include |
31 | DEPENDPATH += $(OPIEDIR)/include | 29 | DEPENDPATH += $(OPIEDIR)/include |
32 | 30 | ||
33 | !contains( platform, x11 ) { | 31 | !contains( platform, x11 ) { |
34 | LIBS = -lqpe | 32 | LIBS = -lqpe |
35 | include ( $(OPIEDIR)/include.pro ) | 33 | include ( $(OPIEDIR)/include.pro ) |
36 | } | 34 | } |
37 | 35 | ||
38 | contains( platform, x11 ) { | 36 | contains( platform, x11 ) { |
39 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 37 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
40 | } | 38 | } |
41 | 39 | ||
diff --git a/libopie2/opiecore/oprocctrl.cpp b/libopie2/opiecore/oprocctrl.cpp index 0403526..46708ba 100644 --- a/libopie2/opiecore/oprocctrl.cpp +++ b/libopie2/opiecore/oprocctrl.cpp | |||
@@ -1,235 +1,237 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | 2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | // | 19 | // |
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | 20 | // KPROCESSCONTROLLER -- A helper class for KProcess |
21 | // | 21 | // |
22 | // version 0.3.1, Jan, 8th 1997 | 22 | // version 0.3.1, Jan, 8th 1997 |
23 | // | 23 | // |
24 | // (C) Christian Czezatke | 24 | // (C) Christian Czezatke |
25 | // e9025461@student.tuwien.ac.at | 25 | // e9025461@student.tuwien.ac.at |
26 | // Ported by Holger Freyther | 26 | // Ported by Holger Freyther |
27 | // | 27 | // |
28 | 28 | ||
29 | //#include <config.h> | 29 | //#include <config.h> |
30 | 30 | ||
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <sys/socket.h> | 32 | #include <sys/socket.h> |
33 | 33 | ||
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | #include <fcntl.h> | 35 | #include <fcntl.h> |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <assert.h> | 39 | #include <assert.h> |
40 | 40 | ||
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include "oprocctrl.h" | 42 | #include "oprocctrl.h" |
43 | 43 | ||
44 | using namespace Opie::Core::Private; | ||
45 | |||
44 | OProcessController *OProcessController::theOProcessController = 0; | 46 | OProcessController *OProcessController::theOProcessController = 0; |
45 | 47 | ||
46 | struct sigaction OProcessController::oldChildHandlerData; | 48 | struct sigaction OProcessController::oldChildHandlerData; |
47 | bool OProcessController::handlerSet = false; | 49 | bool OProcessController::handlerSet = false; |
48 | 50 | ||
49 | OProcessController::OProcessController() | 51 | OProcessController::OProcessController() |
50 | { | 52 | { |
51 | assert( theOProcessController == 0 ); | 53 | assert( theOProcessController == 0 ); |
52 | 54 | ||
53 | if (0 > pipe(fd)) | 55 | if (0 > pipe(fd)) |
54 | printf(strerror(errno)); | 56 | printf(strerror(errno)); |
55 | 57 | ||
56 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); | 58 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); |
57 | notifier->setEnabled(true); | 59 | notifier->setEnabled(true); |
58 | QObject::connect(notifier, SIGNAL(activated(int)), | 60 | QObject::connect(notifier, SIGNAL(activated(int)), |
59 | this, SLOT(slotDoHousekeeping(int))); | 61 | this, SLOT(slotDoHousekeeping(int))); |
60 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), | 62 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), |
61 | SLOT( delayedChildrenCleanup())); | 63 | SLOT( delayedChildrenCleanup())); |
62 | 64 | ||
63 | theOProcessController = this; | 65 | theOProcessController = this; |
64 | 66 | ||
65 | setupHandlers(); | 67 | setupHandlers(); |
66 | } | 68 | } |
67 | 69 | ||
68 | 70 | ||
69 | void OProcessController::setupHandlers() | 71 | void OProcessController::setupHandlers() |
70 | { | 72 | { |
71 | if( handlerSet ) | 73 | if( handlerSet ) |
72 | return; | 74 | return; |
73 | struct sigaction act; | 75 | struct sigaction act; |
74 | act.sa_handler=theSigCHLDHandler; | 76 | act.sa_handler=theSigCHLDHandler; |
75 | sigemptyset(&(act.sa_mask)); | 77 | sigemptyset(&(act.sa_mask)); |
76 | sigaddset(&(act.sa_mask), SIGCHLD); | 78 | sigaddset(&(act.sa_mask), SIGCHLD); |
77 | // Make sure we don't block this signal. gdb tends to do that :-( | 79 | // Make sure we don't block this signal. gdb tends to do that :-( |
78 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); | 80 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); |
79 | 81 | ||
80 | act.sa_flags = SA_NOCLDSTOP; | 82 | act.sa_flags = SA_NOCLDSTOP; |
81 | 83 | ||
82 | // CC: take care of SunOS which automatically restarts interrupted system | 84 | // CC: take care of SunOS which automatically restarts interrupted system |
83 | // calls (and thus does not have SA_RESTART) | 85 | // calls (and thus does not have SA_RESTART) |
84 | 86 | ||
85 | #ifdef SA_RESTART | 87 | #ifdef SA_RESTART |
86 | act.sa_flags |= SA_RESTART; | 88 | act.sa_flags |= SA_RESTART; |
87 | #endif | 89 | #endif |
88 | 90 | ||
89 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); | 91 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); |
90 | 92 | ||
91 | act.sa_handler=SIG_IGN; | 93 | act.sa_handler=SIG_IGN; |
92 | sigemptyset(&(act.sa_mask)); | 94 | sigemptyset(&(act.sa_mask)); |
93 | sigaddset(&(act.sa_mask), SIGPIPE); | 95 | sigaddset(&(act.sa_mask), SIGPIPE); |
94 | act.sa_flags = 0; | 96 | act.sa_flags = 0; |
95 | sigaction( SIGPIPE, &act, 0L); | 97 | sigaction( SIGPIPE, &act, 0L); |
96 | handlerSet = true; | 98 | handlerSet = true; |
97 | } | 99 | } |
98 | 100 | ||
99 | void OProcessController::resetHandlers() | 101 | void OProcessController::resetHandlers() |
100 | { | 102 | { |
101 | if( !handlerSet ) | 103 | if( !handlerSet ) |
102 | return; | 104 | return; |
103 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); | 105 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); |
104 | // there should be no problem with SIGPIPE staying SIG_IGN | 106 | // there should be no problem with SIGPIPE staying SIG_IGN |
105 | handlerSet = false; | 107 | handlerSet = false; |
106 | } | 108 | } |
107 | 109 | ||
108 | // block SIGCHLD handler, because it accesses processList | 110 | // block SIGCHLD handler, because it accesses processList |
109 | void OProcessController::addOProcess( OProcess* p ) | 111 | void OProcessController::addOProcess( OProcess* p ) |
110 | { | 112 | { |
111 | sigset_t newset, oldset; | 113 | sigset_t newset, oldset; |
112 | sigemptyset( &newset ); | 114 | sigemptyset( &newset ); |
113 | sigaddset( &newset, SIGCHLD ); | 115 | sigaddset( &newset, SIGCHLD ); |
114 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | 116 | sigprocmask( SIG_BLOCK, &newset, &oldset ); |
115 | processList.append( p ); | 117 | processList.append( p ); |
116 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | 118 | sigprocmask( SIG_SETMASK, &oldset, 0 ); |
117 | } | 119 | } |
118 | 120 | ||
119 | void OProcessController::removeOProcess( OProcess* p ) | 121 | void OProcessController::removeOProcess( OProcess* p ) |
120 | { | 122 | { |
121 | sigset_t newset, oldset; | 123 | sigset_t newset, oldset; |
122 | sigemptyset( &newset ); | 124 | sigemptyset( &newset ); |
123 | sigaddset( &newset, SIGCHLD ); | 125 | sigaddset( &newset, SIGCHLD ); |
124 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | 126 | sigprocmask( SIG_BLOCK, &newset, &oldset ); |
125 | processList.remove( p ); | 127 | processList.remove( p ); |
126 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | 128 | sigprocmask( SIG_SETMASK, &oldset, 0 ); |
127 | } | 129 | } |
128 | 130 | ||
129 | //using a struct which contains both the pid and the status makes it easier to write | 131 | //using a struct which contains both the pid and the status makes it easier to write |
130 | //and read the data into the pipe | 132 | //and read the data into the pipe |
131 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received | 133 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received |
132 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) | 134 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) |
133 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX | 135 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX |
134 | struct waitdata | 136 | struct waitdata |
135 | { | 137 | { |
136 | pid_t pid; | 138 | pid_t pid; |
137 | int status; | 139 | int status; |
138 | }; | 140 | }; |
139 | 141 | ||
140 | void OProcessController::theSigCHLDHandler(int arg) | 142 | void OProcessController::theSigCHLDHandler(int arg) |
141 | { | 143 | { |
142 | struct waitdata wd; | 144 | struct waitdata wd; |
143 | // int status; | 145 | // int status; |
144 | // pid_t this_pid; | 146 | // pid_t this_pid; |
145 | int saved_errno; | 147 | int saved_errno; |
146 | 148 | ||
147 | saved_errno = errno; | 149 | saved_errno = errno; |
148 | // since waitpid and write change errno, we have to save it and restore it | 150 | // since waitpid and write change errno, we have to save it and restore it |
149 | // (Richard Stevens, Advanced programming in the Unix Environment) | 151 | // (Richard Stevens, Advanced programming in the Unix Environment) |
150 | 152 | ||
151 | bool found = false; | 153 | bool found = false; |
152 | if( theOProcessController != 0 ) | 154 | if( theOProcessController != 0 ) |
153 | { | 155 | { |
154 | // iterating the list doesn't perform any system call | 156 | // iterating the list doesn't perform any system call |
155 | for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin(); | 157 | for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin(); |
156 | it != theOProcessController->processList.end(); | 158 | it != theOProcessController->processList.end(); |
157 | ++it ) | 159 | ++it ) |
158 | { | 160 | { |
159 | if( !(*it)->isRunning()) | 161 | if( !(*it)->isRunning()) |
160 | continue; | 162 | continue; |
161 | wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); | 163 | wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); |
162 | if ( wd.pid > 0 ) | 164 | if ( wd.pid > 0 ) |
163 | { | 165 | { |
164 | ::write(theOProcessController->fd[1], &wd, sizeof(wd)); | 166 | ::write(theOProcessController->fd[1], &wd, sizeof(wd)); |
165 | found = true; | 167 | found = true; |
166 | } | 168 | } |
167 | } | 169 | } |
168 | } | 170 | } |
169 | if( !found && oldChildHandlerData.sa_handler != SIG_IGN | 171 | if( !found && oldChildHandlerData.sa_handler != SIG_IGN |
170 | && oldChildHandlerData.sa_handler != SIG_DFL ) | 172 | && oldChildHandlerData.sa_handler != SIG_DFL ) |
171 | oldChildHandlerData.sa_handler( arg ); // call the old handler | 173 | oldChildHandlerData.sa_handler( arg ); // call the old handler |
172 | // handle the rest | 174 | // handle the rest |
173 | if( theOProcessController != 0 ) | 175 | if( theOProcessController != 0 ) |
174 | { | 176 | { |
175 | static const struct waitdata dwd = { 0, 0 } | 177 | static const struct waitdata dwd = { 0, 0 } |
176 | ; // delayed waitpid() | 178 | ; // delayed waitpid() |
177 | ::write(theOProcessController->fd[1], &dwd, sizeof(dwd)); | 179 | ::write(theOProcessController->fd[1], &dwd, sizeof(dwd)); |
178 | } | 180 | } |
179 | else | 181 | else |
180 | { | 182 | { |
181 | int dummy; | 183 | int dummy; |
182 | while( waitpid( -1, &dummy, WNOHANG ) > 0 ) | 184 | while( waitpid( -1, &dummy, WNOHANG ) > 0 ) |
183 | ; | 185 | ; |
184 | } | 186 | } |
185 | 187 | ||
186 | errno = saved_errno; | 188 | errno = saved_errno; |
187 | } | 189 | } |
188 | 190 | ||
189 | 191 | ||
190 | 192 | ||
191 | void OProcessController::slotDoHousekeeping(int ) | 193 | void OProcessController::slotDoHousekeeping(int ) |
192 | { | 194 | { |
193 | unsigned int bytes_read = 0; | 195 | unsigned int bytes_read = 0; |
194 | unsigned int errcnt=0; | 196 | unsigned int errcnt=0; |
195 | // read pid and status from the pipe. | 197 | // read pid and status from the pipe. |
196 | struct waitdata wd; | 198 | struct waitdata wd; |
197 | while ((bytes_read < sizeof(wd)) && (errcnt < 50)) | 199 | while ((bytes_read < sizeof(wd)) && (errcnt < 50)) |
198 | { | 200 | { |
199 | int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); | 201 | int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); |
200 | if (r > 0) bytes_read += r; | 202 | if (r > 0) bytes_read += r; |
201 | else if (r < 0) errcnt++; | 203 | else if (r < 0) errcnt++; |
202 | } | 204 | } |
203 | if (errcnt >= 50) | 205 | if (errcnt >= 50) |
204 | { | 206 | { |
205 | fprintf(stderr, | 207 | fprintf(stderr, |
206 | "Error: Max. error count for pipe read " | 208 | "Error: Max. error count for pipe read " |
207 | "exceeded in OProcessController::slotDoHousekeeping\n"); | 209 | "exceeded in OProcessController::slotDoHousekeeping\n"); |
208 | return; // it makes no sense to continue here! | 210 | return; // it makes no sense to continue here! |
209 | } | 211 | } |
210 | if (bytes_read != sizeof(wd)) | 212 | if (bytes_read != sizeof(wd)) |
211 | { | 213 | { |
212 | fprintf(stderr, | 214 | fprintf(stderr, |
213 | "Error: Could not read info from signal handler %d <> %d!\n", | 215 | "Error: Could not read info from signal handler %d <> %d!\n", |
214 | bytes_read, sizeof(wd)); | 216 | bytes_read, sizeof(wd)); |
215 | return; // it makes no sense to continue here! | 217 | return; // it makes no sense to continue here! |
216 | } | 218 | } |
217 | if (wd.pid==0) | 219 | if (wd.pid==0) |
218 | { // special case, see delayedChildrenCleanup() | 220 | { // special case, see delayedChildrenCleanup() |
219 | delayedChildrenCleanupTimer.start( 1000, true ); | 221 | delayedChildrenCleanupTimer.start( 1000, true ); |
220 | return; | 222 | return; |
221 | } | 223 | } |
222 | 224 | ||
223 | for( QValueList<OProcess*>::ConstIterator it = processList.begin(); | 225 | for( QValueList<OProcess*>::ConstIterator it = processList.begin(); |
224 | it != processList.end(); | 226 | it != processList.end(); |
225 | ++it ) | 227 | ++it ) |
226 | { | 228 | { |
227 | OProcess* proc = *it; | 229 | OProcess* proc = *it; |
228 | if (proc->pid() == wd.pid) | 230 | if (proc->pid() == wd.pid) |
229 | { | 231 | { |
230 | // process has exited, so do emit the respective events | 232 | // process has exited, so do emit the respective events |
231 | if (proc->run_mode == OProcess::Block) | 233 | if (proc->run_mode == OProcess::Block) |
232 | { | 234 | { |
233 | // If the reads are done blocking then set the status in proc | 235 | // If the reads are done blocking then set the status in proc |
234 | // but do nothing else because OProcess will perform the other | 236 | // but do nothing else because OProcess will perform the other |
235 | // actions of processHasExited. | 237 | // actions of processHasExited. |
diff --git a/libopie2/opiecore/oprocctrl.h b/libopie2/opiecore/oprocctrl.h index 44b8a48..4922ba2 100644 --- a/libopie2/opiecore/oprocctrl.h +++ b/libopie2/opiecore/oprocctrl.h | |||
@@ -1,121 +1,129 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | 2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | // | 19 | // |
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | 20 | // KPROCESSCONTROLLER -- A helper class for KProcess |
21 | // | 21 | // |
22 | // version 0.3.1, Jan 8th 1997 | 22 | // version 0.3.1, Jan 8th 1997 |
23 | // | 23 | // |
24 | // (C) Christian Czezatke | 24 | // (C) Christian Czezatke |
25 | // e9025461@student.tuwien.ac.at | 25 | // e9025461@student.tuwien.ac.at |
26 | // Ported by Holger Freyther | 26 | // Ported by Holger Freyther |
27 | // | 27 | // |
28 | 28 | ||
29 | #ifndef __KPROCCTRL_H__ | 29 | #ifndef __KPROCCTRL_H__ |
30 | #define __KPROCCTRL_H__ | 30 | #define __KPROCCTRL_H__ |
31 | 31 | ||
32 | #include <qvaluelist.h> | 32 | #include <qvaluelist.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | 34 | ||
35 | #include "oprocess.h" | 35 | #include "oprocess.h" |
36 | 36 | ||
37 | class OProcessControllerPrivate; | ||
38 | class QSocketNotifier; | 37 | class QSocketNotifier; |
39 | 38 | ||
39 | |||
40 | namespace Opie { | ||
41 | namespace Core { | ||
42 | namespace Private { | ||
43 | class OProcessControllerPrivate; | ||
44 | |||
40 | /** | 45 | /** |
41 | * @short Used internally by @ref OProcess | 46 | * @short Used internally by @ref OProcess |
42 | * @internal | 47 | * @internal |
43 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> | 48 | * @author Christian Czezakte <e9025461@student.tuwien.ac.at> |
44 | * | 49 | * |
45 | * A class for internal use by OProcess only. -- Exactly one instance | 50 | * A class for internal use by OProcess only. -- Exactly one instance |
46 | * of this class is generated by the first instance of OProcess that is | 51 | * of this class is generated by the first instance of OProcess that is |
47 | * created (a pointer to it gets stored in @ref theOProcessController ). | 52 | * created (a pointer to it gets stored in @ref theOProcessController ). |
48 | * | 53 | * |
49 | * This class takes care of the actual (UN*X) signal handling. | 54 | * This class takes care of the actual (UN*X) signal handling. |
50 | */ | 55 | */ |
51 | class OProcessController : public QObject | 56 | class OProcessController : public QObject |
52 | { | 57 | { |
53 | Q_OBJECT | 58 | Q_OBJECT |
54 | 59 | ||
55 | public: | 60 | public: |
56 | OProcessController(); | 61 | OProcessController(); |
57 | ~OProcessController(); | 62 | ~OProcessController(); |
58 | //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...) | 63 | //CC: WARNING! Destructor Not virtual (but you don't derive classes from this anyhow...) |
59 | 64 | ||
60 | public: | 65 | public: |
61 | 66 | ||
62 | /** | 67 | /** |
63 | * Only a single instance of this class is allowed at a time, | 68 | * Only a single instance of this class is allowed at a time, |
64 | * and this static variable is used to track the one instance. | 69 | * and this static variable is used to track the one instance. |
65 | */ | 70 | */ |
66 | static OProcessController *theOProcessController; | 71 | static OProcessController *theOProcessController; |
67 | 72 | ||
68 | /** | 73 | /** |
69 | * Automatically called upon SIGCHLD. | 74 | * Automatically called upon SIGCHLD. |
70 | * | 75 | * |
71 | * Normally you do not need to do anything with this function but | 76 | * Normally you do not need to do anything with this function but |
72 | * if your application needs to disable SIGCHLD for some time for | 77 | * if your application needs to disable SIGCHLD for some time for |
73 | * reasons beyond your control, you should call this function afterwards | 78 | * reasons beyond your control, you should call this function afterwards |
74 | * to make sure that no SIGCHLDs where missed. | 79 | * to make sure that no SIGCHLDs where missed. |
75 | */ | 80 | */ |
76 | static void theSigCHLDHandler(int signal); | 81 | static void theSigCHLDHandler(int signal); |
77 | // handler for sigchld | 82 | // handler for sigchld |
78 | 83 | ||
79 | /** | 84 | /** |
80 | * @internal | 85 | * @internal |
81 | */ | 86 | */ |
82 | static void setupHandlers(); | 87 | static void setupHandlers(); |
83 | /** | 88 | /** |
84 | * @internal | 89 | * @internal |
85 | */ | 90 | */ |
86 | static void resetHandlers(); | 91 | static void resetHandlers(); |
87 | /** | 92 | /** |
88 | * @internal | 93 | * @internal |
89 | */ | 94 | */ |
90 | void addOProcess( OProcess* ); | 95 | void addOProcess( OProcess* ); |
91 | /** | 96 | /** |
92 | * @internal | 97 | * @internal |
93 | */ | 98 | */ |
94 | void removeOProcess( OProcess* ); | 99 | void removeOProcess( OProcess* ); |
95 | public slots: | 100 | public slots: |
96 | /** | 101 | /** |
97 | * @internal | 102 | * @internal |
98 | */ | 103 | */ |
99 | void slotDoHousekeeping(int socket); | 104 | void slotDoHousekeeping(int socket); |
100 | 105 | ||
101 | private slots: | 106 | private slots: |
102 | void delayedChildrenCleanup(); | 107 | void delayedChildrenCleanup(); |
103 | private: | 108 | private: |
104 | int fd[2]; | 109 | int fd[2]; |
105 | QSocketNotifier *notifier; | 110 | QSocketNotifier *notifier; |
106 | static struct sigaction oldChildHandlerData; | 111 | static struct sigaction oldChildHandlerData; |
107 | static bool handlerSet; | 112 | static bool handlerSet; |
108 | QValueList<OProcess*> processList; | 113 | QValueList<OProcess*> processList; |
109 | QTimer delayedChildrenCleanupTimer; | 114 | QTimer delayedChildrenCleanupTimer; |
110 | 115 | ||
111 | // Disallow assignment and copy-construction | 116 | // Disallow assignment and copy-construction |
112 | OProcessController( const OProcessController& ); | 117 | OProcessController( const OProcessController& ); |
113 | OProcessController& operator= ( const OProcessController& ); | 118 | OProcessController& operator= ( const OProcessController& ); |
114 | 119 | ||
115 | OProcessControllerPrivate *d; | 120 | OProcessControllerPrivate *d; |
116 | }; | 121 | }; |
117 | 122 | ||
123 | } | ||
124 | } | ||
125 | } | ||
118 | 126 | ||
119 | 127 | ||
120 | #endif | 128 | #endif |
121 | 129 | ||
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index 6349c83..dfde74a 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp | |||
@@ -1,267 +1,272 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2002-2004 Holger Freyther <zecke@handhelds.org> | 3 | Copyright (C) 2002-2004 Holger Freyther <zecke@handhelds.org> |
4 | and The Opie Team <opie-devel@handhelds.org> | 4 | and The Opie Team <opie-devel@handhelds.org> |
5 | =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) | 5 | =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "oprocctrl.h" | 31 | #include "oprocctrl.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/oprocess.h> | 34 | #include <opie2/oprocess.h> |
35 | 35 | ||
36 | /* QT */ | 36 | /* QT */ |
37 | 37 | ||
38 | #include <qapplication.h> | 38 | #include <qapplication.h> |
39 | #include <qdir.h> | 39 | #include <qdir.h> |
40 | #include <qmap.h> | 40 | #include <qmap.h> |
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <errno.h> | 45 | #include <errno.h> |
46 | #include <fcntl.h> | 46 | #include <fcntl.h> |
47 | #include <pwd.h> | 47 | #include <pwd.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <signal.h> | 49 | #include <signal.h> |
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <string.h> | 51 | #include <string.h> |
52 | #include <sys/time.h> | 52 | #include <sys/time.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
55 | #include <sys/socket.h> | 55 | #include <sys/socket.h> |
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | #ifdef HAVE_SYS_SELECT_H | 57 | #ifdef HAVE_SYS_SELECT_H |
58 | #include <sys/select.h> | 58 | #include <sys/select.h> |
59 | #endif | 59 | #endif |
60 | #ifdef HAVE_INITGROUPS | 60 | #ifdef HAVE_INITGROUPS |
61 | #include <grp.h> | 61 | #include <grp.h> |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | using namespace Opie::Core::Private; | ||
65 | |||
66 | namespace Opie { | ||
67 | namespace Core { | ||
68 | namespace Private { | ||
64 | class OProcessPrivate | 69 | class OProcessPrivate |
65 | { | 70 | { |
66 | public: | 71 | public: |
67 | OProcessPrivate() : useShell( false ) | 72 | OProcessPrivate() : useShell( false ) |
68 | { } | 73 | { } |
69 | 74 | ||
70 | bool useShell; | 75 | bool useShell; |
71 | QMap<QString, QString> env; | 76 | QMap<QString, QString> env; |
72 | QString wd; | 77 | QString wd; |
73 | QCString shell; | 78 | QCString shell; |
74 | }; | 79 | }; |
75 | 80 | } | |
76 | 81 | ||
77 | OProcess::OProcess( QObject *parent, const char *name ) | 82 | OProcess::OProcess( QObject *parent, const char *name ) |
78 | : QObject( parent, name ) | 83 | : QObject( parent, name ) |
79 | { | 84 | { |
80 | init ( ); | 85 | init ( ); |
81 | } | 86 | } |
82 | 87 | ||
83 | OProcess::OProcess( const QString &arg0, QObject *parent, const char *name ) | 88 | OProcess::OProcess( const QString &arg0, QObject *parent, const char *name ) |
84 | : QObject( parent, name ) | 89 | : QObject( parent, name ) |
85 | { | 90 | { |
86 | init ( ); | 91 | init ( ); |
87 | *this << arg0; | 92 | *this << arg0; |
88 | } | 93 | } |
89 | 94 | ||
90 | OProcess::OProcess( const QStringList &args, QObject *parent, const char *name ) | 95 | OProcess::OProcess( const QStringList &args, QObject *parent, const char *name ) |
91 | : QObject( parent, name ) | 96 | : QObject( parent, name ) |
92 | { | 97 | { |
93 | init ( ); | 98 | init ( ); |
94 | *this << args; | 99 | *this << args; |
95 | } | 100 | } |
96 | 101 | ||
97 | void OProcess::init ( ) | 102 | void OProcess::init ( ) |
98 | { | 103 | { |
99 | run_mode = NotifyOnExit; | 104 | run_mode = NotifyOnExit; |
100 | runs = false; | 105 | runs = false; |
101 | pid_ = 0; | 106 | pid_ = 0; |
102 | status = 0; | 107 | status = 0; |
103 | keepPrivs = false; | 108 | keepPrivs = false; |
104 | innot = 0; | 109 | innot = 0; |
105 | outnot = 0; | 110 | outnot = 0; |
106 | errnot = 0; | 111 | errnot = 0; |
107 | communication = NoCommunication; | 112 | communication = NoCommunication; |
108 | input_data = 0; | 113 | input_data = 0; |
109 | input_sent = 0; | 114 | input_sent = 0; |
110 | input_total = 0; | 115 | input_total = 0; |
111 | d = 0; | 116 | d = 0; |
112 | 117 | ||
113 | if ( 0 == OProcessController::theOProcessController ) | 118 | if ( 0 == OProcessController::theOProcessController ) |
114 | { | 119 | { |
115 | ( void ) new OProcessController(); | 120 | ( void ) new OProcessController(); |
116 | CHECK_PTR( OProcessController::theOProcessController ); | 121 | CHECK_PTR( OProcessController::theOProcessController ); |
117 | } | 122 | } |
118 | 123 | ||
119 | OProcessController::theOProcessController->addOProcess( this ); | 124 | OProcessController::theOProcessController->addOProcess( this ); |
120 | out[ 0 ] = out[ 1 ] = -1; | 125 | out[ 0 ] = out[ 1 ] = -1; |
121 | in[ 0 ] = in[ 1 ] = -1; | 126 | in[ 0 ] = in[ 1 ] = -1; |
122 | err[ 0 ] = err[ 1 ] = -1; | 127 | err[ 0 ] = err[ 1 ] = -1; |
123 | } | 128 | } |
124 | 129 | ||
125 | void OProcess::setEnvironment( const QString &name, const QString &value ) | 130 | void OProcess::setEnvironment( const QString &name, const QString &value ) |
126 | { | 131 | { |
127 | if ( !d ) | 132 | if ( !d ) |
128 | d = new OProcessPrivate; | 133 | d = new OProcessPrivate; |
129 | d->env.insert( name, value ); | 134 | d->env.insert( name, value ); |
130 | } | 135 | } |
131 | 136 | ||
132 | void OProcess::setWorkingDirectory( const QString &dir ) | 137 | void OProcess::setWorkingDirectory( const QString &dir ) |
133 | { | 138 | { |
134 | if ( !d ) | 139 | if ( !d ) |
135 | d = new OProcessPrivate; | 140 | d = new OProcessPrivate; |
136 | d->wd = dir; | 141 | d->wd = dir; |
137 | } | 142 | } |
138 | 143 | ||
139 | void OProcess::setupEnvironment() | 144 | void OProcess::setupEnvironment() |
140 | { | 145 | { |
141 | if ( d ) | 146 | if ( d ) |
142 | { | 147 | { |
143 | QMap<QString, QString>::Iterator it; | 148 | QMap<QString, QString>::Iterator it; |
144 | for ( it = d->env.begin(); it != d->env.end(); ++it ) | 149 | for ( it = d->env.begin(); it != d->env.end(); ++it ) |
145 | setenv( QFile::encodeName( it.key() ).data(), | 150 | setenv( QFile::encodeName( it.key() ).data(), |
146 | QFile::encodeName( it.data() ).data(), 1 ); | 151 | QFile::encodeName( it.data() ).data(), 1 ); |
147 | if ( !d->wd.isEmpty() ) | 152 | if ( !d->wd.isEmpty() ) |
148 | chdir( QFile::encodeName( d->wd ).data() ); | 153 | chdir( QFile::encodeName( d->wd ).data() ); |
149 | } | 154 | } |
150 | } | 155 | } |
151 | 156 | ||
152 | void OProcess::setRunPrivileged( bool keepPrivileges ) | 157 | void OProcess::setRunPrivileged( bool keepPrivileges ) |
153 | { | 158 | { |
154 | keepPrivs = keepPrivileges; | 159 | keepPrivs = keepPrivileges; |
155 | } | 160 | } |
156 | 161 | ||
157 | bool OProcess::runPrivileged() const | 162 | bool OProcess::runPrivileged() const |
158 | { | 163 | { |
159 | return keepPrivs; | 164 | return keepPrivs; |
160 | } | 165 | } |
161 | 166 | ||
162 | OProcess::~OProcess() | 167 | OProcess::~OProcess() |
163 | { | 168 | { |
164 | // destroying the OProcess instance sends a SIGKILL to the | 169 | // destroying the OProcess instance sends a SIGKILL to the |
165 | // child process (if it is running) after removing it from the | 170 | // child process (if it is running) after removing it from the |
166 | // list of valid processes (if the process is not started as | 171 | // list of valid processes (if the process is not started as |
167 | // "DontCare") | 172 | // "DontCare") |
168 | 173 | ||
169 | OProcessController::theOProcessController->removeOProcess( this ); | 174 | OProcessController::theOProcessController->removeOProcess( this ); |
170 | // this must happen before we kill the child | 175 | // this must happen before we kill the child |
171 | // TODO: block the signal while removing the current process from the process list | 176 | // TODO: block the signal while removing the current process from the process list |
172 | 177 | ||
173 | if ( runs && ( run_mode != DontCare ) ) | 178 | if ( runs && ( run_mode != DontCare ) ) |
174 | kill( SIGKILL ); | 179 | kill( SIGKILL ); |
175 | 180 | ||
176 | // Clean up open fd's and socket notifiers. | 181 | // Clean up open fd's and socket notifiers. |
177 | closeStdin(); | 182 | closeStdin(); |
178 | closeStdout(); | 183 | closeStdout(); |
179 | closeStderr(); | 184 | closeStderr(); |
180 | 185 | ||
181 | // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess | 186 | // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess |
182 | delete d; | 187 | delete d; |
183 | } | 188 | } |
184 | 189 | ||
185 | void OProcess::detach() | 190 | void OProcess::detach() |
186 | { | 191 | { |
187 | OProcessController::theOProcessController->removeOProcess( this ); | 192 | OProcessController::theOProcessController->removeOProcess( this ); |
188 | 193 | ||
189 | runs = false; | 194 | runs = false; |
190 | pid_ = 0; | 195 | pid_ = 0; |
191 | 196 | ||
192 | // Clean up open fd's and socket notifiers. | 197 | // Clean up open fd's and socket notifiers. |
193 | closeStdin(); | 198 | closeStdin(); |
194 | closeStdout(); | 199 | closeStdout(); |
195 | closeStderr(); | 200 | closeStderr(); |
196 | } | 201 | } |
197 | 202 | ||
198 | bool OProcess::setExecutable( const QString& proc ) | 203 | bool OProcess::setExecutable( const QString& proc ) |
199 | { | 204 | { |
200 | if ( runs ) | 205 | if ( runs ) |
201 | return false; | 206 | return false; |
202 | 207 | ||
203 | if ( proc.isEmpty() ) | 208 | if ( proc.isEmpty() ) |
204 | return false; | 209 | return false; |
205 | 210 | ||
206 | if ( !arguments.isEmpty() ) | 211 | if ( !arguments.isEmpty() ) |
207 | arguments.remove( arguments.begin() ); | 212 | arguments.remove( arguments.begin() ); |
208 | arguments.prepend( QFile::encodeName( proc ) ); | 213 | arguments.prepend( QFile::encodeName( proc ) ); |
209 | 214 | ||
210 | return true; | 215 | return true; |
211 | } | 216 | } |
212 | 217 | ||
213 | OProcess &OProcess::operator<<( const QStringList& args ) | 218 | OProcess &OProcess::operator<<( const QStringList& args ) |
214 | { | 219 | { |
215 | QStringList::ConstIterator it = args.begin(); | 220 | QStringList::ConstIterator it = args.begin(); |
216 | for ( ; it != args.end() ; ++it ) | 221 | for ( ; it != args.end() ; ++it ) |
217 | arguments.append( QFile::encodeName( *it ) ); | 222 | arguments.append( QFile::encodeName( *it ) ); |
218 | return *this; | 223 | return *this; |
219 | } | 224 | } |
220 | 225 | ||
221 | OProcess &OProcess::operator<<( const QCString& arg ) | 226 | OProcess &OProcess::operator<<( const QCString& arg ) |
222 | { | 227 | { |
223 | return operator<< ( arg.data() ); | 228 | return operator<< ( arg.data() ); |
224 | } | 229 | } |
225 | 230 | ||
226 | OProcess &OProcess::operator<<( const char* arg ) | 231 | OProcess &OProcess::operator<<( const char* arg ) |
227 | { | 232 | { |
228 | arguments.append( arg ); | 233 | arguments.append( arg ); |
229 | return *this; | 234 | return *this; |
230 | } | 235 | } |
231 | 236 | ||
232 | OProcess &OProcess::operator<<( const QString& arg ) | 237 | OProcess &OProcess::operator<<( const QString& arg ) |
233 | { | 238 | { |
234 | arguments.append( QFile::encodeName( arg ) ); | 239 | arguments.append( QFile::encodeName( arg ) ); |
235 | return *this; | 240 | return *this; |
236 | } | 241 | } |
237 | 242 | ||
238 | void OProcess::clearArguments() | 243 | void OProcess::clearArguments() |
239 | { | 244 | { |
240 | arguments.clear(); | 245 | arguments.clear(); |
241 | } | 246 | } |
242 | 247 | ||
243 | bool OProcess::start( RunMode runmode, Communication comm ) | 248 | bool OProcess::start( RunMode runmode, Communication comm ) |
244 | { | 249 | { |
245 | uint i; | 250 | uint i; |
246 | uint n = arguments.count(); | 251 | uint n = arguments.count(); |
247 | char **arglist; | 252 | char **arglist; |
248 | 253 | ||
249 | if ( runs || ( 0 == n ) ) | 254 | if ( runs || ( 0 == n ) ) |
250 | { | 255 | { |
251 | return false; // cannot start a process that is already running | 256 | return false; // cannot start a process that is already running |
252 | // or if no executable has been assigned | 257 | // or if no executable has been assigned |
253 | } | 258 | } |
254 | run_mode = runmode; | 259 | run_mode = runmode; |
255 | status = 0; | 260 | status = 0; |
256 | 261 | ||
257 | QCString shellCmd; | 262 | QCString shellCmd; |
258 | if ( d && d->useShell ) | 263 | if ( d && d->useShell ) |
259 | { | 264 | { |
260 | if ( d->shell.isEmpty() ) | 265 | if ( d->shell.isEmpty() ) |
261 | { | 266 | { |
262 | qWarning( "Could not find a valid shell" ); | 267 | qWarning( "Could not find a valid shell" ); |
263 | return false; | 268 | return false; |
264 | } | 269 | } |
265 | 270 | ||
266 | arglist = static_cast<char **>( malloc( ( 4 ) * sizeof( char * ) ) ); | 271 | arglist = static_cast<char **>( malloc( ( 4 ) * sizeof( char * ) ) ); |
267 | for ( i = 0; i < n; i++ ) | 272 | for ( i = 0; i < n; i++ ) |
@@ -752,192 +757,195 @@ void OProcess::commClose() | |||
752 | bool b_in = ( communication & Stdin ); | 757 | bool b_in = ( communication & Stdin ); |
753 | bool b_out = ( communication & Stdout ); | 758 | bool b_out = ( communication & Stdout ); |
754 | bool b_err = ( communication & Stderr ); | 759 | bool b_err = ( communication & Stderr ); |
755 | if ( b_in ) | 760 | if ( b_in ) |
756 | delete innot; | 761 | delete innot; |
757 | 762 | ||
758 | if ( b_out || b_err ) | 763 | if ( b_out || b_err ) |
759 | { | 764 | { |
760 | // If both channels are being read we need to make sure that one socket buffer | 765 | // If both channels are being read we need to make sure that one socket buffer |
761 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). | 766 | // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). |
762 | // Hence we need to use select. | 767 | // Hence we need to use select. |
763 | 768 | ||
764 | // Once one or other of the channels has reached EOF (or given an error) go back | 769 | // Once one or other of the channels has reached EOF (or given an error) go back |
765 | // to the usual mechanism. | 770 | // to the usual mechanism. |
766 | 771 | ||
767 | int fds_ready = 1; | 772 | int fds_ready = 1; |
768 | fd_set rfds; | 773 | fd_set rfds; |
769 | 774 | ||
770 | int max_fd = 0; | 775 | int max_fd = 0; |
771 | if ( b_out ) | 776 | if ( b_out ) |
772 | { | 777 | { |
773 | fcntl( out[ 0 ], F_SETFL, O_NONBLOCK ); | 778 | fcntl( out[ 0 ], F_SETFL, O_NONBLOCK ); |
774 | if ( out[ 0 ] > max_fd ) | 779 | if ( out[ 0 ] > max_fd ) |
775 | max_fd = out[ 0 ]; | 780 | max_fd = out[ 0 ]; |
776 | delete outnot; | 781 | delete outnot; |
777 | outnot = 0; | 782 | outnot = 0; |
778 | } | 783 | } |
779 | if ( b_err ) | 784 | if ( b_err ) |
780 | { | 785 | { |
781 | fcntl( err[ 0 ], F_SETFL, O_NONBLOCK ); | 786 | fcntl( err[ 0 ], F_SETFL, O_NONBLOCK ); |
782 | if ( err[ 0 ] > max_fd ) | 787 | if ( err[ 0 ] > max_fd ) |
783 | max_fd = err[ 0 ]; | 788 | max_fd = err[ 0 ]; |
784 | delete errnot; | 789 | delete errnot; |
785 | errnot = 0; | 790 | errnot = 0; |
786 | } | 791 | } |
787 | 792 | ||
788 | 793 | ||
789 | while ( b_out || b_err ) | 794 | while ( b_out || b_err ) |
790 | { | 795 | { |
791 | // * If the process is still running we block until we | 796 | // * If the process is still running we block until we |
792 | // receive data. (p_timeout = 0, no timeout) | 797 | // receive data. (p_timeout = 0, no timeout) |
793 | // * If the process has already exited, we only check | 798 | // * If the process has already exited, we only check |
794 | // the available data, we don't wait for more. | 799 | // the available data, we don't wait for more. |
795 | // (p_timeout = &timeout, timeout immediately) | 800 | // (p_timeout = &timeout, timeout immediately) |
796 | struct timeval timeout; | 801 | struct timeval timeout; |
797 | timeout.tv_sec = 0; | 802 | timeout.tv_sec = 0; |
798 | timeout.tv_usec = 0; | 803 | timeout.tv_usec = 0; |
799 | struct timeval *p_timeout = runs ? 0 : &timeout; | 804 | struct timeval *p_timeout = runs ? 0 : &timeout; |
800 | 805 | ||
801 | FD_ZERO( &rfds ); | 806 | FD_ZERO( &rfds ); |
802 | if ( b_out ) | 807 | if ( b_out ) |
803 | FD_SET( out[ 0 ], &rfds ); | 808 | FD_SET( out[ 0 ], &rfds ); |
804 | 809 | ||
805 | if ( b_err ) | 810 | if ( b_err ) |
806 | FD_SET( err[ 0 ], &rfds ); | 811 | FD_SET( err[ 0 ], &rfds ); |
807 | 812 | ||
808 | fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout ); | 813 | fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout ); |
809 | if ( fds_ready <= 0 ) | 814 | if ( fds_ready <= 0 ) |
810 | break; | 815 | break; |
811 | 816 | ||
812 | if ( b_out && FD_ISSET( out[ 0 ], &rfds ) ) | 817 | if ( b_out && FD_ISSET( out[ 0 ], &rfds ) ) |
813 | { | 818 | { |
814 | int ret = 1; | 819 | int ret = 1; |
815 | while ( ret > 0 ) | 820 | while ( ret > 0 ) |
816 | ret = childOutput( out[ 0 ] ); | 821 | ret = childOutput( out[ 0 ] ); |
817 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) | 822 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) |
818 | b_out = false; | 823 | b_out = false; |
819 | } | 824 | } |
820 | 825 | ||
821 | if ( b_err && FD_ISSET( err[ 0 ], &rfds ) ) | 826 | if ( b_err && FD_ISSET( err[ 0 ], &rfds ) ) |
822 | { | 827 | { |
823 | int ret = 1; | 828 | int ret = 1; |
824 | while ( ret > 0 ) | 829 | while ( ret > 0 ) |
825 | ret = childError( err[ 0 ] ); | 830 | ret = childError( err[ 0 ] ); |
826 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) | 831 | if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) |
827 | b_err = false; | 832 | b_err = false; |
828 | } | 833 | } |
829 | } | 834 | } |
830 | } | 835 | } |
831 | 836 | ||
832 | if ( b_in ) | 837 | if ( b_in ) |
833 | { | 838 | { |
834 | communication = ( Communication ) ( communication & ~Stdin ); | 839 | communication = ( Communication ) ( communication & ~Stdin ); |
835 | close( in[ 1 ] ); | 840 | close( in[ 1 ] ); |
836 | } | 841 | } |
837 | if ( b_out ) | 842 | if ( b_out ) |
838 | { | 843 | { |
839 | communication = ( Communication ) ( communication & ~Stdout ); | 844 | communication = ( Communication ) ( communication & ~Stdout ); |
840 | close( out[ 0 ] ); | 845 | close( out[ 0 ] ); |
841 | } | 846 | } |
842 | if ( b_err ) | 847 | if ( b_err ) |
843 | { | 848 | { |
844 | communication = ( Communication ) ( communication & ~Stderr ); | 849 | communication = ( Communication ) ( communication & ~Stderr ); |
845 | close( err[ 0 ] ); | 850 | close( err[ 0 ] ); |
846 | } | 851 | } |
847 | } | 852 | } |
848 | } | 853 | } |
849 | 854 | ||
850 | void OProcess::setUseShell( bool useShell, const char *shell ) | 855 | void OProcess::setUseShell( bool useShell, const char *shell ) |
851 | { | 856 | { |
852 | if ( !d ) | 857 | if ( !d ) |
853 | d = new OProcessPrivate; | 858 | d = new OProcessPrivate; |
854 | d->useShell = useShell; | 859 | d->useShell = useShell; |
855 | d->shell = shell; | 860 | d->shell = shell; |
856 | if ( d->shell.isEmpty() ) | 861 | if ( d->shell.isEmpty() ) |
857 | d->shell = searchShell(); | 862 | d->shell = searchShell(); |
858 | } | 863 | } |
859 | 864 | ||
860 | QString OProcess::quote( const QString &arg ) | 865 | QString OProcess::quote( const QString &arg ) |
861 | { | 866 | { |
862 | QString res = arg; | 867 | QString res = arg; |
863 | res.replace( QRegExp( QString::fromLatin1( "\'" ) ), | 868 | res.replace( QRegExp( QString::fromLatin1( "\'" ) ), |
864 | QString::fromLatin1( "'\"'\"'" ) ); | 869 | QString::fromLatin1( "'\"'\"'" ) ); |
865 | res.prepend( '\'' ); | 870 | res.prepend( '\'' ); |
866 | res.append( '\'' ); | 871 | res.append( '\'' ); |
867 | return res; | 872 | return res; |
868 | } | 873 | } |
869 | 874 | ||
870 | QCString OProcess::searchShell() | 875 | QCString OProcess::searchShell() |
871 | { | 876 | { |
872 | QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); | 877 | QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); |
873 | if ( !isExecutable( tmpShell ) ) | 878 | if ( !isExecutable( tmpShell ) ) |
874 | { | 879 | { |
875 | tmpShell = "/bin/sh"; | 880 | tmpShell = "/bin/sh"; |
876 | } | 881 | } |
877 | 882 | ||
878 | return tmpShell; | 883 | return tmpShell; |
879 | } | 884 | } |
880 | 885 | ||
881 | bool OProcess::isExecutable( const QCString &filename ) | 886 | bool OProcess::isExecutable( const QCString &filename ) |
882 | { | 887 | { |
883 | struct stat fileinfo; | 888 | struct stat fileinfo; |
884 | 889 | ||
885 | if ( filename.isEmpty() ) | 890 | if ( filename.isEmpty() ) |
886 | return false; | 891 | return false; |
887 | 892 | ||
888 | // CC: we've got a valid filename, now let's see whether we can execute that file | 893 | // CC: we've got a valid filename, now let's see whether we can execute that file |
889 | 894 | ||
890 | if ( -1 == stat( filename.data(), &fileinfo ) ) | 895 | if ( -1 == stat( filename.data(), &fileinfo ) ) |
891 | return false; | 896 | return false; |
892 | // CC: return false if the file does not exist | 897 | // CC: return false if the file does not exist |
893 | 898 | ||
894 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets | 899 | // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets |
895 | if ( ( S_ISDIR( fileinfo.st_mode ) ) || | 900 | if ( ( S_ISDIR( fileinfo.st_mode ) ) || |
896 | ( S_ISCHR( fileinfo.st_mode ) ) || | 901 | ( S_ISCHR( fileinfo.st_mode ) ) || |
897 | ( S_ISBLK( fileinfo.st_mode ) ) || | 902 | ( S_ISBLK( fileinfo.st_mode ) ) || |
898 | #ifdef S_ISSOCK | 903 | #ifdef S_ISSOCK |
899 | // CC: SYSVR4 systems don't have that macro | 904 | // CC: SYSVR4 systems don't have that macro |
900 | ( S_ISSOCK( fileinfo.st_mode ) ) || | 905 | ( S_ISSOCK( fileinfo.st_mode ) ) || |
901 | #endif | 906 | #endif |
902 | ( S_ISFIFO( fileinfo.st_mode ) ) || | 907 | ( S_ISFIFO( fileinfo.st_mode ) ) || |
903 | ( S_ISDIR( fileinfo.st_mode ) ) ) | 908 | ( S_ISDIR( fileinfo.st_mode ) ) ) |
904 | { | 909 | { |
905 | return false; | 910 | return false; |
906 | } | 911 | } |
907 | 912 | ||
908 | // CC: now check for permission to execute the file | 913 | // CC: now check for permission to execute the file |
909 | if ( access( filename.data(), X_OK ) != 0 ) | 914 | if ( access( filename.data(), X_OK ) != 0 ) |
910 | return false; | 915 | return false; |
911 | 916 | ||
912 | // CC: we've passed all the tests... | 917 | // CC: we've passed all the tests... |
913 | return true; | 918 | return true; |
914 | } | 919 | } |
915 | 920 | ||
916 | int OProcess::processPID( const QString& process ) | 921 | int OProcess::processPID( const QString& process ) |
917 | { | 922 | { |
918 | QString line; | 923 | QString line; |
919 | QDir d = QDir( "/proc" ); | 924 | QDir d = QDir( "/proc" ); |
920 | QStringList dirs = d.entryList( QDir::Dirs ); | 925 | QStringList dirs = d.entryList( QDir::Dirs ); |
921 | QStringList::Iterator it; | 926 | QStringList::Iterator it; |
922 | for ( it = dirs.begin(); it != dirs.end(); ++it ) | 927 | for ( it = dirs.begin(); it != dirs.end(); ++it ) |
923 | { | 928 | { |
924 | //qDebug( "next entry: %s", (const char*) *it ); | 929 | //qDebug( "next entry: %s", (const char*) *it ); |
925 | QFile file( "/proc/"+*it+"/cmdline" ); | 930 | QFile file( "/proc/"+*it+"/cmdline" ); |
926 | file.open( IO_ReadOnly ); | 931 | file.open( IO_ReadOnly ); |
927 | if ( !file.isOpen() ) continue; | 932 | if ( !file.isOpen() ) continue; |
928 | QTextStream t( &file ); | 933 | QTextStream t( &file ); |
929 | line = t.readLine(); | 934 | line = t.readLine(); |
930 | //qDebug( "cmdline = %s", (const char*) line ); | 935 | //qDebug( "cmdline = %s", (const char*) line ); |
931 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) | 936 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) |
932 | } | 937 | } |
933 | if ( line.contains( process ) ) | 938 | if ( line.contains( process ) ) |
934 | { | 939 | { |
935 | //qDebug( "found process id #%d", (*it).toInt() ); | 940 | //qDebug( "found process id #%d", (*it).toInt() ); |
936 | return (*it).toInt(); | 941 | return (*it).toInt(); |
937 | } | 942 | } |
938 | else | 943 | else |
939 | { | 944 | { |
940 | //qDebug( "process '%s' not found", (const char*) process ); | 945 | //qDebug( "process '%s' not found", (const char*) process ); |
941 | return 0; | 946 | return 0; |
942 | } | 947 | } |
943 | } | 948 | } |
949 | |||
950 | } | ||
951 | } | ||
diff --git a/libopie2/opiecore/oprocess.h b/libopie2/opiecore/oprocess.h index 1a2472d..eb56b03 100644 --- a/libopie2/opiecore/oprocess.h +++ b/libopie2/opiecore/oprocess.h | |||
@@ -1,752 +1,761 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 Holger Freyther <zecke@handhelds.org> | 3 | Copyright (C) 2003-2004 Holger Freyther <zecke@handhelds.org> |
4 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) | 5 | =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OPROCESS_H | 31 | #ifndef OPROCESS_H |
32 | #define OPROCESS_H | 32 | #define OPROCESS_H |
33 | 33 | ||
34 | /* QT */ | 34 | /* QT */ |
35 | #include <qcstring.h> | 35 | #include <qcstring.h> |
36 | #include <qobject.h> | 36 | #include <qobject.h> |
37 | #include <qvaluelist.h> | 37 | #include <qvaluelist.h> |
38 | 38 | ||
39 | /* STD */ | 39 | /* STD */ |
40 | #include <sys/types.h> // for pid_t | 40 | #include <sys/types.h> // for pid_t |
41 | #include <sys/wait.h> | 41 | #include <sys/wait.h> |
42 | #include <signal.h> | 42 | #include <signal.h> |
43 | #include <unistd.h> | 43 | #include <unistd.h> |
44 | 44 | ||
45 | class QSocketNotifier; | 45 | class QSocketNotifier; |
46 | |||
47 | namespace Opie { | ||
48 | namespace Core { | ||
49 | namespace Private { | ||
50 | class OProcessController; | ||
46 | class OProcessPrivate; | 51 | class OProcessPrivate; |
52 | } | ||
47 | 53 | ||
48 | /** | 54 | /** |
49 | * Child process invocation, monitoring and control. | 55 | * Child process invocation, monitoring and control. |
50 | * | 56 | * |
51 | * @sect General usage and features | 57 | * @sect General usage and features |
52 | * | 58 | * |
53 | *This class allows a KDE and OPIE application to start child processes without having | 59 | *This class allows a KDE and OPIE application to start child processes without having |
54 | *to worry about UN*X signal handling issues and zombie process reaping. | 60 | *to worry about UN*X signal handling issues and zombie process reaping. |
55 | * | 61 | * |
56 | *@see KProcIO | 62 | *@see KProcIO |
57 | * | 63 | * |
58 | *Basically, this class distinguishes three different ways of running | 64 | *Basically, this class distinguishes three different ways of running |
59 | *child processes: | 65 | *child processes: |
60 | * | 66 | * |
61 | *@li OProcess::DontCare -- The child process is invoked and both the child | 67 | *@li OProcess::DontCare -- The child process is invoked and both the child |
62 | *process and the parent process continue concurrently. | 68 | *process and the parent process continue concurrently. |
63 | * | 69 | * |
64 | *Starting a DontCare child process means that the application is | 70 | *Starting a DontCare child process means that the application is |
65 | *not interested in any notification to determine whether the | 71 | *not interested in any notification to determine whether the |
66 | *child process has already exited or not. | 72 | *child process has already exited or not. |
67 | * | 73 | * |
68 | *@li OProcess::NotifyOnExit -- The child process is invoked and both the | 74 | *@li OProcess::NotifyOnExit -- The child process is invoked and both the |
69 | *child and the parent process run concurrently. | 75 | *child and the parent process run concurrently. |
70 | * | 76 | * |
71 | *When the child process exits, the OProcess instance | 77 | *When the child process exits, the OProcess instance |
72 | *corresponding to it emits the Qt signal @ref processExited(). | 78 | *corresponding to it emits the Qt signal @ref processExited(). |
73 | * | 79 | * |
74 | *Since this signal is @em not emitted from within a UN*X | 80 | *Since this signal is @em not emitted from within a UN*X |
75 | *signal handler, arbitrary function calls can be made. | 81 | *signal handler, arbitrary function calls can be made. |
76 | * | 82 | * |
77 | *Be aware: When the OProcess objects gets destructed, the child | 83 | *Be aware: When the OProcess objects gets destructed, the child |
78 | *process will be killed if it is still running! | 84 | *process will be killed if it is still running! |
79 | *This means in particular, that you cannot use a OProcess on the stack | 85 | *This means in particular, that you cannot use a OProcess on the stack |
80 | *with OProcess::NotifyOnExit. | 86 | *with OProcess::NotifyOnExit. |
81 | * | 87 | * |
82 | *@li OProcess::Block -- The child process starts and the parent process | 88 | *@li OProcess::Block -- The child process starts and the parent process |
83 | *is suspended until the child process exits. (@em Really not recommended | 89 | *is suspended until the child process exits. (@em Really not recommended |
84 | *for programs with a GUI.) | 90 | *for programs with a GUI.) |
85 | * | 91 | * |
86 | *OProcess also provides several functions for determining the exit status | 92 | *OProcess also provides several functions for determining the exit status |
87 | *and the pid of the child process it represents. | 93 | *and the pid of the child process it represents. |
88 | * | 94 | * |
89 | *Furthermore it is possible to supply command-line arguments to the process | 95 | *Furthermore it is possible to supply command-line arguments to the process |
90 | *in a clean fashion (no null -- terminated stringlists and such...) | 96 | *in a clean fashion (no null -- terminated stringlists and such...) |
91 | * | 97 | * |
92 | *A small usage example: | 98 | *A small usage example: |
93 | *<pre> | 99 | *<pre> |
94 | *OProcess *proc = new OProcess; | 100 | *OProcess *proc = new OProcess; |
95 | * | 101 | * |
96 | **proc << "my_executable"; | 102 | **proc << "my_executable"; |
97 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; | 103 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; |
98 | *QApplication::connect(proc, SIGNAL(processExited(OProcess *)), | 104 | *QApplication::connect(proc, SIGNAL(processExited(OProcess *)), |
99 | * pointer_to_my_object, SLOT(my_objects_slot(OProcess *))); | 105 | * pointer_to_my_object, SLOT(my_objects_slot(OProcess *))); |
100 | *proc->start(); | 106 | *proc->start(); |
101 | *</pre> | 107 | *</pre> |
102 | * | 108 | * |
103 | *This will start "my_executable" with the commandline arguments "These"... | 109 | *This will start "my_executable" with the commandline arguments "These"... |
104 | * | 110 | * |
105 | *When the child process exits, the respective Qt signal will be emitted. | 111 | *When the child process exits, the respective Qt signal will be emitted. |
106 | * | 112 | * |
107 | *@sect Communication with the child process | 113 | *@sect Communication with the child process |
108 | * | 114 | * |
109 | *OProcess supports communication with the child process through | 115 | *OProcess supports communication with the child process through |
110 | *stdin/stdout/stderr. | 116 | *stdin/stdout/stderr. |
111 | * | 117 | * |
112 | *The following functions are provided for getting data from the child | 118 | *The following functions are provided for getting data from the child |
113 | *process or sending data to the child's stdin (For more information, | 119 | *process or sending data to the child's stdin (For more information, |
114 | *have a look at the documentation of each function): | 120 | *have a look at the documentation of each function): |
115 | * | 121 | * |
116 | *@li bool @ref writeStdin(char *buffer, int buflen); | 122 | *@li bool @ref writeStdin(char *buffer, int buflen); |
117 | *@li -- Transmit data to the child process's stdin. | 123 | *@li -- Transmit data to the child process's stdin. |
118 | * | 124 | * |
119 | *@li bool @ref closeStdin(); | 125 | *@li bool @ref closeStdin(); |
120 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). | 126 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). |
121 | *Returns false if you try to close stdin for a process that has been started | 127 | *Returns false if you try to close stdin for a process that has been started |
122 | *without a communication channel to stdin. | 128 | *without a communication channel to stdin. |
123 | * | 129 | * |
124 | *@li bool @ref closeStdout(); | 130 | *@li bool @ref closeStdout(); |
125 | *@li -- Closes the child process's stdout. | 131 | *@li -- Closes the child process's stdout. |
126 | *Returns false if you try to close stdout for a process that has been started | 132 | *Returns false if you try to close stdout for a process that has been started |
127 | *without a communication channel to stdout. | 133 | *without a communication channel to stdout. |
128 | * | 134 | * |
129 | *@li bool @ref closeStderr(); | 135 | *@li bool @ref closeStderr(); |
130 | *@li -- Closes the child process's stderr. | 136 | *@li -- Closes the child process's stderr. |
131 | *Returns false if you try to close stderr for a process that has been started | 137 | *Returns false if you try to close stderr for a process that has been started |
132 | *without a communication channel to stderr. | 138 | *without a communication channel to stderr. |
133 | * | 139 | * |
134 | * | 140 | * |
135 | *@sect QT signals: | 141 | *@sect QT signals: |
136 | * | 142 | * |
137 | *@li void @ref receivedStdout(OProcess *proc, char *buffer, int buflen); | 143 | *@li void @ref receivedStdout(OProcess *proc, char *buffer, int buflen); |
138 | *@li void @ref receivedStderr(OProcess *proc, char *buffer, int buflen); | 144 | *@li void @ref receivedStderr(OProcess *proc, char *buffer, int buflen); |
139 | *@li -- Indicates that new data has arrived from either the | 145 | *@li -- Indicates that new data has arrived from either the |
140 | *child process's stdout or stderr. | 146 | *child process's stdout or stderr. |
141 | * | 147 | * |
142 | *@li void @ref wroteStdin(OProcess *proc); | 148 | *@li void @ref wroteStdin(OProcess *proc); |
143 | *@li -- Indicates that all data that has been sent to the child process | 149 | *@li -- Indicates that all data that has been sent to the child process |
144 | *by a prior call to @ref writeStdin() has actually been transmitted to the | 150 | *by a prior call to @ref writeStdin() has actually been transmitted to the |
145 | *client . | 151 | *client . |
146 | * | 152 | * |
147 | *@author Christian Czezakte e9025461@student.tuwien.ac.at | 153 | *@author Christian Czezakte e9025461@student.tuwien.ac.at |
148 | *@author Holger Freyther (Opie Port) | 154 | *@author Holger Freyther (Opie Port) |
149 | * | 155 | * |
150 | **/ | 156 | **/ |
151 | class OProcess : public QObject | 157 | class OProcess : public QObject |
152 | { | 158 | { |
153 | Q_OBJECT | 159 | Q_OBJECT |
154 | 160 | ||
155 | public: | 161 | public: |
156 | 162 | ||
157 | /** | 163 | /** |
158 | * Modes in which the communication channel can be opened. | 164 | * Modes in which the communication channel can be opened. |
159 | * | 165 | * |
160 | * If communication for more than one channel is required, | 166 | * If communication for more than one channel is required, |
161 | * the values have to be or'ed together, for example to get | 167 | * the values have to be or'ed together, for example to get |
162 | * communication with stdout as well as with stdin, you would | 168 | * communication with stdout as well as with stdin, you would |
163 | * specify @p Stdin @p | @p Stdout | 169 | * specify @p Stdin @p | @p Stdout |
164 | * | 170 | * |
165 | * If @p NoRead is specified in conjunction with @p Stdout, | 171 | * If @p NoRead is specified in conjunction with @p Stdout, |
166 | * no data is actually read from @p Stdout but only | 172 | * no data is actually read from @p Stdout but only |
167 | * the signal @ref childOutput(int fd) is emitted. | 173 | * the signal @ref childOutput(int fd) is emitted. |
168 | */ | 174 | */ |
169 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, | 175 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, |
170 | AllOutput = 6, All = 7, | 176 | AllOutput = 6, All = 7, |
171 | NoRead }; | 177 | NoRead }; |
172 | 178 | ||
173 | /** | 179 | /** |
174 | * Run-modes for a child process. | 180 | * Run-modes for a child process. |
175 | */ | 181 | */ |
176 | enum RunMode { | 182 | enum RunMode { |
177 | /** | 183 | /** |
178 | * The application does not receive notifications from the subprocess when | 184 | * The application does not receive notifications from the subprocess when |
179 | * it is finished or aborted. | 185 | * it is finished or aborted. |
180 | */ | 186 | */ |
181 | DontCare, | 187 | DontCare, |
182 | /** | 188 | /** |
183 | * The application is notified when the subprocess dies. | 189 | * The application is notified when the subprocess dies. |
184 | */ | 190 | */ |
185 | NotifyOnExit, | 191 | NotifyOnExit, |
186 | /** | 192 | /** |
187 | * The application is suspended until the started process is finished. | 193 | * The application is suspended until the started process is finished. |
188 | */ | 194 | */ |
189 | Block }; | 195 | Block }; |
190 | 196 | ||
191 | /** | 197 | /** |
192 | * Constructor | 198 | * Constructor |
193 | */ | 199 | */ |
194 | OProcess( QObject *parent = 0, const char *name = 0 ); | 200 | OProcess( QObject *parent = 0, const char *name = 0 ); |
195 | /** | 201 | /** |
196 | * Constructor | 202 | * Constructor |
197 | */ | 203 | */ |
198 | OProcess( const QString &arg0, QObject *parent = 0, const char *name = 0 ); | 204 | OProcess( const QString &arg0, QObject *parent = 0, const char *name = 0 ); |
199 | /** | 205 | /** |
200 | * Constructor | 206 | * Constructor |
201 | */ | 207 | */ |
202 | OProcess( const QStringList &args, QObject *parent = 0, const char *name = 0 ); | 208 | OProcess( const QStringList &args, QObject *parent = 0, const char *name = 0 ); |
203 | 209 | ||
204 | /** | 210 | /** |
205 | *Destructor: | 211 | *Destructor: |
206 | * | 212 | * |
207 | * If the process is running when the destructor for this class | 213 | * If the process is running when the destructor for this class |
208 | * is called, the child process is killed with a SIGKILL, but | 214 | * is called, the child process is killed with a SIGKILL, but |
209 | * only if the run mode is not of type @p DontCare. | 215 | * only if the run mode is not of type @p DontCare. |
210 | * Processes started as @p DontCare keep running anyway. | 216 | * Processes started as @p DontCare keep running anyway. |
211 | */ | 217 | */ |
212 | virtual ~OProcess(); | 218 | virtual ~OProcess(); |
213 | 219 | ||
214 | /** | 220 | /** |
215 | @deprecated | 221 | @deprecated |
216 | 222 | ||
217 | The use of this function is now deprecated. -- Please use the | 223 | The use of this function is now deprecated. -- Please use the |
218 | "operator<<" instead of "setExecutable". | 224 | "operator<<" instead of "setExecutable". |
219 | 225 | ||
220 | Sets the executable to be started with this OProcess object. | 226 | Sets the executable to be started with this OProcess object. |
221 | Returns false if the process is currently running (in that | 227 | Returns false if the process is currently running (in that |
222 | case the executable remains unchanged.) | 228 | case the executable remains unchanged.) |
223 | 229 | ||
224 | @see operator<< | 230 | @see operator<< |
225 | 231 | ||
226 | */ | 232 | */ |
227 | bool setExecutable( const QString& proc ); | 233 | bool setExecutable( const QString& proc ); |
228 | 234 | ||
229 | 235 | ||
230 | /** | 236 | /** |
231 | * Sets the executable and the command line argument list for this process. | 237 | * Sets the executable and the command line argument list for this process. |
232 | * | 238 | * |
233 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: | 239 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: |
234 | * <pre> | 240 | * <pre> |
235 | * OProcess p; | 241 | * OProcess p; |
236 | * ... | 242 | * ... |
237 | * p << "ls" << "-l" << "/usr/local/bin" | 243 | * p << "ls" << "-l" << "/usr/local/bin" |
238 | * </pre> | 244 | * </pre> |
239 | * | 245 | * |
240 | **/ | 246 | **/ |
241 | OProcess &operator<<( const QString& arg ); | 247 | OProcess &operator<<( const QString& arg ); |
242 | /** | 248 | /** |
243 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. | 249 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. |
244 | */ | 250 | */ |
245 | OProcess &operator<<( const char * arg ); | 251 | OProcess &operator<<( const char * arg ); |
246 | /** | 252 | /** |
247 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. | 253 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. |
248 | */ | 254 | */ |
249 | OProcess &operator<<( const QCString & arg ); | 255 | OProcess &operator<<( const QCString & arg ); |
250 | 256 | ||
251 | /** | 257 | /** |
252 | * Sets the executable and the command line argument list for this process, | 258 | * Sets the executable and the command line argument list for this process, |
253 | * in a single method call, or add a list of arguments. | 259 | * in a single method call, or add a list of arguments. |
254 | **/ | 260 | **/ |
255 | OProcess &operator<<( const QStringList& args ); | 261 | OProcess &operator<<( const QStringList& args ); |
256 | 262 | ||
257 | /** | 263 | /** |
258 | * Clear a command line argument list that has been set by using | 264 | * Clear a command line argument list that has been set by using |
259 | * the "operator<<". | 265 | * the "operator<<". |
260 | */ | 266 | */ |
261 | void clearArguments(); | 267 | void clearArguments(); |
262 | 268 | ||
263 | /** | 269 | /** |
264 | * Starts the process. | 270 | * Starts the process. |
265 | * For a detailed description of the | 271 | * For a detailed description of the |
266 | * various run modes and communication semantics, have a look at the | 272 | * various run modes and communication semantics, have a look at the |
267 | * general description of the OProcess class. | 273 | * general description of the OProcess class. |
268 | * | 274 | * |
269 | * The following problems could cause this function to | 275 | * The following problems could cause this function to |
270 | * return false: | 276 | * return false: |
271 | * | 277 | * |
272 | * @li The process is already running. | 278 | * @li The process is already running. |
273 | * @li The command line argument list is empty. | 279 | * @li The command line argument list is empty. |
274 | * @li The starting of the process failed (could not fork). | 280 | * @li The starting of the process failed (could not fork). |
275 | * @li The executable was not found. | 281 | * @li The executable was not found. |
276 | * | 282 | * |
277 | * @param comm Specifies which communication links should be | 283 | * @param comm Specifies which communication links should be |
278 | * established to the child process (stdin/stdout/stderr). By default, | 284 | * established to the child process (stdin/stdout/stderr). By default, |
279 | * no communication takes place and the respective communication | 285 | * no communication takes place and the respective communication |
280 | * signals will never get emitted. | 286 | * signals will never get emitted. |
281 | * | 287 | * |
282 | * @return true on success, false on error | 288 | * @return true on success, false on error |
283 | * (see above for error conditions) | 289 | * (see above for error conditions) |
284 | **/ | 290 | **/ |
285 | virtual bool start( RunMode runmode = NotifyOnExit, | 291 | virtual bool start( RunMode runmode = NotifyOnExit, |
286 | Communication comm = NoCommunication ); | 292 | Communication comm = NoCommunication ); |
287 | 293 | ||
288 | /** | 294 | /** |
289 | * Stop the process (by sending it a signal). | 295 | * Stop the process (by sending it a signal). |
290 | * | 296 | * |
291 | * @param signoThe signal to send. The default is SIGTERM. | 297 | * @param signoThe signal to send. The default is SIGTERM. |
292 | * @return @p true if the signal was delivered successfully. | 298 | * @return @p true if the signal was delivered successfully. |
293 | */ | 299 | */ |
294 | virtual bool kill( int signo = SIGTERM ); | 300 | virtual bool kill( int signo = SIGTERM ); |
295 | 301 | ||
296 | /** | 302 | /** |
297 | @return @p true if the process is (still) considered to be running | 303 | @return @p true if the process is (still) considered to be running |
298 | */ | 304 | */ |
299 | bool isRunning() const; | 305 | bool isRunning() const; |
300 | 306 | ||
301 | /** Returns the process id of the process. | 307 | /** Returns the process id of the process. |
302 | * | 308 | * |
303 | * If it is called after | 309 | * If it is called after |
304 | * the process has exited, it returns the process id of the last | 310 | * the process has exited, it returns the process id of the last |
305 | * child process that was created by this instance of OProcess. | 311 | * child process that was created by this instance of OProcess. |
306 | * | 312 | * |
307 | * Calling it before any child process has been started by this | 313 | * Calling it before any child process has been started by this |
308 | * OProcess instance causes pid() to return 0. | 314 | * OProcess instance causes pid() to return 0. |
309 | **/ | 315 | **/ |
310 | pid_t pid() const; | 316 | pid_t pid() const; |
311 | 317 | ||
312 | /** | 318 | /** |
313 | * Suspend processing of data from stdout of the child process. | 319 | * Suspend processing of data from stdout of the child process. |
314 | */ | 320 | */ |
315 | void suspend(); | 321 | void suspend(); |
316 | 322 | ||
317 | /** | 323 | /** |
318 | * Resume processing of data from stdout of the child process. | 324 | * Resume processing of data from stdout of the child process. |
319 | */ | 325 | */ |
320 | void resume(); | 326 | void resume(); |
321 | 327 | ||
322 | /** | 328 | /** |
323 | * @return @p true if the process has already finished and has exited | 329 | * @return @p true if the process has already finished and has exited |
324 | * "voluntarily", ie: it has not been killed by a signal. | 330 | * "voluntarily", ie: it has not been killed by a signal. |
325 | * | 331 | * |
326 | * Note that you should check @ref OProcess::exitStatus() to determine | 332 | * Note that you should check @ref OProcess::exitStatus() to determine |
327 | * whether the process completed its task successful or not. | 333 | * whether the process completed its task successful or not. |
328 | */ | 334 | */ |
329 | bool normalExit() const; | 335 | bool normalExit() const; |
330 | 336 | ||
331 | /** | 337 | /** |
332 | * Returns the exit status of the process. | 338 | * Returns the exit status of the process. |
333 | * | 339 | * |
334 | * Please use | 340 | * Please use |
335 | * @ref OProcess::normalExit() to check whether the process has exited | 341 | * @ref OProcess::normalExit() to check whether the process has exited |
336 | * cleanly (i.e., @ref OProcess::normalExit() returns @p true) before calling | 342 | * cleanly (i.e., @ref OProcess::normalExit() returns @p true) before calling |
337 | * this function because if the process did not exit normally, | 343 | * this function because if the process did not exit normally, |
338 | * it does not have a valid exit status. | 344 | * it does not have a valid exit status. |
339 | */ | 345 | */ |
340 | int exitStatus() const; | 346 | int exitStatus() const; |
341 | 347 | ||
342 | 348 | ||
343 | /** | 349 | /** |
344 | * Transmit data to the child process's stdin. | 350 | * Transmit data to the child process's stdin. |
345 | * | 351 | * |
346 | * OProcess::writeStdin may return false in the following cases: | 352 | * OProcess::writeStdin may return false in the following cases: |
347 | * | 353 | * |
348 | * @li The process is not currently running. | 354 | * @li The process is not currently running. |
349 | * | 355 | * |
350 | * @li Communication to stdin has not been requested in the @ref start() call. | 356 | * @li Communication to stdin has not been requested in the @ref start() call. |
351 | * | 357 | * |
352 | * @li Transmission of data to the child process by a previous call to | 358 | * @li Transmission of data to the child process by a previous call to |
353 | * @ref writeStdin() is still in progress. | 359 | * @ref writeStdin() is still in progress. |
354 | * | 360 | * |
355 | * Please note that the data is sent to the client asynchronously, | 361 | * Please note that the data is sent to the client asynchronously, |
356 | * so when this function returns, the data might not have been | 362 | * so when this function returns, the data might not have been |
357 | * processed by the child process. | 363 | * processed by the child process. |
358 | * | 364 | * |
359 | * If all the data has been sent to the client, the signal | 365 | * If all the data has been sent to the client, the signal |
360 | * @ref wroteStdin() will be emitted. | 366 | * @ref wroteStdin() will be emitted. |
361 | * | 367 | * |
362 | * Please note that you must not free "buffer" or call @ref writeStdin() | 368 | * Please note that you must not free "buffer" or call @ref writeStdin() |
363 | * again until either a @ref wroteStdin() signal indicates that the | 369 | * again until either a @ref wroteStdin() signal indicates that the |
364 | * data has been sent or a @ref processHasExited() signal shows that | 370 | * data has been sent or a @ref processHasExited() signal shows that |
365 | * the child process is no longer alive... | 371 | * the child process is no longer alive... |
366 | **/ | 372 | **/ |
367 | bool writeStdin( const char *buffer, int buflen ); | 373 | bool writeStdin( const char *buffer, int buflen ); |
368 | 374 | ||
369 | void flushStdin(); | 375 | void flushStdin(); |
370 | 376 | ||
371 | /** | 377 | /** |
372 | * This causes the stdin file descriptor of the child process to be | 378 | * This causes the stdin file descriptor of the child process to be |
373 | * closed indicating an "EOF" to the child. | 379 | * closed indicating an "EOF" to the child. |
374 | * | 380 | * |
375 | * @return @p false if no communication to the process's stdin | 381 | * @return @p false if no communication to the process's stdin |
376 | * had been specified in the call to @ref start(). | 382 | * had been specified in the call to @ref start(). |
377 | */ | 383 | */ |
378 | bool closeStdin(); | 384 | bool closeStdin(); |
379 | 385 | ||
380 | /** | 386 | /** |
381 | * This causes the stdout file descriptor of the child process to be | 387 | * This causes the stdout file descriptor of the child process to be |
382 | * closed. | 388 | * closed. |
383 | * | 389 | * |
384 | * @return @p false if no communication to the process's stdout | 390 | * @return @p false if no communication to the process's stdout |
385 | * had been specified in the call to @ref start(). | 391 | * had been specified in the call to @ref start(). |
386 | */ | 392 | */ |
387 | bool closeStdout(); | 393 | bool closeStdout(); |
388 | 394 | ||
389 | /** | 395 | /** |
390 | * This causes the stderr file descriptor of the child process to be | 396 | * This causes the stderr file descriptor of the child process to be |
391 | * closed. | 397 | * closed. |
392 | * | 398 | * |
393 | * @return @p false if no communication to the process's stderr | 399 | * @return @p false if no communication to the process's stderr |
394 | * had been specified in the call to @ref start(). | 400 | * had been specified in the call to @ref start(). |
395 | */ | 401 | */ |
396 | bool closeStderr(); | 402 | bool closeStderr(); |
397 | 403 | ||
398 | /** | 404 | /** |
399 | * Lets you see what your arguments are for debugging. | 405 | * Lets you see what your arguments are for debugging. |
406 | * \todo make const | ||
400 | */ | 407 | */ |
401 | 408 | ||
402 | const QValueList<QCString> &args() | 409 | const QValueList<QCString> &args() |
403 | { | 410 | { |
404 | return arguments; | 411 | return arguments; |
405 | } | 412 | } |
406 | 413 | ||
407 | /** | 414 | /** |
408 | * Controls whether the started process should drop any | 415 | * Controls whether the started process should drop any |
409 | * setuid/segid privileges or whether it should keep them | 416 | * setuid/segid privileges or whether it should keep them |
410 | * | 417 | * |
411 | * The default is @p false : drop privileges | 418 | * The default is @p false : drop privileges |
412 | */ | 419 | */ |
413 | void setRunPrivileged( bool keepPrivileges ); | 420 | void setRunPrivileged( bool keepPrivileges ); |
414 | 421 | ||
415 | /** | 422 | /** |
416 | * Returns whether the started process will drop any | 423 | * Returns whether the started process will drop any |
417 | * setuid/segid privileges or whether it will keep them | 424 | * setuid/segid privileges or whether it will keep them |
418 | */ | 425 | */ |
419 | bool runPrivileged() const; | 426 | bool runPrivileged() const; |
420 | 427 | ||
421 | /** | 428 | /** |
422 | * Modifies the environment of the process to be started. | 429 | * Modifies the environment of the process to be started. |
423 | * This function must be called before starting the process. | 430 | * This function must be called before starting the process. |
424 | */ | 431 | */ |
425 | void setEnvironment( const QString &name, const QString &value ); | 432 | void setEnvironment( const QString &name, const QString &value ); |
426 | 433 | ||
427 | /** | 434 | /** |
428 | * Changes the current working directory (CWD) of the process | 435 | * Changes the current working directory (CWD) of the process |
429 | * to be started. | 436 | * to be started. |
430 | * This function must be called before starting the process. | 437 | * This function must be called before starting the process. |
431 | */ | 438 | */ |
432 | void setWorkingDirectory( const QString &dir ); | 439 | void setWorkingDirectory( const QString &dir ); |
433 | 440 | ||
434 | /** | 441 | /** |
435 | * Specify whether to start the command via a shell or directly. | 442 | * Specify whether to start the command via a shell or directly. |
436 | * The default is to start the command directly. | 443 | * The default is to start the command directly. |
437 | * If @p useShell is true @p shell will be used as shell, or | 444 | * If @p useShell is true @p shell will be used as shell, or |
438 | * if shell is empty, the standard shell is used. | 445 | * if shell is empty, the standard shell is used. |
439 | * @p quote A flag indicating whether to quote the arguments. | 446 | * @p quote A flag indicating whether to quote the arguments. |
440 | * | 447 | * |
441 | * When using a shell, the caller should make sure that all filenames etc. | 448 | * When using a shell, the caller should make sure that all filenames etc. |
442 | * are properly quoted when passed as argument. | 449 | * are properly quoted when passed as argument. |
443 | * @see quote() | 450 | * @see quote() |
444 | */ | 451 | */ |
445 | void setUseShell( bool useShell, const char *shell = 0 ); | 452 | void setUseShell( bool useShell, const char *shell = 0 ); |
446 | 453 | ||
447 | /** | 454 | /** |
448 | * This function can be used to quote an argument string such that | 455 | * This function can be used to quote an argument string such that |
449 | * the shell processes it properly. This is e. g. necessary for | 456 | * the shell processes it properly. This is e. g. necessary for |
450 | * user-provided file names which may contain spaces or quotes. | 457 | * user-provided file names which may contain spaces or quotes. |
451 | * It also prevents expansion of wild cards and environment variables. | 458 | * It also prevents expansion of wild cards and environment variables. |
452 | */ | 459 | */ |
453 | static QString quote( const QString &arg ); | 460 | static QString quote( const QString &arg ); |
454 | 461 | ||
455 | /** | 462 | /** |
456 | * Detaches OProcess from child process. All communication is closed. | 463 | * Detaches OProcess from child process. All communication is closed. |
457 | * No exit notification is emitted any more for the child process. | 464 | * No exit notification is emitted any more for the child process. |
458 | * Deleting the OProcess will no longer kill the child process. | 465 | * Deleting the OProcess will no longer kill the child process. |
459 | * Note that the current process remains the parent process of the | 466 | * Note that the current process remains the parent process of the |
460 | * child process. | 467 | * child process. |
461 | */ | 468 | */ |
462 | void detach(); | 469 | void detach(); |
463 | 470 | ||
464 | /** | 471 | /** |
465 | * @return the PID of @a process, or -1 if the process is not running | 472 | * @return the PID of @a process, or -1 if the process is not running |
466 | */ | 473 | */ |
467 | static int processPID( const QString& process ); | 474 | static int processPID( const QString& process ); |
468 | 475 | ||
469 | signals: | 476 | signals: |
470 | 477 | ||
471 | /** | 478 | /** |
472 | * Emitted after the process has terminated when | 479 | * Emitted after the process has terminated when |
473 | * the process was run in the @p NotifyOnExit (==default option to | 480 | * the process was run in the @p NotifyOnExit (==default option to |
474 | * @ref start()) or the @ref Block mode. | 481 | * @ref start()) or the @ref Block mode. |
475 | **/ | 482 | **/ |
476 | void processExited( OProcess *proc ); | 483 | void processExited( OProcess *proc ); |
477 | 484 | ||
478 | 485 | ||
479 | /** | 486 | /** |
480 | * Emitted, when output from the child process has | 487 | * Emitted, when output from the child process has |
481 | * been received on stdout. | 488 | * been received on stdout. |
482 | * | 489 | * |
483 | * To actually get | 490 | * To actually get |
484 | * these signals, the respective communication link (stdout/stderr) | 491 | * these signals, the respective communication link (stdout/stderr) |
485 | * has to be turned on in @ref start(). | 492 | * has to be turned on in @ref start(). |
486 | * | 493 | * |
487 | * @param buffer The data received. | 494 | * @param buffer The data received. |
488 | * @param buflen The number of bytes that are available. | 495 | * @param buflen The number of bytes that are available. |
489 | * | 496 | * |
490 | * You should copy the information contained in @p buffer to your private | 497 | * You should copy the information contained in @p buffer to your private |
491 | * data structures before returning from this slot. | 498 | * data structures before returning from this slot. |
492 | **/ | 499 | **/ |
493 | void receivedStdout( OProcess *proc, char *buffer, int buflen ); | 500 | void receivedStdout( OProcess *proc, char *buffer, int buflen ); |
494 | 501 | ||
495 | /** | 502 | /** |
496 | * Emitted when output from the child process has | 503 | * Emitted when output from the child process has |
497 | * been received on stdout. | 504 | * been received on stdout. |
498 | * | 505 | * |
499 | * To actually get these signals, the respective communications link | 506 | * To actually get these signals, the respective communications link |
500 | * (stdout/stderr) has to be turned on in @ref start() and the | 507 | * (stdout/stderr) has to be turned on in @ref start() and the |
501 | * @p NoRead flag should have been passed. | 508 | * @p NoRead flag should have been passed. |
502 | * | 509 | * |
503 | * You will need to explicitly call resume() after your call to start() | 510 | * You will need to explicitly call resume() after your call to start() |
504 | * to begin processing data from the child process's stdout. This is | 511 | * to begin processing data from the child process's stdout. This is |
505 | * to ensure that this signal is not emitted when no one is connected | 512 | * to ensure that this signal is not emitted when no one is connected |
506 | * to it, otherwise this signal will not be emitted. | 513 | * to it, otherwise this signal will not be emitted. |
507 | * | 514 | * |
508 | * The data still has to be read from file descriptor @p fd. | 515 | * The data still has to be read from file descriptor @p fd. |
509 | **/ | 516 | **/ |
510 | void receivedStdout( int fd, int &len ); | 517 | void receivedStdout( int fd, int &len ); |
511 | 518 | ||
512 | 519 | ||
513 | /** | 520 | /** |
514 | * Emitted, when output from the child process has | 521 | * Emitted, when output from the child process has |
515 | * been received on stderr. | 522 | * been received on stderr. |
516 | * To actually get | 523 | * To actually get |
517 | * these signals, the respective communication link (stdout/stderr) | 524 | * these signals, the respective communication link (stdout/stderr) |
518 | * has to be turned on in @ref start(). | 525 | * has to be turned on in @ref start(). |
519 | * | 526 | * |
520 | * @param buffer The data received. | 527 | * @param buffer The data received. |
521 | * @param buflen The number of bytes that are available. | 528 | * @param buflen The number of bytes that are available. |
522 | * | 529 | * |
523 | * You should copy the information contained in @p buffer to your private | 530 | * You should copy the information contained in @p buffer to your private |
524 | * data structures before returning from this slot. | 531 | * data structures before returning from this slot. |
525 | */ | 532 | */ |
526 | void receivedStderr( OProcess *proc, char *buffer, int buflen ); | 533 | void receivedStderr( OProcess *proc, char *buffer, int buflen ); |
527 | 534 | ||
528 | /** | 535 | /** |
529 | * Emitted after all the data that has been | 536 | * Emitted after all the data that has been |
530 | * specified by a prior call to @ref writeStdin() has actually been | 537 | * specified by a prior call to @ref writeStdin() has actually been |
531 | * written to the child process. | 538 | * written to the child process. |
532 | **/ | 539 | **/ |
533 | void wroteStdin( OProcess *proc ); | 540 | void wroteStdin( OProcess *proc ); |
534 | 541 | ||
535 | protected slots: | 542 | protected slots: |
536 | 543 | ||
537 | /** | 544 | /** |
538 | * This slot gets activated when data from the child's stdout arrives. | 545 | * This slot gets activated when data from the child's stdout arrives. |
539 | * It usually calls "childOutput" | 546 | * It usually calls "childOutput" |
540 | */ | 547 | */ |
541 | void slotChildOutput( int fdno ); | 548 | void slotChildOutput( int fdno ); |
542 | 549 | ||
543 | /** | 550 | /** |
544 | * This slot gets activated when data from the child's stderr arrives. | 551 | * This slot gets activated when data from the child's stderr arrives. |
545 | * It usually calls "childError" | 552 | * It usually calls "childError" |
546 | */ | 553 | */ |
547 | void slotChildError( int fdno ); | 554 | void slotChildError( int fdno ); |
548 | /* | 555 | /* |
549 | Slot functions for capturing stdout and stderr of the child | 556 | Slot functions for capturing stdout and stderr of the child |
550 | */ | 557 | */ |
551 | 558 | ||
552 | /** | 559 | /** |
553 | * Called when another bulk of data can be sent to the child's | 560 | * Called when another bulk of data can be sent to the child's |
554 | * stdin. If there is no more data to be sent to stdin currently | 561 | * stdin. If there is no more data to be sent to stdin currently |
555 | * available, this function must disable the QSocketNotifier "innot". | 562 | * available, this function must disable the QSocketNotifier "innot". |
556 | */ | 563 | */ |
557 | void slotSendData( int dummy ); | 564 | void slotSendData( int dummy ); |
558 | 565 | ||
559 | protected: | 566 | protected: |
560 | 567 | ||
561 | /** | 568 | /** |
562 | * Sets up the environment according to the data passed via | 569 | * Sets up the environment according to the data passed via |
563 | * setEnvironment(...) | 570 | * setEnvironment(...) |
564 | */ | 571 | */ |
565 | void setupEnvironment(); | 572 | void setupEnvironment(); |
566 | 573 | ||
567 | /** | 574 | /** |
568 | * The list of the process' command line arguments. The first entry | 575 | * The list of the process' command line arguments. The first entry |
569 | * in this list is the executable itself. | 576 | * in this list is the executable itself. |
570 | */ | 577 | */ |
571 | QValueList<QCString> arguments; | 578 | QValueList<QCString> arguments; |
572 | /** | 579 | /** |
573 | * How to run the process (Block, NotifyOnExit, DontCare). You should | 580 | * How to run the process (Block, NotifyOnExit, DontCare). You should |
574 | * not modify this data member directly from derived classes. | 581 | * not modify this data member directly from derived classes. |
575 | */ | 582 | */ |
576 | RunMode run_mode; | 583 | RunMode run_mode; |
577 | /** | 584 | /** |
578 | * true if the process is currently running. You should not | 585 | * true if the process is currently running. You should not |
579 | * modify this data member directly from derived classes. For | 586 | * modify this data member directly from derived classes. For |
580 | * reading the value of this data member, please use "isRunning()" | 587 | * reading the value of this data member, please use "isRunning()" |
581 | * since "runs" will probably be made private in later versions | 588 | * since "runs" will probably be made private in later versions |
582 | * of OProcess. | 589 | * of OProcess. |
583 | */ | 590 | */ |
584 | bool runs; | 591 | bool runs; |
585 | 592 | ||
586 | /** | 593 | /** |
587 | * The PID of the currently running process (see "getPid()"). | 594 | * The PID of the currently running process (see "getPid()"). |
588 | * You should not modify this data member in derived classes. | 595 | * You should not modify this data member in derived classes. |
589 | * Please use "getPid()" instead of directly accessing this | 596 | * Please use "getPid()" instead of directly accessing this |
590 | * member function since it will probably be made private in | 597 | * member function since it will probably be made private in |
591 | * later versions of OProcess. | 598 | * later versions of OProcess. |
592 | */ | 599 | */ |
593 | pid_t pid_; | 600 | pid_t pid_; |
594 | 601 | ||
595 | /** | 602 | /** |
596 | * The process' exit status as returned by "waitpid". You should not | 603 | * The process' exit status as returned by "waitpid". You should not |
597 | * modify the value of this data member from derived classes. You should | 604 | * modify the value of this data member from derived classes. You should |
598 | * rather use @ref exitStatus than accessing this data member directly | 605 | * rather use @ref exitStatus than accessing this data member directly |
599 | * since it will probably be made private in further versions of | 606 | * since it will probably be made private in further versions of |
600 | * OProcess. | 607 | * OProcess. |
601 | */ | 608 | */ |
602 | int status; | 609 | int status; |
603 | 610 | ||
604 | 611 | ||
605 | /** | 612 | /** |
606 | * See setRunPrivileged() | 613 | * See setRunPrivileged() |
607 | */ | 614 | */ |
608 | bool keepPrivs; | 615 | bool keepPrivs; |
609 | 616 | ||
610 | /* | 617 | /* |
611 | Functions for setting up the sockets for communication. | 618 | Functions for setting up the sockets for communication. |
612 | setupCommunication | 619 | setupCommunication |
613 | -- is called from "start" before "fork"ing. | 620 | -- is called from "start" before "fork"ing. |
614 | commSetupDoneP | 621 | commSetupDoneP |
615 | -- completes communication socket setup in the parent | 622 | -- completes communication socket setup in the parent |
616 | commSetupDoneC | 623 | commSetupDoneC |
617 | -- completes communication setup in the child process | 624 | -- completes communication setup in the child process |
618 | commClose | 625 | commClose |
619 | -- frees all allocated communication resources in the parent | 626 | -- frees all allocated communication resources in the parent |
620 | after the process has exited | 627 | after the process has exited |
621 | */ | 628 | */ |
622 | 629 | ||
623 | /** | 630 | /** |
624 | * This function is called from "OProcess::start" right before a "fork" takes | 631 | * This function is called from "OProcess::start" right before a "fork" takes |
625 | * place. According to | 632 | * place. According to |
626 | * the "comm" parameter this function has to initialize the "in", "out" and | 633 | * the "comm" parameter this function has to initialize the "in", "out" and |
627 | * "err" data member of OProcess. | 634 | * "err" data member of OProcess. |
628 | * | 635 | * |
629 | * This function should return 0 if setting the needed communication channels | 636 | * This function should return 0 if setting the needed communication channels |
630 | * was successful. | 637 | * was successful. |
631 | * | 638 | * |
632 | * The default implementation is to create UNIX STREAM sockets for the communication, | 639 | * The default implementation is to create UNIX STREAM sockets for the communication, |
633 | * but you could overload this function and establish a TCP/IP communication for | 640 | * but you could overload this function and establish a TCP/IP communication for |
634 | * network communication, for example. | 641 | * network communication, for example. |
635 | */ | 642 | */ |
636 | virtual int setupCommunication( Communication comm ); | 643 | virtual int setupCommunication( Communication comm ); |
637 | 644 | ||
638 | /** | 645 | /** |
639 | * Called right after a (successful) fork on the parent side. This function | 646 | * Called right after a (successful) fork on the parent side. This function |
640 | * will usually do some communications cleanup, like closing the reading end | 647 | * will usually do some communications cleanup, like closing the reading end |
641 | * of the "stdin" communication channel. | 648 | * of the "stdin" communication channel. |
642 | * | 649 | * |
643 | * Furthermore, it must also create the QSocketNotifiers "innot", "outnot" and | 650 | * Furthermore, it must also create the QSocketNotifiers "innot", "outnot" and |
644 | * "errnot" and connect their Qt slots to the respective OProcess member functions. | 651 | * "errnot" and connect their Qt slots to the respective OProcess member functions. |
645 | * | 652 | * |
646 | * For a more detailed explanation, it is best to have a look at the default | 653 | * For a more detailed explanation, it is best to have a look at the default |
647 | * implementation of "setupCommunication" in kprocess.cpp. | 654 | * implementation of "setupCommunication" in kprocess.cpp. |
648 | */ | 655 | */ |
649 | virtual int commSetupDoneP(); | 656 | virtual int commSetupDoneP(); |
650 | 657 | ||
651 | /** | 658 | /** |
652 | * Called right after a (successful) fork, but before an "exec" on the child | 659 | * Called right after a (successful) fork, but before an "exec" on the child |
653 | * process' side. It usually just closes the unused communication ends of | 660 | * process' side. It usually just closes the unused communication ends of |
654 | * "in", "out" and "err" (like the writing end of the "in" communication | 661 | * "in", "out" and "err" (like the writing end of the "in" communication |
655 | * channel. | 662 | * channel. |
656 | */ | 663 | */ |
657 | virtual int commSetupDoneC(); | 664 | virtual int commSetupDoneC(); |
658 | 665 | ||
659 | 666 | ||
660 | /** | 667 | /** |
661 | * Immediately called after a process has exited. This function normally | 668 | * Immediately called after a process has exited. This function normally |
662 | * calls commClose to close all open communication channels to this | 669 | * calls commClose to close all open communication channels to this |
663 | * process and emits the "processExited" signal (if the process was | 670 | * process and emits the "processExited" signal (if the process was |
664 | * not running in the "DontCare" mode). | 671 | * not running in the "DontCare" mode). |
665 | */ | 672 | */ |
666 | virtual void processHasExited( int state ); | 673 | virtual void processHasExited( int state ); |
667 | 674 | ||
668 | /** | 675 | /** |
669 | * Should clean up the communication links to the child after it has | 676 | * Should clean up the communication links to the child after it has |
670 | * exited. Should be called from "processHasExited". | 677 | * exited. Should be called from "processHasExited". |
671 | */ | 678 | */ |
672 | virtual void commClose(); | 679 | virtual void commClose(); |
673 | 680 | ||
674 | 681 | ||
675 | /** | 682 | /** |
676 | * the socket descriptors for stdin/stdout/stderr. | 683 | * the socket descriptors for stdin/stdout/stderr. |
677 | */ | 684 | */ |
678 | int out[ 2 ]; | 685 | int out[ 2 ]; |
679 | int in[ 2 ]; | 686 | int in[ 2 ]; |
680 | int err[ 2 ]; | 687 | int err[ 2 ]; |
681 | 688 | ||
682 | /** | 689 | /** |
683 | * The socket notifiers for the above socket descriptors. | 690 | * The socket notifiers for the above socket descriptors. |
684 | */ | 691 | */ |
685 | QSocketNotifier *innot; | 692 | QSocketNotifier *innot; |
686 | QSocketNotifier *outnot; | 693 | QSocketNotifier *outnot; |
687 | QSocketNotifier *errnot; | 694 | QSocketNotifier *errnot; |
688 | 695 | ||
689 | /** | 696 | /** |
690 | * Lists the communication links that are activated for the child | 697 | * Lists the communication links that are activated for the child |
691 | * process. Should not be modified from derived classes. | 698 | * process. Should not be modified from derived classes. |
692 | */ | 699 | */ |
693 | Communication communication; | 700 | Communication communication; |
694 | 701 | ||
695 | /** | 702 | /** |
696 | * Called by "slotChildOutput" this function copies data arriving from the | 703 | * Called by "slotChildOutput" this function copies data arriving from the |
697 | * child process's stdout to the respective buffer and emits the signal | 704 | * child process's stdout to the respective buffer and emits the signal |
698 | * "@ref receivedStderr". | 705 | * "@ref receivedStderr". |
699 | */ | 706 | */ |
700 | int childOutput( int fdno ); | 707 | int childOutput( int fdno ); |
701 | 708 | ||
702 | /** | 709 | /** |
703 | * Called by "slotChildOutput" this function copies data arriving from the | 710 | * Called by "slotChildOutput" this function copies data arriving from the |
704 | * child process's stdout to the respective buffer and emits the signal | 711 | * child process's stdout to the respective buffer and emits the signal |
705 | * "@ref receivedStderr" | 712 | * "@ref receivedStderr" |
706 | */ | 713 | */ |
707 | int childError( int fdno ); | 714 | int childError( int fdno ); |
708 | 715 | ||
709 | // information about the data that has to be sent to the child: | 716 | // information about the data that has to be sent to the child: |
710 | 717 | ||
711 | const char *input_data; // the buffer holding the data | 718 | const char *input_data; // the buffer holding the data |
712 | int input_sent; // # of bytes already transmitted | 719 | int input_sent; // # of bytes already transmitted |
713 | int input_total; // total length of input_data | 720 | int input_total; // total length of input_data |
714 | 721 | ||
715 | /** | 722 | /** |
716 | * @ref OProcessController is a friend of OProcess because it has to have | 723 | * @ref OProcessController is a friend of OProcess because it has to have |
717 | * access to various data members. | 724 | * access to various data members. |
718 | */ | 725 | */ |
719 | friend class OProcessController; | 726 | friend class Private::OProcessController; |
720 | 727 | ||
721 | private: | 728 | private: |
722 | /** | 729 | /** |
723 | * Searches for a valid shell. | 730 | * Searches for a valid shell. |
724 | * Here is the algorithm used for finding an executable shell: | 731 | * Here is the algorithm used for finding an executable shell: |
725 | * | 732 | * |
726 | * @li Try the executable pointed to by the "SHELL" environment | 733 | * @li Try the executable pointed to by the "SHELL" environment |
727 | * variable with white spaces stripped off | 734 | * variable with white spaces stripped off |
728 | * | 735 | * |
729 | * @li If your process runs with uid != euid or gid != egid, a shell | 736 | * @li If your process runs with uid != euid or gid != egid, a shell |
730 | * not listed in /etc/shells will not used. | 737 | * not listed in /etc/shells will not used. |
731 | * | 738 | * |
732 | * @li If no valid shell could be found, "/bin/sh" is used as a last resort. | 739 | * @li If no valid shell could be found, "/bin/sh" is used as a last resort. |
733 | */ | 740 | */ |
734 | QCString searchShell(); | 741 | QCString searchShell(); |
735 | 742 | ||
736 | /** | 743 | /** |
737 | * Used by @ref searchShell in order to find out whether the shell found | 744 | * Used by @ref searchShell in order to find out whether the shell found |
738 | * is actually executable at all. | 745 | * is actually executable at all. |
739 | */ | 746 | */ |
740 | bool isExecutable( const QCString &filename ); | 747 | bool isExecutable( const QCString &filename ); |
741 | 748 | ||
742 | // Disallow assignment and copy-construction | 749 | // Disallow assignment and copy-construction |
743 | OProcess( const OProcess& ); | 750 | OProcess( const OProcess& ); |
744 | OProcess& operator= ( const OProcess& ); | 751 | OProcess& operator= ( const OProcess& ); |
745 | 752 | ||
746 | private: | 753 | private: |
747 | void init ( ); | 754 | void init ( ); |
748 | OProcessPrivate *d; | 755 | Private::OProcessPrivate *d; |
749 | }; | 756 | }; |
757 | } | ||
758 | } | ||
750 | 759 | ||
751 | #endif | 760 | #endif |
752 | 761 | ||
diff --git a/libopie2/opiecore/osmartpointer.h b/libopie2/opiecore/osmartpointer.h index 9000e71..8f9da7f 100644 --- a/libopie2/opiecore/osmartpointer.h +++ b/libopie2/opiecore/osmartpointer.h | |||
@@ -1,145 +1,147 @@ | |||
1 | // -*- Mode: C++; -*- | 1 | // -*- Mode: C++; -*- |
2 | /* | 2 | /* |
3 | This file is part of the Opie Project | 3 | This file is part of the Opie Project |
4 | Copyright (C) 2004 Rajko Albrecht <alwin@handhelds.org> | 4 | Copyright (C) 2004 Rajko Albrecht <alwin@handhelds.org> |
5 | Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | Copyright (C) The Opie Team <opie-devel@handhelds.org> |
6 | =. | 6 | =. |
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 _OSmartPointer_h | 32 | #ifndef _OSmartPointer_h |
33 | #define _OSmartPointer_h | 33 | #define _OSmartPointer_h |
34 | 34 | ||
35 | /*! | 35 | /*! |
36 | * \file OSmartPointer.h | 36 | * \file OSmartPointer.h |
37 | * \brief smart pointer and reference counter | 37 | * \brief smart pointer and reference counter |
38 | * \author Rajko Albrecht | 38 | * \author Rajko Albrecht |
39 | * | 39 | * |
40 | */ | 40 | */ |
41 | 41 | ||
42 | namespace Opie { | 42 | namespace Opie { |
43 | namespace Core { | ||
43 | 44 | ||
44 | //! simple reference counter class | 45 | //! simple reference counter class |
45 | class ORefCount { | 46 | class ORefCount { |
46 | protected: | 47 | protected: |
47 | //! reference count member | 48 | //! reference count member |
48 | long m_RefCount; | 49 | long m_RefCount; |
49 | public: | 50 | public: |
50 | //! first reference must be added after "new" via Pointer() | 51 | //! first reference must be added after "new" via Pointer() |
51 | ORefCount() : m_RefCount(0) | 52 | ORefCount() : m_RefCount(0) |
52 | {} | 53 | {} |
53 | virtual ~ORefCount() {} | 54 | virtual ~ORefCount() {} |
54 | //! add a reference | 55 | //! add a reference |
55 | void Incr() { | 56 | void Incr() { |
56 | ++m_RefCount; | 57 | ++m_RefCount; |
57 | } | 58 | } |
58 | //! delete a reference | 59 | //! delete a reference |
59 | void Decr() { | 60 | void Decr() { |
60 | --m_RefCount; | 61 | --m_RefCount; |
61 | } | 62 | } |
62 | //! is it referenced | 63 | //! is it referenced |
63 | bool Shared() { return (m_RefCount > 0); } | 64 | bool Shared() { return (m_RefCount > 0); } |
64 | }; | 65 | }; |
65 | 66 | ||
66 | //! reference counting wrapper class | 67 | //! reference counting wrapper class |
67 | template<class T> class OSmartPointer { | 68 | template<class T> class OSmartPointer { |
68 | //! pointer to object | 69 | //! pointer to object |
69 | /*! | 70 | /*! |
70 | * this object must contain Incr(), Decr() and Shared() | 71 | * this object must contain Incr(), Decr() and Shared() |
71 | * methode as public members. The best way is, that it will be a child | 72 | * methode as public members. The best way is, that it will be a child |
72 | * class of RefCount | 73 | * class of RefCount |
73 | */ | 74 | */ |
74 | T *ptr; | 75 | T *ptr; |
75 | public: | 76 | public: |
76 | //! standart constructor | 77 | //! standart constructor |
77 | OSmartPointer() { ptr = NULL; } | 78 | OSmartPointer() { ptr = NULL; } |
78 | //! standart destructor | 79 | //! standart destructor |
79 | /*! | 80 | /*! |
80 | * release the reference, if it were the last reference, destroys | 81 | * release the reference, if it were the last reference, destroys |
81 | * ptr | 82 | * ptr |
82 | */ | 83 | */ |
83 | ~OSmartPointer() | 84 | ~OSmartPointer() |
84 | { | 85 | { |
85 | if (ptr){ | 86 | if (ptr){ |
86 | ptr->Decr(); | 87 | ptr->Decr(); |
87 | if (!ptr->Shared()) | 88 | if (!ptr->Shared()) |
88 | delete ptr; | 89 | delete ptr; |
89 | } | 90 | } |
90 | } | 91 | } |
91 | //! construction | 92 | //! construction |
92 | OSmartPointer(T* t) { if (ptr = t) ptr->Incr(); } | 93 | OSmartPointer(T* t) { if (ptr = t) ptr->Incr(); } |
93 | //! Pointer copy | 94 | //! Pointer copy |
94 | OSmartPointer(const OSmartPointer<T>& p) | 95 | OSmartPointer(const OSmartPointer<T>& p) |
95 | { if (ptr = p.ptr) ptr->Incr(); } | 96 | { if (ptr = p.ptr) ptr->Incr(); } |
96 | //! pointer copy by assignment | 97 | //! pointer copy by assignment |
97 | OSmartPointer<T>& operator= (const OSmartPointer<T>& p) | 98 | OSmartPointer<T>& operator= (const OSmartPointer<T>& p) |
98 | { | 99 | { |
99 | // already same: nothing to do | 100 | // already same: nothing to do |
100 | if (ptr == p.ptr) return *this; | 101 | if (ptr == p.ptr) return *this; |
101 | // decouple reference | 102 | // decouple reference |
102 | if (ptr) { ptr->Decr(); if (!ptr->Shared()) delete ptr; } | 103 | if (ptr) { ptr->Decr(); if (!ptr->Shared()) delete ptr; } |
103 | // establish new reference | 104 | // establish new reference |
104 | if (ptr = p.ptr) ptr->Incr(); | 105 | if (ptr = p.ptr) ptr->Incr(); |
105 | return *this; | 106 | return *this; |
106 | } | 107 | } |
107 | OSmartPointer<T>& operator= (T*p) | 108 | OSmartPointer<T>& operator= (T*p) |
108 | { | 109 | { |
109 | if (ptr==p)return *this; | 110 | if (ptr==p)return *this; |
110 | if (ptr) { | 111 | if (ptr) { |
111 | ptr->Decr(); | 112 | ptr->Decr(); |
112 | if (!ptr->Shared()) delete ptr; | 113 | if (!ptr->Shared()) delete ptr; |
113 | } | 114 | } |
114 | if (ptr=p) ptr->Incr(); | 115 | if (ptr=p) ptr->Incr(); |
115 | return *this; | 116 | return *this; |
116 | } | 117 | } |
117 | 118 | ||
118 | //! cast to conventional pointer | 119 | //! cast to conventional pointer |
119 | operator T* () const { return ptr; } | 120 | operator T* () const { return ptr; } |
120 | 121 | ||
121 | //! deref: fails for NULL pointer | 122 | //! deref: fails for NULL pointer |
122 | T& operator* () {return *ptr; } | 123 | T& operator* () {return *ptr; } |
123 | //! deref: fails for NULL pointer | 124 | //! deref: fails for NULL pointer |
124 | const T& operator* ()const {return *ptr; } | 125 | const T& operator* ()const {return *ptr; } |
125 | 126 | ||
126 | //! deref with method call | 127 | //! deref with method call |
127 | T* operator-> () {return ptr; } | 128 | T* operator-> () {return ptr; } |
128 | //! deref with const method call | 129 | //! deref with const method call |
129 | const T* operator-> ()const {return ptr; } | 130 | const T* operator-> ()const {return ptr; } |
130 | 131 | ||
131 | //! supports "if (pointer)" | 132 | //! supports "if (pointer)" |
132 | operator bool () const { return (ptr != NULL); } | 133 | operator bool () const { return (ptr != NULL); } |
133 | //! "if (pointer)" as non const | 134 | //! "if (pointer)" as non const |
134 | operator bool () { return ptr != NULL;} | 135 | operator bool () { return ptr != NULL;} |
135 | 136 | ||
136 | //! support if (!pointer)" | 137 | //! support if (!pointer)" |
137 | bool operator! () const { return (ptr == NULL); } | 138 | bool operator! () const { return (ptr == NULL); } |
138 | //! support if (!pointer)" as non const | 139 | //! support if (!pointer)" as non const |
139 | bool operator! () { return (ptr == NULL); } | 140 | bool operator! () { return (ptr == NULL); } |
140 | }; | 141 | }; |
141 | 142 | ||
142 | } | 143 | } |
144 | } | ||
143 | 145 | ||
144 | #endif | 146 | #endif |
145 | 147 | ||
diff --git a/libopie2/opiecore/ostorageinfo.cpp b/libopie2/opiecore/ostorageinfo.cpp index aa8d2fc..8fcf5fc 100644 --- a/libopie2/opiecore/ostorageinfo.cpp +++ b/libopie2/opiecore/ostorageinfo.cpp | |||
@@ -1,85 +1,87 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> | 3 | Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/ostorageinfo.h> | 30 | #include <opie2/ostorageinfo.h> |
31 | 31 | ||
32 | using namespace Opie::Core; | ||
33 | |||
32 | OStorageInfo::OStorageInfo( QObject *parent ) | 34 | OStorageInfo::OStorageInfo( QObject *parent ) |
33 | : StorageInfo( parent ) | 35 | : StorageInfo( parent ) |
34 | { | 36 | { |
35 | } | 37 | } |
36 | 38 | ||
37 | OStorageInfo::~OStorageInfo() | 39 | OStorageInfo::~OStorageInfo() |
38 | { | 40 | { |
39 | } | 41 | } |
40 | 42 | ||
41 | QString OStorageInfo::cfPath()const | 43 | QString OStorageInfo::cfPath()const |
42 | { | 44 | { |
43 | QString r = ""; | 45 | QString r = ""; |
44 | 46 | ||
45 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) | 47 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) |
46 | { | 48 | { |
47 | if ( (*i)->disk().left( 8 ) == "/dev/hda" ) | 49 | if ( (*i)->disk().left( 8 ) == "/dev/hda" ) |
48 | { | 50 | { |
49 | r = (*i)->path(); | 51 | r = (*i)->path(); |
50 | break; | 52 | break; |
51 | } | 53 | } |
52 | } | 54 | } |
53 | return r; | 55 | return r; |
54 | } | 56 | } |
55 | 57 | ||
56 | QString OStorageInfo::sdPath()const | 58 | QString OStorageInfo::sdPath()const |
57 | { | 59 | { |
58 | QString r = ""; | 60 | QString r = ""; |
59 | 61 | ||
60 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) | 62 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) |
61 | { | 63 | { |
62 | if ( (*i)->disk().left( 9 ) == "/dev/mmcd" ) | 64 | if ( (*i)->disk().left( 9 ) == "/dev/mmcd" ) |
63 | { | 65 | { |
64 | r = (*i)->path(); | 66 | r = (*i)->path(); |
65 | break; | 67 | break; |
66 | } | 68 | } |
67 | } | 69 | } |
68 | return r; | 70 | return r; |
69 | } | 71 | } |
70 | 72 | ||
71 | QString OStorageInfo::mmcPath()const | 73 | QString OStorageInfo::mmcPath()const |
72 | { | 74 | { |
73 | QString r = ""; | 75 | QString r = ""; |
74 | 76 | ||
75 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) | 77 | for (QListIterator<FileSystem> i( fileSystems() ); i.current(); ++i) |
76 | { | 78 | { |
77 | if ( (*i)->disk().left( 14 ) == "/dev/mmc/part1" ) | 79 | if ( (*i)->disk().left( 14 ) == "/dev/mmc/part1" ) |
78 | { | 80 | { |
79 | r = (*i)->path(); | 81 | r = (*i)->path(); |
80 | break; | 82 | break; |
81 | } | 83 | } |
82 | } | 84 | } |
83 | return r; | 85 | return r; |
84 | } | 86 | } |
85 | 87 | ||
diff --git a/libopie2/opiecore/ostorageinfo.h b/libopie2/opiecore/ostorageinfo.h index 740fa85..4e1097f 100644 --- a/libopie2/opiecore/ostorageinfo.h +++ b/libopie2/opiecore/ostorageinfo.h | |||
@@ -1,62 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> | 3 | Copyright (C) 2004 Andreas 'ar' Richter <ar@oszine.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifndef OSTORAGE_H | 30 | #ifndef OSTORAGE_H |
31 | #define OSTORAGE_H | 31 | #define OSTORAGE_H |
32 | 32 | ||
33 | #include <qpe/storage.h> | 33 | #include <qpe/storage.h> |
34 | 34 | ||
35 | namespace Opie { | ||
36 | namespace Core { | ||
37 | |||
35 | class OStorageInfo : public StorageInfo | 38 | class OStorageInfo : public StorageInfo |
36 | { | 39 | { |
37 | Q_OBJECT | 40 | Q_OBJECT |
38 | 41 | ||
39 | public: | 42 | public: |
40 | 43 | ||
41 | OStorageInfo( QObject *parent=0 ); | 44 | OStorageInfo( QObject *parent=0 ); |
42 | ~OStorageInfo(); | 45 | ~OStorageInfo(); |
43 | 46 | ||
44 | /** | 47 | /** |
45 | * @returns the mount path of the CF (Compact Flash) card | 48 | * @returns the mount path of the CF (Compact Flash) card |
46 | * | 49 | * |
47 | **/ | 50 | **/ |
48 | QString cfPath() const; | 51 | QString cfPath() const; |
49 | /** | 52 | /** |
50 | * @returns the mount path of the SD (Secure Digital) card | 53 | * @returns the mount path of the SD (Secure Digital) card |
51 | * | 54 | * |
52 | **/ | 55 | **/ |
53 | QString sdPath() const; | 56 | QString sdPath() const; |
54 | /** | 57 | /** |
55 | * @returns the mount path of the MMC (MultiMedia) card | 58 | * @returns the mount path of the MMC (MultiMedia) card |
56 | * | 59 | * |
57 | **/ | 60 | **/ |
58 | QString mmcPath() const; | 61 | QString mmcPath() const; |
62 | private: | ||
63 | class Private; | ||
64 | Private *d; | ||
59 | }; | 65 | }; |
60 | 66 | ||
67 | } | ||
68 | } | ||
61 | #endif // OSTORAGE_H | 69 | #endif // OSTORAGE_H |
62 | 70 | ||
diff --git a/libopie2/opiecore/xmltree.cc b/libopie2/opiecore/xmltree.cc deleted file mode 100644 index 059791b..0000000 --- a/libopie2/opiecore/xmltree.cc +++ b/dev/null | |||
@@ -1,323 +0,0 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include <opie2/xmltree.h> | ||
21 | |||
22 | #include <qpe/stringutil.h> | ||
23 | |||
24 | #include <qxml.h> | ||
25 | |||
26 | #include <assert.h> | ||
27 | |||
28 | using namespace Opie; | ||
29 | |||
30 | XMLElement::XMLElement() | ||
31 | : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | XMLElement::~XMLElement() | ||
36 | { | ||
37 | XMLElement *n = m_first; | ||
38 | |||
39 | while ( n ) | ||
40 | { | ||
41 | XMLElement *tmp = n; | ||
42 | n = n->m_next; | ||
43 | delete tmp; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | void XMLElement::appendChild( XMLElement *child ) | ||
48 | { | ||
49 | if ( child->m_parent ) | ||
50 | child->m_parent->removeChild( child ); | ||
51 | |||
52 | child->m_parent = this; | ||
53 | |||
54 | if ( m_last ) | ||
55 | m_last->m_next = child; | ||
56 | |||
57 | child->m_prev = m_last; | ||
58 | |||
59 | if ( !m_first ) | ||
60 | m_first = child; | ||
61 | |||
62 | m_last = child; | ||
63 | } | ||
64 | |||
65 | void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) | ||
66 | { | ||
67 | assert( newChild != refChild ); | ||
68 | |||
69 | if ( refChild == m_last ) | ||
70 | { | ||
71 | appendChild( newChild ); | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | assert( refChild ); | ||
76 | assert( refChild->m_parent ); | ||
77 | assert( refChild->m_parent == this ); | ||
78 | |||
79 | if ( newChild->m_parent && newChild != refChild ) | ||
80 | newChild->m_parent->removeChild( newChild ); | ||
81 | |||
82 | newChild->m_parent = this; | ||
83 | |||
84 | XMLElement *next = refChild->m_next; | ||
85 | |||
86 | refChild->m_next = newChild; | ||
87 | |||
88 | newChild->m_prev = refChild; | ||
89 | newChild->m_next = next; | ||
90 | |||
91 | if ( next ) | ||
92 | next->m_prev = newChild; | ||
93 | } | ||
94 | |||
95 | QString XMLElement::attribute( const QString &attr ) const | ||
96 | { | ||
97 | AttributeMap::ConstIterator it = m_attributes.find( attr ); | ||
98 | if ( it == m_attributes.end() ) | ||
99 | return QString::null; | ||
100 | return it.data(); | ||
101 | } | ||
102 | |||
103 | void XMLElement::setAttribute( const QString &attr, const QString &value ) | ||
104 | { | ||
105 | m_attributes.replace( attr, value ); | ||
106 | } | ||
107 | |||
108 | void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) | ||
109 | { | ||
110 | assert( refChild ); | ||
111 | assert( refChild->m_parent ); | ||
112 | assert( refChild->m_parent == this ); | ||
113 | assert( newChild != refChild ); | ||
114 | |||
115 | if ( newChild->m_parent && newChild != refChild ) | ||
116 | newChild->m_parent->removeChild( newChild ); | ||
117 | |||
118 | newChild->m_parent = this; | ||
119 | |||
120 | XMLElement *prev = refChild->m_prev; | ||
121 | |||
122 | refChild->m_prev = newChild; | ||
123 | |||
124 | newChild->m_prev = prev; | ||
125 | newChild->m_next = refChild; | ||
126 | |||
127 | if ( prev ) | ||
128 | prev->m_next = newChild; | ||
129 | |||
130 | if ( refChild == m_first ) | ||
131 | m_first = newChild; | ||
132 | } | ||
133 | |||
134 | void XMLElement::removeChild( XMLElement *child ) | ||
135 | { | ||
136 | if ( child->m_parent != this ) | ||
137 | return; | ||
138 | |||
139 | if ( m_first == child ) | ||
140 | m_first = child->m_next; | ||
141 | |||
142 | if ( m_last == child ) | ||
143 | m_last = child->m_prev; | ||
144 | |||
145 | if ( child->m_prev ) | ||
146 | child->m_prev->m_next = child->m_next; | ||
147 | |||
148 | if ( child->m_next ) | ||
149 | child->m_next->m_prev = child->m_prev; | ||
150 | |||
151 | child->m_parent = 0; | ||
152 | child->m_prev = 0; | ||
153 | child->m_next = 0; | ||
154 | } | ||
155 | |||
156 | void XMLElement::save( QTextStream &s, uint indent ) | ||
157 | { | ||
158 | if ( !m_value.isEmpty() ) | ||
159 | { | ||
160 | s << Qtopia::escapeString( m_value ); | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | for ( uint i = 0; i < indent; ++i ) | ||
165 | s << " "; | ||
166 | |||
167 | s << "<" << m_tag; | ||
168 | |||
169 | if ( !m_attributes.isEmpty() ) | ||
170 | { | ||
171 | s << " "; | ||
172 | AttributeMap::ConstIterator it = m_attributes.begin(); | ||
173 | AttributeMap::ConstIterator end = m_attributes.end(); | ||
174 | for (; it != end; ++it ) | ||
175 | { | ||
176 | s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\""; | ||
177 | s << " "; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | if ( m_last ) | ||
182 | { | ||
183 | if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent ) | ||
184 | s << ">"; | ||
185 | else | ||
186 | s << ">" << endl; | ||
187 | |||
188 | int newIndent = indent; | ||
189 | if ( m_parent ) | ||
190 | newIndent++; | ||
191 | |||
192 | XMLElement *n = m_first; | ||
193 | while ( n ) | ||
194 | { | ||
195 | n->save( s, newIndent ); | ||
196 | n = n->nextChild(); | ||
197 | } | ||
198 | |||
199 | if ( m_last && m_last->value().isEmpty() && m_parent ) | ||
200 | for ( uint i = 0; i < indent; ++i ) | ||
201 | s << " "; | ||
202 | |||
203 | if ( m_parent ) | ||
204 | s << "</" << m_tag << ">" << endl; | ||
205 | } | ||
206 | else | ||
207 | s << "/>" << endl; | ||
208 | } | ||
209 | |||
210 | class Handler : public QXmlDefaultHandler | ||
211 | { | ||
212 | public: | ||
213 | Handler() : m_node( 0 ), m_root( 0 ) {} | ||
214 | |||
215 | XMLElement *root() const { return m_root; } | ||
216 | |||
217 | virtual bool startDocument(); | ||
218 | virtual bool endDocument(); | ||
219 | virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, | ||
220 | const QXmlAttributes &attr ); | ||
221 | virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); | ||
222 | virtual bool characters( const QString &ch ); | ||
223 | |||
224 | private: | ||
225 | XMLElement *m_node; | ||
226 | XMLElement *m_root; | ||
227 | }; | ||
228 | |||
229 | bool Handler::startDocument() | ||
230 | { | ||
231 | m_root = m_node = new XMLElement; | ||
232 | |||
233 | return true; | ||
234 | } | ||
235 | |||
236 | bool Handler::endDocument() | ||
237 | { | ||
238 | return m_root == m_node; | ||
239 | } | ||
240 | |||
241 | bool Handler::startElement( const QString &, const QString &, const QString &qName, | ||
242 | const QXmlAttributes &attr ) | ||
243 | { | ||
244 | XMLElement *bm = new XMLElement; | ||
245 | |||
246 | XMLElement::AttributeMap attributes; | ||
247 | for ( int i = 0; i < attr.length(); ++i ) | ||
248 | attributes[ attr.qName( i ) ] = attr.value( i ); | ||
249 | |||
250 | bm->setAttributes( attributes ); | ||
251 | |||
252 | bm->setTagName( qName ); | ||
253 | |||
254 | m_node->appendChild( bm ); | ||
255 | m_node = bm; | ||
256 | |||
257 | return true; | ||
258 | } | ||
259 | |||
260 | bool Handler::endElement( const QString &, const QString &, const QString & ) | ||
261 | { | ||
262 | if ( m_node == m_root ) | ||
263 | return false; | ||
264 | |||
265 | m_node = m_node->parent(); | ||
266 | return true; | ||
267 | } | ||
268 | |||
269 | bool Handler::characters( const QString &ch ) | ||
270 | { | ||
271 | XMLElement *textNode = new XMLElement; | ||
272 | textNode->setValue( ch ); | ||
273 | m_node->appendChild( textNode ); | ||
274 | return true; | ||
275 | } | ||
276 | |||
277 | XMLElement *XMLElement::namedItem( const QString &name ) | ||
278 | { | ||
279 | XMLElement *e = m_first; | ||
280 | |||
281 | for (; e; e = e->nextChild() ) | ||
282 | if ( e->tagName() == name ) | ||
283 | return e; | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | XMLElement *XMLElement::clone() const | ||
289 | { | ||
290 | XMLElement *res = new XMLElement; | ||
291 | |||
292 | res->setTagName( m_tag ); | ||
293 | res->setValue( m_value ); | ||
294 | res->setAttributes( m_attributes ); | ||
295 | |||
296 | XMLElement *e = m_first; | ||
297 | for (; e; e = e->m_next ) | ||
298 | res->appendChild( e->clone() ); | ||
299 | |||
300 | return res; | ||
301 | } | ||
302 | |||
303 | XMLElement *XMLElement::load( const QString &fileName ) | ||
304 | { | ||
305 | QFile f( fileName ); | ||
306 | if ( !f.open( IO_ReadOnly ) ) | ||
307 | return 0; | ||
308 | |||
309 | QTextStream stream( &f ); | ||
310 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | ||
311 | QXmlInputSource src( stream ); | ||
312 | QXmlSimpleReader reader; | ||
313 | Handler handler; | ||
314 | |||
315 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); | ||
316 | reader.setContentHandler( &handler ); | ||
317 | reader.parse( src ); | ||
318 | |||
319 | return handler.root();; | ||
320 | } | ||
321 | |||
322 | /* vim: et sw=4 | ||
323 | */ | ||
diff --git a/libopie2/opiecore/xmltree.h b/libopie2/opiecore/xmltree.h deleted file mode 100644 index 4b6bdfa..0000000 --- a/libopie2/opiecore/xmltree.h +++ b/dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | /* This file is part of the KDE project | ||
2 | Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | |||
21 | #ifndef __bookmarks_h__ | ||
22 | #define __bookmarks_h__ | ||
23 | |||
24 | #include <qstring.h> | ||
25 | #include <qmap.h> | ||
26 | #include <qtextstream.h> | ||
27 | |||
28 | namespace Opie | ||
29 | { | ||
30 | |||
31 | /** | ||
32 | * A small xml lib written by Simon Hausmann. | ||
33 | */ | ||
34 | class XMLElement | ||
35 | { | ||
36 | public: | ||
37 | typedef QMap<QString, QString> AttributeMap; | ||
38 | |||
39 | /** | ||
40 | * The constructor of XMLElement | ||
41 | */ | ||
42 | XMLElement(); | ||
43 | ~XMLElement(); | ||
44 | |||
45 | /** appendChild appends a child to the XMLElement behind the last element. | ||
46 | * The ownership of the child get's transfered to the | ||
47 | * this XMLElement. | ||
48 | * If child is already the child of another parent | ||
49 | * it's get removed from the other parent first. | ||
50 | */ | ||
51 | void appendChild( XMLElement *child ); | ||
52 | |||
53 | /** inserts newChild after refChild. If newChild is the child | ||
54 | * of another parent the child will get removed. | ||
55 | * The ownership of child gets transfered. | ||
56 | * | ||
57 | */ | ||
58 | void insertAfter( XMLElement *newChild, XMLElement *refChild ); | ||
59 | |||
60 | /** same as insertAfter but the element get's inserted before refChild. | ||
61 | * | ||
62 | */ | ||
63 | void insertBefore( XMLElement *newChild, XMLElement *refChild ); | ||
64 | |||
65 | /** removeChild removes the child from the XMLElement. | ||
66 | * The ownership gets dropped. You need to delete the | ||
67 | * child yourself. | ||
68 | */ | ||
69 | void removeChild( XMLElement *child ); | ||
70 | |||
71 | /** parent() returns the parent of this XMLElement | ||
72 | * If there is no parent 0l gets returned | ||
73 | */ | ||
74 | XMLElement *parent() const { return m_parent; } | ||
75 | XMLElement *firstChild() const { return m_first; } | ||
76 | XMLElement *nextChild() const { return m_next; } | ||
77 | XMLElement *prevChild() const { return m_prev; } | ||
78 | XMLElement *lastChild() const { return m_last; } | ||
79 | |||
80 | void setTagName( const QString &tag ) { m_tag = tag; } | ||
81 | QString tagName() const { return m_tag; } | ||
82 | |||
83 | void setValue( const QString &val ) { m_value = val; } | ||
84 | QString value() const { return m_value; } | ||
85 | |||
86 | void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; } | ||
87 | AttributeMap attributes() const { return m_attributes; } | ||
88 | AttributeMap &attributes() { return m_attributes; } | ||
89 | |||
90 | QString attribute( const QString & ) const; | ||
91 | void setAttribute( const QString &attr, const QString &value ); | ||
92 | void save( QTextStream &stream, uint indent = 0 ); | ||
93 | |||
94 | XMLElement *namedItem( const QString &name ); | ||
95 | |||
96 | XMLElement *clone() const; | ||
97 | |||
98 | static XMLElement *load( const QString &fileName ); | ||
99 | |||
100 | private: | ||
101 | QString m_tag; | ||
102 | QString m_value; | ||
103 | AttributeMap m_attributes; | ||
104 | |||
105 | XMLElement *m_parent; | ||
106 | XMLElement *m_next; | ||
107 | XMLElement *m_prev; | ||
108 | XMLElement *m_first; | ||
109 | XMLElement *m_last; | ||
110 | |||
111 | XMLElement( const XMLElement &rhs ); | ||
112 | XMLElement &operator=( const XMLElement &rhs ); | ||
113 | class Private; | ||
114 | Private* d; | ||
115 | }; | ||
116 | |||
117 | } // namespace Opie | ||
118 | |||
119 | #endif | ||