game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
details_panel_manager.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// ui/qt/details_panel_manager.cpp
4// ==============================================================================
5// Extracted from MainWindow in the MED-7 pass. Owns the right-hand "details
6// panel" widget tree and the rendering logic that populates it. Behaviour is
7// preserved verbatim — this file only relocates code, it does not change it.
8// ==============================================================================
9
11
12#include "a11y_utils.h"
16#include "dpr_utils.h"
17#include "icon_font.h"
22#include "models/game.h"
25#include "theme_manager.h"
28
29#include <QComboBox>
30#include <QDateTime>
31#include <QDesktopServices>
32#include <QFrame>
33#include <QHBoxLayout>
34#include <QInputDialog>
35#include <QLabel>
36#include <QLayoutItem>
37#include <QMouseEvent>
38#include <QPalette>
39#include <QProcess>
40#include <QProgressBar>
41#include <QPushButton>
42#include <QScrollArea>
43#include <QSignalBlocker>
44#include <QSizePolicy>
45#include <QStringList>
46#include <QVBoxLayout>
47
48#include <algorithm>
49#include <chrono>
50#include <filesystem>
51#include <unordered_map>
52
53namespace
54{
55// Open a steam:// URL using the steam command directly (avoids KIO issues)
56void openSteamUrlFromPanel(const QString& steamUrl)
57{
58 // Use steam command directly to avoid KIO protocol handler issues
59 // steam:// URLs work when passed to the steam executable
60 QProcess::startDetached("steam", {steamUrl});
61}
62} // namespace
63
64// ==============================================================================
65// DetailsPanelManager::Impl
66// ==============================================================================
67
68class DetailsPanelManager::Impl : public QObject
69{
70 public:
71 Impl(DetailsPanelManager* owner, QWidget* parent, core::GameLibraryController* libCtrl,
72 core::LaunchController* launchCtrl, GameThumbnailCache* imgCache, ThemeManager* themeMgr)
73 : QObject(owner), owner_(owner), libCtrl_(libCtrl), launchCtrl_(launchCtrl),
74 imgCache_(imgCache), themeMgr_(themeMgr)
75 {
76 setupWidgets(parent);
77 }
78
79 void update(const std::string& gameId);
80 void updateRunningInfo(const std::string& gameId);
81 void updateLaunchButton(const std::string& gameId);
82 void applyTheme();
83
84 bool eventFilter(QObject* obj, QEvent* event) override;
85
86 // Widget accessors
87 QWidget* detailsPanel() const
88 {
89 return detailsPanel_;
90 }
91 QLabel* heroImageLabel() const
92 {
93 return heroImageLabel_;
94 }
95 QWidget* downloadProgressWidget() const
96 {
97 return downloadProgressWidget_;
98 }
99 QProgressBar* downloadProgressBar() const
100 {
101 return downloadProgressBar_;
102 }
103 QLabel* downloadProgressLabel() const
104 {
105 return downloadProgressLabel_;
106 }
107 QPushButton* launchButton() const
108 {
109 return launchButton_;
110 }
112 {
113 return frameMetricsWidget_;
114 }
115
116 // Current selection context (updated by update()).
117 std::string currentGameId_;
118
119 private:
120 void setupWidgets(QWidget* parent);
121
122 // Disk-space cache moved with updateDetailsPanel() body. Returns
123 // available bytes for a path, refreshed at most every 30 seconds.
124 uint64_t getCachedDiskSpace(const std::string& path);
125
126 struct DiskSpaceCacheEntry
127 {
128 std::string path;
129 uint64_t availableBytes = 0;
130 std::chrono::steady_clock::time_point lastUpdate;
131 };
132 std::unordered_map<std::string, DiskSpaceCacheEntry> diskSpaceCache_;
133
134 // ---- context ----
135 DetailsPanelManager* owner_ = nullptr;
136 core::GameLibraryController* libCtrl_ = nullptr;
137 core::LaunchController* launchCtrl_ = nullptr;
138 GameThumbnailCache* imgCache_ = nullptr;
139 ThemeManager* themeMgr_ = nullptr;
140
141 // ---- widgets (migrated from MainWindow) ----
142 QWidget* detailsPanel_ = nullptr;
143 QLabel* heroImageLabel_ = nullptr;
144 QLabel* logoImageLabel_ = nullptr;
145 QLabel* gameNameLabel_ = nullptr;
146 QLabel* gameInfoLabel_ = nullptr;
147 QLabel* coverArtLabel_ = nullptr;
148 QLabel* gameDescLabel_ = nullptr;
149 QLabel* gameGenresLabel_ = nullptr;
150 QLabel* gameStatsLabel_ = nullptr;
151 QLabel* gameSteamInfoLabel_ = nullptr;
152 QLabel* gameLaunchConfigLabel_ = nullptr;
153
154 QComboBox* completionStatusCombo_ = nullptr;
155 QProgressBar* completionProgressBar_ = nullptr;
156
157 QWidget* hltbSection_ = nullptr;
158 QLabel* hltbMainLabel_ = nullptr;
159 QLabel* hltbExtrasLabel_ = nullptr;
160 QLabel* hltbCompleteLabel_ = nullptr;
161
162 QWidget* sessionHistorySection_ = nullptr;
163 QLabel* sessionHistoryLabel_ = nullptr;
164
165 QWidget* userNotesSection_ = nullptr;
166 QLabel* userNotesLabel_ = nullptr;
167
168 QWidget* configPresetsSection_ = nullptr;
169 QHBoxLayout* presetsButtonLayout_ = nullptr;
170
171 QLabel* collectionsLabel_ = nullptr;
172
173 CollapsibleSection* overviewSection_ = nullptr;
174 CollapsibleSection* statisticsSection_ = nullptr;
175 CollapsibleSection* configurationSection_ = nullptr;
176 CollapsibleSection* notesSection_ = nullptr;
177 CollapsibleSection* systemSection_ = nullptr;
178
179 QWidget* runningInfoContainer_ = nullptr;
180 QLabel* gameRunningInfoLabel_ = nullptr;
181 FrameMetricsWidget* frameMetricsWidget_ = nullptr;
182 QLabel* systemInfoLabel_ = nullptr;
183
184 QWidget* downloadProgressWidget_ = nullptr;
185 QProgressBar* downloadProgressBar_ = nullptr;
186 QLabel* downloadProgressLabel_ = nullptr;
187
188 QWidget* updateBannerWidget_ = nullptr;
189 QLabel* updateBannerLabel_ = nullptr;
190 QPushButton* updateNowButton_ = nullptr;
191
192 QPushButton* launchButton_ = nullptr;
193 QPushButton* stopButton_ = nullptr;
194 QPushButton* configButton_ = nullptr;
195};
196
197// ------------------------------------------------------------------------
198// setupWidgets — MOVED VERBATIM from MainWindow::setupDetailsPanel()
199// ------------------------------------------------------------------------
200void DetailsPanelManager::Impl::setupWidgets(QWidget* parent)
201{
202 const ThemeColors& c = themeMgr_->colors();
203
204 detailsPanel_ = new QWidget(parent);
205 QVBoxLayout* detailsLayout = new QVBoxLayout(detailsPanel_);
206 detailsLayout->setContentsMargins(0, 0, 0, 16);
207 detailsLayout->setSpacing(0);
208
209 // Hero image at top - scales to panel width, height follows aspect ratio
210 // OUTSIDE collapsible sections (always visible)
211 heroImageLabel_ = new QLabel(detailsPanel_);
212 heroImageLabel_->setAlignment(Qt::AlignCenter);
213 heroImageLabel_->setScaledContents(false);
214 heroImageLabel_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
215 heroImageLabel_->setStyleSheet(QString("background-color: %1; border-bottom: 1px solid %2;")
216 .arg(c.windowBackground.name())
217 .arg(c.border.name()));
218 heroImageLabel_->setVisible(false);
219
220 // Logo image overlay (positioned over hero - will be placed manually)
221 logoImageLabel_ = new QLabel(detailsPanel_);
222 logoImageLabel_->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
223 logoImageLabel_->setStyleSheet("background: transparent;");
224 logoImageLabel_->setVisible(false);
225
226 detailsLayout->addWidget(heroImageLabel_);
227
228 // =========================================================================
229 // STICKY HEADER: Game name, info, and action buttons (always visible)
230 // =========================================================================
231 QWidget* headerWidget = new QWidget(detailsPanel_);
232 headerWidget->setStyleSheet(QString("background-color: %1; border-bottom: 1px solid %2;")
233 .arg(c.panelBackground.name())
234 .arg(c.borderLight.name()));
235 QVBoxLayout* headerLayout = new QVBoxLayout(headerWidget);
236 headerLayout->setContentsMargins(16, 10, 16, 10);
237 headerLayout->setSpacing(4);
238
239 // Game name (prominent, left-aligned)
240 gameNameLabel_ = new QLabel(headerWidget);
241 gameNameLabel_->setStyleSheet(
242 QString(
243 "font-size: %2px; font-weight: bold; color: %1; background: transparent; border: none;")
244 .arg(c.textPrimary.name())
245 .arg(themeMgr_->scaledFontSize(18)));
246 gameNameLabel_->setAlignment(Qt::AlignLeft);
247 gameNameLabel_->setWordWrap(true);
248 headerLayout->addWidget(gameNameLabel_);
249
250 // Game info (source, runner, developer)
251 gameInfoLabel_ = new QLabel(headerWidget);
252 gameInfoLabel_->setStyleSheet(
253 QString("color: %1; font-size: 11px; background: transparent; border: none;")
254 .arg(c.textSecondary.name()));
255 gameInfoLabel_->setAlignment(Qt::AlignLeft);
256 gameInfoLabel_->setWordWrap(true);
257 headerLayout->addWidget(gameInfoLabel_);
258
259 // Genres (inline under info)
260 gameGenresLabel_ = new QLabel(headerWidget);
261 gameGenresLabel_->setStyleSheet(
262 QString("color: %1; font-size: 10px; background: transparent; border: none;")
263 .arg(c.info.name()));
264 gameGenresLabel_->setAlignment(Qt::AlignLeft);
265 gameGenresLabel_->setWordWrap(true);
266 gameGenresLabel_->setVisible(false);
267 headerLayout->addWidget(gameGenresLabel_);
268
269 // Action buttons row (Launch / Stop / Configure)
270 headerLayout->addSpacing(6);
271 QHBoxLayout* buttonLayout = new QHBoxLayout();
272 buttonLayout->setSpacing(8);
273
274 launchButton_ = new QPushButton("Launch", headerWidget);
275 launchButton_->setMinimumHeight(34);
276 launchButton_->setCursor(Qt::PointingHandCursor);
277 launchButton_->setStyleSheet(
278 QString("QPushButton { background-color: %1; color: %6; font-weight: bold; "
279 "border-radius: 6px; padding: 0 24px; border: none; }"
280 "QPushButton:hover { background-color: %2; }"
281 "QPushButton:pressed { background-color: %3; }"
282 "QPushButton:disabled { background-color: %4; color: %5; }")
283 .arg(c.success.name())
284 .arg(ThemeManager::lightenColor(c.success, 15).name())
285 .arg(ThemeManager::darkenColor(c.success, 15).name())
286 .arg(c.inputBackground.name())
287 .arg(c.textMuted.name())
288 .arg(c.textOnAccent.name()));
289 connect(launchButton_, &QPushButton::clicked, this,
290 [this]() { emit owner_->launchRequested(currentGameId_); });
291 buttonLayout->addWidget(launchButton_);
292
293 stopButton_ = new QPushButton("Stop", headerWidget);
294 stopButton_->setMinimumHeight(34);
295 stopButton_->setCursor(Qt::PointingHandCursor);
296 stopButton_->setStyleSheet(
297 QString("QPushButton { background-color: %1; color: %5; font-weight: bold; "
298 "border-radius: 6px; padding: 0 24px; border: none; }"
299 "QPushButton:hover { background-color: %2; }"
300 "QPushButton:pressed { background-color: %3; }"
301 "QPushButton:disabled { background-color: %4; }")
302 .arg(c.error.name())
303 .arg(ThemeManager::lightenColor(c.error, 15).name())
304 .arg(ThemeManager::darkenColor(c.error, 15).name())
305 .arg(c.inputBackground.name())
306 .arg(c.textOnAccent.name()));
307 stopButton_->setVisible(false);
308 connect(stopButton_, &QPushButton::clicked, this,
309 [this]() { emit owner_->stopRequested(currentGameId_); });
310 buttonLayout->addWidget(stopButton_);
311
312 configButton_ = new QPushButton("Configure", headerWidget);
313 configButton_->setMinimumHeight(34);
314 configButton_->setCursor(Qt::PointingHandCursor);
315 configButton_->setStyleSheet(
316 QString("QPushButton { background-color: %1; color: %2; font-weight: bold; "
317 "border-radius: 6px; border: 1px solid %3; padding: 0 20px; }"
318 "QPushButton:hover { background-color: %4; border-color: %5; }"
319 "QPushButton:pressed { background-color: %6; }")
320 .arg(c.cardBackground.name())
321 .arg(c.textSecondary.name())
322 .arg(c.border.name())
323 .arg(c.hoverBackground.name())
324 .arg(c.accent.name())
325 .arg(c.inputBackground.name()));
326 connect(configButton_, &QPushButton::clicked, this,
327 [this]() { emit owner_->configureRequested(currentGameId_); });
328 buttonLayout->addWidget(configButton_);
329 buttonLayout->addStretch();
330
331 headerLayout->addLayout(buttonLayout);
332 detailsLayout->addWidget(headerWidget);
333
334 // =========================================================================
335 // SCROLLABLE CONTENT: All detail sections below the header
336 // =========================================================================
337 QScrollArea* detailsScrollArea = new QScrollArea(detailsPanel_);
338 detailsScrollArea->setWidgetResizable(true);
339 detailsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
340 detailsScrollArea->setFrameShape(QFrame::NoFrame);
341 detailsScrollArea->setStyleSheet(
342 QString("QScrollArea { background-color: %1; }").arg(c.windowBackground.name()));
343
344 QWidget* contentWidget = new QWidget(detailsScrollArea);
345 QVBoxLayout* contentLayout = new QVBoxLayout(contentWidget);
346 contentLayout->setContentsMargins(16, 12, 16, 0);
347 contentLayout->setSpacing(4);
348
349 // ===========================================================================
350 // COLLAPSIBLE SECTION: Overview (default expanded)
351 // Contains: cover art, description
352 // ===========================================================================
353 overviewSection_ =
354 new CollapsibleSection("Overview", "details/overview_collapsed", false, contentWidget);
355
356 // Cover art (smaller, floats left conceptually but centered for now)
357 coverArtLabel_ = new QLabel(contentWidget);
358 coverArtLabel_->setMinimumSize(140, 210);
359 coverArtLabel_->setMaximumSize(200, 300);
360 coverArtLabel_->setAlignment(Qt::AlignCenter);
361 coverArtLabel_->setStyleSheet(
362 QString("background-color: %1; border-radius: 4px;").arg(c.cardBackground.name()));
363 coverArtLabel_->setText(QString("<div style='text-align:center; color:%1;'>"
364 "<span style='font-family:%2; font-size:32px;'>%3</span><br>"
365 "<span style='font-size:10px;'>No Cover Art</span></div>")
366 .arg(themeMgr_->colors().textMuted.name(), IconFont::solidFamily(),
368
369 // Wrapper to center cover art in collapsible section
370 QWidget* coverArtWrapper = new QWidget(contentWidget);
371 QHBoxLayout* coverArtWrapperLayout = new QHBoxLayout(coverArtWrapper);
372 coverArtWrapperLayout->setContentsMargins(0, 0, 0, 0);
373 coverArtWrapperLayout->addStretch();
374 coverArtWrapperLayout->addWidget(coverArtLabel_);
375 coverArtWrapperLayout->addStretch();
376 overviewSection_->addWidget(coverArtWrapper);
377
378 // Description
379 gameDescLabel_ = new QLabel(contentWidget);
380 gameDescLabel_->setStyleSheet(
381 QString("color: %1; font-size: 10px; margin-top: 8px; padding: 8px; "
382 "background-color: %2; border-radius: 4px;")
383 .arg(c.textSecondary.name())
384 .arg(c.cardBackground.name()));
385 gameDescLabel_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
386 gameDescLabel_->setWordWrap(true);
387 gameDescLabel_->setMaximumHeight(80);
388 gameDescLabel_->setVisible(false);
389 overviewSection_->addWidget(gameDescLabel_);
390
391 contentLayout->addWidget(overviewSection_);
392
393 // ===========================================================================
394 // COLLAPSIBLE SECTION: Statistics (default expanded)
395 // Contains: stats label, steam info, completion, HLTB, session history
396 // ===========================================================================
397 statisticsSection_ =
398 new CollapsibleSection("Statistics", "details/statistics_collapsed", false, contentWidget);
399
400 // Statistics (playtime, launches, last played)
401 gameStatsLabel_ = new QLabel(contentWidget);
402 gameStatsLabel_->setStyleSheet(
403 QString("color: %1; font-size: 11px; margin-top: 6px;").arg(c.textSecondary.name()));
404 gameStatsLabel_->setAlignment(Qt::AlignCenter);
405 gameStatsLabel_->setWordWrap(true);
406 statisticsSection_->addWidget(gameStatsLabel_);
407
408 // Steam-specific info (cloud saves, DLC, categories)
409 gameSteamInfoLabel_ = new QLabel(contentWidget);
410 gameSteamInfoLabel_->setStyleSheet(
411 QString("color: %1; font-size: 10px; margin-top: 2px;").arg(c.info.name()));
412 gameSteamInfoLabel_->setAlignment(Qt::AlignCenter);
413 gameSteamInfoLabel_->setWordWrap(true);
414 gameSteamInfoLabel_->setVisible(false);
415 statisticsSection_->addWidget(gameSteamInfoLabel_);
416
417 // Completion status row (inline in statistics)
418 QWidget* completionRow = new QWidget(contentWidget);
419 QHBoxLayout* completionRowLayout = new QHBoxLayout(completionRow);
420 completionRowLayout->setContentsMargins(0, 4, 0, 0);
421 completionRowLayout->setSpacing(6);
422 completionRowLayout->addStretch();
423
424 completionStatusCombo_ = new QComboBox(contentWidget);
425 completionStatusCombo_->addItem("Not Played", static_cast<int>(CompletionStatus::NotPlayed));
426 completionStatusCombo_->addItem("Playing", static_cast<int>(CompletionStatus::Playing));
427 completionStatusCombo_->addItem("Beaten", static_cast<int>(CompletionStatus::Beaten));
428 completionStatusCombo_->addItem("Completed", static_cast<int>(CompletionStatus::Completed));
429 completionStatusCombo_->addItem("On Hold", static_cast<int>(CompletionStatus::OnHold));
430 completionStatusCombo_->addItem("Abandoned", static_cast<int>(CompletionStatus::Abandoned));
431 completionStatusCombo_->addItem("Played", static_cast<int>(CompletionStatus::Played));
432 completionStatusCombo_->setMaximumWidth(120);
433 completionStatusCombo_->setStyleSheet(
434 QString("QComboBox { background-color: %1; color: %2; border: 1px solid %3; "
435 "border-radius: 3px; padding: 2px 8px; font-size: 10px; }"
436 "QComboBox:hover { border-color: %4; }"
437 "QComboBox::drop-down { border: none; width: 16px; }"
438 "QComboBox::down-arrow { image: none; border-left: 4px solid transparent; "
439 "border-right: 4px solid transparent; border-top: 5px solid %2; }")
440 .arg(c.inputBackground.name(), c.textSecondary.name(), c.border.name(),
441 c.accent.name()));
442 connect(completionStatusCombo_, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
443 [this](int index)
444 {
445 if (currentGameId_.empty())
446 return;
447 Game* game = libCtrl_->getGameForEdit(currentGameId_);
448 if (!game)
449 return;
450 game->completionStatus =
451 static_cast<CompletionStatus>(completionStatusCombo_->itemData(index).toInt());
452 libCtrl_->updateGame(currentGameId_, *game);
453 emit owner_->gameChanged(currentGameId_);
454 });
455 completionRowLayout->addWidget(completionStatusCombo_);
456 completionRowLayout->addStretch();
457 statisticsSection_->addWidget(completionRow);
458
459 // Progress bar (based on HLTB, shown inline)
460 completionProgressBar_ = new QProgressBar(contentWidget);
461 completionProgressBar_->setMinimum(0);
462 completionProgressBar_->setMaximum(100);
463 completionProgressBar_->setValue(0);
464 completionProgressBar_->setTextVisible(false);
465 completionProgressBar_->setMinimumHeight(4);
466 completionProgressBar_->setMaximumHeight(4);
467 completionProgressBar_->setStyleSheet(
468 QString("QProgressBar { background-color: %1; border-radius: 2px; }"
469 "QProgressBar::chunk { background-color: %2; border-radius: 2px; }")
470 .arg(c.inputBackground.name(), c.accent.name()));
471 completionProgressBar_->setVisible(false);
472 statisticsSection_->addWidget(completionProgressBar_);
473
474 // HowLongToBeat Section
475 hltbSection_ = new QWidget(contentWidget);
476 hltbSection_->setStyleSheet(
477 QString("background-color: %1; border-radius: 4px; margin-top: 6px;")
478 .arg(c.cardBackground.name()));
479 QVBoxLayout* hltbLayout = new QVBoxLayout(hltbSection_);
480 hltbLayout->setContentsMargins(10, 8, 10, 8);
481 hltbLayout->setSpacing(4);
482
483 QLabel* hltbTitle = new QLabel("How Long To Beat", hltbSection_);
484 hltbTitle->setStyleSheet(
485 QString("font-weight: bold; color: %1; font-size: 10px;").arg(c.textSecondary.name()));
486 hltbLayout->addWidget(hltbTitle);
487
488 QHBoxLayout* hltbTimesRow = new QHBoxLayout();
489 hltbTimesRow->setSpacing(12);
490
491 hltbMainLabel_ = new QLabel(hltbSection_);
492 hltbMainLabel_->setStyleSheet(
493 QString("color: %1; font-size: 10px;").arg(c.textSecondary.name()));
494 hltbTimesRow->addWidget(hltbMainLabel_);
495
496 hltbExtrasLabel_ = new QLabel(hltbSection_);
497 hltbExtrasLabel_->setStyleSheet(
498 QString("color: %1; font-size: 10px;").arg(c.textSecondary.name()));
499 hltbTimesRow->addWidget(hltbExtrasLabel_);
500
501 hltbCompleteLabel_ = new QLabel(hltbSection_);
502 hltbCompleteLabel_->setStyleSheet(
503 QString("color: %1; font-size: 10px;").arg(c.textSecondary.name()));
504 hltbTimesRow->addWidget(hltbCompleteLabel_);
505
506 hltbTimesRow->addStretch();
507 hltbLayout->addLayout(hltbTimesRow);
508
509 hltbSection_->setVisible(false);
510 statisticsSection_->addWidget(hltbSection_);
511
512 // Session History Section
513 sessionHistorySection_ = new QWidget(contentWidget);
514 sessionHistorySection_->setStyleSheet(
515 QString("background-color: %1; border-radius: 4px; margin-top: 6px;")
516 .arg(c.cardBackground.name()));
517 QVBoxLayout* sessionLayout = new QVBoxLayout(sessionHistorySection_);
518 sessionLayout->setContentsMargins(10, 8, 10, 8);
519 sessionLayout->setSpacing(4);
520
521 QLabel* sessionTitle = new QLabel("Recent Sessions", sessionHistorySection_);
522 sessionTitle->setStyleSheet(
523 QString("font-weight: bold; color: %1; font-size: 10px;").arg(c.textSecondary.name()));
524 sessionLayout->addWidget(sessionTitle);
525
526 sessionHistoryLabel_ = new QLabel(sessionHistorySection_);
527 sessionHistoryLabel_->setStyleSheet(
528 QString("color: %1; font-size: 10px;").arg(c.textSecondary.name()));
529 sessionHistoryLabel_->setWordWrap(true);
530 sessionHistoryLabel_->setTextFormat(Qt::RichText);
531 sessionLayout->addWidget(sessionHistoryLabel_);
532
533 sessionHistorySection_->setVisible(false);
534 statisticsSection_->addWidget(sessionHistorySection_);
535
536 contentLayout->addWidget(statisticsSection_);
537
538 // ===========================================================================
539 // COLLAPSIBLE SECTION: Configuration (default collapsed)
540 // Contains: launch config, config presets, collections
541 // ===========================================================================
542 configurationSection_ = new CollapsibleSection(
543 "Configuration", "details/configuration_collapsed", true, contentWidget);
544
545 // Launch configuration summary
546 gameLaunchConfigLabel_ = new QLabel(contentWidget);
547 gameLaunchConfigLabel_->setStyleSheet(
548 QString("color: %1; font-size: 10px; margin-top: 10px; padding: 10px; "
549 "background-color: %2; border-radius: 4px; border: 1px solid %3;")
550 .arg(c.textSecondary.name())
551 .arg(c.cardBackground.name())
552 .arg(c.border.name()));
553 gameLaunchConfigLabel_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
554 gameLaunchConfigLabel_->setWordWrap(true);
555 gameLaunchConfigLabel_->setTextFormat(Qt::RichText);
556 gameLaunchConfigLabel_->setVisible(false);
557 configurationSection_->addWidget(gameLaunchConfigLabel_);
558
559 // Configuration Presets Section
560 configPresetsSection_ = new QWidget(contentWidget);
561 configPresetsSection_->setStyleSheet(
562 QString("background-color: %1; border-radius: 4px; margin-top: 6px;")
563 .arg(c.cardBackground.name()));
564 QVBoxLayout* presetsLayout = new QVBoxLayout(configPresetsSection_);
565 presetsLayout->setContentsMargins(10, 8, 10, 8);
566 presetsLayout->setSpacing(6);
567
568 QLabel* presetsTitle = new QLabel("Config Presets", configPresetsSection_);
569 presetsTitle->setStyleSheet(
570 QString("font-weight: bold; color: %1; font-size: 10px;").arg(c.textSecondary.name()));
571 presetsLayout->addWidget(presetsTitle);
572
573 presetsButtonLayout_ = new QHBoxLayout();
574 presetsButtonLayout_->setSpacing(4);
575 presetsLayout->addLayout(presetsButtonLayout_);
576
577 configPresetsSection_->setVisible(false);
578 configurationSection_->addWidget(configPresetsSection_);
579
580 // Collections Badges
581 collectionsLabel_ = new QLabel(contentWidget);
582 collectionsLabel_->setStyleSheet(
583 QString("color: %1; font-size: 10px; margin-top: 6px;").arg(c.info.name()));
584 collectionsLabel_->setWordWrap(true);
585 collectionsLabel_->setTextFormat(Qt::RichText);
586 collectionsLabel_->setVisible(false);
587 configurationSection_->addWidget(collectionsLabel_);
588
589 contentLayout->addWidget(configurationSection_);
590
591 // ===========================================================================
592 // COLLAPSIBLE SECTION: Notes (default collapsed)
593 // Contains: user notes
594 // ===========================================================================
595 notesSection_ = new CollapsibleSection("Notes", "details/notes_collapsed", true, contentWidget);
596
597 // User Notes Section
598 userNotesSection_ = new QWidget(contentWidget);
599 userNotesSection_->setStyleSheet(
600 QString("background-color: %1; border-radius: 4px; margin-top: 6px;")
601 .arg(c.cardBackground.name()));
602 QVBoxLayout* notesLayout = new QVBoxLayout(userNotesSection_);
603 notesLayout->setContentsMargins(10, 8, 10, 8);
604 notesLayout->setSpacing(4);
605
606 QLabel* notesTitle = new QLabel("Notes", userNotesSection_);
607 notesTitle->setStyleSheet(
608 QString("font-weight: bold; color: %1; font-size: 10px;").arg(c.textSecondary.name()));
609 notesLayout->addWidget(notesTitle);
610
611 userNotesLabel_ = new QLabel(userNotesSection_);
612 userNotesLabel_->setStyleSheet(QString("color: %1; font-size: 10px; padding: 6px; "
613 "border: 1px dashed %2; border-radius: 4px; "
614 "background-color: %3;")
615 .arg(c.textSecondary.name())
616 .arg(c.borderLight.name())
617 .arg(c.inputBackground.name()));
618 userNotesLabel_->setWordWrap(true);
619 userNotesLabel_->setCursor(Qt::PointingHandCursor);
620 userNotesLabel_->setToolTip("Click to edit notes");
621 // Click handler to edit notes
622 userNotesLabel_->installEventFilter(this);
623 notesLayout->addWidget(userNotesLabel_);
624
625 userNotesSection_->setVisible(false);
626 notesSection_->addWidget(userNotesSection_);
627
628 contentLayout->addWidget(notesSection_);
629
630 // ===========================================================================
631 // COLLAPSIBLE SECTION: System (default collapsed)
632 // Contains: system info, running info, frame metrics
633 // ===========================================================================
634 systemSection_ =
635 new CollapsibleSection("System", "details/system_collapsed", true, contentWidget);
636
637 // Container for running game info (includes text info + frametime graph)
638 runningInfoContainer_ = new QWidget(contentWidget);
639 runningInfoContainer_->setVisible(false);
640 runningInfoContainer_->setStyleSheet(
641 QString("background-color: %1; border-radius: 4px; margin-top: 10px;")
642 .arg(ThemeManager::darkenColor(c.cardBackground, 5).name()));
643 QVBoxLayout* runningLayout = new QVBoxLayout(runningInfoContainer_);
644 runningLayout->setContentsMargins(0, 0, 0, 0);
645 runningLayout->setSpacing(0);
646
647 // Running info label (inside container)
648 gameRunningInfoLabel_ = new QLabel(runningInfoContainer_);
649 gameRunningInfoLabel_->setStyleSheet(
650 QString("color: %1; font-size: 10px; padding: 10px; background: transparent;")
651 .arg(c.textSecondary.name()));
652 gameRunningInfoLabel_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
653 gameRunningInfoLabel_->setWordWrap(true);
654 gameRunningInfoLabel_->setTextFormat(Qt::RichText);
655 runningLayout->addWidget(gameRunningInfoLabel_);
656
657 // Frame metrics widget (shows frametime graph when game is running - inside container)
658 frameMetricsWidget_ = new FrameMetricsWidget(runningInfoContainer_);
659 frameMetricsWidget_->setVisible(false);
660 frameMetricsWidget_->setTargetFps(144.0); // Default target, can be updated per-game
661 runningLayout->addWidget(frameMetricsWidget_);
662
663 systemSection_->addWidget(runningInfoContainer_);
664
665 // System info section
666 systemInfoLabel_ = new QLabel(contentWidget);
667 systemInfoLabel_->setStyleSheet(
668 QString("color: %1; font-size: 10px; margin-top: 10px; padding: 8px; "
669 "background-color: %2; border-radius: 4px;")
670 .arg(c.textSecondary.name())
671 .arg(ThemeManager::darkenColor(c.cardBackground, 5).name()));
672 systemInfoLabel_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
673 systemInfoLabel_->setWordWrap(true);
674 systemInfoLabel_->setTextFormat(Qt::RichText);
675 systemInfoLabel_->setVisible(false);
676 systemSection_->addWidget(systemInfoLabel_);
677
678 contentLayout->addWidget(systemSection_);
679
680 // ===========================================================================
681 // OUTSIDE COLLAPSIBLE SECTIONS: Download progress & update banner
682 // These are temporary status indicators that should always be visible
683 // ===========================================================================
684
685 // Download progress widget (hidden by default)
686 downloadProgressWidget_ = new QWidget(contentWidget);
687 QVBoxLayout* progressLayout = new QVBoxLayout(downloadProgressWidget_);
688 progressLayout->setContentsMargins(0, 8, 0, 8);
689 progressLayout->setSpacing(4);
690
691 downloadProgressLabel_ = new QLabel(downloadProgressWidget_);
692 downloadProgressLabel_->setStyleSheet(
693 QString("color: %1; font-size: 11px; font-weight: bold;").arg(c.info.name()));
694 downloadProgressLabel_->setAlignment(Qt::AlignCenter);
695 progressLayout->addWidget(downloadProgressLabel_);
696
697 downloadProgressBar_ = new QProgressBar(downloadProgressWidget_);
698 downloadProgressBar_->setMinimum(0);
699 downloadProgressBar_->setMaximum(100);
700 downloadProgressBar_->setValue(0);
701 downloadProgressBar_->setTextVisible(false);
702 downloadProgressBar_->setMinimumHeight(8);
703 downloadProgressBar_->setMaximumHeight(8);
704 downloadProgressBar_->setStyleSheet(
705 QString("QProgressBar { background-color: %1; border-radius: 4px; }"
706 "QProgressBar::chunk { background-color: %2; border-radius: 4px; }")
707 .arg(c.inputBackground.name())
708 .arg(c.info.name()));
709 progressLayout->addWidget(downloadProgressBar_);
710
711 downloadProgressWidget_->setVisible(false);
712 contentLayout->addWidget(downloadProgressWidget_);
713
714 // Update available banner (hidden by default)
715 updateBannerWidget_ = new QWidget(contentWidget);
716 QHBoxLayout* updateBannerLayout = new QHBoxLayout(updateBannerWidget_);
717 updateBannerLayout->setContentsMargins(8, 8, 8, 8);
718 updateBannerLayout->setSpacing(12);
719
720 updateBannerLabel_ = new QLabel("⬆ Update Available", updateBannerWidget_);
721 updateBannerLabel_->setStyleSheet(
722 QString("color: %1; font-size: 12px; font-weight: bold;").arg(c.warning.name()));
723 updateBannerLayout->addWidget(updateBannerLabel_, 1);
724
725 updateNowButton_ = new QPushButton("Update Now", updateBannerWidget_);
726 updateNowButton_->setCursor(Qt::PointingHandCursor);
727 updateNowButton_->setStyleSheet(
728 QString("QPushButton { background-color: %1; color: %2; font-weight: bold; "
729 "border-radius: 4px; padding: 4px 12px; font-size: 11px; }"
730 "QPushButton:hover { background-color: %3; }")
731 .arg(c.warning.name())
732 .arg(c.panelBackground.name())
733 .arg(c.warning.lighter(110).name()));
734 connect(updateNowButton_, &QPushButton::clicked, this,
735 [this]()
736 {
737 if (!currentGameId_.empty())
738 {
739 const Game* game = libCtrl_->getGame(currentGameId_);
740 if (game && game->metadata.steamAppId > 0)
741 {
742 // Use steam://install/ to download/update without auto-launching
744 QString("steam://install/%1").arg(game->metadata.steamAppId));
745 }
746 }
747 });
748 updateBannerLayout->addWidget(updateNowButton_);
749
750 updateBannerWidget_->setStyleSheet(
751 QString("background-color: %1; border-radius: 6px; border: 1px solid %2;")
752 .arg(c.warning.darker(200).name())
753 .arg(c.warning.darker(150).name()));
754 updateBannerWidget_->setVisible(false);
755 contentLayout->addWidget(updateBannerWidget_);
756
757 contentLayout->addStretch();
758
759 detailsScrollArea->setWidget(contentWidget);
760 detailsLayout->addWidget(detailsScrollArea, 1); // Stretch factor 1 so it fills remaining space
761}
762
763// ------------------------------------------------------------------------
764// update — MOVED VERBATIM from MainWindow::updateDetailsPanel()
765// ------------------------------------------------------------------------
766void DetailsPanelManager::Impl::update(const std::string& gameId)
767{
768 currentGameId_ = gameId;
769
770 if (gameId.empty())
771 {
772 heroImageLabel_->setVisible(false);
773 logoImageLabel_->setVisible(false);
774 coverArtLabel_->setVisible(false);
775 gameNameLabel_->setText("Select a Game");
776 gameInfoLabel_->setText("Choose a game from the list to see details");
777 gameGenresLabel_->setVisible(false);
778 gameStatsLabel_->clear();
779 gameSteamInfoLabel_->setVisible(false);
780 gameDescLabel_->setVisible(false);
781 gameLaunchConfigLabel_->setVisible(false);
782 runningInfoContainer_->setVisible(false);
783 systemInfoLabel_->setVisible(false);
784 // Hide enhanced details panel sections
785 if (overviewSection_)
786 overviewSection_->setVisible(false);
787 if (statisticsSection_)
788 statisticsSection_->setVisible(false);
789 completionProgressBar_->setVisible(false);
790 hltbSection_->setVisible(false);
791 sessionHistorySection_->setVisible(false);
792 userNotesSection_->setVisible(false);
793 configPresetsSection_->setVisible(false);
794 collectionsLabel_->setVisible(false);
795 if (updateBannerWidget_)
796 updateBannerWidget_->setVisible(false);
797 launchButton_->setEnabled(false);
798 stopButton_->setVisible(false);
799 configButton_->setEnabled(false);
800 return;
801 }
802
803 const Game* game = libCtrl_->getGame(gameId);
804 if (!game)
805 {
806 return;
807 }
808
809 gameNameLabel_->setText(QString::fromStdString(game->name));
810 configButton_->setEnabled(true);
811 if (statisticsSection_)
812 statisticsSection_->setVisible(true);
813
814 // Load hero image (wide banner at top). All scaling, LRU eviction, and
815 // DPR handling lives in GameThumbnailCache now — we just show the result.
816 const QPixmap heroPixmap =
817 imgCache_ ? imgCache_->getHeroImage(game, detailsPanel_->width()) : QPixmap();
818 if (!heroPixmap.isNull())
819 {
820 heroImageLabel_->setPixmap(heroPixmap);
821 // deviceIndependentSize() gives us the logical height accounting for
822 // DPR, which is what QLabel's fixed-height should use.
823 heroImageLabel_->setFixedHeight(
824 static_cast<int>(qRound(heroPixmap.deviceIndependentSize().height())));
825 heroImageLabel_->setVisible(true);
826 }
827 else
828 {
829 heroImageLabel_->setVisible(false);
830 }
831
832 // Load and display game logo (overlaid on hero or standalone)
833 QString logoPath = QString::fromStdString(game->getImagePath(ImageType::Logo));
834 if (!logoPath.isEmpty() && heroImageLabel_->isVisible())
835 {
836 QPixmap logoPixmap(logoPath);
837 if (!logoPixmap.isNull())
838 {
839 // Scale logo to fit within hero area (about 40% of hero width, max 50% height)
840 int heroHeight = heroImageLabel_->height();
841 int heroWidth = heroImageLabel_->width();
842 int maxLogoWidth = static_cast<int>(heroWidth * 0.4);
843 int maxLogoHeight = static_cast<int>(heroHeight * 0.5);
844
845 QPixmap scaledLogo = logoPixmap.scaled(maxLogoWidth, maxLogoHeight, Qt::KeepAspectRatio,
846 Qt::SmoothTransformation);
847
848 logoImageLabel_->setPixmap(scaledLogo);
849 logoImageLabel_->setFixedSize(scaledLogo.size());
850
851 // Position logo at bottom-left of hero with padding
852 int padding = 10;
853 logoImageLabel_->move(padding, heroHeight - scaledLogo.height() - padding);
854 logoImageLabel_->setVisible(true);
855 }
856 else
857 {
858 logoImageLabel_->setVisible(false);
859 }
860 }
861 else
862 {
863 logoImageLabel_->setVisible(false);
864 }
865
866 // Build info text (source, runner, developer, publisher)
867 QStringList info;
868 info << QString::fromStdString(game->getSourceName());
869
870 // Show installation status for Steam games
871 if (game->source == GameSource::Steam)
872 {
873 if (game->isInstalled())
874 {
875 info << "Installed";
876 }
877 else if (game->status == GameStatus::Installing)
878 {
879 info << "Installing...";
880 }
881 else
882 {
883 info << "Not Installed";
884 }
885 }
886
887 info << QString::fromStdString(game->getRunnerName());
888 if (!game->metadata.developer.empty())
889 {
890 info << QString::fromStdString(game->metadata.developer);
891 }
892 if (!game->metadata.publisher.empty() && game->metadata.publisher != game->metadata.developer)
893 {
894 info << QString("Published by %1").arg(QString::fromStdString(game->metadata.publisher));
895 }
896 if (game->metadata.releaseYear > 0)
897 {
898 info << QString::number(game->metadata.releaseYear);
899 }
900 gameInfoLabel_->setText(info.join(" • "));
901
902 // Genres
903 if (!game->metadata.genres.empty())
904 {
905 QStringList genres;
906 for (const auto& genre : game->metadata.genres)
907 {
908 genres << QString::fromStdString(genre);
909 }
910 gameGenresLabel_->setText(genres.join(" • "));
911 gameGenresLabel_->setVisible(true);
912 }
913 else
914 {
915 gameGenresLabel_->setVisible(false);
916 }
917
918 // Statistics — playtime as hero metric, secondary stats below
919 {
920 const auto& sc = themeMgr_->colors();
921 QString html;
922
923 // Hero: playtime
924 if (game->statistics.totalPlayTimeSeconds > 0)
925 {
926 html +=
927 QString("<div style='text-align:center;'>"
928 "<span style='font-size:20px; font-weight:bold; color:%1;'>%2</span><br>"
929 "<span style='font-size:10px; color:%3;'>Total Playtime</span></div>")
930 .arg(sc.textPrimary.name(),
931 QString::fromStdString(game->getFormattedPlayTime()), sc.textMuted.name());
932 }
933
934 // Secondary stats
935 QStringList secondary;
936 if (game->statistics.timesLaunched > 0)
937 secondary << QString("%1 launches").arg(game->statistics.timesLaunched);
938 if (game->statistics.lastPlayed > 0)
939 {
940 QDateTime lastPlayed = QDateTime::fromSecsSinceEpoch(game->statistics.lastPlayed);
941 secondary << QString("Last: %1").arg(lastPlayed.toString("MMM d, yyyy"));
942 }
943 if (game->installSizeBytes > 0)
944 {
945 double sizeGB =
946 static_cast<double>(game->installSizeBytes) / (1024.0 * 1024.0 * 1024.0);
947 if (sizeGB >= 1.0)
948 secondary << QString("%1 GB").arg(sizeGB, 0, 'f', 1);
949 else
950 {
951 double sizeMB = static_cast<double>(game->installSizeBytes) / (1024.0 * 1024.0);
952 secondary << QString("%1 MB").arg(sizeMB, 0, 'f', 0);
953 }
954 }
955 if (game->status == GameStatus::Installed && !game->installPath.empty())
956 {
957 uint64_t available = getCachedDiskSpace(game->installPath);
958 if (available > 0)
959 {
960 double availGB = static_cast<double>(available) / (1024.0 * 1024.0 * 1024.0);
961 secondary << QString("%1 GB free").arg(availGB, 0, 'f', 0);
962 }
963 }
964 if (game->statistics.crashCount > 0)
965 {
966 secondary << QString("%1 crash%2")
967 .arg(game->statistics.crashCount)
968 .arg(game->statistics.crashCount > 1 ? "es" : "");
969 }
970 if (!secondary.isEmpty())
971 {
972 html += QString("<div style='text-align:center; font-size:11px; color:%1; "
973 "margin-top:4px;'>%2</div>")
974 .arg(sc.textSecondary.name(), secondary.join(" | "));
975 }
976
977 gameStatsLabel_->setText(html);
978 }
979
980 // Steam-specific info
981 if (game->metadata.steamAppId > 0)
982 {
983 QStringList steamInfo;
984 steamInfo << QString("Steam ID: %1").arg(game->metadata.steamAppId);
985
986 // Cloud save status with sync info
987 if (game->metadata.cloudSave.enabled)
988 {
989 QString cloudStatus = "☁ Cloud Saves";
990 // Show sync state if available (0=synced, 1=uploading, 2=downloading, 3=conflict)
991 if (game->metadata.cloudSave.lastSyncState == 0)
992 {
993 cloudStatus += " ✓"; // Synced
994 }
995 else if (game->metadata.cloudSave.lastSyncState == 3)
996 {
997 cloudStatus += " ⚠"; // Conflict
998 }
999 // Show cloud storage size if available
1000 if (game->metadata.cloudSave.storageBytes > 0)
1001 {
1002 double sizeMB =
1003 static_cast<double>(game->metadata.cloudSave.storageBytes) / (1024.0 * 1024.0);
1004 if (sizeMB >= 1.0)
1005 {
1006 cloudStatus += QString(" (%1 MB)").arg(sizeMB, 0, 'f', 1);
1007 }
1008 }
1009 steamInfo << cloudStatus;
1010 }
1011 else if (game->metadata.cloudSave.supported)
1012 {
1013 steamInfo << "☁ Cloud (disabled)";
1014 }
1015
1016 // DLC count with install status
1017 if (!game->metadata.dlc.empty())
1018 {
1019 int installedDlc = 0;
1020 for (const auto& dlc : game->metadata.dlc)
1021 {
1022 if (dlc.installed)
1023 installedDlc++;
1024 }
1025 if (installedDlc == static_cast<int>(game->metadata.dlc.size()))
1026 {
1027 steamInfo << QString("%1 DLC").arg(game->metadata.dlc.size());
1028 }
1029 else
1030 {
1031 steamInfo << QString("%1/%2 DLC").arg(installedDlc).arg(game->metadata.dlc.size());
1032 }
1033 }
1034
1035 // Update status badge (check state flags)
1037 {
1038 steamInfo << "⬆ Update Available";
1039 }
1040
1041 // Categories (limit to 3)
1042 if (!game->metadata.steamCategories.empty())
1043 {
1044 QStringList categories;
1045 for (size_t i = 0; i < std::min(game->metadata.steamCategories.size(), size_t(3)); ++i)
1046 {
1047 categories << QString::fromStdString(game->metadata.steamCategories[i]);
1048 }
1049 steamInfo << categories.join(", ");
1050 }
1051 gameSteamInfoLabel_->setText(steamInfo.join(" | "));
1052 gameSteamInfoLabel_->setVisible(true);
1053 }
1054 else
1055 {
1056 gameSteamInfoLabel_->setVisible(false);
1057 }
1058
1059 // ProtonDB compatibility info (for Steam games with cached data)
1060 if (game->metadata.steamAppId > 0 && !game->metadata.protondbTier.empty())
1061 {
1062 const ThemeColors& tc = themeMgr_->colors();
1063 QString tierText = QString::fromStdString(game->metadata.protondbTier);
1064 QString tierCapitalized = tierText.left(1).toUpper() + tierText.mid(1);
1065
1066 // Color-code the tier (ProtonDB brand colors for standard tiers)
1067 QString tierColor;
1068 if (tierText == "platinum")
1069 tierColor = "#b4c7dc"; // ProtonDB platinum color
1070 else if (tierText == "gold")
1071 tierColor = "#cfb53b"; // ProtonDB gold color
1072 else if (tierText == "silver")
1073 tierColor = "#a6a6a6"; // ProtonDB silver color
1074 else if (tierText == "bronze")
1075 tierColor = "#cd7f32"; // ProtonDB bronze color
1076 else if (tierText == "borked")
1077 tierColor = tc.error.name(); // Use theme error color
1078 else if (tierText == "native")
1079 tierColor = tc.success.name();
1080 else
1081 tierColor = tc.textMuted.name();
1082
1083 QString protondbHtml = QString("<span style='color: %1;'>ProtonDB: </span>"
1084 "<span style='color: %2; font-weight: bold;'>%3</span>")
1085 .arg(tc.textMuted.name(), tierColor, tierCapitalized);
1086
1087 // Add confidence if available
1088 if (!game->metadata.protondbConfidence.empty())
1089 {
1090 protondbHtml +=
1091 QString(" <span style='color: %1;'>(%2 confidence)</span>")
1092 .arg(tc.textMuted.name(),
1093 QString::fromStdString(game->metadata.protondbConfidence).toHtmlEscaped());
1094 }
1095
1096 // Update Steam info label to include ProtonDB info, or create separate display
1097 QString currentSteamInfo = gameSteamInfoLabel_->text();
1098 if (!currentSteamInfo.isEmpty())
1099 {
1100 gameSteamInfoLabel_->setText(currentSteamInfo + " | " + protondbHtml);
1101 }
1102 else
1103 {
1104 gameSteamInfoLabel_->setText(protondbHtml);
1105 gameSteamInfoLabel_->setVisible(true);
1106 }
1107 }
1108
1109 // Description — hide entire Overview section if no description
1110 // (cover art is already shown in the hero image above)
1111 if (!game->metadata.description.empty())
1112 {
1113 QString desc = QString::fromStdString(game->metadata.description);
1114 // Truncate to first 200 characters for display
1115 if (desc.length() > 200)
1116 {
1117 desc = desc.left(200) + "...";
1118 }
1119 gameDescLabel_->setText(desc.toHtmlEscaped());
1120 gameDescLabel_->setVisible(true);
1121 if (overviewSection_)
1122 overviewSection_->setVisible(true);
1123 }
1124 else
1125 {
1126 gameDescLabel_->setVisible(false);
1127 if (overviewSection_)
1128 overviewSection_->setVisible(false);
1129 }
1130
1131 // ===========================================================================
1132 // ENHANCED DETAILS PANEL: Update Completion Status & Progress Bar
1133 // ===========================================================================
1134 {
1135 const ThemeColors& tc = themeMgr_->colors();
1136
1137 // Set completion status dropdown to current value
1138 int statusIndex =
1139 completionStatusCombo_->findData(static_cast<int>(game->completionStatus));
1140 if (statusIndex >= 0)
1141 {
1142 QSignalBlocker blocker(completionStatusCombo_);
1143 completionStatusCombo_->setCurrentIndex(statusIndex);
1144 }
1145
1146 // Show progress bar only when HLTB data is available
1147 if (game->hltbInfo.found && game->hltbInfo.mainStoryHours > 0)
1148 {
1149 double playedHours = game->statistics.totalPlayTimeSeconds / 3600.0;
1150 double targetHours = game->hltbInfo.mainStoryHours;
1151 int progressPercent = qMin(100, static_cast<int>((playedHours / targetHours) * 100));
1152
1153 completionProgressBar_->setValue(progressPercent);
1154
1155 // Color based on completion status
1156 QString progressColor = tc.accent.name();
1157 switch (game->completionStatus)
1158 {
1161 progressColor = tc.success.name();
1162 break;
1164 progressColor = tc.error.name();
1165 break;
1167 progressColor = tc.warning.name();
1168 break;
1169 default:
1170 break;
1171 }
1172 completionProgressBar_->setStyleSheet(
1173 QString("QProgressBar { background-color: %1; border-radius: 2px; }"
1174 "QProgressBar::chunk { background-color: %2; border-radius: 2px; }")
1175 .arg(tc.inputBackground.name(), progressColor));
1176 completionProgressBar_->setVisible(true);
1177 }
1178 else
1179 {
1180 completionProgressBar_->setVisible(false);
1181 }
1182 }
1183
1184 // ===========================================================================
1185 // ENHANCED DETAILS PANEL: Update HowLongToBeat Section
1186 // ===========================================================================
1187 if (game->hltbInfo.found)
1188 {
1189 hltbMainLabel_->setText(QString("Main: %1h").arg(game->hltbInfo.mainStoryHours, 0, 'f', 0));
1190 hltbExtrasLabel_->setText(
1191 QString("+Extras: %1h").arg(game->hltbInfo.mainPlusExtrasHours, 0, 'f', 0));
1192 hltbCompleteLabel_->setText(
1193 QString("100%%: %1h").arg(game->hltbInfo.completionistHours, 0, 'f', 0));
1194
1195 hltbSection_->setVisible(true);
1196 }
1197 else
1198 {
1199 hltbSection_->setVisible(false);
1200 }
1201
1202 // ===========================================================================
1203 // ENHANCED DETAILS PANEL: Update Session History Section
1204 // ===========================================================================
1205 // Load recent sessions from database if not already populated
1206 if (game->recentSessions.empty())
1207 {
1208 auto sessions = libCtrl_->getRecentSessions(gameId, 20);
1209 if (!sessions.empty())
1210 {
1211 // Populate the game's session cache (non-const access needed)
1212 Game* mutableGame = libCtrl_->getGameForEdit(gameId);
1213 if (mutableGame)
1214 {
1215 mutableGame->recentSessions = std::move(sessions);
1216 game = mutableGame; // Update pointer to reflect loaded data
1217 }
1218 }
1219 }
1220
1221 if (!game->recentSessions.empty())
1222 {
1223 const ThemeColors& tc = themeMgr_->colors();
1224 QString sessionsHtml;
1225
1226 // Show up to 5 most recent sessions
1227 int shown = 0;
1228 for (auto it = game->recentSessions.rbegin();
1229 it != game->recentSessions.rend() && shown < 5; ++it, ++shown)
1230 {
1231 const auto& session = *it;
1232 QDateTime startTime = QDateTime::fromSecsSinceEpoch(session.startTime);
1233 QString duration = QString::fromStdString(session.getFormattedDuration());
1234 QString dateStr = startTime.toString("MMM d");
1235
1236 sessionsHtml += QString("<span style='color: %1;'>%2</span> - %3")
1237 .arg(tc.textMuted.name(), dateStr, duration);
1238
1239 // Show FPS if available
1240 if (session.avgFps > 0)
1241 {
1242 sessionsHtml += QString(" <span style='color: %1;'>(%2 avg FPS)</span>")
1243 .arg(tc.info.name())
1244 .arg(session.avgFps, 0, 'f', 0);
1245 }
1246
1247 // Show exit reason if abnormal
1248 if (session.exitReason == "crash")
1249 {
1250 sessionsHtml +=
1251 QString(" <span style='color: %1;'>crashed</span>").arg(tc.error.name());
1252 }
1253
1254 if (shown < 4 && std::next(it) != game->recentSessions.rend())
1255 {
1256 sessionsHtml += "<br>";
1257 }
1258 }
1259
1260 sessionHistoryLabel_->setText(sessionsHtml);
1261 sessionHistorySection_->setVisible(true);
1262 }
1263 else
1264 {
1265 sessionHistorySection_->setVisible(false);
1266 }
1267
1268 // ===========================================================================
1269 // ENHANCED DETAILS PANEL: Update User Notes Section
1270 // ===========================================================================
1271 if (!game->userNotes.empty())
1272 {
1273 QString notes = QString::fromStdString(game->userNotes);
1274 if (notes.length() > 150)
1275 {
1276 notes = notes.left(147) + "...";
1277 }
1278 userNotesLabel_->setText(notes);
1279 userNotesSection_->setVisible(true);
1280 }
1281 else
1282 {
1283 userNotesLabel_->setText("Add notes...");
1284 userNotesSection_->setVisible(true); // Always show so user can add notes
1285 }
1286
1287 // ===========================================================================
1288 // ENHANCED DETAILS PANEL: Update Configuration Presets Section
1289 // ===========================================================================
1290 // Clear existing preset buttons
1291 while (QLayoutItem* item = presetsButtonLayout_->takeAt(0))
1292 {
1293 delete item->widget();
1294 delete item;
1295 }
1296
1297 if (!game->configTemplates.empty())
1298 {
1299 const ThemeColors& tc = themeMgr_->colors();
1300
1301 for (const auto& [name, config] : game->configTemplates)
1302 {
1303 QPushButton* presetBtn =
1304 new QPushButton(QString::fromStdString(name), configPresetsSection_);
1305 presetBtn->setMaximumHeight(24);
1306 presetBtn->setCursor(Qt::PointingHandCursor);
1307
1308 bool isActive = (game->activeTemplateName == name);
1309 if (isActive)
1310 {
1311 presetBtn->setStyleSheet(
1312 QString("QPushButton { background-color: %1; color: %2; border: none; "
1313 "border-radius: 3px; padding: 2px 8px; font-size: 10px; font-weight: "
1314 "bold; }")
1315 .arg(tc.accent.name(), tc.textOnAccent.name()));
1316 }
1317 else
1318 {
1319 presetBtn->setStyleSheet(
1320 QString("QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
1321 "border-radius: 3px; padding: 2px 8px; font-size: 10px; }"
1322 "QPushButton:hover { background-color: %4; border-color: %5; }")
1323 .arg(tc.cardBackground.name(), tc.textSecondary.name(), tc.border.name(),
1324 tc.hoverBackground.name(), tc.accent.name()));
1325 }
1326
1327 // Connect preset activation
1328 QString presetName = QString::fromStdString(name);
1329 connect(presetBtn, &QPushButton::clicked, this,
1330 [this, presetName]()
1331 {
1332 if (currentGameId_.empty())
1333 return;
1334 Game* g = libCtrl_->getGameForEdit(currentGameId_);
1335 if (!g)
1336 return;
1337
1338 std::string templateName = presetName.toStdString();
1339 auto it = g->configTemplates.find(templateName);
1340 if (it != g->configTemplates.end())
1341 {
1342 g->runnerConfig = it->second;
1343 g->activeTemplateName = templateName;
1344 libCtrl_->updateGame(currentGameId_, *g);
1346 emit owner_->gameChanged(currentGameId_);
1347 }
1348 });
1349
1350 presetsButtonLayout_->addWidget(presetBtn);
1351 }
1352 presetsButtonLayout_->addStretch();
1353 configPresetsSection_->setVisible(true);
1354 }
1355 else
1356 {
1357 configPresetsSection_->setVisible(false);
1358 }
1359
1360 // ===========================================================================
1361 // ENHANCED DETAILS PANEL: Update Collections Badges
1362 // ===========================================================================
1363 if (!game->collections.empty())
1364 {
1365 const ThemeColors& tc = themeMgr_->colors();
1366 QStringList badges;
1367 for (const auto& collection : game->collections)
1368 {
1369 badges << QString("<span style='background-color: %1; color: %2; padding: 1px 6px; "
1370 "border-radius: 3px; font-size: 9px;'>%3</span>")
1371 .arg(tc.accent.name(), "white",
1372 QString::fromStdString(collection).toHtmlEscaped());
1373 }
1374 collectionsLabel_->setText(badges.join(" "));
1375 collectionsLabel_->setVisible(true);
1376 }
1377 else
1378 {
1379 collectionsLabel_->setVisible(false);
1380 }
1381
1382 // Build launch configuration summary using HTML table for alignment
1383 QString launchConfig;
1384 const auto& config = game->runnerConfig;
1385 const ThemeColors& tc = themeMgr_->colors();
1386
1387 // Theme-based color strings for HTML
1388 QString labelColor = tc.textMuted.name();
1389 QString valueColor = tc.textSecondary.name();
1390 QString accentColor = tc.accent.name();
1391 QString infoColor = tc.info.name();
1392 QString warnColor = tc.warning.name();
1393 QString successColor = tc.success.name();
1394
1395 // Helper to add a table row
1396 auto addRow = [&launchConfig, &labelColor](const QString& label, const QString& value,
1397 const QString& valColor)
1398 {
1399 launchConfig +=
1400 QString("<tr><td style='color: %1; padding-right: 12px; white-space: nowrap;'>%2</td>"
1401 "<td style='color: %3;'>%4</td></tr>")
1402 .arg(labelColor, label, valColor, value);
1403 };
1404
1405 // Helper to truncate paths
1406 auto truncatePath = [](const QString& path, int maxLen) -> QString
1407 {
1408 if (path.length() > maxLen)
1409 return "..." + path.right(maxLen - 3);
1410 return path;
1411 };
1412
1413 // Header
1414 launchConfig += QString("<b style='color: %1;'>Launch Configuration</b>").arg(accentColor);
1415
1416 // Steam defaults mode indicator
1417 if (config.useSteamDefaults)
1418 {
1419 launchConfig +=
1420 QString("<br><span style='color: %1;'>Using Steam defaults</span>").arg(warnColor);
1421 }
1422
1423 // Start table
1424 launchConfig += "<table style='margin-top: 8px; border-spacing: 0 4px;'>";
1425
1426 // Collect performance wrappers early (needed for hasConfig check)
1427 QStringList wrappers;
1428 if (config.enableMangoHud)
1429 wrappers << "MangoHud";
1430 if (config.enableGameMode)
1431 wrappers << "GameMode";
1432 if (config.enableGamePerformance)
1433 wrappers << "game-performance";
1434 if (config.enableVkBasalt)
1435 wrappers << "VkBasalt";
1436
1437 // Executable
1438 if (!config.executablePath.empty())
1439 {
1440 QString exe = truncatePath(QString::fromStdString(config.executablePath), 45);
1441 addRow("Executable", exe, valueColor);
1442 }
1443
1444 // Working directory
1445 if (!config.workingDirectory.empty())
1446 {
1447 QString workDir = truncatePath(QString::fromStdString(config.workingDirectory), 45);
1448 addRow("Work Dir", workDir, valueColor);
1449 }
1450
1451 // Arguments
1452 if (!config.arguments.empty())
1453 {
1454 QString args = QString::fromStdString(config.arguments);
1455 if (args.length() > 50)
1456 args = args.left(47) + "...";
1457 addRow("Arguments", args, valueColor);
1458 }
1459
1460 // Runner type and version
1461 if (!config.runnerType.empty())
1462 {
1463 QString runner = QString::fromStdString(config.runnerType);
1464 if (!config.runnerVersion.empty())
1465 {
1466 runner += QString(" (%1)").arg(QString::fromStdString(config.runnerVersion));
1467 }
1468 addRow("Runner", runner, valueColor);
1469 }
1470
1471 // Proton/Wine specific settings
1472 // Only show Proton row if it has a specific version AND it's different from runnerVersion
1473 // (avoids showing redundant info or stale "Steam-managed" placeholder)
1474 if (!config.protonVersion.empty() && config.protonVersion != "Proton (Steam-managed)" &&
1475 config.protonVersion != config.runnerVersion)
1476 {
1477 addRow("Proton", QString::fromStdString(config.protonVersion), infoColor);
1478 }
1479
1480 if (!config.winePrefix.empty())
1481 {
1482 QString prefix = truncatePath(QString::fromStdString(config.winePrefix), 40);
1483 addRow("Wine Prefix", prefix, valueColor);
1484 }
1485
1486 if (!config.winePath.empty())
1487 {
1488 QString winePath = truncatePath(QString::fromStdString(config.winePath), 40);
1489 addRow("Wine Path", winePath, valueColor);
1490 }
1491
1492 if (!config.wineDLL.empty())
1493 {
1494 addRow("DLL Overrides", QString::fromStdString(config.wineDLL), warnColor);
1495 }
1496
1497 // Virtual desktop
1498 if (config.useVirtualDesktop)
1499 {
1500 addRow("Virtual Desktop",
1501 QString("%1x%2").arg(config.virtualDesktopWidth).arg(config.virtualDesktopHeight),
1502 successColor);
1503 }
1504
1505 // Performance wrappers
1506 if (!wrappers.isEmpty())
1507 {
1508 addRow("Wrappers", wrappers.join(", "), successColor);
1509 }
1510
1511 // Sync method
1512 if (config.enableFsync)
1513 {
1514 addRow("Sync", "Fsync", successColor);
1515 }
1516 else if (config.autoDetectSync)
1517 {
1518 addRow("Sync", "Auto-detect", labelColor);
1519 }
1520
1521 // Debugging
1522 if (config.enableDetailedLogging)
1523 {
1524 addRow("Logging", "Detailed (debug)", warnColor);
1525 }
1526
1527 // Exclude processes
1528 if (!config.excludeProcesses.empty())
1529 {
1530 QStringList excluded;
1531 for (const auto& proc : config.excludeProcesses)
1532 {
1533 excluded << QString::fromStdString(proc);
1534 }
1535 QString excludeStr = excluded.join(", ");
1536 if (excludeStr.length() > 40)
1537 excludeStr = excludeStr.left(37) + "...";
1538 addRow("Exclude", excludeStr, labelColor);
1539 }
1540
1541 launchConfig += "</table>";
1542
1543 // Environment variables - separate table for cleaner display
1544 if (!config.environmentVariables.empty())
1545 {
1546 launchConfig += QString("<div style='margin-top: 8px;'><span style='color: "
1547 "%1;'>Environment Variables</span></div>")
1548 .arg(labelColor);
1549 launchConfig += "<table style='margin-top: 4px; border-spacing: 0 2px;'>";
1550 for (const auto& [key, value] : config.environmentVariables)
1551 {
1552 QString envKey = QString::fromStdString(key).toHtmlEscaped();
1553 QString envVal = QString::fromStdString(value);
1554 if (envVal.length() > 35)
1555 envVal = envVal.left(32) + "...";
1556 launchConfig +=
1557 QString("<tr><td style='color: %1; padding-right: 8px;'>%2</td>"
1558 "<td style='color: %3;'>=</td>"
1559 "<td style='color: %4; padding-left: 4px;'>%5</td></tr>")
1560 .arg(accentColor, envKey, labelColor, valueColor, envVal.toHtmlEscaped());
1561 }
1562 launchConfig += "</table>";
1563 }
1564
1565 // Show config section - always show if game has any config
1566 bool hasConfig = !config.executablePath.empty() || !config.protonVersion.empty() ||
1567 !wrappers.isEmpty() || !config.environmentVariables.empty() ||
1568 !config.runnerType.empty() || config.useSteamDefaults;
1569 if (hasConfig)
1570 {
1571 gameLaunchConfigLabel_->setText(launchConfig);
1572 gameLaunchConfigLabel_->setVisible(true);
1573 }
1574 else
1575 {
1576 gameLaunchConfigLabel_->setVisible(false);
1577 }
1578
1579 // Show running game info if the game is currently running
1580 bool isRunning = launchCtrl_->isGameRunning(gameId);
1581 if (isRunning)
1582 {
1583 QString runningInfo;
1584
1585 // Get session duration
1586 auto duration = launchCtrl_->getSessionDuration(gameId);
1587 long long totalSecs = static_cast<long long>(duration.count());
1588 int hours = static_cast<int>(totalSecs / 3600);
1589 int minutes = static_cast<int>((totalSecs % 3600) / 60);
1590 int seconds = static_cast<int>(totalSecs % 60);
1591 QString durationStr;
1592 if (hours > 0)
1593 durationStr = QString("%1h %2m %3s").arg(hours).arg(minutes).arg(seconds);
1594 else if (minutes > 0)
1595 durationStr = QString("%1m %2s").arg(minutes).arg(seconds);
1596 else
1597 durationStr = QString("%1s").arg(seconds);
1598
1599 // Get frame metrics
1600 auto frameMetrics = FrameMetricsService::instance().getMetrics(gameId);
1601 bool collecting = FrameMetricsService::instance().isCollecting(gameId);
1602
1603 // === RUNNING STATUS SECTION (styled like other sections) ===
1604 // Header with green accent
1605 runningInfo += QString("<b style='color: %1;'>▶ Running</b>").arg(successColor);
1606 runningInfo += QString(" <span style='color: %1;'>%2</span>")
1607 .arg(tc.textSecondary.name(), durationStr);
1608
1609 // Frame metrics table (if available)
1610 if (frameMetrics.isValid(5000) || frameMetrics.sample_count > 0)
1611 {
1612 // Determine if data is stale - use progressively more dramatic colors
1613 bool isStale = !frameMetrics.isValid(2000);
1614 bool isVeryStale = !frameMetrics.isValid(5000);
1615 int64_t ageMs = frameMetrics.getAgeMs();
1616
1617 // MangoHud-style FPS color coding based on performance
1618 // Green (good): >= 95% of target, Yellow (warn): 50-95%, Red (bad): < 50%
1619 double targetFps = 144.0; // TODO: get from game config or display refresh
1620 QString fpsColor;
1621 if (frameMetrics.fps >= targetFps * 0.95)
1622 fpsColor = tc.success.name(); // Bright green - excellent
1623 else if (frameMetrics.fps >= targetFps * 0.5)
1624 fpsColor = tc.warning.name(); // Yellow - warning
1625 else
1626 fpsColor = tc.error.name(); // Red - poor
1627
1628 QString metricsValueColor = valueColor;
1629 QString staleIndicator;
1630
1631 if (isVeryStale)
1632 {
1633 // Very stale (>5s) - gray out all values
1634 fpsColor = tc.textMuted.name();
1635 metricsValueColor = tc.textMuted.name();
1636 staleIndicator =
1637 QString("<span style='color: %1; font-size: 9px;'> ⚠ stale (%2s)</span>")
1638 .arg(tc.error.name())
1639 .arg(static_cast<double>(ageMs) / 1000.0, 0, 'f', 0);
1640 }
1641 else if (isStale)
1642 {
1643 // Moderately stale (2-5s) - dim the colors
1644 fpsColor = tc.warning.name();
1645 metricsValueColor = tc.textSecondary.name();
1646 staleIndicator =
1647 QString("<span style='color: %1; font-size: 9px;'> (%2s ago)</span>")
1648 .arg(tc.warning.name())
1649 .arg(static_cast<double>(ageMs) / 1000.0, 0, 'f', 1);
1650 }
1651
1652 runningInfo += "<table style='margin-top: 8px; border-spacing: 0 4px;'>";
1653
1654 // Average FPS - large and prominent (more stable than instantaneous)
1655 if (frameMetrics.fps_avg > 0)
1656 {
1657 QString avgFpsColor = fpsColor; // Use same color logic based on avg performance
1658 if (frameMetrics.fps_avg >= targetFps * 0.95)
1659 avgFpsColor = tc.success.name();
1660 else if (frameMetrics.fps_avg >= targetFps * 0.5)
1661 avgFpsColor = tc.warning.name();
1662 else
1663 avgFpsColor = tc.error.name();
1664
1665 if (isVeryStale)
1666 avgFpsColor = tc.textMuted.name();
1667 else if (isStale)
1668 avgFpsColor = tc.warning.name();
1669
1670 runningInfo +=
1671 QString(
1672 "<tr><td style='color: %1; padding-right: 12px; vertical-align: "
1673 "baseline;'>Avg FPS</td>"
1674 "<td style='color: %2; font-weight: bold; font-size: %5px;'>%3%4</td></tr>")
1675 .arg(labelColor, avgFpsColor)
1676 .arg(frameMetrics.fps_avg, 0, 'f', 1)
1677 .arg(staleIndicator)
1678 .arg(themeMgr_->scaledFontSize(18));
1679 }
1680 else
1681 {
1682 // Fall back to instantaneous if no average yet
1683 runningInfo +=
1684 QString(
1685 "<tr><td style='color: %1; padding-right: 12px; vertical-align: "
1686 "baseline;'>FPS</td>"
1687 "<td style='color: %2; font-weight: bold; font-size: %5px;'>%3%4</td></tr>")
1688 .arg(labelColor, fpsColor)
1689 .arg(frameMetrics.fps, 0, 'f', 1)
1690 .arg(staleIndicator)
1691 .arg(themeMgr_->scaledFontSize(18));
1692 }
1693
1694 // Current FPS - smaller secondary metric
1695 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>Current</td>"
1696 "<td style='color: %2;'>%3 FPS</td></tr>")
1697 .arg(labelColor, metricsValueColor)
1698 .arg(frameMetrics.fps, 0, 'f', 1);
1699
1700 // Frametime
1701 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>Frametime</td>"
1702 "<td style='color: %2;'>%3 ms</td></tr>")
1703 .arg(labelColor, metricsValueColor)
1704 .arg(frameMetrics.frametime_ms, 0, 'f', 2);
1705
1706 // 1% Low - highlight if concerning (below 50% of target)
1707 if (frameMetrics.fps_1_low > 0)
1708 {
1709 QString lowColor = metricsValueColor;
1710 if (!isStale && !isVeryStale && frameMetrics.fps_1_low < targetFps * 0.5)
1711 lowColor = ThemeManager::darkenColor(tc.error, 30).name();
1712
1713 runningInfo +=
1714 QString("<tr><td style='color: %1; padding-right: 12px;'>1%% Low</td>"
1715 "<td style='color: %2;'>%3 FPS</td></tr>")
1716 .arg(labelColor, lowColor)
1717 .arg(frameMetrics.fps_1_low, 0, 'f', 1);
1718 }
1719
1720 // 0.1% Low - highlight if concerning
1721 if (frameMetrics.fps_0_1_low > 0)
1722 {
1723 QString lowColor = metricsValueColor;
1724 if (!isStale && !isVeryStale && frameMetrics.fps_0_1_low < targetFps * 0.4)
1725 lowColor = ThemeManager::darkenColor(tc.error, 30).name();
1726
1727 runningInfo +=
1728 QString("<tr><td style='color: %1; padding-right: 12px;'>0.1%% Low</td>"
1729 "<td style='color: %2;'>%3 FPS</td></tr>")
1730 .arg(labelColor, lowColor)
1731 .arg(frameMetrics.fps_0_1_low, 0, 'f', 1);
1732 }
1733
1734 runningInfo += "</table>";
1735 }
1736 else if (collecting)
1737 {
1738 runningInfo += QString("<div style='margin-top: 8px;'>"
1739 "<span style='color: %1;'>Collecting frame data...</span></div>")
1740 .arg(tc.textMuted.name());
1741 }
1742
1743 // Active optimizations
1744 QStringList activeOpts;
1745 if (config.enableMangoHud || collecting)
1746 activeOpts << "MangoHud";
1747 if (config.enableGameMode)
1748 activeOpts << "GameMode";
1749 if (config.enableGamePerformance)
1750 activeOpts << "game-performance";
1751 if (config.enableVkBasalt)
1752 activeOpts << "VkBasalt";
1753 if (config.enableFsync)
1754 activeOpts << "Fsync";
1755 // Don't show stale "Proton (Steam-managed)" placeholder - runner version is shown elsewhere
1756 if (!config.protonVersion.empty() && config.protonVersion != "Proton (Steam-managed)")
1757 activeOpts << QString::fromStdString(config.protonVersion);
1758
1759 if (!activeOpts.isEmpty())
1760 {
1761 runningInfo += QString("<div style='margin-top: 8px;'>"
1762 "<span style='color: %1; font-size: 10px;'>%2</span></div>")
1763 .arg(tc.textMuted.name(), activeOpts.join(" · "));
1764 }
1765
1766 // Update frame metrics widget with graph (if we have history data)
1767 if (!frameMetrics.frametimeHistory.empty())
1768 {
1769 frameMetricsWidget_->setMetrics(frameMetrics);
1770 frameMetricsWidget_->setVisible(true);
1771 }
1772 else
1773 {
1774 frameMetricsWidget_->setVisible(false);
1775 }
1776
1777 // === PROCESS TREE & RUNTIME ENVIRONMENT ===
1778 const auto* process = GameProcessManager::instance().getRunningProcess(gameId);
1779 if (process)
1780 {
1781 int launcherPid = process->getProcessId();
1782 int trackedPid = process->getTrackedProcessId();
1783 QString trackedName = QString::fromStdString(process->getTrackedProcessName());
1784
1785 // Show process tree section
1786 runningInfo += QString("<br><br><b style='color: %1;'>Process Tree</b>").arg(infoColor);
1787 runningInfo += "<table style='margin-top: 4px; border-spacing: 0 2px;'>";
1788
1789 if (trackedPid > 0 && trackedPid != launcherPid)
1790 {
1791 // Launcher spawned a separate game process
1792 runningInfo += QString("<tr><td style='color: %1;'>Launcher</td>"
1793 "<td style='color: %2; padding-left: 8px;'>PID %3</td></tr>")
1794 .arg(labelColor, valueColor)
1795 .arg(launcherPid);
1796 runningInfo += QString("<tr><td style='color: %1;'>└─ %2</td>"
1797 "<td style='color: %3; padding-left: 8px;'>PID %4</td></tr>")
1798 .arg(successColor, trackedName.isEmpty() ? "Game" : trackedName,
1799 successColor)
1800 .arg(trackedPid);
1801 }
1802 else
1803 {
1804 // Direct process (not launcher-based)
1805 QString procName = trackedName.isEmpty() ? "Game" : trackedName;
1806 runningInfo += QString("<tr><td style='color: %1;'>%2</td>"
1807 "<td style='color: %3; padding-left: 8px;'>PID %4</td></tr>")
1808 .arg(successColor, procName, successColor)
1809 .arg(launcherPid);
1810 }
1811 runningInfo += "</table>";
1812
1813 // Read actual runtime environment
1814 int targetPid = (trackedPid > 0) ? trackedPid : launcherPid;
1816
1817 if (runtimeInfo.valid)
1818 {
1819 // Show key gaming environment variables that are actually set
1820 auto keyEnv = runtimeInfo.getKeyEnvironment();
1821 if (!keyEnv.empty())
1822 {
1823 runningInfo +=
1824 QString("<br><b style='color: %1;'>Runtime Environment</b>").arg(infoColor);
1825 runningInfo += "<table style='margin-top: 4px; border-spacing: 0 1px;'>";
1826 int envCount = 0;
1827 for (const auto& [key, value] : keyEnv)
1828 {
1829 QString envVal = QString::fromStdString(value);
1830 if (envVal.length() > 30)
1831 envVal = envVal.left(27) + "...";
1832 runningInfo +=
1833 QString("<tr><td style='color: %1; padding-right: 6px; font-size: "
1834 "10px;'>%2</td>"
1835 "<td style='color: %3; font-size: 10px;'>= %4</td></tr>")
1836 .arg(accentColor, QString::fromStdString(key).toHtmlEscaped(),
1837 valueColor, envVal.toHtmlEscaped());
1838 if (++envCount >= 10)
1839 {
1840 runningInfo += QString("<tr><td colspan='2' style='color: %1; "
1841 "font-size: 9px;'>... and %2 more</td></tr>")
1842 .arg(labelColor)
1843 .arg(static_cast<int>(keyEnv.size()) - envCount);
1844 break;
1845 }
1846 }
1847 runningInfo += "</table>";
1848 }
1849
1850 // Compare configured vs actual - show any differences
1851 std::vector<std::string> configuredEnv;
1852 configuredEnv.reserve(config.environmentVariables.size());
1853 for (const auto& [key, value] : config.environmentVariables)
1854 {
1855 configuredEnv.push_back(key + "=" + value);
1856 }
1857 auto differences = runtimeInfo.compareWithConfigured(configuredEnv);
1858
1859 if (!differences.empty())
1860 {
1861 runningInfo += QString("<br><span style='color: %1; font-size: 10px;'>Config "
1862 "Differences:</span>")
1863 .arg(warnColor);
1864 runningInfo += "<table style='border-spacing: 0 1px;'>";
1865 int diffCount = 0;
1866 for (const auto& diff : differences)
1867 {
1868 runningInfo +=
1869 QString("<tr><td style='color: %1; font-size: 9px;'>%2</td></tr>")
1870 .arg(warnColor, QString::fromStdString(diff).toHtmlEscaped());
1871 if (++diffCount >= 5)
1872 {
1873 runningInfo +=
1874 QString("<tr><td style='color: %1; font-size: 9px;'>... and %2 "
1875 "more</td></tr>")
1876 .arg(labelColor)
1877 .arg(static_cast<int>(differences.size()) - diffCount);
1878 break;
1879 }
1880 }
1881 runningInfo += "</table>";
1882 }
1883
1884 // Show command line
1885 if (!runtimeInfo.commandLine.empty())
1886 {
1887 QString cmdLine = QString::fromStdString(runtimeInfo.commandLine);
1888 if (cmdLine.length() > 80)
1889 cmdLine = cmdLine.left(77) + "...";
1890 runningInfo +=
1891 QString("<br><span style='color: %1; font-size: 10px;'>cmd: </span>"
1892 "<span style='color: %2; font-size: 9px;'>%3</span>")
1893 .arg(labelColor, valueColor, cmdLine.toHtmlEscaped());
1894 }
1895 }
1896 else
1897 {
1898 runningInfo += QString("<br><span style='color: %1; font-size: 10px;'>Unable to "
1899 "read process environment (permission denied)</span>")
1900 .arg(labelColor);
1901 }
1902 }
1903
1904 gameRunningInfoLabel_->setText(runningInfo);
1905 runningInfoContainer_->setVisible(true);
1906 }
1907 else
1908 {
1909 runningInfoContainer_->setVisible(false);
1910 frameMetricsWidget_->clear();
1911 frameMetricsWidget_->setVisible(false);
1912 }
1913
1914 // Show system info section
1915 auto& sysInfo = SystemInfoService::instance();
1916 const auto& gpu = sysInfo.getGPUInfo();
1917 const auto& cpu = sysInfo.getCPUInfo();
1918 const auto& memory = sysInfo.getMemoryInfo();
1919 const auto& kernel = sysInfo.getKernelInfo();
1920 const auto& tools = sysInfo.getToolAvailability();
1921
1922 QString sysInfoHtml;
1923 sysInfoHtml += QString("<b style='color: %1;'>System Info</b>").arg(labelColor);
1924 sysInfoHtml += "<table style='margin-top: 4px; border-spacing: 0 2px;'>";
1925
1926 // GPU - show model with VRAM
1927 if (!gpu.model.empty() || !gpu.vendorName.empty())
1928 {
1929 QString gpuStr = QString::fromStdString(gpu.model.empty() ? gpu.vendorName : gpu.model);
1930 if (gpu.vramMB > 0)
1931 {
1932 gpuStr += QString(" (%1 GB)").arg(gpu.vramMB / 1024);
1933 }
1934 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>GPU</td>"
1935 "<td style='color: %2;'>%3</td></tr>")
1936 .arg(labelColor, valueColor, gpuStr);
1937 }
1938
1939 // CPU - show model with core count
1940 if (!cpu.model.empty())
1941 {
1942 // Shorten the model name if too long
1943 QString cpuStr = QString::fromStdString(cpu.model);
1944 // Remove common redundant suffixes
1945 cpuStr.replace(" 8-Core Processor", "");
1946 cpuStr.replace(" 16-Core Processor", "");
1947 cpuStr.replace(" Processor", "");
1948 if (cpuStr.length() > 30)
1949 {
1950 cpuStr = cpuStr.left(27) + "...";
1951 }
1952 cpuStr += QString(" (%1C/%2T)").arg(cpu.coreCount).arg(cpu.threadCount);
1953 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>CPU</td>"
1954 "<td style='color: %2;'>%3</td></tr>")
1955 .arg(labelColor, valueColor, cpuStr);
1956 }
1957
1958 // RAM
1959 if (memory.totalMB > 0)
1960 {
1961 QString ramStr = QString("%1 GB").arg(memory.totalMB / 1024);
1962 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>RAM</td>"
1963 "<td style='color: %2;'>%3</td></tr>")
1964 .arg(labelColor, valueColor, ramStr);
1965 }
1966
1967 // Kernel
1968 if (!kernel.version.empty())
1969 {
1970 QString kernelStr = QString::fromStdString(kernel.version);
1971 if (kernel.isCachyOS)
1972 kernelStr += " (CachyOS)";
1973 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>Kernel</td>"
1974 "<td style='color: %2;'>%3</td></tr>")
1975 .arg(labelColor, valueColor, kernelStr);
1976 }
1977
1978 // Available tools
1979 QStringList availableTools;
1980 if (tools.mangoHud)
1981 availableTools << "MangoHud";
1982 if (tools.gameMode)
1983 availableTools << "GameMode";
1984 if (tools.gamePerformance)
1985 availableTools << "game-performance";
1986 if (tools.gamescope)
1987 availableTools << "Gamescope";
1988 if (tools.vkBasalt)
1989 availableTools << "VkBasalt";
1990
1991 if (!availableTools.isEmpty())
1992 {
1993 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>Tools</td>"
1994 "<td style='color: %2;'>%3</td></tr>")
1995 .arg(labelColor, successColor, availableTools.join(", "));
1996 }
1997
1998 // Sync support
1999 if (kernel.supportsFsync)
2000 {
2001 sysInfoHtml += QString("<tr><td style='color: %1; padding-right: 8px;'>Sync</td>"
2002 "<td style='color: %2;'>Fsync supported</td></tr>")
2003 .arg(labelColor, successColor);
2004 }
2005
2006 sysInfoHtml += "</table>";
2007 systemInfoLabel_->setText(sysInfoHtml);
2008 systemInfoLabel_->setVisible(true);
2009
2010 // Only show cover art if hero image isn't available (prefer wide images)
2011 bool hasHeroImage = heroImageLabel_->isVisible();
2012 if (!hasHeroImage)
2013 {
2014 // No hero image - show cover art as fallback
2015 QString coverPath =
2016 imgCache_ ? imgCache_->findBestImage(game, ImageType::VerticalCover) : QString();
2017 if (!coverPath.isEmpty())
2018 {
2019 QPixmap coverPixmap = imgCache_ ? imgCache_->getGameThumbnail(game, QSize(200, 300),
2021 : QPixmap();
2022 if (!coverPixmap.isNull())
2023 {
2024 coverArtLabel_->setPixmap(coverPixmap);
2025 coverArtLabel_->setVisible(true);
2026 }
2027 else
2028 {
2029 coverArtLabel_->setText(
2030 QString("<div style='text-align:center; color:%1;'>"
2031 "<span style='font-family:%2; font-size:32px;'>%3</span><br>"
2032 "<span style='font-size:10px;'>No Cover Art</span></div>")
2033 .arg(themeMgr_->colors().textMuted.name(), IconFont::solidFamily(),
2035 coverArtLabel_->setVisible(true);
2036 }
2037 }
2038 else
2039 {
2040 coverArtLabel_->setText(
2041 QString("<div style='text-align:center; color:%1;'>"
2042 "<span style='font-family:%2; font-size:32px;'>%3</span><br>"
2043 "<span style='font-size:10px;'>No Cover Art</span></div>")
2044 .arg(themeMgr_->colors().textMuted.name(), IconFont::solidFamily(),
2046 coverArtLabel_->setVisible(true);
2047 }
2048 }
2049 else
2050 {
2051 // Hero image is visible - hide cover art to keep panel clean
2052 coverArtLabel_->setVisible(false);
2053 }
2054
2055 // Manage download progress widget visibility based on whether THIS game is downloading
2056 if (downloadProgressWidget_)
2057 {
2058 bool showProgress = false;
2059 if (game->source == GameSource::Steam && game->metadata.steamAppId > 0)
2060 {
2061 // Check if game has Installing status (user clicked Install)
2062 if (game->status == GameStatus::Installing)
2063 {
2064 showProgress = true;
2065 // Check for actual download progress from monitor
2066 // TODO MED-7: steamDownloadMonitor_ is owned by MainWindow; reading
2067 // directly from the shared appmanifest via SteamDownloadMonitor::readGameState
2068 // preserves the visible progress without needing a pointer.
2069 {
2071 static_cast<uint32_t>(game->metadata.steamAppId));
2072 bool isActivelyDownloading =
2073 SteamStateFlags::isDownloading(progress.stateFlags) ||
2074 (progress.stateFlags & SteamStateFlags::Staging) != 0;
2075
2076 if (isActivelyDownloading && progress.downloadProgress > 0)
2077 {
2078 downloadProgressBar_->setValue(
2079 static_cast<int>(progress.downloadProgress * 100));
2080 QString statusText = SteamStateFlags::isDownloading(progress.stateFlags)
2081 ? "Downloading"
2082 : "Staging";
2083 QString speedText = QString::fromStdString(progress.getFormattedSpeed());
2084 if (progress.downloadSpeedBytesPerSec > 0)
2085 {
2086 downloadProgressLabel_->setText(
2087 QString("%1 - %2% (%3)")
2088 .arg(statusText)
2089 .arg(static_cast<int>(progress.downloadProgress * 100))
2090 .arg(speedText));
2091 }
2092 else
2093 {
2094 downloadProgressLabel_->setText(
2095 QString("%1 - %2%")
2096 .arg(statusText)
2097 .arg(static_cast<int>(progress.downloadProgress * 100)));
2098 }
2099 }
2100 else
2101 {
2102 // Still waiting for Steam to start or no progress yet
2103 downloadProgressLabel_->setText("Waiting for Steam...");
2104 downloadProgressBar_->setValue(0);
2105 }
2106 }
2107 }
2108 }
2109 downloadProgressWidget_->setVisible(showProgress);
2110 }
2111
2112 // Manage update banner visibility for Steam games with pending updates
2113 if (updateBannerWidget_)
2114 {
2115 bool showUpdateBanner = false;
2116 if (game->source == GameSource::Steam && game->metadata.steamAppId > 0)
2117 {
2118 // Show banner if game needs update and is not currently downloading
2121 {
2122 showUpdateBanner = true;
2123 }
2124 }
2125 updateBannerWidget_->setVisible(showUpdateBanner);
2126 }
2127
2128 updateLaunchButton(gameId);
2129}
2130
2131// ------------------------------------------------------------------------
2132// updateRunningInfo — MOVED VERBATIM from MainWindow::updateRunningInfo()
2133// ------------------------------------------------------------------------
2135{
2136 // Lightweight update for running game metrics only - called frequently when game is running
2137 // Does NOT touch images, static info, or other expensive operations
2138
2139 if (gameId.empty() || !launchCtrl_->isGameRunning(gameId))
2140 {
2141 runningInfoContainer_->setVisible(false);
2142 frameMetricsWidget_->clear();
2143 frameMetricsWidget_->setVisible(false);
2144 return;
2145 }
2146
2147 const Game* game = libCtrl_->getGame(gameId);
2148 if (!game)
2149 return;
2150
2151 // Get theme colors
2152 const ThemeColors& tc = themeMgr_->colors();
2153 QString labelColor = tc.textMuted.name();
2154 QString valueColor = tc.textSecondary.name();
2155 QString accentColor = tc.accent.name();
2156 QString infoColor = tc.info.name();
2157 QString warnColor = tc.warning.name();
2158 QString successColor = tc.success.name();
2159
2160 // Get game config for active optimizations display
2161 const auto& config = game->runnerConfig;
2162
2163 QString runningInfo;
2164
2165 // Get session duration
2166 auto duration = launchCtrl_->getSessionDuration(gameId);
2167 long long totalSecs = static_cast<long long>(duration.count());
2168 int hours = static_cast<int>(totalSecs / 3600);
2169 int minutes = static_cast<int>((totalSecs % 3600) / 60);
2170 int seconds = static_cast<int>(totalSecs % 60);
2171 QString durationStr;
2172 if (hours > 0)
2173 durationStr = QString("%1h %2m %3s").arg(hours).arg(minutes).arg(seconds);
2174 else if (minutes > 0)
2175 durationStr = QString("%1m %2s").arg(minutes).arg(seconds);
2176 else
2177 durationStr = QString("%1s").arg(seconds);
2178
2179 // Get frame metrics
2180 auto frameMetrics = FrameMetricsService::instance().getMetrics(gameId);
2181 bool collecting = FrameMetricsService::instance().isCollecting(gameId);
2182
2183 // === RUNNING STATUS SECTION ===
2184 runningInfo += QString("<b style='color: %1;'>▶ Running</b>").arg(successColor);
2185 runningInfo +=
2186 QString(" <span style='color: %1;'>%2</span>").arg(tc.textSecondary.name(), durationStr);
2187
2188 // Frame metrics table (if available)
2189 if (frameMetrics.isValid(5000) || frameMetrics.sample_count > 0)
2190 {
2191 bool isStale = !frameMetrics.isValid(2000);
2192 bool isVeryStale = !frameMetrics.isValid(5000);
2193 int64_t ageMs = frameMetrics.getAgeMs();
2194
2195 double targetFps = 144.0;
2196 QString fpsColor;
2197 if (frameMetrics.fps >= targetFps * 0.95)
2198 fpsColor = tc.success.name();
2199 else if (frameMetrics.fps >= targetFps * 0.5)
2200 fpsColor = tc.warning.name();
2201 else
2202 fpsColor = tc.error.name();
2203
2204 QString metricsValueColor = valueColor;
2205 QString staleIndicator;
2206
2207 if (isVeryStale)
2208 {
2209 fpsColor = tc.textMuted.name();
2210 metricsValueColor = tc.textMuted.name();
2211 staleIndicator = QString("<span style='color: %1; font-size: 9px;'> stale (%2s)</span>")
2212 .arg(tc.error.name())
2213 .arg(static_cast<double>(ageMs) / 1000.0, 0, 'f', 0);
2214 }
2215 else if (isStale)
2216 {
2217 fpsColor = tc.warning.name();
2218 metricsValueColor = tc.textSecondary.name();
2219 staleIndicator = QString("<span style='color: %1; font-size: 9px;'> (%2s ago)</span>")
2220 .arg(tc.warning.name())
2221 .arg(static_cast<double>(ageMs) / 1000.0, 0, 'f', 1);
2222 }
2223
2224 runningInfo += "<table style='margin-top: 8px; border-spacing: 0 4px;'>";
2225
2226 // Average FPS - large and prominent (more stable than instantaneous)
2227 if (frameMetrics.fps_avg > 0)
2228 {
2229 QString avgFpsColor = fpsColor;
2230 if (frameMetrics.fps_avg >= targetFps * 0.95)
2231 avgFpsColor = tc.success.name();
2232 else if (frameMetrics.fps_avg >= targetFps * 0.5)
2233 avgFpsColor = tc.warning.name();
2234 else
2235 avgFpsColor = tc.error.name();
2236
2237 if (isVeryStale)
2238 avgFpsColor = tc.textMuted.name();
2239 else if (isStale)
2240 avgFpsColor = tc.warning.name();
2241
2242 runningInfo +=
2243 QString("<tr><td style='color: %1; padding-right: 12px; vertical-align: "
2244 "baseline;'>Avg FPS</td>"
2245 "<td style='color: %2; font-weight: bold; font-size: %5px;'>%3%4</td></tr>")
2246 .arg(labelColor, avgFpsColor)
2247 .arg(frameMetrics.fps_avg, 0, 'f', 1)
2248 .arg(staleIndicator)
2249 .arg(themeMgr_->scaledFontSize(18));
2250 }
2251 else
2252 {
2253 // Fall back to instantaneous if no average yet
2254 runningInfo +=
2255 QString("<tr><td style='color: %1; padding-right: 12px; vertical-align: "
2256 "baseline;'>FPS</td>"
2257 "<td style='color: %2; font-weight: bold; font-size: %5px;'>%3%4</td></tr>")
2258 .arg(labelColor, fpsColor)
2259 .arg(frameMetrics.fps, 0, 'f', 1)
2260 .arg(staleIndicator)
2261 .arg(themeMgr_->scaledFontSize(18));
2262 }
2263
2264 // Current FPS - smaller secondary metric
2265 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>Current</td>"
2266 "<td style='color: %2;'>%3 FPS</td></tr>")
2267 .arg(labelColor, metricsValueColor)
2268 .arg(frameMetrics.fps, 0, 'f', 1);
2269
2270 // Frametime
2271 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>Frametime</td>"
2272 "<td style='color: %2;'>%3 ms</td></tr>")
2273 .arg(labelColor, metricsValueColor)
2274 .arg(frameMetrics.frametime_ms, 0, 'f', 2);
2275
2276 if (frameMetrics.fps_1_low > 0)
2277 {
2278 QString lowColor = metricsValueColor;
2279 if (!isStale && !isVeryStale && frameMetrics.fps_1_low < targetFps * 0.5)
2280 lowColor = ThemeManager::darkenColor(tc.error, 30).name();
2281
2282 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>1%% Low</td>"
2283 "<td style='color: %2;'>%3 FPS</td></tr>")
2284 .arg(labelColor, lowColor)
2285 .arg(frameMetrics.fps_1_low, 0, 'f', 1);
2286 }
2287
2288 if (frameMetrics.fps_0_1_low > 0)
2289 {
2290 QString lowColor = metricsValueColor;
2291 if (!isStale && !isVeryStale && frameMetrics.fps_0_1_low < targetFps * 0.4)
2292 lowColor = ThemeManager::darkenColor(tc.error, 30).name();
2293
2294 runningInfo += QString("<tr><td style='color: %1; padding-right: 12px;'>0.1%% Low</td>"
2295 "<td style='color: %2;'>%3 FPS</td></tr>")
2296 .arg(labelColor, lowColor)
2297 .arg(frameMetrics.fps_0_1_low, 0, 'f', 1);
2298 }
2299
2300 runningInfo += "</table>";
2301 }
2302 else if (collecting)
2303 {
2304 runningInfo += QString("<div style='margin-top: 8px;'>"
2305 "<span style='color: %1;'>Collecting frame data...</span></div>")
2306 .arg(tc.textMuted.name());
2307 }
2308
2309 // Active optimizations
2310 QStringList activeOpts;
2311 if (config.enableMangoHud || collecting)
2312 activeOpts << "MangoHud";
2313 if (config.enableGameMode)
2314 activeOpts << "GameMode";
2315 if (config.enableGamePerformance)
2316 activeOpts << "game-performance";
2317 if (config.enableVkBasalt)
2318 activeOpts << "VkBasalt";
2319 if (config.enableFsync)
2320 activeOpts << "Fsync";
2321 // Don't show stale "Proton (Steam-managed)" placeholder - runner version is shown elsewhere
2322 if (!config.protonVersion.empty() && config.protonVersion != "Proton (Steam-managed)")
2323 activeOpts << QString::fromStdString(config.protonVersion);
2324
2325 if (!activeOpts.isEmpty())
2326 {
2327 runningInfo += QString("<div style='margin-top: 8px;'>"
2328 "<span style='color: %1; font-size: 10px;'>%2</span></div>")
2329 .arg(tc.textMuted.name(), activeOpts.join(" · "));
2330 }
2331
2332 // Update frame metrics widget with graph
2333 if (!frameMetrics.frametimeHistory.empty())
2334 {
2335 frameMetricsWidget_->setMetrics(frameMetrics);
2336 frameMetricsWidget_->setVisible(true);
2337 }
2338 else
2339 {
2340 frameMetricsWidget_->setVisible(false);
2341 }
2342
2343 // Process tree (simplified for frequent updates - skip detailed env reading)
2344 const auto* process = GameProcessManager::instance().getRunningProcess(gameId);
2345 if (process)
2346 {
2347 int launcherPid = process->getProcessId();
2348 int trackedPid = process->getTrackedProcessId();
2349 QString trackedName = QString::fromStdString(process->getTrackedProcessName());
2350
2351 runningInfo += QString("<br><br><b style='color: %1;'>Process Tree</b>").arg(infoColor);
2352 runningInfo += "<table style='margin-top: 4px; border-spacing: 0 2px;'>";
2353
2354 if (trackedPid > 0 && trackedPid != launcherPid)
2355 {
2356 runningInfo += QString("<tr><td style='color: %1;'>Launcher</td>"
2357 "<td style='color: %2; padding-left: 8px;'>PID %3</td></tr>")
2358 .arg(labelColor, valueColor)
2359 .arg(launcherPid);
2360 runningInfo += QString("<tr><td style='color: %1;'>└─ %2</td>"
2361 "<td style='color: %3; padding-left: 8px;'>PID %4</td></tr>")
2362 .arg(successColor,
2363 (trackedName.isEmpty() ? "Game" : trackedName).toHtmlEscaped(),
2364 successColor)
2365 .arg(trackedPid);
2366 }
2367 else
2368 {
2369 QString procName = trackedName.isEmpty() ? "Game" : trackedName;
2370 runningInfo += QString("<tr><td style='color: %1;'>%2</td>"
2371 "<td style='color: %3; padding-left: 8px;'>PID %4</td></tr>")
2372 .arg(successColor, procName.toHtmlEscaped(), successColor)
2373 .arg(launcherPid);
2374 }
2375 runningInfo += "</table>";
2376 }
2377
2378 gameRunningInfoLabel_->setText(runningInfo);
2379 runningInfoContainer_->setVisible(true);
2380}
2381
2382// ------------------------------------------------------------------------
2383// updateLaunchButton — MOVED VERBATIM from MainWindow::updateLaunchButton()
2384// (signature takes gameId explicitly, since selectedGameId_ is not accessible)
2385// ------------------------------------------------------------------------
2387{
2388 if (gameId.empty())
2389 {
2390 launchButton_->setEnabled(false);
2391 launchButton_->setText("Launch");
2392 stopButton_->setVisible(false);
2393 return;
2394 }
2395
2396 const Game* game = libCtrl_->getGame(gameId);
2397 if (!game)
2398 {
2399 launchButton_->setEnabled(false);
2400 launchButton_->setText("Launch");
2401 stopButton_->setVisible(false);
2402 return;
2403 }
2404
2405 core::LaunchState state = launchCtrl_->getGameState(gameId);
2406
2407 switch (state)
2408 {
2411 launchButton_->setEnabled(false);
2412 launchButton_->setText("Preparing...");
2413 stopButton_->setVisible(false);
2414 break;
2417 launchButton_->setEnabled(false);
2418 launchButton_->setText("Launching...");
2419 stopButton_->setVisible(false);
2420 break;
2422 launchButton_->setEnabled(false);
2423 launchButton_->setText("Running");
2424 stopButton_->setVisible(true);
2425 break;
2428 launchButton_->setEnabled(false);
2429 launchButton_->setText("Stopping...");
2430 stopButton_->setVisible(false);
2431 break;
2432 default:
2433 // Check if game is installed
2434 if (!game->isInstalled())
2435 {
2436 // Check if it's a Steam game that can be installed
2437 if (game->source == GameSource::Steam && game->metadata.steamAppId > 0)
2438 {
2439 // Check if game is currently installing
2440 if (game->status == GameStatus::Installing)
2441 {
2442 launchButton_->setEnabled(false);
2443 launchButton_->setText("Installing...");
2444 }
2445 else
2446 {
2447 launchButton_->setEnabled(true);
2448
2449 // Check if there's a paused/partial download by reading appmanifest directly
2450 // This works even for games not being actively monitored
2451 uint32_t appId = static_cast<uint32_t>(game->metadata.steamAppId);
2453
2454 if (progress.stateFlags != 0 &&
2456 {
2457 // Show download progress in button text
2458 if (progress.downloadProgress > 0)
2459 {
2460 launchButton_->setText(
2461 QString("Resume (%1%)")
2462 .arg(static_cast<int>(progress.downloadProgress * 100)));
2463 }
2464 else
2465 {
2466 launchButton_->setText("Resume Download");
2467 }
2468 }
2469 else
2470 {
2471 launchButton_->setText("Install");
2472 }
2473 }
2474 }
2475 else
2476 {
2477 launchButton_->setEnabled(false);
2478 launchButton_->setText("Not Installed");
2479 }
2480 }
2481 else
2482 {
2483 launchButton_->setEnabled(true);
2484 launchButton_->setText("Launch");
2485 }
2486 stopButton_->setVisible(false);
2487 break;
2488 }
2489}
2490
2491// ------------------------------------------------------------------------
2492// applyTheme — panel-specific styling lifted from MainWindow::applyTheme()
2493// ------------------------------------------------------------------------
2495{
2496 const ThemeColors& c = themeMgr_->colors();
2497
2498 // Update details panel. windowBackground is already the application
2499 // palette's QPalette::Window role (set by ThemeManager::applyToApplication),
2500 // so we just need autoFillBackground + Window role — no stylesheet
2501 // required. POC of the palette-over-stylesheet pattern documented in
2502 // memory/qt_modernization_audit_2026_04.md.
2503 if (detailsPanel_)
2504 {
2505 detailsPanel_->setAutoFillBackground(true);
2506 detailsPanel_->setBackgroundRole(QPalette::Window);
2507 }
2508
2509 // Update collapsible sections
2510 if (overviewSection_)
2511 overviewSection_->applyTheme();
2512 if (statisticsSection_)
2513 statisticsSection_->applyTheme();
2514 if (configurationSection_)
2515 configurationSection_->applyTheme();
2516 if (notesSection_)
2517 notesSection_->applyTheme();
2518 if (systemSection_)
2519 systemSection_->applyTheme();
2520
2521 // Update hero image label background
2522 if (heroImageLabel_)
2523 {
2524 heroImageLabel_->setAutoFillBackground(true);
2525
2526 heroImageLabel_->setBackgroundRole(QPalette::AlternateBase);
2527 }
2528
2529 // Update sticky header background
2530 if (gameNameLabel_ && gameNameLabel_->parentWidget())
2531 {
2532 QWidget* header = gameNameLabel_->parentWidget();
2533 header->setStyleSheet(QString("background-color: %1; border-bottom: 1px solid %2;")
2534 .arg(c.panelBackground.name())
2535 .arg(c.border.name()));
2536 }
2537
2538 // Update game name label
2539 if (gameNameLabel_)
2540 {
2541 gameNameLabel_->setStyleSheet(QString("font-size: %2px; font-weight: bold; color: %1; "
2542 "background: transparent; border: none;")
2543 .arg(c.textPrimary.name())
2544 .arg(themeMgr_->scaledFontSize(18)));
2545 }
2546
2547 // Update game info label
2548 if (gameInfoLabel_)
2549 {
2550 gameInfoLabel_->setStyleSheet(
2551 QString("color: %1; font-size: 11px; background: transparent; border: none;")
2552 .arg(c.textSecondary.name()));
2553 }
2554
2555 // Update genres label
2556 if (gameGenresLabel_)
2557 {
2558 gameGenresLabel_->setStyleSheet(
2559 QString("color: %1; font-size: 10px; background: transparent; border: none;")
2560 .arg(c.info.name()));
2561 }
2562
2563 // Update stats label
2564 if (gameStatsLabel_)
2565 {
2566 gameStatsLabel_->setStyleSheet(
2567 QString("color: %1; font-size: 10px;").arg(c.textSecondary.name()));
2568 }
2569
2570 // Update Steam info label
2571 if (gameSteamInfoLabel_)
2572 {
2573 gameSteamInfoLabel_->setStyleSheet(
2574 QString("color: %1; font-size: 10px;").arg(c.info.name()));
2575 }
2576
2577 // Update description label
2578 if (gameDescLabel_)
2579 {
2580 gameDescLabel_->setStyleSheet(
2581 QString("color: %1; font-size: 10px; margin-top: 8px; padding: 8px; "
2582 "background-color: %2; border-radius: 4px;")
2583 .arg(c.textSecondary.name())
2584 .arg(c.cardBackground.name()));
2585 }
2586
2587 // Update launch config label
2588 if (gameLaunchConfigLabel_)
2589 {
2590 gameLaunchConfigLabel_->setStyleSheet(
2591 QString("color: %1; font-size: 10px; margin-top: 10px; padding: 10px; "
2592 "background-color: %2; border-radius: 4px; border: 1px solid %3;")
2593 .arg(c.textSecondary.name())
2594 .arg(c.cardBackground.name())
2595 .arg(c.border.name()));
2596 }
2597
2598 // Update launch button
2599 if (launchButton_)
2600 {
2601 launchButton_->setStyleSheet(
2602 QString("QPushButton { background-color: %1; color: %6; font-weight: bold; "
2603 "padding: 0 24px; border-radius: 6px; border: none; }"
2604 "QPushButton:hover { background-color: %2; }"
2605 "QPushButton:pressed { background-color: %3; }"
2606 "QPushButton:disabled { background-color: %4; color: %5; }")
2607 .arg(c.success.name())
2608 .arg(ThemeManager::lightenColor(c.success, 15).name())
2609 .arg(ThemeManager::darkenColor(c.success, 15).name())
2610 .arg(c.inputBackground.name())
2611 .arg(c.textMuted.name())
2612 .arg(c.textOnAccent.name()));
2613 }
2614
2615 // Update stop button
2616 if (stopButton_)
2617 {
2618 stopButton_->setStyleSheet(
2619 QString("QPushButton { background-color: %1; color: %5; font-weight: bold; "
2620 "padding: 0 24px; border-radius: 6px; border: none; }"
2621 "QPushButton:hover { background-color: %2; }"
2622 "QPushButton:pressed { background-color: %3; }"
2623 "QPushButton:disabled { background-color: %4; color: %6; }")
2624 .arg(c.error.name())
2625 .arg(ThemeManager::lightenColor(c.error, 15).name())
2626 .arg(ThemeManager::darkenColor(c.error, 15).name())
2627 .arg(c.inputBackground.name())
2628 .arg(c.textOnAccent.name())
2629 .arg(c.textMuted.name()));
2630 }
2631
2632 // Update config button
2633 if (configButton_)
2634 {
2635 configButton_->setStyleSheet(
2636 QString("QPushButton { background-color: %1; color: %2; font-weight: bold; "
2637 "padding: 0 20px; border-radius: 6px; border: 1px solid %3; }"
2638 "QPushButton:hover { background-color: %4; border-color: %5; }"
2639 "QPushButton:disabled { color: %6; }")
2640 .arg(c.cardBackground.name())
2641 .arg(c.textSecondary.name())
2642 .arg(c.border.name())
2643 .arg(c.hoverBackground.name())
2644 .arg(c.accent.name())
2645 .arg(c.textMuted.name()));
2646 }
2647
2648 // Update running info container
2649 if (runningInfoContainer_)
2650 {
2651 runningInfoContainer_->setStyleSheet(
2652 QString("background-color: %1; border-radius: 4px; margin-top: 10px;")
2653 .arg(ThemeManager::darkenColor(c.cardBackground, 5).name()));
2654 }
2655
2656 // Update running info label
2657 if (gameRunningInfoLabel_)
2658 {
2659 gameRunningInfoLabel_->setStyleSheet(
2660 QString("color: %1; font-size: 10px; padding: 10px; background: transparent;")
2661 .arg(c.textSecondary.name()));
2662 }
2663
2664 // Update system info label
2665 if (systemInfoLabel_)
2666 {
2667 systemInfoLabel_->setStyleSheet(
2668 QString("color: %1; font-size: 9px; margin-top: 10px; padding: 8px; "
2669 "background-color: %2; border-radius: 4px;")
2670 .arg(c.textMuted.name())
2671 .arg(ThemeManager::darkenColor(c.cardBackground, 5).name()));
2672 }
2673
2674 // Update download progress widgets
2675 if (downloadProgressLabel_)
2676 {
2677 downloadProgressLabel_->setStyleSheet(
2678 QString("color: %1; font-size: 11px; font-weight: bold;").arg(c.info.name()));
2679 }
2680 if (downloadProgressBar_)
2681 {
2682 downloadProgressBar_->setStyleSheet(
2683 QString("QProgressBar { background-color: %1; border-radius: 4px; }"
2684 "QProgressBar::chunk { background-color: %2; border-radius: 4px; }")
2685 .arg(c.inputBackground.name())
2686 .arg(c.info.name()));
2687 }
2688}
2689
2690// ------------------------------------------------------------------------
2691// eventFilter — user-notes click handler, lifted from MainWindow::eventFilter
2692// ------------------------------------------------------------------------
2693bool DetailsPanelManager::Impl::eventFilter(QObject* obj, QEvent* event)
2694{
2695 // Handle clicks on user notes label to open edit dialog
2696 if (obj == userNotesLabel_ && event->type() == QEvent::MouseButtonRelease)
2697 {
2698 if (currentGameId_.empty())
2699 return false;
2700 Game* game = libCtrl_->getGameForEdit(currentGameId_);
2701 if (!game)
2702 return false;
2703
2704 // Open a simple input dialog for editing notes
2705 bool ok;
2706 QString currentNotes = QString::fromStdString(game->userNotes);
2707 QString newNotes = QInputDialog::getMultiLineText(
2708 detailsPanel_, "Edit Notes",
2709 QString("Notes for %1:").arg(QString::fromStdString(game->name)), currentNotes, &ok);
2710
2711 if (ok && newNotes != currentNotes)
2712 {
2713 game->userNotes = newNotes.toStdString();
2714 libCtrl_->updateGame(currentGameId_, *game);
2716 emit owner_->gameChanged(currentGameId_);
2717 }
2718 return true;
2719 }
2720 return QObject::eventFilter(obj, event);
2721}
2722
2723// ------------------------------------------------------------------------
2724// getCachedDiskSpace — MOVED from MainWindow::getCachedDiskSpace()
2725// ------------------------------------------------------------------------
2726uint64_t DetailsPanelManager::Impl::getCachedDiskSpace(const std::string& path)
2727{
2728 auto now = std::chrono::steady_clock::now();
2729 auto it = diskSpaceCache_.find(path);
2730
2731 if (it != diskSpaceCache_.end())
2732 {
2733 // Check if cache is still valid (30 seconds)
2734 auto age = std::chrono::duration_cast<std::chrono::seconds>(now - it->second.lastUpdate);
2735 if (age.count() < 30)
2736 {
2737 return it->second.availableBytes;
2738 }
2739 }
2740
2741 // Cache miss or stale - query filesystem
2742 std::error_code ec;
2743 std::filesystem::space_info spaceInfo = std::filesystem::space(path, ec);
2744 uint64_t available = 0;
2745 if (!ec && spaceInfo.available > 0)
2746 {
2747 available = spaceInfo.available;
2748 }
2749
2750 // Update cache
2751 DiskSpaceCacheEntry cache;
2752 cache.path = path;
2753 cache.availableBytes = available;
2754 cache.lastUpdate = now;
2755 diskSpaceCache_[path] = cache;
2756
2757 return available;
2758}
2759
2760// ==============================================================================
2761// DetailsPanelManager — thin forwarders to Impl
2762// ==============================================================================
2763
2765 core::LaunchController* launchCtrl,
2766 GameThumbnailCache* imgCache, ThemeManager* themeManager,
2767 QObject* qparent)
2768 : QObject(qparent),
2769 impl_(std::make_unique<Impl>(this, parent, libCtrl, launchCtrl, imgCache, themeManager))
2770{
2771}
2772
2774
2776{
2777 return impl_->detailsPanel();
2778}
2779
2780void DetailsPanelManager::update(const std::string& gameId)
2781{
2782 impl_->update(gameId);
2783}
2784
2785void DetailsPanelManager::updateRunningInfo(const std::string& gameId)
2786{
2787 impl_->updateRunningInfo(gameId);
2788}
2789
2790void DetailsPanelManager::updateLaunchButton(const std::string& gameId)
2791{
2792 impl_->updateLaunchButton(gameId);
2793}
2794
2796{
2797 impl_->applyTheme();
2798}
2799
2801{
2802 return impl_->frameMetricsWidget();
2803}
2804
2806{
2807 return impl_->heroImageLabel();
2808}
2809
2811{
2812 return impl_->downloadProgressWidget();
2813}
2814
2816{
2817 return impl_->downloadProgressBar();
2818}
2819
2821{
2822 return impl_->downloadProgressLabel();
2823}
2824
2826{
2827 return impl_->launchButton();
2828}
FrameMetricsWidget * frameMetricsWidget() const
void updateRunningInfo(const std::string &gameId)
bool eventFilter(QObject *obj, QEvent *event) override
void update(const std::string &gameId)
QProgressBar * downloadProgressBar() const
Impl(DetailsPanelManager *owner, QWidget *parent, core::GameLibraryController *libCtrl, core::LaunchController *launchCtrl, GameThumbnailCache *imgCache, ThemeManager *themeMgr)
void updateLaunchButton(const std::string &gameId)
QWidget * widget() const
The root widget — slot into MainWindow's splitter.
QProgressBar * downloadProgressBar() const
void update(const std::string &gameId)
Full refresh for a new selection. Safe with empty string (empty state).
~DetailsPanelManager() override
void updateRunningInfo(const std::string &gameId)
Lightweight refresh driven by the running-game timer; only touches FPS/frametime sections.
void applyTheme()
Re-read theme colours and restyle.
FrameMetricsWidget * frameMetricsWidget() const
Optional embed handle so MainWindow can wire the frame metrics timer.
QPushButton * launchButton() const
QLabel * downloadProgressLabel() const
void launchRequested(const std::string &gameId)
QWidget * downloadProgressWidget() const
DetailsPanelManager(QWidget *parent, core::GameLibraryController *libCtrl, core::LaunchController *launchCtrl, GameThumbnailCache *imgCache, ThemeManager *themeManager, QObject *qparent=nullptr)
void updateLaunchButton(const std::string &gameId)
Refresh only the Launch/Stop button state based on the launch state machine.
bool isCollecting(const std::string &gameId) const
Check if collection is active for a game.
FrameMetrics getMetrics(const std::string &gameId) const
Get current metrics for a game.
static FrameMetricsService & instance()
Get the singleton instance.
const GameProcess * getRunningProcess(const std::string &gameId) const
static GameProcessManager & instance()
Complete representation of a game in the library.
Definition game.h:767
GameMetadata metadata
Descriptive information and media.
Definition game.h:785
std::vector< PlaySession > recentSessions
Recent play sessions (last 20 kept in memory).
Definition game.h:811
std::string userNotes
User's personal notes about the game.
Definition game.h:813
std::vector< std::string > collections
Collections this game belongs to.
Definition game.h:804
std::string installPath
Installation directory path.
Definition game.h:819
CompletionStatus completionStatus
User's completion status.
Definition game.h:810
std::string name
Display name shown in UI.
Definition game.h:774
std::string getSourceName() const
Get human-readable source name.
Definition game.cpp:25
GameStatistics statistics
Play statistics and usage tracking.
Definition game.h:786
GameRunnerConfig runnerConfig
How to launch and run the game.
Definition game.h:784
std::string getFormattedPlayTime() const
Format total play time as human-readable string.
Definition game.cpp:114
GameStatus status
Current installation and execution status.
Definition game.h:778
HowLongToBeatInfo hltbInfo
Time-to-beat estimates.
Definition game.h:812
std::map< std::string, GameRunnerConfig > configTemplates
Named configuration templates (presets) that can be switched between Key is template name (e....
Definition game.h:794
uint64_t installSizeBytes
Installation size in bytes.
Definition game.h:820
bool isInstalled() const
Check if game is currently installed.
Definition game.h:944
std::string activeTemplateName
Currently active template name (empty = using runnerConfig directly).
Definition game.h:797
GameSource source
Where the game was acquired from (Steam, GOG, Local, etc.).
Definition game.h:775
std::string getRunnerName() const
Get human-readable runner name.
Definition game.cpp:49
std::string getImagePath(ImageType type) const
Get path for a specific image type.
Definition game.cpp:221
static const QString & solidFamily()
Get the loaded Solid font family name.
Definition icon_font.h:136
static QString text(char32_t codepoint)
Convert a codepoint to a QString glyph.
Definition icon_font.h:113
static SteamDownloadProgress readGameState(uint32_t appId)
Read current state of a game directly from its appmanifest.
static SystemInfoService & instance()
Get singleton instance.
static QColor darkenColor(const QColor &color, int amount)
Darken a color by decreasing its lightness.
static QColor lightenColor(const QColor &color, int amount)
Lighten a color by increasing its lightness.
int scaledFontSize(int baseSize) const
Get scaled font size for given base size.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
@ Steam
Steam store/platform.
Definition game.h:41
@ VerticalCover
Vertical cover art (600x900, portrait).
Definition game.h:479
@ Logo
Game logo with transparency (PNG).
Definition game.h:481
@ Installing
Game is being installed.
Definition game.h:103
@ Installed
Game is installed and ready to play.
Definition game.h:99
CompletionStatus
User's completion/play status for tracking backlog.
Definition game.h:115
@ Played
Played but no clear completion criteria (e.g., multiplayer).
Definition game.h:122
@ Completed
100% completion (achievements, side content, etc.)
Definition game.h:119
@ Abandoned
Stopped playing, unlikely to return.
Definition game.h:121
@ Beaten
Main story/campaign completed.
Definition game.h:118
@ OnHold
Temporarily paused.
Definition game.h:120
@ Playing
Currently playing.
Definition game.h:117
@ NotPlayed
Never played (backlog).
Definition game.h:116
constexpr char32_t Gamepad
Definition icon_font.h:40
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 isDownloading(uint32_t flags)
Check if a game is currently downloading or updating.
constexpr uint32_t Staging
Staging files after download.
Actual environment and command line read from a running process.
Definition game.h:379
std::vector< std::string > compareWithConfigured(const std::vector< std::string > &configured) const
Compare configured vs actual environment.
Definition game.cpp:1085
static ActualRuntimeInfo readFromProcess(int processId)
Read actual runtime info from a process.
Definition game.cpp:999
std::map< std::string, std::string > getKeyEnvironment() const
Get only gaming-related environment variables.
Definition game.cpp:1067
std::string commandLine
Full command line from /proc/pid/cmdline.
Definition game.h:381
bool valid
Whether the read was successful.
Definition game.h:383
uint64_t storageBytes
Cloud storage used in bytes.
Definition game.h:521
bool enabled
Cloud saves enabled for this game.
Definition game.h:518
bool supported
Game supports Steam Cloud.
Definition game.h:519
int lastSyncState
0=synced, 1=uploading, 2=downloading, 3=error
Definition game.h:520
std::vector< std::string > steamCategories
Steam categories (Single-player, Multi-player, etc.).
Definition game.h:584
int steamAppId
Steam App ID (0 if not a Steam game).
Definition game.h:575
uint32_t steamStateFlags
Steam StateFlags from appmanifest.
Definition game.h:587
CloudSaveInfo cloudSave
Steam Cloud save information.
Definition game.h:596
std::string description
Game description text.
Definition game.h:565
std::string developer
Developer/studio name.
Definition game.h:568
int releaseYear
Year the game was released.
Definition game.h:570
std::string publisher
Publisher name.
Definition game.h:569
std::string protondbTier
Cached tier: "platinum", "gold", "silver", "bronze", "borked", "native".
Definition game.h:601
std::vector< DLCInfo > dlc
Installed DLC for this game.
Definition game.h:597
std::vector< std::string > genres
Game genres (RPG, FPS, Strategy, etc.).
Definition game.h:566
std::string protondbConfidence
Cached confidence: "strong", "good", "weak".
Definition game.h:602
double totalPlayTimeSeconds
Total play time in seconds (for all sessions).
Definition game.h:714
time_t lastPlayed
Unix timestamp of last play session.
Definition game.h:715
int timesLaunched
Number of times game was launched.
Definition game.h:713
int crashCount
Number of times game has crashed.
Definition game.h:728
double completionistHours
100% completion
Definition game.h:679
bool found
Whether a match was found.
Definition game.h:684
double mainPlusExtrasHours
Main + side content.
Definition game.h:678
double mainStoryHours
Main story/campaign only.
Definition game.h:677
Real-time download/installation progress for a Steam game.
double downloadProgress
Download progress (0.0 to 1.0).
uint32_t stateFlags
Current StateFlags.
QColor panelBackground
QColor inputBackground
QColor borderLight
QColor cardBackground
QColor textSecondary
QColor textPrimary
QColor windowBackground
QColor textMuted
QColor hoverBackground
QColor textOnAccent
@ Game
Game-specific fixes.