• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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/notificationmessage_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  ItemCache *itemCache;
76 
77  // The waiting list
78  QQueue<NotificationMessage> pendingNotifications;
79  // The messages for which data is currently being fetched
80  QQueue<NotificationMessage> 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 NotificationMessage &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 NotificationMessage &msg );
110  virtual bool emitNotification( const NotificationMessage &msg );
111  void updatePendingStatistics( const NotificationMessage &msg );
112  void invalidateCaches( const NotificationMessage &msg );
113 
117  void invalidateCache( const Collection &col );
118 
120  virtual int pipelineSize() const;
121 
122  // private slots
123  void dataAvailable();
124  void slotSessionDestroyed( QObject* );
125  void slotStatisticsChangedFinished( KJob* );
126  void slotFlushRecentlyChangedCollections();
127 
131  bool translateAndCompress( QQueue<NotificationMessage> &notificationQueue, const NotificationMessage &msg );
132 
133  virtual void slotNotify( const NotificationMessage::List &msgs );
134 
139  bool emitItemNotification( const NotificationMessage &msg, const Item &item = Item(),
140  const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
145  bool emitCollectionNotification( const NotificationMessage &msg, const Collection &col = Collection(),
146  const Collection &par = Collection(), const Collection &dest = Collection() );
147 
148  void serverStateChanged( Akonadi::ServerManager::State state );
149 
153  void invalidateCollectionCache( qint64 collectionId );
154 
158  void invalidateItemCache( qint64 itemId );
159 
172  class PurgeBuffer
173  {
174  // Buffer the most recent 10 unreferenced Collections
175  static const int MAXBUFFERSIZE = 10;
176  public:
177  explicit PurgeBuffer()
178  {
179  }
180 
186  Collection::Id buffer( Collection::Id id );
187 
191  void purge( Collection::Id id );
192 
193  bool isBuffered( Collection::Id id ) const
194  {
195  return m_buffer.contains( id );
196  }
197 
198  private:
199  QQueue<Collection::Id> m_buffer;
200  } m_buffer;
201 
202 
203  QHash<Collection::Id, int> refCountMap;
204  bool useRefCounting;
205  void ref( Collection::Id id );
206  Collection::Id deref( Collection::Id id );
207 
208  private:
209  // collections that need a statistics update
210  QSet<Collection::Id> recentlyChangedCollections;
211  QTimer statisticsCompressionTimer;
212 
216  bool isLazilyIgnored( const NotificationMessage & msg ) const;
217 
218  bool isCollectionMonitored( Collection::Id collection ) const
219  {
220  if (collection < 0)
221  return false;
222  if ( collections.contains( Collection( collection ) ) )
223  return true;
224  if ( collections.contains( Collection::root() ) )
225  return true;
226  return false;
227  }
228 
229  bool isMimeTypeMonitored( const QString& mimetype ) const
230  {
231  if ( mimetypes.contains( mimetype ) )
232  return true;
233 
234  KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
235  if ( mimeType.isNull() )
236  return false;
237 
238  foreach ( const QString &mt, mimetypes ) {
239  if ( mimeType->is( mt ) )
240  return true;
241  }
242 
243  return false;
244  }
245 
246  bool isMoveDestinationResourceMonitored( const NotificationMessage &msg ) const
247  {
248  if ( msg.operation() != NotificationMessage::Move )
249  return false;
250  return resources.contains( msg.destinationResource() );
251  }
252 
253  void fetchStatistics( Collection::Id colId )
254  {
255  CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
256  QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
257  }
258 
259  void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
260 };
261 
262 }
263 
264 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:39 by doxygen 1.8.3.1 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.10.5 API Reference

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