game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
env_var_mapping.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// env_var_mapping.h
4// ==============================================================================
5// Centralized mapping between UI checkboxes and environment variables
6// Eliminates hardcoded if-else chains in load/save methods
7// ==============================================================================
8
9#pragma once
10
11#include <QString>
12#include <functional>
13#include <map>
14#include <string>
15#include <vector>
16
17class EnvVarCheckBox;
18
19/**
20 * @struct EnvVarMapping
21 * @brief Maps a checkbox to its corresponding environment variable
22 *
23 * This struct enables data-driven management of environment variable checkboxes,
24 * replacing hundreds of lines of if-else chains with a simple loop over mappings.
25 */
27{
28 QString envKey; // Environment variable name (e.g., "WINENTSYNC")
29 QString envValue; // Value when enabled (e.g., "1")
30 EnvVarCheckBox** checkbox; // Pointer to the checkbox member pointer
31 bool* boolFlag; // Optional: pointer to runnerConfig bool (nullptr if none)
32
33 // Helper to check if this env var is set in a map
34 bool isSetIn(const std::map<std::string, std::string>& envVars) const
35 {
36 auto it = envVars.find(envKey.toStdString());
37 return it != envVars.end() && it->second == envValue.toStdString();
38 }
39};
40
41/**
42 * @class EnvVarMappingRegistry
43 * @brief Registry of all environment variable mappings for the config dialog
44 *
45 * Provides centralized access to checkbox-to-envvar mappings.
46 * Usage:
47 * for (const auto& m : EnvVarMappingRegistry::getMappings()) {
48 * (*m.checkbox)->setChecked(m.isSetIn(envVars));
49 * }
50 */
52{
53 public:
54 // Get all registered mappings
55 // Note: This returns mappings with checkbox pointers that need to be set
56 // after the dialog creates its widgets
57 static const std::vector<EnvVarMapping>& getBaseMappings();
58
59 // Environment variable keys that have dedicated UI controls
60 // (used to filter these out of the custom env var table)
61 static const std::vector<QString>& getHandledEnvVarKeys();
62
63 // Check if an env var key is handled by a dedicated checkbox
64 static bool isHandledEnvVar(const QString& key);
65 static bool isHandledEnvVar(const std::string& key);
66};
Checkbox that shows the associated environment variable.
Registry of all environment variable mappings for the config dialog.
static bool isHandledEnvVar(const QString &key)
static const std::vector< EnvVarMapping > & getBaseMappings()
static const std::vector< QString > & getHandledEnvVarKeys()
Maps a checkbox to its corresponding environment variable.
bool isSetIn(const std::map< std::string, std::string > &envVars) const
EnvVarCheckBox ** checkbox