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

akonadi

  • sources
  • kde-4.12
  • 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 "job.h"
31 #include <akonadi/private/notificationmessagev2_p.h>
32 #include "entitycache_p.h"
33 #include "servermanager.h"
34 #include "changenotificationdependenciesfactory_p.h"
35 #include "notificationsource_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  NotificationSource* 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 ) 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 AKONADI_TESTS_EXPORT 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  QHash<Collection::Id, int> refCountMap;
206  bool useRefCounting;
207  void ref( Collection::Id id );
208  Collection::Id deref( Collection::Id id );
209 
219  bool isMonitored( Collection::Id colId ) const;
220 
221  private:
222  // collections that need a statistics update
223  QSet<Collection::Id> recentlyChangedCollections;
224  QTimer statisticsCompressionTimer;
225 
229  bool isLazilyIgnored( const NotificationMessageV2 & msg, bool allowModifyFlagsConversion = false ) const;
230 
236  void checkBatchSupport( const NotificationMessageV2 &msg, bool &needsSplit, bool &batchSupported ) const;
237 
238  NotificationMessageV2::List splitMessage( const NotificationMessageV2 &msg, bool legacy ) const;
239 
240  bool isCollectionMonitored( Collection::Id collection ) const
241  {
242  if (collection < 0)
243  return false;
244  if ( collections.contains( Collection( collection ) ) )
245  return true;
246  if ( collections.contains( Collection::root() ) )
247  return true;
248  return false;
249  }
250 
251  bool isMimeTypeMonitored( const QString& mimetype ) const
252  {
253  if ( mimetypes.contains( mimetype ) )
254  return true;
255 
256  KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
257  if ( mimeType.isNull() )
258  return false;
259 
260  foreach ( const QString &mt, mimetypes ) {
261  if ( mimeType->is( mt ) )
262  return true;
263  }
264 
265  return false;
266  }
267 
268  bool isMoveDestinationResourceMonitored( const NotificationMessageV2 &msg ) const
269  {
270  if ( msg.operation() != NotificationMessageV2::Move )
271  return false;
272  return resources.contains( msg.destinationResource() );
273  }
274 
275  void fetchStatistics( Collection::Id colId )
276  {
277  CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
278  QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
279  }
280 
281  void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
282 };
283 
284 }
285 
286 #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::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: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-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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