testwindow.cpp

00001 /***************************************************************************
00002  * testwindow.cpp
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 #include "testwindow.h"
00021 #include "testplugin.h"
00022 
00023 #include <qlabel.h>
00024 #include <qvbox.h>
00025 #include <qvgroupbox.h>
00026 //#include <qhgroupbox.h>
00027 #include <qcombobox.h>
00028 #include <ktextedit.h>
00029 #include <kpushbutton.h>
00030 #include <kpopupmenu.h>
00031 #include <kmenubar.h>
00032 #include <kstandarddirs.h>
00033 
00034 #include <kdebug.h>
00035 
00036 #include <qpopupmenu.h>
00037 TestWindow::TestWindow(const QString& interpretername, const QString& scriptcode)
00038     : KMainWindow()
00039     , m_interpretername(interpretername)
00040     , m_scriptcode(scriptcode)
00041 {
00042     Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager();
00043     manager->addModule( new TestPluginModule("krosstestpluginmodule") );
00044     m_scriptcontainer = manager->getScriptContainer("test");
00045 
00046     KPopupMenu *menuFile = new KPopupMenu( this );
00047     menuBar()->insertItem( "&File", menuFile );
00048 
00049     m_scriptextension = new Kross::Api::ScriptGUIClient(this, this);
00050     //m_scriptextension->setXMLFile( KGlobal::dirs()->findResource("appdata", "testscripting.rc") );
00051 
00052     m_scriptextension->action("executescriptfile")->plug(menuFile);
00053     //m_scriptextension->action("configurescripts")->plug(menuFile);
00054     //menuFile->insertSeparator();
00055     KAction* scriptsaction = m_scriptextension->action("scripts");
00056     if(scriptsaction) scriptsaction->plug(menuFile);
00057     //menuFile->insertItem( ( (KActionMenu*)m_scriptextension->action("scripts") )->popupMenu() );
00058 
00059     QVBox* mainbox = new QVBox(this);
00060 
00061     QVGroupBox* interpretergrpbox = new QVGroupBox("Interpreter", mainbox);
00062     QStringList interpreters = Kross::Api::Manager::scriptManager()->getInterpreters();
00063     m_interpretercombo = new QComboBox(interpretergrpbox);
00064     m_interpretercombo->insertStringList(interpreters);
00065     m_interpretercombo->setCurrentText(interpretername);
00066 
00067     QVGroupBox* scriptgrpbox = new QVGroupBox("Scripting code", mainbox);
00068     m_codeedit = new KTextEdit(m_scriptcode, QString::null, scriptgrpbox);
00069     m_codeedit->setWordWrap(QTextEdit::NoWrap);
00070     m_codeedit->setTextFormat(Qt::PlainText);
00071 
00072     QHBox* btnbox = new QHBox(mainbox);
00073     KPushButton* execbtn = new KPushButton("Execute", btnbox);
00074     connect(execbtn, SIGNAL(clicked()), this, SLOT(execute()));
00075 
00076     setCentralWidget(mainbox);
00077     setMinimumSize(600,420);
00078 }
00079 
00080 TestWindow::~TestWindow()
00081 {
00082 }
00083 
00084 void TestWindow::execute()
00085 {
00086     m_scriptcontainer->setInterpreterName( m_interpretercombo->currentText() );
00087     m_scriptcontainer->setCode(m_codeedit->text());
00088     Kross::Api::Object::Ptr result = m_scriptcontainer->execute();
00089     if(m_scriptcontainer->hadException()) {
00090         kdDebug() << "EXCEPTION => " << m_scriptcontainer->getException()->toString() << endl;
00091     }
00092     else {
00093         QString s = result ? result->toString() : QString::null;
00094         kdDebug() << "DONE => " << s << endl;
00095     }
00096 }
00097 
00098 #include "testwindow.moc"

Generated on Thu Feb 9 17:59:11 2006 for Kross by  doxygen 1.4.6