You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
615 lines
17 KiB
615 lines
17 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999,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 as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
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., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kxmlguifactory.h"
|
||
|
#include "kxmlguifactory_p.h"
|
||
|
#include "kxmlguiclient.h"
|
||
|
#include "kxmlguibuilder.h"
|
||
|
|
||
|
#include <assert.h>
|
||
|
|
||
15 years ago
|
#include <tqdir.h>
|
||
|
#include <tqfile.h>
|
||
|
#include <tqtextstream.h>
|
||
|
#include <tqwidget.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqvariant.h>
|
||
15 years ago
|
|
||
|
#include <kaction.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kinstance.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kshortcut.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kkeydialog.h>
|
||
|
|
||
|
using namespace KXMLGUI;
|
||
|
|
||
|
/*
|
||
15 years ago
|
* TODO: - make more use of TQValueList instead of QPtrList
|
||
15 years ago
|
*/
|
||
|
|
||
|
class KXMLGUIFactoryPrivate : public BuildState
|
||
|
{
|
||
|
public:
|
||
|
KXMLGUIFactoryPrivate()
|
||
|
{
|
||
15 years ago
|
static const TQString &defaultMergingName = KGlobal::staticQString( "<default>" );
|
||
|
static const TQString &actionList = KGlobal::staticQString( "actionlist" );
|
||
|
static const TQString &name = KGlobal::staticQString( "name" );
|
||
15 years ago
|
|
||
15 years ago
|
m_rootNode = new ContainerNode( 0L, TQString::null, 0L );
|
||
15 years ago
|
m_defaultMergingName = defaultMergingName;
|
||
|
tagActionList = actionList;
|
||
|
attrName = name;
|
||
|
}
|
||
|
~KXMLGUIFactoryPrivate()
|
||
|
{
|
||
|
delete m_rootNode;
|
||
|
}
|
||
|
|
||
|
void pushState()
|
||
|
{
|
||
|
m_stateStack.push( *this );
|
||
|
}
|
||
|
|
||
|
void popState()
|
||
|
{
|
||
|
BuildState::operator=( m_stateStack.pop() );
|
||
|
}
|
||
|
|
||
|
ContainerNode *m_rootNode;
|
||
|
|
||
15 years ago
|
TQString m_defaultMergingName;
|
||
15 years ago
|
|
||
|
/*
|
||
|
* Contains the container which is searched for in ::container .
|
||
|
*/
|
||
15 years ago
|
TQString m_containerName;
|
||
15 years ago
|
|
||
|
/*
|
||
|
* List of all clients
|
||
|
*/
|
||
15 years ago
|
TQPtrList<KXMLGUIClient> m_clients;
|
||
15 years ago
|
|
||
15 years ago
|
TQString tagActionList;
|
||
15 years ago
|
|
||
15 years ago
|
TQString attrName;
|
||
15 years ago
|
|
||
|
BuildStateStack m_stateStack;
|
||
|
};
|
||
|
|
||
15 years ago
|
TQString KXMLGUIFactory::readConfigFile( const TQString &filename, const KInstance *instance )
|
||
15 years ago
|
{
|
||
|
return readConfigFile( filename, false, instance );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KXMLGUIFactory::readConfigFile( const TQString &filename, bool never_null, const KInstance *_instance )
|
||
15 years ago
|
{
|
||
|
const KInstance *instance = _instance ? _instance : KGlobal::instance();
|
||
15 years ago
|
TQString xml_file;
|
||
15 years ago
|
|
||
15 years ago
|
if (!TQDir::isRelativePath(filename))
|
||
15 years ago
|
xml_file = filename;
|
||
|
else
|
||
|
{
|
||
14 years ago
|
xml_file = locate("data", TQString::tqfromLatin1(instance->instanceName() + '/' ) + filename);
|
||
15 years ago
|
if ( !TQFile::exists( xml_file ) )
|
||
15 years ago
|
xml_file = locate( "data", filename );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFile file( xml_file );
|
||
15 years ago
|
if ( !file.open( IO_ReadOnly ) )
|
||
|
{
|
||
|
kdError(240) << "No such XML file " << filename << endl;
|
||
|
if ( never_null )
|
||
14 years ago
|
return TQString::tqfromLatin1( "<!DOCTYPE kpartgui>\n<kpartgui name=\"empty\">\n</kpartgui>" );
|
||
15 years ago
|
else
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
#if QT_VERSION <= 0x030302
|
||
15 years ago
|
// Work around bug in TQString::fromUtf8 (which calls strlen).
|
||
|
TQByteArray buffer(file.size() + 1);
|
||
15 years ago
|
buffer = file.readAll();
|
||
|
if(!buffer.isEmpty())
|
||
|
buffer[ buffer.size() - 1 ] = '\0';
|
||
|
else
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
#else
|
||
15 years ago
|
TQByteArray buffer(file.readAll());
|
||
15 years ago
|
#endif
|
||
15 years ago
|
return TQString::fromUtf8(buffer.data(), buffer.size());
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
bool KXMLGUIFactory::saveConfigFile( const TQDomDocument& doc,
|
||
|
const TQString& filename, const KInstance *_instance )
|
||
15 years ago
|
{
|
||
|
const KInstance *instance = _instance ? _instance : KGlobal::instance();
|
||
15 years ago
|
TQString xml_file(filename);
|
||
15 years ago
|
|
||
15 years ago
|
if (TQDir::isRelativePath(xml_file))
|
||
14 years ago
|
xml_file = locateLocal("data", TQString::tqfromLatin1( instance->instanceName() + '/' )
|
||
15 years ago
|
+ filename);
|
||
|
|
||
15 years ago
|
TQFile file( xml_file );
|
||
15 years ago
|
if ( !file.open( IO_WriteOnly ) )
|
||
|
{
|
||
|
kdError(240) << "Could not write to " << filename << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// write out our document
|
||
15 years ago
|
TQTextStream ts(&file);
|
||
|
ts.setEncoding( TQTextStream::UnicodeUTF8 );
|
||
15 years ago
|
ts << doc;
|
||
|
|
||
|
file.close();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KXMLGUIFactory::documentToXML( const TQDomDocument& doc )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString str;
|
||
|
TQTextStream ts(&str, IO_WriteOnly);
|
||
|
ts.setEncoding( TQTextStream::UnicodeUTF8 );
|
||
15 years ago
|
ts << doc;
|
||
|
return str;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KXMLGUIFactory::elementToXML( const TQDomElement& elem )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString str;
|
||
|
TQTextStream ts(&str, IO_WriteOnly);
|
||
|
ts.setEncoding( TQTextStream::UnicodeUTF8 );
|
||
15 years ago
|
ts << elem;
|
||
|
return str;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::removeDOMComments( TQDomNode &node )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomNode n = node.firstChild();
|
||
15 years ago
|
while ( !n.isNull() )
|
||
|
{
|
||
15 years ago
|
if ( n.nodeType() == TQDomNode::CommentNode )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomNode tmp = n;
|
||
15 years ago
|
n = n.nextSibling();
|
||
|
node.removeChild( tmp );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQDomNode tmp = n;
|
||
15 years ago
|
n = n.nextSibling();
|
||
|
removeDOMComments( tmp );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
KXMLGUIFactory::KXMLGUIFactory( KXMLGUIBuilder *builder, TQObject *parent, const char *name )
|
||
|
: TQObject( parent, name )
|
||
15 years ago
|
{
|
||
|
d = new KXMLGUIFactoryPrivate;
|
||
|
d->builder = builder;
|
||
|
d->guiClient = 0;
|
||
|
if ( d->builder )
|
||
|
{
|
||
|
d->builderContainerTags = d->builder->containerTags();
|
||
|
d->builderCustomTags = d->builder->customTags();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KXMLGUIFactory::~KXMLGUIFactory()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KXMLGUIFactory::addClient( KXMLGUIClient *client )
|
||
|
{
|
||
|
kdDebug(1002) << "KXMLGUIFactory::addClient( " << client << " )" << endl; // ellis
|
||
15 years ago
|
static const TQString &actionPropElementName = KGlobal::staticQString( "ActionProperties" );
|
||
15 years ago
|
|
||
|
if ( client->factory() ) {
|
||
|
if ( client->factory() == this )
|
||
|
return;
|
||
|
else
|
||
|
client->factory()->removeClient( client ); //just in case someone does stupid things ;-)
|
||
|
}
|
||
|
|
||
|
d->pushState();
|
||
|
|
||
15 years ago
|
// TQTime dt; dt.start();
|
||
15 years ago
|
|
||
|
d->guiClient = client;
|
||
|
|
||
|
// add this client to our client list
|
||
13 years ago
|
if ( !d->m_clients.containsRef( client ) )
|
||
15 years ago
|
d->m_clients.append( client );
|
||
|
else
|
||
|
kdDebug(1002) << "XMLGUI client already added " << client << endl;
|
||
|
|
||
|
// Tell the client that plugging in is process and
|
||
|
// let it know what builder widget its mainwindow shortcuts
|
||
|
// should be attached to.
|
||
|
client->beginXMLPlug( d->builder->widget() );
|
||
|
|
||
|
// try to use the build document for building the client's GUI, as the build document
|
||
14 years ago
|
// contains the correct container state information (like toolbar positions, sizes, etc.) .
|
||
15 years ago
|
// if there is non available, then use the "real" document.
|
||
15 years ago
|
TQDomDocument doc = client->xmlguiBuildDocument();
|
||
15 years ago
|
if ( doc.documentElement().isNull() )
|
||
|
doc = client->domDocument();
|
||
|
|
||
15 years ago
|
TQDomElement docElement = doc.documentElement();
|
||
15 years ago
|
|
||
|
d->m_rootNode->index = -1;
|
||
|
|
||
|
// cache some variables
|
||
|
|
||
|
d->clientName = docElement.attribute( d->attrName );
|
||
|
d->clientBuilder = client->clientBuilder();
|
||
|
|
||
|
if ( d->clientBuilder )
|
||
|
{
|
||
|
d->clientBuilderContainerTags = d->clientBuilder->containerTags();
|
||
|
d->clientBuilderCustomTags = d->clientBuilder->customTags();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
d->clientBuilderContainerTags.clear();
|
||
|
d->clientBuilderCustomTags.clear();
|
||
|
}
|
||
|
|
||
|
// process a possibly existing actionproperties section
|
||
|
|
||
15 years ago
|
TQDomElement actionPropElement = docElement.namedItem( actionPropElementName ).toElement();
|
||
15 years ago
|
if ( actionPropElement.isNull() )
|
||
|
actionPropElement = docElement.namedItem( actionPropElementName.lower() ).toElement();
|
||
|
|
||
|
if ( !actionPropElement.isNull() )
|
||
|
applyActionProperties( actionPropElement );
|
||
|
|
||
|
BuildHelper( *d, d->m_rootNode ).build( docElement );
|
||
|
|
||
|
// let the client know that we built its GUI.
|
||
|
client->setFactory( this );
|
||
|
|
||
|
// call the finalizeGUI method, to fix up the positions of toolbars for example.
|
||
|
// ### FIXME : obey client builder
|
||
|
// --- Well, toolbars have a bool "positioned", so it doesn't really matter,
|
||
|
// if we call positionYourself on all of them each time. (David)
|
||
|
d->builder->finalizeGUI( d->guiClient );
|
||
|
|
||
|
// reset some variables, for safety
|
||
|
d->BuildState::reset();
|
||
|
|
||
|
client->endXMLPlug();
|
||
|
|
||
|
d->popState();
|
||
|
|
||
|
emit clientAdded( client );
|
||
|
|
||
|
// build child clients
|
||
|
if ( client->childClients()->count() > 0 )
|
||
|
{
|
||
15 years ago
|
const TQPtrList<KXMLGUIClient> *children = client->childClients();
|
||
|
TQPtrListIterator<KXMLGUIClient> childIt( *children );
|
||
15 years ago
|
for (; childIt.current(); ++childIt )
|
||
|
addClient( childIt.current() );
|
||
|
}
|
||
|
|
||
|
// kdDebug() << "addClient took " << dt.elapsed() << endl;
|
||
|
}
|
||
|
|
||
|
void KXMLGUIFactory::removeClient( KXMLGUIClient *client )
|
||
|
{
|
||
|
kdDebug(1002) << "KXMLGUIFactory::removeClient( " << client << " )" << endl; // ellis
|
||
|
|
||
|
// don't try to remove the client's GUI if we didn't build it
|
||
|
if ( !client || client->factory() != this )
|
||
|
return;
|
||
|
|
||
|
// remove this client from our client list
|
||
|
d->m_clients.removeRef( client );
|
||
|
|
||
|
// remove child clients first
|
||
|
if ( client->childClients()->count() > 0 )
|
||
|
{
|
||
15 years ago
|
const TQPtrList<KXMLGUIClient> *children = client->childClients();
|
||
|
TQPtrListIterator<KXMLGUIClient> childIt( *children );
|
||
15 years ago
|
childIt.toLast();
|
||
|
for (; childIt.current(); --childIt )
|
||
|
removeClient( childIt.current() );
|
||
|
}
|
||
|
|
||
|
kdDebug(1002) << "KXMLGUIFactory::removeServant, calling removeRecursive" << endl;
|
||
|
|
||
|
d->pushState();
|
||
|
|
||
|
// cache some variables
|
||
|
|
||
|
d->guiClient = client;
|
||
|
d->clientName = client->domDocument().documentElement().attribute( d->attrName );
|
||
|
d->clientBuilder = client->clientBuilder();
|
||
|
|
||
|
client->setFactory( 0L );
|
||
|
|
||
|
// if we don't have a build document for that client, yet, then create one by
|
||
|
// cloning the original document, so that saving container information in the
|
||
|
// DOM tree does not touch the original document.
|
||
15 years ago
|
TQDomDocument doc = client->xmlguiBuildDocument();
|
||
15 years ago
|
if ( doc.documentElement().isNull() )
|
||
|
{
|
||
|
doc = client->domDocument().cloneNode( true ).toDocument();
|
||
|
client->setXMLGUIBuildDocument( doc );
|
||
|
}
|
||
|
|
||
|
d->m_rootNode->destruct( doc.documentElement(), *d );
|
||
|
|
||
|
d->builder->finalizeGUI( d->guiClient ); //JoWenn
|
||
|
|
||
|
// reset some variables
|
||
|
d->BuildState::reset();
|
||
|
|
||
|
// This will destruct the KAccel object built around the given widget.
|
||
|
client->prepareXMLUnplug( d->builder->widget() );
|
||
|
|
||
|
d->popState();
|
||
|
|
||
|
emit clientRemoved( client );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPtrList<KXMLGUIClient> KXMLGUIFactory::clients() const
|
||
15 years ago
|
{
|
||
|
return d->m_clients;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQWidget *KXMLGUIFactory::container( const TQString &containerName, KXMLGUIClient *client,
|
||
15 years ago
|
bool useTagName )
|
||
|
{
|
||
|
d->pushState();
|
||
|
d->m_containerName = containerName;
|
||
|
d->guiClient = client;
|
||
|
|
||
14 years ago
|
TQWidget *result = findRecursive( d->m_rootNode, useTagName );
|
||
15 years ago
|
|
||
|
d->guiClient = 0L;
|
||
15 years ago
|
d->m_containerName = TQString::null;
|
||
15 years ago
|
|
||
|
d->popState();
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPtrList<TQWidget> KXMLGUIFactory::containers( const TQString &tagName )
|
||
15 years ago
|
{
|
||
14 years ago
|
return findRecursive( d->m_rootNode, tagName );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KXMLGUIFactory::reset()
|
||
|
{
|
||
|
d->m_rootNode->reset();
|
||
|
|
||
|
d->m_rootNode->clearChildren();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::resetContainer( const TQString &containerName, bool useTagName )
|
||
15 years ago
|
{
|
||
|
if ( containerName.isEmpty() )
|
||
|
return;
|
||
|
|
||
14 years ago
|
ContainerNode *container = d->m_rootNode->findContainer( containerName, useTagName );
|
||
15 years ago
|
|
||
|
if ( !container )
|
||
|
return;
|
||
|
|
||
|
ContainerNode *parent = container->parent;
|
||
|
if ( !parent )
|
||
|
return;
|
||
|
|
||
|
// resetInternal( container );
|
||
|
|
||
|
parent->removeChild( container );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQWidget *KXMLGUIFactory::findRecursive( KXMLGUI::ContainerNode *node, bool tag )
|
||
15 years ago
|
{
|
||
|
if ( ( ( !tag && node->name == d->m_containerName ) ||
|
||
|
( tag && node->tagName == d->m_containerName ) ) &&
|
||
|
( !d->guiClient || node->client == d->guiClient ) )
|
||
|
return node->container;
|
||
|
|
||
15 years ago
|
TQPtrListIterator<ContainerNode> it( node->children );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
{
|
||
14 years ago
|
TQWidget *cont = findRecursive( it.current(), tag );
|
||
15 years ago
|
if ( cont )
|
||
|
return cont;
|
||
|
}
|
||
|
|
||
|
return 0L;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQPtrList<TQWidget> KXMLGUIFactory::findRecursive( KXMLGUI::ContainerNode *node,
|
||
15 years ago
|
const TQString &tagName )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrList<TQWidget> res;
|
||
15 years ago
|
|
||
|
if ( node->tagName == tagName.lower() )
|
||
|
res.append( node->container );
|
||
|
|
||
15 years ago
|
TQPtrListIterator<KXMLGUI::ContainerNode> it( node->children );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
{
|
||
14 years ago
|
TQPtrList<TQWidget> lst = findRecursive( it.current(), tagName );
|
||
15 years ago
|
TQPtrListIterator<TQWidget> wit( lst );
|
||
15 years ago
|
for (; wit.current(); ++wit )
|
||
|
res.append( wit.current() );
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::plugActionList( KXMLGUIClient *client, const TQString &name,
|
||
|
const TQPtrList<KAction> &actionList )
|
||
15 years ago
|
{
|
||
|
d->pushState();
|
||
|
d->guiClient = client;
|
||
|
d->actionListName = name;
|
||
|
d->actionList = actionList;
|
||
|
d->clientName = client->domDocument().documentElement().attribute( d->attrName );
|
||
|
|
||
|
d->m_rootNode->plugActionList( *d );
|
||
|
|
||
|
d->BuildState::reset();
|
||
|
d->popState();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::unplugActionList( KXMLGUIClient *client, const TQString &name )
|
||
15 years ago
|
{
|
||
|
d->pushState();
|
||
|
d->guiClient = client;
|
||
|
d->actionListName = name;
|
||
|
d->clientName = client->domDocument().documentElement().attribute( d->attrName );
|
||
|
|
||
|
d->m_rootNode->unplugActionList( *d );
|
||
|
|
||
|
d->BuildState::reset();
|
||
|
d->popState();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::applyActionProperties( const TQDomElement &actionPropElement )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString &tagAction = KGlobal::staticQString( "action" );
|
||
15 years ago
|
|
||
15 years ago
|
for (TQDomNode n = actionPropElement.firstChild();
|
||
15 years ago
|
!n.isNull(); n = n.nextSibling() )
|
||
|
{
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
if ( e.tagName().lower() != tagAction )
|
||
|
continue;
|
||
|
|
||
|
KAction *action = d->guiClient->action( e );
|
||
|
if ( !action )
|
||
|
continue;
|
||
|
|
||
|
configureAction( action, e.attributes() );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::configureAction( KAction *action, const TQDomNamedNodeMap &attributes )
|
||
15 years ago
|
{
|
||
|
for ( uint i = 0; i < attributes.length(); i++ )
|
||
|
{
|
||
15 years ago
|
TQDomAttr attr = attributes.item( i ).toAttr();
|
||
15 years ago
|
if ( attr.isNull() )
|
||
|
continue;
|
||
|
|
||
|
configureAction( action, attr );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KXMLGUIFactory::configureAction( KAction *action, const TQDomAttr &attribute )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString &attrShortcut = KGlobal::staticQString( "shortcut" );
|
||
15 years ago
|
|
||
15 years ago
|
TQString attrName = attribute.name();
|
||
15 years ago
|
// If the attribute is a deprecated "accel", change to "shortcut".
|
||
|
if ( attrName.lower() == "accel" )
|
||
|
attrName = attrShortcut;
|
||
|
|
||
15 years ago
|
TQVariant propertyValue;
|
||
15 years ago
|
|
||
15 years ago
|
TQVariant::Type propertyType = action->property( attrName.latin1() ).type();
|
||
15 years ago
|
|
||
15 years ago
|
if ( propertyType == TQVariant::Int )
|
||
|
propertyValue = TQVariant( attribute.value().toInt() );
|
||
|
else if ( propertyType == TQVariant::UInt )
|
||
|
propertyValue = TQVariant( attribute.value().toUInt() );
|
||
15 years ago
|
else
|
||
15 years ago
|
propertyValue = TQVariant( attribute.value() );
|
||
15 years ago
|
|
||
|
action->setProperty( attrName.latin1(), propertyValue );
|
||
|
}
|
||
|
|
||
|
|
||
|
int KXMLGUIFactory::configureShortcuts(bool bAllowLetterShortcuts , bool bSaveSettings )
|
||
|
{
|
||
14 years ago
|
KKeyDialog dlg( bAllowLetterShortcuts, tqt_dynamic_cast<TQWidget*>(parent()) );
|
||
15 years ago
|
TQPtrListIterator<KXMLGUIClient> it( d->m_clients );
|
||
15 years ago
|
KXMLGUIClient *client;
|
||
|
while( (client=it.current()) !=0 )
|
||
|
{
|
||
|
++it;
|
||
|
if(!client->xmlFile().isEmpty())
|
||
|
dlg.insert( client->actionCollection() );
|
||
|
}
|
||
|
return dlg.configure(bSaveSettings);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomElement KXMLGUIFactory::actionPropertiesElement( TQDomDocument& doc )
|
||
15 years ago
|
{
|
||
14 years ago
|
const TQString tagActionProp = TQString::tqfromLatin1("ActionProperties");
|
||
15 years ago
|
// first, lets see if we have existing properties
|
||
15 years ago
|
TQDomElement elem;
|
||
|
TQDomNode it = doc.documentElement().firstChild();
|
||
15 years ago
|
for( ; !it.isNull(); it = it.nextSibling() ) {
|
||
15 years ago
|
TQDomElement e = it.toElement();
|
||
15 years ago
|
if( e.tagName() == tagActionProp ) {
|
||
|
elem = e;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// if there was none, create one
|
||
|
if( elem.isNull() ) {
|
||
|
elem = doc.createElement( tagActionProp );
|
||
|
doc.documentElement().appendChild( elem );
|
||
|
}
|
||
|
return elem;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement KXMLGUIFactory::findActionByName( TQDomElement& elem, const TQString& sName, bool create )
|
||
15 years ago
|
{
|
||
15 years ago
|
static const TQString& attrName = KGlobal::staticQString( "name" );
|
||
|
static const TQString& tagAction = KGlobal::staticQString( "Action" );
|
||
|
for( TQDomNode it = elem.firstChild(); !it.isNull(); it = it.nextSibling() ) {
|
||
|
TQDomElement e = it.toElement();
|
||
15 years ago
|
if( e.attribute( attrName ) == sName )
|
||
|
return e;
|
||
|
}
|
||
|
|
||
|
if( create ) {
|
||
15 years ago
|
TQDomElement act_elem = elem.ownerDocument().createElement( tagAction );
|
||
15 years ago
|
act_elem.setAttribute( attrName, sName );
|
||
|
elem.appendChild( act_elem );
|
||
|
return act_elem;
|
||
|
}
|
||
15 years ago
|
return TQDomElement();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KXMLGUIFactory::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
#include "kxmlguifactory.moc"
|
||
|
|
||
|
/* vim: et sw=4
|
||
|
*/
|