• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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 "monitor.h"
00024 #include "collection.h"
00025 #include "collectionstatisticsjob.h"
00026 #include "collectionfetchscope.h"
00027 #include "item.h"
00028 #include "itemfetchscope.h"
00029 #include "job.h"
00030 #include <akonadi/private/notificationmessage_p.h>
00031 #include "notificationmanagerinterface.h"
00032 #include "entitycache_p.h"
00033 
00034 #include <kmimetype.h>
00035 
00036 #include <QtCore/QObject>
00037 #include <QtCore/QTimer>
00038 
00039 namespace Akonadi {
00040 
00041 class Monitor;
00042 
00046 class MonitorPrivate
00047 {
00048   public:
00049     MonitorPrivate( Monitor *parent );
00050     virtual ~MonitorPrivate() {}
00051     void init();
00052 
00053     Monitor *q_ptr;
00054     Q_DECLARE_PUBLIC( Monitor )
00055     org::freedesktop::Akonadi::NotificationManager *nm;
00056     Collection::List collections;
00057     QSet<QByteArray> resources;
00058     QSet<Item::Id> items;
00059     QSet<QString> mimetypes;
00060     bool monitorAll;
00061     QList<QByteArray> sessions;
00062     ItemFetchScope mItemFetchScope;
00063     CollectionFetchScope mCollectionFetchScope;
00064     Session *session;
00065     CollectionCache collectionCache;
00066     ItemCache itemCache;
00067     QQueue<NotificationMessage> pendingNotifications;
00068     QQueue<NotificationMessage> pipeline;
00069     bool fetchCollection;
00070     bool fetchCollectionStatistics;
00071 
00072     bool isCollectionMonitored( Collection::Id collection, const QByteArray &resource ) const
00073     {
00074       if ( monitorAll || isCollectionMonitored( collection ) || resources.contains( resource ) )
00075         return true;
00076       return false;
00077     }
00078 
00079     bool isItemMonitored( Item::Id item, Collection::Id collection, Collection::Id collectionDest,
00080                           const QString &mimetype, const QByteArray &resource ) const
00081     {
00082       if ( monitorAll || isCollectionMonitored( collection ) ||
00083            isCollectionMonitored( collectionDest ) ||items.contains( item ) ||
00084            resources.contains( resource ) || isMimeTypeMonitored( mimetype ) )
00085         return true;
00086       return false;
00087     }
00088 
00089     bool isSessionIgnored( const QByteArray &sessionId ) const
00090     {
00091       return sessions.contains( sessionId );
00092     }
00093 
00094     bool connectToNotificationManager();
00095     bool acceptNotification( const NotificationMessage &msg );
00096     void dispatchNotifications();
00097     bool ensureDataAvailable( const NotificationMessage &msg );
00098     void emitNotification( const NotificationMessage &msg );
00099     void updatePendingStatistics( const NotificationMessage &msg );
00100     void invalidateCaches( const NotificationMessage &msg );
00101 
00105     void invalidateCache( const Collection &col );
00106 
00107     virtual int pipelineSize() const;
00108 
00109     // private slots
00110     void dataAvailable();
00111     void slotSessionDestroyed( QObject* );
00112     void slotStatisticsChangedFinished( KJob* );
00113     void slotFlushRecentlyChangedCollections();
00114 
00115     void appendAndCompress( const NotificationMessage &msg  );
00116 
00117     virtual void slotNotify( const NotificationMessage::List &msgs );
00118 
00119     void emitItemNotification( const NotificationMessage &msg, const Item &item = Item(),
00120                                const Collection &collection = Collection(), const Collection &collectionDest = Collection() );
00121     void emitCollectionNotification( const NotificationMessage &msg, const Collection &col = Collection(),
00122                                      const Collection &par = Collection(), const Collection &dest = Collection() );
00123 
00124 
00137     class PurgeBuffer
00138     {
00139       // Buffer the most recent 10 unreferenced Collections
00140       static const int MAXBUFFERSIZE = 10;
00141     public:
00142       explicit PurgeBuffer()
00143         : m_index( 0 ),
00144           m_bufferSize( MAXBUFFERSIZE )
00145       {
00146       }
00147 
00153       Collection::Id buffer( Collection::Id id );
00154 
00158       void purge( Collection::Id id );
00159 
00160       bool isBuffered( Collection::Id id ) const
00161       {
00162         return m_buffer.contains( id );
00163       }
00164 
00165     private:
00166       QList<Collection::Id> m_buffer;
00167       int m_index;
00168       int m_bufferSize;
00169     } m_buffer;
00170 
00171 
00172     QHash<Collection::Id, int> refCountMap;
00173     bool useRefCounting;
00174     void ref( Collection::Id id );
00175     Collection::Id deref( Collection::Id id );
00176 
00177   private:
00178     // collections that need a statistics update
00179     QSet<Collection::Id> recentlyChangedCollections;
00180 
00184     bool isLazilyIgnored( const NotificationMessage & msg ) const;
00185 
00186     bool isCollectionMonitored( Collection::Id collection ) const
00187     {
00188       if ( collections.contains( Collection( collection ) ) )
00189         return true;
00190       if ( collections.contains( Collection::root() ) )
00191         return true;
00192       return false;
00193     }
00194 
00195     bool isMimeTypeMonitored( const QString& mimetype ) const
00196     {
00197       if ( mimetypes.contains( mimetype ) )
00198         return true;
00199 
00200       KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases );
00201       if ( mimeType.isNull() )
00202         return false;
00203 
00204       foreach ( const QString &mt, mimetypes ) {
00205         if ( mimeType->is( mt ) )
00206           return true;
00207       }
00208 
00209       return false;
00210     }
00211 
00212     void fetchStatistics( Collection::Id colId )
00213     {
00214       CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), session );
00215       QObject::connect( job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotStatisticsChangedFinished(KJob*)) );
00216     }
00217 
00218     void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource )
00219     {
00220       if ( isCollectionMonitored( collection, resource ) ) {
00221         if (recentlyChangedCollections.empty() )
00222           QTimer::singleShot( 500, q_ptr, SLOT(slotFlushRecentlyChangedCollections()) );
00223         recentlyChangedCollections.insert( collection );
00224       }
00225     }
00226 };
00227 
00228 }
00229 
00230 #endif

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal