-rw-r--r-- | libopie/odevice.cpp | 108 |
1 files changed, 102 insertions, 6 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 9b2a954..8f954b1 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -1,885 +1,981 @@ | |||
1 | /* This file is part of the OPIE libraries | 1 | /* This file is part of the OPIE libraries |
2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) | 2 | Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <unistd.h> | 21 | #include <unistd.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <sys/ioctl.h> | 23 | #include <sys/ioctl.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <linux/soundcard.h> | 26 | #include <linux/soundcard.h> |
27 | #include <math.h> | 27 | #include <math.h> |
28 | 28 | ||
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | 30 | ||
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qpe/sound.h> | 33 | #include <qpe/sound.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/config.h> | 35 | #include <qpe/config.h> |
36 | #include <qpe/qcopenvelope_qws.h> | 36 | #include <qpe/qcopenvelope_qws.h> |
37 | 37 | ||
38 | #include "odevice.h" | 38 | #include "odevice.h" |
39 | 39 | ||
40 | #include <qwindowsystem_qws.h> | 40 | #include <qwindowsystem_qws.h> |
41 | 41 | ||
42 | 42 | ||
43 | // _IO and friends are only defined in kernel headers ... | 43 | // _IO and friends are only defined in kernel headers ... |
44 | 44 | ||
45 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) | 45 | #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) |
46 | 46 | ||
47 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 47 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
48 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) | 48 | #define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) |
49 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) | 49 | #define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) |
50 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) | 50 | #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) |
51 | 51 | ||
52 | using namespace Opie; | 52 | using namespace Opie; |
53 | 53 | ||
54 | class ODeviceData { | 54 | class ODeviceData { |
55 | public: | 55 | public: |
56 | bool m_qwsserver; | 56 | bool m_qwsserver : 1; |
57 | 57 | ||
58 | QString m_vendorstr; | 58 | QString m_vendorstr; |
59 | OVendor m_vendor; | 59 | OVendor m_vendor; |
60 | 60 | ||
61 | QString m_modelstr; | 61 | QString m_modelstr; |
62 | OModel m_model; | 62 | OModel m_model; |
63 | 63 | ||
64 | QString m_systemstr; | 64 | QString m_systemstr; |
65 | OSystem m_system; | 65 | OSystem m_system; |
66 | 66 | ||
67 | QString m_sysverstr; | 67 | QString m_sysverstr; |
68 | 68 | ||
69 | Transformation m_rotation; | 69 | Transformation m_rotation; |
70 | 70 | ||
71 | QValueList <ODeviceButton> *m_buttons; | 71 | QValueList <ODeviceButton> *m_buttons; |
72 | uint m_holdtime; | 72 | uint m_holdtime; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { | 76 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { |
77 | protected: | 77 | protected: |
78 | virtual void init ( ); | 78 | virtual void init ( ); |
79 | virtual void initButtons ( ); | 79 | virtual void initButtons ( ); |
80 | 80 | ||
81 | public: | 81 | public: |
82 | virtual bool setSoftSuspend ( bool soft ); | 82 | virtual bool setSoftSuspend ( bool soft ); |
83 | 83 | ||
84 | virtual bool setDisplayBrightness ( int b ); | 84 | virtual bool setDisplayBrightness ( int b ); |
85 | virtual int displayBrightnessResolution ( ) const; | 85 | virtual int displayBrightnessResolution ( ) const; |
86 | 86 | ||
87 | virtual void alarmSound ( ); | 87 | virtual void alarmSound ( ); |
88 | 88 | ||
89 | virtual QValueList <OLed> ledList ( ) const; | 89 | virtual QValueList <OLed> ledList ( ) const; |
90 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 90 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
91 | virtual OLedState ledState ( OLed led ) const; | 91 | virtual OLedState ledState ( OLed led ) const; |
92 | virtual bool setLedState ( OLed led, OLedState st ); | 92 | virtual bool setLedState ( OLed led, OLedState st ); |
93 | 93 | ||
94 | virtual bool hasLightSensor ( ) const; | 94 | virtual bool hasLightSensor ( ) const; |
95 | virtual int readLightSensor ( ); | 95 | virtual int readLightSensor ( ); |
96 | virtual int lightSensorResolution ( ) const; | 96 | virtual int lightSensorResolution ( ) const; |
97 | 97 | ||
98 | protected: | 98 | protected: |
99 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 99 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
100 | virtual void timerEvent ( QTimerEvent *te ); | 100 | virtual void timerEvent ( QTimerEvent *te ); |
101 | 101 | ||
102 | int m_power_timer; | 102 | int m_power_timer; |
103 | 103 | ||
104 | OLedState m_leds [2]; | 104 | OLedState m_leds [2]; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | class Zaurus : public ODevice { | 107 | class Zaurus : public ODevice { |
108 | protected: | 108 | protected: |
109 | virtual void init ( ); | 109 | virtual void init ( ); |
110 | virtual void initButtons ( ); | 110 | virtual void initButtons ( ); |
111 | 111 | ||
112 | public: | 112 | public: |
113 | virtual bool setSoftSuspend ( bool soft ); | 113 | virtual bool setSoftSuspend ( bool soft ); |
114 | 114 | ||
115 | virtual bool setDisplayBrightness ( int b ); | 115 | virtual bool setDisplayBrightness ( int b ); |
116 | virtual int displayBrightnessResolution ( ) const; | 116 | virtual int displayBrightnessResolution ( ) const; |
117 | 117 | ||
118 | virtual void alarmSound ( ); | 118 | virtual void alarmSound ( ); |
119 | virtual void keySound ( ); | 119 | virtual void keySound ( ); |
120 | virtual void touchSound ( ); | 120 | virtual void touchSound ( ); |
121 | 121 | ||
122 | virtual QValueList <OLed> ledList ( ) const; | 122 | virtual QValueList <OLed> ledList ( ) const; |
123 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 123 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
124 | virtual OLedState ledState ( OLed led ) const; | 124 | virtual OLedState ledState ( OLed led ) const; |
125 | virtual bool setLedState ( OLed led, OLedState st ); | 125 | virtual bool setLedState ( OLed led, OLedState st ); |
126 | 126 | ||
127 | protected: | 127 | protected: |
128 | virtual void buzzer ( int snd ); | 128 | virtual void buzzer ( int snd ); |
129 | 129 | ||
130 | OLedState m_leds [1]; | 130 | OLedState m_leds [1]; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | 133 | ||
134 | struct i_button { | 134 | struct i_button { |
135 | uint model; | 135 | uint model; |
136 | Qt::Key code; | 136 | Qt::Key code; |
137 | char *utext; | 137 | char *utext; |
138 | char *pix; | 138 | char *pix; |
139 | char *fpressedservice; | 139 | char *fpressedservice; |
140 | char *fpressedaction; | 140 | char *fpressedaction; |
141 | char *fheldservice; | 141 | char *fheldservice; |
142 | char *fheldaction; | 142 | char *fheldaction; |
143 | } ipaq_buttons [] = { | 143 | } ipaq_buttons [] = { |
144 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | 144 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, |
145 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 145 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
146 | "devicebuttons/ipaq_calendar", | 146 | "devicebuttons/ipaq_calendar", |
147 | "datebook", "nextView()", | 147 | "datebook", "nextView()", |
148 | "today", "raise()" }, | 148 | "today", "raise()" }, |
149 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | 149 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, |
150 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 150 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
151 | "devicebuttons/ipaq_contact", | 151 | "devicebuttons/ipaq_contact", |
152 | "addressbook", "raise()", | 152 | "addressbook", "raise()", |
153 | "addressbook", "beamBusinessCard()" }, | 153 | "addressbook", "beamBusinessCard()" }, |
154 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, | 154 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, |
155 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 155 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
156 | "devicebuttons/ipaq_menu", | 156 | "devicebuttons/ipaq_menu", |
157 | "QPE/TaskBar", "toggleMenu()", | 157 | "QPE/TaskBar", "toggleMenu()", |
158 | "QPE/TaskBar", "toggleStartMenu()" }, | 158 | "QPE/TaskBar", "toggleStartMenu()" }, |
159 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx, | 159 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx, |
160 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 160 | Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
161 | "devicebuttons/ipaq_mail", | 161 | "devicebuttons/ipaq_mail", |
162 | "mail", "raise()", | 162 | "mail", "raise()", |
163 | "mail", "newMail()" }, | 163 | "mail", "newMail()" }, |
164 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | 164 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, |
165 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 165 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
166 | "devicebuttons/ipaq_home", | 166 | "devicebuttons/ipaq_home", |
167 | "QPE/Launcher", "home()", | 167 | "QPE/Launcher", "home()", |
168 | "buttonsettings", "raise()" }, | 168 | "buttonsettings", "raise()" }, |
169 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | 169 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, |
170 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | 170 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), |
171 | "devicebuttons/ipaq_record", | 171 | "devicebuttons/ipaq_record", |
172 | "QPE/VMemo", "toggleRecord()", | 172 | "QPE/VMemo", "toggleRecord()", |
173 | "sound", "raise()" }, | 173 | "sound", "raise()" }, |
174 | }; | 174 | }; |
175 | 175 | ||
176 | struct z_button { | 176 | struct z_button { |
177 | Qt::Key code; | 177 | Qt::Key code; |
178 | char *utext; | 178 | char *utext; |
179 | char *pix; | 179 | char *pix; |
180 | char *fpressedservice; | 180 | char *fpressedservice; |
181 | char *fpressedaction; | 181 | char *fpressedaction; |
182 | char *fheldservice; | 182 | char *fheldservice; |
183 | char *fheldaction; | 183 | char *fheldaction; |
184 | } z_buttons [] = { | 184 | } z_buttons [] = { |
185 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | 185 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), |
186 | "devicebuttons/z_calendar", | 186 | "devicebuttons/z_calendar", |
187 | "datebook", "nextView()", | 187 | "datebook", "nextView()", |
188 | "today", "raise()" }, | 188 | "today", "raise()" }, |
189 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | 189 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), |
190 | "devicebuttons/z_contact", | 190 | "devicebuttons/z_contact", |
191 | "addressbook", "raise()", | 191 | "addressbook", "raise()", |
192 | "addressbook", "beamBusinessCard()" }, | 192 | "addressbook", "beamBusinessCard()" }, |
193 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | 193 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), |
194 | "devicebuttons/z_home", | 194 | "devicebuttons/z_home", |
195 | "QPE/Launcher", "home()", | 195 | "QPE/Launcher", "home()", |
196 | "buttonsettings", "raise()" }, | 196 | "buttonsettings", "raise()" }, |
197 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | 197 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), |
198 | "devicebuttons/z_menu", | 198 | "devicebuttons/z_menu", |
199 | "QPE/TaskBar", "toggleMenu()", | 199 | "QPE/TaskBar", "toggleMenu()", |
200 | "QPE/TaskBar", "toggleStartMenu()" }, | 200 | "QPE/TaskBar", "toggleStartMenu()" }, |
201 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | 201 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), |
202 | "devicebuttons/z_mail", | 202 | "devicebuttons/z_mail", |
203 | "mail", "raise()", | 203 | "mail", "raise()", |
204 | "mail", "newMail()" }, | 204 | "mail", "newMail()" }, |
205 | }; | 205 | }; |
206 | 206 | ||
207 | static QCString makeChannel ( const char *str ) | 207 | static QCString makeChannel ( const char *str ) |
208 | { | 208 | { |
209 | if ( str && !::strchr ( str, '/' )) | 209 | if ( str && !::strchr ( str, '/' )) |
210 | return QCString ( "QPE/Application/" ) + str; | 210 | return QCString ( "QPE/Application/" ) + str; |
211 | else | 211 | else |
212 | return str; | 212 | return str; |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
216 | 216 | ||
217 | 217 | ||
218 | ODevice *ODevice::inst ( ) | 218 | ODevice *ODevice::inst ( ) |
219 | { | 219 | { |
220 | static ODevice *dev = 0; | 220 | static ODevice *dev = 0; |
221 | 221 | ||
222 | if ( !dev ) { | 222 | if ( !dev ) { |
223 | if ( QFile::exists ( "/proc/hal/model" )) | 223 | if ( QFile::exists ( "/proc/hal/model" )) |
224 | dev = new iPAQ ( ); | 224 | dev = new iPAQ ( ); |
225 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 225 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
226 | dev = new Zaurus ( ); | 226 | dev = new Zaurus ( ); |
227 | else | 227 | else |
228 | dev = new ODevice ( ); | 228 | dev = new ODevice ( ); |
229 | 229 | ||
230 | dev-> init ( ); | 230 | dev-> init ( ); |
231 | } | 231 | } |
232 | return dev; | 232 | return dev; |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | /************************************************** | 236 | /************************************************** |
237 | * | 237 | * |
238 | * common | 238 | * common |
239 | * | 239 | * |
240 | **************************************************/ | 240 | **************************************************/ |
241 | 241 | ||
242 | 242 | ||
243 | ODevice::ODevice ( ) | 243 | ODevice::ODevice ( ) |
244 | { | 244 | { |
245 | d = new ODeviceData; | 245 | d = new ODeviceData; |
246 | 246 | ||
247 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | 247 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; |
248 | 248 | ||
249 | d-> m_modelstr = "Unknown"; | 249 | d-> m_modelstr = "Unknown"; |
250 | d-> m_model = Model_Unknown; | 250 | d-> m_model = Model_Unknown; |
251 | d-> m_vendorstr = "Unknown"; | 251 | d-> m_vendorstr = "Unknown"; |
252 | d-> m_vendor = Vendor_Unknown; | 252 | d-> m_vendor = Vendor_Unknown; |
253 | d-> m_systemstr = "Unknown"; | 253 | d-> m_systemstr = "Unknown"; |
254 | d-> m_system = System_Unknown; | 254 | d-> m_system = System_Unknown; |
255 | d-> m_sysverstr = "0.0"; | 255 | d-> m_sysverstr = "0.0"; |
256 | d-> m_rotation = Rot0; | 256 | d-> m_rotation = Rot0; |
257 | 257 | ||
258 | d-> m_holdtime = 1000; // 1000ms | 258 | d-> m_holdtime = 1000; // 1000ms |
259 | d-> m_buttons = 0; | 259 | d-> m_buttons = 0; |
260 | } | 260 | } |
261 | 261 | ||
262 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | 262 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) |
263 | { | 263 | { |
264 | if ( msg == "deviceButtonMappingChanged()" ) { | 264 | if ( msg == "deviceButtonMappingChanged()" ) { |
265 | reloadButtonMapping ( ); | 265 | reloadButtonMapping ( ); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | void ODevice::init ( ) | 269 | void ODevice::init ( ) |
270 | { | 270 | { |
271 | } | 271 | } |
272 | 272 | ||
273 | /** | ||
274 | * This method initialises the button mapping | ||
275 | */ | ||
273 | void ODevice::initButtons ( ) | 276 | void ODevice::initButtons ( ) |
274 | { | 277 | { |
275 | if ( d-> m_buttons ) | 278 | if ( d-> m_buttons ) |
276 | return; | 279 | return; |
277 | 280 | ||
278 | // Simulation uses iPAQ 3660 device buttons | 281 | // Simulation uses iPAQ 3660 device buttons |
279 | 282 | ||
280 | qDebug ( "init Buttons" ); | 283 | qDebug ( "init Buttons" ); |
281 | d-> m_buttons = new QValueList <ODeviceButton>; | 284 | d-> m_buttons = new QValueList <ODeviceButton>; |
282 | 285 | ||
283 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 286 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
284 | i_button *ib = ipaq_buttons + i; | 287 | i_button *ib = ipaq_buttons + i; |
285 | ODeviceButton b; | 288 | ODeviceButton b; |
286 | 289 | ||
287 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | 290 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { |
288 | b. setKeycode ( ib-> code ); | 291 | b. setKeycode ( ib-> code ); |
289 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | 292 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); |
290 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | 293 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); |
291 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | 294 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); |
292 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | 295 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); |
293 | d-> m_buttons-> append ( b ); | 296 | d-> m_buttons-> append ( b ); |
294 | } | 297 | } |
295 | } | 298 | } |
296 | reloadButtonMapping ( ); | 299 | reloadButtonMapping ( ); |
297 | 300 | ||
298 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 301 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
299 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | 302 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); |
300 | } | 303 | } |
301 | 304 | ||
302 | ODevice::~ODevice ( ) | 305 | ODevice::~ODevice ( ) |
303 | { | 306 | { |
304 | delete d; | 307 | delete d; |
305 | } | 308 | } |
306 | 309 | ||
307 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 310 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
308 | { | 311 | { |
309 | return false; | 312 | return false; |
310 | } | 313 | } |
311 | 314 | ||
312 | //#include <linux/apm_bios.h> | 315 | //#include <linux/apm_bios.h> |
313 | 316 | ||
314 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 317 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
315 | 318 | ||
316 | 319 | /** | |
320 | * This method will try to suspend the device | ||
321 | * It only works if the user is the QWS Server and the apm application | ||
322 | * is installed. | ||
323 | * It tries to suspend and then waits some time cause some distributions | ||
324 | * do have asynchronus apm implementations. | ||
325 | * This method will either fail and return false or it'll suspend the | ||
326 | * device and return once the device got woken up | ||
327 | * | ||
328 | * @return if the device got suspended | ||
329 | */ | ||
317 | bool ODevice::suspend ( ) | 330 | bool ODevice::suspend ( ) |
318 | { | 331 | { |
319 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend | 332 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend |
320 | return false; | 333 | return false; |
321 | 334 | ||
322 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 335 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
323 | return false; | 336 | return false; |
324 | 337 | ||
325 | bool res = false; | 338 | bool res = false; |
326 | 339 | ||
327 | struct timeval tvs, tvn; | 340 | struct timeval tvs, tvn; |
328 | ::gettimeofday ( &tvs, 0 ); | 341 | ::gettimeofday ( &tvs, 0 ); |
329 | 342 | ||
330 | ::sync ( ); // flush fs caches | 343 | ::sync ( ); // flush fs caches |
331 | res = ( ::system ( "apm --suspend" ) == 0 ); | 344 | res = ( ::system ( "apm --suspend" ) == 0 ); |
332 | 345 | ||
333 | // This is needed because the iPAQ apm implementation is asynchronous and we | 346 | // This is needed because the iPAQ apm implementation is asynchronous and we |
334 | // can not be sure when exactly the device is really suspended | 347 | // can not be sure when exactly the device is really suspended |
335 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. | 348 | // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. |
336 | 349 | ||
337 | if ( res ) { | 350 | if ( res ) { |
338 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed | 351 | do { // wait at most 1.5 sec: either suspend didn't work or the device resumed |
339 | ::usleep ( 200 * 1000 ); | 352 | ::usleep ( 200 * 1000 ); |
340 | ::gettimeofday ( &tvn, 0 ); | 353 | ::gettimeofday ( &tvn, 0 ); |
341 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | 354 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); |
342 | } | 355 | } |
343 | 356 | ||
344 | return res; | 357 | return res; |
345 | } | 358 | } |
346 | 359 | ||
347 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | 360 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... |
348 | 361 | ||
349 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 | 362 | #define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 |
350 | 363 | ||
351 | /* VESA Blanking Levels */ | 364 | /* VESA Blanking Levels */ |
352 | #define VESA_NO_BLANKING 0 | 365 | #define VESA_NO_BLANKING 0 |
353 | #define VESA_VSYNC_SUSPEND 1 | 366 | #define VESA_VSYNC_SUSPEND 1 |
354 | #define VESA_HSYNC_SUSPEND 2 | 367 | #define VESA_HSYNC_SUSPEND 2 |
355 | #define VESA_POWERDOWN 3 | 368 | #define VESA_POWERDOWN 3 |
356 | 369 | ||
357 | 370 | /** | |
371 | * This sets the display on or off | ||
372 | */ | ||
358 | bool ODevice::setDisplayStatus ( bool on ) | 373 | bool ODevice::setDisplayStatus ( bool on ) |
359 | { | 374 | { |
360 | if ( d-> m_model == Model_Unknown ) | 375 | if ( d-> m_model == Model_Unknown ) |
361 | return false; | 376 | return false; |
362 | 377 | ||
363 | bool res = false; | 378 | bool res = false; |
364 | int fd; | 379 | int fd; |
365 | 380 | ||
366 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { | 381 | if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { |
367 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); | 382 | res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); |
368 | ::close ( fd ); | 383 | ::close ( fd ); |
369 | } | 384 | } |
370 | return res; | 385 | return res; |
371 | } | 386 | } |
372 | 387 | ||
373 | bool ODevice::setDisplayBrightness ( int ) | 388 | /** |
389 | * This sets the display brightness | ||
390 | * @return success or failure | ||
391 | */ | ||
392 | bool ODevice::setDisplayBrightness ( int p) | ||
374 | { | 393 | { |
394 | Q_UNUSED( p ) | ||
375 | return false; | 395 | return false; |
376 | } | 396 | } |
377 | 397 | ||
378 | int ODevice::displayBrightnessResolution ( ) const | 398 | int ODevice::displayBrightnessResolution ( ) const |
379 | { | 399 | { |
380 | return 16; | 400 | return 16; |
381 | } | 401 | } |
382 | 402 | ||
403 | /** | ||
404 | * This returns the vendor as string | ||
405 | * @return Vendor as QString | ||
406 | */ | ||
383 | QString ODevice::vendorString ( ) const | 407 | QString ODevice::vendorString ( ) const |
384 | { | 408 | { |
385 | return d-> m_vendorstr; | 409 | return d-> m_vendorstr; |
386 | } | 410 | } |
387 | 411 | ||
412 | /** | ||
413 | * This returns the vendor as one of the values of OVendor | ||
414 | * @return OVendor | ||
415 | */ | ||
388 | OVendor ODevice::vendor ( ) const | 416 | OVendor ODevice::vendor ( ) const |
389 | { | 417 | { |
390 | return d-> m_vendor; | 418 | return d-> m_vendor; |
391 | } | 419 | } |
392 | 420 | ||
421 | /** | ||
422 | * This returns the model as a string | ||
423 | * @return A string representing the model | ||
424 | */ | ||
393 | QString ODevice::modelString ( ) const | 425 | QString ODevice::modelString ( ) const |
394 | { | 426 | { |
395 | return d-> m_modelstr; | 427 | return d-> m_modelstr; |
396 | } | 428 | } |
397 | 429 | ||
430 | /** | ||
431 | * This does return the OModel used | ||
432 | */ | ||
398 | OModel ODevice::model ( ) const | 433 | OModel ODevice::model ( ) const |
399 | { | 434 | { |
400 | return d-> m_model; | 435 | return d-> m_model; |
401 | } | 436 | } |
402 | 437 | ||
438 | /** | ||
439 | * This does return the systen name | ||
440 | */ | ||
403 | QString ODevice::systemString ( ) const | 441 | QString ODevice::systemString ( ) const |
404 | { | 442 | { |
405 | return d-> m_systemstr; | 443 | return d-> m_systemstr; |
406 | } | 444 | } |
407 | 445 | ||
446 | /** | ||
447 | * Return System as OSystem value | ||
448 | */ | ||
408 | OSystem ODevice::system ( ) const | 449 | OSystem ODevice::system ( ) const |
409 | { | 450 | { |
410 | return d-> m_system; | 451 | return d-> m_system; |
411 | } | 452 | } |
412 | 453 | ||
454 | /** | ||
455 | * @return the version string of the base system | ||
456 | */ | ||
413 | QString ODevice::systemVersionString ( ) const | 457 | QString ODevice::systemVersionString ( ) const |
414 | { | 458 | { |
415 | return d-> m_sysverstr; | 459 | return d-> m_sysverstr; |
416 | } | 460 | } |
417 | 461 | ||
462 | /** | ||
463 | * @return the current Transformation | ||
464 | */ | ||
418 | Transformation ODevice::rotation ( ) const | 465 | Transformation ODevice::rotation ( ) const |
419 | { | 466 | { |
420 | return d-> m_rotation; | 467 | return d-> m_rotation; |
421 | } | 468 | } |
422 | 469 | ||
470 | /** | ||
471 | * This plays an alarmSound | ||
472 | */ | ||
423 | void ODevice::alarmSound ( ) | 473 | void ODevice::alarmSound ( ) |
424 | { | 474 | { |
425 | #ifndef QT_NO_SOUND | 475 | #ifndef QT_NO_SOUND |
426 | static Sound snd ( "alarm" ); | 476 | static Sound snd ( "alarm" ); |
427 | 477 | ||
428 | if ( snd. isFinished ( )) | 478 | if ( snd. isFinished ( )) |
429 | snd. play ( ); | 479 | snd. play ( ); |
430 | #endif | 480 | #endif |
431 | } | 481 | } |
432 | 482 | ||
483 | /** | ||
484 | * This plays a key sound | ||
485 | */ | ||
433 | void ODevice::keySound ( ) | 486 | void ODevice::keySound ( ) |
434 | { | 487 | { |
435 | #ifndef QT_NO_SOUND | 488 | #ifndef QT_NO_SOUND |
436 | static Sound snd ( "keysound" ); | 489 | static Sound snd ( "keysound" ); |
437 | 490 | ||
438 | if ( snd. isFinished ( )) | 491 | if ( snd. isFinished ( )) |
439 | snd. play ( ); | 492 | snd. play ( ); |
440 | #endif | 493 | #endif |
441 | } | 494 | } |
442 | 495 | ||
496 | /** | ||
497 | * This plays a touch sound | ||
498 | */ | ||
443 | void ODevice::touchSound ( ) | 499 | void ODevice::touchSound ( ) |
444 | { | 500 | { |
445 | 501 | ||
446 | #ifndef QT_NO_SOUND | 502 | #ifndef QT_NO_SOUND |
447 | static Sound snd ( "touchsound" ); | 503 | static Sound snd ( "touchsound" ); |
448 | 504 | ||
449 | if ( snd. isFinished ( )) | 505 | if ( snd. isFinished ( )) |
450 | snd. play ( ); | 506 | snd. play ( ); |
451 | #endif | 507 | #endif |
452 | } | 508 | } |
453 | 509 | ||
454 | 510 | /** | |
511 | * This method will return a list of leds | ||
512 | * available on this device | ||
513 | * @return a list of LEDs. | ||
514 | */ | ||
455 | QValueList <OLed> ODevice::ledList ( ) const | 515 | QValueList <OLed> ODevice::ledList ( ) const |
456 | { | 516 | { |
457 | return QValueList <OLed> ( ); | 517 | return QValueList <OLed> ( ); |
458 | } | 518 | } |
459 | 519 | ||
520 | /** | ||
521 | * This does return the state of the LEDs | ||
522 | */ | ||
460 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const | 523 | QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const |
461 | { | 524 | { |
462 | return QValueList <OLedState> ( ); | 525 | return QValueList <OLedState> ( ); |
463 | } | 526 | } |
464 | 527 | ||
528 | /** | ||
529 | * @return the state for a given OLed | ||
530 | */ | ||
465 | OLedState ODevice::ledState ( OLed /*which*/ ) const | 531 | OLedState ODevice::ledState ( OLed /*which*/ ) const |
466 | { | 532 | { |
467 | return Led_Off; | 533 | return Led_Off; |
468 | } | 534 | } |
469 | 535 | ||
470 | bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) | 536 | /** |
537 | * Set the state for a LED | ||
538 | * @param which Which OLed to use | ||
539 | * @param st The state to set | ||
540 | * @return success or failure | ||
541 | */ | ||
542 | bool ODevice::setLedState ( OLed which, OLedState st ) | ||
471 | { | 543 | { |
544 | Q_UNUSED( which ) | ||
545 | Q_UNUSED( st ) | ||
472 | return false; | 546 | return false; |
473 | } | 547 | } |
474 | 548 | ||
549 | /** | ||
550 | * @return if the device has a light sensor | ||
551 | */ | ||
475 | bool ODevice::hasLightSensor ( ) const | 552 | bool ODevice::hasLightSensor ( ) const |
476 | { | 553 | { |
477 | return false; | 554 | return false; |
478 | } | 555 | } |
479 | 556 | ||
557 | /** | ||
558 | * @return a value from the light senso | ||
559 | */ | ||
480 | int ODevice::readLightSensor ( ) | 560 | int ODevice::readLightSensor ( ) |
481 | { | 561 | { |
482 | return -1; | 562 | return -1; |
483 | } | 563 | } |
484 | 564 | ||
565 | /** | ||
566 | * @return the light sensor resolution whatever that is ;) | ||
567 | */ | ||
485 | int ODevice::lightSensorResolution ( ) const | 568 | int ODevice::lightSensorResolution ( ) const |
486 | { | 569 | { |
487 | return 0; | 570 | return 0; |
488 | } | 571 | } |
489 | 572 | ||
573 | /** | ||
574 | * @return a list of hardware buttons | ||
575 | */ | ||
490 | const QValueList <ODeviceButton> &ODevice::buttons ( ) | 576 | const QValueList <ODeviceButton> &ODevice::buttons ( ) |
491 | { | 577 | { |
492 | initButtons ( ); | 578 | initButtons ( ); |
493 | 579 | ||
494 | return *d-> m_buttons; | 580 | return *d-> m_buttons; |
495 | } | 581 | } |
496 | 582 | ||
583 | /** | ||
584 | * @return The amount of time that would count as a hold | ||
585 | */ | ||
497 | uint ODevice::buttonHoldTime ( ) const | 586 | uint ODevice::buttonHoldTime ( ) const |
498 | { | 587 | { |
499 | return d-> m_holdtime; | 588 | return d-> m_holdtime; |
500 | } | 589 | } |
501 | 590 | ||
591 | /** | ||
592 | * This method return a ODeviceButton for a key code | ||
593 | * or 0 if no special hardware button is available for the device | ||
594 | * | ||
595 | * @return The devicebutton or 0l | ||
596 | * @see ODeviceButton | ||
597 | */ | ||
502 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | 598 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) |
503 | { | 599 | { |
504 | initButtons ( ); | 600 | initButtons ( ); |
505 | 601 | ||
506 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { | 602 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { |
507 | if ( (*it). keycode ( ) == code ) | 603 | if ( (*it). keycode ( ) == code ) |
508 | return &(*it); | 604 | return &(*it); |
509 | } | 605 | } |
510 | return 0; | 606 | return 0; |
511 | } | 607 | } |
512 | 608 | ||
513 | void ODevice::reloadButtonMapping ( ) | 609 | void ODevice::reloadButtonMapping ( ) |
514 | { | 610 | { |
515 | initButtons ( ); | 611 | initButtons ( ); |
516 | 612 | ||
517 | Config cfg ( "ButtonSettings" ); | 613 | Config cfg ( "ButtonSettings" ); |
518 | 614 | ||
519 | for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { | 615 | for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { |
520 | ODeviceButton &b = ( *d-> m_buttons ) [i]; | 616 | ODeviceButton &b = ( *d-> m_buttons ) [i]; |
521 | QString group = "Button" + QString::number ( i ); | 617 | QString group = "Button" + QString::number ( i ); |
522 | 618 | ||
523 | QCString pch, hch; | 619 | QCString pch, hch; |
524 | QCString pm, hm; | 620 | QCString pm, hm; |
525 | QByteArray pdata, hdata; | 621 | QByteArray pdata, hdata; |
526 | 622 | ||
527 | if ( cfg. hasGroup ( group )) { | 623 | if ( cfg. hasGroup ( group )) { |
528 | cfg. setGroup ( group ); | 624 | cfg. setGroup ( group ); |
529 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); | 625 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); |
530 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); | 626 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); |
531 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | 627 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); |
532 | 628 | ||
533 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); | 629 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); |
534 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); | 630 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); |
535 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | 631 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); |
536 | } | 632 | } |
537 | 633 | ||
538 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | 634 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); |
539 | 635 | ||
540 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | 636 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); |
541 | } | 637 | } |
542 | } | 638 | } |
543 | 639 | ||
544 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | 640 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) |
545 | { | 641 | { |
546 | initButtons ( ); | 642 | initButtons ( ); |
547 | 643 | ||
548 | QString mb_chan; | 644 | QString mb_chan; |
549 | 645 | ||
550 | if ( button >= (int) d-> m_buttons-> count ( )) | 646 | if ( button >= (int) d-> m_buttons-> count ( )) |
551 | return; | 647 | return; |
552 | 648 | ||
553 | ODeviceButton &b = ( *d-> m_buttons ) [button]; | 649 | ODeviceButton &b = ( *d-> m_buttons ) [button]; |
554 | b. setPressedAction ( action ); | 650 | b. setPressedAction ( action ); |
555 | 651 | ||
556 | mb_chan=b. pressedAction ( ). channel ( ); | 652 | mb_chan=b. pressedAction ( ). channel ( ); |
557 | 653 | ||
558 | Config buttonFile ( "ButtonSettings" ); | 654 | Config buttonFile ( "ButtonSettings" ); |
559 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 655 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
560 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); | 656 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); |
561 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); | 657 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); |
562 | 658 | ||
563 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); | 659 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); |
564 | 660 | ||
565 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 661 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
566 | } | 662 | } |
567 | 663 | ||
568 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) | 664 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) |
569 | { | 665 | { |
570 | initButtons ( ); | 666 | initButtons ( ); |
571 | 667 | ||
572 | if ( button >= (int) d-> m_buttons-> count ( )) | 668 | if ( button >= (int) d-> m_buttons-> count ( )) |
573 | return; | 669 | return; |
574 | 670 | ||
575 | ODeviceButton &b = ( *d-> m_buttons ) [button]; | 671 | ODeviceButton &b = ( *d-> m_buttons ) [button]; |
576 | b. setHeldAction ( action ); | 672 | b. setHeldAction ( action ); |
577 | 673 | ||
578 | Config buttonFile ( "ButtonSettings" ); | 674 | Config buttonFile ( "ButtonSettings" ); |
579 | buttonFile. setGroup ( "Button" + QString::number ( button )); | 675 | buttonFile. setGroup ( "Button" + QString::number ( button )); |
580 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); | 676 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); |
581 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); | 677 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); |
582 | 678 | ||
583 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); | 679 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); |
584 | 680 | ||
585 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | 681 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); |
586 | } | 682 | } |
587 | 683 | ||
588 | 684 | ||
589 | 685 | ||
590 | 686 | ||
591 | /************************************************** | 687 | /************************************************** |
592 | * | 688 | * |
593 | * iPAQ | 689 | * iPAQ |
594 | * | 690 | * |
595 | **************************************************/ | 691 | **************************************************/ |
596 | 692 | ||
597 | void iPAQ::init ( ) | 693 | void iPAQ::init ( ) |
598 | { | 694 | { |
599 | d-> m_vendorstr = "HP"; | 695 | d-> m_vendorstr = "HP"; |
600 | d-> m_vendor = Vendor_HP; | 696 | d-> m_vendor = Vendor_HP; |
601 | 697 | ||
602 | QFile f ( "/proc/hal/model" ); | 698 | QFile f ( "/proc/hal/model" ); |
603 | 699 | ||
604 | if ( f. open ( IO_ReadOnly )) { | 700 | if ( f. open ( IO_ReadOnly )) { |
605 | QTextStream ts ( &f ); | 701 | QTextStream ts ( &f ); |
606 | 702 | ||
607 | d-> m_modelstr = "H" + ts. readLine ( ); | 703 | d-> m_modelstr = "H" + ts. readLine ( ); |
608 | 704 | ||
609 | if ( d-> m_modelstr == "H3100" ) | 705 | if ( d-> m_modelstr == "H3100" ) |
610 | d-> m_model = Model_iPAQ_H31xx; | 706 | d-> m_model = Model_iPAQ_H31xx; |
611 | else if ( d-> m_modelstr == "H3600" ) | 707 | else if ( d-> m_modelstr == "H3600" ) |
612 | d-> m_model = Model_iPAQ_H36xx; | 708 | d-> m_model = Model_iPAQ_H36xx; |
613 | else if ( d-> m_modelstr == "H3700" ) | 709 | else if ( d-> m_modelstr == "H3700" ) |
614 | d-> m_model = Model_iPAQ_H37xx; | 710 | d-> m_model = Model_iPAQ_H37xx; |
615 | else if ( d-> m_modelstr == "H3800" ) | 711 | else if ( d-> m_modelstr == "H3800" ) |
616 | d-> m_model = Model_iPAQ_H38xx; | 712 | d-> m_model = Model_iPAQ_H38xx; |
617 | else if ( d-> m_modelstr == "H3900" ) | 713 | else if ( d-> m_modelstr == "H3900" ) |
618 | d-> m_model = Model_iPAQ_H39xx; | 714 | d-> m_model = Model_iPAQ_H39xx; |
619 | else | 715 | else |
620 | d-> m_model = Model_Unknown; | 716 | d-> m_model = Model_Unknown; |
621 | 717 | ||
622 | f. close ( ); | 718 | f. close ( ); |
623 | } | 719 | } |
624 | 720 | ||
625 | switch ( d-> m_model ) { | 721 | switch ( d-> m_model ) { |
626 | case Model_iPAQ_H31xx: | 722 | case Model_iPAQ_H31xx: |
627 | case Model_iPAQ_H38xx: | 723 | case Model_iPAQ_H38xx: |
628 | d-> m_rotation = Rot90; | 724 | d-> m_rotation = Rot90; |
629 | break; | 725 | break; |
630 | case Model_iPAQ_H36xx: | 726 | case Model_iPAQ_H36xx: |
631 | case Model_iPAQ_H37xx: | 727 | case Model_iPAQ_H37xx: |
632 | case Model_iPAQ_H39xx: | 728 | case Model_iPAQ_H39xx: |
633 | default: | 729 | default: |
634 | d-> m_rotation = Rot270; | 730 | d-> m_rotation = Rot270; |
635 | break; | 731 | break; |
636 | } | 732 | } |
637 | 733 | ||
638 | f. setName ( "/etc/familiar-version" ); | 734 | f. setName ( "/etc/familiar-version" ); |
639 | if ( f. open ( IO_ReadOnly )) { | 735 | if ( f. open ( IO_ReadOnly )) { |
640 | d-> m_systemstr = "Familiar"; | 736 | d-> m_systemstr = "Familiar"; |
641 | d-> m_system = System_Familiar; | 737 | d-> m_system = System_Familiar; |
642 | 738 | ||
643 | QTextStream ts ( &f ); | 739 | QTextStream ts ( &f ); |
644 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 740 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
645 | 741 | ||
646 | f. close ( ); | 742 | f. close ( ); |
647 | } else { | 743 | } else { |
648 | f. setName ( "/etc/oz_version" ); | 744 | f. setName ( "/etc/oz_version" ); |
649 | 745 | ||
650 | if ( f. open ( IO_ReadOnly )) { | 746 | if ( f. open ( IO_ReadOnly )) { |
651 | d-> m_systemstr = "OpenEmbedded/iPaq"; | 747 | d-> m_systemstr = "OpenEmbedded/iPaq"; |
652 | d-> m_system = System_Familiar; | 748 | d-> m_system = System_Familiar; |
653 | 749 | ||
654 | QTextStream ts ( &f ); | 750 | QTextStream ts ( &f ); |
655 | ts.setDevice ( &f ); | 751 | ts.setDevice ( &f ); |
656 | d-> m_sysverstr = ts. readLine ( ); | 752 | d-> m_sysverstr = ts. readLine ( ); |
657 | f. close ( ); | 753 | f. close ( ); |
658 | } | 754 | } |
659 | } | 755 | } |
660 | 756 | ||
661 | 757 | ||
662 | 758 | ||
663 | 759 | ||
664 | 760 | ||
665 | m_leds [0] = m_leds [1] = Led_Off; | 761 | m_leds [0] = m_leds [1] = Led_Off; |
666 | 762 | ||
667 | m_power_timer = 0; | 763 | m_power_timer = 0; |
668 | 764 | ||
669 | if ( d-> m_qwsserver ) | 765 | if ( d-> m_qwsserver ) |
670 | QWSServer::setKeyboardFilter ( this ); | 766 | QWSServer::setKeyboardFilter ( this ); |
671 | } | 767 | } |
672 | 768 | ||
673 | void iPAQ::initButtons ( ) | 769 | void iPAQ::initButtons ( ) |
674 | { | 770 | { |
675 | if ( d-> m_buttons ) | 771 | if ( d-> m_buttons ) |
676 | return; | 772 | return; |
677 | 773 | ||
678 | d-> m_buttons = new QValueList <ODeviceButton>; | 774 | d-> m_buttons = new QValueList <ODeviceButton>; |
679 | 775 | ||
680 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | 776 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { |
681 | i_button *ib = ipaq_buttons + i; | 777 | i_button *ib = ipaq_buttons + i; |
682 | ODeviceButton b; | 778 | ODeviceButton b; |
683 | 779 | ||
684 | if (( ib-> model & d-> m_model ) == d-> m_model ) { | 780 | if (( ib-> model & d-> m_model ) == d-> m_model ) { |
685 | b. setKeycode ( ib-> code ); | 781 | b. setKeycode ( ib-> code ); |
686 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); | 782 | b. setUserText ( QObject::tr ( "Button", ib-> utext )); |
687 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | 783 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); |
688 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | 784 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); |
689 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | 785 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); |
690 | 786 | ||
691 | d-> m_buttons-> append ( b ); | 787 | d-> m_buttons-> append ( b ); |
692 | } | 788 | } |
693 | } | 789 | } |
694 | reloadButtonMapping ( ); | 790 | reloadButtonMapping ( ); |
695 | 791 | ||
696 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | 792 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); |
697 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | 793 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); |
698 | } | 794 | } |
699 | 795 | ||
700 | 796 | ||
701 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | 797 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... |
702 | 798 | ||
703 | typedef struct { | 799 | typedef struct { |
704 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 800 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
705 | unsigned char TotalTime; /* Units of 5 seconds */ | 801 | unsigned char TotalTime; /* Units of 5 seconds */ |
706 | unsigned char OnTime; /* units of 100m/s */ | 802 | unsigned char OnTime; /* units of 100m/s */ |
707 | unsigned char OffTime; /* units of 100m/s */ | 803 | unsigned char OffTime; /* units of 100m/s */ |
708 | } LED_IN; | 804 | } LED_IN; |
709 | 805 | ||
710 | typedef struct { | 806 | typedef struct { |
711 | unsigned char mode; | 807 | unsigned char mode; |
712 | unsigned char pwr; | 808 | unsigned char pwr; |
713 | unsigned char brightness; | 809 | unsigned char brightness; |
714 | } FLITE_IN; | 810 | } FLITE_IN; |
715 | 811 | ||
716 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 812 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
717 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 813 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
718 | 814 | ||
719 | 815 | ||
720 | QValueList <OLed> iPAQ::ledList ( ) const | 816 | QValueList <OLed> iPAQ::ledList ( ) const |
721 | { | 817 | { |
722 | QValueList <OLed> vl; | 818 | QValueList <OLed> vl; |
723 | vl << Led_Power; | 819 | vl << Led_Power; |
724 | 820 | ||
725 | if ( d-> m_model == Model_iPAQ_H38xx ) | 821 | if ( d-> m_model == Model_iPAQ_H38xx ) |
726 | vl << Led_BlueTooth; | 822 | vl << Led_BlueTooth; |
727 | return vl; | 823 | return vl; |
728 | } | 824 | } |
729 | 825 | ||
730 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const | 826 | QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const |
731 | { | 827 | { |
732 | QValueList <OLedState> vl; | 828 | QValueList <OLedState> vl; |
733 | 829 | ||
734 | if ( l == Led_Power ) | 830 | if ( l == Led_Power ) |
735 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; | 831 | vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; |
736 | else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) | 832 | else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) |
737 | vl << Led_Off; // << Led_On << ??? | 833 | vl << Led_Off; // << Led_On << ??? |
738 | 834 | ||
739 | return vl; | 835 | return vl; |
740 | } | 836 | } |
741 | 837 | ||
742 | OLedState iPAQ::ledState ( OLed l ) const | 838 | OLedState iPAQ::ledState ( OLed l ) const |
743 | { | 839 | { |
744 | switch ( l ) { | 840 | switch ( l ) { |
745 | case Led_Power: | 841 | case Led_Power: |
746 | return m_leds [0]; | 842 | return m_leds [0]; |
747 | case Led_BlueTooth: | 843 | case Led_BlueTooth: |
748 | return m_leds [1]; | 844 | return m_leds [1]; |
749 | default: | 845 | default: |
750 | return Led_Off; | 846 | return Led_Off; |
751 | } | 847 | } |
752 | } | 848 | } |
753 | 849 | ||
754 | bool iPAQ::setLedState ( OLed l, OLedState st ) | 850 | bool iPAQ::setLedState ( OLed l, OLedState st ) |
755 | { | 851 | { |
756 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); | 852 | static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); |
757 | 853 | ||
758 | if ( l == Led_Power ) { | 854 | if ( l == Led_Power ) { |
759 | if ( fd >= 0 ) { | 855 | if ( fd >= 0 ) { |
760 | LED_IN leds; | 856 | LED_IN leds; |
761 | ::memset ( &leds, 0, sizeof( leds )); | 857 | ::memset ( &leds, 0, sizeof( leds )); |
762 | leds. TotalTime = 0; | 858 | leds. TotalTime = 0; |
763 | leds. OnTime = 0; | 859 | leds. OnTime = 0; |
764 | leds. OffTime = 1; | 860 | leds. OffTime = 1; |
765 | leds. OffOnBlink = 2; | 861 | leds. OffOnBlink = 2; |
766 | 862 | ||
767 | switch ( st ) { | 863 | switch ( st ) { |
768 | case Led_Off : leds. OffOnBlink = 0; break; | 864 | case Led_Off : leds. OffOnBlink = 0; break; |
769 | case Led_On : leds. OffOnBlink = 1; break; | 865 | case Led_On : leds. OffOnBlink = 1; break; |
770 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | 866 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; |
771 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | 867 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; |
772 | } | 868 | } |
773 | 869 | ||
774 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | 870 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { |
775 | m_leds [0] = st; | 871 | m_leds [0] = st; |
776 | return true; | 872 | return true; |
777 | } | 873 | } |
778 | } | 874 | } |
779 | } | 875 | } |
780 | return false; | 876 | return false; |
781 | } | 877 | } |
782 | 878 | ||
783 | 879 | ||
784 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 880 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
785 | { | 881 | { |
786 | int newkeycode = keycode; | 882 | int newkeycode = keycode; |
787 | 883 | ||
788 | switch ( keycode ) { | 884 | switch ( keycode ) { |
789 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key | 885 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key |
790 | case HardKey_Menu: { | 886 | case HardKey_Menu: { |
791 | if (( d-> m_model == Model_iPAQ_H38xx ) || | 887 | if (( d-> m_model == Model_iPAQ_H38xx ) || |
792 | ( d-> m_model == Model_iPAQ_H39xx )) { | 888 | ( d-> m_model == Model_iPAQ_H39xx )) { |
793 | newkeycode = HardKey_Mail; | 889 | newkeycode = HardKey_Mail; |
794 | } | 890 | } |
795 | break; | 891 | break; |
796 | } | 892 | } |
797 | 893 | ||
798 | // Rotate cursor keys 180° | 894 | // Rotate cursor keys 180° |
799 | case Key_Left : | 895 | case Key_Left : |
800 | case Key_Right: | 896 | case Key_Right: |
801 | case Key_Up : | 897 | case Key_Up : |
802 | case Key_Down : { | 898 | case Key_Down : { |
803 | if (( d-> m_model == Model_iPAQ_H31xx ) || | 899 | if (( d-> m_model == Model_iPAQ_H31xx ) || |
804 | ( d-> m_model == Model_iPAQ_H38xx )) { | 900 | ( d-> m_model == Model_iPAQ_H38xx )) { |
805 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; | 901 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; |
806 | } | 902 | } |
807 | break; | 903 | break; |
808 | } | 904 | } |
809 | 905 | ||
810 | // map Power Button short/long press to F34/F35 | 906 | // map Power Button short/long press to F34/F35 |
811 | case Key_SysReq: { | 907 | case Key_SysReq: { |
812 | if ( isPress ) { | 908 | if ( isPress ) { |
813 | if ( m_power_timer ) | 909 | if ( m_power_timer ) |
814 | killTimer ( m_power_timer ); | 910 | killTimer ( m_power_timer ); |
815 | m_power_timer = startTimer ( 500 ); | 911 | m_power_timer = startTimer ( 500 ); |
816 | } | 912 | } |
817 | else if ( m_power_timer ) { | 913 | else if ( m_power_timer ) { |
818 | killTimer ( m_power_timer ); | 914 | killTimer ( m_power_timer ); |
819 | m_power_timer = 0; | 915 | m_power_timer = 0; |
820 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); | 916 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); |
821 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); | 917 | QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); |
822 | } | 918 | } |
823 | newkeycode = Key_unknown; | 919 | newkeycode = Key_unknown; |
824 | break; | 920 | break; |
825 | } | 921 | } |
826 | } | 922 | } |
827 | 923 | ||
828 | if ( newkeycode != keycode ) { | 924 | if ( newkeycode != keycode ) { |
829 | if ( newkeycode != Key_unknown ) | 925 | if ( newkeycode != Key_unknown ) |
830 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); | 926 | QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); |
831 | return true; | 927 | return true; |
832 | } | 928 | } |
833 | else | 929 | else |
834 | return false; | 930 | return false; |
835 | } | 931 | } |
836 | 932 | ||
837 | void iPAQ::timerEvent ( QTimerEvent * ) | 933 | void iPAQ::timerEvent ( QTimerEvent * ) |
838 | { | 934 | { |
839 | killTimer ( m_power_timer ); | 935 | killTimer ( m_power_timer ); |
840 | m_power_timer = 0; | 936 | m_power_timer = 0; |
841 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); | 937 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); |
842 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); | 938 | QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); |
843 | } | 939 | } |
844 | 940 | ||
845 | 941 | ||
846 | void iPAQ::alarmSound ( ) | 942 | void iPAQ::alarmSound ( ) |
847 | { | 943 | { |
848 | #ifndef QT_NO_SOUND | 944 | #ifndef QT_NO_SOUND |
849 | static Sound snd ( "alarm" ); | 945 | static Sound snd ( "alarm" ); |
850 | int fd; | 946 | int fd; |
851 | int vol; | 947 | int vol; |
852 | bool vol_reset = false; | 948 | bool vol_reset = false; |
853 | 949 | ||
854 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { | 950 | if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { |
855 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 951 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
856 | Config cfg ( "qpe" ); | 952 | Config cfg ( "qpe" ); |
857 | cfg. setGroup ( "Volume" ); | 953 | cfg. setGroup ( "Volume" ); |
858 | 954 | ||
859 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); | 955 | int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); |
860 | if ( volalarm < 0 ) | 956 | if ( volalarm < 0 ) |
861 | volalarm = 0; | 957 | volalarm = 0; |
862 | else if ( volalarm > 100 ) | 958 | else if ( volalarm > 100 ) |
863 | volalarm = 100; | 959 | volalarm = 100; |
864 | volalarm |= ( volalarm << 8 ); | 960 | volalarm |= ( volalarm << 8 ); |
865 | 961 | ||
866 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) | 962 | if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) |
867 | vol_reset = true; | 963 | vol_reset = true; |
868 | } | 964 | } |
869 | } | 965 | } |
870 | 966 | ||
871 | snd. play ( ); | 967 | snd. play ( ); |
872 | while ( !snd. isFinished ( )) | 968 | while ( !snd. isFinished ( )) |
873 | qApp-> processEvents ( ); | 969 | qApp-> processEvents ( ); |
874 | 970 | ||
875 | if ( fd >= 0 ) { | 971 | if ( fd >= 0 ) { |
876 | if ( vol_reset ) | 972 | if ( vol_reset ) |
877 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); | 973 | ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); |
878 | ::close ( fd ); | 974 | ::close ( fd ); |
879 | } | 975 | } |
880 | #endif | 976 | #endif |
881 | } | 977 | } |
882 | 978 | ||
883 | 979 | ||
884 | bool iPAQ::setSoftSuspend ( bool soft ) | 980 | bool iPAQ::setSoftSuspend ( bool soft ) |
885 | { | 981 | { |