00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "monitor.h"
00021 #include "monitor_p.h"
00022
00023 #include "itemfetchjob.h"
00024 #include "notificationmessage_p.h"
00025 #include "session.h"
00026
00027 #include <kdebug.h>
00028
00029 #include <QtDBus/QDBusInterface>
00030 #include <QtDBus/QDBusConnection>
00031
00032 #include <QtCore/QDebug>
00033 #include <QtCore/QTimer>
00034 #include "collectionfetchscope.h"
00035
00036 using namespace Akonadi;
00037
00038 #define d d_ptr
00039
00040 Monitor::Monitor( QObject *parent ) :
00041 QObject( parent ),
00042 d_ptr( new MonitorPrivate( this ) )
00043 {
00044 d_ptr->init();
00045 d_ptr->connectToNotificationManager();
00046 }
00047
00048
00049 Monitor::Monitor(MonitorPrivate * d, QObject *parent) :
00050 QObject( parent ),
00051 d_ptr( d )
00052 {
00053 }
00054
00055
00056 Monitor::~Monitor()
00057 {
00058 delete d;
00059 }
00060
00061 void Monitor::setCollectionMonitored( const Collection &collection, bool monitored )
00062 {
00063 if ( monitored ) {
00064 d->collections << collection;
00065 } else {
00066 d->collections.removeAll( collection );
00067 d->cleanOldNotifications();
00068 }
00069 emit collectionMonitored( collection, monitored );
00070 }
00071
00072 void Monitor::setItemMonitored( const Item & item, bool monitored )
00073 {
00074 if ( monitored ) {
00075 d->items.insert( item.id() );
00076 } else {
00077 d->items.remove( item.id() );
00078 d->cleanOldNotifications();
00079 }
00080 emit itemMonitored( item, monitored );
00081 }
00082
00083 void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored )
00084 {
00085 if ( monitored ) {
00086 d->resources.insert( resource );
00087 } else {
00088 d->resources.remove( resource );
00089 d->cleanOldNotifications();
00090 }
00091 emit resourceMonitored( resource, monitored );
00092 }
00093
00094 void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored )
00095 {
00096 if ( monitored ) {
00097 d->mimetypes.insert( mimetype );
00098 } else {
00099 d->mimetypes.remove( mimetype );
00100 d->cleanOldNotifications();
00101 }
00102
00103 emit mimeTypeMonitored( mimetype, monitored );
00104 }
00105
00106 void Akonadi::Monitor::setAllMonitored( bool monitored )
00107 {
00108 d->monitorAll = monitored;
00109
00110 if ( !monitored ) {
00111 d->cleanOldNotifications();
00112 }
00113
00114 emit allMonitored( monitored );
00115 }
00116
00117 void Monitor::ignoreSession(Session * session)
00118 {
00119 d->sessions << session->sessionId();
00120 connect( session, SIGNAL( destroyed( QObject* ) ), this, SLOT( slotSessionDestroyed( QObject* ) ) );
00121 }
00122
00123 void Monitor::fetchCollection(bool enable)
00124 {
00125 d->fetchCollection = enable;
00126 }
00127
00128 void Monitor::fetchCollectionStatistics(bool enable)
00129 {
00130 d->fetchCollectionStatistics = enable;
00131 }
00132
00133 void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope )
00134 {
00135 d->mItemFetchScope = fetchScope;
00136 }
00137
00138 ItemFetchScope &Monitor::itemFetchScope()
00139 {
00140 return d->mItemFetchScope;
00141 }
00142
00143 void Monitor::setCollectionFetchScope( const CollectionFetchScope &fetchScope )
00144 {
00145 d->mCollectionFetchScope = fetchScope;
00146 }
00147
00148 CollectionFetchScope& Monitor::collectionFetchScope()
00149 {
00150 return d->mCollectionFetchScope;
00151 }
00152
00153 Collection::List Monitor::collectionsMonitored() const
00154 {
00155 return d->collections;
00156 }
00157
00158 QList<Item::Id> Monitor::itemsMonitored() const
00159 {
00160 return d->items.toList();
00161 }
00162
00163 QStringList Monitor::mimeTypesMonitored() const
00164 {
00165 return d->mimetypes.toList();
00166 }
00167
00168 QList<QByteArray> Monitor::resourcesMonitored() const
00169 {
00170 return d->resources.toList();
00171 }
00172
00173 bool Monitor::isAllMonitored() const
00174 {
00175 return d->monitorAll;
00176 }
00177
00178 void Monitor::setSession( Akonadi::Session *session )
00179 {
00180 if (session == d->session)
00181 return;
00182
00183 if (!session)
00184 d->session = Session::defaultSession();
00185 else
00186 d->session = session;
00187
00188 d->itemCache.setSession(d->session);
00189 d->collectionCache.setSession(d->session);
00190 }
00191
00192 Session* Monitor::session() const
00193 {
00194 return d->session;
00195 }
00196
00197 #undef d
00198
00199 #include "monitor.moc"