summaryrefslogtreecommitdiff
path: root/libopie/odevice.cpp
authorkergoth <kergoth>2003-04-18 21:54:43 (UTC)
committer kergoth <kergoth>2003-04-18 21:54:43 (UTC)
commitd0852e67c15c5a973b7bc7f7bee238a6fd00dee6 (patch) (unidiff)
tree68acc72ac204045b2492693ca668ece78e5f3a2c /libopie/odevice.cpp
parent1cdd9c974e621f6992ddc6dfccbc815baebd19ee (diff)
downloadopie-d0852e67c15c5a973b7bc7f7bee238a6fd00dee6.zip
opie-d0852e67c15c5a973b7bc7f7bee238a6fd00dee6.tar.gz
opie-d0852e67c15c5a973b7bc7f7bee238a6fd00dee6.tar.bz2
Add rotation direction to ODevice, to ensure the default is appropriate for the hardware in question.
Diffstat (limited to 'libopie/odevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 0e1c0dd..29c8ad2 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,728 +1,738 @@
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 ODirection m_direction;
70 71
71 QValueList <ODeviceButton> *m_buttons; 72 QValueList <ODeviceButton> *m_buttons;
72 uint m_holdtime; 73 uint m_holdtime;
73}; 74};
74 75
75 76
76class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 77class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
77protected: 78protected:
78 virtual void init ( ); 79 virtual void init ( );
79 virtual void initButtons ( ); 80 virtual void initButtons ( );
80 81
81public: 82public:
82 virtual bool setSoftSuspend ( bool soft ); 83 virtual bool setSoftSuspend ( bool soft );
83 84
84 virtual bool setDisplayBrightness ( int b ); 85 virtual bool setDisplayBrightness ( int b );
85 virtual int displayBrightnessResolution ( ) const; 86 virtual int displayBrightnessResolution ( ) const;
86 87
87 virtual void alarmSound ( ); 88 virtual void alarmSound ( );
88 89
89 virtual QValueList <OLed> ledList ( ) const; 90 virtual QValueList <OLed> ledList ( ) const;
90 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 91 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
91 virtual OLedState ledState ( OLed led ) const; 92 virtual OLedState ledState ( OLed led ) const;
92 virtual bool setLedState ( OLed led, OLedState st ); 93 virtual bool setLedState ( OLed led, OLedState st );
93 94
94 virtual bool hasLightSensor ( ) const; 95 virtual bool hasLightSensor ( ) const;
95 virtual int readLightSensor ( ); 96 virtual int readLightSensor ( );
96 virtual int lightSensorResolution ( ) const; 97 virtual int lightSensorResolution ( ) const;
97 98
98protected: 99protected:
99 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 100 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
100 virtual void timerEvent ( QTimerEvent *te ); 101 virtual void timerEvent ( QTimerEvent *te );
101 102
102 int m_power_timer; 103 int m_power_timer;
103 104
104 OLedState m_leds [2]; 105 OLedState m_leds [2];
105}; 106};
106 107
107class Zaurus : public ODevice { 108class Zaurus : public ODevice {
108protected: 109protected:
109 virtual void init ( ); 110 virtual void init ( );
110 virtual void initButtons ( ); 111 virtual void initButtons ( );
111 112
112public: 113public:
113 virtual bool setSoftSuspend ( bool soft ); 114 virtual bool setSoftSuspend ( bool soft );
114 115
115 virtual bool setDisplayBrightness ( int b ); 116 virtual bool setDisplayBrightness ( int b );
116 virtual int displayBrightnessResolution ( ) const; 117 virtual int displayBrightnessResolution ( ) const;
117 118
118 virtual void alarmSound ( ); 119 virtual void alarmSound ( );
119 virtual void keySound ( ); 120 virtual void keySound ( );
120 virtual void touchSound ( ); 121 virtual void touchSound ( );
121 122
122 virtual QValueList <OLed> ledList ( ) const; 123 virtual QValueList <OLed> ledList ( ) const;
123 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 124 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
124 virtual OLedState ledState ( OLed led ) const; 125 virtual OLedState ledState ( OLed led ) const;
125 virtual bool setLedState ( OLed led, OLedState st ); 126 virtual bool setLedState ( OLed led, OLedState st );
126 127
127protected: 128protected:
128 virtual void buzzer ( int snd ); 129 virtual void buzzer ( int snd );
129 130
130 OLedState m_leds [1]; 131 OLedState m_leds [1];
131}; 132};
132 133
133 134
134struct i_button { 135struct i_button {
135 uint model; 136 uint model;
136 Qt::Key code; 137 Qt::Key code;
137 char *utext; 138 char *utext;
138 char *pix; 139 char *pix;
139 char *fpressedservice; 140 char *fpressedservice;
140 char *fpressedaction; 141 char *fpressedaction;
141 char *fheldservice; 142 char *fheldservice;
142 char *fheldaction; 143 char *fheldaction;
143} ipaq_buttons [] = { 144} ipaq_buttons [] = {
144 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 145 { 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"), 146 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
146 "devicebuttons/ipaq_calendar", 147 "devicebuttons/ipaq_calendar",
147 "datebook", "nextView()", 148 "datebook", "nextView()",
148 "today", "raise()" }, 149 "today", "raise()" },
149 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 150 { 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"), 151 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
151 "devicebuttons/ipaq_contact", 152 "devicebuttons/ipaq_contact",
152 "addressbook", "raise()", 153 "addressbook", "raise()",
153 "addressbook", "beamBusinessCard()" }, 154 "addressbook", "beamBusinessCard()" },
154 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 155 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
155 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 156 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
156 "devicebuttons/ipaq_menu", 157 "devicebuttons/ipaq_menu",
157 "QPE/TaskBar", "toggleMenu()", 158 "QPE/TaskBar", "toggleMenu()",
158 "QPE/TaskBar", "toggleStartMenu()" }, 159 "QPE/TaskBar", "toggleStartMenu()" },
159 { Model_iPAQ_H38xx | Model_iPAQ_H39xx, 160 { Model_iPAQ_H38xx | Model_iPAQ_H39xx,
160 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 161 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
161 "devicebuttons/ipaq_mail", 162 "devicebuttons/ipaq_mail",
162 "mail", "raise()", 163 "mail", "raise()",
163 "mail", "newMail()" }, 164 "mail", "newMail()" },
164 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 165 { 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"), 166 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
166 "devicebuttons/ipaq_home", 167 "devicebuttons/ipaq_home",
167 "QPE/Launcher", "home()", 168 "QPE/Launcher", "home()",
168 "buttonsettings", "raise()" }, 169 "buttonsettings", "raise()" },
169 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, 170 { 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"), 171 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
171 "devicebuttons/ipaq_record", 172 "devicebuttons/ipaq_record",
172 "QPE/VMemo", "toggleRecord()", 173 "QPE/VMemo", "toggleRecord()",
173 "sound", "raise()" }, 174 "sound", "raise()" },
174}; 175};
175 176
176struct z_button { 177struct z_button {
177 Qt::Key code; 178 Qt::Key code;
178 char *utext; 179 char *utext;
179 char *pix; 180 char *pix;
180 char *fpressedservice; 181 char *fpressedservice;
181 char *fpressedaction; 182 char *fpressedaction;
182 char *fheldservice; 183 char *fheldservice;
183 char *fheldaction; 184 char *fheldaction;
184} z_buttons [] = { 185} z_buttons [] = {
185 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 186 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
186 "devicebuttons/z_calendar", 187 "devicebuttons/z_calendar",
187 "datebook", "nextView()", 188 "datebook", "nextView()",
188 "today", "raise()" }, 189 "today", "raise()" },
189 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 190 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
190 "devicebuttons/z_contact", 191 "devicebuttons/z_contact",
191 "addressbook", "raise()", 192 "addressbook", "raise()",
192 "addressbook", "beamBusinessCard()" }, 193 "addressbook", "beamBusinessCard()" },
193 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 194 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
194 "devicebuttons/z_home", 195 "devicebuttons/z_home",
195 "QPE/Launcher", "home()", 196 "QPE/Launcher", "home()",
196 "buttonsettings", "raise()" }, 197 "buttonsettings", "raise()" },
197 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 198 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
198 "devicebuttons/z_menu", 199 "devicebuttons/z_menu",
199 "QPE/TaskBar", "toggleMenu()", 200 "QPE/TaskBar", "toggleMenu()",
200 "QPE/TaskBar", "toggleStartMenu()" }, 201 "QPE/TaskBar", "toggleStartMenu()" },
201 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 202 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
202 "devicebuttons/z_mail", 203 "devicebuttons/z_mail",
203 "mail", "raise()", 204 "mail", "raise()",
204 "mail", "newMail()" }, 205 "mail", "newMail()" },
205}; 206};
206 207
207static QCString makeChannel ( const char *str ) 208static QCString makeChannel ( const char *str )
208{ 209{
209 if ( str && !::strchr ( str, '/' )) 210 if ( str && !::strchr ( str, '/' ))
210 return QCString ( "QPE/Application/" ) + str; 211 return QCString ( "QPE/Application/" ) + str;
211 else 212 else
212 return str; 213 return str;
213} 214}
214 215
215 216
216 217
217 218
218ODevice *ODevice::inst ( ) 219ODevice *ODevice::inst ( )
219{ 220{
220 static ODevice *dev = 0; 221 static ODevice *dev = 0;
221 222
222 if ( !dev ) { 223 if ( !dev ) {
223 if ( QFile::exists ( "/proc/hal/model" )) 224 if ( QFile::exists ( "/proc/hal/model" ))
224 dev = new iPAQ ( ); 225 dev = new iPAQ ( );
225 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 226 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
226 dev = new Zaurus ( ); 227 dev = new Zaurus ( );
227 else 228 else
228 dev = new ODevice ( ); 229 dev = new ODevice ( );
229 230
230 dev-> init ( ); 231 dev-> init ( );
231 } 232 }
232 return dev; 233 return dev;
233} 234}
234 235
235 236
236/************************************************** 237/**************************************************
237 * 238 *
238 * common 239 * common
239 * 240 *
240 **************************************************/ 241 **************************************************/
241 242
242 243
243ODevice::ODevice ( ) 244ODevice::ODevice ( )
244{ 245{
245 d = new ODeviceData; 246 d = new ODeviceData;
246 247
247 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 248 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
248 249
249 d-> m_modelstr = "Unknown"; 250 d-> m_modelstr = "Unknown";
250 d-> m_model = Model_Unknown; 251 d-> m_model = Model_Unknown;
251 d-> m_vendorstr = "Unknown"; 252 d-> m_vendorstr = "Unknown";
252 d-> m_vendor = Vendor_Unknown; 253 d-> m_vendor = Vendor_Unknown;
253 d-> m_systemstr = "Unknown"; 254 d-> m_systemstr = "Unknown";
254 d-> m_system = System_Unknown; 255 d-> m_system = System_Unknown;
255 d-> m_sysverstr = "0.0"; 256 d-> m_sysverstr = "0.0";
256 d-> m_rotation = Rot0; 257 d-> m_rotation = Rot0;
258 d-> m_direction = CW;
257 259
258 d-> m_holdtime = 1000; // 1000ms 260 d-> m_holdtime = 1000; // 1000ms
259 d-> m_buttons = 0; 261 d-> m_buttons = 0;
260} 262}
261 263
262void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 264void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
263{ 265{
264 if ( msg == "deviceButtonMappingChanged()" ) { 266 if ( msg == "deviceButtonMappingChanged()" ) {
265 reloadButtonMapping ( ); 267 reloadButtonMapping ( );
266 } 268 }
267} 269}
268 270
269void ODevice::init ( ) 271void ODevice::init ( )
270{ 272{
271} 273}
272 274
273/** 275/**
274 * This method initialises the button mapping 276 * This method initialises the button mapping
275 */ 277 */
276void ODevice::initButtons ( ) 278void ODevice::initButtons ( )
277{ 279{
278 if ( d-> m_buttons ) 280 if ( d-> m_buttons )
279 return; 281 return;
280 282
281 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 283 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
282 284
283 // Simulation uses iPAQ 3660 device buttons 285 // Simulation uses iPAQ 3660 device buttons
284 286
285 qDebug ( "init Buttons" ); 287 qDebug ( "init Buttons" );
286 d-> m_buttons = new QValueList <ODeviceButton>; 288 d-> m_buttons = new QValueList <ODeviceButton>;
287 289
288 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 290 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
289 i_button *ib = ipaq_buttons + i; 291 i_button *ib = ipaq_buttons + i;
290 ODeviceButton b; 292 ODeviceButton b;
291 293
292 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 294 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
293 b. setKeycode ( ib-> code ); 295 b. setKeycode ( ib-> code );
294 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 296 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
295 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 297 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
296 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 298 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
297 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 299 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
298 d-> m_buttons-> append ( b ); 300 d-> m_buttons-> append ( b );
299 } 301 }
300 } 302 }
301 reloadButtonMapping ( ); 303 reloadButtonMapping ( );
302 304
303 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 305 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
304 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); 306 connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & )));
305} 307}
306 308
307ODevice::~ODevice ( ) 309ODevice::~ODevice ( )
308{ 310{
309 delete d; 311 delete d;
310} 312}
311 313
312bool ODevice::setSoftSuspend ( bool /*soft*/ ) 314bool ODevice::setSoftSuspend ( bool /*soft*/ )
313{ 315{
314 return false; 316 return false;
315} 317}
316 318
317//#include <linux/apm_bios.h> 319//#include <linux/apm_bios.h>
318 320
319#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 321#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
320 322
321/** 323/**
322 * This method will try to suspend the device 324 * This method will try to suspend the device
323 * It only works if the user is the QWS Server and the apm application 325 * It only works if the user is the QWS Server and the apm application
324 * is installed. 326 * is installed.
325 * It tries to suspend and then waits some time cause some distributions 327 * It tries to suspend and then waits some time cause some distributions
326 * do have asynchronus apm implementations. 328 * do have asynchronus apm implementations.
327 * This method will either fail and return false or it'll suspend the 329 * This method will either fail and return false or it'll suspend the
328 * device and return once the device got woken up 330 * device and return once the device got woken up
329 * 331 *
330 * @return if the device got suspended 332 * @return if the device got suspended
331 */ 333 */
332bool ODevice::suspend ( ) 334bool ODevice::suspend ( )
333{ 335{
334 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 336 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
335 return false; 337 return false;
336 338
337 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 339 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
338 return false; 340 return false;
339 341
340 bool res = false; 342 bool res = false;
341 343
342 struct timeval tvs, tvn; 344 struct timeval tvs, tvn;
343 ::gettimeofday ( &tvs, 0 ); 345 ::gettimeofday ( &tvs, 0 );
344 346
345 ::sync ( ); // flush fs caches 347 ::sync ( ); // flush fs caches
346 res = ( ::system ( "apm --suspend" ) == 0 ); 348 res = ( ::system ( "apm --suspend" ) == 0 );
347 349
348 // This is needed because the iPAQ apm implementation is asynchronous and we 350 // This is needed because the iPAQ apm implementation is asynchronous and we
349 // can not be sure when exactly the device is really suspended 351 // can not be sure when exactly the device is really suspended
350 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 352 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
351 353
352 if ( res ) { 354 if ( res ) {
353 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 355 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
354 ::usleep ( 200 * 1000 ); 356 ::usleep ( 200 * 1000 );
355 ::gettimeofday ( &tvn, 0 ); 357 ::gettimeofday ( &tvn, 0 );
356 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 358 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
357 } 359 }
358 360
359 return res; 361 return res;
360} 362}
361 363
362//#include <linux/fb.h> better not rely on kernel headers in userspace ... 364//#include <linux/fb.h> better not rely on kernel headers in userspace ...
363 365
364#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 366#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
365 367
366/* VESA Blanking Levels */ 368/* VESA Blanking Levels */
367#define VESA_NO_BLANKING 0 369#define VESA_NO_BLANKING 0
368#define VESA_VSYNC_SUSPEND 1 370#define VESA_VSYNC_SUSPEND 1
369#define VESA_HSYNC_SUSPEND 2 371#define VESA_HSYNC_SUSPEND 2
370#define VESA_POWERDOWN 3 372#define VESA_POWERDOWN 3
371 373
372/** 374/**
373 * This sets the display on or off 375 * This sets the display on or off
374 */ 376 */
375bool ODevice::setDisplayStatus ( bool on ) 377bool ODevice::setDisplayStatus ( bool on )
376{ 378{
377 if ( d-> m_model == Model_Unknown ) 379 if ( d-> m_model == Model_Unknown )
378 return false; 380 return false;
379 381
380 bool res = false; 382 bool res = false;
381 int fd; 383 int fd;
382 384
383 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 385 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
384 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 386 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
385 ::close ( fd ); 387 ::close ( fd );
386 } 388 }
387 return res; 389 return res;
388} 390}
389 391
390/** 392/**
391 * This sets the display brightness 393 * This sets the display brightness
392 * @return success or failure 394 * @return success or failure
393 */ 395 */
394bool ODevice::setDisplayBrightness ( int p) 396bool ODevice::setDisplayBrightness ( int p)
395{ 397{
396 Q_UNUSED( p ) 398 Q_UNUSED( p )
397 return false; 399 return false;
398} 400}
399 401
400int ODevice::displayBrightnessResolution ( ) const 402int ODevice::displayBrightnessResolution ( ) const
401{ 403{
402 return 16; 404 return 16;
403} 405}
404 406
405/** 407/**
406 * This returns the vendor as string 408 * This returns the vendor as string
407 * @return Vendor as QString 409 * @return Vendor as QString
408 */ 410 */
409QString ODevice::vendorString ( ) const 411QString ODevice::vendorString ( ) const
410{ 412{
411 return d-> m_vendorstr; 413 return d-> m_vendorstr;
412} 414}
413 415
414/** 416/**
415 * This returns the vendor as one of the values of OVendor 417 * This returns the vendor as one of the values of OVendor
416 * @return OVendor 418 * @return OVendor
417 */ 419 */
418OVendor ODevice::vendor ( ) const 420OVendor ODevice::vendor ( ) const
419{ 421{
420 return d-> m_vendor; 422 return d-> m_vendor;
421} 423}
422 424
423/** 425/**
424 * This returns the model as a string 426 * This returns the model as a string
425 * @return A string representing the model 427 * @return A string representing the model
426 */ 428 */
427QString ODevice::modelString ( ) const 429QString ODevice::modelString ( ) const
428{ 430{
429 return d-> m_modelstr; 431 return d-> m_modelstr;
430} 432}
431 433
432/** 434/**
433 * This does return the OModel used 435 * This does return the OModel used
434 */ 436 */
435OModel ODevice::model ( ) const 437OModel ODevice::model ( ) const
436{ 438{
437 return d-> m_model; 439 return d-> m_model;
438} 440}
439 441
440/** 442/**
441 * This does return the systen name 443 * This does return the systen name
442 */ 444 */
443QString ODevice::systemString ( ) const 445QString ODevice::systemString ( ) const
444{ 446{
445 return d-> m_systemstr; 447 return d-> m_systemstr;
446} 448}
447 449
448/** 450/**
449 * Return System as OSystem value 451 * Return System as OSystem value
450 */ 452 */
451OSystem ODevice::system ( ) const 453OSystem ODevice::system ( ) const
452{ 454{
453 return d-> m_system; 455 return d-> m_system;
454} 456}
455 457
456/** 458/**
457 * @return the version string of the base system 459 * @return the version string of the base system
458 */ 460 */
459QString ODevice::systemVersionString ( ) const 461QString ODevice::systemVersionString ( ) const
460{ 462{
461 return d-> m_sysverstr; 463 return d-> m_sysverstr;
462} 464}
463 465
464/** 466/**
465 * @return the current Transformation 467 * @return the current Transformation
466 */ 468 */
467Transformation ODevice::rotation ( ) const 469Transformation ODevice::rotation ( ) const
468{ 470{
469 return d-> m_rotation; 471 return d-> m_rotation;
470} 472}
471 473
472/** 474/**
475 * @return the current rotation direction
476 */
477ODirection ODevice::direction ( ) const
478{
479 return d-> m_direction;
480}
481
482/**
473 * This plays an alarmSound 483 * This plays an alarmSound
474 */ 484 */
475void ODevice::alarmSound ( ) 485void ODevice::alarmSound ( )
476{ 486{
477#ifndef QT_NO_SOUND 487#ifndef QT_NO_SOUND
478 static Sound snd ( "alarm" ); 488 static Sound snd ( "alarm" );
479 489
480 if ( snd. isFinished ( )) 490 if ( snd. isFinished ( ))
481 snd. play ( ); 491 snd. play ( );
482#endif 492#endif
483} 493}
484 494
485/** 495/**
486 * This plays a key sound 496 * This plays a key sound
487 */ 497 */
488void ODevice::keySound ( ) 498void ODevice::keySound ( )
489{ 499{
490#ifndef QT_NO_SOUND 500#ifndef QT_NO_SOUND
491 static Sound snd ( "keysound" ); 501 static Sound snd ( "keysound" );
492 502
493 if ( snd. isFinished ( )) 503 if ( snd. isFinished ( ))
494 snd. play ( ); 504 snd. play ( );
495#endif 505#endif
496} 506}
497 507
498/** 508/**
499 * This plays a touch sound 509 * This plays a touch sound
500 */ 510 */
501void ODevice::touchSound ( ) 511void ODevice::touchSound ( )
502{ 512{
503 513
504#ifndef QT_NO_SOUND 514#ifndef QT_NO_SOUND
505 static Sound snd ( "touchsound" ); 515 static Sound snd ( "touchsound" );
506 516
507 if ( snd. isFinished ( )) 517 if ( snd. isFinished ( ))
508 snd. play ( ); 518 snd. play ( );
509#endif 519#endif
510} 520}
511 521
512/** 522/**
513 * This method will return a list of leds 523 * This method will return a list of leds
514 * available on this device 524 * available on this device
515 * @return a list of LEDs. 525 * @return a list of LEDs.
516 */ 526 */
517QValueList <OLed> ODevice::ledList ( ) const 527QValueList <OLed> ODevice::ledList ( ) const
518{ 528{
519 return QValueList <OLed> ( ); 529 return QValueList <OLed> ( );
520} 530}
521 531
522/** 532/**
523 * This does return the state of the LEDs 533 * This does return the state of the LEDs
524 */ 534 */
525QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 535QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
526{ 536{
527 return QValueList <OLedState> ( ); 537 return QValueList <OLedState> ( );
528} 538}
529 539
530/** 540/**
531 * @return the state for a given OLed 541 * @return the state for a given OLed
532 */ 542 */
533OLedState ODevice::ledState ( OLed /*which*/ ) const 543OLedState ODevice::ledState ( OLed /*which*/ ) const
534{ 544{
535 return Led_Off; 545 return Led_Off;
536} 546}
537 547
538/** 548/**
539 * Set the state for a LED 549 * Set the state for a LED
540 * @param which Which OLed to use 550 * @param which Which OLed to use
541 * @param st The state to set 551 * @param st The state to set
542 * @return success or failure 552 * @return success or failure
543 */ 553 */
544bool ODevice::setLedState ( OLed which, OLedState st ) 554bool ODevice::setLedState ( OLed which, OLedState st )
545{ 555{
546 Q_UNUSED( which ) 556 Q_UNUSED( which )
547 Q_UNUSED( st ) 557 Q_UNUSED( st )
548 return false; 558 return false;
549} 559}
550 560
551/** 561/**
552 * @return if the device has a light sensor 562 * @return if the device has a light sensor
553 */ 563 */
554bool ODevice::hasLightSensor ( ) const 564bool ODevice::hasLightSensor ( ) const
555{ 565{
556 return false; 566 return false;
557} 567}
558 568
559/** 569/**
560 * @return a value from the light senso 570 * @return a value from the light senso
561 */ 571 */
562int ODevice::readLightSensor ( ) 572int ODevice::readLightSensor ( )
563{ 573{
564 return -1; 574 return -1;
565} 575}
566 576
567/** 577/**
568 * @return the light sensor resolution whatever that is ;) 578 * @return the light sensor resolution whatever that is ;)
569 */ 579 */
570int ODevice::lightSensorResolution ( ) const 580int ODevice::lightSensorResolution ( ) const
571{ 581{
572 return 0; 582 return 0;
573} 583}
574 584
575/** 585/**
576 * @return a list of hardware buttons 586 * @return a list of hardware buttons
577 */ 587 */
578const QValueList <ODeviceButton> &ODevice::buttons ( ) 588const QValueList <ODeviceButton> &ODevice::buttons ( )
579{ 589{
580 initButtons ( ); 590 initButtons ( );
581 591
582 return *d-> m_buttons; 592 return *d-> m_buttons;
583} 593}
584 594
585/** 595/**
586 * @return The amount of time that would count as a hold 596 * @return The amount of time that would count as a hold
587 */ 597 */
588uint ODevice::buttonHoldTime ( ) const 598uint ODevice::buttonHoldTime ( ) const
589{ 599{
590 return d-> m_holdtime; 600 return d-> m_holdtime;
591} 601}
592 602
593/** 603/**
594 * This method return a ODeviceButton for a key code 604 * This method return a ODeviceButton for a key code
595 * or 0 if no special hardware button is available for the device 605 * or 0 if no special hardware button is available for the device
596 * 606 *
597 * @return The devicebutton or 0l 607 * @return The devicebutton or 0l
598 * @see ODeviceButton 608 * @see ODeviceButton
599 */ 609 */
600const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 610const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
601{ 611{
602 initButtons ( ); 612 initButtons ( );
603 613
604 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 614 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
605 if ( (*it). keycode ( ) == code ) 615 if ( (*it). keycode ( ) == code )
606 return &(*it); 616 return &(*it);
607 } 617 }
608 return 0; 618 return 0;
609} 619}
610 620
611void ODevice::reloadButtonMapping ( ) 621void ODevice::reloadButtonMapping ( )
612{ 622{
613 initButtons ( ); 623 initButtons ( );
614 624
615 Config cfg ( "ButtonSettings" ); 625 Config cfg ( "ButtonSettings" );
616 626
617 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { 627 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) {
618 ODeviceButton &b = ( *d-> m_buttons ) [i]; 628 ODeviceButton &b = ( *d-> m_buttons ) [i];
619 QString group = "Button" + QString::number ( i ); 629 QString group = "Button" + QString::number ( i );
620 630
621 QCString pch, hch; 631 QCString pch, hch;
622 QCString pm, hm; 632 QCString pm, hm;
623 QByteArray pdata, hdata; 633 QByteArray pdata, hdata;
624 634
625 if ( cfg. hasGroup ( group )) { 635 if ( cfg. hasGroup ( group )) {
626 cfg. setGroup ( group ); 636 cfg. setGroup ( group );
627 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 637 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
628 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 638 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
629 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 639 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
630 640
631 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 641 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
632 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 642 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
633 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 643 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
634 } 644 }
635 645
636 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 646 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
637 647
638 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 648 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
639 } 649 }
640} 650}
641 651
642void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 652void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
643{ 653{
644 initButtons ( ); 654 initButtons ( );
645 655
646 QString mb_chan; 656 QString mb_chan;
647 657
648 if ( button >= (int) d-> m_buttons-> count ( )) 658 if ( button >= (int) d-> m_buttons-> count ( ))
649 return; 659 return;
650 660
651 ODeviceButton &b = ( *d-> m_buttons ) [button]; 661 ODeviceButton &b = ( *d-> m_buttons ) [button];
652 b. setPressedAction ( action ); 662 b. setPressedAction ( action );
653 663
654 mb_chan=b. pressedAction ( ). channel ( ); 664 mb_chan=b. pressedAction ( ). channel ( );
655 665
656 Config buttonFile ( "ButtonSettings" ); 666 Config buttonFile ( "ButtonSettings" );
657 buttonFile. setGroup ( "Button" + QString::number ( button )); 667 buttonFile. setGroup ( "Button" + QString::number ( button ));
658 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 668 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
659 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 669 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
660 670
661 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 671 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
662 672
663 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 673 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
664} 674}
665 675
666void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 676void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
667{ 677{
668 initButtons ( ); 678 initButtons ( );
669 679
670 if ( button >= (int) d-> m_buttons-> count ( )) 680 if ( button >= (int) d-> m_buttons-> count ( ))
671 return; 681 return;
672 682
673 ODeviceButton &b = ( *d-> m_buttons ) [button]; 683 ODeviceButton &b = ( *d-> m_buttons ) [button];
674 b. setHeldAction ( action ); 684 b. setHeldAction ( action );
675 685
676 Config buttonFile ( "ButtonSettings" ); 686 Config buttonFile ( "ButtonSettings" );
677 buttonFile. setGroup ( "Button" + QString::number ( button )); 687 buttonFile. setGroup ( "Button" + QString::number ( button ));
678 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 688 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
679 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 689 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
680 690
681 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 691 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
682 692
683 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 693 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
684} 694}
685 695
686 696
687 697
688 698
689/************************************************** 699/**************************************************
690 * 700 *
691 * iPAQ 701 * iPAQ
692 * 702 *
693 **************************************************/ 703 **************************************************/
694 704
695void iPAQ::init ( ) 705void iPAQ::init ( )
696{ 706{
697 d-> m_vendorstr = "HP"; 707 d-> m_vendorstr = "HP";
698 d-> m_vendor = Vendor_HP; 708 d-> m_vendor = Vendor_HP;
699 709
700 QFile f ( "/proc/hal/model" ); 710 QFile f ( "/proc/hal/model" );
701 711
702 if ( f. open ( IO_ReadOnly )) { 712 if ( f. open ( IO_ReadOnly )) {
703 QTextStream ts ( &f ); 713 QTextStream ts ( &f );
704 714
705 d-> m_modelstr = "H" + ts. readLine ( ); 715 d-> m_modelstr = "H" + ts. readLine ( );
706 716
707 if ( d-> m_modelstr == "H3100" ) 717 if ( d-> m_modelstr == "H3100" )
708 d-> m_model = Model_iPAQ_H31xx; 718 d-> m_model = Model_iPAQ_H31xx;
709 else if ( d-> m_modelstr == "H3600" ) 719 else if ( d-> m_modelstr == "H3600" )
710 d-> m_model = Model_iPAQ_H36xx; 720 d-> m_model = Model_iPAQ_H36xx;
711 else if ( d-> m_modelstr == "H3700" ) 721 else if ( d-> m_modelstr == "H3700" )
712 d-> m_model = Model_iPAQ_H37xx; 722 d-> m_model = Model_iPAQ_H37xx;
713 else if ( d-> m_modelstr == "H3800" ) 723 else if ( d-> m_modelstr == "H3800" )
714 d-> m_model = Model_iPAQ_H38xx; 724 d-> m_model = Model_iPAQ_H38xx;
715 else if ( d-> m_modelstr == "H3900" ) 725 else if ( d-> m_modelstr == "H3900" )
716 d-> m_model = Model_iPAQ_H39xx; 726 d-> m_model = Model_iPAQ_H39xx;
717 else 727 else
718 d-> m_model = Model_Unknown; 728 d-> m_model = Model_Unknown;
719 729
720 f. close ( ); 730 f. close ( );
721 } 731 }
722 732
723 switch ( d-> m_model ) { 733 switch ( d-> m_model ) {
724 case Model_iPAQ_H31xx: 734 case Model_iPAQ_H31xx:
725 case Model_iPAQ_H38xx: 735 case Model_iPAQ_H38xx:
726 d-> m_rotation = Rot90; 736 d-> m_rotation = Rot90;
727 break; 737 break;
728 case Model_iPAQ_H36xx: 738 case Model_iPAQ_H36xx: