1/*
2 * Copyright (c) 2009 Igor Trindade Oliveira <igor_trindade@yahoo.com.br>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "script.h"
19#include "global.h"
20#include <KDebug>
21#include <qcoreapplication.h>
22
23Script::Script()
24{
25 action = new Kross::Action(this, "ResourceTester");
26 connect( action, SIGNAL(finished(Kross::Action*)), SLOT(finished(Kross::Action*)) );
27 action->addObject( this, QLatin1String( "Script" ) );
28}
29
30void Script::configure(const QString &path)
31{
32 action->setFile(path);
33}
34
35void Script::insertObject(QObject *object, const QString &objectName)
36{
37 action->addObject(object, objectName);
38}
39
40void Script::include(const QString& path)
41{
42 QFile f( Global::basePath() + path );
43 if ( !f.open( QFile::ReadOnly ) )
44 kError() << "Unable to open file" << Global::basePath() + path;
45 else
46 action->evaluate( f.readAll() );
47}
48
49QString Script::absoluteFileName(const QString& path)
50{
51 return Global::basePath() + path;
52}
53
54void Script::start()
55{
56 action->trigger();
57}
58
59void Script::finished(Kross::Action* action)
60{
61 if ( action->hadError() ) {
62 kError() << action->errorMessage() << action->errorTrace();
63 QCoreApplication::instance()->exit( 1 );
64 } else {
65 QCoreApplication::instance()->quit();
66 }
67}
68
69
70