summaryrefslogtreecommitdiff
authorsandman <sandman>2002-12-22 23:54:50 (UTC)
committer sandman <sandman>2002-12-22 23:54:50 (UTC)
commit5c7694a7baadec8afe128ad2541e0a8acfc23737 (patch) (unidiff)
treec3dc0189dd9933e43565d85183474adfdc0de7aa
parent3ef4b1549eca77c3d1c3ef710eb6abbd3de336be (diff)
downloadopie-5c7694a7baadec8afe128ad2541e0a8acfc23737.zip
opie-5c7694a7baadec8afe128ad2541e0a8acfc23737.tar.gz
opie-5c7694a7baadec8afe128ad2541e0a8acfc23737.tar.bz2
- added the device button stuff to ODevice
- ODevice is now derived from QObject (don't ask me why I didn't make this from the beginning)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro4
-rw-r--r--libopie/odevice.cpp246
-rw-r--r--libopie/odevice.h48
-rw-r--r--libopie/odevicebutton.cpp234
-rw-r--r--libopie/odevicebutton.h97
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
@@ -4,13 +4,13 @@ HEADERS = ofontmenu.h \
4 ocolorbutton.h \ 4 ocolorbutton.h \
5 ofiledialog.h ofileselector.h tododb.h \ 5 ofiledialog.h ofileselector.h tododb.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 \
15 pim/otodo.h \ 15 pim/otodo.h \
16 pim/orecordlist.h \ 16 pim/orecordlist.h \
@@ -46,13 +46,13 @@ SOURCES = ofontmenu.cc \
46 xmltree.cc \ 46 xmltree.cc \
47 ofiledialog.cc ofileselector.cc \ 47 ofiledialog.cc ofileselector.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 \
57 pim/otodoaccess.cpp \ 57 pim/otodoaccess.cpp \
58 pim/otodoaccessbackend.cpp \ 58 pim/otodoaccessbackend.cpp \
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index c947630..f93d1ed 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -30,12 +30,13 @@
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
@@ -61,16 +62,19 @@ public:
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
70class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { 74class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
71protected: 75protected:
72 virtual void init ( ); 76 virtual void init ( );
73 77
74public: 78public:
75 virtual bool setSoftSuspend ( bool soft ); 79 virtual bool setSoftSuspend ( bool soft );
76 80
@@ -85,14 +89,12 @@ public:
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
93protected: 95protected:
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
@@ -115,22 +117,99 @@ public:
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
123protected: 123protected:
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
130struct 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
172struct 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
203static 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
135ODevice *ODevice::inst ( ) 214ODevice *ODevice::inst ( )
136{ 215{
@@ -167,16 +246,45 @@ ODevice::ODevice ( )
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
259void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
260{
261 if ( msg == "deviceButtonMappingChanged()" ) {
262 reloadButtonMapping ( );
263 }
173} 264}
174 265
175void ODevice::init ( ) 266void 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
179ODevice::~ODevice ( ) 287ODevice::~ODevice ( )
180{ 288{
181 delete d; 289 delete d;
182} 290}
@@ -356,16 +464,95 @@ int ODevice::readLightSensor ( )
356 464
357int ODevice::lightSensorResolution ( ) const 465int ODevice::lightSensorResolution ( ) const
358{ 466{
359 return 0; 467 return 0;
360} 468}
361 469
362//QValueList <int> ODevice::keyList ( ) const 470const QValueList <ODeviceButton> &ODevice::buttons ( ) const
363//{ 471{
364 //return QValueList <int> ( ); 472 return d-> m_buttons;
365//} 473}
474
475uint ODevice::buttonHoldTime ( ) const
476{
477 return d-> m_holdtime;
478}
479
480const 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
489void 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
517void 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
535void 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
@@ -412,12 +599,32 @@ void iPAQ::init ( )
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
@@ -500,19 +707,12 @@ bool iPAQ::setLedState ( OLed l, OLedState st )
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
513bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 713bool 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
@@ -751,12 +951,26 @@ void Zaurus::init ( )
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>
diff --git a/libopie/odevice.h b/libopie/odevice.h
index 86491d4..ce62f1a 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -17,15 +17,18 @@
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
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
26class ODeviceData; 29class ODeviceData;
27 30
28namespace Opie { 31namespace Opie {
29 32
30enum OModel { 33enum OModel {
31 Model_Unknown, 34 Model_Unknown,
@@ -84,14 +87,15 @@ enum OHardKey {
84 HardKey_Record = Qt::Key_F24, 87 HardKey_Record = Qt::Key_F24,
85 HardKey_Suspend = Qt::Key_F34, 88 HardKey_Suspend = Qt::Key_F34,
86 HardKey_Backlight = Qt::Key_F35, 89 HardKey_Backlight = Qt::Key_F35,
87}; 90};
88 91
89 92
90class ODevice 93class ODevice : public QObject {
91{ 94 Q_OBJECT
95
92private: 96private:
93 ODevice ( const ODevice & ); 97 ODevice ( const ODevice & );
94 98
95protected: 99protected:
96 ODevice ( ); 100 ODevice ( );
97 virtual void init ( ); 101 virtual void init ( );
@@ -139,12 +143,52 @@ public:
139 virtual OLedState ledState ( OLed led ) const; 143 virtual OLedState ledState ( OLed led ) const;
140 virtual bool setLedState ( OLed led, OLedState st ); 144 virtual bool setLedState ( OLed led, OLedState st );
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
187protected:
188 void reloadButtonMapping ( );
145}; 189};
146 190
147} 191}
148 192
149#endif 193#endif
150 194
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
27using namespace Opie;
28
29
30class OQCopMessageData {
31 public:
32 QCString m_channel;
33 QCString m_message;
34 QByteArray m_data;
35};
36
37
38OQCopMessage::OQCopMessage ( )
39 : d ( 0 )
40{
41 init ( QCString ( ), QCString ( ), QByteArray ( ));
42}
43
44OQCopMessage::OQCopMessage ( const OQCopMessage &copy )
45 : d ( 0 )
46{
47 init ( copy. channel ( ), copy. message ( ), copy. data ( ));
48}
49
50OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign )
51{
52 init ( assign. channel ( ), assign. message ( ), assign. data ( ));
53 return *this;
54}
55
56OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg )
57 : d ( 0 )
58{
59 init ( ch, m, arg );
60}
61
62void 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
71bool 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
84QCString OQCopMessage::channel ( ) const
85{
86 return d-> m_channel;
87}
88
89QCString OQCopMessage::message ( ) const
90{
91 return d-> m_message;
92}
93
94QByteArray OQCopMessage::data ( ) const
95{
96 return d-> m_data;
97}
98
99void OQCopMessage::setChannel ( const QCString &ch )
100{
101 d-> m_channel = ch;
102}
103
104void OQCopMessage::setMessage ( const QCString &m )
105{
106 d-> m_message = m;
107}
108
109void 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
127ODeviceButton::ODeviceButton()
128{
129}
130
131ODeviceButton::~ODeviceButton()
132{
133}
134
135/*!
136 Returns the button's keycode.
137 */
138ushort 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 */
147QString 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 */
156QPixmap 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 */
165OQCopMessage 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 */
174OQCopMessage 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 */
185OQCopMessage 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 */
194OQCopMessage ODeviceButton::heldAction() const
195{
196 if (m_HeldAction.channel().isEmpty())
197 return factoryPresetHeldAction();
198 return m_HeldAction;
199}
200
201void ODeviceButton::setKeycode(ushort keycode)
202{
203 m_Keycode = keycode;
204}
205
206void ODeviceButton::setUserText(const QString& text)
207{
208 m_UserText = text;
209}
210
211void ODeviceButton::setPixmap(const QPixmap& picture)
212{
213 m_Pixmap = picture;
214}
215
216void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action)
217{
218 m_FactoryPresetPressedAction = action;
219}
220
221void ODeviceButton::setPressedAction(const OQCopMessage& action)
222{
223 m_PressedAction = action;
224}
225
226void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action)
227{
228 m_FactoryPresetHeldAction = action;
229}
230
231void 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
26class OQCopMessageData;
27
28namespace Opie
29{
30
31class OQCopMessage {
32public:
33 OQCopMessage ( );
34 OQCopMessage ( const OQCopMessage &copy );
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
49private:
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
63class ODeviceButton
64{
65public:
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
85private:
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