diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 10:44:25 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 10:44:25 +0100 |
commit | d09517a4d4fcdf496c0298ef8b8f54f3c9120293 (patch) | |
tree | 7b35e8ebe88ae5ff47387deb428c3ff8da42d28e /sinksh | |
parent | 4e9f8f2590f55b39b9ff70d2c375fc2d25d2500d (diff) | |
download | sink-d09517a4d4fcdf496c0298ef8b8f54f3c9120293.tar.gz sink-d09517a4d4fcdf496c0298ef8b8f54f3c9120293.zip |
sinksh fixes
Diffstat (limited to 'sinksh')
-rw-r--r-- | sinksh/sinksh_utils.cpp | 7 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_create.cpp | 25 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 15 | ||||
-rw-r--r-- | sinksh/syntaxtree.cpp | 8 |
4 files changed, 51 insertions, 4 deletions
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) | |||
56 | return store; | 56 | return store; |
57 | } | 57 | } |
58 | 58 | ||
59 | qWarning() << "Trying to get a store that doesn't exist, falling back to event"; | 59 | SinkWarning_("", "") << "Trying to get a store that doesn't exist: " << type; |
60 | Q_ASSERT(false); | 60 | Q_ASSERT(false); |
61 | static Store<Sink::ApplicationDomain::Event> store; | 61 | static Store<Sink::ApplicationDomain::ApplicationDomainType> store; |
62 | return store; | 62 | return store; |
63 | } | 63 | } |
64 | 64 | ||
@@ -67,7 +67,8 @@ QList<QByteArray> requestedProperties(const QString &type) | |||
67 | using namespace Sink::ApplicationDomain; | 67 | using namespace Sink::ApplicationDomain; |
68 | if (type == getTypeName<Folder>()) { | 68 | if (type == getTypeName<Folder>()) { |
69 | return QList<QByteArray>() << Folder::Name::name | 69 | return QList<QByteArray>() << Folder::Name::name |
70 | << Folder::Parent::name; | 70 | << Folder::Parent::name |
71 | << Folder::SpecialPurpose::name; | ||
71 | } else if (type == getTypeName<Mail>()) { | 72 | } else if (type == getTypeName<Mail>()) { |
72 | return QList<QByteArray>() << Mail::Subject::name | 73 | return QList<QByteArray>() << Mail::Subject::name |
73 | << Mail::Folder::name | 74 | << 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) | |||
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | 141 | ||
142 | bool identity(const QStringList &args, State &state) | ||
143 | { | ||
144 | auto &store = SinkshUtils::getStore("identity"); | ||
145 | |||
146 | auto map = SinkshUtils::keyValueMapFromArgs(args); | ||
147 | |||
148 | auto identifier = map.take("identifier").toLatin1(); | ||
149 | |||
150 | auto object = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Identity>("", identifier); | ||
151 | |||
152 | for (auto i = map.begin(); i != map.end(); ++i) { | ||
153 | object.setProperty(i.key().toLatin1(), i.value()); | ||
154 | } | ||
155 | |||
156 | auto result = store.create(object).exec(); | ||
157 | result.waitForFinished(); | ||
158 | if (result.errorCode()) { | ||
159 | state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), | ||
160 | "sink_create_e" + QString::number(result.errorCode())); | ||
161 | } | ||
162 | |||
163 | return true; | ||
164 | } | ||
165 | |||
142 | 166 | ||
143 | Syntax::List syntax() | 167 | Syntax::List syntax() |
144 | { | 168 | { |
@@ -147,6 +171,7 @@ Syntax::List syntax() | |||
147 | Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); | 171 | Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); |
148 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); | 172 | create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); |
149 | create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); | 173 | create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account); |
174 | create.children << Syntax("identity", QObject::tr("Creates a new identity"), &SinkCreate::identity); | ||
150 | 175 | ||
151 | syntax << create; | 176 | syntax << create; |
152 | return syntax; | 177 | 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) | |||
82 | line << o.resourceInstanceIdentifier(); | 82 | line << o.resourceInstanceIdentifier(); |
83 | line << o.identifier(); | 83 | line << o.identifier(); |
84 | for (const auto &prop: query.requestedProperties) { | 84 | for (const auto &prop: query.requestedProperties) { |
85 | line << o.getProperty(prop).toString(); | 85 | const auto value = o.getProperty(prop); |
86 | if (value.isValid()) { | ||
87 | if (value.canConvert<QString>()) { | ||
88 | line << value.toString(); | ||
89 | } else if (value.canConvert<QByteArray>()) { | ||
90 | line << value.toByteArray(); | ||
91 | } else if (value.canConvert<QByteArrayList>()) { | ||
92 | line << value.value<QByteArrayList>().join(", "); | ||
93 | } else { | ||
94 | line << QString("Unprintable type: %1").arg(value.typeName()); | ||
95 | } | ||
96 | } else { | ||
97 | line << QString{}; | ||
98 | } | ||
86 | } | 99 | } |
87 | state.stageTableLine(line); | 100 | state.stageTableLine(line); |
88 | } | 101 | } |
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 | |||
101 | QStringList tailCommands; | 101 | QStringList tailCommands; |
102 | while (commandLineIt.hasNext() && syntaxIt.hasNext()) { | 102 | while (commandLineIt.hasNext() && syntaxIt.hasNext()) { |
103 | const QString word = commandLineIt.next(); | 103 | const QString word = commandLineIt.next(); |
104 | bool match = false; | ||
104 | while (syntaxIt.hasNext()) { | 105 | while (syntaxIt.hasNext()) { |
105 | const Syntax &syntax = syntaxIt.next(); | 106 | const Syntax &syntax = syntaxIt.next(); |
106 | if (word == syntax.keyword) { | 107 | if (word == syntax.keyword) { |
107 | lastFullSyntax = &syntax; | 108 | lastFullSyntax = &syntax; |
108 | syntaxIt = syntax.children; | 109 | syntaxIt = syntax.children; |
110 | match = true; | ||
109 | break; | 111 | break; |
110 | } | 112 | } |
111 | } | 113 | } |
114 | if (!match) { | ||
115 | //Otherwise we would miss the just evaluated command from the tailCommands | ||
116 | if (commandLineIt.hasPrevious()) { | ||
117 | commandLineIt.previous(); | ||
118 | } | ||
119 | } | ||
112 | } | 120 | } |
113 | 121 | ||
114 | if (lastFullSyntax) { | 122 | if (lastFullSyntax) { |