89 I.gameList = gameList;
94 I.gameList, &QListView::customContextMenuRequested,
this,
95 [
this](
const QPoint& pos)
98 QModelIndexList selectedItems = II.gameList->selectionModel()->selectedIndexes();
99 if (selectedItems.isEmpty())
102 QMenu contextMenu(II.mainWindow);
103 impl_->themeManager->styleMenu(&contextMenu);
108 if (selectedItems.size() > 1)
110 QAction* selectAllAction = contextMenu.addAction(tr(
"Select All"));
111 connect(selectAllAction, &QAction::triggered, this,
112 [this]() { impl_->gameList->selectAll(); });
114 contextMenu.addSeparator();
116 QAction* deleteAction = contextMenu.addAction(
117 tr(
"Remove %1 Games from Library").arg(selectedItems.size()));
118 connect(deleteAction, &QAction::triggered, this,
119 [this, selectedItems]()
122 QMessageBox::question(impl_->mainWindow, tr(
"Confirm Removal"),
123 tr(
"Are you sure you want to remove %1 "
124 "games from the library?")
125 .arg(selectedItems.size()),
126 QMessageBox::Yes | QMessageBox::No);
127 if (reply != QMessageBox::Yes)
130 std::vector<std::string> ids;
131 ids.reserve(static_cast<size_t>(selectedItems.size()));
132 for (const QModelIndex& idx : selectedItems)
134 ids.push_back(idx.data(GameIdRole).toString().toStdString());
136 emit gamesBatchRemoveRequested(ids);
139 contextMenu.exec(II.gameList->mapToGlobal(pos));
147 const QModelIndex item = selectedItems.first();
148 const std::string gameId = item.data(
GameIdRole).toString().toStdString();
149 const Game* game = II.libraryController->getGame(gameId);
153 const bool isSteamGame =
155 const bool isInstalled = game->isInstalled();
162 contextMenu.addSeparator();
166 contextMenu.addSeparator();
171 if (isSteamGame && isInstalled)
173 const int steamAppId = game->metadata.steamAppId;
174 const std::string gameName = game->name;
175 QAction* uninstallAction =
176 contextMenu.addAction(QStringLiteral(
"\u2715 Uninstall"));
177 connect(uninstallAction, &QAction::triggered,
this,
178 [
this, gameId, gameName, steamAppId]()
182 QMessageBox::question(III.mainWindow, tr(
"Confirm Uninstall"),
183 tr(
"Are you sure you want to uninstall %1?"
184 "\n\nThis will delete the game files "
185 "and free up disk space.\nYou can "
186 "reinstall the game from Steam at any "
188 .arg(QString::fromStdString(gameName)),
189 QMessageBox::Yes | QMessageBox::No);
190 if (reply != QMessageBox::Yes)
193 const std::uint32_t appId =
static_cast<std::uint32_t
>(steamAppId);
194 if (III.notificationService)
196 III.notificationService->info(
"Uninstalling " + gameName +
"...");
205 QPointer<ContextMenuManager> guard(
this);
206 QThreadPool::globalInstance()->start(
207 [guard, appId, gameId, gameName]()
210 QMetaObject::invokeMethod(
212 [guard, success, gameName, gameId, appId]()
216 emit guard->steamUninstallCompleted(gameId, success,
219 Qt::QueuedConnection);
227 contextMenu.addSeparator();
229 QAction* selectAllAction2 = contextMenu.addAction(tr(
"Select All"));
230 connect(selectAllAction2, &QAction::triggered,
this,
231 [
this]() { impl_->gameList->selectAll(); });
233 contextMenu.addSeparator();
238 contextMenu.addSeparator();
247 const QString gameName = QString::fromStdString(game->name);
248 const QString gamePath = QString::fromStdString(game->runnerConfig.executablePath);
249 const int steamAppId = game->metadata.steamAppId;
250 QAction* verifyAction =
251 contextMenu.addAction(QStringLiteral(
"\u2713 Verify Game Files..."));
252 connect(verifyAction, &QAction::triggered,
this,
253 [
this, gameId, gameName, gamePath, steamAppId]()
256 dialog.
setGame(QString::fromStdString(gameId), gameName, gamePath,
263 QMenu* copyMenu = contextMenu.addMenu(tr(
"Copy to Clipboard"));
264 impl_->themeManager->styleMenu(copyMenu);
265 QAction* copyNameAction = copyMenu->addAction(tr(
"Game Name"));
266 connect(copyNameAction, &QAction::triggered,
this, [game]()
267 { QGuiApplication::clipboard()->setText(QString::fromStdString(game->name)); });
268 if (!game->runnerConfig.executablePath.empty())
270 QAction* copyPathAction = copyMenu->addAction(tr(
"Executable Path"));
271 connect(copyPathAction, &QAction::triggered,
this,
274 QGuiApplication::clipboard()->setText(
275 QString::fromStdString(game->runnerConfig.executablePath));
278 if (game->metadata.steamAppId > 0)
280 QAction* copyAppIdAction = copyMenu->addAction(tr(
"Steam App ID"));
281 connect(copyAppIdAction, &QAction::triggered,
this,
284 QGuiApplication::clipboard()->setText(
285 QString::number(game->metadata.steamAppId));
289 contextMenu.addSeparator();
293 contextMenu.exec(II.gameList->mapToGlobal(pos));