akonadi
monitor.cpp
00001 /* 00002 Copyright (c) 2006 - 2007 Volker Krause <vkrause@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 #include "monitor.h" 00021 #include "monitor_p.h" 00022 00023 #include "changemediator_p.h" 00024 #include "collectionfetchscope.h" 00025 #include "itemfetchjob.h" 00026 #include "notificationmessage_p.h" 00027 #include "session.h" 00028 00029 #include <kdebug.h> 00030 00031 #include <QtDBus/QDBusInterface> 00032 #include <QtDBus/QDBusConnection> 00033 00034 #include <QtCore/QDebug> 00035 #include <QtCore/QTimer> 00036 #include <iterator> 00037 00038 using namespace Akonadi; 00039 00040 Monitor::Monitor( QObject *parent ) : 00041 QObject( parent ), 00042 d_ptr( new MonitorPrivate( 0, this ) ) 00043 { 00044 d_ptr->init(); 00045 d_ptr->connectToNotificationManager(); 00046 } 00047 00048 //@cond PRIVATE 00049 Monitor::Monitor(MonitorPrivate * d, QObject *parent) : 00050 QObject( parent ), 00051 d_ptr( d ) 00052 { 00053 d_ptr->init(); 00054 d_ptr->connectToNotificationManager(); 00055 00056 ChangeMediator::registerMonitor(this); 00057 } 00058 //@endcond 00059 00060 Monitor::~Monitor() 00061 { 00062 ChangeMediator::unregisterMonitor(this); 00063 00064 // :TODO: Unsubscribe from the notification manager. That means having some kind of reference 00065 // counting on the server side. 00066 delete d_ptr; 00067 } 00068 00069 void Monitor::setCollectionMonitored( const Collection &collection, bool monitored ) 00070 { 00071 Q_D( Monitor ); 00072 if ( monitored ) { 00073 d->collections << collection; 00074 } else { 00075 d->collections.removeAll( collection ); 00076 d->cleanOldNotifications(); 00077 } 00078 emit collectionMonitored( collection, monitored ); 00079 } 00080 00081 void Monitor::setItemMonitored( const Item & item, bool monitored ) 00082 { 00083 Q_D( Monitor ); 00084 if ( monitored ) { 00085 d->items.insert( item.id() ); 00086 } else { 00087 d->items.remove( item.id() ); 00088 d->cleanOldNotifications(); 00089 } 00090 emit itemMonitored( item, monitored ); 00091 } 00092 00093 void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored ) 00094 { 00095 Q_D( Monitor ); 00096 if ( monitored ) { 00097 d->resources.insert( resource ); 00098 } else { 00099 d->resources.remove( resource ); 00100 d->cleanOldNotifications(); 00101 } 00102 emit resourceMonitored( resource, monitored ); 00103 } 00104 00105 void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored ) 00106 { 00107 Q_D( Monitor ); 00108 if ( monitored ) { 00109 d->mimetypes.insert( mimetype ); 00110 } else { 00111 d->mimetypes.remove( mimetype ); 00112 d->cleanOldNotifications(); 00113 } 00114 00115 emit mimeTypeMonitored( mimetype, monitored ); 00116 } 00117 00118 void Akonadi::Monitor::setAllMonitored( bool monitored ) 00119 { 00120 Q_D( Monitor ); 00121 d->monitorAll = monitored; 00122 00123 if ( !monitored ) { 00124 d->cleanOldNotifications(); 00125 } 00126 00127 emit allMonitored( monitored ); 00128 } 00129 00130 void Monitor::ignoreSession(Session * session) 00131 { 00132 Q_D( Monitor ); 00133 d->sessions << session->sessionId(); 00134 connect( session, SIGNAL(destroyed(QObject*)), this, SLOT(slotSessionDestroyed(QObject*)) ); 00135 } 00136 00137 void Monitor::fetchCollection(bool enable) 00138 { 00139 Q_D( Monitor ); 00140 d->fetchCollection = enable; 00141 } 00142 00143 void Monitor::fetchCollectionStatistics(bool enable) 00144 { 00145 Q_D( Monitor ); 00146 d->fetchCollectionStatistics = enable; 00147 } 00148 00149 void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope ) 00150 { 00151 Q_D( Monitor ); 00152 d->mItemFetchScope = fetchScope; 00153 } 00154 00155 ItemFetchScope &Monitor::itemFetchScope() 00156 { 00157 Q_D( Monitor ); 00158 return d->mItemFetchScope; 00159 } 00160 00161 void Monitor::fetchChangedOnly( bool enable ) 00162 { 00163 Q_D( Monitor ); 00164 d->mFetchChangedOnly = enable; 00165 } 00166 00167 00168 void Monitor::setCollectionFetchScope( const CollectionFetchScope &fetchScope ) 00169 { 00170 Q_D( Monitor ); 00171 d->mCollectionFetchScope = fetchScope; 00172 } 00173 00174 CollectionFetchScope& Monitor::collectionFetchScope() 00175 { 00176 Q_D( Monitor ); 00177 return d->mCollectionFetchScope; 00178 } 00179 00180 Akonadi::Collection::List Monitor::collectionsMonitored() const 00181 { 00182 Q_D( const Monitor ); 00183 return d->collections; 00184 } 00185 00186 QList<Item::Id> Monitor::itemsMonitored() const 00187 { 00188 Q_D( const Monitor ); 00189 return d->items.toList(); 00190 } 00191 00192 QVector<Item::Id> Monitor::itemsMonitoredEx() const 00193 { 00194 Q_D( const Monitor ); 00195 QVector<Item::Id> result; 00196 result.reserve( d->items.size() ); 00197 qCopy( d->items.begin(), d->items.end(), std::back_inserter( result ) ); 00198 return result; 00199 } 00200 00201 QStringList Monitor::mimeTypesMonitored() const 00202 { 00203 Q_D( const Monitor ); 00204 return d->mimetypes.toList(); 00205 } 00206 00207 QList<QByteArray> Monitor::resourcesMonitored() const 00208 { 00209 Q_D( const Monitor ); 00210 return d->resources.toList(); 00211 } 00212 00213 bool Monitor::isAllMonitored() const 00214 { 00215 Q_D( const Monitor ); 00216 return d->monitorAll; 00217 } 00218 00219 void Monitor::setSession( Akonadi::Session *session ) 00220 { 00221 Q_D( Monitor ); 00222 if (session == d->session) 00223 return; 00224 00225 if (!session) 00226 d->session = Session::defaultSession(); 00227 else 00228 d->session = session; 00229 00230 d->itemCache->setSession(d->session); 00231 d->collectionCache->setSession(d->session); 00232 } 00233 00234 Session* Monitor::session() const 00235 { 00236 Q_D( const Monitor ); 00237 return d->session; 00238 } 00239 00240 #include "monitor.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.