author | sandman <sandman> | 2002-12-22 23:54:50 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-22 23:54:50 (UTC) |
commit | 5c7694a7baadec8afe128ad2541e0a8acfc23737 (patch) (side-by-side diff) | |
tree | c3dc0189dd9933e43565d85183474adfdc0de7aa | |
parent | 3ef4b1549eca77c3d1c3ef710eb6abbd3de336be (diff) | |
download | opie-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)
-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 @@ -9,3 +9,3 @@ HEADERS = ofontmenu.h \ oclickablelabel.h oprocctrl.h \ - oprocess.h odevice.h \ + oprocess.h odevice.h odevicebutton.h \ otimepicker.h otabwidget.h \ @@ -51,3 +51,3 @@ SOURCES = ofontmenu.cc \ oprocctrl.cpp oprocess.cpp \ - odevice.cpp otimepicker.cpp \ + odevice.cpp odevicebutton.cpp otimepicker.cpp \ otabwidget.cpp otabbar.cpp \ diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index c947630..f93d1ed 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp @@ -35,2 +35,3 @@ #include <qpe/config.h> +#include <qpe/qcopenvelope_qws.h> @@ -66,2 +67,5 @@ public: QString m_sysverstr; + + QValueList <ODeviceButton> m_buttons; + uint m_holdtime; }; @@ -69,3 +73,3 @@ public: -class iPAQ : public QObject, public ODevice, public QWSServer::KeyboardFilter { +class iPAQ : public ODevice, public QWSServer::KeyboardFilter { protected: @@ -90,4 +94,2 @@ public: - //virtual QValueList <int> keyList ( ) const; - protected: @@ -120,4 +122,2 @@ public: - //virtual QValueList <int> keyList ( ) const; - protected: @@ -129,3 +129,82 @@ protected: +struct i_button { + uint model; + Qt::Key code; + char *utext; + char *pix; + char *fpressedservice; + char *fpressedaction; + char *fheldservice; + char *fheldaction; +} ipaq_buttons [] = { + { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, + Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), + "devicebuttons/ipaq_calendar", + "datebook", "nextView()", + "today", "raise()" }, + { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, + Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), + "devicebuttons/ipaq_contact", + "addressbook", "raise()", + "addressbook", "beamBusinessCard()" }, + { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, + Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), + "devicebuttons/ipaq_menu", + "QPE/TaskBar", "toggleMenu()", + "QPE/TaskBar", "toggleStartMenu()" }, + { Model_iPAQ_H38xx | Model_iPAQ_H39xx, + Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Mail Button"), + "devicebuttons/ipaq_mail", + "mail", "raise()", + "mail", "newMail()" }, + { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, + Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), + "devicebuttons/ipaq_home", + "QPE/Launcher", "home()", + "buttonsettings", "raise()" }, + { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx, + Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), + "devicebuttons/ipaq_record", + "QPE/VMemo", "toggleRecord()", + "sound", "raise()" }, +}; +struct z_button { + Qt::Key code; + char *utext; + char *pix; + char *fpressedservice; + char *fpressedaction; + char *fheldservice; + char *fheldaction; +} z_buttons [] = { + { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), + "devicebuttons/z_calendar", + "datebook", "nextView()", + "today", "raise()" }, + { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), + "devicebuttons/z_contact", + "addressbook", "raise()", + "addressbook", "beamBusinessCard()" }, + { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), + "devicebuttons/z_home", + "QPE/Launcher", "home()", + "buttonsettings", "raise()" }, + { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), + "devicebuttons/z_menu", + "QPE/TaskBar", "toggleMenu()", + "QPE/TaskBar", "toggleStartMenu()" }, + { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), + "devicebuttons/z_mail", + "mail", "raise()", + "mail", "newMail()" }, +}; + +static QCString makeChannel ( const char *str ) +{ + if ( str && !::strchr ( str, '/' )) + return QCString ( "QPE/Application/" ) + str; + else + return str; +} @@ -172,2 +251,14 @@ ODevice::ODevice ( ) d-> m_sysverstr = "0.0"; + + 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 & ))); +} + +void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) +{ + if ( msg == "deviceButtonMappingChanged()" ) { + reloadButtonMapping ( ); + } } @@ -176,2 +267,19 @@ void ODevice::init ( ) { + // Simulation uses iPAQ 3660 device buttons + + 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 ( qApp-> translate ( "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 ); + } + } + reloadButtonMapping ( ); } @@ -361,6 +469,85 @@ int ODevice::lightSensorResolution ( ) const -//QValueList <int> ODevice::keyList ( ) const -//{ -// return QValueList <int> ( ); -//} +const QValueList <ODeviceButton> &ODevice::buttons ( ) const +{ + 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 ) { + if ( (*it). keycode ( ) == code ) + return &(*it); + } + return 0; +} + +void ODevice::reloadButtonMapping ( ) +{ + Config cfg ( "ButtonSettings" ); + + 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 ) +{ + if ( button >= (int) d-> m_buttons. count ( )) + return; + + ODeviceButton &b = d-> m_buttons [button]; + b. setPressedAction ( action ); + + Config buttonFile ( "ButtonSettings" ); + buttonFile. setGroup ( "Button" + QString::number ( button )); + buttonFile. writeEntry ( "PressedActionChannel", (const char*) b. pressedAction ( ). channel ( )); + 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 ( )) + return; + + 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()" ); +} + @@ -417,2 +604,22 @@ void iPAQ::init ( ) + for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { + i_button *ib = ipaq_buttons + i; + ODeviceButton b; + + qDebug ( "%d: %d", i, ib-> model ); + + if (( ib-> model & d-> m_model ) == d-> m_model ) { + b. setKeycode ( ib-> code ); + b. setUserText ( qApp-> translate ( "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 ); + + qDebug ( "code: %d", ib-> code ); + } + } + reloadButtonMapping ( ); + if ( d-> m_qwsserver ) @@ -505,9 +712,2 @@ bool iPAQ::setLedState ( OLed l, OLedState st ) -//QValueList <int> iPAQ::keyList ( ) const -//{ -// QValueList <int> vl; -// vl << HardKey_Datebook << HardKey_Contacts << ( model ( ) == Model_iPAQ_H38xx ? HardKey_Mail : HardKey_Menu ) << HardKey_Home << HardKey_Record << HardKey_Suspend << HardKey_Backlight; -// return vl; -//} - bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) @@ -756,2 +956,16 @@ void Zaurus::init ( ) + 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 ( qApp-> translate ( "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 ); + } + reloadButtonMapping ( ); + m_leds [0] = Led_Off; diff --git a/libopie/odevice.h b/libopie/odevice.h index 86491d4..ce62f1a 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h @@ -22,2 +22,3 @@ +#include <qobject.h> #include <qstring.h> @@ -25,2 +26,4 @@ +#include <opie/odevicebutton.h> + class ODeviceData; @@ -89,4 +92,5 @@ enum OHardKey { -class ODevice -{ +class ODevice : public QObject { + Q_OBJECT + private: @@ -144,2 +148,42 @@ 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; + + /** + * 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; + +signals: + void buttonMappingChanged ( ); + +private slots: + void systemMessage ( const QCString &, const QByteArray & ); + +protected: + void reloadButtonMapping ( ); }; 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 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <qpixmap.h> +#include <qstring.h> + +#include <qpe/qcopenvelope_qws.h> +#include <opie/odevicebutton.h> + +using namespace Opie; + + +class OQCopMessageData { +public: + QCString m_channel; + QCString m_message; + QByteArray m_data; +}; + + +OQCopMessage::OQCopMessage ( ) + : d ( 0 ) +{ + init ( QCString ( ), QCString ( ), QByteArray ( )); +} + +OQCopMessage::OQCopMessage ( const OQCopMessage © ) + : d ( 0 ) +{ + init ( copy. channel ( ), copy. message ( ), copy. data ( )); +} + +OQCopMessage &OQCopMessage::operator = ( const OQCopMessage &assign ) +{ + init ( assign. channel ( ), assign. message ( ), assign. data ( )); + return *this; +} + +OQCopMessage::OQCopMessage ( const QCString &ch, const QCString &m, const QByteArray &arg ) + : d ( 0 ) +{ + init ( ch, m, arg ); +} + +void OQCopMessage::init ( const QCString &ch, const QCString &m, const QByteArray &arg ) +{ + if ( !d ) + d = new OQCopMessageData ( ); + d-> m_channel = ch; + d-> m_message = m; + d-> m_data = arg; +} + +bool OQCopMessage::send ( ) +{ + if ( d-> m_channel. isEmpty ( ) || d-> m_message. isEmpty ( )) + return false; + + QCopEnvelope e ( d-> m_channel, d-> m_message ); + + if ( d-> m_data. size ( )) + e. writeRawBytes ( d-> m_data. data ( ), d-> m_data. size ( )); + + return true; +} + +QCString OQCopMessage::channel ( ) const +{ + return d-> m_channel; +} + +QCString OQCopMessage::message ( ) const +{ + return d-> m_message; +} + +QByteArray OQCopMessage::data ( ) const +{ + return d-> m_data; +} + +void OQCopMessage::setChannel ( const QCString &ch ) +{ + d-> m_channel = ch; +} + +void OQCopMessage::setMessage ( const QCString &m ) +{ + d-> m_message = m; +} + +void OQCopMessage::setData ( const QByteArray &data ) +{ + d-> m_data = data; +} + +/*! \class ODeviceButton + \brief The ODeviceButton class represents a physical user mappable button on a Qtopia device. + + This class represents a physical button on a Qtopia device. A + device may have "user programmable" buttons. + The location and number of buttons will vary from device to + device. userText() and pixmap() may be used to describe this button + to the user in help documentation. + + \ingroup qtopiaemb + \internal +*/ + +ODeviceButton::ODeviceButton() +{ +} + +ODeviceButton::~ODeviceButton() +{ +} + +/*! + Returns the button's keycode. + */ +ushort ODeviceButton::keycode() const +{ + return m_Keycode; +} + + +/*! + This function returns a human readable, translated description of the button. + */ +QString ODeviceButton::userText() const +{ + return m_UserText; +} + +/*! + This function returns the pixmap for this button. If there isn't one + it will return an empty (null) pixmap. + */ +QPixmap ODeviceButton::pixmap() const +{ + return m_Pixmap; +} + +/*! + This function returns the factory preset (default) action for when this button + is pressed. The return value is a legal QCop message. + */ +OQCopMessage ODeviceButton::factoryPresetPressedAction() const +{ + return m_FactoryPresetPressedAction; +} + +/*! + This function returns the user assigned action for when this button is pressed. + If no action is assigned, factoryPresetAction() is returned. + */ +OQCopMessage ODeviceButton::pressedAction() const +{ + if (m_PressedAction.channel().isEmpty()) + return factoryPresetPressedAction(); + return m_PressedAction; +} + +/*! + This function returns the factory preset (default) action for when this button + is pressed and held. The return value is a legal QCop message. + */ +OQCopMessage ODeviceButton::factoryPresetHeldAction() const +{ + return m_FactoryPresetHeldAction; +} + +/*! + This function returns the user assigned action for when this button is pressed + and held. If no action is assigned, factoryPresetAction() is returned. + */ +OQCopMessage ODeviceButton::heldAction() const +{ + if (m_HeldAction.channel().isEmpty()) + return factoryPresetHeldAction(); + return m_HeldAction; +} + +void ODeviceButton::setKeycode(ushort keycode) +{ + m_Keycode = keycode; +} + +void ODeviceButton::setUserText(const QString& text) +{ + m_UserText = text; +} + +void ODeviceButton::setPixmap(const QPixmap& picture) +{ + m_Pixmap = picture; +} + +void ODeviceButton::setFactoryPresetPressedAction(const OQCopMessage& action) +{ + m_FactoryPresetPressedAction = action; +} + +void ODeviceButton::setPressedAction(const OQCopMessage& action) +{ + m_PressedAction = action; +} + +void ODeviceButton::setFactoryPresetHeldAction(const OQCopMessage& action) +{ + m_FactoryPresetHeldAction = action; +} + +void ODeviceButton::setHeldAction(const OQCopMessage& action) +{ + m_HeldAction = action; +} 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 @@ +/********************************************************************** +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef DEVICE_BUTTON_H +#define DEVICE_BUTTON_H + +#include <qpixmap.h> +#include <qstring.h> + +class OQCopMessageData; + +namespace Opie +{ + +class OQCopMessage { +public: + OQCopMessage ( ); + OQCopMessage ( const OQCopMessage © ); + OQCopMessage ( const QCString &m_channel, const QCString &message, const QByteArray &args = QByteArray ( )); + + OQCopMessage &operator = ( const OQCopMessage &assign ); + + void setChannel ( const QCString &channel ); + void setMessage ( const QCString &message ); + void setData ( const QByteArray &ba ); + + QCString channel ( ) const; + QCString message ( ) const; + QByteArray data ( ) const; + + bool send ( ); + +private: + void init ( const QCString &m_channel, const QCString &message, const QByteArray &args ); + + OQCopMessageData *d; +}; + + +/** + * This class represents a physical button on a Qtopia device. A device may + * have n "user programmable" buttons, which are number 1..n. The location + * and number of buttons will vary from device to device. userText() and pixmap() + * may be used to describe this button to the user in help documentation. + */ + +class ODeviceButton +{ +public: + ODeviceButton(); + virtual ~ODeviceButton(); + + ushort keycode ( ) const; + QString userText ( ) const; + QPixmap pixmap ( ) const; + OQCopMessage factoryPresetPressedAction ( ) const; + OQCopMessage pressedAction ( ) const; + OQCopMessage factoryPresetHeldAction ( ) const; + OQCopMessage heldAction ( ) const; + + void setKeycode ( ushort keycode ); + void setUserText ( const QString& text ); + void setPixmap ( const QPixmap& picture ); + void setFactoryPresetPressedAction ( const OQCopMessage& qcopMessage ); + void setPressedAction ( const OQCopMessage& qcopMessage ); + void setFactoryPresetHeldAction ( const OQCopMessage& qcopMessage ); + void setHeldAction ( const OQCopMessage& qcopMessage ); + +private: + ushort m_Keycode; + QString m_UserText; + QPixmap m_Pixmap; + OQCopMessage m_FactoryPresetPressedAction; + OQCopMessage m_PressedAction; + OQCopMessage m_FactoryPresetHeldAction; + OQCopMessage m_HeldAction; +}; + +} + +#endif |