-rw-r--r-- | libopie/odevice.cpp | 246 |
1 files changed, 230 insertions, 16 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index c947630..f93d1ed 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -12,189 +12,297 @@ | |||
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 | 37 | ||
37 | #include "odevice.h" | 38 | #include "odevice.h" |
38 | 39 | ||
39 | #include <qwindowsystem_qws.h> | 40 | #include <qwindowsystem_qws.h> |
40 | 41 | ||
41 | 42 | ||
42 | // _IO and friends are only defined in kernel headers ... | 43 | // _IO and friends are only defined in kernel headers ... |
43 | 44 | ||
44 | #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 )) |
45 | 46 | ||
46 | #define OD_IO(type,number) OD_IOC(0,type,number,0) | 47 | #define OD_IO(type,number) OD_IOC(0,type,number,0) |
47 | #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)) |
48 | #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)) |
49 | #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)) |
50 | 51 | ||
51 | using namespace Opie; | 52 | using namespace Opie; |
52 | 53 | ||
53 | class ODeviceData { | 54 | class ODeviceData { |
54 | public: | 55 | public: |
55 | bool m_qwsserver; | 56 | bool m_qwsserver; |
56 | 57 | ||
57 | QString m_vendorstr; | 58 | QString m_vendorstr; |
58 | OVendor m_vendor; | 59 | OVendor m_vendor; |
59 | 60 | ||
60 | QString m_modelstr; | 61 | QString m_modelstr; |
61 | OModel m_model; | 62 | OModel m_model; |
62 | 63 | ||
63 | QString m_systemstr; | 64 | QString m_systemstr; |
64 | OSystem m_system; | 65 | OSystem m_system; |
65 | 66 | ||
66 | QString m_sysverstr; | 67 | QString m_sysverstr; |
68 | |||
69 | QValueList <ODeviceButton> m_buttons; | ||
70 | uint m_holdtime; | ||
67 | }; | 71 | }; |
68 | 72 | ||
69 | 73 | ||
70 | class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { | 74 | class iPAQ : public ODevice, public QWSServer::KeyboardFilter { |
71 | protected: | 75 | protected: |
72 | virtual void init ( ); | 76 | virtual void init ( ); |
73 | 77 | ||
74 | public: | 78 | public: |
75 | virtual bool setSoftSuspend ( bool soft ); | 79 | virtual bool setSoftSuspend ( bool soft ); |
76 | 80 | ||
77 | virtual bool setDisplayBrightness ( int b ); | 81 | virtual bool setDisplayBrightness ( int b ); |
78 | virtual int displayBrightnessResolution ( ) const; | 82 | virtual int displayBrightnessResolution ( ) const; |
79 | 83 | ||
80 | virtual void alarmSound ( ); | 84 | virtual void alarmSound ( ); |
81 | 85 | ||
82 | virtual QValueList <OLed> ledList ( ) const; | 86 | virtual QValueList <OLed> ledList ( ) const; |
83 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 87 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
84 | virtual OLedState ledState ( OLed led ) const; | 88 | virtual OLedState ledState ( OLed led ) const; |
85 | virtual bool setLedState ( OLed led, OLedState st ); | 89 | virtual bool setLedState ( OLed led, OLedState st ); |
86 | 90 | ||
87 | virtual bool hasLightSensor ( ) const; | 91 | virtual bool hasLightSensor ( ) const; |
88 | virtual int readLightSensor ( ); | 92 | virtual int readLightSensor ( ); |
89 | virtual int lightSensorResolution ( ) const; | 93 | virtual int lightSensorResolution ( ) const; |
90 | 94 | ||
91 | //virtual QValueList <int> keyList ( ) const; | ||
92 | |||
93 | protected: | 95 | protected: |
94 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); | 96 | virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); |
95 | virtual void timerEvent ( QTimerEvent *te ); | 97 | virtual void timerEvent ( QTimerEvent *te ); |
96 | 98 | ||
97 | int m_power_timer; | 99 | int m_power_timer; |
98 | 100 | ||
99 | OLedState m_leds [2]; | 101 | OLedState m_leds [2]; |
100 | }; | 102 | }; |
101 | 103 | ||
102 | class Zaurus : public ODevice { | 104 | class Zaurus : public ODevice { |
103 | protected: | 105 | protected: |
104 | virtual void init ( ); | 106 | virtual void init ( ); |
105 | 107 | ||
106 | public: | 108 | public: |
107 | virtual bool setSoftSuspend ( bool soft ); | 109 | virtual bool setSoftSuspend ( bool soft ); |
108 | 110 | ||
109 | virtual bool setDisplayBrightness ( int b ); | 111 | virtual bool setDisplayBrightness ( int b ); |
110 | virtual int displayBrightnessResolution ( ) const; | 112 | virtual int displayBrightnessResolution ( ) const; |
111 | 113 | ||
112 | virtual void alarmSound ( ); | 114 | virtual void alarmSound ( ); |
113 | virtual void keySound ( ); | 115 | virtual void keySound ( ); |
114 | virtual void touchSound ( ); | 116 | virtual void touchSound ( ); |
115 | 117 | ||
116 | virtual QValueList <OLed> ledList ( ) const; | 118 | virtual QValueList <OLed> ledList ( ) const; |
117 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; | 119 | virtual QValueList <OLedState> ledStateList ( OLed led ) const; |
118 | virtual OLedState ledState ( OLed led ) const; | 120 | virtual OLedState ledState ( OLed led ) const; |
119 | virtual bool setLedState ( OLed led, OLedState st ); | 121 | virtual bool setLedState ( OLed led, OLedState st ); |
120 | 122 | ||
121 | //virtual QValueList <int> keyList ( ) const; | ||
122 | |||
123 | protected: | 123 | protected: |
124 | virtual void buzzer ( int snd ); | 124 | virtual void buzzer ( int snd ); |
125 | 125 | ||
126 | OLedState m_leds [1]; | 126 | OLedState m_leds [1]; |
127 | }; | 127 | }; |
128 | 128 | ||
129 | 129 | ||
130 | struct i_button { | ||
131 | uint model; | ||
132 | Qt::Key code; | ||
133 | char *utext; | ||
134 | char *pix; | ||
135 | char *fpressedservice; | ||
136 | char *fpressedaction; | ||
137 | char *fheldservice; | ||
138 | char *fheldaction; | ||
139 | } ipaq_buttons [] = { | ||
140 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | ||
141 | Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
142 | "devicebuttons/ipaq_calendar", | ||
143 | "datebook", "nextView()", | ||
144 | "today", "raise()" }, | ||
145 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | ||
146 | Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
147 | "devicebuttons/ipaq_contact", | ||
148 | "addressbook", "raise()", | ||
149 | "addressbook", "beamBusinessCard()" }, | ||
150 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, | ||
151 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | ||
152 | "devicebuttons/ipaq_menu", | ||
153 | "QPE/TaskBar", "toggleMenu()", | ||
154 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
155 | { Model_iPAQ_H38xx | Model_iPAQ_H39xx, | ||
156 | Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), | ||
157 | "devicebuttons/ipaq_mail", | ||
158 | "mail", "raise()", | ||
159 | "mail", "newMail()" }, | ||
160 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | ||
161 | Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
162 | "devicebuttons/ipaq_home", | ||
163 | "QPE/Launcher", "home()", | ||
164 | "buttonsettings", "raise()" }, | ||
165 | { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, | ||
166 | Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), | ||
167 | "devicebuttons/ipaq_record", | ||
168 | "QPE/VMemo", "toggleRecord()", | ||
169 | "sound", "raise()" }, | ||
170 | }; | ||
171 | |||
172 | struct z_button { | ||
173 | Qt::Key code; | ||
174 | char *utext; | ||
175 | char *pix; | ||
176 | char *fpressedservice; | ||
177 | char *fpressedaction; | ||
178 | char *fheldservice; | ||
179 | char *fheldaction; | ||
180 | } z_buttons [] = { | ||
181 | { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), | ||
182 | "devicebuttons/z_calendar", | ||
183 | "datebook", "nextView()", | ||
184 | "today", "raise()" }, | ||
185 | { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), | ||
186 | "devicebuttons/z_contact", | ||
187 | "addressbook", "raise()", | ||
188 | "addressbook", "beamBusinessCard()" }, | ||
189 | { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), | ||
190 | "devicebuttons/z_home", | ||
191 | "QPE/Launcher", "home()", | ||
192 | "buttonsettings", "raise()" }, | ||
193 | { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), | ||
194 | "devicebuttons/z_menu", | ||
195 | "QPE/TaskBar", "toggleMenu()", | ||
196 | "QPE/TaskBar", "toggleStartMenu()" }, | ||
197 | { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), | ||
198 | "devicebuttons/z_mail", | ||
199 | "mail", "raise()", | ||
200 | "mail", "newMail()" }, | ||
201 | }; | ||
130 | 202 | ||
203 | static QCString makeChannel ( const char *str ) | ||
204 | { | ||
205 | if ( str && !::strchr ( str, '/' )) | ||
206 | return QCString ( "QPE/Application/" ) + str; | ||
207 | else | ||
208 | return str; | ||
209 | } | ||
131 | 210 | ||
132 | 211 | ||
133 | 212 | ||
134 | 213 | ||
135 | ODevice *ODevice::inst ( ) | 214 | ODevice *ODevice::inst ( ) |
136 | { | 215 | { |
137 | static ODevice *dev = 0; | 216 | static ODevice *dev = 0; |
138 | 217 | ||
139 | if ( !dev ) { | 218 | if ( !dev ) { |
140 | if ( QFile::exists ( "/proc/hal/model" )) | 219 | if ( QFile::exists ( "/proc/hal/model" )) |
141 | dev = new iPAQ ( ); | 220 | dev = new iPAQ ( ); |
142 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 221 | else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
143 | dev = new Zaurus ( ); | 222 | dev = new Zaurus ( ); |
144 | else | 223 | else |
145 | dev = new ODevice ( ); | 224 | dev = new ODevice ( ); |
146 | 225 | ||
147 | dev-> init ( ); | 226 | dev-> init ( ); |
148 | } | 227 | } |
149 | return dev; | 228 | return dev; |
150 | } | 229 | } |
151 | 230 | ||
152 | 231 | ||
153 | /************************************************** | 232 | /************************************************** |
154 | * | 233 | * |
155 | * common | 234 | * common |
156 | * | 235 | * |
157 | **************************************************/ | 236 | **************************************************/ |
158 | 237 | ||
159 | 238 | ||
160 | ODevice::ODevice ( ) | 239 | ODevice::ODevice ( ) |
161 | { | 240 | { |
162 | d = new ODeviceData; | 241 | d = new ODeviceData; |
163 | 242 | ||
164 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; | 243 | d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; |
165 | 244 | ||
166 | d-> m_modelstr = "Unknown"; | 245 | d-> m_modelstr = "Unknown"; |
167 | d-> m_model = Model_Unknown; | 246 | d-> m_model = Model_Unknown; |
168 | d-> m_vendorstr = "Unkown"; | 247 | d-> m_vendorstr = "Unkown"; |
169 | d-> m_vendor = Vendor_Unknown; | 248 | d-> m_vendor = Vendor_Unknown; |
170 | d-> m_systemstr = "Unkown"; | 249 | d-> m_systemstr = "Unkown"; |
171 | d-> m_system = System_Unknown; | 250 | d-> m_system = System_Unknown; |
172 | d-> m_sysverstr = "0.0"; | 251 | d-> m_sysverstr = "0.0"; |
252 | |||
253 | d-> m_holdtime = 1000; // 1000ms | ||
254 | |||
255 | QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); | ||
256 | connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); | ||
257 | } | ||
258 | |||
259 | void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) | ||
260 | { | ||
261 | if ( msg == "deviceButtonMappingChanged()" ) { | ||
262 | reloadButtonMapping ( ); | ||
263 | } | ||
173 | } | 264 | } |
174 | 265 | ||
175 | void ODevice::init ( ) | 266 | void ODevice::init ( ) |
176 | { | 267 | { |
268 | // Simulation uses iPAQ 3660 device buttons | ||
269 | |||
270 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
271 | i_button *ib = ipaq_buttons + i; | ||
272 | ODeviceButton b; | ||
273 | |||
274 | if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { | ||
275 | b. setKeycode ( ib-> code ); | ||
276 | b. setUserText ( qApp-> translate ( "Button", ib-> utext )); | ||
277 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
278 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
279 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
280 | |||
281 | d-> m_buttons. append ( b ); | ||
282 | } | ||
283 | } | ||
284 | reloadButtonMapping ( ); | ||
177 | } | 285 | } |
178 | 286 | ||
179 | ODevice::~ODevice ( ) | 287 | ODevice::~ODevice ( ) |
180 | { | 288 | { |
181 | delete d; | 289 | delete d; |
182 | } | 290 | } |
183 | 291 | ||
184 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) | 292 | bool ODevice::setSoftSuspend ( bool /*soft*/ ) |
185 | { | 293 | { |
186 | return false; | 294 | return false; |
187 | } | 295 | } |
188 | 296 | ||
189 | //#include <linux/apm_bios.h> | 297 | //#include <linux/apm_bios.h> |
190 | 298 | ||
191 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) | 299 | #define APM_IOC_SUSPEND OD_IO( 'A', 2 ) |
192 | 300 | ||
193 | 301 | ||
194 | bool ODevice::suspend ( ) | 302 | bool ODevice::suspend ( ) |
195 | { | 303 | { |
196 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend | 304 | if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend |
197 | return false; | 305 | return false; |
198 | 306 | ||
199 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices | 307 | if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices |
200 | return false; | 308 | return false; |
@@ -338,52 +446,131 @@ OLedState ODevice::ledState ( OLed /*which*/ ) const | |||
338 | { | 446 | { |
339 | return Led_Off; | 447 | return Led_Off; |
340 | } | 448 | } |
341 | 449 | ||
342 | bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) | 450 | bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ ) |
343 | { | 451 | { |
344 | return false; | 452 | return false; |
345 | } | 453 | } |
346 | 454 | ||
347 | bool ODevice::hasLightSensor ( ) const | 455 | bool ODevice::hasLightSensor ( ) const |
348 | { | 456 | { |
349 | return false; | 457 | return false; |
350 | } | 458 | } |
351 | 459 | ||
352 | int ODevice::readLightSensor ( ) | 460 | int ODevice::readLightSensor ( ) |
353 | { | 461 | { |
354 | return -1; | 462 | return -1; |
355 | } | 463 | } |
356 | 464 | ||
357 | int ODevice::lightSensorResolution ( ) const | 465 | int ODevice::lightSensorResolution ( ) const |
358 | { | 466 | { |
359 | return 0; | 467 | return 0; |
360 | } | 468 | } |
361 | 469 | ||
362 | //QValueList <int> ODevice::keyList ( ) const | 470 | const QValueList <ODeviceButton> &ODevice::buttons ( ) const |
363 | //{ | 471 | { |
364 | //return QValueList <int> ( ); | 472 | return d-> m_buttons; |
365 | //} | 473 | } |
474 | |||
475 | uint ODevice::buttonHoldTime ( ) const | ||
476 | { | ||
477 | return d-> m_holdtime; | ||
478 | } | ||
479 | |||
480 | const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) | ||
481 | { | ||
482 | for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons. begin ( ); it != d-> m_buttons. end ( ); ++it ) { | ||
483 | if ( (*it). keycode ( ) == code ) | ||
484 | return &(*it); | ||
485 | } | ||
486 | return 0; | ||
487 | } | ||
488 | |||
489 | void ODevice::reloadButtonMapping ( ) | ||
490 | { | ||
491 | Config cfg ( "ButtonSettings" ); | ||
492 | |||
493 | for ( uint i = 0; i < d-> m_buttons. count ( ); i++ ) { | ||
494 | ODeviceButton &b = d-> m_buttons [i]; | ||
495 | QString group = "Button" + QString::number ( i ); | ||
496 | |||
497 | QCString pch, hch; | ||
498 | QCString pm, hm; | ||
499 | QByteArray pdata, hdata; | ||
500 | |||
501 | if ( cfg. hasGroup ( group )) { | ||
502 | cfg. setGroup ( group ); | ||
503 | pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); | ||
504 | pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); | ||
505 | // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); | ||
506 | |||
507 | hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); | ||
508 | hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); | ||
509 | // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); | ||
510 | } | ||
511 | |||
512 | b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); | ||
513 | b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); | ||
514 | } | ||
515 | } | ||
516 | |||
517 | void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) | ||
518 | { | ||
519 | if ( button >= (int) d-> m_buttons. count ( )) | ||
520 | return; | ||
521 | |||
522 | ODeviceButton &b = d-> m_buttons [button]; | ||
523 | b. setPressedAction ( action ); | ||
524 | |||
525 | Config buttonFile ( "ButtonSettings" ); | ||
526 | buttonFile. setGroup ( "Button" + QString::number ( button )); | ||
527 | buttonFile. writeEntry ( "PressedActionChannel", (const char*) b. pressedAction ( ). channel ( )); | ||
528 | buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); | ||
529 | |||
530 | //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); | ||
531 | |||
532 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | ||
533 | } | ||
534 | |||
535 | void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) | ||
536 | { | ||
537 | if ( button >= (int) d-> m_buttons. count ( )) | ||
538 | return; | ||
539 | |||
540 | ODeviceButton &b = d-> m_buttons [button]; | ||
541 | b. setHeldAction ( action ); | ||
542 | |||
543 | Config buttonFile ( "ButtonSettings" ); | ||
544 | buttonFile. setGroup ( "Button" + QString::number ( button )); | ||
545 | buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); | ||
546 | buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); | ||
547 | |||
548 | //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); | ||
549 | |||
550 | QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); | ||
551 | } | ||
552 | |||
366 | 553 | ||
367 | 554 | ||
368 | 555 | ||
369 | /************************************************** | 556 | /************************************************** |
370 | * | 557 | * |
371 | * iPAQ | 558 | * iPAQ |
372 | * | 559 | * |
373 | **************************************************/ | 560 | **************************************************/ |
374 | 561 | ||
375 | void iPAQ::init ( ) | 562 | void iPAQ::init ( ) |
376 | { | 563 | { |
377 | d-> m_vendorstr = "HP"; | 564 | d-> m_vendorstr = "HP"; |
378 | d-> m_vendor = Vendor_HP; | 565 | d-> m_vendor = Vendor_HP; |
379 | 566 | ||
380 | QFile f ( "/proc/hal/model" ); | 567 | QFile f ( "/proc/hal/model" ); |
381 | 568 | ||
382 | if ( f. open ( IO_ReadOnly )) { | 569 | if ( f. open ( IO_ReadOnly )) { |
383 | QTextStream ts ( &f ); | 570 | QTextStream ts ( &f ); |
384 | 571 | ||
385 | d-> m_modelstr = "H" + ts. readLine ( ); | 572 | d-> m_modelstr = "H" + ts. readLine ( ); |
386 | 573 | ||
387 | if ( d-> m_modelstr == "H3100" ) | 574 | if ( d-> m_modelstr == "H3100" ) |
388 | d-> m_model = Model_iPAQ_H31xx; | 575 | d-> m_model = Model_iPAQ_H31xx; |
389 | else if ( d-> m_modelstr == "H3600" ) | 576 | else if ( d-> m_modelstr == "H3600" ) |
@@ -394,48 +581,68 @@ void iPAQ::init ( ) | |||
394 | d-> m_model = Model_iPAQ_H38xx; | 581 | d-> m_model = Model_iPAQ_H38xx; |
395 | else if ( d-> m_modelstr == "H3900" ) | 582 | else if ( d-> m_modelstr == "H3900" ) |
396 | d-> m_model = Model_iPAQ_H39xx; | 583 | d-> m_model = Model_iPAQ_H39xx; |
397 | else | 584 | else |
398 | d-> m_model = Model_Unknown; | 585 | d-> m_model = Model_Unknown; |
399 | 586 | ||
400 | f. close ( ); | 587 | f. close ( ); |
401 | } | 588 | } |
402 | 589 | ||
403 | f. setName ( "/etc/familiar-version" ); | 590 | f. setName ( "/etc/familiar-version" ); |
404 | if ( f. open ( IO_ReadOnly )) { | 591 | if ( f. open ( IO_ReadOnly )) { |
405 | d-> m_systemstr = "Familiar"; | 592 | d-> m_systemstr = "Familiar"; |
406 | d-> m_system = System_Familiar; | 593 | d-> m_system = System_Familiar; |
407 | 594 | ||
408 | QTextStream ts ( &f ); | 595 | QTextStream ts ( &f ); |
409 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 596 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
410 | 597 | ||
411 | f. close ( ); | 598 | f. close ( ); |
412 | } | 599 | } |
413 | 600 | ||
414 | m_leds [0] = m_leds [1] = Led_Off; | 601 | m_leds [0] = m_leds [1] = Led_Off; |
415 | 602 | ||
416 | m_power_timer = 0; | 603 | m_power_timer = 0; |
417 | 604 | ||
605 | for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { | ||
606 | i_button *ib = ipaq_buttons + i; | ||
607 | ODeviceButton b; | ||
608 | |||
609 | qDebug ( "%d: %d", i, ib-> model ); | ||
610 | |||
611 | if (( ib-> model & d-> m_model ) == d-> m_model ) { | ||
612 | b. setKeycode ( ib-> code ); | ||
613 | b. setUserText ( qApp-> translate ( "Button", ib-> utext )); | ||
614 | b. setPixmap ( Resource::loadPixmap ( ib-> pix )); | ||
615 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); | ||
616 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); | ||
617 | |||
618 | d-> m_buttons. append ( b ); | ||
619 | |||
620 | qDebug ( "code: %d", ib-> code ); | ||
621 | } | ||
622 | } | ||
623 | reloadButtonMapping ( ); | ||
624 | |||
418 | if ( d-> m_qwsserver ) | 625 | if ( d-> m_qwsserver ) |
419 | QWSServer::setKeyboardFilter ( this ); | 626 | QWSServer::setKeyboardFilter ( this ); |
420 | } | 627 | } |
421 | 628 | ||
422 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | 629 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... |
423 | 630 | ||
424 | typedef struct { | 631 | typedef struct { |
425 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 632 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
426 | unsigned char TotalTime; /* Units of 5 seconds */ | 633 | unsigned char TotalTime; /* Units of 5 seconds */ |
427 | unsigned char OnTime; /* units of 100m/s */ | 634 | unsigned char OnTime; /* units of 100m/s */ |
428 | unsigned char OffTime; /* units of 100m/s */ | 635 | unsigned char OffTime; /* units of 100m/s */ |
429 | } LED_IN; | 636 | } LED_IN; |
430 | 637 | ||
431 | typedef struct { | 638 | typedef struct { |
432 | unsigned char mode; | 639 | unsigned char mode; |
433 | unsigned char pwr; | 640 | unsigned char pwr; |
434 | unsigned char brightness; | 641 | unsigned char brightness; |
435 | } FLITE_IN; | 642 | } FLITE_IN; |
436 | 643 | ||
437 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) | 644 | #define LED_ON OD_IOW( 'f', 5, LED_IN ) |
438 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) | 645 | #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) |
439 | 646 | ||
440 | 647 | ||
441 | 648 | ||
@@ -482,55 +689,48 @@ bool iPAQ::setLedState ( OLed l, OLedState st ) | |||
482 | LED_IN leds; | 689 | LED_IN leds; |
483 | ::memset ( &leds, 0, sizeof( leds )); | 690 | ::memset ( &leds, 0, sizeof( leds )); |
484 | leds. TotalTime = 0; | 691 | leds. TotalTime = 0; |
485 | leds. OnTime = 0; | 692 | leds. OnTime = 0; |
486 | leds. OffTime = 1; | 693 | leds. OffTime = 1; |
487 | leds. OffOnBlink = 2; | 694 | leds. OffOnBlink = 2; |
488 | 695 | ||
489 | switch ( st ) { | 696 | switch ( st ) { |
490 | case Led_Off : leds. OffOnBlink = 0; break; | 697 | case Led_Off : leds. OffOnBlink = 0; break; |
491 | case Led_On : leds. OffOnBlink = 1; break; | 698 | case Led_On : leds. OffOnBlink = 1; break; |
492 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; | 699 | case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; |
493 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; | 700 | case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; |
494 | } | 701 | } |
495 | 702 | ||
496 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { | 703 | if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { |
497 | m_leds [0] = st; | 704 | m_leds [0] = st; |
498 | return true; | 705 | return true; |
499 | } | 706 | } |
500 | } | 707 | } |
501 | } | 708 | } |
502 | return false; | 709 | return false; |
503 | } | 710 | } |
504 | 711 | ||
505 | 712 | ||
506 | //QValueList <int> iPAQ::keyList ( ) const | ||
507 | //{ | ||
508 | //QValueList <int> vl; | ||
509 | //vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight; | ||
510 | //return vl; | ||
511 | //} | ||
512 | |||
513 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) | 713 | bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) |
514 | { | 714 | { |
515 | int newkeycode = keycode; | 715 | int newkeycode = keycode; |
516 | 716 | ||
517 | switch ( keycode ) { | 717 | switch ( keycode ) { |
518 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key | 718 | // H38xx/H39xx have no "Q" key anymore - this is now the Mail key |
519 | case HardKey_Menu: { | 719 | case HardKey_Menu: { |
520 | if (( d-> m_model == Model_iPAQ_H38xx ) || | 720 | if (( d-> m_model == Model_iPAQ_H38xx ) || |
521 | ( d-> m_model == Model_iPAQ_H39xx )) { | 721 | ( d-> m_model == Model_iPAQ_H39xx )) { |
522 | newkeycode = HardKey_Mail; | 722 | newkeycode = HardKey_Mail; |
523 | } | 723 | } |
524 | break; | 724 | break; |
525 | } | 725 | } |
526 | 726 | ||
527 | // Rotate cursor keys 180° | 727 | // Rotate cursor keys 180° |
528 | case Key_Left : | 728 | case Key_Left : |
529 | case Key_Right: | 729 | case Key_Right: |
530 | case Key_Up : | 730 | case Key_Up : |
531 | case Key_Down : { | 731 | case Key_Down : { |
532 | if (( d-> m_model == Model_iPAQ_H31xx ) || | 732 | if (( d-> m_model == Model_iPAQ_H31xx ) || |
533 | ( d-> m_model == Model_iPAQ_H38xx )) { | 733 | ( d-> m_model == Model_iPAQ_H38xx )) { |
534 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; | 734 | newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; |
535 | } | 735 | } |
536 | break; | 736 | break; |
@@ -733,48 +933,62 @@ void Zaurus::init ( ) | |||
733 | } | 933 | } |
734 | else { | 934 | else { |
735 | d-> m_systemstr = "Zaurus"; | 935 | d-> m_systemstr = "Zaurus"; |
736 | d-> m_system = System_Zaurus; | 936 | d-> m_system = System_Zaurus; |
737 | } | 937 | } |
738 | 938 | ||
739 | f. setName ( "/proc/deviceinfo/product" ); | 939 | f. setName ( "/proc/deviceinfo/product" ); |
740 | if ( f. open ( IO_ReadOnly ) ) { | 940 | if ( f. open ( IO_ReadOnly ) ) { |
741 | QTextStream ts ( &f ); | 941 | QTextStream ts ( &f ); |
742 | QString model = ts. readLine ( ); | 942 | QString model = ts. readLine ( ); |
743 | f. close ( ); | 943 | f. close ( ); |
744 | if ( model == "SL-5000D" ) { | 944 | if ( model == "SL-5000D" ) { |
745 | d-> m_model = Model_Zaurus_SL5000; | 945 | d-> m_model = Model_Zaurus_SL5000; |
746 | d-> m_modelstr = "Zaurus SL-5000D"; | 946 | d-> m_modelstr = "Zaurus SL-5000D"; |
747 | } else if ( model == "SL-5500" ) { | 947 | } else if ( model == "SL-5500" ) { |
748 | d-> m_model = Model_Zaurus_SL5500; | 948 | d-> m_model = Model_Zaurus_SL5500; |
749 | d-> m_modelstr = "Zaurus SL-5500"; | 949 | d-> m_modelstr = "Zaurus SL-5500"; |
750 | } | 950 | } |
751 | } | 951 | } |
752 | else { | 952 | else { |
753 | d-> m_model = Model_Zaurus_SL5000; | 953 | d-> m_model = Model_Zaurus_SL5000; |
754 | d-> m_modelstr = "Zaurus SL-5000D (unverified)"; | 954 | d-> m_modelstr = "Zaurus SL-5000D (unverified)"; |
755 | } | 955 | } |
756 | 956 | ||
957 | for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) { | ||
958 | z_button *zb = z_buttons + i; | ||
959 | ODeviceButton b; | ||
960 | |||
961 | b. setKeycode ( zb-> code ); | ||
962 | b. setUserText ( qApp-> translate ( "Button", zb-> utext )); | ||
963 | b. setPixmap ( Resource::loadPixmap ( zb-> pix )); | ||
964 | b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction )); | ||
965 | b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction )); | ||
966 | |||
967 | d-> m_buttons. append ( b ); | ||
968 | } | ||
969 | reloadButtonMapping ( ); | ||
970 | |||
757 | m_leds [0] = Led_Off; | 971 | m_leds [0] = Led_Off; |
758 | } | 972 | } |
759 | 973 | ||
760 | #include <unistd.h> | 974 | #include <unistd.h> |
761 | #include <fcntl.h> | 975 | #include <fcntl.h> |
762 | #include <sys/ioctl.h> | 976 | #include <sys/ioctl.h> |
763 | 977 | ||
764 | //#include <asm/sharp_char.h> // including kernel headers is evil ... | 978 | //#include <asm/sharp_char.h> // including kernel headers is evil ... |
765 | 979 | ||
766 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 | 980 | #define SHARP_DEV_IOCTL_COMMAND_START 0x5680 |
767 | 981 | ||
768 | #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | 982 | #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) |
769 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | 983 | #define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) |
770 | 984 | ||
771 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ | 985 | #define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ |
772 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ | 986 | #define SHARP_BUZ_KEYSOUND 2 /* key sound */ |
773 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ | 987 | #define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ |
774 | 988 | ||
775 | /* --- for SHARP_BUZZER device --- */ | 989 | /* --- for SHARP_BUZZER device --- */ |
776 | 990 | ||
777 | //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) | 991 | //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) |
778 | //#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) | 992 | //#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) |
779 | 993 | ||
780 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) | 994 | #define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) |