[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [akonadi-next/feature/new_cli] akonadi2_cli: add count command
From: Aaron Seigo <aseigo () kde ! org>
Date: 2015-12-23 22:14:50
Message-ID: E1aBrgI-00053N-77 () scm ! kde ! org
[Download RAW message or body]
Git commit a638c410ad83f8d8fe236c1500beaf63d69cbac6 by Aaron Seigo.
Committed on 23/12/2015 at 22:10.
Pushed by aseigo into branch 'feature/new_cli'.
add count command
M +2 -1 akonadi2_cli/CMakeLists.txt
A +79 -0 akonadi2_cli/syntax_modules/akonadi_count.cpp [License: GPL (v2+)]
A +29 -0 akonadi2_cli/syntax_modules/akonadi_count.h [License: GPL (v2+)]
M +2 -0 akonadi2_cli/syntaxtree.cpp
http://commits.kde.org/akonadi-next/a638c410ad83f8d8fe236c1500beaf63d69cbac6
diff --git a/akonadi2_cli/CMakeLists.txt b/akonadi2_cli/CMakeLists.txt
index 669ad52..9d0e7a5 100644
--- a/akonadi2_cli/CMakeLists.txt
+++ b/akonadi2_cli/CMakeLists.txt
@@ -1,4 +1,4 @@
-project(akonadi2_cli)
+project(akonadish)
find_package(Readline REQUIRED)
@@ -8,6 +8,7 @@ set(akonadi2_cli_SRCS
syntaxtree.cpp
syntax_modules/core_syntax.cpp
syntax_modules/akonadi_list.cpp
+ syntax_modules/akonadi_count.cpp
akonadish_utils.cpp
repl/repl.cpp
repl/replStates.cpp
diff --git a/akonadi2_cli/syntax_modules/akonadi_count.cpp \
b/akonadi2_cli/syntax_modules/akonadi_count.cpp new file mode 100644
index 0000000..40ad693
--- /dev/null
+++ b/akonadi2_cli/syntax_modules/akonadi_count.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * 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 <QCoreApplication>
+#include <QDebug>
+#include <QObject> // tr()
+#include <QModelIndex>
+#include <QTime>
+
+#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 <type> <resource>"), &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<int> &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/akonadi2_cli/syntax_modules/akonadi_count.h \
b/akonadi2_cli/syntax_modules/akonadi_count.h new file mode 100644
index 0000000..c592c4c
--- /dev/null
+++ b/akonadi2_cli/syntax_modules/akonadi_count.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * 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/akonadi2_cli/syntaxtree.cpp b/akonadi2_cli/syntaxtree.cpp
index cebfc4b..0cd3e3f 100644
--- a/akonadi2_cli/syntaxtree.cpp
+++ b/akonadi2_cli/syntaxtree.cpp
@@ -26,6 +26,7 @@
// almost certainly overkill, but this is not the way either
#include "syntax_modules/core_syntax.h"
#include "syntax_modules/akonadi_list.h"
+#include "syntax_modules/akonadi_count.h"
SyntaxTree *SyntaxTree::s_module = 0;
@@ -46,6 +47,7 @@ SyntaxTree::SyntaxTree()
QVector<std::function<Syntax::List()> > syntaxSyntaxTrees;
syntaxSyntaxTrees << &CoreSyntax::syntax
<< &AkonadiList::syntax
+ << &AkonadiCount::syntax
;
for (auto syntaxSyntaxTree: syntaxSyntaxTrees) {
m_syntax += syntaxSyntaxTree();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic