diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-05 18:16:52 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-05 18:16:52 +0100 |
commit | 234346f18caf775625bbe88ef2eb7c3b17f3321b (patch) | |
tree | 16726f5a2fe902e91a6c3ea178fdf002b491583f /sinksh/syntax_modules/sink_sync.cpp | |
parent | 889bda7e1d885498813ec03c16d84cb052c604b4 (diff) | |
download | sink-234346f18caf775625bbe88ef2eb7c3b17f3321b.tar.gz sink-234346f18caf775625bbe88ef2eb7c3b17f3321b.zip |
Sinksh
Diffstat (limited to 'sinksh/syntax_modules/sink_sync.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_sync.cpp | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index d4a0e1c..f83f0d8 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp | |||
@@ -38,16 +38,62 @@ | |||
38 | namespace SinkSync | 38 | namespace SinkSync |
39 | { | 39 | { |
40 | 40 | ||
41 | bool sync(const QStringList &args, State &state) | 41 | bool isId(const QByteArray &value) |
42 | { | 42 | { |
43 | return value.startsWith("{"); | ||
44 | } | ||
45 | |||
46 | bool sync(const QStringList &args_, State &state) | ||
47 | { | ||
48 | auto args = args_; | ||
43 | Sink::Query query; | 49 | Sink::Query query; |
44 | for (const auto &res : args) { | 50 | if (args.isEmpty()) { |
45 | query.resourceFilter(res.toLatin1()); | 51 | state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder")); |
52 | return false; | ||
53 | } | ||
54 | auto type = args.takeFirst().toLatin1(); | ||
55 | if (type != "*") { | ||
56 | query.setType(type); | ||
57 | } | ||
58 | if (!args.isEmpty()) { | ||
59 | auto resource = args.takeFirst().toLatin1(); | ||
60 | |||
61 | if (resource.contains('/')) { | ||
62 | //The resource isn't an id but a path | ||
63 | auto list = resource.split('/'); | ||
64 | const auto resourceId = list.takeFirst(); | ||
65 | query.resourceFilter(resourceId); | ||
66 | if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Mail>() && !list.isEmpty()) { | ||
67 | auto value = list.takeFirst(); | ||
68 | if (isId(value)) { | ||
69 | query.filter<Sink::ApplicationDomain::Mail::Folder>(value); | ||
70 | } else { | ||
71 | Sink::Query folderQuery; | ||
72 | folderQuery.resourceFilter(resourceId); | ||
73 | folderQuery.filter<Sink::ApplicationDomain::Folder::Name>(value); | ||
74 | folderQuery.filter<Sink::ApplicationDomain::Folder::Parent>(QVariant()); | ||
75 | qWarning() << "Looking for folder: " << value << " in " << resourceId; | ||
76 | auto folders = Sink::Store::read<Sink::ApplicationDomain::Folder>(folderQuery); | ||
77 | if (folders.size() == 1) { | ||
78 | query.filter<Sink::ApplicationDomain::Mail::Folder>(folders.first()); | ||
79 | qWarning() << "Synchronizing folder: " << folders.first().identifier(); | ||
80 | } else { | ||
81 | qWarning() << "Folder name did not match uniquely: " << folders.size(); | ||
82 | for (const auto &f : folders) { | ||
83 | qWarning() << f.getName(); | ||
84 | } | ||
85 | state.printError(QObject::tr("Folder name did not match uniquely.")); | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | } else { | ||
90 | query.resourceFilter(resource); | ||
91 | } | ||
46 | } | 92 | } |
47 | 93 | ||
48 | QTimer::singleShot(0, [query, state]() { | 94 | QTimer::singleShot(0, [query, state]() { |
49 | Sink::Store::synchronize(query) | 95 | Sink::Store::synchronize(query) |
50 | .then(Sink::ResourceControl::flushReplayQueue(query.getResourceFilter().ids)) | 96 | .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) |
51 | .syncThen<void>([state](const KAsync::Error &error) { | 97 | .syncThen<void>([state](const KAsync::Error &error) { |
52 | if (error) { | 98 | if (error) { |
53 | state.printLine("Synchronization failed!"); | 99 | state.printLine("Synchronization failed!"); |