game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/mainwindow.h
4// ==============================================================================
5// Main application window for Qt UI with list/grid view support
6// ==============================================================================
7
8#pragma once
9
14#include "models/game.h"
15
16#include <QAction>
17#include <QActionGroup>
18#include <QComboBox>
19#include <QDragEnterEvent>
20#include <QDropEvent>
21#include <QHBoxLayout>
22#include <QLabel>
23#include <QLineEdit>
24#include <QListView>
25#include <QListWidget> // still used for sidebar (categoryList_, sourceFilterList_, etc.)
26#include <QMainWindow>
27#include <QMenu>
28#include <QMimeData>
29#include <QProgressBar>
30#include <QPushButton>
31#include <QResizeEvent>
32#include <QSlider>
33#include <QSplitter>
34#include <QStackedWidget>
35#include <QStyledItemDelegate>
36#include <QSystemTrayIcon>
37#include <QToolButton>
38#include <atomic>
39#include <memory>
40
41// Forward declarations
43class GameListModel;
53class CommandPalette;
55class DetailsPanelManager; // MED-7 extraction
56class ToolbarManager; // Toolbar extraction 2026-04-19
57class SidebarManager; // Sidebar extraction 2026-04-19
58class MenuBarManager; // MenuBar extraction 2026-04-19
59class GameActionFactory; // Shared per-game action builder 2026-04-19
60class ContextMenuManager; // Context menu extraction 2026-04-19
61class ShortcutsController; // Shortcut + palette registration 2026-04-19
63#ifdef HAVE_QTERMWIDGET
64class TerminalPanel;
65#endif
66#ifdef HAVE_WEBENGINE
68#endif
69
70// ==============================================================================
71// View Mode Enumeration
72// ==============================================================================
73
74enum class ViewMode
75{
79};
80
81// ==============================================================================
82// Sort Options
83// ==============================================================================
84
96
97// ==============================================================================
98// MainWindow Class
99// ==============================================================================
100
101class MainWindow : public QMainWindow
102{
103 Q_OBJECT
104
105 // Friend class — owns the 1,017 LoC of keyboard shortcut / command
106 // palette registration extracted from MainWindow. The coupling is
107 // inherent (every shortcut and palette command operates on window
108 // state), so the helper gets private access rather than a public
109 // API surface.
111
112 public:
113 explicit MainWindow(QWidget* parent = nullptr);
114 ~MainWindow() override;
115
116 void setNotificationService(std::shared_ptr<QtNotificationService> service);
117
118 protected:
119 void closeEvent(QCloseEvent* event) override;
120 void resizeEvent(QResizeEvent* event) override;
121 void changeEvent(QEvent* event) override; // Handle minimize/restore for timer management
122 bool eventFilter(QObject* obj, QEvent* event) override; // Handle clicks on notes label
123 void dragEnterEvent(QDragEnterEvent* event) override; // Accept executable file drops
124 void dropEvent(QDropEvent* event) override; // Handle dropped executable files
125
126 private slots:
127 // Selection handler wired to QItemSelectionModel::currentChanged on the proxy.
128 void onGameSelected(const QModelIndex& current, const QModelIndex& previous);
129 void onLaunchClicked();
130 void onStopClicked();
131 void onSearchTextChanged(const QString& text);
132 void onAddGameClicked();
133 void onSettingsClicked();
134 void onRefreshLibrary();
135 void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
136
137 // View mode
138 void onViewModeChanged(ViewMode mode);
139 void onSortChanged(int index);
140 void onZoomChanged(int value);
141
142 // Steam download progress
143 void onSteamDownloadProgress(uint32_t appId, double progress, const QString& status);
144 void onSteamInstallComplete(uint32_t appId);
145 void onSteamUninstallComplete(uint32_t appId, uint32_t previousState);
146
147 // Async image loading
148 void onAsyncImageLoaded(const QString& cacheKey, const QPixmap& pixmap);
149
150 private:
151 void setupUI();
152 void setupMenuBar();
153 void setupToolBar();
154 void setupSidebar();
155 void setupGameList();
156 void setupGameListContextMenu();
157 void setupStatusBar();
158 void setupTrayIcon();
159 void setupControllerCallbacks();
160 void setupSteamDownloadMonitor();
161 void setupCommandPalette();
162 void registerPaletteCommands();
163
164 void refreshGameList();
165 void applyViewMode();
166 void updateGridIconSize();
167 void setupKeyboardShortcuts();
168 void applyTheme();
169 void deleteSelectedGame();
170 void toggleSelectedFavorite();
171 // Returns the source-model row for `gameId` (-1 if not in the model).
172 int rowForGameId(const std::string& gameId) const;
173 // Maps a source-model row to a proxy index (or invalid if filtered out).
174 QModelIndex proxyIndexForGameId(const std::string& gameId) const;
175 // Ask the model to repaint the row for a given game (data changed).
176 void updateGameRow(const std::string& gameId);
177 void populateRunnerVersions();
178 void updateCollectionsList(); // Refresh collections sidebar list
179 void showCreateCollectionDialog(); // Show dialog to create new collection
180 void updateSourceFilters(); // Update source filter list based on available games
181 void updateCategoryCounts(); // Update category list with game counts
182 void syncSteamInstalledStatus(); // Sync Steam installed status from appmanifests
183 void fetchMissingProtonDB(); // Fetch ProtonDB data for Steam games with stale/missing data
184 void
185 updateItemIcons(); // Update all item icons to current zoom level (faster than refreshGameList)
186
187 // Menu mode management
188 void updateMenuMode(); // Toggle between menu bar and hamburger based on setting
189
190 // Panel management
191 void togglePanel(QWidget* panel, QPushButton* btn, const QString& name);
192 void popOutPanel(QWidget* panel, QWidget*& poppedWindow, const QString& title, int width,
193 int height);
194 void updateToolbarVisibility(); // Show/hide controls based on visible panels
195 void updateRunningGameStatus(); // Update toolbar status widget for running games
196 QWidget* createPanelContainer(QWidget* content, const QString& title, QWidget*& poppedWindow,
197 int popWidth, int popHeight); // Wrap panel with title bar
198 void movePanelLeft(QWidget* container); // Move panel left in splitter
199 void movePanelRight(QWidget* container); // Move panel right in splitter
200
201 // Controllers
202 std::unique_ptr<core::GameLibraryController> libraryController_;
203 std::unique_ptr<core::LaunchController> launchController_;
204 std::unique_ptr<core::SettingsController> settingsController_;
205
206 // Performance profile service
207 std::unique_ptr<PerformanceProfileService> performanceProfileService_;
208
209 // Steam download monitoring
210 std::unique_ptr<SteamDownloadMonitor> steamDownloadMonitor_;
211
212 // Notification service
213 std::shared_ptr<QtNotificationService> notificationService_;
214
215 // Async image loading (offloads image I/O and scaling to background threads)
216 AsyncImageLoader* imageLoader_ = nullptr;
217
218 // UI Components
219 QSplitter* mainSplitter_;
220
221 // Panel containers (wraps content with title bars)
222 QWidget* sidebarContainer_ = nullptr;
223 QWidget* gameListContainer_ = nullptr;
224 QWidget* detailsContainer_ = nullptr;
225#ifdef HAVE_QTERMWIDGET
226 QWidget* terminalContainer_ = nullptr;
227#endif
228#ifdef HAVE_WEBENGINE
229 QWidget* haContainer_ = nullptr;
230#endif
231
232 // Sidebar widget root — owned by SidebarManager; aliased here for the
233 // panel container / splitter wiring. The four filter lists are no
234 // longer exposed; MainWindow reads their state via sidebarManager_
235 // semantic accessors (selectedCategoryIndex(), selectedSourceValue(),
236 // selectedRunnerVersion(), selectedCollection()) and mutates selection
237 // via selectCategoryByRow() / selectCategoryByText() /
238 // clearCollectionsSelection().
239 QWidget* sidebar_ = nullptr;
240 QListView* gameList_; // main library view (MED-6)
241 GameListModel* gameListModel_ = nullptr; // source-of-truth for gameList_
242 GameListProxyModel* gameListProxy_ = nullptr; // filter/sort proxy over gameListModel_
243 QWidget* gameListEmptyOverlay_ = nullptr; // empty-state overlay (first-run / no-results)
244 QLabel* emptyStateLabel_ = nullptr;
245 QPushButton* emptyStateAddButton_ = nullptr;
246 QPushButton* emptyStateImportButton_ = nullptr;
247 QPushButton* emptyStateClearSearchButton_ = nullptr;
248 QPushButton* emptyStateShowAllButton_ = nullptr;
249 GameListDelegate* gameListDelegate_;
250
251 // Details panel (MED-7 extraction). All widget trees, rendering, and
252 // running-game refresh logic live inside DetailsPanelManager; MainWindow
253 // holds a raw alias to the panel widget for splitter/layout wiring.
254 std::unique_ptr<DetailsPanelManager> detailsPanelManager_;
255 QWidget* detailsPanel_ = nullptr; // alias of detailsPanelManager_->widget()
256
257 // Toolbar widgets — owned by ToolbarManager. These are raw alias pointers
258 // populated after toolbarManager_->setupToolbar() returns so that existing
259 // call sites (keyboard shortcuts, command palette, gaming-layout state
260 // machine, etc.) continue to compile without threading the manager
261 // everywhere.
262 QLineEdit* searchEdit_ = nullptr;
263 QComboBox* sortCombo_ = nullptr;
264 QSlider* zoomSlider_ = nullptr;
265 QLabel* zoomLabel_ = nullptr;
266 int zoomLevel_ = 100; // Zoom percentage (50-200)
267 QLabel* statusLabel_;
268 QSystemTrayIcon* trayIcon_;
269
270 // Game ID → source-model row cache was the QListWidget era; replaced by
271 // GameListModel::rowForGameId() which keeps its own map. Kept member-less
272 // here intentionally. MED-6.
273 void invalidateGameItemCache(); // Called when list is cleared/rebuilt
274
275 // Image caching (thumbnails, heroes, path validation) — MED-7 extraction.
276 // Owned by MainWindow so it lives as long as the window. Pointer-form so
277 // we don't need GameThumbnailCache's full declaration in this header.
278 std::unique_ptr<GameThumbnailCache> imageCache_;
279
280 // Shutdown flag for background tasks - set in destructor to stop async operations
281 std::atomic<bool> isShuttingDown_{false};
282
283 // Game list refresh debounce (consolidates rapid refreshGameList() calls)
284 QTimer* refreshDebounceTimer_ = nullptr;
285 void scheduleRefresh(); // Call this instead of refreshGameList() for debounced updates
286
287 // (Search and zoom debounce timers moved into ToolbarManager.)
288 void applyZoomChange(); // Called after ToolbarManager's zoom signal to apply zoom
289
290 // Resize debounce timer (prevents expensive layout during resize drag)
291 QTimer* resizeDebounceTimer_ = nullptr;
292
293 // Frame metrics update timer (for live FPS display while game is running)
294 QTimer* frameMetricsTimer_ = nullptr;
295
296 // (disk-space cache moved to DetailsPanelManager in MED-7 extraction)
297
298 // Status bar progress indicator
299 QProgressBar* statusProgressBar_ = nullptr;
300
301 // View-mode actions owned by ToolbarManager; held here as raw aliases
302 // because the command palette and keyboard shortcuts toggle their
303 // checked state directly.
304 QAction* listViewAction_ = nullptr;
305 QAction* gridViewAction_ = nullptr;
306 QAction* compactViewAction_ = nullptr;
307 QActionGroup* viewModeGroup_ = nullptr;
308
309 // Menu bar menus are owned by MenuBarManager (extracted 2026-04-19);
310 // MainWindow no longer holds pointers to File/Game/View/Tools/Help.
311
312 // Tray menu (independent of the toolbar)
313 QMenu* trayMenu_ = nullptr;
314
315#ifdef HAVE_QTERMWIDGET
316 // Terminal panel for btop++ — owned by MainWindow, controlled by toolbar signals.
317 TerminalPanel* terminalPanel_ = nullptr;
318 QAction* toggleTerminalAction_ = nullptr;
319
320 // Raw aliases to toolbar widgets (owned by ToolbarManager).
321 QComboBox* monitorTypeCombo_ = nullptr;
322 QPushButton* monitorRestartBtn_ = nullptr;
323#endif
324
325#ifdef HAVE_WEBENGINE
326 // Home Assistant embedded panel (MainWindow-owned). The toolbar button is
327 // a raw alias to the widget owned by ToolbarManager.
328 HomeAssistantPanel* haPanel_ = nullptr;
329 QPushButton* panelHABtn_ = nullptr;
330 bool savedHAVisible_ = false;
331#endif
332
333 // Panel toggle buttons — raw aliases to toolbar widgets owned by ToolbarManager.
334 QPushButton* panelSidebarBtn_ = nullptr;
335 QPushButton* panelGamesBtn_ = nullptr;
336 QPushButton* panelDetailsBtn_ = nullptr;
337#ifdef HAVE_QTERMWIDGET
338 QPushButton* panelMonitorBtn_ = nullptr;
339#endif
340
341 // Running-game status widget — raw alias to the widget owned by ToolbarManager.
342 RunningGameStatusWidget* runningGameStatusWidget_ = nullptr;
343
344 // Draggable toolbar — raw alias to the widget owned by ToolbarManager.
345 DraggableToolbar* draggableToolbar_ = nullptr;
346
347 // Toolbar manager (owns the widget tree; MainWindow wires its signals).
348 std::unique_ptr<ToolbarManager> toolbarManager_;
349
350 // Sidebar manager (owns the four filter lists + collection CRUD).
351 std::unique_ptr<SidebarManager> sidebarManager_;
352
353 // MenuBar manager (owns the File/Game/View/Tools/Help menus).
354 std::unique_ptr<MenuBarManager> menuBarManager_;
355
356 // Shared per-game action factory. Builds the Launch/Configure/
357 // Quick Settings/Favorite/Collections/Artwork/ProtonDB/Folder/Steam/
358 // Remove actions for both the menu-bar Game menu and the game-list
359 // context menu so the two no longer diverge.
360 std::unique_ptr<GameActionFactory> gameActionFactory_;
361
362 // Context menu manager — owns the customContextMenuRequested handler
363 // on the games list. Uses GameActionFactory for shared actions and
364 // keeps Uninstall / Verify / Copy to Clipboard / multi-select inline.
365 std::unique_ptr<ContextMenuManager> contextMenuManager_;
366
367 // Shortcuts controller — owns keyboard-shortcut + command-palette
368 // registration (extracted from setupKeyboardShortcuts() and
369 // registerPaletteCommands()).
370 std::unique_ptr<ShortcutsController> shortcutsController_;
371
372 // Pop-out windows for panels
373 QWidget* poppedSidebar_ = nullptr;
374 QWidget* poppedGameList_ = nullptr;
375 QWidget* poppedDetails_ = nullptr;
376#ifdef HAVE_QTERMWIDGET
377 QWidget* poppedMonitor_ = nullptr;
378#endif
379#ifdef HAVE_WEBENGINE
380 QWidget* poppedHA_ = nullptr;
381#endif
382
383 // Command Palette (Ctrl+Shift+P)
384 CommandPalette* commandPalette_ = nullptr;
385
386 // State
387 std::string selectedGameId_;
388 std::string currentFilter_;
389 std::string currentCollection_; // Currently selected collection filter (empty = none)
390 int currentCategory_ = 0;
391 ViewMode currentViewMode_ = ViewMode::List;
392 SortOption currentSort_ = SortOption::NameAsc;
393 bool forceQuit_ = false; // Set true when Exit is clicked from tray to bypass minimize-to-tray
394
395 // Gaming layout state
396 std::string previousRunningGameId_; // Track previous running game for start/stop detection
397 QRect savedNormalGeometry_; // Window geometry before gaming layout
398 bool isInGamingLayout_ = false; // Currently in gaming layout mode
399 bool gamingLayoutOverridden_ =
400 false; // User manually overrode gaming layout - don't auto-restore
401
402 // Saved panel state for gaming layout restoration
403 QList<int> savedSplitterSizes_; // Splitter sizes before gaming layout
404 bool savedSidebarVisible_ = true; // Sidebar visibility before gaming layout
405 bool savedGameListVisible_ = true; // Game list visibility before gaming layout
406 bool savedDetailsVisible_ = true; // Details visibility before gaming layout
407 bool savedMonitorVisible_ = false; // Monitor visibility before gaming layout
408
409 // Gaming layout management
410 void onGameStarted(const std::string& gameId); // Called when game starts running
411 void onGameStopped(const std::string& gameId); // Called when game stops running
412 void enterGamingLayout(); // Switch to compact gaming layout
413 void exitGamingLayout(); // Restore normal layout
414 void checkRunningGameOnStartup(); // Check for already-running games at startup
415
416 // Grid view settings
417 static constexpr int GRID_ICON_WIDTH = 150;
418 static constexpr int GRID_ICON_HEIGHT = 225;
419 static constexpr int COMPACT_ICON_SIZE = 48;
420};
Async image loader using QThreadPool.
Modal dialog providing fuzzy-searchable command list.
void closeEvent(QCloseEvent *event) override
~MainWindow() override
void changeEvent(QEvent *event) override
void dragEnterEvent(QDragEnterEvent *event) override
friend class ShortcutsController
Definition mainwindow.h:110
MainWindow(QWidget *parent=nullptr)
void resizeEvent(QResizeEvent *event) override
void setNotificationService(std::shared_ptr< QtNotificationService > service)
bool eventFilter(QObject *obj, QEvent *event) override
void dropEvent(QDropEvent *event) override
Service for managing per-game performance profiles.
Compact widget showing running game status in the toolbar.
Terminal panel widget that embeds a terminal emulator.
ViewMode
Definition mainwindow.h:75
SortOption
Definition mainwindow.h:86
@ RecentlyAddedAsc
Definition mainwindow.h:94
@ RecentlyAddedDesc
Definition mainwindow.h:93