Diffstat (limited to 'microkde/kdeui/kxmlguiclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/kxmlguiclient.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/microkde/kdeui/kxmlguiclient.cpp b/microkde/kdeui/kxmlguiclient.cpp index 073e30b..8740bde 100644 --- a/microkde/kdeui/kxmlguiclient.cpp +++ b/microkde/kdeui/kxmlguiclient.cpp | |||
@@ -1,198 +1,200 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2000 Simon Hausmann <hausmann@kde.org> |
3 | Copyright (C) 2000 Kurt Granroth <granroth@kde.org> | 3 | Copyright (C) 2000 Kurt Granroth <granroth@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. | 7 | License version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "kxmlguiclient.h" | 20 | #include "kxmlguiclient.h" |
21 | 21 | ||
22 | /*US | 22 | /*US |
23 | #include "kxmlguifactory.h" | 23 | #include "kxmlguifactory.h" |
24 | #include "kxmlguibuilder.h" | 24 | #include "kxmlguibuilder.h" |
25 | */ | 25 | */ |
26 | 26 | ||
27 | /*US | 27 | /*US |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qdom.h> | 30 | #include <qdom.h> |
31 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
32 | #include <qregexp.h> | 32 | #include <qregexp.h> |
33 | */ | 33 | */ |
34 | 34 | ||
35 | //US #include <kinstance.h> | 35 | //US #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | #include <kdebug.h> | 37 | #include <kdebug.h> |
38 | #include <kaction.h> | 38 | #include <kaction.h> |
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | 40 | ||
41 | #include <assert.h> | 41 | #include <assert.h> |
42 | //Added by qt3to4: | ||
43 | #include <Q3PtrList> | ||
42 | 44 | ||
43 | class KXMLGUIClientPrivate | 45 | class KXMLGUIClientPrivate |
44 | { | 46 | { |
45 | public: | 47 | public: |
46 | KXMLGUIClientPrivate() | 48 | KXMLGUIClientPrivate() |
47 | { | 49 | { |
48 | //US m_instance = KGlobal::instance(); | 50 | //US m_instance = KGlobal::instance(); |
49 | //US m_factory = 0L; | 51 | //US m_factory = 0L; |
50 | m_parent = 0L; | 52 | m_parent = 0L; |
51 | //US m_builder = 0L; | 53 | //US m_builder = 0L; |
52 | m_actionCollection = 0; | 54 | m_actionCollection = 0; |
53 | } | 55 | } |
54 | ~KXMLGUIClientPrivate() | 56 | ~KXMLGUIClientPrivate() |
55 | { | 57 | { |
56 | } | 58 | } |
57 | 59 | ||
58 | //US KInstance *m_instance; | 60 | //US KInstance *m_instance; |
59 | 61 | ||
60 | //US QDomDocument m_doc; | 62 | //US QDomDocument m_doc; |
61 | KActionCollection *m_actionCollection; | 63 | KActionCollection *m_actionCollection; |
62 | //US QDomDocument m_buildDocument; | 64 | //US QDomDocument m_buildDocument; |
63 | //US KXMLGUIFactory *m_factory; | 65 | //US KXMLGUIFactory *m_factory; |
64 | KXMLGUIClient *m_parent; | 66 | KXMLGUIClient *m_parent; |
65 | //QPtrList<KXMLGUIClient> m_supers; | 67 | //QPtrList<KXMLGUIClient> m_supers; |
66 | QPtrList<KXMLGUIClient> m_children; | 68 | Q3PtrList<KXMLGUIClient> m_children; |
67 | //US KXMLGUIBuilder *m_builder; | 69 | //US KXMLGUIBuilder *m_builder; |
68 | //US QString m_xmlFile; | 70 | //US QString m_xmlFile; |
69 | //US QString m_localXMLFile; | 71 | //US QString m_localXMLFile; |
70 | }; | 72 | }; |
71 | 73 | ||
72 | KXMLGUIClient::KXMLGUIClient() | 74 | KXMLGUIClient::KXMLGUIClient() |
73 | { | 75 | { |
74 | d = new KXMLGUIClientPrivate; | 76 | d = new KXMLGUIClientPrivate; |
75 | } | 77 | } |
76 | 78 | ||
77 | KXMLGUIClient::KXMLGUIClient( KXMLGUIClient *parent ) | 79 | KXMLGUIClient::KXMLGUIClient( KXMLGUIClient *parent ) |
78 | { | 80 | { |
79 | d = new KXMLGUIClientPrivate; | 81 | d = new KXMLGUIClientPrivate; |
80 | parent->insertChildClient( this ); | 82 | parent->insertChildClient( this ); |
81 | } | 83 | } |
82 | 84 | ||
83 | KXMLGUIClient::~KXMLGUIClient() | 85 | KXMLGUIClient::~KXMLGUIClient() |
84 | { | 86 | { |
85 | if ( d->m_parent ) | 87 | if ( d->m_parent ) |
86 | d->m_parent->removeChildClient( this ); | 88 | d->m_parent->removeChildClient( this ); |
87 | 89 | ||
88 | QPtrListIterator<KXMLGUIClient> it( d->m_children ); | 90 | Q3PtrListIterator<KXMLGUIClient> it( d->m_children ); |
89 | for ( ; it.current(); ++it ) { | 91 | for ( ; it.current(); ++it ) { |
90 | assert( it.current()->d->m_parent == this ); | 92 | assert( it.current()->d->m_parent == this ); |
91 | it.current()->d->m_parent = 0; | 93 | it.current()->d->m_parent = 0; |
92 | } | 94 | } |
93 | 95 | ||
94 | delete d->m_actionCollection; | 96 | delete d->m_actionCollection; |
95 | delete d; | 97 | delete d; |
96 | } | 98 | } |
97 | 99 | ||
98 | KAction *KXMLGUIClient::action( const char *name ) const | 100 | KAction *KXMLGUIClient::action( const char *name ) const |
99 | { | 101 | { |
100 | KAction* act = actionCollection()->action( name ); | 102 | KAction* act = actionCollection()->action( name ); |
101 | if ( !act ) { | 103 | if ( !act ) { |
102 | QPtrListIterator<KXMLGUIClient> childIt( d->m_children ); | 104 | Q3PtrListIterator<KXMLGUIClient> childIt( d->m_children ); |
103 | for (; childIt.current(); ++childIt ) { | 105 | for (; childIt.current(); ++childIt ) { |
104 | act = childIt.current()->actionCollection()->action( name ); | 106 | act = childIt.current()->actionCollection()->action( name ); |
105 | if ( act ) | 107 | if ( act ) |
106 | break; | 108 | break; |
107 | } | 109 | } |
108 | } | 110 | } |
109 | return act; | 111 | return act; |
110 | } | 112 | } |
111 | 113 | ||
112 | KActionCollection *KXMLGUIClient::actionCollection() const | 114 | KActionCollection *KXMLGUIClient::actionCollection() const |
113 | { | 115 | { |
114 | if ( !d->m_actionCollection ) | 116 | if ( !d->m_actionCollection ) |
115 | d->m_actionCollection = new KActionCollection( 0, 0, | 117 | d->m_actionCollection = new KActionCollection( 0, 0, |
116 | "KXMLGUILClient-KActionCollection" ); | 118 | "KXMLGUILClient-KActionCollection" ); |
117 | return d->m_actionCollection; | 119 | return d->m_actionCollection; |
118 | } | 120 | } |
119 | 121 | ||
120 | /*US | 122 | /*US |
121 | KAction *KXMLGUIClient::action( const QDomElement &element ) const | 123 | KAction *KXMLGUIClient::action( const QDomElement &element ) const |
122 | { | 124 | { |
123 | static const QString &attrName = KGlobal::staticQString( "name" ); | 125 | static const QString &attrName = KGlobal::staticQString( "name" ); |
124 | return actionCollection()->action( element.attribute( attrName ).latin1() ); | 126 | return actionCollection()->action( element.attribute( attrName ).latin1() ); |
125 | } | 127 | } |
126 | 128 | ||
127 | KInstance *KXMLGUIClient::instance() const | 129 | KInstance *KXMLGUIClient::instance() const |
128 | { | 130 | { |
129 | return d->m_instance; | 131 | return d->m_instance; |
130 | } | 132 | } |
131 | 133 | ||
132 | QDomDocument KXMLGUIClient::domDocument() const | 134 | QDomDocument KXMLGUIClient::domDocument() const |
133 | { | 135 | { |
134 | return d->m_doc; | 136 | return d->m_doc; |
135 | } | 137 | } |
136 | 138 | ||
137 | QString KXMLGUIClient::xmlFile() const | 139 | QString KXMLGUIClient::xmlFile() const |
138 | { | 140 | { |
139 | return d->m_xmlFile; | 141 | return d->m_xmlFile; |
140 | } | 142 | } |
141 | 143 | ||
142 | QString KXMLGUIClient::localXMLFile() const | 144 | QString KXMLGUIClient::localXMLFile() const |
143 | { | 145 | { |
144 | if ( !d->m_localXMLFile.isEmpty() ) | 146 | if ( !d->m_localXMLFile.isEmpty() ) |
145 | return d->m_localXMLFile; | 147 | return d->m_localXMLFile; |
146 | 148 | ||
147 | if ( d->m_xmlFile[0] == '/' ) | 149 | if ( d->m_xmlFile[0] == '/' ) |
148 | return QString::null; // can't save anything here | 150 | return QString::null; // can't save anything here |
149 | 151 | ||
150 | return locateLocal( "data", QString::fromLatin1( instance()->instanceName() + '/' ) + d->m_xmlFile ); | 152 | return locateLocal( "data", QString::fromLatin1( instance()->instanceName() + '/' ) + d->m_xmlFile ); |
151 | } | 153 | } |
152 | 154 | ||
153 | 155 | ||
154 | void KXMLGUIClient::reloadXML() | 156 | void KXMLGUIClient::reloadXML() |
155 | { | 157 | { |
156 | QString file( xmlFile() ); | 158 | QString file( xmlFile() ); |
157 | if ( !file.isEmpty() ) | 159 | if ( !file.isEmpty() ) |
158 | setXMLFile( file ); | 160 | setXMLFile( file ); |
159 | } | 161 | } |
160 | 162 | ||
161 | void KXMLGUIClient::setInstance( KInstance *instance ) | 163 | void KXMLGUIClient::setInstance( KInstance *instance ) |
162 | { | 164 | { |
163 | d->m_instance = instance; | 165 | d->m_instance = instance; |
164 | actionCollection()->setInstance( instance ); | 166 | actionCollection()->setInstance( instance ); |
165 | if ( d->m_builder ) | 167 | if ( d->m_builder ) |
166 | d->m_builder->setBuilderClient( this ); | 168 | d->m_builder->setBuilderClient( this ); |
167 | } | 169 | } |
168 | 170 | ||
169 | void KXMLGUIClient::setXMLFile( const QString& _file, bool merge, bool setXMLDoc ) | 171 | void KXMLGUIClient::setXMLFile( const QString& _file, bool merge, bool setXMLDoc ) |
170 | { | 172 | { |
171 | // store our xml file name | 173 | // store our xml file name |
172 | if ( !_file.isNull() ) { | 174 | if ( !_file.isNull() ) { |
173 | d->m_xmlFile = _file; | 175 | d->m_xmlFile = _file; |
174 | actionCollection()->setXMLFile( _file ); | 176 | actionCollection()->setXMLFile( _file ); |
175 | } | 177 | } |
176 | 178 | ||
177 | if ( !setXMLDoc ) | 179 | if ( !setXMLDoc ) |
178 | return; | 180 | return; |
179 | 181 | ||
180 | QString file = _file; | 182 | QString file = _file; |
181 | if ( file[0] != '/' ) | 183 | if ( file[0] != '/' ) |
182 | { | 184 | { |
183 | QString doc; | 185 | QString doc; |
184 | 186 | ||
185 | QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + _file; | 187 | QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + _file; |
186 | 188 | ||
187 | QStringList allFiles = instance()->dirs()->findAllResources( "data", filter ) + instance()->dirs()->findAllResources( "data", _file ); | 189 | QStringList allFiles = instance()->dirs()->findAllResources( "data", filter ) + instance()->dirs()->findAllResources( "data", _file ); |
188 | 190 | ||
189 | file = findMostRecentXMLFile( allFiles, doc ); | 191 | file = findMostRecentXMLFile( allFiles, doc ); |
190 | 192 | ||
191 | if ( file.isEmpty() ) | 193 | if ( file.isEmpty() ) |
192 | { | 194 | { |
193 | // this might or might not be an error. for the time being, | 195 | // this might or might not be an error. for the time being, |
194 | // let's treat this as if it isn't a problem and the user just | 196 | // let's treat this as if it isn't a problem and the user just |
195 | // wants the global standards file | 197 | // wants the global standards file |
196 | setXML( QString::null, true ); | 198 | setXML( QString::null, true ); |
197 | return; | 199 | return; |
198 | } | 200 | } |
@@ -495,211 +497,211 @@ bool KXMLGUIClient::mergeXML( QDomElement &base, const QDomElement &additive, KA | |||
495 | // case (at this position we can be *sure* that the container is | 497 | // case (at this position we can be *sure* that the container is |
496 | // *not* empty, as the recursive call for it was in the first loop | 498 | // *not* empty, as the recursive call for it was in the first loop |
497 | // which deleted the element in case the call returned "true" | 499 | // which deleted the element in case the call returned "true" |
498 | else | 500 | else |
499 | { | 501 | { |
500 | deleteMe = false; | 502 | deleteMe = false; |
501 | break; | 503 | break; |
502 | } | 504 | } |
503 | } | 505 | } |
504 | 506 | ||
505 | return deleteMe; | 507 | return deleteMe; |
506 | } | 508 | } |
507 | 509 | ||
508 | QDomElement KXMLGUIClient::findMatchingElement( const QDomElement &base, const QDomElement &additive ) | 510 | QDomElement KXMLGUIClient::findMatchingElement( const QDomElement &base, const QDomElement &additive ) |
509 | { | 511 | { |
510 | static const QString &tagAction = KGlobal::staticQString( "Action" ); | 512 | static const QString &tagAction = KGlobal::staticQString( "Action" ); |
511 | static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" ); | 513 | static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" ); |
512 | static const QString &attrName = KGlobal::staticQString( "name" ); | 514 | static const QString &attrName = KGlobal::staticQString( "name" ); |
513 | 515 | ||
514 | QDomElement e = additive.firstChild().toElement(); | 516 | QDomElement e = additive.firstChild().toElement(); |
515 | for ( ; !e.isNull(); e = e.nextSibling().toElement() ) | 517 | for ( ; !e.isNull(); e = e.nextSibling().toElement() ) |
516 | { | 518 | { |
517 | // skip all action and merge tags as we will never use them | 519 | // skip all action and merge tags as we will never use them |
518 | if ( ( e.tagName() == tagAction ) || ( e.tagName() == tagMergeLocal ) ) | 520 | if ( ( e.tagName() == tagAction ) || ( e.tagName() == tagMergeLocal ) ) |
519 | { | 521 | { |
520 | continue; | 522 | continue; |
521 | } | 523 | } |
522 | 524 | ||
523 | // now see if our tags are equivalent | 525 | // now see if our tags are equivalent |
524 | if ( ( e.tagName() == base.tagName() ) && | 526 | if ( ( e.tagName() == base.tagName() ) && |
525 | ( e.attribute( attrName ) == base.attribute( attrName ) ) ) | 527 | ( e.attribute( attrName ) == base.attribute( attrName ) ) ) |
526 | { | 528 | { |
527 | return e; | 529 | return e; |
528 | } | 530 | } |
529 | } | 531 | } |
530 | 532 | ||
531 | // nope, return a (now) null element | 533 | // nope, return a (now) null element |
532 | return e; | 534 | return e; |
533 | } | 535 | } |
534 | 536 | ||
535 | void KXMLGUIClient::conserveMemory() | 537 | void KXMLGUIClient::conserveMemory() |
536 | { | 538 | { |
537 | d->m_doc = QDomDocument(); | 539 | d->m_doc = QDomDocument(); |
538 | d->m_buildDocument = QDomDocument(); | 540 | d->m_buildDocument = QDomDocument(); |
539 | } | 541 | } |
540 | 542 | ||
541 | void KXMLGUIClient::setXMLGUIBuildDocument( const QDomDocument &doc ) | 543 | void KXMLGUIClient::setXMLGUIBuildDocument( const QDomDocument &doc ) |
542 | { | 544 | { |
543 | d->m_buildDocument = doc; | 545 | d->m_buildDocument = doc; |
544 | } | 546 | } |
545 | 547 | ||
546 | QDomDocument KXMLGUIClient::xmlguiBuildDocument() const | 548 | QDomDocument KXMLGUIClient::xmlguiBuildDocument() const |
547 | { | 549 | { |
548 | return d->m_buildDocument; | 550 | return d->m_buildDocument; |
549 | } | 551 | } |
550 | */ | 552 | */ |
551 | 553 | ||
552 | /*US | 554 | /*US |
553 | void KXMLGUIClient::setFactory( KXMLGUIFactory *factory ) | 555 | void KXMLGUIClient::setFactory( KXMLGUIFactory *factory ) |
554 | { | 556 | { |
555 | d->m_factory = factory; | 557 | d->m_factory = factory; |
556 | } | 558 | } |
557 | 559 | ||
558 | KXMLGUIFactory *KXMLGUIClient::factory() const | 560 | KXMLGUIFactory *KXMLGUIClient::factory() const |
559 | { | 561 | { |
560 | return d->m_factory; | 562 | return d->m_factory; |
561 | } | 563 | } |
562 | */ | 564 | */ |
563 | KXMLGUIClient *KXMLGUIClient::parentClient() const | 565 | KXMLGUIClient *KXMLGUIClient::parentClient() const |
564 | { | 566 | { |
565 | return d->m_parent; | 567 | return d->m_parent; |
566 | } | 568 | } |
567 | 569 | ||
568 | void KXMLGUIClient::insertChildClient( KXMLGUIClient *child ) | 570 | void KXMLGUIClient::insertChildClient( KXMLGUIClient *child ) |
569 | { | 571 | { |
570 | if ( child->d->m_parent ) | 572 | if ( child->d->m_parent ) |
571 | child->d->m_parent->removeChildClient( child ); | 573 | child->d->m_parent->removeChildClient( child ); |
572 | d->m_children.append( child ); | 574 | d->m_children.append( child ); |
573 | child->d->m_parent = this; | 575 | child->d->m_parent = this; |
574 | } | 576 | } |
575 | 577 | ||
576 | void KXMLGUIClient::removeChildClient( KXMLGUIClient *child ) | 578 | void KXMLGUIClient::removeChildClient( KXMLGUIClient *child ) |
577 | { | 579 | { |
578 | assert( d->m_children.containsRef( child ) ); | 580 | assert( d->m_children.containsRef( child ) ); |
579 | d->m_children.removeRef( child ); | 581 | d->m_children.removeRef( child ); |
580 | child->d->m_parent = 0; | 582 | child->d->m_parent = 0; |
581 | } | 583 | } |
582 | 584 | ||
583 | /*bool KXMLGUIClient::addSuperClient( KXMLGUIClient *super ) | 585 | /*bool KXMLGUIClient::addSuperClient( KXMLGUIClient *super ) |
584 | { | 586 | { |
585 | if ( d->m_supers.contains( super ) ) | 587 | if ( d->m_supers.contains( super ) ) |
586 | return false; | 588 | return false; |
587 | d->m_supers.append( super ); | 589 | d->m_supers.append( super ); |
588 | return true; | 590 | return true; |
589 | }*/ | 591 | }*/ |
590 | 592 | ||
591 | const QPtrList<KXMLGUIClient> *KXMLGUIClient::childClients() | 593 | const Q3PtrList<KXMLGUIClient> *KXMLGUIClient::childClients() |
592 | { | 594 | { |
593 | return &d->m_children; | 595 | return &d->m_children; |
594 | } | 596 | } |
595 | /*US | 597 | /*US |
596 | void KXMLGUIClient::setClientBuilder( KXMLGUIBuilder *builder ) | 598 | void KXMLGUIClient::setClientBuilder( KXMLGUIBuilder *builder ) |
597 | { | 599 | { |
598 | d->m_builder = builder; | 600 | d->m_builder = builder; |
599 | if ( builder ) | 601 | if ( builder ) |
600 | builder->setBuilderInstance( instance() ); | 602 | builder->setBuilderInstance( instance() ); |
601 | } | 603 | } |
602 | 604 | ||
603 | KXMLGUIBuilder *KXMLGUIClient::clientBuilder() const | 605 | KXMLGUIBuilder *KXMLGUIClient::clientBuilder() const |
604 | { | 606 | { |
605 | return d->m_builder; | 607 | return d->m_builder; |
606 | } | 608 | } |
607 | */ | 609 | */ |
608 | 610 | ||
609 | void KXMLGUIClient::plugActionList( const QString &name, const QPtrList<KAction> &actionList ) | 611 | void KXMLGUIClient::plugActionList( const QString &name, const Q3PtrList<KAction> &actionList ) |
610 | { | 612 | { |
611 | /*US | 613 | /*US |
612 | if ( !d->m_factory ) | 614 | if ( !d->m_factory ) |
613 | return; | 615 | return; |
614 | 616 | ||
615 | d->m_factory->plugActionList( this, name, actionList ); | 617 | d->m_factory->plugActionList( this, name, actionList ); |
616 | */ | 618 | */ |
617 | } | 619 | } |
618 | 620 | ||
619 | void KXMLGUIClient::unplugActionList( const QString &name ) | 621 | void KXMLGUIClient::unplugActionList( const QString &name ) |
620 | { | 622 | { |
621 | /*US | 623 | /*US |
622 | if ( !d->m_factory ) | 624 | if ( !d->m_factory ) |
623 | return; | 625 | return; |
624 | 626 | ||
625 | d->m_factory->unplugActionList( this, name ); | 627 | d->m_factory->unplugActionList( this, name ); |
626 | */ | 628 | */ |
627 | } | 629 | } |
628 | 630 | ||
629 | /*US | 631 | /*US |
630 | QString KXMLGUIClient::findMostRecentXMLFile( const QStringList &files, QString &doc ) | 632 | QString KXMLGUIClient::findMostRecentXMLFile( const QStringList &files, QString &doc ) |
631 | { | 633 | { |
632 | 634 | ||
633 | QValueList<DocStruct> allDocuments; | 635 | QValueList<DocStruct> allDocuments; |
634 | 636 | ||
635 | QStringList::ConstIterator it = files.begin(); | 637 | QStringList::ConstIterator it = files.begin(); |
636 | QStringList::ConstIterator end = files.end(); | 638 | QStringList::ConstIterator end = files.end(); |
637 | for (; it != end; ++it ) | 639 | for (; it != end; ++it ) |
638 | { | 640 | { |
639 | //kdDebug() << "KXMLGUIClient::findMostRecentXMLFile " << *it << endl; | 641 | //kdDebug() << "KXMLGUIClient::findMostRecentXMLFile " << *it << endl; |
640 | QString data = KXMLGUIFactory::readConfigFile( *it ); | 642 | QString data = KXMLGUIFactory::readConfigFile( *it ); |
641 | DocStruct d; | 643 | DocStruct d; |
642 | d.file = *it; | 644 | d.file = *it; |
643 | d.data = data; | 645 | d.data = data; |
644 | allDocuments.append( d ); | 646 | allDocuments.append( d ); |
645 | } | 647 | } |
646 | 648 | ||
647 | QValueList<DocStruct>::Iterator best = allDocuments.end(); | 649 | QValueList<DocStruct>::Iterator best = allDocuments.end(); |
648 | uint bestVersion = 0; | 650 | uint bestVersion = 0; |
649 | 651 | ||
650 | QValueList<DocStruct>::Iterator docIt = allDocuments.begin(); | 652 | QValueList<DocStruct>::Iterator docIt = allDocuments.begin(); |
651 | QValueList<DocStruct>::Iterator docEnd = allDocuments.end(); | 653 | QValueList<DocStruct>::Iterator docEnd = allDocuments.end(); |
652 | for (; docIt != docEnd; ++docIt ) | 654 | for (; docIt != docEnd; ++docIt ) |
653 | { | 655 | { |
654 | QString versionStr = findVersionNumber( (*docIt).data ); | 656 | QString versionStr = findVersionNumber( (*docIt).data ); |
655 | if ( versionStr.isEmpty() ) | 657 | if ( versionStr.isEmpty() ) |
656 | continue; | 658 | continue; |
657 | 659 | ||
658 | bool ok = false; | 660 | bool ok = false; |
659 | uint version = versionStr.toUInt( &ok ); | 661 | uint version = versionStr.toUInt( &ok ); |
660 | if ( !ok ) | 662 | if ( !ok ) |
661 | continue; | 663 | continue; |
662 | //kdDebug() << "FOUND VERSION " << version << endl; | 664 | //kdDebug() << "FOUND VERSION " << version << endl; |
663 | 665 | ||
664 | if ( version > bestVersion ) | 666 | if ( version > bestVersion ) |
665 | { | 667 | { |
666 | best = docIt; | 668 | best = docIt; |
667 | //kdDebug() << "best version is now " << version << endl; | 669 | //kdDebug() << "best version is now " << version << endl; |
668 | bestVersion = version; | 670 | bestVersion = version; |
669 | } | 671 | } |
670 | } | 672 | } |
671 | 673 | ||
672 | if ( best != docEnd ) | 674 | if ( best != docEnd ) |
673 | { | 675 | { |
674 | if ( best != allDocuments.begin() ) | 676 | if ( best != allDocuments.begin() ) |
675 | { | 677 | { |
676 | QValueList<DocStruct>::Iterator local = allDocuments.begin(); | 678 | QValueList<DocStruct>::Iterator local = allDocuments.begin(); |
677 | 679 | ||
678 | // load the local document and extract the action properties | 680 | // load the local document and extract the action properties |
679 | QDomDocument document; | 681 | QDomDocument document; |
680 | document.setContent( (*local).data ); | 682 | document.setContent( (*local).data ); |
681 | 683 | ||
682 | ActionPropertiesMap properties = extractActionProperties( document ); | 684 | ActionPropertiesMap properties = extractActionProperties( document ); |
683 | 685 | ||
684 | // in case the document has a ActionProperties section | 686 | // in case the document has a ActionProperties section |
685 | // we must not delete it but copy over the global doc | 687 | // we must not delete it but copy over the global doc |
686 | // to the local and insert the ActionProperties section | 688 | // to the local and insert the ActionProperties section |
687 | if ( !properties.isEmpty() ) | 689 | if ( !properties.isEmpty() ) |
688 | { | 690 | { |
689 | // now load the global one with the higher version number | 691 | // now load the global one with the higher version number |
690 | // into memory | 692 | // into memory |
691 | document.setContent( (*best).data ); | 693 | document.setContent( (*best).data ); |
692 | // and store the properties in there | 694 | // and store the properties in there |
693 | storeActionProperties( document, properties ); | 695 | storeActionProperties( document, properties ); |
694 | 696 | ||
695 | (*local).data = document.toString(); | 697 | (*local).data = document.toString(); |
696 | // make sure we pick up the new local doc, when we return later | 698 | // make sure we pick up the new local doc, when we return later |
697 | best = local; | 699 | best = local; |
698 | 700 | ||
699 | // write out the new version of the local document | 701 | // write out the new version of the local document |
700 | QFile f( (*local).file ); | 702 | QFile f( (*local).file ); |
701 | if ( f.open( IO_WriteOnly ) ) | 703 | if ( f.open( IO_WriteOnly ) ) |
702 | { | 704 | { |
703 | QCString utf8data = (*local).data.utf8(); | 705 | QCString utf8data = (*local).data.utf8(); |
704 | f.writeBlock( utf8data.data(), utf8data.length() ); | 706 | f.writeBlock( utf8data.data(), utf8data.length() ); |
705 | f.close(); | 707 | f.close(); |