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

kdeui

  • kdeui
kactioncollection.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 "kactioncollection.h"
27 #include "kactionshortcutlist.h"
28 #include "ktoolbar.h"
29 #include "kxmlguifactory.h"
30 #include "kxmlguiclient.h"
31 
32 #include <kaccel.h>
33 #include <kaccelbase.h>
34 #include <kapplication.h>
35 #include <kdebug.h>
36 
37 #include <tqpopupmenu.h>
38 #include <tqptrdict.h>
39 #include <tqvariant.h>
40 
41 class KActionCollection::KActionCollectionPrivate
42 {
43 public:
44  KActionCollectionPrivate()
45  {
46  m_instance = 0;
47  //m_bOneKAccelOnly = false;
48  //m_iWidgetCurrent = 0;
49  m_bAutoConnectShortcuts = true;
50  m_widget = 0;
51  m_kaccel = m_builderKAccel = 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  KInstance *m_instance;
60  TQString m_sXMLFile;
61  bool m_bAutoConnectShortcuts;
62  //bool m_bOneKAccelOnly;
63  //int m_iWidgetCurrent;
64  //TQValueList<TQWidget*> m_widgetList;
65  //TQValueList<KAccel*> m_kaccelList;
66  TQValueList<KActionCollection*> m_docList;
67  TQWidget *m_widget;
68  KAccel *m_kaccel;
69  KAccel *m_builderKAccel;
70 
71  TQAsciiDict<KAction> m_actionDict;
72  TQPtrDict< TQPtrList<KAction> > m_dctHighlightContainers;
73  bool m_highlight;
74  KAction *m_currentHighlightAction;
75  bool m_statusCleared;
76  const KXMLGUIClient *m_parentGUIClient;
77 };
78 
79 KActionCollection::KActionCollection( TQWidget *parent, const char *name,
80  KInstance *instance )
81  : TQObject( parent, name )
82 {
83  kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis
84  d = new KActionCollectionPrivate;
85  if( parent )
86  setWidget( parent );
87  //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
88  setInstance( instance );
89 }
90 
91 
92 KActionCollection::KActionCollection( TQWidget *watch, TQObject* parent, const char *name,
93  KInstance *instance )
94  : TQObject( parent, name )
95 {
96  kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis
97  d = new KActionCollectionPrivate;
98  if( watch )
99  setWidget( watch );
100  //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
101  setInstance( instance );
102 }
103 
104 #ifndef KDE_NO_COMPAT
105 // KDE 4: remove
106 KActionCollection::KActionCollection( TQObject *parent, const char *name,
107  KInstance *instance )
108  : TQObject( parent, name )
109 {
110  kdWarning(129) << "KActionCollection::KActionCollection( TQObject *parent, const char *name, KInstance *instance )" << endl; //ellis
111  kdDebug(129) << kdBacktrace() << endl;
112  d = new KActionCollectionPrivate;
113  TQWidget* w = tqt_dynamic_cast<TQWidget*>( parent );
114  if( w )
115  setWidget( w );
116  //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
117  setInstance( instance );
118 }
119 
120 KActionCollection::KActionCollection( const KActionCollection &copy )
121  : TQObject()
122 {
123  kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl;
124  d = new KActionCollectionPrivate;
125  *this = copy;
126 }
127 #endif // KDE 4: remove end
128 
129 KActionCollection::KActionCollection( const char *name, const KXMLGUIClient *parent )
130  : TQObject( 0L, name )
131 {
132  d = new KActionCollectionPrivate;
133  d->m_parentGUIClient=parent;
134  d->m_instance=parent->instance();
135 }
136 
137 
138 KActionCollection::~KActionCollection()
139 {
140  kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl;
141  for ( TQAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
142  KAction* pAction = it.current();
143  if ( pAction->m_parentCollection == this )
144  pAction->m_parentCollection = 0L;
145  }
146 
147  delete d->m_kaccel;
148  delete d->m_builderKAccel;
149  delete d; d = 0;
150 }
151 
152 void KActionCollection::setWidget( TQWidget* w )
153 {
154  //if ( d->m_actionDict.count() > 0 ) {
155  // kdError(129) << "KActionCollection::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_kaccel = new KAccel( w, this, "KActionCollection-KAccel" );
162  }
163  else if ( d->m_widget != w )
164  kdWarning(129) << "KActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl;
165 }
166 
167 void KActionCollection::setAutoConnectShortcuts( bool b )
168 {
169  d->m_bAutoConnectShortcuts = b;
170 }
171 
172 bool KActionCollection::isAutoConnectShortcuts()
173 {
174  return d->m_bAutoConnectShortcuts;
175 }
176 
177 bool KActionCollection::addDocCollection( KActionCollection* pDoc )
178 {
179  d->m_docList.append( pDoc );
180  return true;
181 }
182 
183 void KActionCollection::beginXMLPlug( TQWidget *widget )
184 {
185  kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl;
186 
187  if( widget && !d->m_builderKAccel ) {
188  d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" );
189  }
190 }
191 
192 void KActionCollection::endXMLPlug()
193 {
194  kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl;
195  //s_kaccelXML = 0;
196 }
197 
198 void KActionCollection::prepareXMLUnplug()
199 {
200  kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl;
201  unplugShortcuts( d->m_kaccel );
202 
203  if( d->m_builderKAccel ) {
204  unplugShortcuts( d->m_builderKAccel );
205  delete d->m_builderKAccel;
206  d->m_builderKAccel = 0;
207  }
208 }
209 
210 void KActionCollection::unplugShortcuts( KAccel* kaccel )
211 {
212  for ( TQAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
213  KAction* pAction = it.current();
214  pAction->removeKAccel( kaccel );
215  }
216 
217  for( uint i = 0; i < d->m_docList.count(); i++ )
218  d->m_docList[i]->unplugShortcuts( kaccel );
219 }
220 
221 /*void KActionCollection::addWidget( TQWidget* w )
222 {
223  if( !d->m_bOneKAccelOnly ) {
224  kdDebug(129) << "KActionCollection::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_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) );
234  }
235 }
236 
237 void KActionCollection::removeWidget( TQWidget* w )
238 {
239  if( !d->m_bOneKAccelOnly ) {
240  kdDebug(129) << "KActionCollection::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 KAccel object from children.
244  KAccel* pKAccel = d->m_kaccelList[i];
245  for ( TQAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
246  KAction* pAction = it.current();
247  if ( pAction->m_parentCollection == this ) {
248  pAction->removeKAccel( pKAccel );
249  }
250  }
251  delete pKAccel;
252 
253  d->m_widgetList.remove( d->m_widgetList.at( i ) );
254  d->m_kaccelList.remove( d->m_kaccelList.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) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl;
264  }
265 }
266 
267 bool KActionCollection::ownsKAccel() const
268 {
269  return d->m_bOneKAccelOnly;
270 }
271 
272 uint KActionCollection::widgetCount() const
273 {
274  return d->m_widgetList.count();
275 }
276 
277 const KAccel* KActionCollection::widgetKAccel( uint i ) const
278 {
279  return d->m_kaccelList[i];
280 }*/
281 
282 KAccel* KActionCollection::kaccel()
283 {
284  //if( d->m_kaccelList.count() > 0 )
285  // return d->m_kaccelList[d->m_iWidgetCurrent];
286  //else
287  // return 0;
288  return d->m_kaccel;
289 }
290 
291 const KAccel* KActionCollection::kaccel() const
292 {
293  //if( d->m_kaccelList.count() > 0 )
294  // return d->m_kaccelList[d->m_iWidgetCurrent];
295  //else
296  // return 0;
297  return d->m_kaccel;
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( KAction* 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 KActionCollection::_insert( KAction* action )
314 {
315  char unnamed_name[100];
316  const char *name = actionDictKey( action, unnamed_name );
317  KAction *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 KActionCollection::_remove( KAction* action )
327 {
328  char unnamed_name[100];
329  const char *name = actionDictKey( action, unnamed_name );
330 
331  KAction *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 kaccel::remove, to remove any shortcut.
338  delete a;
339 }
340 
341 KAction* KActionCollection::_take( KAction* action )
342 {
343  char unnamed_name[100];
344  const char *name = actionDictKey( action, unnamed_name );
345 
346  KAction *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 KActionCollection::_clear()
359 {
360  TQAsciiDictIterator<KAction> it( d->m_actionDict );
361  while ( it.current() )
362  _remove( it.current() );
363 }
364 
365 void KActionCollection::insert( KAction* action ) { _insert( action ); }
366 void KActionCollection::remove( KAction* action ) { _remove( action ); }
367 KAction* KActionCollection::take( KAction* action ) { return _take( action ); }
368 void KActionCollection::clear() { _clear(); }
369 KAccel* KActionCollection::accel() { return kaccel(); }
370 const KAccel* KActionCollection::accel() const { return kaccel(); }
371 KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; }
372 
373 KAction* KActionCollection::action( const char* name, const char* classname ) const
374 {
375  KAction* pAction = 0;
376 
377  if ( !classname && name )
378  pAction = d->m_actionDict[ name ];
379 
380  else {
381  TQAsciiDictIterator<KAction> 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 KAction* KActionCollection::action( int index ) const
401 {
402  TQAsciiDictIterator<KAction> it( d->m_actionDict );
403  it += index;
404  return it.current();
405 // return d->m_actions.at( index );
406 }
407 
408 bool KActionCollection::readShortcutSettings( const TQString& sConfigGroup, KConfigBase* pConfig )
409 {
410  return KActionShortcutList(this).readSettings( sConfigGroup, pConfig );
411 }
412 
413 bool KActionCollection::writeShortcutSettings( const TQString& sConfigGroup, KConfigBase* pConfig ) const
414 {
415  return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig );
416 }
417 
418 uint KActionCollection::count() const
419 {
420  return d->m_actionDict.count();
421 }
422 
423 TQStringList KActionCollection::groups() const
424 {
425  TQStringList lst;
426 
427  TQAsciiDictIterator<KAction> 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 KActionPtrList KActionCollection::actions( const TQString& group ) const
436 {
437  KActionPtrList lst;
438 
439  TQAsciiDictIterator<KAction> 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 KActionPtrList KActionCollection::actions() const
450 {
451  KActionPtrList lst;
452 
453  TQAsciiDictIterator<KAction> it( d->m_actionDict );
454  for( ; it.current(); ++it )
455  lst.append( it.current() );
456 
457  return lst;
458 }
459 
460 void KActionCollection::setInstance( KInstance *instance )
461 {
462  if ( instance )
463  d->m_instance = instance;
464  else
465  d->m_instance = KGlobal::instance();
466 }
467 
468 KInstance *KActionCollection::instance() const
469 {
470  return d->m_instance;
471 }
472 
473 void KActionCollection::setXMLFile( const TQString& sXMLFile )
474 {
475  d->m_sXMLFile = sXMLFile;
476 }
477 
478 const TQString& KActionCollection::xmlFile() const
479 {
480  return d->m_sXMLFile;
481 }
482 
483 void KActionCollection::setHighlightingEnabled( bool enable )
484 {
485  d->m_highlight = enable;
486 }
487 
488 bool KActionCollection::highlightingEnabled() const
489 {
490  return d->m_highlight;
491 }
492 
493 void KActionCollection::connectHighlight( TQWidget *container, KAction *action )
494 {
495  if ( !d->m_highlight )
496  return;
497 
498  TQPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ];
499 
500  if ( !actionList )
501  {
502  actionList = new TQPtrList<KAction>;
503 
504  if ( ::tqqt_cast<TQPopupMenu *>( container ) )
505  {
506  connect( container, TQT_SIGNAL( highlighted( int ) ),
507  this, TQT_SLOT( slotMenuItemHighlighted( int ) ) );
508  connect( container, TQT_SIGNAL( aboutToHide() ),
509  this, TQT_SLOT( slotMenuAboutToHide() ) );
510  }
511  else if ( ::tqqt_cast<KToolBar *>( container ) )
512  {
513  connect( container, TQT_SIGNAL( highlighted( int, bool ) ),
514  this, TQT_SLOT( slotToolBarButtonHighlighted( int, bool ) ) );
515  }
516 
517  connect( container, TQT_SIGNAL( destroyed() ),
518  this, TQT_SLOT( slotDestroyed() ) );
519 
520  d->m_dctHighlightContainers.insert( container, actionList );
521  }
522 
523  actionList->append( action );
524 }
525 
526 void KActionCollection::disconnectHighlight( TQWidget *container, KAction *action )
527 {
528  if ( !d->m_highlight )
529  return;
530 
531  TQPtrList<KAction> *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 KActionCollection::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 = const_cast<TQWidget*>(TQT_TQWIDGET_CONST( 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 KActionCollection::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 KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight )
580 {
581  if ( !d->m_highlight )
582  return;
583 
584  TQWidget *container = const_cast<TQWidget*>(TQT_TQWIDGET_CONST( sender() ));
585 
586  KAction *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 KActionCollection::slotDestroyed()
608 {
609  d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<TQObject*>(TQT_TQOBJECT_CONST(sender())) ) );
610 }
611 
612 KAction *KActionCollection::findAction( TQWidget *container, int id )
613 {
614  TQPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ];
615 
616  if ( !actionList )
617  return 0;
618 
619  TQPtrListIterator<KAction> 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 *KActionCollection::parentGUIClient() const
628 {
629  return d->m_parentGUIClient;
630 }
631 
632 #ifndef KDE_NO_COMPAT
633 // KDE 4: remove
634 KActionCollection KActionCollection::operator+(const KActionCollection &c ) const
635 {
636  kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl;
637  KActionCollection ret( *this );
638 
639  TQValueList<KAction *> actions = c.actions();
640  TQValueList<KAction *>::ConstIterator it = actions.begin();
641  TQValueList<KAction *>::ConstIterator end = actions.end();
642  for (; it != end; ++it )
643  ret.insert( *it );
644 
645  return ret;
646 }
647 
648 KActionCollection &KActionCollection::operator=( const KActionCollection &copy )
649 {
650  kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl;
651  //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly;
652  //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent;
653  //d->m_widgetList = copy.d->m_widgetList;
654  //d->m_kaccelList = copy.d->m_kaccelList;
655  d->m_widget = copy.d->m_widget;
656  d->m_kaccel = copy.d->m_kaccel;
657  d->m_actionDict = copy.d->m_actionDict;
658  setInstance( copy.instance() );
659  return *this;
660 }
661 
662 KActionCollection &KActionCollection::operator+=( const KActionCollection &c )
663 {
664  kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl;
665  TQAsciiDictIterator<KAction> 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 // KActionShortcutList
675 //---------------------------------------------------------------------
676 
677 KActionShortcutList::KActionShortcutList( KActionCollection* pColl )
678 : m_actions( *pColl )
679  { }
680 KActionShortcutList::~KActionShortcutList()
681  { }
682 uint KActionShortcutList::count() const
683  { return m_actions.count(); }
684 TQString KActionShortcutList::name( uint i ) const
685  { return m_actions.action(i)->name(); }
686 TQString KActionShortcutList::label( uint i ) const
687  { return m_actions.action(i)->text(); }
688 TQString KActionShortcutList::whatsThis( uint i ) const
689  { return m_actions.action(i)->whatsThis(); }
690 const KShortcut& KActionShortcutList::shortcut( uint i ) const
691  { return m_actions.action(i)->shortcut(); }
692 const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const
693  { return m_actions.action(i)->shortcutDefault(); }
694 bool KActionShortcutList::isConfigurable( uint i ) const
695  { return m_actions.action(i)->isShortcutConfigurable(); }
696 bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut )
697  { return m_actions.action(i)->setShortcut( cut ); }
698 const KInstance* KActionShortcutList::instance() const
699  { return m_actions.instance(); }
700 TQVariant KActionShortcutList::getOther( Other, uint ) const
701  { return TQVariant(); }
702 bool KActionShortcutList::setOther( Other, uint, TQVariant )
703  { return false; }
704 const KAction *KActionShortcutList::action( uint i) const
705  { return m_actions.action(i); }
706 
707 bool KActionShortcutList::save() const
708 {
709  const KXMLGUIClient* guiClient=m_actions.parentGUIClient();
710  const TQString xmlFile=guiClient ? guiClient->xmlFile() : m_actions.xmlFile();
711  kdDebug(129) << "KActionShortcutList::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 // KActionPtrShortcutList
760 //---------------------------------------------------------------------
761 
762 KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list )
763 : m_actions( list )
764  { }
765 KActionPtrShortcutList::~KActionPtrShortcutList()
766  { }
767 uint KActionPtrShortcutList::count() const
768  { return m_actions.count(); }
769 TQString KActionPtrShortcutList::name( uint i ) const
770  { return m_actions[i]->name(); }
771 TQString KActionPtrShortcutList::label( uint i ) const
772  { return m_actions[i]->text(); }
773 TQString KActionPtrShortcutList::whatsThis( uint i ) const
774  { return m_actions[i]->whatsThis(); }
775 const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const
776  { return m_actions[i]->shortcut(); }
777 const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const
778  { return m_actions[i]->shortcutDefault(); }
779 bool KActionPtrShortcutList::isConfigurable( uint i ) const
780  { return m_actions[i]->isShortcutConfigurable(); }
781 bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut )
782  { return m_actions[i]->setShortcut( cut ); }
783 TQVariant KActionPtrShortcutList::getOther( Other, uint ) const
784  { return TQVariant(); }
785 bool KActionPtrShortcutList::setOther( Other, uint, TQVariant )
786  { return false; }
787 bool KActionPtrShortcutList::save() const
788  { return false; }
789 
790 void KActionShortcutList::virtual_hook( int id, void* data )
791 { KShortcutList::virtual_hook( id, data ); }
792 
793 void KActionPtrShortcutList::virtual_hook( int id, void* data )
794 { KShortcutList::virtual_hook( id, data ); }
795 
796 void KActionCollection::virtual_hook( int, void* )
797 { /*BASE::virtual_hook( id, data );*/ }
798 
799 /* vim: et sw=2 ts=2
800  */
801 
802 #include "kactioncollection.moc"
KAccel
KActionCollection
A managed set of KAction objects.
Definition: kactioncollection.h:79
KActionCollection::insert
void insert(KAction *action)
Add an action to the collection.
Definition: kactioncollection.cpp:365
KActionCollection::builderKAccel
KAccel * builderKAccel() const
Definition: kactioncollection.cpp:371
KActionCollection::connectHighlight
void connectHighlight(TQWidget *container, KAction *action)
Call this function if you want to receive a signal whenever a KAction is highlighted in a menu or a t...
Definition: kactioncollection.cpp:493
KActionCollection::xmlFile
const TQString & xmlFile() const
Definition: kactioncollection.cpp:478
KActionCollection::kaccel
KAccel * kaccel()
Returns the KAccel object of the most recently set widget.
Definition: kactioncollection.cpp:282
KActionCollection::setWidget
virtual void setWidget(TQWidget *widget)
This sets the widget to which the keyboard shortcuts should be attached.
Definition: kactioncollection.cpp:152
KActionCollection::actions
virtual KActionPtrList actions() const
Returns the list of actions managed by this action collection.
Definition: kactioncollection.cpp:449
KActionCollection::actionHighlighted
void actionHighlighted(KAction *action)
Emitted when action is highlighted.
KActionCollection::readShortcutSettings
bool readShortcutSettings(const TQString &sConfigGroup=TQString::null, KConfigBase *pConfig=0)
Used for reading shortcut configuration from a non-XML rc file.
Definition: kactioncollection.cpp:408
KActionCollection::remove
void remove(KAction *action)
Removes an action from the collection and deletes it.
Definition: kactioncollection.cpp:366
KActionCollection::action
virtual KAction * action(int index) const
Return the KAction* at position "index" in the action collection.
Definition: kactioncollection.cpp:400
KActionCollection::clear
void clear()
Clears the entire actionCollection, deleting all actions.
Definition: kactioncollection.cpp:368
KActionCollection::clearStatusText
void clearStatusText()
Emitted when an action loses highlighting.
KActionCollection::accel
virtual KAccel * accel() KDE_DEPRECATED
Returns the number of widgets which this collection is associated with.
Definition: kactioncollection.cpp:369
KActionCollection::parentGUIClient
const KXMLGUIClient * parentGUIClient() const
The parent KXMLGUIClient, return 0L if not available.
Definition: kactioncollection.cpp:627
KActionCollection::setAutoConnectShortcuts
void setAutoConnectShortcuts(bool)
This indicates whether new actions which are created in this collection should have their keyboard sh...
Definition: kactioncollection.cpp:167
KActionCollection::setHighlightingEnabled
void setHighlightingEnabled(bool enable)
Enable highlighting notification for specific KActions.
Definition: kactioncollection.cpp:483
KActionCollection::writeShortcutSettings
bool writeShortcutSettings(const TQString &sConfigGroup=TQString::null, KConfigBase *pConfig=0) const
Used for writing shortcut configuration to a non-XML rc file.
Definition: kactioncollection.cpp:413
KActionCollection::instance
KInstance * instance() const
The instance with which this class is associated.
Definition: kactioncollection.cpp:468
KActionCollection::actionStatusText
void actionStatusText(const TQString &text)
Emitted when an action is highlighted, with text being the tooltip for the action.
KActionCollection::setXMLFile
void setXMLFile(const TQString &)
Definition: kactioncollection.cpp:473
KActionCollection::disconnectHighlight
void disconnectHighlight(TQWidget *container, KAction *action)
Disconnect highlight notifications for a particular pair of contianer and action.
Definition: kactioncollection.cpp:526
KActionCollection::actions
virtual KActionPtrList actions(const TQString &group) const
Returns the list of actions in a particular group managed by this action collection.
Definition: kactioncollection.cpp:435
KActionCollection::take
KAction * take(KAction *action)
Removes an action from the collection.
Definition: kactioncollection.cpp:367
KActionCollection::count
virtual uint count() const
Returns the KAccel object associated with widget #.
Definition: kactioncollection.cpp:418
KActionCollection::groups
virtual TQStringList groups() const
Returns a list of all the groups of all the KActions in this action collection.
Definition: kactioncollection.cpp:423
KActionCollection::highlightingEnabled
bool highlightingEnabled() const
Return whether highlighting notifications are enabled.
Definition: kactioncollection.cpp:488
KActionCollection::isAutoConnectShortcuts
bool isAutoConnectShortcuts()
This indicates whether new actions which are created in this collection have their keyboard shortcuts...
Definition: kactioncollection.cpp:172
KActionCollection::addDocCollection
bool addDocCollection(KActionCollection *pDoc)
This sets the default shortcut scope for new actions created in this collection.
Definition: kactioncollection.cpp:177
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:203
KConfigBase
KGlobal::instance
static KInstance * instance()
KInstance
KShortcutList::virtual_hook
virtual void virtual_hook(int id, void *data)
KShortcut
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 KInstance * 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
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
KInstance * instance()
KStdAccel::name
TQString name(StdAccel id)
KStdAccel::shortcutDefault
KShortcut shortcutDefault(StdAccel id)
KStdAccel::shortcut
const KShortcut & shortcut(StdAccel id)
KStdAccel::copy
const KShortcut & copy()

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |