game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
system_readiness_widget.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// system_readiness_widget.cpp
4// ==============================================================================
5// Compact system readiness dashboard implementation
6// ==============================================================================
7
9#include "theme_manager.h"
10
11#include <QHBoxLayout>
12#include <QPushButton>
13#include <QVBoxLayout>
14
15// ==============================================================================
16// Constructor
17// ==============================================================================
18
20 : QFrame(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
21{
22 setupUI();
23 applyTheme();
24 refresh();
25
26 connect(themeManager_, &ThemeManager::themeChanged, this, &SystemReadinessWidget::applyTheme);
27}
28
29// ==============================================================================
30// Public Methods
31// ==============================================================================
32
34{
35 updateIndicators();
36}
37
38// ==============================================================================
39// Private Methods
40// ==============================================================================
41
42void SystemReadinessWidget::setupUI()
43{
44 setFrameStyle(QFrame::StyledPanel);
45
46 auto* mainLayout = new QHBoxLayout(this);
47 mainLayout->setContentsMargins(8, 4, 8, 4);
48 mainLayout->setSpacing(12);
49
50 // Score indicator
51 scoreLabel_ = new QLabel();
52 scoreLabel_->setToolTip("Overall gaming readiness score");
53 mainLayout->addWidget(scoreLabel_);
54
55 // Separator
56 auto* sep1 = new QFrame();
57 sep1->setFrameShape(QFrame::VLine);
58 mainLayout->addWidget(sep1);
59
60 // Sync status
61 syncLabel_ = new QLabel();
62 syncLabel_->setToolTip("Synchronization method (NTSync > Fsync > Esync)");
63 mainLayout->addWidget(syncLabel_);
64
65 // Tools status
66 toolsLabel_ = new QLabel();
67 toolsLabel_->setToolTip("Performance tools availability");
68 mainLayout->addWidget(toolsLabel_);
69
70 // Kernel status
71 kernelLabel_ = new QLabel();
72 kernelLabel_->setToolTip("Kernel optimization status");
73 mainLayout->addWidget(kernelLabel_);
74
75 mainLayout->addStretch();
76
77 // Details button
78 detailsBtn_ = new QPushButton("Details");
79 detailsBtn_->setFixedHeight(24);
80 connect(detailsBtn_, &QPushButton::clicked, this, &SystemReadinessWidget::detailsRequested);
81 mainLayout->addWidget(detailsBtn_);
82}
83
84void SystemReadinessWidget::updateIndicators()
85{
86 const auto& sys = SystemInfoService::instance().getCapabilities();
87 const ThemeColors& c = themeManager_->colors();
88
89 int score = 0;
90 int maxScore = 0;
91
92 // === Sync Method Score (max 25 points) ===
93 maxScore += 25;
94 QString syncText;
95 QString syncColor;
96 if (sys.canUseNTSync())
97 {
98 syncText = "NTSync";
99 syncColor = c.success.name();
100 score += 25;
101 }
102 else if (sys.canUseFsync())
103 {
104 syncText = "Fsync";
105 syncColor = ThemeManager::lightenColor(c.success, 20).name();
106 score += 20;
107 }
108 else if (sys.kernel.supportsEsync)
109 {
110 syncText = "Esync";
111 syncColor = c.warning.name();
112 score += 10;
113 }
114 else
115 {
116 syncText = "None";
117 syncColor = c.error.name();
118 }
119 syncLabel_->setText(
120 QString("<span style='color: %1;'>%2 %3</span>")
121 .arg(syncColor, getStatusIcon(sys.canUseNTSync() || sys.canUseFsync()), syncText));
122 syncLabel_->setTextFormat(Qt::RichText);
123
124 // === Performance Tools Score (max 25 points) ===
125 maxScore += 25;
126 int toolCount = 0;
127 QStringList availableTools;
128 if (sys.tools.gameMode || sys.tools.gamePerformance)
129 {
130 toolCount++;
131 availableTools << (sys.tools.gamePerformance ? "game-perf" : "GameMode");
132 }
133 if (sys.tools.mangoHud)
134 {
135 toolCount++;
136 availableTools << "MangoHud";
137 }
138 if (sys.tools.gamescope)
139 {
140 toolCount++;
141 availableTools << "Gamescope";
142 }
143
144 score += qMin(toolCount * 8, 25);
145 QString toolColor = toolCount >= 2 ? c.success.name()
146 : toolCount == 1 ? c.warning.name()
147 : c.error.name();
148 toolsLabel_->setText(
149 QString("<span style='color: %1;'>%2 %3</span>")
150 .arg(toolColor, getStatusIcon(toolCount >= 2),
151 availableTools.isEmpty() ? "No tools" : availableTools.join(", ")));
152 toolsLabel_->setTextFormat(Qt::RichText);
153
154 // === Kernel Parameters Score (max 25 points) ===
155 maxScore += 25;
156 int kernelScore = 0;
157 QStringList kernelIssues;
158 if (sys.kernel.maxMapCountOk)
159 {
160 kernelScore += 10;
161 }
162 else
163 {
164 kernelIssues << "max_map_count";
165 }
166 if (sys.kernel.swappinessOk)
167 {
168 kernelScore += 10;
169 }
170 else
171 {
172 kernelIssues << "swappiness";
173 }
174 if (sys.kernel.isCachyOS)
175 {
176 kernelScore += 5;
177 }
178 score += kernelScore;
179
180 QString kernelColor = kernelScore >= 20 ? c.success.name()
181 : kernelScore >= 10 ? c.warning.name()
182 : c.error.name();
183 QString kernelText =
184 kernelIssues.isEmpty() ? "Kernel OK" : "Issues: " + kernelIssues.join(", ");
185 kernelLabel_->setText(QString("<span style='color: %1;'>%2 %3</span>")
186 .arg(kernelColor, getStatusIcon(kernelScore >= 20), kernelText));
187 kernelLabel_->setTextFormat(Qt::RichText);
188
189 // === GPU Score (max 25 points) ===
190 maxScore += 25;
191 if (sys.gpu.supportsVulkan)
192 score += 15;
193 if (sys.gpu.isRDNA2OrNewer() || sys.gpu.isRTXCapable())
194 score += 10;
195
196 // Calculate final score percentage
197 readinessScore_ = maxScore > 0 ? (score * 100 / maxScore) : 0;
198
199 // Update score display
200 QString scoreColor = getScoreColor(readinessScore_);
201 scoreLabel_->setText(QString("<b style='color: %1; font-size: 14px;'>%2%</b>")
202 .arg(scoreColor)
203 .arg(readinessScore_));
204 scoreLabel_->setTextFormat(Qt::RichText);
205 scoreLabel_->setToolTip(QString("Gaming Readiness: %1/100").arg(readinessScore_));
206}
207
208QString SystemReadinessWidget::getStatusIcon(bool good) const
209{
210 return good ? QString::fromUtf8("\u2713") : QString::fromUtf8("\u2717");
211}
212
213QString SystemReadinessWidget::getScoreColor(int score) const
214{
215 const ThemeColors& c = themeManager_->colors();
216 if (score >= 80)
217 return c.success.name();
218 if (score >= 60)
219 return ThemeManager::lightenColor(c.success, 20).name();
220 if (score >= 40)
221 return c.warning.name();
222 return c.error.name();
223}
224
225// ==============================================================================
226// Theme Support
227// ==============================================================================
228
229void SystemReadinessWidget::applyTheme()
230{
231 const ThemeColors& c = themeManager_->colors();
232
233 setStyleSheet(QString("SystemReadinessWidget { background-color: %1; border: 1px solid %2; "
234 "border-radius: 4px; }")
235 .arg(c.cardBackground.name(), c.border.name()));
236
237 if (detailsBtn_)
238 {
239 detailsBtn_->setStyleSheet(
240 QString("QPushButton { background-color: %1; color: %2; border: 1px solid %3; "
241 "border-radius: 3px; padding: 2px 8px; font-size: 11px; }"
242 "QPushButton:hover { background-color: %4; }")
243 .arg(c.cardBackground.name(), c.textPrimary.name(), c.border.name(),
244 c.hoverBackground.name()));
245 }
246
247 // Refresh indicators with new theme colors
248 updateIndicators();
249}
static SystemInfoService & instance()
Get singleton instance.
const SystemCapabilities & getCapabilities()
Get complete system capabilities.
void detailsRequested()
Emitted when user clicks to see more details.
void refresh()
Refresh the readiness status.
SystemReadinessWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void themeChanged()
Emitted when theme or accent color changes.
static QColor lightenColor(const QColor &color, int amount)
Lighten a color by increasing its lightness.
QColor cardBackground
QColor textPrimary
QColor hoverBackground