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(QString const &)> showStatusMessage;
69 std::function<void()> displayActivity;
70 std::function<void()> clearRxFrameBlockNumbers;
72 std::function<void()> clearActivityPanes;
74 std::function<void()> clearRxPane;
76 std::function<void()> clearCallActivityPane;
78 std::function<void(QString const &)> cacheActivity;
80 std::function<void(QString const &)> dropBandCache;
82 std::function<void(QString const &)> restoreActivity;
84 std::function<void()> clearBandCaches;
85 };
86
96 explicit ActivityStorageController(Context context,
97 QObject *parent = nullptr);
99
100 // Startup
101
114 void beginStartupGrace();
125 void setupRxTextAutosave();
126
127 // The bucket on screen
128
130 QString currentBucket() const { return m_activityBand; }
132 bool isBucketLoaded() const { return m_activityBandLoaded; }
137 void bandUnchanged(QString const &band);
142 void bandChanged(QString const &band);
148 void bucketRestored(QString const &band, bool paneReloaded);
149
150 // Writes
151
158 void persistCallActivity(CallDetail const &d,
159 bool fallbackToCurrentBand = false);
164 void adjustCallActivityOffsets(int hzDelta);
168 void beginBatch();
172 void endBatch();
173
174 // User-facing clears
175
177 void clearAllActivity();
179 void clearRxActivity();
181 void clearCallActivity();
186 void removeStoredCall(QString const &call);
187
188 // Shutdown
189
193 void flushOnClose();
194
195private:
196 QString activityPath() const;
197 ActivityDB *activityDB();
198 QString activityConfigId() const;
199 // single conversion pair, so a CallDetail field added later fails to
200 // persist/restore loudly at the one site instead of silently in
201 // hand-copied blocks
202 ActivityDB::CallRecord toCallRecord(CallDetail const &) const;
203 CallDetail fromCallRecord(ActivityDB::CallRecord const &) const;
204 void seedActivityForBand(QString const &band);
205 QString htmlBelowLegacyCopy(QTextDocument *doc) const;
206 void purgeLegacyActivityIni();
215 QString lastStoreError() const {
216 return m_activityDB ? m_activityDB->error() : QString{};
217 }
218 void startActivityBatchIfPending();
219 void saveRxTextForBand(QString const &band);
220 void switchActivityBucket(QString const &band);
221
222 Context m_ctx;
223
224 std::unique_ptr<ActivityDB> m_activityDB;
225 QElapsedTimer m_activityDBRetryTimer; // throttles reopen attempts
226 QString m_activityBand;
227 bool m_activityBandLoaded = false; // false until the first restore
228 QSet<QString> m_activitySeeded;
229 // Degraded start: the store was down, so readSettings showed the
230 // legacy ini copy in the RX pane.
231 bool m_rxTextLegacyShown = false;
232 QString m_rxTextLegacyBand;
233 int m_rxTextLegacyBlocks = 0;
234 // Depth counter
235 int m_activityBatchDepth = 0;
236 bool m_activityBatchBeginFailed = false;
237 QSet<QString> m_rxTextDirtyBands;
238 // Set when a requested startup reset, or a clone's inherited-activity
239 // copy, could not be applied
240 bool m_activityStoreDisabled = false;
241 // Set in flushOnClose
242 bool m_activityShuttingDown = false;
243 // False until the rig has actually reported a band, and set
244 // unconditionally at close
245 bool m_activityBandConfirmed = false;
246 // Buckets the rig has actually reported this session
247 QSet<QString> m_activityBandConfirmedBands;
248 QElapsedTimer m_activityStartupTimer;
249 QElapsedTimer m_seedRetryTimer; // throttles failed-seed retries
250 QTimer m_rxTextSaveTimer; // debounces RX-text writes to activity.db3
251 QTimer m_rxTextSaveMaxTimer;
252 // Storage id captured at first use
253 mutable QString m_activityConfigId;
254 // Skip unchanged RX-text rewrites via the document's revision counter
255 int m_rxTextLastSavedRevision = -1;
256 QString m_rxTextLastSavedBand;
257};
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:1103
void flushOnClose()
Final flush: sweep every confirmed bucket's pending writes.
Definition ActivityStorageController.cpp:1178
bool importLegacyActivityIfNeeded()
Import the legacy .ini activity once per configuration.
Definition ActivityStorageController.cpp:846
ActivityStorageController(Context context, QObject *parent=nullptr)
Construct the controller over an already-built window.
Definition ActivityStorageController.cpp:66
void bandUnchanged(QString const &band)
The rig reported the band the panes already hold.
Definition ActivityStorageController.cpp:162
void setupRxTextAutosave()
Connect the debounced RX-text write-back timers.
Definition ActivityStorageController.cpp:88
QString currentBucket() const
The bucket the on-screen panes belong to ("" = out-of-plan).
Definition ActivityStorageController.h:130
bool isBucketLoaded() const
Whether a bucket has been restored into the panes yet.
Definition ActivityStorageController.h:132
void beginBatch()
Open a write batch; nested batches share one transaction.
Definition ActivityStorageController.cpp:361
void bucketRestored(QString const &band, bool paneReloaded)
Record that the window has restored a bucket's panes.
Definition ActivityStorageController.cpp:249
void endBatch()
Close a write batch, committing at the outermost level.
Definition ActivityStorageController.cpp:385
void beginStartupGrace()
Start the grace period allowed for the rig to report a band.
Definition ActivityStorageController.cpp:112
void adjustCallActivityOffsets(int hzDelta)
Shift every stored offset for the current bucket.
Definition ActivityStorageController.cpp:542
void showLegacyRxTextIfDegraded()
Show the legacy .ini RX text when the store is unavailable.
Definition ActivityStorageController.cpp:128
void persistCallActivity(CallDetail const &d, bool fallbackToCurrentBand=false)
Upsert one station into the store.
Definition ActivityStorageController.cpp:492
void clearRxActivity()
Drop the current bucket's stored RX text.
Definition ActivityStorageController.cpp:1056
void removeStoredCall(QString const &call)
Drop one station from the current bucket.
Definition ActivityStorageController.cpp:1135
void clearAllActivity()
Drop every stored row, across all buckets and both panes.
Definition ActivityStorageController.cpp:1013
void bandChanged(QString const &band)
The rig reported a different band; park and switch buckets.
Definition ActivityStorageController.cpp:179
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:82
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:84
std::function< void(QString const &)> cacheActivity
UI_Constructor::cacheActivity - park the panes under a bucket.
Definition ActivityStorageController.h:78
std::function< void(QString const &)> dropBandCache
Forget every per-band cache the window holds for one bucket.
Definition ActivityStorageController.h:80
std::function< void()> clearCallActivityPane
UI_Constructor::clearCallActivity.
Definition ActivityStorageController.h:76
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:72
std::function< void()> clearRxPane
UI_Constructor::clearRXActivity.
Definition ActivityStorageController.h:74
One station in the Call Activity table.
Definition CallDetail.h:20