From 8b07718cb47dca6240a70e9aea57b88121cc956b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 23:25:09 +0100 Subject: akonadi2_cli -> akonadish --- akonadish/syntax_modules/akonadi_count.cpp | 79 ++++++++++++++++ akonadish/syntax_modules/akonadi_count.h | 29 ++++++ akonadish/syntax_modules/akonadi_list.cpp | 112 +++++++++++++++++++++++ akonadish/syntax_modules/akonadi_list.h | 29 ++++++ akonadish/syntax_modules/core_syntax.cpp | 139 +++++++++++++++++++++++++++++ akonadish/syntax_modules/core_syntax.h | 33 +++++++ 6 files changed, 421 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_count.cpp create mode 100644 akonadish/syntax_modules/akonadi_count.h create mode 100644 akonadish/syntax_modules/akonadi_list.cpp create mode 100644 akonadish/syntax_modules/akonadi_list.h create mode 100644 akonadish/syntax_modules/core_syntax.cpp create mode 100644 akonadish/syntax_modules/core_syntax.h (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_count.cpp b/akonadish/syntax_modules/akonadi_count.cpp new file mode 100644 index 0000000..40ad693 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_count.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "akonadi_count.h" + +#include +#include +#include // tr() +#include +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" + +namespace AkonadiCount +{ + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count "), &AkonadiCount::count, Syntax::EventDriven); + + return syntax; +} + +bool count(const QStringList &args, State &state) +{ + auto resources = args; + auto type = !resources.isEmpty() ? resources.takeFirst() : QString(); + + if (!type.isEmpty() && !AkonadishUtils::isValidStoreType(type)) { + state.printError(QObject::tr("Unknown type: %1").arg(type)); + return false; + } + + Akonadi2::Query query; + for (const auto &res : resources) { + query.resources << res.toLatin1(); + } + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = false; + + auto model = AkonadishUtils::loadModel(type, query); + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + state.printLine(QObject::tr("Counted results %1").arg(model->rowCount(QModelIndex()))); + state.commandFinished(); + } + }); + + return true; +} + +} diff --git a/akonadish/syntax_modules/akonadi_count.h b/akonadish/syntax_modules/akonadi_count.h new file mode 100644 index 0000000..c592c4c --- /dev/null +++ b/akonadish/syntax_modules/akonadi_count.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "syntaxtree.h" + +namespace AkonadiCount +{ + Syntax::List syntax(); + bool count(const QStringList &commands, State &state); +} + diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp new file mode 100644 index 0000000..6abc853 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_list.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "akonadi_list.h" + +#include +#include +#include // tr() +#include +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" + +namespace AkonadiList +{ + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); + + return syntax; +} + +bool list(const QStringList &args, State &state) +{ + auto resources = args; + auto type = !resources.isEmpty() ? resources.takeFirst() : QString(); + + if (!type.isEmpty() && !AkonadishUtils::isValidStoreType(type)) { + state.printError(QObject::tr("Unknown type: %1").arg(type)); + return false; + } + + Akonadi2::Query query; + for (const auto &res : resources) { + query.resources << res.toLatin1(); + } + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = false; + + QTime time; + time.start(); + auto model = AkonadishUtils::loadModel(type, query); + if (state.debugLevel() > 0) { + state.printLine(QObject::tr("Folder type %1").arg(type)); + state.printLine(QObject::tr("Loaded model in %1 ms").arg(time.elapsed())); + } + + //qDebug() << "Listing"; + int colSize = 38; //Necessary to display a complete UUID + state.print(" " + QObject::tr("Column") + " "); + state.print(QObject::tr("Resource").leftJustified(colSize, ' ', true) + + QObject::tr("Identifier").leftJustified(colSize, ' ', true)); + for (int i = 0; i < model->columnCount(QModelIndex()); i++) { + state.print(" | " + model->headerData(i, Qt::Horizontal).toString().leftJustified(colSize, ' ', true)); + } + state.printLine(); + + QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, colSize, state](const QModelIndex &index, int start, int end) { + for (int i = start; i <= end; i++) { + state.print(" " + QObject::tr("Row %1").arg(QString::number(model->rowCount())).rightJustified(4, ' ') + ": "); + auto object = model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectBaseRole).value(); + state.print(" " + object->resourceInstanceIdentifier().leftJustified(colSize, ' ', true)); + state.print(object->identifier().leftJustified(colSize, ' ', true)); + for (int col = 0; col < model->columnCount(QModelIndex()); col++) { + state.print(" | " + model->data(model->index(i, col, index)).toString().leftJustified(colSize, ' ', true)); + } + state.printLine(); + } + }); + + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + state.commandFinished(); + } + }); + + if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { + return true; + } + + return false; +} + +} diff --git a/akonadish/syntax_modules/akonadi_list.h b/akonadish/syntax_modules/akonadi_list.h new file mode 100644 index 0000000..61effc5 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_list.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "syntaxtree.h" + +namespace AkonadiList +{ + Syntax::List syntax(); + bool list(const QStringList &commands, State &state); +} + diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp new file mode 100644 index 0000000..393a0a5 --- /dev/null +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "core_syntax.h" + +#include +#include // tr() +#include +#include + +namespace CoreSyntax +{ + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); + + Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); + help.completer = &CoreSyntax::showHelpCompleter; + syntax << help; + + Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); + set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); + syntax << set; + + Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); + get.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); + syntax << get; + + return syntax; +} + +bool exit(const QStringList &, State &) +{ + ::exit(0); + return true; +} + +bool showHelp(const QStringList &commands, State &state) +{ + SyntaxTree::Command command = SyntaxTree::self()->match(commands); + if (commands.isEmpty()) { + state.printLine(QObject::tr("Welcome to the Akonadi2 command line tool!")); + state.printLine(QObject::tr("Top-level commands:")); + + QSet sorted; + for (auto syntax: SyntaxTree::self()->syntax()) { + sorted.insert(syntax.keyword); + } + + for (auto keyword: sorted) { + state.printLine(keyword, 1); + } + } else if (const Syntax *syntax = command.first) { + //TODO: get parent! + state.print(QObject::tr("Command `%1`").arg(syntax->keyword)); + + if (!syntax->help.isEmpty()) { + state.print(": " + syntax->help); + } + state.printLine(); + + if (!syntax->children.isEmpty()) { + state.printLine("Sub-commands:", 1); + QSet sorted; + for (auto childSyntax: syntax->children) { + sorted.insert(childSyntax.keyword); + } + + for (auto keyword: sorted) { + state.printLine(keyword, 1); + } + } + } else { + state.printError("Unknown command: " + commands.join(" ")); + } + + return true; +} + +QStringList showHelpCompleter(const QStringList &commands, const QString &fragment) +{ + QStringList items; + + for (auto syntax: SyntaxTree::self()->syntax()) { + if (syntax.keyword != QObject::tr("help") && + (fragment.isEmpty() || syntax.keyword.startsWith(fragment))) { + items << syntax.keyword; + } + } + + qSort(items); + return items; +} + +bool setDebugLevel(const QStringList &commands, State &state) +{ + if (commands.count() != 1) { + state.printError(QObject::tr("Wrong number of arguments; expected 1 got %1").arg(commands.count())); + return false; + } + + bool ok = false; + int level = commands[0].toUInt(&ok); + + if (!ok) { + state.printError(QObject::tr("Expected a number between 0 and 6, got %1").arg(commands[0])); + return false; + } + + state.setDebugLevel(level); + return true; +} + +bool printDebugLevel(const QStringList &commands, State &state) +{ + state.printLine(QString::number(state.debugLevel())); + return true; +} + +} // namespace CoreSyntax + diff --git a/akonadish/syntax_modules/core_syntax.h b/akonadish/syntax_modules/core_syntax.h new file mode 100644 index 0000000..89187e5 --- /dev/null +++ b/akonadish/syntax_modules/core_syntax.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "syntaxtree.h" + +namespace CoreSyntax +{ + Syntax::List syntax(); + bool exit(const QStringList &commands, State &state); + bool showHelp(const QStringList &commands, State &state); + QStringList showHelpCompleter(const QStringList &commands, const QString &fragment); + bool setDebugLevel(const QStringList &commands, State &state); + bool printDebugLevel(const QStringList &commands, State &state); +} + -- cgit v1.2.3 From 17ea319fa8cbdf36396a4a5a68853857ca6ac51f Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 23:39:14 +0100 Subject: sync command --- akonadish/syntax_modules/akonadi_sync.cpp | 67 +++++++++++++++++++++++++++++++ akonadish/syntax_modules/akonadi_sync.h | 29 +++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_sync.cpp create mode 100644 akonadish/syntax_modules/akonadi_sync.h (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_sync.cpp b/akonadish/syntax_modules/akonadi_sync.cpp new file mode 100644 index 0000000..990fdf6 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_sync.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "akonadi_sync.h" + +#include +#include // tr() +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" + +namespace AkonadiSync +{ + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &AkonadiSync::sync, Syntax::EventDriven ); + + return syntax; +} + +bool sync(const QStringList &args, State &state) +{ + Akonadi2::Query query; + for (const auto &res : args) { + query.resources << res.toLatin1(); + } + query.syncOnDemand = true; + query.processAll = true; + + QTimer::singleShot(0, [query, state]() { + Akonadi2::Store::synchronize(query).then([state]() { + state.printLine("Synchronization complete!"); + state.commandFinished(); + }).exec(); + }); + + return true; +} + +} diff --git a/akonadish/syntax_modules/akonadi_sync.h b/akonadish/syntax_modules/akonadi_sync.h new file mode 100644 index 0000000..62f7424 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_sync.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "syntaxtree.h" + +namespace AkonadiSync +{ + Syntax::List syntax(); + bool sync(const QStringList &commands, State &state); +} + -- cgit v1.2.3 From 35f0ddf67c629ce9efaa1ba893afcb2921a251a2 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 24 Dec 2015 10:22:07 +0100 Subject: REGISTER_SYNTAX for automagic adding of syntax a fun abuse of static initialization and std::function --- akonadish/syntax_modules/akonadi_count.cpp | 2 ++ akonadish/syntax_modules/akonadi_list.cpp | 2 ++ akonadish/syntax_modules/akonadi_sync.cpp | 2 ++ akonadish/syntax_modules/core_syntax.cpp | 2 ++ 4 files changed, 8 insertions(+) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_count.cpp b/akonadish/syntax_modules/akonadi_count.cpp index 40ad693..e54ac22 100644 --- a/akonadish/syntax_modules/akonadi_count.cpp +++ b/akonadish/syntax_modules/akonadi_count.cpp @@ -39,6 +39,8 @@ namespace AkonadiCount { +REGISTER_SYNTAX(AkonadiCount) + Syntax::List syntax() { Syntax::List syntax; diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp index 6abc853..25ebbca 100644 --- a/akonadish/syntax_modules/akonadi_list.cpp +++ b/akonadish/syntax_modules/akonadi_list.cpp @@ -39,6 +39,8 @@ namespace AkonadiList { +REGISTER_SYNTAX(AkonadiList) + Syntax::List syntax() { Syntax::List syntax; diff --git a/akonadish/syntax_modules/akonadi_sync.cpp b/akonadish/syntax_modules/akonadi_sync.cpp index 990fdf6..e9388d2 100644 --- a/akonadish/syntax_modules/akonadi_sync.cpp +++ b/akonadish/syntax_modules/akonadi_sync.cpp @@ -37,6 +37,8 @@ namespace AkonadiSync { +REGISTER_SYNTAX(AkonadiSync) + Syntax::List syntax() { Syntax::List syntax; diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index 393a0a5..8fb1448 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -27,6 +27,8 @@ namespace CoreSyntax { +REGISTER_SYNTAX(CoreSyntax) + Syntax::List syntax() { Syntax::List syntax; -- cgit v1.2.3 From 8b397cec29460e2cb53b9be02b4e53da9cce60c9 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 24 Dec 2015 16:23:46 +0100 Subject: bye-bye header files the function-centric approach simply does not require them! --- akonadish/syntax_modules/akonadi_count.cpp | 24 +++++++-------- akonadish/syntax_modules/akonadi_count.h | 29 ------------------ akonadish/syntax_modules/akonadi_list.cpp | 24 +++++++-------- akonadish/syntax_modules/akonadi_list.h | 29 ------------------ akonadish/syntax_modules/akonadi_sync.cpp | 24 +++++++-------- akonadish/syntax_modules/akonadi_sync.h | 29 ------------------ akonadish/syntax_modules/core_syntax.cpp | 49 +++++++++++++++--------------- akonadish/syntax_modules/core_syntax.h | 33 -------------------- 8 files changed, 61 insertions(+), 180 deletions(-) delete mode 100644 akonadish/syntax_modules/akonadi_count.h delete mode 100644 akonadish/syntax_modules/akonadi_list.h delete mode 100644 akonadish/syntax_modules/akonadi_sync.h delete mode 100644 akonadish/syntax_modules/core_syntax.h (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_count.cpp b/akonadish/syntax_modules/akonadi_count.cpp index e54ac22..70aabc9 100644 --- a/akonadish/syntax_modules/akonadi_count.cpp +++ b/akonadish/syntax_modules/akonadi_count.cpp @@ -17,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "akonadi_count.h" - #include #include #include // tr() @@ -35,20 +33,12 @@ #include "common/definitions.h" #include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" namespace AkonadiCount { -REGISTER_SYNTAX(AkonadiCount) - -Syntax::List syntax() -{ - Syntax::List syntax; - syntax << Syntax("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count "), &AkonadiCount::count, Syntax::EventDriven); - - return syntax; -} - bool count(const QStringList &args, State &state) { auto resources = args; @@ -78,4 +68,14 @@ bool count(const QStringList &args, State &state) return true; } +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count "), &AkonadiCount::count, Syntax::EventDriven); + + return syntax; +} + +REGISTER_SYNTAX(AkonadiCount) + } diff --git a/akonadish/syntax_modules/akonadi_count.h b/akonadish/syntax_modules/akonadi_count.h deleted file mode 100644 index c592c4c..0000000 --- a/akonadish/syntax_modules/akonadi_count.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#include "syntaxtree.h" - -namespace AkonadiCount -{ - Syntax::List syntax(); - bool count(const QStringList &commands, State &state); -} - diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp index 25ebbca..25ccabf 100644 --- a/akonadish/syntax_modules/akonadi_list.cpp +++ b/akonadish/syntax_modules/akonadi_list.cpp @@ -17,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "akonadi_list.h" - #include #include #include // tr() @@ -35,20 +33,12 @@ #include "common/definitions.h" #include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" namespace AkonadiList { -REGISTER_SYNTAX(AkonadiList) - -Syntax::List syntax() -{ - Syntax::List syntax; - syntax << Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); - - return syntax; -} - bool list(const QStringList &args, State &state) { auto resources = args; @@ -111,4 +101,14 @@ bool list(const QStringList &args, State &state) return false; } +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); + + return syntax; +} + +REGISTER_SYNTAX(AkonadiList) + } diff --git a/akonadish/syntax_modules/akonadi_list.h b/akonadish/syntax_modules/akonadi_list.h deleted file mode 100644 index 61effc5..0000000 --- a/akonadish/syntax_modules/akonadi_list.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#include "syntaxtree.h" - -namespace AkonadiList -{ - Syntax::List syntax(); - bool list(const QStringList &commands, State &state); -} - diff --git a/akonadish/syntax_modules/akonadi_sync.cpp b/akonadish/syntax_modules/akonadi_sync.cpp index e9388d2..1cf097d 100644 --- a/akonadish/syntax_modules/akonadi_sync.cpp +++ b/akonadish/syntax_modules/akonadi_sync.cpp @@ -17,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "akonadi_sync.h" - #include #include // tr() #include @@ -33,20 +31,12 @@ #include "common/definitions.h" #include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" namespace AkonadiSync { -REGISTER_SYNTAX(AkonadiSync) - -Syntax::List syntax() -{ - Syntax::List syntax; - syntax << Syntax("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &AkonadiSync::sync, Syntax::EventDriven ); - - return syntax; -} - bool sync(const QStringList &args, State &state) { Akonadi2::Query query; @@ -66,4 +56,14 @@ bool sync(const QStringList &args, State &state) return true; } +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &AkonadiSync::sync, Syntax::EventDriven ); + + return syntax; +} + +REGISTER_SYNTAX(AkonadiSync) + } diff --git a/akonadish/syntax_modules/akonadi_sync.h b/akonadish/syntax_modules/akonadi_sync.h deleted file mode 100644 index 62f7424..0000000 --- a/akonadish/syntax_modules/akonadi_sync.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#include "syntaxtree.h" - -namespace AkonadiSync -{ - Syntax::List syntax(); - bool sync(const QStringList &commands, State &state); -} - diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index 8fb1448..a0cd4c6 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -17,37 +17,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "core_syntax.h" - #include #include // tr() #include #include -namespace CoreSyntax -{ - -REGISTER_SYNTAX(CoreSyntax) +#include "state.h" +#include "syntaxtree.h" -Syntax::List syntax() +namespace CoreSyntax { - Syntax::List syntax; - syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); - - Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); - help.completer = &CoreSyntax::showHelpCompleter; - syntax << help; - - Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); - set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); - syntax << set; - - Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); - get.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); - syntax << get; - - return syntax; -} bool exit(const QStringList &, State &) { @@ -137,5 +116,27 @@ bool printDebugLevel(const QStringList &commands, State &state) return true; } +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); + + Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); + help.completer = &CoreSyntax::showHelpCompleter; + syntax << help; + + Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); + set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); + syntax << set; + + Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); + get.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); + syntax << get; + + return syntax; +} + +REGISTER_SYNTAX(CoreSyntax) + } // namespace CoreSyntax diff --git a/akonadish/syntax_modules/core_syntax.h b/akonadish/syntax_modules/core_syntax.h deleted file mode 100644 index 89187e5..0000000 --- a/akonadish/syntax_modules/core_syntax.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2014 Aaron Seigo - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#include "syntaxtree.h" - -namespace CoreSyntax -{ - Syntax::List syntax(); - bool exit(const QStringList &commands, State &state); - bool showHelp(const QStringList &commands, State &state); - QStringList showHelpCompleter(const QStringList &commands, const QString &fragment); - bool setDebugLevel(const QStringList &commands, State &state); - bool printDebugLevel(const QStringList &commands, State &state); -} - -- cgit v1.2.3 From 908dc9b172a08bfa219a834e15916e9fcfc3c4ec Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 10:31:30 +0100 Subject: syntax to turn timing on/off loving the lambdas :) --- akonadish/syntax_modules/core_syntax.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index a0cd4c6..9cd6a6a 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -110,12 +110,18 @@ bool setDebugLevel(const QStringList &commands, State &state) return true; } -bool printDebugLevel(const QStringList &commands, State &state) +bool printDebugLevel(const QStringList &, State &state) { state.printLine(QString::number(state.debugLevel())); return true; } +bool printCommandTiming(const QStringList &, State &state) +{ + state.printLine(state.commandTiming() ? QObject::tr("on") : QObject::tr("off")); + return true; +} + Syntax::List syntax() { Syntax::List syntax; @@ -127,10 +133,15 @@ Syntax::List syntax() Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); + Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete")); + setTiming.children << Syntax(QObject::tr("on"), QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); + setTiming.children << Syntax(QObject::tr("off"), QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); + set.children << setTiming; syntax << set; Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); - get.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); + get.children << Syntax(QObject::tr("debug"), QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); + get.children << Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); syntax << get; return syntax; -- cgit v1.2.3 From 1231996ec2668e330ead79a16edf85ded1e07e48 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 10:47:02 +0100 Subject: print the syntax tree --- akonadish/syntax_modules/core_syntax.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index 9cd6a6a..8f3219f 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -122,6 +122,29 @@ bool printCommandTiming(const QStringList &, State &state) return true; } +void printSyntaxBranch(State &state, const Syntax::List &list, int depth) +{ + if (list.isEmpty()) { + return; + } + + if (depth > 0) { + state.printLine("\\", depth); + } + + for (auto syntax: list) { + state.print("|-", depth); + state.printLine(syntax.keyword); + printSyntaxBranch(state, syntax.children, depth + 1); + } +} + +bool printSyntaxTree(const QStringList &, State &state) +{ + printSyntaxBranch(state, SyntaxTree::self()->syntax(), 0); + return true; +} + Syntax::List syntax() { Syntax::List syntax; @@ -131,6 +154,8 @@ Syntax::List syntax() help.completer = &CoreSyntax::showHelpCompleter; syntax << help; + syntax << Syntax("syntaxtree", QString(), &printSyntaxTree); + Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete")); -- cgit v1.2.3 From 540864148b9bccc4b00bb3ba504190d608489413 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 11:01:01 +0100 Subject: don't translate the commands; let them be scriptable universally --- akonadish/syntax_modules/core_syntax.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp index 8f3219f..31b824a 100644 --- a/akonadish/syntax_modules/core_syntax.cpp +++ b/akonadish/syntax_modules/core_syntax.cpp @@ -150,23 +150,23 @@ Syntax::List syntax() Syntax::List syntax; syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); - Syntax help(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); + Syntax help("help", QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); help.completer = &CoreSyntax::showHelpCompleter; syntax << help; syntax << Syntax("syntaxtree", QString(), &printSyntaxTree); - Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); - set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); - Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete")); - setTiming.children << Syntax(QObject::tr("on"), QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); - setTiming.children << Syntax(QObject::tr("off"), QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); + Syntax set("set", QObject::tr("Sets settings for the session")); + set.children << Syntax("debug", QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); + Syntax setTiming = Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete")); + setTiming.children << Syntax("on", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(true); return true; }); + setTiming.children << Syntax("off", QString(), [](const QStringList &, State &state) -> bool { state.setCommandTiming(false); return true; }); set.children << setTiming; syntax << set; - Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); - get.children << Syntax(QObject::tr("debug"), QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); - get.children << Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); + Syntax get("get", QObject::tr("Gets settings for the session")); + get.children << Syntax("debug", QObject::tr("The current debug level from 0 to 6"), &CoreSyntax::printDebugLevel); + get.children << Syntax("timing", QObject::tr("Whether or not to print the time commands take to complete"), &CoreSyntax::printCommandTiming); syntax << get; return syntax; -- cgit v1.2.3 From c1eb4d6f95962c36e5e3994a0e6578cbff03cf49 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 11:32:51 +0100 Subject: clear command --- akonadish/syntax_modules/akonadi_clear.cpp | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_clear.cpp (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_clear.cpp b/akonadish/syntax_modules/akonadi_clear.cpp new file mode 100644 index 0000000..d17fac2 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_clear.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include // tr() +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace AkonadiClear +{ + +bool clear(const QStringList &args, State &state) +{ + for (const auto &resource : args) { + state.print(QObject::tr("Removing local cache for '%1' ...").arg(resource)); + Akonadi2::Store::removeFromDisk(resource.toLatin1()); + state.printLine(QObject::tr("done")); + } + + return true; +} + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &AkonadiClear::clear); + + return syntax; +} + +REGISTER_SYNTAX(AkonadiClear) + +} -- cgit v1.2.3 From 02ebb2bd3c9a5d4fe224c239b2ea10e7db12ebc6 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 18:27:55 +0100 Subject: create resource --- akonadish/syntax_modules/akonadi_create.cpp | 107 ++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_create.cpp (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_create.cpp b/akonadish/syntax_modules/akonadi_create.cpp new file mode 100644 index 0000000..025cd58 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_create.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include // tr() +#include +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace AkonadiCreate +{ + + /* +{ + auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); + auto &store = getStore(type); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; + if (type == "resource") { + auto resourceType = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); + object = store.getObject(""); + object->setProperty("type", resourceType); + } else { + auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); + object = store.getObject(resource); + } + auto map = consumeMap(args); + 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()) { + std::cout << "An error occurred while creating the entity: " << result.errorMessage().toStdString(); + } +} +*/ +bool resource(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A resource can not be created without a type"), "akonadicreate/01"); + } + + auto &store = AkonadishUtils::getStore("resource"); + + auto resourceType = args.at(0); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(""); + object->setProperty("type", resourceType); + + auto map = AkonadishUtils::keyValueMapFromArgs(args); + 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()), + "akonaid_create_" + QString::number(result.errorCode())); + } + + return true; +} + + +Syntax::List syntax() +{ + Syntax::List syntax; + + Syntax create("create");//, QString(), &AkonadiCreate::resource, Syntax::EventDriven); + create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource);//, Syntax::EventDriven); + + syntax << create; + return syntax; +} + +REGISTER_SYNTAX(AkonadiCreate) + +} -- cgit v1.2.3 From 045c47b877cd6b996eb17b91963d5e25b6707a53 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 19:44:49 +0100 Subject: error out when nothing useful is provided would be nicer to autocomplete? --- akonadish/syntax_modules/akonadi_list.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp index 25ccabf..807119c 100644 --- a/akonadish/syntax_modules/akonadi_list.cpp +++ b/akonadish/syntax_modules/akonadi_list.cpp @@ -41,6 +41,11 @@ namespace AkonadiList bool list(const QStringList &args, State &state) { + if (args.isEmpty()) { + state.printError(QObject::tr("Please provide at least one type to list (e.g. resource, ..")); + return false; + } + auto resources = args; auto type = !resources.isEmpty() ? resources.takeFirst() : QString(); -- cgit v1.2.3 From 5333d2560ecce9795382800fb84117da1a56d8c4 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 19:45:04 +0100 Subject: stat --- akonadish/syntax_modules/akonadi_stat.cpp | 113 ++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_stat.cpp (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_stat.cpp b/akonadish/syntax_modules/akonadi_stat.cpp new file mode 100644 index 0000000..149ccbd --- /dev/null +++ b/akonadish/syntax_modules/akonadi_stat.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include // tr() +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace AkonadiStat +{ + +void statResources(const QStringList &resources, const State &state) +{ + qint64 total = 0; + for (const auto &resource : resources) { + Akonadi2::Storage storage(Akonadi2::storageLocation(), resource, Akonadi2::Storage::ReadOnly); + auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); + + QList databases = transaction.getDatabaseNames(); + for (const auto &databaseName : databases) { + state.printLine(QObject::tr("Database: %1").arg(QString(databaseName)), 1); + auto db = transaction.openDatabase(databaseName); + qint64 size = db.getSize() / 1024; + state.printLine(QObject::tr("Size [kb]: %1").arg(size), 1); + total += size; + } + } + + state.printLine(QObject::tr("Total [kb]: %1").arg(total)); +} + +bool statAllResources(State &state) +{ + Akonadi2::Query query; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = false; + auto model = AkonadishUtils::loadModel("resource", query); + + //SUUUPER ugly, but can't think of a better way with 2 glasses of wine in me on Christmas day + static QStringList resources; + resources.clear(); + + QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) mutable { + for (int i = start; i <= end; i++) { + auto object = model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectBaseRole).value(); + resources << object->identifier(); + } + }); + + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + statResources(resources, state); + state.commandFinished(); + } + }); + + if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { + return true; + } + + return false; +} + +bool stat(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + return statAllResources(state); + } + + statResources(args, state); + return false; +} + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("stat", QObject::tr("Shows database usage for the resources requested"), &AkonadiStat::stat, Syntax::EventDriven); + + return syntax; +} + +REGISTER_SYNTAX(AkonadiStat) + +} -- cgit v1.2.3 From 55e5d310fb1cf1c85359bbb6f3d64120da9b226b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 19:51:34 +0100 Subject: remove resource --- akonadish/syntax_modules/akonadi_remove.cpp | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_remove.cpp (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp new file mode 100644 index 0000000..f58fa7d --- /dev/null +++ b/akonadish/syntax_modules/akonadi_remove.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include // tr() +#include +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace AkonadiRemove +{ + +bool resource(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A resource can not be removed without an id"), "akonadi_remove/01"); + } + + auto &store = AkonadishUtils::getStore("resource"); + + auto resourceId = args.at(0); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1()); + + auto map = AkonadishUtils::keyValueMapFromArgs(args); + for (auto i = map.begin(); i != map.end(); ++i) { + object->setProperty(i.key().toLatin1(), i.value()); + } + + auto result = store.remove(*object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while removing the resource %1: %2").arg(resourceId).arg(result.errorMessage()), + "akonaid_create_" + QString::number(result.errorCode())); + } + + return true; +} + + +Syntax::List syntax() +{ + Syntax::List syntax; + + Syntax create("remove"); + create.children << Syntax("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven); + + syntax << create; + return syntax; +} + +REGISTER_SYNTAX(AkonadiRemove) + +} -- cgit v1.2.3 From 8648ce60eda891404231d7e484de5c2a2a3efd35 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 19:55:25 +0100 Subject: unneeded --- akonadish/syntax_modules/akonadi_remove.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp index f58fa7d..01e4ead 100644 --- a/akonadish/syntax_modules/akonadi_remove.cpp +++ b/akonadish/syntax_modules/akonadi_remove.cpp @@ -50,11 +50,6 @@ bool resource(const QStringList &args, State &state) auto resourceId = args.at(0); Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1()); - auto map = AkonadishUtils::keyValueMapFromArgs(args); - for (auto i = map.begin(); i != map.end(); ++i) { - object->setProperty(i.key().toLatin1(), i.value()); - } - auto result = store.remove(*object).exec(); result.waitForFinished(); if (result.errorCode()) { -- cgit v1.2.3 From 7e548fbe071d3978a9659cedeb5fbbc183985bc3 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 20:03:49 +0100 Subject: crete other items --- akonadish/syntax_modules/akonadi_create.cpp | 45 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_create.cpp b/akonadish/syntax_modules/akonadi_create.cpp index 025cd58..377219a 100644 --- a/akonadish/syntax_modules/akonadi_create.cpp +++ b/akonadish/syntax_modules/akonadi_create.cpp @@ -39,34 +39,45 @@ namespace AkonadiCreate { - /* +bool create(const QStringList &allArgs, State &state) { - auto type = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); - auto &store = getStore(type); - Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; - if (type == "resource") { - auto resourceType = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); - object = store.getObject(""); - object->setProperty("type", resourceType); - } else { - auto resource = !args.isEmpty() ? args.takeFirst().toLatin1() : QByteArray(); - object = store.getObject(resource); + if (allArgs.isEmpty()) { + state.printError(QObject::tr("A type is required"), "akonadicreate/02"); + return false; + } + + if (allArgs.count() < 2) { + state.printError(QObject::tr("A resource ID is required to create items"), "akonadicreate/03"); + return false; } - auto map = consumeMap(args); + + auto args = allArgs; + auto type = args.takeFirst(); + auto &store = AkonadishUtils::getStore(type); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object; + auto resource = args.takeFirst().toLatin1(); + object = store.getObject(resource); + + auto map = AkonadishUtils::keyValueMapFromArgs(args); 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()) { - std::cout << "An error occurred while creating the entity: " << result.errorMessage().toStdString(); + state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), + "akonaid_create_e" + QString::number(result.errorCode())); } + + return true; } -*/ + bool resource(const QStringList &args, State &state) { if (args.isEmpty()) { state.printError(QObject::tr("A resource can not be created without a type"), "akonadicreate/01"); + return false; } auto &store = AkonadishUtils::getStore("resource"); @@ -84,7 +95,7 @@ bool resource(const QStringList &args, State &state) result.waitForFinished(); if (result.errorCode()) { state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), - "akonaid_create_" + QString::number(result.errorCode())); + "akonaid_create_e" + QString::number(result.errorCode())); } return true; @@ -95,8 +106,8 @@ Syntax::List syntax() { Syntax::List syntax; - Syntax create("create");//, QString(), &AkonadiCreate::resource, Syntax::EventDriven); - create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource);//, Syntax::EventDriven); + Syntax create("create", QObject::tr("Create items in a resource"), &AkonadiCreate::create); + create.children << Syntax("resource", QObject::tr("Creates a new resource"), &AkonadiCreate::resource); syntax << create; return syntax; -- cgit v1.2.3 From 47f175743ada27a031c9496a2bd1890c74464b27 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 20:11:02 +0100 Subject: remove non-resources --- akonadish/syntax_modules/akonadi_remove.cpp | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp index 01e4ead..5e11af3 100644 --- a/akonadish/syntax_modules/akonadi_remove.cpp +++ b/akonadish/syntax_modules/akonadi_remove.cpp @@ -39,6 +39,40 @@ namespace AkonadiRemove { +bool remove(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A type is required"), "akonadicreate/02"); + return false; + } + + if (args.count() < 2) { + state.printError(QObject::tr("A resource ID is required to remove items"), "akonadicreate/03"); + return false; + } + + if (args.count() < 3) { + state.printError(QObject::tr("An object ID is required to remove items"), "akonadicreate/03"); + return false; + } + + auto type = args[0]; + auto resourceId = args[1]; + auto identifier = args[2]; + + auto &store = AkonadishUtils::getStore(type); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(resourceId.toUtf8(), identifier.toUtf8()); + + auto result = store.remove(*object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while removing %1 from %1: %2").arg(identifier).arg(resourceId).arg(result.errorMessage()), + "akonaid_create_" + QString::number(result.errorCode())); + } + + return true; +} + bool resource(const QStringList &args, State &state) { if (args.isEmpty()) { -- cgit v1.2.3 From 2a88528b15312e011a6acc0e92ecbd4766103a23 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 22:45:23 +0100 Subject: cleanup --- akonadish/syntax_modules/akonadi_remove.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp index 5e11af3..bf09e2e 100644 --- a/akonadish/syntax_modules/akonadi_remove.cpp +++ b/akonadish/syntax_modules/akonadi_remove.cpp @@ -42,17 +42,17 @@ namespace AkonadiRemove bool remove(const QStringList &args, State &state) { if (args.isEmpty()) { - state.printError(QObject::tr("A type is required"), "akonadicreate/02"); + state.printError(QObject::tr("A type is required"), "akonadi_remove/02"); return false; } if (args.count() < 2) { - state.printError(QObject::tr("A resource ID is required to remove items"), "akonadicreate/03"); + state.printError(QObject::tr("A resource ID is required to remove items"), "akonadi_remove/03"); return false; } if (args.count() < 3) { - state.printError(QObject::tr("An object ID is required to remove items"), "akonadicreate/03"); + state.printError(QObject::tr("An object ID is required to remove items"), "akonadi_remove/03"); return false; } @@ -67,7 +67,7 @@ bool remove(const QStringList &args, State &state) result.waitForFinished(); if (result.errorCode()) { state.printError(QObject::tr("An error occurred while removing %1 from %1: %2").arg(identifier).arg(resourceId).arg(result.errorMessage()), - "akonaid_create_" + QString::number(result.errorCode())); + "akonaid_remove_e" + QString::number(result.errorCode())); } return true; @@ -88,7 +88,7 @@ bool resource(const QStringList &args, State &state) result.waitForFinished(); if (result.errorCode()) { state.printError(QObject::tr("An error occurred while removing the resource %1: %2").arg(resourceId).arg(result.errorMessage()), - "akonaid_create_" + QString::number(result.errorCode())); + "akonaid_remove_e" + QString::number(result.errorCode())); } return true; @@ -99,10 +99,10 @@ Syntax::List syntax() { Syntax::List syntax; - Syntax create("remove"); - create.children << Syntax("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven); + Syntax remove("remove", QObject::tr("Remove items in a resource"), &AkonadiRemove::remove); + remove.children << Syntax("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven); - syntax << create; + syntax << remove; return syntax; } -- cgit v1.2.3 From c8fda874bb4625217b6f5cb70228d891c2a419bb Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 22:46:48 +0100 Subject: modify --- akonadish/syntax_modules/akonadi_modify.cpp | 121 ++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_modify.cpp (limited to 'akonadish/syntax_modules') diff --git a/akonadish/syntax_modules/akonadi_modify.cpp b/akonadish/syntax_modules/akonadi_modify.cpp new file mode 100644 index 0000000..8438301 --- /dev/null +++ b/akonadish/syntax_modules/akonadi_modify.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include // tr() +#include +#include + +#include "common/resource.h" +#include "common/storage.h" +#include "common/domain/event.h" +#include "common/domain/folder.h" +#include "common/resourceconfig.h" +#include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" + +#include "akonadish_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace AkonadiModify +{ + +bool modify(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A type is required"), "akonadi_modify/02"); + return false; + } + + if (args.count() < 2) { + state.printError(QObject::tr("A resource ID is required to remove items"), "akonadi_modify/03"); + return false; + } + + if (args.count() < 3) { + state.printError(QObject::tr("An object ID is required to remove items"), "akonadi_modify/03"); + return false; + } + + auto type = args[0]; + auto resourceId = args[1]; + auto identifier = args[2]; + + auto &store = AkonadishUtils::getStore(type); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(resourceId.toUtf8(), identifier.toUtf8()); + + auto map = AkonadishUtils::keyValueMapFromArgs(args); + for (auto i = map.begin(); i != map.end(); ++i) { + object->setProperty(i.key().toLatin1(), i.value()); + } + + auto result = store.modify(*object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while removing %1 from %1: %2").arg(identifier).arg(resourceId).arg(result.errorMessage()), + "akonaid__modify_e" + QString::number(result.errorCode())); + } + + return true; +} + +bool resource(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A resource can not be modified without an id"), "akonadi_modify/01"); + } + + auto &store = AkonadishUtils::getStore("resource"); + + auto resourceId = args.at(0); + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1()); + + auto map = AkonadishUtils::keyValueMapFromArgs(args); + for (auto i = map.begin(); i != map.end(); ++i) { + object->setProperty(i.key().toLatin1(), i.value()); + } + + auto result = store.modify(*object).exec(); + result.waitForFinished(); + if (result.errorCode()) { + state.printError(QObject::tr("An error occurred while modifying the resource %1: %2").arg(resourceId).arg(result.errorMessage()), + "akonaid_modify_e" + QString::number(result.errorCode())); + } + + return true; +} + + +Syntax::List syntax() +{ + Syntax::List syntax; + + Syntax modify("modify", QObject::tr("Modify items in a resource"), &AkonadiModify::modify); + modify.children << Syntax("resource", QObject::tr("Modify a resource"), &AkonadiModify::resource);//, Syntax::EventDriven); + + syntax << modify; + return syntax; +} + +REGISTER_SYNTAX(AkonadiModify) + +} -- cgit v1.2.3