lib
scriptaction.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KROSS_API_SCRIPTACTION_H
00021 #define KROSS_API_SCRIPTACTION_H
00022
00023 #include <qdom.h>
00024 #include <kaction.h>
00025
00026 #include "scriptcontainer.h"
00027
00028 namespace Kross { namespace Api {
00029
00030
00031 class ScriptContainer;
00032 class ScriptActionCollection;
00033 class ScriptActionPrivate;
00034
00039 class ScriptAction
00040 : public KAction
00041 , public Kross::Api::ScriptContainer
00042 {
00043 Q_OBJECT
00044
00046
00047
00049
00050
00052
00053
00055 Q_PROPERTY(QString description READ getDescription WRITE setDescription)
00056
00057 public:
00058
00060 typedef KSharedPtr<ScriptAction> Ptr;
00061
00063
00064
00071 explicit ScriptAction(const QString& file);
00072
00081 explicit ScriptAction(const QString& scriptconfigfile, const QDomElement& element);
00082
00086 virtual ~ScriptAction();
00087
00094 int version() const;
00095
00099 const QString getDescription() const;
00100
00104 void setDescription(const QString& description);
00105
00113 void setInterpreterName(const QString& name);
00114
00120 const QString getPackagePath() const;
00121
00126 const QStringList& getLogs() const;
00127
00132 void attach(ScriptActionCollection* collection);
00133
00138 void detach(ScriptActionCollection* collection);
00139
00144 void detachAll();
00145
00146 public slots:
00147
00153 virtual void activate();
00154
00159 void finalize();
00160
00161 signals:
00162
00166 void activated(const Kross::Api::ScriptAction*);
00167
00172 void success();
00173
00179 void failed(const QString& errormessage, const QString& tracedetails);
00180
00181 private:
00183 ScriptActionPrivate* d;
00184 };
00185
00192 class ScriptActionCollection
00193 {
00194 private:
00195
00199 QValueList<ScriptAction::Ptr> m_list;
00200
00205 QMap<QCString, ScriptAction::Ptr> m_actions;
00206
00211 KActionMenu* m_actionmenu;
00212
00219 bool m_dirty;
00220
00228 ScriptActionCollection(const ScriptActionCollection&) {}
00229
00230 public:
00231
00240 ScriptActionCollection(const QString& text, KActionCollection* ac, const char* name)
00241 : m_actionmenu( new KActionMenu(text, ac, name) )
00242 , m_dirty(true) {}
00243
00244
00248 ~ScriptActionCollection() {
00249 for(QValueList<ScriptAction::Ptr>::Iterator it = m_list.begin(); it != m_list.end(); ++it)
00250 (*it)->detach(this);
00251 }
00252
00257 ScriptAction::Ptr action(const QCString& name) { return m_actions[name]; }
00258
00262 QValueList<ScriptAction::Ptr> actions() { return m_list; }
00263
00267 KActionMenu* actionMenu() { return m_actionmenu; }
00268
00272 void attach(ScriptAction::Ptr action) {
00273 m_dirty = true;
00274 m_actions[ action->name() ] = action;
00275 m_list.append(action);
00276 m_actionmenu->insert(action);
00277 action->attach(this);
00278 }
00279
00283 void detach(ScriptAction::Ptr action) {
00284 m_dirty = true;
00285 m_actions.remove(action->name());
00286 m_list.remove(action);
00287 m_actionmenu->remove(action);
00288 action->detach(this);
00289 }
00290
00295 void clear() {
00296 for(QValueList<ScriptAction::Ptr>::Iterator it = m_list.begin(); it != m_list.end(); ++it) {
00297 m_actionmenu->remove(*it);
00298 (*it)->detach(this);
00299 }
00300 m_list.clear();
00301 m_actions.clear();
00302 }
00303
00304 };
00305
00306 }}
00307
00308 #endif
00309
|