diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-05-22 08:50:26 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-05-22 08:50:26 -0500 |
commit | bb58a013f4dc10a359d786ce157d53408fd4fcdd (patch) | |
tree | ca8208a9385fd90682d99ed67b82b55e1c3f5c35 /ui/qt5 | |
parent | a9b35213d330faa3fc551c9a8c3524d519d8466b (diff) | |
download | horizon-bb58a013f4dc10a359d786ce157d53408fd4fcdd.tar.gz horizon-bb58a013f4dc10a359d786ce157d53408fd4fcdd.tar.bz2 horizon-bb58a013f4dc10a359d786ce157d53408fd4fcdd.tar.xz horizon-bb58a013f4dc10a359d786ce157d53408fd4fcdd.zip |
Qt UI: Implement Mount Point selection, the last wizard page
Diffstat (limited to 'ui/qt5')
-rw-r--r-- | ui/qt5/CMakeLists.txt | 4 | ||||
-rw-r--r-- | ui/qt5/horizonwizard.cc | 6 | ||||
-rw-r--r-- | ui/qt5/mountdialog.cc | 106 | ||||
-rw-r--r-- | ui/qt5/mountdialog.hh | 45 | ||||
-rw-r--r-- | ui/qt5/partitionmountpage.cc | 78 | ||||
-rw-r--r-- | ui/qt5/partitionmountpage.hh | 31 |
6 files changed, 269 insertions, 1 deletions
diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt index f8bdb56..934cd70 100644 --- a/ui/qt5/CMakeLists.txt +++ b/ui/qt5/CMakeLists.txt @@ -9,6 +9,7 @@ set(UI_SOURCES ${CMAKE_SOURCE_DIR}/3rdparty/Section.cpp stepprogresswidget.cc subnetbox.cc + mountdialog.cc useraccountwidget.cc avatardialog.cc crypt_sha512.c @@ -51,7 +52,8 @@ IF(INSTALL) LIST(APPEND UI_SOURCES commitpage.cc partitionprobe.cc - partitionpage.cc) + partitionpage.cc + partitionmountpage.cc) ELSE(INSTALL) LIST(APPEND UI_SOURCES writeoutpage.cc) ENDIF(INSTALL) diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc index 161accf..143ae43 100644 --- a/ui/qt5/horizonwizard.cc +++ b/ui/qt5/horizonwizard.cc @@ -47,6 +47,7 @@ extern "C" { #include "partitiondiskpage.hh" #include "partitionchoicepage.hh" #include "partitionmanualpage.hh" +#include "partitionmountpage.hh" #include "networkingpage.hh" #include "networkifacepage.hh" #include "netsimplewifipage.hh" @@ -251,6 +252,9 @@ HorizonWizard::HorizonWizard(QWidget *parent) : QWizard(parent) { setPage(Page_PartitionDisk, new PartitionDiskPage); setPage(Page_PartitionChoose, new PartitionChoicePage); setPage(Page_PartitionManual, new PartitionManualPage); +#ifdef HAS_INSTALL_ENV + setPage(Page_PartitionMount, new PartitionMountPage); +#endif /* HAS_INSTALL_ENV */ setPage(Page_Network, new NetworkingPage); setPage(Page_Network_Iface, new NetworkIfacePage); setPage(Page_Network_Wireless, new NetworkSimpleWirelessPage); @@ -538,6 +542,8 @@ QString HorizonWizard::toHScript() { break; } + part_lines << (dynamic_cast<PartitionMountPage *>(page(Page_PartitionMount)))->mountLines(); + if(chosen_disk.empty()) { lines << part_lines; } else if(!auto_part) { diff --git a/ui/qt5/mountdialog.cc b/ui/qt5/mountdialog.cc new file mode 100644 index 0000000..f986423 --- /dev/null +++ b/ui/qt5/mountdialog.cc @@ -0,0 +1,106 @@ +/* + * mountdialog.cc - Implementation of a dialog for selecting a mount point + * 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 "mountdialog.hh" + +#include <QHBoxLayout> +#include <QLabel> +#include <QLineEdit> +#include <QPushButton> +#include <QVBoxLayout> + +MountDialog::MountDialog(QStringList skipParts, QStringList skipMounts, + HorizonWizard *wizard, QWidget *parent) + : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint) { + setWindowTitle(tr("Choose Partition and Mount Point")); + + QPushButton *ok = new QPushButton(tr("Confirm")); + ok->setEnabled(false); + connect(ok, &QPushButton::clicked, this, &QDialog::accept); + QPushButton *cancel = new QPushButton(tr("Cancel")); + connect(cancel, &QPushButton::clicked, this, &QDialog::reject); + + QVBoxLayout *buttonLayout = new QVBoxLayout; + buttonLayout->setAlignment(Qt::AlignTop); + buttonLayout->addWidget(ok); + buttonLayout->addWidget(cancel); + +#ifdef HAS_INSTALL_ENV + QStringList partitions; + + for(const auto &disk : wizard->disks) { + if(disk.has_fs()) { + partitions << QString::fromStdString(disk.node()); + } else if(disk.has_label()) { + for(const auto &part : disk.partitions()) { + partitions << QString::fromStdString(part.node()); + } + } + } + + QSet<QString> parts = partitions.toSet().subtract(skipParts.toSet()); + partitions = parts.toList(); + partitions.sort(); + + partList = new QListWidget; + partList->setWhatsThis(tr("A list of the partitions available on this system.")); + partList->addItems(partitions); + connect(partList, &QListWidget::currentItemChanged, [=] { + ok->setEnabled(partList->currentItem() != nullptr); + }); +#else + partInput = new QLineEdit; + partInput->setWhatsThis(tr("Input the name of a partition, such as /dev/sda1, here.")); +#endif + + QStringList pathCandidates = {"/", "/home", "/opt", "/srv", "/usr", + "/usr/local", "/var", "/var/db", "/var/log"}; + QSet<QString> paths = pathCandidates.toSet().subtract(skipMounts.toSet()); + pathCandidates = paths.toList(); + pathCandidates.sort(); + + pathInput = new QComboBox; + pathInput->setEditable(true); + pathInput->setWhatsThis(tr("Select where the partition will be mounted.")); + pathInput->addItems(pathCandidates); + + QVBoxLayout *controlLayout = new QVBoxLayout; + controlLayout->addWidget(new QLabel(tr("Partition"))); + controlLayout->addWidget(partList); + controlLayout->addWidget(new QLabel(tr("will be mounted on"))); + controlLayout->addWidget(pathInput); + + QHBoxLayout *mainBox = new QHBoxLayout; + mainBox->addLayout(controlLayout); + mainBox->addLayout(buttonLayout); + + setLayout(mainBox); +} + +QString MountDialog::partition() const { + assert(partList->currentItem() != nullptr); + return partList->currentItem()->text(); +} + +void MountDialog::setPartition(const QString &part) { + QList<QListWidgetItem *> candidate = partList->findItems(part, Qt::MatchExactly); + if(candidate.empty()) return; + partList->setCurrentItem(candidate.at(0)); +} + +QString MountDialog::mountPoint() const { + return pathInput->currentText(); +} + +void MountDialog::setMountPoint(const QString &path) { + pathInput->setCurrentText(path); +} diff --git a/ui/qt5/mountdialog.hh b/ui/qt5/mountdialog.hh new file mode 100644 index 0000000..f701438 --- /dev/null +++ b/ui/qt5/mountdialog.hh @@ -0,0 +1,45 @@ +/* + * mountdialog.hh - Definition of a dialog for selecting a mount point + * 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 MOUNTDIALOG_HH +#define MOUNTDIALOG_HH + +#include "horizonwizard.hh" + +#include <QComboBox> +#include <QDialog> +#ifdef HAS_INSTALL_ENV +#include <QListWidget> +#else /* !HAS_INSTALL_ENV */ +#include <QLineEdit> +#endif /* HAS_INSTALL_ENV */ + +class MountDialog : public QDialog { +public: + explicit MountDialog(QStringList skipParts, QStringList skipMounts, + HorizonWizard *wizard, QWidget *parent = nullptr); + + QString partition() const; + void setPartition(const QString &part); + QString mountPoint() const; + void setMountPoint(const QString &path); +private: +#ifdef HAS_INSTALL_ENV + QListWidget *partList; +#else /* !HAS_INSTALL_ENV */ + QLineEdit *partInput; +#endif /* HAS_INSTALL_ENV */ + QComboBox *pathInput; + QString path; +}; + +#endif /* !MOUNTDIALOG_HH */ diff --git a/ui/qt5/partitionmountpage.cc b/ui/qt5/partitionmountpage.cc index 687d603..7631d0b 100644 --- a/ui/qt5/partitionmountpage.cc +++ b/ui/qt5/partitionmountpage.cc @@ -11,9 +11,87 @@ */ #include "partitionmountpage.hh" +#include "mountdialog.hh" + +#include <functional> +#include <QDebug> +#include <QHBoxLayout> +#include <QVBoxLayout> PartitionMountPage::PartitionMountPage(QWidget *parent) : HorizonWizardPage(parent) { loadWatermark("disk"); setTitle(tr("Set Mount Points")); + + mountList = new QListWidget; + + QVBoxLayout *buttonLayout = new QVBoxLayout; + addMountButton = new QPushButton(tr("&Add Mount...")); + addMountButton->setIcon(QIcon::fromTheme("list-add")); + connect(addMountButton, &QPushButton::clicked, [=] { + QStringList parts, paths; + for(const auto &mount : mountList->findItems("", Qt::MatchContains)) { + parts << mount->data(Qt::UserRole + 1).toString(); + paths << mount->data(Qt::UserRole + 2).toString(); + } + MountDialog md(parts, paths, horizonWizard()); + if(md.exec() == QDialog::Accepted) { + QListWidgetItem *mount = new QListWidgetItem; + QString part = md.partition(); + QString path = md.mountPoint(); + mount->setText(tr("%1 on %2").arg(part).arg(path)); + mount->setIcon(QIcon::fromTheme("drive-harddisk")); + mount->setData(Qt::UserRole + 1, part); + mount->setData(Qt::UserRole + 2, path); + + mountList->addItem(mount); + } + }); + buttonLayout->addWidget(addMountButton); + + delMountButton = new QPushButton(tr("&Remove Mount")); + delMountButton->setEnabled(false); + delMountButton->setIcon(QIcon::fromTheme("list-remove")); + connect(delMountButton, &QPushButton::clicked, [=] { + delete mountList->takeItem(mountList->currentRow()); + }); + buttonLayout->addWidget(delMountButton); + + /*rescanButton = new QPushButton(tr("Re&scan Devices")); + rescanButton->setIcon(QIcon::fromTheme("view-refresh")); + connect(rescanButton, &QPushButton::clicked, [=] { + + }); + buttonLayout->addWidget(rescanButton);*/ + + connect(mountList, &QListWidget::currentItemChanged, [=] { + delMountButton->setEnabled(mountList->currentItem() != nullptr); + }); + + std::function<void()> listRowsChanged { [=] { + emit completeChanged(); + } }; + connect(mountList->model(), &QAbstractItemModel::rowsInserted, listRowsChanged); + connect(mountList->model(), &QAbstractItemModel::rowsRemoved, listRowsChanged); + + QHBoxLayout *layout = new QHBoxLayout; + layout->addStretch(); + layout->addWidget(mountList); + layout->addLayout(buttonLayout); + layout->addStretch(); + + setLayout(layout); +} + +bool PartitionMountPage::isComplete() const { + return !mountList->findItems(" on /", Qt::MatchEndsWith).isEmpty(); +} + +QStringList PartitionMountPage::mountLines() const { + QStringList lines; + for(const auto &mount : mountList->findItems("", Qt::MatchContains)) { + lines << QString("mount %1 %2").arg(mount->data(Qt::UserRole + 1).toString()) + .arg(mount->data(Qt::UserRole + 2).toString()); + } + return lines; } diff --git a/ui/qt5/partitionmountpage.hh b/ui/qt5/partitionmountpage.hh new file mode 100644 index 0000000..d9a4939 --- /dev/null +++ b/ui/qt5/partitionmountpage.hh @@ -0,0 +1,31 @@ +/* + * partitionmountpage.hh - Definition of the UI.Partition.Install.Mount 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 PARTITIONMOUNTPAGE_HH +#define PARTITIONMOUNTPAGE_HH + +#include "horizonwizardpage.hh" +#include <QListWidget> +#include <QPushButton> + +class PartitionMountPage : public HorizonWizardPage { +public: + PartitionMountPage(QWidget *parent = nullptr); + + bool isComplete() const override; + QStringList mountLines() const; +private: + QListWidget *mountList; + QPushButton *addMountButton, *delMountButton, *rescanButton; +}; + +#endif /* !PARTITIONMOUNTPAGE_HH */ |