JS8Call-Improved master
Loading...
Searching...
No Matches
ActivityStorageController.h
Go to the documentation of this file.
1
5#pragma once
6
9
10#include <QElapsedTimer>
11#include <QMap>
12#include <QObject>
13#include <QSet>
14#include <QString>
15#include <QTimer>
16
17#include <functional>
18#include <memory>
19
20class Configuration;
21class QSettings;
22class QTextDocument;
23class QTextEdit;
24
42class ActivityStorageController : public QObject {
43 Q_OBJECT
44
45public:
53 struct Context {
54 Configuration const *config = nullptr;
56 QSettings *settings = nullptr;
58 Radio::Frequency defaultDial = 0;
59 QTextEdit *rxTextEdit = nullptr;
61 QMap<QString, CallDetail> *callActivity = nullptr;
63 QMap<QString, int> const *inboxCounts = nullptr;
64 QMap<QString, QMap<QString, CallDetail>> *callActivityBandCache =
65 nullptr;
66 QMap<QString, QString> const *rxTextBandCache = nullptr;
67
68 std::function<void()> displayActivity;
69 std::function<void()> clearRxFrameBlockNumbers;
71 std::function<void()> clearActivityPanes;
73 std::function<void()> clearRxPane;
75 std::function<void()> clearCallActivityPane;
77 std::function<void(QString const &)> cacheActivity;
79 std::function<void(QString const &)> dropBandCache;
81 std::function<void(QString const &)> restoreActivity;
83 std::function<void()> clearBandCaches;
84 };
85
95 explicit ActivityStorageController(Context context,
96 QObject *parent = nullptr);
98
99 // Startup
100
113 void beginStartupGrace();
124 void setupRxTextAutosave();
125
126 // The bucket on screen
127
129 QString currentBucket() const { return m_activityBand; }
131 bool isBucketLoaded() const { return m_activityBandLoaded; }
136 void bandUnchanged(QString const &band);
141 void bandChanged(QString const &band);
147 void bucketRestored(QString const &band, bool paneReloaded);
148
149 // Writes
150
157 void persistCallActivity(CallDetail const &d,
158 bool fallbackToCurrentBand = false);
163 void adjustCallActivityOffsets(int hzDelta);
167 void beginBatch();
171 void endBatch();
172
173 // User-facing clears
174
176 void clearAllActivity();
178 void clearRxActivity();
180 void clearCallActivity();
185 void removeStoredCall(QString const &call);
186
187 // Shutdown
188
192 void flushOnClose();
193
194private:
195 QString activityPath() const;
196 ActivityDB *activityDB();
197 QString activityConfigId() const;
198 // single conversion pair, so a CallDetail field added later fails to
199 // persist/restore loudly at the one site instead of silently in
200 // hand-copied blocks
201 ActivityDB::CallRecord toCallRecord(CallDetail const &) const;
202 CallDetail fromCallRecord(ActivityDB::CallRecord const &) const;
203 void seedActivityForBand(QString const &band);
204 QString htmlBelowLegacyCopy(QTextDocument *doc) const;
205 void purgeLegacyActivityIni();
214 QString lastStoreError() const {
215 return m_activityDB ? m_activityDB->error() : QString{};
216 }
217 void startActivityBatchIfPending();
218 void saveRxTextForBand(QString const &band);
219 void switchActivityBucket(QString const &band);
220
221 Context m_ctx;
222
223 std::unique_ptr<ActivityDB> m_activityDB;
224 QElapsedTimer m_activityDBRetryTimer; // throttles reopen attempts
225 QString m_activityBand;
226 bool m_activityBandLoaded = false; // false until the first restore
227 QSet<QString> m_activitySeeded;
228 // Degraded start: the store was down, so readSettings showed the
229 // legacy ini copy in the RX pane.
230 bool m_rxTextLegacyShown = false;
231 QString m_rxTextLegacyBand;
232 int m_rxTextLegacyBlocks = 0;
233 // Depth counter
234 int m_activityBatchDepth = 0;
235 bool m_activityBatchBeginFailed = false;
236 QSet<QString> m_rxTextDirtyBands;
237 // Set when a requested startup reset, or a clone's inherited-activity
238 // copy, could not be applied
239 bool m_activityStoreDisabled = false;
240 // Set in flushOnClose
241 bool m_activityShuttingDown = false;
242 // False until the rig has actually reported a band, and set
243 // unconditionally at close
244 bool m_activityBandConfirmed = false;
245 // Buckets the rig has actually reported this session
246 QSet<QString> m_activityBandConfirmedBands;
247 QElapsedTimer m_activityStartupTimer;
248 QElapsedTimer m_seedRetryTimer; // throttles failed-seed retries
249 QTimer m_rxTextSaveTimer; // debounces RX-text writes to activity.db3
250 QTimer m_rxTextSaveMaxTimer;
251 // Storage id captured at first use
252 mutable QString m_activityConfigId;
253 // Skip unchanged RX-text rewrites via the document's revision counter
254 int m_rxTextLastSavedRevision = -1;
255 QString m_rxTextLastSavedBand;
256};
Declares the SQLite store behind activity.db3 (issue #267).
Defines the Call Activity record shared by the UI and storage.
Persistent per-band activity storage (activity.db3).
Definition ActivityDB.h:50
void clearCallActivity()
Drop the current bucket's stored Call Activity rows.
Definition ActivityStorageController.cpp:871
void flushOnClose()
Final flush: sweep every confirmed bucket's pending writes.
Definition ActivityStorageController.cpp:911
bool importLegacyActivityIfNeeded()
Import the legacy .ini activity once per configuration.
Definition ActivityStorageController.cpp:661
ActivityStorageController(Context context, QObject *parent=nullptr)
Construct the controller over an already-built window.
Definition ActivityStorageController.cpp:46
void bandUnchanged(QString const &band)
The rig reported the band the panes already hold.
Definition ActivityStorageController.cpp:114
void setupRxTextAutosave()
Connect the debounced RX-text write-back timers.
Definition ActivityStorageController.cpp:58
QString currentBucket() const
The bucket the on-screen panes belong to ("" = out-of-plan).
Definition ActivityStorageController.h:129
bool isBucketLoaded() const
Whether a bucket has been restored into the panes yet.
Definition ActivityStorageController.h:131
void beginBatch()
Open a write batch; nested batches share one transaction.
Definition ActivityStorageController.cpp:254
void bucketRestored(QString const &band, bool paneReloaded)
Record that the window has restored a bucket's panes.
Definition ActivityStorageController.cpp:177
void endBatch()
Close a write batch, committing at the outermost level.
Definition ActivityStorageController.cpp:271
void beginStartupGrace()
Start the grace period allowed for the rig to report a band.
Definition ActivityStorageController.cpp:76
void adjustCallActivityOffsets(int hzDelta)
Shift every stored offset for the current bucket.
Definition ActivityStorageController.cpp:405
void showLegacyRxTextIfDegraded()
Show the legacy .ini RX text when the store is unavailable.
Definition ActivityStorageController.cpp:87
void persistCallActivity(CallDetail const &d, bool fallbackToCurrentBand=false)
Upsert one station into the store.
Definition ActivityStorageController.cpp:358
void clearRxActivity()
Drop the current bucket's stored RX text.
Definition ActivityStorageController.cpp:837
void removeStoredCall(QString const &call)
Drop one station from the current bucket.
Definition ActivityStorageController.cpp:888
void clearAllActivity()
Drop every stored row, across all buckets and both panes.
Definition ActivityStorageController.cpp:807
void bandChanged(QString const &band)
The rig reported a different band; park and switch buckets.
Definition ActivityStorageController.cpp:126
Definition Configuration.h:59
One persisted Call Activity row - the full CallDetail field set, so a band round-trip within a sessio...
Definition ActivityDB.h:57
The window state and operations this controller needs.
Definition ActivityStorageController.h:53
QMap< QString, int > const * inboxCounts
Unread-message counts; unread senders are exempt from aging.
Definition ActivityStorageController.h:63
std::function< void(QString const &)> restoreActivity
UI_Constructor::restoreActivity - show a bucket's panes.
Definition ActivityStorageController.h:81
QMap< QString, CallDetail > * callActivity
The live Call Activity table; a seed merges stored rows into it.
Definition ActivityStorageController.h:61
std::function< void()> clearBandCaches
Empty every RAM band cache (the "Clear All Activity" action).
Definition ActivityStorageController.h:83
std::function< void(QString const &)> cacheActivity
UI_Constructor::cacheActivity - park the panes under a bucket.
Definition ActivityStorageController.h:77
std::function< void(QString const &)> dropBandCache
Forget every per-band cache the window holds for one bucket.
Definition ActivityStorageController.h:79
std::function< void()> clearCallActivityPane
UI_Constructor::clearCallActivity.
Definition ActivityStorageController.h:75
Radio::Frequency defaultDial
The dial the ini falls back to when it has never recorded one.
Definition ActivityStorageController.h:58
QSettings * settings
The current configuration's settings (legacy import, config id).
Definition ActivityStorageController.h:56
std::function< void()> clearActivityPanes
UI_Constructor::clearActivity - every pane and session queue.
Definition ActivityStorageController.h:71
std::function< void()> clearRxPane
UI_Constructor::clearRXActivity.
Definition ActivityStorageController.h:73
One station in the Call Activity table.
Definition CallDetail.h:20