konq_xmlguiclient.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>
00003    Copyright (c) 1998, 1999 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
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   /*m_builder = new KonqPopupMenuGUIBuilder( this );
00060   m_factory = new KXMLGUIFactory( m_builder ); */
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 //void KonqXMLGUIClient::addWeakSeparator()
00112 //{
00113 //  static const QString& tagWeakSeparator = KGlobal::staticQString( "weakSeparator" );
00114 //  m_menuElement.appendChild( m_doc.createElement( tagWeakSeparator ) );
00115 //}
00116 
00117 void KonqXMLGUIClient::addMerge( const QString &name )
00118 {
00119   // can't call handlePendingSeparator. Merge could be empty
00120   // (testcase: RMB in embedded katepart)
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 
KDE Home | KDE Accessibility Home | Description of Access Keys