lib

scriptaction.h
1/***************************************************************************
2 * scriptaction.h
3 * This file is part of the KDE project
4 * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#ifndef KROSS_API_SCRIPTACTION_H
21#define KROSS_API_SCRIPTACTION_H
22
23#include <tqdom.h>
24#include <tdeaction.h>
25
26#include "scriptcontainer.h"
27
28namespace Kross { namespace Api {
29
30 // Forward declarations.
31 class ScriptContainer;
33 class ScriptActionPrivate;
34
40 : public TDEAction
42 {
43 TQ_OBJECT
44
45
47 //TQ_PROPERTY(TQString interpretername READ getInterpreterName WRITE setInterpreterName)
48
50 //TQ_PROPERTY(TQString code READ getCode WRITE setCode)
51
53 //TQ_PROPERTY(TQString file READ getFile WRITE setFile)
54
56 TQ_PROPERTY(TQString description READ getDescription WRITE setDescription)
57
58 public:
59
61 typedef TDESharedPtr<ScriptAction> Ptr;
62
64 //typedef TQValueList<ScriptAction::Ptr> List;
65
72 explicit ScriptAction(const TQString& file);
73
82 explicit ScriptAction(const TQString& scriptconfigfile, const TQDomElement& element);
83
87 virtual ~ScriptAction();
88
95 int version() const;
96
100 const TQString getDescription() const;
101
105 void setDescription(const TQString& description);
106
114 void setInterpreterName(const TQString& name);
115
121 const TQString getPackagePath() const;
122
127 const TQStringList& getLogs() const;
128
133 void attach(ScriptActionCollection* collection);
134
139 void detach(ScriptActionCollection* collection);
140
145 void detachAll();
146
147 public slots:
148
154 virtual void activate();
155
160 void finalize();
161
162 signals:
163
168
173 void success();
174
180 void failed(const TQString& errormessage, const TQString& tracedetails);
181
182 private:
184 ScriptActionPrivate* d;
185 };
186
193 class ScriptActionCollection
194 {
195 private:
196
200 TQValueList<ScriptAction::Ptr> m_list;
201
206 TQMap<TQCString, ScriptAction::Ptr> m_actions;
207
212 TDEActionMenu* m_actionmenu;
213
220 bool m_dirty;
221
229 ScriptActionCollection(const ScriptActionCollection&) {}
230
231 public:
232
241 ScriptActionCollection(const TQString& text, TDEActionCollection* ac, const char* name)
242 : m_actionmenu( new TDEActionMenu(text, ac, name) )
243 , m_dirty(true) {}
244
245
250 for(TQValueList<ScriptAction::Ptr>::Iterator it = m_list.begin(); it != m_list.end(); ++it)
251 (*it)->detach(this);
252 }
253
258 ScriptAction::Ptr action(const TQCString& name) { return m_actions[name]; }
259
263 TQValueList<ScriptAction::Ptr> actions() { return m_list; }
264
268 TDEActionMenu* actionMenu() { return m_actionmenu; }
269
274 m_dirty = true;
275 m_actions[ action->name() ] = action;
276 m_list.append(action);
277 m_actionmenu->insert(action);
278 action->attach(this);
279 }
280
285 m_dirty = true;
286 m_actions.remove(action->name());
287 m_list.remove(action);
288 m_actionmenu->remove(action);
289 action->detach(this);
290 }
291
296 void clear() {
297 for(TQValueList<ScriptAction::Ptr>::Iterator it = m_list.begin(); it != m_list.end(); ++it) {
298 m_actionmenu->remove(*it);
299 (*it)->detach(this);
300 }
301 m_list.clear();
302 m_actions.clear();
303 }
304
305 };
306
307}}
308
309#endif
310
A collection to store ScriptAction shared pointers.
void detach(ScriptAction::Ptr action)
Detach a ScriptAction instance from this ScriptActionCollection .
void clear()
Clear this ScriptActionCollection .
TQValueList< ScriptAction::Ptr > actions()
ScriptActionCollection(const TQString &text, TDEActionCollection *ac, const char *name)
Constructor.
ScriptAction::Ptr action(const TQCString &name)
void attach(ScriptAction::Ptr action)
Attach a ScriptAction instance to this ScriptActionCollection .
A ScriptAction extends a TDEAction by providing a wrapper around a ScriptContainer to execute scripti...
void detach(ScriptActionCollection *collection)
Detach this ScriptAction from the ScriptActionCollection collection .
void failed(const TQString &errormessage, const TQString &tracedetails)
This signal got emitted after the try to execute this ScriptAction failed.
void finalize()
This slot finalizes the ScriptContainer and tries to clean any still running script.
void activated(const Kross::Api::ScriptAction *)
This signal got emitted when this action is emitted before execution.
void attach(ScriptActionCollection *collection)
Attach this ScriptAction to the ScriptActionCollection collection .
const TQString getDescription() const
TDESharedPtr< ScriptAction > Ptr
The name of the interpreter used to execute the scripting code.
void setInterpreterName(const TQString &name)
Set the name of the interpreter which will be used on activation to execute the scripting code.
void detachAll()
Detach this ScriptAction from all ScriptActionCollection instance his ScriptAction is attached to.
const TQStringList & getLogs() const
void setDescription(const TQString &description)
Set the description description for this ScriptAction .
ScriptAction(const TQString &file)
A list of ScriptAction instances.
virtual ~ScriptAction()
Destructor.
virtual void activate()
If the ScriptAction got activated the ScriptContainer got executed.
const TQString getPackagePath() const
void success()
This signal got emitted after this ScriptAction got executed successfully.
The ScriptContainer class is something like a single standalone scriptfile.
TDEAction(const TQString &text, const TDEShortcut &cut, const TQObject *receiver, const char *slot, TDEActionCollection *parent, const char *name)
The common Kross API used as common codebase.
Definition callable.h:33
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:33