From 76a75bb104e9cb8eb36b8c4081aadebad4f75da8 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 7 Feb 2020 20:50:13 -0600 Subject: Qt UI: Factor out steps to StepProgressWidget --- ui/qt5/CMakeLists.txt | 2 + ui/qt5/netdhcppage.cc | 53 +++++---------------- ui/qt5/netdhcppage.hh | 6 +-- ui/qt5/runner/executepage.cc | 100 +++++---------------------------------- ui/qt5/runner/executepage.hh | 19 +------- ui/qt5/stepprogresswidget.cc | 110 +++++++++++++++++++++++++++++++++++++++++++ ui/qt5/stepprogresswidget.hh | 66 ++++++++++++++++++++++++++ 7 files changed, 207 insertions(+), 149 deletions(-) create mode 100644 ui/qt5/stepprogresswidget.cc create mode 100644 ui/qt5/stepprogresswidget.hh (limited to 'ui') diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt index ca3ef67..b536dcb 100644 --- a/ui/qt5/CMakeLists.txt +++ b/ui/qt5/CMakeLists.txt @@ -7,6 +7,7 @@ set(UI_SOURCES horizonhelpwindow.cc main.cc ${CMAKE_SOURCE_DIR}/3rdparty/Section.cpp + stepprogresswidget.cc useraccountwidget.cc avatardialog.cc crypt_sha512.c @@ -32,6 +33,7 @@ set(UI_SOURCES set(RUN_QT_SOURCES horizonhelpwindow.cc horizonwizardpage.cc + stepprogresswidget.cc runner/main.cc runner/executorwizard.cc runner/executepage.cc diff --git a/ui/qt5/netdhcppage.cc b/ui/qt5/netdhcppage.cc index 44422f4..5ada162 100644 --- a/ui/qt5/netdhcppage.cc +++ b/ui/qt5/netdhcppage.cc @@ -23,24 +23,12 @@ NetDHCPPage::NetDHCPPage(QWidget *parent) : HorizonWizardPage(parent) { setTitle(tr("Automatic Network Configuration")); loadWatermark("network"); - QLabel *overall = new QLabel(tr("Please wait while System Installation performs the following tasks:")); - overall->setWordWrap(true); information = new QLabel; information->setWordWrap(true); - addrStatus = new QLabel; - address = new QLabel(tr("Obtain a network address")); - address->setWordWrap(true); - inetStatus = new QLabel; - inet = new QLabel(tr("Check Internet connectivity")); - inet->setWordWrap(true); - - QGridLayout *progressLayout = new QGridLayout; - progressLayout->addWidget(addrStatus, 0, 0); - progressLayout->addWidget(address, 0, 1); - progressLayout->addWidget(inetStatus, 1, 0); - progressLayout->addWidget(inet, 1, 1); - progressLayout->setColumnStretch(1, 100); + progress = new StepProgressWidget; + progress->addStep(tr("Obtain a network address")); + progress->addStep(tr("Check Internet connectivity")); logButton = new QPushButton(tr("Review DHCP Log")); logButton->setHidden(true); @@ -52,9 +40,7 @@ NetDHCPPage::NetDHCPPage(QWidget *parent) : HorizonWizardPage(parent) { }); QVBoxLayout *overallLayout = new QVBoxLayout(this); - overallLayout->addWidget(overall); - overallLayout->addSpacing(40); - overallLayout->addLayout(progressLayout); + overallLayout->addWidget(progress); overallLayout->addSpacing(40); overallLayout->addWidget(information); overallLayout->addWidget(logButton, 0, Qt::AlignCenter); @@ -68,7 +54,7 @@ void NetDHCPPage::startDHCP() { "-j", "/var/log/horizon/dhcpcd.log", iface}); connect(dhcpcd, &QProcess::errorOccurred, [=](QProcess::ProcessError error) { - addrStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + progress->setStepStatus(0, StepProgressWidget::Failed); if(error == QProcess::FailedToStart) { information->setText(tr("The Installation Environment is missing a critical component. dhcpcd could not be loaded.")); logButton->setHidden(true); @@ -84,16 +70,11 @@ void NetDHCPPage::startDHCP() { void NetDHCPPage::dhcpFinished(int exitcode) { if(exitcode != 0) { - addrStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + progress->setStepStatus(0, StepProgressWidget::Failed); information->setText(tr("The system could not obtain an address.")); logButton->setHidden(false); } else { - addrStatus->setPixmap(loadDPIAwarePixmap("status-success", ".svg")); - inetStatus->setPixmap(loadDPIAwarePixmap("status-current", ".svg")); - QFont addrFont = address->font(); - inet->setFont(addrFont); - addrFont.setBold(false); - address->setFont(addrFont); + progress->stepPassed(0); checkInet(); } } @@ -110,7 +91,7 @@ void NetDHCPPage::inetFinished() { assert(inetReply); if(inetReply->error()) { - inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + progress->setStepStatus(1, StepProgressWidget::Failed); information->setText(tr("Couldn't connect to %1: %2") .arg(QString::fromStdString(horizonWizard()->mirror_domain)) .arg(inetReply->errorString())); @@ -121,7 +102,7 @@ void NetDHCPPage::inetFinished() { const QVariant redirUrl = inetReply->attribute(QNetworkRequest::RedirectionTargetAttribute); if(!redirUrl.isNull()) { - inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + progress->setStepStatus(1, StepProgressWidget::Failed); /* XXX TODO BAD UNIMPLEMENTED !!!! LOOK AT ME DO NOT RELEASE YET !!!! */ information->setText(tr("Received redirect to %2 while connecting to %1." "God help us if we don't ship Otter Browser and have to handle captive portals with QtWebKitWidgets.") @@ -137,7 +118,7 @@ void NetDHCPPage::inetFinished() { result[2] != '\n') { QString res_str(result.left(512)); if(result.size() > 512) res_str += "..."; - inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + progress->setStepStatus(1, StepProgressWidget::Failed); information->setText(tr("Received unexpected %3 byte reply from %1: %2") .arg(QString::fromStdString(horizonWizard()->mirror_domain)) .arg(res_str).arg(result.size())); @@ -146,10 +127,7 @@ void NetDHCPPage::inetFinished() { return; } - inetStatus->setPixmap(loadDPIAwarePixmap("status-success", ".svg")); - QFont inetFont = inet->font(); - inetFont.setBold(false); - inet->setFont(inetFont); + progress->stepPassed(1); information->setText(tr("Your computer has successfully connected to the network. You may now proceed.")); @@ -160,14 +138,7 @@ void NetDHCPPage::inetFinished() { void NetDHCPPage::initializePage() { assert(!horizonWizard()->chosen_auto_iface.empty()); - addrStatus->setPixmap(loadDPIAwarePixmap("status-current", ".svg")); - inetStatus->clear(); - - QFont addrFont = address->font(); - addrFont.setBold(true); - address->setFont(addrFont); - addrFont.setBold(false); - inet->setFont(addrFont); + progress->setStepStatus(0, StepProgressWidget::InProgress); startDHCP(); } diff --git a/ui/qt5/netdhcppage.hh b/ui/qt5/netdhcppage.hh index 792cddd..0d54ba5 100644 --- a/ui/qt5/netdhcppage.hh +++ b/ui/qt5/netdhcppage.hh @@ -14,6 +14,7 @@ #define NETDHCPPAGE_HH #include "horizonwizardpage.hh" +#include "stepprogresswidget.hh" #include #include @@ -27,10 +28,7 @@ public: void initializePage(); bool isComplete() const; private: - QLabel *addrStatus; - QLabel *address; - QLabel *inetStatus; - QLabel *inet; + StepProgressWidget *progress; QLabel *information; QPushButton *logButton; diff --git a/ui/qt5/runner/executepage.cc b/ui/qt5/runner/executepage.cc index 6338e26..a5ed839 100644 --- a/ui/qt5/runner/executepage.cc +++ b/ui/qt5/runner/executepage.cc @@ -25,55 +25,23 @@ ExecutePage::ExecutePage(QWidget *parent) : HorizonWizardPage(parent) { loadWatermark("intro"); failed = false; - QLabel *descLabel = new QLabel(tr("Please wait while System Installation performs the following tasks:")); - descLabel->setWordWrap(true); - - prepareStatus = new QLabel; - prepare = new QLabel(tr("Prepare installation")); - validateStatus = new QLabel; - validate = new QLabel(tr("Validate installation")); - diskStatus = new QLabel; - disk = new QLabel(tr("Configure hard disk(s)")); - preMetaStatus = new QLabel; - preMeta = new QLabel(tr("Initial configuration")); - netStatus = new QLabel; - net = new QLabel(tr("Networking configuration")); - pkgStatus = new QLabel; - pkg = new QLabel(tr("Install software")); - postMetaStatus = new QLabel; - postMeta = new QLabel(tr("Final configuration")); - - QGridLayout *progressLayout = new QGridLayout; - progressLayout->addWidget(prepareStatus, 0, 0); - progressLayout->addWidget(prepare, 0, 1); - progressLayout->addWidget(validateStatus, 1, 0); - progressLayout->addWidget(validate, 1, 1); - progressLayout->addWidget(diskStatus, 2, 0); - progressLayout->addWidget(disk, 2, 1); - progressLayout->addWidget(preMetaStatus, 3, 0); - progressLayout->addWidget(preMeta, 3, 1); - progressLayout->addWidget(netStatus, 4, 0); - progressLayout->addWidget(net, 4, 1); - progressLayout->addWidget(pkgStatus, 5, 0); - progressLayout->addWidget(pkg, 5, 1); - progressLayout->addWidget(postMetaStatus, 6, 0); - progressLayout->addWidget(postMeta, 6, 1); - progressLayout->setColumnStretch(1, 100); - - normalFont = validate->font(); - boldFont = normalFont; - boldFont.setBold(true); + progress = new StepProgressWidget; + progress->addStep(tr("Prepare installation")); + progress->addStep(tr("Validate installation")); + progress->addStep(tr("Configure hard disk(s)")); + progress->addStep(tr("Initial configuration")); + progress->addStep(tr("Networking configuration")); + progress->addStep(tr("Install software")); + progress->addStep(tr("Final configuration")); QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(descLabel); - mainLayout->addStretch(); - mainLayout->addLayout(progressLayout); + mainLayout->addWidget(progress); mainLayout->addStretch(); setLayout(mainLayout); finishTimer = new QTimer(this); - finishTimer->setInterval(1500); + finishTimer->setInterval(5000); finishTimer->setSingleShot(true); connect(finishTimer, &QTimer::timeout, [=]{ wizard()->next(); @@ -108,58 +76,16 @@ ExecutePage::Phase ExecutePage::stepToPhase(QString step) { return Prepare; } -void ExecutePage::labelsForPhase(Phase phase, QLabel **icon, QLabel **text) { - switch(phase) { - case Prepare: - *icon = prepareStatus; - *text = prepare; - break; - case Validate: - *icon = validateStatus; - *text = validate; - break; - case Disk: - *icon = diskStatus; - *text = disk; - break; - case PreMeta: - *icon = preMetaStatus; - *text = preMeta; - break; - case Net: - *icon = netStatus; - *text = net; - break; - case Pkg: - *icon = pkgStatus; - *text = pkg; - break; - case PostMeta: - *icon = postMetaStatus; - *text = postMeta; - break; - } -} - void ExecutePage::markRunning(Phase phase) { - QLabel *icon, *text; - labelsForPhase(phase, &icon, &text); - icon->setPixmap(loadDPIAwarePixmap("status-current", ".svg")); - text->setFont(boldFont); + progress->setStepStatus(phase, StepProgressWidget::InProgress); } void ExecutePage::markFinished(Phase phase) { - QLabel *icon, *text; - labelsForPhase(phase, &icon, &text); - icon->setPixmap(loadDPIAwarePixmap("status-success", ".svg")); - text->setFont(normalFont); + progress->setStepStatus(phase, StepProgressWidget::Finished); } void ExecutePage::markFailed(Phase phase) { - QLabel *icon, *text; - labelsForPhase(phase, &icon, &text); - icon->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); - text->setFont(boldFont); + progress->setStepStatus(phase, StepProgressWidget::Failed); failed = true; } diff --git a/ui/qt5/runner/executepage.hh b/ui/qt5/runner/executepage.hh index 57d38da..01289ff 100644 --- a/ui/qt5/runner/executepage.hh +++ b/ui/qt5/runner/executepage.hh @@ -14,6 +14,7 @@ #define EXECUTEPAGE_HH #include "../horizonwizardpage.hh" +#include "../stepprogresswidget.hh" #include #include @@ -37,22 +38,7 @@ public: Phase currentPhase() { return this->current; } private: - QLabel *prepareStatus; - QLabel *prepare; - QLabel *validateStatus; - QLabel *validate; - QLabel *diskStatus; - QLabel *disk; - QLabel *preMetaStatus; - QLabel *preMeta; - QLabel *netStatus; - QLabel *net; - QLabel *pkgStatus; - QLabel *pkg; - QLabel *postMetaStatus; - QLabel *postMeta; - - QFont normalFont, boldFont; + StepProgressWidget *progress; QProcess *executor; QTimer *finishTimer; QFile log; @@ -61,7 +47,6 @@ private: bool failed; Phase stepToPhase(QString step); - void labelsForPhase(Phase phase, QLabel **icon, QLabel **text); void markRunning(Phase phase); void markFinished(Phase phase); void markFailed(Phase phase); diff --git a/ui/qt5/stepprogresswidget.cc b/ui/qt5/stepprogresswidget.cc new file mode 100644 index 0000000..b6e1921 --- /dev/null +++ b/ui/qt5/stepprogresswidget.cc @@ -0,0 +1,110 @@ +/* + * stepprogresswidget.cc - + * Implementation of a widget for displaying progress through a series of steps + * 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 "stepprogresswidget.hh" + +#include "horizonwizardpage.hh" + +#include + +StepProgressWidget::StepProgressWidget(QWidget *parent) : QWidget(parent) { + overview = new QLabel(tr("Please wait while System Installation " + "performs the following tasks:")); + overview->setWordWrap(true); + + /* Initialise the normal and bold fonts using the overview label. */ + QFont myFont = overview->font(); + myFont.setBold(false); + normalFont = myFont; + myFont.setBold(true); + boldFont = myFont; + + stepGrid = new QGridLayout; + stepGrid->setColumnStretch(1, 100); + + QVBoxLayout *overallLayout = new QVBoxLayout; + overallLayout->addWidget(overview); + overallLayout->addSpacing(40); + overallLayout->addLayout(stepGrid); + setLayout(overallLayout); +} + +QString StepProgressWidget::overviewText() { + return overview->text(); +} + +void StepProgressWidget::setOverviewText(QString text) { + overview->setText(text); +} + +int16_t StepProgressWidget::addStep(QString stepInfo) { + QLabel *status = new QLabel; + QLabel *info = new QLabel(stepInfo); + + statuses.push_back(status); + infos.push_back(info); + + int16_t row = infos.size(); + + stepGrid->addWidget(status, row, 0); + stepGrid->addWidget(info, row, 1); + + return row; +} + +QPixmap StepProgressWidget::loadDPIAwarePixmap(QString pixmap, QString type) { + QString path = ":/wizard_pixmaps/resources/"; + path += pixmap; + path += "-"; + + if(this->devicePixelRatioF() <= 1.0) { + path += "low"; + } else { + path += "high"; + } + + path += type; + return QPixmap(path); +} + +void StepProgressWidget::setStepStatus(int16_t step, Status status) { + QLabel *stat = statuses.at(step); + QLabel *info = infos.at(step); + + switch(status) { + case NotStarted: + stat->clear(); + info->setFont(normalFont); + break; + case InProgress: + stat->setPixmap(loadDPIAwarePixmap("status-current", ".svg")); + info->setFont(boldFont); + break; + case Finished: + stat->setPixmap(loadDPIAwarePixmap("status-success", ".svg")); + info->setFont(normalFont); + break; + case Failed: + stat->setPixmap(loadDPIAwarePixmap("status-issue", ".svg")); + info->setFont(boldFont); + break; + } +} + +void StepProgressWidget::stepPassed(int16_t step) { + setStepStatus(step, Finished); + + if(step + 1 < statuses.size()) { + setStepStatus(step + 1, InProgress); + } +} diff --git a/ui/qt5/stepprogresswidget.hh b/ui/qt5/stepprogresswidget.hh new file mode 100644 index 0000000..07f2979 --- /dev/null +++ b/ui/qt5/stepprogresswidget.hh @@ -0,0 +1,66 @@ +/* + * stepprogresswidget.hh - + * Interface for a widget for displaying progress through a series of steps + * 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 STEPPROGRESSWIDGET_HH +#define STEPPROGRESSWIDGET_HH + +#include +#include +#include + +class StepProgressWidget : public QWidget { +public: + enum Status { + NotStarted, + InProgress, + Finished, + Failed + }; + + StepProgressWidget(QWidget *parent = nullptr); + + /*! Returns the current overview text. */ + QString overviewText(); + /*! Sets a custom overview text for the operations being performed. */ + void setOverviewText(QString overview); + + /*! Add a step to this progress widget. */ + int16_t addStep(QString stepInfo); + /*! Set the status of a step. */ + void setStepStatus(int16_t step, Status status); + /*! Sets the status of +step+ as Finished, and the following step + * InProgress. This is a short hand for: + * + * setStepStatus(step, Finished); + * setStepStatus(step + 1, InProgress); + */ + void stepPassed(int16_t step); +private: + /*! The overview text widget */ + QLabel *overview; + + /*! Grid layout with the steps */ + QGridLayout *stepGrid; + + /*! All the step status icons */ + QVector statuses; + /*! All the step info labels */ + QVector infos; + + /*! The fonts used for infos */ + QFont normalFont, boldFont; + + QPixmap loadDPIAwarePixmap(QString pixmap, QString type); +}; + +#endif /* !STEPPROGRESSWIDGET_HH */ -- cgit v1.2.3-60-g2f50