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 #include <iterator>
00036
00037 using namespace Akonadi;
00038
00039 Monitor::Monitor( QObject *parent ) :
00040 QObject( parent ),
00041 d_ptr( new MonitorPrivate( this ) )
00042 {
00043 d_ptr->init();
00044 d_ptr->connectToNotificationManager();
00045 }
00046
00047
00048 Monitor::Monitor(MonitorPrivate * d, QObject *parent) :
00049 QObject( parent ),
00050 d_ptr( d )
00051 {
00052 d_ptr->init();
00053 d_ptr->connectToNotificationManager();
00054 }
00055
00056
00057 Monitor::~Monitor()
00058 {
00059
00060
00061 delete d_ptr;
00062 }
00063
00064 void Monitor::setCollectionMonitored( const Collection &collection, bool monitored )
00065 {
00066 Q_D( Monitor );
00067 if ( monitored ) {
00068 d->collections << collection;
00069 } else {
00070 d->collections.removeAll( collection );
00071 d->cleanOldNotifications();
00072 }
00073 emit collectionMonitored( collection, monitored );
00074 }
00075
00076 void Monitor::setItemMonitored( const Item & item, bool monitored )
00077 {
00078 Q_D( Monitor );
00079 if ( monitored ) {
00080 d->items.insert( item.id() );
00081 } else {
00082 d->items.remove( item.id() );
00083 d->cleanOldNotifications();
00084 }
00085 emit itemMonitored( item, monitored );
00086 }
00087
00088 void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored )
00089 {
00090 Q_D( Monitor );
00091 if ( monitored ) {
00092 d->resources.insert( resource );
00093 } else {
00094 d->resources.remove( resource );
00095 d->cleanOldNotifications();
00096 }
00097 emit resourceMonitored( resource, monitored );
00098 }
00099
00100 void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored )
00101 {
00102 Q_D( Monitor );
00103 if ( monitored ) {
00104 d->mimetypes.insert( mimetype );
00105 } else {
00106 d->mimetypes.remove( mimetype );
00107 d->cleanOldNotifications();
00108 }
00109
00110 emit mimeTypeMonitored( mimetype, monitored );
00111 }
00112
00113 void Akonadi::Monitor::setAllMonitored( bool monitored )
00114 {
00115 Q_D( Monitor );
00116 d->monitorAll = monitored;
00117
00118 if ( !monitored ) {
00119 d->cleanOldNotifications();
00120 }
00121
00122 emit allMonitored( monitored );
00123 }
00124
00125 void Monitor::ignoreSession(Session * session)
00126 {
00127 Q_D( Monitor );
00128 d->sessions << session->sessionId();
00129 connect( session, SIGNAL( destroyed( QObject* ) ), this, SLOT( slotSessionDestroyed( QObject* ) ) );
00130 }
00131
00132 void Monitor::fetchCollection(bool enable)
00133 {
00134 Q_D( Monitor );
00135 d->fetchCollection = enable;
00136 }
00137
00138 void Monitor::fetchCollectionStatistics(bool enable)
00139 {
00140 Q_D( Monitor );
00141 d->fetchCollectionStatistics = enable;
00142 }
00143
00144 void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope )
00145 {
00146 Q_D( Monitor );
00147 d->mItemFetchScope = fetchScope;
00148 }
00149
00150 ItemFetchScope &Monitor::itemFetchScope()
00151 {
00152 Q_D( Monitor );
00153 return d->mItemFetchScope;
00154 }
00155
00156 void Monitor::setCollectionFetchScope( const CollectionFetchScope &fetchScope )
00157 {
00158 Q_D( Monitor );
00159 d->mCollectionFetchScope = fetchScope;
00160 }
00161
00162 CollectionFetchScope& Monitor::collectionFetchScope()
00163 {
00164 Q_D( Monitor );
00165 return d->mCollectionFetchScope;
00166 }
00167
00168 Akonadi::Collection::List Monitor::collectionsMonitored() const
00169 {
00170 Q_D( const Monitor );
00171 return d->collections;
00172 }
00173
00174 QList<Item::Id> Monitor::itemsMonitored() const
00175 {
00176 Q_D( const Monitor );
00177 return d->items.toList();
00178 }
00179
00180 QVector<Item::Id> Monitor::itemsMonitoredEx() const
00181 {
00182 Q_D( const Monitor );
00183 QVector<Item::Id> result;
00184 result.reserve( d->items.size() );
00185 qCopy( d->items.begin(), d->items.end(), std::back_inserter( result ) );
00186 return result;
00187 }
00188
00189 QStringList Monitor::mimeTypesMonitored() const
00190 {
00191 Q_D( const Monitor );
00192 return d->mimetypes.toList();
00193 }
00194
00195 QList<QByteArray> Monitor::resourcesMonitored() const
00196 {
00197 Q_D( const Monitor );
00198 return d->resources.toList();
00199 }
00200
00201 bool Monitor::isAllMonitored() const
00202 {
00203 Q_D( const Monitor );
00204 return d->monitorAll;
00205 }
00206
00207 void Monitor::setSession( Akonadi::Session *session )
00208 {
00209 Q_D( Monitor );
00210 if (session == d->session)
00211 return;
00212
00213 if (!session)
00214 d->session = Session::defaultSession();
00215 else
00216 d->session = session;
00217
00218 d->itemCache.setSession(d->session);
00219 d->collectionCache.setSession(d->session);
00220 }
00221
00222 Session* Monitor::session() const
00223 {
00224 Q_D( const Monitor );
00225 return d->session;
00226 }
00227
00228 #include "monitor.moc"