21 #include "tdeapplication.h"
23 #include "konq_xmlguiclient.h"
26 class KonqXMLGUIClient::Private
29 Private() : attrName(
"name" ), separatorPending( false ), hasAction( false ) {}
31 bool separatorPending;
35 KonqXMLGUIClient::KonqXMLGUIClient( ) : KXMLGUIClient( )
38 prepareXMLGUIStuff( );
41 KonqXMLGUIClient::KonqXMLGUIClient( KXMLGUIClient *parent ) : KXMLGUIClient(parent )
44 prepareXMLGUIStuff( );
47 void KonqXMLGUIClient::prepareXMLGUIStuff()
49 m_doc = TQDomDocument(
"kpartgui" );
51 TQDomElement root = m_doc.createElement(
"kpartgui" );
52 m_doc.appendChild( root );
53 root.setAttribute( d->attrName,
"popupmenu" );
55 m_menuElement = m_doc.createElement(
"Menu" );
56 root.appendChild( m_menuElement );
57 m_menuElement.setAttribute( d->attrName,
"popupmenu" );
63 TQDomElement KonqXMLGUIClient::DomElement()
const
73 void KonqXMLGUIClient::addAction( TDEAction *act,
const TQDomElement &menu )
75 addAction( act->name(), menu );
78 void KonqXMLGUIClient::addAction(
const char *name,
const TQDomElement &menu )
80 static const TQString& tagAction = TDEGlobal::staticQString(
"action" );
82 if (!kapp->authorizeTDEAction(name))
85 handlePendingSeparator();
86 TQDomElement parent = menu;
87 if ( parent.isNull() ) {
88 parent = m_menuElement;
91 TQDomElement e = m_doc.createElement( tagAction );
92 parent.appendChild( e );
93 e.setAttribute( d->attrName, name );
97 void KonqXMLGUIClient::addSeparator(
const TQDomElement &menu )
99 static const TQString& tagSeparator = TDEGlobal::staticQString(
"separator" );
101 TQDomElement parent = menu;
102 if ( parent.isNull() ) {
103 parent = m_menuElement;
106 parent.appendChild( m_doc.createElement( tagSeparator ) );
108 d->separatorPending =
false;
117 void KonqXMLGUIClient::addMerge(
const TQString &name )
121 TQDomElement merge = m_doc.createElement(
"merge" );
122 m_menuElement.appendChild( merge );
123 if ( !name.isEmpty() )
124 merge.setAttribute( d->attrName, name );
127 void KonqXMLGUIClient::addGroup(
const TQString &grp )
129 handlePendingSeparator();
130 TQDomElement group = m_doc.createElement(
"definegroup" );
131 m_menuElement.appendChild( group );
132 group.setAttribute( d->attrName, grp );
135 KonqXMLGUIClient::~KonqXMLGUIClient()
140 void KonqXMLGUIClient::handlePendingSeparator()
142 if ( d->separatorPending ) {
149 d->separatorPending =
true;
152 bool KonqXMLGUIClient::hasAction()
const
157 bool KonqXMLGUIClient::hasGroup(
const TQString &name)
const
163 TQDomNodeList groups = m_doc.elementsByTagName(
"definegroup");
164 for (uint idx = 0; idx < groups.count(); ++idx)
166 TQDomElement group = groups.item(idx).toElement();
167 if (group.hasAttribute(d->attrName) && group.attribute(d->attrName) == name)
void addPendingSeparator()
only add a separator if an action is added afterwards
TQDomDocument domDocument() const
Reimplemented for internal purpose.