Akonadi

changerecorder.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "changerecorder.h"
8 #include "changerecorder_p.h"
9 
10 #include <QSettings>
11 
12 using namespace Akonadi;
13 
15  : Monitor(new ChangeRecorderPrivate(nullptr, this), parent)
16 {
17 }
18 
19 ChangeRecorder::ChangeRecorder(ChangeRecorderPrivate *privateclass, QObject *parent)
20  : Monitor(privateclass, parent)
21 {
22 }
23 
25 {
26 }
27 
29 {
30  Q_D(ChangeRecorder);
31  if (settings) {
32  d->settings = settings;
33  Q_ASSERT(d->pendingNotifications.isEmpty());
34  d->loadNotifications();
35  } else if (d->settings) {
36  if (d->enableChangeRecording) {
37  d->saveNotifications();
38  }
39  d->settings = settings;
40  }
41 }
42 
44 {
45  Q_D(ChangeRecorder);
46 
47  if (!d->enableChangeRecording) {
48  return;
49  }
50 
51  if (!d->pendingNotifications.isEmpty()) {
52  const auto msg = d->pendingNotifications.head();
53  if (d->ensureDataAvailable(msg)) {
54  d->emitNotification(msg);
55  } else if (d->translateAndCompress(d->pipeline, msg)) {
56  // The msg is now in both pipeline and pendingNotifications.
57  // When data is available, MonitorPrivate::flushPipeline will emitNotification.
58  // When changeProcessed is called, we'll finally remove it from pendingNotifications.
59  } else {
60  // In the case of a move where both source and destination are
61  // ignored, we ignore the message and process the next one.
62  d->dequeueNotification();
63  replayNext();
64  return;
65  }
66  } else {
67  // This is necessary when none of the notifications were accepted / processed
68  // above, and so there is no one to call changeProcessed() and the ChangeReplay task
69  // will be stuck forever in the ResourceScheduler.
71  }
72 }
73 
75 {
76  Q_D(const ChangeRecorder);
77  return d->pendingNotifications.isEmpty();
78 }
79 
81 {
82  Q_D(ChangeRecorder);
83 
84  if (!d->enableChangeRecording) {
85  return;
86  }
87 
88  // changerecordertest.cpp calls changeProcessed after receiving nothingToReplay,
89  // so test for emptiness. Not sure real code does this though.
90  // Q_ASSERT( !d->pendingNotifications.isEmpty() )
91  if (!d->pendingNotifications.isEmpty()) {
92  d->dequeueNotification();
93  }
94 }
95 
97 {
98  Q_D(ChangeRecorder);
99  if (d->enableChangeRecording == enable) {
100  return;
101  }
102  d->enableChangeRecording = enable;
103  if (enable) {
104  d->m_needFullSave = true;
105  d->notificationsLoaded();
106  } else {
107  d->dispatchNotifications();
108  }
109 }
110 
112 {
113  Q_D(const ChangeRecorder);
114  return d->dumpNotificationListToString();
115 }
void nothingToReplay()
Emitted when replayNext() was called, but there was no valid change to replay.
ChangeRecorder(QObject *parent=nullptr)
Creates a new change recorder.
void setChangeRecordingEnabled(bool enable)
Enables change recording.
Monitor(QObject *parent=nullptr)
Creates a new monitor.
Definition: monitor.cpp:22
~ChangeRecorder()
Destroys the change recorder.
void setConfig(QSettings *settings)
Sets the QSettings object used for persistent recorded changes.
Monitors an item or collection for changes.
Definition: monitor.h:71
QString dumpNotificationListToString() const
Debugging: dump current list of notifications, as saved on disk.
void replayNext()
Replay the next change notification and erase the previous one from the record.
Helper integration between Akonadi and Qt.
void changeProcessed()
Removes the previously emitted change from the records.
bool isEmpty() const
Returns whether there are recorded changes.
QObject * parent() const const
Q_EMITQ_EMIT
Records and replays change notification.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.