summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 8f954b1..0e1c0dd 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,1377 +1,1384 @@
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
52using namespace Opie; 52using namespace Opie;
53 53
54class ODeviceData { 54class ODeviceData {
55public: 55public:
56 bool m_qwsserver : 1; 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
76class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 76class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
77protected: 77protected:
78 virtual void init ( ); 78 virtual void init ( );
79 virtual void initButtons ( ); 79 virtual void initButtons ( );
80 80
81public: 81public:
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
98protected: 98protected:
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
107class Zaurus : public ODevice { 107class Zaurus : public ODevice {
108protected: 108protected:
109 virtual void init ( ); 109 virtual void init ( );
110 virtual void initButtons ( ); 110 virtual void initButtons ( );
111 111
112public: 112public:
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 ( );
121 121
122 virtual QValueList <OLed> ledList ( ) const; 122 virtual QValueList <OLed> ledList ( ) const;
123 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 123 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
124 virtual OLedState ledState ( OLed led ) const; 124 virtual OLedState ledState ( OLed led ) const;
125 virtual bool setLedState ( OLed led, OLedState st ); 125 virtual bool setLedState ( OLed led, OLedState st );
126 126
127protected: 127protected:
128 virtual void buzzer ( int snd ); 128 virtual void buzzer ( int snd );
129 129
130 OLedState m_leds [1]; 130 OLedState m_leds [1];
131}; 131};
132 132
133 133
134struct i_button { 134struct i_button {
135 uint model; 135 uint model;
136 Qt::Key code; 136 Qt::Key code;
137 char *utext; 137 char *utext;
138 char *pix; 138 char *pix;
139 char *fpressedservice; 139 char *fpressedservice;
140 char *fpressedaction; 140 char *fpressedaction;
141 char *fheldservice; 141 char *fheldservice;
142 char *fheldaction; 142 char *fheldaction;
143} ipaq_buttons [] = { 143} ipaq_buttons [] = {
144 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 144 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
145 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 145 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
146 "devicebuttons/ipaq_calendar", 146 "devicebuttons/ipaq_calendar",
147 "datebook", "nextView()", 147 "datebook", "nextView()",
148 "today", "raise()" }, 148 "today", "raise()" },
149 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 149 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
150 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 150 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
151 "devicebuttons/ipaq_contact", 151 "devicebuttons/ipaq_contact",
152 "addressbook", "raise()", 152 "addressbook", "raise()",
153 "addressbook", "beamBusinessCard()" }, 153 "addressbook", "beamBusinessCard()" },
154 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 154 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
155 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 155 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
156 "devicebuttons/ipaq_menu", 156 "devicebuttons/ipaq_menu",
157 "QPE/TaskBar", "toggleMenu()", 157 "QPE/TaskBar", "toggleMenu()",
158 "QPE/TaskBar", "toggleStartMenu()" }, 158 "QPE/TaskBar", "toggleStartMenu()" },
159 { Model_iPAQ_H38xx | Model_iPAQ_H39xx, 159 { Model_iPAQ_H38xx | Model_iPAQ_H39xx,
160 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 160 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
161 "devicebuttons/ipaq_mail", 161 "devicebuttons/ipaq_mail",
162 "mail", "raise()", 162 "mail", "raise()",
163 "mail", "newMail()" }, 163 "mail", "newMail()" },
164 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 164 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
165 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 165 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
166 "devicebuttons/ipaq_home", 166 "devicebuttons/ipaq_home",
167 "QPE/Launcher", "home()", 167 "QPE/Launcher", "home()",
168 "buttonsettings", "raise()" }, 168 "buttonsettings", "raise()" },
169 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 169 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx,
170 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 170 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
171 "devicebuttons/ipaq_record", 171 "devicebuttons/ipaq_record",
172 "QPE/VMemo", "toggleRecord()", 172 "QPE/VMemo", "toggleRecord()",
173 "sound", "raise()" }, 173 "sound", "raise()" },
174}; 174};
175 175
176struct z_button { 176struct z_button {
177 Qt::Key code; 177 Qt::Key code;
178 char *utext; 178 char *utext;
179 char *pix; 179 char *pix;
180 char *fpressedservice; 180 char *fpressedservice;
181 char *fpressedaction; 181 char *fpressedaction;
182 char *fheldservice; 182 char *fheldservice;
183 char *fheldaction; 183 char *fheldaction;
184} z_buttons [] = { 184} z_buttons [] = {
185 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 185 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
186 "devicebuttons/z_calendar", 186 "devicebuttons/z_calendar",
187 "datebook", "nextView()", 187 "datebook", "nextView()",
188 "today", "raise()" }, 188 "today", "raise()" },
189 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 189 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
190 "devicebuttons/z_contact", 190 "devicebuttons/z_contact",
191 "addressbook", "raise()", 191 "addressbook", "raise()",
192 "addressbook", "beamBusinessCard()" }, 192 "addressbook", "beamBusinessCard()" },
193 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 193 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
194 "devicebuttons/z_home", 194 "devicebuttons/z_home",
195 "QPE/Launcher", "home()", 195 "QPE/Launcher", "home()",
196 "buttonsettings", "raise()" }, 196 "buttonsettings", "raise()" },
197 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 197 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
198 "devicebuttons/z_menu", 198 "devicebuttons/z_menu",
199 "QPE/TaskBar", "toggleMenu()", 199 "QPE/TaskBar", "toggleMenu()",
200 "QPE/TaskBar", "toggleStartMenu()" }, 200 "QPE/TaskBar", "toggleStartMenu()" },
201 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 201 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
202 "devicebuttons/z_mail", 202 "devicebuttons/z_mail",
203 "mail", "raise()", 203 "mail", "raise()",
204 "mail", "newMail()" }, 204 "mail", "newMail()" },
205}; 205};
206 206
207static QCString makeChannel ( const char *str ) 207static QCString makeChannel ( const char *str )
208{ 208{
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
218ODevice *ODevice::inst ( ) 218ODevice *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
243ODevice::ODevice ( ) 243ODevice::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
262void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 262void 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
269void ODevice::init ( ) 269void ODevice::init ( )
270{ 270{
271} 271}
272 272
273/** 273/**
274 * This method initialises the button mapping 274 * This method initialises the button mapping
275 */ 275 */
276void ODevice::initButtons ( ) 276void ODevice::initButtons ( )
277{ 277{
278 if ( d-> m_buttons ) 278 if ( d-> m_buttons )
279 return; 279 return;
280 280
281 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
282
281 // Simulation uses iPAQ 3660 device buttons 283 // Simulation uses iPAQ 3660 device buttons
282 284
283 qDebug ( "init Buttons" ); 285 qDebug ( "init Buttons" );
284 d-> m_buttons = new QValueList <ODeviceButton>; 286 d-> m_buttons = new QValueList <ODeviceButton>;
285 287
286 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 288 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
287 i_button *ib = ipaq_buttons + i; 289 i_button *ib = ipaq_buttons + i;
288 ODeviceButton b; 290 ODeviceButton b;
289 291
290 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 292 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
291 b. setKeycode ( ib-> code ); 293 b. setKeycode ( ib-> code );
292 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 294 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
293 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 295 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
294 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 296 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
295 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 297 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
296 d-> m_buttons-> append ( b ); 298 d-> m_buttons-> append ( b );
297 } 299 }
298 } 300 }
299 reloadButtonMapping ( ); 301 reloadButtonMapping ( );
300 302
301 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 303 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
302 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 304 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
303} 305}
304 306
305ODevice::~ODevice ( ) 307ODevice::~ODevice ( )
306{ 308{
307 delete d; 309 delete d;
308} 310}
309 311
310bool ODevice::setSoftSuspend ( bool /*soft*/ ) 312bool ODevice::setSoftSuspend ( bool /*soft*/ )
311{ 313{
312 return false; 314 return false;
313} 315}
314 316
315//#include <linux/apm_bios.h> 317//#include <linux/apm_bios.h>
316 318
317#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 319#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
318 320
319/** 321/**
320 * This method will try to suspend the device 322 * This method will try to suspend the device
321 * It only works if the user is the QWS Server and the apm application 323 * It only works if the user is the QWS Server and the apm application
322 * is installed. 324 * is installed.
323 * It tries to suspend and then waits some time cause some distributions 325 * It tries to suspend and then waits some time cause some distributions
324 * do have asynchronus apm implementations. 326 * do have asynchronus apm implementations.
325 * This method will either fail and return false or it'll suspend the 327 * This method will either fail and return false or it'll suspend the
326 * device and return once the device got woken up 328 * device and return once the device got woken up
327 * 329 *
328 * @return if the device got suspended 330 * @return if the device got suspended
329 */ 331 */
330bool ODevice::suspend ( ) 332bool ODevice::suspend ( )
331{ 333{
332 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 334 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
333 return false; 335 return false;
334 336
335 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 337 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
336 return false; 338 return false;
337 339
338 bool res = false; 340 bool res = false;
339 341
340 struct timeval tvs, tvn; 342 struct timeval tvs, tvn;
341 ::gettimeofday ( &tvs, 0 ); 343 ::gettimeofday ( &tvs, 0 );
342 344
343 ::sync ( ); // flush fs caches 345 ::sync ( ); // flush fs caches
344 res = ( ::system ( "apm --suspend" ) == 0 ); 346 res = ( ::system ( "apm --suspend" ) == 0 );
345 347
346 // This is needed because the iPAQ apm implementation is asynchronous and we 348 // This is needed because the iPAQ apm implementation is asynchronous and we
347 // can not be sure when exactly the device is really suspended 349 // can not be sure when exactly the device is really suspended
348 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 350 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
349 351
350 if ( res ) { 352 if ( res ) {
351 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 353 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
352 ::usleep ( 200 * 1000 ); 354 ::usleep ( 200 * 1000 );
353 ::gettimeofday ( &tvn, 0 ); 355 ::gettimeofday ( &tvn, 0 );
354 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 356 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
355 } 357 }
356 358
357 return res; 359 return res;
358} 360}
359 361
360//#include <linux/fb.h> better not rely on kernel headers in userspace ... 362//#include <linux/fb.h> better not rely on kernel headers in userspace ...
361 363
362#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 364#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
363 365
364/* VESA Blanking Levels */ 366/* VESA Blanking Levels */
365#define VESA_NO_BLANKING 0 367#define VESA_NO_BLANKING 0
366#define VESA_VSYNC_SUSPEND 1 368#define VESA_VSYNC_SUSPEND 1
367#define VESA_HSYNC_SUSPEND 2 369#define VESA_HSYNC_SUSPEND 2
368#define VESA_POWERDOWN 3 370#define VESA_POWERDOWN 3
369 371
370/** 372/**
371 * This sets the display on or off 373 * This sets the display on or off
372 */ 374 */
373bool ODevice::setDisplayStatus ( bool on ) 375bool ODevice::setDisplayStatus ( bool on )
374{ 376{
375 if ( d-> m_model == Model_Unknown ) 377 if ( d-> m_model == Model_Unknown )
376 return false; 378 return false;
377 379
378 bool res = false; 380 bool res = false;
379 int fd; 381 int fd;
380 382
381 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 383 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
382 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 384 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
383 ::close ( fd ); 385 ::close ( fd );
384 } 386 }
385 return res; 387 return res;
386} 388}
387 389
388/** 390/**
389 * This sets the display brightness 391 * This sets the display brightness
390 * @return success or failure 392 * @return success or failure
391 */ 393 */
392bool ODevice::setDisplayBrightness ( int p) 394bool ODevice::setDisplayBrightness ( int p)
393{ 395{
394 Q_UNUSED( p ) 396 Q_UNUSED( p )
395 return false; 397 return false;
396} 398}
397 399
398int ODevice::displayBrightnessResolution ( ) const 400int ODevice::displayBrightnessResolution ( ) const
399{ 401{
400 return 16; 402 return 16;
401} 403}
402 404
403/** 405/**
404 * This returns the vendor as string 406 * This returns the vendor as string
405 * @return Vendor as QString 407 * @return Vendor as QString
406 */ 408 */
407QString ODevice::vendorString ( ) const 409QString ODevice::vendorString ( ) const
408{ 410{
409 return d-> m_vendorstr; 411 return d-> m_vendorstr;
410} 412}
411 413
412/** 414/**
413 * This returns the vendor as one of the values of OVendor 415 * This returns the vendor as one of the values of OVendor
414 * @return OVendor 416 * @return OVendor
415 */ 417 */
416OVendor ODevice::vendor ( ) const 418OVendor ODevice::vendor ( ) const
417{ 419{
418 return d-> m_vendor; 420 return d-> m_vendor;
419} 421}
420 422
421/** 423/**
422 * This returns the model as a string 424 * This returns the model as a string
423 * @return A string representing the model 425 * @return A string representing the model
424 */ 426 */
425QString ODevice::modelString ( ) const 427QString ODevice::modelString ( ) const
426{ 428{
427 return d-> m_modelstr; 429 return d-> m_modelstr;
428} 430}
429 431
430/** 432/**
431 * This does return the OModel used 433 * This does return the OModel used
432 */ 434 */
433OModel ODevice::model ( ) const 435OModel ODevice::model ( ) const
434{ 436{
435 return d-> m_model; 437 return d-> m_model;
436} 438}
437 439
438/** 440/**
439 * This does return the systen name 441 * This does return the systen name
440 */ 442 */
441QString ODevice::systemString ( ) const 443QString ODevice::systemString ( ) const
442{ 444{
443 return d-> m_systemstr; 445 return d-> m_systemstr;
444} 446}
445 447
446/** 448/**
447 * Return System as OSystem value 449 * Return System as OSystem value
448 */ 450 */
449OSystem ODevice::system ( ) const 451OSystem ODevice::system ( ) const
450{ 452{
451 return d-> m_system; 453 return d-> m_system;
452} 454}
453 455
454/** 456/**
455 * @return the version string of the base system 457 * @return the version string of the base system
456 */ 458 */
457QString ODevice::systemVersionString ( ) const 459QString ODevice::systemVersionString ( ) const
458{ 460{
459 return d-> m_sysverstr; 461 return d-> m_sysverstr;
460} 462}
461 463
462/** 464/**
463 * @return the current Transformation 465 * @return the current Transformation
464 */ 466 */
465Transformation ODevice::rotation ( ) const 467Transformation ODevice::rotation ( ) const
466{ 468{
467 return d-> m_rotation; 469 return d-> m_rotation;
468} 470}
469 471
470/** 472/**
471 * This plays an alarmSound 473 * This plays an alarmSound
472 */ 474 */
473void ODevice::alarmSound ( ) 475void ODevice::alarmSound ( )
474{ 476{
475#ifndef QT_NO_SOUND 477#ifndef QT_NO_SOUND
476 static Sound snd ( "alarm" ); 478 static Sound snd ( "alarm" );
477 479
478 if ( snd. isFinished ( )) 480 if ( snd. isFinished ( ))
479 snd. play ( ); 481 snd. play ( );
480#endif 482#endif
481} 483}
482 484
483/** 485/**
484 * This plays a key sound 486 * This plays a key sound
485 */ 487 */
486void ODevice::keySound ( ) 488void ODevice::keySound ( )
487{ 489{
488#ifndef QT_NO_SOUND 490#ifndef QT_NO_SOUND
489 static Sound snd ( "keysound" ); 491 static Sound snd ( "keysound" );
490 492
491 if ( snd. isFinished ( )) 493 if ( snd. isFinished ( ))
492 snd. play ( ); 494 snd. play ( );
493#endif 495#endif
494} 496}
495 497
496/** 498/**
497 * This plays a touch sound 499 * This plays a touch sound
498 */ 500 */
499void ODevice::touchSound ( ) 501void ODevice::touchSound ( )
500{ 502{
501 503
502#ifndef QT_NO_SOUND 504#ifndef QT_NO_SOUND
503 static Sound snd ( "touchsound" ); 505 static Sound snd ( "touchsound" );
504 506
505 if ( snd. isFinished ( )) 507 if ( snd. isFinished ( ))
506 snd. play ( ); 508 snd. play ( );
507#endif 509#endif
508} 510}
509 511
510/** 512/**
511 * This method will return a list of leds 513 * This method will return a list of leds
512 * available on this device 514 * available on this device
513 * @return a list of LEDs. 515 * @return a list of LEDs.
514 */ 516 */
515QValueList <OLed> ODevice::ledList ( ) const 517QValueList <OLed> ODevice::ledList ( ) const
516{ 518{
517 return QValueList <OLed> ( ); 519 return QValueList <OLed> ( );
518} 520}
519 521
520/** 522/**
521 * This does return the state of the LEDs 523 * This does return the state of the LEDs
522 */ 524 */
523QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 525QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
524{ 526{
525 return QValueList <OLedState> ( ); 527 return QValueList <OLedState> ( );
526} 528}
527 529
528/** 530/**
529 * @return the state for a given OLed 531 * @return the state for a given OLed
530 */ 532 */
531OLedState ODevice::ledState ( OLed /*which*/ ) const 533OLedState ODevice::ledState ( OLed /*which*/ ) const
532{ 534{
533 return Led_Off; 535 return Led_Off;
534} 536}
535 537
536/** 538/**
537 * Set the state for a LED 539 * Set the state for a LED
538 * @param which Which OLed to use 540 * @param which Which OLed to use
539 * @param st The state to set 541 * @param st The state to set
540 * @return success or failure 542 * @return success or failure
541 */ 543 */
542bool ODevice::setLedState ( OLed which, OLedState st ) 544bool ODevice::setLedState ( OLed which, OLedState st )
543{ 545{
544 Q_UNUSED( which ) 546 Q_UNUSED( which )
545 Q_UNUSED( st ) 547 Q_UNUSED( st )
546 return false; 548 return false;
547} 549}
548 550
549/** 551/**
550 * @return if the device has a light sensor 552 * @return if the device has a light sensor
551 */ 553 */
552bool ODevice::hasLightSensor ( ) const 554bool ODevice::hasLightSensor ( ) const
553{ 555{
554 return false; 556 return false;
555} 557}
556 558
557/** 559/**
558 * @return a value from the light senso 560 * @return a value from the light senso
559 */ 561 */
560int ODevice::readLightSensor ( ) 562int ODevice::readLightSensor ( )
561{ 563{
562 return -1; 564 return -1;
563} 565}
564 566
565/** 567/**
566 * @return the light sensor resolution whatever that is ;) 568 * @return the light sensor resolution whatever that is ;)
567 */ 569 */
568int ODevice::lightSensorResolution ( ) const 570int ODevice::lightSensorResolution ( ) const
569{ 571{
570 return 0; 572 return 0;
571} 573}
572 574
573/** 575/**
574 * @return a list of hardware buttons 576 * @return a list of hardware buttons
575 */ 577 */
576const QValueList <ODeviceButton> &ODevice::buttons ( ) 578const QValueList <ODeviceButton> &ODevice::buttons ( )
577{ 579{
578 initButtons ( ); 580 initButtons ( );
579 581
580 return *d-> m_buttons; 582 return *d-> m_buttons;
581} 583}
582 584
583/** 585/**
584 * @return The amount of time that would count as a hold 586 * @return The amount of time that would count as a hold
585 */ 587 */
586uint ODevice::buttonHoldTime ( ) const 588uint ODevice::buttonHoldTime ( ) const
587{ 589{
588 return d-> m_holdtime; 590 return d-> m_holdtime;
589} 591}
590 592
591/** 593/**
592 * This method return a ODeviceButton for a key code 594 * This method return a ODeviceButton for a key code
593 * or 0 if no special hardware button is available for the device 595 * or 0 if no special hardware button is available for the device
594 * 596 *
595 * @return The devicebutton or 0l 597 * @return The devicebutton or 0l
596 * @see ODeviceButton 598 * @see ODeviceButton
597 */ 599 */
598const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 600const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
599{ 601{
600 initButtons ( ); 602 initButtons ( );
601 603
602 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 604 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
603 if ( (*it). keycode ( ) == code ) 605 if ( (*it). keycode ( ) == code )
604 return &(*it); 606 return &(*it);
605 } 607 }
606 return 0; 608 return 0;
607} 609}
608 610
609void ODevice::reloadButtonMapping ( ) 611void ODevice::reloadButtonMapping ( )
610{ 612{
611 initButtons ( ); 613 initButtons ( );
612 614
613 Config cfg ( "ButtonSettings" ); 615 Config cfg ( "ButtonSettings" );
614 616
615 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { 617 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) {
616 ODeviceButton &b = ( *d-> m_buttons ) [i]; 618 ODeviceButton &b = ( *d-> m_buttons ) [i];
617 QString group = "Button" + QString::number ( i ); 619 QString group = "Button" + QString::number ( i );
618 620
619 QCString pch, hch; 621 QCString pch, hch;
620 QCString pm, hm; 622 QCString pm, hm;
621 QByteArray pdata, hdata; 623 QByteArray pdata, hdata;
622 624
623 if ( cfg. hasGroup ( group )) { 625 if ( cfg. hasGroup ( group )) {
624 cfg. setGroup ( group ); 626 cfg. setGroup ( group );
625 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 627 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
626 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 628 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
627 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 629 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
628 630
629 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 631 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
630 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 632 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
631 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 633 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
632 } 634 }
633 635
634 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 636 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
635 637
636 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 638 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
637 } 639 }
638} 640}
639 641
640void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 642void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
641{ 643{
642 initButtons ( ); 644 initButtons ( );
643 645
644 QString mb_chan; 646 QString mb_chan;
645 647
646 if ( button >= (int) d-> m_buttons-> count ( )) 648 if ( button >= (int) d-> m_buttons-> count ( ))
647 return; 649 return;
648 650
649 ODeviceButton &b = ( *d-> m_buttons ) [button]; 651 ODeviceButton &b = ( *d-> m_buttons ) [button];
650 b. setPressedAction ( action ); 652 b. setPressedAction ( action );
651 653
652 mb_chan=b. pressedAction ( ). channel ( ); 654 mb_chan=b. pressedAction ( ). channel ( );
653 655
654 Config buttonFile ( "ButtonSettings" ); 656 Config buttonFile ( "ButtonSettings" );
655 buttonFile. setGroup ( "Button" + QString::number ( button )); 657 buttonFile. setGroup ( "Button" + QString::number ( button ));
656 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 658 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
657 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 659 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
658 660
659 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 661 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
660 662
661 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 663 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
662} 664}
663 665
664void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 666void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
665{ 667{
666 initButtons ( ); 668 initButtons ( );
667 669
668 if ( button >= (int) d-> m_buttons-> count ( )) 670 if ( button >= (int) d-> m_buttons-> count ( ))
669 return; 671 return;
670 672
671 ODeviceButton &b = ( *d-> m_buttons ) [button]; 673 ODeviceButton &b = ( *d-> m_buttons ) [button];
672 b. setHeldAction ( action ); 674 b. setHeldAction ( action );
673 675
674 Config buttonFile ( "ButtonSettings" ); 676 Config buttonFile ( "ButtonSettings" );
675 buttonFile. setGroup ( "Button" + QString::number ( button )); 677 buttonFile. setGroup ( "Button" + QString::number ( button ));
676 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 678 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
677 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 679 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
678 680
679 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 681 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
680 682
681 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 683 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
682} 684}
683 685
684 686
685 687
686 688
687/************************************************** 689/**************************************************
688 * 690 *
689 * iPAQ 691 * iPAQ
690 * 692 *
691 **************************************************/ 693 **************************************************/
692 694
693void iPAQ::init ( ) 695void iPAQ::init ( )
694{ 696{
695 d-> m_vendorstr = "HP"; 697 d-> m_vendorstr = "HP";
696 d-> m_vendor = Vendor_HP; 698 d-> m_vendor = Vendor_HP;
697 699
698 QFile f ( "/proc/hal/model" ); 700 QFile f ( "/proc/hal/model" );
699 701
700 if ( f. open ( IO_ReadOnly )) { 702 if ( f. open ( IO_ReadOnly )) {
701 QTextStream ts ( &f ); 703 QTextStream ts ( &f );
702 704
703 d-> m_modelstr = "H" + ts. readLine ( ); 705 d-> m_modelstr = "H" + ts. readLine ( );
704 706
705 if ( d-> m_modelstr == "H3100" ) 707 if ( d-> m_modelstr == "H3100" )
706 d-> m_model = Model_iPAQ_H31xx; 708 d-> m_model = Model_iPAQ_H31xx;
707 else if ( d-> m_modelstr == "H3600" ) 709 else if ( d-> m_modelstr == "H3600" )
708 d-> m_model = Model_iPAQ_H36xx; 710 d-> m_model = Model_iPAQ_H36xx;
709 else if ( d-> m_modelstr == "H3700" ) 711 else if ( d-> m_modelstr == "H3700" )
710 d-> m_model = Model_iPAQ_H37xx; 712 d-> m_model = Model_iPAQ_H37xx;
711 else if ( d-> m_modelstr == "H3800" ) 713 else if ( d-> m_modelstr == "H3800" )
712 d-> m_model = Model_iPAQ_H38xx; 714 d-> m_model = Model_iPAQ_H38xx;
713 else if ( d-> m_modelstr == "H3900" ) 715 else if ( d-> m_modelstr == "H3900" )
714 d-> m_model = Model_iPAQ_H39xx; 716 d-> m_model = Model_iPAQ_H39xx;
715 else 717 else
716 d-> m_model = Model_Unknown; 718 d-> m_model = Model_Unknown;
717 719
718 f. close ( ); 720 f. close ( );
719 } 721 }
720 722
721 switch ( d-> m_model ) { 723 switch ( d-> m_model ) {
722 case Model_iPAQ_H31xx: 724 case Model_iPAQ_H31xx:
723 case Model_iPAQ_H38xx: 725 case Model_iPAQ_H38xx:
724 d-> m_rotation = Rot90; 726 d-> m_rotation = Rot90;
725 break; 727 break;
726 case Model_iPAQ_H36xx: 728 case Model_iPAQ_H36xx:
727 case Model_iPAQ_H37xx: 729 case Model_iPAQ_H37xx:
728 case Model_iPAQ_H39xx: 730 case Model_iPAQ_H39xx:
729 default: 731 default:
730 d-> m_rotation = Rot270; 732 d-> m_rotation = Rot270;
731 break; 733 break;
732 } 734 }
733 735
734 f. setName ( "/etc/familiar-version" ); 736 f. setName ( "/etc/familiar-version" );
735 if ( f. open ( IO_ReadOnly )) { 737 if ( f. open ( IO_ReadOnly )) {
736 d-> m_systemstr = "Familiar"; 738 d-> m_systemstr = "Familiar";
737 d-> m_system = System_Familiar; 739 d-> m_system = System_Familiar;
738 740
739 QTextStream ts ( &f ); 741 QTextStream ts ( &f );
740 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 742 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
741 743
742 f. close ( ); 744 f. close ( );
743 } else { 745 } else {
744 f. setName ( "/etc/oz_version" ); 746 f. setName ( "/etc/oz_version" );
745 747
746 if ( f. open ( IO_ReadOnly )) { 748 if ( f. open ( IO_ReadOnly )) {
747 d-> m_systemstr = "OpenEmbedded/iPaq"; 749 d-> m_systemstr = "OpenEmbedded/iPaq";
748 d-> m_system = System_Familiar; 750 d-> m_system = System_Familiar;
749 751
750 QTextStream ts ( &f ); 752 QTextStream ts ( &f );
751 ts.setDevice ( &f ); 753 ts.setDevice ( &f );
752 d-> m_sysverstr = ts. readLine ( ); 754 d-> m_sysverstr = ts. readLine ( );
753 f. close ( ); 755 f. close ( );
754 } 756 }
755 } 757 }
756 758
757 759
758 760
759 761
760 762
761 m_leds [0] = m_leds [1] = Led_Off; 763 m_leds [0] = m_leds [1] = Led_Off;
762 764
763 m_power_timer = 0; 765 m_power_timer = 0;
764 766
765 if ( d-> m_qwsserver )
766 QWSServer::setKeyboardFilter ( this );
767} 767}
768 768
769void iPAQ::initButtons ( ) 769void iPAQ::initButtons ( )
770{ 770{
771 if ( d-> m_buttons ) 771 if ( d-> m_buttons )
772 return; 772 return;
773 773
774 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
775
776 if ( d-> m_qwsserver )
777 QWSServer::setKeyboardFilter ( this );
778
774 d-> m_buttons = new QValueList <ODeviceButton>; 779 d-> m_buttons = new QValueList <ODeviceButton>;
775 780
776 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 781 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
777 i_button *ib = ipaq_buttons + i; 782 i_button *ib = ipaq_buttons + i;
778 ODeviceButton b; 783 ODeviceButton b;
779 784
780 if (( ib-> model & d-> m_model ) == d-> m_model ) { 785 if (( ib-> model & d-> m_model ) == d-> m_model ) {
781 b. setKeycode ( ib-> code ); 786 b. setKeycode ( ib-> code );
782 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 787 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
783 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 788 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
784 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 789 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
785 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 790 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
786 791
787 d-> m_buttons-> append ( b ); 792 d-> m_buttons-> append ( b );
788 } 793 }
789 } 794 }
790 reloadButtonMapping ( ); 795 reloadButtonMapping ( );
791 796
792 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 797 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
793 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 798 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
794} 799}
795 800
796 801
797//#include <linux/h3600_ts.h> // including kernel headers is evil ... 802//#include <linux/h3600_ts.h> // including kernel headers is evil ...
798 803
799typedef struct { 804typedef struct {
800 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 805 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
801 unsigned char TotalTime; /* Units of 5 seconds */ 806 unsigned char TotalTime; /* Units of 5 seconds */
802 unsigned char OnTime; /* units of 100m/s */ 807 unsigned char OnTime; /* units of 100m/s */
803 unsigned char OffTime; /* units of 100m/s */ 808 unsigned char OffTime; /* units of 100m/s */
804} LED_IN; 809} LED_IN;
805 810
806typedef struct { 811typedef struct {
807 unsigned char mode; 812 unsigned char mode;
808 unsigned char pwr; 813 unsigned char pwr;
809 unsigned char brightness; 814 unsigned char brightness;
810} FLITE_IN; 815} FLITE_IN;
811 816
812#define LED_ON OD_IOW( 'f', 5, LED_IN ) 817#define LED_ON OD_IOW( 'f', 5, LED_IN )
813#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 818#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
814 819
815 820
816QValueList <OLed> iPAQ::ledList ( ) const 821QValueList <OLed> iPAQ::ledList ( ) const
817{ 822{
818 QValueList <OLed> vl; 823 QValueList <OLed> vl;
819 vl << Led_Power; 824 vl << Led_Power;
820 825
821 if ( d-> m_model == Model_iPAQ_H38xx ) 826 if ( d-> m_model == Model_iPAQ_H38xx )
822 vl << Led_BlueTooth; 827 vl << Led_BlueTooth;
823 return vl; 828 return vl;
824} 829}
825 830
826QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 831QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
827{ 832{
828 QValueList <OLedState> vl; 833 QValueList <OLedState> vl;
829 834
830 if ( l == Led_Power ) 835 if ( l == Led_Power )
831 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 836 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
832 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 837 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
833 vl << Led_Off; // << Led_On << ??? 838 vl << Led_Off; // << Led_On << ???
834 839
835 return vl; 840 return vl;
836} 841}
837 842
838OLedState iPAQ::ledState ( OLed l ) const 843OLedState iPAQ::ledState ( OLed l ) const
839{ 844{
840 switch ( l ) { 845 switch ( l ) {
841 case Led_Power: 846 case Led_Power:
842 return m_leds [0]; 847 return m_leds [0];
843 case Led_BlueTooth: 848 case Led_BlueTooth:
844 return m_leds [1]; 849 return m_leds [1];
845 default: 850 default:
846 return Led_Off; 851 return Led_Off;
847 } 852 }
848} 853}
849 854
850bool iPAQ::setLedState ( OLed l, OLedState st ) 855bool iPAQ::setLedState ( OLed l, OLedState st )
851{ 856{
852 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 857 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
853 858
854 if ( l == Led_Power ) { 859 if ( l == Led_Power ) {
855 if ( fd >= 0 ) { 860 if ( fd >= 0 ) {
856 LED_IN leds; 861 LED_IN leds;
857 ::memset ( &leds, 0, sizeof( leds )); 862 ::memset ( &leds, 0, sizeof( leds ));
858 leds. TotalTime = 0; 863 leds. TotalTime = 0;
859 leds. OnTime = 0; 864 leds. OnTime = 0;
860 leds. OffTime = 1; 865 leds. OffTime = 1;
861 leds. OffOnBlink = 2; 866 leds. OffOnBlink = 2;
862 867
863 switch ( st ) { 868 switch ( st ) {
864 case Led_Off : leds. OffOnBlink = 0; break; 869 case Led_Off : leds. OffOnBlink = 0; break;
865 case Led_On : leds. OffOnBlink = 1; break; 870 case Led_On : leds. OffOnBlink = 1; break;
866 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 871 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
867 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 872 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
868 } 873 }
869 874
870 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 875 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
871 m_leds [0] = st; 876 m_leds [0] = st;
872 return true; 877 return true;
873 } 878 }
874 } 879 }
875 } 880 }
876 return false; 881 return false;
877} 882}
878 883
879 884
880bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 885bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
881{ 886{
882 int newkeycode = keycode; 887 int newkeycode = keycode;
883 888
884 switch ( keycode ) { 889 switch ( keycode ) {
885 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 890 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
886 case HardKey_Menu: { 891 case HardKey_Menu: {
887 if (( d-> m_model == Model_iPAQ_H38xx ) || 892 if (( d-> m_model == Model_iPAQ_H38xx ) ||
888 ( d-> m_model == Model_iPAQ_H39xx )) { 893 ( d-> m_model == Model_iPAQ_H39xx )) {
889 newkeycode = HardKey_Mail; 894 newkeycode = HardKey_Mail;
890 } 895 }
891 break; 896 break;
892 } 897 }
893 898
894 // Rotate cursor keys 180° 899 // Rotate cursor keys 180°
895 case Key_Left : 900 case Key_Left :
896 case Key_Right: 901 case Key_Right:
897 case Key_Up : 902 case Key_Up :
898 case Key_Down : { 903 case Key_Down : {
899 if (( d-> m_model == Model_iPAQ_H31xx ) || 904 if (( d-> m_model == Model_iPAQ_H31xx ) ||
900 ( d-> m_model == Model_iPAQ_H38xx )) { 905 ( d-> m_model == Model_iPAQ_H38xx )) {
901 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 906 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4;
902 } 907 }
903 break; 908 break;
904 } 909 }
905 910
906 // map Power Button short/long press to F34/F35 911 // map Power Button short/long press to F34/F35
907 case Key_SysReq: { 912 case Key_SysReq: {
908 if ( isPress ) { 913 if ( isPress ) {
909 if ( m_power_timer ) 914 if ( m_power_timer )
910 killTimer ( m_power_timer ); 915 killTimer ( m_power_timer );
911 m_power_timer = startTimer ( 500 ); 916 m_power_timer = startTimer ( 500 );
912 } 917 }
913 else if ( m_power_timer ) { 918 else if ( m_power_timer ) {
914 killTimer ( m_power_timer ); 919 killTimer ( m_power_timer );
915 m_power_timer = 0; 920 m_power_timer = 0;
916 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 921 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
917 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 922 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
918 } 923 }
919 newkeycode = Key_unknown; 924 newkeycode = Key_unknown;
920 break; 925 break;
921 } 926 }
922 } 927 }
923 928
924 if ( newkeycode != keycode ) { 929 if ( newkeycode != keycode ) {
925 if ( newkeycode != Key_unknown ) 930 if ( newkeycode != Key_unknown )
926 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 931 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
927 return true; 932 return true;
928 } 933 }
929 else 934 else
930 return false; 935 return false;
931} 936}
932 937
933void iPAQ::timerEvent ( QTimerEvent * ) 938void iPAQ::timerEvent ( QTimerEvent * )
934{ 939{
935 killTimer ( m_power_timer ); 940 killTimer ( m_power_timer );
936 m_power_timer = 0; 941 m_power_timer = 0;
937 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 942 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
938 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 943 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
939} 944}
940 945
941 946
942void iPAQ::alarmSound ( ) 947void iPAQ::alarmSound ( )
943{ 948{
944#ifndef QT_NO_SOUND 949#ifndef QT_NO_SOUND
945 static Sound snd ( "alarm" ); 950 static Sound snd ( "alarm" );
946 int fd; 951 int fd;
947 int vol; 952 int vol;
948 bool vol_reset = false; 953 bool vol_reset = false;
949 954
950 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 955 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
951 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 956 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
952 Config cfg ( "qpe" ); 957 Config cfg ( "qpe" );
953 cfg. setGroup ( "Volume" ); 958 cfg. setGroup ( "Volume" );
954 959
955 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 960 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
956 if ( volalarm < 0 ) 961 if ( volalarm < 0 )
957 volalarm = 0; 962 volalarm = 0;
958 else if ( volalarm > 100 ) 963 else if ( volalarm > 100 )
959 volalarm = 100; 964 volalarm = 100;
960 volalarm |= ( volalarm << 8 ); 965 volalarm |= ( volalarm << 8 );
961 966
962 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 967 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
963 vol_reset = true; 968 vol_reset = true;
964 } 969 }
965 } 970 }
966 971
967 snd. play ( ); 972 snd. play ( );
968 while ( !snd. isFinished ( )) 973 while ( !snd. isFinished ( ))
969 qApp-> processEvents ( ); 974 qApp-> processEvents ( );
970 975
971 if ( fd >= 0 ) { 976 if ( fd >= 0 ) {
972 if ( vol_reset ) 977 if ( vol_reset )
973 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 978 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
974 ::close ( fd ); 979 ::close ( fd );
975 } 980 }
976#endif 981#endif
977} 982}
978 983
979 984
980bool iPAQ::setSoftSuspend ( bool soft ) 985bool iPAQ::setSoftSuspend ( bool soft )
981{ 986{
982 bool res = false; 987 bool res = false;
983 int fd; 988 int fd;
984 989
985 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 990 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
986 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 991 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
987 res = true; 992 res = true;
988 else 993 else
989 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 994 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
990 995
991 ::close ( fd ); 996 ::close ( fd );
992 } 997 }
993 else 998 else
994 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 999 ::perror ( "/proc/sys/ts/suspend_button_mode" );
995 1000
996 return res; 1001 return res;
997} 1002}
998 1003
999 1004
1000bool iPAQ::setDisplayBrightness ( int bright ) 1005bool iPAQ::setDisplayBrightness ( int bright )
1001{ 1006{
1002 bool res = false; 1007 bool res = false;
1003 int fd; 1008 int fd;
1004 1009
1005 if ( bright > 255 ) 1010 if ( bright > 255 )
1006 bright = 255; 1011 bright = 255;
1007 if ( bright < 0 ) 1012 if ( bright < 0 )
1008 bright = 0; 1013 bright = 0;
1009 1014
1010 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 1015 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
1011 FLITE_IN bl; 1016 FLITE_IN bl;
1012 bl. mode = 1; 1017 bl. mode = 1;
1013 bl. pwr = bright ? 1 : 0; 1018 bl. pwr = bright ? 1 : 0;
1014 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 1019 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
1015 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 1020 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
1016 ::close ( fd ); 1021 ::close ( fd );
1017 } 1022 }
1018 return res; 1023 return res;
1019} 1024}
1020 1025
1021int iPAQ::displayBrightnessResolution ( ) const 1026int iPAQ::displayBrightnessResolution ( ) const
1022{ 1027{
1023 switch ( model ( )) { 1028 switch ( model ( )) {
1024 case Model_iPAQ_H31xx: 1029 case Model_iPAQ_H31xx:
1025 case Model_iPAQ_H36xx: 1030 case Model_iPAQ_H36xx:
1026 case Model_iPAQ_H37xx: 1031 case Model_iPAQ_H37xx:
1027 return 128; // really 256, but >128 could damage the LCD 1032 return 128; // really 256, but >128 could damage the LCD
1028 1033
1029 case Model_iPAQ_H38xx: 1034 case Model_iPAQ_H38xx:
1030 case Model_iPAQ_H39xx: 1035 case Model_iPAQ_H39xx:
1031 return 64; 1036 return 64;
1032 1037
1033 default: 1038 default:
1034 return 2; 1039 return 2;
1035 } 1040 }
1036} 1041}
1037 1042
1038 1043
1039bool iPAQ::hasLightSensor ( ) const 1044bool iPAQ::hasLightSensor ( ) const
1040{ 1045{
1041 return true; 1046 return true;
1042} 1047}
1043 1048
1044int iPAQ::readLightSensor ( ) 1049int iPAQ::readLightSensor ( )
1045{ 1050{
1046 int fd; 1051 int fd;
1047 int val = -1; 1052 int val = -1;
1048 1053
1049 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 1054 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
1050 char buffer [8]; 1055 char buffer [8];
1051 1056
1052 if ( ::read ( fd, buffer, 5 ) == 5 ) { 1057 if ( ::read ( fd, buffer, 5 ) == 5 ) {
1053 char *endptr; 1058 char *endptr;
1054 1059
1055 buffer [4] = 0; 1060 buffer [4] = 0;
1056 val = ::strtol ( buffer + 2, &endptr, 16 ); 1061 val = ::strtol ( buffer + 2, &endptr, 16 );
1057 1062
1058 if ( *endptr != 0 ) 1063 if ( *endptr != 0 )
1059 val = -1; 1064 val = -1;
1060 } 1065 }
1061 ::close ( fd ); 1066 ::close ( fd );
1062 } 1067 }
1063 1068
1064 return val; 1069 return val;
1065} 1070}
1066 1071
1067int iPAQ::lightSensorResolution ( ) const 1072int iPAQ::lightSensorResolution ( ) const
1068{ 1073{
1069 return 256; 1074 return 256;
1070} 1075}
1071 1076
1072/************************************************** 1077/**************************************************
1073 * 1078 *
1074 * Zaurus 1079 * Zaurus
1075 * 1080 *
1076 **************************************************/ 1081 **************************************************/
1077 1082
1078 1083
1079 1084
1080void Zaurus::init ( ) 1085void Zaurus::init ( )
1081{ 1086{
1082 d-> m_vendorstr = "Sharp"; 1087 d-> m_vendorstr = "Sharp";
1083 d-> m_vendor = Vendor_Sharp; 1088 d-> m_vendor = Vendor_Sharp;
1084 1089
1085 QFile f ( "/proc/filesystems" ); 1090 QFile f ( "/proc/filesystems" );
1086 1091
1087 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 1092 if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
1088 d-> m_vendorstr = "OpenZaurus Team"; 1093 d-> m_vendorstr = "OpenZaurus Team";
1089 d-> m_systemstr = "OpenZaurus"; 1094 d-> m_systemstr = "OpenZaurus";
1090 d-> m_system = System_OpenZaurus; 1095 d-> m_system = System_OpenZaurus;
1091 1096
1092 f. close ( ); 1097 f. close ( );
1093 1098
1094 f. setName ( "/etc/oz_version" ); 1099 f. setName ( "/etc/oz_version" );
1095 if ( f. open ( IO_ReadOnly )) { 1100 if ( f. open ( IO_ReadOnly )) {
1096 QTextStream ts ( &f ); 1101 QTextStream ts ( &f );
1097 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); 1102 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 );
1098 f. close ( ); 1103 f. close ( );
1099 } 1104 }
1100 } 1105 }
1101 else { 1106 else {
1102 d-> m_systemstr = "Zaurus"; 1107 d-> m_systemstr = "Zaurus";
1103 d-> m_system = System_Zaurus; 1108 d-> m_system = System_Zaurus;
1104 } 1109 }
1105 1110
1106 f. setName ( "/proc/deviceinfo/product" ); 1111 f. setName ( "/proc/deviceinfo/product" );
1107 if ( f. open ( IO_ReadOnly ) ) { 1112 if ( f. open ( IO_ReadOnly ) ) {
1108 QTextStream ts ( &f ); 1113 QTextStream ts ( &f );
1109 QString model = ts. readLine ( ); 1114 QString model = ts. readLine ( );
1110 f. close ( ); 1115 f. close ( );
1111 1116
1112 d-> m_modelstr = QString("Zaurus ") + model; 1117 d-> m_modelstr = QString("Zaurus ") + model;
1113 if ( model == "SL-5500" ) 1118 if ( model == "SL-5500" )
1114 d-> m_model = Model_Zaurus_SL5500; 1119 d-> m_model = Model_Zaurus_SL5500;
1115 else if ( model == "SL-C700" ) 1120 else if ( model == "SL-C700" )
1116 d-> m_model = Model_Zaurus_SLC700; 1121 d-> m_model = Model_Zaurus_SLC700;
1117 else if ( model == "SL-A300" ) 1122 else if ( model == "SL-A300" )
1118 d-> m_model = Model_Zaurus_SLA300; 1123 d-> m_model = Model_Zaurus_SLA300;
1119 else if ( model == "SL-B600" || model == "SL-5600" ) 1124 else if ( model == "SL-B600" || model == "SL-5600" )
1120 d-> m_model = Model_Zaurus_SLB600; 1125 d-> m_model = Model_Zaurus_SLB600;
1121 else 1126 else
1122 d-> m_model = Model_Zaurus_SL5000; 1127 d-> m_model = Model_Zaurus_SL5000;
1123 } 1128 }
1124 else { 1129 else {
1125 d-> m_model = Model_Zaurus_SL5000; 1130 d-> m_model = Model_Zaurus_SL5000;
1126 d-> m_modelstr = "Zaurus (model unknown)"; 1131 d-> m_modelstr = "Zaurus (model unknown)";
1127 } 1132 }
1128 1133
1129 switch ( d-> m_model ) { 1134 switch ( d-> m_model ) {
1130 case Model_Zaurus_SLA300: 1135 case Model_Zaurus_SLA300:
1131 d-> m_rotation = Rot0; 1136 d-> m_rotation = Rot0;
1132 break; 1137 break;
1133 case Model_Zaurus_SLC700: 1138 case Model_Zaurus_SLC700:
1134 /* note for C700, we must check the display rotation 1139 /* note for C700, we must check the display rotation
1135 * sensor to set an appropriate value 1140 * sensor to set an appropriate value
1136 */ 1141 */
1137 case Model_Zaurus_SLB600: 1142 case Model_Zaurus_SLB600:
1138 case Model_Zaurus_SL5500: 1143 case Model_Zaurus_SL5500:
1139 case Model_Zaurus_SL5000: 1144 case Model_Zaurus_SL5000:
1140 default: 1145 default:
1141 d-> m_rotation = Rot270; 1146 d-> m_rotation = Rot270;
1142 break; 1147 break;
1143 } 1148 }
1144 m_leds [0] = Led_Off; 1149 m_leds [0] = Led_Off;
1145} 1150}
1146 1151
1147void Zaurus::initButtons ( ) 1152void Zaurus::initButtons ( )
1148{ 1153{
1149 if ( d-> m_buttons ) 1154 if ( d-> m_buttons )
1150 return; 1155 return;
1151 1156
1157 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
1158
1152 d-> m_buttons = new QValueList <ODeviceButton>; 1159 d-> m_buttons = new QValueList <ODeviceButton>;
1153 1160
1154 for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) { 1161 for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) {
1155 z_button *zb = z_buttons + i; 1162 z_button *zb = z_buttons + i;
1156 ODeviceButton b; 1163 ODeviceButton b;
1157 1164
1158 b. setKeycode ( zb-> code ); 1165 b. setKeycode ( zb-> code );
1159 b. setUserText ( QObject::tr ( "Button", zb-> utext )); 1166 b. setUserText ( QObject::tr ( "Button", zb-> utext ));
1160 b. setPixmap ( Resource::loadPixmap ( zb-> pix )); 1167 b. setPixmap ( Resource::loadPixmap ( zb-> pix ));
1161 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction )); 1168 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction ));
1162 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction )); 1169 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction ));
1163 1170
1164 d-> m_buttons-> append ( b ); 1171 d-> m_buttons-> append ( b );
1165 } 1172 }
1166 1173
1167 reloadButtonMapping ( ); 1174 reloadButtonMapping ( );
1168 1175
1169 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 1176 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
1170 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 1177 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
1171} 1178}
1172 1179
1173#include <unistd.h> 1180#include <unistd.h>
1174#include <fcntl.h> 1181#include <fcntl.h>
1175#include <sys/ioctl.h> 1182#include <sys/ioctl.h>
1176 1183
1177//#include <asm/sharp_char.h> // including kernel headers is evil ... 1184//#include <asm/sharp_char.h> // including kernel headers is evil ...
1178 1185
1179#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 1186#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
1180 1187
1181 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1188 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1182#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1189#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1183 1190
1184#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1191#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1185#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1192#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1186#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1193#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1187 1194
1188/* --- for SHARP_BUZZER device --- */ 1195/* --- for SHARP_BUZZER device --- */
1189 1196
1190 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1197 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1191//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1198//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1192 1199
1193#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 1200#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
1194#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 1201#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
1195#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 1202#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
1196#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 1203#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
1197#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 1204#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
1198 1205
1199//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1206//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1200//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1207//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1201 1208
1202//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 1209//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
1203//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 1210//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
1204//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 1211//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
1205//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 1212//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
1206//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 1213//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
1207//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 1214//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
1208//#define SHARP_PDA_APPSTART 9 /* application start */ 1215//#define SHARP_PDA_APPSTART 9 /* application start */
1209//#define SHARP_PDA_APPQUIT 10 /* application ends */ 1216//#define SHARP_PDA_APPQUIT 10 /* application ends */
1210 1217
1211//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1218//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1212//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 1219//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
1213//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 1220//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
1214//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 1221//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
1215// 1222//
1216 1223
1217 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1224 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1218#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 1225#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
1219 1226
1220typedef struct sharp_led_status { 1227typedef struct sharp_led_status {
1221 int which; /* select which LED status is wanted. */ 1228 int which; /* select which LED status is wanted. */
1222 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 1229 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
1223} sharp_led_status; 1230} sharp_led_status;
1224 1231
1225#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 1232#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
1226 1233
1227#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 1234#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
1228#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 1235#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
1229#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 1236#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
1230 1237
1231// #include <asm/sharp_apm.h> // including kernel headers is evil ... 1238// #include <asm/sharp_apm.h> // including kernel headers is evil ...
1232 1239
1233#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 1240#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
1234#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 1241#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
1235#define APM_EVT_POWER_BUTTON (1 << 0) 1242#define APM_EVT_POWER_BUTTON (1 << 0)
1236 1243
1237#define FL_IOCTL_STEP_CONTRAST 100 1244#define FL_IOCTL_STEP_CONTRAST 100
1238 1245
1239 1246
1240void Zaurus::buzzer ( int sound ) 1247void Zaurus::buzzer ( int sound )
1241{ 1248{
1242 static int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 1249 static int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
1243 1250
1244 if ( fd >= 0 ) { 1251 if ( fd >= 0 ) {
1245 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 1252 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
1246 ::close ( fd ); 1253 ::close ( fd );
1247 } 1254 }
1248} 1255}
1249 1256
1250 1257
1251void Zaurus::alarmSound ( ) 1258void Zaurus::alarmSound ( )
1252{ 1259{
1253 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 1260 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
1254} 1261}
1255 1262
1256void Zaurus::touchSound ( ) 1263void Zaurus::touchSound ( )
1257{ 1264{
1258 buzzer ( SHARP_BUZ_TOUCHSOUND ); 1265 buzzer ( SHARP_BUZ_TOUCHSOUND );
1259} 1266}
1260 1267
1261void Zaurus::keySound ( ) 1268void Zaurus::keySound ( )
1262{ 1269{
1263 buzzer ( SHARP_BUZ_KEYSOUND ); 1270 buzzer ( SHARP_BUZ_KEYSOUND );
1264} 1271}
1265 1272
1266 1273
1267QValueList <OLed> Zaurus::ledList ( ) const 1274QValueList <OLed> Zaurus::ledList ( ) const
1268{ 1275{
1269 QValueList <OLed> vl; 1276 QValueList <OLed> vl;
1270 vl << Led_Mail; 1277 vl << Led_Mail;
1271 return vl; 1278 return vl;
1272} 1279}
1273 1280
1274QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 1281QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
1275{ 1282{
1276 QValueList <OLedState> vl; 1283 QValueList <OLedState> vl;
1277 1284
1278 if ( l == Led_Mail ) 1285 if ( l == Led_Mail )
1279 vl << Led_Off << Led_On << Led_BlinkSlow; 1286 vl << Led_Off << Led_On << Led_BlinkSlow;
1280 return vl; 1287 return vl;
1281} 1288}
1282 1289
1283OLedState Zaurus::ledState ( OLed which ) const 1290OLedState Zaurus::ledState ( OLed which ) const
1284{ 1291{
1285 if ( which == Led_Mail ) 1292 if ( which == Led_Mail )
1286 return m_leds [0]; 1293 return m_leds [0];
1287 else 1294 else
1288 return Led_Off; 1295 return Led_Off;
1289} 1296}
1290 1297
1291bool Zaurus::setLedState ( OLed which, OLedState st ) 1298bool Zaurus::setLedState ( OLed which, OLedState st )
1292{ 1299{
1293 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 1300 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
1294 1301
1295 if ( which == Led_Mail ) { 1302 if ( which == Led_Mail ) {
1296 if ( fd >= 0 ) { 1303 if ( fd >= 0 ) {
1297 struct sharp_led_status leds; 1304 struct sharp_led_status leds;
1298 ::memset ( &leds, 0, sizeof( leds )); 1305 ::memset ( &leds, 0, sizeof( leds ));
1299 leds. which = SHARP_LED_MAIL_EXISTS; 1306 leds. which = SHARP_LED_MAIL_EXISTS;
1300 bool ok = true; 1307 bool ok = true;
1301 1308
1302 switch ( st ) { 1309 switch ( st ) {
1303 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 1310 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
1304 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 1311 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
1305 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 1312 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
1306 default : ok = false; 1313 default : ok = false;
1307 } 1314 }
1308 1315
1309 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 1316 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
1310 m_leds [0] = st; 1317 m_leds [0] = st;
1311 return true; 1318 return true;
1312 } 1319 }
1313 } 1320 }
1314 } 1321 }
1315 return false; 1322 return false;
1316} 1323}
1317 1324
1318bool Zaurus::setSoftSuspend ( bool soft ) 1325bool Zaurus::setSoftSuspend ( bool soft )
1319{ 1326{
1320 bool res = false; 1327 bool res = false;
1321 int fd; 1328 int fd;
1322 1329
1323 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 1330 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
1324 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 1331 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
1325 1332
1326 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 1333 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
1327 1334
1328 if ( sources >= 0 ) { 1335 if ( sources >= 0 ) {
1329 if ( soft ) 1336 if ( soft )
1330 sources &= ~APM_EVT_POWER_BUTTON; 1337 sources &= ~APM_EVT_POWER_BUTTON;
1331 else 1338 else
1332 sources |= APM_EVT_POWER_BUTTON; 1339 sources |= APM_EVT_POWER_BUTTON;
1333 1340
1334 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 1341 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
1335 res = true; 1342 res = true;
1336 else 1343 else
1337 perror ( "APM_IOCGEVTSRC" ); 1344 perror ( "APM_IOCGEVTSRC" );
1338 } 1345 }
1339 else 1346 else
1340 perror ( "APM_IOCGEVTSRC" ); 1347 perror ( "APM_IOCGEVTSRC" );
1341 1348
1342 ::close ( fd ); 1349 ::close ( fd );
1343 } 1350 }
1344 else 1351 else
1345 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 1352 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
1346 1353
1347 return res; 1354 return res;
1348} 1355}
1349 1356
1350 1357
1351bool Zaurus::setDisplayBrightness ( int bright ) 1358bool Zaurus::setDisplayBrightness ( int bright )
1352{ 1359{
1353 bool res = false; 1360 bool res = false;
1354 int fd; 1361 int fd;
1355 1362
1356 if ( bright > 255 ) 1363 if ( bright > 255 )
1357 bright = 255; 1364 bright = 255;
1358 if ( bright < 0 ) 1365 if ( bright < 0 )
1359 bright = 0; 1366 bright = 0;
1360 1367
1361 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 1368 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
1362 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 1369 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
1363 if ( bright && !bl ) 1370 if ( bright && !bl )
1364 bl = 1; 1371 bl = 1;
1365 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 1372 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
1366 ::close ( fd ); 1373 ::close ( fd );
1367 } 1374 }
1368 return res; 1375 return res;
1369} 1376}
1370 1377
1371 1378
1372int Zaurus::displayBrightnessResolution ( ) const 1379int Zaurus::displayBrightnessResolution ( ) const
1373{ 1380{
1374 return 5; 1381 return 5;
1375} 1382}
1376 1383
1377 1384