From 275e69dfd3f7e0017deef1ec5b262f5af83d75f0 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 22 May 2020 09:38:56 -0500 Subject: Qt UI: Settle on Netsurf, implement Captive Portal support --- ui/qt5/intropage.cc | 6 +++--- ui/qt5/netdhcppage.cc | 43 ++++++++++++++++++++++++++++--------------- ui/qt5/netdhcppage.hh | 2 +- 3 files changed, 32 insertions(+), 19 deletions(-) (limited to 'ui') diff --git a/ui/qt5/intropage.cc b/ui/qt5/intropage.cc index 2cbbbe2..f0c80ee 100644 --- a/ui/qt5/intropage.cc +++ b/ui/qt5/intropage.cc @@ -49,10 +49,10 @@ IntroPage::IntroPage(QWidget *parent) : HorizonWizardPage(parent) { QProcess p; p.execute("partitionmanager"); }); - /*connect(toolMenu->addAction("&Web Browser"), &QAction::triggered, [=](void){ + connect(toolMenu->addAction("&Web Browser"), &QAction::triggered, [=](void){ QProcess p; - p.execute("otter-browser"); - });*/ + p.execute("netsurf-gtk"); + }); toolButton->setMenu(toolMenu); descLabel = new QLabel( diff --git a/ui/qt5/netdhcppage.cc b/ui/qt5/netdhcppage.cc index ed4d394..5a16af2 100644 --- a/ui/qt5/netdhcppage.cc +++ b/ui/qt5/netdhcppage.cc @@ -40,11 +40,20 @@ NetDHCPPage::NetDHCPPage(QWidget *parent) : HorizonWizardPage(parent) { logview.exec(); }); + authButton = new QPushButton(tr("Authenticate")); + authButton->setHidden(true); + authButton->setWhatsThis(tr("Opens a browser window where you can authenticate to this network.")); + connect(authButton, &QPushButton::clicked, [=] { + QProcess p; + p.execute("netsurf-gtk", {"http://distfiles.adelielinux.org/horizon.txt"}); + }); + QVBoxLayout *overallLayout = new QVBoxLayout(this); overallLayout->addWidget(progress); overallLayout->addSpacing(40); overallLayout->addWidget(information); overallLayout->addWidget(logButton, 0, Qt::AlignCenter); + overallLayout->addWidget(authButton, 0, Qt::AlignCenter); } void NetDHCPPage::startDHCP() { @@ -89,6 +98,9 @@ void NetDHCPPage::checkInet() { } void NetDHCPPage::inetFinished() { + QVariant redirUrl; + QByteArray result; + assert(inetReply); if(inetReply->error()) { @@ -96,25 +108,22 @@ void NetDHCPPage::inetFinished() { information->setText(tr("Couldn't connect to %1: %2") .arg(QString::fromStdString(horizonWizard()->mirror_domain)) .arg(inetReply->errorString())); - inetReply->deleteLater(); - inetReply = nullptr; - return; + goto cleanReply; } - const QVariant redirUrl = inetReply->attribute(QNetworkRequest::RedirectionTargetAttribute); + redirUrl = inetReply->attribute(QNetworkRequest::RedirectionTargetAttribute); if(!redirUrl.isNull()) { - 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.") + progress->stepPassed(1); + information->setText(tr("Received redirect to %2 while connecting to %1. " + "You may need to authenticate to this network before continuing. " + "Choose 'Authenticate' and close the browser window when you have successfully connected.") .arg(QString::fromStdString(horizonWizard()->mirror_domain)) .arg(redirUrl.toUrl().toString())); - inetReply->deleteLater(); - inetReply = nullptr; - return; + authButton->setHidden(false); + goto goOnline; } - QByteArray result = inetReply->readAll(); + result = inetReply->readAll(); if(result.size() != 3 || result[0] != 'O' || result[1] != 'K' || result[2] != '\n') { QString res_str(result.left(512)); @@ -123,17 +132,21 @@ void NetDHCPPage::inetFinished() { 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; + goto goOnline; } progress->stepPassed(1); information->setText(tr("Your computer has successfully connected to the network. You may now proceed.")); +goOnline: online = true; emit completeChanged(); + +cleanReply: + inetReply->deleteLater(); + inetReply = nullptr; + return; } void NetDHCPPage::initializePage() { diff --git a/ui/qt5/netdhcppage.hh b/ui/qt5/netdhcppage.hh index 0d54ba5..5d0f3fd 100644 --- a/ui/qt5/netdhcppage.hh +++ b/ui/qt5/netdhcppage.hh @@ -30,7 +30,7 @@ public: private: StepProgressWidget *progress; QLabel *information; - QPushButton *logButton; + QPushButton *logButton, *authButton; QNetworkAccessManager qnam; QNetworkReply *inetReply; -- cgit v1.2.3-60-g2f50