summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-01 18:08:46 (UTC)
committer zecke <zecke>2004-05-01 18:08:46 (UTC)
commitec6a887d8abddbab085a0a3aecae5760ff85dbe8 (patch) (side-by-side diff)
tree93f42bc5ebc3a5428dc93af6b7b90392085a551f
parent8dd2d693000c916346f0bb7d94cbc02b8456c65b (diff)
downloadopie-ec6a887d8abddbab085a0a3aecae5760ff85dbe8.zip
opie-ec6a887d8abddbab085a0a3aecae5760ff85dbe8.tar.gz
opie-ec6a887d8abddbab085a0a3aecae5760ff85dbe8.tar.bz2
Make the code more appealing to me
Fix small memory leak for the blacklist QMap
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/okeyconfigmanager.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp
index 18740ef..ad0f7f7 100644
--- a/libopie2/opiecore/okeyconfigmanager.cpp
+++ b/libopie2/opiecore/okeyconfigmanager.cpp
@@ -464,88 +464,91 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const {
* }
* }
* }
*
* \endcode
*
* @param conf The Config where the KeySetting should be stored
* @param group The group where the KeySetting will be stored
* @param black Which keys shouldn't be allowed to handle
* @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
* @param par The parent/owner of this manager
* @param name The name of this object
*/
OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
const QString& group,
const OKeyPair::List& black,
bool grabkeyboard, QObject* par,
const char* name)
: QObject( par, name ), m_conf( conf ), m_group( group ),
m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){
if ( m_grab )
QPEApplication::grabKeyboard();
m_event_mask = OKeyConfigManager::MaskReleased;
}
/**
* Destructor
*/
OKeyConfigManager::~OKeyConfigManager() {
if ( m_grab )
QPEApplication::ungrabKeyboard();
+ delete m_map;
}
/**
* Load the Configuration from the OConfig
* If a Key is restricted but was in the config we will
* make it be the empty key paur
* We will change the group but restore to the previous.
*
* @see OKeyPair::emptyKey
*/
void OKeyConfigManager::load() {
Opie::Core::OConfigGroupSaver( m_conf, m_group );
/*
* Read each item
*/
int key, mod;
for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) {
- key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() );
- mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() );
+ key = m_conf->readNumEntry( (*it).configKey()+"key",
+ (*it).defaultKeyPair().keycode() );
+ mod = m_conf->readNumEntry( (*it).configKey()+"mod",
+ (*it).defaultKeyPair().modifier() );
OKeyPair okey( key, mod );
if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 )
- (*it).setKeyPair( OKeyPair(key, mod) );
+ (*it).setKeyPair( okey );
else
(*it).setKeyPair( OKeyPair::emptyKey() );
}
delete m_map; m_map = 0;
}
/**
* We will save the current configuration
* to the OConfig. We will change the group but restore
* to the previous
*/
void OKeyConfigManager::save() {
Opie::Core::OConfigGroupSaver( m_conf, m_group );
/*
* Write each item
*/
for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) {
/* skip empty items */
if ( (*it).isEmpty() )
continue;
OKeyPair pair = (*it).keyPair();
OKeyPair deft = (*it).defaultKeyPair();
/*
* don't write if it is the default setting
* FIXME allow to remove Keys from config
if ( (pair.keycode() == deft.keycode()) &&
(pair.modifier()== deft.modifier() ) )
return;
*/
m_conf->writeEntry((*it).configKey()+"key", pair.keycode() );
@@ -656,64 +659,67 @@ void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) {
* Clear the blackList
*/
void OKeyConfigManager::clearBlackList() {
m_blackKeys.clear();
delete m_map; m_map = 0;
}
/**
* Return a copy of the blackList
*/
OKeyPair::List OKeyConfigManager::blackList()const {
return m_blackKeys;
}
/**
* Ask the Manager to handle KeyEvents for you.
* All handled keys will emit a QSignal and return true
* that it handled the keyevent
*/
void OKeyConfigManager::handleWidget( QWidget* wid ) {
wid->installEventFilter( this );
}
/**
* @internal
*/
bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) {
if ( !obj->isWidgetType() )
return false;
+ /*
+ * check if we care for the event
+ */
if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) &&
(ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) )
return false;
QKeyEvent *key = static_cast<QKeyEvent*>( ev );
OKeyConfigItem item = handleKeyEvent( key );
if ( item.isEmpty() )
return false;
QWidget *wid = static_cast<QWidget*>( obj );
if ( item.object() && !item.slot().isEmpty() ) {
connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)),
item.object(), item.slot().data() );
emit actionActivated(wid, key);
disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)),
item.object(), item.slot().data() );
}
emit actionActivated( wid, key, item );
return true;
}
/**
* @internal
*/
OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) {
/*
* Create the map if not existing anymore
*/
if ( !m_map ) {