From bdb01c2c068df326f5a8328ed1492ab1bea388c5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 20 Jan 2016 19:07:07 +0100 Subject: Renamed Akonadi2 to Sink (except for documentation). --- CMakeLists.txt | 4 +- akonadish/CMakeLists.txt | 29 --- akonadish/TODO | 11 - akonadish/akonadish_utils.cpp | 134 ------------- akonadish/akonadish_utils.h | 88 -------- akonadish/main.cpp | 115 ----------- akonadish/repl/repl.cpp | 91 --------- akonadish/repl/repl.h | 35 ---- akonadish/repl/replStates.cpp | 171 ---------------- akonadish/repl/replStates.h | 87 -------- akonadish/state.cpp | 144 -------------- akonadish/state.h | 52 ----- akonadish/syntax_modules/akonadi_clear.cpp | 61 ------ akonadish/syntax_modules/akonadi_count.cpp | 83 -------- akonadish/syntax_modules/akonadi_create.cpp | 118 ----------- akonadish/syntax_modules/akonadi_list.cpp | 114 ----------- akonadish/syntax_modules/akonadi_modify.cpp | 120 ----------- akonadish/syntax_modules/akonadi_remove.cpp | 110 ---------- akonadish/syntax_modules/akonadi_stat.cpp | 120 ----------- akonadish/syntax_modules/akonadi_sync.cpp | 67 ------- akonadish/syntax_modules/core_syntax.cpp | 204 ------------------- akonadish/syntaxtree.cpp | 221 --------------------- akonadish/syntaxtree.h | 80 -------- akonadish/utils.cpp | 42 ---- akonadish/utils.h | 30 --- common/Akonadi2CommonConfig.cmake.in | 5 - common/CMakeLists.txt | 24 +-- common/SinkCommonConfig.cmake.in | 5 + common/bufferadaptor.h | 2 +- common/bufferutils.h | 2 +- common/clientapi.cpp | 48 ++--- common/clientapi.h | 10 +- common/commands.cpp | 4 +- common/commands.h | 14 +- common/commands/commandcompletion.fbs | 2 +- common/commands/createentity.fbs | 2 +- common/commands/deleteentity.fbs | 2 +- common/commands/fetchentity.fbs | 2 +- common/commands/handshake.fbs | 2 +- common/commands/inspection.fbs | 2 +- common/commands/modifyentity.fbs | 2 +- common/commands/notification.fbs | 2 +- common/commands/revisionreplayed.fbs | 2 +- common/commands/revisionupdate.fbs | 2 +- common/commands/synchronize.fbs | 2 +- common/definitions.cpp | 6 +- common/definitions.h | 2 +- common/domain/applicationdomaintype.cpp | 6 +- common/domain/applicationdomaintype.h | 36 ++-- common/domain/dummy.fbs | 2 +- common/domain/event.cpp | 8 +- common/domain/event.fbs | 2 +- common/domain/event.h | 14 +- common/domain/folder.cpp | 8 +- common/domain/folder.fbs | 2 +- common/domain/folder.h | 14 +- common/domain/mail.cpp | 8 +- common/domain/mail.fbs | 2 +- common/domain/mail.h | 14 +- common/domainadaptor.h | 28 +-- common/domaintypeadaptorfactoryinterface.h | 6 +- common/entity.fbs | 2 +- common/entitybuffer.cpp | 16 +- common/entitybuffer.h | 2 +- common/facade.cpp | 26 +-- common/facade.h | 10 +- common/facadefactory.cpp | 6 +- common/facadefactory.h | 2 +- common/facadeinterface.h | 8 +- common/genericresource.cpp | 174 ++++++++-------- common/genericresource.h | 28 +-- common/index.cpp | 12 +- common/index.h | 8 +- common/indexupdater.h | 28 +-- common/inspection.h | 6 +- common/listener.cpp | 80 ++++---- common/listener.h | 8 +- common/listmodelresult.h | 6 +- common/log.cpp | 18 +- common/log.h | 10 +- common/messagequeue.cpp | 24 +-- common/messagequeue.h | 4 +- common/metadata.fbs | 2 +- common/modelresult.cpp | 18 +- common/modelresult.h | 8 +- common/notification.h | 6 +- common/pipeline.cpp | 114 +++++------ common/pipeline.h | 16 +- common/query.h | 6 +- common/queryrunner.cpp | 132 ++++++------ common/queryrunner.h | 8 +- common/queuedcommand.fbs | 2 +- common/resource.cpp | 8 +- common/resource.h | 10 +- common/resourceaccess.cpp | 56 +++--- common/resourceaccess.h | 2 +- common/resourceconfig.cpp | 4 +- common/resourcefacade.cpp | 22 +- common/resourcefacade.h | 12 +- common/resultprovider.h | 2 +- common/resultset.h | 6 +- common/storage.h | 24 +-- common/storage_common.cpp | 26 +-- common/storage_lmdb.cpp | 4 +- common/synclistresult.h | 4 +- common/typeindex.cpp | 12 +- common/typeindex.h | 8 +- examples/client/CMakeLists.txt | 4 +- examples/client/main.cpp | 66 +++--- examples/dummyresource/CMakeLists.txt | 6 +- examples/dummyresource/domainadaptor.h | 6 +- examples/dummyresource/facade.cpp | 6 +- examples/dummyresource/facade.h | 6 +- examples/dummyresource/resourcefactory.cpp | 56 +++--- examples/dummyresource/resourcefactory.h | 24 +-- examples/maildirresource/CMakeLists.txt | 6 +- examples/maildirresource/domainadaptor.h | 4 +- examples/maildirresource/facade.cpp | 4 +- examples/maildirresource/facade.h | 4 +- examples/maildirresource/libmaildir/maildir.cpp | 16 +- examples/maildirresource/libmaildir/maildir.h | 2 +- examples/maildirresource/maildirresource.cpp | 90 ++++----- examples/maildirresource/maildirresource.h | 20 +- sinksh/CMakeLists.txt | 29 +++ sinksh/TODO | 11 + sinksh/main.cpp | 115 +++++++++++ sinksh/repl/repl.cpp | 91 +++++++++ sinksh/repl/repl.h | 35 ++++ sinksh/repl/replStates.cpp | 171 ++++++++++++++++ sinksh/repl/replStates.h | 87 ++++++++ sinksh/sinksh_utils.cpp | 134 +++++++++++++ sinksh/sinksh_utils.h | 88 ++++++++ sinksh/state.cpp | 144 ++++++++++++++ sinksh/state.h | 52 +++++ sinksh/syntax_modules/core_syntax.cpp | 204 +++++++++++++++++++ sinksh/syntax_modules/sink_clear.cpp | 61 ++++++ sinksh/syntax_modules/sink_count.cpp | 83 ++++++++ sinksh/syntax_modules/sink_create.cpp | 118 +++++++++++ sinksh/syntax_modules/sink_list.cpp | 114 +++++++++++ sinksh/syntax_modules/sink_modify.cpp | 120 +++++++++++ sinksh/syntax_modules/sink_remove.cpp | 110 ++++++++++ sinksh/syntax_modules/sink_stat.cpp | 120 +++++++++++ sinksh/syntax_modules/sink_sync.cpp | 67 +++++++ sinksh/syntaxtree.cpp | 221 +++++++++++++++++++++ sinksh/syntaxtree.h | 80 ++++++++ sinksh/utils.cpp | 42 ++++ sinksh/utils.h | 30 +++ synchronizer/CMakeLists.txt | 8 +- tests/CMakeLists.txt | 18 +- tests/clientapitest.cpp | 118 +++++------ .../databasepopulationandfacadequerybenchmark.cpp | 22 +- tests/domainadaptortest.cpp | 26 +-- tests/dummyresourcebenchmark.cpp | 44 ++-- tests/dummyresourcetest.cpp | 124 ++++++------ tests/dummyresourcewritebenchmark.cpp | 24 +-- tests/genericfacadetest.cpp | 38 ++-- tests/genericresourcebenchmark.cpp | 46 ++--- tests/genericresourcetest.cpp | 28 +-- tests/hawd/CMakeLists.txt | 2 +- tests/hawd/dataset.cpp | 8 +- tests/hawd/dataset.h | 4 +- tests/indextest.cpp | 6 +- tests/inspectiontest.cpp | 14 +- tests/maildirresourcetest.cpp | 138 ++++++------- tests/messagequeuetest.cpp | 24 +-- tests/modelinteractivitytest.cpp | 18 +- tests/pipelinetest.cpp | 90 ++++----- tests/querytest.cpp | 136 ++++++------- tests/resourcecommunicationtest.cpp | 20 +- tests/storagebenchmark.cpp | 22 +- tests/storagetest.cpp | 120 +++++------ tests/testimplementations.h | 16 +- 172 files changed, 3688 insertions(+), 3688 deletions(-) delete mode 100644 akonadish/CMakeLists.txt delete mode 100644 akonadish/TODO delete mode 100644 akonadish/akonadish_utils.cpp delete mode 100644 akonadish/akonadish_utils.h delete mode 100644 akonadish/main.cpp delete mode 100644 akonadish/repl/repl.cpp delete mode 100644 akonadish/repl/repl.h delete mode 100644 akonadish/repl/replStates.cpp delete mode 100644 akonadish/repl/replStates.h delete mode 100644 akonadish/state.cpp delete mode 100644 akonadish/state.h delete mode 100644 akonadish/syntax_modules/akonadi_clear.cpp delete mode 100644 akonadish/syntax_modules/akonadi_count.cpp delete mode 100644 akonadish/syntax_modules/akonadi_create.cpp delete mode 100644 akonadish/syntax_modules/akonadi_list.cpp delete mode 100644 akonadish/syntax_modules/akonadi_modify.cpp delete mode 100644 akonadish/syntax_modules/akonadi_remove.cpp delete mode 100644 akonadish/syntax_modules/akonadi_stat.cpp delete mode 100644 akonadish/syntax_modules/akonadi_sync.cpp delete mode 100644 akonadish/syntax_modules/core_syntax.cpp delete mode 100644 akonadish/syntaxtree.cpp delete mode 100644 akonadish/syntaxtree.h delete mode 100644 akonadish/utils.cpp delete mode 100644 akonadish/utils.h delete mode 100644 common/Akonadi2CommonConfig.cmake.in create mode 100644 common/SinkCommonConfig.cmake.in create mode 100644 sinksh/CMakeLists.txt create mode 100644 sinksh/TODO create mode 100644 sinksh/main.cpp create mode 100644 sinksh/repl/repl.cpp create mode 100644 sinksh/repl/repl.h create mode 100644 sinksh/repl/replStates.cpp create mode 100644 sinksh/repl/replStates.h create mode 100644 sinksh/sinksh_utils.cpp create mode 100644 sinksh/sinksh_utils.h create mode 100644 sinksh/state.cpp create mode 100644 sinksh/state.h create mode 100644 sinksh/syntax_modules/core_syntax.cpp create mode 100644 sinksh/syntax_modules/sink_clear.cpp create mode 100644 sinksh/syntax_modules/sink_count.cpp create mode 100644 sinksh/syntax_modules/sink_create.cpp create mode 100644 sinksh/syntax_modules/sink_list.cpp create mode 100644 sinksh/syntax_modules/sink_modify.cpp create mode 100644 sinksh/syntax_modules/sink_remove.cpp create mode 100644 sinksh/syntax_modules/sink_stat.cpp create mode 100644 sinksh/syntax_modules/sink_sync.cpp create mode 100644 sinksh/syntaxtree.cpp create mode 100644 sinksh/syntaxtree.h create mode 100644 sinksh/utils.cpp create mode 100644 sinksh/utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cbba78..6fa2c09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ configure_file(hawd.conf hawd.conf) enable_testing() -set(AKONADI2_RESOURCE_PLUGINS_PATH ${QT_PLUGIN_INSTALL_DIR}/akonadi2/resources) +set(SINK_RESOURCE_PLUGINS_PATH ${QT_PLUGIN_INSTALL_DIR}/sink/resources) # common, eventually a lib but right now just the command buffers add_subdirectory(common) @@ -65,6 +65,6 @@ add_subdirectory(examples) add_subdirectory(tests) # cli -add_subdirectory(akonadish) +add_subdirectory(sinksh) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/akonadish/CMakeLists.txt b/akonadish/CMakeLists.txt deleted file mode 100644 index eaedf9a..0000000 --- a/akonadish/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -project(akonadish) - -find_package(Readline REQUIRED) - - -set(akonadi2_cli_SRCS - main.cpp - syntaxtree.cpp - syntax_modules/core_syntax.cpp - syntax_modules/akonadi_list.cpp - syntax_modules/akonadi_clear.cpp - syntax_modules/akonadi_count.cpp - syntax_modules/akonadi_create.cpp - syntax_modules/akonadi_modify.cpp - syntax_modules/akonadi_remove.cpp - syntax_modules/akonadi_stat.cpp - syntax_modules/akonadi_sync.cpp - akonadish_utils.cpp - repl/repl.cpp - repl/replStates.cpp - state.cpp - utils.cpp) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) - -add_executable(${PROJECT_NAME} ${akonadi2_cli_SRCS}) -target_link_libraries(${PROJECT_NAME} Qt5::Core ${Readline_LIBRARY} akonadi2common) -install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) - diff --git a/akonadish/TODO b/akonadish/TODO deleted file mode 100644 index 93c4ff1..0000000 --- a/akonadish/TODO +++ /dev/null @@ -1,11 +0,0 @@ -* commands - * improve modify/remove/create to dynamically add syntax items for each type - * improve modify/remove/create to autocomplete resource names -* provide a setting to turn on/off user interaction during commands (e.g. deletion confirmations) - * add a "ask the user a question" helper in State - * confirm deletions in remove -* handle env vars and similar for scripting purposes -* key/value syntax objects -* json objects! (set json on; ...) -* make the shell generic and have it load a plugin matching the name of argv[0] for syntax - diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp deleted file mode 100644 index 27a863d..0000000 --- a/akonadish/akonadish_utils.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2015 Aaron Seigo - * Copyright (C) 2015 Christian Mollekopf - * - * 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 "akonadish_utils.h" - -#include "common/clientapi.h" - -#include "utils.h" - -namespace AkonadishUtils -{ - -static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event"; - -bool isValidStoreType(const QString &type) -{ - return s_types.contains(type); -} - -StoreBase &getStore(const QString &type) -{ - if (type == "folder") { - static Store store; - return store; - } else if (type == "mail") { - static Store store; - return store; - } else if (type == "event") { - static Store store; - return store; - } else if (type == "resource") { - static Store store; - return store; - } - - //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; -} - -QSharedPointer loadModel(const QString &type, Akonadi2::Query query) -{ - if (type == "folder") { - query.requestedProperties << "name" << "parent"; - } else if (type == "mail") { - query.requestedProperties << "subject" << "folder" << "date"; - } else if (type == "event") { - query.requestedProperties << "summary"; - } else if (type == "resource") { - query.requestedProperties << "type"; - } - auto model = getStore(type).loadModel(query); - Q_ASSERT(model); - return model; -} - -QStringList resourceIds(State &state) -{ - QStringList resources; - Akonadi2::Query query; - query.liveQuery = false; - auto model = AkonadishUtils::loadModel("resource", query); - - 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), 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)) { - state.commandFinished(); - } - }); - - state.commandStarted(); - - return resources; -} - -QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) -{ - return Utils::filteredCompletions(resourceIds(state), fragment); -} - -QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) -{ - static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event"; - if (commands.count() == 1) { - return Utils::filteredCompletions(s_types, fragment); - } - - return Utils::filteredCompletions(resourceIds(state), fragment); -} - -QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) -{ - return Utils::filteredCompletions(s_types, fragment); -} - -QMap keyValueMapFromArgs(const QStringList &args) -{ - //TODO: this is not the most clever of algorithms. preserved during the port of commands - // from akonadi2_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; -} - -} - diff --git a/akonadish/akonadish_utils.h b/akonadish/akonadish_utils.h deleted file mode 100644 index 5dd24f1..0000000 --- a/akonadish/akonadish_utils.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2015 Aaron Seigo - * Copyright (C) 2015 Christian Mollekopf - * - * 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 -#include - -#include "common/query.h" -#include "common/clientapi.h" - -#include "state.h" - -namespace AkonadishUtils -{ - -class StoreBase; - -bool isValidStoreType(const QString &type); -StoreBase &getStore(const QString &type); -QSharedPointer loadModel(const QString &type, Akonadi2::Query query); -QStringList resourceIds(); -QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); -QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); -QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); -QMap keyValueMapFromArgs(const QStringList &args); - -/** - * A small abstraction layer to use the akonadi store with the type available as string. - */ -class StoreBase { -public: - virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; - virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; - virtual KAsync::Job create(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job modify(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job remove(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual QSharedPointer loadModel(const Akonadi2::Query &query) = 0; -}; - -template -class Store : public StoreBase { -public: - Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { - return T::Ptr::create(); - } - - Akonadi2::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 Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::Store::create(*static_cast(&type)); - } - - KAsync::Job modify(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::Store::modify(*static_cast(&type)); - } - - KAsync::Job remove(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::Store::remove(*static_cast(&type)); - } - - QSharedPointer loadModel(const Akonadi2::Query &query) Q_DECL_OVERRIDE { - return Akonadi2::Store::loadModel(query); - } -}; - - -} - diff --git a/akonadish/main.cpp b/akonadish/main.cpp deleted file mode 100644 index 4c00b9b..0000000 --- a/akonadish/main.cpp +++ /dev/null @@ -1,115 +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. - */ - -#include - -#include -#include -#include -#include - -#include "syntaxtree.h" -// #include "jsonlistener.h" -#include "repl/repl.h" - -/* - * modes of operation: - * - * 1. called with no commands: start the REPL - * 2. called with -: listen for commands on stdin - * 3. called with a filename: try to run it as a script - * 4. called with commands: try to match to syntax and run the result - */ - -int enterRepl() -{ - if (State::hasEventLoop()) { - return 0; - } - - Repl *repl = new Repl; - 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(); - State::setHasEventLoop(false); - return rv; -} - -bool goInteractive(const QStringList &, State &) -{ - enterRepl(); - return true; -} - -Syntax::List goInteractiveSyntax() -{ - Syntax interactive("go_interactive", QString(), &goInteractive); - return Syntax::List() << interactive; -} - -void processCommandStream(QTextStream &stream) -{ - SyntaxTree::self()->registerSyntax(&goInteractiveSyntax); - QString line = stream.readLine(); - while (!line.isEmpty()) { - line = line.trimmed(); - - if (!line.isEmpty() && !line.startsWith('#')) { - SyntaxTree::self()->run(SyntaxTree::tokenize(line)); - } - - line = stream.readLine(); - } -} - -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 - const bool fromScript = !startRepl && QFile::exists(argv[1]); - - //qDebug() << "state at startup is" << interactive << startRepl << fromScript; - - QCoreApplication app(argc, argv); - app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); - - if (startRepl) { - return enterRepl(); - } else if (fromScript) { - QFile f(argv[1]); - if (!f.open(QIODevice::ReadOnly)) { - return 1; - } - - QTextStream inputStream(&f); - processCommandStream(inputStream); - } else if (!interactive) { - QTextStream inputStream(stdin); - processCommandStream(inputStream); - } else { - QStringList commands = app.arguments(); - commands.removeFirst(); - return SyntaxTree::self()->run(commands); - } -} diff --git a/akonadish/repl/repl.cpp b/akonadish/repl/repl.cpp deleted file mode 100644 index 499a4af..0000000 --- a/akonadish/repl/repl.cpp +++ /dev/null @@ -1,91 +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. - */ - -#include "repl.h" - -#include - -#include -#include -#include -#include -#include - -#include "replStates.h" -#include "syntaxtree.h" - -Repl::Repl(QObject *parent) - : QStateMachine(parent) -{ - // readline history setup - using_history(); - read_history(commandHistoryPath().toLocal8Bit()); - - // create all states - ReadState *read = new ReadState(this); - UnfinishedReadState *unfinishedRead = new UnfinishedReadState(this); - EvalState *eval = new EvalState(this); - PrintState *print = new PrintState(this); - QFinalState *final = new QFinalState(this); - - // connect the transitions - read->addTransition(read, SIGNAL(command(QString)), eval); - read->addTransition(read, SIGNAL(exitRequested()), final); - - unfinishedRead->addTransition(unfinishedRead, SIGNAL(command(QString)), eval); - unfinishedRead->addTransition(unfinishedRead, SIGNAL(exitRequested()), final); - - eval->addTransition(eval, SIGNAL(completed()), read); - eval->addTransition(eval, SIGNAL(continueInput()), unfinishedRead); - eval->addTransition(eval, SIGNAL(output(QString)), print); - - print->addTransition(print, SIGNAL(completed()), eval); - - setInitialState(read); - printWelcomeBanner(); - start(); -} - -Repl::~Repl() -{ - // readline history writing - write_history(commandHistoryPath().toLocal8Bit()); -} - -void Repl::printWelcomeBanner() -{ - QTextStream out(stdout); - out << QObject::tr("Welcome to the Akonadi2 interative shell!\n"); - out << QObject::tr("Type `help` for information on the available commands.\n"); - out.flush(); -} - -QString Repl::commandHistoryPath() -{ - const QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - - if (!QFile::exists(path)) { - QDir dir; - dir.mkpath(path); - } - - return path + "/repl_history"; -} - -#include "moc_repl.cpp" diff --git a/akonadish/repl/repl.h b/akonadish/repl/repl.h deleted file mode 100644 index d8d2533..0000000 --- a/akonadish/repl/repl.h +++ /dev/null @@ -1,35 +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 - -class Repl : public QStateMachine -{ - Q_OBJECT - -public: - Repl(QObject *parent = 0); - ~Repl(); - -private: - static void printWelcomeBanner(); - static QString commandHistoryPath(); -}; diff --git a/akonadish/repl/replStates.cpp b/akonadish/repl/replStates.cpp deleted file mode 100644 index 55fdf39..0000000 --- a/akonadish/repl/replStates.cpp +++ /dev/null @@ -1,171 +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. - */ - -#include "replStates.h" - -#include -#include - -#include -#include - -#include -#include -#include - -#include "syntaxtree.h" - -static char *akonadi2_cli_next_tab_complete_match(const char *text, int state); -static char ** akonadi2_cli_tab_completion(const char *text, int start, int end); - -ReadState::ReadState(QState *parent) - : QState(parent) -{ - rl_completion_entry_function = akonadi2_cli_next_tab_complete_match; - rl_attempted_completion_function = akonadi2_cli_tab_completion; -} - -void ReadState::onEntry(QEvent *event) -{ - Q_UNUSED(event) - char *line = readline(prompt()); - - if (!line) { - std::cout << std::endl; - emit exitRequested(); - return; - } - - // we have actual data, so let's wait for a full line of text - QByteArray input(line); - const QString text = QString(line).simplified(); - //qDebug() << "Line is ... " << text; - - if (text.length() > 0) { - add_history(line); - } - - free(line); - emit command(text); -} - -const char *ReadState::prompt() const -{ - return "> "; -} - -UnfinishedReadState::UnfinishedReadState(QState *parent) - : ReadState(parent) -{ -} - -const char *UnfinishedReadState::prompt() const -{ - return " "; -} - -EvalState::EvalState(QState *parent) - : QState(parent) -{ -} - -void EvalState::onEntry(QEvent *event) -{ - QStateMachine::SignalEvent *e = dynamic_cast(event); - - const QString command = e ? e->arguments()[0].toString() : QString(); - - if (command.isEmpty()) { - complete(); - return; - } - - if (command.right(1) == "\\") { - m_partial += " " + command.left(command.size() - 1); - continueInput(); - } else { - m_partial += " " + command; - complete(); - } -} - -void EvalState::complete() -{ - m_partial = m_partial.simplified(); - - if (!m_partial.isEmpty()) { - //emit output("Processing ... " + command); - const QStringList commands = SyntaxTree::tokenize(m_partial); - SyntaxTree::self()->run(commands); - m_partial.clear(); - } - - emit completed(); -} - -PrintState::PrintState(QState *parent) - : QState(parent) -{ -} - -void PrintState::onEntry(QEvent *event) -{ - QStateMachine::SignalEvent *e = dynamic_cast(event); - - if (e && !e->arguments().isEmpty()) { - const QString command = e->arguments()[0].toString(); - QTextStream stream(stdout); - stream << command << "\n"; - } - - emit completed(); -} - -static QStringList tab_completion_full_state; -static bool tab_completion_at_root = false; - -static char **akonadi2_cli_tab_completion(const char *text, int start, int end) -{ - tab_completion_at_root = start == 0; - tab_completion_full_state = QString(rl_line_buffer).remove(start, end - start).split(" ", QString::SkipEmptyParts); - return NULL; -} - -static char *akonadi2_cli_next_tab_complete_match(const char *text, int state) -{ - const QString fragment(text); - Syntax::List nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, fragment); - //for (auto syntax: nearest) { qDebug() << "Nearest: " << syntax.keyword; } - - if (nearest.isEmpty()) { - SyntaxTree::Command command = SyntaxTree::self()->match(tab_completion_full_state); - if (command.first && command.first->completer) { - QStringList commandCompletions = command.first->completer(tab_completion_full_state, fragment, SyntaxTree::self()->state()); - if (commandCompletions.size() > state) { - return qstrdup(commandCompletions[state].toUtf8()); - } - } - } else if (nearest.size() > state) { - return qstrdup(nearest[state].keyword.toUtf8()); - } - - return rl_filename_completion_function(text, state); -} - -#include "moc_replStates.cpp" diff --git a/akonadish/repl/replStates.h b/akonadish/repl/replStates.h deleted file mode 100644 index a0d3f90..0000000 --- a/akonadish/repl/replStates.h +++ /dev/null @@ -1,87 +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 - -class QSocketNotifier; - -class ReadState : public QState -{ - Q_OBJECT - -public: - ReadState(QState *parent = 0); - -Q_SIGNALS: - void command(const QString &command); - void exitRequested(); - -protected: - void onEntry(QEvent *event); - virtual const char *prompt() const; -}; - -class UnfinishedReadState : public ReadState -{ - Q_OBJECT - -public: - UnfinishedReadState(QState *parent = 0); - -protected: - const char *prompt() const; -}; - -class EvalState : public QState -{ - Q_OBJECT - -public: - EvalState(QState *parent = 0); - -Q_SIGNALS: - void completed(); - void continueInput(); - void output(const QString &output); - -protected: - void onEntry(QEvent *event); - -private: - void complete(); - - QString m_partial; -}; - -class PrintState : public QState -{ - Q_OBJECT - -public: - PrintState(QState *parent = 0); - -Q_SIGNALS: - void completed(); - -protected: - void onEntry(QEvent *event); -}; - diff --git a/akonadish/state.cpp b/akonadish/state.cpp deleted file mode 100644 index 9fb5bcc..0000000 --- a/akonadish/state.cpp +++ /dev/null @@ -1,144 +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. - */ - -#include "state.h" - -#include -#include -#include -#include - -#include "common/log.h" - -static bool s_hasEventLoop = false; - -class State::Private -{ -public: - Private() - : outStream(stdout) - { - } - - QEventLoop *eventLoop() - { - if (!event) { - event = new QEventLoop; - } - - return event; - } - - int debugLevel = 0; - QEventLoop *event = 0; - bool timing = false; - QTextStream outStream; -}; - -State::State() - : d(new Private) -{ -} - -void State::print(const QString &message, unsigned int indentationLevel) const -{ - for (unsigned int i = 0; i < indentationLevel; ++i) { - d->outStream << "\t"; - } - - d->outStream << message; -} - -void State::printLine(const QString &message, unsigned int indentationLevel) const -{ - print(message, indentationLevel); - d->outStream << "\n"; - d->outStream.flush(); -} - -void State::printError(const QString &errorMessage, const QString &errorCode) const -{ - printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage); -} - -void State::setDebugLevel(unsigned int level) -{ - if (level < 7) { - d->debugLevel = level; - } -} - -unsigned int State::debugLevel() const -{ - return d->debugLevel; -} - -int State::commandStarted() const -{ - if (!s_hasEventLoop) { - return QCoreApplication::exec(); - } else if (!d->eventLoop()->isRunning()) { - return d->eventLoop()->exec(); - } - - return 0; -} - -void State::commandFinished(int returnCode) const -{ - if (!s_hasEventLoop) { - QCoreApplication::exit(returnCode); - } else { - d->eventLoop()->exit(returnCode); - } -} - -void State::setHasEventLoop(bool evented) -{ - s_hasEventLoop = evented; -} - -bool State::hasEventLoop() -{ - return s_hasEventLoop; -} - -void State::setCommandTiming(bool time) -{ - d->timing = time; -} - -bool State::commandTiming() const -{ - return d->timing; -} - -void State::setLoggingLevel(const QString &level) const -{ - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::debugLevelFromName(level.toLatin1())); -} - -QString State::loggingLevel() const -{ - // do not turn this into a single line return: that core dumps due to allocation of - // the byte array in Akonadi2::Log - QByteArray rv = Akonadi2::Log::debugLevelName(Akonadi2::Log::debugOutputLevel()); - return rv.toLower(); -} - diff --git a/akonadish/state.h b/akonadish/state.h deleted file mode 100644 index 3c4c2c7..0000000 --- a/akonadish/state.h +++ /dev/null @@ -1,52 +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 - -class State -{ -public: - State(); - - void print(const QString &message, unsigned int indentationLevel = 0) const; - void printLine(const QString &message = QString(), unsigned int indentationLevel = 0) const; - void printError(const QString &errorMessage, const QString &errorCode = QString()) const; - - void setDebugLevel(unsigned int level); - unsigned int debugLevel() const; - - void setCommandTiming(bool); - bool commandTiming() const; - - int commandStarted() const; - void commandFinished(int returnCode = 0) const; - - void setLoggingLevel(const QString &level) const; - QString loggingLevel() const; - - static void setHasEventLoop(bool evented); - static bool hasEventLoop(); - -private: - class Private; - Private * const d; -}; - diff --git a/akonadish/syntax_modules/akonadi_clear.cpp b/akonadish/syntax_modules/akonadi_clear.cpp deleted file mode 100644 index d328849..0000000 --- a/akonadish/syntax_modules/akonadi_clear.cpp +++ /dev/null @@ -1,61 +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. - */ - -#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 clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &AkonadiClear::clear); - clear.completer = &AkonadishUtils::resourceCompleter; - - return Syntax::List() << clear; -} - -REGISTER_SYNTAX(AkonadiClear) - -} diff --git a/akonadish/syntax_modules/akonadi_count.cpp b/akonadish/syntax_modules/akonadi_count.cpp deleted file mode 100644 index bb1cd19..0000000 --- a/akonadish/syntax_modules/akonadi_count.cpp +++ /dev/null @@ -1,83 +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. - */ - -#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 AkonadiCount -{ - -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.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(); - } - }); - - if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { - return true; - } - - return true; -} - -Syntax::List syntax() -{ - Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count "), &AkonadiCount::count, Syntax::EventDriven); - count.completer = &AkonadishUtils::typeCompleter; - - return Syntax::List() << count; -} - -REGISTER_SYNTAX(AkonadiCount) - -} diff --git a/akonadish/syntax_modules/akonadi_create.cpp b/akonadish/syntax_modules/akonadi_create.cpp deleted file mode 100644 index 377219a..0000000 --- a/akonadish/syntax_modules/akonadi_create.cpp +++ /dev/null @@ -1,118 +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. - */ - -#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 -{ - -bool create(const QStringList &allArgs, State &state) -{ - 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 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()) { - 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"); - - 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_e" + QString::number(result.errorCode())); - } - - return true; -} - - -Syntax::List syntax() -{ - Syntax::List syntax; - - 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; -} - -REGISTER_SYNTAX(AkonadiCreate) - -} diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp deleted file mode 100644 index 7709d3b..0000000 --- a/akonadish/syntax_modules/akonadi_list.cpp +++ /dev/null @@ -1,114 +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. - */ - -#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 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(); - - 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.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("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++) { - 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; -} - -Syntax::List syntax() -{ - Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); - list.completer = &AkonadishUtils::resourceOrTypeCompleter; - return Syntax::List() << list; -} - -REGISTER_SYNTAX(AkonadiList) - -} diff --git a/akonadish/syntax_modules/akonadi_modify.cpp b/akonadish/syntax_modules/akonadi_modify.cpp deleted file mode 100644 index 76a7f5e..0000000 --- a/akonadish/syntax_modules/akonadi_modify.cpp +++ /dev/null @@ -1,120 +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. - */ - -#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 modify("modify", QObject::tr("Modify items in a resource"), &AkonadiModify::modify); - Syntax resource("resource", QObject::tr("Modify a resource"), &AkonadiModify::resource);//, Syntax::EventDriven); - resource.completer = &AkonadishUtils::resourceOrTypeCompleter; - modify.children << resource; - - return Syntax::List() << modify; -} - -REGISTER_SYNTAX(AkonadiModify) - -} diff --git a/akonadish/syntax_modules/akonadi_remove.cpp b/akonadish/syntax_modules/akonadi_remove.cpp deleted file mode 100644 index 9691d78..0000000 --- a/akonadish/syntax_modules/akonadi_remove.cpp +++ /dev/null @@ -1,110 +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. - */ - -#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 remove(const QStringList &args, State &state) -{ - if (args.isEmpty()) { - 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"), "akonadi_remove/03"); - return false; - } - - if (args.count() < 3) { - state.printError(QObject::tr("An object ID is required to remove items"), "akonadi_remove/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_remove_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 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 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_remove_e" + QString::number(result.errorCode())); - } - - return true; -} - - -Syntax::List syntax() -{ - Syntax remove("remove", QObject::tr("Remove items in a resource"), &AkonadiRemove::remove); - Syntax resource("resource", QObject::tr("Removes a resource"), &AkonadiRemove::resource);//, Syntax::EventDriven); - resource.completer = &AkonadishUtils::resourceCompleter; - remove.children << resource; - - return Syntax::List() << remove; -} - -REGISTER_SYNTAX(AkonadiRemove) - -} diff --git a/akonadish/syntax_modules/akonadi_stat.cpp b/akonadish/syntax_modules/akonadi_stat.cpp deleted file mode 100644 index d10556f..0000000 --- a/akonadish/syntax_modules/akonadi_stat.cpp +++ /dev/null @@ -1,120 +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. - */ - -#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 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; - } - int diskUsage = 0; - - QDir dir(Akonadi2::storageLocation()); - for (const auto &folder : dir.entryList(QStringList() << resource + "*")) { - diskUsage += Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadOnly).diskUsage(); - } - auto size = diskUsage / 1024; - state.printLine(QObject::tr("Disk usage [kb]: %1").arg(size), 1); - } - - state.printLine(QObject::tr("Total [kb]: %1").arg(total)); -} - -bool statAllResources(State &state) -{ - Akonadi2::Query query; - 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 state("stat", QObject::tr("Shows database usage for the resources requested"), &AkonadiStat::stat, Syntax::EventDriven); - state.completer = &AkonadishUtils::resourceCompleter; - - return Syntax::List() << state; -} - -REGISTER_SYNTAX(AkonadiStat) - -} diff --git a/akonadish/syntax_modules/akonadi_sync.cpp b/akonadish/syntax_modules/akonadi_sync.cpp deleted file mode 100644 index 0c994d0..0000000 --- a/akonadish/syntax_modules/akonadi_sync.cpp +++ /dev/null @@ -1,67 +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. - */ - -#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 AkonadiSync -{ - -bool sync(const QStringList &args, State &state) -{ - Akonadi2::Query query; - for (const auto &res : args) { - query.resources << res.toLatin1(); - } - - QTimer::singleShot(0, [query, state]() { - Akonadi2::Store::synchronize(query).then([state]() { - state.printLine("Synchronization complete!"); - state.commandFinished(); - }).exec(); - }); - - return true; -} - -Syntax::List syntax() -{ - Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &AkonadiSync::sync, Syntax::EventDriven ); - sync.completer = &AkonadishUtils::resourceCompleter; - - return Syntax::List() << sync; -} - -REGISTER_SYNTAX(AkonadiSync) - -} diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp deleted file mode 100644 index ccf96c1..0000000 --- a/akonadish/syntax_modules/core_syntax.cpp +++ /dev/null @@ -1,204 +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. - */ - -#include -#include // tr() -#include -#include - -#include "state.h" -#include "syntaxtree.h" -#include "utils.h" - -namespace CoreSyntax -{ - -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, State &) -{ - 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 &, 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; -} - -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; -} - -bool setLoggingLevel(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; - } - - state.setLoggingLevel(commands.at(0)); - return true; -} - -bool printLoggingLevel(const QStringList &commands, State &state) -{ - const QString level = state.loggingLevel(); - state.printLine(level); - return true; -} - -Syntax::List syntax() -{ - Syntax::List syntax; - syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); - - 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("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 logging("logging", QObject::tr("Set the logging level to one of Trace, Log, Warning or Error"), &CoreSyntax::setLoggingLevel); - logging.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "trace" << "log" << "warning" << "error", fragment, Qt::CaseInsensitive); }; - set.children << logging; - - syntax << set; - - 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); - get.children << Syntax("logging", QObject::tr("The current logging level"), &CoreSyntax::printLoggingLevel); - syntax << get; - - return syntax; -} - -REGISTER_SYNTAX(CoreSyntax) - -} // namespace CoreSyntax - diff --git a/akonadish/syntaxtree.cpp b/akonadish/syntaxtree.cpp deleted file mode 100644 index 4860582..0000000 --- a/akonadish/syntaxtree.cpp +++ /dev/null @@ -1,221 +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. - */ - -#include "syntaxtree.h" - -#include -#include - -SyntaxTree *SyntaxTree::s_module = 0; - -Syntax::Syntax() -{ -} - -Syntax::Syntax(const QString &k, const QString &helpText, std::function l, Interactivity inter) - : keyword(k), - help(helpText), - interactivity(inter), - lambda(l) -{ -} - -SyntaxTree::SyntaxTree() -{ -} - -int SyntaxTree::registerSyntax(std::function f) -{ - m_syntax += f(); - return m_syntax.size(); -} - -SyntaxTree *SyntaxTree::self() -{ - if (!s_module) { - s_module = new SyntaxTree; - } - - return s_module; -} - -Syntax::List SyntaxTree::syntax() const -{ - return m_syntax; -} - -bool SyntaxTree::run(const QStringList &commands) -{ - bool success = false; - m_timeElapsed.start(); - Command command = match(commands); - if (command.first) { - if (command.first->lambda) { - success = command.first->lambda(command.second, m_state); - if (success && command.first->interactivity == Syntax::EventDriven) { - success = m_state.commandStarted(); - } - } else if (command.first->children.isEmpty()) { - m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); - } else { - QStringList keywordList; - for (auto syntax: command.first->children) { - keywordList << syntax.keyword; - } - const QString keywords = keywordList.join(" " ); - m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); - } - } else { - m_state.printError(QObject::tr("Unknown command"), "st_unknown"); - } - - if (m_state.commandTiming()) { - m_state.printLine(QObject::tr("Time elapsed: %1").arg(m_timeElapsed.elapsed())); - } - return false; -} - -SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const -{ - if (commandLine.isEmpty()) { - return Command(); - } - - QStringListIterator commandLineIt(commandLine); - - QVectorIterator syntaxIt(m_syntax); - const Syntax *lastFullSyntax = 0; - QStringList tailCommands; - while (commandLineIt.hasNext() && syntaxIt.hasNext()) { - const QString word = commandLineIt.next(); - while (syntaxIt.hasNext()) { - const Syntax &syntax = syntaxIt.next(); - if (word == syntax.keyword) { - lastFullSyntax = &syntax; - syntaxIt = syntax.children; - break; - } - } - } - - if (lastFullSyntax) { - while (commandLineIt.hasNext()) { - tailCommands << commandLineIt.next(); - } - - return std::make_pair(lastFullSyntax, tailCommands); - } - - return Command(); -} - -Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString &fragment) const -{ - Syntax::List matches; - - //qDebug() << "words are" << words; - if (words.isEmpty()) { - for (const Syntax &syntax: m_syntax) { - if (syntax.keyword.startsWith(fragment)) { - matches.push_back(syntax); - } - } - } else { - QStringListIterator wordIt(words); - QVectorIterator syntaxIt(m_syntax); - Syntax lastFullSyntax; - - while (wordIt.hasNext()) { - const QString &word = wordIt.next(); - while (syntaxIt.hasNext()) { - const Syntax &syntax = syntaxIt.next(); - if (word == syntax.keyword) { - lastFullSyntax = syntax; - syntaxIt = syntax.children; - break; - } - } - } - - //qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); - if (lastFullSyntax.keyword == words.last()) { - syntaxIt = lastFullSyntax.children; - while (syntaxIt.hasNext()) { - Syntax syntax = syntaxIt.next(); - if (fragment.isEmpty() || syntax.keyword.startsWith(fragment)) { - matches.push_back(syntax); - } - } - } - } - - return matches; -} - -State &SyntaxTree::state() -{ - return m_state; -} - -QStringList SyntaxTree::tokenize(const QString &text) -{ - //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a - static const QVector quoters = QVector() << '"' << '\''; - QStringList tokens; - QString acc; - QChar closer; - for (int i = 0; i < text.size(); ++i) { - const QChar c = text.at(i); - if (c == '\\') { - ++i; - if (i < text.size()) { - acc.append(text.at(i)); - } - } else if (!closer.isNull()) { - if (c == closer) { - acc = acc.trimmed(); - if (!acc.isEmpty()) { - tokens << acc; - } - acc.clear(); - closer = QChar(); - } else { - acc.append(c); - } - } else if (c.isSpace()) { - acc = acc.trimmed(); - if (!acc.isEmpty()) { - tokens << acc; - } - acc.clear(); - } else if (quoters.contains(c)) { - closer = c; - } else { - acc.append(c); - } - } - - acc = acc.trimmed(); - if (!acc.isEmpty()) { - tokens << acc; - } - - return tokens; -} - diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h deleted file mode 100644 index 468aad3..0000000 --- a/akonadish/syntaxtree.h +++ /dev/null @@ -1,80 +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 "state.h" - -#include -#include -#include - -#include - -class Syntax -{ -public: - typedef QVector List; - - enum Interactivity { - NotInteractive = 0, - EventDriven - }; - - Syntax(); - Syntax(const QString &keyword, - const QString &helpText = QString(), - std::function lambda = std::function(), - Interactivity interactivity = NotInteractive); - - QString keyword; - QString help; - Interactivity interactivity; - std::function lambda; - std::function completer; - - QVector children; -}; - -class SyntaxTree -{ -public: - typedef std::pair Command; - - static SyntaxTree *self(); - - int registerSyntax(std::function f); - Syntax::List syntax() const; - Command match(const QStringList &commands) const; - Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; - State &state(); - bool run(const QStringList &commands); - - static QStringList tokenize(const QString &text); - -private: - SyntaxTree(); - - Syntax::List m_syntax; - State m_state; - QTime m_timeElapsed; - static SyntaxTree *s_module; -}; - -#define REGISTER_SYNTAX(name) static const int theTrickFor##name = SyntaxTree::self()->registerSyntax(&name::syntax); diff --git a/akonadish/utils.cpp b/akonadish/utils.cpp deleted file mode 100644 index d2a28ed..0000000 --- a/akonadish/utils.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2016 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 "utils.h" - -namespace Utils -{ - -QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) -{ - if (commandFragment.isEmpty()) { - return possibleCompletions; - } - - QStringList filtered; - for (auto item: possibleCompletions) { - if (item.startsWith(commandFragment, cs)) { - filtered << item; - } - } - - return filtered; -} - -} // namespace Utils - diff --git a/akonadish/utils.h b/akonadish/utils.h deleted file mode 100644 index 82be8d5..0000000 --- a/akonadish/utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2016 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 - -namespace Utils -{ - -QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); - -} // namespace Utils - diff --git a/common/Akonadi2CommonConfig.cmake.in b/common/Akonadi2CommonConfig.cmake.in deleted file mode 100644 index ae0aefc..0000000 --- a/common/Akonadi2CommonConfig.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -@PACKAGE_INIT@ - -find_dependency(KF5Mime "@KMIME_LIB_VERSION@") - -include("${CMAKE_CURRENT_LIST_DIR}/Akonadi2CommonTargets.cmake") diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 06b2af6..e9cf78f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,31 +1,31 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(domain) -project(akonadi2common) +project(sinkcommon) -ecm_setup_version("0.1" VARIABLE_PREFIX Akonadi2Common - VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/akonadi2common_version.h" - PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfigVersion.cmake" +ecm_setup_version("0.1" VARIABLE_PREFIX SinkCommon + VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/sinkcommon_version.h" + PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfigVersion.cmake" SOVERSION 0 ) ########### CMake Config Files ########### -set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/Akonadi2Common") +set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/SinkCommon") ecm_configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/Akonadi2CommonConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfig.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/SinkCommonConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/Akonadi2CommonConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/SinkCommonConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) -install(EXPORT Akonadi2CommonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE Akonadi2CommonTargets.cmake NAMESPACE KF5::) +install(EXPORT SinkCommonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE SinkCommonTargets.cmake NAMESPACE KF5::) set(storage_SRCS storage_lmdb.cpp) set(storage_LIBS lmdb) @@ -85,7 +85,7 @@ generate_flatbuffers( queuedcommand ) -generate_export_header(${PROJECT_NAME} BASE_NAME Akonadi2Common EXPORT_FILE_NAME akonadi2common_export.h) +generate_export_header(${PROJECT_NAME} BASE_NAME SinkCommon EXPORT_FILE_NAME sinkcommon_export.h) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX VERSION "0.1" @@ -95,7 +95,7 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} qt5_use_modules(${PROJECT_NAME} Network) target_link_libraries(${PROJECT_NAME} ${storage_LIBS} KF5::Async) install(TARGETS ${PROJECT_NAME} - EXPORT Akonadi2CommonTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) + EXPORT SinkCommonTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) install(FILES clientapi.h diff --git a/common/SinkCommonConfig.cmake.in b/common/SinkCommonConfig.cmake.in new file mode 100644 index 0000000..6c2a1c2 --- /dev/null +++ b/common/SinkCommonConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +find_dependency(KF5Mime "@KMIME_LIB_VERSION@") + +include("${CMAKE_CURRENT_LIST_DIR}/SinkCommonTargets.cmake") diff --git a/common/bufferadaptor.h b/common/bufferadaptor.h index aaff1c2..892635f 100644 --- a/common/bufferadaptor.h +++ b/common/bufferadaptor.h @@ -23,7 +23,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { diff --git a/common/bufferutils.h b/common/bufferutils.h index b0fb75a..b08b7f8 100644 --- a/common/bufferutils.h +++ b/common/bufferutils.h @@ -3,7 +3,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { namespace BufferUtils { template static QByteArray extractBuffer(const T *data) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 824ef19..be9f3fd 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -39,23 +39,23 @@ #include "storage.h" #include "log.h" -namespace Akonadi2 +namespace Sink { QString Store::storageLocation() { - return Akonadi2::storageLocation(); + return Sink::storageLocation(); } QByteArray Store::resourceName(const QByteArray &instanceIdentifier) { - return Akonadi2::resourceName(instanceIdentifier); + return Sink::resourceName(instanceIdentifier); } static QList getResources(const QList &resourceFilter, const QByteArray &type) { //Return the global resource (signified by an empty name) for types that don't eblong to a specific resource - if (type == "akonadiresource") { + if (type == "sinkresource") { return QList() << ""; } QList resources; @@ -162,9 +162,9 @@ KAsync::Job Store::shutdown(const QByteArray &identifier) return ResourceAccess::connectToServer(identifier).then>([identifier](QSharedPointer socket, KAsync::Future &future) { //We can't currently reuse the socket socket->close(); - auto resourceAccess = QSharedPointer::create(identifier); + auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); - resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then([&future, resourceAccess]() { + resourceAccess->sendCommand(Sink::Commands::ShutdownCommand).then([&future, resourceAccess]() { Trace() << "Shutdown complete"; future.setFinished(); }).exec(); @@ -180,9 +180,9 @@ KAsync::Job Store::shutdown(const QByteArray &identifier) KAsync::Job Store::start(const QByteArray &identifier) { Trace() << "start " << identifier; - auto resourceAccess = QSharedPointer::create(identifier); + auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); - return resourceAccess->sendCommand(Akonadi2::Commands::PingCommand).then([resourceAccess]() { + return resourceAccess->sendCommand(Sink::Commands::PingCommand).then([resourceAccess]() { Trace() << "Start complete"; }); } @@ -191,19 +191,19 @@ void Store::removeFromDisk(const QByteArray &identifier) { //TODO By calling the resource executable with a --remove option instead //we can ensure that no other resource process is running at the same time - QDir dir(Akonadi2::storageLocation()); + QDir dir(Sink::storageLocation()); for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { - Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); } } -KAsync::Job Store::synchronize(const Akonadi2::Query &query) +KAsync::Job Store::synchronize(const Sink::Query &query) { Trace() << "synchronize" << query.resources; return KAsync::iterate(query.resources) .template each([query](const QByteArray &resource, KAsync::Future &future) { Trace() << "Synchronizing " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); resourceAccess->synchronizeResource(true, false).then([&future, resourceAccess]() { future.setFinished(); @@ -219,7 +219,7 @@ KAsync::Job Store::flushMessageQueue(const QByteArrayList &resourceIdentif return KAsync::iterate(resourceIdentifier) .template each([](const QByteArray &resource, KAsync::Future &future) { Trace() << "Flushing message queue " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); resourceAccess->synchronizeResource(false, true).then([&future, resourceAccess]() { future.setFinished(); @@ -235,7 +235,7 @@ KAsync::Job Store::flushReplayQueue(const QByteArrayList &resourceIdentifi } template -KAsync::Job Store::fetchOne(const Akonadi2::Query &query) +KAsync::Job Store::fetchOne(const Sink::Query &query) { return KAsync::start([query](KAsync::Future &future) { //FIXME We could do this more elegantly if composed jobs would have the correct type (In that case we'd simply return the value from then continuation, and could avoid the outer job entirely) @@ -251,13 +251,13 @@ KAsync::Job Store::fetchOne(const Akonadi2::Query &query) } template -KAsync::Job > Store::fetchAll(const Akonadi2::Query &query) +KAsync::Job > Store::fetchAll(const Sink::Query &query) { return fetch(query); } template -KAsync::Job > Store::fetch(const Akonadi2::Query &query, int minimumAmount) +KAsync::Job > Store::fetch(const Sink::Query &query, int minimumAmount) { auto model = loadModel(query); auto list = QSharedPointer >::create(); @@ -265,12 +265,12 @@ KAsync::Job > Store::fetch(const Akonadi2::Query return KAsync::start >([model, list, context, minimumAmount](KAsync::Future > &future) { if (model->rowCount() >= 1) { for (int i = 0; i < model->rowCount(); i++) { - list->append(model->index(i, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).template value()); + list->append(model->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).template value()); } } else { QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, context.data(), [model, &future, list](const QModelIndex &index, int start, int end) { for (int i = start; i <= end; i++) { - list->append(model->index(i, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).template value()); + list->append(model->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).template value()); } }); QObject::connect(model.data(), &QAbstractItemModel::dataChanged, context.data(), [model, &future, list, minimumAmount](const QModelIndex &, const QModelIndex &, const QVector &roles) { @@ -301,9 +301,9 @@ KAsync::Job Resources::inspect(const Inspection &inspectionCommand) auto resource = inspectionCommand.resourceIdentifier; Trace() << "Sending inspection " << resource; - auto resourceAccess = QSharedPointer::create(resource); + auto resourceAccess = QSharedPointer::create(resource); resourceAccess->open(); - auto notifier = QSharedPointer::create(resourceAccess); + auto notifier = QSharedPointer::create(resourceAccess); auto id = QUuid::createUuid().toByteArray(); return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) .template then([resourceAccess, notifier, id](KAsync::Future &future) { @@ -319,7 +319,7 @@ KAsync::Job Resources::inspect(const Inspection &inspectionCommand) }); } -class Akonadi2::Notifier::Private { +class Sink::Notifier::Private { public: Private() : context(new QObject) @@ -332,7 +332,7 @@ public: }; Notifier::Notifier(const QSharedPointer &resourceAccess) - : d(new Akonadi2::Notifier::Private) + : d(new Sink::Notifier::Private) { QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const Notification ¬ification) { for (const auto &handler : d->handler) { @@ -359,7 +359,7 @@ void Notifier::registerHandler(std::function handler REGISTER_TYPE(ApplicationDomain::Event); REGISTER_TYPE(ApplicationDomain::Mail); REGISTER_TYPE(ApplicationDomain::Folder); -REGISTER_TYPE(ApplicationDomain::AkonadiResource); +REGISTER_TYPE(ApplicationDomain::SinkResource); -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/clientapi.h b/common/clientapi.h index 06376c2..64c4f64 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -31,7 +31,7 @@ class QAbstractItemModel; -namespace Akonadi2 { +namespace Sink { class ResourceAccess; class Notification; @@ -78,7 +78,7 @@ public: /** * Synchronize data to local cache. */ - static KAsync::Job synchronize(const Akonadi2::Query &query); + static KAsync::Job synchronize(const Sink::Query &query); /** * Shutdown resource. @@ -110,13 +110,13 @@ public: static void removeFromDisk(const QByteArray &resourceIdentifier); template - static KAsync::Job fetchOne(const Akonadi2::Query &query); + static KAsync::Job fetchOne(const Sink::Query &query); template - static KAsync::Job > fetchAll(const Akonadi2::Query &query); + static KAsync::Job > fetchAll(const Sink::Query &query); template - static KAsync::Job > fetch(const Akonadi2::Query &query, int minimumAmount = 0); + static KAsync::Job > fetch(const Sink::Query &query, int minimumAmount = 0); }; namespace Resources { diff --git a/common/commands.cpp b/common/commands.cpp index 35dfb13..8b915f0 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -22,7 +22,7 @@ #include -namespace Akonadi2 +namespace Sink { namespace Commands @@ -102,4 +102,4 @@ void write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBuf } // namespace Commands -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/commands.h b/common/commands.h index 33d5cd7..19c827e 100644 --- a/common/commands.h +++ b/common/commands.h @@ -20,13 +20,13 @@ #pragma once -#include +#include #include #include class QIODevice; -namespace Akonadi2 +namespace Sink { namespace Commands @@ -54,11 +54,11 @@ enum CommandIds { QByteArray name(int commandId); -int AKONADI2COMMON_EXPORT headerSize(); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size); -void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb); +int SINKCOMMON_EXPORT headerSize(); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size); +void SINKCOMMON_EXPORT write(QIODevice *device, int messageId, int commandId, flatbuffers::FlatBufferBuilder &fbb); } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/commands/commandcompletion.fbs b/common/commands/commandcompletion.fbs index de7ec14..6d95dbc 100644 --- a/common/commands/commandcompletion.fbs +++ b/common/commands/commandcompletion.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table CommandCompletion { id: ulong; diff --git a/common/commands/createentity.fbs b/common/commands/createentity.fbs index 5358dea..b97e8f6 100644 --- a/common/commands/createentity.fbs +++ b/common/commands/createentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table CreateEntity { entityId: string; diff --git a/common/commands/deleteentity.fbs b/common/commands/deleteentity.fbs index 9f865be..c3a3fc7 100644 --- a/common/commands/deleteentity.fbs +++ b/common/commands/deleteentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table DeleteEntity { revision: ulong; diff --git a/common/commands/fetchentity.fbs b/common/commands/fetchentity.fbs index 7a1d74d..bceafbd 100644 --- a/common/commands/fetchentity.fbs +++ b/common/commands/fetchentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table FetchEntity { revision: ulong; diff --git a/common/commands/handshake.fbs b/common/commands/handshake.fbs index e824715..1d0b3cb 100644 --- a/common/commands/handshake.fbs +++ b/common/commands/handshake.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Handshake { name: string; diff --git a/common/commands/inspection.fbs b/common/commands/inspection.fbs index aaae1ae..e99fc71 100644 --- a/common/commands/inspection.fbs +++ b/common/commands/inspection.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Inspection { id: string; diff --git a/common/commands/modifyentity.fbs b/common/commands/modifyentity.fbs index 03b543f..efa2fa0 100644 --- a/common/commands/modifyentity.fbs +++ b/common/commands/modifyentity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table ModifyEntity { revision: ulong; diff --git a/common/commands/notification.fbs b/common/commands/notification.fbs index 89687cf..ff01fc5 100644 --- a/common/commands/notification.fbs +++ b/common/commands/notification.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; enum NotificationType : byte { Shutdown = 1, Status, Warning, Progress, Inspection } enum NotificationCode : byte { Success = 0, Failure = 1, UserCode } diff --git a/common/commands/revisionreplayed.fbs b/common/commands/revisionreplayed.fbs index e1b11e3..f110ff9 100644 --- a/common/commands/revisionreplayed.fbs +++ b/common/commands/revisionreplayed.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table RevisionReplayed { revision: ulong; diff --git a/common/commands/revisionupdate.fbs b/common/commands/revisionupdate.fbs index 93fbe34..cc092e4 100644 --- a/common/commands/revisionupdate.fbs +++ b/common/commands/revisionupdate.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table RevisionUpdate { revision: ulong; diff --git a/common/commands/synchronize.fbs b/common/commands/synchronize.fbs index 7c3ae9a..5528166 100644 --- a/common/commands/synchronize.fbs +++ b/common/commands/synchronize.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.Commands; +namespace Sink.Commands; table Synchronize { sourceSync: bool; //Synchronize with source diff --git a/common/definitions.cpp b/common/definitions.cpp index 33512ad..daf354c 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp @@ -22,12 +22,12 @@ #include -QString Akonadi2::storageLocation() +QString Sink::storageLocation() { - return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; + return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/storage"; } -QByteArray Akonadi2::resourceName(const QByteArray &instanceIdentifier) +QByteArray Sink::resourceName(const QByteArray &instanceIdentifier) { auto split = instanceIdentifier.split('.'); if (split.size() <= 1) { diff --git a/common/definitions.h b/common/definitions.h index 333d106..5834f01 100644 --- a/common/definitions.h +++ b/common/definitions.h @@ -23,7 +23,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { QString storageLocation(); QByteArray resourceName(const QByteArray &instanceIdentifier); } diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index c9a8bba..b0433be 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -21,7 +21,7 @@ #include "log.h" #include "../bufferadaptor.h" -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { ApplicationDomainType::ApplicationDomainType() @@ -113,9 +113,9 @@ QByteArray getTypeName() } template<> -QByteArray getTypeName() +QByteArray getTypeName() { - return "akonadiresource"; + return "sinkresource"; } template<> diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 44d8743..63f030c 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -24,7 +24,7 @@ #include #include "bufferadaptor.h" -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { @@ -48,7 +48,7 @@ public: template static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList properties = QList()) { - auto memoryAdaptor = QSharedPointer::create(*(domainType.mAdaptor), properties); + auto memoryAdaptor = QSharedPointer::create(*(domainType.mAdaptor), properties); //The identifier still internal refers to the memory-mapped pointer, we need to copy the memory or it will become invalid return QSharedPointer::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); } @@ -113,13 +113,13 @@ struct Folder : public Entity { }; /** - * Represents an akonadi resource. + * Represents an sink resource. * * This type is used for configuration of resources, * and for creating and removing resource instances. */ -struct AkonadiResource : public ApplicationDomainType { - typedef QSharedPointer Ptr; +struct SinkResource : public ApplicationDomainType { + typedef QSharedPointer Ptr; using ApplicationDomainType::ApplicationDomainType; }; @@ -138,7 +138,7 @@ template<> QByteArray getTypeName(); template<> -QByteArray getTypeName(); +QByteArray getTypeName(); template<> QByteArray getTypeName(); @@ -158,15 +158,15 @@ class TypeImplementation; } } -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::ApplicationDomainType) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Entity) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Entity::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder::Ptr) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource) -Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Folder) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Folder::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkResource) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkResource::Ptr) diff --git a/common/domain/dummy.fbs b/common/domain/dummy.fbs index 8816b09..4b12827 100644 --- a/common/domain/dummy.fbs +++ b/common/domain/dummy.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Dummy { } diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 18009fc..9f81eb8 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -50,17 +50,17 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { return getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { return getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/event.fbs b/common/domain/event.fbs index 0c6628b..69148ef 100644 --- a/common/domain/event.fbs +++ b/common/domain/event.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Event { uid:string; diff --git a/common/domain/event.h b/common/domain/event.h index 577367b..479969d 100644 --- a/common/domain/event.h +++ b/common/domain/event.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -45,19 +45,19 @@ namespace ApplicationDomain { * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. */ template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Event Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::EventBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Event Buffer; + typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; static QSet indexedProperties(); /** * Returns the potential result set based on the indexes. * * An empty result set indicates that a full scan is required. */ - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 7934841..16b2ec9 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -51,18 +51,18 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { Trace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/folder.fbs b/common/domain/folder.fbs index 31dc32a..b5d01ef 100644 --- a/common/domain/folder.fbs +++ b/common/domain/folder.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Folder { name:string; diff --git a/common/domain/folder.h b/common/domain/folder.h index 545836f..40c799c 100644 --- a/common/domain/folder.h +++ b/common/domain/folder.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -40,14 +40,14 @@ namespace ApplicationDomain { } template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Folder Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Folder Buffer; + typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; static QSet indexedProperties(); - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 8875d88..518331f 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -37,7 +37,7 @@ static QMutex sMutex; -using namespace Akonadi2::ApplicationDomain; +using namespace Sink::ApplicationDomain; static TypeIndex &getIndex() { @@ -55,18 +55,18 @@ static TypeIndex &getIndex() return *index; } -ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { return getIndex().query(query, appliedFilters, transaction); } -void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { Trace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } -void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { getIndex().remove(identifier, bufferAdaptor, transaction); } diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs index 17b29a0..0d11e32 100644 --- a/common/domain/mail.fbs +++ b/common/domain/mail.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2.ApplicationDomain.Buffer; +namespace Sink.ApplicationDomain.Buffer; table Mail { uid:string; diff --git a/common/domain/mail.h b/common/domain/mail.h index d1ef8d6..e45d64d 100644 --- a/common/domain/mail.h +++ b/common/domain/mail.h @@ -30,7 +30,7 @@ class ReadPropertyMapper; template class WritePropertyMapper; -namespace Akonadi2 { +namespace Sink { class Query; namespace ApplicationDomain { @@ -40,19 +40,19 @@ namespace ApplicationDomain { } template<> -class TypeImplementation { +class TypeImplementation { public: - typedef Akonadi2::ApplicationDomain::Buffer::Mail Buffer; - typedef Akonadi2::ApplicationDomain::Buffer::MailBuilder BufferBuilder; + typedef Sink::ApplicationDomain::Buffer::Mail Buffer; + typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; static QSet indexedProperties(); /** * Returns the potential result set based on the indexes. * * An empty result set indicates that a full scan is required. */ - static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); - static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Sink::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); static QSharedPointer > initializeReadPropertyMapper(); static QSharedPointer > initializeWritePropertyMapper(); }; diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 39bd3b8..d43fad7 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -39,7 +39,7 @@ * Create a buffer from a domain object using the provided mappings */ template -flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) +flatbuffers::Offset createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) { //First create a primitives such as strings using the mappings QList > propertiesToAddToResource; @@ -67,11 +67,11 @@ flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain:: * After this the buffer can be extracted from the FlatBufferBuilder object. */ template -static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) +static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) { auto pos = createBufferPart(domainObject, fbb, mapper); // Because we cannot template the following call - // Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); + // Sink::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); // FIXME: This means all buffers in here must have the AKFB identifier fbb.Finish(pos, "AKFB"); flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); @@ -84,7 +84,7 @@ static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::Applicatio * A generic adaptor implementation that uses a property mapper to read/write values. */ template -class GenericBufferAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor +class GenericBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor { public: GenericBufferAdaptor() @@ -123,13 +123,13 @@ public: template class DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface { - typedef typename Akonadi2::ApplicationDomain::TypeImplementation::Buffer LocalBuffer; - typedef typename Akonadi2::ApplicationDomain::TypeImplementation::BufferBuilder LocalBuilder; + typedef typename Sink::ApplicationDomain::TypeImplementation::Buffer LocalBuffer; + typedef typename Sink::ApplicationDomain::TypeImplementation::BufferBuilder LocalBuilder; public: DomainTypeAdaptorFactory() : - mLocalMapper(Akonadi2::ApplicationDomain::TypeImplementation::initializeReadPropertyMapper()), + mLocalMapper(Sink::ApplicationDomain::TypeImplementation::initializeReadPropertyMapper()), mResourceMapper(QSharedPointer >::create()), - mLocalWriteMapper(Akonadi2::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper()), + mLocalWriteMapper(Sink::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper()), mResourceWriteMapper(QSharedPointer >::create()) {}; virtual ~DomainTypeAdaptorFactory() {}; @@ -139,11 +139,11 @@ public: * * This returns by default a GenericBufferAdaptor initialized with the corresponding property mappers. */ - virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) Q_DECL_OVERRIDE + virtual QSharedPointer createAdaptor(const Sink::Entity &entity) Q_DECL_OVERRIDE { - const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer(entity.resource()); - const auto localBuffer = Akonadi2::EntityBuffer::readBuffer(entity.local()); - // const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + const auto resourceBuffer = Sink::EntityBuffer::readBuffer(entity.resource()); + const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); + // const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); auto adaptor = QSharedPointer >::create(); adaptor->mLocalBuffer = localBuffer; @@ -153,7 +153,7 @@ public: return adaptor; } - virtual void createBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE + virtual void createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE { flatbuffers::FlatBufferBuilder localFbb; if (mLocalWriteMapper) { @@ -167,7 +167,7 @@ public: createBufferPartBuffer(domainObject, resFbb, *mResourceWriteMapper); } - Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); } diff --git a/common/domaintypeadaptorfactoryinterface.h b/common/domaintypeadaptorfactoryinterface.h index 8c99aa1..d974bbf 100644 --- a/common/domaintypeadaptorfactoryinterface.h +++ b/common/domaintypeadaptorfactoryinterface.h @@ -20,7 +20,7 @@ #include -namespace Akonadi2 { +namespace Sink { namespace ApplicationDomain { class BufferAdaptor; class ApplicationDomainType; @@ -37,6 +37,6 @@ class DomainTypeAdaptorFactoryInterface public: typedef QSharedPointer Ptr; virtual ~DomainTypeAdaptorFactoryInterface() {}; - virtual QSharedPointer createAdaptor(const Akonadi2::Entity &entity) = 0; - virtual void createBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainType, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) = 0; + virtual QSharedPointer createAdaptor(const Sink::Entity &entity) = 0; + virtual void createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainType, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) = 0; }; diff --git a/common/entity.fbs b/common/entity.fbs index 565b1a7..fe9b727 100644 --- a/common/entity.fbs +++ b/common/entity.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; table Entity { metadata: [ubyte]; diff --git a/common/entitybuffer.cpp b/common/entitybuffer.cpp index c14c86d..0e5435a 100644 --- a/common/entitybuffer.cpp +++ b/common/entitybuffer.cpp @@ -4,17 +4,17 @@ #include "metadata_generated.h" #include -using namespace Akonadi2; +using namespace Sink; EntityBuffer::EntityBuffer(const void *dataValue, int dataSize) : mEntity(nullptr) { flatbuffers::Verifier verifyer(reinterpret_cast(dataValue), dataSize); - // Q_ASSERT(Akonadi2::VerifyEntity(verifyer)); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + // Q_ASSERT(Sink::VerifyEntity(verifyer)); + if (!Sink::VerifyEntityBuffer(verifyer)) { qWarning() << "invalid buffer"; } else { - mEntity = Akonadi2::GetEntity(dataValue); + mEntity = Sink::GetEntity(dataValue); } } @@ -23,7 +23,7 @@ bool EntityBuffer::isValid() const return mEntity; } -const Akonadi2::Entity &EntityBuffer::entity() +const Sink::Entity &EntityBuffer::entity() { return *mEntity; } @@ -55,7 +55,7 @@ const uint8_t* EntityBuffer::localBuffer() void EntityBuffer::extractResourceBuffer(void *dataValue, int dataSize, const std::function &handler) { - Akonadi2::EntityBuffer buffer(dataValue, dataSize); + Sink::EntityBuffer buffer(dataValue, dataSize); if (auto resourceData = buffer.entity().resource()) { handler(resourceData->Data(), resourceData->size()); } @@ -76,7 +76,7 @@ void EntityBuffer::assembleEntityBuffer(flatbuffers::FlatBufferBuilder &fbb, voi auto metadata = appendAsVector(fbb, metadataData, metadataSize); auto resource = appendAsVector(fbb, resourceData, resourceSize); auto local = appendAsVector(fbb, localData, localSize); - auto entity = Akonadi2::CreateEntity(fbb, metadata, resource, local); - Akonadi2::FinishEntityBuffer(fbb, entity); + auto entity = Sink::CreateEntity(fbb, metadata, resource, local); + Sink::FinishEntityBuffer(fbb, entity); } diff --git a/common/entitybuffer.h b/common/entitybuffer.h index a58aae9..c9c2453 100644 --- a/common/entitybuffer.h +++ b/common/entitybuffer.h @@ -3,7 +3,7 @@ #include #include -namespace Akonadi2 { +namespace Sink { struct Entity; class EntityBuffer { diff --git a/common/facade.cpp b/common/facade.cpp index 91021db..8cb776c 100644 --- a/common/facade.cpp +++ b/common/facade.cpp @@ -27,7 +27,7 @@ #include "queryrunner.h" #include "bufferutils.h" -using namespace Akonadi2; +using namespace Sink; class ResourceAccessFactory { public: @@ -40,7 +40,7 @@ public: return *instance; } - Akonadi2::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier) + Sink::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier) { if (!mCache.contains(instanceIdentifier)) { //Reuse the pointer if something else kept the resourceaccess alive @@ -52,8 +52,8 @@ public: } if (!mCache.contains(instanceIdentifier)) { //Create a new instance if necessary - auto sharedPointer = Akonadi2::ResourceAccess::Ptr::create(instanceIdentifier); - QObject::connect(sharedPointer.data(), &Akonadi2::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { + auto sharedPointer = Sink::ResourceAccess::Ptr::create(instanceIdentifier); + QObject::connect(sharedPointer.data(), &Sink::ResourceAccess::ready, sharedPointer.data(), [this, instanceIdentifier](bool ready) { if (!ready) { mCache.remove(instanceIdentifier); } @@ -76,14 +76,14 @@ public: return mCache.value(instanceIdentifier); } - QHash > mWeakCache; - QHash mCache; + QHash > mWeakCache; + QHash mCache; QHash mTimer; }; template -GenericFacade::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer resourceAccess) - : Akonadi2::StoreFacade(), +GenericFacade::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer resourceAccess) + : Sink::StoreFacade(), mResourceAccess(resourceAccess), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier) @@ -102,7 +102,7 @@ template QByteArray GenericFacade::bufferTypeForDomainType() { //We happen to have a one to one mapping - return Akonadi2::ApplicationDomain::getTypeName(); + return Sink::ApplicationDomain::getTypeName(); } template @@ -136,7 +136,7 @@ KAsync::Job GenericFacade::remove(const DomainType &domainObje } template -QPair, typename ResultEmitter::Ptr> GenericFacade::load(const Akonadi2::Query &query) +QPair, typename ResultEmitter::Ptr> GenericFacade::load(const Sink::Query &query) { //The runner lives for the lifetime of the query auto runner = new QueryRunner(query, mResourceAccess, mResourceInstanceIdentifier, mDomainTypeAdaptorFactory, bufferTypeForDomainType()); @@ -144,8 +144,8 @@ QPair, typename ResultEmitter::Ptr> } -template class Akonadi2::GenericFacade; -template class Akonadi2::GenericFacade; -template class Akonadi2::GenericFacade; +template class Sink::GenericFacade; +template class Sink::GenericFacade; +template class Sink::GenericFacade; #include "facade.moc" diff --git a/common/facade.h b/common/facade.h index de67e05..c25464f 100644 --- a/common/facade.h +++ b/common/facade.h @@ -29,7 +29,7 @@ #include "domaintypeadaptorfactoryinterface.h" #include "storage.h" -namespace Akonadi2 { +namespace Sink { /** * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class. @@ -43,7 +43,7 @@ namespace Akonadi2 { * Additionally a resource only has to provide a synchronizer plugin to execute the synchronization */ template -class GenericFacade: public Akonadi2::StoreFacade +class GenericFacade: public Sink::StoreFacade { public: /** @@ -52,18 +52,18 @@ public: * @param resourceIdentifier is the identifier of the resource instance * @param adaptorFactory is the adaptor factory used to generate the mappings from domain to resource types and vice versa */ - GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory = DomainTypeAdaptorFactoryInterface::Ptr(), const QSharedPointer resourceAccess = QSharedPointer()); + GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory = DomainTypeAdaptorFactoryInterface::Ptr(), const QSharedPointer resourceAccess = QSharedPointer()); ~GenericFacade(); static QByteArray bufferTypeForDomainType(); KAsync::Job create(const DomainType &domainObject) Q_DECL_OVERRIDE; KAsync::Job modify(const DomainType &domainObject) Q_DECL_OVERRIDE; KAsync::Job remove(const DomainType &domainObject) Q_DECL_OVERRIDE; - QPair, typename ResultEmitter::Ptr> load(const Akonadi2::Query &query) Q_DECL_OVERRIDE; + QPair, typename ResultEmitter::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; protected: //TODO use one resource access instance per application & per resource - QSharedPointer mResourceAccess; + QSharedPointer mResourceAccess; DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; QByteArray mResourceInstanceIdentifier; }; diff --git a/common/facadefactory.cpp b/common/facadefactory.cpp index 707d9ad..d9ee5f7 100644 --- a/common/facadefactory.cpp +++ b/common/facadefactory.cpp @@ -22,7 +22,7 @@ #include "resourcefacade.h" #include "resource.h" -using namespace Akonadi2; +using namespace Sink; QMutex FacadeFactory::sMutex; @@ -54,7 +54,7 @@ void FacadeFactory::resetFactory() void FacadeFactory::registerStaticFacades() { - registerFacade(QByteArray()); + registerFacade(QByteArray()); } std::shared_ptr FacadeFactory::getFacade(const QByteArray &resource, const QByteArray &instanceIdentifier, const QByteArray &typeName) @@ -65,7 +65,7 @@ std::shared_ptr FacadeFactory::getFacade(const QByteArray &resource, const if (!mFacadeRegistry.contains(k)) { locker.unlock(); //This will call FacadeFactory::instace() internally - Akonadi2::ResourceFactory::load(QString::fromLatin1(resource)); + Sink::ResourceFactory::load(QString::fromLatin1(resource)); locker.relock(); } diff --git a/common/facadefactory.h b/common/facadefactory.h index 19d1f40..3dca63b 100644 --- a/common/facadefactory.h +++ b/common/facadefactory.h @@ -30,7 +30,7 @@ #include "applicationdomaintype.h" #include "log.h" -namespace Akonadi2 { +namespace Sink { /** * Facade factory that returns a store facade implementation, by loading a plugin and providing the relevant implementation. diff --git a/common/facadeinterface.h b/common/facadeinterface.h index 318abf3..17cba5e 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h @@ -27,7 +27,7 @@ #include "applicationdomaintype.h" #include "resultprovider.h" -namespace Akonadi2 { +namespace Sink { class Query; /** @@ -68,7 +68,7 @@ public: /** * Load entities from the store. */ - virtual QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Query &query) = 0; + virtual QPair, typename Sink::ResultEmitter::Ptr > load(const Query &query) = 0; }; template @@ -90,9 +90,9 @@ public: return KAsync::error(-1, "Failed to create a facade"); } - QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Query &query) + QPair, typename Sink::ResultEmitter::Ptr > load(const Query &query) { - return qMakePair(KAsync::null(), typename Akonadi2::ResultEmitter::Ptr()); + return qMakePair(KAsync::null(), typename Sink::ResultEmitter::Ptr()); } }; diff --git a/common/genericresource.cpp b/common/genericresource.cpp index c7f323a..c7326d3 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -20,7 +20,7 @@ static int sBatchSize = 100; -using namespace Akonadi2; +using namespace Sink; /** * Replays changes from the storage one by one. @@ -105,8 +105,8 @@ public Q_SLOTS: } private: - Akonadi2::Storage mStorage; - Akonadi2::Storage mChangeReplayStore; + Sink::Storage mStorage; + Sink::Storage mChangeReplayStore; ReplayFunction mReplayFunction; }; @@ -118,7 +118,7 @@ class CommandProcessor : public QObject Q_OBJECT typedef std::function(void const *, size_t)> InspectionFunction; public: - CommandProcessor(Akonadi2::Pipeline *pipeline, QList commandQueues) + CommandProcessor(Sink::Pipeline *pipeline, QList commandQueues) : QObject(), mPipeline(pipeline), mCommandQueues(commandQueues), @@ -175,18 +175,18 @@ private slots: }).exec(); } - KAsync::Job processQueuedCommand(const Akonadi2::QueuedCommand *queuedCommand) + KAsync::Job processQueuedCommand(const Sink::QueuedCommand *queuedCommand) { - Log() << "Processing command: " << Akonadi2::Commands::name(queuedCommand->commandId()); + Log() << "Processing command: " << Sink::Commands::name(queuedCommand->commandId()); //Throw command into appropriate pipeline switch (queuedCommand->commandId()) { - case Akonadi2::Commands::DeleteEntityCommand: + case Sink::Commands::DeleteEntityCommand: return mPipeline->deletedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::ModifyEntityCommand: + case Sink::Commands::ModifyEntityCommand: return mPipeline->modifiedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::CreateEntityCommand: + case Sink::Commands::CreateEntityCommand: return mPipeline->newEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); - case Akonadi2::Commands::InspectionCommand: + case Sink::Commands::InspectionCommand: if (mInspect) { return mInspect(queuedCommand->command()->Data(), queuedCommand->command()->size()).then([]() { return -1; @@ -203,16 +203,16 @@ private slots: KAsync::Job processQueuedCommand(const QByteArray &data) { flatbuffers::Verifier verifyer(reinterpret_cast(data.constData()), data.size()); - if (!Akonadi2::VerifyQueuedCommandBuffer(verifyer)) { + if (!Sink::VerifyQueuedCommandBuffer(verifyer)) { Warning() << "invalid buffer"; // return KAsync::error(1, "Invalid Buffer"); } - auto queuedCommand = Akonadi2::GetQueuedCommand(data.constData()); + auto queuedCommand = Sink::GetQueuedCommand(data.constData()); const auto commandId = queuedCommand->commandId(); - Trace() << "Dequeued Command: " << Akonadi2::Commands::name(commandId); + Trace() << "Dequeued Command: " << Sink::Commands::name(commandId); return processQueuedCommand(queuedCommand).then( [commandId](qint64 createdRevision) -> qint64 { - Trace() << "Command pipeline processed: " << Akonadi2::Commands::name(commandId); + Trace() << "Command pipeline processed: " << Sink::Commands::name(commandId); return createdRevision; } , @@ -278,7 +278,7 @@ private slots: } private: - Akonadi2::Pipeline *mPipeline; + Sink::Pipeline *mPipeline; //Ordered by priority QList mCommandQueues; bool mProcessingLock; @@ -289,19 +289,19 @@ private: GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, const QSharedPointer &pipeline) - : Akonadi2::Resource(), - mUserQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".userqueue"), - mSynchronizerQueue(Akonadi2::storageLocation(), resourceInstanceIdentifier + ".synchronizerqueue"), + : Sink::Resource(), + mUserQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".userqueue"), + mSynchronizerQueue(Sink::storageLocation(), resourceInstanceIdentifier + ".synchronizerqueue"), mResourceInstanceIdentifier(resourceInstanceIdentifier), - mPipeline(pipeline ? pipeline : QSharedPointer::create(resourceInstanceIdentifier)), + mPipeline(pipeline ? pipeline : QSharedPointer::create(resourceInstanceIdentifier)), mError(0), mClientLowerBoundRevision(std::numeric_limits::max()) { mProcessor = new CommandProcessor(mPipeline.data(), QList() << &mUserQueue << &mSynchronizerQueue); mProcessor->setInspectionCommand([this](void const *command, size_t size) { flatbuffers::Verifier verifier((const uint8_t *)command, size); - if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetInspection(command); + if (Sink::Commands::VerifyInspectionBuffer(verifier)) { + auto buffer = Sink::Commands::GetInspection(command); int inspectionType = buffer->type(); QByteArray inspectionId = BufferUtils::extractBuffer(buffer->id()); @@ -313,17 +313,17 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QVariant expectedValue; s >> expectedValue; inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then([=]() { - Akonadi2::Notification n; - n.type = Akonadi2::Commands::NotificationType_Inspection; + Sink::Notification n; + n.type = Sink::Commands::NotificationType_Inspection; n.id = inspectionId; - n.code = Akonadi2::Commands::NotificationCode_Success; + n.code = Sink::Commands::NotificationCode_Success; emit notify(n); }, [=](int code, const QString &message) { - Akonadi2::Notification n; - n.type = Akonadi2::Commands::NotificationType_Inspection; + Sink::Notification n; + n.type = Sink::Commands::NotificationType_Inspection; n.message = message; n.id = inspectionId; - n.code = Akonadi2::Commands::NotificationCode_Failure; + n.code = Sink::Commands::NotificationCode_Failure; emit notify(n); }).exec(); return KAsync::null(); @@ -334,7 +334,7 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { //This results in a deadlock when a sync is in progress and we try to create a second writing transaction (which is why we turn changereplay off during the sync) - auto synchronizationStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); + auto synchronizationStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadWrite); return this->replay(*synchronizationStore, type, key, value).then([synchronizationStore](){}); }); enableChangeReplay(true); @@ -370,13 +370,13 @@ void GenericResource::enableChangeReplay(bool enable) } } -void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors) +void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors) { mPipeline->setPreprocessors(type, preprocessors); mPipeline->setAdaptorFactory(type, factory); } -KAsync::Job GenericResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job GenericResource::replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { return KAsync::null(); } @@ -384,18 +384,18 @@ KAsync::Job GenericResource::replay(Akonadi2::Storage &synchronizationStor void GenericResource::removeFromDisk(const QByteArray &instanceIdentifier) { Warning() << "Removing from generic resource"; - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier, Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".userqueue", Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronizerqueue", Akonadi2::Storage::ReadWrite).removeFromDisk(); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".changereplay", Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadWrite).removeFromDisk(); } qint64 GenericResource::diskUsage(const QByteArray &instanceIdentifier) { - auto size = Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier, Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".userqueue", Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronizerqueue", Akonadi2::Storage::ReadOnly).diskUsage(); - size += Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".changereplay", Akonadi2::Storage::ReadOnly).diskUsage(); + auto size = Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadOnly).diskUsage(); + size += Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadOnly).diskUsage(); return size; } @@ -413,9 +413,9 @@ int GenericResource::error() const void GenericResource::enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data) { flatbuffers::FlatBufferBuilder fbb; - auto commandData = Akonadi2::EntityBuffer::appendAsVector(fbb, data.constData(), data.size()); - auto buffer = Akonadi2::CreateQueuedCommand(fbb, commandId, commandData); - Akonadi2::FinishQueuedCommandBuffer(fbb, buffer); + auto commandData = Sink::EntityBuffer::appendAsVector(fbb, data.constData(), data.size()); + auto buffer = Sink::CreateQueuedCommand(fbb, commandId, commandData); + Sink::FinishQueuedCommandBuffer(fbb, buffer); mq.enqueue(fbb.GetBufferPointer(), fbb.GetSize()); } @@ -440,8 +440,8 @@ KAsync::Job GenericResource::synchronizeWithSource() Log() << " Synchronizing"; //Changereplay would deadlock otherwise when trying to open the synchronization store enableChangeReplay(false); - auto mainStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier, Akonadi2::Storage::ReadOnly); - auto syncStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); + auto mainStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier, Sink::Storage::ReadOnly); + auto syncStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadWrite); synchronizeWithSource(*mainStore, *syncStore).then([this, mainStore, syncStore]() { Log() << "Done Synchronizing"; enableChangeReplay(true); @@ -449,7 +449,7 @@ KAsync::Job GenericResource::synchronizeWithSource() }); } -KAsync::Job GenericResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) +KAsync::Job GenericResource::synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) { return KAsync::null(); } @@ -508,7 +508,7 @@ void GenericResource::setLowerBoundRevision(qint64 revision) updateLowerBoundRevision(); } -void GenericResource::createEntity(const QByteArray &akonadiId, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) +void GenericResource::createEntity(const QByteArray &sinkId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) { //These changes are coming from the source const auto replayToSource = false; @@ -516,45 +516,45 @@ void GenericResource::createEntity(const QByteArray &akonadiId, const QByteArray adaptorFactory.createBuffer(domainObject, entityFbb); flatbuffers::FlatBufferBuilder fbb; //This is the resource type and not the domain type - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); auto type = fbb.CreateString(bufferType.toStdString()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto location = Sink::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::modifyEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) +void GenericResource::modifyEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback) { //These changes are coming from the source const auto replayToSource = false; flatbuffers::FlatBufferBuilder entityFbb; adaptorFactory.createBuffer(domainObject, entityFbb); flatbuffers::FlatBufferBuilder fbb; - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); //This is the resource type and not the domain type auto type = fbb.CreateString(bufferType.toStdString()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); //TODO removals - auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); - Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); + Sink::Commands::FinishModifyEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::deleteEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, std::function callback) +void GenericResource::deleteEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, std::function callback) { //These changes are coming from the source const auto replayToSource = false; flatbuffers::FlatBufferBuilder fbb; - auto entityId = fbb.CreateString(akonadiId.toStdString()); + auto entityId = fbb.CreateString(sinkId.toStdString()); //This is the resource type and not the domain type auto type = fbb.CreateString(bufferType.toStdString()); - auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); - Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); + Sink::Commands::FinishDeleteEntityBuffer(fbb, location); callback(BufferUtils::extractBuffer(fbb)); } -void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); @@ -562,7 +562,7 @@ void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteAr localIndex.add(localId, remoteId); } -void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); @@ -570,21 +570,21 @@ void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteAr localIndex.remove(localId, remoteId); } -QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) +QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { //Lookup local id for remote id, or insert a new pair otherwise Index index("rid.mapping." + bufferType, transaction); Index localIndex("localid.mapping." + bufferType, transaction); - QByteArray akonadiId = index.lookup(remoteId); - if (akonadiId.isEmpty()) { - akonadiId = QUuid::createUuid().toString().toUtf8(); - index.add(remoteId, akonadiId); - localIndex.add(akonadiId, remoteId); + QByteArray sinkId = index.lookup(remoteId); + if (sinkId.isEmpty()) { + sinkId = QUuid::createUuid().toString().toUtf8(); + index.add(remoteId, sinkId); + localIndex.add(sinkId, remoteId); } - return akonadiId; + return sinkId; } -QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Akonadi2::Storage::Transaction &transaction) +QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction) { Index index("localid.mapping." + bufferType, transaction); QByteArray remoteId = index.lookup(localId); @@ -595,29 +595,29 @@ QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const Q return remoteId; } -void GenericResource::scanForRemovals(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists) +void GenericResource::scanForRemovals(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists) { entryGenerator([this, &transaction, bufferType, &synchronizationTransaction, &exists](const QByteArray &key) { - auto akonadiId = Akonadi2::Storage::uidFromKey(key); + auto sinkId = Sink::Storage::uidFromKey(key); Trace() << "Checking for removal " << key; - const auto remoteId = resolveLocalId(bufferType, akonadiId, synchronizationTransaction); + const auto remoteId = resolveLocalId(bufferType, sinkId, synchronizationTransaction); //If we have no remoteId, the entity hasn't been replayed to the source yet if (!remoteId.isEmpty()) { if (!exists(remoteId)) { - Trace() << "Found a removed entity: " << akonadiId; - deleteEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::DeleteEntityCommand, buffer); + Trace() << "Found a removed entity: " << sinkId; + deleteEntity(sinkId, Sink::Storage::maxRevision(transaction), bufferType, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::DeleteEntityCommand, buffer); }); } } }); } -static QSharedPointer getLatest(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory) +static QSharedPointer getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory) { - QSharedPointer current; + QSharedPointer current; db.findLatest(uid, [¤t, &adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { @@ -625,35 +625,35 @@ static QSharedPointer getLatest(cons } return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); return current; } -void GenericResource::createOrModify(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Akonadi2::ApplicationDomain::ApplicationDomainType &entity) +void GenericResource::createOrModify(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) { auto mainDatabase = transaction.openDatabase(bufferType + ".main"); - const auto akonadiId = resolveRemoteId(bufferType, remoteId, synchronizationTransaction); - const auto found = mainDatabase.contains(akonadiId); + const auto sinkId = resolveRemoteId(bufferType, remoteId, synchronizationTransaction); + const auto found = mainDatabase.contains(sinkId); if (!found) { Trace() << "Found a new entity: " << remoteId; - createEntity(akonadiId, bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, buffer); + createEntity(sinkId, bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::CreateEntityCommand, buffer); }); } else { //modification - if (auto current = getLatest(mainDatabase, akonadiId, adaptorFactory)) { + if (auto current = getLatest(mainDatabase, sinkId, adaptorFactory)) { bool changed = false; for (const auto &property : entity.changedProperties()) { if (entity.getProperty(property) != current->getProperty(property)) { - Trace() << "Property changed " << akonadiId << property; + Trace() << "Property changed " << sinkId << property; changed = true; } } if (changed) { Trace() << "Found a modified entity: " << remoteId; - modifyEntity(akonadiId, Akonadi2::Storage::maxRevision(transaction), bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { - enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::ModifyEntityCommand, buffer); + modifyEntity(sinkId, Sink::Storage::maxRevision(transaction), bufferType, entity, adaptorFactory, [this](const QByteArray &buffer) { + enqueueCommand(mSynchronizerQueue, Sink::Commands::ModifyEntityCommand, buffer); }); } } else { diff --git a/common/genericresource.h b/common/genericresource.h index d71061c..4ae2645 100644 --- a/common/genericresource.h +++ b/common/genericresource.h @@ -19,7 +19,7 @@ */ #pragma once -#include +#include #include #include #include @@ -29,7 +29,7 @@ class CommandProcessor; class ChangeReplay; -namespace Akonadi2 +namespace Sink { class Pipeline; class Preprocessor; @@ -37,7 +37,7 @@ class Preprocessor; /** * Generic Resource implementation. */ -class AKONADI2COMMON_EXPORT GenericResource : public Resource +class SINKCOMMON_EXPORT GenericResource : public Resource { public: GenericResource(const QByteArray &resourceInstanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); @@ -45,7 +45,7 @@ public: virtual void processCommand(int commandId, const QByteArray &data) Q_DECL_OVERRIDE; virtual KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE; - virtual KAsync::Job synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore); + virtual KAsync::Job synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore); virtual KAsync::Job processAllMessages() Q_DECL_OVERRIDE; virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE; virtual KAsync::Job inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue); @@ -60,34 +60,34 @@ private Q_SLOTS: protected: void enableChangeReplay(bool); - void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors); - virtual KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value); + void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors); + virtual KAsync::Job replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value); void onProcessorError(int errorCode, const QString &errorMessage); void enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data); - static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); - static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); + static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); + static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function callback); static void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, std::function callback); /** * Records a localId to remoteId mapping */ - void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); - void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); + void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); + void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); /** * Tries to find a local id for the remote id, and creates a new local id otherwise. * * The new local id is recorded in the local to remote id mapping. */ - QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction); + QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); /** * Tries to find a remote id for a local id. * * This can fail if the entity hasn't been written back to the server yet. */ - QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Akonadi2::Storage::Transaction &transaction); + QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction); /** * A synchronous algorithm to remove entities that are no longer existing. @@ -99,14 +99,14 @@ protected: * * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. */ - void scanForRemovals(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists); + void scanForRemovals(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QByteArray &bufferType, const std::function &callback)> &entryGenerator, std::function exists); /** * An algorithm to create or modify the entity. * * Depending on whether the entity is locally available, or has changed. */ - void createOrModify(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Akonadi2::ApplicationDomain::ApplicationDomainType &entity); + void createOrModify(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity); MessageQueue mUserQueue; MessageQueue mSynchronizerQueue; diff --git a/common/index.cpp b/common/index.cpp index f4de93c..25dfb7c 100644 --- a/common/index.cpp +++ b/common/index.cpp @@ -1,15 +1,15 @@ #include "index.h" #include -Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) - : mTransaction(Akonadi2::Storage(storageRoot, name, mode).createTransaction(mode)), - mDb(mTransaction.openDatabase(name.toLatin1(), std::function(), true)) +Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) + : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), + mDb(mTransaction.openDatabase(name.toLatin1(), std::function(), true)) { } -Index::Index(const QByteArray &name, Akonadi2::Storage::Transaction &transaction) - : mDb(transaction.openDatabase(name, std::function(), true)) +Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction) + : mDb(transaction.openDatabase(name, std::function(), true)) { } @@ -31,7 +31,7 @@ void Index::lookup(const QByteArray &key, const std::function #include -class IndexUpdater : public Akonadi2::Preprocessor { +class IndexUpdater : public Sink::Preprocessor { public: IndexUpdater(const QByteArray &index, const QByteArray &type, const QByteArray &property) :mIndexIdentifier(index), @@ -31,31 +31,31 @@ public: } - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { add(newEntity.getProperty(mProperty), uid, transaction); } - void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { remove(oldEntity.getProperty(mProperty), uid, transaction); add(newEntity.getProperty(mProperty), uid, transaction); } - void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { remove(oldEntity.getProperty(mProperty), uid, transaction); } private: - void add(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) + void add(const QVariant &value, const QByteArray &uid, Sink::Storage::Transaction &transaction) { if (value.isValid()) { Index(mIndexIdentifier, transaction).add(value.toByteArray(), uid); } } - void remove(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) + void remove(const QVariant &value, const QByteArray &uid, Sink::Storage::Transaction &transaction) { //TODO hide notfound error Index(mIndexIdentifier, transaction).remove(value.toByteArray(), uid); @@ -67,21 +67,21 @@ private: }; template -class DefaultIndexUpdater : public Akonadi2::Preprocessor { +class DefaultIndexUpdater : public Sink::Preprocessor { public: - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); } - void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); } - void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Sink::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); } }; diff --git a/common/inspection.h b/common/inspection.h index ecf5b3d..b9f6bf3 100644 --- a/common/inspection.h +++ b/common/inspection.h @@ -23,11 +23,11 @@ #include #include "applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { namespace Resources { struct Inspection { - static Inspection PropertyInspection(const Akonadi2::ApplicationDomain::Entity &entity, const QByteArray &property, const QVariant &expectedValue) + static Inspection PropertyInspection(const Sink::ApplicationDomain::Entity &entity, const QByteArray &property, const QVariant &expectedValue) { Inspection inspection; inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); @@ -37,7 +37,7 @@ struct Inspection { return inspection; } - static Inspection ExistenceInspection(const Akonadi2::ApplicationDomain::Entity &entity, bool exists) + static Inspection ExistenceInspection(const Sink::ApplicationDomain::Entity &entity, bool exists) { Inspection inspection; inspection.resourceIdentifier = entity.resourceInstanceIdentifier(); diff --git a/common/listener.cpp b/common/listener.cpp index fa08472..13ebbbb 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -42,7 +42,7 @@ Listener::Listener(const QByteArray &resourceInstanceIdentifier, QObject *parent) : QObject(parent), m_server(new QLocalServer(this)), - m_resourceName(Akonadi2::resourceName(resourceInstanceIdentifier)), + m_resourceName(Sink::resourceName(resourceInstanceIdentifier)), m_resourceInstanceIdentifier(resourceInstanceIdentifier), m_resource(0), m_clientBufferProcessesTimer(new QTimer(this)), @@ -209,20 +209,20 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c { bool success = true; switch (commandId) { - case Akonadi2::Commands::HandshakeCommand: { + case Sink::Commands::HandshakeCommand: { flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifyHandshakeBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetHandshake(commandBuffer.constData()); + if (Sink::Commands::VerifyHandshakeBuffer(verifier)) { + auto buffer = Sink::Commands::GetHandshake(commandBuffer.constData()); client.name = buffer->name()->c_str(); } else { Warning() << "received invalid command"; } break; } - case Akonadi2::Commands::SynchronizeCommand: { + case Sink::Commands::SynchronizeCommand: { flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifySynchronizeBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetSynchronize(commandBuffer.constData()); + if (Sink::Commands::VerifySynchronizeBuffer(verifier)) { + auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData()); Log() << QString("\tSynchronize request (id %1) from %2").arg(messageId).arg(client.name); auto timer = QSharedPointer::create(); timer->start(); @@ -243,28 +243,28 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c } break; } - case Akonadi2::Commands::InspectionCommand: - case Akonadi2::Commands::FetchEntityCommand: - case Akonadi2::Commands::DeleteEntityCommand: - case Akonadi2::Commands::ModifyEntityCommand: - case Akonadi2::Commands::CreateEntityCommand: - Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; + case Sink::Commands::InspectionCommand: + case Sink::Commands::FetchEntityCommand: + case Sink::Commands::DeleteEntityCommand: + case Sink::Commands::ModifyEntityCommand: + case Sink::Commands::CreateEntityCommand: + Log() << "\tCommand id " << messageId << " of type \"" << Sink::Commands::name(commandId) << "\" from " << client.name; loadResource()->processCommand(commandId, commandBuffer); break; - case Akonadi2::Commands::ShutdownCommand: + case Sink::Commands::ShutdownCommand: Log() << QString("\tReceived shutdown command from %1").arg(client.name); //Immediately reject new connections m_server->close(); QTimer::singleShot(0, this, &Listener::quit); break; - case Akonadi2::Commands::PingCommand: + case Sink::Commands::PingCommand: Log() << QString("\tReceived ping command from %1").arg(client.name); break; - case Akonadi2::Commands::RevisionReplayedCommand: { + case Sink::Commands::RevisionReplayedCommand: { Log() << QString("\tReceived revision replayed command from %1").arg(client.name); flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); - if (Akonadi2::Commands::VerifyRevisionReplayedBuffer(verifier)) { - auto buffer = Akonadi2::Commands::GetRevisionReplayed(commandBuffer.constData()); + if (Sink::Commands::VerifyRevisionReplayedBuffer(verifier)) { + auto buffer = Sink::Commands::GetRevisionReplayed(commandBuffer.constData()); client.currentRevision = buffer->revision(); } else { Warning() << "received invalid command"; @@ -273,7 +273,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c } break; default: - if (commandId > Akonadi2::Commands::CustomCommand) { + if (commandId > Sink::Commands::CustomCommand) { Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; loadResource()->processCommand(commandId, commandBuffer); } else { @@ -303,11 +303,11 @@ qint64 Listener::lowerBoundRevision() void Listener::quit() { //Broadcast shutdown notifications to open clients, so they don't try to restart the resource - auto command = Akonadi2::Commands::CreateNotification(m_fbb, Akonadi2::Commands::NotificationType::NotificationType_Shutdown); - Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); + auto command = Sink::Commands::CreateNotification(m_fbb, Sink::Commands::NotificationType::NotificationType_Shutdown); + Sink::Commands::FinishNotificationBuffer(m_fbb, command); for (Client &client : m_connections) { if (client.socket && client.socket->isOpen()) { - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); } } m_fbb.Clear(); @@ -318,7 +318,7 @@ void Listener::quit() bool Listener::processClientBuffer(Client &client) { - static const int headerSize = Akonadi2::Commands::headerSize(); + static const int headerSize = Sink::Commands::headerSize(); if (client.commandBuffer.size() < headerSize) { return false; } @@ -339,7 +339,7 @@ bool Listener::processClientBuffer(Client &client) const QByteArray commandBuffer = client.commandBuffer.left(size); client.commandBuffer.remove(0, size); processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { - Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); + Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Sink::Commands::name(commandId))).arg(clientName); if (socket) { sendCommandCompleted(socket.data(), messageId, success); } else { @@ -359,9 +359,9 @@ void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId, bool s return; } - auto command = Akonadi2::Commands::CreateCommandCompletion(m_fbb, messageId, success); - Akonadi2::Commands::FinishCommandCompletionBuffer(m_fbb, command); - Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletionCommand, m_fbb); + auto command = Sink::Commands::CreateCommandCompletion(m_fbb, messageId, success); + Sink::Commands::FinishCommandCompletionBuffer(m_fbb, command); + Sink::Commands::write(socket, ++m_messageId, Sink::Commands::CommandCompletionCommand, m_fbb); m_fbb.Clear(); } @@ -372,8 +372,8 @@ void Listener::refreshRevision(qint64 revision) void Listener::updateClientsWithRevision(qint64 revision) { - auto command = Akonadi2::Commands::CreateRevisionUpdate(m_fbb, revision); - Akonadi2::Commands::FinishRevisionUpdateBuffer(m_fbb, command); + auto command = Sink::Commands::CreateRevisionUpdate(m_fbb, revision); + Sink::Commands::FinishRevisionUpdateBuffer(m_fbb, command); for (const Client &client: m_connections) { if (!client.socket || !client.socket->isValid()) { @@ -381,44 +381,44 @@ void Listener::updateClientsWithRevision(qint64 revision) } Trace() << "Sending revision update for " << client.name << revision; - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::RevisionUpdateCommand, m_fbb); } m_fbb.Clear(); } -void Listener::notify(const Akonadi2::Notification ¬ification) +void Listener::notify(const Sink::Notification ¬ification) { auto messageString = m_fbb.CreateString(notification.message.toUtf8().constData(), notification.message.toUtf8().size()); auto idString = m_fbb.CreateString(notification.id.constData(), notification.id.size()); - Akonadi2::Commands::NotificationBuilder builder(m_fbb); - builder.add_type(static_cast(notification.type)); + Sink::Commands::NotificationBuilder builder(m_fbb); + builder.add_type(static_cast(notification.type)); builder.add_code(notification.code); builder.add_identifier(idString); builder.add_message(messageString); auto command = builder.Finish(); - Akonadi2::Commands::FinishNotificationBuffer(m_fbb, command); + Sink::Commands::FinishNotificationBuffer(m_fbb, command); for (Client &client : m_connections) { if (client.socket && client.socket->isOpen()) { - Akonadi2::Commands::write(client.socket, ++m_messageId, Akonadi2::Commands::NotificationCommand, m_fbb); + Sink::Commands::write(client.socket, ++m_messageId, Sink::Commands::NotificationCommand, m_fbb); } } m_fbb.Clear(); } -Akonadi2::Resource *Listener::loadResource() +Sink::Resource *Listener::loadResource() { if (!m_resource) { - if (Akonadi2::ResourceFactory *resourceFactory = Akonadi2::ResourceFactory::load(m_resourceName)) { + if (Sink::ResourceFactory *resourceFactory = Sink::ResourceFactory::load(m_resourceName)) { m_resource = resourceFactory->createResource(m_resourceInstanceIdentifier); Trace() << QString("Resource factory: %1").arg((qlonglong)resourceFactory); Trace() << QString("\tResource: %1").arg((qlonglong)m_resource); - connect(m_resource, &Akonadi2::Resource::revisionUpdated, + connect(m_resource, &Sink::Resource::revisionUpdated, this, &Listener::refreshRevision); - connect(m_resource, &Akonadi2::Resource::notify, + connect(m_resource, &Sink::Resource::notify, this, &Listener::notify); } else { ErrorMsg() << "Failed to load resource " << m_resourceName; - m_resource = new Akonadi2::Resource; + m_resource = new Sink::Resource; } } return m_resource; diff --git a/common/listener.h b/common/listener.h index 4112a6a..e17f315 100644 --- a/common/listener.h +++ b/common/listener.h @@ -25,7 +25,7 @@ #include #include -namespace Akonadi2 +namespace Sink { class Resource; class Notification; @@ -77,7 +77,7 @@ private Q_SLOTS: void onDataAvailable(); void processClientBuffers(); void refreshRevision(qint64); - void notify(const Akonadi2::Notification &); + void notify(const Sink::Notification &); void quit(); private: @@ -85,7 +85,7 @@ private: bool processClientBuffer(Client &client); void sendCommandCompleted(QLocalSocket *socket, uint messageId, bool success); void updateClientsWithRevision(qint64); - Akonadi2::Resource *loadResource(); + Sink::Resource *loadResource(); void readFromSocket(QLocalSocket *socket); qint64 lowerBoundRevision(); @@ -94,7 +94,7 @@ private: flatbuffers::FlatBufferBuilder m_fbb; const QByteArray m_resourceName; const QByteArray m_resourceInstanceIdentifier; - Akonadi2::Resource *m_resource; + Sink::Resource *m_resource; QTimer *m_clientBufferProcessesTimer; QTimer *m_checkConnectionsTimer; int m_messageId; diff --git a/common/listmodelresult.h b/common/listmodelresult.h index a095c2a..71a0d09 100644 --- a/common/listmodelresult.h +++ b/common/listmodelresult.h @@ -39,14 +39,14 @@ public: { } - ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) + ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) :QAbstractListModel(), mPropertyColumns(propertyColumns) { setEmitter(emitter); } - void setEmitter(const QSharedPointer > &emitter) + void setEmitter(const QSharedPointer > &emitter) { beginResetModel(); mEntities.clear(); @@ -118,7 +118,7 @@ public: } private: - QSharedPointer > mEmitter; + QSharedPointer > mEmitter; QMap mEntities; QList mPropertyColumns; }; diff --git a/common/log.cpp b/common/log.cpp index 489e1bd..45bbec1 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -6,7 +6,7 @@ #include #include -using namespace Akonadi2::Log; +using namespace Sink::Log; class DebugStream: public QIODevice { @@ -96,7 +96,7 @@ static QString colorCommand(QList colorCodes) return string; } -QByteArray Akonadi2::Log::debugLevelName(DebugLevel debugLevel) +QByteArray Sink::Log::debugLevelName(DebugLevel debugLevel) { switch (debugLevel) { case DebugLevel::Trace: @@ -114,7 +114,7 @@ QByteArray Akonadi2::Log::debugLevelName(DebugLevel debugLevel) return QByteArray(); } -DebugLevel Akonadi2::Log::debugLevelFromName(const QByteArray &name) +DebugLevel Sink::Log::debugLevelFromName(const QByteArray &name) { const QByteArray lowercaseName = name.toLower(); if (lowercaseName == "trace") @@ -128,19 +128,19 @@ DebugLevel Akonadi2::Log::debugLevelFromName(const QByteArray &name) return DebugLevel::Log; } -void Akonadi2::Log::setDebugOutputLevel(DebugLevel debugLevel) +void Sink::Log::setDebugOutputLevel(DebugLevel debugLevel) { - qputenv("AKONADI2DEBUGLEVEL", debugLevelName(debugLevel)); + qputenv("SINKDEBUGLEVEL", debugLevelName(debugLevel)); } -Akonadi2::Log::DebugLevel Akonadi2::Log::debugOutputLevel() +Sink::Log::DebugLevel Sink::Log::debugOutputLevel() { - return debugLevelFromName(qgetenv("AKONADI2DEBUGLEVEL")); + return debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); } -QDebug Akonadi2::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) +QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) { - DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("AKONADI2DEBUGLEVEL")); + DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("SINKDEBUGLEVEL")); if (debugLevel < debugOutputLevel) { static NullStream stream; return QDebug(&stream); diff --git a/common/log.h b/common/log.h index e531348..483f16f 100644 --- a/common/log.h +++ b/common/log.h @@ -2,7 +2,7 @@ #include -namespace Akonadi2 { +namespace Sink { namespace Log { enum DebugLevel { @@ -23,8 +23,8 @@ QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char } } -#define Trace() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) -#define Log() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) -#define Warning() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) +#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) +#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) +#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) //FIXME Error clashes with Storage::Error and MessageQueue::Error -#define ErrorMsg() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) +#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index 8e3d7d7..1055922 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp @@ -37,7 +37,7 @@ static KAsync::Job waitForCompletion(QList > &futures } MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) - : mStorage(storageRoot, name, Akonadi2::Storage::ReadWrite) + : mStorage(storageRoot, name, Sink::Storage::ReadWrite) { } @@ -56,13 +56,13 @@ void MessageQueue::startTransaction() return; } processRemovals(); - mWriteTransaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadWrite)); + mWriteTransaction = std::move(mStorage.createTransaction(Sink::Storage::ReadWrite)); } void MessageQueue::commit() { mWriteTransaction.commit(); - mWriteTransaction = Akonadi2::Storage::Transaction(); + mWriteTransaction = Sink::Storage::Transaction(); processRemovals(); emit messageReady(); } @@ -74,10 +74,10 @@ void MessageQueue::enqueue(const QByteArray &value) implicitTransaction = true; startTransaction(); } - const qint64 revision = Akonadi2::Storage::maxRevision(mWriteTransaction) + 1; + const qint64 revision = Sink::Storage::maxRevision(mWriteTransaction) + 1; const QByteArray key = QString("%1").arg(revision).toUtf8(); mWriteTransaction.openDatabase().write(key, value); - Akonadi2::Storage::setMaxRevision(mWriteTransaction, revision); + Sink::Storage::setMaxRevision(mWriteTransaction, revision); if (implicitTransaction) { commit(); } @@ -88,7 +88,7 @@ void MessageQueue::processRemovals() if (mWriteTransaction) { return; } - auto transaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadWrite)); + auto transaction = std::move(mStorage.createTransaction(Sink::Storage::ReadWrite)); for (const auto &key : mPendingRemoval) { transaction.openDatabase().remove(key); } @@ -117,8 +117,8 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi return KAsync::start([this, maxBatchSize, resultHandler, resultCount](KAsync::Future &future) { int count = 0; QList > waitCondition; - mStorage.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { - if (Akonadi2::Storage::isInternalKey(key) || mPendingRemoval.contains(key)) { + mStorage.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { + if (Sink::Storage::isInternalKey(key) || mPendingRemoval.contains(key)) { return true; } *resultCount += 1; @@ -133,7 +133,7 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi } return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { ErrorMsg() << "Error while retrieving value" << error.message; // errorHandler(Error(error.store, error.code, error.message)); }); @@ -157,17 +157,17 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi bool MessageQueue::isEmpty() { int count = 0; - auto t = mStorage.createTransaction(Akonadi2::Storage::ReadOnly); + auto t = mStorage.createTransaction(Sink::Storage::ReadOnly); auto db = t.openDatabase(); if (db) { db.scan("", [&count, this](const QByteArray &key, const QByteArray &value) -> bool { - if (!Akonadi2::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { + if (!Sink::Storage::isInternalKey(key) && !mPendingRemoval.contains(key)) { count++; return false; } return true; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { ErrorMsg() << "Error while checking if empty" << error.message; }); } diff --git a/common/messagequeue.h b/common/messagequeue.h index a04e22f..3206388 100644 --- a/common/messagequeue.h +++ b/common/messagequeue.h @@ -54,7 +54,7 @@ private slots: private: Q_DISABLE_COPY(MessageQueue); - Akonadi2::Storage mStorage; - Akonadi2::Storage::Transaction mWriteTransaction; + Sink::Storage mStorage; + Sink::Storage::Transaction mWriteTransaction; QByteArrayList mPendingRemoval; }; diff --git a/common/metadata.fbs b/common/metadata.fbs index 0a709fe..f2f336d 100644 --- a/common/metadata.fbs +++ b/common/metadata.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; enum Operation : byte { Creation = 1, Modification, Removal } diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 22798d9..3a9fb95 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -24,7 +24,7 @@ #include "domain/folder.h" #include "log.h" -static uint qHash(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) +static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) { Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty()); Q_ASSERT(!type.identifier().isEmpty()); @@ -32,7 +32,7 @@ static uint qHash(const Akonadi2::ApplicationDomain::ApplicationDomainType &typ } template -ModelResult::ModelResult(const Akonadi2::Query &query, const QList &propertyColumns) +ModelResult::ModelResult(const Sink::Query &query, const QList &propertyColumns) :QAbstractItemModel(), mPropertyColumns(propertyColumns), mQuery(query) @@ -53,7 +53,7 @@ qint64 ModelResult::parentId(const Ptr &value) if (!mQuery.parentProperty.isEmpty()) { const auto identifier = value->getProperty(mQuery.parentProperty).toByteArray(); if (!identifier.isEmpty()) { - return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer())); + return qHash(T(value->resourceInstanceIdentifier(), identifier, 0, QSharedPointer())); } } return 0; @@ -91,7 +91,7 @@ QVariant ModelResult::data(const QModelIndex &index, int role) const } if (role == DomainObjectBaseRole) { Q_ASSERT(mEntities.contains(index.internalId())); - return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast()); + return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast()); } if (role == ChildrenFetchedRole) { return childrenFetched(index); @@ -226,7 +226,7 @@ void ModelResult::setFetcher(const std::function -void ModelResult::setEmitter(const typename Akonadi2::ResultEmitter::Ptr &emitter) +void ModelResult::setEmitter(const typename Sink::ResultEmitter::Ptr &emitter) { setFetcher([this](const Ptr &parent) {mEmitter->fetch(parent);}); emitter->onAdded([this](const Ptr &value) { @@ -272,7 +272,7 @@ void ModelResult::modify(const Ptr &value) emit dataChanged(idx, idx); } -template class ModelResult; -template class ModelResult; -template class ModelResult; -template class ModelResult; +template class ModelResult; +template class ModelResult; +template class ModelResult; +template class ModelResult; diff --git a/common/modelresult.h b/common/modelresult.h index ec62a67..062517f 100644 --- a/common/modelresult.h +++ b/common/modelresult.h @@ -38,9 +38,9 @@ public: DomainObjectBaseRole }; - ModelResult(const Akonadi2::Query &query, const QList &propertyColumns); + ModelResult(const Sink::Query &query, const QList &propertyColumns); - void setEmitter(const typename Akonadi2::ResultEmitter::Ptr &); + void setEmitter(const typename Sink::ResultEmitter::Ptr &); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -73,8 +73,8 @@ private: QSet mEntityChildrenFetched; QSet mEntityChildrenFetchComplete; QList mPropertyColumns; - Akonadi2::Query mQuery; + Sink::Query mQuery; std::function loadEntities; - typename Akonadi2::ResultEmitter::Ptr mEmitter; + typename Sink::ResultEmitter::Ptr mEmitter; }; diff --git a/common/notification.h b/common/notification.h index e1b5bff..ae24bd2 100644 --- a/common/notification.h +++ b/common/notification.h @@ -19,16 +19,16 @@ */ #pragma once -#include +#include #include -namespace Akonadi2 +namespace Sink { /** * A notification */ -class AKONADI2COMMON_EXPORT Notification +class SINKCOMMON_EXPORT Notification { public: QByteArray id; diff --git a/common/pipeline.cpp b/common/pipeline.cpp index a087def..401c26d 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -36,14 +36,14 @@ #include "definitions.h" #include "bufferutils.h" -namespace Akonadi2 +namespace Sink { class Pipeline::Private { public: Private(const QString &resourceName) - : storage(Akonadi2::storageLocation(), resourceName, Storage::ReadWrite), + : storage(Sink::storageLocation(), resourceName, Storage::ReadWrite), revisionChanged(false) { } @@ -86,7 +86,7 @@ void Pipeline::startTransaction() if (d->transaction) { return; } - d->transaction = std::move(storage().createTransaction(Akonadi2::Storage::ReadWrite)); + d->transaction = std::move(storage().createTransaction(Sink::Storage::ReadWrite)); } void Pipeline::commit() @@ -96,7 +96,7 @@ void Pipeline::commit() // for (auto processor : d->processors[bufferType]) { // processor->finalize(); // } - const auto revision = Akonadi2::Storage::maxRevision(d->transaction); + const auto revision = Sink::Storage::maxRevision(d->transaction); Trace() << "Committing " << revision; if (d->transaction) { d->transaction.commit(); @@ -120,14 +120,14 @@ Storage &Pipeline::storage() const void Pipeline::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid) { - d->transaction.openDatabase(bufferType + ".main").write(Akonadi2::Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), - [](const Akonadi2::Storage::Error &error) { + d->transaction.openDatabase(bufferType + ".main").write(Sink::Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), + [](const Sink::Storage::Error &error) { Warning() << "Failed to write entity"; } ); d->revisionChanged = true; - Akonadi2::Storage::setMaxRevision(d->transaction, newRevision); - Akonadi2::Storage::recordRevision(d->transaction, newRevision, uid, bufferType); + Sink::Storage::setMaxRevision(d->transaction, newRevision); + Sink::Storage::recordRevision(d->transaction, newRevision, uid, bufferType); } KAsync::Job Pipeline::newEntity(void const *command, size_t size) @@ -136,23 +136,23 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyCreateEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyCreateEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a create entity buffer"; return KAsync::error(0); } } - auto createEntity = Akonadi2::Commands::GetCreateEntity(command); + auto createEntity = Sink::Commands::GetCreateEntity(command); const bool replayToSource = createEntity->replayToSource(); const QByteArray bufferType = QByteArray(reinterpret_cast(createEntity->domainType()->Data()), createEntity->domainType()->size()); { flatbuffers::Verifier verifyer(reinterpret_cast(createEntity->delta()->Data()), createEntity->delta()->size()); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + if (!Sink::VerifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not an entity buffer"; return KAsync::error(0); } } - auto entity = Akonadi2::GetEntity(createEntity->delta()->Data()); + auto entity = Sink::GetEntity(createEntity->delta()->Data()); if (!entity->resource()->size() && !entity->local()->size()) { Warning() << "No local and no resource buffer while trying to create entity."; return KAsync::error(0); @@ -171,16 +171,16 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) key = QUuid::createUuid().toString().toUtf8(); } Q_ASSERT(!key.isEmpty()); - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Creation); + metadataBuilder.add_operation(Sink::Operation_Creation); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), entity->resource()->Data(), entity->resource()->size(), entity->local()->Data(), entity->local()->size()); @@ -194,14 +194,14 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) } Log() << "Pipeline: wrote entity: " << key << newRevision << bufferType; - d->transaction.openDatabase(bufferType + ".main").scan(Akonadi2::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, key](const QByteArray &, const QByteArray &value) -> bool { - auto entity = Akonadi2::GetEntity(value); + d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, key](const QByteArray &, const QByteArray &value) -> bool { + auto entity = Sink::GetEntity(value); auto adaptor = adaptorFactory->createAdaptor(*entity); for (auto processor : d->processors[bufferType]) { processor->newEntity(key, newRevision, *adaptor, d->transaction); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); return KAsync::start([newRevision](){ @@ -213,16 +213,16 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) { Trace() << "Pipeline: Modified Entity"; - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyModifyEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyModifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a modify entity buffer"; return KAsync::error(0); } } - auto modifyEntity = Akonadi2::Commands::GetModifyEntity(command); + auto modifyEntity = Sink::Commands::GetModifyEntity(command); Q_ASSERT(modifyEntity); const qint64 baseRevision = modifyEntity->revision(); @@ -236,7 +236,7 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) } { flatbuffers::Verifier verifyer(reinterpret_cast(modifyEntity->delta()->Data()), modifyEntity->delta()->size()); - if (!Akonadi2::VerifyEntityBuffer(verifyer)) { + if (!Sink::VerifyEntityBuffer(verifyer)) { Warning() << "invalid buffer, not an entity buffer"; return KAsync::error(0); } @@ -249,13 +249,13 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) return KAsync::error(0); } - auto diffEntity = Akonadi2::GetEntity(modifyEntity->delta()->Data()); + auto diffEntity = Sink::GetEntity(modifyEntity->delta()->Data()); Q_ASSERT(diffEntity); auto diff = adaptorFactory->createAdaptor(*diffEntity); - QSharedPointer current; + QSharedPointer current; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [¤t, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { @@ -273,8 +273,8 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) } //resource and uid don't matter at this point - const Akonadi2::ApplicationDomain::ApplicationDomainType existingObject("", "", newRevision, current); - auto newObject = Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(existingObject); + const Sink::ApplicationDomain::ApplicationDomainType existingObject("", "", newRevision, current); + auto newObject = Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(existingObject); //Apply diff //FIXME only apply the properties that are available in the buffer @@ -292,26 +292,26 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Modification); + metadataBuilder.add_operation(Sink::Operation_Modification); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; adaptorFactory->createBuffer(*newObject, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); storeNewRevision(newRevision, fbb, bufferType, key); Log() << "Pipeline: modified entity: " << key << newRevision << bufferType; - d->transaction.openDatabase(bufferType + ".main").scan(Akonadi2::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { - auto entity = Akonadi2::GetEntity(value); + d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { + auto entity = Sink::GetEntity(value); auto newEntity = adaptorFactory->createAdaptor(*entity); for (auto processor : d->processors[bufferType]) { processor->modifiedEntity(key, newRevision, *current, *newEntity, d->transaction); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); return KAsync::start([newRevision](){ @@ -325,12 +325,12 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) { flatbuffers::Verifier verifyer(reinterpret_cast(command), size); - if (!Akonadi2::Commands::VerifyDeleteEntityBuffer(verifyer)) { + if (!Sink::Commands::VerifyDeleteEntityBuffer(verifyer)) { Warning() << "invalid buffer, not a delete entity buffer"; return KAsync::error(0); } } - auto deleteEntity = Akonadi2::Commands::GetDeleteEntity(command); + auto deleteEntity = Sink::Commands::GetDeleteEntity(command); const bool replayToSource = deleteEntity->replayToSource(); const QByteArray bufferType = QByteArray(reinterpret_cast(deleteEntity->domainType()->Data()), deleteEntity->domainType()->size()); @@ -339,12 +339,12 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) bool found = false; bool alreadyRemoved = false; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [&found, &alreadyRemoved](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); - auto entity = Akonadi2::GetEntity(data.data()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); + auto entity = Sink::GetEntity(data.data()); if (entity && entity->metadata()) { - auto metadata = Akonadi2::GetMetadata(entity->metadata()->Data()); + auto metadata = Sink::GetMetadata(entity->metadata()->Data()); found = true; - if (metadata->operation() == Akonadi2::Operation_Removal) { + if (metadata->operation() == Sink::Operation_Removal) { alreadyRemoved = true; } @@ -364,16 +364,16 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) return KAsync::error(0); } - const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; + const qint64 newRevision = Sink::Storage::maxRevision(d->transaction) + 1; //Add metadata buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(newRevision); - metadataBuilder.add_operation(Akonadi2::Operation_Removal); + metadataBuilder.add_operation(Sink::Operation_Removal); metadataBuilder.add_replayToSource(replayToSource); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), 0, 0, 0, 0); @@ -384,16 +384,16 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) return KAsync::error(0); } - QSharedPointer current; + QSharedPointer current; d->transaction.openDatabase(bufferType + ".main").findLatest(key, [this, bufferType, newRevision, adaptorFactory, key, ¤t](const QByteArray &, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { current = adaptorFactory->createAdaptor(buffer.entity()); } return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { ErrorMsg() << "Failed to find value in pipeline: " << error.message; }); @@ -411,33 +411,33 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) void Pipeline::cleanupRevision(qint64 revision) { - const auto uid = Akonadi2::Storage::getUidFromRevision(d->transaction, revision); - const auto bufferType = Akonadi2::Storage::getTypeFromRevision(d->transaction, revision); + const auto uid = Sink::Storage::getUidFromRevision(d->transaction, revision); + const auto bufferType = Sink::Storage::getTypeFromRevision(d->transaction, revision); Trace() << "Cleaning up revision " << revision << uid << bufferType; d->transaction.openDatabase(bufferType + ".main").scan(uid, [&](const QByteArray &key, const QByteArray &data) -> bool { - Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + Sink::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; } else { - const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); + const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); const qint64 rev = metadata->revision(); //Remove old revisions, and the current if the entity has already been removed - if (rev < revision || metadata->operation() == Akonadi2::Operation_Removal) { - Akonadi2::Storage::removeRevision(d->transaction, rev); + if (rev < revision || metadata->operation() == Sink::Operation_Removal) { + Sink::Storage::removeRevision(d->transaction, rev); d->transaction.openDatabase(bufferType + ".main").remove(key); } } return true; - }, [](const Akonadi2::Storage::Error &error) { + }, [](const Sink::Storage::Error &error) { Warning() << "Error while reading: " << error.message; }, true); - Akonadi2::Storage::setCleanedUpRevision(d->transaction, revision); + Sink::Storage::setCleanedUpRevision(d->transaction, revision); } qint64 Pipeline::cleanedUpRevision() { - return Akonadi2::Storage::cleanedUpRevision(d->transaction); + return Sink::Storage::cleanedUpRevision(d->transaction); } Preprocessor::Preprocessor() @@ -457,5 +457,5 @@ void Preprocessor::finalize() { } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/pipeline.h b/common/pipeline.h index f11d880..60a5fa5 100644 --- a/common/pipeline.h +++ b/common/pipeline.h @@ -25,19 +25,19 @@ #include #include -#include +#include #include #include #include "domainadaptor.h" -namespace Akonadi2 +namespace Sink { class Preprocessor; -class AKONADI2COMMON_EXPORT Pipeline : public QObject +class SINKCOMMON_EXPORT Pipeline : public QObject { Q_OBJECT @@ -79,16 +79,16 @@ private: Private * const d; }; -class AKONADI2COMMON_EXPORT Preprocessor +class SINKCOMMON_EXPORT Preprocessor { public: Preprocessor(); virtual ~Preprocessor(); virtual void startBatch(); - virtual void newEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) = 0; - virtual void modifiedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) = 0; - virtual void deletedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) = 0; + virtual void newEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) = 0; + virtual void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) = 0; + virtual void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) = 0; virtual void finalize(); private: @@ -96,5 +96,5 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/query.h b/common/query.h index 1df32da..a0a50ba 100644 --- a/common/query.h +++ b/common/query.h @@ -24,7 +24,7 @@ #include #include "applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { /** * A query that matches a set of entities. @@ -64,7 +64,7 @@ public: return query; } - static Query ResourceFilter(const ApplicationDomain::AkonadiResource &entity) + static Query ResourceFilter(const ApplicationDomain::SinkResource &entity) { return ResourceFilter(entity.identifier()); } @@ -138,4 +138,4 @@ public: } -Q_DECLARE_OPERATORS_FOR_FLAGS(Akonadi2::Query::Flags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Sink::Query::Flags) diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 89610e3..25d69b1 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp @@ -26,7 +26,7 @@ #include "domainadaptor.h" #include "asyncutils.h" -using namespace Akonadi2; +using namespace Sink; /* * This class wraps the actual query implementation. @@ -38,34 +38,34 @@ template class QueryWorker : public QObject { public: - QueryWorker(const Akonadi2::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); + QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); virtual ~QueryWorker(); - qint64 executeIncrementalQuery(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider); - qint64 executeInitialQuery(const Akonadi2::Query &query, const typename DomainType::Ptr &parent, Akonadi2::ResultProviderInterface &resultProvider); + qint64 executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface &resultProvider); + qint64 executeInitialQuery(const Sink::Query &query, const typename DomainType::Ptr &parent, Sink::ResultProviderInterface &resultProvider); private: - static void replaySet(ResultSet &resultSet, Akonadi2::ResultProviderInterface &resultProvider, const QList &properties); + static void replaySet(ResultSet &resultSet, Sink::ResultProviderInterface &resultProvider, const QList &properties); - void readEntity(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback); + void readEntity(const Sink::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback); - ResultSet loadInitialResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters); - ResultSet loadIncrementalResultSet(qint64 baseRevision, const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters); + ResultSet loadInitialResultSet(const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters); + ResultSet loadIncrementalResultSet(qint64 baseRevision, const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters); - ResultSet filterSet(const ResultSet &resultSet, const std::function &filter, const Akonadi2::Storage::NamedDatabase &db, bool initialQuery); - std::function getFilter(const QSet remainingFilters, const Akonadi2::Query &query); - qint64 load(const Akonadi2::Query &query, const std::function &)> &baseSetRetriever, Akonadi2::ResultProviderInterface &resultProvider, bool initialQuery); + ResultSet filterSet(const ResultSet &resultSet, const std::function &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery); + std::function getFilter(const QSet remainingFilters, const Sink::Query &query); + qint64 load(const Sink::Query &query, const std::function &)> &baseSetRetriever, Sink::ResultProviderInterface &resultProvider, bool initialQuery); private: DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; QByteArray mResourceInstanceIdentifier; QByteArray mBufferType; - Akonadi2::Query mQuery; + Sink::Query mQuery; }; template -QueryRunner::QueryRunner(const Akonadi2::Query &query, const Akonadi2::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) +QueryRunner::QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &resourceAccess, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) : QueryRunnerBase(), mResourceAccess(resourceAccess), mResultProvider(new ResultProvider) @@ -107,7 +107,7 @@ QueryRunner::QueryRunner(const Akonadi2::Query &query, const Akonadi //Ensure the connection is open, if it wasn't already opened //TODO If we are not connected already, we have to check for the latest revision once connected, otherwise we could miss some updates mResourceAccess->open(); - QObject::connect(mResourceAccess.data(), &Akonadi2::ResourceAccess::revisionChanged, this, &QueryRunner::revisionChanged); + QObject::connect(mResourceAccess.data(), &Sink::ResourceAccess::revisionChanged, this, &QueryRunner::revisionChanged); } } @@ -118,26 +118,26 @@ QueryRunner::~QueryRunner() } template -typename Akonadi2::ResultEmitter::Ptr QueryRunner::emitter() +typename Sink::ResultEmitter::Ptr QueryRunner::emitter() { return mResultProvider->emitter(); } -static inline ResultSet fullScan(const Akonadi2::Storage::Transaction &transaction, const QByteArray &bufferType) +static inline ResultSet fullScan(const Sink::Storage::Transaction &transaction, const QByteArray &bufferType) { //TODO use a result set with an iterator, to read values on demand QVector keys; transaction.openDatabase(bufferType + ".main").scan(QByteArray(), [&](const QByteArray &key, const QByteArray &value) -> bool { //Skip internals - if (Akonadi2::Storage::isInternalKey(key)) { + if (Sink::Storage::isInternalKey(key)) { return true; } - keys << Akonadi2::Storage::uidFromKey(key); + keys << Sink::Storage::uidFromKey(key); return true; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { qWarning() << "Error during query: " << error.message; }); @@ -147,7 +147,7 @@ static inline ResultSet fullScan(const Akonadi2::Storage::Transaction &transacti template -QueryWorker::QueryWorker(const Akonadi2::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) +QueryWorker::QueryWorker(const Sink::Query &query, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &factory, const QByteArray &bufferType) : QObject(), mDomainTypeAdaptorFactory(factory), mResourceInstanceIdentifier(instanceIdentifier), @@ -164,23 +164,23 @@ QueryWorker::~QueryWorker() } template -void QueryWorker::replaySet(ResultSet &resultSet, Akonadi2::ResultProviderInterface &resultProvider, const QList &properties) +void QueryWorker::replaySet(ResultSet &resultSet, Sink::ResultProviderInterface &resultProvider, const QList &properties) { int counter = 0; - while (resultSet.next([&resultProvider, &counter, &properties](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool { + while (resultSet.next([&resultProvider, &counter, &properties](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &value, Sink::Operation operation) -> bool { counter++; switch (operation) { - case Akonadi2::Operation_Creation: + case Sink::Operation_Creation: // Trace() << "Got creation"; - resultProvider.add(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.add(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; - case Akonadi2::Operation_Modification: + case Sink::Operation_Modification: // Trace() << "Got modification"; - resultProvider.modify(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.modify(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; - case Akonadi2::Operation_Removal: + case Sink::Operation_Removal: // Trace() << "Got removal"; - resultProvider.remove(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); + resultProvider.remove(Sink::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation(*value, properties).template staticCast()); break; } return true; @@ -189,35 +189,35 @@ void QueryWorker::replaySet(ResultSet &resultSet, Akonadi2::ResultPr } template -void QueryWorker::readEntity(const Akonadi2::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback) +void QueryWorker::readEntity(const Sink::Storage::NamedDatabase &db, const QByteArray &key, const std::function &resultCallback) { //This only works for a 1:1 mapping of resource to domain types. //Not i.e. for tags that are stored as flags in each entity of an imap store. //additional properties that don't have a 1:1 mapping (such as separately stored tags), //could be added to the adaptor. db.findLatest(key, [=](const QByteArray &key, const QByteArray &value) -> bool { - Akonadi2::EntityBuffer buffer(value.data(), value.size()); - const Akonadi2::Entity &entity = buffer.entity(); - const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + Sink::EntityBuffer buffer(value.data(), value.size()); + const Sink::Entity &entity = buffer.entity(); + const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); Q_ASSERT(metadataBuffer); const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; - const auto operation = metadataBuffer ? metadataBuffer->operation() : Akonadi2::Operation_Creation; - resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mDomainTypeAdaptorFactory->createAdaptor(entity)), operation); + const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; + resultCallback(DomainType::Ptr::create(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, mDomainTypeAdaptorFactory->createAdaptor(entity)), operation); return false; }, - [](const Akonadi2::Storage::Error &error) { + [](const Sink::Storage::Error &error) { qWarning() << "Error during query: " << error.message; }); } template -ResultSet QueryWorker::loadInitialResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) +ResultSet QueryWorker::loadInitialResultSet(const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters) { if (!query.ids.isEmpty()) { return ResultSet(query.ids.toVector()); } QSet appliedFilters; - auto resultSet = Akonadi2::ApplicationDomain::TypeImplementation::queryIndexes(query, mResourceInstanceIdentifier, appliedFilters, transaction); + auto resultSet = Sink::ApplicationDomain::TypeImplementation::queryIndexes(query, mResourceInstanceIdentifier, appliedFilters, transaction); remainingFilters = query.propertyFilter.keys().toSet() - appliedFilters; //We do a full scan if there were no indexes available to create the initial set. @@ -229,24 +229,24 @@ ResultSet QueryWorker::loadInitialResultSet(const Akonadi2::Query &q } template -ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) +ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, const Sink::Query &query, Sink::Storage::Transaction &transaction, QSet &remainingFilters) { const auto bufferType = mBufferType; auto revisionCounter = QSharedPointer::create(baseRevision); remainingFilters = query.propertyFilter.keys().toSet(); return ResultSet([bufferType, revisionCounter, &transaction]() -> QByteArray { - const qint64 topRevision = Akonadi2::Storage::maxRevision(transaction); + const qint64 topRevision = Sink::Storage::maxRevision(transaction); //Spit out the revision keys one by one. while (*revisionCounter <= topRevision) { - const auto uid = Akonadi2::Storage::getUidFromRevision(transaction, *revisionCounter); - const auto type = Akonadi2::Storage::getTypeFromRevision(transaction, *revisionCounter); + const auto uid = Sink::Storage::getUidFromRevision(transaction, *revisionCounter); + const auto type = Sink::Storage::getTypeFromRevision(transaction, *revisionCounter); // Trace() << "Revision" << *revisionCounter << type << uid; if (type != bufferType) { //Skip revision *revisionCounter += 1; continue; } - const auto key = Akonadi2::Storage::assembleKey(uid, *revisionCounter); + const auto key = Sink::Storage::assembleKey(uid, *revisionCounter); *revisionCounter += 1; return key; } @@ -257,21 +257,21 @@ ResultSet QueryWorker::loadIncrementalResultSet(qint64 baseRevision, } template -ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const std::function &filter, const Akonadi2::Storage::NamedDatabase &db, bool initialQuery) +ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const std::function &filter, const Sink::Storage::NamedDatabase &db, bool initialQuery) { auto resultSetPtr = QSharedPointer::create(resultSet); //Read through the source values and return whatever matches the filter - std::function)> generator = [this, resultSetPtr, &db, filter, initialQuery](std::function callback) -> bool { + std::function)> generator = [this, resultSetPtr, &db, filter, initialQuery](std::function callback) -> bool { if (resultSetPtr->next()) { //readEntity is only necessary if we actually want to filter or know the operation type (but not a big deal if we do it always I guess) - readEntity(db, resultSetPtr->id(), [this, filter, callback, initialQuery](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Akonadi2::Operation operation) { + readEntity(db, resultSetPtr->id(), [this, filter, callback, initialQuery](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject, Sink::Operation operation) { //Always remove removals, they probably don't match due to non-available properties - if (filter(domainObject) || operation == Akonadi2::Operation_Removal) { + if (filter(domainObject) || operation == Sink::Operation_Removal) { if (initialQuery) { //We're not interested in removals during the initial query - if (operation != Akonadi2::Operation_Removal) { - callback(domainObject, Akonadi2::Operation_Creation); + if (operation != Sink::Operation_Removal) { + callback(domainObject, Sink::Operation_Creation); } } else { callback(domainObject, operation); @@ -287,9 +287,9 @@ ResultSet QueryWorker::filterSet(const ResultSet &resultSet, const s } template -std::function QueryWorker::getFilter(const QSet remainingFilters, const Akonadi2::Query &query) +std::function QueryWorker::getFilter(const QSet remainingFilters, const Sink::Query &query) { - return [remainingFilters, query](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { + return [remainingFilters, query](const Sink::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { if (!query.ids.isEmpty()) { if (!query.ids.contains(domainObject->identifier())) { return false; @@ -312,32 +312,32 @@ std::function -qint64 QueryWorker::load(const Akonadi2::Query &query, const std::function &)> &baseSetRetriever, Akonadi2::ResultProviderInterface &resultProvider, bool initialQuery) +qint64 QueryWorker::load(const Sink::Query &query, const std::function &)> &baseSetRetriever, Sink::ResultProviderInterface &resultProvider, bool initialQuery) { - Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier); - storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) { + Sink::Storage storage(Sink::storageLocation(), mResourceInstanceIdentifier); + storage.setDefaultErrorHandler([](const Sink::Storage::Error &error) { Warning() << "Error during query: " << error.store << error.message; }); - auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); + auto transaction = storage.createTransaction(Sink::Storage::ReadOnly); auto db = transaction.openDatabase(mBufferType + ".main"); QSet remainingFilters; auto resultSet = baseSetRetriever(transaction, remainingFilters); auto filteredSet = filterSet(resultSet, getFilter(remainingFilters, query), db, initialQuery); replaySet(filteredSet, resultProvider, query.requestedProperties); - resultProvider.setRevision(Akonadi2::Storage::maxRevision(transaction)); - return Akonadi2::Storage::maxRevision(transaction); + resultProvider.setRevision(Sink::Storage::maxRevision(transaction)); + return Sink::Storage::maxRevision(transaction); } template -qint64 QueryWorker::executeIncrementalQuery(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface &resultProvider) +qint64 QueryWorker::executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface &resultProvider) { QTime time; time.start(); const qint64 baseRevision = resultProvider.revision() + 1; Trace() << "Running incremental query " << baseRevision; - auto revision = load(query, [&](Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { + auto revision = load(query, [&](Sink::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { return loadIncrementalResultSet(baseRevision, query, transaction, remainingFilters); }, resultProvider, false); Trace() << "Incremental query took: " << time.elapsed() << " ms"; @@ -345,7 +345,7 @@ qint64 QueryWorker::executeIncrementalQuery(const Akonadi2::Query &q } template -qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query, const typename DomainType::Ptr &parent, Akonadi2::ResultProviderInterface &resultProvider) +qint64 QueryWorker::executeInitialQuery(const Sink::Query &query, const typename DomainType::Ptr &parent, Sink::ResultProviderInterface &resultProvider) { QTime time; time.start(); @@ -360,7 +360,7 @@ qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query modifiedQuery.propertyFilter.insert(query.parentProperty, QVariant()); } } - auto revision = load(modifiedQuery, [&](Akonadi2::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { + auto revision = load(modifiedQuery, [&](Sink::Storage::Transaction &transaction, QSet &remainingFilters) -> ResultSet { return loadInitialResultSet(modifiedQuery, transaction, remainingFilters); }, resultProvider, true); Trace() << "Initial query took: " << time.elapsed() << " ms"; @@ -368,9 +368,9 @@ qint64 QueryWorker::executeInitialQuery(const Akonadi2::Query &query return revision; } -template class QueryRunner; -template class QueryRunner; -template class QueryRunner; -template class QueryWorker; -template class QueryWorker; -template class QueryWorker; +template class QueryRunner; +template class QueryRunner; +template class QueryRunner; +template class QueryWorker; +template class QueryWorker; +template class QueryWorker; diff --git a/common/queryrunner.h b/common/queryrunner.h index aba7912..0ee6a81 100644 --- a/common/queryrunner.h +++ b/common/queryrunner.h @@ -79,13 +79,13 @@ template class QueryRunner : public QueryRunnerBase { public: - QueryRunner(const Akonadi2::Query &query, const Akonadi2::ResourceAccessInterface::Ptr &, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); + QueryRunner(const Sink::Query &query, const Sink::ResourceAccessInterface::Ptr &, const QByteArray &instanceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &, const QByteArray &bufferType); virtual ~QueryRunner(); - typename Akonadi2::ResultEmitter::Ptr emitter(); + typename Sink::ResultEmitter::Ptr emitter(); private: - QSharedPointer mResourceAccess; - QSharedPointer > mResultProvider; + QSharedPointer mResourceAccess; + QSharedPointer > mResultProvider; }; diff --git a/common/queuedcommand.fbs b/common/queuedcommand.fbs index 0ca899f..06226d3 100644 --- a/common/queuedcommand.fbs +++ b/common/queuedcommand.fbs @@ -1,4 +1,4 @@ -namespace Akonadi2; +namespace Sink; table QueuedCommand { commandId: int; diff --git a/common/resource.cpp b/common/resource.cpp index 4541726..8c448a8 100644 --- a/common/resource.cpp +++ b/common/resource.cpp @@ -27,7 +27,7 @@ #include "facadefactory.h" -namespace Akonadi2 +namespace Sink { Resource::Resource() @@ -94,8 +94,8 @@ ResourceFactory *ResourceFactory::load(const QString &resourceName) if (path.endsWith(QLatin1String("plugins"))) { QDir pluginDir(path); //TODO: centralize this so that it is easy to change centrally - // also ref'd in cmake as ${AKONADI_RESOURCE_PLUGINS_PATH} - pluginDir.cd(QStringLiteral("akonadi2")); + // also ref'd in cmake as ${SINK_RESOURCE_PLUGINS_PATH} + pluginDir.cd(QStringLiteral("sink")); pluginDir.cd(QStringLiteral("resources")); for (const QString &fileName: pluginDir.entryList(QDir::Files)) { @@ -128,4 +128,4 @@ ResourceFactory *ResourceFactory::load(const QString &resourceName) return nullptr; } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/resource.h b/common/resource.h index 2ae71a0..30d6c46 100644 --- a/common/resource.h +++ b/common/resource.h @@ -19,19 +19,19 @@ */ #pragma once -#include +#include #include #include "notification.h" -namespace Akonadi2 +namespace Sink { class FacadeFactory; /** * Resource interface */ -class AKONADI2COMMON_EXPORT Resource : public QObject +class SINKCOMMON_EXPORT Resource : public QObject { Q_OBJECT public: @@ -83,8 +83,8 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink -Q_DECLARE_INTERFACE(Akonadi2::ResourceFactory, "org.kde.akonadi2.resourcefactory") +Q_DECLARE_INTERFACE(Sink::ResourceFactory, "org.kde.sink.resourcefactory") diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 6592699..0c435c9 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -43,9 +43,9 @@ #include #undef Trace -#define Trace() Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess") +#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess") #undef Log -#define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") +#define Log(IDENTIFIER) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") static void queuedInvoke(const std::function &f, QObject *context = 0) { @@ -57,7 +57,7 @@ static void queuedInvoke(const std::function &f, QObject *context = 0) timer->start(0); } -namespace Akonadi2 +namespace Sink { struct QueuedCommand @@ -205,7 +205,7 @@ KAsync::Job ResourceAccess::Private::initializeSocket() QStringList args; args << resourceInstanceIdentifier; qint64 pid = 0; - if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { + if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { Trace() << "Started resource " << pid; tryToConnect() .then([&future]() { @@ -298,8 +298,8 @@ KAsync::Job ResourceAccess::synchronizeResource(bool sourceSync, bool loca { Trace() << "Sending synchronize command: " << sourceSync << localSync; flatbuffers::FlatBufferBuilder fbb; - auto command = Akonadi2::Commands::CreateSynchronize(fbb, sourceSync, localSync); - Akonadi2::Commands::FinishSynchronizeBuffer(fbb, command); + auto command = Sink::Commands::CreateSynchronize(fbb, sourceSync, localSync); + Sink::Commands::FinishSynchronizeBuffer(fbb, command); open(); return sendCommand(Commands::SynchronizeCommand, fbb); } @@ -309,11 +309,11 @@ KAsync::Job ResourceAccess::sendCreateCommand(const QByteArray &resourceBu flatbuffers::FlatBufferBuilder fbb; //This is the resource buffer type and not the domain type auto type = fbb.CreateString(resourceBufferType.constData()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, 0, type, delta); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); + auto location = Sink::Commands::CreateCreateEntity(fbb, 0, type, delta); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); + return sendCommand(Sink::Commands::CreateEntityCommand, fbb); } KAsync::Job ResourceAccess::sendModifyCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType, const QByteArrayList &deletedProperties, const QByteArray &buffer) @@ -324,11 +324,11 @@ KAsync::Job ResourceAccess::sendModifyCommand(const QByteArray &uid, qint6 auto type = fbb.CreateString(resourceBufferType.constData()); //FIXME auto deletions = 0; - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta); - Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); + auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta); + Sink::Commands::FinishModifyEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::ModifyEntityCommand, fbb); + return sendCommand(Sink::Commands::ModifyEntityCommand, fbb); } KAsync::Job ResourceAccess::sendDeleteCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType) @@ -337,19 +337,19 @@ KAsync::Job ResourceAccess::sendDeleteCommand(const QByteArray &uid, qint6 auto entityId = fbb.CreateString(uid.constData()); //This is the resource buffer type and not the domain type auto type = fbb.CreateString(resourceBufferType.constData()); - auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type); - Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); + auto location = Sink::Commands::CreateDeleteEntity(fbb, revision, entityId, type); + Sink::Commands::FinishDeleteEntityBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::DeleteEntityCommand, fbb); + return sendCommand(Sink::Commands::DeleteEntityCommand, fbb); } KAsync::Job ResourceAccess::sendRevisionReplayedCommand(qint64 revision) { flatbuffers::FlatBufferBuilder fbb; - auto location = Akonadi2::Commands::CreateRevisionReplayed(fbb, revision); - Akonadi2::Commands::FinishRevisionReplayedBuffer(fbb, location); + auto location = Sink::Commands::CreateRevisionReplayed(fbb, revision); + Sink::Commands::FinishRevisionReplayedBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::RevisionReplayedCommand, fbb); + return sendCommand(Sink::Commands::RevisionReplayedCommand, fbb); } KAsync::Job ResourceAccess::sendInspectionCommand(const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) @@ -365,10 +365,10 @@ KAsync::Job ResourceAccess::sendInspectionCommand(const QByteArray &inspec s << expectedValue; auto expected = fbb.CreateString(array.toStdString()); - auto location = Akonadi2::Commands::CreateInspection (fbb, id, 0, entity, domain, prop, expected); - Akonadi2::Commands::FinishInspectionBuffer(fbb, location); + auto location = Sink::Commands::CreateInspection (fbb, id, 0, entity, domain, prop, expected); + Sink::Commands::FinishInspectionBuffer(fbb, location); open(); - return sendCommand(Akonadi2::Commands::InspectionCommand, fbb); + return sendCommand(Sink::Commands::InspectionCommand, fbb); } void ResourceAccess::open() @@ -412,7 +412,7 @@ void ResourceAccess::sendCommand(const QSharedPointer &command) //TODO: we should have a timeout for commands d->messageId++; const auto messageId = d->messageId; - log(QString("Sending command \"%1\" with messageId %2").arg(QString(Akonadi2::Commands::name(command->commandId))).arg(d->messageId)); + log(QString("Sending command \"%1\" with messageId %2").arg(QString(Sink::Commands::name(command->commandId))).arg(d->messageId)); Q_ASSERT(command->callback); registerCallback(d->messageId, [this, messageId, command](int errorCode, QString errorMessage) { Trace() << "Command complete " << messageId; @@ -457,8 +457,8 @@ void ResourceAccess::connected() { flatbuffers::FlatBufferBuilder fbb; auto name = fbb.CreateString(QString("PID: %1 ResourceAccess: %2").arg(QCoreApplication::applicationPid()).arg(reinterpret_cast(this)).toLatin1()); - auto command = Akonadi2::Commands::CreateHandshake(fbb, name); - Akonadi2::Commands::FinishHandshakeBuffer(fbb, command); + auto command = Sink::Commands::CreateHandshake(fbb, name); + Sink::Commands::FinishHandshakeBuffer(fbb, command); Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb); } @@ -543,11 +543,11 @@ bool ResourceAccess::processMessageBuffer() case Commands::NotificationCommand: { auto buffer = Commands::GetNotification(d->partialMessageBuffer.constData() + headerSize); switch (buffer->type()) { - case Akonadi2::Commands::NotificationType::NotificationType_Shutdown: + case Sink::Commands::NotificationType::NotificationType_Shutdown: Log(d->resourceInstanceIdentifier) << "Received shutdown notification."; close(); break; - case Akonadi2::Commands::NotificationType::NotificationType_Inspection: { + case Sink::Commands::NotificationType::NotificationType_Inspection: { Log(d->resourceInstanceIdentifier) << "Received inspection notification."; Notification n; if (buffer->identifier()) { diff --git a/common/resourceaccess.h b/common/resourceaccess.h index 2fe83ed..73b676b 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h @@ -29,7 +29,7 @@ #include #include "notification.h" -namespace Akonadi2 +namespace Sink { struct QueuedCommand; diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index a0f39a8..a34340b 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp @@ -25,12 +25,12 @@ static QSharedPointer getSettings() { - return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/resources.ini", QSettings::IniFormat); + return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/resources.ini", QSettings::IniFormat); } static QSharedPointer getResourceConfig(const QByteArray &identifier) { - return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + identifier, QSettings::IniFormat); + return QSharedPointer::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/" + identifier, QSettings::IniFormat); } QByteArray ResourceConfig::newIdentifier(const QByteArray &type) diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 20d9a7c..414e390 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -25,7 +25,7 @@ #include ResourceFacade::ResourceFacade(const QByteArray &) - : Akonadi2::StoreFacade() + : Sink::StoreFacade() { } @@ -35,7 +35,7 @@ ResourceFacade::~ResourceFacade() } -KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::create(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray type = resource.getProperty("type").toByteArray(); @@ -57,7 +57,7 @@ KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::Akon }); } -KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::modify(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.identifier(); @@ -79,7 +79,7 @@ KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::Akon }); } -KAsync::Job ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) +KAsync::Job ResourceFacade::remove(const Sink::ApplicationDomain::SinkResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.identifier(); @@ -89,18 +89,18 @@ KAsync::Job ResourceFacade::remove(const Akonadi2::ApplicationDomain::Akon } ResourceConfig::removeResource(identifier); //TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) - QDir dir(Akonadi2::storageLocation()); + QDir dir(Sink::storageLocation()); for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { - Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); } }); } -QPair, typename Akonadi2::ResultEmitter::Ptr > ResourceFacade::load(const Akonadi2::Query &query) +QPair, typename Sink::ResultEmitter::Ptr > ResourceFacade::load(const Sink::Query &query) { - auto resultProvider = new Akonadi2::ResultProvider(); + auto resultProvider = new Sink::ResultProvider(); auto emitter = resultProvider->emitter(); - resultProvider->setFetcher([](const QSharedPointer &) {}); + resultProvider->setFetcher([](const QSharedPointer &) {}); resultProvider->onDone([resultProvider]() { delete resultProvider; }); @@ -109,13 +109,13 @@ QPair, typename Akonadi2::ResultEmitter::create()); + auto resource = Sink::ApplicationDomain::SinkResource::Ptr::create("", res, 0, QSharedPointer::create()); resource->setProperty("type", type); resultProvider->add(resource); } } //TODO initialResultSetComplete should be implicit - resultProvider->initialResultSetComplete(Akonadi2::ApplicationDomain::AkonadiResource::Ptr()); + resultProvider->initialResultSetComplete(Sink::ApplicationDomain::SinkResource::Ptr()); resultProvider->complete(); }); return qMakePair(job, emitter); diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 99ec632..5ddaa79 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h @@ -25,19 +25,19 @@ #include "common/resultprovider.h" #include "common/domain/applicationdomaintype.h" -namespace Akonadi2 { +namespace Sink { class Query; class Inspection; } -class ResourceFacade : public Akonadi2::StoreFacade +class ResourceFacade : public Sink::StoreFacade { public: ResourceFacade(const QByteArray &instanceIdentifier); virtual ~ResourceFacade(); - KAsync::Job create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - KAsync::Job modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - KAsync::Job remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) Q_DECL_OVERRIDE; - QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE; + KAsync::Job create(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + KAsync::Job modify(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + KAsync::Job remove(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; + QPair, typename Sink::ResultEmitter::Ptr > load(const Sink::Query &query) Q_DECL_OVERRIDE; }; diff --git a/common/resultprovider.h b/common/resultprovider.h index a064ab5..6958dbf 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h @@ -29,7 +29,7 @@ using namespace async; -namespace Akonadi2 { +namespace Sink { /** * Query result set diff --git a/common/resultset.h b/common/resultset.h index 746b94b..ec399fc 100644 --- a/common/resultset.h +++ b/common/resultset.h @@ -37,7 +37,7 @@ class ResultSet { } - ResultSet(const std::function)> &generator) + ResultSet(const std::function)> &generator) : mIt(nullptr), mValueGenerator(generator) { @@ -76,7 +76,7 @@ class ResultSet { return false; } - bool next(std::function callback) + bool next(std::function callback) { Q_ASSERT(mValueGenerator); return mValueGenerator(callback); @@ -116,6 +116,6 @@ class ResultSet { QVector::ConstIterator mIt; QByteArray mCurrentValue; std::function mGenerator; - std::function)> mValueGenerator; + std::function)> mValueGenerator; }; diff --git a/common/storage.h b/common/storage.h index daeace8..2d34f1f 100644 --- a/common/storage.h +++ b/common/storage.h @@ -21,15 +21,15 @@ #pragma once -#include +#include #include #include #include -namespace Akonadi2 +namespace Sink { -class AKONADI2COMMON_EXPORT Storage { +class SINKCOMMON_EXPORT Storage { public: enum AccessMode { ReadOnly, ReadWrite }; @@ -180,16 +180,16 @@ public: qint64 diskUsage() const; void removeFromDisk() const; - static qint64 maxRevision(const Akonadi2::Storage::Transaction &); - static void setMaxRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static qint64 maxRevision(const Sink::Storage::Transaction &); + static void setMaxRevision(Sink::Storage::Transaction &, qint64 revision); - static qint64 cleanedUpRevision(const Akonadi2::Storage::Transaction &); - static void setCleanedUpRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static qint64 cleanedUpRevision(const Sink::Storage::Transaction &); + static void setCleanedUpRevision(Sink::Storage::Transaction &, qint64 revision); - static QByteArray getUidFromRevision(const Akonadi2::Storage::Transaction &, qint64 revision); - static QByteArray getTypeFromRevision(const Akonadi2::Storage::Transaction &, qint64 revision); - static void recordRevision(Akonadi2::Storage::Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); - static void removeRevision(Akonadi2::Storage::Transaction &, qint64 revision); + static QByteArray getUidFromRevision(const Sink::Storage::Transaction &, qint64 revision); + static QByteArray getTypeFromRevision(const Sink::Storage::Transaction &, qint64 revision); + static void recordRevision(Sink::Storage::Transaction &, qint64 revision, const QByteArray &uid, const QByteArray &type); + static void removeRevision(Sink::Storage::Transaction &, qint64 revision); bool exists() const; @@ -208,5 +208,5 @@ private: Private * const d; }; -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/storage_common.cpp b/common/storage_common.cpp index e534bc1..ea97ac2 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -23,7 +23,7 @@ #include "log.h" -namespace Akonadi2 +namespace Sink { static const char *s_internalPrefix = "__internal"; @@ -52,45 +52,45 @@ std::function Storage::defaultErrorHandler() return basicErrorHandler(); } -void Storage::setMaxRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::setMaxRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase().write("__internal_maxRevision", QByteArray::number(revision)); } -qint64 Storage::maxRevision(const Akonadi2::Storage::Transaction &transaction) +qint64 Storage::maxRevision(const Sink::Storage::Transaction &transaction) { qint64 r = 0; transaction.openDatabase().scan("__internal_maxRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { r = revision.toLongLong(); return false; }, [](const Error &error){ - if (error.code != Akonadi2::Storage::NotFound) { + if (error.code != Sink::Storage::NotFound) { Warning() << "Coultn'd find the maximum revision."; } }); return r; } -void Storage::setCleanedUpRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::setCleanedUpRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase().write("__internal_cleanedUpRevision", QByteArray::number(revision)); } -qint64 Storage::cleanedUpRevision(const Akonadi2::Storage::Transaction &transaction) +qint64 Storage::cleanedUpRevision(const Sink::Storage::Transaction &transaction) { qint64 r = 0; transaction.openDatabase().scan("__internal_cleanedUpRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { r = revision.toLongLong(); return false; }, [](const Error &error){ - if (error.code != Akonadi2::Storage::NotFound) { + if (error.code != Sink::Storage::NotFound) { Warning() << "Coultn'd find the maximum revision."; } }); return r; } -QByteArray Storage::getUidFromRevision(const Akonadi2::Storage::Transaction &transaction, qint64 revision) +QByteArray Storage::getUidFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) { QByteArray uid; transaction.openDatabase("revisions").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { @@ -102,7 +102,7 @@ QByteArray Storage::getUidFromRevision(const Akonadi2::Storage::Transaction &tra return uid; } -QByteArray Storage::getTypeFromRevision(const Akonadi2::Storage::Transaction &transaction, qint64 revision) +QByteArray Storage::getTypeFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) { QByteArray type; transaction.openDatabase("revisionType").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { @@ -114,14 +114,14 @@ QByteArray Storage::getTypeFromRevision(const Akonadi2::Storage::Transaction &tr return type; } -void Storage::recordRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) +void Storage::recordRevision(Sink::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) { //TODO use integerkeys transaction.openDatabase("revisions").write(QByteArray::number(revision), uid); transaction.openDatabase("revisionType").write(QByteArray::number(revision), type); } -void Storage::removeRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) +void Storage::removeRevision(Sink::Storage::Transaction &transaction, qint64 revision) { transaction.openDatabase("revisions").remove(QByteArray::number(revision)); } @@ -162,9 +162,9 @@ bool Storage::NamedDatabase::contains(const QByteArray &uid) scan(uid, [&found](const QByteArray &, const QByteArray &) -> bool { found = true; return false; - }, [this](const Akonadi2::Storage::Error &error) { + }, [this](const Sink::Storage::Error &error) { }, true); return found; } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 79f32ba..6539eb0 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -33,7 +33,7 @@ #include -namespace Akonadi2 +namespace Sink { int getErrorCode(int e) @@ -615,4 +615,4 @@ void Storage::removeFromDisk() const mdb_env_close(env); } -} // namespace Akonadi2 +} // namespace Sink diff --git a/common/synclistresult.h b/common/synclistresult.h index 3ae2bed..055714f 100644 --- a/common/synclistresult.h +++ b/common/synclistresult.h @@ -19,7 +19,7 @@ namespace async { template class SyncListResult : public QList { public: - SyncListResult(const QSharedPointer > &emitter) + SyncListResult(const QSharedPointer > &emitter) :QList(), mEmitter(emitter) { @@ -66,7 +66,7 @@ public: } private: - QSharedPointer > mEmitter; + QSharedPointer > mEmitter; std::function eventLoopAborter; }; diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 19e0507..03ad8f7 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp @@ -31,7 +31,7 @@ TypeIndex::TypeIndex(const QByteArray &type) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); if (value.isValid()) { Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); @@ -46,7 +46,7 @@ void TypeIndex::addProperty(const QByteArray &property) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { // Trace() << "Indexing " << mType + ".index." + property << value.toByteArray(); if (value.isValid()) { Index(mType + ".index." + property, transaction).add(value.toByteArray(), identifier); @@ -61,7 +61,7 @@ void TypeIndex::addProperty(const QByteArray &property) template<> void TypeIndex::addProperty(const QByteArray &property) { - auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Akonadi2::Storage::Transaction &transaction) { + auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { const auto date = value.toDateTime(); // Trace() << "Indexing " << mType + ".index." + property << date.toString(); if (date.isValid()) { @@ -72,7 +72,7 @@ void TypeIndex::addProperty(const QByteArray &property) mProperties << property; } -void TypeIndex::add(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeIndex::add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { for (const auto &property : mProperties) { const auto value = bufferAdaptor.getProperty(property); @@ -81,7 +81,7 @@ void TypeIndex::add(const QByteArray &identifier, const Akonadi2::ApplicationDom } } -void TypeIndex::remove(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +void TypeIndex::remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { for (const auto &property : mProperties) { const auto value = bufferAdaptor.getProperty(property); @@ -94,7 +94,7 @@ void TypeIndex::remove(const QByteArray &identifier, const Akonadi2::Application } } -ResultSet TypeIndex::query(const Akonadi2::Query &query, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +ResultSet TypeIndex::query(const Sink::Query &query, QSet &appliedFilters, Sink::Storage::Transaction &transaction) { QVector keys; for (const auto &property : mProperties) { diff --git a/common/typeindex.h b/common/typeindex.h index fb66c2c..b8a6e39 100644 --- a/common/typeindex.h +++ b/common/typeindex.h @@ -32,14 +32,14 @@ public: template void addProperty(const QByteArray &property); - void add(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); - void remove(const QByteArray &identifier, const Akonadi2::ApplicationDomain::BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + void add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); + void remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); - ResultSet query(const Akonadi2::Query &query, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); + ResultSet query(const Sink::Query &query, QSet &appliedFilters, Sink::Storage::Transaction &transaction); private: QByteArray mType; QByteArrayList mProperties; - QHash > mIndexer; + QHash > mIndexer; }; diff --git a/examples/client/CMakeLists.txt b/examples/client/CMakeLists.txt index 97b5ad2..85840c4 100644 --- a/examples/client/CMakeLists.txt +++ b/examples/client/CMakeLists.txt @@ -1,8 +1,8 @@ -project(akonadi2_client) +project(sink_client) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) add_executable(${PROJECT_NAME} main.cpp console.cpp) -target_link_libraries(${PROJECT_NAME} akonadi2common) +target_link_libraries(${PROJECT_NAME} sinkcommon) qt5_use_modules(${PROJECT_NAME} Widgets Network) install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 6660f86..f437c19 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -34,64 +34,64 @@ #include /** - * A small abstraction layer to use the akonadi store with the type available as string. + * A small abstraction layer to use the sink store with the type available as string. */ class StoreBase { public: - virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; - virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; - virtual KAsync::Job create(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job modify(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual KAsync::Job remove(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; - virtual QSharedPointer loadModel(const Akonadi2::Query &query) = 0; + 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; + virtual KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; + virtual KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; + virtual QSharedPointer loadModel(const Sink::Query &query) = 0; }; template class Store : public StoreBase { public: - Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { + Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { return T::Ptr::create(); } - Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { - return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer::create()); + 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 Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::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 Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::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 Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { - return Akonadi2::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 Akonadi2::Query &query) Q_DECL_OVERRIDE { - return Akonadi2::Store::loadModel(query); + QSharedPointer loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { + return Sink::Store::loadModel(query); } }; StoreBase& getStore(const QString &type) { if (type == "folder") { - static Store store; + static Store store; return store; } else if (type == "mail") { - static Store store; + static Store store; return store; } else if (type == "event") { - static Store store; + static Store store; return store; } else if (type == "resource") { - static Store store; + static Store store; return store; } Q_ASSERT(false); qWarning() << "Trying to get a store that doesn't exist, falling back to event"; - static Store store; + static Store store; return store; } @@ -118,17 +118,17 @@ public: auto syncButton = new QPushButton(this); syncButton->setText("Synchronize!"); QObject::connect(syncButton, &QPushButton::pressed, []() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; - Akonadi2::Store::synchronize(query).exec(); + Sink::Store::synchronize(query).exec(); }); auto removeButton = new QPushButton(this); removeButton->setText("Remove"); QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { for (auto index : modelView->selectionModel()->selectedIndexes()) { - auto object = index.data(Akonadi2::Store::DomainObjectRole).value(); - Akonadi2::Store::remove(*object).exec(); + auto object = index.data(Sink::Store::DomainObjectRole).value(); + Sink::Store::remove(*object).exec(); } }); @@ -142,7 +142,7 @@ public: }; -static QSharedPointer loadModel(const QString &type, Akonadi2::Query query) +static QSharedPointer loadModel(const QString &type, Sink::Query query) { QTime time; time.start(); @@ -187,13 +187,13 @@ int main(int argc, char *argv[]) QStringList args = cliOptions.positionalArguments(); if (cliOptions.isSet("debuglevel")) { - Akonadi2::Log::setDebugOutputLevel(static_cast(cliOptions.value("debuglevel").toInt())); + Sink::Log::setDebugOutputLevel(static_cast(cliOptions.value("debuglevel").toInt())); } auto type = !args.isEmpty() ? args.takeFirst() : QByteArray(); auto resources = args; - Akonadi2::Query query; + Sink::Query query; for (const auto &res : resources) { query.resources << res.toLatin1(); } @@ -208,13 +208,13 @@ int main(int argc, char *argv[]) model->fetchMore(model->index(i, 0, index)); } }); - auto view = QSharedPointer >::create(model.data()); + auto view = QSharedPointer >::create(model.data()); app.exec(); } else if (type == "mail") { - auto view = QSharedPointer >::create(model.data()); + auto view = QSharedPointer >::create(model.data()); app.exec(); } else if (type == "event") { - auto view = QSharedPointer >::create(model.data()); + auto view = QSharedPointer >::create(model.data()); app.exec(); } return 0; diff --git a/examples/dummyresource/CMakeLists.txt b/examples/dummyresource/CMakeLists.txt index 1e80f81..6ffac9a 100644 --- a/examples/dummyresource/CMakeLists.txt +++ b/examples/dummyresource/CMakeLists.txt @@ -1,4 +1,4 @@ -project(akonadi2_resource_dummy) +project(sink_resource_dummy) add_definitions(-DQT_PLUGIN) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) @@ -7,6 +7,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp dummystore.cpp) generate_flatbuffers(${PROJECT_NAME} dummycalendar) qt5_use_modules(${PROJECT_NAME} Core Network) -target_link_libraries(${PROJECT_NAME} akonadi2common) +target_link_libraries(${PROJECT_NAME} sinkcommon) -install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${AKONADI2_RESOURCE_PLUGINS_PATH}) +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) diff --git a/examples/dummyresource/domainadaptor.h b/examples/dummyresource/domainadaptor.h index e5856f8..e7098e9 100644 --- a/examples/dummyresource/domainadaptor.h +++ b/examples/dummyresource/domainadaptor.h @@ -26,21 +26,21 @@ #include "dummycalendar_generated.h" #include "entity_generated.h" -class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory +class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory { public: DummyEventAdaptorFactory(); virtual ~DummyEventAdaptorFactory() {}; }; -class DummyMailAdaptorFactory : public DomainTypeAdaptorFactory +class DummyMailAdaptorFactory : public DomainTypeAdaptorFactory { public: DummyMailAdaptorFactory(); virtual ~DummyMailAdaptorFactory() {}; }; -class DummyFolderAdaptorFactory : public DomainTypeAdaptorFactory +class DummyFolderAdaptorFactory : public DomainTypeAdaptorFactory { public: DummyFolderAdaptorFactory(); diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp index f337bdc..120498a 100644 --- a/examples/dummyresource/facade.cpp +++ b/examples/dummyresource/facade.cpp @@ -22,7 +22,7 @@ #include "domainadaptor.h" DummyResourceFacade::DummyResourceFacade(const QByteArray &instanceIdentifier) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create()) { } @@ -32,7 +32,7 @@ DummyResourceFacade::~DummyResourceFacade() DummyResourceMailFacade::DummyResourceMailFacade(const QByteArray &instanceIdentifier) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create()) { } @@ -42,7 +42,7 @@ DummyResourceMailFacade::~DummyResourceMailFacade() DummyResourceFolderFacade::DummyResourceFolderFacade(const QByteArray &instanceIdentifier) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create()) { } diff --git a/examples/dummyresource/facade.h b/examples/dummyresource/facade.h index b00e1d7..5e0096d 100644 --- a/examples/dummyresource/facade.h +++ b/examples/dummyresource/facade.h @@ -22,21 +22,21 @@ #include "common/facade.h" #include "common/domain/event.h" -class DummyResourceFacade : public Akonadi2::GenericFacade +class DummyResourceFacade : public Sink::GenericFacade { public: DummyResourceFacade(const QByteArray &instanceIdentifier); virtual ~DummyResourceFacade(); }; -class DummyResourceMailFacade : public Akonadi2::GenericFacade +class DummyResourceMailFacade : public Sink::GenericFacade { public: DummyResourceMailFacade(const QByteArray &instanceIdentifier); virtual ~DummyResourceMailFacade(); }; -class DummyResourceFolderFacade : public Akonadi2::GenericFacade +class DummyResourceFolderFacade : public Sink::GenericFacade { public: DummyResourceFolderFacade(const QByteArray &instanceIdentifier); diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index c43b5e6..31633d7 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -43,24 +43,24 @@ #define ENTITY_TYPE_MAIL "mail" #define ENTITY_TYPE_FOLDER "folder" -DummyResource::DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) - : Akonadi2::GenericResource(instanceIdentifier, pipeline), +DummyResource::DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) + : Sink::GenericResource(instanceIdentifier, pipeline), mEventAdaptorFactory(QSharedPointer::create()), mMailAdaptorFactory(QSharedPointer::create()), mFolderAdaptorFactory(QSharedPointer::create()) { addType(ENTITY_TYPE_MAIL, mMailAdaptorFactory, - QVector() << new DefaultIndexUpdater); + QVector() << new DefaultIndexUpdater); addType(ENTITY_TYPE_FOLDER, mFolderAdaptorFactory, - QVector() << new DefaultIndexUpdater); + QVector() << new DefaultIndexUpdater); addType(ENTITY_TYPE_EVENT, mEventAdaptorFactory, - QVector() << new DefaultIndexUpdater); + QVector() << new DefaultIndexUpdater); } -Akonadi2::ApplicationDomain::Event::Ptr DummyResource::createEvent(const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &transaction) +Sink::ApplicationDomain::Event::Ptr DummyResource::createEvent(const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &transaction) { static uint8_t rawData[100]; - auto event = Akonadi2::ApplicationDomain::Event::Ptr::create(); + auto event = Sink::ApplicationDomain::Event::Ptr::create(); event->setProperty("summary", data.value("summary").toString()); event->setProperty("remoteId", ridBuffer); event->setProperty("description", data.value("description").toString()); @@ -68,9 +68,9 @@ Akonadi2::ApplicationDomain::Event::Ptr DummyResource::createEvent(const QByteAr return event; } -Akonadi2::ApplicationDomain::Mail::Ptr DummyResource::createMail(const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &transaction) +Sink::ApplicationDomain::Mail::Ptr DummyResource::createMail(const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &transaction) { - auto mail = Akonadi2::ApplicationDomain::Mail::Ptr::create(); + auto mail = Sink::ApplicationDomain::Mail::Ptr::create(); mail->setProperty("subject", data.value("subject").toString()); mail->setProperty("senderEmail", data.value("senderEmail").toString()); mail->setProperty("senderName", data.value("senderName").toString()); @@ -81,19 +81,19 @@ Akonadi2::ApplicationDomain::Mail::Ptr DummyResource::createMail(const QByteArra return mail; } -Akonadi2::ApplicationDomain::Folder::Ptr DummyResource::createFolder(const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &transaction) +Sink::ApplicationDomain::Folder::Ptr DummyResource::createFolder(const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &transaction) { - auto folder = Akonadi2::ApplicationDomain::Folder::Ptr::create(); + auto folder = Sink::ApplicationDomain::Folder::Ptr::create(); folder->setProperty("name", data.value("name").toString()); folder->setProperty("icon", data.value("icon").toString()); if (!data.value("parent").toString().isEmpty()) { - auto akonadiId = resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toByteArray(), transaction); - folder->setProperty("parent", akonadiId); + auto sinkId = resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toByteArray(), transaction); + folder->setProperty("parent", sinkId); } return folder; } -void DummyResource::synchronize(const QByteArray &bufferType, const QMap > &data, Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function &data, Akonadi2::Storage::Transaction &)> createEntity) +void DummyResource::synchronize(const QByteArray &bufferType, const QMap > &data, Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function &data, Sink::Storage::Transaction &)> createEntity) { //TODO find items to remove for (auto it = data.constBegin(); it != data.constEnd(); it++) { @@ -103,26 +103,26 @@ void DummyResource::synchronize(const QByteArray &bufferType, const QMap DummyResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) +KAsync::Job DummyResource::synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) { Log() << " Synchronizing"; return KAsync::start([this, &mainStore, &synchronizationStore]() { - auto transaction = mainStore.createTransaction(Akonadi2::Storage::ReadOnly); - auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); - synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), transaction, synchronizationTransaction, *mEventAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &synchronizationTransaction) { + auto transaction = mainStore.createTransaction(Sink::Storage::ReadOnly); + auto synchronizationTransaction = synchronizationStore.createTransaction(Sink::Storage::ReadWrite); + synchronize(ENTITY_TYPE_EVENT, DummyStore::instance().events(), transaction, synchronizationTransaction, *mEventAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &synchronizationTransaction) { return createEvent(ridBuffer, data, synchronizationTransaction); }); - synchronize(ENTITY_TYPE_MAIL, DummyStore::instance().mails(), transaction, synchronizationTransaction, *mMailAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &synchronizationTransaction) { + synchronize(ENTITY_TYPE_MAIL, DummyStore::instance().mails(), transaction, synchronizationTransaction, *mMailAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &synchronizationTransaction) { return createMail(ridBuffer, data, synchronizationTransaction); }); - synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), transaction, synchronizationTransaction, *mFolderAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Akonadi2::Storage::Transaction &synchronizationTransaction) { + synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), transaction, synchronizationTransaction, *mFolderAdaptorFactory, [this](const QByteArray &ridBuffer, const QMap &data, Sink::Storage::Transaction &synchronizationTransaction) { return createFolder(ridBuffer, data, synchronizationTransaction); }); Log() << "Done Synchronizing"; }); } -KAsync::Job DummyResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job DummyResource::replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { Trace() << "Replaying " << key; return KAsync::null(); @@ -131,7 +131,7 @@ KAsync::Job DummyResource::replay(Akonadi2::Storage &synchronizationStore, void DummyResource::removeFromDisk(const QByteArray &instanceIdentifier) { GenericResource::removeFromDisk(instanceIdentifier); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::ReadWrite).removeFromDisk(); } KAsync::Job DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) @@ -151,20 +151,20 @@ KAsync::Job DummyResource::inspect(int inspectionType, const QByteArray &i } DummyResourceFactory::DummyResourceFactory(QObject *parent) - : Akonadi2::ResourceFactory(parent) + : Sink::ResourceFactory(parent) { } -Akonadi2::Resource *DummyResourceFactory::createResource(const QByteArray &instanceIdentifier) +Sink::Resource *DummyResourceFactory::createResource(const QByteArray &instanceIdentifier) { return new DummyResource(instanceIdentifier); } -void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) +void DummyResourceFactory::registerFacades(Sink::FacadeFactory &factory) { - factory.registerFacade(PLUGIN_NAME); - factory.registerFacade(PLUGIN_NAME); - factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); } diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 634829e..240bb9f 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h @@ -33,36 +33,36 @@ class DummyEventAdaptorFactory; class DummyMailAdaptorFactory; class DummyFolderAdaptorFactory; -class DummyResource : public Akonadi2::GenericResource +class DummyResource : public Sink::GenericResource { public: - DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); - KAsync::Job synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; + DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); + KAsync::Job synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) Q_DECL_OVERRIDE; using GenericResource::synchronizeWithSource; static void removeFromDisk(const QByteArray &instanceIdentifier); KAsync::Job inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; private: - KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; - Akonadi2::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap &data, Akonadi2::Storage::Transaction &); - Akonadi2::ApplicationDomain::Mail::Ptr createMail(const QByteArray &rid, const QMap &data, Akonadi2::Storage::Transaction &); - Akonadi2::ApplicationDomain::Folder::Ptr createFolder(const QByteArray &rid, const QMap &data, Akonadi2::Storage::Transaction &); - void synchronize(const QByteArray &bufferType, const QMap > &data, Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function &data, Akonadi2::Storage::Transaction &)> createEntity); + KAsync::Job replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; + Sink::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap &data, Sink::Storage::Transaction &); + Sink::ApplicationDomain::Mail::Ptr createMail(const QByteArray &rid, const QMap &data, Sink::Storage::Transaction &); + Sink::ApplicationDomain::Folder::Ptr createFolder(const QByteArray &rid, const QMap &data, Sink::Storage::Transaction &); + void synchronize(const QByteArray &bufferType, const QMap > &data, Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function &data, Sink::Storage::Transaction &)> createEntity); QSharedPointer mEventAdaptorFactory; QSharedPointer mMailAdaptorFactory; QSharedPointer mFolderAdaptorFactory; }; -class DummyResourceFactory : public Akonadi2::ResourceFactory +class DummyResourceFactory : public Sink::ResourceFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.dummy") - Q_INTERFACES(Akonadi2::ResourceFactory) + Q_INTERFACES(Sink::ResourceFactory) public: DummyResourceFactory(QObject *parent = 0); - Akonadi2::Resource *createResource(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; - void registerFacades(Akonadi2::FacadeFactory &factory) Q_DECL_OVERRIDE; + Sink::Resource *createResource(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; + void registerFacades(Sink::FacadeFactory &factory) Q_DECL_OVERRIDE; }; diff --git a/examples/maildirresource/CMakeLists.txt b/examples/maildirresource/CMakeLists.txt index 2340cf6..baacd44 100644 --- a/examples/maildirresource/CMakeLists.txt +++ b/examples/maildirresource/CMakeLists.txt @@ -1,4 +1,4 @@ -project(akonadi2_resource_maildir) +project(sink_resource_maildir) add_definitions(-DQT_PLUGIN) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) @@ -8,8 +8,8 @@ find_package(KF5 COMPONENTS REQUIRED Mime) add_library(${PROJECT_NAME} SHARED facade.cpp maildirresource.cpp domainadaptor.cpp) # generate_flatbuffers(${PROJECT_NAME} dummycalendar) qt5_use_modules(${PROJECT_NAME} Core Network) -target_link_libraries(${PROJECT_NAME} akonadi2common maildir KF5::Mime) +target_link_libraries(${PROJECT_NAME} sinkcommon maildir KF5::Mime) -install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${AKONADI2_RESOURCE_PLUGINS_PATH}) +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SINK_RESOURCE_PLUGINS_PATH}) add_subdirectory(libmaildir) diff --git a/examples/maildirresource/domainadaptor.h b/examples/maildirresource/domainadaptor.h index 0fc7108..700d2e5 100644 --- a/examples/maildirresource/domainadaptor.h +++ b/examples/maildirresource/domainadaptor.h @@ -23,14 +23,14 @@ #include "folder_generated.h" #include "dummy_generated.h" -class MaildirMailAdaptorFactory : public DomainTypeAdaptorFactory +class MaildirMailAdaptorFactory : public DomainTypeAdaptorFactory { public: MaildirMailAdaptorFactory(); virtual ~MaildirMailAdaptorFactory() {}; }; -class MaildirFolderAdaptorFactory : public DomainTypeAdaptorFactory +class MaildirFolderAdaptorFactory : public DomainTypeAdaptorFactory { public: MaildirFolderAdaptorFactory(); diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp index 3cf3fde..7178ab9 100644 --- a/examples/maildirresource/facade.cpp +++ b/examples/maildirresource/facade.cpp @@ -22,7 +22,7 @@ #include "domainadaptor.h" MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceIdentifier) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create()) { } @@ -32,7 +32,7 @@ MaildirResourceMailFacade::~MaildirResourceMailFacade() MaildirResourceFolderFacade::MaildirResourceFolderFacade(const QByteArray &instanceIdentifier) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create()) { } diff --git a/examples/maildirresource/facade.h b/examples/maildirresource/facade.h index 80f0d06..a243b0d 100644 --- a/examples/maildirresource/facade.h +++ b/examples/maildirresource/facade.h @@ -21,14 +21,14 @@ #include "common/facade.h" -class MaildirResourceMailFacade : public Akonadi2::GenericFacade +class MaildirResourceMailFacade : public Sink::GenericFacade { public: MaildirResourceMailFacade(const QByteArray &instanceIdentifier); virtual ~MaildirResourceMailFacade(); }; -class MaildirResourceFolderFacade : public Akonadi2::GenericFacade +class MaildirResourceFolderFacade : public Sink::GenericFacade { public: MaildirResourceFolderFacade(const QByteArray &instanceIdentifier); diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp index 28cf46e..3d4630f 100644 --- a/examples/maildirresource/libmaildir/maildir.cpp +++ b/examples/maildirresource/libmaildir/maildir.cpp @@ -688,7 +688,7 @@ bool Maildir::removeEntry(const QString& key) // return QFile::remove(realKey); } -// QString Maildir::changeEntryFlags(const QString& key, const Akonadi::Item::Flags& flags) +// QString Maildir::changeEntryFlags(const QString& key, const Sink::Item::Flags& flags) // { // QString realKey(d->findRealKey(key)); // if (realKey.isEmpty()) { @@ -701,16 +701,16 @@ bool Maildir::removeEntry(const QString& key) // QString finalKey = key.left(key.indexOf(rx)); // // QStringList mailDirFlags; -// Q_FOREACH (const Akonadi::Item::Flag &flag, flags) { -// if (flag == Akonadi::MessageFlags::Forwarded) +// Q_FOREACH (const Sink::Item::Flag &flag, flags) { +// if (flag == Sink::MessageFlags::Forwarded) // mailDirFlags << QLatin1String("P"); -// if (flag == Akonadi::MessageFlags::Replied) +// if (flag == Sink::MessageFlags::Replied) // mailDirFlags << QLatin1String("R"); -// if (flag == Akonadi::MessageFlags::Seen) +// if (flag == Sink::MessageFlags::Seen) // mailDirFlags << QLatin1String("S"); -// if (flag == Akonadi::MessageFlags::Deleted) +// if (flag == Sink::MessageFlags::Deleted) // mailDirFlags << QLatin1String("T"); -// if (flag == Akonadi::MessageFlags::Flagged) +// if (flag == Sink::MessageFlags::Flagged) // mailDirFlags << QLatin1String("F"); // } // mailDirFlags.sort(); @@ -726,7 +726,7 @@ bool Maildir::removeEntry(const QString& key) // finalKey.prepend(d->path + QString::fromLatin1("/cur/")); // // if (realKey == finalKey) { -// // Somehow it already is named this way (e.g. migration bug -> wrong status in akonadi) +// // Somehow it already is named this way (e.g. migration bug -> wrong status in sink) // return newUniqueKey; // } // diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h index fefd5a7..a89a832 100644 --- a/examples/maildirresource/libmaildir/maildir.h +++ b/examples/maildirresource/libmaildir/maildir.h @@ -211,7 +211,7 @@ public: * Change the flags for an entry specified by @p key. Returns the new key of the entry (the key might change because * flags are stored in the unique filename). */ - // QString changeEntryFlags( const QString& key, const Akonadi::Item::Flags& flags ); + // QString changeEntryFlags( const QString& key, const Sink::Item::Flags& flags ); /** * Moves this maildir into @p destination. diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 9280bdc..33883a7 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -46,15 +46,15 @@ #define ENTITY_TYPE_MAIL "mail" #define ENTITY_TYPE_FOLDER "folder" -MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) - : Akonadi2::GenericResource(instanceIdentifier, pipeline), +MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) + : Sink::GenericResource(instanceIdentifier, pipeline), mMailAdaptorFactory(QSharedPointer::create()), mFolderAdaptorFactory(QSharedPointer::create()) { addType(ENTITY_TYPE_MAIL, mMailAdaptorFactory, - QVector() << new DefaultIndexUpdater); + QVector() << new DefaultIndexUpdater); addType(ENTITY_TYPE_FOLDER, mFolderAdaptorFactory, - QVector() << new DefaultIndexUpdater); + QVector() << new DefaultIndexUpdater); auto config = ResourceConfig::getConfiguration(instanceIdentifier); mMaildirPath = QDir::cleanPath(QDir::fromNativeSeparators(config.value("path").toString())); //Chop a trailing slash if necessary @@ -91,7 +91,7 @@ QStringList MaildirResource::listAvailableFolders() return folderList; } -void MaildirResource::synchronizeFolders(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction) +void MaildirResource::synchronizeFolders(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction) { const QByteArray bufferType = ENTITY_TYPE_FOLDER; QStringList folderList = listAvailableFolders(); @@ -102,7 +102,7 @@ void MaildirResource::synchronizeFolders(Akonadi2::Storage::Transaction &transac //TODO Instead of iterating over all entries in the database, which can also pick up the same item multiple times, //we should rather iterate over an index that contains every uid exactly once. The remoteId index would be such an index, //but we currently fail to iterate over all entries in an index it seems. - // auto remoteIds = synchronizationTransaction.openDatabase("rid.mapping." + bufferType, std::function(), true); + // auto remoteIds = synchronizationTransaction.openDatabase("rid.mapping." + bufferType, std::function(), true); auto mainDatabase = transaction.openDatabase(bufferType + ".main"); mainDatabase.scan("", [&](const QByteArray &key, const QByteArray &) { callback(key); @@ -119,7 +119,7 @@ void MaildirResource::synchronizeFolders(Akonadi2::Storage::Transaction &transac Trace() << "Processing folder " << remoteId; KPIM::Maildir md(folderPath, folderPath == mMaildirPath); - Akonadi2::ApplicationDomain::Folder folder; + Sink::ApplicationDomain::Folder folder; folder.setProperty("name", md.name()); folder.setProperty("icon", "folder"); if (!md.isRoot()) { @@ -129,7 +129,7 @@ void MaildirResource::synchronizeFolders(Akonadi2::Storage::Transaction &transac } } -void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QString &path) +void MaildirResource::synchronizeMails(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QString &path) { Trace() << "Synchronizing mails" << path; const QByteArray bufferType = ENTITY_TYPE_MAIL; @@ -150,8 +150,8 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti scanForRemovals(transaction, synchronizationTransaction, bufferType, [&](const std::function &callback) { Index index(bufferType + ".index." + property, transaction); - index.lookup(folderLocalId, [&](const QByteArray &akonadiId) { - callback(akonadiId); + index.lookup(folderLocalId, [&](const QByteArray &sinkId) { + callback(sinkId); }, [&](const Index::Error &error) { Warning() << "Error in index: " << error.message << property; @@ -175,7 +175,7 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti Trace() << "Found a mail " << filePath << " : " << fileName << msg->subject(true)->asUnicodeString(); - Akonadi2::ApplicationDomain::Mail mail; + Sink::ApplicationDomain::Mail mail; mail.setProperty("subject", msg->subject(true)->asUnicodeString()); mail.setProperty("sender", msg->from(true)->asUnicodeString()); mail.setProperty("senderName", msg->from(true)->asUnicodeString()); @@ -189,19 +189,19 @@ void MaildirResource::synchronizeMails(Akonadi2::Storage::Transaction &transacti } } -KAsync::Job MaildirResource::synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) +KAsync::Job MaildirResource::synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) { Log() << " Synchronizing"; return KAsync::start([this, &mainStore, &synchronizationStore]() { - auto transaction = mainStore.createTransaction(Akonadi2::Storage::ReadOnly); + auto transaction = mainStore.createTransaction(Sink::Storage::ReadOnly); { - auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); + auto synchronizationTransaction = synchronizationStore.createTransaction(Sink::Storage::ReadWrite); synchronizeFolders(transaction, synchronizationTransaction); //The next sync needs the folders available synchronizationTransaction.commit(); } for (const auto &folder : listAvailableFolders()) { - auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); + auto synchronizationTransaction = synchronizationStore.createTransaction(Sink::Storage::ReadWrite); synchronizeMails(transaction, synchronizationTransaction, folder); //Don't let the transaction grow too much synchronizationTransaction.commit(); @@ -210,23 +210,23 @@ KAsync::Job MaildirResource::synchronizeWithSource(Akonadi2::Storage &main }); } -KAsync::Job MaildirResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job MaildirResource::replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { - auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); + auto synchronizationTransaction = synchronizationStore.createTransaction(Sink::Storage::ReadWrite); Trace() << "Replaying " << key << type; if (type == ENTITY_TYPE_FOLDER) { - Akonadi2::EntityBuffer buffer(value.data(), value.size()); - const Akonadi2::Entity &entity = buffer.entity(); - const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + Sink::EntityBuffer buffer(value.data(), value.size()); + const Sink::Entity &entity = buffer.entity(); + const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); if (metadataBuffer && !metadataBuffer->replayToSource()) { Trace() << "Change is coming from the source"; return KAsync::null(); } const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; - const auto operation = metadataBuffer ? metadataBuffer->operation() : Akonadi2::Operation_Creation; - if (operation == Akonadi2::Operation_Creation) { - const Akonadi2::ApplicationDomain::Folder folder(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mFolderAdaptorFactory->createAdaptor(entity)); + const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; + if (operation == Sink::Operation_Creation) { + const Sink::ApplicationDomain::Folder folder(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, mFolderAdaptorFactory->createAdaptor(entity)); auto folderName = folder.getProperty("name").toString(); //TODO handle non toplevel folders auto path = mMaildirPath + "/" + folderName; @@ -234,31 +234,31 @@ KAsync::Job MaildirResource::replay(Akonadi2::Storage &synchronizationStor KPIM::Maildir maildir(path, false); maildir.create(); recordRemoteId(ENTITY_TYPE_FOLDER, folder.identifier(), path.toUtf8(), synchronizationTransaction); - } else if (operation == Akonadi2::Operation_Removal) { - const auto uid = Akonadi2::Storage::uidFromKey(key); + } else if (operation == Sink::Operation_Removal) { + const auto uid = Sink::Storage::uidFromKey(key); const auto remoteId = resolveLocalId(ENTITY_TYPE_FOLDER, uid, synchronizationTransaction); const auto path = remoteId; Trace() << "Removing a folder: " << path; KPIM::Maildir maildir(path, false); maildir.remove(); removeRemoteId(ENTITY_TYPE_FOLDER, uid, remoteId, synchronizationTransaction); - } else if (operation == Akonadi2::Operation_Modification) { + } else if (operation == Sink::Operation_Modification) { Warning() << "Folder modifications are not implemented"; } else { Warning() << "Unkown operation" << operation; } } else if (type == ENTITY_TYPE_MAIL) { - Akonadi2::EntityBuffer buffer(value.data(), value.size()); - const Akonadi2::Entity &entity = buffer.entity(); - const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer(entity.metadata()); + Sink::EntityBuffer buffer(value.data(), value.size()); + const Sink::Entity &entity = buffer.entity(); + const auto metadataBuffer = Sink::EntityBuffer::readBuffer(entity.metadata()); if (metadataBuffer && !metadataBuffer->replayToSource()) { Trace() << "Change is coming from the source"; return KAsync::null(); } const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; - const auto operation = metadataBuffer ? metadataBuffer->operation() : Akonadi2::Operation_Creation; - if (operation == Akonadi2::Operation_Creation) { - const Akonadi2::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Akonadi2::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity)); + const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; + if (operation == Sink::Operation_Creation) { + const Sink::ApplicationDomain::Mail mail(mResourceInstanceIdentifier, Sink::Storage::uidFromKey(key), revision, mMailAdaptorFactory->createAdaptor(entity)); auto parentFolder = mail.getProperty("folder").toByteArray(); QByteArray parentFolderRemoteId; if (!parentFolder.isEmpty()) { @@ -272,13 +272,13 @@ KAsync::Job MaildirResource::replay(Akonadi2::Storage &synchronizationStor const auto id = maildir.addEntry("foobar"); Trace() << "Creating a new mail: " << id; recordRemoteId(ENTITY_TYPE_MAIL, mail.identifier(), id.toUtf8(), synchronizationTransaction); - } else if (operation == Akonadi2::Operation_Removal) { - const auto uid = Akonadi2::Storage::uidFromKey(key); + } else if (operation == Sink::Operation_Removal) { + const auto uid = Sink::Storage::uidFromKey(key); const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, uid, synchronizationTransaction); Trace() << "Removing a mail: " << remoteId; QFile::remove(remoteId); removeRemoteId(ENTITY_TYPE_MAIL, uid, remoteId, synchronizationTransaction); - } else if (operation == Akonadi2::Operation_Modification) { + } else if (operation == Sink::Operation_Modification) { Warning() << "Mail modifications are not implemented"; } else { Warning() << "Unkown operation" << operation; @@ -290,16 +290,16 @@ KAsync::Job MaildirResource::replay(Akonadi2::Storage &synchronizationStor void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) { GenericResource::removeFromDisk(instanceIdentifier); - Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::ReadWrite).removeFromDisk(); } KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) { - auto synchronizationStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadOnly); - auto synchronizationTransaction = synchronizationStore->createTransaction(Akonadi2::Storage::ReadOnly); + auto synchronizationStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadOnly); + auto synchronizationTransaction = synchronizationStore->createTransaction(Sink::Storage::ReadOnly); Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; if (domainType == ENTITY_TYPE_MAIL) { - if (inspectionType == Akonadi2::Resources::Inspection::PropertyInspectionType) { + if (inspectionType == Sink::Resources::Inspection::PropertyInspectionType) { if (property == "unread") { const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); const auto flags = KPIM::Maildir::readEntryFlags(remoteId.split('/').last()); @@ -312,7 +312,7 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray return KAsync::null(); } } - if (inspectionType == Akonadi2::Resources::Inspection::ExistenceInspectionType) { + if (inspectionType == Sink::Resources::Inspection::ExistenceInspectionType) { const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); if (QFileInfo(remoteId).exists() != expectedValue.toBool()) { return KAsync::error(1, "Wrong file existence: " + remoteId); @@ -323,19 +323,19 @@ KAsync::Job MaildirResource::inspect(int inspectionType, const QByteArray } MaildirResourceFactory::MaildirResourceFactory(QObject *parent) - : Akonadi2::ResourceFactory(parent) + : Sink::ResourceFactory(parent) { } -Akonadi2::Resource *MaildirResourceFactory::createResource(const QByteArray &instanceIdentifier) +Sink::Resource *MaildirResourceFactory::createResource(const QByteArray &instanceIdentifier) { return new MaildirResource(instanceIdentifier); } -void MaildirResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) +void MaildirResourceFactory::registerFacades(Sink::FacadeFactory &factory) { - factory.registerFacade(PLUGIN_NAME); - factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); } diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index 5f7795b..9af2f39 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h @@ -39,34 +39,34 @@ class MaildirFolderAdaptorFactory; * files: full file path * directories: full directory path */ -class MaildirResource : public Akonadi2::GenericResource +class MaildirResource : public Sink::GenericResource { public: - MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); - KAsync::Job synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; + MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline = QSharedPointer()); + KAsync::Job synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) Q_DECL_OVERRIDE; KAsync::Job inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; static void removeFromDisk(const QByteArray &instanceIdentifier); private: - KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; + KAsync::Job replay(Sink::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; - void synchronizeFolders(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction); - void synchronizeMails(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QString &folder); + void synchronizeFolders(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction); + void synchronizeMails(Sink::Storage::Transaction &transaction, Sink::Storage::Transaction &synchronizationTransaction, const QString &folder); QStringList listAvailableFolders(); QString mMaildirPath; QSharedPointer mMailAdaptorFactory; QSharedPointer mFolderAdaptorFactory; }; -class MaildirResourceFactory : public Akonadi2::ResourceFactory +class MaildirResourceFactory : public Sink::ResourceFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.maildir") - Q_INTERFACES(Akonadi2::ResourceFactory) + Q_INTERFACES(Sink::ResourceFactory) public: MaildirResourceFactory(QObject *parent = 0); - Akonadi2::Resource *createResource(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; - void registerFacades(Akonadi2::FacadeFactory &factory) Q_DECL_OVERRIDE; + Sink::Resource *createResource(const QByteArray &instanceIdentifier) Q_DECL_OVERRIDE; + void registerFacades(Sink::FacadeFactory &factory) Q_DECL_OVERRIDE; }; diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt new file mode 100644 index 0000000..1489fb3 --- /dev/null +++ b/sinksh/CMakeLists.txt @@ -0,0 +1,29 @@ +project(sinksh) + +find_package(Readline REQUIRED) + + +set(sink_cli_SRCS + main.cpp + syntaxtree.cpp + syntax_modules/core_syntax.cpp + syntax_modules/sink_list.cpp + syntax_modules/sink_clear.cpp + syntax_modules/sink_count.cpp + syntax_modules/sink_create.cpp + syntax_modules/sink_modify.cpp + syntax_modules/sink_remove.cpp + syntax_modules/sink_stat.cpp + syntax_modules/sink_sync.cpp + sinksh_utils.cpp + repl/repl.cpp + repl/replStates.cpp + state.cpp + utils.cpp) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(${PROJECT_NAME} ${sink_cli_SRCS}) +target_link_libraries(${PROJECT_NAME} Qt5::Core ${Readline_LIBRARY} sinkcommon) +install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) + diff --git a/sinksh/TODO b/sinksh/TODO new file mode 100644 index 0000000..93c4ff1 --- /dev/null +++ b/sinksh/TODO @@ -0,0 +1,11 @@ +* commands + * improve modify/remove/create to dynamically add syntax items for each type + * improve modify/remove/create to autocomplete resource names +* provide a setting to turn on/off user interaction during commands (e.g. deletion confirmations) + * add a "ask the user a question" helper in State + * confirm deletions in remove +* handle env vars and similar for scripting purposes +* key/value syntax objects +* json objects! (set json on; ...) +* make the shell generic and have it load a plugin matching the name of argv[0] for syntax + diff --git a/sinksh/main.cpp b/sinksh/main.cpp new file mode 100644 index 0000000..4c00b9b --- /dev/null +++ b/sinksh/main.cpp @@ -0,0 +1,115 @@ +/* + * 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 +#include +#include + +#include "syntaxtree.h" +// #include "jsonlistener.h" +#include "repl/repl.h" + +/* + * modes of operation: + * + * 1. called with no commands: start the REPL + * 2. called with -: listen for commands on stdin + * 3. called with a filename: try to run it as a script + * 4. called with commands: try to match to syntax and run the result + */ + +int enterRepl() +{ + if (State::hasEventLoop()) { + return 0; + } + + Repl *repl = new Repl; + 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(); + State::setHasEventLoop(false); + return rv; +} + +bool goInteractive(const QStringList &, State &) +{ + enterRepl(); + return true; +} + +Syntax::List goInteractiveSyntax() +{ + Syntax interactive("go_interactive", QString(), &goInteractive); + return Syntax::List() << interactive; +} + +void processCommandStream(QTextStream &stream) +{ + SyntaxTree::self()->registerSyntax(&goInteractiveSyntax); + QString line = stream.readLine(); + while (!line.isEmpty()) { + line = line.trimmed(); + + if (!line.isEmpty() && !line.startsWith('#')) { + SyntaxTree::self()->run(SyntaxTree::tokenize(line)); + } + + line = stream.readLine(); + } +} + +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 + const bool fromScript = !startRepl && QFile::exists(argv[1]); + + //qDebug() << "state at startup is" << interactive << startRepl << fromScript; + + QCoreApplication app(argc, argv); + app.setApplicationName(fromScript ? "interactive-app-shell" : argv[0]); + + if (startRepl) { + return enterRepl(); + } else if (fromScript) { + QFile f(argv[1]); + if (!f.open(QIODevice::ReadOnly)) { + return 1; + } + + QTextStream inputStream(&f); + processCommandStream(inputStream); + } else if (!interactive) { + QTextStream inputStream(stdin); + processCommandStream(inputStream); + } else { + QStringList commands = app.arguments(); + commands.removeFirst(); + return SyntaxTree::self()->run(commands); + } +} diff --git a/sinksh/repl/repl.cpp b/sinksh/repl/repl.cpp new file mode 100644 index 0000000..21209fc --- /dev/null +++ b/sinksh/repl/repl.cpp @@ -0,0 +1,91 @@ +/* + * 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 "repl.h" + +#include + +#include +#include +#include +#include +#include + +#include "replStates.h" +#include "syntaxtree.h" + +Repl::Repl(QObject *parent) + : QStateMachine(parent) +{ + // readline history setup + using_history(); + read_history(commandHistoryPath().toLocal8Bit()); + + // create all states + ReadState *read = new ReadState(this); + UnfinishedReadState *unfinishedRead = new UnfinishedReadState(this); + EvalState *eval = new EvalState(this); + PrintState *print = new PrintState(this); + QFinalState *final = new QFinalState(this); + + // connect the transitions + read->addTransition(read, SIGNAL(command(QString)), eval); + read->addTransition(read, SIGNAL(exitRequested()), final); + + unfinishedRead->addTransition(unfinishedRead, SIGNAL(command(QString)), eval); + unfinishedRead->addTransition(unfinishedRead, SIGNAL(exitRequested()), final); + + eval->addTransition(eval, SIGNAL(completed()), read); + eval->addTransition(eval, SIGNAL(continueInput()), unfinishedRead); + eval->addTransition(eval, SIGNAL(output(QString)), print); + + print->addTransition(print, SIGNAL(completed()), eval); + + setInitialState(read); + printWelcomeBanner(); + start(); +} + +Repl::~Repl() +{ + // readline history writing + write_history(commandHistoryPath().toLocal8Bit()); +} + +void Repl::printWelcomeBanner() +{ + QTextStream out(stdout); + out << QObject::tr("Welcome to the Sink interative shell!\n"); + out << QObject::tr("Type `help` for information on the available commands.\n"); + out.flush(); +} + +QString Repl::commandHistoryPath() +{ + const QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + + if (!QFile::exists(path)) { + QDir dir; + dir.mkpath(path); + } + + return path + "/repl_history"; +} + +#include "moc_repl.cpp" diff --git a/sinksh/repl/repl.h b/sinksh/repl/repl.h new file mode 100644 index 0000000..d8d2533 --- /dev/null +++ b/sinksh/repl/repl.h @@ -0,0 +1,35 @@ +/* + * 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 + +class Repl : public QStateMachine +{ + Q_OBJECT + +public: + Repl(QObject *parent = 0); + ~Repl(); + +private: + static void printWelcomeBanner(); + static QString commandHistoryPath(); +}; diff --git a/sinksh/repl/replStates.cpp b/sinksh/repl/replStates.cpp new file mode 100644 index 0000000..43b1353 --- /dev/null +++ b/sinksh/repl/replStates.cpp @@ -0,0 +1,171 @@ +/* + * 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 "replStates.h" + +#include +#include + +#include +#include + +#include +#include +#include + +#include "syntaxtree.h" + +static char *sink_cli_next_tab_complete_match(const char *text, int state); +static char ** sink_cli_tab_completion(const char *text, int start, int end); + +ReadState::ReadState(QState *parent) + : QState(parent) +{ + rl_completion_entry_function = sink_cli_next_tab_complete_match; + rl_attempted_completion_function = sink_cli_tab_completion; +} + +void ReadState::onEntry(QEvent *event) +{ + Q_UNUSED(event) + char *line = readline(prompt()); + + if (!line) { + std::cout << std::endl; + emit exitRequested(); + return; + } + + // we have actual data, so let's wait for a full line of text + QByteArray input(line); + const QString text = QString(line).simplified(); + //qDebug() << "Line is ... " << text; + + if (text.length() > 0) { + add_history(line); + } + + free(line); + emit command(text); +} + +const char *ReadState::prompt() const +{ + return "> "; +} + +UnfinishedReadState::UnfinishedReadState(QState *parent) + : ReadState(parent) +{ +} + +const char *UnfinishedReadState::prompt() const +{ + return " "; +} + +EvalState::EvalState(QState *parent) + : QState(parent) +{ +} + +void EvalState::onEntry(QEvent *event) +{ + QStateMachine::SignalEvent *e = dynamic_cast(event); + + const QString command = e ? e->arguments()[0].toString() : QString(); + + if (command.isEmpty()) { + complete(); + return; + } + + if (command.right(1) == "\\") { + m_partial += " " + command.left(command.size() - 1); + continueInput(); + } else { + m_partial += " " + command; + complete(); + } +} + +void EvalState::complete() +{ + m_partial = m_partial.simplified(); + + if (!m_partial.isEmpty()) { + //emit output("Processing ... " + command); + const QStringList commands = SyntaxTree::tokenize(m_partial); + SyntaxTree::self()->run(commands); + m_partial.clear(); + } + + emit completed(); +} + +PrintState::PrintState(QState *parent) + : QState(parent) +{ +} + +void PrintState::onEntry(QEvent *event) +{ + QStateMachine::SignalEvent *e = dynamic_cast(event); + + if (e && !e->arguments().isEmpty()) { + const QString command = e->arguments()[0].toString(); + QTextStream stream(stdout); + stream << command << "\n"; + } + + emit completed(); +} + +static QStringList tab_completion_full_state; +static bool tab_completion_at_root = false; + +static char **sink_cli_tab_completion(const char *text, int start, int end) +{ + tab_completion_at_root = start == 0; + tab_completion_full_state = QString(rl_line_buffer).remove(start, end - start).split(" ", QString::SkipEmptyParts); + return NULL; +} + +static char *sink_cli_next_tab_complete_match(const char *text, int state) +{ + const QString fragment(text); + Syntax::List nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, fragment); + //for (auto syntax: nearest) { qDebug() << "Nearest: " << syntax.keyword; } + + if (nearest.isEmpty()) { + SyntaxTree::Command command = SyntaxTree::self()->match(tab_completion_full_state); + if (command.first && command.first->completer) { + QStringList commandCompletions = command.first->completer(tab_completion_full_state, fragment, SyntaxTree::self()->state()); + if (commandCompletions.size() > state) { + return qstrdup(commandCompletions[state].toUtf8()); + } + } + } else if (nearest.size() > state) { + return qstrdup(nearest[state].keyword.toUtf8()); + } + + return rl_filename_completion_function(text, state); +} + +#include "moc_replStates.cpp" diff --git a/sinksh/repl/replStates.h b/sinksh/repl/replStates.h new file mode 100644 index 0000000..a0d3f90 --- /dev/null +++ b/sinksh/repl/replStates.h @@ -0,0 +1,87 @@ +/* + * 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 + +class QSocketNotifier; + +class ReadState : public QState +{ + Q_OBJECT + +public: + ReadState(QState *parent = 0); + +Q_SIGNALS: + void command(const QString &command); + void exitRequested(); + +protected: + void onEntry(QEvent *event); + virtual const char *prompt() const; +}; + +class UnfinishedReadState : public ReadState +{ + Q_OBJECT + +public: + UnfinishedReadState(QState *parent = 0); + +protected: + const char *prompt() const; +}; + +class EvalState : public QState +{ + Q_OBJECT + +public: + EvalState(QState *parent = 0); + +Q_SIGNALS: + void completed(); + void continueInput(); + void output(const QString &output); + +protected: + void onEntry(QEvent *event); + +private: + void complete(); + + QString m_partial; +}; + +class PrintState : public QState +{ + Q_OBJECT + +public: + PrintState(QState *parent = 0); + +Q_SIGNALS: + void completed(); + +protected: + void onEntry(QEvent *event); +}; + diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp new file mode 100644 index 0000000..fa06b34 --- /dev/null +++ b/sinksh/sinksh_utils.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2015 Aaron Seigo + * Copyright (C) 2015 Christian Mollekopf + * + * 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 "sinksh_utils.h" + +#include "common/clientapi.h" + +#include "utils.h" + +namespace SinkshUtils +{ + +static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event"; + +bool isValidStoreType(const QString &type) +{ + return s_types.contains(type); +} + +StoreBase &getStore(const QString &type) +{ + if (type == "folder") { + static Store store; + return store; + } else if (type == "mail") { + static Store store; + return store; + } else if (type == "event") { + static Store store; + return store; + } else if (type == "resource") { + static Store store; + return store; + } + + //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; +} + +QSharedPointer loadModel(const QString &type, Sink::Query query) +{ + if (type == "folder") { + query.requestedProperties << "name" << "parent"; + } else if (type == "mail") { + query.requestedProperties << "subject" << "folder" << "date"; + } else if (type == "event") { + query.requestedProperties << "summary"; + } else if (type == "resource") { + query.requestedProperties << "type"; + } + auto model = getStore(type).loadModel(query); + Q_ASSERT(model); + return model; +} + +QStringList resourceIds(State &state) +{ + QStringList resources; + Sink::Query query; + 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 { + for (int i = start; i <= end; i++) { + auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); + resources << object->identifier(); + } + }); + + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Sink::Store::ChildrenFetchedRole)) { + state.commandFinished(); + } + }); + + state.commandStarted(); + + return resources; +} + +QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) +{ + return Utils::filteredCompletions(resourceIds(state), fragment); +} + +QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state) +{ + static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event"; + if (commands.count() == 1) { + return Utils::filteredCompletions(s_types, fragment); + } + + return Utils::filteredCompletions(resourceIds(state), fragment); +} + +QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) +{ + return Utils::filteredCompletions(s_types, 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; +} + +} + diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h new file mode 100644 index 0000000..457f644 --- /dev/null +++ b/sinksh/sinksh_utils.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2015 Aaron Seigo + * Copyright (C) 2015 Christian Mollekopf + * + * 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 +#include + +#include "common/query.h" +#include "common/clientapi.h" + +#include "state.h" + +namespace SinkshUtils +{ + +class StoreBase; + +bool isValidStoreType(const QString &type); +StoreBase &getStore(const QString &type); +QSharedPointer loadModel(const QString &type, Sink::Query query); +QStringList resourceIds(); +QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); +QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); +QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); +QMap keyValueMapFromArgs(const QStringList &args); + +/** + * A small abstraction layer to use the sink store with the type available as string. + */ +class StoreBase { +public: + 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; + virtual KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; + virtual KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; + virtual QSharedPointer loadModel(const Sink::Query &query) = 0; +}; + +template +class Store : public StoreBase { +public: + 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 { + 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 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)); + } + + QSharedPointer loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { + return Sink::Store::loadModel(query); + } +}; + + +} + diff --git a/sinksh/state.cpp b/sinksh/state.cpp new file mode 100644 index 0000000..e03bf87 --- /dev/null +++ b/sinksh/state.cpp @@ -0,0 +1,144 @@ +/* + * 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 "state.h" + +#include +#include +#include +#include + +#include "common/log.h" + +static bool s_hasEventLoop = false; + +class State::Private +{ +public: + Private() + : outStream(stdout) + { + } + + QEventLoop *eventLoop() + { + if (!event) { + event = new QEventLoop; + } + + return event; + } + + int debugLevel = 0; + QEventLoop *event = 0; + bool timing = false; + QTextStream outStream; +}; + +State::State() + : d(new Private) +{ +} + +void State::print(const QString &message, unsigned int indentationLevel) const +{ + for (unsigned int i = 0; i < indentationLevel; ++i) { + d->outStream << "\t"; + } + + d->outStream << message; +} + +void State::printLine(const QString &message, unsigned int indentationLevel) const +{ + print(message, indentationLevel); + d->outStream << "\n"; + d->outStream.flush(); +} + +void State::printError(const QString &errorMessage, const QString &errorCode) const +{ + printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage); +} + +void State::setDebugLevel(unsigned int level) +{ + if (level < 7) { + d->debugLevel = level; + } +} + +unsigned int State::debugLevel() const +{ + return d->debugLevel; +} + +int State::commandStarted() const +{ + if (!s_hasEventLoop) { + return QCoreApplication::exec(); + } else if (!d->eventLoop()->isRunning()) { + return d->eventLoop()->exec(); + } + + return 0; +} + +void State::commandFinished(int returnCode) const +{ + if (!s_hasEventLoop) { + QCoreApplication::exit(returnCode); + } else { + d->eventLoop()->exit(returnCode); + } +} + +void State::setHasEventLoop(bool evented) +{ + s_hasEventLoop = evented; +} + +bool State::hasEventLoop() +{ + return s_hasEventLoop; +} + +void State::setCommandTiming(bool time) +{ + d->timing = time; +} + +bool State::commandTiming() const +{ + return d->timing; +} + +void State::setLoggingLevel(const QString &level) const +{ + Sink::Log::setDebugOutputLevel(Sink::Log::debugLevelFromName(level.toLatin1())); +} + +QString State::loggingLevel() const +{ + // do not turn this into a single line return: that core dumps due to allocation of + // the byte array in Sink::Log + QByteArray rv = Sink::Log::debugLevelName(Sink::Log::debugOutputLevel()); + return rv.toLower(); +} + diff --git a/sinksh/state.h b/sinksh/state.h new file mode 100644 index 0000000..3c4c2c7 --- /dev/null +++ b/sinksh/state.h @@ -0,0 +1,52 @@ +/* + * 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 + +class State +{ +public: + State(); + + void print(const QString &message, unsigned int indentationLevel = 0) const; + void printLine(const QString &message = QString(), unsigned int indentationLevel = 0) const; + void printError(const QString &errorMessage, const QString &errorCode = QString()) const; + + void setDebugLevel(unsigned int level); + unsigned int debugLevel() const; + + void setCommandTiming(bool); + bool commandTiming() const; + + int commandStarted() const; + void commandFinished(int returnCode = 0) const; + + void setLoggingLevel(const QString &level) const; + QString loggingLevel() const; + + static void setHasEventLoop(bool evented); + static bool hasEventLoop(); + +private: + class Private; + Private * const d; +}; + diff --git a/sinksh/syntax_modules/core_syntax.cpp b/sinksh/syntax_modules/core_syntax.cpp new file mode 100644 index 0000000..f5b6274 --- /dev/null +++ b/sinksh/syntax_modules/core_syntax.cpp @@ -0,0 +1,204 @@ +/* + * 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 + +#include "state.h" +#include "syntaxtree.h" +#include "utils.h" + +namespace CoreSyntax +{ + +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 Sink 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, State &) +{ + 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 &, 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; +} + +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; +} + +bool setLoggingLevel(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; + } + + state.setLoggingLevel(commands.at(0)); + return true; +} + +bool printLoggingLevel(const QStringList &commands, State &state) +{ + const QString level = state.loggingLevel(); + state.printLine(level); + return true; +} + +Syntax::List syntax() +{ + Syntax::List syntax; + syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); + + 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("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 logging("logging", QObject::tr("Set the logging level to one of Trace, Log, Warning or Error"), &CoreSyntax::setLoggingLevel); + logging.completer = [](const QStringList &, const QString &fragment, State &state) -> QStringList { return Utils::filteredCompletions(QStringList() << "trace" << "log" << "warning" << "error", fragment, Qt::CaseInsensitive); }; + set.children << logging; + + syntax << set; + + 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); + get.children << Syntax("logging", QObject::tr("The current logging level"), &CoreSyntax::printLoggingLevel); + syntax << get; + + return syntax; +} + +REGISTER_SYNTAX(CoreSyntax) + +} // namespace CoreSyntax + diff --git a/sinksh/syntax_modules/sink_clear.cpp b/sinksh/syntax_modules/sink_clear.cpp new file mode 100644 index 0000000..d02c638 --- /dev/null +++ b/sinksh/syntax_modules/sink_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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkClear +{ + +bool clear(const QStringList &args, State &state) +{ + for (const auto &resource : args) { + state.print(QObject::tr("Removing local cache for '%1' ...").arg(resource)); + Sink::Store::removeFromDisk(resource.toLatin1()); + state.printLine(QObject::tr("done")); + } + + return true; +} + +Syntax::List syntax() +{ + Syntax clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &SinkClear::clear); + clear.completer = &SinkshUtils::resourceCompleter; + + return Syntax::List() << clear; +} + +REGISTER_SYNTAX(SinkClear) + +} diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp new file mode 100644 index 0000000..fde7c33 --- /dev/null +++ b/sinksh/syntax_modules/sink_count.cpp @@ -0,0 +1,83 @@ +/* + * 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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkCount +{ + +bool count(const QStringList &args, State &state) +{ + auto resources = args; + auto type = !resources.isEmpty() ? resources.takeFirst() : QString(); + + if (!type.isEmpty() && !SinkshUtils::isValidStoreType(type)) { + state.printError(QObject::tr("Unknown type: %1").arg(type)); + return false; + } + + Sink::Query query; + for (const auto &res : resources) { + query.resources << res.toLatin1(); + } + query.liveQuery = false; + + auto model = SinkshUtils::loadModel(type, query); + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Sink::Store::ChildrenFetchedRole)) { + state.printLine(QObject::tr("Counted results %1").arg(model->rowCount(QModelIndex()))); + state.commandFinished(); + } + }); + + if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { + return true; + } + + return true; +} + +Syntax::List syntax() +{ + Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count "), &SinkCount::count, Syntax::EventDriven); + count.completer = &SinkshUtils::typeCompleter; + + return Syntax::List() << count; +} + +REGISTER_SYNTAX(SinkCount) + +} diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp new file mode 100644 index 0000000..cd2cd80 --- /dev/null +++ b/sinksh/syntax_modules/sink_create.cpp @@ -0,0 +1,118 @@ +/* + * 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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkCreate +{ + +bool create(const QStringList &allArgs, State &state) +{ + if (allArgs.isEmpty()) { + state.printError(QObject::tr("A type is required"), "sinkcreate/02"); + return false; + } + + if (allArgs.count() < 2) { + state.printError(QObject::tr("A resource ID is required to create items"), "sinkcreate/03"); + return false; + } + + auto args = allArgs; + auto type = args.takeFirst(); + auto &store = SinkshUtils::getStore(type); + Sink::ApplicationDomain::ApplicationDomainType::Ptr object; + auto resource = args.takeFirst().toLatin1(); + object = store.getObject(resource); + + auto map = SinkshUtils::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_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"), "sinkcreate/01"); + return false; + } + + auto &store = SinkshUtils::getStore("resource"); + + auto resourceType = args.at(0); + Sink::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(""); + object->setProperty("type", resourceType); + + auto map = SinkshUtils::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_e" + QString::number(result.errorCode())); + } + + return true; +} + + +Syntax::List syntax() +{ + Syntax::List syntax; + + Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); + create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); + + syntax << create; + return syntax; +} + +REGISTER_SYNTAX(SinkCreate) + +} diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp new file mode 100644 index 0000000..9712b6f --- /dev/null +++ b/sinksh/syntax_modules/sink_list.cpp @@ -0,0 +1,114 @@ +/* + * 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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkList +{ + +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(); + + if (!type.isEmpty() && !SinkshUtils::isValidStoreType(type)) { + state.printError(QObject::tr("Unknown type: %1").arg(type)); + return false; + } + + Sink::Query query; + for (const auto &res : resources) { + query.resources << res.toLatin1(); + } + query.liveQuery = false; + + QTime time; + time.start(); + auto model = SinkshUtils::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("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++) { + auto object = model->data(model->index(i, 0, index), Sink::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(Sink::Store::ChildrenFetchedRole)) { + state.commandFinished(); + } + }); + + if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { + return true; + } + + return false; +} + +Syntax::List syntax() +{ + Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources"), &SinkList::list, Syntax::EventDriven); + list.completer = &SinkshUtils::resourceOrTypeCompleter; + return Syntax::List() << list; +} + +REGISTER_SYNTAX(SinkList) + +} diff --git a/sinksh/syntax_modules/sink_modify.cpp b/sinksh/syntax_modules/sink_modify.cpp new file mode 100644 index 0000000..4d637d8 --- /dev/null +++ b/sinksh/syntax_modules/sink_modify.cpp @@ -0,0 +1,120 @@ +/* + * 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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkModify +{ + +bool modify(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A type is required"), "sink_modify/02"); + return false; + } + + if (args.count() < 2) { + state.printError(QObject::tr("A resource ID is required to remove items"), "sink_modify/03"); + return false; + } + + if (args.count() < 3) { + state.printError(QObject::tr("An object ID is required to remove items"), "sink_modify/03"); + return false; + } + + auto type = args[0]; + auto resourceId = args[1]; + auto identifier = args[2]; + + auto &store = SinkshUtils::getStore(type); + Sink::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject(resourceId.toUtf8(), identifier.toUtf8()); + + auto map = SinkshUtils::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"), "sink_modify/01"); + } + + auto &store = SinkshUtils::getStore("resource"); + + auto resourceId = args.at(0); + Sink::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1()); + + auto map = SinkshUtils::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 modify("modify", QObject::tr("Modify items in a resource"), &SinkModify::modify); + Syntax resource("resource", QObject::tr("Modify a resource"), &SinkModify::resource);//, Syntax::EventDriven); + resource.completer = &SinkshUtils::resourceOrTypeCompleter; + modify.children << resource; + + return Syntax::List() << modify; +} + +REGISTER_SYNTAX(SinkModify) + +} diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp new file mode 100644 index 0000000..b374824 --- /dev/null +++ b/sinksh/syntax_modules/sink_remove.cpp @@ -0,0 +1,110 @@ +/* + * 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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkRemove +{ + +bool remove(const QStringList &args, State &state) +{ + if (args.isEmpty()) { + state.printError(QObject::tr("A type is required"), "sink_remove/02"); + return false; + } + + if (args.count() < 2) { + state.printError(QObject::tr("A resource ID is required to remove items"), "sink_remove/03"); + return false; + } + + if (args.count() < 3) { + state.printError(QObject::tr("An object ID is required to remove items"), "sink_remove/03"); + return false; + } + + auto type = args[0]; + auto resourceId = args[1]; + auto identifier = args[2]; + + auto &store = SinkshUtils::getStore(type); + Sink::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_remove_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 removed without an id"), "sink_remove/01"); + } + + auto &store = SinkshUtils::getStore("resource"); + + auto resourceId = args.at(0); + Sink::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("", resourceId.toLatin1()); + + 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_remove_e" + QString::number(result.errorCode())); + } + + return true; +} + + +Syntax::List syntax() +{ + Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); + Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource);//, Syntax::EventDriven); + resource.completer = &SinkshUtils::resourceCompleter; + remove.children << resource; + + return Syntax::List() << remove; +} + +REGISTER_SYNTAX(SinkRemove) + +} diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp new file mode 100644 index 0000000..06586d9 --- /dev/null +++ b/sinksh/syntax_modules/sink_stat.cpp @@ -0,0 +1,120 @@ +/* + * 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 + +#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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkStat +{ + +void statResources(const QStringList &resources, const State &state) +{ + qint64 total = 0; + for (const auto &resource : resources) { + Sink::Storage storage(Sink::storageLocation(), resource, Sink::Storage::ReadOnly); + auto transaction = storage.createTransaction(Sink::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; + } + int diskUsage = 0; + + QDir dir(Sink::storageLocation()); + for (const auto &folder : dir.entryList(QStringList() << resource + "*")) { + diskUsage += Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadOnly).diskUsage(); + } + auto size = diskUsage / 1024; + state.printLine(QObject::tr("Disk usage [kb]: %1").arg(size), 1); + } + + state.printLine(QObject::tr("Total [kb]: %1").arg(total)); +} + +bool statAllResources(State &state) +{ + Sink::Query query; + query.liveQuery = false; + auto model = SinkshUtils::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), Sink::Store::DomainObjectBaseRole).value(); + resources << object->identifier(); + } + }); + + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Sink::Store::ChildrenFetchedRole)) { + statResources(resources, state); + state.commandFinished(); + } + }); + + if (!model->data(QModelIndex(), Sink::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 state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::EventDriven); + state.completer = &SinkshUtils::resourceCompleter; + + return Syntax::List() << state; +} + +REGISTER_SYNTAX(SinkStat) + +} diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp new file mode 100644 index 0000000..3006202 --- /dev/null +++ b/sinksh/syntax_modules/sink_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 +#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 "sinksh_utils.h" +#include "state.h" +#include "syntaxtree.h" + +namespace SinkSync +{ + +bool sync(const QStringList &args, State &state) +{ + Sink::Query query; + for (const auto &res : args) { + query.resources << res.toLatin1(); + } + + QTimer::singleShot(0, [query, state]() { + Sink::Store::synchronize(query).then([state]() { + state.printLine("Synchronization complete!"); + state.commandFinished(); + }).exec(); + }); + + return true; +} + +Syntax::List syntax() +{ + Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven ); + sync.completer = &SinkshUtils::resourceCompleter; + + return Syntax::List() << sync; +} + +REGISTER_SYNTAX(SinkSync) + +} diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp new file mode 100644 index 0000000..4860582 --- /dev/null +++ b/sinksh/syntaxtree.cpp @@ -0,0 +1,221 @@ +/* + * 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 "syntaxtree.h" + +#include +#include + +SyntaxTree *SyntaxTree::s_module = 0; + +Syntax::Syntax() +{ +} + +Syntax::Syntax(const QString &k, const QString &helpText, std::function l, Interactivity inter) + : keyword(k), + help(helpText), + interactivity(inter), + lambda(l) +{ +} + +SyntaxTree::SyntaxTree() +{ +} + +int SyntaxTree::registerSyntax(std::function f) +{ + m_syntax += f(); + return m_syntax.size(); +} + +SyntaxTree *SyntaxTree::self() +{ + if (!s_module) { + s_module = new SyntaxTree; + } + + return s_module; +} + +Syntax::List SyntaxTree::syntax() const +{ + return m_syntax; +} + +bool SyntaxTree::run(const QStringList &commands) +{ + bool success = false; + m_timeElapsed.start(); + Command command = match(commands); + if (command.first) { + if (command.first->lambda) { + success = command.first->lambda(command.second, m_state); + if (success && command.first->interactivity == Syntax::EventDriven) { + success = m_state.commandStarted(); + } + } else if (command.first->children.isEmpty()) { + m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); + } else { + QStringList keywordList; + for (auto syntax: command.first->children) { + keywordList << syntax.keyword; + } + const QString keywords = keywordList.join(" " ); + m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); + } + } else { + m_state.printError(QObject::tr("Unknown command"), "st_unknown"); + } + + if (m_state.commandTiming()) { + m_state.printLine(QObject::tr("Time elapsed: %1").arg(m_timeElapsed.elapsed())); + } + return false; +} + +SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const +{ + if (commandLine.isEmpty()) { + return Command(); + } + + QStringListIterator commandLineIt(commandLine); + + QVectorIterator syntaxIt(m_syntax); + const Syntax *lastFullSyntax = 0; + QStringList tailCommands; + while (commandLineIt.hasNext() && syntaxIt.hasNext()) { + const QString word = commandLineIt.next(); + while (syntaxIt.hasNext()) { + const Syntax &syntax = syntaxIt.next(); + if (word == syntax.keyword) { + lastFullSyntax = &syntax; + syntaxIt = syntax.children; + break; + } + } + } + + if (lastFullSyntax) { + while (commandLineIt.hasNext()) { + tailCommands << commandLineIt.next(); + } + + return std::make_pair(lastFullSyntax, tailCommands); + } + + return Command(); +} + +Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString &fragment) const +{ + Syntax::List matches; + + //qDebug() << "words are" << words; + if (words.isEmpty()) { + for (const Syntax &syntax: m_syntax) { + if (syntax.keyword.startsWith(fragment)) { + matches.push_back(syntax); + } + } + } else { + QStringListIterator wordIt(words); + QVectorIterator syntaxIt(m_syntax); + Syntax lastFullSyntax; + + while (wordIt.hasNext()) { + const QString &word = wordIt.next(); + while (syntaxIt.hasNext()) { + const Syntax &syntax = syntaxIt.next(); + if (word == syntax.keyword) { + lastFullSyntax = syntax; + syntaxIt = syntax.children; + break; + } + } + } + + //qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); + if (lastFullSyntax.keyword == words.last()) { + syntaxIt = lastFullSyntax.children; + while (syntaxIt.hasNext()) { + Syntax syntax = syntaxIt.next(); + if (fragment.isEmpty() || syntax.keyword.startsWith(fragment)) { + matches.push_back(syntax); + } + } + } + } + + return matches; +} + +State &SyntaxTree::state() +{ + return m_state; +} + +QStringList SyntaxTree::tokenize(const QString &text) +{ + //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a + static const QVector quoters = QVector() << '"' << '\''; + QStringList tokens; + QString acc; + QChar closer; + for (int i = 0; i < text.size(); ++i) { + const QChar c = text.at(i); + if (c == '\\') { + ++i; + if (i < text.size()) { + acc.append(text.at(i)); + } + } else if (!closer.isNull()) { + if (c == closer) { + acc = acc.trimmed(); + if (!acc.isEmpty()) { + tokens << acc; + } + acc.clear(); + closer = QChar(); + } else { + acc.append(c); + } + } else if (c.isSpace()) { + acc = acc.trimmed(); + if (!acc.isEmpty()) { + tokens << acc; + } + acc.clear(); + } else if (quoters.contains(c)) { + closer = c; + } else { + acc.append(c); + } + } + + acc = acc.trimmed(); + if (!acc.isEmpty()) { + tokens << acc; + } + + return tokens; +} + diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h new file mode 100644 index 0000000..468aad3 --- /dev/null +++ b/sinksh/syntaxtree.h @@ -0,0 +1,80 @@ +/* + * 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 "state.h" + +#include +#include +#include + +#include + +class Syntax +{ +public: + typedef QVector List; + + enum Interactivity { + NotInteractive = 0, + EventDriven + }; + + Syntax(); + Syntax(const QString &keyword, + const QString &helpText = QString(), + std::function lambda = std::function(), + Interactivity interactivity = NotInteractive); + + QString keyword; + QString help; + Interactivity interactivity; + std::function lambda; + std::function completer; + + QVector children; +}; + +class SyntaxTree +{ +public: + typedef std::pair Command; + + static SyntaxTree *self(); + + int registerSyntax(std::function f); + Syntax::List syntax() const; + Command match(const QStringList &commands) const; + Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; + State &state(); + bool run(const QStringList &commands); + + static QStringList tokenize(const QString &text); + +private: + SyntaxTree(); + + Syntax::List m_syntax; + State m_state; + QTime m_timeElapsed; + static SyntaxTree *s_module; +}; + +#define REGISTER_SYNTAX(name) static const int theTrickFor##name = SyntaxTree::self()->registerSyntax(&name::syntax); diff --git a/sinksh/utils.cpp b/sinksh/utils.cpp new file mode 100644 index 0000000..d2a28ed --- /dev/null +++ b/sinksh/utils.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 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 "utils.h" + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) +{ + if (commandFragment.isEmpty()) { + return possibleCompletions; + } + + QStringList filtered; + for (auto item: possibleCompletions) { + if (item.startsWith(commandFragment, cs)) { + filtered << item; + } + } + + return filtered; +} + +} // namespace Utils + diff --git a/sinksh/utils.h b/sinksh/utils.h new file mode 100644 index 0000000..82be8d5 --- /dev/null +++ b/sinksh/utils.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 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 + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); + +} // namespace Utils + diff --git a/synchronizer/CMakeLists.txt b/synchronizer/CMakeLists.txt index f0c235d..f2802a4 100644 --- a/synchronizer/CMakeLists.txt +++ b/synchronizer/CMakeLists.txt @@ -1,12 +1,12 @@ -project(akonadi2_synchronizer) +project(sink_synchronizer) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -set(akonadi2synchronizer_SRCS +set(sinksynchronizer_SRCS main.cpp ) -add_executable(${PROJECT_NAME} ${akonadi2synchronizer_SRCS}) -target_link_libraries(${PROJECT_NAME} akonadi2common KF5::Async) +add_executable(${PROJECT_NAME} ${sinksynchronizer_SRCS}) +target_link_libraries(${PROJECT_NAME} sinkcommon KF5::Async) qt5_use_modules(${PROJECT_NAME} Widgets Network) install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 38e5512..b01a329 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,7 @@ macro(manual_tests) add_executable(${_testname} ${_testname}.cpp testimplementations.cpp getrssusage.cpp) generate_flatbuffers(${_testname} calendar) qt5_use_modules(${_testname} Core Test Concurrent) - target_link_libraries(${_testname} akonadi2common libhawd) + target_link_libraries(${_testname} sinkcommon libhawd) endforeach(_testname) endmacro(manual_tests) @@ -25,7 +25,7 @@ macro(auto_tests) generate_flatbuffers(${_testname} calendar) add_test(${_testname} ${_testname}) qt5_use_modules(${_testname} Core Test Concurrent) - target_link_libraries(${_testname} akonadi2common libhawd) + target_link_libraries(${_testname} sinkcommon libhawd) endforeach(_testname) endmacro(auto_tests) @@ -53,16 +53,16 @@ auto_tests ( modelinteractivitytest inspectiontest ) -target_link_libraries(dummyresourcetest akonadi2_resource_dummy) -target_link_libraries(dummyresourcebenchmark akonadi2_resource_dummy) -target_link_libraries(dummyresourcewritebenchmark akonadi2_resource_dummy) -target_link_libraries(querytest akonadi2_resource_dummy) -target_link_libraries(modelinteractivitytest akonadi2_resource_dummy) -target_link_libraries(inspectiontest akonadi2_resource_dummy) +target_link_libraries(dummyresourcetest sink_resource_dummy) +target_link_libraries(dummyresourcebenchmark sink_resource_dummy) +target_link_libraries(dummyresourcewritebenchmark sink_resource_dummy) +target_link_libraries(querytest sink_resource_dummy) +target_link_libraries(modelinteractivitytest sink_resource_dummy) +target_link_libraries(inspectiontest sink_resource_dummy) if (BUILD_MAILDIR) auto_tests ( maildirresourcetest ) - target_link_libraries(maildirresourcetest akonadi2_resource_maildir) + target_link_libraries(maildirresourcetest sink_resource_maildir) endif() diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5942849..a85b03b 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -10,7 +10,7 @@ #include "facadefactory.h" template -class DummyResourceFacade : public Akonadi2::StoreFacade +class DummyResourceFacade : public Sink::StoreFacade { public: static std::shared_ptr > registerFacade(const QByteArray &instanceIdentifier = QByteArray()) @@ -19,7 +19,7 @@ public: auto facade = std::make_shared >(); map.insert(instanceIdentifier, facade); bool alwaysReturnFacade = instanceIdentifier.isEmpty(); - Akonadi2::FacadeFactory::instance().registerFacade >("dummyresource", + Sink::FacadeFactory::instance().registerFacade >("dummyresource", [alwaysReturnFacade](const QByteArray &instanceIdentifier) { if (alwaysReturnFacade) { return map.value(QByteArray()); @@ -33,9 +33,9 @@ public: KAsync::Job create(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job modify(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; KAsync::Job remove(const T &domainObject) Q_DECL_OVERRIDE { return KAsync::null(); }; - QPair, typename Akonadi2::ResultEmitter::Ptr > load(const Akonadi2::Query &query) Q_DECL_OVERRIDE + QPair, typename Sink::ResultEmitter::Ptr > load(const Sink::Query &query) Q_DECL_OVERRIDE { - auto resultProvider = new Akonadi2::ResultProvider(); + auto resultProvider = new Sink::ResultProvider(); resultProvider->onDone([resultProvider]() { Trace() << "Result provider is done"; delete resultProvider; @@ -67,7 +67,7 @@ public: } QList results; - Akonadi2::ResultProviderInterface *mResultProvider; + Sink::ResultProviderInterface *mResultProvider; }; @@ -83,117 +83,117 @@ private Q_SLOTS: void initTestCase() { - Akonadi2::FacadeFactory::instance().resetFactory(); + Sink::FacadeFactory::instance().resetFactory(); ResourceConfig::clear(); - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void testLoad() { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 1); } void testLoadWithoutResource() { - Akonadi2::Query query; + Sink::Query query; query.resources << "nonexisting.resource"; query.liveQuery = false; - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); } //TODO: This test doesn't belong to this testsuite void resourceManagement() { ResourceConfig::clear(); - Akonadi2::FacadeFactory::instance().registerStaticFacades(); + Sink::FacadeFactory::instance().registerStaticFacades(); - Akonadi2::ApplicationDomain::AkonadiResource res("", "dummyresource.identifier1", 0, QSharedPointer::create()); + Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer::create()); res.setProperty("identifier", "dummyresource.identifier1"); res.setProperty("type", "dummyresource"); - Akonadi2::Store::create(res).exec().waitForFinished(); + Sink::Store::create(res).exec().waitForFinished(); { - Akonadi2::Query query; + Sink::Query query; query.propertyFilter.insert("type", "dummyresource"); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); } - Akonadi2::Store::remove(res).exec().waitForFinished(); + Sink::Store::remove(res).exec().waitForFinished(); { - Akonadi2::Query query; + Sink::Query query; query.propertyFilter.insert("type", "dummyresource"); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 0); } } void testModelSingle() { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); } void testModelNested() { - auto facade = DummyResourceFacade::registerFacade(); - auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); subfolder->setProperty("parent", "id"); facade->results << folder << subfolder; ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; query.parentProperty = "parent"; - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); - QTRY_VERIFY(model->data(model->index(0, 0), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(model->index(0, 0), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(model->index(0, 0)), 1); } void testModelSignals() { - auto facade = DummyResourceFacade::registerFacade(); - auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); - auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("resource", "subId", 0, QSharedPointer::create()); subfolder->setProperty("parent", "id"); facade->results << folder << subfolder; ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; query.parentProperty = "parent"; - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QSignalSpy spy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); QVERIFY(spy.isValid()); model->fetchMore(model->index(0, 0)); @@ -202,20 +202,20 @@ private Q_SLOTS: void testModelNestedLive() { - auto facade = DummyResourceFacade::registerFacade(); - auto folder = QSharedPointer::create("dummyresource.instance1", "id", 0, QSharedPointer::create()); - auto subfolder = QSharedPointer::create("dummyresource.instance1", "subId", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + auto folder = QSharedPointer::create("dummyresource.instance1", "id", 0, QSharedPointer::create()); + auto subfolder = QSharedPointer::create("dummyresource.instance1", "subId", 0, QSharedPointer::create()); subfolder->setProperty("parent", "id"); facade->results << folder << subfolder; ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = true; query.parentProperty = "parent"; - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); QTRY_COMPARE(model->rowCount(model->index(0, 0)), 1); @@ -225,7 +225,7 @@ private Q_SLOTS: //Test new toplevel folder { QSignalSpy rowsInsertedSpy(model.data(), SIGNAL(rowsInserted(const QModelIndex &, int, int))); - auto folder2 = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); + auto folder2 = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); resultProvider->add(folder2); QTRY_COMPARE(model->rowCount(), 2); QTRY_COMPARE(rowsInsertedSpy.count(), 1); @@ -255,24 +255,24 @@ private Q_SLOTS: void testLoadMultiResource() { - auto facade1 = DummyResourceFacade::registerFacade("dummyresource.instance1"); - facade1->results << QSharedPointer::create("resource1", "id", 0, QSharedPointer::create()); - auto facade2 = DummyResourceFacade::registerFacade("dummyresource.instance2"); - facade2->results << QSharedPointer::create("resource2", "id", 0, QSharedPointer::create()); + auto facade1 = DummyResourceFacade::registerFacade("dummyresource.instance1"); + facade1->results << QSharedPointer::create("resource1", "id", 0, QSharedPointer::create()); + auto facade2 = DummyResourceFacade::registerFacade("dummyresource.instance2"); + facade2->results << QSharedPointer::create("resource2", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); ResourceConfig::addResource("dummyresource.instance2", "dummyresource"); - Akonadi2::Query query; + Sink::Query query; query.liveQuery = false; int childrenFetchedCount = 0; - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [&childrenFetchedCount](const QModelIndex &, const QModelIndex &, const QVector &roles) { - if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + if (roles.contains(Sink::Store::ChildrenFetchedRole)) { childrenFetchedCount++; } }); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 2); //Ensure children fetched is only emitted once (when all resources are done) QTest::qWait(50); @@ -281,17 +281,17 @@ private Q_SLOTS: void testImperativeLoad() { - auto facade = DummyResourceFacade::registerFacade(); - facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); + auto facade = DummyResourceFacade::registerFacade(); + facade->results << QSharedPointer::create("resource", "id", 0, QSharedPointer::create()); ResourceConfig::addResource("dummyresource.instance1", "dummyresource"); - Akonadi2::Query query; + Sink::Query query; query.resources << "dummyresource.instance1"; query.liveQuery = false; bool gotValue = false; - auto result = Akonadi2::Store::fetchOne(query) - .then([&gotValue](const Akonadi2::ApplicationDomain::Event &event) { + auto result = Sink::Store::fetchOne(query) + .then([&gotValue](const Sink::ApplicationDomain::Event &event) { gotValue = true; }).exec(); result.waitForFinished(); diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp index 5a96bdd..8581c49 100644 --- a/tests/databasepopulationandfacadequerybenchmark.cpp +++ b/tests/databasepopulationandfacadequerybenchmark.cpp @@ -34,12 +34,12 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject void populateDatabase(int count) { - Akonadi2::Storage(Akonadi2::storageLocation(), "identifier", Akonadi2::Storage::ReadWrite).removeFromDisk(); + Sink::Storage(Sink::storageLocation(), "identifier", Sink::Storage::ReadWrite).removeFromDisk(); //Setup auto domainTypeAdaptorFactory = QSharedPointer::create(); { - Akonadi2::Storage storage(Akonadi2::storageLocation(), identifier, Akonadi2::Storage::ReadWrite); - auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite); + auto transaction = storage.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("event.main"); int bufferSizeTotal = 0; @@ -47,7 +47,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject QByteArray attachment; attachment.fill('c', 1000); for (int i = 0; i < count; i++) { - auto domainObject = Akonadi2::ApplicationDomain::Event::Ptr::create(); + auto domainObject = Sink::ApplicationDomain::Event::Ptr::create(); domainObject->setProperty("uid", "uid"); domainObject->setProperty("summary", "summary"); domainObject->setProperty("attachment", attachment); @@ -82,7 +82,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject { const auto startingRss = getCurrentRSS(); - Akonadi2::Query query; + Sink::Query query; query.liveQuery = false; query.requestedProperties << "uid" << "summary"; @@ -90,22 +90,22 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject QTime time; time.start(); - auto resultSet = QSharedPointer >::create(); + auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); TestResourceFacade facade(identifier, resourceAccess); auto ret = facade.load(query); ret.first.exec().waitForFinished(); auto emitter = ret.second; - QList list; - emitter->onAdded([&list](const Akonadi2::ApplicationDomain::Event::Ptr &event) { + QList list; + emitter->onAdded([&list](const Sink::ApplicationDomain::Event::Ptr &event) { list << event; }); bool done = false; - emitter->onInitialResultSetComplete([&done](const Akonadi2::ApplicationDomain::Event::Ptr &event) { + emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Event::Ptr &event) { done = true; }); - emitter->fetch(Akonadi2::ApplicationDomain::Event::Ptr()); + emitter->fetch(Sink::ApplicationDomain::Event::Ptr()); QTRY_VERIFY(done); QCOMPARE(list.size(), count); @@ -114,7 +114,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject const auto finalRss = getCurrentRSS(); const auto rssGrowth = finalRss - startingRss; //Since the database is memory mapped it is attributted to the resident set size. - const auto rssWithoutDb = finalRss - Akonadi2::Storage(Akonadi2::storageLocation(), identifier, Akonadi2::Storage::ReadWrite).diskUsage(); + const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage(); const auto peakRss = getPeakRSS(); //How much peak deviates from final rss in percent (should be around 0) const auto percentageRssError = static_cast(peakRss - finalRss)*100.0/static_cast(finalRss); diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index b3d2a00..ff8f639 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp @@ -13,12 +13,12 @@ #include "metadata_generated.h" #include "entity_generated.h" -class TestFactory : public DomainTypeAdaptorFactory +class TestFactory : public DomainTypeAdaptorFactory { public: TestFactory() { - mResourceWriteMapper = Akonadi2::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper(); + mResourceWriteMapper = Sink::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper(); } }; @@ -39,27 +39,27 @@ private Q_SLOTS: void testCreateBufferPart() { - auto writeMapper = Akonadi2::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper(); + auto writeMapper = Sink::ApplicationDomain::TypeImplementation::initializeWritePropertyMapper(); - Akonadi2::ApplicationDomain::Event event; + Sink::ApplicationDomain::Event event; event.setProperty("summary", "foo"); flatbuffers::FlatBufferBuilder fbb; - auto pos = createBufferPart(event, fbb, *writeMapper); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); + auto pos = createBufferPart(event, fbb, *writeMapper); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); - QVERIFY(verifier.VerifyBuffer()); + QVERIFY(verifier.VerifyBuffer()); } void testAdaptor() { //Create entity buffer flatbuffers::FlatBufferBuilder metadataFbb; - auto metadataBuilder = Akonadi2::MetadataBuilder(metadataFbb); + auto metadataBuilder = Sink::MetadataBuilder(metadataFbb); metadataBuilder.add_revision(1); auto metadataBuffer = metadataBuilder.Finish(); - Akonadi2::FinishMetadataBuffer(metadataFbb, metadataBuffer); + Sink::FinishMetadataBuffer(metadataFbb, metadataBuffer); flatbuffers::FlatBufferBuilder m_fbb; auto summary = m_fbb.CreateString("summary1"); @@ -67,20 +67,20 @@ private Q_SLOTS: static uint8_t rawData[100]; auto attachment = m_fbb.CreateVector(rawData, 100); - auto builder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(m_fbb); + auto builder = Sink::ApplicationDomain::Buffer::EventBuilder(m_fbb); builder.add_summary(summary); builder.add_description(description); builder.add_attachment(attachment); auto buffer = builder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(m_fbb, buffer); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(m_fbb, buffer); flatbuffers::FlatBufferBuilder fbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize(), m_fbb.GetBufferPointer(), m_fbb.GetSize()); //Extract entity buffer { std::string data(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); - Akonadi2::EntityBuffer buffer((void*)(data.data()), data.size()); + Sink::EntityBuffer buffer((void*)(data.data()), data.size()); TestFactory factory; auto adaptor = factory.createAdaptor(buffer.entity()); diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index c52eee3..e511613 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -30,8 +30,8 @@ private: private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + Sink::Log::setDebugOutputLevel(Sink::Log::Warning); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); num = 5000; @@ -79,20 +79,20 @@ private Q_SLOTS: time.start(); QList > waitCondition; for (int i = 0; i < num; i++) { - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - waitCondition << Akonadi2::Store::create(event).exec(); + waitCondition << Sink::Store::create(event).exec(); } waitForCompletion(waitCondition).exec().waitForFinished(); auto appendTime = time.elapsed(); //Ensure everything is processed { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); } auto allProcessedTime = time.elapsed(); @@ -119,11 +119,11 @@ private Q_SLOTS: //Measure query { time.start(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.propertyFilter.insert("uid", "testuid"); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), num); } auto queryTime = time.elapsed(); @@ -142,44 +142,44 @@ private Q_SLOTS: QTime time; time.start(); - auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); + auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); DummyResource resource("org.kde.dummy.instance1", pipeline); flatbuffers::FlatBufferBuilder eventFbb; eventFbb.Clear(); { auto summary = eventFbb.CreateString("summary"); - Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); eventBuilder.add_summary(summary); auto eventLocation = eventBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); } flatbuffers::FlatBufferBuilder localFbb; { auto uid = localFbb.CreateString("testuid"); - auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); auto location = localBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } flatbuffers::FlatBufferBuilder entityFbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); + Sink::Commands::CreateEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); auto location = builder.Finish(); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); for (int i = 0; i < num; i++) { - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); } auto appendTime = time.elapsed(); @@ -203,7 +203,7 @@ private Q_SLOTS: void testCreateCommand() { - Akonadi2::ApplicationDomain::Event event; + Sink::ApplicationDomain::Event event; QBENCHMARK { auto mFactory = new DummyEventAdaptorFactory; @@ -217,9 +217,9 @@ private Q_SLOTS: auto entityId = fbb.CreateString(""); auto type = fbb.CreateString("event"); // auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto location = Sink::Commands::CreateCreateEntity(fbb, entityId, type, delta); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); } } diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 72a24b6..82c713d 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -22,8 +22,8 @@ class DummyResourceTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); DummyResource::removeFromDisk("org.kde.dummy.instance1"); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); @@ -31,11 +31,11 @@ private Q_SLOTS: void cleanup() { - Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); DummyResource::removeFromDisk("org.kde.dummy.instance1"); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); - Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } void init() @@ -47,54 +47,54 @@ private Q_SLOTS: void testProperty() { - Akonadi2::ApplicationDomain::Event event; + Sink::ApplicationDomain::Event event; event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); } void testWriteToFacadeAndQueryByUid() { - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); } void testWriteToFacadeAndQueryByUid2() { - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("summary", "summaryValue"); event.setProperty("uid", "testuid"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); event.setProperty("uid", "testuid2"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); @@ -102,27 +102,27 @@ private Q_SLOTS: void testWriteToFacadeAndQueryBySummary() { - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); event.setProperty("summary", "summaryValue1"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); event.setProperty("uid", "testuid2"); event.setProperty("summary", "summaryValue2"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("summary", "summaryValue2"); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); qDebug() << value->getProperty("uid").toByteArray(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid2")); @@ -130,7 +130,7 @@ private Q_SLOTS: void testResourceSync() { - auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); + auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); DummyResource resource("org.kde.dummy.instance1", pipeline); auto job = resource.synchronizeWithSource(); //TODO pass in optional timeout? @@ -145,16 +145,16 @@ private Q_SLOTS: void testSyncAndFacade() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!value->getProperty("summary").toString().isEmpty()); qDebug() << value->getProperty("summary").toString(); @@ -162,16 +162,16 @@ private Q_SLOTS: void testSyncAndFacadeMail() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!value->getProperty("subject").toString().isEmpty()); qDebug() << value->getProperty("subject").toString(); @@ -179,25 +179,25 @@ private Q_SLOTS: void testWriteModifyDelete() { - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.propertyFilter.insert("uid", "testuid"); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //Test create - Akonadi2::ApplicationDomain::Event event2; + Sink::ApplicationDomain::Event event2; { - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); @@ -206,30 +206,30 @@ private Q_SLOTS: event2.setProperty("uid", "testuid"); event2.setProperty("summary", "summaryValue2"); - Akonadi2::Store::modify(event2).exec().waitForFinished(); + Sink::Store::modify(event2).exec().waitForFinished(); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //Test modify { - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } - Akonadi2::Store::remove(event2).exec().waitForFinished(); + Sink::Store::remove(event2).exec().waitForFinished(); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //Test remove { - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } @@ -237,25 +237,25 @@ private Q_SLOTS: void testWriteModifyDeleteLive() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = true; query.propertyFilter.insert("uid", "testuid"); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); - Akonadi2::ApplicationDomain::Event event("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Event event("org.kde.dummy.instance1"); event.setProperty("uid", "testuid"); QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); event.setProperty("summary", "summaryValue"); - Akonadi2::Store::create(event).exec().waitForFinished(); + Sink::Store::create(event).exec().waitForFinished(); //Test create - Akonadi2::ApplicationDomain::Event event2; + Sink::ApplicationDomain::Event event2; { QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue")); event2 = *value; @@ -263,18 +263,18 @@ private Q_SLOTS: event2.setProperty("uid", "testuid"); event2.setProperty("summary", "summaryValue2"); - Akonadi2::Store::modify(event2).exec().waitForFinished(); + Sink::Store::modify(event2).exec().waitForFinished(); //Test modify { //TODO wait for a change signal QTRY_COMPARE(model->rowCount(QModelIndex()), 1); - auto value = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto value = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QCOMPARE(value->getProperty("uid").toByteArray(), QByteArray("testuid")); QCOMPARE(value->getProperty("summary").toByteArray(), QByteArray("summaryValue2")); } - Akonadi2::Store::remove(event2).exec().waitForFinished(); + Sink::Store::remove(event2).exec().waitForFinished(); //Test remove { diff --git a/tests/dummyresourcewritebenchmark.cpp b/tests/dummyresourcewritebenchmark.cpp index 1e7f1ef..1a8893b 100644 --- a/tests/dummyresourcewritebenchmark.cpp +++ b/tests/dummyresourcewritebenchmark.cpp @@ -60,33 +60,33 @@ static QByteArray createEntityBuffer(int &bufferSize) eventFbb.Clear(); { auto summary = eventFbb.CreateString("summary"); - Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); eventBuilder.add_summary(summary); auto eventLocation = eventBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); } flatbuffers::FlatBufferBuilder localFbb; { auto uid = localFbb.CreateString("testuid"); - auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); auto location = localBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } flatbuffers::FlatBufferBuilder entityFbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); bufferSize = entityFbb.GetSize(); flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); + Sink::Commands::CreateEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); auto location = builder.Finish(); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); return QByteArray(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); } @@ -109,7 +109,7 @@ class DummyResourceWriteBenchmark : public QObject QTime time; time.start(); - auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); + auto pipeline = QSharedPointer::create("org.kde.dummy.instance1"); DummyResource resource("org.kde.dummy.instance1", pipeline); int bufferSize = 0; @@ -117,7 +117,7 @@ class DummyResourceWriteBenchmark : public QObject const auto startingRss = getCurrentRSS(); for (int i = 0; i < num; i++) { - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); } auto appendTime = time.elapsed(); auto bufferSizeTotal = bufferSize * num; @@ -174,7 +174,7 @@ class DummyResourceWriteBenchmark : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + Sink::Log::setDebugOutputLevel(Sink::Log::Warning); } void cleanup() @@ -215,7 +215,7 @@ private Q_SLOTS: void getFreePages() { - std::system(QString("mdb_stat %1/%2 -ff").arg(Akonadi2::storageLocation()).arg("org.kde.dummy.instance1").toLatin1().constData()); + std::system(QString("mdb_stat %1/%2 -ff").arg(Sink::storageLocation()).arg("org.kde.dummy.instance1").toLatin1().constData()); } //This allows to run individual parts without doing a cleanup, but still cleaning up normally diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index bb95f4e..63e93f8 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp @@ -26,20 +26,20 @@ private Q_SLOTS: void init() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void testLoad() { - Akonadi2::Query query; + Sink::Query query; query.liveQuery = false; - auto resultSet = QSharedPointer >::create(); + auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); - // storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); + // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); TestResourceFacade facade("identifier", resourceAccess); - async::SyncListResult result(resultSet->emitter()); + async::SyncListResult result(resultSet->emitter()); facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); @@ -52,15 +52,15 @@ private Q_SLOTS: void testLiveQuery() { - Akonadi2::Query query; + Sink::Query query; query.liveQuery = true; - auto resultSet = QSharedPointer >::create(); + auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); - // storage->mResults << Akonadi2::ApplicationDomain::Event::Ptr::create(); + // storage->mResults << Sink::ApplicationDomain::Event::Ptr::create(); TestResourceFacade facade("identifier", resourceAccess); - async::SyncListResult result(resultSet->emitter()); + async::SyncListResult result(resultSet->emitter()); facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); @@ -70,7 +70,7 @@ private Q_SLOTS: //Enter a second result // storage->mResults.clear(); - // storage->mResults << QSharedPointer::create("resource", "id2", 0, QSharedPointer()); + // storage->mResults << QSharedPointer::create("resource", "id2", 0, QSharedPointer()); // storage->mLatestRevision = 2; resourceAccess->emit revisionChanged(2); @@ -83,17 +83,17 @@ private Q_SLOTS: void testLiveQueryModify() { - Akonadi2::Query query; + Sink::Query query; query.liveQuery = true; - auto resultSet = QSharedPointer >::create(); + auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); - auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); + auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); entity->setProperty("test", "test1"); // storage->mResults << entity; TestResourceFacade facade("identifier", resourceAccess); - async::SyncListResult result(resultSet->emitter()); + async::SyncListResult result(resultSet->emitter()); facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); @@ -103,7 +103,7 @@ private Q_SLOTS: //Modify the entity again // storage->mResults.clear(); - entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); + entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer::create()); entity->setProperty("test", "test2"); // storage->mModifications << entity; // storage->mLatestRevision = 2; @@ -119,16 +119,16 @@ private Q_SLOTS: void testLiveQueryRemove() { - Akonadi2::Query query; + Sink::Query query; query.liveQuery = true; - auto resultSet = QSharedPointer >::create(); + auto resultSet = QSharedPointer >::create(); auto resourceAccess = QSharedPointer::create(); - auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer()); + auto entity = QSharedPointer::create("resource", "id2", 0, QSharedPointer()); // storage->mResults << entity; TestResourceFacade facade("identifier", resourceAccess); - async::SyncListResult result(resultSet->emitter()); + async::SyncListResult result(resultSet->emitter()); facade.load(query, *resultSet).exec().waitForFinished(); resultSet->initialResultSetComplete(); diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp index fbe0d12..7f0d3a2 100644 --- a/tests/genericresourcebenchmark.cpp +++ b/tests/genericresourcebenchmark.cpp @@ -20,7 +20,7 @@ static void removeFromDisk(const QString &name) { - Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); + Sink::Storage store(Sink::storageLocation(), name, Sink::Storage::ReadWrite); store.removeFromDisk(); } @@ -30,39 +30,39 @@ static QByteArray createEntityBuffer() eventFbb.Clear(); { auto summary = eventFbb.CreateString("summary"); - Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); eventBuilder.add_summary(summary); auto eventLocation = eventBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); } flatbuffers::FlatBufferBuilder localFbb; { auto uid = localFbb.CreateString("testuid"); - auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); auto location = localBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } flatbuffers::FlatBufferBuilder entityFbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); + Sink::Commands::CreateEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); auto location = builder.Finish(); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); return QByteArray(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); } -class IndexUpdater : public Akonadi2::Preprocessor { +class IndexUpdater : public Sink::Preprocessor { public: - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { for (int i = 0; i < 10; i++) { Index ridIndex(QString("index.index%1").arg(i).toLatin1(), transaction); @@ -70,11 +70,11 @@ public: } } - void modifiedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { } - void deletedEntity(const QByteArray &key, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { } }; @@ -89,7 +89,7 @@ private Q_SLOTS: void init() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + Sink::Log::setDebugOutputLevel(Sink::Log::Warning); } void initTestCase() @@ -104,7 +104,7 @@ private Q_SLOTS: { int num = 10000; - auto pipeline = QSharedPointer::create("org.kde.test.instance1"); + auto pipeline = QSharedPointer::create("org.kde.test.instance1"); TestResource resource("org.kde.test.instance1", pipeline); auto command = createEntityBuffer(); @@ -113,7 +113,7 @@ private Q_SLOTS: time.start(); for (int i = 0; i < num; i++) { - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); } auto appendTime = time.elapsed(); @@ -139,13 +139,13 @@ private Q_SLOTS: { int num = 50000; - auto pipeline = QSharedPointer::create("org.kde.test.instance1"); + auto pipeline = QSharedPointer::create("org.kde.test.instance1"); auto eventFactory = QSharedPointer::create(); const QByteArray resourceIdentifier = "org.kde.test.instance1"; auto indexer = QSharedPointer::create(); - pipeline->setPreprocessors("event", QVector() << indexer.data()); + pipeline->setPreprocessors("event", QVector() << indexer.data()); pipeline->setAdaptorFactory("event", eventFactory); TestResource resource("org.kde.test.instance1", pipeline); @@ -156,7 +156,7 @@ private Q_SLOTS: time.start(); for (int i = 0; i < num; i++) { - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); } auto appendTime = time.elapsed(); @@ -180,7 +180,7 @@ private Q_SLOTS: void testCreateCommand() { - Akonadi2::ApplicationDomain::Event event; + Sink::ApplicationDomain::Event event; QBENCHMARK { auto mFactory = new TestEventAdaptorFactory; @@ -193,9 +193,9 @@ private Q_SLOTS: //This is the resource buffer type and not the domain type auto type = fbb.CreateString("event"); // auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto location = Sink::Commands::CreateCreateEntity(fbb, type, delta); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); } } diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp index 0c64659..76c604e 100644 --- a/tests/genericresourcetest.cpp +++ b/tests/genericresourcetest.cpp @@ -26,8 +26,8 @@ private Q_SLOTS: void init() { - Akonadi2::GenericResource::removeFromDisk("org.kde.test.instance1"); - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + Sink::GenericResource::removeFromDisk("org.kde.test.instance1"); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } ///Ensure the resource can process messages @@ -37,46 +37,46 @@ private Q_SLOTS: eventFbb.Clear(); { auto summary = eventFbb.CreateString("summary"); - Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); eventBuilder.add_summary(summary); auto eventLocation = eventBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); } flatbuffers::FlatBufferBuilder localFbb; { auto uid = localFbb.CreateString("testuid"); - auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); auto location = localBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } flatbuffers::FlatBufferBuilder entityFbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); + Sink::Commands::CreateEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); auto location = builder.Finish(); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); { flatbuffers::Verifier verifyer(reinterpret_cast(command.data()), command.size()); - QVERIFY(Akonadi2::Commands::VerifyCreateEntityBuffer(verifyer)); + QVERIFY(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); } //Actual test - auto pipeline = QSharedPointer::create("org.kde.test.instance1"); + auto pipeline = QSharedPointer::create("org.kde.test.instance1"); QSignalSpy revisionSpy(pipeline.data(), SIGNAL(revisionUpdated(qint64))); QVERIFY(revisionSpy.isValid()); TestResource resource("org.kde.test.instance1", pipeline); - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); - resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); + resource.processCommand(Sink::Commands::CreateEntityCommand, command); resource.processAllMessages().exec().waitForFinished(); QCOMPARE(revisionSpy.last().at(0).toInt(), 2); } diff --git a/tests/hawd/CMakeLists.txt b/tests/hawd/CMakeLists.txt index 071f2ba..268e7a9 100644 --- a/tests/hawd/CMakeLists.txt +++ b/tests/hawd/CMakeLists.txt @@ -26,7 +26,7 @@ set(SRCS add_library(lib${PROJECT_NAME} SHARED ${lib_SRCS}) generate_export_header(lib${PROJECT_NAME} BASE_NAME HAWD EXPORT_FILE_NAME hawd_export.h) qt5_use_modules(lib${PROJECT_NAME} Core) -target_link_libraries(lib${PROJECT_NAME} akonadi2common) +target_link_libraries(lib${PROJECT_NAME} sinkcommon) if (LIBGIT2_FOUND) target_link_libraries(lib${PROJECT_NAME} ${LIBGIT2_LIBRARIES}) endif(LIBGIT2_FOUND) diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index 93eb5cd..fd931e8 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp @@ -215,7 +215,7 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const Dataset::Dataset(const QString &name, const State &state) : m_definition(state.datasetDefinition(name)), - m_storage(state.resultsPath(), name, Akonadi2::Storage::ReadWrite), + m_storage(state.resultsPath(), name, Sink::Storage::ReadWrite), m_commitHash(state.commitHash()), m_transaction(std::move(m_storage.createTransaction())) { @@ -270,13 +270,13 @@ void Dataset::eachRow(const std::function &resultHandler) resultHandler(row); return true; }, - Akonadi2::Storage::basicErrorHandler()); + Sink::Storage::basicErrorHandler()); } Dataset::Row Dataset::row(qint64 key) { if (key < 1) { - Row row(*this, Akonadi2::Storage::maxRevision(m_transaction)); + Row row(*this, Sink::Storage::maxRevision(m_transaction)); row.setCommitHash(m_commitHash); return row; } @@ -287,7 +287,7 @@ Dataset::Row Dataset::row(qint64 key) row.fromBinary(value); return true; }, - Akonadi2::Storage::basicErrorHandler() + Sink::Storage::basicErrorHandler() ); return row; } diff --git a/tests/hawd/dataset.h b/tests/hawd/dataset.h index cdfd3f2..0fca8f0 100644 --- a/tests/hawd/dataset.h +++ b/tests/hawd/dataset.h @@ -84,8 +84,8 @@ public: private: DatasetDefinition m_definition; - Akonadi2::Storage m_storage; - Akonadi2::Storage::Transaction m_transaction; + Sink::Storage m_storage; + Sink::Storage::Transaction m_transaction; QString m_commitHash; }; diff --git a/tests/indextest.cpp b/tests/indextest.cpp index edaf907..7ec95ce 100644 --- a/tests/indextest.cpp +++ b/tests/indextest.cpp @@ -16,19 +16,19 @@ class IndexTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Storage store("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + Sink::Storage store("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite); store.removeFromDisk(); } void cleanup() { - Akonadi2::Storage store("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + Sink::Storage store("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite); store.removeFromDisk(); } void testIndex() { - Index index("./testindex", "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + Index index("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite); //The first key is specifically a substring of the second key index.add("key", "value1"); index.add("keyFoo", "value2"); diff --git a/tests/inspectiontest.cpp b/tests/inspectiontest.cpp index 29cce6c..c876aa9 100644 --- a/tests/inspectiontest.cpp +++ b/tests/inspectiontest.cpp @@ -18,8 +18,8 @@ class InspectionTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); DummyResource::removeFromDisk("org.kde.dummy.instance1"); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); @@ -27,11 +27,11 @@ private Q_SLOTS: void cleanup() { - Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); DummyResource::removeFromDisk("org.kde.dummy.instance1"); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); - Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } void testInspection_data() @@ -44,8 +44,8 @@ private Q_SLOTS: void testInspection() { QFETCH(bool, success); - using namespace Akonadi2; - using namespace Akonadi2::ApplicationDomain; + using namespace Sink; + using namespace Sink::ApplicationDomain; Mail mail(QByteArray("org.kde.dummy.instance1"), QByteArray("identifier"), 0, QSharedPointer::create()); diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index ec4f6a4..6ad6ca6 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -57,18 +57,18 @@ private Q_SLOTS: { targetPath = tempDir.path() + "/maildir1/"; - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); MaildirResource::removeFromDisk("org.kde.maildir.instance1"); - Akonadi2::ApplicationDomain::AkonadiResource resource; + Sink::ApplicationDomain::SinkResource resource; resource.setProperty("identifier", "org.kde.maildir.instance1"); resource.setProperty("type", "org.kde.maildir"); resource.setProperty("path", targetPath); - Akonadi2::Store::create(resource).exec().waitForFinished(); + Sink::Store::create(resource).exec().waitForFinished(); } void cleanup() { - Akonadi2::Store::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); + Sink::Store::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); MaildirResource::removeFromDisk("org.kde.maildir.instance1"); QDir dir(targetPath); dir.removeRecursively(); @@ -80,46 +80,46 @@ private Q_SLOTS: qDebug() << "-----------------------------------------"; qDebug(); copyRecursively(TESTDATAPATH "/maildir1", targetPath); - Akonadi2::Store::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); + Sink::Store::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); } void testListFolders() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 2); } void testListFolderTree() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; query.parentProperty = "parent"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 1); auto parentIndex = model->index(0, 0, QModelIndex()); model->fetchMore(parentIndex); - QTRY_VERIFY(model->data(parentIndex, Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(parentIndex, Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(parentIndex), 1); } void testListMailsOfFolder() { - using namespace Akonadi2; - using namespace Akonadi2::ApplicationDomain; + using namespace Sink; + using namespace Sink::ApplicationDomain; //Ensure all local data is processed auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); @@ -143,18 +143,18 @@ private Q_SLOTS: void testMailContent() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; query.requestedProperties << "folder" << "subject" << "mimeMessage" << "date"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto mailModel = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto mailModel = Sink::Store::loadModel(query); + QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QVERIFY(mailModel->rowCount(QModelIndex()) >= 1); - auto mail = mailModel->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto mail = mailModel->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!mail->getProperty("subject").toString().isEmpty()); QVERIFY(!mail->getProperty("mimeMessage").toString().isEmpty()); QVERIFY(mail->getProperty("date").toDateTime().isValid()); @@ -163,85 +163,85 @@ private Q_SLOTS: void testSyncFolderMove() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; query.requestedProperties << "name"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/"; QDir dir(targetPath); QVERIFY(dir.rename("inbox", "newbox")); //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 2); QCOMPARE(model->match(model->index(0, 0, QModelIndex()), Qt::DisplayRole, QStringLiteral("newbox"), 1).size(), 1); } void testReSyncMail() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; query.requestedProperties << "folder" << "subject"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto mailModel = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto mailModel = Sink::Store::loadModel(query); + QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(mailModel->rowCount(QModelIndex()), 2); } void testSyncMailRemoval() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; query.requestedProperties << "folder" << "subject"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; QFile file(targetPath); QVERIFY(file.remove()); //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto mailModel = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(mailModel->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto mailModel = Sink::Store::loadModel(query); + QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(mailModel->rowCount(QModelIndex()), 1); } void testCreateFolder() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - Akonadi2::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); + Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); folder.setProperty("name", "testCreateFolder"); - Akonadi2::Store::create(folder).exec().waitForFinished(); + Sink::Store::create(folder).exec().waitForFinished(); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; QFileInfo file(targetPath); @@ -251,45 +251,45 @@ private Q_SLOTS: void testRemoveFolder() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; - Akonadi2::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); + Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); folder.setProperty("name", "testCreateFolder"); - Akonadi2::Store::create(folder).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::create(folder).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); QTRY_VERIFY(QFileInfo(targetPath).exists()); - Akonadi2::Query folderQuery; + Sink::Query folderQuery; folderQuery.resources << "org.kde.maildir.instance1"; folderQuery.propertyFilter.insert("name", "testCreateFolder"); - auto model = Akonadi2::Store::loadModel(folderQuery); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(folderQuery); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(QModelIndex()), 1); - auto createdFolder = model->index(0, 0, QModelIndex()).data(Akonadi2::Store::DomainObjectRole).value(); + auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); - Akonadi2::Store::remove(*createdFolder).exec().waitForFinished(); - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::remove(*createdFolder).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); QTRY_VERIFY(!QFileInfo(targetPath).exists()); } void testCreateMail() { - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.maildir.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - Akonadi2::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); + Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); mail.setProperty("name", "testCreateMail"); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/new"; QDir dir(targetPath); @@ -299,8 +299,8 @@ private Q_SLOTS: void testRemoveMail() { - using namespace Akonadi2; - using namespace Akonadi2::ApplicationDomain; + using namespace Sink; + using namespace Sink::ApplicationDomain; auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); @@ -333,8 +333,8 @@ private Q_SLOTS: void testMarkMailAsRead() { - using namespace Akonadi2; - using namespace Akonadi2::ApplicationDomain; + using namespace Sink; + using namespace Sink::ApplicationDomain; auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp index 7d406ed..c835b53 100644 --- a/tests/messagequeuetest.cpp +++ b/tests/messagequeuetest.cpp @@ -17,8 +17,8 @@ class MessageQueueTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); - Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue", Akonadi2::Storage::ReadWrite); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + Sink::Storage store(Sink::Store::storageLocation(), "org.kde.dummy.testqueue", Sink::Storage::ReadWrite); store.removeFromDisk(); } @@ -28,13 +28,13 @@ private Q_SLOTS: void cleanup() { - Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue", Akonadi2::Storage::ReadWrite); + Sink::Storage store(Sink::Store::storageLocation(), "org.kde.dummy.testqueue", Sink::Storage::ReadWrite); store.removeFromDisk(); } void testEmpty() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); QVERIFY(queue.isEmpty()); queue.enqueue("value"); QVERIFY(!queue.isEmpty()); @@ -42,7 +42,7 @@ private Q_SLOTS: void testDequeueEmpty() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); bool gotValue = false; bool gotError = false; queue.dequeue([&](void *ptr, int size, std::function callback) { @@ -57,7 +57,7 @@ private Q_SLOTS: void testEnqueue() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); QSignalSpy spy(&queue, SIGNAL(messageReady())); queue.enqueue("value1"); QCOMPARE(spy.size(), 1); @@ -65,7 +65,7 @@ private Q_SLOTS: void testDrained() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); QSignalSpy spy(&queue, SIGNAL(drained())); queue.enqueue("value1"); @@ -81,7 +81,7 @@ private Q_SLOTS: values << "value1"; values << "value2"; - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); for (const QByteArray &value : values) { queue.enqueue(value); } @@ -112,7 +112,7 @@ private Q_SLOTS: values << "value1"; values << "value2"; - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); for (const QByteArray &value : values) { queue.enqueue(value); } @@ -151,7 +151,7 @@ private Q_SLOTS: */ void testNestedEnqueue() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); queue.enqueue("value1"); bool gotError = false; @@ -167,7 +167,7 @@ private Q_SLOTS: void testBatchDequeue() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); queue.enqueue("value1"); queue.enqueue("value2"); queue.enqueue("value3"); @@ -188,7 +188,7 @@ private Q_SLOTS: void testBatchEnqueue() { - MessageQueue queue(Akonadi2::Store::storageLocation(), "org.kde.dummy.testqueue"); + MessageQueue queue(Sink::Store::storageLocation(), "org.kde.dummy.testqueue"); QSignalSpy spy(&queue, SIGNAL(messageReady())); queue.startTransaction(); queue.enqueue("value1"); diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp index 59c2c6f..14c9fd0 100644 --- a/tests/modelinteractivitytest.cpp +++ b/tests/modelinteractivitytest.cpp @@ -45,16 +45,16 @@ class ModelinteractivityTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + Sink::Log::setDebugOutputLevel(Sink::Log::Warning); DummyResource::removeFromDisk("org.kde.dummy.instance1"); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); } void cleanup() { - Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); DummyResource::removeFromDisk("org.kde.dummy.instance1"); - Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } void init() @@ -65,24 +65,24 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); for (int i = 0; i < 1000; i++) { - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } } - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = true; - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //Test QTime time; time.start(); - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); blockingTime += time.elapsed(); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); //Never block longer than 10 ms QVERIFY2(blockingTime < 10, QString("Total blocking time: %1").arg(blockingTime).toLatin1().data()); } diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index f0fd1a4..c74d319 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -22,14 +22,14 @@ static void removeFromDisk(const QString &name) { - Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite); + Sink::Storage store(Sink::Store::storageLocation(), name, Sink::Storage::ReadWrite); store.removeFromDisk(); } static QList getKeys(const QByteArray &dbEnv, const QByteArray &name) { - Akonadi2::Storage store(Akonadi2::storageLocation(), dbEnv, Akonadi2::Storage::ReadOnly); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadOnly); + Sink::Storage store(Sink::storageLocation(), dbEnv, Sink::Storage::ReadOnly); + auto transaction = store.createTransaction(Sink::Storage::ReadOnly); auto db = transaction.openDatabase(name, nullptr, false); QList result; db.scan("", [&](const QByteArray &key, const QByteArray &value) { @@ -41,8 +41,8 @@ static QList getKeys(const QByteArray &dbEnv, const QByteArray &name static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, const QByteArray &uid) { - Akonadi2::Storage store(Akonadi2::storageLocation(), dbEnv, Akonadi2::Storage::ReadOnly); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadOnly); + Sink::Storage store(Sink::storageLocation(), dbEnv, Sink::Storage::ReadOnly); + auto transaction = store.createTransaction(Sink::Storage::ReadOnly); auto db = transaction.openDatabase(name, nullptr, false); QByteArray result; db.scan(uid, [&](const QByteArray &key, const QByteArray &value) { @@ -57,41 +57,41 @@ flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &enti flatbuffers::FlatBufferBuilder eventFbb; eventFbb.Clear(); { - Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); auto eventLocation = eventBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); } flatbuffers::FlatBufferBuilder localFbb; { auto uid = localFbb.CreateString("testuid"); auto summary = localFbb.CreateString(s.toStdString()); - auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); localBuilder.add_summary(summary); auto location = localBuilder.Finish(); - Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); return entityFbb; } QByteArray createEntityCommand(const flatbuffers::FlatBufferBuilder &entityFbb) { flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); + Sink::Commands::CreateEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); auto location = builder.Finish(); - Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + Sink::Commands::FinishCreateEntityBuffer(fbb, location); const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); { flatbuffers::Verifier verifyer(reinterpret_cast(command.data()), command.size()); - Q_ASSERT(Akonadi2::Commands::VerifyCreateEntityBuffer(verifyer)); + Q_ASSERT(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); } return command; } @@ -99,22 +99,22 @@ QByteArray createEntityCommand(const flatbuffers::FlatBufferBuilder &entityFbb) QByteArray modifyEntityCommand(const flatbuffers::FlatBufferBuilder &entityFbb, const QByteArray &uid, qint64 revision) { flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto id = fbb.CreateString(std::string(uid.constData(), uid.size())); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - // auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); - Akonadi2::Commands::ModifyEntityBuilder builder(fbb); + // auto delta = Sink::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); + Sink::Commands::ModifyEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_delta(delta); builder.add_revision(revision); builder.add_entityId(id); auto location = builder.Finish(); - Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); + Sink::Commands::FinishModifyEntityBuffer(fbb, location); const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); { flatbuffers::Verifier verifyer(reinterpret_cast(command.data()), command.size()); - Q_ASSERT(Akonadi2::Commands::VerifyCreateEntityBuffer(verifyer)); + Q_ASSERT(Sink::Commands::VerifyCreateEntityBuffer(verifyer)); } return command; } @@ -122,38 +122,38 @@ QByteArray modifyEntityCommand(const flatbuffers::FlatBufferBuilder &entityFbb, QByteArray deleteEntityCommand(const QByteArray &uid, qint64 revision) { flatbuffers::FlatBufferBuilder fbb; - auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName().toStdString().data()); auto id = fbb.CreateString(std::string(uid.constData(), uid.size())); - Akonadi2::Commands::DeleteEntityBuilder builder(fbb); + Sink::Commands::DeleteEntityBuilder builder(fbb); builder.add_domainType(type); builder.add_revision(revision); builder.add_entityId(id); auto location = builder.Finish(); - Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); + Sink::Commands::FinishDeleteEntityBuffer(fbb, location); const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); { flatbuffers::Verifier verifyer(reinterpret_cast(command.data()), command.size()); - Q_ASSERT(Akonadi2::Commands::VerifyDeleteEntityBuffer(verifyer)); + Q_ASSERT(Sink::Commands::VerifyDeleteEntityBuffer(verifyer)); } return command; } -class TestProcessor : public Akonadi2::Preprocessor { +class TestProcessor : public Sink::Preprocessor { public: - void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { newUids << uid; newRevisions << revision; } - void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { modifiedUids << uid; modifiedRevisions << revision; } - void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { deletedUids << uid; deletedRevisions << revision; @@ -178,7 +178,7 @@ class PipelineTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void init() @@ -191,7 +191,7 @@ private Q_SLOTS: flatbuffers::FlatBufferBuilder entityFbb; auto command = createEntityCommand(createEvent(entityFbb)); - Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); + Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); pipeline.startTransaction(); pipeline.newEntity(command.constData(), command.size()); pipeline.commit(); @@ -205,7 +205,7 @@ private Q_SLOTS: flatbuffers::FlatBufferBuilder entityFbb; auto command = createEntityCommand(createEvent(entityFbb)); - Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); + Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); auto adaptorFactory = QSharedPointer::create(); pipeline.setAdaptorFactory("event", adaptorFactory); @@ -219,7 +219,7 @@ private Q_SLOTS: auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); QCOMPARE(keys.size(), 1); const auto key = keys.first(); - const auto uid = Akonadi2::Storage::uidFromKey(key); + const auto uid = Sink::Storage::uidFromKey(key); //Execute the modification entityFbb.Clear(); @@ -229,9 +229,9 @@ private Q_SLOTS: pipeline.commit(); //Ensure we've got the new revision with the modification - auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Akonadi2::Storage::assembleKey(uid, 2)); + auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 2)); QVERIFY(!buffer.isEmpty()); - Akonadi2::EntityBuffer entityBuffer(buffer.data(), buffer.size()); + Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary2")); @@ -252,7 +252,7 @@ private Q_SLOTS: flatbuffers::FlatBufferBuilder entityFbb; auto command = createEntityCommand(createEvent(entityFbb)); - Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); + Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); auto adaptorFactory = QSharedPointer::create(); pipeline.setAdaptorFactory("event", adaptorFactory); @@ -265,7 +265,7 @@ private Q_SLOTS: //Get uid of written entity auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Akonadi2::Storage::uidFromKey(keys.first()); + const auto uid = Sink::Storage::uidFromKey(keys.first()); //Create another operation inbetween @@ -285,9 +285,9 @@ private Q_SLOTS: pipeline.commit(); //Ensure we've got the new revision with the modification - auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Akonadi2::Storage::assembleKey(uid, 3)); + auto buffer = getEntity("org.kde.pipelinetest.instance1", "event.main", Sink::Storage::assembleKey(uid, 3)); QVERIFY(!buffer.isEmpty()); - Akonadi2::EntityBuffer entityBuffer(buffer.data(), buffer.size()); + Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary2")); } @@ -296,7 +296,7 @@ private Q_SLOTS: { flatbuffers::FlatBufferBuilder entityFbb; auto command = createEntityCommand(createEvent(entityFbb)); - Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); + Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); pipeline.setAdaptorFactory("event", QSharedPointer::create()); //Create the initial revision @@ -307,7 +307,7 @@ private Q_SLOTS: auto result = getKeys("org.kde.pipelinetest.instance1", "event.main"); QCOMPARE(result.size(), 1); - const auto uid = Akonadi2::Storage::uidFromKey(result.first()); + const auto uid = Sink::Storage::uidFromKey(result.first()); //Delete entity auto deleteCommand = deleteEntityCommand(uid, 1); @@ -333,8 +333,8 @@ private Q_SLOTS: TestProcessor testProcessor; - Akonadi2::Pipeline pipeline("org.kde.pipelinetest.instance1"); - pipeline.setPreprocessors("event", QVector() << &testProcessor); + Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); + pipeline.setPreprocessors("event", QVector() << &testProcessor); pipeline.startTransaction(); pipeline.setAdaptorFactory("event", QSharedPointer::create()); @@ -345,21 +345,21 @@ private Q_SLOTS: QCOMPARE(testProcessor.newUids.size(), 1); QCOMPARE(testProcessor.newRevisions.size(), 1); //Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor.newUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.newUids.at(0))); + QCOMPARE(testProcessor.newUids.at(0), Sink::Storage::uidFromKey(testProcessor.newUids.at(0))); } pipeline.commit(); entityFbb.Clear(); pipeline.startTransaction(); auto keys = getKeys("org.kde.pipelinetest.instance1", "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Akonadi2::Storage::uidFromKey(keys.first()); + const auto uid = Sink::Storage::uidFromKey(keys.first()); { auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); QCOMPARE(testProcessor.modifiedUids.size(), 1); QCOMPARE(testProcessor.modifiedRevisions.size(), 1); //Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor.modifiedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.modifiedUids.at(0))); + QCOMPARE(testProcessor.modifiedUids.at(0), Sink::Storage::uidFromKey(testProcessor.modifiedUids.at(0))); } pipeline.commit(); entityFbb.Clear(); @@ -371,7 +371,7 @@ private Q_SLOTS: QCOMPARE(testProcessor.deletedUids.size(), 1); QCOMPARE(testProcessor.deletedSummaries.size(), 1); //Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor.deletedUids.at(0), Akonadi2::Storage::uidFromKey(testProcessor.deletedUids.at(0))); + QCOMPARE(testProcessor.deletedUids.at(0), Sink::Storage::uidFromKey(testProcessor.deletedUids.at(0))); QCOMPARE(testProcessor.deletedSummaries.at(0), QByteArray("summary2")); } } diff --git a/tests/querytest.cpp b/tests/querytest.cpp index f9344cd..62db15b 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -20,8 +20,8 @@ class QueryTest : public QObject private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Trace); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); DummyResource::removeFromDisk("org.kde.dummy.instance1"); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); @@ -29,11 +29,11 @@ private Q_SLOTS: void cleanup() { - Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); DummyResource::removeFromDisk("org.kde.dummy.instance1"); - auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); + auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); - Akonadi2::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); + Sink::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } void init() @@ -46,13 +46,13 @@ private Q_SLOTS: void testNoResources() { //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "foobar"; query.liveQuery = true; //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 0); } @@ -61,17 +61,17 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = true; //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); } @@ -80,23 +80,23 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = false; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } @@ -105,31 +105,31 @@ private Q_SLOTS: QByteArray id; //Setup { - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); - Akonadi2::Store::create(mail).exec().waitForFinished(); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::synchronize(query).exec().waitForFinished(); + Sink::Store::synchronize(query).exec().waitForFinished(); //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QVERIFY(model->rowCount() >= 1); - id = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value()->identifier(); + id = model->index(0, 0).data(Sink::Store::DomainObjectRole).value()->identifier(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.ids << id; - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } @@ -137,20 +137,20 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); - Akonadi2::Store::create(folder).exec().waitForFinished(); + Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = true; //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); QTRY_COMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); } @@ -158,42 +158,42 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); - Akonadi2::Store::create(folder).exec().waitForFinished(); + Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); - auto folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value(); + auto folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); - Akonadi2::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Folder subfolder("org.kde.dummy.instance1"); subfolder.setProperty("parent", folderEntity->identifier()); - Akonadi2::Store::create(subfolder).exec().waitForFinished(); + Sink::Store::create(subfolder).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.parentProperty = "parent"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); + auto model = Sink::Store::loadModel(query); model->fetchMore(QModelIndex()); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); model->fetchMore(model->index(0, 0)); - QTRY_VERIFY(model->data(model->index(0, 0), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QTRY_VERIFY(model->data(model->index(0, 0), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(model->index(0, 0)), 1); } @@ -201,65 +201,65 @@ private Q_SLOTS: { //Setup { - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); mail.setProperty("uid", "test1"); mail.setProperty("sender", "doe@example.org"); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.liveQuery = false; query.propertyFilter.insert("uid", "test1"); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } void testMailByFolder() { //Setup - Akonadi2::ApplicationDomain::Folder::Ptr folderEntity; + Sink::ApplicationDomain::Folder::Ptr folderEntity; { - Akonadi2::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); - Akonadi2::Store::create(folder).exec().waitForFinished(); + Sink::ApplicationDomain::Folder folder("org.kde.dummy.instance1"); + Sink::Store::create(folder).exec().waitForFinished(); - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); - folderEntity = model->index(0, 0).data(Akonadi2::Store::DomainObjectRole).value(); + folderEntity = model->index(0, 0).data(Sink::Store::DomainObjectRole).value(); QVERIFY(!folderEntity->identifier().isEmpty()); - Akonadi2::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); + Sink::ApplicationDomain::Mail mail("org.kde.dummy.instance1"); mail.setProperty("uid", "test1"); mail.setProperty("folder", folderEntity->identifier()); - Akonadi2::Store::create(mail).exec().waitForFinished(); + Sink::Store::create(mail).exec().waitForFinished(); } //Test - Akonadi2::Query query; + Sink::Query query; query.resources << "org.kde.dummy.instance1"; query.propertyFilter.insert("folder", folderEntity->identifier()); //Ensure all local data is processed - Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch before the data is available and rely on the live query mechanism to deliver the actual data - auto model = Akonadi2::Store::loadModel(query); - QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + auto model = Sink::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); } }; diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp index 1b09c5f..f9ea3de 100644 --- a/tests/resourcecommunicationtest.cpp +++ b/tests/resourcecommunicationtest.cpp @@ -16,9 +16,9 @@ private Q_SLOTS: { const QByteArray resourceIdentifier("test"); Listener listener(resourceIdentifier); - Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + Sink::ResourceAccess resourceAccess(resourceIdentifier); - QSignalSpy spy(&resourceAccess, &Akonadi2::ResourceAccess::ready); + QSignalSpy spy(&resourceAccess, &Sink::ResourceAccess::ready); resourceAccess.open(); QTRY_COMPARE(spy.size(), 1); } @@ -27,14 +27,14 @@ private Q_SLOTS: { const QByteArray resourceIdentifier("test"); Listener listener(resourceIdentifier); - Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + Sink::ResourceAccess resourceAccess(resourceIdentifier); resourceAccess.open(); flatbuffers::FlatBufferBuilder fbb; auto name = fbb.CreateString("test"); - auto command = Akonadi2::Commands::CreateHandshake(fbb, name); - Akonadi2::Commands::FinishHandshakeBuffer(fbb, command); - auto result = resourceAccess.sendCommand(Akonadi2::Commands::HandshakeCommand, fbb).exec(); + auto command = Sink::Commands::CreateHandshake(fbb, name); + Sink::Commands::FinishHandshakeBuffer(fbb, command); + auto result = resourceAccess.sendCommand(Sink::Commands::HandshakeCommand, fbb).exec(); result.waitForFinished(); QVERIFY(!result.errorCode()); } @@ -43,14 +43,14 @@ private Q_SLOTS: { const QByteArray resourceIdentifier("test"); Listener listener(resourceIdentifier); - Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + Sink::ResourceAccess resourceAccess(resourceIdentifier); resourceAccess.open(); const int count = 500; int complete = 0; int errors = 0; for (int i = 0; i < count; i++) { - auto result = resourceAccess.sendCommand(Akonadi2::Commands::PingCommand) + auto result = resourceAccess.sendCommand(Sink::Commands::PingCommand) .then([&complete]() { complete++; }, @@ -69,14 +69,14 @@ private Q_SLOTS: qDebug(); const QByteArray resourceIdentifier("test"); Listener listener(resourceIdentifier); - Akonadi2::ResourceAccess resourceAccess(resourceIdentifier); + Sink::ResourceAccess resourceAccess(resourceIdentifier); resourceAccess.open(); const int count = 10; int complete = 0; int errors = 0; for (int i = 0; i < count; i++) { - resourceAccess.sendCommand(Akonadi2::Commands::PingCommand) + resourceAccess.sendCommand(Sink::Commands::PingCommand) .then([&complete]() { complete++; }, diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index 3e7b609..eada4ee 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp @@ -54,7 +54,7 @@ private: private Q_SLOTS: void initTestCase() { - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + Sink::Log::setDebugOutputLevel(Sink::Log::Warning); testDataPath = "./testdb"; dbName = "test"; filePath = testDataPath + "buffer.fb"; @@ -62,7 +62,7 @@ private Q_SLOTS: void cleanupTestCase() { - Akonadi2::Storage store(testDataPath, dbName); + Sink::Storage store(testDataPath, dbName); store.removeFromDisk(); } @@ -70,7 +70,7 @@ private Q_SLOTS: { auto event = createEvent(); - QScopedPointer store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite)); + QScopedPointer store(new Sink::Storage(testDataPath, dbName, Sink::Storage::ReadWrite)); const char *keyPrefix = "key"; @@ -78,12 +78,12 @@ private Q_SLOTS: time.start(); //Test db write time { - auto transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); + auto transaction = store->createTransaction(Sink::Storage::ReadWrite); for (int i = 0; i < count; i++) { transaction.openDatabase().write(keyPrefix + QByteArray::number(i), event); if ((i % 10000) == 0) { transaction.commit(); - transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); + transaction = store->createTransaction(Sink::Storage::ReadWrite); } } transaction.commit(); @@ -105,7 +105,7 @@ private Q_SLOTS: //Db read time { - auto transaction = store->createTransaction(Akonadi2::Storage::ReadOnly); + auto transaction = store->createTransaction(Sink::Storage::ReadOnly); auto db = transaction.openDatabase(); for (int i = 0; i < count; i++) { db.scan(keyPrefix + QByteArray::number(i), [](const QByteArray &key, const QByteArray &value) -> bool { return true; }); @@ -126,7 +126,7 @@ private Q_SLOTS: void testSizes() { - Akonadi2::Storage store(testDataPath, dbName); + Sink::Storage store(testDataPath, dbName); qDebug() << "Database size [kb]: " << store.diskUsage()/1024; QFileInfo fileInfo(filePath); @@ -135,11 +135,11 @@ private Q_SLOTS: void testScan() { - QScopedPointer store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly)); + QScopedPointer store(new Sink::Storage(testDataPath, dbName, Sink::Storage::ReadOnly)); QBENCHMARK { int hit = 0; - store->createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { + store->createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { if (key == "key10000") { //qDebug() << "hit"; hit++; @@ -152,11 +152,11 @@ private Q_SLOTS: void testKeyLookup() { - QScopedPointer store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly)); + QScopedPointer store(new Sink::Storage(testDataPath, dbName, Sink::Storage::ReadOnly)); QBENCHMARK { int hit = 0; - store->createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("key40000", [&](const QByteArray &key, const QByteArray &value) -> bool { + store->createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key40000", [&](const QByteArray &key, const QByteArray &value) -> bool { hit++; return true; }); diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index d950961..b0db1ac 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -21,14 +21,14 @@ private: void populate(int count) { - Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = storage.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = storage.createTransaction(Sink::Storage::ReadWrite); for (int i = 0; i < count; i++) { //This should perhaps become an implementation detail of the db? if (i % 10000 == 0) { if (i > 0) { transaction.commit(); - transaction = std::move(storage.createTransaction(Akonadi2::Storage::ReadWrite)); + transaction = std::move(storage.createTransaction(Sink::Storage::ReadWrite)); } } transaction.openDatabase().write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i)); @@ -36,12 +36,12 @@ private: transaction.commit(); } - bool verify(Akonadi2::Storage &storage, int i) + bool verify(Sink::Storage &storage, int i) { bool success = true; bool keyMatch = true; const auto reference = keyPrefix + QByteArray::number(i); - storage.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan(keyPrefix + QByteArray::number(i), + storage.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan(keyPrefix + QByteArray::number(i), [&keyMatch, &reference](const QByteArray &key, const QByteArray &value) -> bool { if (value != reference) { qDebug() << "Mismatch while reading"; @@ -49,7 +49,7 @@ private: } return keyMatch; }, - [&success](const Akonadi2::Storage::Error &error) { + [&success](const Sink::Storage::Error &error) { qDebug() << error.message; success = false; } @@ -62,20 +62,20 @@ private Q_SLOTS: { testDataPath = "./testdb"; dbName = "test"; - Akonadi2::Storage storage(testDataPath, dbName); + Sink::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } void cleanup() { - Akonadi2::Storage storage(testDataPath, dbName); + Sink::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } void testCleanup() { populate(1); - Akonadi2::Storage storage(testDataPath, dbName); + Sink::Storage storage(testDataPath, dbName); storage.removeFromDisk(); QFileInfo info(testDataPath + "/" + dbName); QVERIFY(!info.exists()); @@ -89,7 +89,7 @@ private Q_SLOTS: //ensure we can read everything back correctly { - Akonadi2::Storage storage(testDataPath, dbName); + Sink::Storage storage(testDataPath, dbName); for (int i = 0; i < count; i++) { QVERIFY(verify(storage, i)); } @@ -104,8 +104,8 @@ private Q_SLOTS: //ensure we can scan for values { int hit = 0; - Akonadi2::Storage store(testDataPath, dbName); - store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { + Sink::Storage store(testDataPath, dbName); + store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { if (key == "key50") { hit++; } @@ -118,8 +118,8 @@ private Q_SLOTS: { int hit = 0; bool foundInvalidValue = false; - Akonadi2::Storage store(testDataPath, dbName); - store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool { + Sink::Storage store(testDataPath, dbName); + store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key50", [&](const QByteArray &key, const QByteArray &value) -> bool { if (key != "key50") { foundInvalidValue = true; } @@ -134,10 +134,10 @@ private Q_SLOTS: void testNestedOperations() { populate(3); - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); transaction.openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { - transaction.openDatabase().remove(key, [](const Akonadi2::Storage::Error &) { + transaction.openDatabase().remove(key, [](const Sink::Storage::Error &) { QVERIFY(false); }); return false; @@ -147,9 +147,9 @@ private Q_SLOTS: void testNestedTransactions() { populate(3); - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { - store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase().remove(key, [](const Akonadi2::Storage::Error &) { + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + store.createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("key1", [&](const QByteArray &key, const QByteArray &value) -> bool { + store.createTransaction(Sink::Storage::ReadWrite).openDatabase().remove(key, [](const Sink::Storage::Error &) { QVERIFY(false); }); return false; @@ -160,9 +160,9 @@ private Q_SLOTS: { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadOnly); - auto db = transaction.openDatabase("default", [&](const Akonadi2::Storage::Error &error) { + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadOnly); + auto db = transaction.openDatabase("default", [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -170,7 +170,7 @@ private Q_SLOTS: gotResult = true; return false; }, - [&](const Akonadi2::Storage::Error &error) { + [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -195,8 +195,8 @@ private Q_SLOTS: const int concurrencyLevel = 20; for (int num = 0; num < concurrencyLevel; num++) { futures << QtConcurrent::run([this, count, &error](){ - Akonadi2::Storage storage(testDataPath, dbName, Akonadi2::Storage::ReadOnly); - Akonadi2::Storage storage2(testDataPath, dbName + "2", Akonadi2::Storage::ReadOnly); + Sink::Storage storage(testDataPath, dbName, Sink::Storage::ReadOnly); + Sink::Storage storage2(testDataPath, dbName + "2", Sink::Storage::ReadOnly); for (int i = 0; i < count; i++) { if (!verify(storage, i)) { error = true; @@ -212,9 +212,9 @@ private Q_SLOTS: } { - Akonadi2::Storage storage(testDataPath, dbName); + Sink::Storage storage(testDataPath, dbName); storage.removeFromDisk(); - Akonadi2::Storage storage2(testDataPath, dbName + "2"); + Sink::Storage storage2(testDataPath, dbName + "2"); storage2.removeFromDisk(); } } @@ -223,8 +223,8 @@ private Q_SLOTS: { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("default", nullptr, false); db.write("key","value"); db.write("key","value"); @@ -233,7 +233,7 @@ private Q_SLOTS: gotResult = true; return true; }, - [&](const Akonadi2::Storage::Error &error) { + [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -246,8 +246,8 @@ private Q_SLOTS: { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("default", nullptr, true); db.write("key","value1"); db.write("key","value2"); @@ -255,7 +255,7 @@ private Q_SLOTS: gotResult = true; return true; }, - [&](const Akonadi2::Storage::Error &error) { + [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -268,12 +268,12 @@ private Q_SLOTS: { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); - int numValues = store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadOnly); + int numValues = store.createTransaction(Sink::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { gotResult = true; return false; }, - [&](const Akonadi2::Storage::Error &error) { + [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -285,8 +285,8 @@ private Q_SLOTS: void testWriteToNamedDb() { bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -296,8 +296,8 @@ private Q_SLOTS: void testWriteDuplicatesToNamedDb() { bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + store.createTransaction(Sink::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Sink::Storage::Error &error) { qDebug() << error.message; gotError = true; }); @@ -307,8 +307,8 @@ private Q_SLOTS: //By default we want only exact matches void testSubstringKeys() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, true); db.write("sub","value1"); db.write("subsub","value2"); @@ -321,8 +321,8 @@ private Q_SLOTS: void testFindSubstringKeys() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, false); db.write("sub","value1"); db.write("subsub","value2"); @@ -336,8 +336,8 @@ private Q_SLOTS: void testKeySorting() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, false); db.write("sub_2","value2"); db.write("sub_1","value1"); @@ -357,8 +357,8 @@ private Q_SLOTS: //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. void testKeyRange() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, true); db.write("sub1","value1"); int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { @@ -370,8 +370,8 @@ private Q_SLOTS: void testFindLatest() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, false); db.write("sub1","value1"); db.write("sub2","value2"); @@ -387,8 +387,8 @@ private Q_SLOTS: void testFindLatestInSingle() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, false); db.write("sub2","value2"); QByteArray result; @@ -401,8 +401,8 @@ private Q_SLOTS: void testFindLast() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); auto db = transaction.openDatabase("test", nullptr, false); db.write("sub2","value2"); db.write("wub3","value3"); @@ -416,11 +416,11 @@ private Q_SLOTS: void testRecordRevision() { - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); - auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); - Akonadi2::Storage::recordRevision(transaction, 1, "uid", "type"); - QCOMPARE(Akonadi2::Storage::getTypeFromRevision(transaction, 1), QByteArray("type")); - QCOMPARE(Akonadi2::Storage::getUidFromRevision(transaction, 1), QByteArray("uid")); + Sink::Storage store(testDataPath, dbName, Sink::Storage::ReadWrite); + auto transaction = store.createTransaction(Sink::Storage::ReadWrite); + Sink::Storage::recordRevision(transaction, 1, "uid", "type"); + QCOMPARE(Sink::Storage::getTypeFromRevision(transaction, 1), QByteArray("type")); + QCOMPARE(Sink::Storage::getUidFromRevision(transaction, 1), QByteArray("uid")); } }; diff --git a/tests/testimplementations.h b/tests/testimplementations.h index a47a775..785c408 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -30,7 +30,7 @@ //Replace with something different #include "event_generated.h" -class TestEventAdaptorFactory : public DomainTypeAdaptorFactory +class TestEventAdaptorFactory : public DomainTypeAdaptorFactory { public: TestEventAdaptorFactory() @@ -41,7 +41,7 @@ public: virtual ~TestEventAdaptorFactory() {}; }; -class TestResourceAccess : public Akonadi2::ResourceAccessInterface +class TestResourceAccess : public Sink::ResourceAccessInterface { Q_OBJECT public: @@ -55,11 +55,11 @@ public Q_SLOTS: void close() Q_DECL_OVERRIDE {} }; -class TestResourceFacade : public Akonadi2::GenericFacade +class TestResourceFacade : public Sink::GenericFacade { public: - TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer resourceAccess) - : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create(), resourceAccess) + TestResourceFacade(const QByteArray &instanceIdentifier, const QSharedPointer resourceAccess) + : Sink::GenericFacade(instanceIdentifier, QSharedPointer::create(), resourceAccess) { } @@ -69,11 +69,11 @@ public: } }; -class TestResource : public Akonadi2::GenericResource +class TestResource : public Sink::GenericResource { public: - TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) - : Akonadi2::GenericResource(instanceIdentifier, pipeline) + TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) + : Sink::GenericResource(instanceIdentifier, pipeline) { } -- cgit v1.2.3