game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_action_factory.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// ui/qt/game_action_factory.h
4// ==============================================================================
5// Shared factory for per-game QActions. Two call sites used to duplicate
6// ~250 LoC of identical action construction — MenuBarManager's dynamic
7// Game menu and MainWindow's game-list context menu — so this factory
8// owns the single source of truth for:
9//
10// Launch / Stop / Install-via-Steam (conditional on game state)
11// Configure ... (launches GameConfigDialog)
12// Quick Settings submenu (MangoHud / GameMode / Gamescope / VkBasalt)
13// Favorite toggle
14// Collections submenu (per-game add/remove + "Create New...")
15// Change Artwork... (SteamGridDBSelectorDialog)
16// View on ProtonDB (steam://... handled by QDesktopServices)
17// Open Game Folder (file:// via QDesktopServices)
18// Manage in Steam... / View on Steam Store (steam:// URLs)
19// Remove from Library (with confirmation)
20//
21// Each method takes a QMenu* plus the relevant game state and appends a
22// QAction (or submenu). Mutations go through the injected controller;
23// after a mutation completes, the factory emits a semantic signal and
24// the caller — MenuBarManager or MainWindow — handles global refresh
25// cascades (refreshGameList, updateSourceFilters, updateCategoryCounts,
26// updateCollectionsList, imageCache->clearAll, ...).
27//
28// Context-menu-unique actions (Verify Game Files, Copy to Clipboard,
29// Uninstall, Select All, Remove-N-games multi-select) remain outside
30// the factory: they're specific to the right-click menu and benefit
31// nothing from sharing.
32//
33// Menu-bar-unique actions (View modes, Sort By, Theme, zoom) are also
34// outside the factory since they aren't per-game.
35// ==============================================================================
36
37#pragma once
38
39#include <QObject>
40#include <memory>
41#include <string>
42
43class ThemeManager;
44class QMenu;
45class QWidget;
48struct Game;
49
50namespace core
51{
54} // namespace core
55
56class GameActionFactory : public QObject
57{
58 Q_OBJECT
59
60 public:
61 GameActionFactory(QWidget* dialogParent, core::GameLibraryController* libraryController,
62 core::LaunchController* launchController,
63 DetailsPanelManager* detailsPanelManager, GameThumbnailCache* imageCache,
64 ThemeManager* themeManager, QObject* qparent = nullptr);
66
67 // -------------------------------------------------------------------------
68 // Each method APPENDS one action (or submenu) to `menu`. Callers remain
69 // responsible for inserting separators / ordering. Methods that take the
70 // Game* read current state for decision-making but do NOT cache it — they
71 // re-fetch through libraryController at mutation time.
72 // -------------------------------------------------------------------------
73
74 /// Launch (if installed + not running), Stop (if running), or
75 /// Install via Steam (if Steam game + not installed).
76 void addLaunchActions(QMenu* menu, const std::string& gameId, const Game* game);
77
78 /// Configure... — opens GameConfigDialog. After Accepted, updates the
79 /// game through libraryController and emits gameConfigUpdated so the
80 /// caller can refresh the details panel / game-list row.
81 void addConfigureAction(QMenu* menu, const std::string& gameId);
82
83 /// "Quick Settings" submenu with MangoHud / GameMode / Gamescope /
84 /// VkBasalt toggles. Each toggle mutates runnerConfig.enableXxx and
85 /// emits gameConfigUpdated.
86 /// @param menu Parent menu the submenu is attached to.
87 /// @param gameId Identifier of the game whose runnerConfig is mutated.
88 /// @param game Backing Game pointer used for the current toggle state.
89 /// @param includeMoreSettings when true, appends a "More settings..."
90 /// entry that opens GameConfigDialog (used by the context menu).
91 void addQuickSettingsSubmenu(QMenu* menu, const std::string& gameId, const Game* game,
92 bool includeMoreSettings);
93
94 /// Favorite toggle (text flips between Add/Remove based on current
95 /// state). Shortcut: F.
96 void addFavoriteAction(QMenu* menu, const std::string& gameId, const Game* game);
97
98 /// "Collections" submenu listing every collection as a checkmarked
99 /// action, plus "Create New..." at the bottom.
100 void addCollectionsSubmenu(QMenu* menu, const std::string& gameId, const Game* game);
101
102 /// "Change Artwork..." — opens SteamGridDBSelectorDialog if the game
103 /// has a Steam App ID. No-op for non-Steam games.
104 void addChangeArtworkAction(QMenu* menu, const std::string& gameId, const Game* game);
105
106 /// "View on ProtonDB" — opens https://www.protondb.com/app/{appId}
107 /// in the default browser. No-op for non-Steam games.
108 void addProtonDBAction(QMenu* menu, const Game* game);
109
110 /// "Open Game Folder" — opens the executable's parent directory in
111 /// the file manager. No-op unless installed + executablePath is set.
112 void addOpenFolderAction(QMenu* menu, const Game* game);
113
114 /// Steam actions — "Manage in Steam..." (if installed) and
115 /// "View on Steam Store" (always for Steam games). No-op for non-Steam.
116 void addSteamActions(QMenu* menu, const Game* game);
117
118 /// "Remove from Library" with confirmation QMessageBox. Shortcut: Delete.
119 /// Emits removeGameRequested after user confirms; the caller is
120 /// responsible for calling libraryController->removeGame() + refresh
121 /// cascades (so the caller can decide whether to remove multiple
122 /// games in the multi-select path).
123 void addRemoveAction(QMenu* menu, const std::string& gameId);
124
125 signals:
126 /// The Launch action was triggered. Caller runs the launch pipeline.
127 void launchRequested(const std::string& gameId);
128
129 /// The Stop action was triggered. Caller calls launchController->kill.
130 void stopRequested(const std::string& gameId);
131
132 /// Configure dialog closed Accepted OR a Quick Setting was toggled.
133 /// Caller should refresh the details panel + list row for `gameId`.
134 void gameConfigUpdated(const std::string& gameId);
135
136 /// Favorite state flipped. Caller should refresh the list.
137 void favoriteChanged(const std::string& gameId);
138
139 /// Collections (add / remove / create+add) changed for `gameId`.
140 /// Caller should refresh the collections list + game list (sidebar
141 /// counts depend on it).
143
144 /// Artwork was changed via SteamGridDBSelectorDialog. Caller should
145 /// clear the image cache, refresh the list, and update the details
146 /// panel.
147 void artworkChanged(const std::string& gameId);
148
149 /// Remove from Library confirmed. Caller removes the game from the
150 /// library controller + runs refresh cascades.
151 void removeGameRequested(const std::string& gameId);
152
153 private:
154 class Impl;
155 std::unique_ptr<Impl> impl_;
156};
void addQuickSettingsSubmenu(QMenu *menu, const std::string &gameId, const Game *game, bool includeMoreSettings)
"Quick Settings" submenu with MangoHud / GameMode / Gamescope / VkBasalt toggles.
~GameActionFactory() override
void addCollectionsSubmenu(QMenu *menu, const std::string &gameId, const Game *game)
"Collections" submenu listing every collection as a checkmarked action, plus "Create New....
void gameConfigUpdated(const std::string &gameId)
Configure dialog closed Accepted OR a Quick Setting was toggled.
GameActionFactory(QWidget *dialogParent, core::GameLibraryController *libraryController, core::LaunchController *launchController, DetailsPanelManager *detailsPanelManager, GameThumbnailCache *imageCache, ThemeManager *themeManager, QObject *qparent=nullptr)
void removeGameRequested(const std::string &gameId)
Remove from Library confirmed.
void favoriteChanged(const std::string &gameId)
Favorite state flipped. Caller should refresh the list.
void addChangeArtworkAction(QMenu *menu, const std::string &gameId, const Game *game)
"Change Artwork..." — opens SteamGridDBSelectorDialog if the game has a Steam App ID.
void addFavoriteAction(QMenu *menu, const std::string &gameId, const Game *game)
Favorite toggle (text flips between Add/Remove based on current state).
void addConfigureAction(QMenu *menu, const std::string &gameId)
Configure... — opens GameConfigDialog.
void addRemoveAction(QMenu *menu, const std::string &gameId)
"Remove from Library" with confirmation QMessageBox.
void artworkChanged(const std::string &gameId)
Artwork was changed via SteamGridDBSelectorDialog.
void stopRequested(const std::string &gameId)
The Stop action was triggered. Caller calls launchController->kill.
void launchRequested(const std::string &gameId)
The Launch action was triggered. Caller runs the launch pipeline.
void addProtonDBAction(QMenu *menu, const Game *game)
"View on ProtonDB" — opens https://www.protondb.com/app/{appId} in the default browser.
void addOpenFolderAction(QMenu *menu, const Game *game)
"Open Game Folder" — opens the executable's parent directory in the file manager.
void addSteamActions(QMenu *menu, const Game *game)
Steam actions — "Manage in Steam..." (if installed) and "View on Steam Store" (always for Steam games...
void addLaunchActions(QMenu *menu, const std::string &gameId, const Game *game)
Launch (if installed + not running), Stop (if running), or Install via Steam (if Steam game + not ins...
void gameListChanged()
Collections (add / remove / create+add) changed for gameId.
Complete representation of a game in the library.
Definition game.h:767