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"
30 #include "tagfetchscope.h"
32 #include "entitycache_p.h"
33 #include "servermanager.h"
34 #include "changenotificationdependenciesfactory_p.h"
35 #include "notificationsource_p.h"
37 #include <akonadi/private/notificationmessagev3_p.h>
39 #include <kmimetype.h>
41 #include <QtCore/QObject>
42 #include <QtCore/QTimer>
56 delete dependenciesFactory;
57 delete collectionCache;
65 NotificationSource *notificationSource;
67 QSet<QByteArray> resources;
70 QSet<Monitor::Type> types;
71 QSet<QString> mimetypes;
73 QList<QByteArray> sessions;
77 bool mFetchChangedOnly;
80 ItemListCache *itemCache;
81 TagListCache *tagCache;
84 QQueue<NotificationMessageV3> pendingNotifications;
86 QQueue<NotificationMessageV3> pipeline;
94 bool fetchCollectionStatistics;
95 bool collectionMoveTranslationEnabled;
98 virtual void notificationsEnqueued(
int)
101 virtual void notificationsErased()
106 virtual bool connectToNotificationManager();
107 bool acceptNotification(
const NotificationMessageV3 &msg)
const;
108 void dispatchNotifications();
109 void flushPipeline();
113 void cleanOldNotifications();
115 bool ensureDataAvailable(
const NotificationMessageV3 &msg);
121 virtual bool emitNotification(
const NotificationMessageV3 &msg);
122 void updatePendingStatistics(
const NotificationMessageV3 &msg);
123 void invalidateCaches(
const NotificationMessageV3 &msg);
131 virtual int pipelineSize()
const;
134 void dataAvailable();
135 void slotSessionDestroyed(QObject *
object);
136 void slotStatisticsChangedFinished(KJob *job);
137 void slotFlushRecentlyChangedCollections();
142 int translateAndCompress(QQueue<NotificationMessageV3> ¬ificationQueue,
const NotificationMessageV3 &msg);
144 virtual void slotNotify(
const NotificationMessageV3::List &msgs);
150 bool emitItemsNotification(
const NotificationMessageV3 &msg,
const Item::List &items = Item::List(),
156 bool emitCollectionNotification(
const NotificationMessageV3 &msg,
const Collection &col =
Collection(),
159 bool emitTagsNotification(
const NotificationMessageV3 &msg,
const Tag::List &tags);
166 void invalidateCollectionCache(qint64 collectionId);
171 void invalidateItemCache(qint64 itemId);
176 void invalidateTagCache(qint64 tagId);
193 static const int MAXBUFFERSIZE = 10;
213 return m_buffer.contains(
id);
216 static int buffersize();
219 QQueue<Collection::Id> m_buffer;
222 QHash<Collection::Id, int> refCountMap;
240 QSet<Collection::Id> recentlyChangedCollections;
241 QTimer statisticsCompressionTimer;
246 bool isLazilyIgnored(
const NotificationMessageV3 &msg,
bool allowModifyFlagsConversion =
false)
const;
253 void checkBatchSupport(
const NotificationMessageV3 &msg,
bool &needsSplit,
bool &batchSupported)
const;
255 NotificationMessageV3::List splitMessage(
const NotificationMessageV3 &msg,
bool legacy)
const;
259 if (collection < 0) {
262 if (collections.contains(
Collection(collection))) {
271 bool isMimeTypeMonitored(
const QString &mimetype)
const
273 if (mimetypes.contains(mimetype)) {
277 KMimeType::Ptr mimeType = KMimeType::mimeType(mimetype, KMimeType::ResolveAliases);
278 if (mimeType.isNull()) {
282 foreach (
const QString &mt, mimetypes) {
283 if (mimeType->is(mt)) {
291 bool isMoveDestinationResourceMonitored(
const NotificationMessageV3 &msg)
const
293 if (msg.operation() != NotificationMessageV2::Move) {
296 return resources.contains(msg.destinationResource());
301 CollectionStatisticsJob *job =
new CollectionStatisticsJob(Collection(colId), session);
302 QObject::connect(job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotStatisticsChangedFinished(KJob*)));
305 void notifyCollectionStatisticsWatchers(
Collection::Id collection,
const QByteArray &resource);