From 7fe9e61230de11feb2698443105ecb57f4709c23 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 10 Nov 2019 03:54:10 -0600 Subject: Qt UI: Finish implementing UI.Network.ChooseIface and add help doc --- ui/qt5/horizon.qrc | 1 + ui/qt5/networkifacepage.cc | 70 +++++++++++++++++++++++++++++---- ui/qt5/networkifacepage.hh | 6 +++ ui/qt5/resources/network-iface-help.txt | 21 ++++++++++ 4 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 ui/qt5/resources/network-iface-help.txt (limited to 'ui') diff --git a/ui/qt5/horizon.qrc b/ui/qt5/horizon.qrc index b828069..562418c 100644 --- a/ui/qt5/horizon.qrc +++ b/ui/qt5/horizon.qrc @@ -12,6 +12,7 @@ resources/input-help.txt resources/partition-help.txt resources/network-start-help.txt + resources/network-iface-help.txt resources/packages-simple-help.txt diff --git a/ui/qt5/networkifacepage.cc b/ui/qt5/networkifacepage.cc index d8a9655..323bbe2 100644 --- a/ui/qt5/networkifacepage.cc +++ b/ui/qt5/networkifacepage.cc @@ -13,27 +13,45 @@ #include "networkifacepage.hh" #include "horizonwizard.hh" +#ifdef HAS_INSTALL_ENV +# include /* ifreq */ +# include /* ioctl */ +# include /* close */ +#endif + +#include +#include #include #include -#include #include NetworkIfacePage::NetworkIfacePage(QWidget *parent) : HorizonWizardPage(parent) { loadWatermark("network"); setTitle(tr("Multiple Network Interfaces Detected")); + + ifaceList = new QListWidget(this); + connect(ifaceList, &QListWidget::currentRowChanged, [=](int row) { + emit completeChanged(); + if(row == -1) return; + auto iterator = horizonWizard()->interfaces.begin(); + std::advance(iterator, row); + horizonWizard()->chosen_auto_iface = iterator->first; + }); + + ifaceList->setGridSize(QSize(160, 128)); + ifaceList->setIconSize(QSize(96, 96)); + ifaceList->setViewMode(QListView::IconMode); } void NetworkIfacePage::initializePage() { QLabel *descLabel; - QListWidget *ifaceList; QVBoxLayout *layout; descLabel = new QLabel(tr( "Your computer has more than one network interface device. Select the one you wish to use during installation.")); descLabel->setWordWrap(true); - ifaceList = new QListWidget(this); for(auto &iface : horizonWizard()->interfaces) { QIcon ifaceIcon; QString ifaceDevName = QString::fromStdString(iface.first); @@ -58,14 +76,52 @@ void NetworkIfacePage::initializePage() { break; } - new QListWidgetItem(ifaceIcon, ifaceName, ifaceList); + QListWidgetItem *item = new QListWidgetItem(ifaceIcon, ifaceName, + ifaceList); + /* Retrieving the index is always valid, and is not even privileged. */ + struct ifreq request; + int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); + if(my_sock == -1) { + continue; + } + memset(&request, 0, sizeof(request)); + memcpy(&request.ifr_name, iface.first.c_str(), iface.first.size()); + errno = 0; + if(ioctl(my_sock, SIOCGIFHWADDR, &request) != -1) { + char *buf; + asprintf(&buf, "%02X:%02X:%02X:%02X:%02X:%02X", + request.ifr_ifru.ifru_hwaddr.sa_data[0], + request.ifr_ifru.ifru_hwaddr.sa_data[1], + request.ifr_ifru.ifru_hwaddr.sa_data[2], + request.ifr_ifru.ifru_hwaddr.sa_data[3], + request.ifr_ifru.ifru_hwaddr.sa_data[4], + request.ifr_ifru.ifru_hwaddr.sa_data[5]); + item->setToolTip(QString(buf)); + free(buf); + } + ::close(my_sock); } - ifaceList->setGridSize(QSize(160, 128)); - ifaceList->setIconSize(QSize(96, 96)); - ifaceList->setViewMode(QListView::IconMode); layout = new QVBoxLayout; layout->addWidget(descLabel); layout->addWidget(ifaceList); setLayout(layout); } + +bool NetworkIfacePage::isComplete() const { + return ifaceList->currentRow() != -1; +} + +int NetworkIfacePage::nextId() const { + if(ifaceList->currentRow() < 0) return HorizonWizard::Page_Network_Iface; + + auto iterator = horizonWizard()->interfaces.begin(); + std::advance(iterator, ifaceList->currentRow()); + + switch(iterator->second) { + case HorizonWizard::Wireless: + return HorizonWizard::Page_Network_Wireless; + default: + return HorizonWizard::Page_Network_DHCP; + } +} diff --git a/ui/qt5/networkifacepage.hh b/ui/qt5/networkifacepage.hh index bcd37c6..05b0e2b 100644 --- a/ui/qt5/networkifacepage.hh +++ b/ui/qt5/networkifacepage.hh @@ -13,12 +13,18 @@ #ifndef NETWORKIFACEPAGE_HH #define NETWORKIFACEPAGE_HH +#include + #include "horizonwizardpage.hh" class NetworkIfacePage : public HorizonWizardPage { public: NetworkIfacePage(QWidget *parent = nullptr); void initializePage() override; + bool isComplete() const; + int nextId() const; +private: + QListWidget *ifaceList; }; #endif /* !NETWORKIFACEPAGE_HH */ diff --git a/ui/qt5/resources/network-iface-help.txt b/ui/qt5/resources/network-iface-help.txt new file mode 100644 index 0000000..14e31d8 --- /dev/null +++ b/ui/qt5/resources/network-iface-help.txt @@ -0,0 +1,21 @@ +

Network Interface Selection

+ +

This page is shown when your computer has multiple network interfaces. +Select the one that you wish to use during installation. You can configure +additional network interfaces after installation.

+ +

How do I know which interface to select?

+ +
    +
  • If you use a wireless connection, select Wi-Fi.
  • +
  • If you use a wired connection, select Ethernet.
  • +
+ +

If you're not sure which interface is correct, and you know the MAC address +of your interface, use the mouse to hover over each interface. Each interface +has its MAC address in its tool-tip.

+ +

If you see multiple interfaces of the same type, and you aren't expecting +this, your hardware may have been incorrectly detected by Adélie Linux. You +can contact our community for help at +https://help.adelielinux.org/.

-- cgit v1.2.3-60-g2f50