diff options
author | Kevin Simons <kevin.simons@nokia.com> | 2012-02-19 19:36:48 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-21 01:42:00 +0100 |
commit | caf6804da729d56fec0c14b91a056a562e1d630b (patch) | |
tree | 932b763b78ff6df299092ac49645b8ac48df807c /tools | |
parent | ba4e837eb6b55b17401890433a0df1bab066562d (diff) |
Move the -load functionality from the daemon to the client
Current we support 3 file formats:
1) .qml, providing the full JSONDB API
2) .json, simple JSON files whose objects get created in the DB
3) .js, deprecated format supporting the former server-side API
Change-Id: I74905d26f909c6cf7e46ee2bd29926df035737ea
Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/jsondb-client/client.cpp | 246 | ||||
-rw-r--r-- | tools/jsondb-client/client.h | 27 | ||||
-rw-r--r-- | tools/jsondb-client/jsondb-client.pro | 8 | ||||
-rw-r--r-- | tools/jsondb-client/jsondbproxy.cpp | 128 | ||||
-rw-r--r-- | tools/jsondb-client/jsondbproxy.h | 28 | ||||
-rw-r--r-- | tools/jsondb-client/main.cpp | 102 |
6 files changed, 439 insertions, 100 deletions
diff --git a/tools/jsondb-client/client.cpp b/tools/jsondb-client/client.cpp index 697abd12..7a47ae3a 100644 --- a/tools/jsondb-client/client.cpp +++ b/tools/jsondb-client/client.cpp @@ -40,12 +40,18 @@ ****************************************************************************/ #include "client.h" +#ifndef QTJSONDB_NO_DEPRECATED +#include "jsondbproxy.h" +#endif #include <iostream> #include <sstream> #include <iomanip> -extern bool gDebug; +#include <QDeclarativeComponent> +#include <QDeclarativeEngine> + +QT_USE_NAMESPACE const char* InputThread::commands[] = { "changesSince", "create {\"", @@ -198,8 +204,13 @@ void InputThread::async_print(const QString &message) el_set(el, EL_REFRESH); } -Client::Client( QObject *parent ) - : QObject(parent), mNotifier(NULL), mInputThread(NULL) +Client::Client( QObject *parent ) : + QObject(parent) + , mNotifier(0) + , mInputThread(0) + , mTerminate(false) + , mDebug(false) + , mEngine(0) { } @@ -303,6 +314,9 @@ void Client::statusChanged(QtJsonDb::QJsonDbConnection::Status) void Client::error(QtJsonDb::QJsonDbConnection::ErrorCode error, const QString &message) { + Q_UNUSED(error); + Q_UNUSED(message); + switch (error) { case QtJsonDb::QJsonDbConnection::NoError: Q_ASSERT(false); @@ -326,9 +340,12 @@ void Client::onRequestFinished() message += QLatin1String(",\n") + QJsonDocument(objects.at(i)).toJson().trimmed(); } InputThread::print(message); +} - if (!mInputThread) - QCoreApplication::exit(0); // Non-interactive mode just stops + +void Client::onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message) +{ + InputThread::print(message); } void Client::pushRequest(QtJsonDb::QJsonDbRequest *request) @@ -338,10 +355,9 @@ void Client::pushRequest(QtJsonDb::QJsonDbRequest *request) void Client::popRequest() { - QtJsonDb::QJsonDbRequest *request = mRequests.takeFirst(); - delete request; - if (mRequests.isEmpty()) - emit requestsProcessed(); + mRequests.takeFirst()->deleteLater(); + if (mRequests.isEmpty() && mTerminate) + emit terminate(); } void Client::usage() @@ -392,8 +408,6 @@ bool Client::processCommand(const QString &command) rest = command.mid(space+1).trimmed(); } - gDebug = true; - QString partition; if (rest.startsWith(QLatin1String("partition:"))) { partition = rest.left(rest.indexOf(' ')); @@ -420,14 +434,17 @@ bool Client::processCommand(const QString &command) } rest.truncate(idx+1); } - if (gDebug) + if (mDebug) qDebug() << "Sending query:" << rest; + QtJsonDb::QJsonDbReadRequest *request = new QtJsonDb::QJsonDbReadRequest(this); request->setPartition(partition); request->setQuery(rest); request->setQueryLimit(limit); connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished())); connect(request, SIGNAL(finished()), this, SLOT(popRequest())); + connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)), + this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString))); pushRequest(request); mConnection->send(request); } else if (cmd == "notify") { @@ -451,7 +468,7 @@ bool Client::processCommand(const QString &command) actions |= action; } QString query = rest.mid(s+1).trimmed(); - if (gDebug) + if (mDebug) qDebug() << "Creating notification:" << alist << ":" << query; QtJsonDb::QJsonDbWatcher *watcher = new QtJsonDb::QJsonDbWatcher(this); watcher->setPartition(partition); @@ -470,15 +487,20 @@ bool Client::processCommand(const QString &command) usage(); return false; } - if (gDebug) + + if (mDebug) qDebug() << "Sending" << cmd << ":" << doc; + QList<QJsonObject> objects; if (doc.isObject()) { objects.append(doc.object()); } else { - foreach (const QJsonValue &value, doc.array()) - objects.append(value.toObject()); + foreach (const QJsonValue &value, doc.array()) { + if (value.isObject()) + objects.append(value.toObject()); + } } + QtJsonDb::QJsonDbWriteRequest *request = 0; if (cmd == "create") request = new QtJsonDb::QJsonDbCreateRequest(objects); @@ -491,28 +513,12 @@ bool Client::processCommand(const QString &command) request->setPartition(partition); connect(request, SIGNAL(finished()), this, SLOT(onRequestFinished())); connect(request, SIGNAL(finished()), this, SLOT(popRequest())); + connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)), + this, SLOT(onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString))); pushRequest(request); mConnection->send(request); } else if (cmd == "changesSince") { -// int stateNumber = 0; -// QStringList types; -// QStringList args = rest.split(" "); - -// if (args.isEmpty()) { -// InputThread::print("Must specify the state number"); -// usage(); -// return false; -// } - -// stateNumber = args.takeFirst().trimmed().toInt(); - -// if (!args.isEmpty()) -// types = args; - -// if (gDebug) -// qDebug() << "Sending changesSince: " << stateNumber << "types: " << types; - -// mRequests << mConnection->changesSince(stateNumber, types, partition); + qWarning() << "Not yet supported"; } else if (cmd == "connect") { mConnection->connectToServer(); } else if (cmd == "disconnect") { @@ -528,23 +534,157 @@ bool Client::processCommand(const QString &command) return true; } -bool Client::loadJsonFile(const QString &fileName) +void Client::loadFiles(const QStringList &files) { -// QFile file(fileName); -// if (!file.open(QFile::ReadOnly)) { -// if (gDebug) -// qDebug() << "Couldn't load file" << fileName; -// return false; -// } -// JsonReader parser; -// bool ok = parser.parse(file.readAll()); -// file.close(); -// if (!ok) { -// std::cout << "Unable to parse the content of the file" << qPrintable(fileName) << ":" -// << qPrintable(parser.errorString()) << std::endl; -// return false; -// } -// QVariant arg = parser.result(); -// mRequests << mConnection->create(arg); - return true; + mFilesToLoad = files; + loadNextFile(); +} + +void Client::fileLoadSuccess() +{ + // make sure it's a request so we don't accidently delete the declarative engine + QtJsonDb::QJsonDbRequest *request = qobject_cast<QtJsonDb::QJsonDbRequest *>(sender()); + if (request) + request->deleteLater(); + + qDebug() << "Successfully loaded:" << mFilesToLoad.takeFirst(); + loadNextFile(); +} + +void Client::fileLoadError() +{ + // Could be a QJsonDbWriteRequest or a QTimer, either way it needs to be cleaned up + if (sender()) + sender()->deleteLater(); + + qDebug() << "Error loading:" << mFilesToLoad.takeFirst(); + loadNextFile(); +} + +void Client::loadNextFile() +{ + if (mFilesToLoad.isEmpty()) { + if (mTerminate) + emit terminate(); + else + interactiveMode(); + return; + } + + QFileInfo info(mFilesToLoad.first()); + if (info.suffix() == QLatin1Literal("json")) { + loadJsonFile(info.filePath()); + } else if (info.suffix() == QLatin1Literal("qml")) { + loadQmlFile(info.filePath()); +#ifndef QTJSONDB_NO_DEPRECATED + } else if (info.suffix() == QLatin1Literal("js")) { + loadJavaScriptFile(info.filePath()); +#endif + } else { + qDebug() << "Unknown file type:" << mFilesToLoad.takeFirst(); + loadNextFile(); + } } + +void Client::loadJsonFile(const QString &jsonFile) +{ + QFile json(jsonFile); + + if (!json.exists()) { + qDebug() << "File not found:" << jsonFile; + fileLoadError(); + return; + } + + json.open(QFile::ReadOnly); + QJsonDocument doc = QJsonDocument::fromJson(json.readAll()); + json.close(); + + QList<QJsonObject> objects; + if (doc.isArray()) { + QJsonArray objectArray = doc.array(); + for (QJsonArray::const_iterator it = objectArray.begin(); it != objectArray.end(); it++) { + QJsonValue val = *it; + if (val.isObject()) + objects.append(val.toObject()); + } + } else { + objects.append(doc.object()); + } + + QtJsonDb::QJsonDbCreateRequest *write = new QtJsonDb::QJsonDbCreateRequest(objects, this); + connect(write, SIGNAL(finished()), this, SLOT(fileLoadSuccess())); + connect(write, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)), + this, SLOT(fileLoadError())); + mConnection->send(write); +} + +void Client::loadQmlFile(const QString &qmlFile) +{ + QFile qml(qmlFile); + + if (!qml.exists()) { + qDebug() << "File not found:" << qmlFile; + fileLoadError(); + return; + } + + if (!mEngine) { + mEngine = new QDeclarativeEngine(this); + connect(mEngine, SIGNAL(quit()), this, SLOT(fileLoadSuccess())); + } + + qml.open(QFile::ReadOnly); + QDeclarativeComponent *component = new QDeclarativeComponent(mEngine, this); + component->setData(qml.readAll(), QUrl()); + qml.close(); + + // Time the qml loading out after 10 seconds + QTimer *timeout = new QTimer(this); + timeout->setSingleShot(true); + connect(timeout, SIGNAL(timeout()), this, SLOT(fileLoadError())); + connect(mEngine, SIGNAL(quit()), timeout, SLOT(stop())); + timeout->start(10000); + + QObject *created = component->create(); + if (created) { + connect(mEngine, SIGNAL(quit()), component, SLOT(deleteLater())); + connect(mEngine, SIGNAL(quit()), created, SLOT(deleteLater())); + return; + } + + fileLoadError(); +} + +#ifndef QTJSONDB_NO_DEPRECATED +void Client::loadJavaScriptFile(const QString &jsFile) +{ + QFile js(jsFile); + + if (!js.exists()) { + qDebug() << "File not found:" << jsFile; + fileLoadError(); + return; + } + + QJSEngine *scriptEngine = new QJSEngine(this); + QJSValue globalObject = scriptEngine->globalObject(); + QJSValue proxy = scriptEngine->newQObject(new JsonDbProxy(mConnection, this)); + globalObject.setProperty("jsondb", proxy); + globalObject.setProperty("console", proxy); + + js.open(QFile::ReadOnly); + QJSValue sv = scriptEngine->evaluate(js.readAll(), jsFile); + scriptEngine->deleteLater(); + js.close(); + + if (sv.isError()) { + qDebug() << sv.toString(); + fileLoadError(); + return; + } + + fileLoadSuccess(); +} + +#endif diff --git a/tools/jsondb-client/client.h b/tools/jsondb-client/client.h index fe523c7c..3ae8d5f4 100644 --- a/tools/jsondb-client/client.h +++ b/tools/jsondb-client/client.h @@ -47,6 +47,10 @@ #include <histedit.h> +QT_BEGIN_NAMESPACE +class QDeclarativeEngine; +QT_END_NAMESPACE + class InputThread : public QThread { Q_OBJECT public: @@ -78,10 +82,13 @@ public: bool connectToServer(); void interactiveMode(); + void loadFiles(const QStringList &files); + + inline void setTerminateOnCompleted(bool terminate) { mTerminate = terminate; } + inline void setDebug(bool debug) { mDebug = debug; } public slots: bool processCommand(const QString &); // true if we're waiting for a response - bool loadJsonFile(const QString &fileName); protected slots: void error(QtJsonDb::QJsonDbConnection::ErrorCode, const QString &message); @@ -92,21 +99,35 @@ protected slots: void onNotificationError(QtJsonDb::QJsonDbWatcher::ErrorCode, const QString &); void onRequestFinished(); + void onRequestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &message); void pushRequest(QtJsonDb::QJsonDbRequest *); void popRequest(); + void fileLoadError(); + void fileLoadSuccess(); + Q_SIGNALS: - void requestsProcessed(); + void terminate(); private: void usage(); + void loadNextFile(); + void loadJsonFile(const QString &jsonFile); + void loadQmlFile(const QString &qmlFile); +#ifndef JSONDB_NO_DEPRECATED + void loadJavaScriptFile(const QString &jsFile); +#endif + QSocketNotifier *mNotifier; - QFile *mInput; QtJsonDb::QJsonDbConnection *mConnection; QList<QtJsonDb::QJsonDbRequest *> mRequests; InputThread *mInputThread; + bool mTerminate; + bool mDebug; + QStringList mFilesToLoad; + QDeclarativeEngine *mEngine; }; diff --git a/tools/jsondb-client/jsondb-client.pro b/tools/jsondb-client/jsondb-client.pro index f2326d98..dbdca1d4 100644 --- a/tools/jsondb-client/jsondb-client.pro +++ b/tools/jsondb-client/jsondb-client.pro @@ -4,7 +4,7 @@ DESTDIR = $$QT.jsondb.bins target.path = $$[QT_INSTALL_PREFIX]/bin INSTALLS += target -QT = core jsondb +QT = core jsondb declarative LIBS += -ledit @@ -14,3 +14,9 @@ mac:CONFIG -= app_bundle HEADERS += client.h SOURCES += main.cpp client.cpp + +!contains(DEFINES, QTJSONDB_NO_DEPRECATED) { + HEADERS += jsondbproxy.h + SOURCES += jsondbproxy.cpp +} + diff --git a/tools/jsondb-client/jsondbproxy.cpp b/tools/jsondb-client/jsondbproxy.cpp new file mode 100644 index 00000000..f48a1b6d --- /dev/null +++ b/tools/jsondb-client/jsondbproxy.cpp @@ -0,0 +1,128 @@ +#include "jsondbproxy.h" +#include "qjsondbobject.h" +#include "qjsondbreadrequest.h" +#include "qjsondbwriterequest.h" + +#include <QDebug> +#include <QEventLoop> +#include <QJsonDocument> +#include <QJsonObject> +#include <QString> + +QT_USE_NAMESPACE + +QVariantMap _waitForResponse(QtJsonDb::QJsonDbRequest *request) { + QEventLoop e; + while (!(request->status() == QtJsonDb::QJsonDbRequest::Error || request->status() == QtJsonDb::QJsonDbRequest::Finished)) + e.processEvents(); + + QVariantMap res; + + if (request->status() != QtJsonDb::QJsonDbRequest::Error) { + QList<QJsonObject> results = request->takeResults(); + QVariantList data; + foreach (const QJsonObject &obj, results) + data.append(obj.toVariantMap()); + res.insert(QLatin1Literal("result"), data); + } else { + QVariantMap error; + error.insert(QLatin1Literal("code"), 1); + error.insert(QLatin1Literal("message"), "Error processing request"); + res.insert(QLatin1Literal("error"), error); + } + return res; +} + + +JsonDbProxy::JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, QObject *parent) : + QObject(parent) + , mConnection(conn) +{ +} + +QVariantMap JsonDbProxy::find(QVariantMap object) +{ + QtJsonDb::QJsonDbReadRequest *request = new QtJsonDb::QJsonDbReadRequest(this); + request->setQuery(object.value(QLatin1Literal("query")).toString()); + if (object.contains(QLatin1Literal("limit"))) + request->setQueryLimit(object.value(QLatin1Literal("limit")).toInt()); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::create(QVariantMap object) +{ + // handle the to-be-deprecated _id property + QtJsonDb::QJsonDbObject obj = QJsonObject::fromVariantMap(object); + if (obj.uuid().isNull() && obj.contains(QLatin1Literal("_id"))) { + obj.setUuid(QtJsonDb::QJsonDbObject::createUuidFromString(obj.value(QLatin1Literal("_id")).toString())); + obj.remove(QLatin1String("_id")); + } + QtJsonDb::QJsonDbCreateRequest *request = new QtJsonDb::QJsonDbCreateRequest(QList<QJsonObject>() << obj, + this); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::update(QVariantMap object) +{ + QtJsonDb::QJsonDbUpdateRequest *request = new QtJsonDb::QJsonDbUpdateRequest(QList<QJsonObject>() << QJsonObject::fromVariantMap(object), + this); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::remove(QVariantMap object ) +{ + QtJsonDb::QJsonDbRemoveRequest *request = new QtJsonDb::QJsonDbRemoveRequest(QList<QJsonObject>() << QJsonObject::fromVariantMap(object), + this); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::createList(QVariantList list) +{ + QList<QJsonObject> objects; + foreach (const QVariant &object, list) { + QtJsonDb::QJsonDbObject obj = QJsonObject::fromVariantMap(object.toMap()); + if (!obj.uuid().isNull() && obj.contains(QLatin1Literal("_id"))) { + obj.setUuid(QtJsonDb::QJsonDbObject::createUuidFromString(obj.value(QLatin1Literal("_id")).toString())); + obj.remove(QLatin1String("_id")); + } + objects << obj; + } + QtJsonDb::QJsonDbCreateRequest *request = new QtJsonDb::QJsonDbCreateRequest(objects, this); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::updateList(QVariantList list) +{ + QList<QJsonObject> objects; + foreach (const QVariant &obj, list) + objects << QJsonObject::fromVariantMap(obj.toMap()); + QtJsonDb::QJsonDbUpdateRequest *request = new QtJsonDb::QJsonDbUpdateRequest(objects, this); + mConnection->send(request); + return _waitForResponse(request); +} + +QVariantMap JsonDbProxy::removeList(QVariantList list) +{ + QList<QJsonObject> objects; + foreach (const QVariant &obj, list) + objects << QJsonObject::fromVariantMap(obj.toMap()); + QtJsonDb::QJsonDbRemoveRequest *request = new QtJsonDb::QJsonDbRemoveRequest(objects, this); + mConnection->send(request); + return _waitForResponse(request); +} + +void JsonDbProxy::log(const QString &msg) +{ + qDebug() << msg; +} + +void JsonDbProxy::debug(const QString &msg) +{ + qDebug() << msg; +} + diff --git a/tools/jsondb-client/jsondbproxy.h b/tools/jsondb-client/jsondbproxy.h new file mode 100644 index 00000000..4e14477a --- /dev/null +++ b/tools/jsondb-client/jsondbproxy.h @@ -0,0 +1,28 @@ +#ifndef JSONDBPROXY_H +#define JSONDBPROXY_H + +#include <QJsonDbConnection> +#include <QVariantMap> + +class JsonDbProxy : public QObject +{ + Q_OBJECT +public: + explicit JsonDbProxy(QtJsonDb::QJsonDbConnection *conn, QObject *parent = 0); + Q_SCRIPTABLE QVariantMap find(QVariantMap object); + Q_SCRIPTABLE QVariantMap create(QVariantMap object); + Q_SCRIPTABLE QVariantMap update(QVariantMap object); + Q_SCRIPTABLE QVariantMap remove(QVariantMap object); + + Q_SCRIPTABLE QVariantMap createList(QVariantList list); + Q_SCRIPTABLE QVariantMap updateList(QVariantList list); + Q_SCRIPTABLE QVariantMap removeList(QVariantList list); + + Q_SCRIPTABLE void log(const QString &msg); + Q_SCRIPTABLE void debug(const QString &msg); + +private: + QtJsonDb::QJsonDbConnection *mConnection; +}; + +#endif // JSONDBPROXY_H diff --git a/tools/jsondb-client/main.cpp b/tools/jsondb-client/main.cpp index c8ef7c97..aa575aba 100644 --- a/tools/jsondb-client/main.cpp +++ b/tools/jsondb-client/main.cpp @@ -40,79 +40,95 @@ ****************************************************************************/ #include <QtCore> +#include <QGuiApplication> #include <iostream> #include "client.h" -QString progname; -bool gDebug; - -/***************************************************************************/ - using namespace std; -static void usage() +static void usage(const QString &name, int exitCode = 0) { - cout << "Usage: " << qPrintable(progname) << " [OPTIONS] [command]" << endl + cout << "Usage: " << qPrintable(name) << " [OPTIONS] [command]" << endl << endl << " -debug" << endl - << " -load file.json Load objects from a json file" << endl + << " -load FILE Load the specified .json or .qml file" << endl + << " -terminate Terminate after processing any -load parameters" << endl << endl << " where command is valid JsonDb command object" << endl; - exit(0); + exit(exitCode); } int main(int argc, char * argv[]) { - QCoreApplication::setOrganizationName("Nokia"); - QCoreApplication::setOrganizationDomain("nrcc.noklab.com"); - QCoreApplication::setApplicationName("jclient"); - QCoreApplication::setApplicationVersion("1.0"); + // Hack to avoid making people specify a platform plugin. + // We only need QGuiApplication so that we can use QDeclarativeEngine. + bool platformSpecified = false; + for (int i = 0; i < argc; i++) { + if (strcmp(argv[i], "-platform") == 0) + platformSpecified = true; + } + + if (!platformSpecified) + setenv("QT_QPA_PLATFORM", "minimal", false); + + QGuiApplication::setOrganizationName("Nokia"); + QGuiApplication::setOrganizationDomain("qt.nokia.com"); + QGuiApplication::setApplicationName("jclient"); + QGuiApplication::setApplicationVersion("1.0"); + QGuiApplication app(argc, argv); - QCoreApplication app(argc, argv); QStringList args = QCoreApplication::arguments(); - QString loadFile; + qDebug() << "args: " << args; + QString progname = args.takeFirst(); + QStringList command; + QStringList filesToLoad; + bool terminate = false; + bool debug = false; + - progname = args.takeFirst(); while (args.size()) { - QString arg = args.at(0); - if (!arg.startsWith("-")) - break; - args.removeFirst(); - if ( arg == "-help") - usage(); - else if ( arg == "-debug") - gDebug = true; - else if (arg == "-load") { + QString arg = args.takeFirst(); + if (!arg.startsWith("-")) { + command << arg; + continue; + } + + if (arg == QLatin1Literal("-help")) { + usage(progname); + } else if (arg == QLatin1Literal("-debug")) { + debug = true; + } else if (arg == QLatin1Literal("-load")) { if (args.isEmpty()) { - cout << "Invalid argument " << qPrintable(arg) << endl; - usage(); - return 0; + cout << "Must specify a file to load" << endl; + usage(progname, 1); } - loadFile = args.at(0); - args.removeFirst(); + filesToLoad << args.takeFirst(); + } else if (arg == QLatin1Literal("-terminate")) { + terminate = true; } else { cout << "Unknown argument " << qPrintable(arg) << endl; - usage(); - return 0; + usage(progname, 1); } } Client client; - if (!client.connectToServer()) - return 0; + QObject::connect(&client, SIGNAL(terminate()), &app, SLOT(quit()), Qt::QueuedConnection); + client.setTerminateOnCompleted(terminate); + client.setDebug(debug); - bool interactive = !args.size(); - if (!interactive) - QObject::connect(&client, SIGNAL(requestsProcessed()), &app, SLOT(quit())); + if (!client.connectToServer()) + return 1; - if (!loadFile.isEmpty()) { - client.loadJsonFile(loadFile); - } else if (!args.size()) { - client.interactiveMode(); + if (!filesToLoad.isEmpty()) { + client.loadFiles(filesToLoad); + } else if (command.size()) { + client.setTerminateOnCompleted(true); + if (!client.processCommand(command.join(" "))) + return 1; } else { - if (!client.processCommand(args.join(" "))) - return 0; + client.interactiveMode(); } + return app.exec(); } |