Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
wavelength_config.h
Go to the documentation of this file.
1#ifndef WAVELENGTH_CONFIG_H
2#define WAVELENGTH_CONFIG_H
3
4#include <QColor>
5#include <QKeySequence>
6#include <QSettings>
7#include <QString>
8
10namespace DefaultConfig {
11 const QString kRelayServerAddress = "localhost";
12 constexpr int kRelayServerPort = 3000;
13 constexpr int kConnectionTimeout = 5000;
14 constexpr int kKeepAliveInterval = 30000;
15 constexpr int kMaxReconnectAttempts = 5;
16 constexpr bool kIsDebugMode = false;
17 const auto kBackgroundColor = QColor(0x101820);
18 const auto kBlobColor = QColor(0x4682B4);
19 const auto kMessageColor = QColor(0xE0E0E0);
20 const auto kStreamColor = QColor(0x00B3FF);
21 constexpr auto kGridColor = QColor(40, 60, 80, 150);
22 constexpr int kGridSpacing = 35;
23 const auto kTitleTextColor = QColor(0xFFFFFF);
24 const auto kTitleBorderColor = QColor(0xE0B0FF);
25 const auto kTitleGlowColor = QColor(0xE0B0FF);
26 const QString kPreferredStartFrequency = "130.0";
27}
28
36class WavelengthConfig final : public QObject {
37 Q_OBJECT
38
42 static constexpr int kMaxRecentColors = 5;
43
47 const QString kShortcutsPrefix = "Shortcuts/";
48
49public:
55
59 ~WavelengthConfig() override = default;
60
65
70
75 [[nodiscard]] QString GetRelayServerAddress() const;
76
82 void SetRelayServerAddress(const QString &address);
83
88 [[nodiscard]] int GetRelayServerPort() const;
89
95 void SetRelayServerPort(int port);
96
101 [[nodiscard]] QString GetRelayServerUrl() const;
102
107 [[nodiscard]] int GetConnectionTimeout() const;
108
114 void SetConnectionTimeout(int timeout);
115
120 [[nodiscard]] int GetKeepAliveInterval() const;
121
127 void SetKeepAliveInterval(int interval);
128
133 [[nodiscard]] int GetMaxReconnectAttempts() const;
134
140 void SetMaxReconnectAttempts(int attempts);
141
147 void SetDebugMode(bool enabled);
148
153 [[nodiscard]] bool IsDebugMode() const;
154
159 [[nodiscard]] QString GetPreferredStartFrequency() const;
160
167 void SetPreferredStartFrequency(const QString &frequency);
168
173 [[nodiscard]] QColor GetBackgroundColor() const;
174
181 void SetBackgroundColor(const QColor &color);
182
187 [[nodiscard]] QColor GetBlobColor() const;
188
195 void SetBlobColor(const QColor &color);
196
201 [[nodiscard]] QColor GetStreamColor() const;
202
209 void SetStreamColor(const QColor &color);
210
215 [[nodiscard]] QColor GetGridColor() const;
216
223 void SetGridColor(const QColor &color);
224
229 [[nodiscard]] int GetGridSpacing() const;
230
236 void SetGridSpacing(int spacing);
237
242 [[nodiscard]] QColor GetTitleTextColor() const;
243
250 void SetTitleTextColor(const QColor &color);
251
256 [[nodiscard]] QColor GetTitleBorderColor() const;
257
264 void SetTitleBorderColor(const QColor &color);
265
270 [[nodiscard]] QColor GetTitleGlowColor() const;
271
278 void SetTitleGlowColor(const QColor &color);
279
284 [[nodiscard]] QStringList GetRecentColors() const;
285
292 void AddRecentColor(const QColor &color);
293
302 [[nodiscard]] QKeySequence GetShortcut(const QString &action_id,
303 const QKeySequence &default_sequence = QKeySequence()) const;
304
311 void SetShortcut(const QString &action_id, const QKeySequence &sequence);
312
317 [[nodiscard]] QMap<QString, QKeySequence> GetAllShortcuts() const;
318
323 [[nodiscard]] QMap<QString, QKeySequence> GetDefaultShortcutsMap() const;
324
328 void SaveSettings();
329
335 void RestoreDefaults();
336
343 [[nodiscard]] QVariant GetSetting(const QString &key) const;
344
349 [[nodiscard]] QString GetLanguageCode() const;
350
357 void SetLanguageCode(const QString &code);
358
359signals:
365 void configChanged(const QString &key);
366
371
372private:
378 explicit WavelengthConfig(QObject *parent = nullptr);
379
384 void LoadDefaults();
385
390 void LoadSettings();
391
396
401
405 QSettings settings_;
406
411 QMap<QString, QKeySequence> default_shortcuts_;
412
420 QMap<QString, QKeySequence> shortcuts_;
426 bool debug_mode_{};
428 QColor blob_color_;
430 QStringList recent_colors_;
431 QColor grid_color_;
438};
439
440#endif // WAVELENGTH_CONFIG_H
int grid_spacing_
The spacing between background grid lines in pixels.
Definition wavelength_config.h:432
QColor blob_color_
The color used for the blob animation.
Definition wavelength_config.h:428
void RestoreDefaults()
Restores all configuration settings to their default values. Also clears saved shortcuts in persisten...
Definition wavelength_config.cpp:158
~WavelengthConfig() override=default
Default destructor.
void SetRelayServerAddress(const QString &address)
Sets the relay server address. Emits configChanged("relayServerAddress") if the value changes.
Definition wavelength_config.cpp:208
void SetBlobColor(const QColor &color)
Sets the color for the blob animation. Adds the color to recent colors. Emits configChanged("blob_col...
Definition wavelength_config.cpp:230
QSettings settings_
QSettings object used for reading and writing configuration data.
Definition wavelength_config.h:405
void LoadDefaultShortcuts()
Loads the hardcoded default keyboard shortcuts into the default_shortcuts_ map.
Definition wavelength_config.cpp:46
void SaveSettings()
Saves all current configuration settings to persistent storage (QSettings).
Definition wavelength_config.cpp:115
static constexpr int kMaxRecentColors
Maximum number of recently used colors to store.
Definition wavelength_config.h:42
QColor GetTitleBorderColor() const
Gets the color for the title label border.
Definition wavelength_config.cpp:178
QColor GetBackgroundColor() const
Gets the main background color.
Definition wavelength_config.cpp:171
bool IsDebugMode() const
Checks if debug mode is enabled.
Definition wavelength_config.cpp:184
void SetRelayServerPort(int port)
Sets the relay server port. Emits configChanged("relayServerPort") if the value changes.
Definition wavelength_config.cpp:215
bool debug_mode_
Flag indicating if debug mode is enabled.
Definition wavelength_config.h:426
void LoadSettings()
Loads settings from the persistent storage (QSettings) into the member variables, overwriting the def...
Definition wavelength_config.cpp:68
QVariant GetSetting(const QString &key) const
Gets a configuration setting value by its key. This provides a generic way to access settings,...
Definition wavelength_config.cpp:333
QString preferred_start_frequency_
The preferred starting frequency for new Wavelengths.
Definition wavelength_config.h:436
void SetTitleGlowColor(const QColor &color)
Sets the color for the title label glow effect. Adds the color to recent colors. Emits configChanged(...
Definition wavelength_config.cpp:277
QString relay_server_address_
The address of the relay server.
Definition wavelength_config.h:421
void SetKeepAliveInterval(int interval)
Sets the keep-alive interval in milliseconds. Emits configChanged("keepAliveInterval") if the value c...
Definition wavelength_config.cpp:306
QMap< QString, QKeySequence > GetAllShortcuts() const
Gets a map of all currently configured shortcuts.
Definition wavelength_config.cpp:185
int GetConnectionTimeout() const
Gets the connection timeout in milliseconds.
Definition wavelength_config.cpp:181
QString language_code_
The selected language code (e.g., "en", "pl")
Definition wavelength_config.h:437
int GetRelayServerPort() const
Gets the configured relay server port.
Definition wavelength_config.cpp:170
void LoadDefaults()
Loads the hardcoded default values for all settings into the member variables. Also copies the defaul...
Definition wavelength_config.cpp:23
QString GetLanguageCode() const
Gets the currently configured language code (e.g., "en", "pl").
Definition wavelength_config.cpp:180
int max_reconnect_attempts_
The maximum number of reconnection attempts.
Definition wavelength_config.h:425
void SetBackgroundColor(const QColor &color)
Sets the main background color. Adds the color to recent colors. Emits configChanged("background_colo...
Definition wavelength_config.cpp:222
int connection_timeout_
The connection timeout in milliseconds.
Definition wavelength_config.h:423
int GetMaxReconnectAttempts() const
Gets the maximum number of reconnection attempts.
Definition wavelength_config.cpp:183
WavelengthConfig & operator=(const WavelengthConfig &)=delete
Deleted assignment operator.
const QString kShortcutsPrefix
Prefix used for storing shortcut keys within QSettings.
Definition wavelength_config.h:47
QColor GetTitleTextColor() const
Gets the color for the title label text.
Definition wavelength_config.cpp:177
QColor GetStreamColor() const
Gets the color used for stream visualization elements.
Definition wavelength_config.cpp:173
void AddRecentColor(const QColor &color)
Adds a color to the list of recently used colors. If the color already exists, it's moved to the fron...
Definition wavelength_config.cpp:285
QColor GetGridColor() const
Gets the color for the background grid lines.
Definition wavelength_config.cpp:175
void SetTitleBorderColor(const QColor &color)
Sets the color for the title label border. Adds the color to recent colors. Emits configChanged("titl...
Definition wavelength_config.cpp:269
WavelengthConfig(const WavelengthConfig &)=delete
Deleted copy constructor.
QStringList recent_colors_
List of recently used colors (hex codes)
Definition wavelength_config.h:430
void SetDebugMode(bool enabled)
Enables or disables debug mode. Emits configChanged("debugMode") if the value changes.
Definition wavelength_config.cpp:320
QMap< QString, QKeySequence > GetDefaultShortcutsMap() const
Gets a map of the default shortcuts defined within the application.
Definition wavelength_config.cpp:186
int keep_alive_interval_
The keep-alive interval in milliseconds.
Definition wavelength_config.h:424
int GetGridSpacing() const
Gets the spacing between background grid lines in pixels.
Definition wavelength_config.cpp:176
QMap< QString, QKeySequence > default_shortcuts_
Map storing the default keyboard shortcuts. Key: Action ID (e.g., "MainWindow.OpenSettings")....
Definition wavelength_config.h:411
void SetStreamColor(const QColor &color)
Sets the color for stream visualization elements. Adds the color to recent colors....
Definition wavelength_config.cpp:238
QColor title_glow_color_
The color for the title label glow effect.
Definition wavelength_config.h:435
void SetLanguageCode(const QString &code)
Sets the application language code. Emits configChanged("languageCode") if the value changes....
Definition wavelength_config.cpp:201
static WavelengthConfig * instance_
Static pointer to the singleton instance.
Definition wavelength_config.h:400
QString GetPreferredStartFrequency() const
Gets the preferred starting frequency for new Wavelengths.
Definition wavelength_config.cpp:187
void recentColorsChanged()
Emitted when the list of recent colors changes (a color was added).
void SetGridSpacing(int spacing)
Sets the spacing between background grid lines. Emits configChanged("grid_spacing") if the value chan...
Definition wavelength_config.cpp:254
QMap< QString, QKeySequence > shortcuts_
Map storing the currently active keyboard shortcuts (loaded from settings or defaults).
Definition wavelength_config.h:420
QColor GetTitleGlowColor() const
Gets the color for the title label glow effect.
Definition wavelength_config.cpp:179
void configChanged(const QString &key)
Emitted when a configuration setting changes.
static WavelengthConfig * GetInstance()
Gets the singleton instance of the WavelengthConfig.
Definition wavelength_config.cpp:6
int relay_server_port_
The port of the relay server.
Definition wavelength_config.h:422
QColor title_border_color_
The color for the title label border.
Definition wavelength_config.h:434
QColor title_text_color_
The color for the title label text.
Definition wavelength_config.h:433
QColor GetBlobColor() const
Gets the color used for the blob animation.
Definition wavelength_config.cpp:172
QString GetRelayServerUrl() const
Constructs the full WebSocket URL for the relay server.
Definition wavelength_config.cpp:189
QColor stream_color_
The color used for stream visualization elements.
Definition wavelength_config.h:429
QStringList GetRecentColors() const
Gets the list of recently used colors.
Definition wavelength_config.cpp:174
QColor background_color_
The main background color of the application.
Definition wavelength_config.h:427
void SetConnectionTimeout(int timeout)
Sets the connection timeout in milliseconds. Emits configChanged("connectionTimeout") if the value ch...
Definition wavelength_config.cpp:299
void SetGridColor(const QColor &color)
Sets the color for the background grid lines. Adds the color to recent colors. Emits configChanged("g...
Definition wavelength_config.cpp:246
void SetMaxReconnectAttempts(int attempts)
Sets the maximum number of reconnection attempts. Emits configChanged("maxReconnectAttempts") if the ...
Definition wavelength_config.cpp:313
void SetPreferredStartFrequency(const QString &frequency)
Sets the preferred starting frequency. Validates that the frequency is a number >= 130....
Definition wavelength_config.cpp:355
void SetTitleTextColor(const QColor &color)
Sets the color for the title label text. Adds the color to recent colors. Emits configChanged("title_...
Definition wavelength_config.cpp:261
QString GetRelayServerAddress() const
Gets the configured relay server address.
Definition wavelength_config.cpp:169
void SetShortcut(const QString &action_id, const QKeySequence &sequence)
Sets the keyboard shortcut for a specific action. This updates the internal map; SaveSettings() must ...
Definition wavelength_config.cpp:327
QKeySequence GetShortcut(const QString &action_id, const QKeySequence &default_sequence=QKeySequence()) const
Gets the configured keyboard shortcut for a specific action. If no shortcut is configured for the act...
Definition wavelength_config.cpp:193
int GetKeepAliveInterval() const
Gets the keep-alive interval in milliseconds.
Definition wavelength_config.cpp:182
QColor grid_color_
The color for the background grid lines.
Definition wavelength_config.h:431
Default configuration values for the Wavelength application.
Definition wavelength_config.h:10
constexpr bool kIsDebugMode
Default debug mode status.
Definition wavelength_config.h:16
constexpr int kRelayServerPort
Default relay server port.
Definition wavelength_config.h:12
const auto kTitleTextColor
White color for title text.
Definition wavelength_config.h:23
const QString kPreferredStartFrequency
Default preferred starting frequency.
Definition wavelength_config.h:26
constexpr auto kGridColor
Grid color with transparency.
Definition wavelength_config.h:21
constexpr int kGridSpacing
Default grid spacing in pixels.
Definition wavelength_config.h:22
const auto kTitleBorderColor
Light Purple color for a title border.
Definition wavelength_config.h:24
const auto kStreamColor
Light Blue color for stream visualization.
Definition wavelength_config.h:20
const auto kMessageColor
Light Gray color for messages.
Definition wavelength_config.h:19
const auto kBackgroundColor
Dark Blue background color.
Definition wavelength_config.h:17
constexpr int kMaxReconnectAttempts
Default maximum number of reconnection attempts.
Definition wavelength_config.h:15
const auto kTitleGlowColor
Light Purple color for a title glow.
Definition wavelength_config.h:25
constexpr int kConnectionTimeout
Default connection timeout in milliseconds.
Definition wavelength_config.h:13
const auto kBlobColor
Steel Blue color for blob animation.
Definition wavelength_config.h:18
constexpr int kKeepAliveInterval
Default keep-alive interval in milliseconds.
Definition wavelength_config.h:14
const QString kRelayServerAddress
Default relay server address.
Definition wavelength_config.h:11