Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

xmlactionclient.h

00001 // -*- c++ -*-
00002 
00003 /*
00004  *  Copyright (C) 2002-2003, Richard J. Moore <rich@kde.org>
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef XMLACTIONCLIENT_H
00023 #define XMLACTIONCLIENT_H
00024 
00025 #include <qobject.h>
00026 #include <qxml.h>
00027 #include <qmap.h>
00028 
00029 class KActionCollection;
00030 class KAction;
00031 
00032 namespace KJSEmbed {
00033 
00034 class XMLActionHandler;
00035 class XMLActionRunner;
00036 class XMLActionClient;
00037 
00041 class XMLActionScript
00042 {
00043 public:
00044     bool isValid() const { return !type.isEmpty(); }
00045     void clear() { src = type = text = QString::null; }
00046 
00047     QString src;
00048     QString type;
00049     QString text;
00050 };
00051 
00055 class XMLActionRunner
00056 {
00057 public:
00058     virtual bool run( XMLActionClient *client, const XMLActionScript &script );
00059 };
00060 
00064 class XMLActionClient : public QObject
00065 {
00066     Q_OBJECT
00067 
00068 public:
00069 
00070     XMLActionClient( QObject *parent=0, const char *name=0 );
00071     virtual ~XMLActionClient();
00072 
00073     KActionCollection *actionCollection() const { return ac; }
00074     void setActionCollection( KActionCollection *acts ) { ac = acts; }
00075 
00076     XMLActionRunner *runner() const { return actrun; }
00077     void setRunner( XMLActionRunner *r ) { if (actrun) delete actrun; actrun = r; }
00078 
00080     bool load( const QString &filename );
00081 
00083     bool load( XMLActionHandler *handler, const QString &filename );
00084 
00086     bool run( const QString &name );
00087 
00089     XMLActionScript script( const QString &name ) const { return scripts[name]; }
00090 
00092     bool run( const XMLActionScript &script );
00093 
00095     virtual bool bind( const QString &name, const XMLActionScript &script );
00096 
00098     virtual bool bind( KAction *act, const XMLActionScript &script );
00099 
00100 protected slots:
00105     void action_activated();
00106 
00107 private:
00108     KActionCollection *ac;
00109     XMLActionRunner *actrun;
00110     QMap<QString, XMLActionScript> scripts;
00111 };
00112 
00139 class XMLActionHandler : public QXmlDefaultHandler
00140 {
00141 public:
00142     XMLActionHandler( XMLActionClient *ac );
00143 
00144     virtual bool startElement( const QString &ns, const QString &ln, const QString &qn,
00145                                const QXmlAttributes &attrs );
00146     virtual bool endElement( const QString &ns, const QString &ln, const QString &qn );
00147     virtual bool characters( const QString &chars );
00148 
00150     void defineAction();
00151 
00152     XMLActionClient *client() const { return ac; }
00153 
00155     virtual KAction *createAction( KActionCollection *parent );
00156 
00157 protected:
00161     struct XMLActionData {
00162         XMLActionData() { clear(); }
00163 
00164         void clear() {
00165             text = icons = keys = name = group = whatsthis = status = QString::null;
00166             exclusive = false;
00167             script.clear();
00168         }
00169 
00170         QString type;
00171         QString text;
00172         QString icons;
00173         QString keys;
00174         QString name;
00175         QString group;
00176         bool exclusive;
00177         QString status;
00178         QString whatsthis;
00179         XMLActionScript script;
00180         QStringList items;
00181     };
00182 
00183     XMLActionData *actionData() { return &ad; }
00184 
00185 private:
00186     XMLActionClient *ac;
00187     QString cdata;
00188     bool inAction;
00189     XMLActionData ad;
00190 };
00191 
00192 }; // namespace KJSEmbed
00193 
00194 #endif // XMLACTIONCLIENT_H
00195 

Generated at Sat Feb 1 03:23:35 2003 for KJSEmbed by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001