10#include <QApplication>
42 catch (
const std::exception& e)
44 emit
searchError(QString(
"Search failed: %1").arg(e.what()));
55 catch (
const std::exception& e)
57 emit
searchError(QString(
"Failed to load installers: %1").arg(e.what()));
66 installerSlug.toStdString());
69 catch (
const std::exception& e)
72 QString(
"Failed to load script: %1").arg(e.what()));
82 : QDialog(parent), libraryController_(libraryController)
85 setWindowTitle(tr(
"Install from Lutris"));
89 workerThread_ =
new QThread(
this);
91 worker_->moveToThread(workerThread_);
94 &LutrisSearchDialog::onSearchComplete);
97 &LutrisSearchDialog::onInstallersLoaded);
99 &LutrisSearchDialog::onInstallerScriptLoaded);
101 &LutrisSearchDialog::onInstallerScriptError);
103 connect(workerThread_, &QThread::finished, worker_, &QObject::deleteLater);
105 workerThread_->start();
108 searchDebounce_ =
new QTimer(
this);
109 searchDebounce_->setSingleShot(
true);
110 searchDebounce_->setInterval(300);
111 connect(searchDebounce_, &QTimer::timeout,
this, &LutrisSearchDialog::onSearchTriggered);
118 workerThread_->quit();
119 workerThread_->wait();
123void LutrisSearchDialog::setupUI()
125 QVBoxLayout* mainLayout =
new QVBoxLayout(
this);
128 QHBoxLayout* searchLayout =
new QHBoxLayout();
130 searchEdit_ =
new QLineEdit(
this);
131 searchEdit_->setPlaceholderText(tr(
"Search for games..."));
132 searchEdit_->setClearButtonEnabled(
true);
133 connect(searchEdit_, &QLineEdit::textChanged,
this, &LutrisSearchDialog::onSearchTextChanged);
134 connect(searchEdit_, &QLineEdit::returnPressed,
this, &LutrisSearchDialog::onSearchTriggered);
135 searchLayout->addWidget(searchEdit_);
137 searchBtn_ =
new QPushButton(
"Search",
this);
138 connect(searchBtn_, &QPushButton::clicked,
this, &LutrisSearchDialog::onSearchTriggered);
139 searchLayout->addWidget(searchBtn_);
141 mainLayout->addLayout(searchLayout);
144 QHBoxLayout* statusLayout =
new QHBoxLayout();
145 statusLabel_ =
new QLabel(
"Enter a game name to search",
this);
146 statusLayout->addWidget(statusLabel_);
147 statusLayout->addStretch();
148 mainLayout->addLayout(statusLayout);
150 progressBar_ =
new QProgressBar(
this);
151 progressBar_->setRange(0, 0);
152 progressBar_->setVisible(
false);
153 mainLayout->addWidget(progressBar_);
156 QSplitter* splitter =
new QSplitter(Qt::Horizontal,
this);
159 QWidget* gamesWidget =
new QWidget(splitter);
160 QVBoxLayout* gamesLayout =
new QVBoxLayout(gamesWidget);
161 gamesLayout->setContentsMargins(0, 0, 0, 0);
163 QLabel* gamesLabel =
new QLabel(
"Games", gamesWidget);
164 gamesLabel->setStyleSheet(
"font-weight: bold;");
165 gamesLayout->addWidget(gamesLabel);
167 gameTree_ =
new QTreeWidget(gamesWidget);
168 gameTree_->setHeaderLabels({
"Name",
"Year",
"Installers"});
169 gameTree_->setRootIsDecorated(
false);
170 gameTree_->setSelectionMode(QAbstractItemView::SingleSelection);
171 gameTree_->header()->setStretchLastSection(
false);
172 gameTree_->header()->setSectionResizeMode(0, QHeaderView::Stretch);
173 gameTree_->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
174 gameTree_->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
175 connect(gameTree_, &QTreeWidget::itemSelectionChanged,
this,
176 &LutrisSearchDialog::onGameSelectionChanged);
177 gamesLayout->addWidget(gameTree_);
179 splitter->addWidget(gamesWidget);
182 QWidget* installersWidget =
new QWidget(splitter);
183 QVBoxLayout* installersLayout =
new QVBoxLayout(installersWidget);
184 installersLayout->setContentsMargins(0, 0, 0, 0);
186 installerLabel_ =
new QLabel(
"Installers", installersWidget);
187 installerLabel_->setStyleSheet(
"font-weight: bold;");
188 installersLayout->addWidget(installerLabel_);
190 installerTree_ =
new QTreeWidget(installersWidget);
191 installerTree_->setHeaderLabels({
"Installer",
"Runner",
"Version"});
192 installerTree_->setRootIsDecorated(
false);
193 installerTree_->setSelectionMode(QAbstractItemView::SingleSelection);
194 installerTree_->header()->setStretchLastSection(
false);
195 installerTree_->header()->setSectionResizeMode(0, QHeaderView::Stretch);
196 installerTree_->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
197 installerTree_->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
198 connect(installerTree_, &QTreeWidget::itemClicked,
this,
199 &LutrisSearchDialog::onInstallerSelected);
200 connect(installerTree_, &QTreeWidget::itemDoubleClicked,
this,
201 [
this](QTreeWidgetItem*,
int) { onInstallClicked(); });
202 installersLayout->addWidget(installerTree_);
204 splitter->addWidget(installersWidget);
207 splitter->setSizes({540, 360});
208 mainLayout->addWidget(splitter, 1);
211 QHBoxLayout* buttonLayout =
new QHBoxLayout();
212 buttonLayout->addStretch();
214 installBtn_ =
new QPushButton(
"Install...",
this);
215 installBtn_->setEnabled(
false);
216 connect(installBtn_, &QPushButton::clicked,
this, &LutrisSearchDialog::onInstallClicked);
217 buttonLayout->addWidget(installBtn_);
219 closeBtn_ =
new QPushButton(
"Close",
this);
220 connect(closeBtn_, &QPushButton::clicked,
this, &QDialog::reject);
221 buttonLayout->addWidget(closeBtn_);
223 mainLayout->addLayout(buttonLayout);
226void LutrisSearchDialog::onSearchTextChanged(
const QString& text)
230 searchDebounce_->start();
233void LutrisSearchDialog::onSearchTriggered()
235 QString query = searchEdit_->text().trimmed();
238 statusLabel_->setText(tr(
"Enter a game name to search"));
244 if (query.length() < 2)
246 statusLabel_->setText(tr(
"Please enter at least 2 characters"));
253void LutrisSearchDialog::startSearch(
const QString& query)
256 progressBar_->setVisible(
true);
257 statusLabel_->setText(tr(
"Searching..."));
261 worker_->setQuery(query);
262 QMetaObject::invokeMethod(worker_,
"doSearch", Qt::QueuedConnection);
265void LutrisSearchDialog::onSearchComplete(
const std::vector<LutrisSearchResult>& results)
268 progressBar_->setVisible(
false);
269 searchResults_ = results;
275 statusLabel_->setText(tr(
"No games found"));
279 for (
const auto& result : results)
281 QTreeWidgetItem* item =
new QTreeWidgetItem();
282 item->setText(0, QString::fromStdString(result.name));
283 item->setText(1, result.year > 0 ? QString::number(result.year) :
"-");
284 item->setText(2, QString::number(result.installerCount));
285 item->setData(0, Qt::UserRole, QString::fromStdString(result.slug));
287 gameTree_->addTopLevelItem(item);
290 statusLabel_->setText(QString(
"Found %1 game(s)").arg(results.size()));
293void LutrisSearchDialog::onSearchError(
const QString& error)
296 progressBar_->setVisible(
false);
297 statusLabel_->setText(error);
298 QMessageBox::warning(
this, tr(
"Search Error"), error);
301void LutrisSearchDialog::onGameSelectionChanged()
303 QList<QTreeWidgetItem*> selected = gameTree_->selectedItems();
304 if (selected.isEmpty())
310 QTreeWidgetItem* item = selected.first();
311 QString gameSlug = item->data(0, Qt::UserRole).toString();
313 if (gameSlug == selectedGameSlug_)
318 selectedGameSlug_ = gameSlug;
321 installerLabel_->setText(QString(
"Installers for %1 - Loading...").arg(item->text(0)));
322 progressBar_->setVisible(
true);
324 QMetaObject::invokeMethod(worker_,
"loadInstallers", Qt::QueuedConnection,
325 Q_ARG(QString, gameSlug));
328void LutrisSearchDialog::onInstallersLoaded(
const QString& gameSlug,
329 const std::vector<LutrisInstallerSummary>& installers)
331 progressBar_->setVisible(
false);
333 if (gameSlug != selectedGameSlug_)
338 currentInstallers_ = installers;
339 installerTree_->clear();
341 if (installers.empty())
343 installerLabel_->setText(tr(
"No installers available"));
349 for (
const auto& result : searchResults_)
351 if (result.slug == gameSlug.toStdString())
353 gameName = QString::fromStdString(result.name);
358 installerLabel_->setText(
359 QString(
"Installers for %1 (%2 available)").arg(gameName).arg(installers.size()));
361 for (
const auto& installer : installers)
363 QTreeWidgetItem* item =
new QTreeWidgetItem();
366 QString name = QString::fromStdString(installer.name);
369 name = QString::fromStdString(installer.slug);
371 item->setText(0, name);
374 QString runner = QString::fromStdString(installer.runner);
375 if (runner ==
"wine")
376 runner =
"Wine/Proton";
377 else if (runner ==
"linux")
378 runner =
"Native Linux";
379 else if (runner ==
"steam")
381 item->setText(1, runner);
384 item->setText(2, QString::fromStdString(installer.version));
386 item->setData(0, Qt::UserRole, QString::fromStdString(installer.slug));
389 if (!installer.description.empty())
391 item->setToolTip(0, QString::fromStdString(installer.description));
394 installerTree_->addTopLevelItem(item);
398 if (installerTree_->topLevelItemCount() > 0)
400 installerTree_->setCurrentItem(installerTree_->topLevelItem(0));
401 onInstallerSelected(installerTree_->topLevelItem(0), 0);
405void LutrisSearchDialog::onInstallerSelected(QTreeWidgetItem* item,
int column)
411 selectedInstallerSlug_.clear();
412 hasSelectedScript_ =
false;
413 updateInstallButton();
417 QString installerSlug = item->data(0, Qt::UserRole).toString();
419 if (installerSlug == selectedInstallerSlug_ && hasSelectedScript_)
424 selectedInstallerSlug_ = installerSlug;
425 hasSelectedScript_ =
false;
426 updateInstallButton();
429 progressBar_->setVisible(
true);
430 statusLabel_->setText(tr(
"Loading installer details..."));
432 QMetaObject::invokeMethod(worker_,
"loadInstallerScript", Qt::QueuedConnection,
433 Q_ARG(QString, selectedGameSlug_), Q_ARG(QString, installerSlug));
436void LutrisSearchDialog::onInstallerScriptLoaded(
const QString& installerSlug,
439 progressBar_->setVisible(
false);
441 if (installerSlug != selectedInstallerSlug_)
446 selectedScript_ = script;
447 hasSelectedScript_ =
true;
450 QString status = QString(
"Ready to install: %1 files, %2 steps")
451 .arg(script.
files.size())
452 .arg(script.
steps.size());
453 statusLabel_->setText(status);
455 updateInstallButton();
458void LutrisSearchDialog::onInstallerScriptError(
const QString& installerSlug,
const QString& error)
460 progressBar_->setVisible(
false);
462 if (installerSlug != selectedInstallerSlug_)
467 hasSelectedScript_ =
false;
468 statusLabel_->setText(error);
469 updateInstallButton();
472void LutrisSearchDialog::onInstallClicked()
474 if (!hasSelectedScript_)
476 QMessageBox::warning(
this, tr(
"No Installer Selected"),
477 tr(
"Please select an installer first."));
488void LutrisSearchDialog::clearInstallers()
490 installerTree_->clear();
491 currentInstallers_.clear();
492 selectedInstallerSlug_.clear();
493 hasSelectedScript_ =
false;
494 installerLabel_->setText(tr(
"Installers"));
495 updateInstallButton();
498void LutrisSearchDialog::updateInstallButton()
500 installBtn_->setEnabled(hasSelectedScript_);
502 if (hasSelectedScript_)
504 installBtn_->setText(
505 QString(
"Install %1...").arg(QString::fromStdString(selectedScript_.gameName)));
509 installBtn_->setText(tr(
"Install..."));
static std::vector< LutrisInstallerSummary > getInstallers(const std::string &gameSlug)
Get available installers for a game.
static std::vector< LutrisSearchResult > searchGames(const std::string &query, int maxResults=20)
Search for games by name.
static LutrisInstallerScript getInstallerScript(const std::string &gameSlug, const std::string &installerSlug)
Get full installer script with all details.
void installRequested(const LutrisInstallerScript &script)
LutrisSearchDialog(core::GameLibraryController *libraryController, QWidget *parent=nullptr)
~LutrisSearchDialog() override
void installerScriptLoaded(const QString &installerSlug, const LutrisInstallerScript &script)
void loadInstallers(const QString &gameSlug)
void searchError(const QString &error)
void installerScriptError(const QString &installerSlug, const QString &error)
void installersLoaded(const QString &gameSlug, const std::vector< LutrisInstallerSummary > &installers)
LutrisSearchWorker(QObject *parent=nullptr)
void searchComplete(const std::vector< LutrisSearchResult > &results)
void setQuery(const QString &query)
void loadInstallerScript(const QString &gameSlug, const QString &installerSlug)
std::vector< LutrisInstallerFile > files
std::vector< LutrisInstallStep > steps