• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.11.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 "job.h"
31 #include <akonadi/private/notificationmessagev2_p.h>
32 #include "notificationsourceinterface.h"
33 #include "entitycache_p.h"
34 #include "servermanager.h"
35 #include "changenotificationdependenciesfactory_p.h"
36 
37 #include <kmimetype.h>
38 
39 #include <QtCore/QObject>
40 #include <QtCore/QTimer>
41 
42 namespace Akonadi {
43 
44 class Monitor;
45 
49 class AKONADI_TESTS_EXPORT MonitorPrivate
50 {
51  public:
52  MonitorPrivate( ChangeNotificationDependenciesFactory *dependenciesFactory_, Monitor *parent );
53  virtual ~MonitorPrivate() {
54  delete dependenciesFactory;
55  delete collectionCache;
56  delete itemCache;
57  }
58  void init();
59 
60  Monitor *q_ptr;
61  Q_DECLARE_PUBLIC( Monitor )
62  ChangeNotificationDependenciesFactory *dependenciesFactory;
63  QObject* notificationSource;
64  Collection::List collections;
65  QSet<QByteArray> resources;
66  QSet<Item::Id> items;
67  QSet<QString> mimetypes;
68  bool monitorAll;
69  QList<QByteArray> sessions;
70  ItemFetchScope mItemFetchScope;
71  CollectionFetchScope mCollectionFetchScope;
72  bool mFetchChangedOnly;
73  Session *session;
74  CollectionCache *collectionCache;
75  ItemListCache *itemCache;
76 
77  // The waiting list
78  QQueue<NotificationMessageV2> pendingNotifications;
79  // The messages for which data is currently being fetched
80  QQueue<NotificationMessageV2> pipeline;
81  // In a pure Monitor, the pipeline contains items that were dequeued from pendingNotifications.
82  // The ordering [ pipeline ] [ pendingNotifications ] is kept at all times.
83  // [] [A B C] -> [A B] [C] -> [B] [C] -> [B C] [] -> [C] [] -> []
84  // In a ChangeRecorder, the pipeline contains one item only, and not dequeued yet.
85  // [] [A B C] -> [A] [A B C] -> [] [A B C] -> (changeProcessed) [] [B C] -> [B] [B C] etc...
86 
87  bool fetchCollection;
88  bool fetchCollectionStatistics;
89  bool collectionMoveTranslationEnabled;
90 
91  // Virtual methods for ChangeRecorder
92  virtual void notificationsEnqueued( int ) {}
93  virtual void notificationsErased() {}
94 
95  // Virtual so it can be overridden in FakeMonitor.
96  virtual bool connectToNotificationManager();
97  bool acceptNotification( const NotificationMessageV2 &msg, bool allowModifyFlagsConversion = false ) const;
98  void dispatchNotifications();
99  void flushPipeline();
100 
101  // Called when the monitored item/collection changes, checks if the queued messages
102  // are still accepted, if not they are removed
103  void cleanOldNotifications();
104 
105  bool ensureDataAvailable( const NotificationMessageV2 &msg );
111  virtual bool emitNotification( const NotificationMessageV2 &msg );
112  void updatePendingStatistics( const NotificationMessageV2 &msg );
113  void invalidateCaches( const NotificationMessageV2 &msg );
114 
118  void invalidateCache( const Collection &col );
119 
121  virtual int pipelineSize() const;
122 
123  // private slots
124  void dataAvailable();
125  void slotSessionDestroyed( QObject* );
126  void slotStatisticsChangedFinished( KJob* );
127  void slotFlushRecentlyChangedCollections();
128 
132  int translateAndCompress( QQueue<NotificationMessageV2> &notificationQueue, const NotificationMessageV2 &msg );
133 
134  virtual void slotNotify( const NotificationMessageV2::List &msgs );
135 
140  bool emitItemsNotification( const NotificationMessageV2 &msg, const Item::List &items = Item::List(),
141  const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
146  bool emitCollectionNotification( const NotificationMessageV2 &msg, const Collection &col = Collection(),
147  const Collection &par = Collection(), const Collection &dest = Collection() );
148 
149  void serverStateChanged( Akonadi::ServerManager::State state );
150 
154  void invalidateCollectionCache( qint64 collectionId );
155 
159  void invalidateItemCache( qint64 itemId );
160 
173  class PurgeBuffer
174  {
175  // Buffer the most recent 10 unreferenced Collections
176  static const int MAXBUFFERSIZE = 10;
177  public:
178  explicit PurgeBuffer()
179  {
180  }
181 
187  Collection::Id buffer( Collection::Id id );
188 
192  void purge( Collection::Id id );
193 
194  bool isBuffered( Collection::Id id ) const
195  {
196  return m_buffer.contains( id );
197  }
198 
199  static int buffersize();
200 
201  private:
202  QQueue<Collection::Id> m_buffer;
203  } m_buffer;
204 
205 
206  QHash<Collection::Id, int> refCountMap;
207  bool useRefCounting;
208  void ref( Collection::Id id );
209  Collection::Id deref( Collection::Id id );
210 
220  bool isMonitored( Collection::Id colId ) const;
221 
222  private:
223  // collections that need a statistics update
224  QSet<Collection::Id> recentlyChangedCollections;
225  QTimer statisticsCompressionTimer;
226 
230  bool isLazilyIgnored( const NotificationMessageV2 & msg, bool allowModifyFlagsConversion = false ) const;
231 
237  void checkBatchSupport( const NotificationMessageV2 &msg, bool &needsSplit, bool &batchSupported ) const;
238 
239  NotificationMessageV2::List splitMessage( const NotificationMessageV2 &msg, bool legacy ) const;
240 
241  bool isCollectionMonitored( Collection::Id collection ) const
242  {
243  if (collection < 0)
244  return false;
245  if ( collections.contains( Collection( collection ) ) )
246  return true;
247  if ( collections.contains( Collection::root() ) )
248  return true;
249  return false;
250  }
251 
252  bool isMimeTypeMonitored( const QString& mimetype ) const
253  {
254  if ( mimetypes.contains( mimetype ) )
255  return true;
256 
257  KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
258  if ( mimeType.isNull() )
259  return false;
260 
261  foreach ( const QString &mt, mimetypes ) {
262  if ( mimeType->is( mt ) )
263  return true;
264  }
265 
266  return false;
267  }
268 
269  bool isMoveDestinationResourceMonitored( const NotificationMessageV2 &msg ) const
270  {
271  if ( msg.operation() != NotificationMessageV2::Move )
272  return false;
273  return resources.contains( msg.destinationResource() );
274  }
275 
276  void fetchStatistics( Collection::Id colId )
277  {
278  CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
279  QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
280  }
281 
282  void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
283 };
284 
285 }
286 
287 #endif
Akonadi::ChangeNotificationDependenciesFactory
This class exists so that we can create a fake notification source in unit tests. ...
Definition: changenotificationdependenciesfactory_p.h:33
Akonadi::CollectionFetchScope
Specifies which parts of a collection should be fetched from the Akonadi storage. ...
Definition: collectionfetchscope.h:68
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:64
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:72
Akonadi::MonitorPrivate
Definition: monitor_p.h:49
Akonadi::EntityCache
Definition: entitycache_p.h:83
Akonadi::MonitorPrivate::PurgeBuffer
Class used to determine when to purge items in a Collection.
Definition: monitor_p.h:173
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-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:18 by doxygen 1.8.5 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.11.3 API Reference

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