• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
monitor.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "monitor.h"
21 #include "monitor_p.h"
22 
23 #include "changemediator_p.h"
24 #include "collectionfetchscope.h"
25 #include "itemfetchjob.h"
26 #include "session.h"
27 
28 #include <kdebug.h>
29 
30 #include <QtDBus/QDBusInterface>
31 #include <QtDBus/QDBusConnection>
32 
33 #include <QtCore/QDebug>
34 #include <QtCore/QTimer>
35 #include <iterator>
36 
37 using namespace Akonadi;
38 
39 Monitor::Monitor(QObject *parent)
40  : QObject(parent)
41  , d_ptr(new MonitorPrivate(0, this))
42 {
43  d_ptr->init();
44  d_ptr->connectToNotificationManager();
45 }
46 
47 //@cond PRIVATE
48 Monitor::Monitor(MonitorPrivate *d, QObject *parent)
49  : QObject(parent)
50  , d_ptr(d)
51 {
52  d_ptr->init();
53  d_ptr->connectToNotificationManager();
54 
55  ChangeMediator::registerMonitor(this);
56 }
57 //@endcond
58 
59 Monitor::~Monitor()
60 {
61  ChangeMediator::unregisterMonitor(this);
62 
63  delete d_ptr;
64 }
65 
66 void Monitor::setCollectionMonitored(const Collection &collection, bool monitored)
67 {
68  Q_D(Monitor);
69  if (!d->collections.contains(collection) && monitored) {
70  d->collections << collection;
71  if (d->notificationSource) {
72  d->notificationSource->setMonitoredCollection(collection.id(), true);
73  }
74  } else if (!monitored) {
75  if (d->collections.removeAll(collection)) {
76  d->cleanOldNotifications();
77  if (d->notificationSource) {
78  d->notificationSource->setMonitoredCollection(collection.id(), false);
79  }
80  }
81  }
82 
83  emit collectionMonitored(collection, monitored);
84 }
85 
86 void Monitor::setItemMonitored(const Item &item, bool monitored)
87 {
88  Q_D(Monitor);
89  if (!d->items.contains(item.id()) && monitored) {
90  d->items.insert(item.id());
91  if (d->notificationSource) {
92  d->notificationSource->setMonitoredItem(item.id(), true);
93  }
94  } else if (!monitored) {
95  if (d->items.remove(item.id())) {
96  d->cleanOldNotifications();
97  if (d->notificationSource) {
98  d->notificationSource->setMonitoredItem(item.id(), false);
99  }
100  }
101  }
102 
103  emit itemMonitored(item, monitored);
104 }
105 
106 void Monitor::setResourceMonitored(const QByteArray &resource, bool monitored)
107 {
108  Q_D(Monitor);
109  if (!d->resources.contains(resource) && monitored) {
110  d->resources.insert(resource);
111  if (d->notificationSource) {
112  d->notificationSource->setMonitoredResource(resource, true);
113  }
114  } else if (!monitored) {
115  if (d->resources.remove(resource)) {
116  d->cleanOldNotifications();
117  if (d->notificationSource) {
118  d->notificationSource->setMonitoredResource(resource, false);
119  }
120  }
121  }
122 
123  emit resourceMonitored(resource, monitored);
124 }
125 
126 void Monitor::setMimeTypeMonitored(const QString &mimetype, bool monitored)
127 {
128  Q_D(Monitor);
129  if (!d->mimetypes.contains(mimetype) && monitored) {
130  d->mimetypes.insert(mimetype);
131  if (d->notificationSource) {
132  d->notificationSource->setMonitoredMimeType(mimetype, true);
133  }
134  } else if (!monitored) {
135  if (d->mimetypes.remove(mimetype)) {
136  d->cleanOldNotifications();
137  if (d->notificationSource) {
138  d->notificationSource->setMonitoredMimeType(mimetype, false);
139  }
140  }
141  }
142 
143  emit mimeTypeMonitored(mimetype, monitored);
144 }
145 
146 void Monitor::setTagMonitored(const Akonadi::Tag &tag, bool monitored)
147 {
148  Q_D(Monitor);
149  if (!d->tags.contains(tag.id()) && monitored) {
150  d->tags.insert(tag.id());
151  if (d->notificationSource) {
152  d->notificationSource->setMonitoredTag(tag.id(), true);
153  }
154  } else if (!monitored) {
155  if (d->tags.remove(tag.id())) {
156  d->cleanOldNotifications();
157  if (d->notificationSource) {
158  d->notificationSource->setMonitoredTag(tag.id(), false);
159  }
160  }
161  }
162 
163  emit tagMonitored(tag, monitored);
164 }
165 
166 void Monitor::setTypeMonitored(Monitor::Type type, bool monitored)
167 {
168  Q_D(Monitor);
169  if (!d->types.contains(type) && monitored) {
170  d->types.insert(type);
171  if (d->notificationSource) {
172  d->notificationSource->setMonitoredType(static_cast<NotificationMessageV2::Type>(type), true);
173  }
174  } else if (!monitored) {
175  if (d->types.remove(type)) {
176  d->cleanOldNotifications();
177  if (d->notificationSource) {
178  d->notificationSource->setMonitoredType(static_cast<NotificationMessageV2::Type>(type), false);
179  }
180  }
181  }
182 
183  emit typeMonitored(type, monitored);
184 }
185 
186 void Akonadi::Monitor::setAllMonitored(bool monitored)
187 {
188  Q_D(Monitor);
189  if (d->monitorAll == monitored) {
190  return;
191  }
192 
193  d->monitorAll = monitored;
194 
195  if (!monitored) {
196  d->cleanOldNotifications();
197  }
198 
199  if (d->notificationSource) {
200  d->notificationSource->setAllMonitored(monitored);
201  }
202 
203  emit allMonitored(monitored);
204 }
205 
206 void Monitor::ignoreSession(Session *session)
207 {
208  Q_D(Monitor);
209 
210  if (!d->sessions.contains(session->sessionId())) {
211  d->sessions << session->sessionId();
212  connect(session, SIGNAL(destroyed(QObject*)), this, SLOT(slotSessionDestroyed(QObject*)));
213  if (d->notificationSource) {
214  d->notificationSource->setIgnoredSession(session->sessionId(), true);
215  }
216  }
217 }
218 
219 void Monitor::fetchCollection(bool enable)
220 {
221  Q_D(Monitor);
222  d->fetchCollection = enable;
223 }
224 
225 void Monitor::fetchCollectionStatistics(bool enable)
226 {
227  Q_D(Monitor);
228  d->fetchCollectionStatistics = enable;
229 }
230 
231 void Monitor::setItemFetchScope(const ItemFetchScope &fetchScope)
232 {
233  Q_D(Monitor);
234  d->mItemFetchScope = fetchScope;
235 }
236 
237 ItemFetchScope &Monitor::itemFetchScope()
238 {
239  Q_D(Monitor);
240  return d->mItemFetchScope;
241 }
242 
243 void Monitor::fetchChangedOnly(bool enable)
244 {
245  Q_D(Monitor);
246  d->mFetchChangedOnly = enable;
247 }
248 
249 void Monitor::setCollectionFetchScope(const CollectionFetchScope &fetchScope)
250 {
251  Q_D(Monitor);
252  d->mCollectionFetchScope = fetchScope;
253 }
254 
255 CollectionFetchScope &Monitor::collectionFetchScope()
256 {
257  Q_D(Monitor);
258  return d->mCollectionFetchScope;
259 }
260 
261 void Monitor::setTagFetchScope(const TagFetchScope &fetchScope)
262 {
263  Q_D(Monitor);
264  d->mTagFetchScope = fetchScope;
265 }
266 
267 TagFetchScope &Monitor::tagFetchScope()
268 {
269  Q_D(Monitor);
270  return d->mTagFetchScope;
271 }
272 
273 Akonadi::Collection::List Monitor::collectionsMonitored() const
274 {
275  Q_D(const Monitor);
276  return d->collections;
277 }
278 
279 QList<Item::Id> Monitor::itemsMonitored() const
280 {
281  Q_D(const Monitor);
282  return d->items.toList();
283 }
284 
285 QVector<Item::Id> Monitor::itemsMonitoredEx() const
286 {
287  Q_D(const Monitor);
288  QVector<Item::Id> result;
289  result.reserve(d->items.size());
290  qCopy(d->items.begin(), d->items.end(), std::back_inserter(result));
291  return result;
292 }
293 
294 int Monitor::numItemsMonitored() const
295 {
296  Q_D(const Monitor);
297  return d->items.size();
298 }
299 
300 QVector<Tag::Id> Monitor::tagsMonitored() const
301 {
302  Q_D(const Monitor);
303  QVector<Tag::Id> result;
304  result.reserve(d->tags.size());
305  qCopy(d->tags.begin(), d->tags.end(), std::back_inserter(result));
306  return result;
307 }
308 
309 QVector<Monitor::Type> Monitor::typesMonitored() const
310 {
311  Q_D(const Monitor);
312  QVector<Monitor::Type> result;
313  result.reserve(d->types.size());
314  qCopy(d->types.begin(), d->types.end(), std::back_inserter(result));
315  return result;
316 }
317 
318 QStringList Monitor::mimeTypesMonitored() const
319 {
320  Q_D(const Monitor);
321  return d->mimetypes.toList();
322 }
323 
324 int Monitor::numMimeTypesMonitored() const
325 {
326  Q_D(const Monitor);
327  return d->mimetypes.count();
328 }
329 
330 QList<QByteArray> Monitor::resourcesMonitored() const
331 {
332  Q_D(const Monitor);
333  return d->resources.toList();
334 }
335 
336 int Monitor::numResourcesMonitored() const
337 {
338  Q_D(const Monitor);
339  return d->resources.count();
340 }
341 
342 bool Monitor::isAllMonitored() const
343 {
344  Q_D(const Monitor);
345  return d->monitorAll;
346 }
347 
348 void Monitor::setSession(Akonadi::Session *session)
349 {
350  Q_D(Monitor);
351  if (session == d->session) {
352  return;
353  }
354 
355  if (!session) {
356  d->session = Session::defaultSession();
357  } else {
358  d->session = session;
359  }
360 
361  d->itemCache->setSession(d->session);
362  d->collectionCache->setSession(d->session);
363 }
364 
365 Session *Monitor::session() const
366 {
367  Q_D(const Monitor);
368  return d->session;
369 }
370 
371 void Monitor::setCollectionMoveTranslationEnabled(bool enabled)
372 {
373  Q_D(Monitor);
374  d->collectionMoveTranslationEnabled = enabled;
375 }
376 
377 #include "moc_monitor.cpp"
Akonadi::Monitor::setAllMonitored
void setAllMonitored(bool monitored=true)
Sets whether all items shall be monitored.
Definition: monitor.cpp:186
Akonadi::Monitor::fetchCollectionStatistics
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage...
Definition: monitor.cpp:225
Akonadi::Monitor::mimeTypesMonitored
QStringList mimeTypesMonitored() const
Returns the set of mimetypes being monitored.
Definition: monitor.cpp:318
Akonadi::Monitor::setTagMonitored
void setTagMonitored(const Tag &tag, bool monitored=true)
Sets whether the specified tag shall be monitored for changes.
Definition: monitor.cpp:146
Akonadi::Monitor::tagFetchScope
TagFetchScope & tagFetchScope()
Returns the tag fetch scope.
Definition: monitor.cpp:267
Akonadi::Monitor::resourcesMonitored
QList< QByteArray > resourcesMonitored() const
Returns the set of identifiers for resources being monitored.
Definition: monitor.cpp:330
Akonadi::Monitor::session
Session * session() const
Returns the Session used by the monitor to communicate with Akonadi.
Definition: monitor.cpp:365
Akonadi::Monitor::collectionMonitored
void collectionMonitored(const Akonadi::Collection &collection, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring collection explicitly.
QByteArray
Akonadi::Monitor::setTagFetchScope
void setTagFetchScope(const TagFetchScope &fetchScope)
Sets the tag fetch scope.
Definition: monitor.cpp:261
Akonadi::CollectionFetchScope
Specifies which parts of a collection should be fetched from the Akonadi storage. ...
Definition: collectionfetchscope.h:68
Akonadi::Monitor::setSession
void setSession(Akonadi::Session *session)
Sets the session used by the Monitor to communicate with the Akonadi server.
Definition: monitor.cpp:348
Akonadi::Monitor::setMimeTypeMonitored
void setMimeTypeMonitored(const QString &mimetype, bool monitored=true)
Sets whether items of the specified mime type shall be monitored for changes.
Definition: monitor.cpp:126
Akonadi::Monitor::setCollectionMonitored
void setCollectionMonitored(const Collection &collection, bool monitored=true)
Sets whether the specified collection shall be monitored for changes.
Definition: monitor.cpp:66
Akonadi::TagFetchScope
Specifies which parts of a tag should be fetched from the Akonadi storage.
Definition: tagfetchscope.h:33
QSet::size
int size() const
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Monitor::mimeTypeMonitored
void mimeTypeMonitored(const QString &mimeType, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring mimeType explicitly.
Akonadi::Monitor::setItemFetchScope
void setItemFetchScope(const ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: monitor.cpp:231
Akonadi::Monitor::ignoreSession
void ignoreSession(Session *session)
Ignores all change notifications caused by the given session.
Definition: monitor.cpp:206
Akonadi::Monitor::~Monitor
virtual ~Monitor()
Destroys the monitor.
Definition: monitor.cpp:59
Akonadi::Tag::id
Id id() const
Returns the unique identifier of the tag.
Definition: tag.cpp:131
QSet::insert
const_iterator insert(const T &value)
Akonadi::Session::defaultSession
static Session * defaultSession()
Returns the default session for this thread.
Definition: session.cpp:496
Akonadi::Session::sessionId
QByteArray sessionId() const
Returns the session identifier.
Definition: session.cpp:474
Akonadi::Monitor::tagsMonitored
QVector< Tag::Id > tagsMonitored() const
Returns the set of tags being monitored.
Definition: monitor.cpp:300
Akonadi::Monitor::itemFetchScope
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition: monitor.cpp:237
Akonadi::Monitor::collectionsMonitored
Collection::List collectionsMonitored() const
Returns the list of collections being monitored.
Definition: monitor.cpp:273
Akonadi::Monitor::resourceMonitored
void resourceMonitored(const QByteArray &identifier, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring the resource with the identifier ide...
Akonadi::Monitor::numResourcesMonitored
int numResourcesMonitored() const
Returns the number of resources being monitored.
Definition: monitor.cpp:336
QObject
Akonadi::Monitor::collectionFetchScope
CollectionFetchScope & collectionFetchScope()
Returns the collection fetch scope.
Definition: monitor.cpp:255
Akonadi::Monitor::setCollectionFetchScope
void setCollectionFetchScope(const CollectionFetchScope &fetchScope)
Sets the collection fetch scope.
Definition: monitor.cpp:249
QList::removeAll
int removeAll(const T &value)
Akonadi::Session
A communication session with the Akonadi storage.
Definition: session.h:59
Akonadi::Monitor::Monitor
Monitor(QObject *parent=0)
Creates a new monitor.
Definition: monitor.cpp:39
QString
QList
QSet::count
int count() const
Akonadi::Monitor::fetchCollection
void fetchCollection(bool enable)
Enables automatic fetching of changed collections from the Akonadi storage.
Definition: monitor.cpp:219
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::Monitor::isAllMonitored
bool isAllMonitored() const
Returns true if everything is being monitored.
Definition: monitor.cpp:342
QStringList
Akonadi::Monitor::tagMonitored
void tagMonitored(const Akonadi::Tag &tag, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring tag explicitly.
Akonadi::Monitor::setCollectionMoveTranslationEnabled
void setCollectionMoveTranslationEnabled(bool enabled)
Allows to enable/disable collection move translation.
Definition: monitor.cpp:371
Akonadi::Monitor::Type
Type
Definition: monitor.h:79
QVector::reserve
void reserve(int size)
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:69
Akonadi::Monitor::numItemsMonitored
int numItemsMonitored() const
Returns the number of items being monitored.
Definition: monitor.cpp:294
QSet::begin
iterator begin()
QList::contains
bool contains(const T &value) const
Akonadi::Monitor::setResourceMonitored
void setResourceMonitored(const QByteArray &resource, bool monitored=true)
Sets whether the specified resource shall be monitored for changes.
Definition: monitor.cpp:106
QSet::contains
bool contains(const T &value) const
Akonadi::Monitor::setTypeMonitored
void setTypeMonitored(Type type, bool monitored=true)
Sets whether given type (Collection, Item, Tag should be monitored).
Definition: monitor.cpp:166
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:74
Akonadi::MonitorPrivate
Definition: monitor_p.h:51
Akonadi::Monitor::typeMonitored
void typeMonitored(const Akonadi::Monitor::Type type, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring type explicitly. ...
QSet::remove
bool remove(const T &value)
QVector
Definition: kcolumnfilterproxymodel_p.h:27
QSet::end
iterator end()
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
Akonadi::Monitor::itemsMonitoredEx
QVector< Item::Id > itemsMonitoredEx() const
Returns the set of items being monitored.
Definition: monitor.cpp:285
QSet::toList
QList< T > toList() const
Akonadi::Monitor::itemMonitored
void itemMonitored(const Akonadi::Item &item, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring item explicitly. ...
Akonadi::Monitor::typesMonitored
QVector< Type > typesMonitored() const
Returns the set of types being monitored.
Definition: monitor.cpp:309
Akonadi::Monitor::numMimeTypesMonitored
int numMimeTypesMonitored() const
Returns the number of mimetypes being monitored.
Definition: monitor.cpp:324
Akonadi::Monitor::setItemMonitored
void setItemMonitored(const Item &item, bool monitored=true)
Sets whether the specified item shall be monitored for changes.
Definition: monitor.cpp:86
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::destroyed
void destroyed(QObject *obj)
Akonadi::Monitor::fetchChangedOnly
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:243
Akonadi::Monitor::itemsMonitored
AKONADI_DEPRECATED QList< Item::Id > itemsMonitored() const
Returns the set of items being monitored.
Definition: monitor.cpp:279
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal