summaryrefslogtreecommitdiff
path: root/libopie
authorsandman <sandman>2003-03-26 23:53:14 (UTC)
committer sandman <sandman>2003-03-26 23:53:14 (UTC)
commit9d291e88efa5b33bbf34112cdee8b0e516150dd6 (patch) (side-by-side diff)
tree6059b942d98691d7882d5290d5aa854b187f13ce /libopie
parenteda6fffbe8ad7e3635985d9b2a8f7b46964aa271 (diff)
downloadopie-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
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp91
-rw-r--r--libopie/odevice.h3
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
@@ -47,86 +47,88 @@
#define OD_IO(type,number) OD_IOC(0,type,number,0)
#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
using namespace Opie;
class ODeviceData {
public:
bool m_qwsserver;
QString m_vendorstr;
OVendor m_vendor;
QString m_modelstr;
OModel m_model;
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 ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
virtual bool hasLightSensor ( ) const;
virtual int readLightSensor ( );
virtual int lightSensorResolution ( ) const;
protected:
virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
virtual void timerEvent ( QTimerEvent *te );
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 ( );
virtual void keySound ( );
virtual void touchSound ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
protected:
virtual void buzzer ( int snd );
OLedState m_leds [1];
};
struct i_button {
@@ -233,78 +235,89 @@ ODevice *ODevice::inst ( )
/**************************************************
*
* common
*
**************************************************/
ODevice::ODevice ( )
{
d = new ODeviceData;
d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
d-> m_modelstr = "Unknown";
d-> m_model = Model_Unknown;
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*/ )
{
return false;
}
//#include <linux/apm_bios.h>
#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
bool ODevice::suspend ( )
{
if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend
return false;
if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
return false;
@@ -453,125 +466,134 @@ OLedState ODevice::ledState ( OLed /*which*/ ) const
{
return Led_Off;
}
bool ODevice::setLedState ( OLed /*which*/, OLedState /*st*/ )
{
return false;
}
bool ODevice::hasLightSensor ( ) const
{
return false;
}
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 );
pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
// pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
// hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
}
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 ( )));
QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
}
/**************************************************
*
* iPAQ
*
**************************************************/
void iPAQ::init ( )
{
d-> m_vendorstr = "HP";
@@ -607,68 +629,80 @@ void iPAQ::init ( )
break;
case Model_iPAQ_H36xx:
case Model_iPAQ_H37xx:
case Model_iPAQ_H39xx:
default:
d-> m_rotation = Rot270;
break;
}
f. setName ( "/etc/familiar-version" );
if ( f. open ( IO_ReadOnly )) {
d-> m_systemstr = "Familiar";
d-> m_system = System_Familiar;
QTextStream ts ( &f );
d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
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;
typedef struct {
unsigned char mode;
unsigned char pwr;
unsigned char brightness;
} FLITE_IN;
#define LED_ON OD_IOW( 'f', 5, LED_IN )
#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
QValueList <OLed> iPAQ::ledList ( ) const
{
QValueList <OLed> vl;
vl << Led_Power;
@@ -972,64 +1006,75 @@ void Zaurus::init ( )
d-> m_model = Model_Zaurus_SLA300;
else if ( model == "SL-B600" || model == "SL-5600" )
d-> m_model = Model_Zaurus_SLB600;
else
d-> m_model = Model_Zaurus_SL5000;
}
else {
d-> m_model = Model_Zaurus_SL5000;
d-> m_modelstr = "Zaurus (model unknown)";
}
switch ( d-> m_model ) {
case Model_Zaurus_SLC700:
/* note for C700, we must check the display rotation
* sensor to set an appropriate value
*/
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 ...
#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
#define SHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
#define SHARP_BUZ_KEYSOUND 2 /* key sound */
#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
/* --- for SHARP_BUZZER device --- */
//#define SHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
diff --git a/libopie/odevice.h b/libopie/odevice.h
index 575e1fe..ff578d8 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -82,48 +82,49 @@ enum OLed {
Led_Power,
Led_BlueTooth
};
enum OHardKey {
HardKey_Datebook = Qt::Key_F9,
HardKey_Contacts = Qt::Key_F10,
HardKey_Menu = Qt::Key_F11,
HardKey_Home = Qt::Key_F12,
HardKey_Mail = Qt::Key_F13,
HardKey_Record = Qt::Key_F24,
HardKey_Suspend = Qt::Key_F34,
HardKey_Backlight = Qt::Key_F35,
};
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 ( );
// information
QString modelString ( ) const;
OModel model ( ) const;
inline OModel series ( ) const { return (OModel) ( model ( ) & Model_Series_Mask ); }
QString vendorString ( ) const;
OVendor vendor ( ) const;
QString systemString ( ) const;
OSystem system ( ) const;
QString systemVersionString ( ) const;
Transformation rotation ( ) const;
@@ -136,49 +137,49 @@ public:
virtual bool setDisplayBrightness ( int brightness );
virtual int displayBrightnessResolution ( ) const;
// input / output
virtual void alarmSound ( );
virtual void keySound ( );
virtual void touchSound ( );
virtual QValueList <OLed> ledList ( ) const;
virtual QValueList <OLedState> ledStateList ( OLed led ) const;
virtual OLedState ledState ( OLed led ) const;
virtual bool setLedState ( OLed led, OLedState st );
virtual bool hasLightSensor ( ) const;
virtual int readLightSensor ( );
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 );
/**
* Reassigns the pressed action for \a button. To return to the factory
* default pass an empty string as \a qcopMessage.
*/
void remapPressedAction ( int button, const OQCopMessage &qcopMessage );
/**
* Reassigns the held action for \a button. To return to the factory
* default pass an empty string as \a qcopMessage.
*/
void remapHeldAction ( int button, const OQCopMessage &qcopMessage );
/**
* How long (in ms) you have to press a button for a "hold" action
*/
uint buttonHoldTime ( ) const;