• 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
changerecorder.cpp
1 /*
2  Copyright (c) 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 "changerecorder.h"
21 #include "changerecorder_p.h"
22 
23 #include <kdebug.h>
24 #include <QtCore/QSettings>
25 
26 using namespace Akonadi;
27 
28 ChangeRecorder::ChangeRecorder( QObject * parent ) :
29  Monitor( new ChangeRecorderPrivate( 0, this ), parent )
30 {
31 }
32 
33 ChangeRecorder::ChangeRecorder( ChangeRecorderPrivate *privateclass, QObject * parent ) :
34  Monitor( privateclass, parent )
35 {
36 }
37 
38 ChangeRecorder::~ChangeRecorder()
39 {
40 }
41 
42 void ChangeRecorder::setConfig(QSettings * settings)
43 {
44  Q_D( ChangeRecorder );
45  if ( settings ) {
46  d->settings = settings;
47  Q_ASSERT( d->pendingNotifications.isEmpty() );
48  d->loadNotifications();
49  } else if ( d->settings ) {
50  if ( d->enableChangeRecording )
51  d->saveNotifications();
52  d->settings = settings;
53  }
54 }
55 
56 void ChangeRecorder::replayNext()
57 {
58  Q_D( ChangeRecorder );
59 
60  if ( !d->enableChangeRecording )
61  return;
62 
63  if ( !d->pendingNotifications.isEmpty() ) {
64  const NotificationMessageV2 msg = d->pendingNotifications.head();
65  if ( d->ensureDataAvailable( msg ) ) {
66  d->emitNotification( msg );
67  } else if ( d->translateAndCompress( d->pipeline, msg ) ) {
68  // The msg is now in both pipeline and pendingNotifications.
69  // When data is available, MonitorPrivate::flushPipeline will emitNotification.
70  // When changeProcessed is called, we'll finally remove it from pendingNotifications.
71  } else {
72  // In the case of a move where both source and destination are
73  // ignored, we ignore the message and process the next one.
74  d->dequeueNotification();
75  return replayNext();
76  }
77  } else {
78  // This is necessary when none of the notifications were accepted / processed
79  // above, and so there is no one to call changeProcessed() and the ChangeReplay task
80  // will be stuck forever in the ResourceScheduler.
81  emit nothingToReplay();
82  }
83 }
84 
85 bool ChangeRecorder::isEmpty() const
86 {
87  Q_D( const ChangeRecorder );
88  return d->pendingNotifications.isEmpty();
89 }
90 
91 void ChangeRecorder::changeProcessed()
92 {
93  Q_D( ChangeRecorder );
94 
95  if ( !d->enableChangeRecording )
96  return;
97 
98  // changerecordertest.cpp calls changeProcessed after receiving nothingToReplay,
99  // so test for emptiness. Not sure real code does this though.
100  // Q_ASSERT( !d->pendingNotifications.isEmpty() )
101  if ( !d->pendingNotifications.isEmpty() )
102  d->dequeueNotification();
103 }
104 
105 void ChangeRecorder::setChangeRecordingEnabled( bool enable )
106 {
107  Q_D( ChangeRecorder );
108  if ( d->enableChangeRecording == enable ) {
109  return;
110  }
111  d->enableChangeRecording = enable;
112  if ( enable ) {
113  d->m_needFullSave = true;
114  d->notificationsLoaded();
115  } else {
116  d->dispatchNotifications();
117  }
118 }
119 
120 QString Akonadi::ChangeRecorder::dumpNotificationListToString() const
121 {
122  Q_D( const ChangeRecorder );
123  return d->dumpNotificationListToString();
124 }
125 
Akonadi::ChangeRecorder::nothingToReplay
void nothingToReplay()
Emitted when replayNext() was called, but there was no valid change to replay.
Akonadi::ChangeRecorder::setChangeRecordingEnabled
void setChangeRecordingEnabled(bool enable)
Enables change recording.
Definition: changerecorder.cpp:105
Akonadi::ChangeRecorder::ChangeRecorder
ChangeRecorder(QObject *parent=0)
Creates a new change recorder.
Definition: changerecorder.cpp:28
Akonadi::ChangeRecorder::~ChangeRecorder
~ChangeRecorder()
Destroys the change recorder.
Definition: changerecorder.cpp:38
Akonadi::ChangeRecorder::setConfig
void setConfig(QSettings *settings)
Sets the QSettings object used for persistent recorded changes.
Definition: changerecorder.cpp:42
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:72
Akonadi::ChangeRecorder::dumpNotificationListToString
QString dumpNotificationListToString() const
Debugging: dump current list of notifications, as saved on disk.
Definition: changerecorder.cpp:120
Akonadi::ChangeRecorder::replayNext
void replayNext()
Replay the next change notification and erase the previous one from the record.
Definition: changerecorder.cpp:56
Akonadi::ChangeRecorder::changeProcessed
void changeProcessed()
Removes the previously emitted change from the records.
Definition: changerecorder.cpp:91
Akonadi::ChangeRecorder::isEmpty
bool isEmpty() const
Returns whether there are recorded changes.
Definition: changerecorder.cpp:85
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 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