From 910848185f3632cbd8b3bb72bf9d8b54ff4d2909 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 16 Feb 2020 23:34:27 -0600 Subject: Qt UI: Add UI.Partition.Install.UserPrompt page --- ui/qt5/CMakeLists.txt | 1 + ui/qt5/horizonwizard.cc | 4 +- ui/qt5/horizonwizard.hh | 6 +- ui/qt5/partitionchoicepage.cc | 128 ++++++++++++++++++++++++++++++++++++++++++ ui/qt5/partitionchoicepage.hh | 41 ++++++++++++++ ui/qt5/partitiondiskpage.cc | 16 +++++- 6 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 ui/qt5/partitionchoicepage.cc create mode 100644 ui/qt5/partitionchoicepage.hh diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt index 0134fcd..92e70ec 100644 --- a/ui/qt5/CMakeLists.txt +++ b/ui/qt5/CMakeLists.txt @@ -17,6 +17,7 @@ set(UI_SOURCES inputpage.cc partitionpage.cc partitiondiskpage.cc + partitionchoicepage.cc networkingpage.cc networkifacepage.cc netsimplewifipage.cc diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc index 6166946..862d2d6 100644 --- a/ui/qt5/horizonwizard.cc +++ b/ui/qt5/horizonwizard.cc @@ -43,6 +43,7 @@ extern "C" { #endif /* NON_LIBRE_FIRMWARE */ #include "partitionpage.hh" #include "partitiondiskpage.hh" +#include "partitionchoicepage.hh" #include "networkingpage.hh" #include "networkifacepage.hh" #include "netsimplewifipage.hh" @@ -212,6 +213,7 @@ HorizonWizard::HorizonWizard(QWidget *parent) : QWizard(parent) { #endif /* NON_LIBRE_FIRMWARE */ setPage(Page_Partition, new PartitionPage); setPage(Page_PartitionDisk, new PartitionDiskPage); + setPage(Page_PartitionChoose, new PartitionChoicePage); setPage(Page_Network, new NetworkingPage); setPage(Page_Network_Iface, new NetworkIfacePage); setPage(Page_Network_Wireless, new NetworkSimpleWirelessPage); @@ -396,7 +398,7 @@ QString HorizonWizard::toHScript() { break; } - if(auto_disk.empty()) { + if(chosen_disk.empty()) { lines << part_lines; } else { /* XXX TODO: examples for thoughts on auto-partition setups are in diff --git a/ui/qt5/horizonwizard.hh b/ui/qt5/horizonwizard.hh index 0b12466..2c253f1 100644 --- a/ui/qt5/horizonwizard.hh +++ b/ui/qt5/horizonwizard.hh @@ -140,10 +140,12 @@ public: /*! The disks present on this computer. */ std::vector disks; #endif + /*! Whether to automatically partition the disk. */ + bool auto_part; /*! Whether to erase the disk when automatically partitioning. */ bool erase; - /*! The disk to partition automatically. */ - std::string auto_disk; + /*! The disk to install to. */ + std::string chosen_disk; /*! The HorizonScript lines describing what to do about partitioning. * If auto_disk is set, this is not used. * Otherwise, this should have any relevant disklabel/partition/fs etc. */ diff --git a/ui/qt5/partitionchoicepage.cc b/ui/qt5/partitionchoicepage.cc new file mode 100644 index 0000000..63317e7 --- /dev/null +++ b/ui/qt5/partitionchoicepage.cc @@ -0,0 +1,128 @@ +/* + * partitionchoicepage.cc - Implementation of UI.Partition.Install.UserPrompt + * horizon-qt5, the Qt 5 user interface for + * Project Horizon + * + * Copyright (c) 2020 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 "partitionchoicepage.hh" + +#include +#include + +PartitionChoicePage::PartitionChoicePage(QWidget *parent) + : HorizonWizardPage(parent) { + loadWatermark("disk"); + setTitle(tr("Choose Partitioning Type")); + + descLabel = new QLabel(tr("Select the method you wish to use for partitioning %1:")); + descLabel->setWordWrap(true); + + eraseButton = new QRadioButton(tr("&Erase and Use Whole Disk")); + eraseButton->setHidden(true); + eraseLabel = new QLabel(tr("The entire disk will be erased and then automatically partitioned.
Warning: This will destroy all existing data on the disk.")); + eraseLabel->setHidden(true); + eraseLabel->setIndent(25); + eraseLabel->setTextFormat(Qt::RichText); + eraseLabel->setWordWrap(true); + + fitInButton = new QRadioButton(tr("Use &Free Space")); + fitInButton->setHidden(true); + fitInLabel = new QLabel(tr("The free space on the disk will be automatically partitioned for use with Adélie. Existing data will be preserved.")); + fitInLabel->setHidden(true); + fitInLabel->setIndent(25); + fitInLabel->setWordWrap(true); + + useExistingButton = new QRadioButton(tr("Use Existing &Partition")); + useExistingButton->setHidden(true); + useExistingLabel = new QLabel(tr("No partitions will be modified. You must select the partition on which you wish to install Adélie.")); + useExistingLabel->setHidden(true); + useExistingLabel->setIndent(25); + useExistingLabel->setWordWrap(true); + + manualButton = new QRadioButton(tr("&Manual")); + manualButton->setHidden(true); + manualLabel = new QLabel(tr("Open a partitioning tool.")); + manualLabel->setHidden(true); + manualLabel->setIndent(25); + manualLabel->setWordWrap(true); + + buttons = new QButtonGroup(this); + buttons->setExclusive(true); + buttons->addButton(eraseButton); + buttons->addButton(fitInButton); + buttons->addButton(useExistingButton); + buttons->addButton(manualButton); + + connect(buttons, QOverload::of(&QButtonGroup::buttonClicked), + this, &PartitionChoicePage::completeChanged); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(descLabel); + layout->addStretch(); + layout->addWidget(eraseButton); + layout->addWidget(eraseLabel); + layout->addStretch(); + layout->addWidget(fitInButton); + layout->addWidget(fitInLabel); + layout->addStretch(); + layout->addWidget(useExistingButton); + layout->addWidget(useExistingLabel); + layout->addStretch(); + layout->addWidget(manualButton); + layout->addWidget(manualLabel); + layout->addStretch(); + setLayout(layout); +} + +void PartitionChoicePage::initializePage() { + Q_ASSERT(horizonWizard()->chosen_disk.size() > 0); + + QString chosen{QString::fromStdString(horizonWizard()->chosen_disk)}; + descLabel->setText(descLabel->text().arg(chosen)); + + /* these options are, as of right now, always available */ + eraseButton->setHidden(false); + eraseLabel->setHidden(false); + manualButton->setHidden(false); + manualLabel->setHidden(false); + + Horizon::DiskMan::Disk *d = nullptr; + for(auto &disk : horizonWizard()->disks) { + if(disk.node() == horizonWizard()->chosen_disk) { + d = &disk; + break; + } + } + + Q_ASSERT(d != nullptr); + if(d->has_label()) { + useExistingButton->setHidden(false); + useExistingLabel->setHidden(false); + + if(d->contiguous_block() > 2000) { + fitInButton->setHidden(false); + fitInLabel->setHidden(false); + } + } + +} + +bool PartitionChoicePage::isComplete() const { + return buttons->checkedButton() != nullptr; +} + +int PartitionChoicePage::nextId() const { + if(buttons->checkedButton() == manualButton) { + return HorizonWizard::Page_PartitionManual; + } else if(buttons->checkedButton() == useExistingButton) { + return HorizonWizard::Page_PartitionMount; + } else { + return HorizonWizard::Page_Network; + } +} diff --git a/ui/qt5/partitionchoicepage.hh b/ui/qt5/partitionchoicepage.hh new file mode 100644 index 0000000..2e879ba --- /dev/null +++ b/ui/qt5/partitionchoicepage.hh @@ -0,0 +1,41 @@ +/* + * partitionchoicepage.hh - Definition of UI.Partition.Install.UserPrompt page + * horizon-qt5, the Qt 5 user interface for + * Project Horizon + * + * Copyright (c) 2020 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 PARTITIONCHOICEPAGE_HH +#define PARTITIONCHOICEPAGE_HH + +#include "horizonwizardpage.hh" + +#include +#include +#include + +class PartitionChoicePage : public HorizonWizardPage { +public: + PartitionChoicePage(QWidget *parent = nullptr); + void initializePage() override; + bool isComplete() const override; + int nextId() const override; +private: + QLabel *descLabel; + QButtonGroup *buttons; + QRadioButton *eraseButton; + QLabel *eraseLabel; + QRadioButton *fitInButton; + QLabel *fitInLabel; + QRadioButton *manualButton; + QLabel *manualLabel; + QRadioButton *useExistingButton; + QLabel *useExistingLabel; +}; + +#endif /* !PARTITIONCHOICEPAGE_HH */ diff --git a/ui/qt5/partitiondiskpage.cc b/ui/qt5/partitiondiskpage.cc index 65a2994..2f7f9e9 100644 --- a/ui/qt5/partitiondiskpage.cc +++ b/ui/qt5/partitiondiskpage.cc @@ -14,6 +14,7 @@ #include #include +#include "partitionchoicepage.hh" QIcon iconForDisk(Horizon::DiskMan::Disk disk) { QString iconName; @@ -44,8 +45,18 @@ PartitionDiskPage::PartitionDiskPage(QWidget *parent) descLabel->setWordWrap(true); diskChooser = new QListWidget; - connect(diskChooser, &QListWidget::currentItemChanged, - this, &PartitionDiskPage::completeChanged); + connect(diskChooser, &QListWidget::currentItemChanged, [=]{ + if(diskChooser->currentItem() != nullptr) { + QVariant itemData = diskChooser->currentItem()->data(Qt::UserRole); + horizonWizard()->chosen_disk = itemData.toString().toStdString(); + + /* ensure that the Choice page receives our new disk information */ + horizonWizard()->removePage(HorizonWizard::Page_PartitionChoose); + horizonWizard()->setPage(HorizonWizard::Page_PartitionChoose, + new PartitionChoicePage); + } + emit completeChanged(); + }); diskChooser->setAutoFillBackground(true); diskChooser->setFrameShape(QFrame::NoFrame); diskChooser->setIconSize(QSize(32, 32)); @@ -72,6 +83,7 @@ void PartitionDiskPage::initializePage() { .arg(disk.contiguous_block()).arg(disk.total_size())}; QListWidgetItem *item = new QListWidgetItem(iconForDisk(disk), name, diskChooser); item->setToolTip(QString::fromStdString(disk.dev_path())); + item->setData(Qt::UserRole, QString::fromStdString(disk.node())); } if(horizonWizard()->disks.size() == 0) { -- cgit v1.2.3-60-g2f50