From 1ef70a4c8c2bb9fd70d5bc73614b09177b6b970c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 2 Jan 2017 00:19:01 +0100 Subject: Foldercontroller --- framework/domain/CMakeLists.txt | 1 + framework/domain/controller.h | 8 ++++++ framework/domain/foldercontroller.cpp | 50 +++++++++++++++++++++++++++++++++++ framework/domain/foldercontroller.h | 33 +++++++++++++++++++++++ framework/domain/mailcontroller.h | 7 ----- framework/domain/mailplugin.cpp | 2 ++ 6 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 framework/domain/foldercontroller.cpp create mode 100644 framework/domain/foldercontroller.h (limited to 'framework/domain') diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index 8f343928..70a86d01 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt @@ -25,6 +25,7 @@ set(mailplugin_SRCS controller.cpp outboxcontroller.cpp mailcontroller.cpp + foldercontroller.cpp ) find_package(KF5 REQUIRED COMPONENTS Package) diff --git a/framework/domain/controller.h b/framework/domain/controller.h index c152a588..77baa606 100644 --- a/framework/domain/controller.h +++ b/framework/domain/controller.h @@ -35,6 +35,14 @@ void clear##NAME() { setProperty(NAME::name, QVariant{}); } \ TYPE get##NAME() const { return m##NAME; } \ + +#define KUBE_CONTROLLER_ACTION(NAME) \ + Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \ + private: QScopedPointer action_##NAME; \ + public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \ + private slots: void NAME(); \ + + namespace Kube { class ControllerAction : public QObject { diff --git a/framework/domain/foldercontroller.cpp b/framework/domain/foldercontroller.cpp new file mode 100644 index 00000000..45fb86a6 --- /dev/null +++ b/framework/domain/foldercontroller.cpp @@ -0,0 +1,50 @@ +/* + Copyright (c) 2016 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include "foldercontroller.h" + +#include +#include + +SINK_DEBUG_AREA("foldercontroller"); + +FolderController::FolderController() + : Kube::Controller(), + action_synchronize{new Kube::ControllerAction} +{ + QObject::connect(synchronizeAction(), &Kube::ControllerAction::triggered, this, &FolderController::synchronize); +} + +void FolderController::synchronize() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + auto job = [&] { + if (auto folder = getFolder()) { + SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); + auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter(QVariant::fromValue(folder->identifier())); + scope.setType(); + return Store::synchronize(scope); + } else { + SinkLog() << "Synchronizing all"; + return Store::synchronize(SyncScope()); + } + }(); + run(job); +} + diff --git a/framework/domain/foldercontroller.h b/framework/domain/foldercontroller.h new file mode 100644 index 00000000..24d6929c --- /dev/null +++ b/framework/domain/foldercontroller.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2016 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library 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 Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#pragma once + +#include +#include "controller.h" +#include "sink/applicationdomaintype.h" + +class FolderController : public Kube::Controller +{ + Q_OBJECT + KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) + KUBE_CONTROLLER_ACTION(synchronize) + +public: + explicit FolderController(); +}; diff --git a/framework/domain/mailcontroller.h b/framework/domain/mailcontroller.h index 66cb7b4b..6c41f433 100644 --- a/framework/domain/mailcontroller.h +++ b/framework/domain/mailcontroller.h @@ -22,13 +22,6 @@ #include "controller.h" #include "sink/applicationdomaintype.h" -#define KUBE_CONTROLLER_ACTION(NAME) \ - Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \ - private: QScopedPointer action_##NAME; \ - public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \ - private slots: void NAME(); \ - - class MailController : public Kube::Controller { Q_OBJECT diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index eeb1aeb1..e63f3ad1 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp @@ -31,6 +31,7 @@ #include "outboxmodel.h" #include "outboxcontroller.h" #include "mailcontroller.h" +#include "foldercontroller.h" #include @@ -49,4 +50,5 @@ void MailPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "OutboxController"); qmlRegisterType(uri, 1, 0, "OutboxModel"); qmlRegisterType(uri, 1, 0, "MailController"); + qmlRegisterType(uri, 1, 0, "FolderController"); } -- cgit v1.2.3