• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
tdeactioncollection.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3  (C) 1999 Simon Hausmann <hausmann@kde.org>
4  (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5  (C) 2000 Kurt Granroth <granroth@kde.org>
6  (C) 2000 Michael Koch <koch@kde.org>
7  (C) 2001 Holger Freyther <freyther@kde.org>
8  (C) 2002 Ellis Whitehead <ellis@kde.org>
9  (C) 2002 Joseph Wenninger <jowenn@kde.org>
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License version 2 as published by the Free Software Foundation.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
25 
26 #include "tdeactioncollection.h"
27 #include "tdeactionshortcutlist.h"
28 #include "tdetoolbar.h"
29 #include "kxmlguifactory.h"
30 #include "kxmlguiclient.h"
31 
32 #include <tdeaccel.h>
33 #include <tdeaccelbase.h>
34 #include <tdeapplication.h>
35 #include <kdebug.h>
36 
37 #include <tqpopupmenu.h>
38 #include <tqptrdict.h>
39 #include <tqvariant.h>
40 
41 class TDEActionCollection::TDEActionCollectionPrivate
42 {
43 public:
44  TDEActionCollectionPrivate()
45  {
46  m_instance = 0;
47  //m_bOneTDEAccelOnly = false;
48  //m_iWidgetCurrent = 0;
49  m_bAutoConnectShortcuts = true;
50  m_widget = 0;
51  m_tdeaccel = m_builderTDEAccel = 0;
52  m_dctHighlightContainers.setAutoDelete( true );
53  m_highlight = false;
54  m_currentHighlightAction = 0;
55  m_statusCleared = true;
56  m_parentGUIClient = 0L;
57  }
58 
59  TDEInstance *m_instance;
60  TQString m_sXMLFile;
61  bool m_bAutoConnectShortcuts;
62  //bool m_bOneTDEAccelOnly;
63  //int m_iWidgetCurrent;
64  //TQValueList<TQWidget*> m_widgetList;
65  //TQValueList<TDEAccel*> m_tdeaccelList;
66  TQValueList<TDEActionCollection*> m_docList;
67  TQWidget *m_widget;
68  TDEAccel *m_tdeaccel;
69  TDEAccel *m_builderTDEAccel;
70 
71  TQAsciiDict<TDEAction> m_actionDict;
72  TQPtrDict< TQPtrList<TDEAction> > m_dctHighlightContainers;
73  bool m_highlight;
74  TDEAction *m_currentHighlightAction;
75  bool m_statusCleared;
76  const KXMLGUIClient *m_parentGUIClient;
77 };
78 
79 TDEActionCollection::TDEActionCollection( TQWidget *parent, const char *name,
80  TDEInstance *instance )
81  : TQObject( parent, name )
82 {
83  kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis
84  d = new TDEActionCollectionPrivate;
85  if( parent )
86  setWidget( parent );
87  //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0);
88  setInstance( instance );
89 }
90 
91 
92 TDEActionCollection::TDEActionCollection( TQWidget *watch, TQObject* parent, const char *name,
93  TDEInstance *instance )
94  : TQObject( parent, name )
95 {
96  kdDebug(129) << "TDEActionCollection::TDEActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis
97  d = new TDEActionCollectionPrivate;
98  if( watch )
99  setWidget( watch );
100  //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0);
101  setInstance( instance );
102 }
103 
104 #ifndef KDE_NO_COMPAT
105 // KDE 4: remove
106 TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name,
107  TDEInstance *instance )
108  : TQObject( parent, name )
109 {
110  kdWarning(129) << "TDEActionCollection::TDEActionCollection( TQObject *parent, const char *name, TDEInstance *instance )" << endl; //ellis
111  kdDebug(129) << kdBacktrace() << endl;
112  d = new TDEActionCollectionPrivate;
113  TQWidget* w = dynamic_cast<TQWidget*>( parent );
114  if( w )
115  setWidget( w );
116  //d->m_bOneTDEAccelOnly = (d->m_tdeaccelList.count() > 0);
117  setInstance( instance );
118 }
119 
120 TDEActionCollection::TDEActionCollection( const TDEActionCollection &copy )
121  : TQObject()
122 {
123  kdWarning(129) << "TDEActionCollection::TDEActionCollection( const TDEActionCollection & ): function is severely deprecated." << endl;
124  d = new TDEActionCollectionPrivate;
125  *this = copy;
126 }
127 #endif // KDE 4: remove end
128 
129 TDEActionCollection::TDEActionCollection( const char *name, const KXMLGUIClient *parent )
130  : TQObject( 0L, name )
131 {
132  d = new TDEActionCollectionPrivate;
133  d->m_parentGUIClient=parent;
134  d->m_instance=parent->instance();
135 }
136 
137 
138 TDEActionCollection::~TDEActionCollection()
139 {
140  kdDebug(129) << "TDEActionCollection::~TDEActionCollection(): this = " << this << endl;
141  for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) {
142  TDEAction* pAction = it.current();
143  if ( pAction->m_parentCollection == this )
144  pAction->m_parentCollection = 0L;
145  }
146 
147  delete d->m_tdeaccel;
148  delete d->m_builderTDEAccel;
149  delete d; d = 0;
150 }
151 
152 void TDEActionCollection::setWidget( TQWidget* w )
153 {
154  //if ( d->m_actionDict.count() > 0 ) {
155  // kdError(129) << "TDEActionCollection::setWidget(): must be called before any actions are added to collection!" << endl;
156  // kdDebug(129) << kdBacktrace() << endl;
157  //}
158  //else
159  if ( !d->m_widget ) {
160  d->m_widget = w;
161  d->m_tdeaccel = new TDEAccel( w, this, "TDEActionCollection-TDEAccel" );
162  }
163  else if ( d->m_widget != w )
164  kdWarning(129) << "TDEActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl;
165 }
166 
167 void TDEActionCollection::setAutoConnectShortcuts( bool b )
168 {
169  d->m_bAutoConnectShortcuts = b;
170 }
171 
172 bool TDEActionCollection::isAutoConnectShortcuts()
173 {
174  return d->m_bAutoConnectShortcuts;
175 }
176 
177 bool TDEActionCollection::addDocCollection( TDEActionCollection* pDoc )
178 {
179  d->m_docList.append( pDoc );
180  return true;
181 }
182 
183 void TDEActionCollection::beginXMLPlug( TQWidget *widget )
184 {
185  kdDebug(129) << "TDEActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderTDEAccel = " << d->m_builderTDEAccel << endl;
186 
187  if( widget && !d->m_builderTDEAccel ) {
188  d->m_builderTDEAccel = new TDEAccel( widget, this, "TDEActionCollection-BuilderTDEAccel" );
189  }
190 }
191 
192 void TDEActionCollection::endXMLPlug()
193 {
194  kdDebug(129) << "TDEActionCollection::endXMLPlug(): this = " << this << endl;
195  //s_tdeaccelXML = 0;
196 }
197 
198 void TDEActionCollection::prepareXMLUnplug()
199 {
200  kdDebug(129) << "TDEActionCollection::prepareXMLUnplug(): this = " << this << endl;
201  unplugShortcuts( d->m_tdeaccel );
202 
203  if( d->m_builderTDEAccel ) {
204  unplugShortcuts( d->m_builderTDEAccel );
205  delete d->m_builderTDEAccel;
206  d->m_builderTDEAccel = 0;
207  }
208 }
209 
210 void TDEActionCollection::unplugShortcuts( TDEAccel* tdeaccel )
211 {
212  for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) {
213  TDEAction* pAction = it.current();
214  pAction->removeTDEAccel( tdeaccel );
215  }
216 
217  for( uint i = 0; i < d->m_docList.count(); i++ )
218  d->m_docList[i]->unplugShortcuts( tdeaccel );
219 }
220 
221 /*void TDEActionCollection::addWidget( TQWidget* w )
222 {
223  if( !d->m_bOneTDEAccelOnly ) {
224  kdDebug(129) << "TDEActionCollection::addWidget( " << w << " ): this = " << this << endl;
225  for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
226  if( d->m_widgetList[i] == w ) {
227  d->m_iWidgetCurrent = i;
228  return;
229  }
230  }
231  d->m_iWidgetCurrent = d->m_widgetList.count();
232  d->m_widgetList.append( w );
233  d->m_tdeaccelList.append( new TDEAccel( w, this, "TDEActionCollection-TDEAccel" ) );
234  }
235 }
236 
237 void TDEActionCollection::removeWidget( TQWidget* w )
238 {
239  if( !d->m_bOneTDEAccelOnly ) {
240  kdDebug(129) << "TDEActionCollection::removeWidget( " << w << " ): this = " << this << endl;
241  for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
242  if( d->m_widgetList[i] == w ) {
243  // Remove TDEAccel object from children.
244  TDEAccel* pTDEAccel = d->m_tdeaccelList[i];
245  for ( TQAsciiDictIterator<TDEAction> it( d->m_actionDict ); it.current(); ++it ) {
246  TDEAction* pAction = it.current();
247  if ( pAction->m_parentCollection == this ) {
248  pAction->removeTDEAccel( pTDEAccel );
249  }
250  }
251  delete pTDEAccel;
252 
253  d->m_widgetList.remove( d->m_widgetList.at( i ) );
254  d->m_tdeaccelList.remove( d->m_tdeaccelList.at( i ) );
255 
256  if( d->m_iWidgetCurrent == (int)i )
257  d->m_iWidgetCurrent = -1;
258  else if( d->m_iWidgetCurrent > (int)i )
259  d->m_iWidgetCurrent--;
260  return;
261  }
262  }
263  kdWarning(129) << "TDEActionCollection::removeWidget( " << w << " ): widget not in list." << endl;
264  }
265 }
266 
267 bool TDEActionCollection::ownsTDEAccel() const
268 {
269  return d->m_bOneTDEAccelOnly;
270 }
271 
272 uint TDEActionCollection::widgetCount() const
273 {
274  return d->m_widgetList.count();
275 }
276 
277 const TDEAccel* TDEActionCollection::widgetTDEAccel( uint i ) const
278 {
279  return d->m_tdeaccelList[i];
280 }*/
281 
282 TDEAccel* TDEActionCollection::tdeaccel()
283 {
284  //if( d->m_tdeaccelList.count() > 0 )
285  // return d->m_tdeaccelList[d->m_iWidgetCurrent];
286  //else
287  // return 0;
288  return d->m_tdeaccel;
289 }
290 
291 const TDEAccel* TDEActionCollection::tdeaccel() const
292 {
293  //if( d->m_tdeaccelList.count() > 0 )
294  // return d->m_tdeaccelList[d->m_iWidgetCurrent];
295  //else
296  // return 0;
297  return d->m_tdeaccel;
298 }
299 
300 // Return the key to use in d->m_actionDict for the given action.
301 // Usually name(), except when unnamed.
302 static const char* actionDictKey( TDEAction* action, char* buffer )
303 {
304  const char* name = action->name();
305  if( !qstrcmp( name, "unnamed" ) )
306  {
307  sprintf(buffer, "unnamed-%p", (void *)action);
308  return buffer;
309  }
310  return name;
311 }
312 
313 void TDEActionCollection::_insert( TDEAction* action )
314 {
315  char unnamed_name[100];
316  const char *name = actionDictKey( action, unnamed_name );
317  TDEAction *a = d->m_actionDict[ name ];
318  if ( a == action )
319  return;
320 
321  d->m_actionDict.insert( name, action );
322 
323  emit inserted( action );
324 }
325 
326 void TDEActionCollection::_remove( TDEAction* action )
327 {
328  char unnamed_name[100];
329  const char *name = actionDictKey( action, unnamed_name );
330 
331  TDEAction *a = d->m_actionDict.take( name );
332  if ( !a || a != action )
333  return;
334 
335  emit removed( action );
336  // note that we delete the action without its parent collection set to 0.
337  // This triggers tdeaccel::remove, to remove any shortcut.
338  delete a;
339 }
340 
341 TDEAction* TDEActionCollection::_take( TDEAction* action )
342 {
343  char unnamed_name[100];
344  const char *name = actionDictKey( action, unnamed_name );
345 
346  TDEAction *a = d->m_actionDict.take( name );
347  if ( !a || a != action )
348  return 0;
349 
350  if ( a->m_parentCollection == this )
351  a->m_parentCollection = 0;
352 
353  emit removed( action );
354 
355  return a;
356 }
357 
358 void TDEActionCollection::_clear()
359 {
360  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
361  while ( it.current() )
362  _remove( it.current() );
363 }
364 
365 void TDEActionCollection::insert( TDEAction* action ) { _insert( action ); }
366 void TDEActionCollection::remove( TDEAction* action ) { _remove( action ); }
367 TDEAction* TDEActionCollection::take( TDEAction* action ) { return _take( action ); }
368 void TDEActionCollection::clear() { _clear(); }
369 TDEAccel* TDEActionCollection::accel() { return tdeaccel(); }
370 const TDEAccel* TDEActionCollection::accel() const { return tdeaccel(); }
371 TDEAccel* TDEActionCollection::builderTDEAccel() const { return d->m_builderTDEAccel; }
372 
373 TDEAction* TDEActionCollection::action( const char* name, const char* classname ) const
374 {
375  TDEAction* pAction = 0;
376 
377  if ( !classname && name )
378  pAction = d->m_actionDict[ name ];
379 
380  else {
381  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
382  for( ; it.current(); ++it )
383  {
384  if ( ( !name || !strcmp( it.current()->name(), name ) ) &&
385  ( !classname || !strcmp( it.current()->className(), classname ) ) ) {
386  pAction = it.current();
387  break;
388  }
389  }
390  }
391 
392  if( !pAction ) {
393  for( uint i = 0; i < d->m_docList.count() && !pAction; i++ )
394  pAction = d->m_docList[i]->action( name, classname );
395  }
396 
397  return pAction;
398 }
399 
400 TDEAction* TDEActionCollection::action( int index ) const
401 {
402  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
403  it += index;
404  return it.current();
405 // return d->m_actions.at( index );
406 }
407 
408 bool TDEActionCollection::readShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig )
409 {
410  return TDEActionShortcutList(this).readSettings( sConfigGroup, pConfig );
411 }
412 
413 bool TDEActionCollection::writeShortcutSettings( const TQString& sConfigGroup, TDEConfigBase* pConfig ) const
414 {
415  return TDEActionShortcutList((TDEActionCollection*)this).writeSettings( sConfigGroup, pConfig );
416 }
417 
418 uint TDEActionCollection::count() const
419 {
420  return d->m_actionDict.count();
421 }
422 
423 TQStringList TDEActionCollection::groups() const
424 {
425  TQStringList lst;
426 
427  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
428  for( ; it.current(); ++it )
429  if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) )
430  lst.append( it.current()->group() );
431 
432  return lst;
433 }
434 
435 TDEActionPtrList TDEActionCollection::actions( const TQString& group ) const
436 {
437  TDEActionPtrList lst;
438 
439  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
440  for( ; it.current(); ++it )
441  if ( it.current()->group() == group )
442  lst.append( it.current() );
443  else if ( it.current()->group().isEmpty() && group.isEmpty() )
444  lst.append( it.current() );
445 
446  return lst;
447 }
448 
449 TDEActionPtrList TDEActionCollection::actions() const
450 {
451  TDEActionPtrList lst;
452 
453  TQAsciiDictIterator<TDEAction> it( d->m_actionDict );
454  for( ; it.current(); ++it )
455  lst.append( it.current() );
456 
457  return lst;
458 }
459 
460 void TDEActionCollection::setInstance( TDEInstance *instance )
461 {
462  if ( instance )
463  d->m_instance = instance;
464  else
465  d->m_instance = TDEGlobal::instance();
466 }
467 
468 TDEInstance *TDEActionCollection::instance() const
469 {
470  return d->m_instance;
471 }
472 
473 void TDEActionCollection::setXMLFile( const TQString& sXMLFile )
474 {
475  d->m_sXMLFile = sXMLFile;
476 }
477 
478 const TQString& TDEActionCollection::xmlFile() const
479 {
480  return d->m_sXMLFile;
481 }
482 
483 void TDEActionCollection::setHighlightingEnabled( bool enable )
484 {
485  d->m_highlight = enable;
486 }
487 
488 bool TDEActionCollection::highlightingEnabled() const
489 {
490  return d->m_highlight;
491 }
492 
493 void TDEActionCollection::connectHighlight( TQWidget *container, TDEAction *action )
494 {
495  if ( !d->m_highlight )
496  return;
497 
498  TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ];
499 
500  if ( !actionList )
501  {
502  actionList = new TQPtrList<TDEAction>;
503 
504  if ( ::tqt_cast<TQPopupMenu *>( container ) )
505  {
506  connect( container, TQ_SIGNAL( highlighted( int ) ),
507  this, TQ_SLOT( slotMenuItemHighlighted( int ) ) );
508  connect( container, TQ_SIGNAL( aboutToHide() ),
509  this, TQ_SLOT( slotMenuAboutToHide() ) );
510  }
511  else if ( ::tqt_cast<TDEToolBar *>( container ) )
512  {
513  connect( container, TQ_SIGNAL( highlighted( int, bool ) ),
514  this, TQ_SLOT( slotToolBarButtonHighlighted( int, bool ) ) );
515  }
516 
517  connect( container, TQ_SIGNAL( destroyed() ),
518  this, TQ_SLOT( slotDestroyed() ) );
519 
520  d->m_dctHighlightContainers.insert( container, actionList );
521  }
522 
523  actionList->append( action );
524 }
525 
526 void TDEActionCollection::disconnectHighlight( TQWidget *container, TDEAction *action )
527 {
528  if ( !d->m_highlight )
529  return;
530 
531  TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ container ];
532 
533  if ( !actionList )
534  return;
535 
536  actionList->removeRef( action );
537 
538  if ( actionList->isEmpty() )
539  d->m_dctHighlightContainers.remove( container );
540 }
541 
542 void TDEActionCollection::slotMenuItemHighlighted( int id )
543 {
544  if ( !d->m_highlight )
545  return;
546 
547  if ( d->m_currentHighlightAction )
548  emit actionHighlighted( d->m_currentHighlightAction, false );
549 
550  TQWidget *container = static_cast<TQWidget *>( const_cast<TQObject *>( sender() ));
551 
552  d->m_currentHighlightAction = findAction( container, id );
553 
554  if ( !d->m_currentHighlightAction )
555  {
556  if ( !d->m_statusCleared )
557  emit clearStatusText();
558  d->m_statusCleared = true;
559  return;
560  }
561 
562  d->m_statusCleared = false;
563  emit actionHighlighted( d->m_currentHighlightAction );
564  emit actionHighlighted( d->m_currentHighlightAction, true );
565  emit actionStatusText( d->m_currentHighlightAction->toolTip() );
566 }
567 
568 void TDEActionCollection::slotMenuAboutToHide()
569 {
570  if ( d->m_currentHighlightAction )
571  emit actionHighlighted( d->m_currentHighlightAction, false );
572  d->m_currentHighlightAction = 0;
573 
574  if ( !d->m_statusCleared )
575  emit clearStatusText();
576  d->m_statusCleared = true;
577 }
578 
579 void TDEActionCollection::slotToolBarButtonHighlighted( int id, bool highlight )
580 {
581  if ( !d->m_highlight )
582  return;
583 
584  TQWidget *container = static_cast<TQWidget *>( const_cast<TQObject *>( sender() ));
585 
586  TDEAction *action = findAction( container, id );
587 
588  if ( !action )
589  {
590  d->m_currentHighlightAction = 0;
591  // use tooltip groups for toolbar status text stuff instead (Simon)
592 // emit clearStatusText();
593  return;
594  }
595 
596  emit actionHighlighted( action, highlight );
597 
598  if ( highlight )
599  d->m_currentHighlightAction = action;
600  else
601  {
602  d->m_currentHighlightAction = 0;
603 // emit clearStatusText();
604  }
605 }
606 
607 void TDEActionCollection::slotDestroyed()
608 {
609  d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<TQObject*>(sender()) ) );
610 }
611 
612 TDEAction *TDEActionCollection::findAction( TQWidget *container, int id )
613 {
614  TQPtrList<TDEAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ];
615 
616  if ( !actionList )
617  return 0;
618 
619  TQPtrListIterator<TDEAction> it( *actionList );
620  for (; it.current(); ++it )
621  if ( it.current()->isPlugged( container, id ) )
622  return it.current();
623 
624  return 0;
625 }
626 
627 const KXMLGUIClient *TDEActionCollection::parentGUIClient() const
628 {
629  return d->m_parentGUIClient;
630 }
631 
632 #ifndef KDE_NO_COMPAT
633 // KDE 4: remove
634 TDEActionCollection TDEActionCollection::operator+(const TDEActionCollection &c ) const
635 {
636  kdWarning(129) << "TDEActionCollection::operator+(): function is severely deprecated." << endl;
637  TDEActionCollection ret( *this );
638 
639  TQValueList<TDEAction *> actions = c.actions();
640  TQValueList<TDEAction *>::ConstIterator it = actions.begin();
641  TQValueList<TDEAction *>::ConstIterator end = actions.end();
642  for (; it != end; ++it )
643  ret.insert( *it );
644 
645  return ret;
646 }
647 
648 TDEActionCollection &TDEActionCollection::operator=( const TDEActionCollection &copy )
649 {
650  kdWarning(129) << "TDEActionCollection::operator=(): function is severely deprecated." << endl;
651  //d->m_bOneTDEAccelOnly = copy.d->m_bOneTDEAccelOnly;
652  //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent;
653  //d->m_widgetList = copy.d->m_widgetList;
654  //d->m_tdeaccelList = copy.d->m_tdeaccelList;
655  d->m_widget = copy.d->m_widget;
656  d->m_tdeaccel = copy.d->m_tdeaccel;
657  d->m_actionDict = copy.d->m_actionDict;
658  setInstance( copy.instance() );
659  return *this;
660 }
661 
662 TDEActionCollection &TDEActionCollection::operator+=( const TDEActionCollection &c )
663 {
664  kdWarning(129) << "TDEActionCollection::operator+=(): function is severely deprecated." << endl;
665  TQAsciiDictIterator<TDEAction> it(c.d->m_actionDict);
666  for ( ; it.current(); ++it )
667  insert( it.current() );
668 
669  return *this;
670 }
671 #endif // KDE 4: remove end
672 
673 //---------------------------------------------------------------------
674 // TDEActionShortcutList
675 //---------------------------------------------------------------------
676 
677 TDEActionShortcutList::TDEActionShortcutList( TDEActionCollection* pColl )
678 : m_actions( *pColl )
679  { }
680 TDEActionShortcutList::~TDEActionShortcutList()
681  { }
682 uint TDEActionShortcutList::count() const
683  { return m_actions.count(); }
684 TQString TDEActionShortcutList::name( uint i ) const
685  { return m_actions.action(i)->name(); }
686 TQString TDEActionShortcutList::label( uint i ) const
687  { return m_actions.action(i)->text(); }
688 TQString TDEActionShortcutList::whatsThis( uint i ) const
689  { return m_actions.action(i)->whatsThis(); }
690 const TDEShortcut& TDEActionShortcutList::shortcut( uint i ) const
691  { return m_actions.action(i)->shortcut(); }
692 const TDEShortcut& TDEActionShortcutList::shortcutDefault( uint i ) const
693  { return m_actions.action(i)->shortcutDefault(); }
694 bool TDEActionShortcutList::isConfigurable( uint i ) const
695  { return m_actions.action(i)->isShortcutConfigurable(); }
696 bool TDEActionShortcutList::setShortcut( uint i, const TDEShortcut& cut )
697  { return m_actions.action(i)->setShortcut( cut ); }
698 const TDEInstance* TDEActionShortcutList::instance() const
699  { return m_actions.instance(); }
700 TQVariant TDEActionShortcutList::getOther( Other, uint ) const
701  { return TQVariant(); }
702 bool TDEActionShortcutList::setOther( Other, uint, TQVariant )
703  { return false; }
704 const TDEAction *TDEActionShortcutList::action( uint i) const
705  { return m_actions.action(i); }
706 
707 bool TDEActionShortcutList::save() const
708 {
709  const KXMLGUIClient* guiClient=m_actions.parentGUIClient();
710  const TQString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile();
711  kdDebug(129) << "TDEActionShortcutList::save(): xmlFile = " << xmlFile << endl;
712 
713  if( m_actions.xmlFile().isEmpty() )
714  return writeSettings();
715 
716  TQString attrShortcut = TQString::fromLatin1("shortcut");
717  TQString attrAccel = TQString::fromLatin1("accel"); // Depricated attribute
718 
719  // Read XML file
720  TQString sXml( KXMLGUIFactory::readConfigFile( xmlFile, false, instance() ) );
721  TQDomDocument doc;
722  doc.setContent( sXml );
723 
724  // Process XML data
725 
726  // Get hold of ActionProperties tag
727  TQDomElement elem = KXMLGUIFactory::actionPropertiesElement( doc );
728 
729  // now, iterate through our actions
730  uint nSize = count();
731  for( uint i = 0; i < nSize; i++ ) {
732  const TQString& sName = name(i);
733 
734  bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
735  //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl;
736 
737  // now see if this element already exists
738  // and create it if necessary (unless bSameAsDefault)
739  TQDomElement act_elem = KXMLGUIFactory::findActionByName( elem, sName, !bSameAsDefault );
740  if ( act_elem.isNull() )
741  continue;
742 
743  act_elem.removeAttribute( attrAccel );
744  if( bSameAsDefault ) {
745  act_elem.removeAttribute( attrShortcut );
746  //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl;
747  if( act_elem.attributes().count() == 1 )
748  elem.removeChild( act_elem );
749  } else {
750  act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() );
751  }
752  }
753 
754  // Write back to XML file
755  return KXMLGUIFactory::saveConfigFile( doc, guiClient ? guiClient->localXMLFile() : m_actions.xmlFile(), instance() );
756 }
757 
758 //---------------------------------------------------------------------
759 // TDEActionPtrShortcutList
760 //---------------------------------------------------------------------
761 
762 TDEActionPtrShortcutList::TDEActionPtrShortcutList( TDEActionPtrList& list )
763 : m_actions( list )
764  { }
765 TDEActionPtrShortcutList::~TDEActionPtrShortcutList()
766  { }
767 uint TDEActionPtrShortcutList::count() const
768  { return m_actions.count(); }
769 TQString TDEActionPtrShortcutList::name( uint i ) const
770  { return m_actions[i]->name(); }
771 TQString TDEActionPtrShortcutList::label( uint i ) const
772  { return m_actions[i]->text(); }
773 TQString TDEActionPtrShortcutList::whatsThis( uint i ) const
774  { return m_actions[i]->whatsThis(); }
775 const TDEShortcut& TDEActionPtrShortcutList::shortcut( uint i ) const
776  { return m_actions[i]->shortcut(); }
777 const TDEShortcut& TDEActionPtrShortcutList::shortcutDefault( uint i ) const
778  { return m_actions[i]->shortcutDefault(); }
779 bool TDEActionPtrShortcutList::isConfigurable( uint i ) const
780  { return m_actions[i]->isShortcutConfigurable(); }
781 bool TDEActionPtrShortcutList::setShortcut( uint i, const TDEShortcut& cut )
782  { return m_actions[i]->setShortcut( cut ); }
783 TQVariant TDEActionPtrShortcutList::getOther( Other, uint ) const
784  { return TQVariant(); }
785 bool TDEActionPtrShortcutList::setOther( Other, uint, TQVariant )
786  { return false; }
787 bool TDEActionPtrShortcutList::save() const
788  { return false; }
789 
790 void TDEActionShortcutList::virtual_hook( int id, void* data )
791 { TDEShortcutList::virtual_hook( id, data ); }
792 
793 void TDEActionPtrShortcutList::virtual_hook( int id, void* data )
794 { TDEShortcutList::virtual_hook( id, data ); }
795 
796 void TDEActionCollection::virtual_hook( int, void* )
797 { /*BASE::virtual_hook( id, data );*/ }
798 
799 #include "tdeactioncollection.moc"
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
Definition: kxmlguiclient.h:44
KXMLGUIClient::xmlFile
virtual TQString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
Definition: kxmlguiclient.cpp:133
KXMLGUIClient::instance
virtual TDEInstance * instance() const
Definition: kxmlguiclient.cpp:123
KXMLGUIFactory::findActionByName
static TQDomElement findActionByName(TQDomElement &elem, const TQString &sName, bool create)
Definition: kxmlguifactory.cpp:589
KXMLGUIFactory::actionPropertiesElement
static TQDomElement actionPropertiesElement(TQDomDocument &doc)
Definition: kxmlguifactory.cpp:567
TDEAccel
TDEActionCollection
A managed set of TDEAction objects.
Definition: tdeactioncollection.h:79
TDEActionCollection::actions
virtual TDEActionPtrList actions(const TQString &group) const
Returns the list of actions in a particular group managed by this action collection.
Definition: tdeactioncollection.cpp:435
TDEActionCollection::accel
virtual TDEAccel * accel() TDE_DEPRECATED
Returns the number of widgets which this collection is associated with.
Definition: tdeactioncollection.cpp:369
TDEActionCollection::tdeaccel
TDEAccel * tdeaccel()
Returns the TDEAccel object of the most recently set widget.
Definition: tdeactioncollection.cpp:282
TDEActionCollection::insert
void insert(TDEAction *action)
Add an action to the collection.
Definition: tdeactioncollection.cpp:365
TDEActionCollection::highlightingEnabled
bool highlightingEnabled() const
Return whether highlighting notifications are enabled.
Definition: tdeactioncollection.cpp:488
TDEActionCollection::groups
virtual TQStringList groups() const
Returns a list of all the groups of all the TDEActions in this action collection.
Definition: tdeactioncollection.cpp:423
TDEActionCollection::disconnectHighlight
void disconnectHighlight(TQWidget *container, TDEAction *action)
Disconnect highlight notifications for a particular pair of contianer and action.
Definition: tdeactioncollection.cpp:526
TDEActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, return 0L if not available.
Definition: tdeactioncollection.cpp:627
TDEActionCollection::take
TDEAction * take(TDEAction *action)
Removes an action from the collection.
Definition: tdeactioncollection.cpp:367
TDEActionCollection::clearStatusText
void clearStatusText()
Emitted when an action loses highlighting.
TDEActionCollection::setHighlightingEnabled
void setHighlightingEnabled(bool enable)
Enable highlighting notification for specific TDEActions.
Definition: tdeactioncollection.cpp:483
TDEActionCollection::instance
TDEInstance * instance() const
The instance with which this class is associated.
Definition: tdeactioncollection.cpp:468
TDEActionCollection::readShortcutSettings
bool readShortcutSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0)
Used for reading shortcut configuration from a non-XML rc file.
Definition: tdeactioncollection.cpp:408
TDEActionCollection::clear
void clear()
Clears the entire actionCollection, deleting all actions.
Definition: tdeactioncollection.cpp:368
TDEActionCollection::action
virtual TDEAction * action(int index) const
Return the TDEAction* at position "index" in the action collection.
Definition: tdeactioncollection.cpp:400
TDEActionCollection::builderTDEAccel
TDEAccel * builderTDEAccel() const
Definition: tdeactioncollection.cpp:371
TDEActionCollection::setXMLFile
void setXMLFile(const TQString &)
Definition: tdeactioncollection.cpp:473
TDEActionCollection::connectHighlight
void connectHighlight(TQWidget *container, TDEAction *action)
Call this function if you want to receive a signal whenever a TDEAction is highlighted in a menu or a...
Definition: tdeactioncollection.cpp:493
TDEActionCollection::actions
virtual TDEActionPtrList actions() const
Returns the list of actions managed by this action collection.
Definition: tdeactioncollection.cpp:449
TDEActionCollection::addDocCollection
bool addDocCollection(TDEActionCollection *pDoc)
This sets the default shortcut scope for new actions created in this collection.
Definition: tdeactioncollection.cpp:177
TDEActionCollection::actionHighlighted
void actionHighlighted(TDEAction *action)
Emitted when action is highlighted.
TDEActionCollection::writeShortcutSettings
bool writeShortcutSettings(const TQString &sConfigGroup=TQString::null, TDEConfigBase *pConfig=0) const
Used for writing shortcut configuration to a non-XML rc file.
Definition: tdeactioncollection.cpp:413
TDEActionCollection::remove
void remove(TDEAction *action)
Removes an action from the collection and deletes it.
Definition: tdeactioncollection.cpp:366
TDEActionCollection::setWidget
virtual void setWidget(TQWidget *widget)
This sets the widget to which the keyboard shortcuts should be attached.
Definition: tdeactioncollection.cpp:152
TDEActionCollection::xmlFile
const TQString & xmlFile() const
Definition: tdeactioncollection.cpp:478
TDEActionCollection::count
virtual uint count() const
Returns the TDEAccel object associated with widget #.
Definition: tdeactioncollection.cpp:418
TDEActionCollection::isAutoConnectShortcuts
bool isAutoConnectShortcuts()
This indicates whether new actions which are created in this collection have their keyboard shortcuts...
Definition: tdeactioncollection.cpp:172
TDEActionCollection::actionStatusText
void actionStatusText(const TQString &text)
Emitted when an action is highlighted, with text being the tooltip for the action.
TDEActionCollection::setAutoConnectShortcuts
void setAutoConnectShortcuts(bool)
This indicates whether new actions which are created in this collection should have their keyboard sh...
Definition: tdeactioncollection.cpp:167
TDEAction
Class to encapsulate user-driven action or event.
Definition: tdeaction.h:203
TDEConfigBase
TDEGlobal::instance
static TDEInstance * instance()
TDEInstance
TDEShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
TDEShortcut
endl
kndbgstream & endl(kndbgstream &s)
kdBacktrace
TQString kdBacktrace(int levels=-1)
kdWarning
kdbgstream kdWarning(int area=0)
kdDebug
kdbgstream kdDebug(int area=0)
KNotifyClient::instance
TDEInstance * instance()
TDEStdAccel::copy
const TDEShortcut & copy()
TDEStdAccel::name
TQString name(StdAccel id)
TDEStdAccel::shortcutDefault
TDEShortcut shortcutDefault(StdAccel id)
TDEStdAccel::shortcut
const TDEShortcut & shortcut(StdAccel id)

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.