From d09517a4d4fcdf496c0298ef8b8f54f3c9120293 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 15 Dec 2016 10:44:25 +0100 Subject: sinksh fixes --- sinksh/sinksh_utils.cpp | 7 ++++--- sinksh/syntax_modules/sink_create.cpp | 25 +++++++++++++++++++++++++ sinksh/syntax_modules/sink_list.cpp | 15 ++++++++++++++- sinksh/syntaxtree.cpp | 8 ++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) (limited to 'sinksh') diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 855a8e7..c42fad3 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -56,9 +56,9 @@ StoreBase &getStore(const QString &type) return store; } - qWarning() << "Trying to get a store that doesn't exist, falling back to event"; + SinkWarning_("", "") << "Trying to get a store that doesn't exist: " << type; Q_ASSERT(false); - static Store store; + static Store store; return store; } @@ -67,7 +67,8 @@ QList requestedProperties(const QString &type) using namespace Sink::ApplicationDomain; if (type == getTypeName()) { return QList() << Folder::Name::name - << Folder::Parent::name; + << Folder::Parent::name + << Folder::SpecialPurpose::name; } else if (type == getTypeName()) { return QList() << Mail::Subject::name << Mail::Folder::name diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp index 4fedff4..95a4cce 100644 --- a/sinksh/syntax_modules/sink_create.cpp +++ b/sinksh/syntax_modules/sink_create.cpp @@ -139,6 +139,30 @@ bool account(const QStringList &args, State &state) return true; } +bool identity(const QStringList &args, State &state) +{ + auto &store = SinkshUtils::getStore("identity"); + + auto map = SinkshUtils::keyValueMapFromArgs(args); + + auto identifier = map.take("identifier").toLatin1(); + + auto object = ApplicationDomain::ApplicationDomainType::createEntity("", identifier); + + for (auto i = map.begin(); i != map.end(); ++i) { + object.setProperty(i.key().toLatin1(), i.value()); + } + + auto result = store.create(object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), + "sink_create_e" + QString::number(result.errorCode())); + } + + return true; +} + Syntax::List syntax() { @@ -147,6 +171,7 @@ Syntax::List syntax() Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); + create.children << Syntax("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); syntax << create; return syntax; diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index bb2f1fe..8507d48 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -82,7 +82,20 @@ bool list(const QStringList &args, State &state) line << o.resourceInstanceIdentifier(); line << o.identifier(); for (const auto &prop: query.requestedProperties) { - line << o.getProperty(prop).toString(); + const auto value = o.getProperty(prop); + if (value.isValid()) { + if (value.canConvert()) { + line << value.toString(); + } else if (value.canConvert()) { + line << value.toByteArray(); + } else if (value.canConvert()) { + line << value.value().join(", "); + } else { + line << QString("Unprintable type: %1").arg(value.typeName()); + } + } else { + line << QString{}; + } } state.stageTableLine(line); } diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp index 3380b04..8a8684c 100644 --- a/sinksh/syntaxtree.cpp +++ b/sinksh/syntaxtree.cpp @@ -101,14 +101,22 @@ SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const QStringList tailCommands; while (commandLineIt.hasNext() && syntaxIt.hasNext()) { const QString word = commandLineIt.next(); + bool match = false; while (syntaxIt.hasNext()) { const Syntax &syntax = syntaxIt.next(); if (word == syntax.keyword) { lastFullSyntax = &syntax; syntaxIt = syntax.children; + match = true; break; } } + if (!match) { + //Otherwise we would miss the just evaluated command from the tailCommands + if (commandLineIt.hasPrevious()) { + commandLineIt.previous(); + } + } } if (lastFullSyntax) { -- cgit v1.2.3