game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
settings_controller.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// settings_controller.h
4// ==============================================================================
5// Controller for application settings - UI-agnostic business logic
6// Manages app configuration, defaults, and persistence
7// ==============================================================================
8
9#pragma once
10
11#include <functional>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace core
17{
18
19// ==============================================================================
20// Application Settings - General preferences
21// ==============================================================================
22
24{
25 bool autoScan = true; // Auto-scan for new games on startup
26 bool notifications = true; // Show desktop notifications
27 bool startMinimized = false; // Start minimized to tray
28 bool minimizeToTray = true; // Minimize to tray on close (false = actually exit)
29 bool confirmDelete = true; // Confirm before deleting games
30 bool steamMinimized = true; // Pass `-silent` when *we* start Steam (no
31 // foreground popup on cold-start). Has no
32 // effect when Steam is already running —
33 // per ValveSoftware/steam-for-linux #1983,
34 // a second `steam -silent` invocation is
35 // IPC'd to the existing instance and the
36 // flag is ignored (no reliable CLI way to
37 // hide an already-visible Steam window).
38 bool autoApplyDefaults = false; // Auto-apply default config to new Steam imports
39 bool useSteamLaunchByDefault = true; // Route Steam games via "steam -applaunch"
40 // by default so the Steam overlay,
41 // achievements, and cloud saves work.
42 // Per-game runnerConfig.useSteamLaunch
43 // can still force it on; turning this
44 // off restores direct-Proton launches
45 // (full env-var control, no overlay).
46 bool isolateMangoHudLogs = true; // Write per-game MangoHud CSV logs and our
47 // generated launch configs under
48 // ${XDG_STATE_HOME:-$HOME/.local/state}/
49 // gamelauncher/mangohud-logs/ (per the
50 // XDG Base Directory Spec, which lists
51 // logs as appropriate $XDG_STATE_HOME
52 // content). Otherwise the user's
53 // ~/.config/MangoHud/MangoHud.conf
54 // output_folder is used — required if
55 // they want goverlay's Logs analysis tab
56 // to find them, but pollutes $HOME.
57 bool silentSteamSync = true; // Silent Steam sync (no popup, just background sync)
58 bool showToolbarGameStatus = true; // Show running game status in toolbar
59 bool toolbarLocked = false; // Lock toolbar (prevent drag reordering)
60 int toolbarSearchWidth = 150; // Width of toolbar search field (80-300)
61 int toolbarZoomWidth = 50; // Width of toolbar zoom slider (30-100)
62 std::string toolbarSectionOrder; // Comma-separated list of toolbar section IDs
63 std::string defaultRunner; // Default runner for new games (e.g., "proton-cachyos")
64
65 // Theme settings
66 std::string themeId = "system"; // Current theme ID (default: follows system)
67 std::string customAccentColor; // Hex color if custom accent (empty = theme default)
68 int uiZoom = 100; // UI zoom percentage (75-150, default 100)
69 std::string fontFamily; // Custom font family (empty = system default)
70
71 // Gaming layout settings - auto-adjust UI when a game is running
72 bool autoSwitchToRunningGame = true; // Auto-switch to details panel when game starts
73 bool autoGamingLayout = false; // Auto-resize window for gaming layout when game starts
74 int gamingLayoutWidthPercent = 25; // Window width as % of screen (10-50%)
75 int gamingLayoutEdge = 0; // 0=left edge, 1=right edge, 2=keep position
76 bool gamingLayoutFullHeight = true; // Use full screen height during gaming mode
77 bool restoreLayoutOnExit = true; // Restore previous layout when game exits
78
79 // Game scanning
80 std::string customScanDirectories; // Semicolon-separated list of custom game scan directories
81 int gameLaunchTimeoutSeconds = 30; // Timeout in seconds for game launch (1-300)
82
83 // Home Assistant integration
84 bool enableHomeAssistant = false; // Enable HA panel (toolbar button + panel)
85 std::string homeAssistantUrl; // HA URL (empty = use panel's stored URL)
86
87 // Panel visibility state (persisted across sessions)
88 bool panelSidebarVisible = false;
89 bool panelGamesVisible = false;
90 bool panelDetailsVisible = false;
91 bool panelMonitorVisible = false;
92 bool panelHAVisible = false;
93 std::string splitterSizes; // Comma-separated splitter sizes (e.g., "200,700,400")
94
95 // Window layout persistence — if rememberWindowLayout is true, the launcher
96 // restores the user's last window geometry, view mode, and sidebar
97 // selection on startup. Per Qt docs, QMainWindow::saveGeometry/saveState
98 // return opaque QByteArrays we round-trip through Base64 strings (the
99 // settings file is JSON; QByteArray::toBase64 yields ASCII-safe text).
101 std::string windowGeometry; // Base64 of QMainWindow::saveGeometry()
102 std::string windowState; // Base64 of QMainWindow::saveState() (toolbars/docks)
103 int lastViewMode = 0; // 0=List, 1=Grid, 2=Compact
104 int lastSidebarCategory = 0; // sidebar category list row (matches order in setupSidebar)
105
106 // Default library view applied on startup. -1 means "use whatever was
107 // shown last session" (lastSidebarCategory). Otherwise the value is a
108 // sidebar category index (0=All, 1=Favorites, 2=Recently Played,
109 // 3=Installed, 4=Not Installed, 5=Updates Available, 6=Running).
111};
112
113// ==============================================================================
114// Settings Events
115// ==============================================================================
116
118{
119 std::string section; // Which section changed: "app" or "defaults"
120 std::string key; // Specific key that changed (empty = multiple)
121};
122
123// ==============================================================================
124// SettingsController
125// ==============================================================================
126
128{
129 public:
130 using OnSettingsChanged = std::function<void(const SettingsChangedEvent&)>;
131 using OnSettingsSaved = std::function<void()>;
132 using OnSettingsLoaded = std::function<void()>;
133
136
137 // Non-copyable, movable
142
143 // =========================================================================
144 // Load/Save
145 // =========================================================================
146
147 /// Load settings from disk
148 bool loadSettings();
149
150 /// Save settings to disk
151 bool saveSettings();
152
153 /// Reset all settings to defaults
154 void resetToDefaults();
155
156 /// Check if settings have unsaved changes
157 bool hasUnsavedChanges() const;
158
159 // =========================================================================
160 // Getters
161 // =========================================================================
162
163 /// Get application settings (returns copy for thread safety)
165
166 /// Read just `useSteamLaunchByDefault` directly from the settings file.
167 /// Used by code paths (e.g. core/src/models/game_process.cpp) that don't
168 /// own a SettingsController instance. Reads disk every call — fine because
169 /// game launches are infrequent.
171
172 /// Read just `isolateMangoHudLogs` directly from the settings file. Used
173 /// by MangoHudLogReader::getDefaultLogDirectory(), which is called from
174 /// static contexts that don't have a SettingsController instance.
176
177 /// Read just `steamMinimized` directly from the settings file. Used by
178 /// GameProcess::ensureSteamRunning() to decide whether to pass `-silent`
179 /// when starting Steam.
180 static bool readSteamMinimizedFromDisk();
181
182 // =========================================================================
183 // Setters (trigger change notifications)
184 // =========================================================================
185
186 /// Set application settings
187 void setAppSettings(const AppSettings& settings);
188
189 // =========================================================================
190 // Individual Setting Accessors - App Settings
191 // =========================================================================
192
193 bool isAutoScanEnabled() const;
194 void setAutoScanEnabled(bool enabled);
195
196 bool areNotificationsEnabled() const;
197 void setNotificationsEnabled(bool enabled);
198
199 bool isStartMinimizedEnabled() const;
200 void setStartMinimizedEnabled(bool enabled);
201
202 bool isMinimizeToTrayEnabled() const;
203 void setMinimizeToTrayEnabled(bool enabled);
204
205 bool isConfirmDeleteEnabled() const;
206 void setConfirmDeleteEnabled(bool enabled);
207
208 bool isSteamMinimizedEnabled() const;
209 void setSteamMinimizedEnabled(bool enabled);
210
211 bool isAutoApplyDefaultsEnabled() const;
212 void setAutoApplyDefaultsEnabled(bool enabled);
213
214 bool isSilentSteamSyncEnabled() const;
215 void setSilentSteamSyncEnabled(bool enabled);
216
217 std::string getDefaultRunner() const;
218 void setDefaultRunner(const std::string& runner);
219
220 std::string getCustomScanDirectories() const;
221 void setCustomScanDirectories(const std::string& dirs);
222
223 int getGameLaunchTimeout() const;
224 void setGameLaunchTimeout(int seconds);
225
226 // =========================================================================
227 // Path Helpers
228 // =========================================================================
229
230 /// Get the settings file path
231 std::string getSettingsFilePath() const;
232
233 /// Get application data directory
234 std::string getDataDirectory() const;
235
236 /// Get available Proton versions
237 std::vector<std::string> getAvailableProtonVersions() const;
238
239 /// Get available Wine versions
240 std::vector<std::string> getAvailableWineVersions() const;
241
242 // =========================================================================
243 // Event Subscriptions
244 // =========================================================================
245
247 void setOnSettingsSaved(OnSettingsSaved callback);
249
250 private:
251 class Impl;
252 std::unique_ptr<Impl> impl_;
253};
254
255} // namespace core
void setOnSettingsSaved(OnSettingsSaved callback)
void setConfirmDeleteEnabled(bool enabled)
std::function< void()> OnSettingsSaved
SettingsController(SettingsController &&) noexcept
AppSettings getAppSettings() const
Get application settings (returns copy for thread safety).
std::string getDataDirectory() const
Get application data directory.
std::vector< std::string > getAvailableProtonVersions() const
Get available Proton versions.
void setAutoApplyDefaultsEnabled(bool enabled)
void resetToDefaults()
Reset all settings to defaults.
bool saveSettings()
Save settings to disk.
std::string getDefaultRunner() const
void setStartMinimizedEnabled(bool enabled)
SettingsController(const SettingsController &)=delete
std::vector< std::string > getAvailableWineVersions() const
Get available Wine versions.
bool hasUnsavedChanges() const
Check if settings have unsaved changes.
std::function< void(const SettingsChangedEvent &)> OnSettingsChanged
void setOnSettingsChanged(OnSettingsChanged callback)
std::function< void()> OnSettingsLoaded
void setSteamMinimizedEnabled(bool enabled)
void setAppSettings(const AppSettings &settings)
Set application settings.
std::string getSettingsFilePath() const
Get the settings file path.
static bool readSteamMinimizedFromDisk()
Read just steamMinimized directly from the settings file.
bool loadSettings()
Load settings from disk.
SettingsController & operator=(const SettingsController &)=delete
void setOnSettingsLoaded(OnSettingsLoaded callback)
static bool readUseSteamLaunchByDefaultFromDisk()
Read just useSteamLaunchByDefault directly from the settings file.
void setSilentSteamSyncEnabled(bool enabled)
void setCustomScanDirectories(const std::string &dirs)
std::string getCustomScanDirectories() const
void setAutoScanEnabled(bool enabled)
void setDefaultRunner(const std::string &runner)
static bool readIsolateMangoHudLogsFromDisk()
Read just isolateMangoHudLogs directly from the settings file.
void setNotificationsEnabled(bool enabled)
void setMinimizeToTrayEnabled(bool enabled)
std::string toolbarSectionOrder
std::string customScanDirectories
std::string customAccentColor