kexi

formscript.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "formscript.h"
00021 #include "scriptmanager.h"
00022 
00023 #include "form.h"
00024 #include "objecttree.h"
00025 // Kross Includes
00026 #include "main/manager.h"
00027 #include "main/scriptcontainer.h"
00028 #include "api/exception.h"
00029 
00030 #include <kdebug.h>
00031 
00032 using namespace KFormDesigner;
00033 
00034 FormScript::FormScript(Form *form, ScriptManager *manager, const char *name)
00035  : QObject(manager, name), m_manager(manager), m_form(form)
00036 {
00037     m_script = manager->krossManager()->getScriptContainer(form->widget()->name());
00038 }
00039 
00040 FormScript::~FormScript()
00041 {
00042 }
00043 
00044 QString
00045 FormScript::getCode(const QString &)
00046 {
00048     return m_script->getCode();
00049 }
00050 
00051 void
00052 FormScript::setCode(const QString &code)
00053 {
00054     m_script->setCode(code);
00055 }
00056 
00057 void
00058 FormScript::appendCode(const QString &code)
00059 {
00060     QString s = m_script->getCode();
00061     s.append("\n");
00062     s.append(code);
00063     m_script->setCode(s);
00064 }
00065 
00066 bool
00067 FormScript::execute(const QString &functionName)
00068 {
00070     try {
00071         m_script->callFunction(functionName);
00072     }
00073     catch(Kross::Api::Exception& e) {
00074         kdDebug() << QString("EXCEPTION type='%1' description='%2'").arg(e.type()).arg(e.description()) << endl;
00075         return false;
00076     }
00077     return true;
00078 }
00079 
00080 void
00081 FormScript::connectEvents()
00082 {
00083     if(!m_form || !m_form->objectTree())
00084         return;
00085     // first call addQObject for each widget in the Form
00086     ObjectTreeDict *dict = m_form->objectTree()->dict();
00087     ObjectTreeDictIterator it(*dict);
00088     for(; it.current(); ++it)
00089         m_script->addQObject(it.current()->widget());
00090     m_script->addQObject(m_form->widget());
00091 
00092     // Then we connect all signals
00093     QValueListConstIterator<Event*> endIt = m_list.constEnd();
00094     for(QValueListConstIterator<Event*> it = m_list.constBegin(); it != endIt; ++it) {
00095         if( (*it)->type() == Event::Slot) {
00096             connect((*it)->sender(), (*it)->signal(), (*it)->receiver(), (*it)->slot());
00097         }
00098         else if( (*it)->type() == Event::UserFunction) {
00099             m_script->connect((*it)->sender(), (*it)->signal(), (*it)->slot());
00100         }
00101         else if( (*it)->type() == Event::Action) {
00103         }
00104     }
00105 }
00106 
00107 
00108 #include "formscript.moc"
00109 
KDE Home | KDE Accessibility Home | Description of Access Keys