From d488457bf699752b39b270cc88535d44f452b594 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 4 Oct 2016 14:57:40 +0200 Subject: Less hardcoding of entity types --- sinksh/sinksh_utils.cpp | 74 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'sinksh') diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 5a01d40..0b9a34d 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -27,33 +27,29 @@ namespace SinkshUtils { -static QStringList s_types = QStringList() << "resource" - << "folder" - << "mail" - << "event" - << "account"; - bool isValidStoreType(const QString &type) { - return s_types.contains(type); + return Sink::ApplicationDomain::getTypeNames().contains(type.toLatin1()); } StoreBase &getStore(const QString &type) { - if (type == "folder") { - static Store store; + using namespace Sink::ApplicationDomain; + + if (type == getTypeName()) { + static Store store; return store; - } else if (type == "mail") { - static Store store; + } else if (type == getTypeName()) { + static Store store; return store; - } else if (type == "event") { - static Store store; + } else if (type == getTypeName()) { + static Store store; return store; - } else if (type == "resource") { - static Store store; + } else if (type == getTypeName()) { + static Store store; return store; - } else if (type == "account") { - static Store store; + } else if (type == getTypeName()) { + static Store store; return store; } @@ -66,19 +62,20 @@ StoreBase &getStore(const QString &type) QList requestedProperties(const QString &type) { - if (type == "folder") { - return QList() << "name" - << "parent"; - } else if (type == "mail") { - return QList() << "subject" - << "folder" - << "date"; - } else if (type == "event") { - return QList() << "summary"; - } else if (type == "resource") { - return QList() << "type" << "account"; - } else if (type == "account") { - return QList() << "type" << "name"; + using namespace Sink::ApplicationDomain; + if (type == getTypeName()) { + return QList() << Folder::Name::name + << Folder::Parent::name; + } else if (type == getTypeName()) { + return QList() << Mail::Subject::name + << Mail::Folder::name + << Mail::Date::name; + } else if (type == getTypeName()) { + return QList() << Event::Summary::name; + } else if (type == getTypeName()) { + return QList() << SinkResource::ResourceType::name << SinkResource::Account::name; + } else if (type == getTypeName()) { + return QList() << SinkAccount::AccountType::name << SinkAccount::Name::name; } return QList(); } @@ -112,11 +109,19 @@ QStringList resourceCompleter(const QStringList &, const QString &fragment, Stat return Utils::filteredCompletions(resourceIds(), fragment); } +static QStringList toStringList(const QByteArrayList &l) +{ + QStringList list; + for (const auto &s : l) { + list << s; + } + return list; +} + QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) { - static QStringList types = s_types; if (commands.count() == 1) { - return Utils::filteredCompletions(s_types, fragment); + return Utils::filteredCompletions(toStringList(Sink::ApplicationDomain::getTypeNames()), fragment); } return Utils::filteredCompletions(resourceIds(), fragment); @@ -124,18 +129,15 @@ QStringList resourceOrTypeCompleter(const QStringList &commands, const QString & QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) { - return Utils::filteredCompletions(s_types, fragment); + return Utils::filteredCompletions(toStringList(Sink::ApplicationDomain::getTypeNames()), fragment); } QMap keyValueMapFromArgs(const QStringList &args) { - // 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) { map.insert(args.at(i), args.at(i + 1)); } - return map; } } -- cgit v1.2.3