game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
lutrisinstallpreviewdialog.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/lutrisinstallpreviewdialog.cpp
4// ==============================================================================
5// Lutris install preview dialog implementation
6// ==============================================================================
7
9#include "theme_manager.h"
10
11#include <QDir>
12#include <QFileDialog>
13#include <QFormLayout>
14#include <QGroupBox>
15#include <QHBoxLayout>
16#include <QHeaderView>
17#include <QMessageBox>
18#include <QStandardPaths>
19#include <QStorageInfo>
20#include <QTabWidget>
21#include <QVBoxLayout>
22
24 QWidget* parent, ThemeManager* themeManager)
25 : QDialog(parent), script_(script),
26 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
27{
28 setupUI();
29 setWindowTitle(QString("Install %1").arg(QString::fromStdString(script.gameName)));
30 resize(700, 600);
31
32 populateScriptDetails();
33 onValidateConfig();
34}
35
36void LutrisInstallPreviewDialog::setupUI()
37{
38 QVBoxLayout* mainLayout = new QVBoxLayout(this);
39
40 // Game info header
41 QLabel* headerLabel = new QLabel(this);
42 headerLabel->setText(QString("<h2>%1</h2><p>Installer: %2 (%3)</p>")
43 .arg(QString::fromStdString(script_.gameName).toHtmlEscaped())
44 .arg(QString::fromStdString(script_.installerSlug).toHtmlEscaped())
45 .arg(QString::fromStdString(script_.runner).toHtmlEscaped()));
46 mainLayout->addWidget(headerLabel);
47
48 // Tab widget for different sections
49 QTabWidget* tabs = new QTabWidget(this);
50
51 // =========================================================================
52 // Configuration Tab
53 // =========================================================================
54 QWidget* configTab = new QWidget();
55 QVBoxLayout* configLayout = new QVBoxLayout(configTab);
56
57 // Install location
58 QGroupBox* locationGroup = new QGroupBox("Install Location", configTab);
59 QVBoxLayout* locationLayout = new QVBoxLayout(locationGroup);
60
61 QHBoxLayout* installDirLayout = new QHBoxLayout();
62 installDirEdit_ = new QLineEdit(locationGroup);
63
64 // Default install directory
65 QString defaultDir =
66 QDir::homePath() + "/Games/" +
67 QString::fromStdString(script_.gameName).replace(QRegularExpression("[^a-zA-Z0-9_-]"), "_");
68 installDirEdit_->setText(defaultDir);
69 installDirLayout->addWidget(installDirEdit_);
70
71 installDirBrowseBtn_ = new QPushButton("Browse...", locationGroup);
72 connect(installDirBrowseBtn_, &QPushButton::clicked, this,
73 &LutrisInstallPreviewDialog::onBrowseInstallDir);
74 installDirLayout->addWidget(installDirBrowseBtn_);
75 locationLayout->addLayout(installDirLayout);
76
77 diskSpaceLabel_ = new QLabel(locationGroup);
78 locationLayout->addWidget(diskSpaceLabel_);
79
80 configLayout->addWidget(locationGroup);
81
82 // Wine configuration (only for Wine runner)
83 wineGroup_ = new QGroupBox("Wine Configuration", configTab);
84 QFormLayout* wineLayout = new QFormLayout(wineGroup_);
85
86 // Wine prefix
87 QHBoxLayout* prefixLayout = new QHBoxLayout();
88 winePrefixEdit_ = new QLineEdit(wineGroup_);
89 QString defaultPrefix =
90 QDir::homePath() + "/.wine-" +
91 QString::fromStdString(script_.gameSlug).replace(QRegularExpression("[^a-zA-Z0-9_-]"), "_");
92 winePrefixEdit_->setText(defaultPrefix);
93 prefixLayout->addWidget(winePrefixEdit_);
94
95 winePrefixBrowseBtn_ = new QPushButton("Browse...", wineGroup_);
96 connect(winePrefixBrowseBtn_, &QPushButton::clicked, this,
97 &LutrisInstallPreviewDialog::onBrowseWinePrefix);
98 prefixLayout->addWidget(winePrefixBrowseBtn_);
99 wineLayout->addRow("Wine Prefix:", prefixLayout);
100
101 // Wine version
102 wineVersionCombo_ = new QComboBox(wineGroup_);
103 wineVersionCombo_->addItem("System Wine", "system");
104 wineVersionCombo_->addItem("Proton (Steam)", "proton");
105 wineVersionCombo_->addItem("Wine-GE", "wine-ge");
106 wineVersionCombo_->addItem("Proton-GE", "proton-ge");
107 wineLayout->addRow("Wine Version:", wineVersionCombo_);
108
109 // Wine options
110 QHBoxLayout* wineOptionsLayout = new QHBoxLayout();
111
112 dxvkCheck_ = new QCheckBox("DXVK", wineGroup_);
113 dxvkCheck_->setChecked(true);
114 dxvkCheck_->setToolTip("Vulkan-based DirectX 9/10/11 translation layer");
115 wineOptionsLayout->addWidget(dxvkCheck_);
116
117 vkd3dCheck_ = new QCheckBox("VKD3D", wineGroup_);
118 vkd3dCheck_->setChecked(true);
119 vkd3dCheck_->setToolTip("Vulkan-based DirectX 12 translation layer");
120 wineOptionsLayout->addWidget(vkd3dCheck_);
121
122 esyncCheck_ = new QCheckBox("Esync", wineGroup_);
123 esyncCheck_->setChecked(true);
124 esyncCheck_->setToolTip("Eventfd-based synchronization (improves performance)");
125 wineOptionsLayout->addWidget(esyncCheck_);
126
127 fsyncCheck_ = new QCheckBox("Fsync", wineGroup_);
128 fsyncCheck_->setChecked(true);
129 fsyncCheck_->setToolTip("Futex-based synchronization (requires kernel support)");
130 wineOptionsLayout->addWidget(fsyncCheck_);
131
132 wineOptionsLayout->addStretch();
133 wineLayout->addRow("Options:", wineOptionsLayout);
134
135 configLayout->addWidget(wineGroup_);
136
137 // Hide Wine config for non-Wine runners
138 wineGroup_->setVisible(script_.runner == "wine");
139
140 configLayout->addStretch();
141 tabs->addTab(configTab, "Configuration");
142
143 // =========================================================================
144 // Files Tab
145 // =========================================================================
146 QWidget* filesTab = new QWidget();
147 QVBoxLayout* filesLayout = new QVBoxLayout(filesTab);
148
149 QLabel* filesInfoLabel = new QLabel("The following files will be downloaded:", filesTab);
150 filesLayout->addWidget(filesInfoLabel);
151
152 filesTree_ = new QTreeWidget(filesTab);
153 filesTree_->setHeaderLabels({"File", "URL", "Size"});
154 filesTree_->setRootIsDecorated(false);
155 filesTree_->header()->setStretchLastSection(false);
156 filesTree_->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
157 filesTree_->header()->setSectionResizeMode(1, QHeaderView::Stretch);
158 filesTree_->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
159 filesLayout->addWidget(filesTree_);
160
161 totalDownloadLabel_ = new QLabel(filesTab);
162 filesLayout->addWidget(totalDownloadLabel_);
163
164 tabs->addTab(filesTab, "Files to Download");
165
166 // =========================================================================
167 // Steps Tab
168 // =========================================================================
169 QWidget* stepsTab = new QWidget();
170 QVBoxLayout* stepsLayout = new QVBoxLayout(stepsTab);
171
172 QLabel* stepsInfoLabel = new QLabel("Installation steps that will be executed:", stepsTab);
173 stepsLayout->addWidget(stepsInfoLabel);
174
175 stepsTree_ = new QTreeWidget(stepsTab);
176 stepsTree_->setHeaderLabels({"#", "Action", "Details"});
177 stepsTree_->setRootIsDecorated(false);
178 stepsTree_->header()->setStretchLastSection(false);
179 stepsTree_->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
180 stepsTree_->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
181 stepsTree_->header()->setSectionResizeMode(2, QHeaderView::Stretch);
182 stepsLayout->addWidget(stepsTree_);
183
184 tabs->addTab(stepsTab, "Installation Steps");
185
186 // =========================================================================
187 // Details Tab
188 // =========================================================================
189 QWidget* detailsTab = new QWidget();
190 QVBoxLayout* detailsLayout = new QVBoxLayout(detailsTab);
191
192 QLabel* detailsInfoLabel = new QLabel("Raw installer script details:", detailsTab);
193 detailsLayout->addWidget(detailsInfoLabel);
194
195 scriptDetailsText_ = new QTextEdit(detailsTab);
196 scriptDetailsText_->setReadOnly(true);
197 scriptDetailsText_->setFontFamily("monospace");
198 detailsLayout->addWidget(scriptDetailsText_);
199
200 tabs->addTab(detailsTab, "Script Details");
201
202 mainLayout->addWidget(tabs, 1);
203
204 // =========================================================================
205 // Dialog buttons
206 // =========================================================================
207 QHBoxLayout* buttonLayout = new QHBoxLayout();
208 buttonLayout->addStretch();
209
210 installBtn_ = new QPushButton("Install", this);
211 installBtn_->setDefault(true);
212 connect(installBtn_, &QPushButton::clicked, this,
213 &LutrisInstallPreviewDialog::onInstallClicked);
214 buttonLayout->addWidget(installBtn_);
215
216 cancelBtn_ = new QPushButton("Cancel", this);
217 connect(cancelBtn_, &QPushButton::clicked, this, &QDialog::reject);
218 buttonLayout->addWidget(cancelBtn_);
219
220 mainLayout->addLayout(buttonLayout);
221
222 // Connect for validation
223 connect(installDirEdit_, &QLineEdit::textChanged, this,
224 &LutrisInstallPreviewDialog::onValidateConfig);
225 connect(winePrefixEdit_, &QLineEdit::textChanged, this,
226 &LutrisInstallPreviewDialog::onValidateConfig);
227}
228
229void LutrisInstallPreviewDialog::populateScriptDetails()
230{
231 // Populate files tree
232 filesTree_->clear();
233 uint64_t totalSize = 0;
234
235 for (const auto& file : script_.files)
236 {
237 QTreeWidgetItem* item = new QTreeWidgetItem();
238 item->setText(0, QString::fromStdString(file.filename.empty() ? file.id : file.filename));
239 item->setText(1, QString::fromStdString(file.url));
240 item->setText(2, file.size > 0 ? formatSize(file.size) : "Unknown");
241 item->setToolTip(1, QString::fromStdString(file.url));
242 filesTree_->addTopLevelItem(item);
243 totalSize += file.size;
244 }
245
246 if (script_.files.empty())
247 {
248 QTreeWidgetItem* item = new QTreeWidgetItem();
249 item->setText(0, "(No files to download)");
250 item->setForeground(0, themeManager_->colors().textSecondary);
251 filesTree_->addTopLevelItem(item);
252 totalDownloadLabel_->setText("No files to download");
253 }
254 else
255 {
256 totalDownloadLabel_->setText(QString("Total download size: %1 (%2 file(s))")
257 .arg(totalSize > 0 ? formatSize(totalSize) : "Unknown")
258 .arg(script_.files.size()));
259 }
260
261 // Populate steps tree
262 stepsTree_->clear();
263 int stepNum = 1;
264 for (const auto& step : script_.steps)
265 {
266 QTreeWidgetItem* item = new QTreeWidgetItem();
267 item->setText(0, QString::number(stepNum++));
268 item->setText(1, QString::fromStdString(step.task));
269 item->setText(2, QString::fromStdString(step.description));
270 item->setToolTip(2, QString::fromStdString(step.description));
271 stepsTree_->addTopLevelItem(item);
272 }
273
274 if (script_.steps.empty())
275 {
276 QTreeWidgetItem* item = new QTreeWidgetItem();
277 item->setText(0, "-");
278 item->setText(1, "(No steps)");
279 item->setForeground(1, themeManager_->colors().textSecondary);
280 stepsTree_->addTopLevelItem(item);
281 }
282
283 // Populate script details
284 QString details;
285 details += QString("Game: %1\n").arg(QString::fromStdString(script_.gameName));
286 details += QString("Slug: %1\n").arg(QString::fromStdString(script_.gameSlug));
287 details += QString("Installer: %1\n").arg(QString::fromStdString(script_.installerSlug));
288 details += QString("Runner: %1\n").arg(QString::fromStdString(script_.runner));
289 details += QString("\n");
290
291 if (!script_.executable.empty())
292 {
293 details += QString("Executable: %1\n").arg(QString::fromStdString(script_.executable));
294 }
295 if (!script_.workingDir.empty())
296 {
297 details += QString("Working Dir: %1\n").arg(QString::fromStdString(script_.workingDir));
298 }
299 if (!script_.arguments.empty())
300 {
301 details += QString("Arguments: %1\n").arg(QString::fromStdString(script_.arguments));
302 }
303
304 if (!script_.environmentVariables.empty())
305 {
306 details += QString("\nEnvironment Variables:\n");
307 for (const auto& [key, value] : script_.environmentVariables)
308 {
309 details += QString(" %1=%2\n")
310 .arg(QString::fromStdString(key))
311 .arg(QString::fromStdString(value));
312 }
313 }
314
315 if (script_.runner == "wine")
316 {
317 details += QString("\nWine Configuration:\n");
318 if (!script_.wineConfig.version.empty())
319 {
320 details +=
321 QString(" Version: %1\n").arg(QString::fromStdString(script_.wineConfig.version));
322 }
323 details += QString(" DXVK: %1\n").arg(script_.wineConfig.dxvk ? "Yes" : "No");
324 details += QString(" VKD3D: %1\n").arg(script_.wineConfig.vkd3d ? "Yes" : "No");
325 details += QString(" Esync: %1\n").arg(script_.wineConfig.esync ? "Yes" : "No");
326 details += QString(" Fsync: %1\n").arg(script_.wineConfig.fsync ? "Yes" : "No");
327 }
328
329 scriptDetailsText_->setPlainText(details);
330
331 // Apply script's Wine settings to UI
332 if (script_.runner == "wine")
333 {
334 dxvkCheck_->setChecked(script_.wineConfig.dxvk);
335 vkd3dCheck_->setChecked(script_.wineConfig.vkd3d);
336 esyncCheck_->setChecked(script_.wineConfig.esync);
337 fsyncCheck_->setChecked(script_.wineConfig.fsync);
338 }
339
340 updateDiskSpaceInfo();
341}
342
343void LutrisInstallPreviewDialog::updateDiskSpaceInfo()
344{
345 QString installDir = installDirEdit_->text();
346 if (installDir.isEmpty())
347 {
348 diskSpaceLabel_->setText("Please specify an install directory");
349 return;
350 }
351
352 // Find the mount point for the install directory
353 QDir dir(installDir);
354 while (!dir.exists() && !dir.isRoot())
355 {
356 dir.cdUp();
357 }
358
359 QStorageInfo storage(dir.absolutePath());
360 if (storage.isValid())
361 {
362 QString available = formatSize(static_cast<uint64_t>(storage.bytesAvailable()));
363 QString total = formatSize(static_cast<uint64_t>(storage.bytesTotal()));
364 diskSpaceLabel_->setText(
365 QString("Available disk space: %1 / %2").arg(available).arg(total));
366 }
367 else
368 {
369 diskSpaceLabel_->setText("Unable to determine disk space");
370 }
371}
372
373void LutrisInstallPreviewDialog::onBrowseInstallDir()
374{
375 QString dir = QFileDialog::getExistingDirectory(
376 this, "Select Install Directory",
377 installDirEdit_->text().isEmpty() ? QDir::homePath() : installDirEdit_->text());
378
379 if (!dir.isEmpty())
380 {
381 installDirEdit_->setText(dir);
382 }
383}
384
385void LutrisInstallPreviewDialog::onBrowseWinePrefix()
386{
387 QString dir = QFileDialog::getExistingDirectory(
388 this, "Select Wine Prefix Directory",
389 winePrefixEdit_->text().isEmpty() ? QDir::homePath() : winePrefixEdit_->text());
390
391 if (!dir.isEmpty())
392 {
393 winePrefixEdit_->setText(dir);
394 }
395}
396
397void LutrisInstallPreviewDialog::onInstallClicked()
398{
399 // Validate configuration
400 QString installDir = installDirEdit_->text().trimmed();
401 if (installDir.isEmpty())
402 {
403 QMessageBox::warning(this, "Invalid Configuration", "Please specify an install directory.");
404 return;
405 }
406
407 if (script_.runner == "wine")
408 {
409 QString winePrefix = winePrefixEdit_->text().trimmed();
410 if (winePrefix.isEmpty())
411 {
412 QMessageBox::warning(this, "Invalid Configuration",
413 "Please specify a Wine prefix directory.");
414 return;
415 }
416 }
417
418 accept();
419}
420
421void LutrisInstallPreviewDialog::onValidateConfig()
422{
423 updateDiskSpaceInfo();
424
425 bool valid = true;
426
427 if (installDirEdit_->text().trimmed().isEmpty())
428 {
429 valid = false;
430 }
431
432 if (script_.runner == "wine" && winePrefixEdit_->text().trimmed().isEmpty())
433 {
434 valid = false;
435 }
436
437 installBtn_->setEnabled(valid);
438}
439
441{
442 InstallConfig config;
443 config.installPath = installDirEdit_->text().toStdString();
444 config.winePrefixPath = winePrefixEdit_->text().toStdString();
445 config.downloadCachePath = config.installPath + "/.downloads";
446
447 // Wine version selection
448 QString wineVersion = wineVersionCombo_->currentData().toString();
449 config.wineVersion = wineVersion.toStdString();
450
451 return config;
452}
453
454QString LutrisInstallPreviewDialog::formatSize(uint64_t bytes) const
455{
456 if (bytes == 0)
457 return "0 B";
458
459 const char* units[] = {"B", "KB", "MB", "GB", "TB"};
460 int unitIndex = 0;
461 double size = static_cast<double>(bytes);
462
463 while (size >= 1024.0 && unitIndex < 4)
464 {
465 size /= 1024.0;
466 unitIndex++;
467 }
468
469 if (unitIndex == 0)
470 {
471 return QString("%1 B").arg(static_cast<int>(size));
472 }
473 else
474 {
475 return QString("%1 %2").arg(size, 0, 'f', 1).arg(units[unitIndex]);
476 }
477}
LutrisInstallPreviewDialog(const LutrisInstallerScript &script, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
std::string downloadCachePath
std::string winePrefixPath