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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
monitor.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "monitor.h"
21 #include "monitor_p.h"
22 
23 #include "changemediator_p.h"
24 #include "collectionfetchscope.h"
25 #include "itemfetchjob.h"
26 #include "session.h"
27 
28 #include <kdebug.h>
29 
30 #include <QtDBus/QDBusInterface>
31 #include <QtDBus/QDBusConnection>
32 
33 #include <QtCore/QDebug>
34 #include <QtCore/QTimer>
35 #include <iterator>
36 
37 using namespace Akonadi;
38 
39 Monitor::Monitor( QObject *parent ) :
40  QObject( parent ),
41  d_ptr( new MonitorPrivate( 0, this ) )
42 {
43  d_ptr->init();
44  d_ptr->connectToNotificationManager();
45 }
46 
47 //@cond PRIVATE
48 Monitor::Monitor(MonitorPrivate * d, QObject *parent) :
49  QObject( parent ),
50  d_ptr( d )
51 {
52  d_ptr->init();
53  d_ptr->connectToNotificationManager();
54 
55  ChangeMediator::registerMonitor(this);
56 }
57 //@endcond
58 
59 Monitor::~Monitor()
60 {
61  ChangeMediator::unregisterMonitor(this);
62 
63  delete d_ptr;
64 }
65 
66 void Monitor::setCollectionMonitored( const Collection &collection, bool monitored )
67 {
68  Q_D( Monitor );
69  if ( !d->collections.contains( collection ) && monitored ) {
70  d->collections << collection;
71  if ( d->notificationSource ) {
72  d->notificationSource->setMonitoredCollection( collection.id(), true );
73  }
74  } else if ( !monitored ) {
75  if ( d->collections.removeAll( collection ) ) {
76  d->cleanOldNotifications();
77  if ( d->notificationSource ) {
78  d->notificationSource->setMonitoredCollection( collection.id(), false );
79  }
80  }
81  }
82 
83  emit collectionMonitored( collection, monitored );
84 }
85 
86 void Monitor::setItemMonitored( const Item &item, bool monitored )
87 {
88  Q_D( Monitor );
89  if ( !d->items.contains( item.id() ) && monitored ) {
90  d->items.insert( item.id() );
91  if ( d->notificationSource ) {
92  d->notificationSource->setMonitoredItem( item.id(), true );
93  }
94  } else if ( !monitored ) {
95  if ( d->items.remove( item.id() ) ) {
96  d->cleanOldNotifications();
97  if ( d->notificationSource ) {
98  d->notificationSource->setMonitoredItem( item.id(), false );
99  }
100  }
101  }
102 
103  emit itemMonitored( item, monitored );
104 }
105 
106 void Monitor::setResourceMonitored( const QByteArray &resource, bool monitored )
107 {
108  Q_D( Monitor );
109  if ( !d->resources.contains( resource) && monitored ) {
110  d->resources.insert( resource );
111  if ( d->notificationSource ) {
112  d->notificationSource->setMonitoredResource( resource, true );
113  }
114  } else if ( !monitored ) {
115  if ( d->resources.remove( resource ) ) {
116  d->cleanOldNotifications();
117  if ( d->notificationSource ) {
118  d->notificationSource->setMonitoredResource( resource, false );
119  }
120  }
121  }
122 
123  emit resourceMonitored( resource, monitored );
124 }
125 
126 void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored )
127 {
128  Q_D( Monitor );
129  if ( !d->mimetypes.contains( mimetype ) && monitored ) {
130  d->mimetypes.insert( mimetype );
131  if ( d->notificationSource ) {
132  d->notificationSource->setMonitoredMimeType( mimetype, true );
133  }
134  } else if ( !monitored ) {
135  if ( d->mimetypes.remove( mimetype ) ) {
136  d->cleanOldNotifications();
137  if ( d->notificationSource ) {
138  d->notificationSource->setMonitoredMimeType( mimetype, false );
139  }
140  }
141  }
142 
143  emit mimeTypeMonitored( mimetype, monitored );
144 }
145 
146 void Akonadi::Monitor::setAllMonitored( bool monitored )
147 {
148  Q_D( Monitor );
149  if ( d->monitorAll == monitored ) {
150  return;
151  }
152 
153  d->monitorAll = monitored;
154 
155  if ( !monitored ) {
156  d->cleanOldNotifications();
157  }
158 
159  if ( d->notificationSource ) {
160  d->notificationSource->setAllMonitored( monitored );
161  }
162 
163  emit allMonitored( monitored );
164 }
165 
166 void Monitor::ignoreSession( Session * session )
167 {
168  Q_D( Monitor );
169 
170  if ( !d->sessions.contains( session->sessionId() )) {
171  d->sessions << session->sessionId();
172  connect( session, SIGNAL(destroyed(QObject*)), this, SLOT(slotSessionDestroyed(QObject*)) );
173  if ( d->notificationSource ) {
174  d->notificationSource->setIgnoredSession( session->sessionId(), true );
175  }
176  }
177 }
178 
179 void Monitor::fetchCollection( bool enable )
180 {
181  Q_D( Monitor );
182  d->fetchCollection = enable;
183 }
184 
185 void Monitor::fetchCollectionStatistics( bool enable )
186 {
187  Q_D( Monitor );
188  d->fetchCollectionStatistics = enable;
189 }
190 
191 void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope )
192 {
193  Q_D( Monitor );
194  d->mItemFetchScope = fetchScope;
195 }
196 
197 ItemFetchScope &Monitor::itemFetchScope()
198 {
199  Q_D( Monitor );
200  return d->mItemFetchScope;
201 }
202 
203 void Monitor::fetchChangedOnly( bool enable )
204 {
205  Q_D( Monitor );
206  d->mFetchChangedOnly = enable;
207 }
208 
209 void Monitor::setCollectionFetchScope( const CollectionFetchScope &fetchScope )
210 {
211  Q_D( Monitor );
212  d->mCollectionFetchScope = fetchScope;
213 }
214 
215 CollectionFetchScope& Monitor::collectionFetchScope()
216 {
217  Q_D( Monitor );
218  return d->mCollectionFetchScope;
219 }
220 
221 Akonadi::Collection::List Monitor::collectionsMonitored() const
222 {
223  Q_D( const Monitor );
224  return d->collections;
225 }
226 
227 QList<Item::Id> Monitor::itemsMonitored() const
228 {
229  Q_D( const Monitor );
230  return d->items.toList();
231 }
232 
233 QVector<Item::Id> Monitor::itemsMonitoredEx() const
234 {
235  Q_D( const Monitor );
236  QVector<Item::Id> result;
237  result.reserve( d->items.size() );
238  qCopy( d->items.begin(), d->items.end(), std::back_inserter( result ) );
239  return result;
240 }
241 
242 QStringList Monitor::mimeTypesMonitored() const
243 {
244  Q_D( const Monitor );
245  return d->mimetypes.toList();
246 }
247 
248 QList<QByteArray> Monitor::resourcesMonitored() const
249 {
250  Q_D( const Monitor );
251  return d->resources.toList();
252 }
253 
254 bool Monitor::isAllMonitored() const
255 {
256  Q_D( const Monitor );
257  return d->monitorAll;
258 }
259 
260 void Monitor::setSession( Akonadi::Session *session )
261 {
262  Q_D( Monitor );
263  if (session == d->session)
264  return;
265 
266  if (!session)
267  d->session = Session::defaultSession();
268  else
269  d->session = session;
270 
271  d->itemCache->setSession(d->session);
272  d->collectionCache->setSession(d->session);
273 }
274 
275 Session* Monitor::session() const
276 {
277  Q_D( const Monitor );
278  return d->session;
279 }
280 
281 void Monitor::setCollectionMoveTranslationEnabled( bool enabled )
282 {
283  Q_D( Monitor );
284  d->collectionMoveTranslationEnabled = enabled;
285 }
286 
287 #include "moc_monitor.cpp"
Akonadi::Monitor::setAllMonitored
void setAllMonitored(bool monitored=true)
Sets whether all items shall be monitored.
Definition: monitor.cpp:146
Akonadi::Monitor::fetchCollectionStatistics
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage...
Definition: monitor.cpp:185
Akonadi::Monitor::mimeTypesMonitored
QStringList mimeTypesMonitored() const
Returns the set of mimetypes being monitored.
Definition: monitor.cpp:242
Akonadi::Monitor::resourcesMonitored
QList< QByteArray > resourcesMonitored() const
Returns the set of identifiers for resources being monitored.
Definition: monitor.cpp:248
Akonadi::Monitor::session
Session * session() const
Returns the Session used by the monitor to communicate with Akonadi.
Definition: monitor.cpp:275
Akonadi::Monitor::collectionMonitored
void collectionMonitored(const Akonadi::Collection &collection, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring collection explicitly.
Akonadi::CollectionFetchScope
Specifies which parts of a collection should be fetched from the Akonadi storage. ...
Definition: collectionfetchscope.h:68
Akonadi::Monitor::setSession
void setSession(Akonadi::Session *session)
Sets the session used by the Monitor to communicate with the Akonadi server.
Definition: monitor.cpp:260
Akonadi::Monitor::setMimeTypeMonitored
void setMimeTypeMonitored(const QString &mimetype, bool monitored=true)
Sets whether items of the specified mime type shall be monitored for changes.
Definition: monitor.cpp:126
Akonadi::Monitor::setCollectionMonitored
void setCollectionMonitored(const Collection &collection, bool monitored=true)
Sets whether the specified collection shall be monitored for changes.
Definition: monitor.cpp:66
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Monitor::mimeTypeMonitored
void mimeTypeMonitored(const QString &mimeType, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring mimeType explicitly.
Akonadi::Monitor::setItemFetchScope
void setItemFetchScope(const ItemFetchScope &fetchScope)
Sets the item fetch scope.
Definition: monitor.cpp:191
Akonadi::Monitor::ignoreSession
void ignoreSession(Session *session)
Ignores all change notifications caused by the given session.
Definition: monitor.cpp:166
Akonadi::Monitor::~Monitor
virtual ~Monitor()
Destroys the monitor.
Definition: monitor.cpp:59
Akonadi::Session::defaultSession
static Session * defaultSession()
Returns the default session for this thread.
Definition: session.cpp:444
Akonadi::Session::sessionId
QByteArray sessionId() const
Returns the session identifier.
Definition: session.cpp:422
Akonadi::Monitor::itemFetchScope
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition: monitor.cpp:197
Akonadi::Monitor::collectionsMonitored
Collection::List collectionsMonitored() const
Returns the list of collections being monitored.
Definition: monitor.cpp:221
Akonadi::Monitor::resourceMonitored
void resourceMonitored(const QByteArray &identifier, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring the resource with the identifier ide...
Akonadi::Monitor::collectionFetchScope
CollectionFetchScope & collectionFetchScope()
Returns the collection fetch scope.
Definition: monitor.cpp:215
Akonadi::Monitor::setCollectionFetchScope
void setCollectionFetchScope(const CollectionFetchScope &fetchScope)
Sets the collection fetch scope.
Definition: monitor.cpp:209
Akonadi::Session
A communication session with the Akonadi storage.
Definition: session.h:59
Akonadi::Monitor::Monitor
Monitor(QObject *parent=0)
Creates a new monitor.
Definition: monitor.cpp:39
Akonadi::Monitor::fetchCollection
void fetchCollection(bool enable)
Enables automatic fetching of changed collections from the Akonadi storage.
Definition: monitor.cpp:179
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::Monitor::isAllMonitored
bool isAllMonitored() const
Returns true if everything is being monitored.
Definition: monitor.cpp:254
Akonadi::Monitor::setCollectionMoveTranslationEnabled
void setCollectionMoveTranslationEnabled(bool enabled)
Allows to enable/disable collection move translation.
Definition: monitor.cpp:281
Akonadi::ItemFetchScope
Specifies which parts of an item should be fetched from the Akonadi storage.
Definition: itemfetchscope.h:68
Akonadi::Monitor::setResourceMonitored
void setResourceMonitored(const QByteArray &resource, bool monitored=true)
Sets whether the specified resource shall be monitored for changes.
Definition: monitor.cpp:106
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:72
Akonadi::MonitorPrivate
Definition: monitor_p.h:49
Akonadi::Monitor::itemsMonitoredEx
QVector< Item::Id > itemsMonitoredEx() const
Returns the set of items being monitored.
Definition: monitor.cpp:233
Akonadi::Monitor::itemMonitored
void itemMonitored(const Akonadi::Item &item, bool monitored)
This signal is emitted if the Monitor starts or stops monitoring item explicitly. ...
Akonadi::Monitor::setItemMonitored
void setItemMonitored(const Item &item, bool monitored=true)
Sets whether the specified item shall be monitored for changes.
Definition: monitor.cpp:86
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::Monitor::fetchChangedOnly
void fetchChangedOnly(bool enable)
Instructs the monitor to fetch only those parts that were changed and were requested in the fetch sco...
Definition: monitor.cpp:203
Akonadi::Monitor::itemsMonitored
AKONADI_DEPRECATED QList< Item::Id > itemsMonitored() const
Returns the set of items being monitored.
Definition: monitor.cpp:227
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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