summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/kactioncollection.cpp
Unidiff
Diffstat (limited to 'microkde/kdeui/kactioncollection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/kactioncollection.cpp839
1 files changed, 839 insertions, 0 deletions
diff --git a/microkde/kdeui/kactioncollection.cpp b/microkde/kdeui/kactioncollection.cpp
new file mode 100644
index 0000000..b819e76
--- a/dev/null
+++ b/microkde/kdeui/kactioncollection.cpp
@@ -0,0 +1,839 @@
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., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
24*/
25
26#include "kactioncollection.h"
27//US#include "kactionshortcutlist.h"
28
29#include <qptrdict.h>
30//US#include <qvariant.h>
31
32//US#include <kaccel.h>
33//US#include <kaccelbase.h>
34//US#include <kapplication.h>
35#include <kdebug.h>
36//US#include <kxmlguifactory.h>
37
38//US I included the following files
39#include <qasciidict.h>
40#include <qptrlist.h>
41#include "kaction.h"
42#include <kglobal.h>
43#include <qobject.h>
44#include <qwidget.h>
45
46class KActionCollection::KActionCollectionPrivate
47{
48public:
49 KActionCollectionPrivate()
50 {
51//US m_instance = 0;
52 //m_bOneKAccelOnly = false;
53 //m_iWidgetCurrent = 0;
54 m_bAutoConnectShortcuts = true;
55 m_widget = 0;
56 m_kaccel = m_builderKAccel = 0;
57 m_dctHighlightContainers.setAutoDelete( true );
58 m_highlight = false;
59 m_currentHighlightAction = 0;
60 m_statusCleared = true;
61 }
62
63//US KInstance *m_instance;
64//US QString m_sXMLFile;
65 bool m_bAutoConnectShortcuts;
66 //bool m_bOneKAccelOnly;
67 //int m_iWidgetCurrent;
68 //QValueList<QWidget*> m_widgetList;
69 //QValueList<KAccel*> m_kaccelList;
70 QValueList<KActionCollection*> m_docList;
71 QWidget *m_widget;
72 KAccel *m_kaccel;
73 KAccel *m_builderKAccel;
74
75 QAsciiDict<KAction> m_actionDict;
76 QPtrDict< QPtrList<KAction> > m_dctHighlightContainers;
77 bool m_highlight;
78 KAction *m_currentHighlightAction;
79 bool m_statusCleared;
80};
81
82KActionCollection::KActionCollection( QWidget *parent, const char *name /*US,
83 KInstance *instance */)
84 : QObject( (QObject*)parent, name )
85{
86 kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis
87 d = new KActionCollectionPrivate;
88 if( parent )
89 setWidget( parent );
90 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
91//US setInstance( instance );
92}
93
94
95KActionCollection::KActionCollection( QWidget *watch, QObject* parent, const char *name /*US,
96 KInstance *instance */)
97 : QObject( parent, name )
98{
99 kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis
100 d = new KActionCollectionPrivate;
101 if( watch )
102 setWidget( watch );
103 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
104//US setInstance( instance );
105}
106
107// KDE 4: remove
108KActionCollection::KActionCollection( QObject *parent, const char *name /*US,
109 KInstance *instance */)
110 : QObject( parent, name )
111{
112 kdWarning(129) << "KActionCollection::KActionCollection( QObject *parent, const char *name, KInstance *instance )" << endl; //ellis
113//US kdBacktrace not available
114//US kdDebug(129) << kdBacktrace() << endl;
115 d = new KActionCollectionPrivate;
116//US QWidget* w = dynamic_cast<QWidget*>( parent );
117 QWidget* w = (QWidget*)( parent );
118 if( w )
119 setWidget( w );
120 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
121//US setInstance( instance );
122}
123
124KActionCollection::KActionCollection( const KActionCollection &copy )
125 : QObject()
126{
127 kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl;
128 d = new KActionCollectionPrivate;
129 *this = copy;
130}
131// KDE 4: remove end
132
133KActionCollection::~KActionCollection()
134{
135 kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl;
136 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
137 KAction* pAction = it.current();
138 if ( pAction->m_parentCollection == this )
139 pAction->m_parentCollection = 0L;
140 }
141
142//US delete d->m_kaccel;
143//US delete d->m_builderKAccel;
144 delete d; d = 0;
145}
146
147void KActionCollection::setWidget( QWidget* w )
148{
149 //if ( d->m_actionDict.count() > 0 ) {
150 // kdError(129) << "KActionCollection::setWidget(): must be called before any actions are added to collection!" << endl;
151 // kdDebug(129) << kdBacktrace() << endl;
152 //}
153 //else
154 if ( !d->m_widget ) {
155 d->m_widget = w;
156 qDebug("KActionCollection::setWidget: warning: KAccel is never used in microkde");
157//US d->m_kaccel = new KAccel( w, this, "KActionCollection-KAccel" );
158 }
159 else if ( d->m_widget != w )
160 kdWarning(129) << "KActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl;
161}
162
163void KActionCollection::setAutoConnectShortcuts( bool b )
164{
165 d->m_bAutoConnectShortcuts = b;
166}
167
168bool KActionCollection::isAutoConnectShortcuts()
169{
170 return d->m_bAutoConnectShortcuts;
171}
172
173bool KActionCollection::addDocCollection( KActionCollection* pDoc )
174{
175 d->m_docList.append( pDoc );
176 return true;
177}
178
179void KActionCollection::beginXMLPlug( QWidget *widget )
180{
181 qDebug("KActionCollection::beginXMLPlug has to be fixed");
182/*US
183 kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl;
184
185 if( widget && !d->m_builderKAccel ) {
186 d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" );
187 }
188*/
189}
190
191void KActionCollection::endXMLPlug()
192{
193 kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl;
194 //s_kaccelXML = 0;
195}
196
197void KActionCollection::prepareXMLUnplug()
198{
199 qDebug("KActionCollection::prepareXMLUnplug has to be fixed");
200/*US
201 kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl;
202 unplugShortcuts( d->m_kaccel );
203
204 if( d->m_builderKAccel ) {
205 unplugShortcuts( d->m_builderKAccel );
206 delete d->m_builderKAccel;
207 d->m_builderKAccel = 0;
208 }
209*/
210}
211
212void KActionCollection::unplugShortcuts( KAccel* kaccel )
213{
214 qDebug("KActionCollection::unplugShortcuts has to be fixed");
215/*US
216 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
217 KAction* pAction = it.current();
218 pAction->removeKAccel( kaccel );
219 }
220
221 for( uint i = 0; i < d->m_docList.count(); i++ )
222 d->m_docList[i]->unplugShortcuts( kaccel );
223*/
224
225}
226
227/*void KActionCollection::addWidget( QWidget* w )
228{
229 if( !d->m_bOneKAccelOnly ) {
230 kdDebug(129) << "KActionCollection::addWidget( " << w << " ): this = " << this << endl;
231 for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
232 if( d->m_widgetList[i] == w ) {
233 d->m_iWidgetCurrent = i;
234 return;
235 }
236 }
237 d->m_iWidgetCurrent = d->m_widgetList.count();
238 d->m_widgetList.append( w );
239 d->m_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) );
240 }
241}
242
243void KActionCollection::removeWidget( QWidget* w )
244{
245 if( !d->m_bOneKAccelOnly ) {
246 kdDebug(129) << "KActionCollection::removeWidget( " << w << " ): this = " << this << endl;
247 for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
248 if( d->m_widgetList[i] == w ) {
249 // Remove KAccel object from children.
250 KAccel* pKAccel = d->m_kaccelList[i];
251 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
252 KAction* pAction = it.current();
253 if ( pAction->m_parentCollection == this ) {
254 pAction->removeKAccel( pKAccel );
255 }
256 }
257 delete pKAccel;
258
259 d->m_widgetList.remove( d->m_widgetList.at( i ) );
260 d->m_kaccelList.remove( d->m_kaccelList.at( i ) );
261
262 if( d->m_iWidgetCurrent == (int)i )
263 d->m_iWidgetCurrent = -1;
264 else if( d->m_iWidgetCurrent > (int)i )
265 d->m_iWidgetCurrent--;
266 return;
267 }
268 }
269 kdWarning(129) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl;
270 }
271}
272
273bool KActionCollection::ownsKAccel() const
274{
275 return d->m_bOneKAccelOnly;
276}
277
278uint KActionCollection::widgetCount() const
279{
280 return d->m_widgetList.count();
281}
282
283const KAccel* KActionCollection::widgetKAccel( uint i ) const
284{
285 return d->m_kaccelList[i];
286}*/
287
288//US we are using no accelerators so far. So just setup an empty implementation.
289KAccel* KActionCollection::kaccel()
290{
291 //if( d->m_kaccelList.count() > 0 )
292 // return d->m_kaccelList[d->m_iWidgetCurrent];
293 //else
294 // return 0;
295//US return d->m_kaccel;
296 return 0;
297}
298
299//US we are using no accelerators so far. So just setup an empty implementation.
300const KAccel* KActionCollection::kaccel() const
301{
302 //if( d->m_kaccelList.count() > 0 )
303 // return d->m_kaccelList[d->m_iWidgetCurrent];
304 //else
305 // return 0;
306 //USreturn d->m_kaccel;
307 return 0;
308}
309
310/*void KActionCollection::findMainWindow( QWidget *w )
311{
312 // Note: topLevelWidget() stops too early, we can't use it.
313 QWidget * tl = w;
314 while ( tl->parentWidget() ) // lookup parent and store
315 tl = tl->parentWidget();
316
317 KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow
318 if (mw)
319 d->m_mainwindow = mw;
320 else
321 kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl;
322}*/
323
324void KActionCollection::_insert( KAction* action )
325{
326 char unnamed_name[100];
327 const char *name = action->name();
328 if( qstrcmp( name, "unnamed" ) == 0 )
329 {
330 sprintf(unnamed_name, "unnamed-%p", (void *)action);
331 name = unnamed_name;
332 }
333 KAction *a = d->m_actionDict[ name ];
334 if ( a == action )
335 return;
336
337 d->m_actionDict.insert( name, action );
338
339 emit inserted( action );
340}
341
342void KActionCollection::_remove( KAction* action )
343{
344 delete _take( action );
345}
346
347KAction* KActionCollection::_take( KAction* action )
348{
349 char unnamed_name[100];
350 const char *name = action->name();
351 if( qstrcmp( name, "unnamed" ) == 0 )
352 {
353 sprintf(unnamed_name, "unnamed-%p", (void *) action);
354 name = unnamed_name;
355 }
356
357 KAction *a = d->m_actionDict.take( name );
358 if ( !a || a != action )
359 return 0;
360
361 emit removed( action );
362 return a;
363}
364
365void KActionCollection::_clear()
366{
367 QAsciiDictIterator<KAction> it( d->m_actionDict );
368 while ( it.current() )
369 _remove( it.current() );
370}
371
372void KActionCollection::insert( KAction* action ) { _insert( action ); }
373void KActionCollection::remove( KAction* action ) { _remove( action ); }
374KAction* KActionCollection::take( KAction* action ) { return _take( action ); }
375void KActionCollection::clear() { _clear(); }
376KAccel* KActionCollection::accel() { return kaccel(); }
377const KAccel* KActionCollection::accel() const { return kaccel(); }
378KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; }
379
380KAction* KActionCollection::action( const char* name, const char* classname ) const
381{
382 KAction* pAction = 0;
383
384 if ( !classname && name )
385 pAction = d->m_actionDict[ name ];
386
387 else {
388 QAsciiDictIterator<KAction> it( d->m_actionDict );
389 for( ; it.current(); ++it )
390 {
391 if ( ( !name || strcmp( it.current()->name(), name ) == 0 ) &&
392 ( !classname || strcmp( it.current()->className(), classname ) == 0 ) ) {
393 pAction = it.current();
394 break;
395 }
396 }
397 }
398
399 if( !pAction ) {
400 for( uint i = 0; i < d->m_docList.count() && !pAction; i++ )
401 pAction = d->m_docList[i]->action( name, classname );
402 }
403
404 return pAction;
405}
406
407KAction* KActionCollection::action( int index ) const
408{
409 QAsciiDictIterator<KAction> it( d->m_actionDict );
410 it += index;
411 return it.current();
412// return d->m_actions.at( index );
413}
414/*US
415bool KActionCollection::readShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig )
416{
417 return KActionShortcutList(this).readSettings( sConfigGroup, pConfig );
418}
419
420bool KActionCollection::writeShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) const
421{
422 return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig );
423}
424*/
425uint KActionCollection::count() const
426{
427 return d->m_actionDict.count();
428}
429
430QStringList KActionCollection::groups() const
431{
432 QStringList lst;
433
434 QAsciiDictIterator<KAction> it( d->m_actionDict );
435 for( ; it.current(); ++it )
436 if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) )
437 lst.append( it.current()->group() );
438
439 return lst;
440}
441
442KActionPtrList KActionCollection::actions( const QString& group ) const
443{
444 KActionPtrList lst;
445
446 QAsciiDictIterator<KAction> it( d->m_actionDict );
447 for( ; it.current(); ++it )
448 if ( it.current()->group() == group )
449 lst.append( it.current() );
450 else if ( it.current()->group().isEmpty() && group.isEmpty() )
451 lst.append( it.current() );
452
453 return lst;
454}
455
456KActionPtrList KActionCollection::actions() const
457{
458 KActionPtrList lst;
459
460 QAsciiDictIterator<KAction> it( d->m_actionDict );
461 for( ; it.current(); ++it )
462 lst.append( it.current() );
463
464 return lst;
465}
466
467/*US we have no instance object. Use KGlobal instead
468void KActionCollection::setInstance( KInstance *instance )
469{
470 if ( instance )
471 d->m_instance = instance;
472qDebug("KActionCollection::setInstance has to be fixed");
473 else
474 d->m_instance = KGlobal::instance();
475}
476
477KInstance *KActionCollection::instance() const
478{
479 return d->m_instance;
480}
481*/
482
483/*US we have no XML facility in microkde
484void KActionCollection::setXMLFile( const QString& sXMLFile )
485{
486 d->m_sXMLFile = sXMLFile;
487}
488
489const QString& KActionCollection::xmlFile() const
490{
491 return d->m_sXMLFile;
492}
493*/
494
495void KActionCollection::setHighlightingEnabled( bool enable )
496{
497 d->m_highlight = enable;
498}
499
500bool KActionCollection::highlightingEnabled() const
501{
502 return d->m_highlight;
503}
504
505void KActionCollection::connectHighlight( QWidget *container, KAction *action )
506{
507 if ( !d->m_highlight )
508 return;
509
510 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ];
511
512 if ( !actionList )
513 {
514 actionList = new QPtrList<KAction>;
515
516 if ( container->inherits( "QPopupMenu" ) )
517 {
518 connect( container, SIGNAL( highlighted( int ) ),
519 this, SLOT( slotMenuItemHighlighted( int ) ) );
520 connect( container, SIGNAL( aboutToHide() ),
521 this, SLOT( slotMenuAboutToHide() ) );
522 }
523//US else if ( container->inherits( "KToolBar" ) )
524 else if ( container->inherits( "QToolBar" ) )
525 {
526 connect( container, SIGNAL( highlighted( int, bool ) ),
527 this, SLOT( slotToolBarButtonHighlighted( int, bool ) ) );
528 }
529
530 connect( container, SIGNAL( destroyed() ),
531 this, SLOT( slotDestroyed() ) );
532
533 d->m_dctHighlightContainers.insert( container, actionList );
534 }
535
536 actionList->append( action );
537}
538
539void KActionCollection::disconnectHighlight( QWidget *container, KAction *action )
540{
541 if ( !d->m_highlight )
542 return;
543
544 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ];
545
546 if ( !actionList )
547 return;
548
549 actionList->removeRef( action );
550
551 if ( actionList->count() == 0 )
552 d->m_dctHighlightContainers.remove( container );
553}
554
555void KActionCollection::slotMenuItemHighlighted( int id )
556{
557 if ( !d->m_highlight )
558 return;
559
560 if ( d->m_currentHighlightAction )
561 emit actionHighlighted( d->m_currentHighlightAction, false );
562
563 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) );
564
565 d->m_currentHighlightAction = findAction( container, id );
566
567 if ( !d->m_currentHighlightAction )
568 {
569 if ( !d->m_statusCleared )
570 emit clearStatusText();
571 d->m_statusCleared = true;
572 return;
573 }
574
575 d->m_statusCleared = false;
576 emit actionHighlighted( d->m_currentHighlightAction );
577 emit actionHighlighted( d->m_currentHighlightAction, true );
578 emit actionStatusText( d->m_currentHighlightAction->toolTip() );
579}
580
581void KActionCollection::slotMenuAboutToHide()
582{
583 if ( d->m_currentHighlightAction )
584 emit actionHighlighted( d->m_currentHighlightAction, false );
585 d->m_currentHighlightAction = 0;
586
587 if ( !d->m_statusCleared )
588 emit clearStatusText();
589 d->m_statusCleared = true;
590}
591
592void KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight )
593{
594 if ( !d->m_highlight )
595 return;
596
597 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) );
598
599 KAction *action = findAction( container, id );
600
601 if ( !action )
602 {
603 d->m_currentHighlightAction = 0;
604 // use tooltip groups for toolbar status text stuff instead (Simon)
605// emit clearStatusText();
606 return;
607 }
608
609 emit actionHighlighted( action, highlight );
610
611 if ( highlight )
612 d->m_currentHighlightAction = action;
613 else
614 {
615 d->m_currentHighlightAction = 0;
616// emit clearStatusText();
617 }
618}
619
620void KActionCollection::slotDestroyed()
621{
622 d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<QObject *>(sender()) ) );
623}
624
625KAction *KActionCollection::findAction( QWidget *container, int id )
626{
627 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ];
628
629 if ( !actionList )
630 return 0;
631
632 QPtrListIterator<KAction> it( *actionList );
633 for (; it.current(); ++it )
634 if ( it.current()->isPlugged( container, id ) )
635 return it.current();
636
637 return 0;
638}
639
640// KDE 4: remove
641KActionCollection KActionCollection::operator+(const KActionCollection &c ) const
642{
643 kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl;
644 KActionCollection ret( *this );
645
646 QValueList<KAction *> actions = c.actions();
647 QValueList<KAction *>::ConstIterator it = actions.begin();
648 QValueList<KAction *>::ConstIterator end = actions.end();
649 for (; it != end; ++it )
650 ret.insert( *it );
651
652 return ret;
653}
654
655KActionCollection &KActionCollection::operator=( const KActionCollection &copy )
656{
657 kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl;
658 //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly;
659 //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent;
660 //d->m_widgetList = copy.d->m_widgetList;
661 //d->m_kaccelList = copy.d->m_kaccelList;
662 d->m_widget = copy.d->m_widget;
663 d->m_kaccel = copy.d->m_kaccel;
664 d->m_actionDict = copy.d->m_actionDict;
665//US setInstance( copy.instance() );
666 return *this;
667}
668
669KActionCollection &KActionCollection::operator+=( const KActionCollection &c )
670{
671 kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl;
672 QAsciiDictIterator<KAction> it(c.d->m_actionDict);
673 for ( ; it.current(); ++it )
674 insert( it.current() );
675
676 return *this;
677}
678// KDE 4: remove end
679
680//---------------------------------------------------------------------
681// KActionShortcutList
682//---------------------------------------------------------------------
683/*US
684KActionShortcutList::KActionShortcutList( KActionCollection* pColl )
685: m_actions( *pColl )
686 { }
687KActionShortcutList::~KActionShortcutList()
688 { }
689uint KActionShortcutList::count() const
690 { return m_actions.count(); }
691QString KActionShortcutList::name( uint i ) const
692 { return m_actions.action(i)->name(); }
693QString KActionShortcutList::label( uint i ) const
694 { return m_actions.action(i)->text(); }
695QString KActionShortcutList::whatsThis( uint i ) const
696 { return m_actions.action(i)->whatsThis(); }
697const KShortcut& KActionShortcutList::shortcut( uint i ) const
698 { return m_actions.action(i)->shortcut(); }
699const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const
700 { return m_actions.action(i)->shortcutDefault(); }
701bool KActionShortcutList::isConfigurable( uint i ) const
702 { return m_actions.action(i)->isShortcutConfigurable(); }
703bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut )
704 { return m_actions.action(i)->setShortcut( cut ); }
705const KInstance* KActionShortcutList::instance() const
706 { return m_actions.instance(); }
707QVariant KActionShortcutList::getOther( Other, uint ) const
708 { return QVariant(); }
709bool KActionShortcutList::setOther( Other, uint, QVariant )
710 { return false; }
711
712bool KActionShortcutList::save() const
713{
714 kdDebug(129) << "KActionShortcutList::save(): xmlFile = " << m_actions.xmlFile() << endl;
715
716 if( m_actions.xmlFile().isEmpty() )
717 return writeSettings();
718
719 QString tagActionProp = QString::fromLatin1("ActionProperties");
720 QString tagAction = QString::fromLatin1("Action");
721 QString attrName = QString::fromLatin1("name");
722 QString attrShortcut = QString::fromLatin1("shortcut");
723 QString attrAccel = QString::fromLatin1("accel"); // Depricated attribute
724
725 // Read XML file
726 QString sXml( KXMLGUIFactory::readConfigFile( m_actions.xmlFile(), false, instance() ) );
727 QDomDocument doc;
728 doc.setContent( sXml );
729
730 // Process XML data
731
732 // first, lets see if we have existing properties
733 QDomElement elem;
734 QDomElement it = doc.documentElement();
735 // KXMLGUIFactory::removeDOMComments( it ); <-- What was this for? --ellis
736 it = it.firstChild().toElement();
737 for( ; !it.isNull(); it = it.nextSibling().toElement() ) {
738 if( it.tagName() == tagActionProp ) {
739 elem = it;
740 break;
741 }
742 }
743
744 // if there was none, create one
745 if( elem.isNull() ) {
746 elem = doc.createElement( tagActionProp );
747 doc.documentElement().appendChild( elem );
748 }
749
750 // now, iterate through our actions
751 uint nSize = count();
752 for( uint i = 0; i < nSize; i++ ) {
753 const QString& sName = name(i);
754
755 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
756 //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl;
757
758 // now see if this element already exists
759 QDomElement act_elem;
760 for( it = elem.firstChild().toElement(); !it.isNull(); it = it.nextSibling().toElement() ) {
761 if( it.attribute( attrName ) == sName ) {
762 act_elem = it;
763 break;
764 }
765 }
766
767 // nope, create a new one
768 if( act_elem.isNull() ) {
769 if( bSameAsDefault )
770 continue;
771 //kdDebug(129) << "\tnode doesn't exist." << endl;
772 act_elem = doc.createElement( tagAction );
773 act_elem.setAttribute( attrName, sName );
774 }
775
776 act_elem.removeAttribute( attrAccel );
777 if( bSameAsDefault ) {
778 act_elem.removeAttribute( attrShortcut );
779 //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl;
780 if( act_elem.attributes().count() == 1 )
781 elem.removeChild( act_elem );
782 } else {
783 act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() );
784 elem.appendChild( act_elem );
785 }
786 }
787
788 // Write back to XML file
789 return KXMLGUIFactory::saveConfigFile( doc, m_actions.xmlFile(), instance() );
790}
791
792//---------------------------------------------------------------------
793// KActionPtrShortcutList
794//---------------------------------------------------------------------
795
796KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list )
797: m_actions( list )
798 { }
799KActionPtrShortcutList::~KActionPtrShortcutList()
800 { }
801uint KActionPtrShortcutList::count() const
802 { return m_actions.count(); }
803QString KActionPtrShortcutList::name( uint i ) const
804 { return m_actions[i]->name(); }
805QString KActionPtrShortcutList::label( uint i ) const
806 { return m_actions[i]->text(); }
807QString KActionPtrShortcutList::whatsThis( uint i ) const
808 { return m_actions[i]->whatsThis(); }
809const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const
810 { return m_actions[i]->shortcut(); }
811const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const
812 { return m_actions[i]->shortcutDefault(); }
813bool KActionPtrShortcutList::isConfigurable( uint i ) const
814 { return m_actions[i]->isShortcutConfigurable(); }
815bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut )
816 { return m_actions[i]->setShortcut( cut ); }
817QVariant KActionPtrShortcutList::getOther( Other, uint ) const
818 { return QVariant(); }
819bool KActionPtrShortcutList::setOther( Other, uint, QVariant )
820 { return false; }
821bool KActionPtrShortcutList::save() const
822 { return false; }
823
824void KActionShortcutList::virtual_hook( int id, void* data )
825{ KShortcutList::virtual_hook( id, data ); }
826
827void KActionPtrShortcutList::virtual_hook( int id, void* data )
828{ KShortcutList::virtual_hook( id, data ); }
829*/
830
831void KActionCollection::virtual_hook( int, void* )
832{ /*BASE::virtual_hook( id, data );*/ }
833
834/* vim: et sw=2 ts=2
835 */
836
837/*US
838#include "kactioncollection.moc"
839*/