summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-15 14:36:03 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-15 14:36:03 -0600
commit5967de4afb4e00f136baab49cacd11b7f9b725bb (patch)
tree96b2c89aae3bded09c230b1a8d39973d746d6c71 /ui
parent77a4ad101732fa77ff7253bc6bda06c180a9fe2a (diff)
downloadhorizon-5967de4afb4e00f136baab49cacd11b7f9b725bb.tar.gz
horizon-5967de4afb4e00f136baab49cacd11b7f9b725bb.tar.bz2
horizon-5967de4afb4e00f136baab49cacd11b7f9b725bb.tar.xz
horizon-5967de4afb4e00f136baab49cacd11b7f9b725bb.zip
Qt UI: Add UI.Network.Automatic page and logic
Diffstat (limited to 'ui')
-rw-r--r--ui/CMakeLists.txt2
-rw-r--r--ui/qt5/CMakeLists.txt3
-rw-r--r--ui/qt5/horizon.qrc1
-rw-r--r--ui/qt5/horizonwizard.cc4
-rw-r--r--ui/qt5/netdhcppage.cc173
-rw-r--r--ui/qt5/netdhcppage.hh48
-rw-r--r--ui/qt5/networkifacepage.cc13
-rw-r--r--ui/qt5/networkifacepage.hh5
-rw-r--r--ui/qt5/resources/network-dhcp-help.txt15
9 files changed, 258 insertions, 6 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt
index 597de26..628c9fc 100644
--- a/ui/CMakeLists.txt
+++ b/ui/CMakeLists.txt
@@ -1,4 +1,4 @@
-find_package(Qt5 COMPONENTS Widgets)
+find_package(Qt5 COMPONENTS Network Widgets)
IF(Qt5_FOUND)
option(BUILD_QT "Build the Qt 5 user interface" ON)
diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt
index af7fd82..a5c88ab 100644
--- a/ui/qt5/CMakeLists.txt
+++ b/ui/qt5/CMakeLists.txt
@@ -12,12 +12,13 @@ set(UI_SOURCES
networkingpage.cc
networkifacepage.cc
netsimplewifipage.cc
+ netdhcppage.cc
datetimepage.cc
hostnamepage.cc
horizon.qrc)
add_executable(horizon-qt5 ${UI_SOURCES})
-target_link_libraries(horizon-qt5 Qt5::Widgets)
+target_link_libraries(horizon-qt5 Qt5::Network Qt5::Widgets)
install(TARGETS horizon-qt5 DESTINATION bin)
diff --git a/ui/qt5/horizon.qrc b/ui/qt5/horizon.qrc
index 9af8207..43e8475 100644
--- a/ui/qt5/horizon.qrc
+++ b/ui/qt5/horizon.qrc
@@ -19,6 +19,7 @@
<file>resources/partition-help.txt</file>
<file>resources/network-start-help.txt</file>
<file>resources/network-iface-help.txt</file>
+ <file>resources/network-dhcp-help.txt</file>
<file>resources/datetime-help.txt</file>
<file>resources/hostname-help.txt</file>
<file>resources/packages-simple-help.txt</file>
diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc
index 4eaddb5..edfc9c2 100644
--- a/ui/qt5/horizonwizard.cc
+++ b/ui/qt5/horizonwizard.cc
@@ -31,6 +31,7 @@
#include "networkingpage.hh"
#include "networkifacepage.hh"
#include "netsimplewifipage.hh"
+#include "netdhcppage.hh"
#include "datetimepage.hh"
#include "hostnamepage.hh"
@@ -48,7 +49,7 @@ static std::map<int, std::string> help_id_map = {
{HorizonWizard::Page_Network_Iface, "network-iface"},
{HorizonWizard::Page_Network_Wireless, "network-wifi"},
{HorizonWizard::Page_Network_CustomAP, "network-wifi-ap"},
- {HorizonWizard::Page_Network_DHCP, "none"},
+ {HorizonWizard::Page_Network_DHCP, "network-dhcp"},
{HorizonWizard::Page_Network_Portal, "network-portal"},
{HorizonWizard::Page_Network_Manual, "network-manual"},
{HorizonWizard::Page_DateTime, "datetime"},
@@ -181,6 +182,7 @@ HorizonWizard::HorizonWizard(QWidget *parent) : QWizard(parent) {
setPage(Page_Network, new NetworkingPage);
setPage(Page_Network_Iface, new NetworkIfacePage);
setPage(Page_Network_Wireless, new NetworkSimpleWirelessPage);
+ setPage(Page_Network_DHCP, new NetDHCPPage);
setPage(Page_DateTime, new DateTimePage);
setPage(Page_Hostname, new HostnamePage);
diff --git a/ui/qt5/netdhcppage.cc b/ui/qt5/netdhcppage.cc
new file mode 100644
index 0000000..bf223f0
--- /dev/null
+++ b/ui/qt5/netdhcppage.cc
@@ -0,0 +1,173 @@
+/*
+ * netdhcppage.cc - Implementation of the UI.Network.Automatic 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
+ */
+
+#include "netdhcppage.hh"
+#include "horizonhelpwindow.hh"
+
+#include <assert.h>
+#include <QGridLayout>
+#include <QProcess>
+#include <QUrl>
+#include <QVBoxLayout>
+
+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:"));
+ information = new QLabel;
+ information->setWordWrap(true);
+
+ addrStatus = new QLabel;
+ address = new QLabel(tr("Obtain a network address"));
+ inetStatus = new QLabel;
+ inet = new QLabel(tr("Check Internet connectivity"));
+
+ 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);
+
+ logButton = new QPushButton(tr("Review DHCP Log"));
+ logButton->setHidden(true);
+ connect(logButton, &QPushButton::clicked, [=]() {
+ QFile logfile("/var/log/horizon/dhcpcd.log");
+ logfile.open(QFile::ReadOnly);
+ HorizonHelpWindow logview(&logfile, this, true);
+ logview.exec();
+ });
+
+ QVBoxLayout *overallLayout = new QVBoxLayout(this);
+ overallLayout->addWidget(overall);
+ overallLayout->addSpacing(40);
+ overallLayout->addLayout(progressLayout);
+ overallLayout->addSpacing(40);
+ overallLayout->addWidget(information);
+ overallLayout->addWidget(logButton, 0, Qt::AlignCenter);
+}
+
+void NetDHCPPage::startDHCP() {
+ QProcess *dhcpcd = new QProcess(this);
+ QString iface(QString::fromStdString(horizonWizard()->chosen_auto_iface));
+ dhcpcd->setProgram("dhcpcd");
+ dhcpcd->setArguments({"-q", "-t", "15", "-n",
+ "-j", "/var/log/horizon/dhcpcd.log", iface});
+ connect(dhcpcd, &QProcess::errorOccurred,
+ [=](QProcess::ProcessError error) {
+ addrStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
+ if(error == QProcess::FailedToStart) {
+ information->setText(tr("The Installation Environment is missing a critical component: dhcpcd could not be run."));
+ } else {
+ information->setText(tr("The system has encountered an internal issue."));
+ logButton->setHidden(false);
+ }
+ });
+ connect(dhcpcd, static_cast<void (QProcess:: *)(int)>(&QProcess::finished),
+ this, &NetDHCPPage::dhcpFinished);
+ dhcpcd->start();
+}
+
+void NetDHCPPage::dhcpFinished(int exitcode) {
+ if(exitcode != 0) {
+ addrStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
+ 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);
+ checkInet();
+ }
+}
+
+void NetDHCPPage::checkInet() {
+ QString url = QString::fromStdString("http://" +
+ horizonWizard()->mirror_domain +
+ "/horizon.txt");
+ inetReply = qnam.get(QNetworkRequest(QUrl(url)));
+ connect(inetReply, &QNetworkReply::finished, this, &NetDHCPPage::inetFinished);
+}
+
+void NetDHCPPage::inetFinished() {
+ assert(inetReply);
+
+ if(inetReply->error()) {
+ inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
+ information->setText(tr("Couldn't connect to %1: %2")
+ .arg(QString::fromStdString(horizonWizard()->mirror_domain))
+ .arg(inetReply->errorString()));
+ inetReply->deleteLater();
+ inetReply = nullptr;
+ return;
+ }
+
+ const QVariant redirUrl = inetReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if(!redirUrl.isNull()) {
+ inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
+ /* 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.")
+ .arg(QString::fromStdString(horizonWizard()->mirror_domain))
+ .arg(redirUrl.toUrl().toString()));
+ inetReply->deleteLater();
+ inetReply = nullptr;
+ return;
+ }
+
+ QByteArray result = inetReply->readAll();
+ if(result.size() != 3 || result[0] != 'O' || result[1] != 'K' ||
+ result[2] != '\n') {
+ QString res_str(result.left(512));
+ if(result.size() > 512) res_str += "...";
+ inetStatus->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
+ information->setText(tr("Received unexpected %3 byte reply from %1: %2")
+ .arg(QString::fromStdString(horizonWizard()->mirror_domain))
+ .arg(res_str).arg(result.size()));
+ inetReply->deleteLater();
+ inetReply = nullptr;
+ return;
+ }
+
+ inetStatus->setPixmap(loadDPIAwarePixmap("status-success", ".svg"));
+ QFont inetFont = inet->font();
+ inetFont.setBold(false);
+ inet->setFont(inetFont);
+
+ information->setText(tr("Your computer has successfully connected to the network. You may now proceed."));
+
+ online = true;
+ emit completeChanged();
+}
+
+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);
+
+ startDHCP();
+}
+
+bool NetDHCPPage::isComplete() const {
+ return online;
+}
diff --git a/ui/qt5/netdhcppage.hh b/ui/qt5/netdhcppage.hh
new file mode 100644
index 0000000..792cddd
--- /dev/null
+++ b/ui/qt5/netdhcppage.hh
@@ -0,0 +1,48 @@
+/*
+ * netdhcppage.hh - Definition of the UI.Network.Automatic 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 NETDHCPPAGE_HH
+#define NETDHCPPAGE_HH
+
+#include "horizonwizardpage.hh"
+
+#include <QLabel>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QPushButton>
+
+class NetDHCPPage : public HorizonWizardPage {
+public:
+ NetDHCPPage(QWidget *parent = nullptr);
+
+ void initializePage();
+ bool isComplete() const;
+private:
+ QLabel *addrStatus;
+ QLabel *address;
+ QLabel *inetStatus;
+ QLabel *inet;
+ QLabel *information;
+ QPushButton *logButton;
+
+ QNetworkAccessManager qnam;
+ QNetworkReply *inetReply;
+
+ bool online = false;
+
+ void startDHCP();
+ void dhcpFinished(int exitcode);
+ void checkInet();
+ void inetFinished();
+};
+
+#endif /* !NETDHCPPAGE_HH */
diff --git a/ui/qt5/networkifacepage.cc b/ui/qt5/networkifacepage.cc
index 4d292fb..3fbd6e5 100644
--- a/ui/qt5/networkifacepage.cc
+++ b/ui/qt5/networkifacepage.cc
@@ -12,6 +12,7 @@
#include "networkifacepage.hh"
#include "horizonwizard.hh"
+#include "netdhcppage.hh"
#include <algorithm>
#include <QDebug>
@@ -96,6 +97,16 @@ int NetworkIfacePage::nextId() const {
case HorizonWizard::Wireless:
return HorizonWizard::Page_Network_Wireless;
default:
- return HorizonWizard::Page_DateTime;
+ return HorizonWizard::Page_Network_DHCP;
}
}
+
+bool NetworkIfacePage::validatePage() {
+ /* What a hack!
+ *
+ * Independent Pages means the DHCP page is never cleaned, even when Back
+ * is chosen. So, we have to do it from here. */
+ horizonWizard()->removePage(HorizonWizard::Page_Network_DHCP);
+ horizonWizard()->setPage(HorizonWizard::Page_Network_DHCP, new NetDHCPPage);
+ return true;
+}
diff --git a/ui/qt5/networkifacepage.hh b/ui/qt5/networkifacepage.hh
index 05b0e2b..d9141e9 100644
--- a/ui/qt5/networkifacepage.hh
+++ b/ui/qt5/networkifacepage.hh
@@ -21,8 +21,9 @@ class NetworkIfacePage : public HorizonWizardPage {
public:
NetworkIfacePage(QWidget *parent = nullptr);
void initializePage() override;
- bool isComplete() const;
- int nextId() const;
+ bool isComplete() const override;
+ int nextId() const override;
+ bool validatePage() override;
private:
QListWidget *ifaceList;
};
diff --git a/ui/qt5/resources/network-dhcp-help.txt b/ui/qt5/resources/network-dhcp-help.txt
new file mode 100644
index 0000000..7e4bad7
--- /dev/null
+++ b/ui/qt5/resources/network-dhcp-help.txt
@@ -0,0 +1,15 @@
+<h2>Automatic Network Configuration</h2>
+
+<p>This page configures your system for network access automatically.</p>
+
+<h3>What should I do if System Installation reports an issue?</h3>
+
+<ul>
+<li>Ensure that all cables are connected firmly to your computer and other
+networking equipment.</li>
+<li>Try restarting your computer and networking equipment.</li>
+<li>If these steps do not resolve your issue, and your network connection
+works on another operating system on your computer, you may contact our
+community at
+<a href="https://help.adelielinux.org/">https://help.adelielinux.org</a>.</li>
+</ul>