00001 /*************************************************************************** 00002 * mainmodule.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_MAINMODULE_H 00021 #define KROSS_API_MAINMODULE_H 00022 00023 #include "../api/object.h" 00024 #include "../api/variant.h" 00025 #include "../api/module.h" 00026 #include "../api/event.h" 00027 #include "../api/eventsignal.h" 00028 #include "../api/eventslot.h" 00029 #include "../api/qtobject.h" 00030 #include "../api/eventaction.h" 00031 00032 #include <qstring.h> 00033 #include <qvariant.h> 00034 #include <qobject.h> 00035 00036 #include <ksharedptr.h> 00037 #include <kaction.h> 00038 00039 namespace Kross { namespace Api { 00040 00041 // Forward declarations. 00042 class MainModulePrivate; 00043 00044 /** 00045 * This class implements \a Module for the global 00046 * \a Manager singleton and local \a ScriptContainer 00047 * instances. 00048 * 00049 * The MainModule class provides base functionality 00050 * for a root node in a tree of \a Kross::Api::Object 00051 * instances. 00052 */ 00053 class MainModule : public Module 00054 { 00055 public: 00056 00057 /// Shared pointer to implement reference-counting. 00058 typedef KSharedPtr<MainModule> Ptr; 00059 00060 /** 00061 * Constructor. 00062 * 00063 * \param name the name of the \a Module . While the 00064 * global manager module has the name "Kross" 00065 * the \a ScriptContainer instances are accessible 00066 * by there \a ScriptContainer::getName() name. 00067 */ 00068 explicit MainModule(const QString& name); 00069 00070 /** 00071 * Destructor. 00072 */ 00073 virtual ~MainModule(); 00074 00075 /// \see Kross::Api::Object::getClassName() 00076 virtual const QString getClassName() const; 00077 00078 /** 00079 * \return true if the script throwed an exception 00080 * else false. 00081 */ 00082 bool hadException(); 00083 00084 /** 00085 * \return the \a Exception this module throwed. 00086 */ 00087 Exception::Ptr getException(); 00088 00089 /** 00090 * Set the \a Exception this module throwed. 00091 * 00092 * \param exception The \a Exception this module throws or 00093 * NULL if you like to clear exception and to let 00094 * \a hadException() return false. 00095 */ 00096 void setException(Exception::Ptr exception); 00097 00098 /** 00099 * Returns if the defined child is avaible. 00100 * 00101 * \return true if child exists else false. 00102 */ 00103 bool hasChild(const QString& name) const; 00104 00105 /** 00106 * Add a Qt signal to the \a Module by creating 00107 * an \a EventSignal for it. 00108 * 00109 * \param name the name the \a EventSignal is 00110 * reachable as 00111 * \param sender the QObject instance which 00112 * is the sender of the \p signal 00113 * \param signal the Qt signal macro the \p sender 00114 * emits to call the \a EventSignal 00115 * \return the newly added \a EventSignal instance 00116 * which is now a child of this \a MainModule 00117 */ 00118 EventSignal::Ptr addSignal(const QString& name, QObject* sender, QCString signal); 00119 00120 /** 00121 * Add a Qt slot to the \a Module by creating 00122 * an \a EventSlot for it. 00123 * 00124 * \param name the name the \a EventSlot is 00125 * reachable as 00126 * \param receiver the QObject instance which 00127 * is the receiver of the \p signal 00128 * \param slot the Qt slot macro of the \p receiver 00129 * to invoke if the \a EventSlot got called. 00130 * \return the newly added \a EventSlot instance 00131 * which is now a child of this \a MainModule 00132 */ 00133 EventSlot::Ptr addSlot(const QString& name, QObject* receiver, QCString slot); 00134 00135 /** 00136 * Add a \a QObject to the eventcollection. All 00137 * signals and slots the QObject has will be 00138 * added to a new \a EventCollection instance 00139 * which is child of this \a EventCollection 00140 * instance. 00141 * 00142 * \param object the QObject instance that should 00143 * be added to this \a MainModule 00144 * \param name the name under which this QObject instance 00145 * should be registered as 00146 * \return the newly added \a QtObject instance 00147 * which is now a child of this \a MainModule 00148 */ 00149 QtObject::Ptr addQObject(QObject* object, const QString& name = QString::null); 00150 00151 /** 00152 * Add a \a KAction to the eventcollection. The 00153 * KAction will be wrapped by a \a EventAction 00154 * and will be added to this collection. 00155 * 00156 * \param name name to identify the \a action by 00157 * \param action the KAction instance that should 00158 * be added to this \a MainModule 00159 * \return the newly added \a EventAction instance 00160 * which is now a child of this \a MainModule 00161 * 00162 * \todo check \a name dox. 00163 */ 00164 EventAction::Ptr addKAction(KAction* action, const QString& name = QString::null); 00165 00166 //typedef QValueList<Callable::Ptr> EventList; 00167 //EventList getEvents(); 00168 //const QString& serializeToXML(); 00169 //void unserializeFromXML(const QString& xml); 00170 00171 private: 00172 /// Private d-pointer class. 00173 MainModulePrivate* d; 00174 }; 00175 00176 }} 00177 00178 #endif 00179
1.4.6