summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/kxmlguiclient.cpp
Side-by-side diff
Diffstat (limited to 'microkde/kdeui/kxmlguiclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/kxmlguiclient.cpp12
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 @@
/* This file is part of the KDE libraries
Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
Copyright (C) 2000 Kurt Granroth <granroth@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "kxmlguiclient.h"
/*US
#include "kxmlguifactory.h"
#include "kxmlguibuilder.h"
*/
/*US
#include <qdir.h>
#include <qfile.h>
#include <qdom.h>
#include <qtextstream.h>
#include <qregexp.h>
*/
//US #include <kinstance.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <kaction.h>
#include <kapplication.h>
#include <assert.h>
+//Added by qt3to4:
+#include <Q3PtrList>
class KXMLGUIClientPrivate
{
public:
KXMLGUIClientPrivate()
{
//US m_instance = KGlobal::instance();
//US m_factory = 0L;
m_parent = 0L;
//US m_builder = 0L;
m_actionCollection = 0;
}
~KXMLGUIClientPrivate()
{
}
//US KInstance *m_instance;
//US QDomDocument m_doc;
KActionCollection *m_actionCollection;
//US QDomDocument m_buildDocument;
//US KXMLGUIFactory *m_factory;
KXMLGUIClient *m_parent;
//QPtrList<KXMLGUIClient> m_supers;
- QPtrList<KXMLGUIClient> m_children;
+ Q3PtrList<KXMLGUIClient> m_children;
//US KXMLGUIBuilder *m_builder;
//US QString m_xmlFile;
//US QString m_localXMLFile;
};
KXMLGUIClient::KXMLGUIClient()
{
d = new KXMLGUIClientPrivate;
}
KXMLGUIClient::KXMLGUIClient( KXMLGUIClient *parent )
{
d = new KXMLGUIClientPrivate;
parent->insertChildClient( this );
}
KXMLGUIClient::~KXMLGUIClient()
{
if ( d->m_parent )
d->m_parent->removeChildClient( this );
- QPtrListIterator<KXMLGUIClient> it( d->m_children );
+ Q3PtrListIterator<KXMLGUIClient> it( d->m_children );
for ( ; it.current(); ++it ) {
assert( it.current()->d->m_parent == this );
it.current()->d->m_parent = 0;
}
delete d->m_actionCollection;
delete d;
}
KAction *KXMLGUIClient::action( const char *name ) const
{
KAction* act = actionCollection()->action( name );
if ( !act ) {
- QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
+ Q3PtrListIterator<KXMLGUIClient> childIt( d->m_children );
for (; childIt.current(); ++childIt ) {
act = childIt.current()->actionCollection()->action( name );
if ( act )
break;
}
}
return act;
}
KActionCollection *KXMLGUIClient::actionCollection() const
{
if ( !d->m_actionCollection )
d->m_actionCollection = new KActionCollection( 0, 0,
"KXMLGUILClient-KActionCollection" );
return d->m_actionCollection;
}
/*US
KAction *KXMLGUIClient::action( const QDomElement &element ) const
{
static const QString &attrName = KGlobal::staticQString( "name" );
return actionCollection()->action( element.attribute( attrName ).latin1() );
}
KInstance *KXMLGUIClient::instance() const
{
return d->m_instance;
}
QDomDocument KXMLGUIClient::domDocument() const
{
return d->m_doc;
}
QString KXMLGUIClient::xmlFile() const
{
return d->m_xmlFile;
}
QString KXMLGUIClient::localXMLFile() const
{
if ( !d->m_localXMLFile.isEmpty() )
return d->m_localXMLFile;
if ( d->m_xmlFile[0] == '/' )
return QString::null; // can't save anything here
return locateLocal( "data", QString::fromLatin1( instance()->instanceName() + '/' ) + d->m_xmlFile );
}
void KXMLGUIClient::reloadXML()
{
QString file( xmlFile() );
if ( !file.isEmpty() )
setXMLFile( file );
}
void KXMLGUIClient::setInstance( KInstance *instance )
{
d->m_instance = instance;
actionCollection()->setInstance( instance );
if ( d->m_builder )
d->m_builder->setBuilderClient( this );
}
void KXMLGUIClient::setXMLFile( const QString& _file, bool merge, bool setXMLDoc )
{
// store our xml file name
if ( !_file.isNull() ) {
d->m_xmlFile = _file;
actionCollection()->setXMLFile( _file );
}
if ( !setXMLDoc )
return;
QString file = _file;
if ( file[0] != '/' )
{
QString doc;
QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + _file;
QStringList allFiles = instance()->dirs()->findAllResources( "data", filter ) + instance()->dirs()->findAllResources( "data", _file );
file = findMostRecentXMLFile( allFiles, doc );
if ( file.isEmpty() )
{
// this might or might not be an error. for the time being,
// let's treat this as if it isn't a problem and the user just
// wants the global standards file
setXML( QString::null, true );
return;
}
@@ -495,211 +497,211 @@ bool KXMLGUIClient::mergeXML( QDomElement &base, const QDomElement &additive, KA
// case (at this position we can be *sure* that the container is
// *not* empty, as the recursive call for it was in the first loop
// which deleted the element in case the call returned "true"
else
{
deleteMe = false;
break;
}
}
return deleteMe;
}
QDomElement KXMLGUIClient::findMatchingElement( const QDomElement &base, const QDomElement &additive )
{
static const QString &tagAction = KGlobal::staticQString( "Action" );
static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" );
static const QString &attrName = KGlobal::staticQString( "name" );
QDomElement e = additive.firstChild().toElement();
for ( ; !e.isNull(); e = e.nextSibling().toElement() )
{
// skip all action and merge tags as we will never use them
if ( ( e.tagName() == tagAction ) || ( e.tagName() == tagMergeLocal ) )
{
continue;
}
// now see if our tags are equivalent
if ( ( e.tagName() == base.tagName() ) &&
( e.attribute( attrName ) == base.attribute( attrName ) ) )
{
return e;
}
}
// nope, return a (now) null element
return e;
}
void KXMLGUIClient::conserveMemory()
{
d->m_doc = QDomDocument();
d->m_buildDocument = QDomDocument();
}
void KXMLGUIClient::setXMLGUIBuildDocument( const QDomDocument &doc )
{
d->m_buildDocument = doc;
}
QDomDocument KXMLGUIClient::xmlguiBuildDocument() const
{
return d->m_buildDocument;
}
*/
/*US
void KXMLGUIClient::setFactory( KXMLGUIFactory *factory )
{
d->m_factory = factory;
}
KXMLGUIFactory *KXMLGUIClient::factory() const
{
return d->m_factory;
}
*/
KXMLGUIClient *KXMLGUIClient::parentClient() const
{
return d->m_parent;
}
void KXMLGUIClient::insertChildClient( KXMLGUIClient *child )
{
if ( child->d->m_parent )
child->d->m_parent->removeChildClient( child );
d->m_children.append( child );
child->d->m_parent = this;
}
void KXMLGUIClient::removeChildClient( KXMLGUIClient *child )
{
assert( d->m_children.containsRef( child ) );
d->m_children.removeRef( child );
child->d->m_parent = 0;
}
/*bool KXMLGUIClient::addSuperClient( KXMLGUIClient *super )
{
if ( d->m_supers.contains( super ) )
return false;
d->m_supers.append( super );
return true;
}*/
-const QPtrList<KXMLGUIClient> *KXMLGUIClient::childClients()
+const Q3PtrList<KXMLGUIClient> *KXMLGUIClient::childClients()
{
return &d->m_children;
}
/*US
void KXMLGUIClient::setClientBuilder( KXMLGUIBuilder *builder )
{
d->m_builder = builder;
if ( builder )
builder->setBuilderInstance( instance() );
}
KXMLGUIBuilder *KXMLGUIClient::clientBuilder() const
{
return d->m_builder;
}
*/
-void KXMLGUIClient::plugActionList( const QString &name, const QPtrList<KAction> &actionList )
+void KXMLGUIClient::plugActionList( const QString &name, const Q3PtrList<KAction> &actionList )
{
/*US
if ( !d->m_factory )
return;
d->m_factory->plugActionList( this, name, actionList );
*/
}
void KXMLGUIClient::unplugActionList( const QString &name )
{
/*US
if ( !d->m_factory )
return;
d->m_factory->unplugActionList( this, name );
*/
}
/*US
QString KXMLGUIClient::findMostRecentXMLFile( const QStringList &files, QString &doc )
{
QValueList<DocStruct> allDocuments;
QStringList::ConstIterator it = files.begin();
QStringList::ConstIterator end = files.end();
for (; it != end; ++it )
{
//kdDebug() << "KXMLGUIClient::findMostRecentXMLFile " << *it << endl;
QString data = KXMLGUIFactory::readConfigFile( *it );
DocStruct d;
d.file = *it;
d.data = data;
allDocuments.append( d );
}
QValueList<DocStruct>::Iterator best = allDocuments.end();
uint bestVersion = 0;
QValueList<DocStruct>::Iterator docIt = allDocuments.begin();
QValueList<DocStruct>::Iterator docEnd = allDocuments.end();
for (; docIt != docEnd; ++docIt )
{
QString versionStr = findVersionNumber( (*docIt).data );
if ( versionStr.isEmpty() )
continue;
bool ok = false;
uint version = versionStr.toUInt( &ok );
if ( !ok )
continue;
//kdDebug() << "FOUND VERSION " << version << endl;
if ( version > bestVersion )
{
best = docIt;
//kdDebug() << "best version is now " << version << endl;
bestVersion = version;
}
}
if ( best != docEnd )
{
if ( best != allDocuments.begin() )
{
QValueList<DocStruct>::Iterator local = allDocuments.begin();
// load the local document and extract the action properties
QDomDocument document;
document.setContent( (*local).data );
ActionPropertiesMap properties = extractActionProperties( document );
// in case the document has a ActionProperties section
// we must not delete it but copy over the global doc
// to the local and insert the ActionProperties section
if ( !properties.isEmpty() )
{
// now load the global one with the higher version number
// into memory
document.setContent( (*best).data );
// and store the properties in there
storeActionProperties( document, properties );
(*local).data = document.toString();
// make sure we pick up the new local doc, when we return later
best = local;
// write out the new version of the local document
QFile f( (*local).file );
if ( f.open( IO_WriteOnly ) )
{
QCString utf8data = (*local).data.utf8();
f.writeBlock( utf8data.data(), utf8data.length() );
f.close();