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