author | sandman <sandman> | 2003-03-26 23:53:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2003-03-26 23:53:14 (UTC) |
commit | 9d291e88efa5b33bbf34112cdee8b0e516150dd6 (patch) (side-by-side diff) | |
tree | 6059b942d98691d7882d5290d5aa854b187f13ce | |
parent | eda6fffbe8ad7e3635985d9b2a8f7b46964aa271 (diff) | |
download | opie-9d291e88efa5b33bbf34112cdee8b0e516150dd6.zip opie-9d291e88efa5b33bbf34112cdee8b0e516150dd6.tar.gz opie-9d291e88efa5b33bbf34112cdee8b0e516150dd6.tar.bz2 |
delay the initialization of the button information:
- faster startup for apps that are not accessing the HW buttons
- the basic ODevice stuff is useable without a QApplication object
-rw-r--r-- | libopie/odevice.cpp | 91 | ||||
-rw-r--r-- | libopie/odevice.h | 3 |
2 files changed, 70 insertions, 24 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index 80975c9..377945d 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -63,24 +63,25 @@ public: QString m_systemstr; OSystem m_system; QString m_sysverstr; Transformation m_rotation; - QValueList <ODeviceButton> m_buttons; - uint m_holdtime; + QValueList <ODeviceButton> *m_buttons; + uint m_holdtime; }; class iPAQ : public ODevice, public QWSServer::KeyboardFilter { protected: virtual void init ( ); + virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); @@ -101,16 +102,17 @@ protected: int m_power_timer; OLedState m_leds [2]; }; class Zaurus : public ODevice { protected: virtual void init ( ); + virtual void initButtons ( ); public: virtual bool setSoftSuspend ( bool soft ); virtual bool setDisplayBrightness ( int b ); virtual int displayBrightnessResolution ( ) const; virtual void alarmSound ( ); @@ -249,46 +251,57 @@ ODevice::ODevice ( ) d-> m_vendorstr = "Unknown"; d-> m_vendor = Vendor_Unknown; d-> m_systemstr = "Unknown"; d-> m_system = System_Unknown; d-> m_sysverstr = "0.0"; d-> m_rotation = Rot0; d-> m_holdtime = 1000; // 1000ms - - QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); - connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); + d-> m_buttons = 0; } void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) { if ( msg == "deviceButtonMappingChanged()" ) { reloadButtonMapping ( ); } } void ODevice::init ( ) { +} + +void ODevice::initButtons ( ) +{ + if ( d-> m_buttons ) + return; + // Simulation uses iPAQ 3660 device buttons + qDebug ( "init Buttons" ); + d-> m_buttons = new QValueList <ODeviceButton>; + for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { i_button *ib = ipaq_buttons + i; ODeviceButton b; if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { b. setKeycode ( ib-> code ); b. setUserText ( QObject::tr ( "Button", ib-> utext )); b. setPixmap ( Resource::loadPixmap ( ib-> pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); - d-> m_buttons. append ( b ); + d-> m_buttons-> append ( b ); } } reloadButtonMapping ( ); + + QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); + connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); } ODevice::~ODevice ( ) { delete d; } bool ODevice::setSoftSuspend ( bool /*soft*/ ) @@ -469,41 +482,47 @@ int ODevice::readLightSensor ( ) return -1; } int ODevice::lightSensorResolution ( ) const { return 0; } -const QValueList <ODeviceButton> &ODevice::buttons ( ) const +const QValueList <ODeviceButton> &ODevice::buttons ( ) { - return d-> m_buttons; + initButtons ( ); + + return *d-> m_buttons; } uint ODevice::buttonHoldTime ( ) const { return d-> m_holdtime; } const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) { - for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons. begin ( ); it != d-> m_buttons. end ( ); ++it ) { + initButtons ( ); + + for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { if ( (*it). keycode ( ) == code ) return &(*it); } return 0; } void ODevice::reloadButtonMapping ( ) { + initButtons ( ); + Config cfg ( "ButtonSettings" ); - for ( uint i = 0; i < d-> m_buttons. count ( ); i++ ) { - ODeviceButton &b = d-> m_buttons [i]; + for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { + ODeviceButton &b = ( *d-> m_buttons ) [i]; QString group = "Button" + QString::number ( i ); QCString pch, hch; QCString pm, hm; QByteArray pdata, hdata; if ( cfg. hasGroup ( group )) { cfg. setGroup ( group ); @@ -519,43 +538,46 @@ void ODevice::reloadButtonMapping ( ) b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); } } void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) { + initButtons ( ); + QString mb_chan; - if ( button >= (int) d-> m_buttons. count ( )) + if ( button >= (int) d-> m_buttons-> count ( )) return; - - ODeviceButton &b = d-> m_buttons [button]; + ODeviceButton &b = ( *d-> m_buttons ) [button]; b. setPressedAction ( action ); mb_chan=b. pressedAction ( ). channel ( ); Config buttonFile ( "ButtonSettings" ); buttonFile. setGroup ( "Button" + QString::number ( button )); buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); // buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); } void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) { - if ( button >= (int) d-> m_buttons. count ( )) + initButtons ( ); + + if ( button >= (int) d-> m_buttons-> count ( )) return; - ODeviceButton &b = d-> m_buttons [button]; + ODeviceButton &b = ( *d-> m_buttons ) [button]; b. setHeldAction ( action ); Config buttonFile ( "ButtonSettings" ); buttonFile. setGroup ( "Button" + QString::number ( button )); buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); // buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); @@ -623,36 +645,48 @@ void iPAQ::init ( ) f. close ( ); } m_leds [0] = m_leds [1] = Led_Off; m_power_timer = 0; + if ( d-> m_qwsserver ) + QWSServer::setKeyboardFilter ( this ); +} + +void iPAQ::initButtons ( ) +{ + if ( d-> m_buttons ) + return; + + d-> m_buttons = new QValueList <ODeviceButton>; + for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { i_button *ib = ipaq_buttons + i; ODeviceButton b; if (( ib-> model & d-> m_model ) == d-> m_model ) { b. setKeycode ( ib-> code ); b. setUserText ( QObject::tr ( "Button", ib-> utext )); b. setPixmap ( Resource::loadPixmap ( ib-> pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); - d-> m_buttons. append ( b ); + d-> m_buttons-> append ( b ); } } - reloadButtonMapping ( ); + reloadButtonMapping ( ); - if ( d-> m_qwsserver ) - QWSServer::setKeyboardFilter ( this ); + QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); + connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); } + //#include <linux/h3600_ts.h> // including kernel headers is evil ... typedef struct { unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ unsigned char TotalTime; /* Units of 5 seconds */ unsigned char OnTime; /* units of 100m/s */ unsigned char OffTime; /* units of 100m/s */ } LED_IN; @@ -988,32 +1022,43 @@ void Zaurus::init ( ) case Model_Zaurus_SLA300: case Model_Zaurus_SLB600: case Model_Zaurus_SL5500: case Model_Zaurus_SL5000: default: d-> m_rotation = Rot270; break; } + m_leds [0] = Led_Off; +} + +void Zaurus::initButtons ( ) +{ + if ( d-> m_buttons ) + return; + + d-> m_buttons = new QValueList <ODeviceButton>; for ( uint i = 0; i < ( sizeof( z_buttons ) / sizeof( z_button )); i++ ) { z_button *zb = z_buttons + i; ODeviceButton b; b. setKeycode ( zb-> code ); b. setUserText ( QObject::tr ( "Button", zb-> utext )); b. setPixmap ( Resource::loadPixmap ( zb-> pix )); b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), zb-> fpressedaction )); b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), zb-> fheldaction )); - d-> m_buttons. append ( b ); + d-> m_buttons-> append ( b ); } + reloadButtonMapping ( ); - - m_leds [0] = Led_Off; + + QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); + connect ( sysch, SIGNAL( received( const QCString &, const QByteArray & )), this, SLOT( systemMessage ( const QCString &, const QByteArray & ))); } #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> //#include <asm/sharp_char.h> // including kernel headers is evil ... diff --git a/libopie/odevice.h b/libopie/odevice.h index 575e1fe..ff578d8 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h @@ -98,16 +98,17 @@ class ODevice : public QObject { Q_OBJECT private: ODevice ( const ODevice & ); protected: ODevice ( ); virtual void init ( ); + virtual void initButtons ( ); ODeviceData *d; public: virtual ~ODevice ( ); static ODevice *inst ( ); @@ -152,17 +153,17 @@ public: virtual int lightSensorResolution ( ) const; /** * Returns the available buttons on this device. The number and location * of buttons will vary depending on the device. Button numbers will be assigned * by the device manufacturer and will be from most preferred button to least preffered * button. Note that this list only contains "user mappable" buttons. */ - const QValueList<ODeviceButton> &buttons ( ) const; + const QValueList<ODeviceButton> &buttons ( ); /** * Returns the DeviceButton for the \a keyCode. If \a keyCode is not found, it * returns 0L */ const ODeviceButton *buttonForKeycode ( ushort keyCode ); /** |