lib

scriptaction.h

00001 /***************************************************************************
00002  * scriptaction.h
00003  * This file is part of the KDE project
00004  * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program 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  * This program 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  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     // Forward declarations.
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             //Q_PROPERTY(QString interpretername READ getInterpreterName WRITE setInterpreterName)
00047 
00049             //Q_PROPERTY(QString code READ getCode WRITE setCode)
00050 
00052             //Q_PROPERTY(QString file READ getFile WRITE setFile)
00053 
00055             Q_PROPERTY(QString description READ getDescription WRITE setDescription)
00056 
00057         public:
00058 
00060             typedef KSharedPtr<ScriptAction> Ptr;
00061 
00063             //typedef QValueList<ScriptAction::Ptr> List;
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 
KDE Home | KDE Accessibility Home | Description of Access Keys