summaryrefslogtreecommitdiffstats
path: root/sinksh
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
commit4d9746c828558c9f872e0aed52442863affb25d5 (patch)
tree507d7c2ba67f47d3cbbcf01a722236ff1b48426b /sinksh
parent9cea920b7dd51867a0be0fed2f461b6be73c103e (diff)
downloadsink-4d9746c828558c9f872e0aed52442863affb25d5.tar.gz
sink-4d9746c828558c9f872e0aed52442863affb25d5.zip
Fromatted the whole codebase with clang-format.
clang-format -i */**{.cpp,.h}
Diffstat (limited to 'sinksh')
-rw-r--r--sinksh/main.cpp12
-rw-r--r--sinksh/sinksh_utils.cpp32
-rw-r--r--sinksh/sinksh_utils.h38
-rw-r--r--sinksh/state.cpp7
-rw-r--r--sinksh/state.h3
-rw-r--r--sinksh/syntaxtree.cpp18
-rw-r--r--sinksh/syntaxtree.h9
-rw-r--r--sinksh/utils.cpp6
-rw-r--r--sinksh/utils.h4
9 files changed, 62 insertions, 67 deletions
diff --git a/sinksh/main.cpp b/sinksh/main.cpp
index 4c00b9b..84f532d 100644
--- a/sinksh/main.cpp
+++ b/sinksh/main.cpp
@@ -44,10 +44,8 @@ int enterRepl()
44 } 44 }
45 45
46 Repl *repl = new Repl; 46 Repl *repl = new Repl;
47 QObject::connect(repl, &QStateMachine::finished, 47 QObject::connect(repl, &QStateMachine::finished, repl, &QObject::deleteLater);
48 repl, &QObject::deleteLater); 48 QObject::connect(repl, &QStateMachine::finished, QCoreApplication::instance(), &QCoreApplication::quit);
49 QObject::connect(repl, &QStateMachine::finished,
50 QCoreApplication::instance(), &QCoreApplication::quit);
51 49
52 State::setHasEventLoop(true); 50 State::setHasEventLoop(true);
53 int rv = QCoreApplication::instance()->exec(); 51 int rv = QCoreApplication::instance()->exec();
@@ -86,10 +84,10 @@ int main(int argc, char *argv[])
86{ 84{
87 const bool interactive = isatty(fileno(stdin)); 85 const bool interactive = isatty(fileno(stdin));
88 const bool startRepl = (argc == 1) && interactive; 86 const bool startRepl = (argc == 1) && interactive;
89 //TODO: make a json command parse cause that would be awesomesauce 87 // TODO: make a json command parse cause that would be awesomesauce
90 const bool fromScript = !startRepl && QFile::exists(argv[1]); 88 const bool fromScript = !startRepl && QFile::exists(argv[1]);
91 89
92 //qDebug() << "state at startup is" << interactive << startRepl << fromScript; 90 // qDebug() << "state at startup is" << interactive << startRepl << fromScript;
93 91
94 QCoreApplication app(argc, argv); 92 QCoreApplication app(argc, argv);
95 app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); 93 app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]);
@@ -98,7 +96,7 @@ int main(int argc, char *argv[])
98 return enterRepl(); 96 return enterRepl();
99 } else if (fromScript) { 97 } else if (fromScript) {
100 QFile f(argv[1]); 98 QFile f(argv[1]);
101 if (!f.open(QIODevice::ReadOnly)) { 99 if (!f.open(QIODevice::ReadOnly)) {
102 return 1; 100 return 1;
103 } 101 }
104 102
diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp
index d5b1c22..9ff966b 100644
--- a/sinksh/sinksh_utils.cpp
+++ b/sinksh/sinksh_utils.cpp
@@ -24,10 +24,12 @@
24 24
25#include "utils.h" 25#include "utils.h"
26 26
27namespace SinkshUtils 27namespace SinkshUtils {
28{
29 28
30static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event"; 29static QStringList s_types = QStringList() << "resource"
30 << "folder"
31 << "mail"
32 << "event";
31 33
32bool isValidStoreType(const QString &type) 34bool isValidStoreType(const QString &type)
33{ 35{
@@ -50,9 +52,9 @@ StoreBase &getStore(const QString &type)
50 return store; 52 return store;
51 } 53 }
52 54
53 //TODO: reinstate the warning+assert 55 // TODO: reinstate the warning+assert
54 //Q_ASSERT(false); 56 // Q_ASSERT(false);
55 //qWarning() << "Trying to get a store that doesn't exist, falling back to event"; 57 // qWarning() << "Trying to get a store that doesn't exist, falling back to event";
56 static Store<Sink::ApplicationDomain::Event> store; 58 static Store<Sink::ApplicationDomain::Event> store;
57 return store; 59 return store;
58} 60}
@@ -60,9 +62,12 @@ StoreBase &getStore(const QString &type)
60QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query) 62QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query)
61{ 63{
62 if (type == "folder") { 64 if (type == "folder") {
63 query.requestedProperties << "name" << "parent"; 65 query.requestedProperties << "name"
66 << "parent";
64 } else if (type == "mail") { 67 } else if (type == "mail") {
65 query.requestedProperties << "subject" << "folder" << "date"; 68 query.requestedProperties << "subject"
69 << "folder"
70 << "date";
66 } else if (type == "event") { 71 } else if (type == "event") {
67 query.requestedProperties << "summary"; 72 query.requestedProperties << "summary";
68 } else if (type == "resource") { 73 } else if (type == "resource") {
@@ -80,7 +85,7 @@ QStringList resourceIds(State &state)
80 query.liveQuery = false; 85 query.liveQuery = false;
81 auto model = SinkshUtils::loadModel("resource", query); 86 auto model = SinkshUtils::loadModel("resource", query);
82 87
83 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources] (const QModelIndex &index, int start, int end) mutable { 88 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources](const QModelIndex &index, int start, int end) mutable {
84 for (int i = start; i <= end; i++) { 89 for (int i = start; i <= end; i++) {
85 auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>(); 90 auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>();
86 resources << object->identifier(); 91 resources << object->identifier();
@@ -105,7 +110,10 @@ QStringList resourceCompleter(const QStringList &, const QString &fragment, Stat
105 110
106QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) 111QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state)
107{ 112{
108 static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event"; 113 static QStringList types = QStringList() << "resource"
114 << "folder"
115 << "mail"
116 << "event";
109 if (commands.count() == 1) { 117 if (commands.count() == 1) {
110 return Utils::filteredCompletions(s_types, fragment); 118 return Utils::filteredCompletions(s_types, fragment);
111 } 119 }
@@ -120,7 +128,7 @@ QStringList typeCompleter(const QStringList &commands, const QString &fragment,
120 128
121QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) 129QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
122{ 130{
123 //TODO: this is not the most clever of algorithms. preserved during the port of commands 131 // TODO: this is not the most clever of algorithms. preserved during the port of commands
124 // from sink_client ... we can probably do better, however ;) 132 // from sink_client ... we can probably do better, however ;)
125 QMap<QString, QString> map; 133 QMap<QString, QString> map;
126 for (int i = 0; i + 2 <= args.size(); i += 2) { 134 for (int i = 0; i + 2 <= args.size(); i += 2) {
@@ -129,6 +137,4 @@ QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
129 137
130 return map; 138 return map;
131} 139}
132
133} 140}
134
diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h
index bc4f6e5..5f470ff 100644
--- a/sinksh/sinksh_utils.h
+++ b/sinksh/sinksh_utils.h
@@ -28,8 +28,7 @@
28 28
29#include "state.h" 29#include "state.h"
30 30
31namespace SinkshUtils 31namespace SinkshUtils {
32{
33 32
34class StoreBase; 33class StoreBase;
35 34
@@ -45,9 +44,10 @@ QMap<QString, QString> keyValueMapFromArgs(const QStringList &args);
45/** 44/**
46 * A small abstraction layer to use the sink store with the type available as string. 45 * A small abstraction layer to use the sink store with the type available as string.
47 */ 46 */
48class StoreBase { 47class StoreBase
48{
49public: 49public:
50 virtual ~StoreBase() {}; 50 virtual ~StoreBase(){};
51 virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; 51 virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0;
52 virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; 52 virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0;
53 virtual KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; 53 virtual KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0;
@@ -57,33 +57,37 @@ public:
57}; 57};
58 58
59template <typename T> 59template <typename T>
60class Store : public StoreBase { 60class Store : public StoreBase
61{
61public: 62public:
62 Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { 63 Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE
64 {
63 return T::Ptr::create(); 65 return T::Ptr::create();
64 } 66 }
65 67
66 Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { 68 Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE
69 {
67 return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 70 return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
68 } 71 }
69 72
70 KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { 73 KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE
71 return Sink::Store::create<T>(*static_cast<const T*>(&type)); 74 {
75 return Sink::Store::create<T>(*static_cast<const T *>(&type));
72 } 76 }
73 77
74 KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { 78 KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE
75 return Sink::Store::modify<T>(*static_cast<const T*>(&type)); 79 {
80 return Sink::Store::modify<T>(*static_cast<const T *>(&type));
76 } 81 }
77 82
78 KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { 83 KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE
79 return Sink::Store::remove<T>(*static_cast<const T*>(&type)); 84 {
85 return Sink::Store::remove<T>(*static_cast<const T *>(&type));
80 } 86 }
81 87
82 QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { 88 QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) Q_DECL_OVERRIDE
89 {
83 return Sink::Store::loadModel<T>(query); 90 return Sink::Store::loadModel<T>(query);
84 } 91 }
85}; 92};
86
87
88} 93}
89
diff --git a/sinksh/state.cpp b/sinksh/state.cpp
index e03bf87..7fd3959 100644
--- a/sinksh/state.cpp
+++ b/sinksh/state.cpp
@@ -31,8 +31,7 @@ static bool s_hasEventLoop = false;
31class State::Private 31class State::Private
32{ 32{
33public: 33public:
34 Private() 34 Private() : outStream(stdout)
35 : outStream(stdout)
36 { 35 {
37 } 36 }
38 37
@@ -51,8 +50,7 @@ public:
51 QTextStream outStream; 50 QTextStream outStream;
52}; 51};
53 52
54State::State() 53State::State() : d(new Private)
55 : d(new Private)
56{ 54{
57} 55}
58 56
@@ -141,4 +139,3 @@ QString State::loggingLevel() const
141 QByteArray rv = Sink::Log::debugLevelName(Sink::Log::debugOutputLevel()); 139 QByteArray rv = Sink::Log::debugLevelName(Sink::Log::debugOutputLevel());
142 return rv.toLower(); 140 return rv.toLower();
143} 141}
144
diff --git a/sinksh/state.h b/sinksh/state.h
index 3c4c2c7..2a0eb7c 100644
--- a/sinksh/state.h
+++ b/sinksh/state.h
@@ -47,6 +47,5 @@ public:
47 47
48private: 48private:
49 class Private; 49 class Private;
50 Private * const d; 50 Private *const d;
51}; 51};
52
diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp
index 4860582..3380b04 100644
--- a/sinksh/syntaxtree.cpp
+++ b/sinksh/syntaxtree.cpp
@@ -29,10 +29,7 @@ Syntax::Syntax()
29} 29}
30 30
31Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) 31Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter)
32 : keyword(k), 32 : keyword(k), help(helpText), interactivity(inter), lambda(l)
33 help(helpText),
34 interactivity(inter),
35 lambda(l)
36{ 33{
37} 34}
38 35
@@ -75,10 +72,10 @@ bool SyntaxTree::run(const QStringList &commands)
75 m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); 72 m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken");
76 } else { 73 } else {
77 QStringList keywordList; 74 QStringList keywordList;
78 for (auto syntax: command.first->children) { 75 for (auto syntax : command.first->children) {
79 keywordList << syntax.keyword; 76 keywordList << syntax.keyword;
80 } 77 }
81 const QString keywords = keywordList.join(" " ); 78 const QString keywords = keywordList.join(" ");
82 m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); 79 m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords));
83 } 80 }
84 } else { 81 } else {
@@ -129,9 +126,9 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString &
129{ 126{
130 Syntax::List matches; 127 Syntax::List matches;
131 128
132 //qDebug() << "words are" << words; 129 // qDebug() << "words are" << words;
133 if (words.isEmpty()) { 130 if (words.isEmpty()) {
134 for (const Syntax &syntax: m_syntax) { 131 for (const Syntax &syntax : m_syntax) {
135 if (syntax.keyword.startsWith(fragment)) { 132 if (syntax.keyword.startsWith(fragment)) {
136 matches.push_back(syntax); 133 matches.push_back(syntax);
137 } 134 }
@@ -153,7 +150,7 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString &
153 } 150 }
154 } 151 }
155 152
156 //qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); 153 // qDebug() << "exiting with" << lastFullSyntax.keyword << words.last();
157 if (lastFullSyntax.keyword == words.last()) { 154 if (lastFullSyntax.keyword == words.last()) {
158 syntaxIt = lastFullSyntax.children; 155 syntaxIt = lastFullSyntax.children;
159 while (syntaxIt.hasNext()) { 156 while (syntaxIt.hasNext()) {
@@ -175,7 +172,7 @@ State &SyntaxTree::state()
175 172
176QStringList SyntaxTree::tokenize(const QString &text) 173QStringList SyntaxTree::tokenize(const QString &text)
177{ 174{
178 //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a 175 // TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a
179 static const QVector<QChar> quoters = QVector<QChar>() << '"' << '\''; 176 static const QVector<QChar> quoters = QVector<QChar>() << '"' << '\'';
180 QStringList tokens; 177 QStringList tokens;
181 QString acc; 178 QString acc;
@@ -218,4 +215,3 @@ QStringList SyntaxTree::tokenize(const QString &text)
218 215
219 return tokens; 216 return tokens;
220} 217}
221
diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h
index 468aad3..be56067 100644
--- a/sinksh/syntaxtree.h
+++ b/sinksh/syntaxtree.h
@@ -32,16 +32,15 @@ class Syntax
32public: 32public:
33 typedef QVector<Syntax> List; 33 typedef QVector<Syntax> List;
34 34
35 enum Interactivity { 35 enum Interactivity
36 {
36 NotInteractive = 0, 37 NotInteractive = 0,
37 EventDriven 38 EventDriven
38 }; 39 };
39 40
40 Syntax(); 41 Syntax();
41 Syntax(const QString &keyword, 42 Syntax(const QString &keyword, const QString &helpText = QString(),
42 const QString &helpText = QString(), 43 std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), Interactivity interactivity = NotInteractive);
43 std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(),
44 Interactivity interactivity = NotInteractive);
45 44
46 QString keyword; 45 QString keyword;
47 QString help; 46 QString help;
diff --git a/sinksh/utils.cpp b/sinksh/utils.cpp
index d2a28ed..7eea85f 100644
--- a/sinksh/utils.cpp
+++ b/sinksh/utils.cpp
@@ -19,8 +19,7 @@
19 19
20#include "utils.h" 20#include "utils.h"
21 21
22namespace Utils 22namespace Utils {
23{
24 23
25QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) 24QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs)
26{ 25{
@@ -29,7 +28,7 @@ QStringList filteredCompletions(const QStringList &possibleCompletions, const QS
29 } 28 }
30 29
31 QStringList filtered; 30 QStringList filtered;
32 for (auto item: possibleCompletions) { 31 for (auto item : possibleCompletions) {
33 if (item.startsWith(commandFragment, cs)) { 32 if (item.startsWith(commandFragment, cs)) {
34 filtered << item; 33 filtered << item;
35 } 34 }
@@ -39,4 +38,3 @@ QStringList filteredCompletions(const QStringList &possibleCompletions, const QS
39} 38}
40 39
41} // namespace Utils 40} // namespace Utils
42
diff --git a/sinksh/utils.h b/sinksh/utils.h
index 82be8d5..bcbdedb 100644
--- a/sinksh/utils.h
+++ b/sinksh/utils.h
@@ -21,10 +21,8 @@
21 21
22#include <QStringList> 22#include <QStringList>
23 23
24namespace Utils 24namespace Utils {
25{
26 25
27QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); 26QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive);
28 27
29} // namespace Utils 28} // namespace Utils
30