-rw-r--r-- | libopie/odevice.cpp | 108 |
1 files changed, 102 insertions, 6 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 9b2a954..8f954b1 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -1,120 +1,120 @@ | |||
1 | /* This file is part of the OPIE libraries | 1 | /* This file is part of the OPIE libraries |
2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) | 2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) |
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 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <sys/ioctl.h> | 23 | #include <sys/ioctl.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <linux/soundcard.h> | 26 | #include <linux/soundcard.h> |
27 | #include <math.h> | 27 | #include <math.h> |
28 | 28 | ||
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | 30 | ||
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qpe/sound.h> | 33 | #include <qpe/sound.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | #include <qpe/qcopenvelope_qws.h> | 36 | #include <qpe/qcopenvelope_qws.h> |
37 | 37 | ||
38 | #include "odevice.h" | 38 | #include "odevice.h" |
39 | 39 | ||
40 | #include <qwindowsystem_qws.h> | 40 | #include <qwindowsystem_qws.h> |
41 | 41 | ||
42 | 42 | ||
43 | // _IO and friends are only defined in kernel headers ... | 43 | // _IO and friends are only defined in kernel headers ... |
44 | 44 | ||
45 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 45 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
46 | 46 | ||
47 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 47 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
48 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 48 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
49 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 49 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
50 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 50 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
51 | 51 | ||
52 | using namespace Opie; | 52 | using namespace Opie; |
53 | 53 | ||
54 | class ODeviceData { | 54 | class ODeviceData { |
55 | public: | 55 | public: |
56 | bool m_qwsserver; | 56 | bool m_qwsserver : 1; |
57 | 57 | ||
58 | QString m_vendorstr; | 58 | QString m_vendorstr; |
59 | OVendor m_vendor; | 59 | OVendor m_vendor; |
60 | 60 | ||
61 | QString m_modelstr; | 61 | QString m_modelstr; |
62 | OModel m_model; | 62 | OModel m_model; |
63 | 63 | ||
64 | QString m_systemstr; | 64 | QString m_systemstr; |
65 | OSystem m_system; | 65 | OSystem m_system; |
66 | 66 | ||
67 | QString m_sysverstr; | 67 | QString m_sysverstr; |
68 | 68 | ||
69 | Transformation m_rotation; | 69 | Transformation m_rotation; |
70 | 70 | ||
71 | QValueList <ODeviceButton> *m_buttons; | 71 | QValueList <ODeviceButton> *m_buttons; |
72 | uint m_holdtime; | 72 | uint m_holdtime; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { | 76 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { |
77 | protected: | 77 | protected: |
78 | virtual void init ( ); | 78 | virtual void init ( ); |
79 | virtual void initButtons ( ); | 79 | virtual void initButtons ( ); |
80 | 80 | ||
81 | public: | 81 | public: |
82 | virtual bool setSoftSuspend ( bool soft ); | 82 | virtual bool setSoftSuspend ( bool soft ); |
83 | 83 | ||
84 | virtual bool setDisplayBrightness ( int b ); | 84 | virtual bool setDisplayBrightness ( int b ); |
85 | virtual int displayBrightnessResolution ( ) const; | 85 | virtual int displayBrightnessResolution ( ) const; |
86 | 86 | ||
87 | virtual void alarmSound ( ); | 87 | virtual void alarmSound ( ); |
88 | 88 | ||
89 | virtual QValueList <OLed> ledList ( ) const; | 89 | virtual QValueList <OLed> ledList ( ) const; |
90 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 90 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
91 | virtual OLedState ledState ( OLed led ) const; | 91 | virtual OLedState ledState ( OLed led ) const; |
92 | virtual bool setLedState ( OLed led, OLedState st ); | 92 | virtual bool setLedState ( OLed led, OLedState st ); |
93 | 93 | ||
94 | virtual bool hasLightSensor ( ) const; | 94 | virtual bool hasLightSensor ( ) const; |
95 | virtual int readLightSensor ( ); | 95 | virtual int readLightSensor ( ); |
96 | virtual int lightSensorResolution ( ) const; | 96 | virtual int lightSensorResolution ( ) const; |
97 | 97 | ||
98 | protected: | 98 | protected: |
99 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 99 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
100 | virtual void timerEvent ( QTimerEvent *te ); | 100 | virtual void timerEvent ( QTimerEvent *te ); |
101 | 101 | ||
102 | int m_power_timer; | 102 | int m_power_timer; |
103 | 103 | ||
104 | OLedState m_leds [2]; | 104 | OLedState m_leds [2]; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | class Zaurus : public ODevice { | 107 | class Zaurus : public ODevice { |
108 | protected: | 108 | protected: |
109 | virtual void init ( ); | 109 | virtual void init ( ); |
110 | virtual void initButtons ( ); | 110 | virtual void initButtons ( ); |
111 | 111 | ||
112 | public: | 112 | public: |
113 | virtual bool setSoftSuspend ( bool soft ); | 113 | virtual bool setSoftSuspend ( bool soft ); |
114 | 114 | ||
115 | virtual bool setDisplayBrightness ( int b ); | 115 | virtual bool setDisplayBrightness ( int b ); |
116 | virtual int displayBrightnessResolution ( ) const; | 116 | virtual int displayBrightnessResolution ( ) const; |
117 | 117 | ||
118 | virtual void alarmSound ( ); | 118 | virtual void alarmSound ( ); |
119 | virtual void keySound ( ); | 119 | virtual void keySound ( ); |
120 | virtual void touchSound ( ); | 120 | virtual void touchSound ( ); |
@@ -209,357 +209,453 @@ static QCString makeChannel ( const char *str ) | |||
209 | if ( str && !::strchr ( str, '/' )) | 209 | if ( str && !::strchr ( str, '/' )) |
210 | return QCString ( "QPE/Application/" ) + str; | 210 | return QCString ( "QPE/Application/" ) + str; |
211 | else | 211 | else |
212 | return str; | 212 | return str; |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | 216 | ||
217 | 217 | ||
218 | ODevice *ODevice::inst ( ) | 218 | ODevice *ODevice::inst ( ) |
219 | { | 219 | { |
220 | static ODevice *dev = 0; | 220 | static ODevice *dev = 0; |
221 | 221 | ||
222 | if ( !dev ) { | 222 | if ( !dev ) { |
223 | if ( QFile::exists ( "/proc/hal/model" )) | 223 | if ( QFile::exists ( "/proc/hal/model" )) |
224 | dev = new iPAQ ( ); | 224 | dev = new iPAQ ( ); |
225 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 225 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
226 | dev = new Zaurus ( ); | 226 | dev = new Zaurus ( ); |
227 | else | 227 | else |
228 | dev = new ODevice ( ); | 228 | dev = new ODevice ( ); |
229 | 229 | ||
230 | dev-> init ( ); | 230 | dev-> init ( ); |
231 | } | 231 | } |
232 | return dev; | 232 | return dev; |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | /************************************************** | 236 | /************************************************** |
237 | * | 237 | * |
238 | * common | 238 | * common |
239 | * | 239 | * |
240 | **************************************************/ | 240 | **************************************************/ |
241 | 241 | ||
242 | 242 | ||
243 | ODevice::ODevice ( ) | 243 | ODevice::ODevice ( ) |
244 | { | 244 | { |
245 | d = new ODeviceData; | 245 | d = new ODeviceData; |
246 | 246 | ||
247 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | 247 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; |
248 | 248 | ||
249 | d-> m_modelstr = "Unknown"; | 249 | d-> m_modelstr = "Unknown"; |
250 | d-> m_model = Model_Unknown; | 250 | d-> m_model = Model_Unknown; |
251 | d-> m_vendorstr = "Unknown"; | 251 | d-> m_vendorstr = "Unknown"; |
252 | d-> m_vendor = Vendor_Unknown; | 252 | d-> m_vendor = Vendor_Unknown; |
253 | d-> m_systemstr = "Unknown"; | 253 | d-> m_systemstr = "Unknown"; |
254 | d-> m_system = System_Unknown; | 254 | d-> m_system = System_Unknown; |
255 | d-> m_sysverstr = "0.0"; | 255 | d-> m_sysverstr = "0.0"; |
256 | d-> m_rotation = Rot0; | 256 | d-> m_rotation = Rot0; |
257 | 257 | ||
258 | d-> m_holdtime = 1000; // 1000ms | 258 | d-> m_holdtime = 1000; // 1000ms |
259 | d-> m_buttons = 0; | 259 | d-> m_buttons = 0; |
260 | } | 260 | } |
261 | 261 | ||
262 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | 262 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) |
263 | { | 263 | { |
264 | if ( msg == "deviceButtonMappingChanged()" ) { | 264 | if ( msg == "deviceButtonMappingChanged()" ) { |
265 | reloadButtonMapping ( ); | 265 | reloadButtonMapping ( ); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | void ODevice::init ( ) | 269 | void ODevice::init ( ) |
270 | { | 270 | { |
271 | } | 271 | } |
272 | 272 | ||
273 | /** | ||
274 | * This method initialises the button mapping | ||
275 | */ | ||
273 | void ODevice::initButtons ( ) | 276 | void ODevice::initButtons ( ) |
274 | { | 277 | { |
275 | if ( d-> m_buttons ) | 278 | if ( d-> m_buttons ) |
276 | return; | 279 | return; |
277 | 280 | ||
278 | // Simulation uses iPAQ 3660 device buttons | 281 | // Simulation uses iPAQ 3660 device buttons |
279 | 282 | ||
280 | qDebug ( "init Buttons" ); | 283 | qDebug ( "init Buttons" ); |
281 | d-> m_buttons = new QValueList <ODeviceButton>; | 284 | d-> m_buttons = new QValueList <ODeviceButton>; |
282 | 285 | ||
283 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 286 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
284 | i_button *ib = ipaq_buttons + i; | 287 | i_button *ib = ipaq_buttons + i; |
285 | ODeviceButton b; | 288 | ODeviceButton b; |
286 | 289 | ||
287 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | 290 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { |
288 | b. setKeycode ( ib-> code ); | 291 | b. setKeycode ( ib-> code ); |
289 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | 292 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); |
290 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | 293 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); |
291 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | 294 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); |
292 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | 295 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); |
293 | d-> m_buttons-> append ( b ); | 296 | d-> m_buttons-> append ( b ); |
294 | } | 297 | } |
295 | } | 298 | } |
296 | reloadButtonMapping ( ); | 299 | reloadButtonMapping ( ); |
297 | 300 | ||
298 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 301 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
299 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | 302 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); |
300 | } | 303 | } |
301 | 304 | ||
302 | ODevice::~ODevice ( ) | 305 | ODevice::~ODevice ( ) |
303 | { | 306 | { |
304 | delete d; | 307 | delete d; |
305 | } | 308 | } |
306 | 309 | ||
307 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 310 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
308 | { | 311 | { |
309 | return false; | 312 | return false; |
310 | } | 313 | } |
311 | 314 | ||
312 | //#include <linux/apm_bios.h> | 315 | //#include <linux/apm_bios.h> |
313 | 316 | ||
314 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 317 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
315 | 318 | ||
316 | 319 | /** | |
320 | * This method will try to suspend the device | ||
321 | * It only works if the user is the QWS Server and the apm application | ||
322 | * is installed. | ||
323 | * It tries to suspend and then waits some time cause some distributions | ||
324 | * do have asynchronus apm implementations. | ||
325 | * This method will either fail and return false or it'll suspend the | ||
326 | * device and return once the device got woken up | ||
327 | * | ||
328 | * @return if the device got suspended | ||
329 | */ | ||
317 | bool ODevice::suspend ( ) | 330 | bool ODevice::suspend ( ) |
318 | { | 331 | { |
319 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend | 332 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend |
320 | return false; | 333 | return false; |
321 | 334 | ||
322 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 335 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
323 | return false; | 336 | return false; |
324 | 337 | ||
325 | bool res = false; | 338 | bool res = false; |
326 | 339 | ||
327 | struct timeval tvs, tvn; | 340 | struct timeval tvs, tvn; |
328 | ::gettimeofday ( &tvs, 0 ); | 341 | ::gettimeofday ( &tvs, 0 ); |
329 | 342 | ||
330 | ::sync ( ); // flush fs caches | 343 | ::sync ( ); // flush fs caches |
331 | res = ( ::system ( "apm --suspend" ) == 0 ); | 344 | res = ( ::system ( "apm --suspend" ) == 0 ); |
332 | 345 | ||
333 | // This is needed because the iPAQ apm implementation is asynchronous and we | 346 | // This is needed because the iPAQ apm implementation is asynchronous and we |
334 | // can not be sure when exactly the device is really suspended | 347 | // can not be sure when exactly the device is really suspended |
335 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | 348 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. |
336 | 349 | ||
337 | if ( res ) { | 350 | if ( res ) { |
338 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 351 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
339 | ::usleep ( 200 * 1000 ); | 352 | ::usleep ( 200 * 1000 ); |
340 | ::gettimeofday ( &tvn, 0 ); | 353 | ::gettimeofday ( &tvn, 0 ); |
341 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 354 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
342 | } | 355 | } |
343 | 356 | ||
344 | return res; | 357 | return res; |
345 | } | 358 | } |
346 | 359 | ||
347 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | 360 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... |
348 | 361 | ||
349 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 | 362 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 |
350 | 363 | ||
351 | /* VESA Blanking Levels */ | 364 | /* VESA Blanking Levels */ |
352 | #define VESA_NO_BLANKING 0 | 365 | #define VESA_NO_BLANKING 0 |
353 | #define VESA_VSYNC_SUSPEND 1 | 366 | #define VESA_VSYNC_SUSPEND 1 |
354 | #define VESA_HSYNC_SUSPEND 2 | 367 | #define VESA_HSYNC_SUSPEND 2 |
355 | #define VESA_POWERDOWN 3 | 368 | #define VESA_POWERDOWN 3 |
356 | 369 | ||
357 | 370 | /** | |
371 | * This sets the display on or off | ||
372 | */ | ||
358 | bool ODevice::setDisplayStatus ( bool on ) | 373 | bool ODevice::setDisplayStatus ( bool on ) |
359 | { | 374 | { |
360 | if ( d-> m_model == Model_Unknown ) | 375 | if ( d-> m_model == Model_Unknown ) |
361 | return false; | 376 | return false; |
362 | 377 | ||
363 | bool res = false; | 378 | bool res = false; |
364 | int fd; | 379 | int fd; |
365 | 380 | ||
366 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | 381 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { |
367 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | 382 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); |
368 | ::close ( fd ); | 383 | ::close ( fd ); |
369 | } | 384 | } |
370 | return res; | 385 | return res; |
371 | } | 386 | } |
372 | 387 | ||
373 | bool ODevice::setDisplayBrightness ( int ) | 388 | /** |
389 | * This sets the display brightness | ||
390 | * @return success or failure | ||
391 | */ | ||
392 | bool ODevice::setDisplayBrightness ( int p) | ||
374 | { | 393 | { |
394 | Q_UNUSED( p ) | ||
375 | return false; | 395 | return false; |
376 | } | 396 | } |
377 | 397 | ||
378 | int ODevice::displayBrightnessResolution ( ) const | 398 | int ODevice::displayBrightnessResolution ( ) const |
379 | { | 399 | { |
380 | return 16; | 400 | return 16; |
381 | } | 401 | } |
382 | 402 | ||
403 | /** | ||
404 | * This returns the vendor as string | ||
405 | * @return Vendor as QString | ||
406 | */ | ||
383 | QString ODevice::vendorString ( ) const | 407 | QString ODevice::vendorString ( ) const |
384 | { | 408 | { |
385 | return d-> m_vendorstr; | 409 | return d-> m_vendorstr; |
386 | } | 410 | } |
387 | 411 | ||
412 | /** | ||
413 | * This returns the vendor as one of the values of OVendor | ||
414 | * @return OVendor | ||
415 | */ | ||
388 | OVendor ODevice::vendor ( ) const | 416 | OVendor ODevice::vendor ( ) const |
389 | { | 417 | { |
390 | return d-> m_vendor; | 418 | return d-> m_vendor; |
391 | } | 419 | } |
392 | 420 | ||
421 | /** | ||
422 | * This returns the model as a string | ||
423 | * @return A string representing the model | ||
424 | */ | ||
393 | QString ODevice::modelString ( ) const | 425 | QString ODevice::modelString ( ) const |
394 | { | 426 | { |
395 | return d-> m_modelstr; | 427 | return d-> m_modelstr; |
396 | } | 428 | } |
397 | 429 | ||
430 | /** | ||
431 | * This does return the OModel used | ||
432 | */ | ||
398 | OModel ODevice::model ( ) const | 433 | OModel ODevice::model ( ) const |
399 | { | 434 | { |
400 | return d-> m_model; | 435 | return d-> m_model; |
401 | } | 436 | } |
402 | 437 | ||
438 | /** | ||
439 | * This does return the systen name | ||
440 | */ | ||
403 | QString ODevice::systemString ( ) const | 441 | QString ODevice::systemString ( ) const |
404 | { | 442 | { |
405 | return d-> m_systemstr; | 443 | return d-> m_systemstr; |
406 | } | 444 | } |
407 | 445 | ||
446 | /** | ||
447 | * Return System as OSystem value | ||
448 | */ | ||
408 | OSystem ODevice::system ( ) const | 449 | OSystem ODevice::system ( ) const |
409 | { | 450 | { |
410 | return d-> m_system; | 451 | return d-> m_system; |
411 | } | 452 | } |
412 | 453 | ||
454 | /** | ||
455 | * @return the version string of the base system | ||
456 | */ | ||
413 | QString ODevice::systemVersionString ( ) const | 457 | QString ODevice::systemVersionString ( ) const |
414 | { | 458 | { |
415 | return d-> m_sysverstr; | 459 | return d-> m_sysverstr; |
416 | } | 460 | } |
417 | 461 | ||
462 | /** | ||
463 | * @return the current Transformation | ||
464 | */ | ||
418 | Transformation ODevice::rotation ( ) const | 465 | Transformation ODevice::rotation ( ) const |
419 | { | 466 | { |
420 | return d-> m_rotation; | 467 | return d-> m_rotation; |
421 | } | 468 | } |
422 | 469 | ||
470 | /** | ||
471 | * This plays an alarmSound | ||
472 | */ | ||
423 | void ODevice::alarmSound ( ) | 473 | void ODevice::alarmSound ( ) |
424 | { | 474 | { |
425 | #ifndef QT_NO_SOUND | 475 | #ifndef QT_NO_SOUND |
426 | static Sound snd ( "alarm" ); | 476 | static Sound snd ( "alarm" ); |
427 | 477 | ||
428 | if ( snd. isFinished ( )) | 478 | if ( snd. isFinished ( )) |
429 | snd. play ( ); | 479 | snd. play ( ); |
430 | #endif | 480 | #endif |
431 | } | 481 | } |
432 | 482 | ||
483 | /** | ||
484 | * This plays a key sound | ||
485 | */ | ||
433 | void ODevice::keySound ( ) | 486 | void ODevice::keySound ( ) |
434 | { | 487 | { |
435 | #ifndef QT_NO_SOUND | 488 | #ifndef QT_NO_SOUND |
436 | static Sound snd ( "keysound" ); | 489 | static Sound snd ( "keysound" ); |
437 | 490 | ||
438 | if ( snd. isFinished ( )) | 491 | if ( snd. isFinished ( )) |
439 | snd. play ( ); | 492 | snd. play ( ); |
440 | #endif | 493 | #endif |
441 | } | 494 | } |
442 | 495 | ||
496 | /** | ||
497 | * This plays a touch sound | ||
498 | */ | ||
443 | void ODevice::touchSound ( ) | 499 | void ODevice::touchSound ( ) |
444 | { | 500 | { |
445 | 501 | ||
446 | #ifndef QT_NO_SOUND | 502 | #ifndef QT_NO_SOUND |
447 | static Sound snd ( "touchsound" ); | 503 | static Sound snd ( "touchsound" ); |
448 | 504 | ||
449 | if ( snd. isFinished ( )) | 505 | if ( snd. isFinished ( )) |
450 | snd. play ( ); | 506 | snd. play ( ); |
451 | #endif | 507 | #endif |
452 | } | 508 | } |
453 | 509 | ||
454 | 510 | /** | |
511 | * This method will return a list of leds | ||
512 | * available on this device | ||
513 | * @return a list of LEDs. | ||
514 | */ | ||
455 | QValueList <OLed> ODevice::ledList ( ) const | 515 | QValueList <OLed> ODevice::ledList ( ) const |
456 | { | 516 | { |
457 | return QValueList <OLed> ( ); | 517 | return QValueList <OLed> ( ); |
458 | } | 518 | } |
459 | 519 | ||
520 | /** | ||
521 | * This does return the state of the LEDs | ||
522 | */ | ||
460 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const | 523 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const |
461 | { | 524 | { |
462 | return QValueList <OLedState> ( ); | 525 | return QValueList <OLedState> ( ); |
463 | } | 526 | } |
464 | 527 | ||
528 | /** | ||
529 | * @return the state for a given OLed | ||
530 | */ | ||
465 | OLedState ODevice::ledState ( OLed /*which*/ ) const | 531 | OLedState ODevice::ledState ( OLed /*which*/ ) const |
466 | { | 532 | { |
467 | return Led_Off; | 533 | return Led_Off; |
468 | } | 534 | } |
469 | 535 | ||
470 | bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) | 536 | /** |
537 | * Set the state for a LED | ||
538 | * @param which Which OLed to use | ||
539 | * @param st The state to set | ||
540 | * @return success or failure | ||
541 | */ | ||
542 | bool ODevice::setLedState ( OLed which, OLedState st ) | ||
471 | { | 543 | { |
544 | Q_UNUSED( which ) | ||
545 | Q_UNUSED( st ) | ||
472 | return false; | 546 | return false; |
473 | } | 547 | } |
474 | 548 | ||
549 | /** | ||
550 | * @return if the device has a light sensor | ||
551 | */ | ||
475 | bool ODevice::hasLightSensor ( ) const | 552 | bool ODevice::hasLightSensor ( ) const |
476 | { | 553 | { |
477 | return false; | 554 | return false; |
478 | } | 555 | } |
479 | 556 | ||
557 | /** | ||
558 | * @return a value from the light senso | ||
559 | */ | ||
480 | int ODevice::readLightSensor ( ) | 560 | int ODevice::readLightSensor ( ) |
481 | { | 561 | { |
482 | return -1; | 562 | return -1; |
483 | } | 563 | } |
484 | 564 | ||
565 | /** | ||
566 | * @return the light sensor resolution whatever that is ;) | ||
567 | */ | ||
485 | int ODevice::lightSensorResolution ( ) const | 568 | int ODevice::lightSensorResolution ( ) const |
486 | { | 569 | { |
487 | return 0; | 570 | return 0; |
488 | } | 571 | } |
489 | 572 | ||
573 | /** | ||
574 | * @return a list of hardware buttons | ||
575 | */ | ||
490 | const QValueList <ODeviceButton> &ODevice::buttons ( ) | 576 | const QValueList <ODeviceButton> &ODevice::buttons ( ) |
491 | { | 577 | { |
492 | initButtons ( ); | 578 | initButtons ( ); |
493 | 579 | ||
494 | return *d-> m_buttons; | 580 | return *d-> m_buttons; |
495 | } | 581 | } |
496 | 582 | ||
583 | /** | ||
584 | * @return The amount of time that would count as a hold | ||
585 | */ | ||
497 | uint ODevice::buttonHoldTime ( ) const | 586 | uint ODevice::buttonHoldTime ( ) const |
498 | { | 587 | { |
499 | return d-> m_holdtime; | 588 | return d-> m_holdtime; |
500 | } | 589 | } |
501 | 590 | ||
591 | /** | ||
592 | * This method return a ODeviceButton for a key code | ||
593 | * or 0 if no special hardware button is available for the device | ||
594 | * | ||
595 | * @return The devicebutton or 0l | ||
596 | * @see ODeviceButton | ||
597 | */ | ||
502 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | 598 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) |
503 | { | 599 | { |
504 | initButtons ( ); | 600 | initButtons ( ); |
505 | 601 | ||
506 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { | 602 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { |
507 | if ( (*it). keycode ( ) == code ) | 603 | if ( (*it). keycode ( ) == code ) |
508 | return &(*it); | 604 | return &(*it); |
509 | } | 605 | } |
510 | return 0; | 606 | return 0; |
511 | } | 607 | } |
512 | 608 | ||
513 | void ODevice::reloadButtonMapping ( ) | 609 | void ODevice::reloadButtonMapping ( ) |
514 | { | 610 | { |
515 | initButtons ( ); | 611 | initButtons ( ); |
516 | 612 | ||
517 | Config cfg ( "ButtonSettings" ); | 613 | Config cfg ( "ButtonSettings" ); |
518 | 614 | ||
519 | for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { | 615 | for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { |
520 | ODeviceButton &b = ( *d-> m_buttons ) [i]; | 616 | ODeviceButton &b = ( *d-> m_buttons ) [i]; |
521 | QString group = "Button" + QString::number ( i ); | 617 | QString group = "Button" + QString::number ( i ); |
522 | 618 | ||
523 | QCString pch, hch; | 619 | QCString pch, hch; |
524 | QCString pm, hm; | 620 | QCString pm, hm; |
525 | QByteArray pdata, hdata; | 621 | QByteArray pdata, hdata; |
526 | 622 | ||
527 | if ( cfg. hasGroup ( group )) { | 623 | if ( cfg. hasGroup ( group )) { |
528 | cfg. setGroup ( group ); | 624 | cfg. setGroup ( group ); |
529 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); | 625 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); |
530 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); | 626 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); |
531 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | 627 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); |
532 | 628 | ||
533 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); | 629 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); |
534 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); | 630 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); |
535 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | 631 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); |
536 | } | 632 | } |
537 | 633 | ||
538 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | 634 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); |
539 | 635 | ||
540 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | 636 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); |
541 | } | 637 | } |
542 | } | 638 | } |
543 | 639 | ||
544 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | 640 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) |
545 | { | 641 | { |
546 | initButtons ( ); | 642 | initButtons ( ); |
547 | 643 | ||
548 | QString mb_chan; | 644 | QString mb_chan; |
549 | 645 | ||
550 | if ( button >= (int) d-> m_buttons-> count ( )) | 646 | if ( button >= (int) d-> m_buttons-> count ( )) |
551 | return; | 647 | return; |
552 | 648 | ||
553 | ODeviceButton &b = ( *d-> m_buttons ) [button]; | 649 | ODeviceButton &b = ( *d-> m_buttons ) [button]; |
554 | b. setPressedAction ( action ); | 650 | b. setPressedAction ( action ); |
555 | 651 | ||
556 | mb_chan=b. pressedAction ( ). channel ( ); | 652 | mb_chan=b. pressedAction ( ). channel ( ); |
557 | 653 | ||
558 | Config buttonFile ( "ButtonSettings" ); | 654 | Config buttonFile ( "ButtonSettings" ); |
559 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 655 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
560 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | 656 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); |
561 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); | 657 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); |
562 | 658 | ||
563 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); | 659 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); |
564 | 660 | ||
565 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 661 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |