00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kxmlguiclient.h"
00021
#include "kxmlguifactory.h"
00022
#include "kxmlguibuilder.h"
00023
00024
#include <qdir.h>
00025
#include <qfile.h>
00026
#include <qdom.h>
00027
#include <qtextstream.h>
00028
#include <qregexp.h>
00029
#include <qguardedptr.h>
00030
00031
#include <kinstance.h>
00032
#include <kstandarddirs.h>
00033
#include <kdebug.h>
00034
#include <kaction.h>
00035
#include <kapplication.h>
00036
00037
#include <assert.h>
00038
00039
class KXMLGUIClientPrivate
00040 {
00041
public:
00042 KXMLGUIClientPrivate()
00043 {
00044 m_instance =
KGlobal::instance();
00045 m_parent = 0L;
00046 m_builder = 0L;
00047 m_actionCollection = 0;
00048 }
00049 ~KXMLGUIClientPrivate()
00050 {
00051 }
00052
00053
KInstance *m_instance;
00054
00055
QDomDocument m_doc;
00056
KActionCollection *m_actionCollection;
00057
QDomDocument m_buildDocument;
00058
QGuardedPtr<KXMLGUIFactory> m_factory;
00059
KXMLGUIClient *m_parent;
00060
00061
QPtrList<KXMLGUIClient> m_children;
00062
KXMLGUIBuilder *m_builder;
00063
QString m_xmlFile;
00064
QString m_localXMLFile;
00065 };
00066
00067 KXMLGUIClient::KXMLGUIClient()
00068 {
00069 d =
new KXMLGUIClientPrivate;
00070 }
00071
00072 KXMLGUIClient::KXMLGUIClient(
KXMLGUIClient *parent )
00073 {
00074 d =
new KXMLGUIClientPrivate;
00075 parent->
insertChildClient(
this );
00076 }
00077
00078 KXMLGUIClient::~KXMLGUIClient()
00079 {
00080
if ( d->m_parent )
00081 d->m_parent->removeChildClient(
this );
00082
00083
QPtrListIterator<KXMLGUIClient> it( d->m_children );
00084
for ( ; it.current(); ++it ) {
00085 assert( it.current()->d->m_parent ==
this );
00086 it.current()->d->m_parent = 0;
00087 }
00088
00089
delete d->m_actionCollection;
00090
delete d;
00091 }
00092
00093 KAction *
KXMLGUIClient::action(
const char *name )
const
00094
{
00095
KAction* act =
actionCollection()->
action( name );
00096
if ( !act ) {
00097
QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
00098
for (; childIt.current(); ++childIt ) {
00099 act = childIt.current()->actionCollection()->action( name );
00100
if ( act )
00101
break;
00102 }
00103 }
00104
return act;
00105 }
00106
00107 KActionCollection *
KXMLGUIClient::actionCollection()
const
00108
{
00109
if ( !d->m_actionCollection )
00110 {
00111 d->m_actionCollection =
new KActionCollection(
00112
"KXMLGUIClient-KActionCollection",
this );
00113 }
00114
return d->m_actionCollection;
00115 }
00116
00117 KAction *
KXMLGUIClient::action(
const QDomElement &element )
const
00118
{
00119
static const QString &attrName =
KGlobal::staticQString(
"name" );
00120
return actionCollection()->
action( element.attribute( attrName ).latin1() );
00121 }
00122
00123 KInstance *
KXMLGUIClient::instance()
const
00124
{
00125
return d->m_instance;
00126 }
00127
00128 QDomDocument KXMLGUIClient::domDocument()
const
00129
{
00130
return d->m_doc;
00131 }
00132
00133 QString KXMLGUIClient::xmlFile()
const
00134
{
00135
return d->m_xmlFile;
00136 }
00137
00138
QString KXMLGUIClient::localXMLFile()
const
00139
{
00140
if ( !d->m_localXMLFile.isEmpty() )
00141
return d->m_localXMLFile;
00142
00143
if ( d->m_xmlFile[0] ==
'/' )
00144
return QString::null;
00145
00146
return locateLocal(
"data", QString::fromLatin1(
instance()->instanceName() +
'/' ) + d->m_xmlFile );
00147 }
00148
00149
00150 void KXMLGUIClient::reloadXML()
00151 {
00152
QString file(
xmlFile() );
00153
if ( !file.isEmpty() )
00154
setXMLFile( file );
00155 }
00156
00157 void KXMLGUIClient::setInstance(
KInstance *instance )
00158 {
00159 d->m_instance = instance;
00160
actionCollection()->
setInstance( instance );
00161
if ( d->m_builder )
00162 d->m_builder->setBuilderClient(
this );
00163 }
00164
00165 void KXMLGUIClient::setXMLFile(
const QString& _file,
bool merge,
bool setXMLDoc )
00166 {
00167
00168
if ( !_file.isNull() ) {
00169 d->m_xmlFile = _file;
00170
actionCollection()->
setXMLFile( _file );
00171 }
00172
00173
if ( !setXMLDoc )
00174
return;
00175
00176
QString file = _file;
00177
if ( file[0] !=
'/' )
00178 {
00179
QString doc;
00180
00181
QString filter = QString::fromLatin1(
instance()->instanceName() +
'/' ) + _file;
00182
00183
QStringList allFiles =
instance()->
dirs()->
findAllResources(
"data", filter ) +
instance()->
dirs()->
findAllResources(
"data", _file );
00184
00185 file = findMostRecentXMLFile( allFiles, doc );
00186
00187
if ( file.isEmpty() )
00188 {
00189
00190
00191
00192
00193
00194
00195
if ( !_file.isEmpty() )
00196
kdWarning() <<
"KXMLGUIClient::setXMLFile: cannot find .rc file " << _file <<
endl;
00197
00198
setXML( QString::null,
true );
00199
return;
00200 }
00201
else if ( !doc.isEmpty() )
00202 {
00203
setXML( doc, merge );
00204
return;
00205 }
00206 }
00207
00208
QString xml = KXMLGUIFactory::readConfigFile( file );
00209
setXML( xml, merge );
00210 }
00211
00212
void KXMLGUIClient::setLocalXMLFile(
const QString &file )
00213 {
00214 d->m_localXMLFile = file;
00215 }
00216
00217 void KXMLGUIClient::setXML(
const QString &document,
bool merge )
00218 {
00219
QDomDocument doc;
00220 doc.setContent( document );
00221
setDOMDocument( doc, merge );
00222 }
00223
00224 void KXMLGUIClient::setDOMDocument(
const QDomDocument &document,
bool merge )
00225 {
00226
if ( merge )
00227 {
00228
QDomElement base = d->m_doc.documentElement();
00229
00230
QDomElement e = document.documentElement();
00231
00232
00233 mergeXML(base, e,
actionCollection());
00234
00235
00236
00237 base = d->m_doc.documentElement();
00238
00239
00240
if ( base.isNull() )
00241 d->m_doc = document;
00242 }
00243
else
00244 {
00245 d->m_doc = document;
00246 }
00247
00248 setXMLGUIBuildDocument(
QDomDocument() );
00249 }
00250
00251
bool KXMLGUIClient::mergeXML(
QDomElement &base,
const QDomElement &additive,
KActionCollection *actionCollection )
00252 {
00253
static const QString &tagAction =
KGlobal::staticQString(
"Action" );
00254
static const QString &tagMerge =
KGlobal::staticQString(
"Merge" );
00255
static const QString &tagSeparator =
KGlobal::staticQString(
"Separator" );
00256
static const QString &attrName =
KGlobal::staticQString(
"name" );
00257
static const QString &attrAppend =
KGlobal::staticQString(
"append" );
00258
static const QString &attrWeakSeparator =
KGlobal::staticQString(
"weakSeparator" );
00259
static const QString &tagMergeLocal =
KGlobal::staticQString(
"MergeLocal" );
00260
static const QString &tagText =
KGlobal::staticQString(
"text" );
00261
static const QString &attrAlreadyVisited =
KGlobal::staticQString(
"alreadyVisited" );
00262
static const QString &attrNoMerge =
KGlobal::staticQString(
"noMerge" );
00263
static const QString &attrOne =
KGlobal::staticQString(
"1" );
00264
00265
00266
00267
00268
00269
00270
if ( additive.attribute(attrNoMerge) == attrOne )
00271 {
00272 base.parentNode().replaceChild(additive, base);
00273
return true;
00274 }
00275
00276
QString tag;
00277
00278
00279
QDomNode n = base.firstChild();
00280
while ( !n.isNull() )
00281 {
00282
QDomElement e = n.toElement();
00283 n = n.nextSibling();
00284
if (e.isNull())
00285
continue;
00286
00287 tag = e.tagName();
00288
00289
00290
00291
if ( tag == tagAction )
00292 {
00293
QCString name = e.attribute( attrName ).utf8();
00294
if ( !actionCollection->
action( name ) ||
00295 (kapp && !kapp->authorizeKAction(name)))
00296 {
00297
00298 base.removeChild( e );
00299
continue;
00300 }
00301 }
00302
00303
00304
00305
else if ( tag == tagSeparator )
00306 {
00307 e.setAttribute( attrWeakSeparator, (uint)1 );
00308
00309
00310
00311
00312
QDomElement prev = e.previousSibling().toElement();
00313
if ( prev.isNull() ||
00314 ( prev.tagName() == tagSeparator && !prev.attribute( attrWeakSeparator ).isNull() ) ||
00315 ( prev.tagName() == tagText ) )
00316 {
00317
00318 base.removeChild( e );
00319
continue;
00320 }
00321 }
00322
00323
00324
00325
00326
else if ( tag == tagMergeLocal )
00327 {
00328
QDomNode it = additive.firstChild();
00329
while ( !it.isNull() )
00330 {
00331
QDomElement newChild = it.toElement();
00332 it = it.nextSibling();
00333
if (newChild.isNull() )
00334
continue;
00335
00336
if ( newChild.tagName() == tagText )
00337
continue;
00338
00339
if ( newChild.attribute( attrAlreadyVisited ) == attrOne )
00340
continue;
00341
00342
QString itAppend( newChild.attribute( attrAppend ) );
00343
QString elemName( e.attribute( attrName ) );
00344
00345
if ( ( itAppend.isNull() && elemName.isEmpty() ) ||
00346 ( itAppend == elemName ) )
00347 {
00348
00349
00350
00351
QDomElement matchingElement = findMatchingElement( newChild, base );
00352
if ( matchingElement.isNull() || newChild.tagName() == tagSeparator )
00353 base.insertBefore( newChild, e );
00354 }
00355 }
00356
00357 base.removeChild( e );
00358
continue;
00359 }
00360
00361
00362
00363
00364
00365
else if ( tag != tagMerge )
00366 {
00367
00368
if ( tag == tagText )
00369
continue;
00370
00371
QDomElement matchingElement = findMatchingElement( e, additive );
00372
00373
if ( !matchingElement.isNull() )
00374 {
00375 matchingElement.setAttribute( attrAlreadyVisited, (uint)1 );
00376
00377
if ( mergeXML( e, matchingElement, actionCollection ) )
00378 {
00379 base.removeChild( e );
00380
continue;
00381 }
00382
00383
00384
QDomNamedNodeMap attribs = matchingElement.attributes();
00385
for(uint i = 0; i < attribs.count(); i++)
00386 {
00387
QDomNode node = attribs.item(i);
00388 e.setAttribute(node.nodeName(), node.nodeValue());
00389 }
00390
00391
continue;
00392 }
00393
else
00394 {
00395
00396
00397
00398
00399
00400
if ( mergeXML( e,
QDomElement(), actionCollection ) )
00401 base.removeChild( e );
00402
continue;
00403 }
00404 }
00405 }
00406
00407
00408
00409 n = additive.firstChild();
00410
while ( !n.isNull() )
00411 {
00412
QDomElement e = n.toElement();
00413 n = n.nextSibling();
00414
if (e.isNull())
00415
continue;
00416
00417
QDomElement matchingElement = findMatchingElement( e, base );
00418
00419
if ( matchingElement.isNull() )
00420 {
00421 base.appendChild( e );
00422 }
00423 }
00424
00425
00426
00427
QDomElement last = base.lastChild().toElement();
00428
if ( (last.tagName() == tagSeparator) && (!last.attribute( attrWeakSeparator ).isNull()) )
00429 {
00430 base.removeChild( last );
00431 }
00432
00433
00434
00435
00436
bool deleteMe =
true;
00437
00438 n = base.firstChild();
00439
while ( !n.isNull() )
00440 {
00441
QDomElement e = n.toElement();
00442 n = n.nextSibling();
00443
if (e.isNull())
00444
continue;
00445
00446 tag = e.tagName();
00447
00448
if ( tag == tagAction )
00449 {
00450
00451
00452
00453
if ( actionCollection->
action( e.attribute( attrName ).utf8() ) )
00454 {
00455 deleteMe =
false;
00456
break;
00457 }
00458 }
00459
else if ( tag == tagSeparator )
00460 {
00461
00462
00463
00464
QString weakAttr = e.attribute( attrWeakSeparator );
00465
if ( weakAttr.isEmpty() || weakAttr.toInt() != 1 )
00466 {
00467 deleteMe =
false;
00468
break;
00469 }
00470 }
00471
00472
00473
else if ( tag == tagMerge )
00474 {
00475
00476
00477
continue;
00478 }
00479
00480
00481
else if ( tag == tagText )
00482 {
00483
continue;
00484 }
00485
00486
00487
00488
00489
00490
else
00491 {
00492 deleteMe =
false;
00493
break;
00494 }
00495 }
00496
00497
return deleteMe;
00498 }
00499
00500
QDomElement KXMLGUIClient::findMatchingElement(
const QDomElement &base,
const QDomElement &additive )
00501 {
00502
static const QString &tagAction =
KGlobal::staticQString(
"Action" );
00503
static const QString &tagMergeLocal =
KGlobal::staticQString(
"MergeLocal" );
00504
static const QString &attrName =
KGlobal::staticQString(
"name" );
00505
00506
QDomNode n = additive.firstChild();
00507
while ( !n.isNull() )
00508 {
00509
QDomElement e = n.toElement();
00510 n = n.nextSibling();
00511
if (e.isNull())
00512
continue;
00513
00514
00515
if ( ( e.tagName() == tagAction ) || ( e.tagName() == tagMergeLocal ) )
00516 {
00517
continue;
00518 }
00519
00520
00521
if ( ( e.tagName() == base.tagName() ) &&
00522 ( e.attribute( attrName ) == base.attribute( attrName ) ) )
00523 {
00524
return e;
00525 }
00526 }
00527
00528
00529
return QDomElement();
00530 }
00531
00532 void KXMLGUIClient::conserveMemory()
00533 {
00534 d->m_doc =
QDomDocument();
00535 d->m_buildDocument =
QDomDocument();
00536 }
00537
00538
void KXMLGUIClient::setXMLGUIBuildDocument(
const QDomDocument &doc )
00539 {
00540 d->m_buildDocument = doc;
00541 }
00542
00543
QDomDocument KXMLGUIClient::xmlguiBuildDocument()
const
00544
{
00545
return d->m_buildDocument;
00546 }
00547
00548 void KXMLGUIClient::setFactory(
KXMLGUIFactory *factory )
00549 {
00550 d->m_factory = factory;
00551 }
00552
00553 KXMLGUIFactory *
KXMLGUIClient::factory()
const
00554
{
00555
return d->m_factory;
00556 }
00557
00558 KXMLGUIClient *
KXMLGUIClient::parentClient()
const
00559
{
00560
return d->m_parent;
00561 }
00562
00563 void KXMLGUIClient::insertChildClient(
KXMLGUIClient *child )
00564 {
00565
if ( child->
d->m_parent )
00566 child->
d->m_parent->removeChildClient( child );
00567 d->m_children.append( child );
00568 child->
d->m_parent =
this;
00569 }
00570
00571 void KXMLGUIClient::removeChildClient(
KXMLGUIClient *child )
00572 {
00573 assert( d->m_children.containsRef( child ) );
00574 d->m_children.removeRef( child );
00575 child->
d->m_parent = 0;
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 const QPtrList<KXMLGUIClient> *
KXMLGUIClient::childClients()
00587 {
00588
return &d->m_children;
00589 }
00590
00591 void KXMLGUIClient::setClientBuilder(
KXMLGUIBuilder *builder )
00592 {
00593 d->m_builder = builder;
00594
if ( builder )
00595 builder->
setBuilderInstance(
instance() );
00596 }
00597
00598 KXMLGUIBuilder *
KXMLGUIClient::clientBuilder()
const
00599
{
00600
return d->m_builder;
00601 }
00602
00603 void KXMLGUIClient::plugActionList(
const QString &name,
const QPtrList<KAction> &actionList )
00604 {
00605
if ( !d->m_factory )
00606
return;
00607
00608 d->m_factory->plugActionList(
this, name, actionList );
00609 }
00610
00611 void KXMLGUIClient::unplugActionList(
const QString &name )
00612 {
00613
if ( !d->m_factory )
00614
return;
00615
00616 d->m_factory->unplugActionList(
this, name );
00617 }
00618
00619
QString KXMLGUIClient::findMostRecentXMLFile(
const QStringList &files,
QString &doc )
00620 {
00621
00622
QValueList<DocStruct> allDocuments;
00623
00624 QStringList::ConstIterator it = files.begin();
00625 QStringList::ConstIterator end = files.end();
00626
for (; it != end; ++it )
00627 {
00628
00629
QString data = KXMLGUIFactory::readConfigFile( *it );
00630 DocStruct d;
00631 d.file = *it;
00632 d.data = data;
00633 allDocuments.append( d );
00634 }
00635
00636
QValueList<DocStruct>::Iterator best = allDocuments.end();
00637 uint bestVersion = 0;
00638
00639
QValueList<DocStruct>::Iterator docIt = allDocuments.begin();
00640
QValueList<DocStruct>::Iterator docEnd = allDocuments.end();
00641
for (; docIt != docEnd; ++docIt )
00642 {
00643
QString versionStr = findVersionNumber( (*docIt).data );
00644
if ( versionStr.isEmpty() )
00645
continue;
00646
00647
bool ok =
false;
00648 uint
version = versionStr.toUInt( &ok );
00649
if ( !ok )
00650
continue;
00651
00652
00653
if (
version > bestVersion )
00654 {
00655 best = docIt;
00656
00657 bestVersion =
version;
00658 }
00659 }
00660
00661
if ( best != docEnd )
00662 {
00663
if ( best != allDocuments.begin() )
00664 {
00665
QValueList<DocStruct>::Iterator local = allDocuments.begin();
00666
00667
00668
QDomDocument document;
00669 document.setContent( (*local).data );
00670
00671 ActionPropertiesMap properties = extractActionProperties( document );
00672
00673
00674
00675
00676
if ( !properties.isEmpty() )
00677 {
00678
00679
00680 document.setContent( (*best).data );
00681
00682 storeActionProperties( document, properties );
00683
00684 (*local).data = document.toString();
00685
00686 best = local;
00687
00688
00689
QFile f( (*local).file );
00690
if ( f.open( IO_WriteOnly ) )
00691 {
00692
QCString utf8data = (*local).data.utf8();
00693 f.writeBlock( utf8data.data(), utf8data.length() );
00694 f.close();
00695 }
00696 }
00697
else
00698 {
00699
QString f = (*local).file;
00700
QString backup = f + QString::fromLatin1(
".backup" );
00701
QDir dir;
00702 dir.rename( f, backup );
00703 }
00704 }
00705 doc = (*best).data;
00706
return (*best).file;
00707 }
00708
else if ( files.count() > 0 )
00709 {
00710
00711 doc = (*allDocuments.begin()).data;
00712
return (*allDocuments.begin()).file;
00713 }
00714
00715
return QString::null;
00716 }
00717
00718
00719
00720
QString KXMLGUIClient::findVersionNumber(
const QString &xml )
00721 {
00722
enum { ST_START, ST_AFTER_OPEN, ST_AFTER_GUI,
00723 ST_EXPECT_VERSION, ST_VERSION_NUM} state = ST_START;
00724
for (
unsigned int pos = 0; pos < xml.length(); pos++)
00725 {
00726
switch (state)
00727 {
00728
case ST_START:
00729
if (xml[pos] ==
'<')
00730 state = ST_AFTER_OPEN;
00731
break;
00732
case ST_AFTER_OPEN:
00733 {
00734
00735
int guipos = xml.find(
"gui", pos,
false );
00736
if (guipos == -1)
00737
return QString::null;
00738
00739 pos = guipos + 2;
00740 state = ST_AFTER_GUI;
00741
break;
00742 }
00743
case ST_AFTER_GUI:
00744 state = ST_EXPECT_VERSION;
00745
break;
00746
case ST_EXPECT_VERSION:
00747 {
00748
int verpos = xml.find(
"version=\"", pos,
false );
00749
if (verpos == -1)
00750
return QString::null;
00751
00752 pos = verpos + 8;
00753 state = ST_VERSION_NUM;
00754
break;
00755 }
00756
case ST_VERSION_NUM:
00757 {
00758
unsigned int endpos;
00759
for (endpos = pos; endpos < xml.length(); endpos++)
00760 {
00761
if (xml[endpos].unicode() >=
'0' && xml[endpos].unicode() <=
'9')
00762
continue;
00763
if (xml[endpos].unicode() ==
'"')
00764
break;
00765
else
00766 {
00767 endpos = xml.length();
00768 }
00769 }
00770
00771
if (endpos != pos && endpos < xml.length() )
00772 {
00773
QString matchCandidate = xml.mid(pos, endpos - pos);
00774
return matchCandidate;
00775 }
00776
00777 state = ST_EXPECT_VERSION;
00778
break;
00779 }
00780 }
00781 }
00782
00783
return QString::null;
00784 }
00785
00786
KXMLGUIClient::ActionPropertiesMap KXMLGUIClient::extractActionProperties(
const QDomDocument &doc )
00787 {
00788 ActionPropertiesMap properties;
00789
00790
QDomElement actionPropElement = doc.documentElement().namedItem(
"ActionProperties" ).toElement();
00791
00792
if ( actionPropElement.isNull() )
00793
return properties;
00794
00795
QDomNode n = actionPropElement.firstChild();
00796
while(!n.isNull())
00797 {
00798
QDomElement e = n.toElement();
00799 n = n.nextSibling();
00800
if ( e.isNull() )
00801
continue;
00802
00803
if ( e.tagName().lower() !=
"action" )
00804
continue;
00805
00806
QString actionName = e.attribute(
"name" );
00807
00808
if ( actionName.isEmpty() )
00809
continue;
00810
00811
QMap<QString, QMap<QString, QString> >::Iterator propIt = properties.find( actionName );
00812
if ( propIt == properties.end() )
00813 propIt = properties.insert( actionName,
QMap<QString, QString>() );
00814
00815
QDomNamedNodeMap attributes = e.attributes();
00816
for ( uint i = 0; i < attributes.length(); ++i )
00817 {
00818
QDomAttr attr = attributes.item( i ).toAttr();
00819
00820
if ( attr.isNull() )
00821
continue;
00822
00823
QString name = attr.name();
00824
00825
if (
name ==
"name" ||
name.isEmpty() )
00826
continue;
00827
00828 (*propIt)[
name ] = attr.value();
00829 }
00830
00831 }
00832
00833
return properties;
00834 }
00835
00836
void KXMLGUIClient::storeActionProperties(
QDomDocument &doc,
const ActionPropertiesMap &properties )
00837 {
00838
QDomElement actionPropElement = doc.documentElement().namedItem(
"ActionProperties" ).toElement();
00839
00840
if ( actionPropElement.isNull() )
00841 {
00842 actionPropElement = doc.createElement(
"ActionProperties" );
00843 doc.documentElement().appendChild( actionPropElement );
00844 }
00845
00846
while ( !actionPropElement.firstChild().isNull() )
00847 actionPropElement.removeChild( actionPropElement.firstChild() );
00848
00849 ActionPropertiesMap::ConstIterator it = properties.begin();
00850 ActionPropertiesMap::ConstIterator
end = properties.end();
00851
for (; it !=
end; ++it )
00852 {
00853
QDomElement action = doc.createElement(
"Action" );
00854
action.setAttribute(
"name", it.key() );
00855 actionPropElement.appendChild( action );
00856
00857
QMap<QString, QString> attributes = (*it);
00858
QMap<QString, QString>::ConstIterator attrIt = attributes.begin();
00859
QMap<QString, QString>::ConstIterator attrEnd = attributes.end();
00860
for (; attrIt != attrEnd; ++attrIt )
00861
action.setAttribute( attrIt.key(), attrIt.data() );
00862 }
00863 }
00864
00865
void KXMLGUIClient::addStateActionEnabled(
const QString& state,
00866
const QString& action)
00867 {
00868 StateChange stateChange = getActionsToChangeForState(state);
00869
00870 stateChange.actionsToEnable.append( action );
00871
00872
00873 m_actionsStateMap.replace( state, stateChange );
00874 }
00875
00876
00877
void KXMLGUIClient::addStateActionDisabled(
const QString& state,
00878
const QString& action)
00879 {
00880 StateChange stateChange = getActionsToChangeForState(state);
00881
00882 stateChange.actionsToDisable.append( action );
00883
00884
00885 m_actionsStateMap.replace( state, stateChange );
00886 }
00887
00888
00889 KXMLGUIClient::StateChange KXMLGUIClient::getActionsToChangeForState(
const QString& state)
00890 {
00891
return m_actionsStateMap[state];
00892 }
00893
00894
00895 void KXMLGUIClient::stateChanged(
const QString &newstate, KXMLGUIClient::ReverseStateChange reverse)
00896 {
00897 StateChange stateChange = getActionsToChangeForState(newstate);
00898
00899
bool setTrue = (reverse == StateNoReverse);
00900
bool setFalse = !setTrue;
00901
00902
00903
00904
for ( QStringList::Iterator it = stateChange.actionsToEnable.begin();
00905 it != stateChange.actionsToEnable.end(); ++it ) {
00906
00907
KAction *
action =
actionCollection()->
action((*it).latin1());
00908
if (action) action->setEnabled(setTrue);
00909 }
00910
00911
00912
00913
for ( QStringList::Iterator it = stateChange.actionsToDisable.begin();
00914 it != stateChange.actionsToDisable.end(); ++it ) {
00915
00916
KAction *
action =
actionCollection()->
action((*it).latin1());
00917
if (action) action->setEnabled(setFalse);
00918 }
00919
00920 }
00921
00922 void KXMLGUIClient::beginXMLPlug(
QWidget *w )
00923 {
00924
actionCollection()->
beginXMLPlug( w );
00925
QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
00926
for (; childIt.current(); ++childIt )
00927 childIt.current()->actionCollection()->beginXMLPlug( w );
00928 }
00929
00930 void KXMLGUIClient::endXMLPlug()
00931 {
00932
actionCollection()->
endXMLPlug();
00933
QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
00934
for (; childIt.current(); ++childIt )
00935 childIt.current()->actionCollection()->endXMLPlug();
00936 }
00937
00938 void KXMLGUIClient::prepareXMLUnplug(
QWidget * )
00939 {
00940
actionCollection()->
prepareXMLUnplug();
00941
QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
00942
for (; childIt.current(); ++childIt )
00943 childIt.current()->actionCollection()->prepareXMLUnplug();
00944 }
00945
00946
void KXMLGUIClient::virtual_hook(
int,
void* )
00947 { }