• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.1 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  QQueue<NotificationMessage> pendingNotifications;
77  QQueue<NotificationMessage> pipeline;
78  bool fetchCollection;
79  bool fetchCollectionStatistics;
80  bool collectionMoveTranslationEnabled;
81 
82  // Virtual so it can be overridden in FakeMonitor.
83  virtual bool connectToNotificationManager();
84  bool acceptNotification( const NotificationMessage &msg );
85  void dispatchNotifications();
86  void flushPipeline();
87 
88  // Called when the monitored item/collection changes, checks if the queued messages
89  // are still accepted, if not they are removed
90  void cleanOldNotifications();
91 
92  bool ensureDataAvailable( const NotificationMessage &msg );
97  virtual bool emitNotification( const NotificationMessage &msg );
98  void updatePendingStatistics( const NotificationMessage &msg );
99  void invalidateCaches( const NotificationMessage &msg );
100 
104  void invalidateCache( const Collection &col );
105 
106  virtual int pipelineSize() const;
107 
108  // private slots
109  void dataAvailable();
110  void slotSessionDestroyed( QObject* );
111  void slotStatisticsChangedFinished( KJob* );
112  void slotFlushRecentlyChangedCollections();
113 
117  bool translateAndCompress( QQueue<NotificationMessage> &notificationQueue, const NotificationMessage &msg );
118 
119  virtual void slotNotify( const NotificationMessage::List &msgs );
120 
125  bool emitItemNotification( const NotificationMessage &msg, const Item &item = Item(),
126  const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
131  bool emitCollectionNotification( const NotificationMessage &msg, const Collection &col = Collection(),
132  const Collection &par = Collection(), const Collection &dest = Collection() );
133 
134  void serverStateChanged( Akonadi::ServerManager::State state );
135 
139  void invalidateCollectionCache( qint64 collectionId );
140 
144  void invalidateItemCache( qint64 itemId );
145 
158  class PurgeBuffer
159  {
160  // Buffer the most recent 10 unreferenced Collections
161  static const int MAXBUFFERSIZE = 10;
162  public:
163  explicit PurgeBuffer()
164  : m_index( 0 ),
165  m_bufferSize( MAXBUFFERSIZE )
166  {
167  }
168 
174  Collection::Id buffer( Collection::Id id );
175 
179  void purge( Collection::Id id );
180 
181  bool isBuffered( Collection::Id id ) const
182  {
183  return m_buffer.contains( id );
184  }
185 
186  private:
187  QVector<Collection::Id> m_buffer;
188  int m_index;
189  int m_bufferSize;
190  } m_buffer;
191 
192 
193  QHash<Collection::Id, int> refCountMap;
194  bool useRefCounting;
195  void ref( Collection::Id id );
196  Collection::Id deref( Collection::Id id );
197 
198  private:
199  // collections that need a statistics update
200  QSet<Collection::Id> recentlyChangedCollections;
201  QTimer statisticsCompressionTimer;
202 
206  bool isLazilyIgnored( const NotificationMessage & msg ) const;
207 
208  bool isCollectionMonitored( Collection::Id collection ) const
209  {
210  if (collection < 0)
211  return false;
212  if ( collections.contains( Collection( collection ) ) )
213  return true;
214  if ( collections.contains( Collection::root() ) )
215  return true;
216  return false;
217  }
218 
219  bool isMimeTypeMonitored( const QString& mimetype ) const
220  {
221  if ( mimetypes.contains( mimetype ) )
222  return true;
223 
224  KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
225  if ( mimeType.isNull() )
226  return false;
227 
228  foreach ( const QString &mt, mimetypes ) {
229  if ( mimeType->is( mt ) )
230  return true;
231  }
232 
233  return false;
234  }
235 
236  bool isMoveDestinationResourceMonitored( const NotificationMessage &msg )
237  {
238  if ( msg.operation() != NotificationMessage::Move )
239  return false;
240  return resources.contains( msg.destinationResource() );
241  }
242 
243  void fetchStatistics( Collection::Id colId )
244  {
245  CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
246  QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
247  }
248 
249  void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
250 };
251 
252 }
253 
254 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:06:27 by doxygen 1.8.1.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.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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