• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

monitor_p.h
00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #ifndef AKONADI_MONITOR_P_H
00021 #define AKONADI_MONITOR_P_H
00022 
00023 #include "akonadiprivate_export.h"
00024 #include "monitor.h"
00025 #include "collection.h"
00026 #include "collectionstatisticsjob.h"
00027 #include "collectionfetchscope.h"
00028 #include "item.h"
00029 #include "itemfetchscope.h"
00030 #include "job.h"
00031 #include <akonadi/private/notificationmessage_p.h>
00032 #include "notificationsourceinterface.h"
00033 #include "entitycache_p.h"
00034 #include "servermanager.h"
00035 #include "changenotificationdependenciesfactory_p.h"
00036 
00037 #include <kmimetype.h>
00038 
00039 #include <QtCore/QObject>
00040 #include <QtCore/QTimer>
00041 
00042 namespace Akonadi {
00043 
00044 class Monitor;
00045 
00049 class AKONADI_TESTS_EXPORT MonitorPrivate
00050 {
00051   public:
00052     MonitorPrivate( ChangeNotificationDependenciesFactory *dependenciesFactory_, Monitor *parent );
00053     virtual ~MonitorPrivate() {
00054       delete dependenciesFactory;
00055       delete collectionCache;
00056       delete itemCache;
00057     }
00058     void init();
00059 
00060     Monitor *q_ptr;
00061     Q_DECLARE_PUBLIC( Monitor )
00062     ChangeNotificationDependenciesFactory *dependenciesFactory;
00063     QObject* notificationSource;
00064     Collection::List collections;
00065     QSet<QByteArray> resources;
00066     QSet<Item::Id> items;
00067     QSet<QString> mimetypes;
00068     bool monitorAll;
00069     QList<QByteArray> sessions;
00070     ItemFetchScope mItemFetchScope;
00071     CollectionFetchScope mCollectionFetchScope;
00072     bool mFetchChangedOnly;
00073     Session *session;
00074     CollectionCache *collectionCache;
00075     ItemCache *itemCache;
00076     QQueue<NotificationMessage> pendingNotifications;
00077     QQueue<NotificationMessage> pipeline;
00078     bool fetchCollection;
00079     bool fetchCollectionStatistics;
00080 
00081     // Virtual so it can be overridden in FakeMonitor.
00082     virtual bool connectToNotificationManager();
00083     bool acceptNotification( const NotificationMessage &msg );
00084     void dispatchNotifications();
00085     void flushPipeline();
00086 
00087     // Called when the monitored item/collection changes, checks if the queued messages
00088     // are still accepted, if not they are removed
00089     void cleanOldNotifications();
00090 
00091     bool ensureDataAvailable( const NotificationMessage &msg );
00096     virtual bool emitNotification( const NotificationMessage &msg );
00097     void updatePendingStatistics( const NotificationMessage &msg );
00098     void invalidateCaches( const NotificationMessage &msg );
00099 
00103     void invalidateCache( const Collection &col );
00104 
00105     virtual int pipelineSize() const;
00106 
00107     // private slots
00108     void dataAvailable();
00109     void slotSessionDestroyed( QObject* );
00110     void slotStatisticsChangedFinished( KJob* );
00111     void slotFlushRecentlyChangedCollections();
00112 
00116     bool translateAndCompress( QQueue<NotificationMessage> &notificationQueue, const NotificationMessage &msg  );
00117 
00118     virtual void slotNotify( const NotificationMessage::List &msgs );
00119 
00124     bool emitItemNotification( const NotificationMessage &msg, const Item &item = Item(),
00125                                const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
00130     bool emitCollectionNotification( const NotificationMessage &msg, const Collection &col = Collection(),
00131                                      const Collection &par = Collection(), const Collection &dest = Collection() );
00132 
00133     void serverStateChanged( Akonadi::ServerManager::State state );
00134 
00138     void invalidateCollectionCache( qint64 collectionId );
00139 
00143     void invalidateItemCache( qint64 itemId );
00144 
00157     class PurgeBuffer
00158     {
00159       // Buffer the most recent 10 unreferenced Collections
00160       static const int MAXBUFFERSIZE = 10;
00161     public:
00162       explicit PurgeBuffer()
00163         : m_index( 0 ),
00164           m_bufferSize( MAXBUFFERSIZE )
00165       {
00166       }
00167 
00173       Collection::Id buffer( Collection::Id id );
00174 
00178       void purge( Collection::Id id );
00179 
00180       bool isBuffered( Collection::Id id ) const
00181       {
00182         return m_buffer.contains( id );
00183       }
00184 
00185     private:
00186       QVector<Collection::Id> m_buffer;
00187       int m_index;
00188       int m_bufferSize;
00189     } m_buffer;
00190 
00191 
00192     QHash<Collection::Id, int> refCountMap;
00193     bool useRefCounting;
00194     void ref( Collection::Id id );
00195     Collection::Id deref( Collection::Id id );
00196 
00197   private:
00198     // collections that need a statistics update
00199     QSet<Collection::Id> recentlyChangedCollections;
00200     QTimer statisticsCompressionTimer;
00201 
00205     bool isLazilyIgnored( const NotificationMessage & msg ) const;
00206 
00207     bool isCollectionMonitored( Collection::Id collection ) const
00208     {
00209       if (collection < 0)
00210         return false;
00211       if ( collections.contains( Collection( collection ) ) )
00212         return true;
00213       if ( collections.contains( Collection::root() ) )
00214         return true;
00215       return false;
00216     }
00217 
00218     bool isMimeTypeMonitored( const QString& mimetype ) const
00219     {
00220       if ( mimetypes.contains( mimetype ) )
00221         return true;
00222 
00223       KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
00224       if ( mimeType.isNull() )
00225         return false;
00226 
00227       foreach ( const QString &mt, mimetypes ) {
00228         if ( mimeType->is( mt ) )
00229           return true;
00230       }
00231 
00232       return false;
00233     }
00234 
00235     bool isMoveDestinationResourceMonitored( const NotificationMessage &msg )
00236     {
00237       if ( msg.operation() != NotificationMessage::Move )
00238         return false;
00239       return resources.contains( msg.destinationResource() );
00240     }
00241 
00242     void fetchStatistics( Collection::Id colId )
00243     {
00244       CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
00245       QObject::connect( job, SIGNAL( result( KJob* ) ), q_ptr, SLOT( slotStatisticsChangedFinished( KJob* ) ) );
00246     }
00247 
00248     void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource );
00249 };
00250 
00251 }
00252 
00253 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:45 by doxygen 1.8.0 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.8.3 API Reference

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