11#include <QApplication>
67 : QDialog(parent), script_(script), config_(config), libraryController_(libraryController)
70 setWindowTitle(QString(
"Installing %1").arg(QString::fromStdString(script.
gameName)));
75 setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
88 workerThread_->quit();
89 workerThread_->wait();
93void LutrisInstallProgressDialog::setupUI()
95 QVBoxLayout* mainLayout =
new QVBoxLayout(
this);
98 gameLabel_ =
new QLabel(
this);
99 gameLabel_->setText(QString(
"<h3>Installing %1</h3>")
100 .arg(QString::fromStdString(script_.
gameName).toHtmlEscaped()));
101 mainLayout->addWidget(gameLabel_);
104 statusLabel_ =
new QLabel(
"Preparing installation...",
this);
105 statusLabel_->setStyleSheet(
"font-weight: bold;");
106 mainLayout->addWidget(statusLabel_);
109 currentOpLabel_ =
new QLabel(
this);
110 currentOpLabel_->setWordWrap(
true);
111 mainLayout->addWidget(currentOpLabel_);
114 QGroupBox* progressGroup =
new QGroupBox(
"Progress",
this);
115 QVBoxLayout* progressLayout =
new QVBoxLayout(progressGroup);
117 QLabel* overallLabel =
new QLabel(
"Overall Progress:", progressGroup);
118 progressLayout->addWidget(overallLabel);
120 overallProgress_ =
new QProgressBar(progressGroup);
121 overallProgress_->setRange(0, 100);
122 overallProgress_->setValue(0);
123 overallProgress_->setTextVisible(
true);
124 progressLayout->addWidget(overallProgress_);
126 stepInfoLabel_ =
new QLabel(
"Step 0 of 0", progressGroup);
127 progressLayout->addWidget(stepInfoLabel_);
129 QLabel* currentLabel =
new QLabel(
"Current Operation:", progressGroup);
130 progressLayout->addWidget(currentLabel);
132 currentProgress_ =
new QProgressBar(progressGroup);
133 currentProgress_->setRange(0, 100);
134 currentProgress_->setValue(0);
135 currentProgress_->setTextVisible(
true);
136 progressLayout->addWidget(currentProgress_);
138 downloadInfoLabel_ =
new QLabel(progressGroup);
139 progressLayout->addWidget(downloadInfoLabel_);
141 mainLayout->addWidget(progressGroup);
144 QGroupBox* logGroup =
new QGroupBox(
"Installation Log",
this);
145 QVBoxLayout* logLayout =
new QVBoxLayout(logGroup);
147 logText_ =
new QTextEdit(logGroup);
148 logText_->setReadOnly(
true);
149 logText_->setFontFamily(
"monospace");
150 logText_->setMaximumHeight(150);
151 logLayout->addWidget(logText_);
153 mainLayout->addWidget(logGroup);
156 QHBoxLayout* buttonLayout =
new QHBoxLayout();
157 buttonLayout->addStretch();
159 cancelBtn_ =
new QPushButton(
"Cancel",
this);
160 connect(cancelBtn_, &QPushButton::clicked,
this, &LutrisInstallProgressDialog::onCancelClicked);
161 buttonLayout->addWidget(cancelBtn_);
163 closeBtn_ =
new QPushButton(
"Close",
this);
164 closeBtn_->setEnabled(
false);
165 connect(closeBtn_, &QPushButton::clicked,
this, &LutrisInstallProgressDialog::onCloseClicked);
166 buttonLayout->addWidget(closeBtn_);
168 mainLayout->addLayout(buttonLayout);
171void LutrisInstallProgressDialog::startInstall()
177 workerThread_ =
new QThread(
this);
178 worker_ =
new LutrisInstallWorker();
179 worker_->setScript(script_);
180 worker_->setConfig(config_);
181 worker_->moveToThread(workerThread_);
187 &LutrisInstallProgressDialog::onProgressUpdate, Qt::QueuedConnection);
189 &LutrisInstallProgressDialog::onLogMessage, Qt::QueuedConnection);
191 &LutrisInstallProgressDialog::onInstallComplete, Qt::QueuedConnection);
193 connect(workerThread_, &QThread::finished, worker_, &QObject::deleteLater);
195 workerThread_->start();
198void LutrisInstallProgressDialog::onProgressUpdate(
const InstallProgress& progress)
202 switch (progress.
state)
208 stateText =
"Preparing...";
211 stateText =
"Downloading files...";
214 stateText =
"Extracting archives...";
217 stateText =
"Installing...";
220 stateText =
"Configuring Wine...";
223 stateText =
"Finalizing...";
226 stateText =
"Complete!";
229 stateText =
"Failed";
232 stateText =
"Cancelled";
235 statusLabel_->setText(stateText);
238 currentOpLabel_->setText(QString::fromStdString(progress.
currentOperation));
244 stepInfoLabel_->setText(
251 currentProgress_->setValue(percent);
253 QString info = QString(
"%1 / %2")
265 int eta =
static_cast<int>(
static_cast<double>(remaining) /
267 info += QString(
" - ETA: %1").arg(formatEta(eta));
270 downloadInfoLabel_->setText(info);
275 downloadInfoLabel_->clear();
279void LutrisInstallProgressDialog::onLogMessage(
const QString& message)
281 logText_->append(message);
284 QTextCursor cursor = logText_->textCursor();
285 cursor.movePosition(QTextCursor::End);
286 logText_->setTextCursor(cursor);
289void LutrisInstallProgressDialog::onInstallComplete(
const InstallResult& result)
295 cancelBtn_->setEnabled(
false);
296 closeBtn_->setEnabled(
true);
299 setWindowFlags(windowFlags() | Qt::WindowCloseButtonHint);
304 statusLabel_->setText(tr(
"Installation Complete!"));
305 statusLabel_->setStyleSheet(
"font-weight: bold; color: green;");
306 overallProgress_->setValue(100);
307 currentProgress_->setValue(100);
309 onLogMessage(
"Installation completed successfully!");
312 if (libraryController_)
317 game.
name = script_.gameName;
321 if (script_.runner ==
"wine")
323 else if (script_.runner ==
"linux")
325 else if (script_.runner ==
"steam")
350 libraryController_->addGame(game);
351 onLogMessage(
"Game added to library!");
353 catch (
const std::exception& e)
355 onLogMessage(QString(
"Warning: Failed to add game to library: %1").arg(e.what()));
359 QMessageBox::information(
this, tr(
"Installation Complete"),
360 QString(
"%1 has been installed successfully!")
361 .arg(QString::fromStdString(script_.gameName)));
365 statusLabel_->setText(tr(
"Installation Failed"));
366 statusLabel_->setStyleSheet(
"font-weight: bold; color: red;");
369 QString(
"Installation failed: %1").arg(QString::fromStdString(result.
errorMessage)));
371 QMessageBox::critical(
this, tr(
"Installation Failed"),
372 QString(
"Failed to install %1:\n\n%2")
373 .arg(QString::fromStdString(script_.gameName))
378void LutrisInstallProgressDialog::onCancelClicked()
386 int result = QMessageBox::question(
this, tr(
"Cancel Installation"),
387 tr(
"Are you sure you want to cancel the installation?\n\n"
388 "Any downloaded files will be kept for later use."),
389 QMessageBox::Yes | QMessageBox::No);
391 if (result == QMessageBox::Yes)
394 statusLabel_->setText(tr(
"Cancelling..."));
395 cancelBtn_->setEnabled(
false);
404void LutrisInstallProgressDialog::onCloseClicked()
429QString LutrisInstallProgressDialog::formatSpeed(
double bytesPerSec)
const
431 if (bytesPerSec < 1024)
433 return QString(
"%1 B").arg(
static_cast<int>(bytesPerSec));
435 else if (bytesPerSec < 1024 * 1024)
437 return QString(
"%1 KB").arg(bytesPerSec / 1024, 0,
'f', 1);
441 return QString(
"%1 MB").arg(bytesPerSec / (1024 * 1024), 0,
'f', 1);
445QString LutrisInstallProgressDialog::formatEta(
int seconds)
const
449 return QString(
"%1s").arg(seconds);
451 else if (seconds < 3600)
453 int min = seconds / 60;
454 int sec = seconds % 60;
455 return QString(
"%1m %2s").arg(min).arg(sec);
459 int hours = seconds / 3600;
460 int min = (seconds % 3600) / 60;
461 return QString(
"%1h %2m").arg(hours).arg(min);
465QString LutrisInstallProgressDialog::formatSize(uint64_t bytes)
const
470 const char* units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
472 double size =
static_cast<double>(bytes);
474 while (size >= 1024.0 && unitIndex < 4)
482 return QString(
"%1 B").arg(
static_cast<int>(size));
486 return QString(
"%1 %2").arg(size, 0,
'f', 1).arg(units[unitIndex]);
std::string name
Display name shown in UI.
void syncPlatformFromRunner()
Sync the deprecated platform field from the current runner and source.
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.).
static void cancel()
Cancel current installation.
static InstallResult install(const LutrisInstallerScript &script, const InstallConfig &config, const ProgressCallback &progressCallback=nullptr)
Execute an installation (blocking).
LutrisInstallProgressDialog(const LutrisInstallerScript &script, const InstallConfig &config, core::GameLibraryController *libraryController, QWidget *parent=nullptr)
~LutrisInstallProgressDialog() override
void closeEvent(QCloseEvent *event) override
void installComplete(const InstallResult &result)
void logMessage(const QString &message)
void progressUpdate(const InstallProgress &progress)
void setConfig(const InstallConfig &config)
LutrisInstallWorker(QObject *parent=nullptr)
void setScript(const LutrisInstallerScript &script)
@ Lutris
Lutris community scripts.
@ Native
Native Linux executable (no compatibility layer).
@ Wine
Wine compatibility layer.
std::string executablePath
Full path to game executable.
std::string workingDirectory
Working directory for game execution.
std::string arguments
Command line arguments to pass to game.
std::string winePrefix
WINEPREFIX path (Wine install location).
std::map< std::string, std::string > environmentVariables
Environment variables to set before launching (KEY=VALUE pairs).
double downloadSpeedBytesPerSec
std::string currentOperation
std::string winePrefixPath
std::map< std::string, std::string > environmentVariables
std::string executablePath
@ Game
Game-specific fixes.