11#include <QDialogButtonBox>
28 QString borderColor = highlight ? c.
accent.name() : c.
border.name();
31 group->setStyleSheet(QString(
"QGroupBox {"
33 " border: 1px solid %1;"
34 " border-radius: 6px;"
40 " subcontrol-origin: margin;"
45 "QCheckBox { color: %3; spacing: 8px; }"
46 "QRadioButton { color: %3; spacing: 8px; }"
47 "QLabel { color: %3; }")
48 .arg(borderColor, titleColor, c.
textPrimary.name()));
52 : QDialog(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
56 setWindowTitle(
"Add Game");
62void AddGameDialog::setupUI()
64 QVBoxLayout* mainLayout =
new QVBoxLayout(
this);
65 mainLayout->setSpacing(12);
68 tabWidget_ =
new QTabWidget(
this);
70 QWidget* basicTab =
new QWidget();
71 QWidget* runnerTab =
new QWidget();
72 QWidget* advancedTab =
new QWidget();
74 setupBasicTab(basicTab);
75 setupRunnerTab(runnerTab);
76 setupAdvancedTab(advancedTab);
78 tabWidget_->addTab(basicTab,
"Basic");
79 tabWidget_->addTab(runnerTab,
"Runner");
80 tabWidget_->addTab(advancedTab,
"Advanced");
82 mainLayout->addWidget(tabWidget_);
85 QDialogButtonBox* buttonBox =
new QDialogButtonBox(
this);
87 autoDetectButton_ =
new QPushButton(
"Auto-Detect");
88 buttonBox->addButton(autoDetectButton_, QDialogButtonBox::ActionRole);
90 okButton_ = buttonBox->addButton(QDialogButtonBox::Ok);
91 cancelButton_ = buttonBox->addButton(QDialogButtonBox::Cancel);
93 connect(autoDetectButton_, &QPushButton::clicked,
this, &AddGameDialog::onAutoDetect);
94 connect(okButton_, &QPushButton::clicked,
this, &AddGameDialog::onAccept);
95 connect(cancelButton_, &QPushButton::clicked,
this, &QDialog::reject);
97 mainLayout->addWidget(buttonBox);
100void AddGameDialog::setupBasicTab(QWidget* tab)
102 QFormLayout* layout =
new QFormLayout(tab);
103 layout->setSpacing(10);
106 nameEdit_ =
new QLineEdit();
107 nameEdit_->setPlaceholderText(
"Game name");
108 layout->addRow(
"Name:", nameEdit_);
111 QHBoxLayout* exeLayout =
new QHBoxLayout();
112 executableEdit_ =
new QLineEdit();
113 executableEdit_->setPlaceholderText(
"/path/to/game.exe or game");
114 QPushButton* browseExeBtn =
new QPushButton(
"Browse...");
115 connect(browseExeBtn, &QPushButton::clicked,
this, &AddGameDialog::onBrowseExecutable);
116 connect(executableEdit_, &QLineEdit::textChanged,
this, &AddGameDialog::onExecutableChanged);
117 exeLayout->addWidget(executableEdit_);
118 exeLayout->addWidget(browseExeBtn);
119 layout->addRow(
"Executable:", exeLayout);
122 QHBoxLayout* workDirLayout =
new QHBoxLayout();
123 workingDirEdit_ =
new QLineEdit();
124 workingDirEdit_->setPlaceholderText(
"Leave empty for executable's directory");
125 QPushButton* browseWorkDirBtn =
new QPushButton(
"Browse...");
126 connect(browseWorkDirBtn, &QPushButton::clicked,
this, &AddGameDialog::onBrowseWorkingDir);
127 workDirLayout->addWidget(workingDirEdit_);
128 workDirLayout->addWidget(browseWorkDirBtn);
129 layout->addRow(
"Working Dir:", workDirLayout);
132 argumentsEdit_ =
new QLineEdit();
133 argumentsEdit_->setPlaceholderText(
"-fullscreen -nolog");
134 layout->addRow(
"Arguments:", argumentsEdit_);
137 sourceCombo_ =
new QComboBox();
143 layout->addRow(
"Source:", sourceCombo_);
146 runnerCombo_ =
new QComboBox();
152 connect(runnerCombo_, QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
153 &AddGameDialog::onRunnerChanged);
154 layout->addRow(
"Runner:", runnerCombo_);
157void AddGameDialog::setupRunnerTab(QWidget* tab)
159 QFormLayout* layout =
new QFormLayout(tab);
160 layout->setSpacing(10);
163 QHBoxLayout* prefixLayout =
new QHBoxLayout();
164 winePrefixEdit_ =
new QLineEdit();
165 winePrefixEdit_->setPlaceholderText(
"~/.wine or custom prefix path");
166 QPushButton* browsePrefixBtn =
new QPushButton(
"Browse...");
167 connect(browsePrefixBtn, &QPushButton::clicked,
this, &AddGameDialog::onBrowseWinePrefix);
168 prefixLayout->addWidget(winePrefixEdit_);
169 prefixLayout->addWidget(browsePrefixBtn);
170 layout->addRow(
"Wine Prefix:", prefixLayout);
173 protonVersionCombo_ =
new QComboBox();
174 protonVersionCombo_->setEditable(
true);
175 protonVersionCombo_->addItem(
"(Auto-detect)");
176 protonVersionCombo_->addItem(
"proton-cachyos-slr");
177 protonVersionCombo_->addItem(
"GE-Proton");
178 protonVersionCombo_->addItem(
"Proton Experimental");
179 protonVersionCombo_->addItem(
"Proton 9.0");
180 protonVersionCombo_->addItem(
"Proton 8.0");
181 layout->addRow(
"Proton Version:", protonVersionCombo_);
184 vdGroup_ =
new QGroupBox(
"Virtual Desktop");
185 QVBoxLayout* vdLayout =
new QVBoxLayout(vdGroup_);
187 virtualDesktopCheck_ =
new QCheckBox(
"Enable virtual desktop");
188 vdLayout->addWidget(virtualDesktopCheck_);
190 QHBoxLayout* resLayout =
new QHBoxLayout();
191 resLayout->addWidget(
new QLabel(
"Resolution:"));
192 desktopWidthSpin_ =
new QSpinBox();
193 desktopWidthSpin_->setRange(640, 7680);
194 desktopWidthSpin_->setValue(1920);
195 resLayout->addWidget(desktopWidthSpin_);
196 resLayout->addWidget(
new QLabel(
"x"));
197 desktopHeightSpin_ =
new QSpinBox();
198 desktopHeightSpin_->setRange(480, 4320);
199 desktopHeightSpin_->setValue(1080);
200 resLayout->addWidget(desktopHeightSpin_);
201 resLayout->addStretch();
202 vdLayout->addLayout(resLayout);
204 layout->addRow(vdGroup_);
207 onRunnerChanged(runnerCombo_->currentIndex());
210void AddGameDialog::setupAdvancedTab(QWidget* tab)
212 QFormLayout* layout =
new QFormLayout(tab);
213 layout->setSpacing(10);
216 QHBoxLayout* coverLayout =
new QHBoxLayout();
217 coverArtEdit_ =
new QLineEdit();
218 coverArtEdit_->setPlaceholderText(
"Path to cover art image");
219 QPushButton* browseCoverBtn =
new QPushButton(
"Browse...");
220 connect(browseCoverBtn, &QPushButton::clicked,
this, &AddGameDialog::onBrowseCoverArt);
221 coverLayout->addWidget(coverArtEdit_);
222 coverLayout->addWidget(browseCoverBtn);
223 layout->addRow(
"Cover Art:", coverLayout);
226 descriptionEdit_ =
new QLineEdit();
227 descriptionEdit_->setPlaceholderText(
"Game description (optional)");
228 layout->addRow(
"Description:", descriptionEdit_);
231void AddGameDialog::onBrowseExecutable()
233 QString filter =
"All Files (*);;Executables (*.exe *.sh *.AppImage)";
235 QFileDialog::getOpenFileName(
this,
"Select Game Executable", QDir::homePath(), filter);
238 executableEdit_->setText(path);
242void AddGameDialog::onBrowseWorkingDir()
245 QFileDialog::getExistingDirectory(
this,
"Select Working Directory", QDir::homePath());
248 workingDirEdit_->setText(path);
252void AddGameDialog::onBrowseWinePrefix()
254 QString path = QFileDialog::getExistingDirectory(
this,
"Select Wine Prefix", QDir::homePath());
257 winePrefixEdit_->setText(path);
261void AddGameDialog::onBrowseCoverArt()
263 QString filter =
"Images (*.png *.jpg *.jpeg *.webp);;All Files (*)";
264 QString path = QFileDialog::getOpenFileName(
this,
"Select Cover Art", QDir::homePath(), filter);
267 coverArtEdit_->setText(path);
271void AddGameDialog::onExecutableChanged(
const QString& path)
277 if (nameEdit_->text().isEmpty())
279 QFileInfo info(path);
280 QString name = info.completeBaseName();
282 name.remove(QRegularExpression(
"[-_](x64|x86|win64|win32|launcher)$",
283 QRegularExpression::CaseInsensitiveOption));
284 nameEdit_->setText(name);
288 if (path.endsWith(
".exe", Qt::CaseInsensitive))
292 if (protonIndex >= 0)
294 runnerCombo_->setCurrentIndex(protonIndex);
299void AddGameDialog::onRunnerChanged(
int index)
304 winePrefixEdit_->setEnabled(isWineProton);
306 virtualDesktopCheck_->setEnabled(isWineProton);
307 desktopWidthSpin_->setEnabled(isWineProton && virtualDesktopCheck_->isChecked());
308 desktopHeightSpin_->setEnabled(isWineProton && virtualDesktopCheck_->isChecked());
311void AddGameDialog::onAutoDetect()
313 QString path = executableEdit_->text();
316 QMessageBox::information(
this,
"Auto-Detect",
"Please select an executable first.");
320 autoDetectFromPath(path);
323void AddGameDialog::autoDetectFromPath(
const QString& path)
325 QFileInfo info(path);
328 QString dir = info.absolutePath();
333 for (
int i = 0; i < 10; ++i)
335 if (QDir(current.filePath(
"drive_c")).exists())
337 prefix = current.absolutePath();
344 if (!prefix.isEmpty())
346 winePrefixEdit_->setText(prefix);
350 if (workingDirEdit_->text().isEmpty())
352 workingDirEdit_->setText(info.absolutePath());
356void AddGameDialog::onAccept()
359 if (nameEdit_->text().trimmed().isEmpty())
361 QMessageBox::warning(
this,
"Validation Error",
"Please enter a game name.");
362 nameEdit_->setFocus();
366 if (executableEdit_->text().trimmed().isEmpty())
368 QMessageBox::warning(
this,
"Validation Error",
"Please select an executable.");
369 executableEdit_->setFocus();
386 setWindowTitle(editing ?
"Edit Game" :
"Add Game");
387 autoDetectButton_->setVisible(!editing);
395void AddGameDialog::updateUIFromGame()
397 nameEdit_->setText(QString::fromStdString(game_.
name));
403 int sourceIndex = sourceCombo_->findData(
static_cast<int>(game_.
source));
404 if (sourceIndex >= 0)
405 sourceCombo_->setCurrentIndex(sourceIndex);
408 int runnerIndex = runnerCombo_->findData(
static_cast<int>(game_.
runner));
409 if (runnerIndex >= 0)
410 runnerCombo_->setCurrentIndex(runnerIndex);
426void AddGameDialog::updateGameFromUI()
428 game_.name = nameEdit_->text().trimmed().toStdString();
429 game_.runnerConfig.executablePath = executableEdit_->text().trimmed().toStdString();
430 game_.runnerConfig.workingDirectory = workingDirEdit_->text().trimmed().toStdString();
431 game_.runnerConfig.arguments = argumentsEdit_->text().trimmed().toStdString();
433 game_.source =
static_cast<GameSource>(sourceCombo_->currentData().toInt());
434 game_.runner =
static_cast<GameRunner>(runnerCombo_->currentData().toInt());
437 game_.runnerConfig.winePrefix = winePrefixEdit_->text().trimmed().toStdString();
438 QString protonVersion = protonVersionCombo_->currentText().trimmed();
439 if (protonVersion !=
"(Auto-detect)")
441 game_.runnerConfig.protonVersion = protonVersion.toStdString();
444 game_.runnerConfig.useVirtualDesktop = virtualDesktopCheck_->isChecked();
445 game_.runnerConfig.virtualDesktopWidth = desktopWidthSpin_->value();
446 game_.runnerConfig.virtualDesktopHeight = desktopHeightSpin_->value();
449 game_.metadata.coverArtPath = coverArtEdit_->text().trimmed().toStdString();
450 game_.metadata.description = descriptionEdit_->text().trimmed().toStdString();
453 QFileInfo exeInfo(QString::fromStdString(game_.runnerConfig.executablePath));
457 if (game_.id.empty())
459 game_.id = std::to_string(std::time(
nullptr)) +
"_" +
460 std::to_string(std::hash<std::string>{}(game_.name));
464 if (game_.statistics.dateAdded == 0)
466 game_.statistics.dateAdded = std::time(
nullptr);
474void AddGameDialog::applyTheme()
476 const auto& c = themeManager_->colors();
481 tabWidget_->setStyleSheet(QString(
"QTabWidget::pane {"
482 " border: 1px solid %1;"
486 .arg(c.borderLight.name(), c.panelBackground.name()));
498 okButton_->setStyleSheet(
499 QString(
"QPushButton {"
500 " background-color: %1;"
503 " border-radius: 4px;"
504 " padding: 6px 16px;"
505 " font-weight: bold;"
507 "QPushButton:hover { background-color: %3; }")
508 .arg(c.accent.name(), c.textOnAccent.name(), c.accentHover.name()));
512 if (autoDetectButton_)
514 autoDetectButton_->setStyleSheet(QString(
"QPushButton {"
515 " background-color: transparent;"
517 " border: 1px solid %1;"
518 " border-radius: 4px;"
519 " padding: 6px 16px;"
521 "QPushButton:hover { background-color: %2; }")
522 .arg(c.accent.name(), c.hoverBackground.name()));
Complete representation of a game in the library.
GameMetadata metadata
Descriptive information and media.
std::string name
Display name shown in UI.
GameRunner runner
Runner/compatibility layer to use (Native, Proton, Wine, etc.).
GameRunnerConfig runnerConfig
How to launch and run the game.
GameSource source
Where the game was acquired from (Steam, GOG, Local, etc.).
void themeChanged()
Emitted when theme or accent color changes.
GameSource
Where the game was acquired from (store/service/local).
@ Steam
Steam store/platform.
@ Local
Manually added game (not from a store).
@ Lutris
Lutris community scripts.
@ GOG
GOG.com (DRM-free games).
@ NotInstalled
Game is in library but not installed.
@ Installed
Game is installed and ready to play.
GameRunner
Runner/compatibility layer for executing the game.
@ Proton
Proton (Steam's Wine fork).
@ Native
Native Linux executable (no compatibility layer).
@ Wine
Wine compatibility layer.
std::string executablePath
Full path to game executable.
int virtualDesktopWidth
Virtual desktop width in pixels.
std::string workingDirectory
Working directory for game execution.
bool useVirtualDesktop
Launch game in Wine virtual desktop.
std::string arguments
Command line arguments to pass to game.
std::string winePrefix
WINEPREFIX path (Wine install location).
int virtualDesktopHeight
Virtual desktop height in pixels.
std::string protonVersion
Proton version (e.g., "proton-cachyos-slr").