-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 | |||
@@ -33,6 +33,7 @@ | |||
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 | ||
@@ -64,10 +65,13 @@ public: | |||
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 | ||
@@ -88,8 +92,6 @@ public: | |||
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 ); |
@@ -118,8 +120,6 @@ public: | |||
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 | ||
@@ -127,7 +127,86 @@ protected: | |||
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 | ||
@@ -170,10 +249,39 @@ ODevice::ODevice ( ) | |||
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 ( ) |
@@ -359,10 +467,89 @@ int ODevice::lightSensorResolution ( ) const | |||
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 | ||
@@ -415,6 +602,26 @@ void iPAQ::init ( ) | |||
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 | } |
@@ -503,13 +710,6 @@ bool iPAQ::setLedState ( OLed l, OLedState st ) | |||
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; |
@@ -754,6 +954,20 @@ void Zaurus::init ( ) | |||
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 | ||