Akonadi

changerecorder.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
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
12using namespace Akonadi;
13
15 : Monitor(new ChangeRecorderPrivate(nullptr, this), parent)
16{
17}
18
19ChangeRecorder::ChangeRecorder(ChangeRecorderPrivate *privateclass, QObject *parent)
20 : Monitor(privateclass, parent)
21{
22}
23
27
29{
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{
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{
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{
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}
116
117#include "moc_changerecorder.cpp"
Records and replays change notification.
bool isEmpty() const
Returns whether there are recorded changes.
void replayNext()
Replay the next change notification and erase the previous one from the record.
void setChangeRecordingEnabled(bool enable)
Enables change recording.
void changeProcessed()
Removes the previously emitted change from the records.
ChangeRecorder(QObject *parent=nullptr)
Creates a new change recorder.
void nothingToReplay()
Emitted when replayNext() was called, but there was no valid change to replay.
void setConfig(QSettings *settings)
Sets the QSettings object used for persistent recorded changes.
~ChangeRecorder() override
Destroys the change recorder.
QString dumpNotificationListToString() const
Debugging: dump current list of notifications, as saved on disk.
Monitors an item or collection for changes.
Definition monitor.h:71
Helper integration between Akonadi and Qt.
Q_EMITQ_EMIT
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.