37 #include <QtXml/QDomElement>
38 #include <QtCore/QObject>
39 #include <QtCore/QMutableStringListIterator>
40 #include "kmenumenuhandler_p.h"
43 using namespace KDEPrivate;
45 class KXMLGUIBuilderPrivate
48 KXMLGUIBuilderPrivate() : m_client(0L) {}
49 ~KXMLGUIBuilderPrivate() { }
75 KMenuMenuHandler *m_menumenuhandler;
80 : d( new KXMLGUIBuilderPrivate )
84 d->tagMainWindow = QLatin1String(
"mainwindow" );
85 d->tagMenuBar = QLatin1String(
"menubar" );
86 d->tagMenu = QLatin1String(
"menu" );
87 d->tagToolBar = QLatin1String(
"toolbar" );
88 d->tagStatusBar = QLatin1String(
"statusbar" );
90 d->tagSeparator = QLatin1String(
"separator" );
91 d->tagTearOffHandle = QLatin1String(
"tearoffhandle" );
92 d->tagMenuTitle = QLatin1String(
"title" );
94 d->attrName = QLatin1String(
"name" );
95 d->attrLineSeparator = QLatin1String(
"lineseparator" );
97 d->attrText1 = QLatin1String(
"text" );
98 d->attrText2 = QLatin1String(
"Text" );
99 d->attrContext = QLatin1String(
"context" );
101 d->attrIcon = QLatin1String(
"icon" );
103 d->m_menumenuhandler=
new KMenuMenuHandler(
this);
108 delete d->m_menumenuhandler;
120 res << d->tagMenu << d->tagToolBar << d->tagMainWindow << d->tagMenuBar << d->tagStatusBar;
129 if (element.attribute(
"deleted").toLower() ==
"true") {
133 const QString tagName = element.tagName().toLower();
134 if ( tagName == d->tagMainWindow ) {
139 if ( tagName == d->tagMenuBar ) {
150 if ( tagName == d->tagMenu ) {
161 while ( p && !qobject_cast<QMainWindow*>( p ) )
162 p = p->parentWidget();
164 QByteArray
name = element.attribute( d->attrName ).toUtf8();
166 if (!KAuthorized::authorizeKAction(name))
170 popup->setObjectName(name);
172 d->m_menumenuhandler->insertKMenu(popup);
175 QDomElement textElem = element.namedItem( d->attrText1 ).toElement();
176 if ( textElem.isNull() )
177 textElem = element.namedItem( d->attrText2 ).toElement();
178 const QByteArray text = textElem.text().toUtf8();
179 const QByteArray context = textElem.attribute(d->attrContext).toUtf8();
181 if ( text.isEmpty() )
182 i18nText =
i18n(
"No text" );
183 else if ( context.isEmpty() )
184 i18nText =
i18n( text );
186 i18nText =
i18nc( context, text );
188 const QString icon = element.attribute( d->attrIcon );
190 if (!icon.isEmpty()) {
195 QAction* act = popup->menuAction();
196 if ( !icon.isEmpty() )
198 act->setText(i18nText);
199 if (index == -1 || index >= parent->actions().count())
200 parent->addAction(act);
202 parent->insertAction(parent->actions().value(index), act);
203 containerAction = act;
204 containerAction->setObjectName( name );
210 if ( tagName == d->tagToolBar ) {
211 QByteArray
name = element.attribute( d->attrName ).toUtf8();
216 bar =
new KToolBar(name, d->m_widget,
false);
219 if ( qobject_cast<KMainWindow*>( d->m_widget ) )
221 if ( d->m_client && !d->m_client->xmlFile().isEmpty() )
230 if ( tagName == d->tagStatusBar ) {
247 if ( qobject_cast<QMenu*>( container ) )
250 parent->removeAction( containerAction );
255 else if ( qobject_cast<KToolBar*>( container ) )
262 else if ( qobject_cast<KMenuBar*>( container ) )
271 else if ( qobject_cast<KStatusBar*>( container ) )
273 if ( qobject_cast<KMainWindow*>( d->m_widget ) )
279 kWarning() <<
"Unhandled container to remove : " << container->metaObject()->className();
285 res << d->tagSeparator << d->tagTearOffHandle << d->tagMenuTitle;
292 if (index > 0 && index < parent->actions().count())
293 before = parent->actions().at(index);
295 const QString tagName = element.tagName().toLower();
296 if (tagName == d->tagSeparator)
298 if (
QMenu *menu = qobject_cast<QMenu*>( parent ) )
302 return menu->insertSeparator( before );
304 else if (
QMenuBar* bar = qobject_cast<QMenuBar*>( parent ) )
307 separatorAction->setSeparator(
true);
308 bar->insertAction( before, separatorAction );
309 return separatorAction;
311 else if (
KToolBar *bar = qobject_cast<KToolBar*>( parent ) )
334 return bar->insertSeparator( before );
337 else if (tagName == d->tagTearOffHandle)
339 static_cast<QMenu *
>(parent)->setTearOffEnabled(
true);
341 else if (tagName == d->tagMenuTitle)
343 if (
KMenu* m = qobject_cast<KMenu*>( parent ) )
346 QByteArray text = element.text().toUtf8();
348 if ( text.isEmpty() )
349 i18nText =
i18n(
"No text" );
351 i18nText =
i18n( text );
353 QString icon = element.attribute( d->attrIcon );
356 if ( !icon.isEmpty() )
361 if ( !icon.isEmpty() ) {
362 return m->addTitle( pix, i18nText, before );
364 return m->addTitle( i18nText, before );
370 blank->setVisible(
false);
371 parent->insertAction(before, blank);
377 parent->removeAction(action);
387 d->m_client = client;
394 return d->m_componentData;
399 d->m_componentData = componentData;
409 QListIterator<KToolBar> it( ( (
KMainWindow*)d->m_widget )->toolBarIterator() );
410 while ( ( toolbar = it.current() ) ) {
411 kDebug(260) <<
"KXMLGUIBuilder::finalizeGUI toolbar=" << (
void*)toolbar;
413 toolbar->positionYourself();