24 #include <QtGui/QApplication>
25 #include <QtCore/QDebug>
26 #include <QtCore/QStringList>
29 #include <kapplication.h>
30 #include <kaboutdata.h>
31 #include <kcmdlineargs.h>
32 #include <kdeversion.h>
35 #include <kjs/interpreter.h>
36 #include <kjs/ustring.h>
41 #include <QtCore/QDate>
43 using namespace KJSEmbed;
49 <<
" -e, --exec execute script without gui support." << endl
50 <<
" -i, --interactive start interactive kjs interpreter." << endl
52 <<
" -n, --no-kde start without KDE KApplication support." << endl
61 int main(
int argc,
char **argv )
68 RedirectIOToConsole();
73 QString appName = argv[0];
75 for (
int i = 1; i < argc; i++ )
100 while (!args.isEmpty())
102 QString arg = args.takeFirst();
103 if (arg.contains(
'-'))
105 if ((arg ==
"--version") || (arg ==
"-v"))
107 printf(
"Qt: %s\n", qVersion());
109 printf(
"KDE: %s\n", KDE_VERSION_STRING);
113 if ((arg ==
"--exec") || (arg ==
"-e"))
117 else if ((arg ==
"--interactive") || (arg ==
"-i"))
120 else if ((arg ==
"-n") || (arg ==
"--no-kde"))
133 if (!script.isEmpty())
147 QCoreApplication *app;
152 KAboutData aboutData(
"kjscmd", 0, ki18n(
"KJSCmd"),
"0.2",
154 "Utility for running KJSEmbed scripts \n" ),
155 KAboutData::License_LGPL,
156 ki18n(
"(C) 2005-2006 The KJSEmbed Authors") );
158 KCmdLineOptions options;
159 options.add(
"e", ki18n(
"Execute script without gui support"));
160 options.add(
"exec", ki18n(
"Execute script without gui support"));
161 options.add(
"i", ki18n(
"start interactive kjs interpreter"));
162 options.add(
"interactive", ki18n(
"start interactive kjs interpreter"));
163 options.add(
"n", ki18n(
"start without KDE KApplication support."));
164 options.add(
"no-kde", ki18n(
"start without KDE KApplication support."));
165 options.add(
"!+command", ki18n(
"Script to execute"));
167 KCmdLineArgs::addCmdLineOptions( options );
168 KCmdLineArgs::init( argc, argv, &aboutData );
170 app =
new KApplication(gui);
177 app =
new QApplication( argc, argv );
178 dynamic_cast<QApplication*
>(app)->connect( app, SIGNAL(lastWindowClosed()), SLOT(quit()) );
183 app =
new QCoreApplication(argc, argv);
185 qDebug(
" New %s %dms", app->metaObject()->className(), time.elapsed());
187 app->setApplicationName( appName );
192 qDebug(
" New engine %dms", time.elapsed());
196 js->setShouldPrintExceptions(
true);
197 KJS::ExecState *exec = js->globalExec();
200 KJS::JSObject *appObject = kernel.
addObject( app,
"Application" );
201 KJS::JSObject *argObject = js->builtinArray()->construct( exec, scriptArgs );
202 appObject->put( exec,
"args", argObject );
205 if (!script.isEmpty())
211 result = kernel.
runFile(
":/console.js" );
KJS::JSObject * addObject(QObject *obj, const KJS::UString &name=KJS::UString()) const
publishes a QObject to the global context of the javascript interpereter.
int main(int argc, char **argv)
ExitStatus
Status codes for script execution.
KJS::Interpreter * interpreter() const
Returns the current interpreter.
KJS::Completion completion() const
Returns the Completion object for the last script executed.
ExitStatus runFile(const KJS::UString &file)
Execute the file with the specified name using the current interpreter.
KJSEMBED_EXPORT QTextStream * conout()
The main interface for running embedded Javascript.
KJS::JSCell * jsString(const QString &s)
KJS::UString toUString(const QString &qs)
KJSEMBED_EXPORT QTextStream * conerr()
void printUsage(QString appName)
QString toQString(const KJS::UString &u)