From 52661635b4f04c356f0092e5b59f1261dd04b34f Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 29 Oct 2023 02:20:25 -0500 Subject: Qt UI: Add Advanced Options screen Allows the user to select arch, repository, signingkey, and version. Closes: #337 --- ui/qt5/CMakeLists.txt | 1 + ui/qt5/advoptsdialog.cc | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ ui/qt5/advoptsdialog.hh | 24 +++++++++ ui/qt5/horizonwizard.cc | 8 ++- ui/qt5/horizonwizard.hh | 38 +++++++++++++-- ui/qt5/intropage.cc | 13 ++++- ui/qt5/intropage.hh | 4 -- 7 files changed, 203 insertions(+), 12 deletions(-) create mode 100644 ui/qt5/advoptsdialog.cc create mode 100644 ui/qt5/advoptsdialog.hh (limited to 'ui') diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt index 449e9bc..086abc7 100644 --- a/ui/qt5/CMakeLists.txt +++ b/ui/qt5/CMakeLists.txt @@ -16,6 +16,7 @@ set(UI_SOURCES crypt_sha512.c intropage.cc + advoptsdialog.cc inputpage.cc partitiondiskpage.cc partitionchoicepage.cc diff --git a/ui/qt5/advoptsdialog.cc b/ui/qt5/advoptsdialog.cc new file mode 100644 index 0000000..598f093 --- /dev/null +++ b/ui/qt5/advoptsdialog.cc @@ -0,0 +1,127 @@ +/* + * advoptsdialog.cc - Implementation of the UI.AdvOpts page + * horizon-qt5, the Qt 5 user interface for + * Project Horizon + * + * Copyright (c) 2023 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "advoptsdialog.hh" + +void updateSubarchBox(QComboBox *subarchBox, HorizonWizard::Arch arch, HorizonWizard *wizard) { + subarchBox->clear(); + auto current = wizard->subarch; + for(const auto &subarch : wizard->subarchesForArch(arch)) { + const auto text = QString::fromStdString(subarch.first); + subarchBox->addItem(text, QVariant::fromValue(subarch.second)); + if(current == subarch.second) { + subarchBox->setCurrentText(text); + } + } +} + +inline void configTextEdit(QTextEdit *edit) { + edit->setAcceptRichText(false); + edit->setFixedHeight(70); + edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + edit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); +} + +AdvOptsDialog::AdvOptsDialog(HorizonWizard *wizard, QWidget *parent) : QDialog(parent) { + setWindowTitle(tr("System Installation Advanced Options")); + + auto warnLabel = new QLabel(tr("WARNING: Modifying any of the settings on this page may cause installation to fail.")); + warnLabel->setTextFormat(Qt::RichText); + + auto version = new QLabel(tr("&Version to install:")); + auto versionEdit = new QLineEdit(this); + versionEdit->setText(QString::fromStdString(wizard->version)); + version->setBuddy(versionEdit); + + auto repos = new QLabel(tr("URLs for package &repositories:")); + auto repoEdit = new QTextEdit(this); + configTextEdit(repoEdit); + repoEdit->setPlainText(wizard->repositories.join("\n")); + repos->setBuddy(repoEdit); + + auto keys = new QLabel(tr("URLs for package &signing keys: (must begin with https:)")); + keys->setTextFormat(Qt::RichText); + auto keyEdit = new QTextEdit(this); + configTextEdit(keyEdit); + keyEdit->setPlainText(wizard->signing_keys.join("\n")); + keys->setBuddy(keyEdit); + + auto arch = new QLabel(tr("Target CPU &architecture:")); + auto archBox = new QComboBox(this); + archBox->setEditable(false); + for(const auto &arches : wizard->arches) { + const auto text = QString::fromStdString(arches.first); + archBox->addItem(text, QVariant::fromValue(arches.second)); + if(wizard->arch == arches.second) { + archBox->setCurrentText(text); + } + } + arch->setBuddy(archBox); + + auto subarch = new QLabel(tr("Sub-architecture (if applicable):")); + auto subarchBox = new QComboBox(this); + subarchBox->setEditable(false); + updateSubarchBox(subarchBox, wizard->arch, wizard); + subarch->setBuddy(subarchBox); + + connect(archBox, QOverload::of(&QComboBox::currentIndexChanged), [=](int index) { + updateSubarchBox(subarchBox, static_cast(archBox->itemData(index).toInt()), wizard); + }); + + auto saveButton = new QPushButton(tr("&Save")); + connect(saveButton, &QPushButton::clicked, + [this, wizard, archBox, subarchBox, versionEdit, repoEdit, keyEdit](bool) { + wizard->arch = static_cast(archBox->currentData().toInt()); + wizard->subarch = static_cast(subarchBox->currentData().toInt()); + wizard->version = versionEdit->text().toStdString(); + wizard->repositories = repoEdit->toPlainText().split('\n'); + wizard->signing_keys = keyEdit->toPlainText().split('\n'); + this->accept(); + }); + auto cancelButton = new QPushButton(tr("&Cancel")); + connect(cancelButton, &QPushButton::clicked, [this](bool) { + this->reject(); + }); + + auto buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(cancelButton); + buttonLayout->addStretch(); + buttonLayout->addWidget(saveButton); + + auto layout = new QVBoxLayout; + layout->addWidget(warnLabel); + layout->addSpacing(25); + layout->addWidget(arch); + layout->addWidget(archBox); + layout->addWidget(subarch); + layout->addWidget(subarchBox); + layout->addSpacing(25); + layout->addWidget(version); + layout->addWidget(versionEdit); + layout->addSpacing(25); + layout->addWidget(repos); + layout->addWidget(repoEdit); + layout->addSpacing(25); + layout->addWidget(keys); + layout->addWidget(keyEdit); + layout->addSpacing(25); + layout->addLayout(buttonLayout); + this->setLayout(layout); +} \ No newline at end of file diff --git a/ui/qt5/advoptsdialog.hh b/ui/qt5/advoptsdialog.hh new file mode 100644 index 0000000..fee511c --- /dev/null +++ b/ui/qt5/advoptsdialog.hh @@ -0,0 +1,24 @@ +/* + * advoptsdialog.hh - Definition of the UI.AdvOpts page + * horizon-qt5, the Qt 5 user interface for + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#ifndef ADVOPTSDIALOG_HH +#define ADVOPTSDIALOG_HH + +#include "horizonwizard.hh" +#include + +class AdvOptsDialog : public QDialog { +public: + AdvOptsDialog(HorizonWizard *wizard, QWidget *parent = nullptr); +}; + +#endif /* !ADVOPTSDIALOG_HH */ diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc index e78d991..97b2939 100644 --- a/ui/qt5/horizonwizard.cc +++ b/ui/qt5/horizonwizard.cc @@ -583,8 +583,14 @@ QString HorizonWizard::toHScript() { break; } + if(!repositories.empty()) { + for(const auto &repo : repositories) { + lines << QString{"repository %1"}.arg(repo); + } + } + if(!signing_keys.empty()) { - for(const auto &key : signing_keys) { + for(const auto &key: signing_keys) { lines << QString{"signingkey %1"}.arg(key); } } diff --git a/ui/qt5/horizonwizard.hh b/ui/qt5/horizonwizard.hh index d4a5dfd..cd0552b 100644 --- a/ui/qt5/horizonwizard.hh +++ b/ui/qt5/horizonwizard.hh @@ -97,10 +97,10 @@ public: enum Arch { aarch64, armv7, - mips, - mips64, - mipsel, - mips64el, + mips, + mips64, + mipsel, + mips64el, pmmx, ppc, ppc64, @@ -115,6 +115,32 @@ public: ppc64_PowerNV }; + /*! Valid architectures, used by AdvOpts */ + const std::vector< std::pair > arches = { + {"64-bit x86 (x86_64)", x86_64}, + {"32-bit x86, with MMX (pmmx)", pmmx}, + {"64-bit PowerPC, big-endian (ppc64)", ppc64}, + {"32-bit PowerPC, big-endian (ppc)", ppc}, + {"64-bit ARM, little-endian (aarch64)", aarch64}, + {"32-bit ARMv7, little-endian (armv7)", armv7}, + {"64-bit MIPS, big-endian (mips64)", mips64}, + {"32-bit MIPS, big-endian (mips)", mips}, + {"64-bit MIPS, little-endian (mips64el)", mips64el}, + {"32-bit MIPS, little-endian (mipsel)", mipsel}, + {"Native / Default (UnknownCPU)", UnknownCPU} + }; + + /*! Returns valid subarchitectures for a given architecture. */ + static std::vector< std::pair > subarchesForArch(HorizonWizard::Arch the_arch) { + if(the_arch == HorizonWizard::ppc64) { + return {std::make_pair("PowerMac", HorizonWizard::ppc64_PowerMac), + std::make_pair("PowerNV", HorizonWizard::ppc64_PowerNV), + std::make_pair("pSeries", HorizonWizard::ppc64_pSeries)}; + } + + return {std::make_pair("None", HorizonWizard::NoSubarch)}; + } + enum PackageType { Standard, Mobile, @@ -151,8 +177,10 @@ public: * @example distfiles.adelielinux.org */ std::string mirror_domain; - /*! The version of Adélie to install. Typically "1.0". */ + /*! The version of Adélie to install. Typically "stable". */ std::string version; + /*! The repositories to use. If empty, use defaults. */ + QStringList repositories; /*! The signing keys to use. If empty, use defaults. */ QStringList signing_keys; /*! The architecture being installed. */ diff --git a/ui/qt5/intropage.cc b/ui/qt5/intropage.cc index ab21657..94e222d 100644 --- a/ui/qt5/intropage.cc +++ b/ui/qt5/intropage.cc @@ -11,6 +11,7 @@ */ #include "intropage.hh" +#include "advoptsdialog.hh" #include #ifdef HAS_INSTALL_ENV @@ -36,6 +37,12 @@ IntroPage::IntroPage(QWidget *parent) : HorizonWizardPage(parent) { "

For more information about the installfile format and syntax, see the Adélie Linux Installation Handbook.

")); descLabel->setOpenExternalLinks(true); descLabel->setTextFormat(Qt::RichText); + + toolButton = new QPushButton(tr("&Advanced Options..."), this); + connect(toolButton, &QPushButton::clicked, [this](bool) { + AdvOptsDialog dialog(horizonWizard(), this); + dialog.exec(); + }); #else /* HAS_INSTALL_ENV */ QMenu *toolMenu; toolButton = new QPushButton(tr("Launch &Tool..."), this); @@ -56,6 +63,10 @@ IntroPage::IntroPage(QWidget *parent) : HorizonWizardPage(parent) { p->start("netsurf-gtk3", QStringList()); horizonWizard()->tools.push_back(p); }); + connect(toolMenu->addAction("&Advanced Options"), &QAction::triggered, [this](void) { + AdvOptsDialog dialog(horizonWizard(), this); + dialog.exec(); + }); toolButton->setMenu(toolMenu); descLabel = new QLabel( @@ -75,9 +86,7 @@ IntroPage::IntroPage(QWidget *parent) : HorizonWizardPage(parent) { layout = new QVBoxLayout; layout->addWidget(descLabel); -#ifdef HAS_INSTALL_ENV layout->addStretch(); layout->addWidget(toolButton, 0, Qt::AlignCenter); -#endif /* HAS_INSTALL_ENV */ setLayout(layout); } diff --git a/ui/qt5/intropage.hh b/ui/qt5/intropage.hh index 5733985..aedb106 100644 --- a/ui/qt5/intropage.hh +++ b/ui/qt5/intropage.hh @@ -13,9 +13,7 @@ #ifndef INTROPAGE_HH #define INTROPAGE_HH -#ifdef HAS_INSTALL_ENV #include -#endif /* HAS_INSTALL_ENV */ #include "horizonwizardpage.hh" @@ -23,10 +21,8 @@ class IntroPage : public HorizonWizardPage { public: IntroPage(QWidget *parent = nullptr); -#ifdef HAS_INSTALL_ENV private: QPushButton *toolButton; -#endif /* HAS_INSTALL_ENV */ }; #endif /* !INTROPAGE_HH */ -- cgit v1.2.3-60-g2f50