Eneboo - Documentación para desarrolladores
|
00001 /*************************************************************************** 00002 AQSSProject_p.h 00003 ------------------- 00004 begin : 07/02/2011 00005 copyright : (C) 2003-2011 by InfoSiAL S.L. 00006 email : mail@infosial.com 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; version 2 of the License. * 00012 ***************************************************************************/ 00013 /*************************************************************************** 00014 Este programa es software libre. Puede redistribuirlo y/o modificarlo 00015 bajo los términos de la Licencia Pública General de GNU en su 00016 versión 2, publicada por la Free Software Foundation. 00017 ***************************************************************************/ 00018 00019 #ifndef AQSSPROJECT_P_H_ 00020 #define AQSSPROJECT_P_H_ 00021 00022 #include "AQSSInterpreter_p.h" 00023 #include <qsproject.h> 00024 #include <qsworkbench.h> 00025 #include <qtimer.h> 00026 00027 class AQSSProject : public AQSObject 00028 { 00029 Q_OBJECT 00030 00031 Q_ENUMS(ScriptState) 00032 00033 Q_PROPERTY(QString entryFunction READ entryFunction) 00034 00035 AQ_DECLARE_AQS_OBJECT(SProject, Object); 00036 00037 public: 00038 enum ScriptState { 00039 New, 00040 Changed, 00041 UnChanged 00042 }; 00043 00044 QString entryFunction() const { 00045 return entryFunction_; 00046 } 00047 00048 protected: 00049 void specializedInternalInit() { 00050 wb_ = 0; 00051 if (!o_) 00052 return; 00053 QObject::setName(o_->name()); 00054 } 00055 00056 private: 00057 QString entryFunction_; 00058 QVariantList scriptInfos_; 00059 QSWorkbench *wb_; 00060 int callTries_; 00061 00062 private slots: 00063 void callEntryFunction() { 00064 if (entryFunction_.isEmpty()) 00065 return; 00066 QSInterpreter *ip = o_->interpreter(); 00067 if (ip->isRunning()) { 00068 QTimer::singleShot(50, this, SLOT(callEntryFunction())); 00069 return; 00070 } 00071 if (callTries_ < 4 && !ip->hasFunction(entryFunction_)) { 00072 ++callTries_; 00073 QTimer::singleShot(50, this, SLOT(callEntryFunction())); 00074 return; 00075 } 00076 ip->call(entryFunction_); 00077 entryFunction_ = QString::null; 00078 } 00079 00080 void evaluateScripts() { 00081 QVariantList::const_iterator it; 00082 for (it = scriptInfos_.begin(); it != scriptInfos_.end(); ++it) { 00083 const QVariantList scrInfo((*it).toList()); 00084 if (scrInfo.size() < 4) 00085 continue; 00086 00087 QString scrName(scrInfo[0].toString()); 00088 QString scrCode(scrInfo[1].toString()); 00089 ScriptState scrState = (ScriptState) scrInfo[2].toUInt(); 00090 00091 switch (scrState) { 00092 case New: { 00093 QSScript *scr = o_->createScript(scrName, scrCode); 00094 if (scr) 00095 scr->setFileName(scrInfo[3].toString()); 00096 break; 00097 } 00098 case Changed: { 00099 QSScript *scr = o_->script(scrName); 00100 if (scr) 00101 scr->setCode(scrCode); 00102 break; 00103 } 00104 } 00105 } 00106 scriptInfos_.clear(); 00107 } 00108 00109 public slots: 00110 void evaluate(const QString &entryFunction) { 00111 if (!o_) 00112 return; 00113 o_->commitEditorContents(); 00114 entryFunction_ = entryFunction; 00115 callTries_ = 0; 00116 QTimer::singleShot(0, o_, SLOT(evaluate())); 00117 QTimer::singleShot(0, this, SLOT(callEntryFunction())); 00118 } 00119 00120 void evaluateScripts(const QValueList<QVariant> &scriptInfos, 00121 const QString &entryFunction = QString::null) { 00122 if (!o_) 00123 return; 00124 scriptInfos_ = scriptInfos; 00125 QTimer::singleShot(0, this, SLOT(evaluateScripts())); 00126 evaluate(entryFunction); 00127 } 00128 00129 QSWorkbench *workbench() { 00130 if (!wb_ && o_) { 00131 wb_ = new QSWorkbench(o_, 0, QObject::name()); 00132 connect(o_, SIGNAL(destroyed()), wb_, SLOT(deleteLater())); 00133 } 00134 return wb_; 00135 } 00136 00137 //@AQ_BEGIN_DEF_PUB_SLOTS@ 00138 public slots: 00139 bool editorsModified() const; 00140 bool scriptsModified() const; 00141 QStringList scriptNames() const; 00142 QSScript *script(const QString &) const; 00143 QSScript *script(QObject *) const; 00144 QObject *object(const QString &) const; 00145 QObjectList objects() const; 00146 QSScript *createScript(QObject *, const QString& = QString::null); 00147 QSScript *createScript(const QString &, const QString& = QString::null); 00148 QSEditor *activeEditor() const; 00149 QSEditor *editor(QSScript *) const; 00150 QSEditor *createEditor(QSScript *, QWidget* = 0, const char* = 0); 00151 void addObject(QObject *); 00152 void removeObject(const QObject *); 00153 00154 protected: 00155 static void *construct(const QSArgumentList &args) { 00156 return 0; 00157 } 00158 //@AQ_END_DEF_PUB_SLOTS@ 00159 }; 00160 00161 //@AQ_BEGIN_IMP_PUB_SLOTS@ 00162 inline bool AQSSProject::editorsModified() const 00163 { 00164 AQ_CALL_RET_V(editorsModified(), bool); 00165 } 00166 inline bool AQSSProject::scriptsModified() const 00167 { 00168 AQ_CALL_RET_V(scriptsModified(), bool); 00169 } 00170 inline QStringList AQSSProject::scriptNames() const 00171 { 00172 AQ_CALL_RET_V(scriptNames(), QStringList); 00173 } 00174 inline QSScript *AQSSProject::script(const QString &arg0) const 00175 { 00176 AQ_CALL_RET(script(arg0)); 00177 } 00178 inline QSScript *AQSSProject::script(QObject *arg0) const 00179 { 00180 AQ_CALL_RET(script(arg0)); 00181 } 00182 inline QObject *AQSSProject::object(const QString &arg0) const 00183 { 00184 AQ_CALL_RET(object(arg0)); 00185 } 00186 inline QObjectList AQSSProject::objects() const 00187 { 00188 AQ_CALL_RET_V(objects(), QObjectList); 00189 } 00190 inline QSScript *AQSSProject::createScript(QObject *arg0, const QString &arg1) 00191 { 00192 AQ_CALL_RET(createScript(arg0, arg1)); 00193 } 00194 inline QSScript *AQSSProject::createScript(const QString &arg0, const QString &arg1) 00195 { 00196 AQ_CALL_RET(createScript(arg0, arg1)); 00197 } 00198 inline QSEditor *AQSSProject::activeEditor() const 00199 { 00200 AQ_CALL_RET(activeEditor()); 00201 } 00202 inline QSEditor *AQSSProject::editor(QSScript *arg0) const 00203 { 00204 AQ_CALL_RET(editor(arg0)); 00205 } 00206 inline QSEditor *AQSSProject::createEditor(QSScript *arg0, QWidget *arg1, const char *arg2) 00207 { 00208 AQ_CALL_RET(createEditor(arg0, arg1, arg2)); 00209 } 00210 inline void AQSSProject::addObject(QObject *arg0) 00211 { 00212 AQ_CALL_VOID(addObject(arg0)); 00213 } 00214 inline void AQSSProject::removeObject(const QObject *arg0) 00215 { 00216 AQ_CALL_VOID(removeObject(arg0)); 00217 } 00218 //@AQ_END_IMP_PUB_SLOTS@ 00219 00220 #endif /* AQSSPROJECT_P_H_ */ 00221 // @AQSOBJECT@