Akonadi

monitor.cpp
1/*
2 SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "monitor.h"
8#include "monitor_p.h"
9
10#include "changemediator_p.h"
11#include "collectionfetchscope.h"
12#include "session.h"
13
14#include "shared/akranges.h"
15
16#include <QMetaMethod>
17
18using namespace Akonadi;
19using namespace AkRanges;
20
22 : QObject(parent)
23 , d_ptr(new MonitorPrivate(nullptr, this))
24{
25 d_ptr->init();
26 d_ptr->connectToNotificationManager();
27
28 ChangeMediator::registerMonitor(this);
29}
30
31/// @cond PRIVATE
32Monitor::Monitor(MonitorPrivate *d, QObject *parent)
33 : QObject(parent)
34 , d_ptr(d)
35{
36 d_ptr->init();
37 d_ptr->connectToNotificationManager();
38
39 ChangeMediator::registerMonitor(this);
40}
41/// @endcond
42
44{
45 ChangeMediator::unregisterMonitor(this);
46}
47
48void Monitor::setCollectionMonitored(const Collection &collection, bool monitored)
49{
50 Q_D(Monitor);
51 if (!d->collections.contains(collection) && monitored) {
52 d->collections << collection;
53 d->pendingModification.startMonitoringCollection(collection.id());
54 d->scheduleSubscriptionUpdate();
55 } else if (!monitored) {
56 if (d->collections.removeAll(collection)) {
57 d->pendingModification.stopMonitoringCollection(collection.id());
58 d->scheduleSubscriptionUpdate();
59 }
60 }
61
62 Q_EMIT collectionMonitored(collection, monitored); // NOLINT(readability-misleading-indentation): false positive
63}
64
65void Monitor::setItemMonitored(const Item &item, bool monitored)
66{
67 Q_D(Monitor);
68 if (!d->items.contains(item.id()) && monitored) {
69 d->items.insert(item.id());
70 d->pendingModification.startMonitoringItem(item.id());
71 d->scheduleSubscriptionUpdate();
72 } else if (!monitored) {
73 if (d->items.remove(item.id())) {
74 d->pendingModification.stopMonitoringItem(item.id());
75 d->scheduleSubscriptionUpdate();
76 }
77 }
78
79 Q_EMIT itemMonitored(item, monitored); // NOLINT(readability-misleading-indentation): false positive
80}
81
82void Monitor::setResourceMonitored(const QByteArray &resource, bool monitored)
83{
84 Q_D(Monitor);
85 if (!d->resources.contains(resource) && monitored) {
86 d->resources.insert(resource);
87 d->pendingModification.startMonitoringResource(resource);
88 d->scheduleSubscriptionUpdate();
89 } else if (!monitored) {
90 if (d->resources.remove(resource)) {
91 d->pendingModification.stopMonitoringResource(resource);
92 d->scheduleSubscriptionUpdate();
93 }
94 }
95
96 Q_EMIT resourceMonitored(resource, monitored); // NOLINT(readability-misleading-indentation): false positive
97}
98
99void Monitor::setMimeTypeMonitored(const QString &mimetype, bool monitored)
100{
101 Q_D(Monitor);
102 if (!d->mimetypes.contains(mimetype) && monitored) {
103 d->mimetypes.insert(mimetype);
104 d->pendingModification.startMonitoringMimeType(mimetype);
105 d->scheduleSubscriptionUpdate();
106 } else if (!monitored) {
107 if (d->mimetypes.remove(mimetype)) {
108 d->pendingModification.stopMonitoringMimeType(mimetype);
109 d->scheduleSubscriptionUpdate();
110 }
111 }
112
113 Q_EMIT mimeTypeMonitored(mimetype, monitored); // NOLINT(readability-misleading-indentation): false positive
114}
115
116void Monitor::setTagMonitored(const Akonadi::Tag &tag, bool monitored)
117{
118 Q_D(Monitor);
119 if (!d->tags.contains(tag.id()) && monitored) {
120 d->tags.insert(tag.id());
121 d->pendingModification.startMonitoringTag(tag.id());
122 d->scheduleSubscriptionUpdate();
123 } else if (!monitored) {
124 if (d->tags.remove(tag.id())) {
125 d->pendingModification.stopMonitoringTag(tag.id());
126 d->scheduleSubscriptionUpdate();
127 }
128 }
129
130 Q_EMIT tagMonitored(tag, monitored); // NOLINT(readability-misleading-indentation): false positive
131}
132
133void Monitor::setTypeMonitored(Monitor::Type type, bool monitored)
134{
135 Q_D(Monitor);
136 if (!d->types.contains(type) && monitored) {
137 d->types.insert(type);
138 d->pendingModification.startMonitoringType(MonitorPrivate::monitorTypeToProtocol(type));
139 d->scheduleSubscriptionUpdate();
140 } else if (!monitored) {
141 if (d->types.remove(type)) {
142 d->pendingModification.stopMonitoringType(MonitorPrivate::monitorTypeToProtocol(type));
143 d->scheduleSubscriptionUpdate();
144 }
145 }
146
147 Q_EMIT typeMonitored(type, monitored); // NOLINT(readability-misleading-indentation): false positive
148}
149
151{
152 Q_D(Monitor);
153 if (d->monitorAll == monitored) {
154 return;
155 }
156
157 d->monitorAll = monitored;
158
159 d->pendingModification.setAllMonitored(monitored);
160 d->scheduleSubscriptionUpdate();
161
162 Q_EMIT allMonitored(monitored);
163}
164
165void Monitor::setExclusive(bool exclusive)
166{
167 Q_D(Monitor);
168 d->exclusive = exclusive;
169 d->pendingModification.setIsExclusive(exclusive);
170 d->scheduleSubscriptionUpdate();
171}
172
173bool Monitor::exclusive() const
174{
175 Q_D(const Monitor);
176 return d->exclusive;
177}
178
180{
181 Q_D(Monitor);
182
183 if (!d->sessions.contains(session->sessionId())) {
184 d->sessions << session->sessionId();
186 d->slotSessionDestroyed(o);
187 });
188 d->pendingModification.startIgnoringSession(session->sessionId());
189 d->scheduleSubscriptionUpdate();
190 }
191}
192
194{
195 Q_D(Monitor);
196 d->fetchCollection = enable;
197}
198
200{
201 Q_D(Monitor);
202 d->fetchCollectionStatistics = enable;
203}
204
206{
207 Q_D(Monitor);
208 d->mItemFetchScope = fetchScope;
209 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::ItemFetchScope;
210 d->scheduleSubscriptionUpdate();
211}
212
214{
215 Q_D(Monitor);
216 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::ItemFetchScope;
217 d->scheduleSubscriptionUpdate();
218 return d->mItemFetchScope;
219}
220
222{
223 Q_D(Monitor);
224 d->mFetchChangedOnly = enable;
225}
226
228{
229 Q_D(Monitor);
230 d->mCollectionFetchScope = fetchScope;
231 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::CollectionFetchScope;
232 d->scheduleSubscriptionUpdate();
233}
234
236{
237 Q_D(Monitor);
238 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::CollectionFetchScope;
239 d->scheduleSubscriptionUpdate();
240 return d->mCollectionFetchScope;
241}
242
244{
245 Q_D(Monitor);
246 d->mTagFetchScope = fetchScope;
247 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::TagFetchScope;
248 d->scheduleSubscriptionUpdate();
249}
250
252{
253 Q_D(Monitor);
254 d->pendingModificationChanges |= Protocol::ModifySubscriptionCommand::TagFetchScope;
255 d->scheduleSubscriptionUpdate();
256 return d->mTagFetchScope;
257}
258
260{
261 Q_D(const Monitor);
262 return d->collections;
263}
264
266{
267 Q_D(const Monitor);
268 QList<Item::Id> result;
269 result.reserve(d->items.size());
270 std::copy(d->items.begin(), d->items.end(), std::back_inserter(result));
271 return result;
272}
273
275{
276 Q_D(const Monitor);
277 return d->items.size();
278}
279
281{
282 Q_D(const Monitor);
283 QList<Tag::Id> result;
284 result.reserve(d->tags.size());
285 std::copy(d->tags.begin(), d->tags.end(), std::back_inserter(result));
286 return result;
287}
288
290{
291 Q_D(const Monitor);
293 result.reserve(d->types.size());
294 std::copy(d->types.begin(), d->types.end(), std::back_inserter(result));
295 return result;
296}
297
299{
300 Q_D(const Monitor);
301 return d->mimetypes | Actions::toQList;
302}
303
305{
306 Q_D(const Monitor);
307 return d->mimetypes.count();
308}
309
311{
312 Q_D(const Monitor);
313 return d->resources | Actions::toQList;
314}
315
317{
318 Q_D(const Monitor);
319 return d->resources.count();
320}
321
323{
324 Q_D(const Monitor);
325 return d->monitorAll;
326}
327
329{
330 Q_D(Monitor);
331 if (session == d->session) {
332 return;
333 }
334
335 if (!session) {
336 d->session = Session::defaultSession();
337 } else {
338 d->session = session;
339 }
340
341 d->itemCache->setSession(d->session);
342 d->collectionCache->setSession(d->session);
343 d->tagCache->setSession(d->session);
344
345 // Reconnect with a new session
346 d->connectToNotificationManager();
347}
348
350{
351 Q_D(const Monitor);
352 return d->session;
353}
354
356{
357 Q_D(Monitor);
358 d->collectionMoveTranslationEnabled = enabled;
359}
360
361void Monitor::connectNotify(const QMetaMethod &signal)
362{
363 Q_D(Monitor);
364 d->updateListeners(signal, MonitorPrivate::AddListener);
365}
366
367void Monitor::disconnectNotify(const QMetaMethod &signal)
368{
369 Q_D(Monitor);
370 d->updateListeners(signal, MonitorPrivate::RemoveListener);
371}
372
373#include "moc_monitor.cpp"
Specifies which parts of a collection should be fetched from the Akonadi storage.
Represents a collection of PIM items.
Definition collection.h:62
Specifies which parts of an item should be fetched from the Akonadi storage.
Represents a PIM item stored in Akonadi storage.
Definition item.h:101
Id id() const
Returns the unique identifier of the item.
Definition item.cpp:63
Monitors an item or collection for changes.
Definition monitor.h:72
QList< Item::Id > itemsMonitoredEx() const
Returns the set of items being monitored.
Definition monitor.cpp:265
bool isAllMonitored() const
Returns true if everything is being monitored.
Definition monitor.cpp:322
QList< QByteArray > resourcesMonitored() const
Returns the set of identifiers for resources being monitored.
Definition monitor.cpp:310
void setTagMonitored(const Tag &tag, bool monitored=true)
Sets whether the specified tag shall be monitored for changes.
Definition monitor.cpp:116
~Monitor() override
Destroys the monitor.
Definition monitor.cpp:43
void collectionMonitored(const Akonadi::Collection &collection, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring collection explicitly.
Session * session() const
Returns the Session used by the monitor to communicate with Akonadi.
Definition monitor.cpp:349
void ignoreSession(Session *session)
Ignores all change notifications caused by the given session.
Definition monitor.cpp:179
void setCollectionFetchScope(const CollectionFetchScope &fetchScope)
Sets the collection fetch scope.
Definition monitor.cpp:227
TagFetchScope & tagFetchScope()
Returns the tag fetch scope.
Definition monitor.cpp:251
void itemMonitored(const Akonadi::Item &item, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring item explicitly.
void setMimeTypeMonitored(const QString &mimetype, bool monitored=true)
Sets whether items of the specified mime type shall be monitored for changes.
Definition monitor.cpp:99
void fetchChangedOnly(bool enable)
Instructs the monitor to fetch only those parts that were changed and were requested in the fetch sco...
Definition monitor.cpp:221
CollectionFetchScope & collectionFetchScope()
Returns the collection fetch scope.
Definition monitor.cpp:235
Collection::List collectionsMonitored() const
Returns the list of collections being monitored.
Definition monitor.cpp:259
int numItemsMonitored() const
Returns the number of items being monitored.
Definition monitor.cpp:274
void resourceMonitored(const QByteArray &identifier, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring the resource with the identifier ide...
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition monitor.cpp:213
void setItemMonitored(const Item &item, bool monitored=true)
Sets whether the specified item shall be monitored for changes.
Definition monitor.cpp:65
void setCollectionMoveTranslationEnabled(bool enabled)
Allows to enable/disable collection move translation.
Definition monitor.cpp:355
void setAllMonitored(bool monitored=true)
Sets whether all items shall be monitored.
Definition monitor.cpp:150
QList< Type > typesMonitored() const
Returns the set of types being monitored.
Definition monitor.cpp:289
void setCollectionMonitored(const Collection &collection, bool monitored=true)
Sets whether the specified collection shall be monitored for changes.
Definition monitor.cpp:48
Monitor(QObject *parent=nullptr)
Creates a new monitor.
Definition monitor.cpp:21
QList< Tag::Id > tagsMonitored() const
Returns the set of tags being monitored.
Definition monitor.cpp:280
void setResourceMonitored(const QByteArray &resource, bool monitored=true)
Sets whether the specified resource shall be monitored for changes.
Definition monitor.cpp:82
void fetchCollection(bool enable)
Enables automatic fetching of changed collections from the Akonadi storage.
Definition monitor.cpp:193
int numResourcesMonitored() const
Returns the number of resources being monitored.
Definition monitor.cpp:316
void mimeTypeMonitored(const QString &mimeType, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring mimeType explicitly.
int numMimeTypesMonitored() const
Returns the number of mimetypes being monitored.
Definition monitor.cpp:304
void setTagFetchScope(const TagFetchScope &fetchScope)
Sets the tag fetch scope.
Definition monitor.cpp:243
void typeMonitored(const Akonadi::Monitor::Type type, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring type explicitly.
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage.
Definition monitor.cpp:199
void setItemFetchScope(const ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition monitor.cpp:205
void tagMonitored(const Akonadi::Tag &tag, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring tag explicitly.
void setTypeMonitored(Type type, bool monitored=true)
Sets whether given type (Collection, Item, Tag should be monitored).
Definition monitor.cpp:133
void setSession(Akonadi::Session *session)
Sets the session used by the Monitor to communicate with the Akonadi server.
Definition monitor.cpp:328
QStringList mimeTypesMonitored() const
Returns the set of mimetypes being monitored.
Definition monitor.cpp:298
A communication session with the Akonadi storage.
static Session * defaultSession()
Returns the default session for this thread.
QByteArray sessionId() const
Returns the session identifier.
Specifies which parts of a tag should be fetched from the Akonadi storage.
An Akonadi Tag.
Definition tag.h:26
Id id() const
Returns the unique identifier of the tag.
Definition tag.cpp:139
Helper integration between Akonadi and Qt.
void reserve(qsizetype size)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual void connectNotify(const QMetaMethod &signal)
void destroyed(QObject *obj)
virtual void disconnectNotify(const QMetaMethod &signal)
T qobject_cast(QObject *object)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.