• 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_p.h
1 /*
2  Copyright (c) 2007 Tobias Koenig <tokoe@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 #ifndef AKONADI_MONITOR_P_H
21 #define AKONADI_MONITOR_P_H
22 
23 #include "akonadiprivate_export.h"
24 #include "monitor.h"
25 #include "collection.h"
26 #include "collectionstatisticsjob.h"
27 #include "collectionfetchscope.h"
28 #include "item.h"
29 #include "itemfetchscope.h"
30 #include "tagfetchscope.h"
31 #include "job.h"
32 #include "entitycache_p.h"
33 #include "servermanager.h"
34 #include "changenotificationdependenciesfactory_p.h"
35 #include "notificationsource_p.h"
36 
37 #include <akonadi/private/notificationmessagev3_p.h>
38 
39 #include <kmimetype.h>
40 
41 #include <QtCore/QObject>
42 #include <QtCore/QTimer>
43 
44 namespace Akonadi {
45 
46 class Monitor;
47 
51 class AKONADI_TESTS_EXPORT MonitorPrivate
52 {
53 public:
54  MonitorPrivate(ChangeNotificationDependenciesFactory *dependenciesFactory_, Monitor *parent);
55  virtual ~MonitorPrivate() {
56  delete dependenciesFactory;
57  delete collectionCache;
58  delete itemCache;
59  }
60  void init();
61 
62  Monitor *q_ptr;
63  Q_DECLARE_PUBLIC(Monitor)
64  ChangeNotificationDependenciesFactory *dependenciesFactory;
65  NotificationSource *notificationSource;
66  Collection::List collections;
67  QSet<QByteArray> resources;
68  QSet<Item::Id> items;
69  QSet<Tag::Id> tags;
70  QSet<Monitor::Type> types;
71  QSet<QString> mimetypes;
72  bool monitorAll;
73  QList<QByteArray> sessions;
74  ItemFetchScope mItemFetchScope;
75  TagFetchScope mTagFetchScope;
76  CollectionFetchScope mCollectionFetchScope;
77  bool mFetchChangedOnly;
78  Session *session;
79  CollectionCache *collectionCache;
80  ItemListCache *itemCache;
81  TagListCache *tagCache;
82 
83  // The waiting list
84  QQueue<NotificationMessageV3> pendingNotifications;
85  // The messages for which data is currently being fetched
86  QQueue<NotificationMessageV3> pipeline;
87  // In a pure Monitor, the pipeline contains items that were dequeued from pendingNotifications.
88  // The ordering [pipeline] [pendingNotifications] is kept at all times.
89  // [] [A B C] -> [A B] [C] -> [B] [C] -> [B C] [] -> [C] [] -> []
90  // In a ChangeRecorder, the pipeline contains one item only, and not dequeued yet.
91  // [] [A B C] -> [A] [A B C] -> [] [A B C] -> (changeProcessed) [] [B C] -> [B] [B C] etc...
92 
93  bool fetchCollection;
94  bool fetchCollectionStatistics;
95  bool collectionMoveTranslationEnabled;
96 
97  // Virtual methods for ChangeRecorder
98  virtual void notificationsEnqueued(int)
99  {
100  }
101  virtual void notificationsErased()
102  {
103  }
104 
105  // Virtual so it can be overridden in FakeMonitor.
106  virtual bool connectToNotificationManager();
107  bool acceptNotification(const NotificationMessageV3 &msg) const;
108  void dispatchNotifications();
109  void flushPipeline();
110 
111  // Called when the monitored item/collection changes, checks if the queued messages
112  // are still accepted, if not they are removed
113  void cleanOldNotifications();
114 
115  bool ensureDataAvailable(const NotificationMessageV3 &msg);
121  virtual bool emitNotification(const NotificationMessageV3 &msg);
122  void updatePendingStatistics(const NotificationMessageV3 &msg);
123  void invalidateCaches(const NotificationMessageV3 &msg);
124 
128  void invalidateCache(const Collection &col);
129 
131  virtual int pipelineSize() const;
132 
133  // private Q_SLOTS
134  void dataAvailable();
135  void slotSessionDestroyed(QObject *object);
136  void slotStatisticsChangedFinished(KJob *job);
137  void slotFlushRecentlyChangedCollections();
138 
142  int translateAndCompress(QQueue<NotificationMessageV3> &notificationQueue, const NotificationMessageV3 &msg);
143 
144  virtual void slotNotify(const NotificationMessageV3::List &msgs);
145 
150  bool emitItemsNotification(const NotificationMessageV3 &msg, const Item::List &items = Item::List(),
151  const Collection &collection = Collection(), const Collection &collectionDest = Collection());
156  bool emitCollectionNotification(const NotificationMessageV3 &msg, const Collection &col = Collection(),
157  const Collection &par = Collection(), const Collection &dest = Collection());
158 
159  bool emitTagsNotification(const NotificationMessageV3 &msg, const Tag::List &tags);
160 
161  void serverStateChanged(Akonadi::ServerManager::State state);
162 
166  void invalidateCollectionCache(qint64 collectionId);
167 
171  void invalidateItemCache(qint64 itemId);
172 
176  void invalidateTagCache(qint64 tagId);
177 
190  class AKONADI_TESTS_EXPORT PurgeBuffer
191  {
192  // Buffer the most recent 10 unreferenced Collections
193  static const int MAXBUFFERSIZE = 10;
194  public:
195  explicit PurgeBuffer()
196  {
197  }
198 
204  Collection::Id buffer(Collection::Id id);
205 
209  void purge(Collection::Id id);
210 
211  bool isBuffered(Collection::Id id) const
212  {
213  return m_buffer.contains(id);
214  }
215 
216  static int buffersize();
217 
218  private:
219  QQueue<Collection::Id> m_buffer;
220  } m_buffer;
221 
222  QHash<Collection::Id, int> refCountMap;
223  bool useRefCounting;
224  void ref(Collection::Id id);
225  Collection::Id deref(Collection::Id id);
226 
236  bool isMonitored(Collection::Id colId) const;
237 
238 private:
239  // collections that need a statistics update
240  QSet<Collection::Id> recentlyChangedCollections;
241  QTimer statisticsCompressionTimer;
242 
246  bool isLazilyIgnored(const NotificationMessageV3 &msg, bool allowModifyFlagsConversion = false) const;
247 
253  void checkBatchSupport(const NotificationMessageV3 &msg, bool &needsSplit, bool &batchSupported) const;
254 
255  NotificationMessageV3::List splitMessage(const NotificationMessageV3 &msg, bool legacy) const;
256 
257  bool isCollectionMonitored(Collection::Id collection) const
258  {
259  if (collection < 0) {
260  return false;
261  }
262  if (collections.contains(Collection(collection))) {
263  return true;
264  }
265  if (collections.contains(Collection::root())) {
266  return true;
267  }
268  return false;
269  }
270 
271  bool isMimeTypeMonitored(const QString &mimetype) const
272  {
273  if (mimetypes.contains(mimetype)) {
274  return true;
275  }
276 
277  KMimeType::Ptr mimeType = KMimeType::mimeType(mimetype, KMimeType::ResolveAliases);
278  if (mimeType.isNull()) {
279  return false;
280  }
281 
282  foreach (const QString &mt, mimetypes) {
283  if (mimeType->is(mt)) {
284  return true;
285  }
286  }
287 
288  return false;
289  }
290 
291  bool isMoveDestinationResourceMonitored(const NotificationMessageV3 &msg) const
292  {
293  if (msg.operation() != NotificationMessageV2::Move) {
294  return false;
295  }
296  return resources.contains(msg.destinationResource());
297  }
298 
299  void fetchStatistics(Collection::Id colId)
300  {
301  CollectionStatisticsJob *job = new CollectionStatisticsJob(Collection(colId), session);
302  QObject::connect(job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotStatisticsChangedFinished(KJob*)));
303  }
304 
305  void notifyCollectionStatisticsWatchers(Collection::Id collection, const QByteArray &resource);
306 };
307 
308 }
309 
310 #endif
Akonadi::ChangeNotificationDependenciesFactory
This class exists so that we can create a fake notification source in unit tests. ...
Definition: changenotificationdependenciesfactory_p.h:35
QQueue< NotificationMessageV3 >
QByteArray
Akonadi::CollectionFetchScope
Specifies which parts of a collection should be fetched from the Akonadi storage. ...
Definition: collectionfetchscope.h:68
Akonadi::TagFetchScope
Specifies which parts of a tag should be fetched from the Akonadi storage.
Definition: tagfetchscope.h:33
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
QTimer
QHash
QObject
Akonadi::Collection::root
static Collection root()
Returns the root collection.
Definition: collection.cpp:192
Akonadi::Session
A communication session with the Akonadi storage.
Definition: session.h:59
QSet< QByteArray >
QString
QList
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:69
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:74
Akonadi::MonitorPrivate
Definition: monitor_p.h:51
Akonadi::EntityCache
Definition: entitycache_p.h:97
Akonadi::MonitorPrivate::PurgeBuffer
Class used to determine when to purge items in a Collection.
Definition: monitor_p.h:190
Akonadi::ServerManager::State
State
Enum for the various states the server can be in.
Definition: servermanager.h:50
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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