notificationcollector.h 9.89 KB
Newer Older
1
/*
2
    Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef AKONADI_NOTIFICATIONCOLLECTOR_H
#define AKONADI_NOTIFICATIONCOLLECTOR_H

Loic Marteau's avatar
Loic Marteau committed
23
#include "entities.h"
24

25
#include <private/protocol_p.h>
26

Daniel Vrátil's avatar
Daniel Vrátil committed
27
28
29
#include <QByteArray>
#include <QList>
#include <QString>
30

Laurent Montel's avatar
Laurent Montel committed
31
32
33
34
namespace Akonadi
{
namespace Server
{
35
36

class DataStore;
37
class Connection;
38
class AkonadiServer;
39
40
41
42
43
44

/**
  Part of the DataStore, collects change notifications and emits
  them after the current transaction has been successfully committed.
  Where possible, notifications are compressed.
*/
45
class NotificationCollector
46
{
47
public:
48
49
    /**
      Create a new notification collector for the given DataStore @p db.
50
      @param db The datastore using this notification collector.
51
    */
52
    explicit NotificationCollector(AkonadiServer &akonadi, DataStore *db);
53
54
55
56

    /**
      Destroys this notification collector.
    */
57
    virtual ~NotificationCollector() = default;
58

59
    /**
60
61
62
     * Sets the connection that is causing the changes.
     */
    void setConnection(Connection *connection);
63

64
65
66
67
68
    /**
      Notify about an added item.
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
    */
69
70
    void itemAdded(const PimItem &item, bool seen,
                   const Collection &collection = Collection(),
71
                   const QByteArray &resource = QByteArray());
72
73
74
75
76
77

    /**
      Notify about a changed item.
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
    */
78
79
80
81
    void itemChanged(const PimItem &item,
                     const QSet<QByteArray> &changedParts,
                     const Collection &collection = Collection(),
                     const QByteArray &resource = QByteArray());
82

83
    /**
84
      Notify about changed items flags
85
86
87
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
    */
88
89
90
91
92
    void itemsFlagsChanged(const PimItem::List &items,
                           const QSet<QByteArray> &addedFlags,
                           const QSet<QByteArray> &removedFlags,
                           const Collection &collection = Collection(),
                           const QByteArray &resource = QByteArray());
93

94
95
96
    /**
     Notify about changed items tags
    **/
97
98
99
100
101
    void itemsTagsChanged(const PimItem::List &items,
                          const QSet<qint64> &addedTags,
                          const QSet<qint64> &removedTags,
                          const Collection &collection = Collection(),
                          const QByteArray &resource = QByteArray());
102

Christian Mollekopf's avatar
Christian Mollekopf committed
103
104
105
106
107
108
109
110
111
    /**
     Notify about changed items relations
    **/
    void itemsRelationsChanged(const PimItem::List &items,
                               const Relation::List &addedRelations,
                               const Relation::List &removedRelations,
                               const Collection &collection = Collection(),
                               const QByteArray &resource = QByteArray());

112
113
114
115
116
    /**
      Notify about moved items
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
    */
117
118
119
    void itemsMoved(const PimItem::List &items, const Collection &collectionSrc = Collection(),
                    const Collection &collectionDest = Collection(),
                    const QByteArray &sourceResource = QByteArray());
120

121
    /**
122
      Notify about removed items.
123
124
      Make sure you either provide all parameters or call this function before
      actually removing the item from database.
125
    */
126
127
    void itemsRemoved(const PimItem::List &items, const Collection &collection = Collection(),
                      const QByteArray &resource = QByteArray());
128

129
    /**
130
     * Notify about linked items
131
     */
132
    void itemsLinked(const PimItem::List &items, const Collection &collection);
133
134

    /**
135
     * Notify about unlinked items.
136
     */
137
    void itemsUnlinked(const PimItem::List &items, const Collection &collection);
138

139
140
141
142
    /**
      Notify about a added collection.
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
143
     */
144
145
    void collectionAdded(const Collection &collection,
                         const QByteArray &resource = QByteArray());
146
147
148
149
150
151

    /**
      Notify about a changed collection.
      Provide as many parameters as you have at hand currently, everything
      that is missing will be looked up in the database later.
    */
152
153
154
    void collectionChanged(const Collection &collection,
                           const QList<QByteArray> &changes,
                           const QByteArray &resource = QByteArray());
155

156
157
158
    /**
      Notify about a moved collection.
      Provide as many parameters as you have at hand currently, everything
159
      missing will be looked up on demand in the database later.
160
    */
161
162
163
164
    void collectionMoved(const Collection &collection,
                         const Collection &source,
                         const QByteArray &resource = QByteArray(),
                         const QByteArray &destResource = QByteArray());
165

166
167
    /**
      Notify about a removed collection.
168
169
170
      Make sure you either provide all parameters or call this function before
      actually removing the item from database.
     */
171
172
    void collectionRemoved(const Collection &collection,
                           const QByteArray &resource = QByteArray());
173

174
175
176
    /**
     *      Notify about a collection subscription.
     */
177
178
    void collectionSubscribed(const Collection &collection,
                              const QByteArray &resource = QByteArray());
179
180
181
    /**
     *      Notify about a collection unsubscription
     */
182
183
    void collectionUnsubscribed(const Collection &collection,
                                const QByteArray &resource = QByteArray());
184

185
186
187
    /**
      Notify about an added tag.
     */
188
    void tagAdded(const Tag &tag);
189
190
191
192

    /**
     Notify about a changed tag.
     */
193
    void tagChanged(const Tag &tag);
194
195
196
197

    /**
      Notify about a removed tag.
     */
198
    void tagRemoved(const Tag &tag, const QByteArray &resource, const QString &remoteId);
199

Christian Mollekopf's avatar
Christian Mollekopf committed
200
201
202
203
204
205
206
207
208
    /**
      Notify about an added relation.
     */
    void relationAdded(const Relation &relation);

    /**
      Notify about a removed relation.
     */
    void relationRemoved(const Relation &relation);
209

210
211
    /**
      Trigger sending of collected notifications.
212
213
214

      @returns Returns true when any notifications were dispatched, false if there
               were no pending notifications.
215
    */
216
    bool dispatchNotifications();
217

218
private:
219
220
    void itemNotification(Protocol::ItemChangeNotification::Operation op,
                          const PimItem::List &items,
221
222
223
224
225
226
227
                          const Collection &collection,
                          const Collection &collectionDest,
                          const QByteArray &resource,
                          const QSet<QByteArray> &parts = QSet<QByteArray>(),
                          const QSet<QByteArray> &addedFlags = QSet<QByteArray>(),
                          const QSet<QByteArray> &removedFlags = QSet<QByteArray>(),
                          const QSet<qint64> &addedTags = QSet<qint64>(),
Christian Mollekopf's avatar
Christian Mollekopf committed
228
229
                          const QSet<qint64> &removedTags = QSet<qint64>(),
                          const Relation::List &addedRelations = Relation::List(),
Laurent Montel's avatar
Laurent Montel committed
230
                          const Relation::List &removedRelations = Relation::List());
231
232
    void itemNotification(Protocol::ItemChangeNotification::Operation op,
                          const PimItem &item,
233
234
235
236
                          const Collection &collection,
                          const Collection &collectionDest,
                          const QByteArray &resource,
                          const QSet<QByteArray> &parts = QSet<QByteArray>());
237
    void collectionNotification(Protocol::CollectionChangeNotification::Operation op,
238
239
240
241
242
                                const Collection &collection,
                                Collection::Id source, Collection::Id destination,
                                const QByteArray &resource,
                                const QSet<QByteArray> &changes = QSet<QByteArray>(),
                                const QByteArray &destResource = QByteArray());
243
    void tagNotification(Protocol::TagChangeNotification::Operation op,
Laurent Montel's avatar
Laurent Montel committed
244
245
246
                         const Tag &tag,
                         const QByteArray &resource = QByteArray(),
                         const QString &remoteId = QString());
247
248
    void relationNotification(Protocol::RelationChangeNotification::Operation op,
                              const Relation &relation);
249
    void dispatchNotification(const Protocol::ChangeNotificationPtr &msg);
250
    void clear();
251

252
    void completeNotification(const Protocol::ChangeNotificationPtr &msg);
253
254
255
256

protected:
    virtual void notify(Protocol::ChangeNotificationList ntfs);

257
private:
258
    DataStore *mDb;
259
    Connection *mConnection = nullptr;
260
    AkonadiServer &mAkonadi;
261
    bool mIgnoreTransactions = false;
262

263
    Protocol::ChangeNotificationList mNotifications;
264
265
};

266
267
} // namespace Server
} // namespace Akonadi
268
269

#endif