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

akonadi

  • 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  virtual void notificationsErased() {}
100 
101  // Virtual so it can be overridden in FakeMonitor.
102  virtual bool connectToNotificationManager();
103  bool acceptNotification( const NotificationMessageV3 &msg ) const;
104  void dispatchNotifications();
105  void flushPipeline();
106 
107  // Called when the monitored item/collection changes, checks if the queued messages
108  // are still accepted, if not they are removed
109  void cleanOldNotifications();
110 
111  bool ensureDataAvailable( const NotificationMessageV3 &msg );
117  virtual bool emitNotification( const NotificationMessageV3 &msg );
118  void updatePendingStatistics( const NotificationMessageV3 &msg );
119  void invalidateCaches( const NotificationMessageV3 &msg );
120 
124  void invalidateCache( const Collection &col );
125 
127  virtual int pipelineSize() const;
128 
129  // private Q_SLOTS
130  void dataAvailable();
131  void slotSessionDestroyed( QObject* );
132  void slotStatisticsChangedFinished( KJob* );
133  void slotFlushRecentlyChangedCollections();
134 
138  int translateAndCompress( QQueue<NotificationMessageV3> &notificationQueue, const NotificationMessageV3 &msg );
139 
140  virtual void slotNotify( const NotificationMessageV3::List &msgs );
141 
146  bool emitItemsNotification( const NotificationMessageV3 &msg, const Item::List &items = Item::List(),
147  const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
152  bool emitCollectionNotification( const NotificationMessageV3 &msg, const Collection &col = Collection(),
153  const Collection &par = Collection(), const Collection &dest = Collection() );
154 
155  bool emitTagsNotification( const NotificationMessageV3 &msg, const Tag::List &tags );
156 
157  void serverStateChanged( Akonadi::ServerManager::State state );
158 
162  void invalidateCollectionCache( qint64 collectionId );
163 
167  void invalidateItemCache( qint64 itemId );
168 
172  void invalidateTagCache( qint64 tagId );
173 
186  class AKONADI_TESTS_EXPORT PurgeBuffer
187  {
188  // Buffer the most recent 10 unreferenced Collections
189  static const int MAXBUFFERSIZE = 10;
190  public:
191  explicit PurgeBuffer()
192  {
193  }
194 
200  Collection::Id buffer( Collection::Id id );
201 
205  void purge( Collection::Id id );
206 
207  bool isBuffered( Collection::Id id ) const
208  {
209  return m_buffer.contains( id );
210  }
211 
212  static int buffersize();
213 
214  private:
215  QQueue<Collection::Id> m_buffer;
216  } m_buffer;
217 
218  QHash<Collection::Id, int> refCountMap;
219  bool useRefCounting;
220  void ref( Collection::Id id );
221  Collection::Id deref( Collection::Id id );
222 
232  bool isMonitored( Collection::Id colId ) const;
233 
234  private:
235  // collections that need a statistics update
236  QSet<Collection::Id> recentlyChangedCollections;
237  QTimer statisticsCompressionTimer;
238 
242  bool isLazilyIgnored( const NotificationMessageV3 & msg, bool allowModifyFlagsConversion = false ) const;
243 
249  void checkBatchSupport( const NotificationMessageV3 &msg, bool &needsSplit, bool &batchSupported ) const;
250 
251  NotificationMessageV3::List splitMessage( const NotificationMessageV3 &msg, bool legacy ) const;
252 
253  bool isCollectionMonitored( Collection::Id collection ) const
254  {
255  if (collection < 0)
256  return false;
257  if ( collections.contains( Collection( collection ) ) )
258  return true;
259  if ( collections.contains( Collection::root() ) )
260  return true;
261  return false;
262  }
263 
264  bool isMimeTypeMonitored( const QString& mimetype ) const
265  {
266  if ( mimetypes.contains( mimetype ) )
267  return true;
268 
269  KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
270  if ( mimeType.isNull() )
271  return false;
272 
273  foreach ( const QString &mt, mimetypes ) {
274  if ( mimeType->is( mt ) )
275  return true;
276  }
277 
278  return false;
279  }
280 
281  bool isMoveDestinationResourceMonitored( const NotificationMessageV3 &msg ) const
282  {
283  if ( msg.operation() != NotificationMessageV2::Move )
284  return false;
285  return resources.contains( msg.destinationResource() );
286  }
287 
288  void fetchStatistics( Collection::Id colId )
289  {
290  CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
291  QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
292  }
293 
294  void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
295 };
296 
297 }
298 
299 #endif
Akonadi::ChangeNotificationDependenciesFactory
This class exists so that we can create a fake notification source in unit tests. ...
Definition: changenotificationdependenciesfactory_p.h:35
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
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
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:68
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:75
Akonadi::MonitorPrivate
Definition: monitor_p.h:51
Akonadi::EntityCache
Definition: entitycache_p.h:96
Akonadi::MonitorPrivate::PurgeBuffer
Class used to determine when to purge items in a Collection.
Definition: monitor_p.h:186
Akonadi::ServerManager::State
State
Enum for the various states the server can be in.
Definition: servermanager.h:50
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:54 by doxygen 1.8.6 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-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 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
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