game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
first_run_wizard.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/first_run_wizard.cpp
4// ==============================================================================
5// First-run setup wizard implementation
6// ==============================================================================
7
9#include "theme_manager.h"
10
11#include <QApplication>
12#include <QCheckBox>
13#include <QDir>
14#include <QDirIterator>
15#include <QFileInfo>
16#include <QFont>
17#include <QFrame>
18#include <QGridLayout>
19#include <QHBoxLayout>
20#include <QLabel>
21#include <QLineEdit>
22#include <QListWidget>
23#include <QPushButton>
24#include <QRegularExpression>
25#include <QSettings>
26#include <QVBoxLayout>
27
28// ==============================================================================
29// FirstRunWizard
30// ==============================================================================
31
32FirstRunWizard::FirstRunWizard(QWidget* parent, ThemeManager* themeManager)
33 : QWizard(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
34{
35 setWindowTitle("Welcome to Game Launcher");
36 setWizardStyle(QWizard::ModernStyle);
37 setMinimumSize(720, 560);
38 resize(780, 600);
39
40 setOption(QWizard::HaveHelpButton, false);
41
42 addPage(new WelcomePage(this, themeManager_));
43 addPage(new ThemePage(this, themeManager_));
44 addPage(new IntegrationsPage(this, themeManager_));
45 addPage(new DonePage(this, themeManager_));
46
47 setupStyle();
48
49 connect(themeManager_, &ThemeManager::themeChanged, this, &FirstRunWizard::setupStyle);
50 connect(this, &QWizard::accepted, this, &FirstRunWizard::markCompleted);
51}
52
54{
55 QSettings settings;
56 return settings.value("app/firstRunCompleted", false).toBool();
57}
58
60{
61 QSettings settings;
62 settings.setValue("app/firstRunCompleted", true);
63
64 // Save the selected theme so MainWindow can pick it up
65 // (ThemeManager's settingsController isn't available yet during wizard).
66 // This is a static method, so use the singleton directly.
67 QString currentTheme = ThemeManager::instance().currentThemeId();
68 if (!currentTheme.isEmpty())
69 {
70 settings.setValue("app/wizardThemeId", currentTheme);
71 }
72}
73
74void FirstRunWizard::setupStyle()
75{
76 const auto& c = themeManager_->colors();
77
78 QColor accentFaded = c.accent;
79 accentFaded.setAlpha(40);
80
81 setStyleSheet(
82 QString("QWizard {"
83 " background: %1;"
84 "}"
85 "QWizardPage {"
86 " background: %1;"
87 " color: %2;"
88 "}"
89 "QLabel {"
90 " color: %2;"
91 "}"
92 // Wizard Next/Finish buttons — accent styled
93 "QPushButton[text=\"Next\"], QPushButton[text=\"Finish\"],"
94 "QPushButton[text=\"&Next >\"], QPushButton[text=\"&Finish\"] {"
95 " background: %6;"
96 " color: %7;"
97 " border: none;"
98 " border-radius: 6px;"
99 " padding: 8px 20px;"
100 " font-weight: bold;"
101 "}"
102 "QPushButton[text=\"Next\"]:hover, QPushButton[text=\"Finish\"]:hover,"
103 "QPushButton[text=\"&Next >\"]:hover, QPushButton[text=\"&Finish\"]:hover {"
104 " background: %9;"
105 "}"
106 // Other wizard buttons — secondary
107 "QPushButton {"
108 " background: %3;"
109 " color: %2;"
110 " border: 1px solid %4;"
111 " border-radius: 6px;"
112 " padding: 8px 18px;"
113 "}"
114 "QPushButton:hover {"
115 " background: %5;"
116 " border-color: %6;"
117 "}"
118 "QPushButton:pressed {"
119 " background: %6;"
120 " color: %7;"
121 "}"
122 "QListWidget {"
123 " background: %8;"
124 " color: %2;"
125 " border: 1px solid %4;"
126 " border-radius: 6px;"
127 "}"
128 "QListWidget::item {"
129 " padding: 7px 10px;"
130 " border-radius: 4px;"
131 " margin: 1px 2px;"
132 "}"
133 "QListWidget::item:hover {"
134 " background: %5;"
135 "}"
136 "QListWidget::item:selected {"
137 " background: %10;"
138 " color: %2;"
139 "}"
140 "QCheckBox {"
141 " color: %2;"
142 " spacing: 8px;"
143 "}"
144 "QCheckBox::indicator {"
145 " width: 18px;"
146 " height: 18px;"
147 " border: 2px solid %4;"
148 " border-radius: 4px;"
149 " background: %8;"
150 "}"
151 "QCheckBox::indicator:checked {"
152 " background: %6;"
153 " border-color: %6;"
154 "}"
155 "QCheckBox::indicator:hover {"
156 " border-color: %6;"
157 "}"
158 "QRadioButton {"
159 " color: %2;"
160 " spacing: 8px;"
161 "}"
162 "QRadioButton::indicator {"
163 " width: 18px;"
164 " height: 18px;"
165 " border: 2px solid %4;"
166 " border-radius: 9px;"
167 " background: %8;"
168 "}"
169 "QRadioButton::indicator:checked {"
170 " background: %6;"
171 " border-color: %6;"
172 "}"
173 "QRadioButton::indicator:hover {"
174 " border-color: %6;"
175 "}"
176 "QLineEdit {"
177 " background: %8;"
178 " color: %2;"
179 " border: 1px solid %4;"
180 " border-radius: 6px;"
181 " padding: 6px 10px;"
182 "}"
183 "QLineEdit:focus {"
184 " border-color: %6;"
185 "}")
186 .arg(c.windowBackground.name(), // %1
187 c.textPrimary.name(), // %2
188 c.cardBackground.name(), // %3
189 c.border.name(), // %4
190 c.hoverBackground.name(), // %5
191 c.accent.name(), // %6
192 c.textOnAccent.name(), // %7
193 c.inputBackground.name(), // %8
194 c.accentHover.name(), // %9
195 accentFaded.name(QColor::HexArgb) // %10
196 ));
197}
198
199// ==============================================================================
200// WelcomePage
201// ==============================================================================
202
203WelcomePage::WelcomePage(QWidget* parent, ThemeManager* themeManager)
204 : QWizardPage(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
205{
206 setTitle("");
207 setupUI();
208}
209
210void WelcomePage::setupUI()
211{
212 auto* layout = new QVBoxLayout(this);
213 layout->setSpacing(16);
214
215 layout->addStretch(2);
216
217 // App icon
218 auto* iconLabel = new QLabel(this);
219 iconLabel->setPixmap(QApplication::windowIcon().pixmap(72, 72));
220 iconLabel->setAlignment(Qt::AlignCenter);
221 layout->addWidget(iconLabel);
222
223 layout->addSpacing(8);
224
225 // Title
226 auto* titleLabel = new QLabel("Game Launcher", this);
227 QFont titleFont = titleLabel->font();
228 titleFont.setPointSize(themeManager_->scaledFontSize(24));
229 titleFont.setBold(true);
230 titleLabel->setFont(titleFont);
231 titleLabel->setAlignment(Qt::AlignCenter);
232 layout->addWidget(titleLabel);
233
234 layout->addSpacing(4);
235
236 // Subtitle
237 auto* subtitleLabel = new QLabel("Your complete game library, unified.\n"
238 "Let's get you set up.",
239 this);
240 QFont subFont = subtitleLabel->font();
241 subFont.setPointSize(themeManager_->scaledFontSize(12));
242 subtitleLabel->setFont(subFont);
243 subtitleLabel->setAlignment(Qt::AlignCenter);
244 subtitleLabel->setWordWrap(true);
245 const auto& c = themeManager_->colors();
246 QPalette subPal = subtitleLabel->palette();
247 subPal.setColor(QPalette::WindowText, c.textSecondary);
248 subtitleLabel->setPalette(subPal);
249 layout->addWidget(subtitleLabel);
250
251 layout->addStretch(3);
252}
253
254// ==============================================================================
255// ThemePage
256// ==============================================================================
257
258ThemePage::ThemePage(QWidget* parent, ThemeManager* themeManager)
259 : QWizardPage(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance()),
260 selectedThemeId_(themeManager_->currentThemeId())
261{
262 setTitle("Appearance");
263 setSubTitle("Choose a color scheme. You can change this anytime in Settings.");
264 setupUI();
265}
266
267void ThemePage::setupUI()
268{
269 auto* layout = new QVBoxLayout(this);
270 layout->setSpacing(16);
271
272 layout->addStretch(1);
273
274 // Theme grid - 4 columns x 3 rows
275 auto* grid = new QGridLayout();
276 grid->setSpacing(12);
277 grid->setAlignment(Qt::AlignCenter);
278
279 struct ThemeInfo
280 {
281 QString id, label;
282 QColor bg, fg, accent;
283 };
284
285 QList<ThemeInfo> themes = {
286 {"auto", "Auto", QColor("#2b2b2b"), QColor("#e0e0e0"), QColor("#4a9eff")},
287 {"standard-dark", "Dark", QColor("#1e1e2e"), QColor("#cdd6f4"), QColor("#89b4fa")},
288 {"standard-light", "Light", QColor("#f5f5f5"), QColor("#1e1e1e"), QColor("#1a73e8")},
289 {"cachyos-emerald", "CachyOS", QColor("#1a1b26"), QColor("#c0caf5"), QColor("#00b894")},
290 {"nord-dark", "Nord Dark", QColor("#2e3440"), QColor("#d8dee9"), QColor("#88c0d0")},
291 {"nord-light", "Nord Light", QColor("#eceff4"), QColor("#2e3440"), QColor("#5e81ac")},
292 {"dracula", "Dracula", QColor("#282a36"), QColor("#f8f8f2"), QColor("#bd93f9")},
293 {"catppuccin-mocha", "Catppuccin", QColor("#1e1e2e"), QColor("#cdd6f4"), QColor("#cba6f7")},
294 {"gruvbox-dark", "Gruvbox Dark", QColor("#282828"), QColor("#ebdbb2"), QColor("#fe8019")},
295 {"gruvbox-light", "Gruvbox Light", QColor("#fbf1c7"), QColor("#3c3836"), QColor("#d65d0e")},
296 {"tokyo-night", "Tokyo Night", QColor("#1a1b26"), QColor("#c0caf5"), QColor("#7aa2f7")},
297 {"solarized-light", "Solarized", QColor("#fdf6e3"), QColor("#657b83"), QColor("#268bd2")},
298 };
299
300 for (int i = 0; i < themes.size(); ++i)
301 {
302 const auto& t = themes[i];
303 auto* btn = createThemeButton(t.id, t.label, t.bg, t.fg, t.accent);
304 grid->addWidget(btn, i / 4, i % 4);
305 }
306
307 layout->addLayout(grid);
308 layout->addStretch(2);
309
310 selectTheme(selectedThemeId_);
311}
312
313QPushButton* ThemePage::createThemeButton(const QString& themeId, const QString& label,
314 const QColor& bg, const QColor& fg, const QColor& accent)
315{
316 auto* btn = new QPushButton(this);
317 btn->setFixedSize(150, 90);
318 btn->setCursor(Qt::PointingHandCursor);
319 btn->setProperty("themeId", themeId);
320
321 auto* btnLayout = new QVBoxLayout(btn);
322 btnLayout->setContentsMargins(0, 0, 0, 0);
323 btnLayout->setSpacing(4);
324
325 // Color preview area
326 auto* swatchFrame = new QFrame(btn);
327 swatchFrame->setFixedHeight(48);
328 swatchFrame->setStyleSheet(QString("QFrame { background: %1; border-top-left-radius: 5px; "
329 "border-top-right-radius: 5px; border: none; }")
330 .arg(bg.name()));
331
332 auto* swatchLayout = new QVBoxLayout(swatchFrame);
333 swatchLayout->setContentsMargins(10, 6, 10, 6);
334
335 // Text sample
336 auto* sampleLabel = new QLabel("Aa", swatchFrame);
337 sampleLabel->setStyleSheet(
338 QString(
339 "color: %1; font-size: %2px; font-weight: bold; background: transparent; border: none;")
340 .arg(fg.name())
341 .arg(themeManager_->scaledFontSize(16)));
342 sampleLabel->setAlignment(Qt::AlignCenter);
343 swatchLayout->addWidget(sampleLabel);
344
345 // Accent bar
346 auto* accentBar = new QFrame(swatchFrame);
347 accentBar->setFixedHeight(3);
348 accentBar->setStyleSheet(
349 QString("QFrame { background: %1; border-radius: 1px; border: none; }").arg(accent.name()));
350 swatchLayout->addWidget(accentBar);
351
352 btnLayout->addWidget(swatchFrame);
353
354 // Theme name
355 auto* nameLabel = new QLabel(label, btn);
356 nameLabel->setAlignment(Qt::AlignCenter);
357 QFont nameFont = nameLabel->font();
358 nameFont.setPointSize(themeManager_->scaledFontSize(9));
359 nameLabel->setFont(nameFont);
360 nameLabel->setStyleSheet("background: transparent; border: none;");
361 btnLayout->addWidget(nameLabel);
362
363 themeButtons_.append(btn);
364
365 connect(btn, &QPushButton::clicked, this, [this, themeId]() { selectTheme(themeId); });
366
367 return btn;
368}
369
370void ThemePage::selectTheme(const QString& themeId)
371{
372 selectedThemeId_ = themeId;
373
374 themeManager_->setTheme(themeId);
375 themeManager_->applyToApplication();
376
377 const auto& c = themeManager_->colors();
378
379 for (auto* btn : themeButtons_)
380 {
381 QString id = btn->property("themeId").toString();
382 bool selected = (id == themeId);
383
384 btn->setStyleSheet(QString("QPushButton {"
385 " background: %1;"
386 " border: %2;"
387 " border-radius: 6px;"
388 " padding: 4px;"
389 "}"
390 "QPushButton:hover {"
391 " border: 2px solid %3;"
392 "}")
393 .arg(c.cardBackground.name(),
394 selected ? QString("2px solid %1").arg(c.accent.name())
395 : QString("1px solid %1").arg(c.border.name()),
396 c.accent.name()));
397 }
398}
399
400// ==============================================================================
401// IntegrationsPage - Home page selection & integrations
402// ==============================================================================
403
405 : QWizardPage(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
406{
407 setTitle("Home Page");
408 setSubTitle("Choose what you see when the app starts.");
409 setupUI();
410}
411
412void IntegrationsPage::setupUI()
413{
414 auto* layout = new QVBoxLayout(this);
415 layout->setSpacing(20);
416
417 layout->addStretch(1);
418
419 const auto& c = themeManager_->colors();
420 QSettings settings;
421
422 // --- Option 1: Game Library ---
423 auto* libraryCard = new QFrame(this);
424 libraryCard->setStyleSheet(
425 QString("QFrame#libraryCard { background: %1; border: 1px solid %2; border-radius: 8px; }")
426 .arg(c.cardBackground.name(), c.border.name()));
427 libraryCard->setObjectName("libraryCard");
428
429 auto* libLayout = new QVBoxLayout(libraryCard);
430 libLayout->setContentsMargins(20, 14, 20, 14);
431 libLayout->setSpacing(6);
432
433 homeGameLibrary_ = new QRadioButton("Game Library", libraryCard);
434 QFont radioFont = homeGameLibrary_->font();
435 radioFont.setPointSize(themeManager_->scaledFontSize(12));
436 radioFont.setBold(true);
437 homeGameLibrary_->setFont(radioFont);
438 homeGameLibrary_->setStyleSheet("border: none;");
439 libLayout->addWidget(homeGameLibrary_);
440
441 auto* libDesc = new QLabel(
442 "Start on your game collection with quick access to launch, configure, and manage games.",
443 libraryCard);
444 libDesc->setWordWrap(true);
445 libDesc->setStyleSheet(
446 QString("color: %1; border: none; padding-left: 24px;").arg(c.textSecondary.name()));
447 libLayout->addWidget(libDesc);
448
449 layout->addWidget(libraryCard);
450
451 // --- Option 2: Home Assistant ---
452 auto* haCard = new QFrame(this);
453 haCard->setStyleSheet(
454 QString("QFrame#haCard { background: %1; border: 1px solid %2; border-radius: 8px; }")
455 .arg(c.cardBackground.name(), c.border.name()));
456 haCard->setObjectName("haCard");
457
458 auto* haLayout = new QVBoxLayout(haCard);
459 haLayout->setContentsMargins(20, 14, 20, 14);
460 haLayout->setSpacing(6);
461
462 homeAssistantRadio_ = new QRadioButton("Home Assistant Dashboard", haCard);
463 homeAssistantRadio_->setFont(radioFont);
464 homeAssistantRadio_->setStyleSheet("border: none;");
465 haLayout->addWidget(homeAssistantRadio_);
466
467 auto* haDesc = new QLabel("Open your Home Assistant dashboard on launch. "
468 "Control smart home devices without leaving the launcher.",
469 haCard);
470 haDesc->setWordWrap(true);
471 haDesc->setStyleSheet(
472 QString("color: %1; border: none; padding-left: 24px;").arg(c.textSecondary.name()));
473 haLayout->addWidget(haDesc);
474
475 // URL field (indented under radio)
476 auto* urlRow = new QHBoxLayout();
477 urlRow->setContentsMargins(24, 4, 0, 0);
478 auto* urlLabel = new QLabel("URL:", haCard);
479 urlLabel->setStyleSheet("border: none;");
480 haUrlEdit_ = new QLineEdit(haCard);
481 haUrlEdit_->setPlaceholderText("http://homeassistant.local:8123");
482
483 QString savedUrl = settings.value("app/homeAssistantUrl", "").toString();
484 haUrlEdit_->setText(savedUrl);
485
486 urlRow->addWidget(urlLabel);
487 urlRow->addWidget(haUrlEdit_, 1);
488 haLayout->addLayout(urlRow);
489
490 layout->addWidget(haCard);
491
492 layout->addStretch(2);
493
494 // Set default selection based on current setting
495 bool haEnabled = settings.value("app/enableHomeAssistant", false).toBool();
496 if (haEnabled && !savedUrl.isEmpty())
497 homeAssistantRadio_->setChecked(true);
498 else
499 homeGameLibrary_->setChecked(true);
500
501 updateHAFields();
502
503 connect(homeGameLibrary_, &QRadioButton::toggled, this, &IntegrationsPage::updateHAFields);
504 connect(homeAssistantRadio_, &QRadioButton::toggled, this, &IntegrationsPage::updateHAFields);
505}
506
507void IntegrationsPage::updateHAFields()
508{
509 bool haSelected = homeAssistantRadio_->isChecked();
510 haUrlEdit_->setEnabled(haSelected);
511}
512
514{
515 QSettings settings;
516 bool haEnabled = homeAssistantRadio_->isChecked();
517 // Save to QSettings so MainWindow can pick up wizard choices
518 // (settings controller isn't available during wizard)
519 settings.setValue("wizard/enableHomeAssistant", haEnabled);
520 if (!haUrlEdit_->text().trimmed().isEmpty())
521 {
522 settings.setValue("wizard/homeAssistantUrl", haUrlEdit_->text().trimmed());
523 }
524}
525
526// ==============================================================================
527// LibraryDetectionPage
528// ==============================================================================
529
531 : QWizardPage(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
532{
533 setTitle("Game Libraries");
534 setSubTitle("Scanning your system for installed games.");
535 setupUI();
536}
537
538void LibraryDetectionPage::setupUI()
539{
540 auto* layout = new QVBoxLayout(this);
541 layout->setSpacing(12);
542
543 sourcesList_ = new QListWidget(this);
544 sourcesList_->setSelectionMode(QAbstractItemView::NoSelection);
545 sourcesList_->setFocusPolicy(Qt::NoFocus);
546 layout->addWidget(sourcesList_, 1);
547
548 summaryLabel_ = new QLabel(this);
549 summaryLabel_->setWordWrap(true);
550 QFont summaryFont = summaryLabel_->font();
551 summaryFont.setPointSize(themeManager_->scaledFontSize(10));
552 summaryLabel_->setFont(summaryFont);
553 const auto& c = themeManager_->colors();
554 QPalette sumPal = summaryLabel_->palette();
555 sumPal.setColor(QPalette::WindowText, c.textSecondary);
556 summaryLabel_->setPalette(sumPal);
557 layout->addWidget(summaryLabel_);
558}
559
561{
562 runDetection();
563}
564
565void LibraryDetectionPage::runDetection()
566{
567 sourcesList_->clear();
568 int totalGames = 0;
569 int sourcesFound = 0;
570
571 const auto& c = themeManager_->colors();
572 auto addSourceItem = [&](const QString& name, bool found, int games = 0, bool showCount = true)
573 {
574 auto* item = new QListWidgetItem(sourcesList_);
575 auto* label = new QLabel(sourcesList_);
576 label->setTextFormat(Qt::RichText);
577
578 QString statusColor, statusText, iconHtml;
579 if (found)
580 {
581 iconHtml = QString("<span style='color:%1; font-weight:bold;'>&#10003;</span>")
582 .arg(c.success.name());
583 statusColor = c.success.name();
584 statusText =
585 (showCount && games > 0) ? QString("%1 game(s) found").arg(games) : "detected";
586 sourcesFound++;
587 totalGames += games;
588 }
589 else
590 {
591 iconHtml = QString("<span style='color:%1; font-weight:bold;'>&#10007;</span>")
592 .arg(c.error.name());
593 statusColor = c.textSecondary.name();
594 statusText = "not detected";
595 }
596
597 int fs14 = themeManager_->scaledFontSize(14);
598 int fs13 = themeManager_->scaledFontSize(13);
599 label->setText(QString("%1 <b style='color:%2; font-size:%6px;'>%3</b>"
600 " <span style='color:%4; font-size:%7px;'>&mdash; %5</span>")
601 .arg(iconHtml, c.textPrimary.name(), name, statusColor, statusText)
602 .arg(fs14)
603 .arg(fs13));
604
605 QFont labelFont = label->font();
606 labelFont.setPointSize(themeManager_->scaledFontSize(11));
607 label->setFont(labelFont);
608 label->setStyleSheet(QString("color: %1; padding: 8px 12px; background: transparent;")
609 .arg(c.textPrimary.name()));
610 label->setMinimumHeight(32);
611 item->setSizeHint(QSize(0, 36));
612 sourcesList_->setItemWidget(item, label);
613 };
614
615 // --- Steam ---
616 {
617 QStringList steamPaths = {
618 QDir::homePath() + "/.local/share/Steam",
619 QDir::homePath() + "/.steam/steam",
620 QDir::homePath() + "/.steam/root",
621 QDir::homePath() + "/.var/app/com.valvesoftware.Steam/.local/share/Steam",
622 };
623
624 bool found = false;
625 int games = 0;
626
627 for (const auto& path : steamPaths)
628 {
629 QDir dir(path);
630 if (!dir.exists())
631 continue;
632 found = true;
633
634 QDir steamApps(path + "/steamapps");
635 if (steamApps.exists())
636 {
637 games = static_cast<int>(
638 steamApps.entryList(QStringList() << "appmanifest_*.acf", QDir::Files).size());
639 }
640
641 // Check additional library folders
642 QFile libFile(path + "/steamapps/libraryfolders.vdf");
643 if (libFile.open(QIODevice::ReadOnly | QIODevice::Text))
644 {
645 QString content = libFile.readAll();
646 libFile.close();
647 QRegularExpression pathRegex(QStringLiteral("\"path\"\\s+\"([^\"]+)\""));
648 auto iter = pathRegex.globalMatch(content);
649 while (iter.hasNext())
650 {
651 auto match = iter.next();
652 QString libPath = match.captured(1);
653 if (libPath != path)
654 {
655 QDir extra(libPath + "/steamapps");
656 if (extra.exists())
657 games += static_cast<int>(
658 extra.entryList(QStringList() << "appmanifest_*.acf", QDir::Files)
659 .size());
660 }
661 }
662 }
663 break;
664 }
665 addSourceItem("Steam", found, games);
666 }
667
668 // --- Lutris ---
669 {
670 bool found = false;
671 int games = 0;
672 QStringList paths = {
673 QDir::homePath() + "/.local/share/lutris",
674 QDir::homePath() + "/.config/lutris",
675 };
676 for (const auto& path : paths)
677 {
678 if (!QDir(path).exists())
679 continue;
680 found = true;
681 QDir gamesDir(path + "/games");
682 if (gamesDir.exists())
683 games = qMax(
684 games, static_cast<int>(
685 gamesDir.entryList(QStringList() << "*.yml" << "*.yaml", QDir::Files)
686 .size()));
687 break;
688 }
689 addSourceItem("Lutris", found, games);
690 }
691
692 // --- Heroic ---
693 {
694 bool found = QDir(QDir::homePath() + "/.config/heroic").exists();
695 addSourceItem("Heroic Games Launcher", found, 0, false);
696 }
697
698 // --- Bottles ---
699 {
700 bool found =
701 QDir(QDir::homePath() + "/.local/share/bottles").exists() ||
702 QDir(QDir::homePath() + "/.var/app/com.usebottles.bottles/data/bottles").exists();
703 addSourceItem("Bottles", found, 0, false);
704 }
705
706 // Summary
707 if (sourcesFound > 0)
708 {
709 summaryLabel_->setText(QString("Found %1 source(s) with %2 total game(s). "
710 "You can add more sources from Settings after setup.")
711 .arg(sourcesFound)
712 .arg(totalGames));
713 }
714 else
715 {
716 summaryLabel_->setText("No game sources detected. You can add games manually "
717 "or configure sources in Settings after setup.");
718 }
719}
720
721// ==============================================================================
722// DonePage
723// ==============================================================================
724
725DonePage::DonePage(QWidget* parent, ThemeManager* themeManager)
726 : QWizardPage(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
727{
728 setTitle("Ready");
729 setSubTitle("Your system has been scanned for game sources.");
730 setupUI();
731}
732
733void DonePage::setupUI()
734{
735 auto* layout = new QVBoxLayout(this);
736 layout->setSpacing(12);
737 layout->setContentsMargins(20, 8, 20, 8);
738
739 // Library detection results
740 sourcesList_ = new QListWidget(this);
741 sourcesList_->setSelectionMode(QAbstractItemView::NoSelection);
742 sourcesList_->setFocusPolicy(Qt::NoFocus);
743 sourcesList_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
744 sourcesList_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
745 layout->addWidget(sourcesList_);
746
747 layout->addSpacing(4);
748
749 summaryLabel_ = new QLabel(this);
750 summaryLabel_->setAlignment(Qt::AlignCenter);
751 summaryLabel_->setWordWrap(true);
752 QFont summaryFont = summaryLabel_->font();
753 summaryFont.setPointSize(themeManager_->scaledFontSize(11));
754 summaryLabel_->setFont(summaryFont);
755 layout->addWidget(summaryLabel_);
756
757 layout->addSpacing(8);
758
759 // Quick tips
760 const auto& c = themeManager_->colors();
761 auto* tipsLabel = new QLabel("Ctrl+K command palette &middot; Right-click game options "
762 "&middot; Ctrl+I import games",
763 this);
764 tipsLabel->setTextFormat(Qt::RichText);
765 QFont tipsFont = tipsLabel->font();
766 tipsFont.setPointSize(themeManager_->scaledFontSize(9));
767 tipsLabel->setFont(tipsFont);
768 tipsLabel->setStyleSheet(
769 QString("color: %1; padding: 10px 16px; background: %2; border-radius: 6px;")
770 .arg(c.textSecondary.name(), c.cardBackground.name()));
771 tipsLabel->setAlignment(Qt::AlignCenter);
772 tipsLabel->setWordWrap(true);
773 layout->addWidget(tipsLabel);
774
775 layout->addStretch(1);
776
777 setButtonText(QWizard::FinishButton, "Get Started");
778}
779
781{
782 // Save integrations page settings
783 auto* wizard = qobject_cast<FirstRunWizard*>(this->wizard());
784 if (wizard)
785 {
786 for (int i = 0; i < wizard->pageIds().size(); ++i)
787 {
788 auto* page = qobject_cast<IntegrationsPage*>(wizard->page(wizard->pageIds()[i]));
789 if (page)
790 {
791 page->saveSettings();
792 break;
793 }
794 }
795 }
796
797 // Run library detection and show results
798 runDetection();
799}
800
801void DonePage::runDetection()
802{
803 sourcesList_->clear();
804 int totalGames = 0;
805 int sourcesFound = 0;
806
807 const auto& c = themeManager_->colors();
808 auto addSourceItem = [&](const QString& name, bool found, int games = 0, bool showCount = true)
809 {
810 auto* item = new QListWidgetItem(sourcesList_);
811 auto* label = new QLabel(sourcesList_);
812 label->setTextFormat(Qt::RichText);
813
814 QString statusColor, statusText, iconHtml;
815 if (found)
816 {
817 iconHtml = QString("<span style='color:%1; font-weight:bold;'>&#10003;</span>")
818 .arg(c.success.name());
819 statusColor = c.success.name();
820 statusText =
821 (showCount && games > 0) ? QString("%1 game(s) found").arg(games) : "detected";
822 sourcesFound++;
823 totalGames += games;
824 }
825 else
826 {
827 iconHtml = QString("<span style='color:%1; font-weight:bold;'>&#10007;</span>")
828 .arg(c.error.name());
829 statusColor = c.textSecondary.name();
830 statusText = "not detected";
831 }
832
833 int fs14 = themeManager_->scaledFontSize(14);
834 int fs13 = themeManager_->scaledFontSize(13);
835 label->setText(QString("%1 <b style='color:%2; font-size:%6px;'>%3</b>"
836 " <span style='color:%4; font-size:%7px;'>&mdash; %5</span>")
837 .arg(iconHtml, c.textPrimary.name(), name, statusColor, statusText)
838 .arg(fs14)
839 .arg(fs13));
840
841 QFont labelFont = label->font();
842 labelFont.setPointSize(themeManager_->scaledFontSize(11));
843 label->setFont(labelFont);
844 label->setStyleSheet(QString("color: %1; padding: 8px 12px; background: transparent;")
845 .arg(c.textPrimary.name()));
846 label->setMinimumHeight(32);
847 item->setSizeHint(QSize(0, 36));
848 sourcesList_->setItemWidget(item, label);
849 };
850
851 // --- Steam ---
852 {
853 QStringList steamPaths = {
854 QDir::homePath() + "/.local/share/Steam",
855 QDir::homePath() + "/.steam/steam",
856 QDir::homePath() + "/.steam/root",
857 QDir::homePath() + "/.var/app/com.valvesoftware.Steam/.local/share/Steam",
858 };
859
860 bool found = false;
861 int games = 0;
862
863 for (const auto& path : steamPaths)
864 {
865 QDir dir(path);
866 if (!dir.exists())
867 continue;
868 found = true;
869
870 QDir steamApps(path + "/steamapps");
871 if (steamApps.exists())
872 {
873 games = static_cast<int>(
874 steamApps.entryList(QStringList() << "appmanifest_*.acf", QDir::Files).size());
875 }
876
877 QFile libFile(path + "/steamapps/libraryfolders.vdf");
878 if (libFile.open(QIODevice::ReadOnly | QIODevice::Text))
879 {
880 QString content = libFile.readAll();
881 libFile.close();
882 QRegularExpression pathRegex(QStringLiteral("\"path\"\\s+\"([^\"]+)\""));
883 auto iter = pathRegex.globalMatch(content);
884 while (iter.hasNext())
885 {
886 auto match = iter.next();
887 QString libPath = match.captured(1);
888 if (libPath != path)
889 {
890 QDir extra(libPath + "/steamapps");
891 if (extra.exists())
892 games += static_cast<int>(
893 extra.entryList(QStringList() << "appmanifest_*.acf", QDir::Files)
894 .size());
895 }
896 }
897 }
898 break;
899 }
900 addSourceItem("Steam", found, games);
901 }
902
903 // --- Lutris ---
904 {
905 bool found = false;
906 int games = 0;
907 QStringList paths = {
908 QDir::homePath() + "/.local/share/lutris",
909 QDir::homePath() + "/.config/lutris",
910 };
911 for (const auto& path : paths)
912 {
913 if (!QDir(path).exists())
914 continue;
915 found = true;
916 QDir gamesDir(path + "/games");
917 if (gamesDir.exists())
918 games = qMax(
919 games, static_cast<int>(
920 gamesDir.entryList(QStringList() << "*.yml" << "*.yaml", QDir::Files)
921 .size()));
922 break;
923 }
924 addSourceItem("Lutris", found, games);
925 }
926
927 // --- Heroic ---
928 {
929 bool found = QDir(QDir::homePath() + "/.config/heroic").exists();
930 addSourceItem("Heroic Games Launcher", found, 0, false);
931 }
932
933 // --- Bottles ---
934 {
935 bool found =
936 QDir(QDir::homePath() + "/.local/share/bottles").exists() ||
937 QDir(QDir::homePath() + "/.var/app/com.usebottles.bottles/data/bottles").exists();
938 addSourceItem("Bottles", found, 0, false);
939 }
940
941 // Build summary
942 QString theme = themeManager_->currentThemeId();
943 const auto* themeObj = themeManager_->getTheme(theme);
944 QString themeName = themeObj ? themeObj->displayName : theme;
945
946 if (sourcesFound > 0)
947 {
948 summaryLabel_->setText(QString("Found %1 source(s) with %2 game(s). Theme: <b>%3</b>.\n"
949 "Use Ctrl+I to import your games after setup.")
950 .arg(sourcesFound)
951 .arg(totalGames)
952 .arg(themeName));
953 }
954 else
955 {
956 summaryLabel_->setText(QString("No game sources detected. Theme: <b>%1</b>.\n"
957 "Add games manually or configure sources in Settings.")
958 .arg(themeName));
959 }
960}
void initializePage() override
DonePage(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
static bool hasBeenCompleted()
static void markCompleted()
FirstRunWizard(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
IntegrationsPage(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
LibraryDetectionPage(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void initializePage() override
static ThemeManager & instance()
QString currentThemeId() const
Get current theme ID.
void themeChanged()
Emitted when theme or accent color changes.
int scaledFontSize(int baseSize) const
Get scaled font size for given base size.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
ThemePage(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
WelcomePage(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)