00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 };
00193
00194 #endif // XMLACTIONCLIENT_H
00195