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/CMakeLists.txt | 1 + akonadish/syntax_modules/akonadi_sync.cpp | 67 +++++++++++++++++++++++++++++++ akonadish/syntax_modules/akonadi_sync.h | 29 +++++++++++++ akonadish/syntaxtree.cpp | 2 + 4 files changed, 99 insertions(+) create mode 100644 akonadish/syntax_modules/akonadi_sync.cpp create mode 100644 akonadish/syntax_modules/akonadi_sync.h (limited to 'akonadish') diff --git a/akonadish/CMakeLists.txt b/akonadish/CMakeLists.txt index 9d0e7a5..39a059f 100644 --- a/akonadish/CMakeLists.txt +++ b/akonadish/CMakeLists.txt @@ -9,6 +9,7 @@ set(akonadi2_cli_SRCS syntax_modules/core_syntax.cpp syntax_modules/akonadi_list.cpp syntax_modules/akonadi_count.cpp + syntax_modules/akonadi_sync.cpp akonadish_utils.cpp repl/repl.cpp repl/replStates.cpp 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); +} + diff --git a/akonadish/syntaxtree.cpp b/akonadish/syntaxtree.cpp index 0cd3e3f..2d7c127 100644 --- a/akonadish/syntaxtree.cpp +++ b/akonadish/syntaxtree.cpp @@ -27,6 +27,7 @@ #include "syntax_modules/core_syntax.h" #include "syntax_modules/akonadi_list.h" #include "syntax_modules/akonadi_count.h" +#include "syntax_modules/akonadi_sync.h" SyntaxTree *SyntaxTree::s_module = 0; @@ -48,6 +49,7 @@ SyntaxTree::SyntaxTree() syntaxSyntaxTrees << &CoreSyntax::syntax << &AkonadiList::syntax << &AkonadiCount::syntax + << &AkonadiSync::syntax ; for (auto syntaxSyntaxTree: syntaxSyntaxTrees) { m_syntax += syntaxSyntaxTree(); -- cgit v1.2.3