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

akonadi

  • 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  // :TODO: Unsubscribe from the notification manager. That means having some kind of reference
64  // counting on the server side.
65  delete d_ptr;
66 }
67 
68 void Monitor::setCollectionMonitored( const Collection &collection, bool monitored )
69 {
70  Q_D( Monitor );
71  if ( monitored ) {
72  d->collections << collection;
73  } else {
74  d->collections.removeAll( collection );
75  d->cleanOldNotifications();
76  }
77  emit collectionMonitored( collection, monitored );
78 }
79 
80 void Monitor::setItemMonitored( const Item & item, bool monitored )
81 {
82  Q_D( Monitor );
83  if ( monitored ) {
84  d->items.insert( item.id() );
85  } else {
86  d->items.remove( item.id() );
87  d->cleanOldNotifications();
88  }
89  emit itemMonitored( item, monitored );
90 }
91 
92 void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored )
93 {
94  Q_D( Monitor );
95  if ( monitored ) {
96  d->resources.insert( resource );
97  } else {
98  d->resources.remove( resource );
99  d->cleanOldNotifications();
100  }
101  emit resourceMonitored( resource, monitored );
102 }
103 
104 void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored )
105 {
106  Q_D( Monitor );
107  if ( monitored ) {
108  d->mimetypes.insert( mimetype );
109  } else {
110  d->mimetypes.remove( mimetype );
111  d->cleanOldNotifications();
112  }
113 
114  emit mimeTypeMonitored( mimetype, monitored );
115 }
116 
117 void Akonadi::Monitor::setAllMonitored( bool monitored )
118 {
119  Q_D( Monitor );
120  d->monitorAll = monitored;
121 
122  if ( !monitored ) {
123  d->cleanOldNotifications();
124  }
125 
126  emit allMonitored( monitored );
127 }
128 
129 void Monitor::ignoreSession(Session * session)
130 {
131  Q_D( Monitor );
132  d->sessions << session->sessionId();
133  connect( session, SIGNAL(destroyed(QObject*)), this, SLOT(slotSessionDestroyed(QObject*)) );
134 }
135 
136 void Monitor::fetchCollection(bool enable)
137 {
138  Q_D( Monitor );
139  d->fetchCollection = enable;
140 }
141 
142 void Monitor::fetchCollectionStatistics(bool enable)
143 {
144  Q_D( Monitor );
145  d->fetchCollectionStatistics = enable;
146 }
147 
148 void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope )
149 {
150  Q_D( Monitor );
151  d->mItemFetchScope = fetchScope;
152 }
153 
154 ItemFetchScope &Monitor::itemFetchScope()
155 {
156  Q_D( Monitor );
157  return d->mItemFetchScope;
158 }
159 
160 void Monitor::fetchChangedOnly( bool enable )
161 {
162  Q_D( Monitor );
163  d->mFetchChangedOnly = enable;
164 }
165 
166 
167 void Monitor::setCollectionFetchScope( const CollectionFetchScope &fetchScope )
168 {
169  Q_D( Monitor );
170  d->mCollectionFetchScope = fetchScope;
171 }
172 
173 CollectionFetchScope& Monitor::collectionFetchScope()
174 {
175  Q_D( Monitor );
176  return d->mCollectionFetchScope;
177 }
178 
179 Akonadi::Collection::List Monitor::collectionsMonitored() const
180 {
181  Q_D( const Monitor );
182  return d->collections;
183 }
184 
185 QList<Item::Id> Monitor::itemsMonitored() const
186 {
187  Q_D( const Monitor );
188  return d->items.toList();
189 }
190 
191 QVector<Item::Id> Monitor::itemsMonitoredEx() const
192 {
193  Q_D( const Monitor );
194  QVector<Item::Id> result;
195  result.reserve( d->items.size() );
196  qCopy( d->items.begin(), d->items.end(), std::back_inserter( result ) );
197  return result;
198 }
199 
200 QStringList Monitor::mimeTypesMonitored() const
201 {
202  Q_D( const Monitor );
203  return d->mimetypes.toList();
204 }
205 
206 QList<QByteArray> Monitor::resourcesMonitored() const
207 {
208  Q_D( const Monitor );
209  return d->resources.toList();
210 }
211 
212 bool Monitor::isAllMonitored() const
213 {
214  Q_D( const Monitor );
215  return d->monitorAll;
216 }
217 
218 void Monitor::setSession( Akonadi::Session *session )
219 {
220  Q_D( Monitor );
221  if (session == d->session)
222  return;
223 
224  if (!session)
225  d->session = Session::defaultSession();
226  else
227  d->session = session;
228 
229  d->itemCache->setSession(d->session);
230  d->collectionCache->setSession(d->session);
231 }
232 
233 Session* Monitor::session() const
234 {
235  Q_D( const Monitor );
236  return d->session;
237 }
238 
239 void Monitor::setCollectionMoveTranslationEnabled( bool enabled )
240 {
241  Q_D( Monitor );
242  d->collectionMoveTranslationEnabled = enabled;
243 }
244 
245 #include "moc_monitor.cpp"
Akonadi::Monitor::setAllMonitored
void setAllMonitored(bool monitored=true)
Sets whether all items shall be monitored.
Definition: monitor.cpp:117
Akonadi::Monitor::fetchCollectionStatistics
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage...
Definition: monitor.cpp:142
Akonadi::Monitor::mimeTypesMonitored
QStringList mimeTypesMonitored() const
Returns the set of mimetypes being monitored.
Definition: monitor.cpp:200
Akonadi::Monitor::resourcesMonitored
QList< QByteArray > resourcesMonitored() const
Returns the set of identifiers for resources being monitored.
Definition: monitor.cpp:206
Akonadi::Monitor::session
Session * session() const
Returns the Session used by the monitor to communicate with Akonadi.
Definition: monitor.cpp:233
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:218
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:104
Akonadi::Monitor::setCollectionMonitored
void setCollectionMonitored(const Collection &collection, bool monitored=true)
Sets whether the specified collection shall be monitored for changes.
Definition: monitor.cpp:68
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:148
Akonadi::Monitor::ignoreSession
void ignoreSession(Session *session)
Ignores all change notifications caused by the given session.
Definition: monitor.cpp:129
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:447
Akonadi::Session::sessionId
QByteArray sessionId() const
Returns the session identifier.
Definition: session.cpp:425
Akonadi::Monitor::itemFetchScope
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition: monitor.cpp:154
Akonadi::Monitor::collectionsMonitored
Collection::List collectionsMonitored() const
Returns the list of collections being monitored.
Definition: monitor.cpp:179
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:173
Akonadi::Monitor::setCollectionFetchScope
void setCollectionFetchScope(const CollectionFetchScope &fetchScope)
Sets the collection fetch scope.
Definition: monitor.cpp:167
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:136
Akonadi::Monitor::isAllMonitored
bool isAllMonitored() const
Returns true if everything is being monitored.
Definition: monitor.cpp:212
Akonadi::Monitor::setCollectionMoveTranslationEnabled
void setCollectionMoveTranslationEnabled(bool enabled)
Allows to enable/disable collection move translation.
Definition: monitor.cpp:239
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:92
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:191
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:80
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:160
Akonadi::Monitor::itemsMonitored
QList< Item::Id > itemsMonitored() const
Returns the set of items being monitored.
Definition: monitor.cpp:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:18 by doxygen 1.8.5 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-4.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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