|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
Manages application configuration settings using a singleton pattern. More...
#include <wavelength_config.h>
Signals | |
| void | configChanged (const QString &key) |
| Emitted when a configuration setting changes. | |
| void | recentColorsChanged () |
| Emitted when the list of recent colors changes (a color was added). | |
Public Member Functions | |
| 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 front. The list is capped at kMaxRecentColors. Emits recentColorsChanged() if the list is modified. | |
| QMap< QString, QKeySequence > | GetAllShortcuts () const |
| Gets a map of all currently configured shortcuts. | |
| QColor | GetBackgroundColor () const |
| Gets the main background color. | |
| QColor | GetBlobColor () const |
| Gets the color used for the blob animation. | |
| int | GetConnectionTimeout () const |
| Gets the connection timeout in milliseconds. | |
| QMap< QString, QKeySequence > | GetDefaultShortcutsMap () const |
| Gets a map of the default shortcuts defined within the application. | |
| QColor | GetGridColor () const |
| Gets the color for the background grid lines. | |
| int | GetGridSpacing () const |
| Gets the spacing between background grid lines in pixels. | |
| int | GetKeepAliveInterval () const |
| Gets the keep-alive interval in milliseconds. | |
| QString | GetLanguageCode () const |
| Gets the currently configured language code (e.g., "en", "pl"). | |
| int | GetMaxReconnectAttempts () const |
| Gets the maximum number of reconnection attempts. | |
| QString | GetPreferredStartFrequency () const |
| Gets the preferred starting frequency for new Wavelengths. | |
| QStringList | GetRecentColors () const |
| Gets the list of recently used colors. | |
| QString | GetRelayServerAddress () const |
| Gets the configured relay server address. | |
| int | GetRelayServerPort () const |
| Gets the configured relay server port. | |
| QString | GetRelayServerUrl () const |
| Constructs the full WebSocket URL for the relay server. | |
| QVariant | GetSetting (const QString &key) const |
| Gets a configuration setting value by its key. This provides a generic way to access settings, primarily for UI elements. | |
| 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 action_id, it returns the default_sequence. If default_sequence is empty, it looks up the default in the internal default map. | |
| QColor | GetStreamColor () const |
| Gets the color used for stream visualization elements. | |
| QColor | GetTitleBorderColor () const |
| Gets the color for the title label border. | |
| QColor | GetTitleGlowColor () const |
| Gets the color for the title label glow effect. | |
| QColor | GetTitleTextColor () const |
| Gets the color for the title label text. | |
| bool | IsDebugMode () const |
| Checks if debug mode is enabled. | |
| WavelengthConfig & | operator= (const WavelengthConfig &)=delete |
| Deleted assignment operator. | |
| void | RestoreDefaults () |
| Restores all configuration settings to their default values. Also clears saved shortcuts in persistent storage and saves the defaults. Emits configChanged("all") and recentColorsChanged(). | |
| void | SaveSettings () |
| Saves all current configuration settings to persistent storage (QSettings). | |
| void | SetBackgroundColor (const QColor &color) |
| Sets the main background color. Adds the color to recent colors. Emits configChanged("background_color") if the value changes and is valid. | |
| void | SetBlobColor (const QColor &color) |
| Sets the color for the blob animation. Adds the color to recent colors. Emits configChanged("blob_color") if the value changes and is valid. | |
| void | SetConnectionTimeout (int timeout) |
| Sets the connection timeout in milliseconds. Emits configChanged("connectionTimeout") if the value changes and is positive. | |
| void | SetDebugMode (bool enabled) |
| Enables or disables debug mode. Emits configChanged("debugMode") if the value changes. | |
| void | SetGridColor (const QColor &color) |
| Sets the color for the background grid lines. Adds the color to recent colors. Emits configChanged("grid_color") if the value changes and is valid. | |
| void | SetGridSpacing (int spacing) |
| Sets the spacing between background grid lines. Emits configChanged("grid_spacing") if the value changes and is positive. | |
| void | SetKeepAliveInterval (int interval) |
| Sets the keep-alive interval in milliseconds. Emits configChanged("keepAliveInterval") if the value changes and is positive. | |
| void | SetLanguageCode (const QString &code) |
| Sets the application language code. Emits configChanged("languageCode") if the value changes. Note: Requires application restart to take full effect. | |
| void | SetMaxReconnectAttempts (int attempts) |
| Sets the maximum number of reconnection attempts. Emits configChanged("maxReconnectAttempts") if the value changes and is non-negative. | |
| void | SetPreferredStartFrequency (const QString &frequency) |
| Sets the preferred starting frequency. Validates that the frequency is a number >= 130.0. Normalizes to one decimal place. Emits configChanged("preferredStartFrequency") if the normalized value changes. | |
| void | SetRelayServerAddress (const QString &address) |
| Sets the relay server address. Emits configChanged("relayServerAddress") if the value changes. | |
| void | SetRelayServerPort (int port) |
| Sets the relay server port. Emits configChanged("relayServerPort") if the value changes. | |
| void | SetShortcut (const QString &action_id, const QKeySequence &sequence) |
| Sets the keyboard shortcut for a specific action. This updates the internal map; SaveSettings() must be called to persist the change. | |
| void | SetStreamColor (const QColor &color) |
| Sets the color for stream visualization elements. Adds the color to recent colors. Emits configChanged("stream_color") if the value changes and is valid. | |
| void | SetTitleBorderColor (const QColor &color) |
| Sets the color for the title label border. Adds the color to recent colors. Emits configChanged("title_border_color") if the value changes and is valid. | |
| void | SetTitleGlowColor (const QColor &color) |
| Sets the color for the title label glow effect. Adds the color to recent colors. Emits configChanged("title_glow_color") if the value changes and is valid. | |
| void | SetTitleTextColor (const QColor &color) |
| Sets the color for the title label text. Adds the color to recent colors. Emits configChanged("title_text_color") if the value changes and is valid. | |
| WavelengthConfig (const WavelengthConfig &)=delete | |
| Deleted copy constructor. | |
| ~WavelengthConfig () override=default | |
| Default destructor. | |
Static Public Member Functions | |
| static WavelengthConfig * | GetInstance () |
| Gets the singleton instance of the WavelengthConfig. | |
Private Member Functions | |
| void | LoadDefaults () |
| Loads the hardcoded default values for all settings into the member variables. Also copies the default shortcuts map to the current shortcuts map. | |
| void | LoadDefaultShortcuts () |
| Loads the hardcoded default keyboard shortcuts into the default_shortcuts_ map. | |
| void | LoadSettings () |
| Loads settings from the persistent storage (QSettings) into the member variables, overwriting the defaults if values exist in storage. | |
| WavelengthConfig (QObject *parent=nullptr) | |
| Private constructor to enforce the singleton pattern. Loads default shortcuts, default values, and then saved settings. | |
Private Attributes | |
| QColor | background_color_ |
| The main background color of the application. | |
| QColor | blob_color_ |
| The color used for the blob animation. | |
| int | connection_timeout_ {} |
| The connection timeout in milliseconds. | |
| bool | debug_mode_ {} |
| Flag indicating if debug mode is enabled. | |
| QMap< QString, QKeySequence > | default_shortcuts_ |
| Map storing the default keyboard shortcuts. Key: Action ID (e.g., "MainWindow.OpenSettings"). Value: Default QKeySequence. | |
| QColor | grid_color_ |
| The color for the background grid lines. | |
| int | grid_spacing_ {} |
| The spacing between background grid lines in pixels. | |
| int | keep_alive_interval_ {} |
| The keep-alive interval in milliseconds. | |
| const QString | kShortcutsPrefix = "Shortcuts/" |
| Prefix used for storing shortcut keys within QSettings. | |
| QString | language_code_ |
| The selected language code (e.g., "en", "pl") | |
| int | max_reconnect_attempts_ {} |
| The maximum number of reconnection attempts. | |
| QString | preferred_start_frequency_ |
| The preferred starting frequency for new Wavelengths. | |
| QStringList | recent_colors_ |
| List of recently used colors (hex codes) | |
| QString | relay_server_address_ |
| The address of the relay server. | |
| int | relay_server_port_ {} |
| The port of the relay server. | |
| QSettings | settings_ |
| QSettings object used for reading and writing configuration data. | |
| QMap< QString, QKeySequence > | shortcuts_ |
| Map storing the currently active keyboard shortcuts (loaded from settings or defaults). | |
| QColor | stream_color_ |
| The color used for stream visualization elements. | |
| QColor | title_border_color_ |
| The color for the title label border. | |
| QColor | title_glow_color_ |
| The color for the title label glow effect. | |
| QColor | title_text_color_ |
| The color for the title label text. | |
Static Private Attributes | |
| static WavelengthConfig * | instance_ = nullptr |
| Static pointer to the singleton instance. | |
| static constexpr int | kMaxRecentColors = 5 |
| Maximum number of recently used colors to store. | |
Manages application configuration settings using a singleton pattern.
This class handles loading, saving, and accessing various configuration parameters for the Wavelength application, such as network settings, appearance colors, application behavior limits, and keyboard shortcuts. It uses QSettings for persistence.
|
overridedefault |
Default destructor.
|
delete |
Deleted copy constructor.
|
explicitprivate |
Private constructor to enforce the singleton pattern. Loads default shortcuts, default values, and then saved settings.
| parent | Optional parent QObject. |
| void WavelengthConfig::AddRecentColor | ( | const QColor & | color | ) |
Adds a color to the list of recently used colors. If the color already exists, it's moved to the front. The list is capped at kMaxRecentColors. Emits recentColorsChanged() if the list is modified.
| color | The QColor to add. |
|
signal |
Emitted when a configuration setting changes.
| key | The key of the setting that changed (e.g., "blobColor", "maxChatHistorySize"). Can be "all" if RestoreDefaults() was called. |
|
nodiscard |
Gets a map of all currently configured shortcuts.
|
nodiscard |
Gets the main background color.
|
nodiscard |
Gets the color used for the blob animation.
|
nodiscard |
Gets the connection timeout in milliseconds.
|
nodiscard |
Gets a map of the default shortcuts defined within the application.
|
nodiscard |
Gets the color for the background grid lines.
|
nodiscard |
Gets the spacing between background grid lines in pixels.
|
static |
Gets the singleton instance of the WavelengthConfig.
|
nodiscard |
Gets the keep-alive interval in milliseconds.
|
nodiscard |
Gets the currently configured language code (e.g., "en", "pl").
|
nodiscard |
Gets the maximum number of reconnection attempts.
|
nodiscard |
Gets the preferred starting frequency for new Wavelengths.
|
nodiscard |
Gets the list of recently used colors.
|
nodiscard |
Gets the configured relay server address.
|
nodiscard |
Gets the configured relay server port.
|
nodiscard |
Constructs the full WebSocket URL for the relay server.
|
nodiscard |
Gets a configuration setting value by its key. This provides a generic way to access settings, primarily for UI elements.
| key | The string key identifying the setting (e.g., "relayServerPort", "backgroundColor"). |
|
nodiscard |
Gets the configured keyboard shortcut for a specific action. If no shortcut is configured for the action_id, it returns the default_sequence. If default_sequence is empty, it looks up the default in the internal default map.
| action_id | The identifier of the action (e.g., "MainWindow.OpenSettings"). |
| default_sequence | An optional fallback sequence if the action_id is not found. |
|
nodiscard |
Gets the color used for stream visualization elements.
|
nodiscard |
Gets the color for the title label border.
|
nodiscard |
Gets the color for the title label glow effect.
|
nodiscard |
Gets the color for the title label text.
|
nodiscard |
Checks if debug mode is enabled.
|
private |
Loads the hardcoded default values for all settings into the member variables. Also copies the default shortcuts map to the current shortcuts map.
|
private |
Loads the hardcoded default keyboard shortcuts into the default_shortcuts_ map.
|
private |
Loads settings from the persistent storage (QSettings) into the member variables, overwriting the defaults if values exist in storage.
|
delete |
Deleted assignment operator.
|
signal |
Emitted when the list of recent colors changes (a color was added).
| void WavelengthConfig::RestoreDefaults | ( | ) |
Restores all configuration settings to their default values. Also clears saved shortcuts in persistent storage and saves the defaults. Emits configChanged("all") and recentColorsChanged().
| void WavelengthConfig::SaveSettings | ( | ) |
Saves all current configuration settings to persistent storage (QSettings).
| void WavelengthConfig::SetBackgroundColor | ( | const QColor & | color | ) |
Sets the main background color. Adds the color to recent colors. Emits configChanged("background_color") if the value changes and is valid.
| color | The new background color. |
| void WavelengthConfig::SetBlobColor | ( | const QColor & | color | ) |
Sets the color for the blob animation. Adds the color to recent colors. Emits configChanged("blob_color") if the value changes and is valid.
| color | The new blob color. |
| void WavelengthConfig::SetConnectionTimeout | ( | int | timeout | ) |
Sets the connection timeout in milliseconds. Emits configChanged("connectionTimeout") if the value changes and is positive.
| timeout | The new connection timeout. |
| void WavelengthConfig::SetDebugMode | ( | bool | enabled | ) |
Enables or disables debug mode. Emits configChanged("debugMode") if the value changes.
| enabled | True to enable debug mode, false to disable. |
| void WavelengthConfig::SetGridColor | ( | const QColor & | color | ) |
Sets the color for the background grid lines. Adds the color to recent colors. Emits configChanged("grid_color") if the value changes and is valid.
| color | The new grid color. |
| void WavelengthConfig::SetGridSpacing | ( | int | spacing | ) |
Sets the spacing between background grid lines. Emits configChanged("grid_spacing") if the value changes and is positive.
| spacing | The new grid spacing in pixels. |
| void WavelengthConfig::SetKeepAliveInterval | ( | int | interval | ) |
Sets the keep-alive interval in milliseconds. Emits configChanged("keepAliveInterval") if the value changes and is positive.
| interval | The new keep-alive interval. |
| void WavelengthConfig::SetLanguageCode | ( | const QString & | code | ) |
Sets the application language code. Emits configChanged("languageCode") if the value changes. Note: Requires application restart to take full effect.
| code | The new language code (e.g., "en", "pl"). |
| void WavelengthConfig::SetMaxReconnectAttempts | ( | int | attempts | ) |
Sets the maximum number of reconnection attempts. Emits configChanged("maxReconnectAttempts") if the value changes and is non-negative.
| attempts | The new maximum number of attempts. |
| void WavelengthConfig::SetPreferredStartFrequency | ( | const QString & | frequency | ) |
Sets the preferred starting frequency. Validates that the frequency is a number >= 130.0. Normalizes to one decimal place. Emits configChanged("preferredStartFrequency") if the normalized value changes.
| frequency | The desired frequency as a string. |
| void WavelengthConfig::SetRelayServerAddress | ( | const QString & | address | ) |
Sets the relay server address. Emits configChanged("relayServerAddress") if the value changes.
| address | The new relay server address. |
| void WavelengthConfig::SetRelayServerPort | ( | int | port | ) |
Sets the relay server port. Emits configChanged("relayServerPort") if the value changes.
| port | The new relay server port. |
| void WavelengthConfig::SetShortcut | ( | const QString & | action_id, |
| const QKeySequence & | sequence ) |
Sets the keyboard shortcut for a specific action. This updates the internal map; SaveSettings() must be called to persist the change.
| action_id | The identifier of the action. |
| sequence | The new QKeySequence. |
| void WavelengthConfig::SetStreamColor | ( | const QColor & | color | ) |
Sets the color for stream visualization elements. Adds the color to recent colors. Emits configChanged("stream_color") if the value changes and is valid.
| color | The new stream color. |
| void WavelengthConfig::SetTitleBorderColor | ( | const QColor & | color | ) |
Sets the color for the title label border. Adds the color to recent colors. Emits configChanged("title_border_color") if the value changes and is valid.
| color | The new title border color. |
| void WavelengthConfig::SetTitleGlowColor | ( | const QColor & | color | ) |
Sets the color for the title label glow effect. Adds the color to recent colors. Emits configChanged("title_glow_color") if the value changes and is valid.
| color | The new title glow color. |
| void WavelengthConfig::SetTitleTextColor | ( | const QColor & | color | ) |
Sets the color for the title label text. Adds the color to recent colors. Emits configChanged("title_text_color") if the value changes and is valid.
| color | The new title text color. |
|
private |
The main background color of the application.
|
private |
The color used for the blob animation.
|
private |
The connection timeout in milliseconds.
|
private |
Flag indicating if debug mode is enabled.
|
private |
Map storing the default keyboard shortcuts. Key: Action ID (e.g., "MainWindow.OpenSettings"). Value: Default QKeySequence.
|
private |
The color for the background grid lines.
|
private |
The spacing between background grid lines in pixels.
|
staticprivate |
Static pointer to the singleton instance.
|
private |
The keep-alive interval in milliseconds.
|
staticconstexprprivate |
Maximum number of recently used colors to store.
|
private |
Prefix used for storing shortcut keys within QSettings.
|
private |
The selected language code (e.g., "en", "pl")
|
private |
The maximum number of reconnection attempts.
|
private |
The preferred starting frequency for new Wavelengths.
|
private |
List of recently used colors (hex codes)
|
private |
The address of the relay server.
|
private |
The port of the relay server.
|
private |
QSettings object used for reading and writing configuration data.
|
private |
Map storing the currently active keyboard shortcuts (loaded from settings or defaults).
Key: Action ID.
Value: Current QKeySequence.
|
private |
The color used for stream visualization elements.
|
private |
The color for the title label border.
|
private |
The color for the title label glow effect.
|
private |
The color for the title label text.