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

akonadi

  • sources
  • kde-4.14
  • 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  }
53  d->settings = settings;
54  }
55 }
56 
57 void ChangeRecorder::replayNext()
58 {
59  Q_D(ChangeRecorder);
60 
61  if (!d->enableChangeRecording) {
62  return;
63  }
64 
65  if (!d->pendingNotifications.isEmpty()) {
66  const NotificationMessageV3 msg = d->pendingNotifications.head();
67  if (d->ensureDataAvailable(msg)) {
68  if (!d->emitNotification(msg)) {
69  //If no signal was emitted (e.g. because noone was connected to it), noone is going to call changeProcessed, so we help ourselves
70  d->dequeueNotification();
71  return replayNext();
72  }
73  } else if (d->translateAndCompress(d->pipeline, msg)) {
74  // The msg is now in both pipeline and pendingNotifications.
75  // When data is available, MonitorPrivate::flushPipeline will emitNotification.
76  // When changeProcessed is called, we'll finally remove it from pendingNotifications.
77  } else {
78  // In the case of a move where both source and destination are
79  // ignored, we ignore the message and process the next one.
80  d->dequeueNotification();
81  return replayNext();
82  }
83  } else {
84  // This is necessary when none of the notifications were accepted / processed
85  // above, and so there is no one to call changeProcessed() and the ChangeReplay task
86  // will be stuck forever in the ResourceScheduler.
87  emit nothingToReplay();
88  }
89 }
90 
91 bool ChangeRecorder::isEmpty() const
92 {
93  Q_D(const ChangeRecorder);
94  return d->pendingNotifications.isEmpty();
95 }
96 
97 void ChangeRecorder::changeProcessed()
98 {
99  Q_D(ChangeRecorder);
100 
101  if (!d->enableChangeRecording) {
102  return;
103  }
104 
105  // changerecordertest.cpp calls changeProcessed after receiving nothingToReplay,
106  // so test for emptiness. Not sure real code does this though.
107  // Q_ASSERT( !d->pendingNotifications.isEmpty() )
108  if (!d->pendingNotifications.isEmpty()) {
109  d->dequeueNotification();
110  }
111 }
112 
113 void ChangeRecorder::setChangeRecordingEnabled(bool enable)
114 {
115  Q_D(ChangeRecorder);
116  if (d->enableChangeRecording == enable) {
117  return;
118  }
119  d->enableChangeRecording = enable;
120  if (enable) {
121  d->m_needFullSave = true;
122  d->notificationsLoaded();
123  } else {
124  d->dispatchNotifications();
125  }
126 }
127 
128 QString Akonadi::ChangeRecorder::dumpNotificationListToString() const
129 {
130  Q_D(const ChangeRecorder);
131  return d->dumpNotificationListToString();
132 }
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:113
QObject
Akonadi::ChangeRecorder::ChangeRecorder
ChangeRecorder(QObject *parent=0)
Creates a new change recorder.
Definition: changerecorder.cpp:28
QString
Akonadi::ChangeRecorder::~ChangeRecorder
~ChangeRecorder()
Destroys the change recorder.
Definition: changerecorder.cpp:38
QSettings
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:74
Akonadi::ChangeRecorder::dumpNotificationListToString
QString dumpNotificationListToString() const
Debugging: dump current list of notifications, as saved on disk.
Definition: changerecorder.cpp:128
Akonadi::ChangeRecorder::replayNext
void replayNext()
Replay the next change notification and erase the previous one from the record.
Definition: changerecorder.cpp:57
Akonadi::ChangeRecorder::changeProcessed
void changeProcessed()
Removes the previously emitted change from the records.
Definition: changerecorder.cpp:97
Akonadi::ChangeRecorder::isEmpty
bool isEmpty() const
Returns whether there are recorded changes.
Definition: changerecorder.cpp:91
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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