20 #ifndef AKONADI_MONITOR_P_H
21 #define AKONADI_MONITOR_P_H
23 #include "akonadiprivate_export.h"
25 #include "collection.h"
26 #include "collectionstatisticsjob.h"
27 #include "collectionfetchscope.h"
29 #include "itemfetchscope.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"
37 #include <kmimetype.h>
39 #include <QtCore/QObject>
40 #include <QtCore/QTimer>
54 delete dependenciesFactory;
55 delete collectionCache;
63 QObject* notificationSource;
65 QSet<QByteArray> resources;
67 QSet<QString> mimetypes;
69 QList<QByteArray> sessions;
72 bool mFetchChangedOnly;
78 QQueue<NotificationMessage> pendingNotifications;
80 QQueue<NotificationMessage> pipeline;
88 bool fetchCollectionStatistics;
89 bool collectionMoveTranslationEnabled;
92 virtual void notificationsEnqueued(
int ) {}
93 virtual void notificationsErased() {}
96 virtual bool connectToNotificationManager();
97 bool acceptNotification(
const NotificationMessage &msg )
const;
98 void dispatchNotifications();
103 void cleanOldNotifications();
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 );
117 void invalidateCache(
const Collection &col );
120 virtual int pipelineSize()
const;
123 void dataAvailable();
124 void slotSessionDestroyed( QObject* );
125 void slotStatisticsChangedFinished( KJob* );
126 void slotFlushRecentlyChangedCollections();
131 bool translateAndCompress( QQueue<NotificationMessage> ¬ificationQueue,
const NotificationMessage &msg );
133 virtual void slotNotify(
const NotificationMessage::List &msgs );
139 bool emitItemNotification(
const NotificationMessage &msg,
const Item &item =
Item(),
145 bool emitCollectionNotification(
const NotificationMessage &msg,
const Collection &col =
Collection(),
153 void invalidateCollectionCache( qint64 collectionId );
158 void invalidateItemCache( qint64 itemId );
175 static const int MAXBUFFERSIZE = 10;
179 m_bufferSize( MAXBUFFERSIZE )
197 return m_buffer.contains(
id );
201 QVector<Collection::Id> m_buffer;
207 QHash<Collection::Id, int> refCountMap;
214 QSet<Collection::Id> recentlyChangedCollections;
215 QTimer statisticsCompressionTimer;
220 bool isLazilyIgnored(
const NotificationMessage & msg )
const;
226 if ( collections.contains(
Collection( collection ) ) )
233 bool isMimeTypeMonitored(
const QString& mimetype )
const
235 if ( mimetypes.contains( mimetype ) )
238 KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
239 if ( mimeType.isNull() )
242 foreach (
const QString &mt, mimetypes ) {
243 if ( mimeType->is( mt ) )
250 bool isMoveDestinationResourceMonitored(
const NotificationMessage &msg )
const
252 if ( msg.operation() != NotificationMessage::Move )
254 return resources.contains( msg.destinationResource() );
259 CollectionStatisticsJob *job =
new CollectionStatisticsJob( Collection( colId ), session );
260 QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
263 void notifyCollectionStatisticsWatchers(
Collection::Id collection,
const QByteArray &resource );