diff options
Diffstat (limited to 'framework/src/domain/foldercontroller.cpp')
-rw-r--r-- | framework/src/domain/foldercontroller.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/framework/src/domain/foldercontroller.cpp b/framework/src/domain/foldercontroller.cpp new file mode 100644 index 00000000..3c10f773 --- /dev/null +++ b/framework/src/domain/foldercontroller.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "foldercontroller.h" | ||
20 | |||
21 | #include <sink/store.h> | ||
22 | #include <sink/log.h> | ||
23 | |||
24 | SINK_DEBUG_AREA("foldercontroller"); | ||
25 | |||
26 | using namespace Sink; | ||
27 | using namespace Sink::ApplicationDomain; | ||
28 | |||
29 | FolderController::FolderController() | ||
30 | : Kube::Controller(), | ||
31 | action_synchronize{new Kube::ControllerAction{this, &FolderController::synchronize}}, | ||
32 | action_moveToFolder{new Kube::ControllerAction{this, &FolderController::moveToFolder}} | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void FolderController::synchronize() | ||
37 | { | ||
38 | auto job = [&] { | ||
39 | auto accountId = getAccountId(); | ||
40 | if (auto folder = getFolder()) { | ||
41 | SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); | ||
42 | auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<ApplicationDomain::Mail::Folder>(QVariant::fromValue(folder->identifier())); | ||
43 | scope.setType<ApplicationDomain::Mail>(); | ||
44 | return Store::synchronize(scope); | ||
45 | } else if (!accountId.isEmpty()) { | ||
46 | return Store::synchronize(SyncScope{}.resourceFilter<ApplicationDomain::SinkResource::Account>(accountId)); | ||
47 | } else { | ||
48 | SinkLog() << "Synchronizing all"; | ||
49 | return Store::synchronize(SyncScope()); | ||
50 | } | ||
51 | }(); | ||
52 | run(job); | ||
53 | } | ||
54 | |||
55 | void FolderController::moveToFolder() | ||
56 | { | ||
57 | auto mail = getMail(); | ||
58 | auto targetFolder = getFolder(); | ||
59 | mail->setFolder(*targetFolder); | ||
60 | SinkLog() << "Moving to folder " << mail->identifier() << targetFolder->identifier(); | ||
61 | run(Store::modify(*mail)); | ||
62 | } | ||