11#include <QApplication>
12#include <QDesktopServices>
17#include <QtConcurrent/QtConcurrent>
24 : QFrame(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
31 fetchWatcher_ =
new QFutureWatcher<GameSuggestions>(
this);
39 if (fetchWatcher_ && fetchWatcher_->isRunning())
41 fetchWatcher_->cancel();
42 fetchWatcher_->waitForFinished();
52 currentSteamAppId_ = steamAppId;
55 if (fetchWatcher_->isRunning())
57 fetchWatcher_->cancel();
58 fetchWatcher_->waitForFinished();
64 confidenceBadge_->setText(
"...");
65 confidenceBadge_->setStyleSheet(QString(
"background-color: %1; color: %2; padding: 4px 12px; "
66 "border-radius: 4px; font-weight: bold;")
68 confidenceSummary_->setText(
"Loading recommendations...");
69 suggestionsText_->setPlainText(
"Fetching data from ProtonDB and other sources...");
70 applyBtn_->setEnabled(
false);
73 std::string gameNameStd = gameName.toStdString();
74 QFuture<GameSuggestions> future = QtConcurrent::run(
75 [steamAppId, gameNameStd]()
81 disconnect(fetchWatcher_, &QFutureWatcher<GameSuggestions>::finished,
this,
nullptr);
82 connect(fetchWatcher_, &QFutureWatcher<GameSuggestions>::finished,
this,
85 if (fetchWatcher_->isCanceled())
91 if (currentSteamAppId_ != steamAppId)
100 fetchWatcher_->setFuture(future);
105 currentSuggestions_ = suggestions;
112 currentSteamAppId_ = 0;
116 confidenceBadge_->setText(
"—");
117 confidenceBadge_->setStyleSheet(QString(
"background-color: %1; color: %2; padding: 4px 12px; "
118 "border-radius: 4px; font-weight: bold;")
120 confidenceSummary_->setText(
"No game selected");
122 protondbLabel_->setText(
"—");
123 steamDeckLabel_->setText(
"—");
124 lutrisLabel_->setText(
"—");
125 nativeLabel_->setText(
"—");
127 suggestionsText_->clear();
128 applyBtn_->setEnabled(
false);
129 viewProtonDBBtn_->setEnabled(
false);
136void RecommendationsWidget::onApplyClicked()
144void RecommendationsWidget::onViewProtonDBClicked()
146 if (currentSteamAppId_ > 0)
148 QString url = QString(
"https://www.protondb.com/app/%1").arg(currentSteamAppId_);
149 QDesktopServices::openUrl(QUrl(url));
157void RecommendationsWidget::setupUI()
159 setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
161 auto* mainLayout =
new QVBoxLayout(
this);
162 mainLayout->setSpacing(12);
163 mainLayout->setContentsMargins(12, 12, 12, 12);
166 auto* headerLayout =
new QHBoxLayout();
168 confidenceBadge_ =
new QLabel(
"—");
169 confidenceBadge_->setFixedHeight(28);
170 headerLayout->addWidget(confidenceBadge_);
172 confidenceSummary_ =
new QLabel(
"No game selected");
173 confidenceSummary_->setWordWrap(
true);
174 headerLayout->addWidget(confidenceSummary_, 1);
176 mainLayout->addLayout(headerLayout);
179 auto* sourcesGroup =
new QGroupBox(
"Data Sources");
180 auto* sourcesLayout =
new QHBoxLayout(sourcesGroup);
181 sourcesLayout->setSpacing(20);
184 auto createSourceColumn = [&](
const QString& title, QLabel*& valueLabel)
186 auto* col =
new QVBoxLayout();
187 auto* titleLabel =
new QLabel(title);
188 titleLabel->setProperty(
"sourceTitle",
true);
189 valueLabel =
new QLabel(
"—");
190 col->addWidget(titleLabel);
191 col->addWidget(valueLabel);
192 sourcesLayout->addLayout(col);
195 createSourceColumn(
"ProtonDB", protondbLabel_);
196 createSourceColumn(
"Steam Deck", steamDeckLabel_);
197 createSourceColumn(
"Lutris", lutrisLabel_);
198 createSourceColumn(
"Native", nativeLabel_);
200 sourcesLayout->addStretch();
201 mainLayout->addWidget(sourcesGroup);
204 auto* suggestionsGroup =
new QGroupBox(
"Recommended Settings");
205 auto* suggestionsLayout =
new QVBoxLayout(suggestionsGroup);
207 suggestionsText_ =
new QTextEdit();
208 suggestionsText_->setReadOnly(
true);
209 suggestionsText_->setMaximumHeight(150);
210 suggestionsLayout->addWidget(suggestionsText_);
212 mainLayout->addWidget(suggestionsGroup);
215 auto* buttonLayout =
new QHBoxLayout();
217 viewProtonDBBtn_ =
new QPushButton(
"View on ProtonDB");
218 viewProtonDBBtn_->setEnabled(
false);
219 connect(viewProtonDBBtn_, &QPushButton::clicked,
this,
220 &RecommendationsWidget::onViewProtonDBClicked);
221 buttonLayout->addWidget(viewProtonDBBtn_);
223 buttonLayout->addStretch();
225 applyBtn_ =
new QPushButton(
"Apply Recommendations");
226 applyBtn_->setEnabled(
false);
227 connect(applyBtn_, &QPushButton::clicked,
this, &RecommendationsWidget::onApplyClicked);
228 buttonLayout->addWidget(applyBtn_);
230 mainLayout->addLayout(buttonLayout);
237void RecommendationsWidget::updateDisplay()
239 updateConfidenceBadge();
241 updateSuggestionsList();
244 viewProtonDBBtn_->setEnabled(currentSteamAppId_ > 0);
247void RecommendationsWidget::updateConfidenceBadge()
249 const ThemeColors& c = themeManager_->colors();
251 auto level = currentSuggestions_.getConfidenceLevel();
252 float score = currentSuggestions_.getConfidenceScore();
253 int percent =
static_cast<int>(score * 100);
255 QString badgeText = QString(
"%1%").arg(percent);
257 QString summary = QString::fromStdString(currentSuggestions_.getConfidenceSummary());
280 confidenceBadge_->setText(badgeText);
281 confidenceBadge_->setStyleSheet(
282 QString(
"background-color: %1; color: %2; padding: 4px 12px; "
283 "border-radius: 4px; font-weight: bold; font-size: 14px;")
286 confidenceSummary_->setText(summary);
287 QPalette summaryPal = confidenceSummary_->palette();
289 confidenceSummary_->setPalette(summaryPal);
292void RecommendationsWidget::updateDataSources()
294 const ThemeColors& c = themeManager_->colors();
296 QString successColor = c.
success.name();
297 QString warningColor = c.
warning.name();
298 QString errorColor = c.
error.name();
301 if (!currentSuggestions_.protondbTier.empty())
303 QString tier = QString::fromStdString(currentSuggestions_.protondbTier).toUpper();
307 if (tier ==
"PLATINUM")
308 tierColor =
"#b4c7dc";
309 else if (tier ==
"GOLD")
310 tierColor =
"#cfb53b";
311 else if (tier ==
"SILVER")
312 tierColor =
"#a8a8a8";
313 else if (tier ==
"BRONZE")
314 tierColor =
"#cd7f32";
315 else if (tier ==
"BORKED")
316 tierColor = errorColor;
318 tierColor = mutedColor;
321 QString(
"<span style='color: %1; font-weight: bold;'>%2</span>").arg(tierColor, tier);
322 if (currentSuggestions_.protondbReportCount > 0)
324 text += QString(
" <span style='color: %1;'>(%2 reports)</span>")
326 .arg(currentSuggestions_.protondbReportCount);
328 protondbLabel_->setText(text);
329 protondbLabel_->setTextFormat(Qt::RichText);
330 protondbLabel_->setStyleSheet(
"");
334 protondbLabel_->setText(
"No data");
335 protondbLabel_->setStyleSheet(QString(
"color: %1;").arg(mutedColor));
339 if (!currentSuggestions_.steamDeckStatus.empty())
341 QString status = QString::fromStdString(currentSuggestions_.steamDeckStatus);
344 if (status ==
"Verified")
345 statusColor = successColor;
346 else if (status ==
"Playable")
347 statusColor = warningColor;
348 else if (status ==
"Unsupported")
349 statusColor = errorColor;
351 statusColor = mutedColor;
353 steamDeckLabel_->setText(QString(
"<span style='color: %1; font-weight: bold;'>%2</span>")
354 .arg(statusColor, status));
355 steamDeckLabel_->setTextFormat(Qt::RichText);
356 steamDeckLabel_->setStyleSheet(
"");
360 steamDeckLabel_->setText(
"Unknown");
361 steamDeckLabel_->setStyleSheet(QString(
"color: %1;").arg(mutedColor));
365 if (currentSuggestions_.hasLutrisInstaller)
367 QString text = QString(
"<span style='color: %1;'>Available</span>").arg(successColor);
368 if (currentSuggestions_.lutrisDownloadCount > 0)
370 text += QString(
" <span style='color: %1;'>(%2 installs)</span>")
372 .arg(currentSuggestions_.lutrisDownloadCount);
374 lutrisLabel_->setText(text);
375 lutrisLabel_->setTextFormat(Qt::RichText);
376 lutrisLabel_->setStyleSheet(
"");
380 lutrisLabel_->setText(
"No installer");
381 lutrisLabel_->setStyleSheet(QString(
"color: %1;").arg(mutedColor));
385 if (currentSuggestions_.hasNativeLinux)
387 nativeLabel_->setText(
388 QString(
"<span style='color: %1; font-weight: bold;'>Yes</span>").arg(successColor));
389 nativeLabel_->setTextFormat(Qt::RichText);
390 nativeLabel_->setStyleSheet(
"");
394 nativeLabel_->setText(
"No");
395 nativeLabel_->setStyleSheet(QString(
"color: %1;").arg(mutedColor));
399void RecommendationsWidget::updateSuggestionsList()
401 if (currentSuggestions_.suggestions.empty())
403 suggestionsText_->setPlainText(
"No specific recommendations available.");
407 const ThemeColors& c = themeManager_->colors();
410 html += QString(
"<style>"
411 "body { font-family: monospace; font-size: 12px; color: %1; }"
412 ".critical { color: %2; }"
413 ".recommended { color: %3; }"
414 ".optional { color: %4; }"
415 ".source { color: %5; font-size: 10px; }"
421 std::vector<const GameSuggestion*> critical, recommended, optional;
422 for (
const auto& s : currentSuggestions_.suggestions)
427 critical.push_back(&s);
430 recommended.push_back(&s);
433 optional.push_back(&s);
438 auto formatSuggestion = [](
const GameSuggestion* s,
const QString& cssClass) -> QString
440 QString line = QString(
"<div class='%1'>• %2")
441 .arg(cssClass, QString::fromStdString(s->
title).toHtmlEscaped());
445 line += QString(
" <code>%1=%2</code>")
446 .arg(QString::fromStdString(s->
envKey).toHtmlEscaped(),
447 QString::fromStdString(s->
envValue).toHtmlEscaped());
452 QString(
" → %1").arg(QString::fromStdString(s->
recommendedRunner).toHtmlEscaped());
456 line += QString(
" <span class='source'>[%1]</span>")
457 .arg(QString::fromStdString(s->
source).toHtmlEscaped());
463 if (!critical.empty())
465 html +=
"<div><b>⚠ Critical:</b></div>";
466 for (
const auto* s : critical)
468 html += formatSuggestion(s,
"critical");
472 if (!recommended.empty())
474 html +=
"<div><b>Recommended:</b></div>";
475 for (
const auto* s : recommended)
477 html += formatSuggestion(s,
"recommended");
481 if (!optional.empty())
483 html +=
"<div><b>Optional:</b></div>";
484 for (
const auto* s : optional)
486 html += formatSuggestion(s,
"optional");
490 suggestionsText_->setHtml(html);
497void RecommendationsWidget::applyTheme()
499 const ThemeColors& c = themeManager_->colors();
503 QString(
"RecommendationsWidget { background-color: %1; border: 1px solid %2; "
504 "border-radius: 6px; }"
505 "QGroupBox { color: %3; border: 1px solid %4; border-radius: 4px; margin-top: 8px; "
506 "padding-top: 8px; }"
507 "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 5px; }"
508 "QLabel[sourceTitle=\"true\"] { font-weight: bold; color: %5; }")
513 if (suggestionsText_)
515 suggestionsText_->setStyleSheet(
516 QString(
"QTextEdit { background-color: %1; border: 1px solid %2; color: %3; }")
523 applyBtn_->setStyleSheet(
524 QString(
"QPushButton { background-color: %1; color: %2; padding: 8px 16px; "
525 "font-weight: bold; border-radius: 4px; } "
526 "QPushButton:hover { background-color: %3; } "
527 "QPushButton:disabled { background-color: %4; color: %5; }")
534 if (viewProtonDBBtn_)
536 viewProtonDBBtn_->setStyleSheet(
537 QString(
"QPushButton { background-color: %1; color: %2; padding: 8px 16px; border: 1px "
538 "solid %3; border-radius: 4px; } "
539 "QPushButton:hover { background-color: %4; } "
540 "QPushButton:disabled { background-color: %5; color: %6; border-color: %5; }")
546 if (confidenceSummary_)
548 QPalette p = confidenceSummary_->palette();
550 confidenceSummary_->setPalette(p);
561 if (confidenceBadge_)
563 confidenceBadge_->setStyleSheet(
564 QString(
"background-color: %1; color: %2; padding: 4px 12px; "
565 "border-radius: 4px; font-weight: bold; font-size: 14px;")
static GameSuggestions getSuggestions(const Game &game)
Get suggestions for a game.
static QColor darkenColor(const QColor &color, int amount)
Darken a color by decreasing its lightness.
void themeChanged()
Emitted when theme or accent color changes.
static QColor lightenColor(const QColor &color, int amount)
Lighten a color by increasing its lightness.
std::string recommendedRunner
Collection of suggestions for a game.
bool hasRecommendations() const