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/notificationmessagev2_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;
75 ItemListCache *itemCache;
78 QQueue<NotificationMessageV2> pendingNotifications;
80 QQueue<NotificationMessageV2> pipeline;
88 bool fetchCollectionStatistics;
89 bool collectionMoveTranslationEnabled;
92 virtual void notificationsEnqueued(
int ) {}
93 virtual void notificationsErased() {}
96 virtual bool connectToNotificationManager();
97 bool acceptNotification(
const NotificationMessageV2 &msg,
bool allowModifyFlagsConversion =
false )
const;
98 void dispatchNotifications();
103 void cleanOldNotifications();
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 );
118 void invalidateCache(
const Collection &col );
121 virtual int pipelineSize()
const;
124 void dataAvailable();
125 void slotSessionDestroyed( QObject* );
126 void slotStatisticsChangedFinished( KJob* );
127 void slotFlushRecentlyChangedCollections();
132 int translateAndCompress( QQueue<NotificationMessageV2> ¬ificationQueue,
const NotificationMessageV2 &msg );
134 virtual void slotNotify(
const NotificationMessageV2::List &msgs );
140 bool emitItemsNotification(
const NotificationMessageV2 &msg,
const Item::List &items =
Item::List(),
146 bool emitCollectionNotification(
const NotificationMessageV2 &msg,
const Collection &col =
Collection(),
154 void invalidateCollectionCache( qint64 collectionId );
159 void invalidateItemCache( qint64 itemId );
176 static const int MAXBUFFERSIZE = 10;
196 return m_buffer.contains(
id );
199 static int buffersize();
202 QQueue<Collection::Id> m_buffer;
206 QHash<Collection::Id, int> refCountMap;
224 QSet<Collection::Id> recentlyChangedCollections;
225 QTimer statisticsCompressionTimer;
230 bool isLazilyIgnored(
const NotificationMessageV2 & msg,
bool allowModifyFlagsConversion =
false )
const;
237 void checkBatchSupport(
const NotificationMessageV2 &msg,
bool &needsSplit,
bool &batchSupported )
const;
239 NotificationMessageV2::List splitMessage(
const NotificationMessageV2 &msg,
bool legacy )
const;
245 if ( collections.contains(
Collection( collection ) ) )
252 bool isMimeTypeMonitored(
const QString& mimetype )
const
254 if ( mimetypes.contains( mimetype ) )
257 KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
258 if ( mimeType.isNull() )
261 foreach (
const QString &mt, mimetypes ) {
262 if ( mimeType->is( mt ) )
269 bool isMoveDestinationResourceMonitored(
const NotificationMessageV2 &msg )
const
271 if ( msg.operation() != NotificationMessageV2::Move )
273 return resources.contains( msg.destinationResource() );
278 CollectionStatisticsJob *job =
new CollectionStatisticsJob( Collection( colId ), session );
279 QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
282 void notifyCollectionStatisticsWatchers(
Collection::Id collection,
const QByteArray &resource );