• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Kross

  • kross
  • qts
qts/main.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * main.cpp
3 * This file is part of the KDE project
4 * copyright (C)2006 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include <QFile>
21#include <QScriptEngine>
22#include <QLibraryInfo>
23#include <QDebug>
24
25#include <kapplication.h>
26#include <kcmdlineargs.h>
27#include <kaboutdata.h>
28// #include <kurl.h>
29
30KApplication* app = 0;
31
32bool runScriptFile(QScriptEngine* engine, const QString& scriptfile)
33{
34 // Read the scriptfile
35 QFile f(scriptfile);
36 if(! f.exists()) {
37 qWarning() << "No such scriptfile:" << scriptfile;
38 return false;
39 }
40 if(! f.open(QIODevice::ReadOnly)) {
41 qWarning() << "Failed to open scriptfile:" << scriptfile;
42 return false;
43 }
44 QByteArray scriptcode = f.readAll();
45 f.close();
46
47 // Execute the javascript code.
48 qDebug() << "Execute scriptfile:" << scriptfile;
49 QScriptValue v = engine->evaluate(scriptcode);
50 qDebug() << "Execute done. Result:" << v.toString();
51
52 return true;
53}
54
55int main(int argc, char **argv)
56{
57 KAboutData about("kross",0,ki18n("Kross"),"0.1",
58 ki18n("KDE application to run Kross scripts."),
59 KAboutData::License_LGPL,
60 ki18n("(C) 2006 Sebastian Sauer"),
61 ki18n("Run Kross scripts."),
62 "http://kross.dipe.org","kross@dipe.org");
63 about.addAuthor(ki18n("Sebastian Sauer"), ki18n("Author"), "mail@dipe.org");
64
65 // Initialize command line args
66 KCmdLineArgs::init(argc, argv, &about);
67 // Tell which options are supported and parse them.
68 KCmdLineOptions options;
69 options.add("+file", ki18n("Scriptfile"));
70 KCmdLineArgs::addCmdLineOptions(options);
71 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
72
73 QStringList files;
74 for(int i = 0; i < args->count(); ++i)
75 files << args->arg(i);
76
77 // If no options are defined.
78 if(files.count() < 1) {
79 qWarning() << "Syntax:" << KCmdLineArgs::appName() << "scriptfile1 [scriptfile2] [scriptfile3] ...";
80 return -1;
81 }
82
83
84 app = new KApplication( /* GUIenabled */ true );
85 QScriptEngine* engine = new QScriptEngine();
86 engine->installTranslatorFunctions();
87 QScriptValue global = engine->globalObject();
88
89 //qDebug()<<"QLibraryInfo::PluginsPath="<<QLibraryInfo::location(QLibraryInfo::PluginsPath);
90 //app->addLibraryPath("/home/kde4/kde4/lib/kde4/");
91
92 engine->importExtension("kross").toString();
93
94 foreach(const QString &file, files)
95 runScriptFile(engine, file);
96
97 delete engine;
98 delete app;
99 return 0;
100}
KAboutData
KAboutData::addAuthor
KAboutData & addAuthor(const KLocalizedString &name, const KLocalizedString &task, const QByteArray &emailAddress, const QByteArray &webAddress, const QByteArray &ocsUsername)
KAboutData::License_LGPL
License_LGPL
KApplication
KCmdLineArgs
KCmdLineArgs::init
static void init(const KAboutData *about)
KCmdLineArgs::appName
static QString appName()
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
KCmdLineArgs::count
int count() const
KCmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const KCmdLineOptions &options, const KLocalizedString &name=KLocalizedString(), const QByteArray &id=QByteArray(), const QByteArray &afterId=QByteArray())
KCmdLineArgs::arg
QString arg(int n) const
KCmdLineOptions
KCmdLineOptions::add
KCmdLineOptions & add(const KCmdLineOptions &options)
kaboutdata.h
kapplication.h
kcmdlineargs.h
ki18n
KLocalizedString ki18n(const char *msg)
runScriptFile
bool runScriptFile(QScriptEngine *engine, const QString &scriptfile)
Definition: qts/main.cpp:32
main
int main(int argc, char **argv)
Definition: qts/main.cpp:55
app
KApplication * app
Definition: qts/main.cpp:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal