58#ifdef HAVE_QTERMWIDGET
66#include <QActionGroup>
67#include <QApplication>
72#include <QDesktopServices>
76#include <QGuiApplication>
78#include <QInputDialog>
79#include <QItemSelectionModel>
91#include <QPainterPath>
93#include <QProgressBar>
94#include <QPropertyAnimation>
103#include <QStyledItemDelegate>
106#include <QVBoxLayout>
107#include <QtConcurrent/QtConcurrent>
115#include <unordered_map>
126 QProcess::startDetached(
"steam", {steamUrl});
134 libraryController_ = std::make_unique<core::GameLibraryController>();
135 launchController_ = std::make_unique<core::LaunchController>();
136 settingsController_ = std::make_unique<core::SettingsController>();
137 performanceProfileService_ = std::make_unique<PerformanceProfileService>();
142 imageCache_ = std::make_unique<GameThumbnailCache>(
146 settingsController_->loadSettings();
147 libraryController_->loadLibrary();
151 syncSteamInstalledStatus();
159 libraryController_->getAllGames(),
160 [
this](
const std::string& gameId,
const std::function<
void(
Game&)>& updater)
161 { libraryController_->executeWithGame(gameId, updater); });
168 QPointer<MainWindow> statsGuard(
this);
170 [statsGuard](
const std::string& gameId)
177 QMetaObject::invokeMethod(
179 [statsGuard, gameId]()
181 if (!statsGuard || !statsGuard->libraryController_)
183 statsGuard->libraryController_->saveLibrary();
184 Logger::info(
"Persisted game statistics for: {}", gameId);
186 Qt::QueuedConnection);
202 if (qSettings.contains(
"wizard/enableHomeAssistant"))
204 auto appSettings = settingsController_->getAppSettings();
205 appSettings.enableHomeAssistant =
206 qSettings.value(
"wizard/enableHomeAssistant").toBool();
207 if (qSettings.contains(
"wizard/homeAssistantUrl"))
208 appSettings.homeAssistantUrl =
209 qSettings.value(
"wizard/homeAssistantUrl").toString().toStdString();
210 settingsController_->setAppSettings(appSettings);
211 qSettings.remove(
"wizard/enableHomeAssistant");
212 qSettings.remove(
"wizard/homeAssistantUrl");
225 setupGameListContextMenu();
229 setupControllerCallbacks();
230 setupKeyboardShortcuts();
231 setupCommandPalette();
232 setupSteamDownloadMonitor();
244 if (imageCache_ && libraryController_)
248 auto src = libraryController_->getAllGames();
249 std::vector<const Game*> games(src.begin(), src.end());
250 imageCache_->buildImagePathCache(games);
260 setWindowTitle(
"Game Launcher");
265 QTimer::singleShot(500,
this, &MainWindow::checkRunningGameOnStartup);
269 QTimer* updateTimer =
new QTimer(
this);
270 updateTimer->setObjectName(
"updateTimer");
271 connect(updateTimer, &QTimer::timeout,
this,
274 launchController_->update();
275 detailsPanelManager_->updateLaunchButton(selectedGameId_);
277 static int timerTicks = 0;
278 if (++timerTicks >= 5)
281 updateCategoryCounts();
286 updateTimer->start(1000);
294 QMetaObject::invokeMethod(
298 if (statusProgressBar_)
300 statusProgressBar_->setVisible(
true);
301 statusLabel_->setText(statusLabel_->text() +
" | Updating images...");
304 Qt::QueuedConnection);
308 QPointer<MainWindow> self =
this;
314 auto* libraryController = libraryController_.get();
315 (void)QtConcurrent::run(
316 [self, libraryController]()
321 int refreshed = libraryController->refreshStaleImages();
324 int discovered = libraryController->discoverMissingImages();
326 int total = refreshed + discovered;
332 QMetaObject::invokeMethod(
334 [self, total, refreshed, discovered]()
340 if (self->statusProgressBar_)
342 self->statusProgressBar_->setVisible(false);
348 if (self->imageCache_)
349 self->imageCache_->clearAll();
351 self->refreshGameList();
352 if (self->notificationService_)
355 if (refreshed > 0 && discovered > 0)
357 msg =
"Updated images: " + std::to_string(refreshed) +
358 " refreshed, " + std::to_string(discovered) +
361 else if (refreshed > 0)
363 msg =
"Refreshed images for " +
364 std::to_string(refreshed) +
" game(s)";
368 msg =
"Discovered images for " +
369 std::to_string(discovered) +
" game(s)";
371 self->notificationService_->success(msg);
375 Qt::QueuedConnection);
381 QTimer::singleShot(5000,
this, [
this]() { fetchMissingProtonDB(); });
388 Logger::info(
"[MainWindow] Starting Steam name fetch task");
391 QPointer<MainWindow> self =
this;
395 auto* libraryController = libraryController_.get();
396 (void)QtConcurrent::run(
397 [self, libraryController]()
402 auto allGames = libraryController->getAllGames();
403 Logger::info(
"[MainWindow] Checking {} games for placeholder names",
407 std::vector<std::pair<std::string, uint32_t>>
410 for (
const auto* game : allGames)
415 if (game->name.find(
"Steam App ") == 0)
418 "[MainWindow] Found placeholder name: '{}' (AppID: {})",
419 game->name, game->metadata.steamAppId);
420 needsNameFetch.emplace_back(
421 game->id,
static_cast<uint32_t
>(game->metadata.steamAppId));
426 if (needsNameFetch.empty())
428 Logger::info(
"[MainWindow] No games with placeholder names found");
432 Logger::info(
"[MainWindow] Found {} games needing name fetch",
433 needsNameFetch.size());
438 QMetaObject::invokeMethod(
440 [self, count = needsNameFetch.size()]()
444 if (self->statusProgressBar_)
446 self->statusProgressBar_->setVisible(true);
447 self->statusLabel_->setText(
"Fetching Steam names for " +
448 QString::number(count) +
452 Qt::QueuedConnection);
456 for (
const auto& entry : needsNameFetch)
461 const std::string& gameId = entry.first;
462 uint32_t steamAppId = entry.second;
464 Logger::info(
"[MainWindow] Fetching name for AppID {}", steamAppId);
467 std::string fetchedName =
470 if (fetchedName.empty())
472 Logger::info(
"[MainWindow] Cache miss for AppID {}, trying API",
480 Logger::info(
"[MainWindow] Cache hit for AppID {}: '{}'", steamAppId,
484 if (!fetchedName.empty() && self)
486 Logger::info(
"[MainWindow] Got name for AppID {}: '{}'", steamAppId,
490 QMetaObject::invokeMethod(
492 [self, libraryController, gameId, fetchedName]()
496 Game* mutableGame = libraryController->getGameForEdit(gameId);
497 if (mutableGame && mutableGame->name.find(
"Steam App ") == 0)
499 Logger::info(
"[MainWindow] Updating game '{}' -> '{}'",
500 mutableGame->name, fetchedName);
501 mutableGame->name = fetchedName;
502 libraryController->updateGame(gameId, *mutableGame);
505 Qt::QueuedConnection);
508 else if (fetchedName.empty())
510 Logger::warn(
"[MainWindow] Failed to fetch name for AppID {}",
515 std::this_thread::sleep_for(std::chrono::milliseconds(100));
518 Logger::info(
"[MainWindow] Steam name fetch complete. Updated {} games",
524 QMetaObject::invokeMethod(
526 [self, libraryController, updated]()
530 if (self->statusProgressBar_)
532 self->statusProgressBar_->setVisible(false);
537 libraryController->saveLibrary();
538 self->refreshGameList();
539 if (self->notificationService_)
541 self->notificationService_->success(
542 "Updated names for " + std::to_string(updated) +
547 Qt::QueuedConnection);
561 isShuttingDown_.store(
true);
563 imageCache_->requestShutdown();
568 imageLoader_->cancelAll();
575 settingsController_->saveSettings();
580 notificationService_ = std::move(service);
581 if (notificationService_)
583 notificationService_->setParentWidget(
this);
591 if (!forceQuit_ && settingsController_->isMinimizeToTrayEnabled() && trayIcon_ &&
592 trayIcon_->isVisible())
600 if (settingsController_ && !isInGamingLayout_)
602 auto settings = settingsController_->getAppSettings();
603 settings.panelSidebarVisible = sidebarContainer_ && sidebarContainer_->isVisible();
604 settings.panelGamesVisible = gameListContainer_ && gameListContainer_->isVisible();
605 settings.panelDetailsVisible = detailsContainer_ && detailsContainer_->isVisible();
606#ifdef HAVE_QTERMWIDGET
607 settings.panelMonitorVisible = terminalContainer_ && terminalContainer_->isVisible();
610 settings.panelHAVisible = haContainer_ && haContainer_->isVisible();
615 QStringList sizeStrs;
616 for (
int s : mainSplitter_->sizes())
617 sizeStrs.append(QString::number(s));
618 settings.splitterSizes = sizeStrs.join(
",").toStdString();
620 settingsController_->setAppSettings(settings);
621 settingsController_->saveSettings();
627 QApplication::quit();
630void MainWindow::setupUI()
632 QWidget* centralWidget =
new QWidget(
this);
633 setCentralWidget(centralWidget);
636 setAcceptDrops(
true);
638 QHBoxLayout* mainLayout =
new QHBoxLayout(centralWidget);
639 mainLayout->setContentsMargins(0, 0, 0, 0);
640 mainLayout->setSpacing(0);
644 mainSplitter_ =
new QSplitter(Qt::Horizontal,
this);
645 mainSplitter_->setHandleWidth(6);
646 mainSplitter_->setChildrenCollapsible(
false);
647 mainSplitter_->setOpaqueResize(
false);
648 mainSplitter_->setStyleSheet(QString(
"QSplitter::handle { background-color: %1; }"
649 "QSplitter::handle:hover { background-color: %2; }"
650 "QSplitter::handle:pressed { background-color: %3; }")
652 .arg(c.
accent.darker(120).name())
654 mainLayout->addWidget(mainSplitter_);
663 detailsPanelManager_ = std::make_unique<DetailsPanelManager>(
664 this, libraryController_.get(), launchController_.get(), imageCache_.get(),
666 detailsPanel_ = detailsPanelManager_->widget();
670 [
this](
const std::string& ) { onLaunchClicked(); });
672 [
this](
const std::string& ) { onStopClicked(); });
674 [
this](
const std::string& gameId)
678 Game* game = libraryController_->getGameForEdit(gameId);
681 GameConfigDialog dialog(game, this);
682 if (dialog.exec() == QDialog::Accepted)
684 libraryController_->updateGame(gameId, *game);
685 detailsPanelManager_->update(gameId);
689 [
this](
const std::string& gameId)
693 updateGameRow(gameId);
697 sidebarContainer_ = createPanelContainer(sidebar_,
"Sidebar", poppedSidebar_, 250, 600);
698 gameListContainer_ = createPanelContainer(gameList_,
"Games", poppedGameList_, 400, 700);
699 detailsContainer_ = createPanelContainer(detailsPanel_,
"Details", poppedDetails_, 450, 700);
702 sidebarContainer_->setMinimumWidth(120);
703 gameListContainer_->setMinimumWidth(200);
704 detailsContainer_->setMinimumWidth(250);
706#ifdef HAVE_QTERMWIDGET
710 createPanelContainer(terminalPanel_,
"System Monitor", poppedMonitor_, 800, 600);
711 terminalContainer_->setVisible(
false);
712 terminalContainer_->setMinimumWidth(300);
718 haContainer_ = createPanelContainer(haPanel_,
"Home Assistant", poppedHA_, 900, 700);
719 haContainer_->setMinimumWidth(400);
721 if (
auto* titleBar = haContainer_->findChild<QWidget*>(
"panelTitleBar"))
722 titleBar->setVisible(
false);
726 mainSplitter_->addWidget(sidebarContainer_);
727 mainSplitter_->addWidget(gameListContainer_);
728 mainSplitter_->addWidget(detailsContainer_);
729#ifdef HAVE_QTERMWIDGET
730 mainSplitter_->addWidget(terminalContainer_);
733 mainSplitter_->addWidget(haContainer_);
738 auto appSettings = settingsController_->getAppSettings();
741 if (sidebarContainer_)
742 sidebarContainer_->setVisible(appSettings.panelSidebarVisible);
743 if (gameListContainer_)
744 gameListContainer_->setVisible(appSettings.panelGamesVisible);
745 if (detailsContainer_)
746 detailsContainer_->setVisible(appSettings.panelDetailsVisible);
747#ifdef HAVE_QTERMWIDGET
748 if (terminalContainer_)
750 terminalContainer_->setVisible(appSettings.panelMonitorVisible);
751 if (appSettings.panelMonitorVisible && terminalPanel_)
752 terminalPanel_->startCommand(
"btop");
758 haContainer_->setVisible(appSettings.panelHAVisible);
759 if (appSettings.panelHAVisible && haPanel_)
760 haPanel_->loadDashboard();
765 if (!appSettings.splitterSizes.empty())
768 for (
const auto& s : QString::fromStdString(appSettings.splitterSizes).split(
","))
771 int val = s.toInt(&ok);
775 if (sizes.size() == mainSplitter_->count())
776 mainSplitter_->setSizes(sizes);
778 mainSplitter_->setSizes({200, 700, 400});
782 mainSplitter_->setSizes({200, 700, 400});
787 connect(mainSplitter_, &QSplitter::splitterMoved,
this,
791 if (!resizeDebounceTimer_)
793 resizeDebounceTimer_ =
new QTimer(
this);
794 resizeDebounceTimer_->setSingleShot(
true);
795 resizeDebounceTimer_->setInterval(150);
796 connect(resizeDebounceTimer_, &QTimer::timeout,
this,
800 if (!selectedGameId_.empty())
802 detailsPanelManager_->update(selectedGameId_);
806 resizeDebounceTimer_->start();
810void MainWindow::setupMenuBar()
815 gameActionFactory_ = std::make_unique<GameActionFactory>(
816 this, libraryController_.get(), launchController_.get(), detailsPanelManager_.get(),
823 menuBarManager_ = std::make_unique<MenuBarManager>(
824 this, libraryController_.get(), launchController_.get(), settingsController_.get(),
825 detailsPanelManager_.get(), imageCache_.get(), gameActionFactory_.get(),
827 menuBarManager_->setupMenus();
830 menuBarManager_->setPanelVisibilityQuery(
831 [
this](
const QString& name) ->
bool
833 if (name == QLatin1String(
"sidebar"))
834 return sidebarContainer_ && sidebarContainer_->isVisible();
835 if (name == QLatin1String(
"games"))
836 return gameListContainer_ && gameListContainer_->isVisible();
837 if (name == QLatin1String(
"details"))
838 return detailsContainer_ && detailsContainer_->isVisible();
839#ifdef HAVE_QTERMWIDGET
840 if (name == QLatin1String(
"monitor"))
841 return terminalContainer_ && terminalContainer_->isVisible();
844 if (name == QLatin1String(
"ha"))
845 return haContainer_ && haContainer_->isVisible();
850 MenuBarManager* mm = menuBarManager_.get();
861 GameImportDialog dialog(libraryController_.get(),
this);
862 if (dialog.exec() == QDialog::Accepted)
865 libraryController_->getAllGames(),
866 [
this](
const std::string& gameId,
const std::function<
void(
Game&)>& updater)
867 { libraryController_->executeWithGame(gameId, updater); });
868 updateSourceFilters();
869 updateCategoryCounts();
871 QTimer::singleShot(500,
this, [
this]() { fetchMissingProtonDB(); });
878 LutrisSearchDialog searchDialog(libraryController_.get(),
this);
880 [
this](
const LutrisInstallerScript& script)
882 LutrisInstallPreviewDialog previewDialog(script,
this);
883 if (previewDialog.exec() == QDialog::Accepted)
885 InstallConfig config = previewDialog.getInstallConfig();
886 LutrisInstallerScript scriptCopy = previewDialog.getScript();
887 LutrisInstallProgressDialog progressDialog(
888 scriptCopy, config, libraryController_.get(),
this);
889 if (progressDialog.exec() == QDialog::Accepted)
892 libraryController_->getAllGames(),
893 [
this](
const std::string& gameId,
894 const std::function<
void(
Game&)>& updater)
895 { libraryController_->executeWithGame(gameId, updater); });
896 updateSourceFilters();
897 updateCategoryCounts();
908 LibraryExportDialog dialog(
this);
909 dialog.setController(libraryController_.get());
910 if (dialog.exec() == QDialog::Accepted)
913 updateSourceFilters();
914 updateCategoryCounts();
921 RunnerManagerDialog dialog(
this);
923 populateRunnerVersions();
929 GameStatisticsDialog dialog(
this);
930 auto filteredGames = libraryController_->getFilteredGames();
931 std::vector<Game*> games;
932 games.reserve(filteredGames.size());
933 for (
const Game* g : filteredGames)
934 games.push_back(
const_cast<Game*
>(g));
935 dialog.setGames(games);
942 DownloadQueueDialog dialog(steamDownloadMonitor_.get(), libraryController_.get(),
955 [
this](
const QString& themeId)
959 settingsController_->saveSettings();
967 [
this](
const std::string&) { onLaunchClicked(); });
969 [
this](
const std::string&) { onStopClicked(); });
971 [
this](
const std::string&) { refreshGameList(); });
973 [
this](
const std::string&) { deleteSelectedGame(); });
975 [
this](
const std::string&)
977 invalidateGameItemCache();
991 for (
int i = 0; i < sortCombo_->count(); ++i)
993 if (sortCombo_->itemData(i).toInt() ==
static_cast<int>(opt))
995 sortCombo_->setCurrentIndex(i);
1005 [
this](
const QString& name)
1007 if (name == QLatin1String(
"sidebar"))
1008 togglePanel(sidebarContainer_, panelSidebarBtn_,
"Sidebar");
1009 else if (name == QLatin1String(
"games"))
1010 togglePanel(gameListContainer_, panelGamesBtn_,
"Games");
1011 else if (name == QLatin1String(
"details"))
1012 togglePanel(detailsContainer_, panelDetailsBtn_,
"Details");
1013#ifdef HAVE_QTERMWIDGET
1014 else if (name == QLatin1String(
"monitor"))
1016 const bool willShow = terminalContainer_ && !terminalContainer_->isVisible();
1017 togglePanel(terminalContainer_, panelMonitorBtn_,
"Monitor");
1018 if (willShow && terminalPanel_)
1019 terminalPanel_->startCommand(
"btop");
1022#ifdef HAVE_WEBENGINE
1023 else if (name == QLatin1String(
"ha"))
1025 const bool willShow = haContainer_ && !haContainer_->isVisible();
1026 togglePanel(haContainer_, panelHABtn_,
"Home Assistant");
1027 if (willShow && haPanel_)
1028 haPanel_->loadDashboard();
1038 zoomSlider_->setValue(qMin(zoomSlider_->maximum(), zoomSlider_->value() + 10));
1044 zoomSlider_->setValue(qMax(zoomSlider_->minimum(), zoomSlider_->value() - 10));
1050 zoomSlider_->setValue(100);
1057 [
this](
const std::string& gameId) { updateGameRow(gameId); });
1061 updateCollectionsList();
1069 if (commandPalette_)
1070 commandPalette_->showPalette();
1078void MainWindow::togglePanel(QWidget* panel, QPushButton* btn,
const QString& )
1085 if (isInGamingLayout_)
1087 Logger::info(
"[MainWindow] User manually toggled panel during gaming layout - marking as "
1089 gamingLayoutOverridden_ =
true;
1090 isInGamingLayout_ =
false;
1093 if (sidebarContainer_)
1095 sidebarContainer_->setMinimumWidth(120);
1096 sidebarContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
1098 if (gameListContainer_)
1100 gameListContainer_->setMinimumWidth(200);
1101 gameListContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
1103 if (detailsContainer_)
1105 detailsContainer_->setMinimumWidth(250);
1106 detailsContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
1108#ifdef HAVE_QTERMWIDGET
1109 if (terminalContainer_)
1111 terminalContainer_->setMinimumWidth(300);
1112 terminalContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
1115#ifdef HAVE_WEBENGINE
1118 haContainer_->setMinimumWidth(400);
1119 haContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
1124 bool newVisible = !panel->isVisible();
1125 panel->setVisible(newVisible);
1127 btn->setChecked(newVisible);
1129#ifdef HAVE_QTERMWIDGET
1131 if (terminalContainer_ && panel == terminalContainer_ && terminalPanel_)
1134 terminalPanel_->resumeProcess();
1136 terminalPanel_->pauseProcess();
1141 QTimer::singleShot(0,
this, &MainWindow::updateToolbarVisibility);
1144 if (newVisible && mainSplitter_)
1146 int panelIndex = mainSplitter_->indexOf(panel);
1147 if (panelIndex >= 0)
1149 QList<int> sizes = mainSplitter_->sizes();
1151 if (panelIndex < sizes.size() && sizes[panelIndex] < 50)
1155 int visibleCount = 0;
1156 for (
int i = 0; i < mainSplitter_->count(); ++i)
1158 if (mainSplitter_->widget(i)->isVisible())
1160 totalWidth += sizes[i];
1166 int newPanelSize = qMax(300, totalWidth / 4);
1169 if (totalWidth > newPanelSize && visibleCount > 1)
1171 double scale =
static_cast<double>(totalWidth - newPanelSize) / totalWidth;
1172 for (
int i = 0; i < sizes.size(); ++i)
1174 if (i == panelIndex)
1176 sizes[i] = newPanelSize;
1178 else if (mainSplitter_->widget(i)->isVisible())
1180 sizes[i] =
static_cast<int>(sizes[i] * scale);
1183 mainSplitter_->setSizes(sizes);
1190void MainWindow::popOutPanel(QWidget* panel, QWidget*& poppedWindow,
const QString& title,
1191 int width,
int height)
1199 poppedWindow->raise();
1200 poppedWindow->activateWindow();
1205 QWidget* container =
nullptr;
1206 if (panel == sidebar_)
1207 container = sidebarContainer_;
1208 else if (panel == gameList_)
1209 container = gameListContainer_;
1210 else if (panel == detailsPanel_)
1211 container = detailsContainer_;
1212#ifdef HAVE_QTERMWIDGET
1213 else if (panel == terminalPanel_)
1214 container = terminalContainer_;
1216#ifdef HAVE_WEBENGINE
1217 else if (panel == haPanel_)
1218 container = haContainer_;
1224 container->setVisible(
false);
1228 poppedWindow =
new QWidget(
nullptr, Qt::Window);
1229 poppedWindow->setWindowTitle(title +
" - Game Launcher");
1230 poppedWindow->resize(width, height);
1231 poppedWindow->setAttribute(Qt::WA_DeleteOnClose);
1233 QVBoxLayout* layout =
new QVBoxLayout(poppedWindow);
1234 layout->setContentsMargins(0, 0, 0, 0);
1237 panel->setParent(poppedWindow);
1238 panel->setVisible(
true);
1239 layout->addWidget(panel);
1242 connect(poppedWindow, &QWidget::destroyed,
this,
1243 [
this, panel, container, &poppedWindow]()
1245 poppedWindow =
nullptr;
1250 QVBoxLayout* containerLayout = qobject_cast<QVBoxLayout*>(container->layout());
1251 if (containerLayout)
1253 panel->setParent(container);
1254 containerLayout->addWidget(panel, 1);
1255 panel->setVisible(
true);
1256 container->setVisible(
true);
1262 panel->setParent(
this);
1263 mainSplitter_->addWidget(panel);
1264 panel->setVisible(
true);
1266 updateToolbarVisibility();
1269 poppedWindow->show();
1270 updateToolbarVisibility();
1273void MainWindow::updateMenuMode()
1276 bool useHamburger = settings.value(
"ui/useHamburgerMenu",
false).toBool();
1279 menuBar()->setVisible(!useHamburger);
1282 if (toolbarManager_)
1284 if (
auto* btn = toolbarManager_->hamburgerButton())
1285 btn->setVisible(useHamburger);
1289void MainWindow::updateToolbarVisibility()
1292 bool gamesListVisible = gameListContainer_ && gameListContainer_->isVisible();
1295 if (draggableToolbar_)
1297 if (
auto* gameControlsSection = draggableToolbar_->section(
"gameControls"))
1298 gameControlsSection->setVisible(gamesListVisible);
1301#ifdef HAVE_QTERMWIDGET
1303 bool monitorVisible = terminalContainer_ && terminalContainer_->isVisible();
1306 if (draggableToolbar_)
1308 if (
auto* monitorSection = draggableToolbar_->section(
"monitor"))
1309 monitorSection->setVisible(monitorVisible);
1313 if (panelMonitorBtn_)
1314 panelMonitorBtn_->setChecked(monitorVisible);
1318 if (panelSidebarBtn_)
1319 panelSidebarBtn_->setChecked(sidebarContainer_ && sidebarContainer_->isVisible());
1321 panelGamesBtn_->setChecked(gameListContainer_ && gameListContainer_->isVisible());
1322 if (panelDetailsBtn_)
1323 panelDetailsBtn_->setChecked(detailsContainer_ && detailsContainer_->isVisible());
1324#ifdef HAVE_WEBENGINE
1326 panelHABtn_->setChecked(haContainer_ && haContainer_->isVisible());
1332 if (gamesListVisible)
1336 switch (currentViewMode_)
1345 viewName =
"Compact";
1349 libraryController_ ?
static_cast<int>(libraryController_->getGameCount()) : 0;
1350 int visibleGames = gameListProxy_ ? gameListProxy_->rowCount() : 0;
1351 statusLabel_->setText(QString(
"Games: %1 (showing %2) | %3 view")
1358 statusLabel_->setText(
"Ready");
1363void MainWindow::updateRunningGameStatus()
1365 if (!runningGameStatusWidget_)
1372 bool featureEnabled =
1373 settingsController_ && settingsController_->getAppSettings().showToolbarGameStatus;
1376 std::string runningGameId;
1377 const Game* runningGame =
nullptr;
1380 if (!selectedGameId_.empty() && launchController_->isGameRunning(selectedGameId_))
1382 runningGameId = selectedGameId_;
1383 runningGame = libraryController_->getGame(runningGameId);
1388 for (
const auto* game : libraryController_->getAllGames())
1390 if (launchController_->isGameRunning(game->id))
1392 runningGameId = game->id;
1400 if (runningGameId != previousRunningGameId_)
1402 if (!runningGameId.empty() && previousRunningGameId_.empty())
1405 onGameStarted(runningGameId);
1407 else if (runningGameId.empty() && !previousRunningGameId_.empty())
1410 onGameStopped(previousRunningGameId_);
1412 previousRunningGameId_ = runningGameId;
1416 bool shouldShow = featureEnabled && runningGame !=
nullptr;
1419 static bool lastShouldShow =
false;
1420 if (shouldShow != lastShouldShow)
1422 Logger::info(
"[RunningStatus] featureEnabled={}, runningGame={}, shouldShow={}",
1423 featureEnabled, runningGame ? runningGame->
name :
"null", shouldShow);
1424 lastShouldShow = shouldShow;
1429 runningGameStatusWidget_->clear();
1430 runningGameStatusWidget_->setVisible(
false);
1431 if (draggableToolbar_)
1433 if (
auto* runningSection = draggableToolbar_->section(
"running"))
1434 runningSection->setVisible(
false);
1440 auto duration = launchController_->getSessionDuration(runningGameId);
1441 int runningSeconds =
static_cast<int>(duration.count());
1447 QString trackedProcessName;
1451 std::string trackedName = process->getTrackedProcessName();
1452 if (!trackedName.empty())
1454 trackedProcessName = QString::fromStdString(trackedName);
1459 runningGameStatusWidget_->updateStatus(
1460 QString::fromStdString(runningGameId), QString::fromStdString(runningGame->
name),
1461 runningSeconds, frameMetrics.fps, frameMetrics.frametime_ms, frameMetrics.frametimeHistory,
1462 trackedProcessName);
1465 QStringList optimizations;
1467 optimizations <<
"MangoHud";
1469 optimizations <<
"GameMode";
1471 optimizations <<
"game-performance";
1473 optimizations <<
"VkBasalt";
1475 optimizations <<
"Fsync";
1478 switch (runningGame->
runner)
1494 QString protonVersion;
1508 if (!steamProtonVersion.empty())
1510 protonVersion = QString::fromStdString(steamProtonVersion);
1515 runningGameStatusWidget_->setLaunchInfo(optimizations, runner, protonVersion);
1516 runningGameStatusWidget_->setVisible(
true);
1517 if (draggableToolbar_)
1519 if (
auto* runningSection = draggableToolbar_->section(
"running"))
1520 runningSection->setVisible(
true);
1528QWidget* MainWindow::createPanelContainer(QWidget* content,
const QString& title,
1529 QWidget*& poppedWindow,
int popWidth,
int popHeight)
1534 QWidget* container =
new QWidget(
this);
1535 QVBoxLayout* layout =
new QVBoxLayout(container);
1536 layout->setContentsMargins(0, 0, 0, 0);
1537 layout->setSpacing(0);
1540 QWidget* titleBar =
new QWidget(container);
1541 titleBar->setObjectName(
"panelTitleBar");
1542 titleBar->setFixedHeight(24);
1543 titleBar->setStyleSheet(
1544 QString(
"QWidget#panelTitleBar { background-color: %1; border-bottom: 1px solid %2; }")
1548 QHBoxLayout* titleLayout =
new QHBoxLayout(titleBar);
1549 titleLayout->setContentsMargins(8, 0, 4, 0);
1550 titleLayout->setSpacing(2);
1553 QLabel* titleLabel =
new QLabel(title, titleBar);
1554 titleLabel->setObjectName(
"panelTitleLabel");
1555 titleLabel->setStyleSheet(QString(
"QLabel { color: %1; font-size: 11px; font-weight: bold; "
1556 "background: transparent; border: none; }")
1558 titleLayout->addWidget(titleLabel);
1560 titleLayout->addStretch();
1564 QString(
"QPushButton { background: transparent; color: %1; border: none; padding: 2px 4px; "
1565 "font-size: 11px; border-radius: 2px; }"
1566 "QPushButton:hover { background-color: %2; color: %3; }"
1567 "QPushButton:pressed { background-color: %4; color: %5; }")
1575 QPushButton* moveLeftBtn =
new QPushButton(
"◀", titleBar);
1576 moveLeftBtn->setObjectName(
"panelTitleBtn");
1577 moveLeftBtn->setFixedSize(20, 18);
1578 moveLeftBtn->setToolTip(
"Move panel left");
1579 moveLeftBtn->setStyleSheet(btnStyle);
1580 connect(moveLeftBtn, &QPushButton::clicked,
this,
1581 [
this, container]() { movePanelLeft(container); });
1582 titleLayout->addWidget(moveLeftBtn);
1585 QPushButton* moveRightBtn =
new QPushButton(
"▶", titleBar);
1586 moveRightBtn->setObjectName(
"panelTitleBtn");
1587 moveRightBtn->setFixedSize(20, 18);
1588 moveRightBtn->setToolTip(
"Move panel right");
1589 moveRightBtn->setStyleSheet(btnStyle);
1590 connect(moveRightBtn, &QPushButton::clicked,
this,
1591 [
this, container]() { movePanelRight(container); });
1592 titleLayout->addWidget(moveRightBtn);
1595 QFrame* sep =
new QFrame(titleBar);
1596 sep->setObjectName(
"panelTitleSep");
1597 sep->setFrameShape(QFrame::VLine);
1598 sep->setFixedWidth(1);
1599 sep->setStyleSheet(QString(
"background-color: %1;").arg(c.
border.name()));
1600 titleLayout->addWidget(sep);
1603 QPushButton* popOutBtn =
new QPushButton(
"⧉", titleBar);
1604 popOutBtn->setObjectName(
"panelTitleBtn");
1605 popOutBtn->setFixedSize(20, 18);
1606 popOutBtn->setToolTip(
"Pop out to separate window");
1607 popOutBtn->setStyleSheet(btnStyle);
1608 connect(popOutBtn, &QPushButton::clicked,
this,
1609 [
this, content, &poppedWindow, title, popWidth, popHeight]()
1610 { popOutPanel(content, poppedWindow, title, popWidth, popHeight); });
1611 titleLayout->addWidget(popOutBtn);
1613 layout->addWidget(titleBar);
1614 layout->addWidget(content, 1);
1619void MainWindow::movePanelLeft(QWidget* container)
1621 if (!mainSplitter_ || !container)
1624 int idx = mainSplitter_->indexOf(container);
1628 for (
int i = idx - 1; i >= 0; --i)
1630 QWidget* w = mainSplitter_->widget(i);
1631 if (w && w->isVisible())
1634 mainSplitter_->insertWidget(i, container);
1641void MainWindow::movePanelRight(QWidget* container)
1643 if (!mainSplitter_ || !container)
1646 int idx = mainSplitter_->indexOf(container);
1647 if (idx >= 0 && idx < mainSplitter_->count() - 1)
1650 for (
int i = idx + 1; i < mainSplitter_->count(); ++i)
1652 QWidget* w = mainSplitter_->widget(i);
1653 if (w && w->isVisible())
1656 mainSplitter_->insertWidget(i + 1, container);
1667void MainWindow::setupToolBar()
1675 std::make_unique<ToolbarManager>(
this, libraryController_.get(), launchController_.get(),
1677 toolbarManager_->setupToolbar();
1681 draggableToolbar_ = toolbarManager_->draggableToolbar();
1682 searchEdit_ = toolbarManager_->searchEdit();
1683 sortCombo_ = toolbarManager_->sortCombo();
1684 zoomSlider_ = toolbarManager_->zoomSlider();
1685 zoomLabel_ = toolbarManager_->zoomLabel();
1686 listViewAction_ = toolbarManager_->listViewAction();
1687 gridViewAction_ = toolbarManager_->gridViewAction();
1688 compactViewAction_ = toolbarManager_->compactViewAction();
1689 viewModeGroup_ = toolbarManager_->viewModeGroup();
1690 panelSidebarBtn_ = toolbarManager_->panelSidebarButton();
1691 panelGamesBtn_ = toolbarManager_->panelGamesButton();
1692 panelDetailsBtn_ = toolbarManager_->panelDetailsButton();
1693#ifdef HAVE_QTERMWIDGET
1694 panelMonitorBtn_ = toolbarManager_->panelMonitorButton();
1695 monitorTypeCombo_ = toolbarManager_->monitorTypeCombo();
1696 monitorRestartBtn_ = toolbarManager_->monitorRestartButton();
1698#ifdef HAVE_WEBENGINE
1699 panelHABtn_ = toolbarManager_->panelHAButton();
1701 runningGameStatusWidget_ = toolbarManager_->runningGameStatusWidget();
1706 ToolbarManager* tm = toolbarManager_.get();
1725 GameImportDialog dialog(libraryController_.get(),
this);
1726 if (dialog.exec() == QDialog::Accepted)
1729 libraryController_->getAllGames(),
1730 [
this](
const std::string& gameId,
const std::function<
void(
Game&)>& updater)
1731 { libraryController_->executeWithGame(gameId, updater); });
1732 updateSourceFilters();
1733 updateCategoryCounts();
1735 QTimer::singleShot(500,
this, [
this]() { fetchMissingProtonDB(); });
1742 LutrisSearchDialog searchDialog(libraryController_.get(),
this);
1744 [
this](
const LutrisInstallerScript& script)
1746 LutrisInstallPreviewDialog previewDialog(script,
this);
1747 if (previewDialog.exec() == QDialog::Accepted)
1749 InstallConfig config = previewDialog.getInstallConfig();
1750 LutrisInstallerScript scriptCopy = previewDialog.getScript();
1751 LutrisInstallProgressDialog progressDialog(
1752 scriptCopy, config, libraryController_.get(),
this);
1753 if (progressDialog.exec() == QDialog::Accepted)
1756 libraryController_->getAllGames(),
1757 [
this](
const std::string& gameId,
1758 const std::function<
void(
Game&)>& updater)
1759 { libraryController_->executeWithGame(gameId, updater); });
1760 updateSourceFilters();
1761 updateCategoryCounts();
1766 searchDialog.exec();
1772 RunnerManagerDialog dialog(
this);
1774 populateRunnerVersions();
1780 GameStatisticsDialog dialog(
this);
1781 auto filteredGames = libraryController_->getFilteredGames();
1782 std::vector<Game*> games;
1783 games.reserve(filteredGames.size());
1784 for (
const Game* g : filteredGames)
1786 games.push_back(
const_cast<Game*
>(g));
1788 dialog.setGames(games);
1795 LibraryExportDialog dialog(
this);
1796 dialog.setController(libraryController_.get());
1797 if (dialog.exec() == QDialog::Accepted)
1800 updateSourceFilters();
1801 updateCategoryCounts();
1808 DownloadQueueDialog dialog(steamDownloadMonitor_.get(), libraryController_.get(),
1821 [
this](
const QString& themeId)
1825 settingsController_->saveSettings();
1830 [
this](
const QString& name)
1832 if (name == QLatin1String(
"sidebar"))
1834 togglePanel(sidebarContainer_, panelSidebarBtn_,
"Sidebar");
1835 if (panelSidebarBtn_)
1836 panelSidebarBtn_->setChecked(sidebarContainer_ &&
1837 sidebarContainer_->isVisible());
1839 else if (name == QLatin1String(
"games"))
1841 togglePanel(gameListContainer_, panelGamesBtn_,
"Games");
1843 panelGamesBtn_->setChecked(gameListContainer_ &&
1844 gameListContainer_->isVisible());
1846 else if (name == QLatin1String(
"details"))
1848 togglePanel(detailsContainer_, panelDetailsBtn_,
"Details");
1849 if (panelDetailsBtn_)
1850 panelDetailsBtn_->setChecked(detailsContainer_ &&
1851 detailsContainer_->isVisible());
1853#ifdef HAVE_QTERMWIDGET
1854 else if (name == QLatin1String(
"monitor"))
1856 bool willShow = terminalContainer_ && !terminalContainer_->isVisible();
1857 togglePanel(terminalContainer_, panelMonitorBtn_,
"Monitor");
1858 if (panelMonitorBtn_)
1859 panelMonitorBtn_->setChecked(terminalContainer_ &&
1860 terminalContainer_->isVisible());
1861 if (willShow && terminalPanel_)
1863 QString command =
"btop";
1864 if (monitorTypeCombo_)
1866 switch (monitorTypeCombo_->currentIndex())
1879 QString s = QString::fromLocal8Bit(qgetenv(
"SHELL"));
1880 command = s.isEmpty() ? QStringLiteral(
"/bin/bash") : s;
1887 terminalPanel_->startCommand(command);
1891#ifdef HAVE_WEBENGINE
1892 else if (name == QLatin1String(
"ha"))
1894 bool willShow = haContainer_ && !haContainer_->isVisible();
1895 togglePanel(haContainer_, panelHABtn_,
"Home Assistant");
1897 panelHABtn_->setChecked(haContainer_ && haContainer_->isVisible());
1898 if (willShow && haPanel_)
1899 haPanel_->loadDashboard();
1907 if (detailsContainer_ && !detailsContainer_->isVisible())
1909 detailsContainer_->setVisible(
true);
1910 if (panelDetailsBtn_)
1911 panelDetailsBtn_->setChecked(
true);
1915#ifdef HAVE_QTERMWIDGET
1919 [
this](
const QString& cmd)
1921 if (terminalPanel_ && terminalPanel_->isVisible())
1923 terminalPanel_->startCommand(
"exit");
1924 QTimer::singleShot(200,
this,
1928 terminalPanel_->startCommand(cmd);
1935 if (terminalPanel_ && monitorTypeCombo_)
1938 switch (monitorTypeCombo_->currentIndex())
1951 QString s = QString::fromLocal8Bit(qgetenv(
"SHELL"));
1952 cmd = s.isEmpty() ? QStringLiteral(
"/bin/bash") : s;
1958 terminalPanel_->startCommand(
"\x03");
1959 QTimer::singleShot(100,
this,
1963 terminalPanel_->startCommand(cmd);
1970void MainWindow::applyTheme()
1975 setUpdatesEnabled(
false);
1978 if (gameListDelegate_)
1980 gameListDelegate_->updateCachedColors();
1984 if (sidebarManager_)
1986 sidebarManager_->applyTheme();
1992 gameList_->setStyleSheet(QString(
"QListView { background-color: %1; border: none; }")
1995 gameList_->viewport()->update();
1999 if (detailsPanelManager_)
2001 detailsPanelManager_->applyTheme();
2005 if (statusProgressBar_)
2007 statusProgressBar_->setStyleSheet(
2008 QString(
"QProgressBar { background-color: %1; border: none; border-radius: 3px; }"
2009 "QProgressBar::chunk { background-color: %2; border-radius: 3px; }")
2016 if (toolbarManager_)
2018 toolbarManager_->applyTheme();
2025 if (menuBarManager_)
2027 menuBarManager_->applyTheme();
2031 setUpdatesEnabled(
true);
2037 QString titleBarStyle =
2038 QString(
"QWidget#panelTitleBar { background-color: %1; border-bottom: 1px solid %2; }")
2041 QString titleLabelStyle = QString(
"QLabel { color: %1; font-size: 11px; font-weight: bold; "
2042 "background: transparent; border: none; }")
2044 QString titleBtnStyle =
2045 QString(
"QPushButton { background: transparent; color: %1; border: none; padding: 2px 4px; "
2046 "font-size: 11px; border-radius: 2px; }"
2047 "QPushButton:hover { background-color: %2; color: %3; }"
2048 "QPushButton:pressed { background-color: %4; }")
2053 QString titleSepStyle = QString(
"background-color: %1;").arg(c.
border.name());
2056 for (QWidget* titleBar : findChildren<QWidget*>(
"panelTitleBar"))
2058 titleBar->setStyleSheet(titleBarStyle);
2060 for (QLabel* label : findChildren<QLabel*>(
"panelTitleLabel"))
2062 label->setStyleSheet(titleLabelStyle);
2064 for (QPushButton* btn : findChildren<QPushButton*>(
"panelTitleBtn"))
2066 btn->setStyleSheet(titleBtnStyle);
2068 for (QFrame* sep : findChildren<QFrame*>(
"panelTitleSep"))
2070 sep->setStyleSheet(titleSepStyle);
2076 mainSplitter_->setStyleSheet(QString(
"QSplitter::handle { background-color: %1; }"
2077 "QSplitter::handle:hover { background-color: %2; }"
2078 "QSplitter::handle:pressed { background-color: %3; }")
2080 .arg(c.
accent.darker(120).name())
2090 statusLabel_->setStyleSheet(QString(
"color: %1; padding: 0 8px;").arg(c.
textMuted.name()));
2095 statusBar()->setStyleSheet(
2096 QString(
"QStatusBar { background-color: %1; border-top: 1px solid %2; }")
2098 statusBar()->update();
2101 if (!selectedGameId_.empty())
2103 detailsPanelManager_->update(selectedGameId_);
2107void MainWindow::setupSidebar()
2116 sidebarManager_ = std::make_unique<SidebarManager>(
2117 libraryController_.get(), launchController_.get(), settingsController_.get(),
2119 sidebarManager_->setupSidebar();
2121 sidebar_ = sidebarManager_->widget();
2123 SidebarManager* sm = sidebarManager_.get();
2127 currentCategory_ = row;
2133 [
this](
const QString& name)
2135 currentCollection_ = name.toStdString();
2139 [
this](
const QString& name)
2141 if (currentCollection_ == name.toStdString())
2143 currentCollection_.clear();
2149void MainWindow::setupGameList()
2151 gameList_ =
new QListView(
this);
2152 gameList_->setViewMode(QListView::ListMode);
2153 gameList_->setSpacing(2);
2154 gameList_->setSelectionMode(QAbstractItemView::ExtendedSelection);
2155 gameList_->setContextMenuPolicy(Qt::CustomContextMenu);
2156 gameList_->setMouseTracking(
true);
2157 gameList_->setUniformItemSizes(
false);
2160 gameListModel_ =
new GameListModel(
this);
2161 gameListProxy_ =
new GameListProxyModel(
this);
2162 gameListProxy_->setSourceModel(gameListModel_);
2163 gameList_->setModel(gameListProxy_);
2166 gameListModel_->setIsRunningAccessor(
2167 [
this](
const std::string&
id)
2168 {
return launchController_ && launchController_->isGameRunning(
id); });
2171 gameListDelegate_ =
new GameListDelegate(
this);
2172 gameList_->setItemDelegate(gameListDelegate_);
2176 gameList_->setStyleSheet(
2177 QString(
"QListView { background-color: %1; border: none; outline: none; }")
2181 gameListEmptyOverlay_ =
new QWidget(gameList_->viewport());
2182 gameListEmptyOverlay_->setObjectName(
"gameListEmptyOverlay");
2183 gameListEmptyOverlay_->setStyleSheet(
"background: transparent;");
2185 auto* overlayLayout =
new QVBoxLayout(gameListEmptyOverlay_);
2186 overlayLayout->setAlignment(Qt::AlignCenter);
2187 overlayLayout->setSpacing(12);
2189 emptyStateLabel_ =
new QLabel(gameListEmptyOverlay_);
2190 emptyStateLabel_->setAlignment(Qt::AlignCenter);
2191 emptyStateLabel_->setWordWrap(
true);
2192 emptyStateLabel_->setStyleSheet(
2193 QString(
"color: %1; padding: 12px;").arg(c.
textSecondary.name()));
2194 overlayLayout->addWidget(emptyStateLabel_);
2196 auto* btnRow =
new QHBoxLayout();
2197 btnRow->setAlignment(Qt::AlignCenter);
2199 emptyStateAddButton_ =
new QPushButton(
"Add Game", gameListEmptyOverlay_);
2200 emptyStateAddButton_->setStyleSheet(
2201 QString(
"QPushButton { background-color: %1; color: %2; border: none; border-radius: "
2202 "6px; padding: 9px 24px; font-weight: bold; }"
2203 "QPushButton:hover { background-color: %3; }"
2204 "QPushButton:pressed { background-color: %4; }")
2209 connect(emptyStateAddButton_, &QPushButton::clicked,
this, &MainWindow::onAddGameClicked);
2211 emptyStateImportButton_ =
new QPushButton(
"Import Games", gameListEmptyOverlay_);
2212 emptyStateImportButton_->setStyleSheet(
2213 QString(
"QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
2214 "border-radius: 6px; padding: 9px 24px; }"
2215 "QPushButton:hover { background-color: %4; border-color: %5; }")
2222 emptyStateImportButton_, &QPushButton::clicked,
this,
2225 GameImportDialog dialog(libraryController_.get(),
this);
2226 if (dialog.exec() == QDialog::Accepted)
2229 libraryController_->getAllGames(),
2230 [
this](
const std::string& gameId,
const std::function<
void(
Game&)>& updater)
2231 { libraryController_->executeWithGame(gameId, updater); });
2232 updateSourceFilters();
2233 updateCategoryCounts();
2235 QTimer::singleShot(500,
this, [
this]() { fetchMissingProtonDB(); });
2239 emptyStateClearSearchButton_ =
new QPushButton(
"Clear Search", gameListEmptyOverlay_);
2240 emptyStateClearSearchButton_->setStyleSheet(
2241 QString(
"QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
2242 "border-radius: 4px; padding: 6px 16px; }"
2243 "QPushButton:hover { background-color: %4; }")
2248 connect(emptyStateClearSearchButton_, &QPushButton::clicked,
this,
2251 searchEdit_->clear();
2252 searchEdit_->setFocus();
2255 emptyStateShowAllButton_ =
new QPushButton(
"Show All Games", gameListEmptyOverlay_);
2256 emptyStateShowAllButton_->setStyleSheet(
2257 QString(
"QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
2258 "border-radius: 4px; padding: 6px 16px; }"
2259 "QPushButton:hover { background-color: %4; }")
2264 connect(emptyStateShowAllButton_, &QPushButton::clicked,
this,
2267 if (sidebarManager_)
2269 sidebarManager_->selectCategoryByRow(0);
2270 sidebarManager_->clearCollectionsSelection();
2272 currentCategory_ = 0;
2273 currentCollection_.clear();
2277 btnRow->addWidget(emptyStateAddButton_);
2278 btnRow->addWidget(emptyStateImportButton_);
2279 btnRow->addWidget(emptyStateClearSearchButton_);
2280 btnRow->addWidget(emptyStateShowAllButton_);
2281 overlayLayout->addLayout(btnRow);
2283 gameListEmptyOverlay_->hide();
2285 gameList_->viewport()->installEventFilter(
this);
2287 connect(gameList_->selectionModel(), &QItemSelectionModel::currentChanged,
this,
2288 &MainWindow::onGameSelected);
2289 connect(gameList_, &QListView::doubleClicked,
this,
2290 [
this](
const QModelIndex&) { onLaunchClicked(); });
2293void MainWindow::setupGameListContextMenu()
2300 contextMenuManager_ = std::make_unique<ContextMenuManager>(
2301 this, libraryController_.get(), detailsPanelManager_.get(), gameActionFactory_.get(),
2303 contextMenuManager_->install(gameList_);
2306 [
this](
const std::vector<std::string>& ids)
2308 for (const auto& id : ids)
2309 libraryController_->removeGame(id);
2310 updateSourceFilters();
2311 updateCategoryCounts();
2316 [
this](
const std::string& gameId,
bool success,
const std::string& gameName,
2317 std::uint32_t appId)
2321 if (notificationService_)
2323 notificationService_->error(
"Failed to uninstall " + gameName);
2327 if (notificationService_)
2329 notificationService_->success(gameName +
" has been uninstalled");
2331 if (
auto* gamePtr = libraryController_->getGameForEdit(gameId))
2333 gamePtr->metadata.steamInstalled = false;
2334 libraryController_->updateGame(gameId, *gamePtr);
2337 detailsPanelManager_->update(gameId);
2338 QProcess::startDetached(
2339 "steam", {QStringLiteral(
"steam://nav/games/details/%1").arg(appId)});
2343void MainWindow::setupStatusBar()
2349 auto* statusIndicators =
new StatusBarContainer(
2350 launchController_.get(), libraryController_.get(),
2353 statusIndicators->setObjectName(
"statusIndicators");
2354 statusBar()->addWidget(statusIndicators, 1);
2358 [
this](
const std::string& gameId) { launchController_->stopGame(gameId); });
2360 [
this](
const std::string& gameId)
2363 QModelIndex idx = proxyIndexForGameId(gameId);
2366 gameList_->setCurrentIndex(idx);
2367 gameList_->scrollTo(idx);
2372 statusProgressBar_ =
new QProgressBar(
this);
2373 statusProgressBar_->setMaximumWidth(150);
2374 statusProgressBar_->setMaximumHeight(16);
2375 statusProgressBar_->setTextVisible(
false);
2376 statusProgressBar_->setRange(0, 0);
2377 statusProgressBar_->setVisible(
false);
2378 statusProgressBar_->setStyleSheet(
2379 QString(
"QProgressBar { background-color: %1; border: none; border-radius: 3px; }"
2380 "QProgressBar::chunk { background-color: %2; border-radius: 3px; }")
2383 statusBar()->addPermanentWidget(statusProgressBar_);
2386 auto* readinessWidget =
new SystemReadinessWidget(
this);
2387 readinessWidget->setMaximumHeight(28);
2392 SettingsDialog dialog(settingsController_.get(),
this);
2395 statusBar()->addPermanentWidget(readinessWidget);
2398 statusLabel_ =
new QLabel(
this);
2399 statusLabel_->setStyleSheet(QString(
"color: %1; padding: 0 8px;").arg(c.
textMuted.name()));
2400 statusBar()->addPermanentWidget(statusLabel_);
2403void MainWindow::setupTrayIcon()
2405 trayIcon_ =
new QSystemTrayIcon(
this);
2406 trayIcon_->setIcon(QIcon::fromTheme(
"applications-games", QIcon(
":/icons/icon.png")));
2407 trayIcon_->setToolTip(
"Game Launcher");
2409 trayMenu_ =
new QMenu(
this);
2413 trayMenu_->addAction(
"Show Window",
this, &QMainWindow::show);
2414 trayMenu_->addAction(
"Hide Window",
this, &QMainWindow::hide);
2415 trayMenu_->addSeparator();
2418 QMenu* runningMenu = trayMenu_->addMenu(
"Running Games");
2420 runningMenu->setEnabled(
false);
2423 QMenu* recentMenu = trayMenu_->addMenu(
"Quick Launch");
2426 trayMenu_->addSeparator();
2427 trayMenu_->addAction(
"Exit",
this,
2434 trayIcon_->setContextMenu(trayMenu_);
2437 connect(trayMenu_, &QMenu::aboutToShow,
this,
2438 [
this, runningMenu, recentMenu]()
2441 runningMenu->clear();
2442 auto runningGames = launchController_->getAllRunningGames();
2443 if (runningGames.empty())
2445 runningMenu->setEnabled(
false);
2446 runningMenu->setTitle(
"Running Games (none)");
2450 runningMenu->setEnabled(
true);
2451 runningMenu->setTitle(QString(
"Running Games (%1)").arg(runningGames.size()));
2452 for (
const auto& info : runningGames)
2454 QString gameName = QString::fromStdString(info.gameName);
2455 QMenu* gameMenu = runningMenu->addMenu(gameName);
2456 gameMenu->addAction(
"Stop",
this, [
this, gameId = info.gameId]()
2457 { launchController_->stopGame(gameId); });
2458 gameMenu->addAction(
"Show in Library",
this,
2459 [
this, gameId = info.gameId]()
2465 QModelIndex idx = proxyIndexForGameId(gameId);
2468 gameList_->setCurrentIndex(idx);
2472 runningMenu->addSeparator();
2473 runningMenu->addAction(
"Stop All",
this,
2474 [
this]() { launchController_->stopAllGames(); });
2478 recentMenu->clear();
2479 auto recentGames = libraryController_->getRecentlyPlayed(5);
2480 if (recentGames.empty())
2482 recentMenu->addAction(
"No recent games")->setEnabled(false);
2486 for (const auto* game : recentGames)
2488 QString gameName = QString::fromStdString(game->name);
2489 std::string gameId = game->id;
2490 QAction* action = recentMenu->addAction(
2494 if (auto recentGame = libraryController_->getGame(gameId))
2496 launchController_->launchGame(gameId, *recentGame);
2501 if (launchController_->isGameRunning(gameId))
2503 action->setEnabled(false);
2504 action->setText(gameName +
" (running)");
2510 if (!runningGames.empty())
2513 QString(
"Game Launcher\n%1 game(s) running").arg(runningGames.size());
2514 trayIcon_->setToolTip(tooltip);
2518 trayIcon_->setToolTip(
"Game Launcher");
2522 connect(trayIcon_, &QSystemTrayIcon::activated,
this, &MainWindow::onTrayIconActivated);
2527void MainWindow::setupControllerCallbacks()
2537 libraryController_->setOnGameAdded(
2538 [guard = QPointer<MainWindow>(
this)](
const core::GameAddedEvent& event)
2542 QMetaObject::invokeMethod(
2546 auto* self = guard.data();
2550 const Game* game = self->libraryController_->getGame(event.gameId);
2551 if (game && game->source == GameSource::Steam &&
2552 game->metadata.steamAppId > 0 && self->steamDownloadMonitor_)
2554 self->steamDownloadMonitor_->watchGame(
2555 static_cast<uint32_t>(game->metadata.steamAppId));
2557 self->scheduleRefresh();
2559 Qt::QueuedConnection);
2562 libraryController_->setOnGameRemoved(
2567 QMetaObject::invokeMethod(
2571 if (auto* self = guard.data())
2572 self->scheduleRefresh();
2574 Qt::QueuedConnection);
2577 libraryController_->setOnGameUpdated(
2582 QMetaObject::invokeMethod(
2586 auto* self = guard.data();
2589 if (event.gameId == self->selectedGameId_)
2590 self->detailsPanelManager_->update(self->selectedGameId_);
2592 Qt::QueuedConnection);
2596 launchController_->setOnStateChanged(
2601 QMetaObject::invokeMethod(
2605 auto* self = guard.data();
2608 self->detailsPanelManager_->updateLaunchButton(self->selectedGameId_);
2612 switch (event.newState)
2614 case core::LaunchState::PreparingLaunch:
2615 statusMsg =
"Preparing to launch...";
2617 case core::LaunchState::WaitingForSteam:
2618 statusMsg =
"Waiting for Steam...";
2620 case core::LaunchState::Launching:
2621 statusMsg =
"Launching game...";
2623 case core::LaunchState::VerifyingStart:
2624 statusMsg =
"Verifying game started...";
2626 case core::LaunchState::Running:
2627 statusMsg =
"Game running";
2629 case core::LaunchState::Stopping:
2630 statusMsg =
"Stopping game...";
2632 case core::LaunchState::Completed:
2633 statusMsg =
"Ready";
2639 if (!statusMsg.isEmpty() && self->statusLabel_)
2641 self->statusLabel_->setText(statusMsg);
2645 if (!event.
gameId.empty())
2647 self->updateGameRow(event.gameId);
2650 Qt::QueuedConnection);
2653 launchController_->setOnProcessStarted(
2658 QMetaObject::invokeMethod(
2662 auto* self = guard.data();
2665 const Game* game = self->libraryController_->getGame(event.gameId);
2666 std::string gameName = game ? game->name : event.processName;
2668 if (self->notificationService_)
2670 self->notificationService_->success(
"▶ " + gameName +
" is now running");
2674 if (self->statusLabel_)
2676 self->statusLabel_->setText(QString::fromStdString(gameName) +
" running");
2679 Qt::QueuedConnection);
2682 launchController_->setOnProcessExited(
2687 QMetaObject::invokeMethod(
2691 auto* self = guard.data();
2694 const Game* game = self->libraryController_->getGame(event.gameId);
2695 std::string gameName = game ? game->name :
"Game";
2697 if (self->notificationService_)
2699 auto duration = event.sessionDuration.count();
2700 auto hours = static_cast<int>(duration / 3600);
2701 auto minutes = static_cast<int>((duration % 3600) / 60);
2702 std::string msg = gameName +
" closed";
2705 msg +=
" • Played " + std::to_string(hours) +
"h " +
2706 std::to_string(minutes) +
"m";
2708 else if (minutes > 0)
2710 msg +=
" • Played " + std::to_string(minutes) +
" minutes";
2712 self->notificationService_->info(msg);
2716 if (self->statusLabel_)
2718 self->statusLabel_->setText(
"Ready");
2724 self->updateGameRow(event.
gameId);
2728 if (event.
gameId == self->selectedGameId_)
2730 if (self->detailsPanelManager_->frameMetricsWidget())
2732 self->detailsPanelManager_->frameMetricsWidget()->clear();
2733 self->detailsPanelManager_->frameMetricsWidget()->setVisible(false);
2735 self->detailsPanelManager_->update(self->selectedGameId_);
2738 Qt::QueuedConnection);
2741 launchController_->setOnLaunchError(
2746 QMetaObject::invokeMethod(
2750 auto* self = guard.data();
2753 const Game* game = self->libraryController_->getGame(event.gameId);
2754 std::string gameName = game ? game->name :
"Game";
2756 if (self->notificationService_)
2758 self->notificationService_->error(
"Failed to launch " + gameName +
": " +
2759 event.errorMessage);
2763 if (self->statusLabel_)
2765 self->statusLabel_->setText(
"Launch failed");
2768 Qt::QueuedConnection);
2772void MainWindow::setupSteamDownloadMonitor()
2774 steamDownloadMonitor_ = std::make_unique<SteamDownloadMonitor>();
2778 steamDownloadMonitor_->setOnProgressUpdate(
2779 [guard = QPointer<MainWindow>(
this)](uint32_t appId,
const SteamDownloadProgress& progress)
2783 QMetaObject::invokeMethod(
2785 [guard, appId, progress]()
2787 if (auto* self = guard.data())
2788 self->onSteamDownloadProgress(
2789 appId, progress.overallProgress,
2790 QString::fromStdString(progress.stateDescription));
2792 Qt::QueuedConnection);
2798 steamDownloadMonitor_->setOnStateChange(
2799 [guard = QPointer<MainWindow>(
this)](uint32_t appId, uint32_t oldState, uint32_t newState)
2801 Logger::info(
"[MainWindow] Steam state change for app {}: {} -> {} ({})", appId,
2806 QMetaObject::invokeMethod(
2808 [guard, appId, oldState, newState]()
2810 auto* self = guard.data();
2814 if (SteamStateFlags::isFullyInstalled(newState))
2818 bool skipBecauseAlreadyKnown = (oldState == 0);
2820 if (skipBecauseAlreadyKnown)
2823 for (const auto* game : self->libraryController_->getAllGames())
2825 if (game->source == GameSource::Steam &&
2826 static_cast<uint32_t>(game->metadata.steamAppId) == appId)
2828 if (!game->metadata.steamInstalled)
2832 skipBecauseAlreadyKnown = false;
2833 Logger::info(
"[MainWindow] App {} is installed in Steam "
2834 "but not in our database - syncing",
2842 if (!skipBecauseAlreadyKnown ||
2843 (oldState != 0 && !SteamStateFlags::isFullyInstalled(oldState)))
2846 self->onSteamInstallComplete(appId);
2849 else if (newState == 0 && oldState != 0)
2852 self->onSteamUninstallComplete(appId, oldState);
2855 Qt::QueuedConnection);
2859 steamDownloadMonitor_->start(1000);
2863 for (
const auto* game : libraryController_->getAllGames())
2867 steamDownloadMonitor_->watchGame(
static_cast<uint32_t
>(game->metadata.steamAppId));
2871 Logger::info(
"[MainWindow] Auto-watching {} Steam games for state changes",
2872 steamDownloadMonitor_->getWatchedGames().size());
2875void MainWindow::onSteamDownloadProgress(uint32_t appId,
double progress,
const QString& status)
2880 const Game* targetGame =
nullptr;
2881 for (
const auto* game : libraryController_->getAllGames())
2884 static_cast<uint32_t
>(game->metadata.steamAppId) == appId)
2886 gameName = QString::fromStdString(game->name);
2894 if (statusLabel_ && !gameName.isEmpty())
2896 statusLabel_->setText(
2897 QString(
"%1: %2 %3%").arg(gameName).arg(status).arg(
static_cast<int>(progress * 100)));
2901 auto* statusIndicators = findChild<StatusBarContainer*>(
"statusIndicators");
2902 if (statusIndicators && statusIndicators->downloadsIndicator())
2904 statusIndicators->downloadsIndicator()->onDownloadProgress(appId, progress, status);
2908 if (targetGame && !gameId.empty())
2915 updateGameRow(gameId);
2917 gameList_->viewport()->update();
2921 const Game* selectedGame =
2922 selectedGameId_.empty() ? nullptr : libraryController_->getGame(selectedGameId_);
2930 if (detailsPanelManager_->downloadProgressWidget() &&
2931 !detailsPanelManager_->downloadProgressWidget()->isVisible())
2933 detailsPanelManager_->downloadProgressWidget()->setVisible(
true);
2937 if (detailsPanelManager_->downloadProgressBar())
2939 detailsPanelManager_->downloadProgressBar()->setValue(
static_cast<int>(progress * 100));
2943 if (detailsPanelManager_->downloadProgressLabel())
2945 QString progressText =
2946 QString(
"%1 - %2%").arg(status).arg(
static_cast<int>(progress * 100));
2947 detailsPanelManager_->downloadProgressLabel()->setText(progressText);
2951 if (detailsPanelManager_->launchButton())
2953 detailsPanelManager_->launchButton()->setEnabled(
false);
2954 detailsPanelManager_->launchButton()->setText(
2955 QString(
"%1... %2%").arg(status).arg(
static_cast<int>(progress * 100)));
2959void MainWindow::onSteamInstallComplete(uint32_t appId)
2962 auto* statusIndicators = findChild<StatusBarContainer*>(
"statusIndicators");
2963 if (statusIndicators && statusIndicators->downloadsIndicator())
2965 statusIndicators->downloadsIndicator()->onDownloadComplete(appId);
2969 if (detailsPanelManager_->downloadProgressWidget())
2971 detailsPanelManager_->downloadProgressWidget()->setVisible(
false);
2975 QString gameName =
"Game";
2976 std::string gameIdToUpdate;
2977 bool wasAlreadyInstalled =
false;
2978 for (
const auto* game : libraryController_->getAllGames())
2981 static_cast<uint32_t
>(game->metadata.steamAppId) == appId)
2983 gameName = QString::fromStdString(game->name);
2984 gameIdToUpdate = game->id;
2986 wasAlreadyInstalled =
2993 if (wasAlreadyInstalled)
2995 Logger::debug(
"[MainWindow] Skipping install complete for {} - already marked installed",
3001 if (!gameIdToUpdate.empty())
3003 if (
auto gamePtr = libraryController_->getGameForEdit(gameIdToUpdate))
3005 gamePtr->metadata.steamInstalled =
true;
3007 libraryController_->updateGame(gameIdToUpdate, *gamePtr);
3012 if (notificationService_)
3014 notificationService_->success(gameName.toStdString() +
" installation complete!");
3017 Logger::info(
"[MainWindow] Steam game {} ({}) installation complete", gameName.toStdString(),
3027 if (!selectedGameId_.empty())
3029 detailsPanelManager_->update(selectedGameId_);
3030 detailsPanelManager_->updateLaunchButton(selectedGameId_);
3034void MainWindow::onSteamUninstallComplete(uint32_t appId, uint32_t previousState)
3036 Q_UNUSED(previousState);
3039 if (detailsPanelManager_->downloadProgressWidget())
3041 detailsPanelManager_->downloadProgressWidget()->setVisible(
false);
3045 QString gameName =
"Game";
3046 std::string gameIdToUpdate;
3047 bool wasInstalled =
false;
3048 for (
const auto* game : libraryController_->getAllGames())
3051 static_cast<uint32_t
>(game->metadata.steamAppId) == appId)
3053 gameName = QString::fromStdString(game->name);
3054 gameIdToUpdate = game->id;
3055 wasInstalled = game->metadata.steamInstalled;
3063 Logger::debug(
"[MainWindow] Skipping uninstall complete for {} - wasn't marked installed",
3069 if (!gameIdToUpdate.empty())
3071 if (
auto gamePtr = libraryController_->getGameForEdit(gameIdToUpdate))
3073 gamePtr->metadata.steamInstalled =
false;
3075 libraryController_->updateGame(gameIdToUpdate, *gamePtr);
3080 if (notificationService_)
3082 notificationService_->info(gameName.toStdString() +
" has been uninstalled.");
3085 Logger::info(
"[MainWindow] Steam game {} ({}) uninstalled", gameName.toStdString(), appId);
3090 statusLabel_->setText(
"Ready");
3100 if (!selectedGameId_.empty())
3102 detailsPanelManager_->update(selectedGameId_);
3103 detailsPanelManager_->updateLaunchButton(selectedGameId_);
3107void MainWindow::onAsyncImageLoaded(
const QString& cacheKey,
const QPixmap& pixmap)
3109 if (pixmap.isNull())
3113 if (cacheKey.startsWith(QStringLiteral(
"hero_")))
3116 QString remainder = cacheKey.mid(5);
3117 qsizetype lastUnderscore = remainder.lastIndexOf(
'_');
3118 if (lastUnderscore > 0)
3120 QString gameId = remainder.left(lastUnderscore);
3121 if (gameId.toStdString() == selectedGameId_ && detailsPanelManager_->heroImageLabel())
3123 detailsPanelManager_->heroImageLabel()->setPixmap(pixmap);
3124 detailsPanelManager_->heroImageLabel()->setFixedHeight(pixmap.height());
3125 detailsPanelManager_->heroImageLabel()->setVisible(
true);
3136 qsizetype xPos = cacheKey.lastIndexOf(
'x');
3141 qsizetype widthStart = cacheKey.lastIndexOf(
'_', xPos - 1);
3145 QString gameId = cacheKey.left(widthStart);
3150 gameListModel_->setIcon(gameId.toStdString(), QIcon(pixmap));
3154void MainWindow::setupKeyboardShortcuts()
3157 if (!shortcutsController_)
3158 shortcutsController_ = std::make_unique<ShortcutsController>(
this);
3159 shortcutsController_->setupKeyboardShortcuts();
3166void MainWindow::setupCommandPalette()
3169 registerPaletteCommands();
3172void MainWindow::registerPaletteCommands()
3175 if (!shortcutsController_)
3176 shortcutsController_ = std::make_unique<ShortcutsController>(
this);
3177 shortcutsController_->registerPaletteCommands();
3180void MainWindow::deleteSelectedGame()
3182 QModelIndexList selectedItems = gameList_ && gameList_->selectionModel()
3183 ? gameList_->selectionModel()->selectedIndexes()
3184 : QModelIndexList();
3185 if (selectedItems.isEmpty())
3189 if (selectedItems.size() > 1)
3191 QMessageBox::StandardButton reply = QMessageBox::question(
3192 this,
"Confirm Removal",
3193 QString(
"Are you sure you want to remove %1 games from the library?")
3194 .arg(selectedItems.size()),
3195 QMessageBox::Yes | QMessageBox::No);
3197 if (reply == QMessageBox::Yes)
3199 int removedCount = 0;
3200 for (
const QModelIndex& idx : selectedItems)
3202 std::string gameId = idx.data(
GameIdRole).toString().toStdString();
3203 libraryController_->removeGame(gameId);
3206 updateSourceFilters();
3207 updateCategoryCounts();
3210 if (notificationService_)
3212 notificationService_->info(
"Removed " + std::to_string(removedCount) +
" games");
3219 if (selectedGameId_.empty())
3222 const Game* game = libraryController_->getGame(selectedGameId_);
3226 QMessageBox::StandardButton reply =
3227 QMessageBox::question(
this,
"Confirm Removal",
3228 QString(
"Are you sure you want to remove '%1' from the library?")
3229 .arg(QString::fromStdString(game->
name)),
3230 QMessageBox::Yes | QMessageBox::No);
3232 if (reply == QMessageBox::Yes)
3234 std::string removedName = game->
name;
3235 libraryController_->removeGame(selectedGameId_);
3238 if (notificationService_)
3240 notificationService_->info(
"Removed: " + removedName);
3245void MainWindow::toggleSelectedFavorite()
3247 if (selectedGameId_.empty())
3250 Game* game = libraryController_->getGameForEdit(selectedGameId_);
3255 libraryController_->updateGame(selectedGameId_, *game);
3258 updateGameRow(selectedGameId_);
3261 detailsPanelManager_->update(selectedGameId_);
3263 if (notificationService_)
3267 notificationService_->success(
"Added to favorites: " + game->
name);
3271 notificationService_->info(
"Removed from favorites: " + game->
name);
3276int MainWindow::rowForGameId(
const std::string& gameId)
const
3278 return gameListModel_ ? gameListModel_->rowForGameId(gameId) : -1;
3281QModelIndex MainWindow::proxyIndexForGameId(
const std::string& gameId)
const
3283 if (!gameListModel_ || !gameListProxy_)
3285 const int srcRow = gameListModel_->rowForGameId(gameId);
3288 return gameListProxy_->mapFromSource(gameListModel_->index(srcRow, 0));
3291void MainWindow::updateGameRow(
const std::string& gameId)
3294 gameListModel_->updateGameById(gameId);
3297void MainWindow::invalidateGameItemCache()
3305void MainWindow::scheduleRefresh()
3309 if (!refreshDebounceTimer_)
3311 refreshDebounceTimer_ =
new QTimer(
this);
3312 refreshDebounceTimer_->setSingleShot(
true);
3313 refreshDebounceTimer_->setInterval(50);
3314 connect(refreshDebounceTimer_, &QTimer::timeout,
this, &MainWindow::refreshGameList);
3316 refreshDebounceTimer_->start();
3319void MainWindow::refreshGameList()
3322 std::string previousSelection = selectedGameId_;
3325 gameList_->setUpdatesEnabled(
false);
3331 core::FilterOptions filter;
3332 switch (currentCategory_)
3364 if (!currentFilter_.empty())
3371 if (sidebarManager_)
3373 int sourceValue = sidebarManager_->selectedSourceValue();
3374 if (sourceValue >= 0)
3379 QString selectedRunnerVersion =
3380 sidebarManager_ ? sidebarManager_->selectedRunnerVersion() : QString();
3383 if (!currentCollection_.empty())
3388 libraryController_->setFilter(filter);
3391 auto games = libraryController_->getFilteredGames();
3393 std::vector<const Game*> filteredGames;
3394 filteredGames.reserve(games.size());
3395 for (
const auto* game : games)
3401 if (currentCategory_ == 5)
3417 if (currentCategory_ == 6 && !launchController_->isGameRunning(game->
id))
3423 if (!selectedRunnerVersion.isEmpty())
3427 if (gameRunner.isEmpty())
3434 gameRunner =
"native";
3436 if (gameRunner != selectedRunnerVersion)
3440 filteredGames.push_back(game);
3448 gameListProxy_->setSearchText(QString());
3449 gameListProxy_->setSourceFilter(QString());
3450 gameListProxy_->setRunnerFilter(QString());
3451 gameListProxy_->setCollectionFilter(QString());
3452 gameListProxy_->setShowRunningOnly(
false);
3453 gameListProxy_->setShowUpdatesOnlyGame(
false);
3454 gameListProxy_->setShowFavoritesOnly(
false);
3458 gameListModel_->setGames(filteredGames);
3469 QString viewModeStr;
3470 switch (currentViewMode_)
3473 viewModeStr =
"List";
3476 viewModeStr =
"Grid";
3479 viewModeStr =
"Compact";
3483 int totalCount =
static_cast<int>(libraryController_->getGameCount());
3484 int showingCount = gameListProxy_ ? gameListProxy_->rowCount() : 0;
3486 statusLabel_->setText(QString(
"Games: %1 (showing %2) | %3 view")
3492 if (!currentFilter_.empty())
3494 searchEdit_->setPlaceholderText(
3495 QString(
"%1 of %2 games").arg(showingCount).arg(totalCount));
3499 searchEdit_->setPlaceholderText(QString(
"Search %1 games...").arg(totalCount));
3503 if (gameListEmptyOverlay_)
3505 if (showingCount == 0)
3507 if (totalCount == 0)
3510 emptyStateLabel_->setText(
3511 "Welcome to Game Launcher!\n\nGet started by importing your game library.");
3512 if (emptyStateAddButton_)
3513 emptyStateAddButton_->setVisible(
true);
3514 if (emptyStateImportButton_)
3515 emptyStateImportButton_->setVisible(
true);
3516 if (emptyStateClearSearchButton_)
3517 emptyStateClearSearchButton_->setVisible(
false);
3518 if (emptyStateShowAllButton_)
3519 emptyStateShowAllButton_->setVisible(
false);
3521 else if (!currentFilter_.empty())
3523 emptyStateLabel_->setText(
3524 QString(
"No games match \"%1\"").arg(QString::fromStdString(currentFilter_)));
3525 if (emptyStateAddButton_)
3526 emptyStateAddButton_->setVisible(
false);
3527 if (emptyStateImportButton_)
3528 emptyStateImportButton_->setVisible(
false);
3529 if (emptyStateClearSearchButton_)
3530 emptyStateClearSearchButton_->setVisible(
true);
3531 if (emptyStateShowAllButton_)
3532 emptyStateShowAllButton_->setVisible(
false);
3534 else if (currentCategory_ > 0 || !currentCollection_.empty())
3536 QString emptyMessage;
3537 if (currentCategory_ == 1)
3538 emptyMessage =
"No favorite games yet\n\nPress F while a game is selected to "
3539 "add it to favorites";
3540 else if (currentCategory_ == 3)
3541 emptyMessage =
"No installed games found";
3542 else if (currentCategory_ == 5)
3543 emptyMessage =
"All games are up to date";
3544 else if (currentCategory_ == 6)
3545 emptyMessage =
"No games currently running";
3546 else if (!currentCollection_.empty())
3547 emptyMessage = QString(
"No games in \"%1\" collection")
3548 .arg(QString::fromStdString(currentCollection_));
3550 emptyMessage =
"No games in this category";
3552 emptyStateLabel_->setText(emptyMessage);
3553 if (emptyStateAddButton_)
3554 emptyStateAddButton_->setVisible(
false);
3555 if (emptyStateImportButton_)
3556 emptyStateImportButton_->setVisible(
false);
3557 if (emptyStateClearSearchButton_)
3558 emptyStateClearSearchButton_->setVisible(
false);
3559 if (emptyStateShowAllButton_)
3560 emptyStateShowAllButton_->setVisible(
true);
3565 emptyStateLabel_->setText(
"No games to show");
3566 if (emptyStateAddButton_)
3567 emptyStateAddButton_->setVisible(
false);
3568 if (emptyStateImportButton_)
3569 emptyStateImportButton_->setVisible(
false);
3570 if (emptyStateClearSearchButton_)
3571 emptyStateClearSearchButton_->setVisible(
false);
3572 if (emptyStateShowAllButton_)
3573 emptyStateShowAllButton_->setVisible(
false);
3576 gameListEmptyOverlay_->resize(gameList_->viewport()->size());
3577 gameListEmptyOverlay_->raise();
3578 gameListEmptyOverlay_->show();
3582 gameListEmptyOverlay_->hide();
3587 gameList_->setUpdatesEnabled(
true);
3590 if (!previousSelection.empty())
3592 QModelIndex idx = proxyIndexForGameId(previousSelection);
3596 const QSignalBlocker blocker(gameList_->selectionModel());
3597 gameList_->setCurrentIndex(idx);
3600 selectedGameId_ = previousSelection;
3601 if (menuBarManager_)
3602 menuBarManager_->setSelectedGameId(selectedGameId_);
3605 detailsPanelManager_->update(previousSelection);
3610void MainWindow::onGameSelected(
const QModelIndex& current,
const QModelIndex& previous)
3614 if (!current.isValid())
3616 selectedGameId_.clear();
3617 detailsPanelManager_->update(
"");
3621 selectedGameId_ = current.data(
GameIdRole).toString().toStdString();
3622 detailsPanelManager_->update(selectedGameId_);
3623 if (menuBarManager_)
3624 menuBarManager_->setSelectedGameId(selectedGameId_);
3626void MainWindow::onLaunchClicked()
3628 if (selectedGameId_.empty())
3631 const Game* game = libraryController_->getGame(selectedGameId_);
3649 steamUrl = QString(
"steam://install/%1").arg(appId);
3651 "Resuming paused download with steam://install/{} (state: {}, progress: {}%)",
3657 steamUrl = QString(
"steam://install/%1").arg(appId);
3658 Logger::info(
"Opening Steam install URL: {}", steamUrl.toStdString());
3665 detailsPanelManager_->launchButton()->setEnabled(
false);
3666 detailsPanelManager_->launchButton()->setText(
"Opening Steam...");
3669 if (
auto gamePtr = libraryController_->getGameForEdit(selectedGameId_))
3672 libraryController_->updateGame(selectedGameId_, *gamePtr);
3676 if (steamDownloadMonitor_)
3678 steamDownloadMonitor_->watchGame(appId);
3682 if (detailsPanelManager_->downloadProgressWidget())
3684 detailsPanelManager_->downloadProgressWidget()->setVisible(
true);
3685 detailsPanelManager_->downloadProgressLabel()->setText(
"Waiting for Steam...");
3686 detailsPanelManager_->downloadProgressBar()->setValue(0);
3692 if (
auto launchGame = libraryController_->getGame(selectedGameId_))
3694 launchController_->launchGame(selectedGameId_, *launchGame);
3699 launchController_->launchGame(selectedGameId_, *game);
3703void MainWindow::onStopClicked()
3705 if (selectedGameId_.empty())
3709 launchController_->killGame(selectedGameId_);
3712void MainWindow::onSearchTextChanged(
const QString& text)
3715 currentFilter_ = text.toStdString();
3719void MainWindow::onAddGameClicked()
3721 AddGameDialog dialog(
this);
3722 if (dialog.exec() == QDialog::Accepted)
3724 Game game = dialog.getGame();
3725 libraryController_->addGame(game);
3726 updateSourceFilters();
3727 updateCategoryCounts();
3730 if (notificationService_)
3732 notificationService_->success(
"Game added: " + game.
name);
3737void MainWindow::onSettingsClicked()
3739 SettingsDialog dialog(settingsController_.get(),
this);
3745#ifdef HAVE_WEBENGINE
3746 const auto& app = settingsController_->getAppSettings();
3748 panelHABtn_->setVisible(app.enableHomeAssistant);
3749 if (!app.enableHomeAssistant && haContainer_ && haContainer_->isVisible())
3750 togglePanel(haContainer_,
nullptr,
"Home Assistant");
3751 if (haPanel_ && !app.homeAssistantUrl.empty())
3752 haPanel_->setUrl(QString::fromStdString(app.homeAssistantUrl));
3756void MainWindow::onRefreshLibrary()
3758 libraryController_->loadLibrary();
3762 libraryController_->getAllGames(),
3763 [
this](
const std::string& gameId,
const std::function<
void(
Game&)>& updater)
3764 { libraryController_->executeWithGame(gameId, updater); });
3767 populateRunnerVersions();
3768 updateSourceFilters();
3769 updateCategoryCounts();
3774void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
3776 if (reason == QSystemTrayIcon::DoubleClick)
3794void MainWindow::onViewModeChanged(
ViewMode mode)
3796 if (currentViewMode_ == mode)
3799 currentViewMode_ = mode;
3800 if (menuBarManager_)
3801 menuBarManager_->setViewMode(mode);
3806void MainWindow::applyViewMode()
3809 gameListDelegate_->setViewMode(currentViewMode_);
3810 gameListDelegate_->setZoomLevel(zoomLevel_);
3813 double zoomFactor = zoomLevel_ / 100.0;
3815 switch (currentViewMode_)
3819 int iconW =
static_cast<int>(64 * zoomFactor);
3820 int iconH =
static_cast<int>(36 * zoomFactor);
3821 gameList_->setViewMode(QListView::ListMode);
3822 gameList_->setIconSize(QSize(iconW, iconH));
3823 gameList_->setSpacing(0);
3824 gameList_->setGridSize(QSize());
3825 gameList_->setWordWrap(
false);
3826 gameList_->setUniformItemSizes(
true);
3832 int gridIconW =
static_cast<int>(GRID_ICON_WIDTH * zoomFactor);
3833 int gridIconH =
static_cast<int>(GRID_ICON_HEIGHT * zoomFactor);
3834 int gridSpacing =
static_cast<int>(12 * zoomFactor);
3835 int textSpace =
static_cast<int>(40 * zoomFactor);
3836 gameList_->setViewMode(QListView::IconMode);
3837 gameList_->setIconSize(QSize(gridIconW, gridIconH));
3838 gameList_->setSpacing(gridSpacing);
3840 gameList_->setGridSize(QSize(gridIconW + 16, gridIconH + textSpace));
3841 gameList_->setWordWrap(
true);
3842 gameList_->setUniformItemSizes(
true);
3843 gameList_->setResizeMode(QListView::Adjust);
3844 gameList_->setMovement(QListView::Static);
3845 gameList_->verticalScrollBar()->setSingleStep(30);
3851 int compactIcon =
static_cast<int>(28 * zoomFactor);
3852 gameList_->setViewMode(QListView::ListMode);
3853 gameList_->setIconSize(QSize(compactIcon, compactIcon));
3854 gameList_->setSpacing(0);
3855 gameList_->setGridSize(QSize());
3856 gameList_->setWordWrap(
false);
3857 gameList_->setUniformItemSizes(
true);
3863void MainWindow::updateGridIconSize()
3868 int spacing =
static_cast<int>(8 * zoomFactor);
3871 int availableWidth = gameList_->viewport()->width();
3872 int baseItemWidth =
static_cast<int>(GRID_ICON_WIDTH * zoomFactor) + spacing * 2;
3873 int columns = qMax(2, availableWidth / baseItemWidth);
3876 int itemWidth = (availableWidth - (columns + 1) * spacing) / columns;
3877 itemWidth = qMax(itemWidth,
static_cast<int>(120 * zoomFactor));
3880 int iconWidth = itemWidth - 10;
3881 int iconHeight =
static_cast<int>(iconWidth * 1.5);
3883 int itemHeight = iconHeight + textSpace;
3885 gameList_->setIconSize(QSize(iconWidth, iconHeight));
3886 gameList_->setGridSize(QSize(itemWidth, itemHeight));
3887 gameList_->setSpacing(spacing);
3893 QMainWindow::resizeEvent(event);
3897 if (!resizeDebounceTimer_)
3899 resizeDebounceTimer_ =
new QTimer(
this);
3900 resizeDebounceTimer_->setSingleShot(
true);
3901 resizeDebounceTimer_->setInterval(200);
3902 connect(resizeDebounceTimer_, &QTimer::timeout,
this, &MainWindow::updateGridIconSize);
3904 resizeDebounceTimer_->start();
3909 QMainWindow::changeEvent(event);
3911 if (event->type() == QEvent::WindowStateChange)
3914 bool isMinimized = windowState() & Qt::WindowMinimized;
3917 QTimer* updateTimer = findChild<QTimer*>(
"updateTimer");
3921 updateTimer->stop();
3923 updateTimer->start();
3926 if (frameMetricsTimer_)
3929 frameMetricsTimer_->stop();
3931 frameMetricsTimer_->start();
3934#ifdef HAVE_QTERMWIDGET
3939 terminalPanel_->pauseProcess();
3941 terminalPanel_->resumeProcess();
3949 if (!event->mimeData()->hasUrls())
3956 const QList<QUrl> urls =
event->mimeData()->urls();
3957 for (
const QUrl& url : urls)
3959 if (!url.isLocalFile())
3962 QString path = url.toLocalFile();
3963 QFileInfo fileInfo(path);
3964 if (!fileInfo.isFile())
3968 QString suffix = fileInfo.suffix().toLower();
3969 static const QStringList gameExtensions = {
3971 "sh",
"x86_64",
"x86",
"appimage",
3975 if (gameExtensions.contains(suffix) || fileInfo.isExecutable())
3977 event->acceptProposedAction();
3987 if (!event->mimeData()->hasUrls())
3993 const QList<QUrl> urls =
event->mimeData()->urls();
3994 for (
const QUrl& url : urls)
3996 if (!url.isLocalFile())
3999 QString filePath = url.toLocalFile();
4000 QFileInfo fileInfo(filePath);
4001 if (!fileInfo.isFile())
4005 QString suffix = fileInfo.suffix().toLower();
4006 static const QStringList gameExtensions = {
4007 "exe",
"msi",
"sh",
"x86_64",
"x86",
"appimage",
"jar",
4010 if (!gameExtensions.contains(suffix) && !fileInfo.isExecutable())
4015 QString baseName = fileInfo.completeBaseName();
4016 baseName.replace(
'_',
' ');
4017 baseName.replace(
'-',
' ');
4020 QStringList words = baseName.split(
' ', Qt::SkipEmptyParts);
4021 for (QString& word : words)
4023 if (!word.isEmpty())
4025 word[0] = word[0].toUpper();
4028 QString gameName = words.join(
' ');
4032 game.
name = gameName.toStdString();
4038 if (suffix ==
"exe" || suffix ==
"msi")
4050 if (dialog.exec() == QDialog::Accepted)
4053 libraryController_->addGame(resultGame);
4054 updateSourceFilters();
4055 updateCategoryCounts();
4058 if (notificationService_)
4060 notificationService_->success(
"Game added: " + resultGame.
name);
4068 event->acceptProposedAction();
4074 if (gameList_ && obj == gameList_->viewport() && event->type() == QEvent::Resize)
4076 if (gameListEmptyOverlay_ && gameListEmptyOverlay_->isVisible())
4078 gameListEmptyOverlay_->resize(gameList_->viewport()->size());
4079 gameListEmptyOverlay_->raise();
4086 return QMainWindow::eventFilter(obj, event);
4089void MainWindow::updateItemIcons()
4100 double zoomFactor = zoomLevel_ / 100.0;
4104 switch (currentViewMode_)
4107 iconSize = QSize(
static_cast<int>(GRID_ICON_WIDTH * zoomFactor),
4108 static_cast<int>(GRID_ICON_HEIGHT * zoomFactor));
4112 iconSize = QSize(
static_cast<int>(48 * zoomFactor),
static_cast<int>(27 * zoomFactor));
4117 iconSize = QSize(
static_cast<int>(64 * zoomFactor),
static_cast<int>(36 * zoomFactor));
4122 if (!gameListProxy_ || !gameListModel_)
4126 QRect visibleRect = gameList_->viewport()->rect();
4129 for (
int pass = 0; pass < 2; ++pass)
4131 bool visiblePass = (pass == 0);
4133 for (
int i = 0; i < gameListProxy_->rowCount(); ++i)
4135 QModelIndex idx = gameListProxy_->index(i, 0);
4140 QRect itemRect = gameList_->visualRect(idx);
4141 bool isVisible = visibleRect.intersects(itemRect);
4144 if (visiblePass != isVisible)
4147 QString gameId = idx.data(
GameIdRole).toString();
4148 const Game* game = libraryController_->getGame(gameId.toStdString());
4154 imageCache_ ? imageCache_->getGameThumbnail(game, iconSize, preferredImageType)
4156 if (!thumbnail.isNull())
4158 gameListModel_->setIcon(gameId.toStdString(), QIcon(thumbnail));
4168void MainWindow::onSortChanged(
int index)
4171 if (currentSort_ == sort)
4174 currentSort_ = sort;
4175 if (menuBarManager_)
4176 menuBarManager_->setSortOption(sort);
4179 core::SortOptions sortOptions;
4208 libraryController_->setSort(sortOptions);
4212void MainWindow::onZoomChanged(
int value)
4221void MainWindow::applyZoomChange()
4224 gameList_->setUpdatesEnabled(
false);
4229 gameList_->setViewMode(QListView::ListMode);
4239 gameList_->setUpdatesEnabled(
true);
4240 gameList_->doItemsLayout();
4241 gameList_->viewport()->update();
4251void MainWindow::populateRunnerVersions()
4253 if (sidebarManager_)
4254 sidebarManager_->populateRunnerVersions();
4257void MainWindow::updateSourceFilters()
4259 if (sidebarManager_)
4260 sidebarManager_->updateSourceFilters();
4263void MainWindow::updateCategoryCounts()
4265 if (sidebarManager_)
4266 sidebarManager_->updateCategoryCounts();
4273void MainWindow::updateCollectionsList()
4275 if (sidebarManager_)
4276 sidebarManager_->updateCollectionsList();
4279void MainWindow::showCreateCollectionDialog()
4281 if (sidebarManager_)
4282 sidebarManager_->showCreateCollectionDialog(
this);
4285void MainWindow::fetchMissingProtonDB()
4287 QPointer<MainWindow> self =
this;
4288 auto* libraryController = libraryController_.get();
4289 (void)QtConcurrent::run(
4290 [self, libraryController]()
4295 auto allGames = libraryController->getAllGames();
4297 std::vector<std::pair<std::string, int>> needsFetch;
4298 const time_t oneWeekAgo = time(
nullptr) - (7 * 24 * 60 * 60);
4299 for (
const auto* game : allGames)
4311 if (needsFetch.empty())
4316 QMetaObject::invokeMethod(
4318 [self, count = needsFetch.size()]()
4322 if (self->statusProgressBar_)
4324 self->statusProgressBar_->setVisible(true);
4325 self->statusLabel_->setText(
"Fetching ProtonDB data for " +
4326 QString::number(count) +
" game(s)...");
4329 Qt::QueuedConnection);
4333 for (
const auto& entry : needsFetch)
4338 const std::string& gameId = entry.first;
4339 int steamAppId = entry.second;
4342 if (info.found && self)
4344 QMetaObject::invokeMethod(
4346 [self, libraryController, gameId, info]()
4350 Game* mutableGame = libraryController->getGameForEdit(gameId);
4353 mutableGame->metadata.protondbTier = info.tier;
4354 mutableGame->metadata.protondbConfidence = info.confidence;
4355 mutableGame->metadata.protondbScore = info.score;
4356 mutableGame->metadata.protondbLastUpdated = time(nullptr);
4357 libraryController->updateGame(gameId, *mutableGame);
4360 Qt::QueuedConnection);
4367 QMetaObject::invokeMethod(
4369 [self, libraryController, updated]()
4373 if (self->statusProgressBar_)
4374 self->statusProgressBar_->setVisible(false);
4378 libraryController->saveLibrary();
4379 self->refreshGameList();
4380 if (self->notificationService_)
4382 self->notificationService_->success(
"Updated ProtonDB data for " +
4383 std::to_string(updated) +
4388 Qt::QueuedConnection);
4393void MainWindow::syncSteamInstalledStatus()
4396 SteamLibraryScanner scanner;
4400 std::set<uint32_t> installedAppIds;
4401 for (
const auto& steamGame : installedGames)
4406 installedAppIds.insert(steamGame.appId);
4412 for (
const auto* game : libraryController_->getAllGames())
4420 bool actuallyInstalled = installedAppIds.count(appId) > 0;
4425 if (
auto gamePtr = libraryController_->getGameForEdit(game->
id))
4427 gamePtr->metadata.steamInstalled = actuallyInstalled;
4430 libraryController_->updateGame(game->
id, *gamePtr);
4433 Logger::info(
"[MainWindow] Synced Steam game {} ({}): installed={}", game->
name,
4434 appId, actuallyInstalled);
4441 Logger::info(
"[MainWindow] Synced installed status for {} Steam games", updated);
4449void MainWindow::onGameStarted(
const std::string& gameId)
4453 if (!settingsController_)
4456 const auto& settings = settingsController_->getAppSettings();
4458 Logger::info(
"[MainWindow] Settings: autoSwitch={}, autoGamingLayout={}, widthPercent={}, "
4459 "edge={}, fullHeight={}",
4460 settings.autoSwitchToRunningGame, settings.autoGamingLayout,
4461 settings.gamingLayoutWidthPercent, settings.gamingLayoutEdge,
4462 settings.gamingLayoutFullHeight);
4465 if (settings.autoSwitchToRunningGame)
4468 QModelIndex idx = proxyIndexForGameId(gameId);
4471 gameList_->setCurrentIndex(idx);
4472 gameList_->scrollTo(idx);
4476 if (detailsContainer_ && !detailsContainer_->isVisible())
4478 togglePanel(detailsContainer_, panelDetailsBtn_,
"Details");
4481 Logger::info(
"[MainWindow] Auto-switched to game details panel");
4485 if (settings.autoGamingLayout && !isInGamingLayout_)
4487 Logger::info(
"[MainWindow] Entering gaming layout...");
4488 enterGamingLayout();
4493 "[MainWindow] Gaming layout skipped: autoGamingLayout={}, isInGamingLayout_={}",
4494 settings.autoGamingLayout, isInGamingLayout_);
4498void MainWindow::onGameStopped(
const std::string& gameId)
4502 if (!settingsController_)
4505 const auto& settings = settingsController_->getAppSettings();
4508 if (isInGamingLayout_ && settings.restoreLayoutOnExit)
4512 else if (gamingLayoutOverridden_)
4514 Logger::info(
"[MainWindow] Gaming layout was manually overridden - not restoring layout");
4518 gamingLayoutOverridden_ =
false;
4521void MainWindow::enterGamingLayout()
4523 if (isInGamingLayout_)
4529 gamingLayoutOverridden_ =
false;
4532 savedSidebarVisible_ = sidebarContainer_ && sidebarContainer_->isVisible();
4533 savedGameListVisible_ = gameListContainer_ && gameListContainer_->isVisible();
4534 savedDetailsVisible_ = detailsContainer_ && detailsContainer_->isVisible();
4535#ifdef HAVE_QTERMWIDGET
4536 savedMonitorVisible_ = terminalContainer_ && terminalContainer_->isVisible();
4538#ifdef HAVE_WEBENGINE
4539 savedHAVisible_ = haContainer_ && haContainer_->isVisible();
4545 savedSplitterSizes_ = mainSplitter_->sizes();
4558 if (sidebarContainer_)
4560 sidebarContainer_->setMinimumWidth(0);
4561 sidebarContainer_->setMaximumWidth(0);
4562 sidebarContainer_->setVisible(
false);
4563 if (panelSidebarBtn_)
4564 panelSidebarBtn_->setChecked(
false);
4568 if (gameListContainer_)
4570 gameListContainer_->setMinimumWidth(0);
4571 gameListContainer_->setMaximumWidth(0);
4572 gameListContainer_->setVisible(
false);
4574 panelGamesBtn_->setChecked(
false);
4578 if (detailsContainer_)
4580 detailsContainer_->setMinimumWidth(200);
4581 detailsContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4582 detailsContainer_->setVisible(
true);
4583 if (panelDetailsBtn_)
4584 panelDetailsBtn_->setChecked(
true);
4587#ifdef HAVE_QTERMWIDGET
4589 if (terminalContainer_)
4591 terminalContainer_->setMinimumWidth(200);
4592 terminalContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4593 terminalContainer_->setVisible(
true);
4594 if (panelMonitorBtn_)
4595 panelMonitorBtn_->setChecked(
true);
4600 terminalPanel_->resumeProcess();
4601 QString command =
"btop";
4602 if (monitorTypeCombo_)
4604 switch (monitorTypeCombo_->currentIndex())
4617 QString s = QString::fromLocal8Bit(qgetenv(
"SHELL"));
4618 command = s.isEmpty() ? QStringLiteral(
"/bin/bash") : s;
4625 terminalPanel_->startCommand(command);
4630#ifdef HAVE_WEBENGINE
4634 haContainer_->setMinimumWidth(0);
4635 haContainer_->setMaximumWidth(0);
4636 haContainer_->setVisible(
false);
4638 panelHABtn_->setChecked(
false);
4642 isInGamingLayout_ =
true;
4650 if (!mainSplitter_ || !isInGamingLayout_)
4657 QApplication::processEvents();
4660 int splitterWidth = mainSplitter_->width();
4661 Logger::info(
"[MainWindow] Gaming layout: window width={}, splitter width={}", width(),
4665 QList<int> targetSizes;
4666#ifdef HAVE_QTERMWIDGET
4667 int detailsWidth = splitterWidth * 15 / 100;
4668 int monitorWidth = splitterWidth - detailsWidth;
4669 targetSizes << 0 << 0 << detailsWidth << monitorWidth;
4670 Logger::info(
"[MainWindow] Gaming layout target: 0, 0, {}, {}", detailsWidth,
4673 targetSizes << 0 << 0 << splitterWidth;
4676 QList<int> startSizes = mainSplitter_->sizes();
4677 const int animSteps = 15;
4678 const int animIntervalMs = 20;
4679 int* step =
new int(0);
4680 QTimer* animTimer =
new QTimer(
this);
4681 animTimer->setInterval(animIntervalMs);
4682 connect(animTimer, &QTimer::timeout,
this,
4683 [
this, startSizes, targetSizes, step, animTimer]()
4686 double t =
static_cast<double>(*step) / animSteps;
4687 double ease = 1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t);
4688 QList<int> interpolated;
4689 for (
int i = 0; i < qMin(startSizes.size(), targetSizes.size()); ++i)
4692 static_cast<int>((targetSizes[i] - startSizes[i]) * ease);
4693 mainSplitter_->setSizes(interpolated);
4694 if (*step >= animSteps)
4696 mainSplitter_->setSizes(targetSizes);
4698 animTimer->deleteLater();
4706 QTimer::singleShot(0,
this, &MainWindow::updateToolbarVisibility);
4708 Logger::info(
"[MainWindow] Gaming layout entered - panels configured");
4711void MainWindow::exitGamingLayout()
4713 if (!isInGamingLayout_)
4722 if (sidebarContainer_)
4724 sidebarContainer_->setMinimumWidth(120);
4725 sidebarContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4726 sidebarContainer_->setVisible(savedSidebarVisible_);
4727 if (panelSidebarBtn_)
4728 panelSidebarBtn_->setChecked(savedSidebarVisible_);
4731 if (gameListContainer_)
4733 gameListContainer_->setMinimumWidth(200);
4734 gameListContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4735 gameListContainer_->setVisible(savedGameListVisible_);
4737 panelGamesBtn_->setChecked(savedGameListVisible_);
4740 if (detailsContainer_)
4742 detailsContainer_->setMinimumWidth(250);
4743 detailsContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4744 detailsContainer_->setVisible(savedDetailsVisible_);
4745 if (panelDetailsBtn_)
4746 panelDetailsBtn_->setChecked(savedDetailsVisible_);
4749#ifdef HAVE_QTERMWIDGET
4750 if (terminalContainer_)
4752 terminalContainer_->setMinimumWidth(300);
4753 terminalContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4754 terminalContainer_->setVisible(savedMonitorVisible_);
4755 if (panelMonitorBtn_)
4756 panelMonitorBtn_->setChecked(savedMonitorVisible_);
4759 if (!savedMonitorVisible_ && terminalPanel_)
4761 terminalPanel_->pauseProcess();
4766#ifdef HAVE_WEBENGINE
4769 haContainer_->setMinimumWidth(400);
4770 haContainer_->setMaximumWidth(QWIDGETSIZE_MAX);
4771 haContainer_->setVisible(savedHAVisible_);
4773 panelHABtn_->setChecked(savedHAVisible_);
4778 if (mainSplitter_ && !savedSplitterSizes_.isEmpty())
4780 QList<int> startSizes = mainSplitter_->sizes();
4781 QList<int> targetSizes = savedSplitterSizes_;
4782 const int animSteps = 15;
4783 const int animIntervalMs = 20;
4784 int* step =
new int(0);
4785 QTimer* animTimer =
new QTimer(
this);
4786 animTimer->setInterval(animIntervalMs);
4787 connect(animTimer, &QTimer::timeout,
this,
4788 [
this, startSizes, targetSizes, step, animTimer]()
4791 double t =
static_cast<double>(*step) / animSteps;
4792 double ease = 1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t);
4793 QList<int> interpolated;
4794 for (
int i = 0; i < qMin(startSizes.size(), targetSizes.size()); ++i)
4797 static_cast<int>((targetSizes[i] - startSizes[i]) * ease);
4798 mainSplitter_->setSizes(interpolated);
4799 if (*step >= animSteps)
4801 mainSplitter_->setSizes(targetSizes);
4803 animTimer->deleteLater();
4810 isInGamingLayout_ =
false;
4813 QTimer::singleShot(0,
this, &MainWindow::updateToolbarVisibility);
4816void MainWindow::checkRunningGameOnStartup()
4818 Logger::info(
"[MainWindow] Checking for already-running games on startup");
4820 if (!launchController_ || !libraryController_)
4822 Logger::warn(
"[MainWindow] Controllers not ready for startup check");
4827 if (settingsController_)
4829 const auto& settings = settingsController_->getAppSettings();
4830 Logger::info(
"[MainWindow] Startup check - autoSwitch={}, autoGamingLayout={}",
4831 settings.autoSwitchToRunningGame, settings.autoGamingLayout);
4835 std::string runningGameId;
4836 int checkedCount = 0;
4837 for (
const auto* game : libraryController_->getAllGames())
4840 if (launchController_->isGameRunning(game->
id))
4842 runningGameId = game->
id;
4843 Logger::info(
"[MainWindow] Found running game on startup: {} (checked {} games)",
4844 game->
name, checkedCount);
4849 if (runningGameId.empty())
4851 Logger::info(
"[MainWindow] No games running on startup (checked {} games)", checkedCount);
4856 previousRunningGameId_ = runningGameId;
4859 Logger::info(
"[MainWindow] Triggering onGameStarted for startup-detected game");
4860 onGameStarted(runningGameId);
Async image loader using QThreadPool.
void imageLoaded(const QString &cacheKey, const QPixmap &pixmap)
Emitted when an image has been loaded (on main thread).
void gameChanged(const std::string &gameId)
void stopRequested(const std::string &gameId)
void configureRequested(const std::string &gameId)
void launchRequested(const std::string &gameId)
FrameMetrics getMetrics(const std::string &gameId) const
Get current metrics for a game.
static FrameMetricsService & instance()
Get the singleton instance.
int cleanupOldLogs(int maxAgeHours=24)
Clean up old MangoHud log files.
void setOnGameStatsUpdated(std::function< void(const std::string &gameId)> callback)
const GameProcess * getRunningProcess(const std::string &gameId) const
void scanForRunningGames(const std::vector< Game * > &games, GameAccessCallback gameAccessCallback)
static GameProcessManager & instance()
Complete representation of a game in the library.
GameMetadata metadata
Descriptive information and media.
bool isFavorite
Is this marked as a favorite game?
std::string name
Display name shown in UI.
std::string id
Unique identifier (auto-generated or user-specified).
GameRunner runner
Runner/compatibility layer to use (Native, Proton, Wine, etc.).
GameRunnerConfig runnerConfig
How to launch and run the game.
bool isInstalled() const
Check if game is currently installed.
GameSource source
Where the game was acquired from (Steam, GOG, Local, etc.).
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
void installRequested(const LutrisInstallerScript &script)
void closeEvent(QCloseEvent *event) override
void changeEvent(QEvent *event) override
void dragEnterEvent(QDragEnterEvent *event) override
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
static ProtonDBGameInfo getGameInfo(int steamAppId)
Get game info by Steam App ID.
void stopGameRequested(const std::string &gameId)
void showGameRequested(const std::string &gameId)
static SteamDownloadProgress readGameState(uint32_t appId)
Read current state of a game directly from its appmanifest.
static std::string fetchGameNameFromCache(uint32_t appId)
Get game name from pre-loaded cache (instant).
static bool loadAppNameCache()
Load Steam app name cache from GetAppList API.
static std::string fetchGameNameFromSteamAPI(uint32_t appId)
Fetch game name from Steam Web API.
std::vector< SteamGame > scanAllLibraries()
Scan all Steam libraries for installed games.
static std::string readSteamProtonVersion(uint32_t appId)
Read Proton compatibility tool mapping for a game from config.vdf.
static SteamProcessMonitor & instance()
Terminal panel widget that embeds a terminal emulator.
static ThemeManager & instance()
void applyToApplication()
Apply current theme to the entire application.
void styleMenu(QMenu *menu) const
Apply complete menu styling (stylesheet + palette) to a QMenu.
void initialize(core::SettingsController *settingsController)
void themeChanged()
Emitted when theme or accent color changes.
int zoomLevel() const
Get current zoom level (75-150, default 100).
void setTheme(const QString &themeId)
Set active theme by ID.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
void saveToSettings()
Save theme settings to settings controller.
GameSource
Where the game was acquired from (store/service/local).
@ Steam
Steam store/platform.
@ Local
Manually added game (not from a store).
ImageType
Types of game images available.
@ VerticalCover
Vertical cover art (600x900, portrait).
@ Header
Small header image (460x215).
@ Installing
Game is being installed.
@ NotInstalled
Game is in library but not installed.
@ Installed
Game is installed and ready to play.
@ Proton
Proton (Steam's Wine fork).
@ Native
Native Linux executable (no compatibility layer).
@ Wine
Wine compatibility layer.
static void openSteamUrl(const QString &steamUrl)
std::string getStateDescription(uint32_t flags)
Get human-readable state description.
bool isFullyInstalled(uint32_t flags)
Check if a game is fully installed.
bool needsUpdate(uint32_t flags)
Check if a game needs an update.
bool enableVkBasalt
Enable VkBasalt shader injection.
std::string executablePath
Full path to game executable.
std::string workingDirectory
Working directory for game execution.
bool enableMangoHud
Enable MangoHud performance overlay.
bool enableGamePerformance
Enable game-performance wrapper (CachyOS).
bool enableFsync
Enable Fsync (kernel 5.16+, best performance).
std::string runnerVersion
Runner version: "wine-8.0", "proton-8.0-5", etc.
std::string runnerType
Runner type: "wine", "proton", "native", etc.
bool enableGameMode
Enable GameMode CPU governor optimization.
std::string protonVersion
Proton version (e.g., "proton-cachyos-slr").
std::string stateDescription
Human-readable state.
uint32_t stateFlags
Current StateFlags.
double overallProgress
Combined progress (0.0 to 1.0).
std::optional< std::string > collection
std::optional< GameSource > source
@ Game
Game-specific fixes.