konq_xmlguiclient.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kapplication.h"
00022
00023 #include "konq_xmlguiclient.h"
00024 #include <kdebug.h>
00025
00026 class KonqXMLGUIClient::Private
00027 {
00028 public:
00029 Private() : attrName( "name" ), separatorPending( false ), hasAction( false ) {}
00030 QString attrName;
00031 bool separatorPending;
00032 bool hasAction;
00033 };
00034
00035 KonqXMLGUIClient::KonqXMLGUIClient( ) : KXMLGUIClient( )
00036 {
00037 d = new Private;
00038 prepareXMLGUIStuff( );
00039 }
00040
00041 KonqXMLGUIClient::KonqXMLGUIClient( KXMLGUIClient *parent ) : KXMLGUIClient(parent )
00042 {
00043 d = new Private;
00044 prepareXMLGUIStuff( );
00045 }
00046
00047 void KonqXMLGUIClient::prepareXMLGUIStuff()
00048 {
00049 m_doc = QDomDocument( "kpartgui" );
00050
00051 QDomElement root = m_doc.createElement( "kpartgui" );
00052 m_doc.appendChild( root );
00053 root.setAttribute( d->attrName, "popupmenu" );
00054
00055 m_menuElement = m_doc.createElement( "Menu" );
00056 root.appendChild( m_menuElement );
00057 m_menuElement.setAttribute( d->attrName, "popupmenu" );
00058
00059
00060
00061 }
00062
00063 QDomElement KonqXMLGUIClient::DomElement() const
00064 {
00065 return m_menuElement;
00066 }
00067
00068 QDomDocument KonqXMLGUIClient::domDocument() const
00069 {
00070 return m_doc;
00071 }
00072
00073 void KonqXMLGUIClient::addAction( KAction *act, const QDomElement &menu )
00074 {
00075 addAction( act->name(), menu );
00076 }
00077
00078 void KonqXMLGUIClient::addAction( const char *name, const QDomElement &menu )
00079 {
00080 static const QString& tagAction = KGlobal::staticQString( "action" );
00081
00082 if (!kapp->authorizeKAction(name))
00083 return;
00084
00085 handlePendingSeparator();
00086 QDomElement parent = menu;
00087 if ( parent.isNull() ) {
00088 parent = m_menuElement;
00089 }
00090
00091 QDomElement e = m_doc.createElement( tagAction );
00092 parent.appendChild( e );
00093 e.setAttribute( d->attrName, name );
00094 d->hasAction = true;
00095 }
00096
00097 void KonqXMLGUIClient::addSeparator( const QDomElement &menu )
00098 {
00099 static const QString& tagSeparator = KGlobal::staticQString( "separator" );
00100
00101 QDomElement parent = menu;
00102 if ( parent.isNull() ) {
00103 parent = m_menuElement;
00104 }
00105
00106 parent.appendChild( m_doc.createElement( tagSeparator ) );
00107
00108 d->separatorPending = false;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 void KonqXMLGUIClient::addMerge( const QString &name )
00118 {
00119
00120
00121 QDomElement merge = m_doc.createElement( "merge" );
00122 m_menuElement.appendChild( merge );
00123 if ( !name.isEmpty() )
00124 merge.setAttribute( d->attrName, name );
00125 }
00126
00127 void KonqXMLGUIClient::addGroup( const QString &grp )
00128 {
00129 handlePendingSeparator();
00130 QDomElement group = m_doc.createElement( "definegroup" );
00131 m_menuElement.appendChild( group );
00132 group.setAttribute( d->attrName, grp );
00133 }
00134
00135 KonqXMLGUIClient::~KonqXMLGUIClient()
00136 {
00137 delete d;
00138 }
00139
00140 void KonqXMLGUIClient::handlePendingSeparator()
00141 {
00142 if ( d->separatorPending ) {
00143 addSeparator();
00144 }
00145 }
00146
00147 void KonqXMLGUIClient::addPendingSeparator()
00148 {
00149 d->separatorPending = true;
00150 }
00151
00152 bool KonqXMLGUIClient::hasAction() const
00153 {
00154 return d->hasAction;
00155 }
00156
00157
|