00001 /*************************************************************************** 00002 * manager.h 00003 * This file is part of the KDE project 00004 * copyright (C)2004-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_MANAGER_H 00021 #define KROSS_API_MANAGER_H 00022 00023 #include <qstring.h> 00024 #include <qstringlist.h> 00025 #include <qmap.h> 00026 //#include <qvariant.h> 00027 //#include <kdebug.h> 00028 #include <ksharedptr.h> 00029 00030 class QObject; 00031 00032 #include "../api/object.h" 00033 #include "mainmodule.h" 00034 00035 namespace Kross { namespace Api { 00036 00037 // Forward declarations. 00038 class Interpreter; 00039 class Object; 00040 class EventSlot; 00041 class EventSignal; 00042 class ScriptContainer; 00043 class ManagerPrivate; 00044 class InterpreterInfo; 00045 00046 /** 00047 * The Manager class is the main entry point to work with 00048 * Kross. It spends an abstraction layer between what is 00049 * under the hood of Kross and the functionality you need 00050 * to access. 00051 * Use \a Interpreter to just work with some implementated 00052 * interpreter like python. While \a Script spends a more 00053 * flexible container. 00054 */ 00055 class KDE_EXPORT Manager : public MainModule 00056 { 00057 protected: 00058 00059 /** 00060 * Constructor. Use \a scriptManager() to access 00061 * the Manager singleton instance. 00062 */ 00063 Manager(); 00064 00065 public: 00066 00067 /** 00068 * Destructor. 00069 */ 00070 ~Manager(); 00071 00072 /** 00073 * Return the Manager instance. Always use this 00074 * function to access the Manager singleton. 00075 */ 00076 static Manager* scriptManager(); 00077 00078 /** 00079 * \return a map with \a InterpreterInfo* instances 00080 * used to describe interpreters. 00081 */ 00082 QMap<QString, InterpreterInfo*> getInterpreterInfos(); 00083 00084 /** 00085 * \return true if there exists an interpreter with the 00086 * name \p interpretername else false. 00087 */ 00088 bool hasInterpreterInfo(const QString& interpretername) const; 00089 00090 /** 00091 * \return the \a InterpreterInfo* matching to the defined 00092 * \p interpretername or NULL if there does not exists such 00093 * a interpreter. 00094 */ 00095 InterpreterInfo* getInterpreterInfo(const QString& interpretername); 00096 00097 /** 00098 * \return the name of the \a Interpreter that feels responsible 00099 * for the defined \p file . 00100 * 00101 * \param file The filename we should try to determinate the 00102 * interpretername for. 00103 * \return The name of the \a Interpreter which will be used 00104 * to execute the file or QString::null if we failed 00105 * to determinate a matching interpreter for the file. 00106 */ 00107 const QString& getInterpreternameForFile(const QString& file); 00108 00109 /** 00110 * Return the existing \a ScriptContainer with scriptname 00111 * or create a new \a ScriptContainer instance and associate 00112 * the passed scriptname with it. 00113 * 00114 * \param scriptname The name of the script. This 00115 * should be unique for each \a Script and 00116 * could be something like the filename. 00117 * \return The \a ScriptContainer instance matching to 00118 * scriptname. 00119 */ 00120 KSharedPtr<ScriptContainer> getScriptContainer(const QString& scriptname); 00121 00122 /** 00123 * Return the \a Interpreter instance defined by 00124 * the interpretername. 00125 * 00126 * \param interpretername The name of the interpreter. 00127 * e.g. "python" or "kjs". 00128 * \return The Interpreter instance or NULL if there 00129 * does not exists an interpreter with such 00130 * an interpretername. 00131 */ 00132 Interpreter* getInterpreter(const QString& interpretername); 00133 00134 /** 00135 * \return a list of names of the at the backend 00136 * supported interpreters. 00137 */ 00138 const QStringList getInterpreters(); 00139 00140 /** 00141 * Add the an external module to the global shared list of 00142 * loaded modules. 00143 * 00144 * @param module The @a Module instace to add. 00145 * @return true if the module was added successfully else 00146 * false. 00147 */ 00148 bool addModule(Module::Ptr module); 00149 00150 /** 00151 * Load an external module and return it. 00152 * 00153 * \param modulename The name of the library we should try to 00154 * load. Those library needs to be a valid kross module. 00155 * \return The loaded \a Object or NULL if loading 00156 * failed. The loaded Module isn't added to the global 00157 * shared list of modules. 00158 */ 00159 Module::Ptr loadModule(const QString& modulename); 00160 00161 private: 00162 /// Private d-pointer class. 00163 ManagerPrivate* d; 00164 }; 00165 00166 }} 00167 00168 #endif 00169
1.4.6