tdeactioncollection.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> 00003 (C) 1999 Simon Hausmann <hausmann@kde.org> 00004 (C) 2000 Nicolas Hadacek <haadcek@kde.org> 00005 (C) 2000 Kurt Granroth <granroth@kde.org> 00006 (C) 2000 Michael Koch <koch@kde.org> 00007 (C) 2001 Holger Freyther <freyther@kde.org> 00008 (C) 2002 Ellis Whitehead <ellis@kde.org> 00009 (C) 2002 Joseph Wenninger <jowenn@kde.org> 00010 00011 This library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public 00013 License version 2 as published by the Free Software Foundation. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Library General Public License for more details. 00019 00020 You should have received a copy of the GNU Library General Public License 00021 along with this library; see the file COPYING.LIB. If not, write to 00022 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00023 Boston, MA 02110-1301, USA. 00024 */ 00025 00026 #include "tdeactioncollection.h" 00027 #include "tdeactionshortcutlist.h" 00028 #include "tdetoolbar.h" 00029 #include "kxmlguifactory.h" 00030 #include "kxmlguiclient.h" 00031 00032 #include <tdeaccel.h> 00033 #include <tdeaccelbase.h> 00034 #include <tdeapplication.h> 00035 #include <kdebug.h> 00036 00037 #include <tqpopupmenu.h> 00038 #include <tqptrdict.h> 00039 #include <tqvariant.h> 00040 00041 class TDEActionCollection::TDEActionCollectionPrivate 00042 { 00043 public: 00044 TDEActionCollectionPrivate() 00045 { 00046 m_instance = 0; 00047 //m_bOneTDEAccelOnly = false; 00048 //m_iWidgetCurrent = 0; 00049 m_bAutoConnectShortcuts = true; 00050 m_widget = 0; 00051 m_tdeaccel = m_builderTDEAccel = 0; 00052 m_dctHighlightContainers.setAutoDelete( true ); 00053 m_highlight = false; 00054 m_currentHighlightAction = 0; 00055 m_statusCleared = true; 00056 m_parentGUIClient = 0L; 00057 } 00058 00059 TDEInstance *m_instance; 00060 TQString m_sXMLFile; 00061 bool m_bAutoConnectShortcuts; 00062 //bool m_bOneTDEAccelOnly; 00063 //int m_iWidgetCurrent; 00064 //TQValueList<TQWidget*> m_widgetList; 00065 //TQValueList<TDEAccel*> m_tdeaccelList; 00066 TQValueList<TDEActionCollection*> m_docList; 00067 TQWidget *m_widget; 00068 TDEAccel *m_tdeaccel; 00069 TDEAccel *m_builderTDEAccel; 00070 00071 TQAsciiDict<TDEAction> m_actionDict; 00072 TQPtrDict< TQPtrList<TDEAction> > m_dctHighlightContainers; 00073 bool m_highlight; 00074 TDEAction *m_currentHighlightAction; 00075 bool m_statusCleared; 00076 const KXMLGUIClient *m_parentGUIClient; 00077 }; 00078 00079 TDEActionCollection::TDEActionCollection( TQWidget *parent, const char *name, 00080 TDEInstance *instance ) 00081 : TQObject( parent, name ) 00082 { 00083 kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis 00084 d = new TDEActionCollectionPrivate; 00085 if( parent ) 00086 setWidget( parent ); 00087 //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0); 00088 setInstance( instance ); 00089 } 00090 00091 00092 TDEActionCollection::TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name, 00093 TDEInstance *instance ) 00094 : TQObject( parent, name ) 00095 { 00096 kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis 00097 d = new TDEActionCollectionPrivate; 00098 if( watch ) 00099 setWidget( watch ); 00100 //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0); 00101 setInstance( instance ); 00102 } 00103 00104 #ifndef KDE_NO_COMPAT 00105 // KDE 4: remove 00106 TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, 00107 TDEInstance *instance ) 00108 : TQObject( parent, name ) 00109 { 00110 kdWarning(129) << "TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, TDEInstance *instance )" << endl; //ellis 00111 kdDebug(129) << kdBacktrace() << endl; 00112 d = new TDEActionCollectionPrivate; 00113 TQWidget* w = tqt_dynamic_cast<TQWidget*>( parent ); 00114 if( w ) 00115 setWidget( w ); 00116 //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0); 00117 setInstance( instance ); 00118 } 00119 00120 TDEActionCollection::TDEActionCollection( const TDEActionCollection © ) 00121 : TQObject() 00122 { 00123 kdWarning(129) << "TDEActionCollection::TDEActionCollection( const TDEActionCollection & ): function is severely deprecated." << endl; 00124 d = new TDEActionCollectionPrivate; 00125 *this = copy; 00126 } 00127 #endif // KDE 4: remove end 00128 00129 TDEActionCollection::TDEActionCollection( const char *name, const KXMLGUIClient *parent ) 00130 : TQObject( 0L, name ) 00131 { 00132 d = new TDEActionCollectionPrivate; 00133 d->m_parentGUIClient=parent; 00134 d->m_instance=parent->instance(); 00135 } 00136 00137 00138 TDEActionCollection::~TDEActionCollection() 00139 { 00140 kdDebug(129) << "TDEActionCollection::~TDEActionCollection(): this = " << this << endl; 00141 for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) { 00142 TDEAction* pAction = it.current(); 00143 if ( pAction->m_parentCollection == this ) 00144 pAction->m_parentCollection = 0L; 00145 } 00146 00147 delete d->m_tdeaccel; 00148 delete d->m_builderTDEAccel; 00149 delete d; d = 0; 00150 } 00151 00152 void TDEActionCollection::setWidget( TQWidget* w ) 00153 { 00154 //if ( d->m_actionDict.count() > 0 ) { 00155 // kdError(129) << "TDEActionCollection::setWidget(): must be called before any actions are added to collection!" << endl; 00156 // kdDebug(129) << kdBacktrace() << endl; 00157 //} 00158 //else 00159 if ( !d->m_widget ) { 00160 d->m_widget = w; 00161 d->m_tdeaccel = new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ); 00162 } 00163 else if ( d->m_widget != w ) 00164 kdWarning(129) << "TDEActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl; 00165 } 00166 00167 void TDEActionCollection::setAutoConnectShortcuts( bool b ) 00168 { 00169 d->m_bAutoConnectShortcuts = b; 00170 } 00171 00172 bool TDEActionCollection::isAutoConnectShortcuts() 00173 { 00174 return d->m_bAutoConnectShortcuts; 00175 } 00176 00177 bool TDEActionCollection::addDocCollection( TDEActionCollection* pDoc ) 00178 { 00179 d->m_docList.append( pDoc ); 00180 return true; 00181 } 00182 00183 void TDEActionCollection::beginXMLPlug( TQWidget *widget ) 00184 { 00185 kdDebug(129) << "TDEActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderTDEAccel = " << d->m_builderTDEAccel << endl; 00186 00187 if( widget && !d->m_builderTDEAccel ) { 00188 d->m_builderTDEAccel = new TDEAccel( widget, this, "TDEActionCollection-BuilderTDEAccel" ); 00189 } 00190 } 00191 00192 void TDEActionCollection::endXMLPlug() 00193 { 00194 kdDebug(129) << "TDEActionCollection::endXMLPlug(): this = " << this << endl; 00195 //s_tdeaccelXML = 0; 00196 } 00197 00198 void TDEActionCollection::prepareXMLUnplug() 00199 { 00200 kdDebug(129) << "TDEActionCollection::prepareXMLUnplug(): this = " << this << endl; 00201 unplugShortcuts( d->m_tdeaccel ); 00202 00203 if( d->m_builderTDEAccel ) { 00204 unplugShortcuts( d->m_builderTDEAccel ); 00205 delete d->m_builderTDEAccel; 00206 d->m_builderTDEAccel = 0; 00207 } 00208 } 00209 00210 void TDEActionCollection::unplugShortcuts( TDEAccel* tdeaccel ) 00211 { 00212 for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) { 00213 TDEAction* pAction = it.current(); 00214 pAction->removeTDEAccel( tdeaccel ); 00215 } 00216 00217 for( uint i = 0; i < d->m_docList.count(); i++ ) 00218 d->m_docList[i]->unplugShortcuts( tdeaccel ); 00219 } 00220 00221 /*void TDEActionCollection::addWidget( TQWidget* w ) 00222 { 00223 if( !d->m_bOneTDEAccelOnly ) { 00224 kdDebug(129) << "TDEActionCollection::addWidget( " << w << " ): this = " << this << endl; 00225 for( uint i = 0; i < d->m_widgetList.count(); i++ ) { 00226 if( d->m_widgetList[i] == w ) { 00227 d->m_iWidgetCurrent = i; 00228 return; 00229 } 00230 } 00231 d->m_iWidgetCurrent = d->m_widgetList.count(); 00232 d->m_widgetList.append( w ); 00233 d->m_tdeaccelList.append( new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ) ); 00234 } 00235 } 00236 00237 void TDEActionCollection::removeWidget( TQWidget* w ) 00238 { 00239 if( !d->m_bOneTDEAccelOnly ) { 00240 kdDebug(129) << "TDEActionCollection::removeWidget( " << w << " ): this = " << this << endl; 00241 for( uint i = 0; i < d->m_widgetList.count(); i++ ) { 00242 if( d->m_widgetList[i] == w ) { 00243 // Remove TDEAccel object from children. 00244 TDEAccel* pTDEAccel = d->m_tdeaccelList[i]; 00245 for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) { 00246 TDEAction* pAction = it.current(); 00247 if ( pAction->m_parentCollection == this ) { 00248 pAction->removeTDEAccel( pTDEAccel ); 00249 } 00250 } 00251 delete pTDEAccel; 00252 00253 d->m_widgetList.remove( d->m_widgetList.at( i ) ); 00254 d->m_tdeaccelList.remove( d->m_tdeaccelList.at( i ) ); 00255 00256 if( d->m_iWidgetCurrent == (int)i ) 00257 d->m_iWidgetCurrent = -1; 00258 else if( d->m_iWidgetCurrent > (int)i ) 00259 d->m_iWidgetCurrent--; 00260 return; 00261 } 00262 } 00263 kdWarning(129) << "TDEActionCollection::removeWidget( " << w << " ): widget not in list." << endl; 00264 } 00265 } 00266 00267 bool TDEActionCollection::ownsTDEAccel() const 00268 { 00269 return d->m_bOneTDEAccelOnly; 00270 } 00271 00272 uint TDEActionCollection::widgetCount() const 00273 { 00274 return d->m_widgetList.count(); 00275 } 00276 00277 const TDEAccel* TDEActionCollection::widgetTDEAccel( uint i ) const 00278 { 00279 return d->m_tdeaccelList[i]; 00280 }*/ 00281 00282 TDEAccel* TDEActionCollection::tdeaccel() 00283 { 00284 //if( d->m_tdeaccelList.count() > 0 ) 00285 // return d->m_tdeaccelList[d->m_iWidgetCurrent]; 00286 //else 00287 // return 0; 00288 return d->m_tdeaccel; 00289 } 00290 00291 const TDEAccel* TDEActionCollection::tdeaccel() const 00292 { 00293 //if( d->m_tdeaccelList.count() > 0 ) 00294 // return d->m_tdeaccelList[d->m_iWidgetCurrent]; 00295 //else 00296 // return 0; 00297 return d->m_tdeaccel; 00298 } 00299 00300 // Return the key to use in d->m_actionDict for the given action. 00301 // Usually name(), except when unnamed. 00302 static const char* actionDictKey( TDEAction* action, char* buffer ) 00303 { 00304 const char* name = action->name(); 00305 if( !qstrcmp( name, "unnamed" ) ) 00306 { 00307 sprintf(buffer, "unnamed-%p", (void *)action); 00308 return buffer; 00309 } 00310 return name; 00311 } 00312 00313 void TDEActionCollection::_insert( TDEAction* action ) 00314 { 00315 char unnamed_name[100]; 00316 const char *name = actionDictKey( action, unnamed_name ); 00317 TDEAction *a = d->m_actionDict[ name ]; 00318 if ( a == action ) 00319 return; 00320 00321 d->m_actionDict.insert( name, action ); 00322 00323 emit inserted( action ); 00324 } 00325 00326 void TDEActionCollection::_remove( TDEAction* action ) 00327 { 00328 char unnamed_name[100]; 00329 const char *name = actionDictKey( action, unnamed_name ); 00330 00331 TDEAction *a = d->m_actionDict.take( name ); 00332 if ( !a || a != action ) 00333 return; 00334 00335 emit removed( action ); 00336 // note that we delete the action without its parent collection set to 0. 00337 // This triggers tdeaccel::remove, to remove any shortcut. 00338 delete a; 00339 } 00340 00341 TDEAction* TDEActionCollection::_take( TDEAction* action ) 00342 { 00343 char unnamed_name[100]; 00344 const char *name = actionDictKey( action, unnamed_name ); 00345 00346 TDEAction *a = d->m_actionDict.take( name ); 00347 if ( !a || a != action ) 00348 return 0; 00349 00350 if ( a->m_parentCollection == this ) 00351 a->m_parentCollection = 0; 00352 00353 emit removed( action ); 00354 00355 return a; 00356 } 00357 00358 void TDEActionCollection::_clear() 00359 { 00360 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00361 while ( it.current() ) 00362 _remove( it.current() ); 00363 } 00364 00365 void TDEActionCollection::insert( TDEAction* action ) { _insert( action ); } 00366 void TDEActionCollection::remove( TDEAction* action ) { _remove( action ); } 00367 TDEAction* TDEActionCollection::take( TDEAction* action ) { return _take( action ); } 00368 void TDEActionCollection::clear() { _clear(); } 00369 TDEAccel* TDEActionCollection::accel() { return tdeaccel(); } 00370 const TDEAccel* TDEActionCollection::accel() const { return tdeaccel(); } 00371 TDEAccel* TDEActionCollection::builderTDEAccel() const { return d->m_builderTDEAccel; } 00372 00373 TDEAction* TDEActionCollection::action( const char* name, const char* classname ) const 00374 { 00375 TDEAction* pAction = 0; 00376 00377 if ( !classname && name ) 00378 pAction = d->m_actionDict[ name ]; 00379 00380 else { 00381 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00382 for( ; it.current(); ++it ) 00383 { 00384 if ( ( !name || !strcmp( it.current()->name(), name ) ) && 00385 ( !classname || !strcmp( it.current()->className(), classname ) ) ) { 00386 pAction = it.current(); 00387 break; 00388 } 00389 } 00390 } 00391 00392 if( !pAction ) { 00393 for( uint i = 0; i < d->m_docList.count() && !pAction; i++ ) 00394 pAction = d->m_docList[i]->action( name, classname ); 00395 } 00396 00397 return pAction; 00398 } 00399 00400 TDEAction* TDEActionCollection::action( int index ) const 00401 { 00402 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00403 it += index; 00404 return it.current(); 00405 // return d->m_actions.at( index ); 00406 } 00407 00408 bool TDEActionCollection::readShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) 00409 { 00410 return TDEActionShortcutList(this).readSettings( sConfigGroup, pConfig ); 00411 } 00412 00413 bool TDEActionCollection::writeShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) const 00414 { 00415 return TDEActionShortcutList((TDEActionCollection*)this).writeSettings( sConfigGroup, pConfig ); 00416 } 00417 00418 uint TDEActionCollection::count() const 00419 { 00420 return d->m_actionDict.count(); 00421 } 00422 00423 TQStringList TDEActionCollection::groups() const 00424 { 00425 TQStringList lst; 00426 00427 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00428 for( ; it.current(); ++it ) 00429 if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) ) 00430 lst.append( it.current()->group() ); 00431 00432 return lst; 00433 } 00434 00435 TDEActionPtrList TDEActionCollection::actions( const TQString& group ) const 00436 { 00437 TDEActionPtrList lst; 00438 00439 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00440 for( ; it.current(); ++it ) 00441 if ( it.current()->group() == group ) 00442 lst.append( it.current() ); 00443 else if ( it.current()->group().isEmpty() && group.isEmpty() ) 00444 lst.append( it.current() ); 00445 00446 return lst; 00447 } 00448 00449 TDEActionPtrList TDEActionCollection::actions() const 00450 { 00451 TDEActionPtrList lst; 00452 00453 TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); 00454 for( ; it.current(); ++it ) 00455 lst.append( it.current() ); 00456 00457 return lst; 00458 } 00459 00460 void TDEActionCollection::setInstance( TDEInstance *instance ) 00461 { 00462 if ( instance ) 00463 d->m_instance = instance; 00464 else 00465 d->m_instance = TDEGlobal::instance(); 00466 } 00467 00468 TDEInstance *TDEActionCollection::instance() const 00469 { 00470 return d->m_instance; 00471 } 00472 00473 void TDEActionCollection::setXMLFile( const TQString& sXMLFile ) 00474 { 00475 d->m_sXMLFile = sXMLFile; 00476 } 00477 00478 const TQString& TDEActionCollection::xmlFile() const 00479 { 00480 return d->m_sXMLFile; 00481 } 00482 00483 void TDEActionCollection::setHighlightingEnabled( bool enable ) 00484 { 00485 d->m_highlight = enable; 00486 } 00487 00488 bool TDEActionCollection::highlightingEnabled() const 00489 { 00490 return d->m_highlight; 00491 } 00492 00493 void TDEActionCollection::connectHighlight( TQWidget *container, TDEAction *action ) 00494 { 00495 if ( !d->m_highlight ) 00496 return; 00497 00498 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ]; 00499 00500 if ( !actionList ) 00501 { 00502 actionList = new TQPtrList<TDEAction>; 00503 00504 if ( ::tqqt_cast<TQPopupMenu *>( container ) ) 00505 { 00506 connect( container, TQT_SIGNAL( highlighted( int ) ), 00507 this, TQT_SLOT( slotMenuItemHighlighted( int ) ) ); 00508 connect( container, TQT_SIGNAL( aboutToHide() ), 00509 this, TQT_SLOT( slotMenuAboutToHide() ) ); 00510 } 00511 else if ( ::tqqt_cast<TDEToolBar *>( container ) ) 00512 { 00513 connect( container, TQT_SIGNAL( highlighted( int, bool ) ), 00514 this, TQT_SLOT( slotToolBarButtonHighlighted( int, bool ) ) ); 00515 } 00516 00517 connect( container, TQT_SIGNAL( destroyed() ), 00518 this, TQT_SLOT( slotDestroyed() ) ); 00519 00520 d->m_dctHighlightContainers.insert( container, actionList ); 00521 } 00522 00523 actionList->append( action ); 00524 } 00525 00526 void TDEActionCollection::disconnectHighlight( TQWidget *container, TDEAction *action ) 00527 { 00528 if ( !d->m_highlight ) 00529 return; 00530 00531 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ]; 00532 00533 if ( !actionList ) 00534 return; 00535 00536 actionList->removeRef( action ); 00537 00538 if ( actionList->isEmpty() ) 00539 d->m_dctHighlightContainers.remove( container ); 00540 } 00541 00542 void TDEActionCollection::slotMenuItemHighlighted( int id ) 00543 { 00544 if ( !d->m_highlight ) 00545 return; 00546 00547 if ( d->m_currentHighlightAction ) 00548 emit actionHighlighted( d->m_currentHighlightAction, false ); 00549 00550 TQWidget *container = const_cast<TQWidget*>(TQT_TQWIDGET_CONST( sender() )); 00551 00552 d->m_currentHighlightAction = findAction( container, id ); 00553 00554 if ( !d->m_currentHighlightAction ) 00555 { 00556 if ( !d->m_statusCleared ) 00557 emit clearStatusText(); 00558 d->m_statusCleared = true; 00559 return; 00560 } 00561 00562 d->m_statusCleared = false; 00563 emit actionHighlighted( d->m_currentHighlightAction ); 00564 emit actionHighlighted( d->m_currentHighlightAction, true ); 00565 emit actionStatusText( d->m_currentHighlightAction->toolTip() ); 00566 } 00567 00568 void TDEActionCollection::slotMenuAboutToHide() 00569 { 00570 if ( d->m_currentHighlightAction ) 00571 emit actionHighlighted( d->m_currentHighlightAction, false ); 00572 d->m_currentHighlightAction = 0; 00573 00574 if ( !d->m_statusCleared ) 00575 emit clearStatusText(); 00576 d->m_statusCleared = true; 00577 } 00578 00579 void TDEActionCollection::slotToolBarButtonHighlighted( int id, bool highlight ) 00580 { 00581 if ( !d->m_highlight ) 00582 return; 00583 00584 TQWidget *container = const_cast<TQWidget*>(TQT_TQWIDGET_CONST( sender() )); 00585 00586 TDEAction *action = findAction( container, id ); 00587 00588 if ( !action ) 00589 { 00590 d->m_currentHighlightAction = 0; 00591 // use tooltip groups for toolbar status text stuff instead (Simon) 00592 // emit clearStatusText(); 00593 return; 00594 } 00595 00596 emit actionHighlighted( action, highlight ); 00597 00598 if ( highlight ) 00599 d->m_currentHighlightAction = action; 00600 else 00601 { 00602 d->m_currentHighlightAction = 0; 00603 // emit clearStatusText(); 00604 } 00605 } 00606 00607 void TDEActionCollection::slotDestroyed() 00608 { 00609 d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<TQObject*>(TQT_TQOBJECT_CONST(sender())) ) ); 00610 } 00611 00612 TDEAction *TDEActionCollection::findAction( TQWidget *container, int id ) 00613 { 00614 TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ]; 00615 00616 if ( !actionList ) 00617 return 0; 00618 00619 TQPtrListIterator<TDEAction> it( *actionList ); 00620 for (; it.current(); ++it ) 00621 if ( it.current()->isPlugged( container, id ) ) 00622 return it.current(); 00623 00624 return 0; 00625 } 00626 00627 const KXMLGUIClient *TDEActionCollection::parentGUIClient() const 00628 { 00629 return d->m_parentGUIClient; 00630 } 00631 00632 #ifndef KDE_NO_COMPAT 00633 // KDE 4: remove 00634 TDEActionCollection TDEActionCollection::operator+(const TDEActionCollection &c ) const 00635 { 00636 kdWarning(129) << "TDEActionCollection::operator+(): function is severely deprecated." << endl; 00637 TDEActionCollection ret( *this ); 00638 00639 TQValueList<TDEAction *> actions = c.actions(); 00640 TQValueList<TDEAction *>::ConstIterator it = actions.begin(); 00641 TQValueList<TDEAction *>::ConstIterator end = actions.end(); 00642 for (; it != end; ++it ) 00643 ret.insert( *it ); 00644 00645 return ret; 00646 } 00647 00648 TDEActionCollection &TDEActionCollection::operator=( const TDEActionCollection © ) 00649 { 00650 kdWarning(129) << "TDEActionCollection::operator=(): function is severely deprecated." << endl; 00651 //d->m_bOneTDEAccelOnly = copy.d->m_bOneTDEAccelOnly; 00652 //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent; 00653 //d->m_widgetList = copy.d->m_widgetList; 00654 //d->m_tdeaccelList = copy.d->m_tdeaccelList; 00655 d->m_widget = copy.d->m_widget; 00656 d->m_tdeaccel = copy.d->m_tdeaccel; 00657 d->m_actionDict = copy.d->m_actionDict; 00658 setInstance( copy.instance() ); 00659 return *this; 00660 } 00661 00662 TDEActionCollection &TDEActionCollection::operator+=( const TDEActionCollection &c ) 00663 { 00664 kdWarning(129) << "TDEActionCollection::operator+=(): function is severely deprecated." << endl; 00665 TQAsciiDictIterator<TDEAction> it(c.d->m_actionDict); 00666 for ( ; it.current(); ++it ) 00667 insert( it.current() ); 00668 00669 return *this; 00670 } 00671 #endif // KDE 4: remove end 00672 00673 //--------------------------------------------------------------------- 00674 // TDEActionShortcutList 00675 //--------------------------------------------------------------------- 00676 00677 TDEActionShortcutList::TDEActionShortcutList( TDEActionCollection* pColl ) 00678 : m_actions( *pColl ) 00679 { } 00680 TDEActionShortcutList::~TDEActionShortcutList() 00681 { } 00682 uint TDEActionShortcutList::count() const 00683 { return m_actions.count(); } 00684 TQString TDEActionShortcutList::name( uint i ) const 00685 { return m_actions.action(i)->name(); } 00686 TQString TDEActionShortcutList::label( uint i ) const 00687 { return m_actions.action(i)->text(); } 00688 TQString TDEActionShortcutList::whatsThis( uint i ) const 00689 { return m_actions.action(i)->whatsThis(); } 00690 const TDEShortcut& TDEActionShortcutList::shortcut( uint i ) const 00691 { return m_actions.action(i)->shortcut(); } 00692 const TDEShortcut& TDEActionShortcutList::shortcutDefault( uint i ) const 00693 { return m_actions.action(i)->shortcutDefault(); } 00694 bool TDEActionShortcutList::isConfigurable( uint i ) const 00695 { return m_actions.action(i)->isShortcutConfigurable(); } 00696 bool TDEActionShortcutList::setShortcut( uint i, const TDEShortcut& cut ) 00697 { return m_actions.action(i)->setShortcut( cut ); } 00698 const TDEInstance* TDEActionShortcutList::instance() const 00699 { return m_actions.instance(); } 00700 TQVariant TDEActionShortcutList::getOther( Other, uint ) const 00701 { return TQVariant(); } 00702 bool TDEActionShortcutList::setOther( Other, uint, TQVariant ) 00703 { return false; } 00704 const TDEAction *TDEActionShortcutList::action( uint i) const 00705 { return m_actions.action(i); } 00706 00707 bool TDEActionShortcutList::save() const 00708 { 00709 const KXMLGUIClient* guiClient=m_actions.parentGUIClient(); 00710 const TQString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile(); 00711 kdDebug(129) << "TDEActionShortcutList::save(): xmlFile = " << xmlFile << endl; 00712 00713 if( m_actions.xmlFile().isEmpty() ) 00714 return writeSettings(); 00715 00716 TQString attrShortcut = TQString::fromLatin1("shortcut"); 00717 TQString attrAccel = TQString::fromLatin1("accel"); // Depricated attribute 00718 00719 // Read XML file 00720 TQString sXml( KXMLGUIFactory::readConfigFile( xmlFile, false, instance() ) ); 00721 TQDomDocument doc; 00722 doc.setContent( sXml ); 00723 00724 // Process XML data 00725 00726 // Get hold of ActionProperties tag 00727 TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc ); 00728 00729 // now, iterate through our actions 00730 uint nSize = count(); 00731 for( uint i = 0; i < nSize; i++ ) { 00732 const TQString& sName = name(i); 00733 00734 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i)); 00735 //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl; 00736 00737 // now see if this element already exists 00738 // and create it if necessary (unless bSameAsDefault) 00739 TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, sName, !bSameAsDefault ); 00740 if ( act_elem.isNull() ) 00741 continue; 00742 00743 act_elem.removeAttribute( attrAccel ); 00744 if( bSameAsDefault ) { 00745 act_elem.removeAttribute( attrShortcut ); 00746 //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl; 00747 if( act_elem.attributes().count() == 1 ) 00748 elem.removeChild( act_elem ); 00749 } else { 00750 act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() ); 00751 } 00752 } 00753 00754 // Write back to XML file 00755 return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(), instance() ); 00756 } 00757 00758 //--------------------------------------------------------------------- 00759 // TDEActionPtrShortcutList 00760 //--------------------------------------------------------------------- 00761 00762 TDEActionPtrShortcutList::TDEActionPtrShortcutList( TDEActionPtrList& list ) 00763 : m_actions( list ) 00764 { } 00765 TDEActionPtrShortcutList::~TDEActionPtrShortcutList() 00766 { } 00767 uint TDEActionPtrShortcutList::count() const 00768 { return m_actions.count(); } 00769 TQString TDEActionPtrShortcutList::name( uint i ) const 00770 { return m_actions[i]->name(); } 00771 TQString TDEActionPtrShortcutList::label( uint i ) const 00772 { return m_actions[i]->text(); } 00773 TQString TDEActionPtrShortcutList::whatsThis( uint i ) const 00774 { return m_actions[i]->whatsThis(); } 00775 const TDEShortcut& TDEActionPtrShortcutList::shortcut( uint i ) const 00776 { return m_actions[i]->shortcut(); } 00777 const TDEShortcut& TDEActionPtrShortcutList::shortcutDefault( uint i ) const 00778 { return m_actions[i]->shortcutDefault(); } 00779 bool TDEActionPtrShortcutList::isConfigurable( uint i ) const 00780 { return m_actions[i]->isShortcutConfigurable(); } 00781 bool TDEActionPtrShortcutList::setShortcut( uint i, const TDEShortcut& cut ) 00782 { return m_actions[i]->setShortcut( cut ); } 00783 TQVariant TDEActionPtrShortcutList::getOther( Other, uint ) const 00784 { return TQVariant(); } 00785 bool TDEActionPtrShortcutList::setOther( Other, uint, TQVariant ) 00786 { return false; } 00787 bool TDEActionPtrShortcutList::save() const 00788 { return false; } 00789 00790 void TDEActionShortcutList::virtual_hook( int id, void* data ) 00791 { TDEShortcutList::virtual_hook( id, data ); } 00792 00793 void TDEActionPtrShortcutList::virtual_hook( int id, void* data ) 00794 { TDEShortcutList::virtual_hook( id, data ); } 00795 00796 void TDEActionCollection::virtual_hook( int, void* ) 00797 { /*BASE::virtual_hook( id, data );*/ } 00798 00799 /* vim: et sw=2 ts=2 00800 */ 00801 00802 #include "tdeactioncollection.moc"