-rw-r--r-- | microkde/kdeui/kaction.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/microkde/kdeui/kaction.cpp b/microkde/kdeui/kaction.cpp index 77d36a5..d38a6d5 100644 --- a/microkde/kdeui/kaction.cpp +++ b/microkde/kdeui/kaction.cpp @@ -167,97 +167,96 @@ KAction::KAction( const QString& text, const KShortcut& cut, KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, 0, 0 ); setIconSet( pix ); } KAction::KAction( const QString& text, const QString& pix, const KShortcut& cut, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, 0, 0 ); d->setIconName( pix ); } KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut, const QObject* receiver, const char* slot, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); setIconSet( pix ); } KAction::KAction( const QString& text, const QString& pix, const KShortcut& cut, const QObject* receiver, const char* slot, QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( text, cut, receiver, slot ); d->setIconName(pix); } KAction::KAction( QObject* parent, const char* name ) : QObject( parent, name ) { initPrivate( QString::null, KShortcut(), 0, 0 ); } // KDE 4: remove end KAction::~KAction() { - kdDebug(129) << "KAction::~KAction( this = \"" << name() << "\" )" << endl; // -- ellis #ifndef KDE_NO_COMPAT if (d->m_kaccel) unplugAccel(); #endif // If actionCollection hasn't already been destructed, if ( m_parentCollection ) { m_parentCollection->take( this ); for( uint i = 0; i < d->m_kaccelList.count(); i++ ) //US d->m_kaccelList[i]->remove( name() ); qDebug("KAction::KAction~ ...1 has top be fixed"); } // Do not call unplugAll from here, as tempting as it sounds. // KAction is designed around the idea that you need to plug // _and_ to unplug it "manually". Unplugging leads to an important // slowdown when e.g. closing the window, in which case we simply // want to destroy everything asap, not to remove actions one by one // from the GUI. delete d; d = 0; } void KAction::initPrivate( const QString& text, const KShortcut& cut, const QObject* receiver, const char* slot ) { d = new KActionPrivate; d->m_cutDefault = cut; //US m_parentCollection = dynamic_cast<KActionCollection *>( parent() ); m_parentCollection = (KActionCollection *)( parent() ); kdDebug(129) << "KAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl; if ( m_parentCollection ) m_parentCollection->insert( this ); if ( receiver && slot ) connect( this, SIGNAL( activated() ), receiver, slot ); if( !cut.isNull() && qstrcmp( name(), "unnamed" ) == 0 ) kdWarning(129) << "KAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl; d->setText( text ); initShortcut( cut ); } bool KAction::isPlugged() const { @@ -390,302 +389,301 @@ void KAction::plugShortcut() for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if( d->m_kaccelList[i] == kaccel ) return; } insertKAccel( kaccel ); } } bool KAction::setShortcut( const KShortcut& cut ) { qDebug("KAction::setShortcut~ ...1 has top be fixed"); /*US bool bChanged = (d->m_cut != cut); d->m_cut = cut; KAccel* kaccel = kaccelCurrent(); bool bInsertRequired = true; // Apply new shortcut to all existing KAccel objects for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { // Check whether shortcut has already been plugged into // the current kaccel object. if( d->m_kaccelList[i] == kaccel ) bInsertRequired = false; if( bChanged ) updateKAccelShortcut( d->m_kaccelList[i] ); } // Only insert action into KAccel if it has a valid name, if( kaccel && bInsertRequired && qstrcmp( name(), "unnamed" ) ) insertKAccel( kaccel ); if( bChanged ) { // KDE 4: remove if ( d->m_kaccel ) d->m_kaccel->setShortcut( name(), cut ); // KDE 4: remove end int len = containerCount(); for( int i = 0; i < len; ++i ) updateShortcut( i ); } */ return true; } bool KAction::updateKAccelShortcut( KAccel* kaccel ) { - qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + //qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + // Check if action is permitted /*US if (kapp && !kapp->authorizeKAction(name())) return false; bool b = true; if ( !kaccel->actions().actionPtr( name() ) ) { if(!d->m_cut.isNull() ) { kdDebug(129) << "Inserting " << name() << ", " << d->text() << ", " << d->plainText() << endl; b = kaccel->insert( name(), d->plainText(), QString::null, d->m_cut, this, SLOT(slotActivated()), isShortcutConfigurable(), isEnabled() ); } } else b = kaccel->setShortcut( name(), d->m_cut ); return b; */ return true; } void KAction::insertKAccel( KAccel* kaccel ) { - qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + //qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed"); + /*US //kdDebug(129) << "KAction::insertKAccel( " << kaccel << " ): this = " << this << endl; if ( !kaccel->actions().actionPtr( name() ) ) { if( updateKAccelShortcut( kaccel ) ) { d->m_kaccelList.append( kaccel ); connect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); } } else kdWarning(129) << "KAction::insertKAccel( kaccel = " << kaccel << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis */ } void KAction::removeKAccel( KAccel* kaccel ) { - qDebug("KAction::removeKAccel~ ...1 has top be fixed"); + // qDebug("KAction::removeKAccel~ ...1 has top be fixed"); + /*US //kdDebug(129) << "KAction::removeKAccel( " << i << " ): this = " << this << endl; for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if( d->m_kaccelList[i] == kaccel ) { kaccel->remove( name() ); d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); disconnect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); break; } } */ } // KDE 4: remove void KAction::setAccel( int keyQt ) { setShortcut( KShortcut(keyQt) ); } // KDE 4: remove end void KAction::updateShortcut( int i ) { int id = itemId( i ); QWidget* w = container( i ); if ( w->inherits( "QPopupMenu" ) ) { QPopupMenu* menu = static_cast<QPopupMenu*>(w); updateShortcut( menu, id ); } else if ( w->inherits( "QMenuBar" ) ) //US static_cast<QMenuBar*>(w)->setAccel( d->m_cut.keyCodeQt(), id ); //US (QMenuBar*)(w)->setAccel( d->m_cut.keyCodeQt(), id ); - qDebug("KAction::updateShortcut( int i ) ...1 has top be fixed"); + + ; //qDebug("KAction::updateShortcut( int i ) ...1 has top be fixed"); } void KAction::updateShortcut( QPopupMenu* menu, int id ) { /*US //kdDebug(129) << "KAction::updateShortcut(): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; // If the action has a KAccel object, // show the string representation of its shortcut. if ( d->m_kaccel || d->m_kaccelList.count() ) { QString s = menu->text( id ); int i = s.find( '\t' ); if ( i >= 0 ) s.replace( i+1, s.length()-i, d->m_cut.seq(0).toString() ); else s += "\t" + d->m_cut.seq(0).toString(); menu->changeItem( id, s ); } // Otherwise insert the shortcut itself into the popup menu. else { // This is a fall-hack in case the KAction is missing a proper parent collection. // It should be removed eventually. --ellis menu->setAccel( d->m_cut.keyCodeQt(), id ); kdWarning(129) << "KAction::updateShortcut(): name = \"" << name() << "\", cut = " << d->m_cut.toStringInternal() << "; No KAccel, probably missing a parent collection." << endl; } */ - qDebug("KAction::updateShortcut( QPopupMenu* menu, int id ) ...1 has top be fixed"); + + +//qDebug("KAction::updateShortcut( QPopupMenu* menu, int id ) ...1 has top be fixed"); } const KShortcut& KAction::shortcut() const { return d->m_cut; } const KShortcut& KAction::shortcutDefault() const { return d->m_cutDefault; } QString KAction::shortcutText() const { return d->m_cut.toStringInternal(); } void KAction::setShortcutText( const QString& s ) { setShortcut( KShortcut(s) ); } int KAction::accel() const { - qDebug("KAction::accel() ...1 has top be fixed"); + // qDebug("KAction::accel() ...1 has top be fixed"); //US return d->m_cut.keyCodeQt(); return 0; } void KAction::setGroup( const QString& grp ) { d->m_group = grp; int len = containerCount(); for( int i = 0; i < len; ++i ) updateGroup( i ); } void KAction::updateGroup( int ) { // DO SOMETHING } QString KAction::group() const { return d->m_group; } bool KAction::isEnabled() const { return d->isEnabled(); } bool KAction::isShortcutConfigurable() const { return d->m_configurable; } void KAction::setToolTip( const QString& tt ) { - qDebug("KAction::setToolTip ...1 has top be fixed"); + //qDebug("KAction::setToolTip ...1 has top be fixed"); d->setToolTip( tt ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateToolTip( i ); } void KAction::updateToolTip( int i ) { - qDebug("KAction::updateToolTip ...1 has top be fixed"); + //qDebug("KAction::updateToolTip ...1 has top be fixed"); QWidget *w = container( i ); if ( w->inherits( "KToolBar" ) ) QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() ); else if ( w->inherits( "QToolBar" ) ) QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() ); } QString KAction::toolTip() const { return d->toolTip(); } int KAction::plug( QWidget *w, int index ) { //kdDebug(129) << "KAction::plug( " << w << ", " << index << " )" << endl; if (w == 0) { kdWarning(129) << "KAction::plug called with 0 argument\n"; return -1; } -#ifndef NDEBUG - KAccel* kaccel = kaccelCurrent(); - // If there is a shortcut, but no KAccel available - if( !d->m_cut.isNull() && kaccel == 0 ) { - kdWarning(129) << "KAction::plug(): has no KAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis -//US kdDebug(129) << kdBacktrace() << endl; - } -#endif + // Check if action is permitted //US if (kapp && !kapp->authorizeKAction(name())) //US return -1; plugShortcut(); if ( w->inherits("QPopupMenu") ) { QPopupMenu* menu = static_cast<QPopupMenu*>( w ); int id; // Don't insert shortcut into menu if it's already in a KAccel object. //qDebug("KAction::plug warning: real shortcuts not available yet. "); //US int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt(); int keyQt = 0; if ( d->hasIcon() ) { /*US KInstance *instance; if ( m_parentCollection ) instance = m_parentCollection->instance(); else instance = KGlobal::instance(); */ id = menu->insertItem( d->iconSet( KIcon::Small, 0/*US , instance */), d->text(), this,//dsweet SLOT( slotActivated() ), keyQt, -1, index ); } else id = menu->insertItem( d->text(), this, SLOT( slotActivated() ), //dsweet keyQt, -1, index ); // If the shortcut is already in a KAccel object, then // we need to set the menu item's shortcut text. /*US if ( d->m_kaccelList.count() || d->m_kaccel ) updateShortcut( menu, id ); */ // call setItemEnabled only if the item really should be disabled, // because that method is slow and the item is per default enabled if ( !d->isEnabled() ) menu->setItemEnabled( id, false ); if ( !d->whatsThis().isEmpty() ) menu->setWhatsThis( id, whatsThisWithIcon() ); addContainer( menu, id ); @@ -730,237 +728,239 @@ int KAction::plug( QWidget *w, int index ) if ( !d->toolTip().isEmpty() ) QToolTip::add( bar->getButton(id_), d->toolTip() ); addContainer( bar, id_ ); connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); if ( m_parentCollection ) m_parentCollection->connectHighlight( bar, this ); return containerCount() - 1; } return -1; } void KAction::unplug( QWidget *w ) { int i = findContainer( w ); if ( i == -1 ) return; int id = itemId( i ); if ( w->inherits( "QPopupMenu" ) ) { QPopupMenu *menu = static_cast<QPopupMenu *>( w ); menu->removeItem( id ); } else if ( w->inherits( "KToolBar" ) ) { KToolBar *bar = static_cast<KToolBar *>( w ); bar->removeItemDelayed( id ); } else if ( w->inherits( "QMenuBar" ) ) { QMenuBar *bar = static_cast<QMenuBar *>( w ); bar->removeItem( id ); } removeContainer( i ); if ( m_parentCollection ) m_parentCollection->disconnectHighlight( w, this ); } void KAction::plugAccel(KAccel *kacc, bool configurable) { - qDebug("KAction::plugAccel ...1 has top be fixed"); + // qDebug("KAction::plugAccel ...1 has top be fixed"); + /*US kdWarning(129) << "KAction::plugAccel(): call to deprecated action." << endl; kdDebug(129) << kdBacktrace() << endl; //kdDebug(129) << "KAction::plugAccel( kacc = " << kacc << " ): name \"" << name() << "\"" << endl; if ( d->m_kaccel ) unplugAccel(); // If the parent collection's accel ptr isn't set yet //if ( m_parentCollection && !m_parentCollection->accel() ) // m_parentCollection->setAccel( kacc ); // We can only plug this action into the given KAccel object // if it does not already contain an action with the same name. if ( !kacc->actions().actionPtr(name()) ) { d->m_kaccel = kacc; d->m_kaccel->insert(name(), d->plainText(), QString::null, KShortcut(d->m_cut), this, SLOT(slotActivated()), configurable, isEnabled()); connect(d->m_kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed())); //connect(d->m_kaccel, SIGNAL(keycodeChanged()), this, SLOT(slotKeycodeChanged())); } else kdWarning(129) << "KAction::plugAccel( kacc = " << kacc << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis */ } void KAction::unplugAccel() { - qDebug("KAction::unplugAccel ...1 has top be fixed"); + // qDebug("KAction::unplugAccel ...1 has top be fixed"); /*US //kdDebug(129) << "KAction::unplugAccel() " << this << " " << name() << endl; if ( d->m_kaccel ) { d->m_kaccel->remove(name()); d->m_kaccel = 0; } */ } void KAction::plugMainWindowAccel( QWidget *w ) { - qDebug("KAction::plugMainWindowAccel ...1 has top be fixed"); + // qDebug("KAction::plugMainWindowAccel ...1 has top be fixed"); + /*US // Note: topLevelWidget() stops too early, we can't use it. QWidget * tl = w; QWidget * n; while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store tl = n; KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow if (mw) plugAccel( mw->accel() ); else kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl; */ } void KAction::setEnabled(bool enable) { //kdDebug(129) << "KAction::setEnabled( " << enable << " ): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl; if ( enable == d->isEnabled() ) return; // KDE 4: remove //US if (d->m_kaccel) //US d->m_kaccel->setEnabled(name(), enable); // KDE 4: remove end //US for ( uint i = 0; i < d->m_kaccelList.count(); i++ ) //US d->m_kaccelList[i]->setEnabled( name(), enable ); d->setEnabled( enable ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateEnabled( i ); emit enabled( d->isEnabled() ); } void KAction::updateEnabled( int i ) { QWidget *w = container( i ); if ( w->inherits("QPopupMenu") ) static_cast<QPopupMenu*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); else if ( w->inherits("QMenuBar") ) static_cast<QMenuBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); else if ( w->inherits( "KToolBar" ) ) { static_cast<KToolBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() ); } } void KAction::setShortcutConfigurable( bool b ) { d->m_configurable = b; } void KAction::setText( const QString& text ) { /*US // KDE 4: remove if (d->m_kaccel) { KAccelAction* pAction = d->m_kaccel->actions().actionPtr(name()); if (pAction) pAction->setLabel( text ); } // KDE 4: remove end for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { KAccelAction* pAction = d->m_kaccelList[i]->actions().actionPtr(name()); if (pAction) pAction->setLabel( text ); } */ d->setText( text ); int len = containerCount(); for( int i = 0; i < len; ++i ) updateText( i ); } void KAction::updateText( int i ) { QWidget *w = container( i ); if ( w->inherits( "QPopupMenu" ) ) { int id = itemId( i ); static_cast<QPopupMenu*>(w)->changeItem( id, d->text() ); updateShortcut( static_cast<QPopupMenu*>(w), id ); } else if ( w->inherits( "QMenuBar" ) ) static_cast<QMenuBar*>(w)->changeItem( itemId( i ), d->text() ); else if ( w->inherits( "KToolBar" ) ) { - qDebug("KAction::updateText ...3 has top be fixed"); + //qDebug("KAction::updateText ...3 has top be fixed"); QWidget *button = static_cast<KToolBar *>(w)->getWidget( itemId( i ) ); if ( button->inherits( "KToolBarButton" ) ) static_cast<KToolBarButton *>(button)->setText( d->plainText() ); } } QString KAction::text() const { return d->text(); } QString KAction::plainText() const { return d->plainText( ); } void KAction::setIcon( const QString &icon ) { d->setIconName( icon ); // now handle any toolbars int len = containerCount(); for ( int i = 0; i < len; ++i ) updateIcon( i ); } void KAction::updateIcon( int id ) { QWidget* w = container( id ); if ( w->inherits( "QPopupMenu" ) ) { int itemId_ = itemId( id ); static_cast<QPopupMenu*>(w)->changeItem( itemId_, d->iconSet( KIcon::Small ), d->text() ); updateShortcut( static_cast<QPopupMenu*>(w), itemId_ ); } else if ( w->inherits( "QMenuBar" ) ) static_cast<QMenuBar*>(w)->changeItem( itemId( id ), d->iconSet( KIcon::Small ), d->text() ); else if ( w->inherits( "KToolBar" ) ) static_cast<KToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() ); else if ( w->inherits( "QToolBar" ) ) { qDebug("KAction::updateIcon has top be fixed"); //US static_cast<QToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() ); } } QString KAction::icon() const @@ -1073,97 +1073,97 @@ QPopupMenu* KAction::popupMenu( int index ) const QWidget* KAction::representative( int index ) const { return d->m_containers[ index ].m_representative; } int KAction::itemId( int index ) const { return d->m_containers[ index ].m_id; } int KAction::containerCount() const { return d->m_containers.count(); } uint KAction::kaccelCount() const { return d->m_kaccelList.count(); } void KAction::addContainer( QWidget* c, int id ) { KActionPrivate::Container p; p.m_container = c; p.m_id = id; d->m_containers.append( p ); } void KAction::addContainer( QWidget* c, QWidget* w ) { KActionPrivate::Container p; p.m_container = c; p.m_representative = w; d->m_containers.append( p ); } void KAction::activate() { slotActivated(); } void KAction::slotActivated() { emit activated(); } void KAction::slotDestroyed() { - kdDebug(129) << "KAction::slotDestroyed(): this = " << this << ", name = \"" << name() << "\", sender = " << sender() << endl; + const QObject* o = sender(); /* // KDE 4: remove if ( o == d->m_kaccel ) { d->m_kaccel = 0; return; } // KDE 4: remove end for( uint i = 0; i < d->m_kaccelList.count(); i++ ) { if ( o == d->m_kaccelList[i] ) { disconnect( d->m_kaccelList[i], SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); d->m_kaccelList.remove( d->m_kaccelList.at( i ) ); return; } } */ int i; do { i = findContainer( static_cast<const QWidget*>( o ) ); if ( i != -1 ) removeContainer( i ); } while ( i != -1 ); } int KAction::findContainer( const QWidget* widget ) const { int pos = 0; QValueList<KActionPrivate::Container>::ConstIterator it = d->m_containers.begin(); while( it != d->m_containers.end() ) { if ( (*it).m_representative == widget || (*it).m_container == widget ) return pos; ++it; ++pos; } return -1; } |