author | zecke <zecke> | 2004-05-01 18:08:46 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-05-01 18:08:46 (UTC) |
commit | ec6a887d8abddbab085a0a3aecae5760ff85dbe8 (patch) (unidiff) | |
tree | 93f42bc5ebc3a5428dc93af6b7b90392085a551f /libopie2 | |
parent | 8dd2d693000c916346f0bb7d94cbc02b8456c65b (diff) | |
download | opie-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
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.cpp | 12 |
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 | |||
@@ -472,72 +472,75 @@ bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | |||
472 | * @param black Which keys shouldn't be allowed to handle | 472 | * @param black Which keys shouldn't be allowed to handle |
473 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | 473 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons |
474 | * @param par The parent/owner of this manager | 474 | * @param par The parent/owner of this manager |
475 | * @param name The name of this object | 475 | * @param name The name of this object |
476 | */ | 476 | */ |
477 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | 477 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, |
478 | const QString& group, | 478 | const QString& group, |
479 | const OKeyPair::List& black, | 479 | const OKeyPair::List& black, |
480 | bool grabkeyboard, QObject* par, | 480 | bool grabkeyboard, QObject* par, |
481 | const char* name) | 481 | const char* name) |
482 | : QObject( par, name ), m_conf( conf ), m_group( group ), | 482 | : QObject( par, name ), m_conf( conf ), m_group( group ), |
483 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | 483 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ |
484 | if ( m_grab ) | 484 | if ( m_grab ) |
485 | QPEApplication::grabKeyboard(); | 485 | QPEApplication::grabKeyboard(); |
486 | m_event_mask = OKeyConfigManager::MaskReleased; | 486 | m_event_mask = OKeyConfigManager::MaskReleased; |
487 | } | 487 | } |
488 | 488 | ||
489 | 489 | ||
490 | /** | 490 | /** |
491 | * Destructor | 491 | * Destructor |
492 | */ | 492 | */ |
493 | OKeyConfigManager::~OKeyConfigManager() { | 493 | OKeyConfigManager::~OKeyConfigManager() { |
494 | if ( m_grab ) | 494 | if ( m_grab ) |
495 | QPEApplication::ungrabKeyboard(); | 495 | QPEApplication::ungrabKeyboard(); |
496 | delete m_map; | ||
496 | } | 497 | } |
497 | 498 | ||
498 | /** | 499 | /** |
499 | * Load the Configuration from the OConfig | 500 | * Load the Configuration from the OConfig |
500 | * If a Key is restricted but was in the config we will | 501 | * If a Key is restricted but was in the config we will |
501 | * make it be the empty key paur | 502 | * make it be the empty key paur |
502 | * We will change the group but restore to the previous. | 503 | * We will change the group but restore to the previous. |
503 | * | 504 | * |
504 | * @see OKeyPair::emptyKey | 505 | * @see OKeyPair::emptyKey |
505 | */ | 506 | */ |
506 | void OKeyConfigManager::load() { | 507 | void OKeyConfigManager::load() { |
507 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | 508 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); |
508 | 509 | ||
509 | /* | 510 | /* |
510 | * Read each item | 511 | * Read each item |
511 | */ | 512 | */ |
512 | int key, mod; | 513 | int key, mod; |
513 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | 514 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { |
514 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | 515 | key = m_conf->readNumEntry( (*it).configKey()+"key", |
515 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | 516 | (*it).defaultKeyPair().keycode() ); |
517 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", | ||
518 | (*it).defaultKeyPair().modifier() ); | ||
516 | OKeyPair okey( key, mod ); | 519 | OKeyPair okey( key, mod ); |
517 | 520 | ||
518 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | 521 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) |
519 | (*it).setKeyPair( OKeyPair(key, mod) ); | 522 | (*it).setKeyPair( okey ); |
520 | else | 523 | else |
521 | (*it).setKeyPair( OKeyPair::emptyKey() ); | 524 | (*it).setKeyPair( OKeyPair::emptyKey() ); |
522 | } | 525 | } |
523 | delete m_map; m_map = 0; | 526 | delete m_map; m_map = 0; |
524 | } | 527 | } |
525 | 528 | ||
526 | /** | 529 | /** |
527 | * We will save the current configuration | 530 | * We will save the current configuration |
528 | * to the OConfig. We will change the group but restore | 531 | * to the OConfig. We will change the group but restore |
529 | * to the previous | 532 | * to the previous |
530 | */ | 533 | */ |
531 | void OKeyConfigManager::save() { | 534 | void OKeyConfigManager::save() { |
532 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | 535 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); |
533 | 536 | ||
534 | /* | 537 | /* |
535 | * Write each item | 538 | * Write each item |
536 | */ | 539 | */ |
537 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | 540 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { |
538 | /* skip empty items */ | 541 | /* skip empty items */ |
539 | if ( (*it).isEmpty() ) | 542 | if ( (*it).isEmpty() ) |
540 | continue; | 543 | continue; |
541 | OKeyPair pair = (*it).keyPair(); | 544 | OKeyPair pair = (*it).keyPair(); |
542 | OKeyPair deft = (*it).defaultKeyPair(); | 545 | OKeyPair deft = (*it).defaultKeyPair(); |
543 | /* | 546 | /* |
@@ -664,48 +667,51 @@ void OKeyConfigManager::clearBlackList() { | |||
664 | /** | 667 | /** |
665 | * Return a copy of the blackList | 668 | * Return a copy of the blackList |
666 | */ | 669 | */ |
667 | OKeyPair::List OKeyConfigManager::blackList()const { | 670 | OKeyPair::List OKeyConfigManager::blackList()const { |
668 | return m_blackKeys; | 671 | return m_blackKeys; |
669 | } | 672 | } |
670 | 673 | ||
671 | 674 | ||
672 | /** | 675 | /** |
673 | * Ask the Manager to handle KeyEvents for you. | 676 | * Ask the Manager to handle KeyEvents for you. |
674 | * All handled keys will emit a QSignal and return true | 677 | * All handled keys will emit a QSignal and return true |
675 | * that it handled the keyevent | 678 | * that it handled the keyevent |
676 | */ | 679 | */ |
677 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | 680 | void OKeyConfigManager::handleWidget( QWidget* wid ) { |
678 | wid->installEventFilter( this ); | 681 | wid->installEventFilter( this ); |
679 | } | 682 | } |
680 | 683 | ||
681 | /** | 684 | /** |
682 | * @internal | 685 | * @internal |
683 | */ | 686 | */ |
684 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | 687 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { |
685 | if ( !obj->isWidgetType() ) | 688 | if ( !obj->isWidgetType() ) |
686 | return false; | 689 | return false; |
687 | 690 | ||
691 | /* | ||
692 | * check if we care for the event | ||
693 | */ | ||
688 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && | 694 | if ( (ev->type() != QEvent::KeyPress||!testEventMask(MaskPressed)) && |
689 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) | 695 | (ev->type() != QEvent::KeyRelease||!testEventMask(MaskReleased)) ) |
690 | return false; | 696 | return false; |
691 | 697 | ||
692 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | 698 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); |
693 | OKeyConfigItem item = handleKeyEvent( key ); | 699 | OKeyConfigItem item = handleKeyEvent( key ); |
694 | 700 | ||
695 | if ( item.isEmpty() ) | 701 | if ( item.isEmpty() ) |
696 | return false; | 702 | return false; |
697 | 703 | ||
698 | QWidget *wid = static_cast<QWidget*>( obj ); | 704 | QWidget *wid = static_cast<QWidget*>( obj ); |
699 | 705 | ||
700 | if ( item.object() && !item.slot().isEmpty() ) { | 706 | if ( item.object() && !item.slot().isEmpty() ) { |
701 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | 707 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), |
702 | item.object(), item.slot().data() ); | 708 | item.object(), item.slot().data() ); |
703 | emit actionActivated(wid, key); | 709 | emit actionActivated(wid, key); |
704 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | 710 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), |
705 | item.object(), item.slot().data() ); | 711 | item.object(), item.slot().data() ); |
706 | } | 712 | } |
707 | emit actionActivated( wid, key, item ); | 713 | emit actionActivated( wid, key, item ); |
708 | 714 | ||
709 | return true; | 715 | return true; |
710 | } | 716 | } |
711 | 717 | ||