-rw-r--r-- | libopie/libopie.pro | 4 | ||||
-rw-r--r-- | libopie/odevice.cpp | 246 | ||||
-rw-r--r-- | libopie/odevice.h | 48 | ||||
-rw-r--r-- | libopie/odevicebutton.cpp | 234 | ||||
-rw-r--r-- | libopie/odevicebutton.h | 97 |
5 files changed, 609 insertions, 20 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index c829083..58a7489 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -6,9 +6,9 @@ HEADERS = ofontmenu.h \ | |||
6 | ocheckitem.h todoevent.h todoresource.h \ | 6 | ocheckitem.h todoevent.h todoresource.h \ |
7 | todovcalresource.h xmltree.h \ | 7 | todovcalresource.h xmltree.h \ |
8 | colordialog.h colorpopupmenu.h \ | 8 | colordialog.h colorpopupmenu.h \ |
9 | oclickablelabel.h oprocctrl.h \ | 9 | oclickablelabel.h oprocctrl.h \ |
10 | oprocess.h odevice.h \ | 10 | oprocess.h odevice.h odevicebutton.h \ |
11 | otimepicker.h otabwidget.h \ | 11 | otimepicker.h otabwidget.h \ |
12 | otabbar.h otabinfo.h \ | 12 | otabbar.h otabinfo.h \ |
13 | ofontselector.h \ | 13 | ofontselector.h \ |
14 | pim/opimrecord.h \ | 14 | pim/opimrecord.h \ |
@@ -48,9 +48,9 @@ SOURCES = ofontmenu.cc \ | |||
48 | ocheckitem.cpp tododb.cpp todoevent.cpp \ | 48 | ocheckitem.cpp tododb.cpp todoevent.cpp \ |
49 | todovcalresource.cpp colordialog.cpp \ | 49 | todovcalresource.cpp colordialog.cpp \ |
50 | colorpopupmenu.cpp oclickablelabel.cpp \ | 50 | colorpopupmenu.cpp oclickablelabel.cpp \ |
51 | oprocctrl.cpp oprocess.cpp \ | 51 | oprocctrl.cpp oprocess.cpp \ |
52 | odevice.cpp otimepicker.cpp \ | 52 | odevice.cpp odevicebutton.cpp otimepicker.cpp \ |
53 | otabwidget.cpp otabbar.cpp \ | 53 | otabwidget.cpp otabbar.cpp \ |
54 | ofontselector.cpp \ | 54 | ofontselector.cpp \ |
55 | pim/otodo.cpp \ | 55 | pim/otodo.cpp \ |
56 | pim/opimrecord.cpp \ | 56 | pim/opimrecord.cpp \ |
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index c947630..f93d1ed 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -32,8 +32,9 @@ | |||
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> |
@@ -63,12 +64,15 @@ public: | |||
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: |
@@ -87,10 +91,8 @@ public: | |||
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 | ||
@@ -117,18 +119,95 @@ public: | |||
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 | ||
@@ -169,12 +248,41 @@ ODevice::ODevice ( ) | |||
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 | { |
@@ -358,12 +466,91 @@ 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 | /************************************************** |
@@ -414,8 +601,28 @@ void iPAQ::init ( ) | |||
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 | ||
@@ -502,15 +709,8 @@ bool iPAQ::setLedState ( OLed l, OLedState st ) | |||
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 | ||
@@ -753,8 +953,22 @@ void Zaurus::init ( ) | |||
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> |
diff --git a/libopie/odevice.h b/libopie/odevice.h index 86491d4..ce62f1a 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h | |||
@@ -19,11 +19,14 @@ | |||
19 | 19 | ||
20 | #ifndef _LIBOPIE_ODEVICE_H_ | 20 | #ifndef _LIBOPIE_ODEVICE_H_ |
21 | #define _LIBOPIE_ODEVICE_H_ | 21 | #define _LIBOPIE_ODEVICE_H_ |
22 | 22 | ||
23 | #include <qobject.h> | ||
23 | #include <qstring.h> | 24 | #include <qstring.h> |
24 | #include <qnamespace.h> | 25 | #include <qnamespace.h> |
25 | 26 | ||
27 | #include <opie/odevicebutton.h> | ||
28 | |||
26 | class ODeviceData; | 29 | class ODeviceData; |
27 | 30 | ||
28 | namespace Opie { | 31 | namespace Opie { |
29 | 32 | ||
@@ -86,10 +89,11 @@ enum OHardKey { | |||
86 | HardKey_Backlight = Qt::Key_F35, | 89 | HardKey_Backlight = Qt::Key_F35, |
87 | }; | 90 | }; |
88 | 91 | ||
89 | 92 | ||
90 | class ODevice | 93 | class ODevice : public QObject { |
91 | { | 94 | Q_OBJECT |
95 | |||
92 | private: | 96 | private: |
93 | ODevice ( const ODevice & ); | 97 | ODevice ( const ODevice & ); |
94 | 98 | ||
95 | protected: | 99 | protected: |
@@ -141,8 +145,48 @@ public: | |||
141 | 145 | ||
142 | virtual bool hasLightSensor ( ) const; | 146 | virtual bool hasLightSensor ( ) const; |
143 | virtual int readLightSensor ( ); | 147 | virtual int readLightSensor ( ); |
144 | virtual int lightSensorResolution ( ) const; | 148 | virtual int lightSensorResolution ( ) const; |
149 | |||
150 | /** | ||
151 | * Returns the available buttons on this device. The number and location | ||
152 | * of buttons will vary depending on the device. Button numbers will be assigned | ||
153 | * by the device manufacturer and will be from most preferred button to least preffered | ||
154 | * button. Note that this list only contains "user mappable" buttons. | ||
155 | */ | ||
156 | const QValueList<ODeviceButton> &buttons ( ) const; | ||
157 | |||
158 | /** | ||
159 | * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it | ||
160 | * returns 0L | ||
161 | */ | ||
162 | const ODeviceButton *buttonForKeycode ( ushort keyCode ); | ||
163 | |||
164 | /** | ||
165 | * Reassigns the pressed action for \a button. To return to the factory | ||
166 | * default pass an empty string as \a qcopMessage. | ||
167 | */ | ||
168 | void remapPressedAction ( int button, const OQCopMessage &qcopMessage ); | ||
169 | |||
170 | /** | ||
171 | * Reassigns the held action for \a button. To return to the factory | ||
172 | * default pass an empty string as \a qcopMessage. | ||
173 | */ | ||
174 | void remapHeldAction ( int button, const OQCopMessage &qcopMessage ); | ||
175 | |||
176 | /** | ||
177 | * How long (in ms) you have to press a button for a "hold" action | ||
178 | */ | ||
179 | uint buttonHoldTime ( ) const; | ||
180 | |||
181 | signals: | ||
182 | void buttonMappingChanged ( ); | ||
183 | |||
184 | private slots: | ||
185 | void systemMessage ( const QCString &, const QByteArray & ); | ||
186 | |||
187 | protected: | ||
188 | void reloadButtonMapping ( ); | ||
145 | }; | 189 | }; |
146 | 190 | ||
147 | } | 191 | } |
148 | 192 | ||
diff --git a/libopie/odevicebutton.cpp b/libopie/odevicebutton.cpp new file mode 100644 index 0000000..2270343 --- a/dev/null +++ b/libopie/odevicebutton.cpp | |||
@@ -0,0 +1,234 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qpixmap.h> | ||
22 | #include <qstring.h> | ||
23 | |||
24 | #include <qpe/qcopenvelope_qws.h> | ||
25 | #include <opie/odevicebutton.h> | ||
26 | |||
27 | using namespace Opie; | ||
28 | |||
29 | |||
30 | class OQCopMessageData { | ||
31 | public: | ||
32 | QCString m_channel; | ||
33 | QCString m_message; | ||
34 | QByteArray m_data; | ||
35 | }; | ||
36 | |||
37 | |||
38 | OQCopMessage::OQCopMessage ( ) | ||
39 | : d ( 0 ) | ||
40 | { | ||
41 | init ( QCString ( ), QCString ( ), QByteArray ( )); | ||
42 | } | ||
43 | |||
44 | OQCopMessage::OQCopMessage ( const OQCopMessage © ) | ||
45 | : d ( 0 ) | ||
46 | { | ||
47 | init ( copy. channel ( ), copy. message ( ), copy. data ( )); | ||
48 | } | ||
49 | |||
50 | OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) | ||
51 | { | ||
52 | init ( assign. channel ( ), assign. message ( ), assign. data ( )); | ||
53 | return *this; | ||
54 | } | ||
55 | |||
56 | OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) | ||
57 | : d ( 0 ) | ||
58 | { | ||
59 | init ( ch, m, arg ); | ||
60 | } | ||
61 | |||
62 | void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg ) | ||
63 | { | ||
64 | if ( !d ) | ||
65 | d = new OQCopMessageData ( ); | ||
66 | d-> m_channel = ch; | ||
67 | d-> m_message = m; | ||
68 | d-> m_data = arg; | ||
69 | } | ||
70 | |||
71 | bool OQCopMessage::send ( ) | ||
72 | { | ||
73 | if ( d-> m_channel. isEmpty ( ) || d-> m_message. isEmpty ( )) | ||
74 | return false; | ||
75 | |||
76 | QCopEnvelope e ( d-> m_channel, d-> m_message ); | ||
77 | |||
78 | if ( d-> m_data. size ( )) | ||
79 | e. writeRawBytes ( d-> m_data. data ( ), d-> m_data. size ( )); | ||
80 | |||
81 | return true; | ||
82 | } | ||
83 | |||
84 | QCString OQCopMessage::channel ( ) const | ||
85 | { | ||
86 | return d-> m_channel; | ||
87 | } | ||
88 | |||
89 | QCString OQCopMessage::message ( ) const | ||
90 | { | ||
91 | return d-> m_message; | ||
92 | } | ||
93 | |||
94 | QByteArray OQCopMessage::data ( ) const | ||
95 | { | ||
96 | return d-> m_data; | ||
97 | } | ||
98 | |||
99 | void OQCopMessage::setChannel ( const QCString &ch ) | ||
100 | { | ||
101 | d-> m_channel = ch; | ||
102 | } | ||
103 | |||
104 | void OQCopMessage::setMessage ( const QCString &m ) | ||
105 | { | ||
106 | d-> m_message = m; | ||
107 | } | ||
108 | |||
109 | void OQCopMessage::setData ( const QByteArray &data ) | ||
110 | { | ||
111 | d-> m_data = data; | ||
112 | } | ||
113 | |||
114 | /*! \class ODeviceButton | ||
115 | \brief The ODeviceButton class represents a physical user mappable button on a Qtopia device. | ||
116 | |||
117 | This class represents a physical button on a Qtopia device. A | ||
118 | device may have "user programmable" buttons. | ||
119 | The location and number of buttons will vary from device to | ||
120 | device. userText() and pixmap() may be used to describe this button | ||
121 | to the user in help documentation. | ||
122 | |||
123 | \ingroup qtopiaemb | ||
124 | \internal | ||
125 | */ | ||
126 | |||
127 | ODeviceButton::ODeviceButton() | ||
128 | { | ||
129 | } | ||
130 | |||
131 | ODeviceButton::~ODeviceButton() | ||
132 | { | ||
133 | } | ||
134 | |||
135 | /*! | ||
136 | Returns the button's keycode. | ||
137 | */ | ||
138 | ushort ODeviceButton::keycode() const | ||
139 | { | ||
140 | return m_Keycode; | ||
141 | } | ||
142 | |||
143 | |||
144 | /*! | ||
145 | This function returns a human readable, translated description of the button. | ||
146 | */ | ||
147 | QString ODeviceButton::userText() const | ||
148 | { | ||
149 | return m_UserText; | ||
150 | } | ||
151 | |||
152 | /*! | ||
153 | This function returns the pixmap for this button. If there isn't one | ||
154 | it will return an empty (null) pixmap. | ||
155 | */ | ||
156 | QPixmap ODeviceButton::pixmap() const | ||
157 | { | ||
158 | return m_Pixmap; | ||
159 | } | ||
160 | |||
161 | /*! | ||
162 | This function returns the factory preset (default) action for when this button | ||
163 | is pressed. The return value is a legal QCop message. | ||
164 | */ | ||
165 | OQCopMessage ODeviceButton::factoryPresetPressedAction() const | ||
166 | { | ||
167 | return m_FactoryPresetPressedAction; | ||
168 | } | ||
169 | |||
170 | /*! | ||
171 | This function returns the user assigned action for when this button is pressed. | ||
172 | If no action is assigned, factoryPresetAction() is returned. | ||
173 | */ | ||
174 | OQCopMessage ODeviceButton::pressedAction() const | ||
175 | { | ||
176 | if (m_PressedAction.channel().isEmpty()) | ||
177 | return factoryPresetPressedAction(); | ||
178 | return m_PressedAction; | ||
179 | } | ||
180 | |||
181 | /*! | ||
182 | This function returns the factory preset (default) action for when this button | ||
183 | is pressed and held. The return value is a legal QCop message. | ||
184 | */ | ||
185 | OQCopMessage ODeviceButton::factoryPresetHeldAction() const | ||
186 | { | ||
187 | return m_FactoryPresetHeldAction; | ||
188 | } | ||
189 | |||
190 | /*! | ||
191 | This function returns the user assigned action for when this button is pressed | ||
192 | and held. If no action is assigned, factoryPresetAction() is returned. | ||
193 | */ | ||
194 | OQCopMessage ODeviceButton::heldAction() const | ||
195 | { | ||
196 | if (m_HeldAction.channel().isEmpty()) | ||
197 | return factoryPresetHeldAction(); | ||
198 | return m_HeldAction; | ||
199 | } | ||
200 | |||
201 | void ODeviceButton::setKeycode(ushort keycode) | ||
202 | { | ||
203 | m_Keycode = keycode; | ||
204 | } | ||
205 | |||
206 | void ODeviceButton::setUserText(const QString& text) | ||
207 | { | ||
208 | m_UserText = text; | ||
209 | } | ||
210 | |||
211 | void ODeviceButton::setPixmap(const QPixmap& picture) | ||
212 | { | ||
213 | m_Pixmap = picture; | ||
214 | } | ||
215 | |||
216 | void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) | ||
217 | { | ||
218 | m_FactoryPresetPressedAction = action; | ||
219 | } | ||
220 | |||
221 | void ODeviceButton::setPressedAction(const OQCopMessage& action) | ||
222 | { | ||
223 | m_PressedAction = action; | ||
224 | } | ||
225 | |||
226 | void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) | ||
227 | { | ||
228 | m_FactoryPresetHeldAction = action; | ||
229 | } | ||
230 | |||
231 | void ODeviceButton::setHeldAction(const OQCopMessage& action) | ||
232 | { | ||
233 | m_HeldAction = action; | ||
234 | } | ||
diff --git a/libopie/odevicebutton.h b/libopie/odevicebutton.h new file mode 100644 index 0000000..5281ab2 --- a/dev/null +++ b/libopie/odevicebutton.h | |||
@@ -0,0 +1,97 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef DEVICE_BUTTON_H | ||
21 | #define DEVICE_BUTTON_H | ||
22 | |||
23 | #include <qpixmap.h> | ||
24 | #include <qstring.h> | ||
25 | |||
26 | class OQCopMessageData; | ||
27 | |||
28 | namespace Opie | ||
29 | { | ||
30 | |||
31 | class OQCopMessage { | ||
32 | public: | ||
33 | OQCopMessage ( ); | ||
34 | OQCopMessage ( const OQCopMessage © ); | ||
35 | OQCopMessage ( const QCString &m_channel, const QCString &message, const QByteArray &args = QByteArray ( )); | ||
36 | |||
37 | OQCopMessage &operator = ( const OQCopMessage &assign ); | ||
38 | |||
39 | void setChannel ( const QCString &channel ); | ||
40 | void setMessage ( const QCString &message ); | ||
41 | void setData ( const QByteArray &ba ); | ||
42 | |||
43 | QCString channel ( ) const; | ||
44 | QCString message ( ) const; | ||
45 | QByteArray data ( ) const; | ||
46 | |||
47 | bool send ( ); | ||
48 | |||
49 | private: | ||
50 | void init ( const QCString &m_channel, const QCString &message, const QByteArray &args ); | ||
51 | |||
52 | OQCopMessageData *d; | ||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * This class represents a physical button on a Qtopia device. A device may | ||
58 | * have n "user programmable" buttons, which are number 1..n. The location | ||
59 | * and number of buttons will vary from device to device. userText() and pixmap() | ||
60 | * may be used to describe this button to the user in help documentation. | ||
61 | */ | ||
62 | |||
63 | class ODeviceButton | ||
64 | { | ||
65 | public: | ||
66 | ODeviceButton(); | ||
67 | virtual ~ODeviceButton(); | ||
68 | |||
69 | ushort keycode ( ) const; | ||
70 | QString userText ( ) const; | ||
71 | QPixmap pixmap ( ) const; | ||
72 | OQCopMessage factoryPresetPressedAction ( ) const; | ||
73 | OQCopMessage pressedAction ( ) const; | ||
74 | OQCopMessage factoryPresetHeldAction ( ) const; | ||
75 | OQCopMessage heldAction ( ) const; | ||
76 | |||
77 | void setKeycode ( ushort keycode ); | ||
78 | void setUserText ( const QString& text ); | ||
79 | void setPixmap ( const QPixmap& picture ); | ||
80 | void setFactoryPresetPressedAction ( const OQCopMessage& qcopMessage ); | ||
81 | void setPressedAction ( const OQCopMessage& qcopMessage ); | ||
82 | void setFactoryPresetHeldAction ( const OQCopMessage& qcopMessage ); | ||
83 | void setHeldAction ( const OQCopMessage& qcopMessage ); | ||
84 | |||
85 | private: | ||
86 | ushort m_Keycode; | ||
87 | QString m_UserText; | ||
88 | QPixmap m_Pixmap; | ||
89 | OQCopMessage m_FactoryPresetPressedAction; | ||
90 | OQCopMessage m_PressedAction; | ||
91 | OQCopMessage m_FactoryPresetHeldAction; | ||
92 | OQCopMessage m_HeldAction; | ||
93 | }; | ||
94 | |||
95 | } | ||
96 | |||
97 | #endif | ||