Akonadi

itemretriever.h
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QDateTime>
10 #include <QObject>
11 
12 #include "../exception.h"
13 #include "entities.h"
14 
15 #include <private/imapset_p.h>
16 #include <private/scope_p.h>
17 
18 #include <optional>
19 
20 AKONADI_EXCEPTION_MAKE_INSTANCE(ItemRetrieverException);
21 
22 namespace Akonadi
23 {
24 namespace Server
25 {
26 class Connection;
27 class CommandContext;
28 class ItemRetrievalManager;
29 class ItemRetrievalRequest;
30 
31 /**
32  Helper class for retrieving missing items parts from remote resources.
33 
34  Stuff in here happens in the calling thread and does not access shared data.
35 
36  @todo make usable for Fetch by allowing to share queries
37 */
38 class ItemRetriever : public QObject
39 {
40  Q_OBJECT
41 
42 public:
43  explicit ItemRetriever(ItemRetrievalManager &manager, Connection *connection, const CommandContext &context);
44 
45  Connection *connection() const;
46 
47  void setRetrieveParts(const QList<QByteArray> &parts);
48  QList<QByteArray> retrieveParts() const;
49  void setRetrieveFullPayload(bool fullPayload);
50  void setChangedSince(const QDateTime &changedSince);
51  void setItemSet(const ImapSet &set, const Collection &collection = Collection());
52  void setItemSet(const ImapSet &set, bool isUid);
53  void setItem(Entity::Id id);
54  /** Retrieve all items in the given collection. */
55  void setCollection(const Collection &collection, bool recursive = true);
56 
57  /** Retrieve all items matching the given item scope. */
58  void setScope(const Scope &scope);
59  Scope scope() const;
60 
61  bool exec();
62 
63  QByteArray lastError() const;
64 
65 Q_SIGNALS:
66  void itemsRetrieved(const QList<qint64> &ids);
67 
68 private:
69  QSqlQuery buildQuery() const;
70 
71  /**
72  * Checks if external files are still present
73  * This costs extra, but allows us to automatically recover from something changing the external file storage.
74  */
75  void verifyCache();
76 
77  /// Execute the retrieval
78  bool runItemRetrievalRequests(std::list<ItemRetrievalRequest> requests);
79  struct PreparedRequests {
80  std::list<ItemRetrievalRequest> requests;
81  QList<qint64> readyItems;
82  };
83  std::optional<PreparedRequests> prepareRequests(QSqlQuery &query, const QByteArrayList &parts);
84 
85  Akonadi::ImapSet mItemSet;
86  Collection mCollection;
87  Scope mScope;
88  ItemRetrievalManager &mItemRetrievalManager;
89  Connection *mConnection = nullptr;
90  const CommandContext &mContext;
91  QList<QByteArray> mParts;
92  bool mFullPayload;
93  bool mRecursive;
94  QDateTime mChangedSince;
95  mutable QByteArray mLastError;
96  bool mCanceled;
97 };
98 
99 } // namespace Server
100 } // namespace Akonadi
Q_OBJECTQ_OBJECT
Represents a collection of PIM items.
Definition: collection.h:61
void setCollection(const Collection &collection, bool recursive=true)
Retrieve all items in the given collection.
Manages and processes item retrieval requests.
Q_SIGNALSQ_SIGNALS
void setScope(const Scope &scope)
Retrieve all items matching the given item scope.
Helper class for retrieving missing items parts from remote resources.
Definition: itemretriever.h:38
An Connection represents one connection of a client to the server.
Definition: connection.h:46
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Nov 28 2023 03:52:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.