00001 /*************************************************************************** 00002 * scriptguiclient.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_SCRIPTGUICLIENT_H 00021 #define KROSS_API_SCRIPTGUICLIENT_H 00022 00023 #include "scriptcontainer.h" 00024 #include "scriptaction.h" 00025 00026 #include <qobject.h> 00027 #include <qdom.h> 00028 #include <kurl.h> 00029 #include <kxmlguiclient.h> 00030 00031 class QWdiget; 00032 00033 namespace Kross { namespace Api { 00034 00035 // Forward declarations. 00036 class ScriptAction; 00037 class ScriptGUIClientPrivate; 00038 00039 /** 00040 * The ScriptGUIClient class provides abstract access to 00041 * scripting code used to extend an applications functionality. 00042 */ 00043 class KDE_EXPORT ScriptGUIClient 00044 : public QObject 00045 , public KXMLGUIClient 00046 { 00047 Q_OBJECT 00048 //Q_PROPERTY(QString configfile READ getConfigFile WRITE setConfigFile) 00049 00050 public: 00051 00052 /// List of KAction instances. 00053 typedef QPtrList<KAction> List; 00054 00055 /** 00056 * Constructor. 00057 * 00058 * \param guiclient The KXMLGUIClient this \a ScriptGUIClient 00059 * is a child of. 00060 * \param parent The parent QObject. If defined Qt will handle 00061 * freeing this \a ScriptGUIClient instance else the 00062 * caller has to take care of freeing this instance 00063 * if not needed any longer. 00064 */ 00065 explicit ScriptGUIClient(KXMLGUIClient* guiclient, QWidget* parent = 0); 00066 00067 /** 00068 * Destructor. 00069 */ 00070 virtual ~ScriptGUIClient(); 00071 00072 /** 00073 * \return true if this \a ScriptGUIClient has a \a ScriptActionCollection 00074 * with the name \p name else false is returned. 00075 */ 00076 bool hasActionCollection(const QString& name); 00077 00078 /** 00079 * \return the \a ScriptActionCollection which has the name \p name 00080 * or NULL if there exists no such \a ScriptActionCollection . 00081 */ 00082 ScriptActionCollection* getActionCollection(const QString& name); 00083 00084 /** 00085 * \return a map of all avaiable \a ScriptActionCollection instances 00086 * this \a ScriptGUIClient knows about. 00087 * Per default there are 2 collections avaiable; 00088 * 1. "installedscripts" The installed collection of scripts. 00089 * 2. "loadedscripts" The loaded scripts. 00090 */ 00091 QMap<QString, ScriptActionCollection*> getActionCollections(); 00092 00093 /** 00094 * Add a new \a ScriptActionCollection with the name \p name to 00095 * our map of actioncollections. 00096 */ 00097 void addActionCollection(const QString& name, ScriptActionCollection* collection); 00098 00099 /** 00100 * Remove the \a ScriptActionCollection defined with name \p name. 00101 */ 00102 bool removeActionCollection(const QString& name); 00103 00104 /** 00105 * Reload the list of installed scripts. 00106 */ 00107 void reloadInstalledScripts(); 00108 00109 /** 00110 * Install the packagefile \p scriptpackagefile . Those 00111 * packagefile should be a tar.gz-archive which will be 00112 * extracted and to the users script-directory. 00113 */ 00114 bool installScriptPackage(const QString& scriptpackagefile); 00115 00116 /** 00117 * Uninstall the scriptpackage located in the path 00118 * \p scriptpackagepath . This just deletes the whole 00119 * directory. 00120 */ 00121 bool uninstallScriptPackage(const QString& scriptpackagepath); 00122 00123 /** 00124 * Load the scriptpackage's configurationfile 00125 * \p scriptconfigfile and add the defined \a ScriptAction 00126 * instances that will be added to the list of installed 00127 * scripts. 00128 */ 00129 bool loadScriptConfig(const QString& scriptconfigfile); 00130 00131 public slots: 00132 00133 /** 00134 * A KFileDialog will be displayed to let the user choose 00135 * a scriptfile. The choosen file will be returned as KURL. 00136 */ 00137 KURL openScriptFile(const QString& caption = QString::null); 00138 00139 /** 00140 * A KFileDialog will be displayed to let the user choose 00141 * a scriptfile that should be loaded. 00142 * Those loaded \a ScriptAction will be added to the 00143 * \a ScriptActionCollection of loaded scripts. 00144 */ 00145 bool loadScriptFile(); 00146 00147 /** 00148 * A KFileDialog will be displayed to let the user choose 00149 * the scriptfile that should be executed. 00150 * The executed \a ScriptAction will be added to the 00151 * \a ScriptActionCollection of executed scripts. 00152 */ 00153 bool executeScriptFile(); 00154 00155 /** 00156 * Execute the scriptfile \p file . Internaly we try to use 00157 * the defined filename to auto-detect the \a Interpreter which 00158 * should be used for the execution. 00159 */ 00160 bool executeScriptFile(const QString& file); 00161 00162 /** 00163 * This method executes the \a ScriptAction \p action . 00164 * Internaly we just call \a ScriptAction::activate and 00165 * redirect the success/failed signals to our internal slots. 00166 */ 00167 bool executeScriptAction(ScriptAction::Ptr action); 00168 00169 /** 00170 * The \a ScriptManagerGUI dialog will be displayed to 00171 * let the user manage the scriptfiles. 00172 */ 00173 void showScriptManager(); 00174 00175 private slots: 00176 00177 /** 00178 * Called if execution of this \a ScriptAction failed and 00179 * displays an errormessage-dialog. 00180 */ 00181 void executionFailed(const QString& errormessage, const QString& tracedetails); 00182 00183 /** 00184 * Called if execution of this \a ScriptAction was 00185 * successfully. The \a ScriptAction will be added 00186 * to the history-collection of successfully executed 00187 * \a ScriptAction instances. 00188 */ 00189 void successfullyExecuted(); 00190 00191 signals: 00192 void collectionChanged(ScriptActionCollection*); 00193 /// This signal is emited when the execution of a script is finished 00194 void executionFinished(const Kross::Api::ScriptAction* ); 00195 private: 00196 /// Internaly used private d-pointer. 00197 ScriptGUIClientPrivate* d; 00198 }; 00199 00200 }} 00201 00202 #endif 00203
1.4.6