Improve UI

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-03-20 00:15:02 +02:00
parent ef4e5eb3cf
commit 09c2c6793b
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
18 changed files with 295 additions and 296 deletions

View File

@ -112,6 +112,5 @@ QHash<int, QByteArray> BaseVersionList::roleNames() const
roles.insert(PathRole, "path"); roles.insert(PathRole, "path");
roles.insert(JavaNameRole, "javaName"); roles.insert(JavaNameRole, "javaName");
roles.insert(CPUArchitectureRole, "architecture"); roles.insert(CPUArchitectureRole, "architecture");
roles.insert(JavaVendorRole, "javaVendor");
return roles; return roles;
} }

View File

@ -50,7 +50,6 @@ class BaseVersionList : public QAbstractListModel {
PathRole, PathRole,
JavaNameRole, JavaNameRole,
CPUArchitectureRole, CPUArchitectureRole,
JavaVendorRole,
SortRole SortRole
}; };
using RoleList = QList<int>; using RoleList = QList<int>;

View File

@ -440,8 +440,8 @@ set(JAVA_SOURCES
java/download/ManifestDownloadTask.cpp java/download/ManifestDownloadTask.cpp
java/download/ManifestDownloadTask.h java/download/ManifestDownloadTask.h
ui/java/JavaDownloader.h ui/java/InstallJavaDialog.h
ui/java/JavaDownloader.cpp ui/java/InstallJavaDialog.cpp
ui/java/VersionList.h ui/java/VersionList.h
ui/java/VersionList.cpp ui/java/VersionList.cpp
) )
@ -1194,7 +1194,6 @@ qt_wrap_ui(LAUNCHER_UI
ui/dialogs/ScrollMessageBox.ui ui/dialogs/ScrollMessageBox.ui
ui/dialogs/BlockedModsDialog.ui ui/dialogs/BlockedModsDialog.ui
ui/dialogs/ChooseProviderDialog.ui ui/dialogs/ChooseProviderDialog.ui
ui/java/JavaDownloader.ui
) )
qt_wrap_ui(PRISM_UPDATE_UI qt_wrap_ui(PRISM_UPDATE_UI

View File

@ -116,8 +116,6 @@ QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation,
return tr("Type"); return tr("Type");
case CPUArchitecture: case CPUArchitecture:
return tr("Architecture"); return tr("Architecture");
case JavaVendor:
return tr("Vendor");
case Path: case Path:
return tr("Path"); return tr("Path");
case JavaName: case JavaName:
@ -137,8 +135,6 @@ QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation,
return tr("The version's type"); return tr("The version's type");
case CPUArchitecture: case CPUArchitecture:
return tr("CPU Architecture"); return tr("CPU Architecture");
case JavaVendor:
return tr("Java vendor");
case Path: case Path:
return tr("Filesystem path to this version"); return tr("Filesystem path to this version");
case JavaName: case JavaName:
@ -175,8 +171,6 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const
return sourceModel()->data(parentIndex, BaseVersionList::TypeRole); return sourceModel()->data(parentIndex, BaseVersionList::TypeRole);
case CPUArchitecture: case CPUArchitecture:
return sourceModel()->data(parentIndex, BaseVersionList::CPUArchitectureRole); return sourceModel()->data(parentIndex, BaseVersionList::CPUArchitectureRole);
case JavaVendor:
return sourceModel()->data(parentIndex, BaseVersionList::JavaVendorRole);
case Path: case Path:
return sourceModel()->data(parentIndex, BaseVersionList::PathRole); return sourceModel()->data(parentIndex, BaseVersionList::PathRole);
case JavaName: case JavaName:
@ -323,9 +317,6 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel* replacingRaw)
if (roles.contains(BaseVersionList::CPUArchitectureRole)) { if (roles.contains(BaseVersionList::CPUArchitectureRole)) {
m_columns.push_back(CPUArchitecture); m_columns.push_back(CPUArchitecture);
} }
if (roles.contains(BaseVersionList::JavaVendorRole)) {
m_columns.push_back(JavaVendor);
}
if (roles.contains(BaseVersionList::PathRole)) { if (roles.contains(BaseVersionList::PathRole)) {
m_columns.push_back(Path); m_columns.push_back(Path);
} }

View File

@ -9,7 +9,7 @@ class VersionFilterModel;
class VersionProxyModel : public QAbstractProxyModel { class VersionProxyModel : public QAbstractProxyModel {
Q_OBJECT Q_OBJECT
public: public:
enum Column { Name, ParentVersion, Branch, Type, CPUArchitecture, Path, Time, JavaName, JavaVendor }; enum Column { Name, ParentVersion, Branch, Type, CPUArchitecture, Path, Time, JavaName };
using FilterMap = QHash<BaseVersionList::ModelRoles, std::shared_ptr<Filter>>; using FilterMap = QHash<BaseVersionList::ModelRoles, std::shared_ptr<Filter>>;
public: public:

View File

@ -52,9 +52,9 @@ MetadataPtr parseJavaMeta(const QJsonObject& in)
meta->vendor = Json::ensureString(in, "vendor", ""); meta->vendor = Json::ensureString(in, "vendor", "");
meta->url = Json::ensureString(in, "url", ""); meta->url = Json::ensureString(in, "url", "");
meta->releaseTime = timeFromS3Time(Json::ensureString(in, "releaseTime", "")); meta->releaseTime = timeFromS3Time(Json::ensureString(in, "releaseTime", ""));
meta->recommended = Json::ensureBoolean(in, "recommended", false);
meta->downloadType = parseDownloadType(Json::ensureString(in, "downloadType", "")); meta->downloadType = parseDownloadType(Json::ensureString(in, "downloadType", ""));
meta->packageType = Json::ensureString(in, "packageType", ""); meta->packageType = Json::ensureString(in, "packageType", "");
meta->runtimeOS = Json::ensureString(in, "runtimeOS", "unknown");
if (in.contains("checksum")) { if (in.contains("checksum")) {
auto obj = Json::requireObject(in, "checksum"); auto obj = Json::requireObject(in, "checksum");

View File

@ -50,10 +50,10 @@ class Metadata : public BaseVersion {
QDateTime releaseTime; QDateTime releaseTime;
QString checksumType; QString checksumType;
QString checksumHash; QString checksumHash;
bool recommended;
DownloadType downloadType; DownloadType downloadType;
QString packageType; QString packageType;
JavaVersion version; JavaVersion version;
QString runtimeOS;
}; };
using MetadataPtr = std::shared_ptr<Metadata>; using MetadataPtr = std::shared_ptr<Metadata>;

View File

@ -258,14 +258,9 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
} }
if (root.contains("runtimes")) { if (root.contains("runtimes")) {
auto runtimes = requireObject(root, "runtimes");
out->runtimes = {}; out->runtimes = {};
for (auto key : runtimes.keys()) { for (auto runtime : ensureArray(root, "runtimes")) {
QList<Java::MetadataPtr> list; out->runtimes.append(Java::parseJavaMeta(ensureObject(runtime)));
for (auto runtime : ensureArray(runtimes, key)) {
list.append(Java::parseJavaMeta(ensureObject(runtime)));
}
out->runtimes[key] = list;
} }
} }

View File

@ -155,7 +155,7 @@ class VersionFile : public ProblemContainer {
/// is volatile -- may be removed as soon as it is no longer needed by something else /// is volatile -- may be removed as soon as it is no longer needed by something else
bool m_volatile = false; bool m_volatile = false;
QHash<QString, QList<Java::MetadataPtr>> runtimes; QList<Java::MetadataPtr> runtimes;
public: public:
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more. // Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.

View File

@ -145,39 +145,35 @@ void AutoInstallJava::setJavaPathFromPartial()
void AutoInstallJava::downloadJava(Meta::Version::Ptr version, QString javaName) void AutoInstallJava::downloadJava(Meta::Version::Ptr version, QString javaName)
{ {
auto runtimes = version->data()->runtimes; auto runtimes = version->data()->runtimes;
if (runtimes.contains(m_supported_arch)) { for (auto java : runtimes) {
for (auto java : runtimes.value(m_supported_arch)) { if (java->runtimeOS == m_supported_arch && java->name() == javaName) {
if (java->name() == javaName) { QDir javaDir(APPLICATION->javaPath());
QDir javaDir(APPLICATION->javaPath()); auto final_path = javaDir.absoluteFilePath(java->m_name);
auto final_path = javaDir.absoluteFilePath(java->m_name); switch (java->downloadType) {
switch (java->downloadType) { case Java::DownloadType::Manifest:
case Java::DownloadType::Manifest: m_current_task = makeShared<Java::ManifestDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
m_current_task = break;
makeShared<Java::ManifestDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash); case Java::DownloadType::Archive:
break; m_current_task = makeShared<Java::ArchiveDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
case Java::DownloadType::Archive: break;
m_current_task =
makeShared<Java::ArchiveDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
break;
}
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(m_current_task.get(), &Task::failed, this, [this, deletePath](QString reason) {
deletePath();
emitFailed(reason);
});
connect(this, &Task::aborted, this, [this, deletePath] {
m_current_task->abort();
deletePath();
});
connect(m_current_task.get(), &Task::succeeded, this, &AutoInstallJava::setJavaPathFromPartial);
connect(m_current_task.get(), &Task::failed, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
m_current_task->start();
return;
} }
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(m_current_task.get(), &Task::failed, this, [this, deletePath](QString reason) {
deletePath();
emitFailed(reason);
});
connect(this, &Task::aborted, this, [this, deletePath] {
m_current_task->abort();
deletePath();
});
connect(m_current_task.get(), &Task::succeeded, this, &AutoInstallJava::setJavaPathFromPartial);
connect(m_current_task.get(), &Task::failed, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
m_current_task->start();
return;
} }
} }
tryNextMajorJava(); tryNextMajorJava();

View File

@ -0,0 +1,234 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "InstallJavaDialog.h"
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include "Application.h"
#include "FileSystem.h"
#include "java/download/ArchiveDownloadTask.h"
#include "java/download/ManifestDownloadTask.h"
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "ui/dialogs/ProgressDialog.h"
#include "ui/java/VersionList.h"
#include "ui/widgets/PageContainer.h"
#include "ui/widgets/VersionSelectWidget.h"
class InstallLoaderPage : public QWidget, public BasePage {
public:
Q_OBJECT
public:
explicit InstallLoaderPage(const QString& id, const QString& iconName, const QString& name, QWidget* parent = nullptr)
: QWidget(parent), uid(id), iconName(iconName), name(name)
{
setObjectName(QStringLiteral("VersionSelectWidget"));
horizontalLayout = new QHBoxLayout(this);
horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
horizontalLayout->setContentsMargins(0, 0, 0, 0);
majorVersionSelect = new VersionSelectWidget(this);
majorVersionSelect->selectCurrent();
majorVersionSelect->setEmptyString(tr("No java versions are currently available in the meta."));
majorVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
horizontalLayout->addWidget(majorVersionSelect, 1);
javaVersionSelect = new VersionSelectWidget(this);
javaVersionSelect->setEmptyString(tr("No java versions are currently available for your OS."));
javaVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
horizontalLayout->addWidget(javaVersionSelect, 4);
connect(majorVersionSelect, &VersionSelectWidget::selectedVersionChanged, this, &InstallLoaderPage::setSelectedVersion);
connect(javaVersionSelect, &VersionSelectWidget::selectedVersionChanged, this, &InstallLoaderPage::selectedVersionChanged);
QMetaObject::connectSlotsByName(this);
}
~InstallLoaderPage()
{
delete horizontalLayout;
delete majorVersionSelect;
delete javaVersionSelect;
}
//! loads the list if needed.
void initialize(Meta::VersionList::Ptr vlist)
{
vlist->setProvidedRoles({ BaseVersionList::VersionRole, BaseVersionList::RecommendedRole, BaseVersionList::VersionPointerRole });
majorVersionSelect->initialize(vlist.get());
}
void setSelectedVersion(BaseVersion::Ptr version)
{
auto dcast = std::dynamic_pointer_cast<Meta::Version>(version);
if (!dcast) {
return;
}
javaVersionSelect->initialize(new Java::VersionList(dcast, this));
javaVersionSelect->selectCurrent();
}
QString id() const override { return uid; }
QString displayName() const override { return name; }
QIcon icon() const override { return APPLICATION->getThemedIcon(iconName); }
void openedImpl() override
{
if (loaded)
return;
const auto versions = APPLICATION->metadataIndex()->get(uid);
if (!versions)
return;
initialize(versions);
loaded = true;
}
void setParentContainer(BasePageContainer* container) override
{
auto dialog = dynamic_cast<QDialog*>(dynamic_cast<PageContainer*>(container)->parent());
connect(javaVersionSelect->view(), &QAbstractItemView::doubleClicked, dialog, &QDialog::accept);
}
BaseVersion::Ptr selectedVersion() const { return javaVersionSelect->selectedVersion(); }
void selectSearch() { javaVersionSelect->selectSearch(); }
void loadList()
{
majorVersionSelect->loadList();
javaVersionSelect->loadList();
}
signals:
void selectedVersionChanged(BaseVersion::Ptr version);
private:
const QString uid;
const QString iconName;
const QString name;
bool loaded = false;
QHBoxLayout* horizontalLayout = nullptr;
VersionSelectWidget* majorVersionSelect = nullptr;
VersionSelectWidget* javaVersionSelect = nullptr;
};
static InstallLoaderPage* pageCast(BasePage* page)
{
auto result = dynamic_cast<InstallLoaderPage*>(page);
Q_ASSERT(result != nullptr);
return result;
}
namespace Java {
InstallDialog::InstallDialog(const QString& uid, QWidget* parent)
: QDialog(parent), container(new PageContainer(this, QString(), this)), buttons(new QDialogButtonBox(this))
{
auto layout = new QVBoxLayout(this);
container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
layout->addWidget(container);
auto buttonLayout = new QHBoxLayout(this);
auto refreshButton = new QPushButton(tr("&Refresh"), this);
connect(refreshButton, &QPushButton::clicked, this, [this] { pageCast(container->selectedPage())->loadList(); });
buttonLayout->addWidget(refreshButton);
buttons->setOrientation(Qt::Horizontal);
buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
buttons->button(QDialogButtonBox::Ok)->setText(tr("Download"));
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
buttonLayout->addWidget(buttons);
layout->addLayout(buttonLayout);
setWindowTitle(dialogTitle());
setWindowModality(Qt::WindowModal);
resize(840, 480);
for (BasePage* page : container->getPages()) {
if (page->id() == uid)
container->selectPage(page->id());
connect(pageCast(page), &InstallLoaderPage::selectedVersionChanged, this, [this, page] {
if (page->id() == container->selectedPage()->id())
validate(container->selectedPage());
});
}
connect(container, &PageContainer::selectedPageChanged, this, [this](BasePage* previous, BasePage* current) { validate(current); });
pageCast(container->selectedPage())->selectSearch();
validate(container->selectedPage());
}
QList<BasePage*> InstallDialog::getPages()
{
return {
// NeoForge
new InstallLoaderPage("net.minecraft.java", "", tr("Mojang")),
// Forge
new InstallLoaderPage("net.adoptium.java", "", tr("Adoptium")),
// Fabric
new InstallLoaderPage("com.azul.java", "", tr("Azul")),
};
}
QString InstallDialog::dialogTitle()
{
return tr("Install Loader");
}
void InstallDialog::validate(BasePage* page)
{
buttons->button(QDialogButtonBox::Ok)->setEnabled(pageCast(page)->selectedVersion() != nullptr);
}
void InstallDialog::done(int result)
{
if (result == Accepted) {
auto* page = pageCast(container->selectedPage());
if (page->selectedVersion()) {
auto meta = std::dynamic_pointer_cast<Java::Metadata>(page->selectedVersion());
if (meta) {
Task::Ptr task;
auto final_path = FS::PathCombine(APPLICATION->javaPath(), meta->m_name);
switch (meta->downloadType) {
case Java::DownloadType::Manifest:
task = makeShared<ManifestDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
case Java::DownloadType::Archive:
task = makeShared<ArchiveDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
}
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(task.get(), &Task::failed, this, deletePath);
connect(task.get(), &Task::aborted, this, deletePath);
ProgressDialog pg(this);
pg.setSkipButton(true, tr("Abort"));
pg.execWithTask(task.get());
}
}
}
QDialog::done(result);
}
} // namespace Java
#include "InstallJavaDialog.moc"

View File

@ -19,30 +19,28 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include "BaseVersion.h" #include "ui/pages/BasePageProvider.h"
namespace Ui { class MinecraftInstance;
class JavaDownloader; class PageContainer;
} class PackProfile;
class QDialogButtonBox;
namespace Java { namespace Java {
class InstallDialog final : public QDialog, protected BasePageProvider {
class Downloader : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit Downloader(QWidget* parent = 0); explicit InstallDialog(const QString& uid = QString(), QWidget* parent = nullptr);
~Downloader();
void accept(); QList<BasePage*> getPages() override;
QString dialogTitle() override;
public slots: void validate(BasePage* page);
void refresh(); void done(int result) override;
protected slots:
void setSelectedVersion(BaseVersion::Ptr version);
private: private:
Ui::JavaDownloader* ui; PageContainer* container;
QDialogButtonBox* buttons;
}; };
} // namespace Java } // namespace Java

View File

@ -1,110 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2024 Trial97 <alexandru.tripon97@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "JavaDownloader.h"
#include <QPushButton>
#include <memory>
#include "Application.h"
#include "BaseVersionList.h"
#include "FileSystem.h"
#include "QObjectPtr.h"
#include "SysInfo.h"
#include "java/JavaMetadata.h"
#include "java/download/ArchiveDownloadTask.h"
#include "java/download/ManifestDownloadTask.h"
#include "meta/Index.h"
#include "meta/Version.h"
#include "meta/VersionList.h"
#include "ui/dialogs/ProgressDialog.h"
#include "ui/java/VersionList.h"
#include "ui_JavaDownloader.h"
namespace Java {
Downloader::Downloader(QWidget* parent) : QDialog(parent), ui(new Ui::JavaDownloader)
{
ui->setupUi(this);
auto versionList = APPLICATION->metadataIndex()->get("net.minecraft.java");
versionList->setProvidedRoles({ BaseVersionList::VersionRole, BaseVersionList::RecommendedRole, BaseVersionList::VersionPointerRole });
ui->majorVersionSelect->initialize(versionList.get());
ui->majorVersionSelect->selectCurrent();
ui->majorVersionSelect->setEmptyString(tr("No java versions are currently available in the meta."));
ui->majorVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
ui->javaVersionSelect->setEmptyString(tr("No java versions are currently available for your OS."));
ui->javaVersionSelect->setEmptyErrorString(tr("Couldn't load or download the java version lists!"));
ui->buttonBox->button(QDialogButtonBox::Reset)->setText(tr("Refresh"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Download"));
connect(ui->majorVersionSelect, &VersionSelectWidget::selectedVersionChanged, this, &Downloader::setSelectedVersion);
auto reset = ui->buttonBox->button(QDialogButtonBox::Reset);
connect(reset, &QPushButton::clicked, this, &Downloader::refresh);
}
Downloader::~Downloader()
{
delete ui;
}
void Downloader::setSelectedVersion(BaseVersion::Ptr version)
{
auto dcast = std::dynamic_pointer_cast<Meta::Version>(version);
if (!dcast) {
return;
}
ui->javaVersionSelect->initialize(new Java::VersionList(dcast, this));
ui->javaVersionSelect->selectCurrent();
}
void Downloader::accept()
{
auto meta = std::dynamic_pointer_cast<Java::Metadata>(ui->javaVersionSelect->selectedVersion());
if (!meta) {
return;
}
Task::Ptr task;
auto final_path = FS::PathCombine(APPLICATION->javaPath(), meta->m_name);
switch (meta->downloadType) {
case Java::DownloadType::Manifest:
task = makeShared<ManifestDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
case Java::DownloadType::Archive:
task = makeShared<ArchiveDownloadTask>(meta->url, final_path, meta->checksumType, meta->checksumHash);
break;
}
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(task.get(), &Task::failed, this, deletePath);
connect(task.get(), &Task::aborted, this, deletePath);
ProgressDialog pg(this);
pg.setSkipButton(true, tr("Abort"));
pg.execWithTask(task.get());
QDialog::accept();
}
void Downloader::refresh()
{
ui->majorVersionSelect->loadList();
}
} // namespace Java

View File

@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JavaDownloader</class>
<widget class="QDialog" name="JavaDownloader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>821</width>
<height>593</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,5">
<item>
<widget class="QGroupBox" name="majorGB">
<property name="title">
<string>Major</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="VersionSelectWidget" name="majorVersionSelect" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="runtimeGB">
<property name="title">
<string>Runtime</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="VersionSelectWidget" name="javaVersionSelect" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>VersionSelectWidget</class>
<extends>QWidget</extends>
<header>ui/widgets/VersionSelectWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>JavaDownloader</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>583</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>JavaDownloader</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>583</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -75,11 +75,9 @@ QVariant VersionList::data(const QModelIndex& index, int role) const
case VersionRole: case VersionRole:
return version->version.toString(); return version->version.toString();
case RecommendedRole: case RecommendedRole:
return version->recommended; return false; // do not recommend any version
case JavaNameRole: case JavaNameRole:
return version->name(); return version->name();
case JavaVendorRole:
return version->vendor;
case TypeRole: case TypeRole:
return version->packageType; return version->packageType;
case Meta::VersionList::TimeRole: case Meta::VersionList::TimeRole:
@ -91,8 +89,7 @@ QVariant VersionList::data(const QModelIndex& index, int role) const
BaseVersionList::RoleList VersionList::providesRoles() const BaseVersionList::RoleList VersionList::providesRoles() const
{ {
return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, return { VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, JavaNameRole, TypeRole, Meta::VersionList::TimeRole };
JavaNameRole, JavaVendorRole, TypeRole, Meta::VersionList::TimeRole };
} }
bool sortJavas(BaseVersion::Ptr left, BaseVersion::Ptr right) bool sortJavas(BaseVersion::Ptr left, BaseVersion::Ptr right)
@ -109,11 +106,12 @@ void VersionList::sortVersions()
QString versionStr = SysInfo::getSupportedJavaArchitecture(); QString versionStr = SysInfo::getSupportedJavaArchitecture();
beginResetModel(); beginResetModel();
auto runtimes = m_version->data()->runtimes; auto runtimes = m_version->data()->runtimes;
if (!versionStr.isEmpty() && !runtimes.isEmpty() && runtimes.contains(versionStr)) { m_vlist = {};
m_vlist = runtimes.value(versionStr); if (!versionStr.isEmpty() && !runtimes.isEmpty()) {
std::copy_if(runtimes.begin(), runtimes.end(), std::back_inserter(m_vlist),
[versionStr](Java::MetadataPtr val) { return val->runtimeOS == versionStr; });
std::sort(m_vlist.begin(), m_vlist.end(), sortJavas); std::sort(m_vlist.begin(), m_vlist.end(), sortJavas);
} else { } else {
m_vlist = {};
qWarning() << "No Java versions found for your operating system." << SysInfo::currentSystem() << " " << SysInfo::useQTForArch(); qWarning() << "No Java versions found for your operating system." << SysInfo::currentSystem() << " " << SysInfo::useQTForArch();
} }
endResetModel(); endResetModel();

View File

@ -39,7 +39,7 @@
#include "JavaCommon.h" #include "JavaCommon.h"
#include "java/JavaInstall.h" #include "java/JavaInstall.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/java/JavaDownloader.h" #include "ui/java/InstallJavaDialog.h"
#include "ui_JavaPage.h" #include "ui_JavaPage.h"
#include <QCheckBox> #include <QCheckBox>
@ -201,7 +201,7 @@ void JavaPage::on_javaTestBtn_clicked()
void JavaPage::on_javaDownloadBtn_clicked() void JavaPage::on_javaDownloadBtn_clicked()
{ {
auto jdialog = new Java::Downloader(this); auto jdialog = new Java::InstallDialog({}, this);
jdialog->exec(); jdialog->exec();
ui->managedJavaList->loadList(); ui->managedJavaList->loadList();
} }

View File

@ -37,7 +37,7 @@
#include "InstanceSettingsPage.h" #include "InstanceSettingsPage.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/java/JavaDownloader.h" #include "ui/java/InstallJavaDialog.h"
#include "ui_InstanceSettingsPage.h" #include "ui_InstanceSettingsPage.h"
#include <QDialog> #include <QDialog>
@ -394,7 +394,7 @@ void InstanceSettingsPage::loadSettings()
void InstanceSettingsPage::on_javaDownloadBtn_clicked() void InstanceSettingsPage::on_javaDownloadBtn_clicked()
{ {
auto jdialog = new Java::Downloader(this); auto jdialog = new Java::InstallDialog({}, this);
jdialog->exec(); jdialog->exec();
} }

View File

@ -21,7 +21,7 @@
#include "java/JavaUtils.h" #include "java/JavaUtils.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/java/JavaDownloader.h" #include "ui/java/InstallJavaDialog.h"
#include "ui/widgets/VersionSelectWidget.h" #include "ui/widgets/VersionSelectWidget.h"
#include "Application.h" #include "Application.h"
@ -351,7 +351,7 @@ void JavaSettingsWidget::on_javaBrowseBtn_clicked()
void JavaSettingsWidget::on_javaDownloadBtn_clicked() void JavaSettingsWidget::on_javaDownloadBtn_clicked()
{ {
auto jdialog = new Java::Downloader(this); auto jdialog = new Java::InstallDialog({}, this);
jdialog->exec(); jdialog->exec();
} }