diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-07 17:56:30 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-07 17:56:30 +0100 |
commit | 35a3afc591c85999de856c21dbb493e341951d91 (patch) | |
tree | f46b6a8c22e5bdb283148e48e0391c2691bcc343 /sinksh/syntax_modules/sink_sync.cpp | |
parent | 470203f1c09fa1811ae2859520c168901d5fa6cd (diff) | |
download | sink-35a3afc591c85999de856c21dbb493e341951d91.tar.gz sink-35a3afc591c85999de856c21dbb493e341951d91.zip |
Share query syntax
Diffstat (limited to 'sinksh/syntax_modules/sink_sync.cpp')
-rw-r--r-- | sinksh/syntax_modules/sink_sync.cpp | 56 |
1 files changed, 8 insertions, 48 deletions
diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index f83f0d8..f90f055 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp | |||
@@ -38,56 +38,16 @@ | |||
38 | namespace SinkSync | 38 | namespace SinkSync |
39 | { | 39 | { |
40 | 40 | ||
41 | bool isId(const QByteArray &value) | 41 | bool sync(const QStringList &args, State &state) |
42 | { | 42 | { |
43 | return value.startsWith("{"); | ||
44 | } | ||
45 | |||
46 | bool sync(const QStringList &args_, State &state) | ||
47 | { | ||
48 | auto args = args_; | ||
49 | Sink::Query query; | 43 | Sink::Query query; |
50 | if (args.isEmpty()) { | 44 | |
51 | state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder")); | 45 | if (!args.isEmpty() && !SinkshUtils::isValidStoreType(args.first())) { |
52 | return false; | 46 | query.resourceFilter(args.first().toLatin1()); |
53 | } | 47 | } else { |
54 | auto type = args.takeFirst().toLatin1(); | 48 | if (!SinkshUtils::applyFilter(query, args)) { |
55 | if (type != "*") { | 49 | state.printError(QObject::tr("Options: $type $resource/$folder/$subfolder")); |
56 | query.setType(type); | 50 | return false; |
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 | } | 51 | } |
92 | } | 52 | } |
93 | 53 | ||