summaryrefslogtreecommitdiffstats
path: root/sinksh
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh')
-rw-r--r--sinksh/syntax_modules/sink_list.cpp2
-rw-r--r--sinksh/syntax_modules/sink_sync.cpp54
2 files changed, 51 insertions, 5 deletions
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp
index dd1498f..a609463 100644
--- a/sinksh/syntax_modules/sink_list.cpp
+++ b/sinksh/syntax_modules/sink_list.cpp
@@ -120,7 +120,7 @@ bool list(const QStringList &args_, State &state)
120 } 120 }
121 121
122 QStringList line; 122 QStringList line;
123 line << o.resourceInstanceIdentifier(); 123 line << compressId(compact, o.resourceInstanceIdentifier());
124 line << compressId(compact, o.identifier()); 124 line << compressId(compact, o.identifier());
125 for (const auto &prop: toPrint) { 125 for (const auto &prop: toPrint) {
126 const auto value = o.getProperty(prop); 126 const auto value = o.getProperty(prop);
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 @@
38namespace SinkSync 38namespace SinkSync
39{ 39{
40 40
41bool sync(const QStringList &args, State &state) 41bool isId(const QByteArray &value)
42{ 42{
43 return value.startsWith("{");
44}
45
46bool 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!");