diff options
Diffstat (limited to 'common/facade.h')
-rw-r--r-- | common/facade.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/common/facade.h b/common/facade.h index 98bcb38..f9b5a83 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -30,6 +30,55 @@ | |||
30 | #include "domainadaptor.h" | 30 | #include "domainadaptor.h" |
31 | #include "entitybuffer.h" | 31 | #include "entitybuffer.h" |
32 | 32 | ||
33 | /** | ||
34 | * A QueryRunner runs a query and updates the corresponding result set. | ||
35 | * | ||
36 | * The lifetime of the QueryRunner is defined by the resut set (otherwise it's doing useless work), | ||
37 | * and by how long a result set must be updated. If the query is one off the runner dies after the execution, | ||
38 | * otherwise it lives on the react to changes and updates the corresponding result set. | ||
39 | * | ||
40 | * QueryRunner has to keep ResourceAccess alive in order to keep getting updates. | ||
41 | */ | ||
42 | class QueryRunner : public QObject | ||
43 | { | ||
44 | Q_OBJECT | ||
45 | public: | ||
46 | typedef std::function<Async::Job<qint64>(qint64 oldRevision, qint64 newRevision)> QueryFunction; | ||
47 | |||
48 | QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {}; | ||
49 | /** | ||
50 | * Starts query | ||
51 | */ | ||
52 | Async::Job<void> run(qint64 newRevision = 0) | ||
53 | { | ||
54 | //TODO: JOBAPI: that last empty .then should not be necessary | ||
55 | return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) { | ||
56 | mLatestRevision = revision; | ||
57 | }).then<void>([](){}); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * | ||
62 | */ | ||
63 | void setQuery(const QueryFunction &query) | ||
64 | { | ||
65 | queryFunction = query; | ||
66 | } | ||
67 | |||
68 | public slots: | ||
69 | /** | ||
70 | * Rerun query with new revision | ||
71 | */ | ||
72 | void revisionChanged(qint64 newRevision) | ||
73 | { | ||
74 | run(newRevision).exec(); | ||
75 | } | ||
76 | |||
77 | private: | ||
78 | QueryFunction queryFunction; | ||
79 | qint64 mLatestRevision; | ||
80 | }; | ||
81 | |||
33 | namespace Akonadi2 { | 82 | namespace Akonadi2 { |
34 | class ResourceAccess; | 83 | class ResourceAccess; |
35 | /** | 84 | /** |
@@ -80,7 +129,7 @@ protected: | |||
80 | return Async::null<void>(); | 129 | return Async::null<void>(); |
81 | } | 130 | } |
82 | 131 | ||
83 | private: | 132 | protected: |
84 | //TODO use one resource access instance per application => make static | 133 | //TODO use one resource access instance per application => make static |
85 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; | 134 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; |
86 | }; | 135 | }; |