From 4d9746c828558c9f872e0aed52442863affb25d5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 3 Mar 2016 09:01:05 +0100 Subject: Fromatted the whole codebase with clang-format. clang-format -i */**{.cpp,.h} --- sinksh/main.cpp | 12 +++++------- sinksh/sinksh_utils.cpp | 32 +++++++++++++++++++------------- sinksh/sinksh_utils.h | 38 +++++++++++++++++++++----------------- sinksh/state.cpp | 7 ++----- sinksh/state.h | 3 +-- sinksh/syntaxtree.cpp | 18 +++++++----------- sinksh/syntaxtree.h | 9 ++++----- sinksh/utils.cpp | 6 ++---- sinksh/utils.h | 4 +--- 9 files changed, 62 insertions(+), 67 deletions(-) (limited to 'sinksh') 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() } Repl *repl = new Repl; - QObject::connect(repl, &QStateMachine::finished, - repl, &QObject::deleteLater); - QObject::connect(repl, &QStateMachine::finished, - QCoreApplication::instance(), &QCoreApplication::quit); + QObject::connect(repl, &QStateMachine::finished, repl, &QObject::deleteLater); + QObject::connect(repl, &QStateMachine::finished, QCoreApplication::instance(), &QCoreApplication::quit); State::setHasEventLoop(true); int rv = QCoreApplication::instance()->exec(); @@ -86,10 +84,10 @@ int main(int argc, char *argv[]) { const bool interactive = isatty(fileno(stdin)); const bool startRepl = (argc == 1) && interactive; - //TODO: make a json command parse cause that would be awesomesauce + // TODO: make a json command parse cause that would be awesomesauce const bool fromScript = !startRepl && QFile::exists(argv[1]); - //qDebug() << "state at startup is" << interactive << startRepl << fromScript; + // qDebug() << "state at startup is" << interactive << startRepl << fromScript; QCoreApplication app(argc, argv); app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); @@ -98,7 +96,7 @@ int main(int argc, char *argv[]) return enterRepl(); } else if (fromScript) { QFile f(argv[1]); - if (!f.open(QIODevice::ReadOnly)) { + if (!f.open(QIODevice::ReadOnly)) { return 1; } 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 @@ #include "utils.h" -namespace SinkshUtils -{ +namespace SinkshUtils { -static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event"; +static QStringList s_types = QStringList() << "resource" + << "folder" + << "mail" + << "event"; bool isValidStoreType(const QString &type) { @@ -50,9 +52,9 @@ StoreBase &getStore(const QString &type) return store; } - //TODO: reinstate the warning+assert - //Q_ASSERT(false); - //qWarning() << "Trying to get a store that doesn't exist, falling back to event"; + // TODO: reinstate the warning+assert + // Q_ASSERT(false); + // qWarning() << "Trying to get a store that doesn't exist, falling back to event"; static Store store; return store; } @@ -60,9 +62,12 @@ StoreBase &getStore(const QString &type) QSharedPointer loadModel(const QString &type, Sink::Query query) { if (type == "folder") { - query.requestedProperties << "name" << "parent"; + query.requestedProperties << "name" + << "parent"; } else if (type == "mail") { - query.requestedProperties << "subject" << "folder" << "date"; + query.requestedProperties << "subject" + << "folder" + << "date"; } else if (type == "event") { query.requestedProperties << "summary"; } else if (type == "resource") { @@ -80,7 +85,7 @@ QStringList resourceIds(State &state) query.liveQuery = false; auto model = SinkshUtils::loadModel("resource", query); - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources] (const QModelIndex &index, int start, int end) mutable { + QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources](const QModelIndex &index, int start, int end) mutable { for (int i = start; i <= end; i++) { auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); resources << object->identifier(); @@ -105,7 +110,10 @@ QStringList resourceCompleter(const QStringList &, const QString &fragment, Stat QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) { - static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event"; + static QStringList types = QStringList() << "resource" + << "folder" + << "mail" + << "event"; if (commands.count() == 1) { return Utils::filteredCompletions(s_types, fragment); } @@ -120,7 +128,7 @@ QStringList typeCompleter(const QStringList &commands, const QString &fragment, QMap keyValueMapFromArgs(const QStringList &args) { - //TODO: this is not the most clever of algorithms. preserved during the port of commands + // TODO: this is not the most clever of algorithms. preserved during the port of commands // from sink_client ... we can probably do better, however ;) QMap map; for (int i = 0; i + 2 <= args.size(); i += 2) { @@ -129,6 +137,4 @@ QMap keyValueMapFromArgs(const QStringList &args) return map; } - } - 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 @@ #include "state.h" -namespace SinkshUtils -{ +namespace SinkshUtils { class StoreBase; @@ -45,9 +44,10 @@ QMap keyValueMapFromArgs(const QStringList &args); /** * A small abstraction layer to use the sink store with the type available as string. */ -class StoreBase { +class StoreBase +{ public: - virtual ~StoreBase() {}; + virtual ~StoreBase(){}; virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; virtual KAsync::Job create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; @@ -57,33 +57,37 @@ public: }; template -class Store : public StoreBase { +class Store : public StoreBase +{ public: - Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { + Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE + { return T::Ptr::create(); } - Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { + Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE + { return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer::create()); } - KAsync::Job create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::create(*static_cast(&type)); + KAsync::Job create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE + { + return Sink::Store::create(*static_cast(&type)); } - KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::modify(*static_cast(&type)); + KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE + { + return Sink::Store::modify(*static_cast(&type)); } - KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Sink::Store::remove(*static_cast(&type)); + KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE + { + return Sink::Store::remove(*static_cast(&type)); } - QSharedPointer loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { + QSharedPointer loadModel(const Sink::Query &query) Q_DECL_OVERRIDE + { return Sink::Store::loadModel(query); } }; - - } - 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; class State::Private { public: - Private() - : outStream(stdout) + Private() : outStream(stdout) { } @@ -51,8 +50,7 @@ public: QTextStream outStream; }; -State::State() - : d(new Private) +State::State() : d(new Private) { } @@ -141,4 +139,3 @@ QString State::loggingLevel() const QByteArray rv = Sink::Log::debugLevelName(Sink::Log::debugOutputLevel()); return rv.toLower(); } - 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: private: class Private; - Private * const d; + Private *const d; }; - 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() } Syntax::Syntax(const QString &k, const QString &helpText, std::function l, Interactivity inter) - : keyword(k), - help(helpText), - interactivity(inter), - lambda(l) + : keyword(k), help(helpText), interactivity(inter), lambda(l) { } @@ -75,10 +72,10 @@ bool SyntaxTree::run(const QStringList &commands) m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); } else { QStringList keywordList; - for (auto syntax: command.first->children) { + for (auto syntax : command.first->children) { keywordList << syntax.keyword; } - const QString keywords = keywordList.join(" " ); + const QString keywords = keywordList.join(" "); m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); } } else { @@ -129,9 +126,9 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString & { Syntax::List matches; - //qDebug() << "words are" << words; + // qDebug() << "words are" << words; if (words.isEmpty()) { - for (const Syntax &syntax: m_syntax) { + for (const Syntax &syntax : m_syntax) { if (syntax.keyword.startsWith(fragment)) { matches.push_back(syntax); } @@ -153,7 +150,7 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString & } } - //qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); + // qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); if (lastFullSyntax.keyword == words.last()) { syntaxIt = lastFullSyntax.children; while (syntaxIt.hasNext()) { @@ -175,7 +172,7 @@ State &SyntaxTree::state() QStringList SyntaxTree::tokenize(const QString &text) { - //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a + // TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a static const QVector quoters = QVector() << '"' << '\''; QStringList tokens; QString acc; @@ -218,4 +215,3 @@ QStringList SyntaxTree::tokenize(const QString &text) return tokens; } - 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 public: typedef QVector List; - enum Interactivity { + enum Interactivity + { NotInteractive = 0, EventDriven }; Syntax(); - Syntax(const QString &keyword, - const QString &helpText = QString(), - std::function lambda = std::function(), - Interactivity interactivity = NotInteractive); + Syntax(const QString &keyword, const QString &helpText = QString(), + std::function lambda = std::function(), Interactivity interactivity = NotInteractive); QString keyword; 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 @@ #include "utils.h" -namespace Utils -{ +namespace Utils { QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) { @@ -29,7 +28,7 @@ QStringList filteredCompletions(const QStringList &possibleCompletions, const QS } QStringList filtered; - for (auto item: possibleCompletions) { + for (auto item : possibleCompletions) { if (item.startsWith(commandFragment, cs)) { filtered << item; } @@ -39,4 +38,3 @@ QStringList filteredCompletions(const QStringList &possibleCompletions, const QS } } // namespace Utils - 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 @@ #include -namespace Utils -{ +namespace Utils { QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); } // namespace Utils - -- cgit v1.2.3