Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
wavelength_state_manager.h
Go to the documentation of this file.
1#ifndef WAVELENGTH_STATE_MANAGER_H
2#define WAVELENGTH_STATE_MANAGER_H
3
4#include <QObject>
5#include <QVariant>
6
7struct WavelengthInfo;
8
18class WavelengthStateManager final : public QObject {
19 Q_OBJECT
20
21public:
27 static WavelengthStateManager instance;
28 return &instance;
29 }
30
37 static WavelengthInfo GetWavelengthInfo(const QString &frequency, bool *is_host = nullptr);
38
43 static QString GetActiveWavelength();
44
50 void SetActiveWavelength(const QString &frequency);
51
56 static bool IsActiveWavelengthHost();
57
63 QList<QString> GetJoinedWavelengths();
64
70 void RegisterJoinedWavelength(const QString &frequency);
71
77 void UnregisterJoinedWavelength(const QString &frequency);
78
84
90 static bool IsWavelengthPasswordProtected(const QString &frequency);
91
97 static bool IsWavelengthHost(const QString &frequency);
98
104 static QDateTime GetWavelengthCreationTime(const QString &frequency);
105
111 static bool IsWavelengthJoined(const QString &frequency);
112
118 static bool IsWavelengthConnected(const QString &frequency);
119
127 void AddActiveSessionData(const QString &frequency, const QString &key, const QVariant &value);
128
136 QVariant GetActiveSessionData(const QString &frequency, const QString &key,
137 const QVariant &default_value = QVariant());
138
143 void ClearSessionData(const QString &frequency);
144
148 void ClearAllSessionData();
149
155 bool IsConnecting(const QString &frequency) const;
156
163 void SetConnecting(const QString &frequency, bool connecting);
164
165signals:
170 void activeWavelengthChanged(QString frequency);
171
172private:
177 explicit WavelengthStateManager(QObject *parent = nullptr) : QObject(parent) {
178 }
179
183 ~WavelengthStateManager() override = default;
184
189
194
196 QMap<QString, QMap<QString, QVariant> > session_data_{};
198 QList<QString> connecting_wavelengths_{};
200 QList<QString> joined_wavelengths_{};
201};
202
203#endif // WAVELENGTH_STATE_MANAGER_H
QVariant GetActiveSessionData(const QString &frequency, const QString &key, const QVariant &default_value=QVariant())
Retrieves previously stored session data for a specific frequency and key.
Definition wavelength_state_manager.cpp:92
static WavelengthStateManager * GetInstance()
Gets the singleton instance of the WavelengthStateManager.
Definition wavelength_state_manager.h:26
static bool IsWavelengthConnected(const QString &frequency)
Checks if the WebSocket connection for a specific wavelength is currently established and valid.
Definition wavelength_state_manager.cpp:78
void SetActiveWavelength(const QString &frequency)
Sets the specified frequency as the currently active wavelength. Updates the registry and emits the a...
Definition wavelength_state_manager.cpp:20
void AddActiveSessionData(const QString &frequency, const QString &key, const QVariant &value)
Stores arbitrary session data associated with a specific frequency and key. Useful for temporary stat...
Definition wavelength_state_manager.cpp:84
int GetJoinedWavelengthCount()
Gets the total number of wavelengths the user is currently joined to.
Definition wavelength_state_manager.cpp:55
static bool IsWavelengthJoined(const QString &frequency)
Checks if the user is currently considered joined to a specific wavelength (based on registry presenc...
Definition wavelength_state_manager.cpp:74
void UnregisterJoinedWavelength(const QString &frequency)
Unregisters that the user has left or been disconnected from a specific wavelength....
Definition wavelength_state_manager.cpp:51
static QDateTime GetWavelengthCreationTime(const QString &frequency)
Gets the creation timestamp of a specific wavelength.
Definition wavelength_state_manager.cpp:69
static QString GetActiveWavelength()
Gets the frequency identifier of the currently active wavelength.
Definition wavelength_state_manager.cpp:16
static bool IsWavelengthPasswordProtected(const QString &frequency)
Checks if a specific wavelength is password protected.
Definition wavelength_state_manager.cpp:59
bool IsConnecting(const QString &frequency) const
Checks if the application is currently in the process of connecting to a specific wavelength.
Definition wavelength_state_manager.cpp:111
QList< QString > GetJoinedWavelengths()
Gets a list of frequency identifiers for all wavelengths the user is currently joined to....
Definition wavelength_state_manager.cpp:33
void ClearSessionData(const QString &frequency)
Removes all session data associated with a specific frequency.
Definition wavelength_state_manager.cpp:101
WavelengthStateManager(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern.
Definition wavelength_state_manager.h:177
static bool IsActiveWavelengthHost()
Checks if the current user is the host of the currently active wavelength.
Definition wavelength_state_manager.cpp:25
void RegisterJoinedWavelength(const QString &frequency)
Registers that the user has successfully joined a specific wavelength. Adds the frequency to an inter...
Definition wavelength_state_manager.cpp:45
void SetConnecting(const QString &frequency, bool connecting)
Sets or clears the "connecting" status for a specific wavelength. Used to track ongoing connection at...
Definition wavelength_state_manager.cpp:115
WavelengthStateManager & operator=(const WavelengthStateManager &)=delete
Deleted assignment operator to prevent assignment.
~WavelengthStateManager() override=default
Private destructor.
QList< QString > joined_wavelengths_
List of frequencies the user is currently joined to (managed internally).
Definition wavelength_state_manager.h:200
void activeWavelengthChanged(QString frequency)
Emitted when the active wavelength changes via SetActiveWavelength().
QList< QString > connecting_wavelengths_
List of frequencies currently undergoing a connection attempt.
Definition wavelength_state_manager.h:198
static bool IsWavelengthHost(const QString &frequency)
Checks if the current user is the host of a specific wavelength.
Definition wavelength_state_manager.cpp:64
void ClearAllSessionData()
Removes all session data for all frequencies.
Definition wavelength_state_manager.cpp:107
QMap< QString, QMap< QString, QVariant > > session_data_
Stores temporary session data, keyed by frequency, then by data key.
Definition wavelength_state_manager.h:196
WavelengthStateManager(const WavelengthStateManager &)=delete
Deleted copy constructor to prevent copying.
static WavelengthInfo GetWavelengthInfo(const QString &frequency, bool *is_host=nullptr)
Retrieves detailed information about a specific wavelength from the registry.
Definition wavelength_state_manager.cpp:5
Structure holding information about a specific wavelength (frequency).
Definition wavelength_registry.h:13