diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/query.h | 46 | ||||
-rw-r--r-- | common/standardqueries.h | 69 |
3 files changed, 71 insertions, 45 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0fc8d81..84fe474 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -123,6 +123,7 @@ install(FILES | |||
123 | resourcecontrol.h | 123 | resourcecontrol.h |
124 | domain/applicationdomaintype.h | 124 | domain/applicationdomaintype.h |
125 | query.h | 125 | query.h |
126 | standardqueries.h | ||
126 | inspection.h | 127 | inspection.h |
127 | notification.h | 128 | notification.h |
128 | bufferadaptor.h | 129 | bufferadaptor.h |
diff --git a/common/query.h b/common/query.h index 85307aa..00ae086 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -59,7 +59,6 @@ public: | |||
59 | Comparators comparator; | 59 | Comparators comparator; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | |||
63 | template <typename T> | 62 | template <typename T> |
64 | Query &request() | 63 | Query &request() |
65 | { | 64 | { |
@@ -289,7 +288,7 @@ public: | |||
289 | * a result set is generated containing all entries with the same value. | 288 | * a result set is generated containing all entries with the same value. |
290 | * | 289 | * |
291 | * Example: | 290 | * Example: |
292 | * For an input result set of one mail; return all emails with the same threadId. | 291 | * For an input set of one mail; return all emails with the same threadId. |
293 | */ | 292 | */ |
294 | class Bloom : public FilterStage { | 293 | class Bloom : public FilterStage { |
295 | public: | 294 | public: |
@@ -308,49 +307,6 @@ public: | |||
308 | mFilterStages << bloom; | 307 | mFilterStages << bloom; |
309 | } | 308 | } |
310 | 309 | ||
311 | //Query fixtures | ||
312 | |||
313 | /** | ||
314 | * Returns the complete thread, containing all mails from all folders. | ||
315 | */ | ||
316 | static Query completeThread(const ApplicationDomain::Mail &mail) | ||
317 | { | ||
318 | Sink::Query query; | ||
319 | if (!mail.resourceInstanceIdentifier().isEmpty()) { | ||
320 | query.resourceFilter(mail.resourceInstanceIdentifier()); | ||
321 | } | ||
322 | query.filter(mail.identifier()); | ||
323 | query.sort<ApplicationDomain::Mail::Date>(); | ||
324 | query.bloom<ApplicationDomain::Mail::ThreadId>(); | ||
325 | return query; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Returns thread leaders only, sorted by date. | ||
330 | */ | ||
331 | static Query threadLeaders(const ApplicationDomain::Folder &folder) | ||
332 | { | ||
333 | Sink::Query query; | ||
334 | if (!folder.resourceInstanceIdentifier().isEmpty()) { | ||
335 | query.resourceFilter(folder.resourceInstanceIdentifier()); | ||
336 | } | ||
337 | query.filter<ApplicationDomain::Mail::Folder>(folder); | ||
338 | query.sort<ApplicationDomain::Mail::Date>(); | ||
339 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | ||
340 | return query; | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * Outgoing mails. | ||
345 | */ | ||
346 | static Query outboxMails() | ||
347 | { | ||
348 | Sink::Query query; | ||
349 | query.resourceContainsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | ||
350 | query.sort<ApplicationDomain::Mail::Date>(); | ||
351 | return query; | ||
352 | } | ||
353 | |||
354 | private: | 310 | private: |
355 | Filter mResourceFilter; | 311 | Filter mResourceFilter; |
356 | Filter mBaseFilterStage; | 312 | Filter mBaseFilterStage; |
diff --git a/common/standardqueries.h b/common/standardqueries.h new file mode 100644 index 0000000..06ce396 --- /dev/null +++ b/common/standardqueries.h | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #pragma once | ||
21 | |||
22 | #include "query.h" | ||
23 | |||
24 | namespace Sink { | ||
25 | namespace StandardQueries { | ||
26 | |||
27 | /** | ||
28 | * Returns the complete thread, containing all mails from all folders. | ||
29 | */ | ||
30 | static Query completeThread(const ApplicationDomain::Mail &mail) | ||
31 | { | ||
32 | Sink::Query query; | ||
33 | if (!mail.resourceInstanceIdentifier().isEmpty()) { | ||
34 | query.resourceFilter(mail.resourceInstanceIdentifier()); | ||
35 | } | ||
36 | query.filter(mail.identifier()); | ||
37 | query.sort<ApplicationDomain::Mail::Date>(); | ||
38 | query.bloom<ApplicationDomain::Mail::ThreadId>(); | ||
39 | return query; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Returns thread leaders only, sorted by date. | ||
44 | */ | ||
45 | static Query threadLeaders(const ApplicationDomain::Folder &folder) | ||
46 | { | ||
47 | Sink::Query query; | ||
48 | if (!folder.resourceInstanceIdentifier().isEmpty()) { | ||
49 | query.resourceFilter(folder.resourceInstanceIdentifier()); | ||
50 | } | ||
51 | query.filter<ApplicationDomain::Mail::Folder>(folder); | ||
52 | query.sort<ApplicationDomain::Mail::Date>(); | ||
53 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | ||
54 | return query; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Outgoing mails. | ||
59 | */ | ||
60 | static Query outboxMails() | ||
61 | { | ||
62 | Sink::Query query; | ||
63 | query.resourceContainsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | ||
64 | query.sort<ApplicationDomain::Mail::Date>(); | ||
65 | return query; | ||
66 | } | ||
67 | |||
68 | } | ||
69 | } | ||