From 7a73cba7ed274cc9f7b06ae1072bc4d790fbcb1d Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 14 Nov 2019 13:12:27 -0600 Subject: Qt UI: Add UI.SysMeta.Hostname page --- ui/qt5/CMakeLists.txt | 1 + ui/qt5/horizon.qrc | 1 + ui/qt5/horizonwizard.cc | 2 ++ ui/qt5/hostnamepage.cc | 68 ++++++++++++++++++++++++++++++++++++++ ui/qt5/hostnamepage.hh | 29 ++++++++++++++++ ui/qt5/resources/hostname-help.txt | 16 +++++++++ 6 files changed, 117 insertions(+) create mode 100644 ui/qt5/hostnamepage.cc create mode 100644 ui/qt5/hostnamepage.hh create mode 100644 ui/qt5/resources/hostname-help.txt (limited to 'ui/qt5') diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt index fc2069d..af7fd82 100644 --- a/ui/qt5/CMakeLists.txt +++ b/ui/qt5/CMakeLists.txt @@ -13,6 +13,7 @@ set(UI_SOURCES networkifacepage.cc netsimplewifipage.cc datetimepage.cc + hostnamepage.cc horizon.qrc) add_executable(horizon-qt5 ${UI_SOURCES}) diff --git a/ui/qt5/horizon.qrc b/ui/qt5/horizon.qrc index f715934..5e740b6 100644 --- a/ui/qt5/horizon.qrc +++ b/ui/qt5/horizon.qrc @@ -14,6 +14,7 @@ resources/network-start-help.txt resources/network-iface-help.txt resources/datetime-help.txt + resources/hostname-help.txt resources/packages-simple-help.txt diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc index 67ed193..d761db1 100644 --- a/ui/qt5/horizonwizard.cc +++ b/ui/qt5/horizonwizard.cc @@ -32,6 +32,7 @@ #include "networkifacepage.hh" #include "netsimplewifipage.hh" #include "datetimepage.hh" +#include "hostnamepage.hh" static std::map help_id_map = { {HorizonWizard::Page_Intro, "intro"}, @@ -178,6 +179,7 @@ HorizonWizard::HorizonWizard(QWidget *parent) : QWizard(parent) { setPage(Page_Network_Iface, new NetworkIfacePage); setPage(Page_Network_Wireless, new NetworkSimpleWirelessPage); setPage(Page_DateTime, new DateTimePage); + setPage(Page_Hostname, new HostnamePage); QObject::connect(this, &QWizard::helpRequested, [=](void) { if(help_id_map.find(currentId()) == help_id_map.end()) { diff --git a/ui/qt5/hostnamepage.cc b/ui/qt5/hostnamepage.cc new file mode 100644 index 0000000..ca8f16d --- /dev/null +++ b/ui/qt5/hostnamepage.cc @@ -0,0 +1,68 @@ +/* + * hostnamepage.cc - Implementation of the UI.SysMeta.Hostname 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 "hostnamepage.hh" + +#include +#include +#include + +HostnamePage::HostnamePage(QWidget *parent) : HorizonWizardPage(parent) { + QLabel *descLabel; + QRegExpValidator *hostnameValidator = new QRegExpValidator(this); + hostnameValidator->setRegExp(QRegExp("[A-Za-z][A-Za-z0-9-_.]+")); + QVBoxLayout *layout; + + setTitle(tr("Computer Name")); + loadWatermark("intro"); + + descLabel = new QLabel(tr("

You need to provide a name for your computer. " + "You may accept the default, or choose your own. " + "If your computer participates in a network, make sure that the name is unique.

" + + "

Computer names may contain letters, numbers, dashes (-), and underscores (_). For example, Living-Room-PC.

" + + "

You may also specify your computer's domain name if necessary (not common). For example, desktop1.my.network.

"), this); + descLabel->setTextFormat(Qt::RichText); + descLabel->setWordWrap(true); + hostnameEdit = new QLineEdit(this); + hostnameEdit->setPlaceholderText(tr("Computer Name")); + hostnameEdit->setValidator(hostnameValidator); + hostnameEdit->setWhatsThis(tr("Enter the name of your computer here.")); + + registerField("hostname*", hostnameEdit); + + layout = new QVBoxLayout(this); + layout->addWidget(descLabel); + layout->addStretch(); + layout->addWidget(hostnameEdit); + layout->addStretch(); + setLayout(layout); +} + +void HostnamePage::initializePage() { +#ifndef HAS_INSTALL_ENV + hostnameEdit->setText("Adelie"); +#else /* HAS_INSTALL_ENV */ + QString name("Adelie"); + + if(horizonWizard()->interfaces.empty()) { + name += "-Banana"; + } else { + QString mac = horizonWizard()->interfaces.begin()->second.mac; + QStringList macparts = mac.split(":"); + name += "-" + macparts[3] + macparts[4] + macparts[5]; + } + + hostnameEdit->setText(name); +#endif /* !HAS_INSTALL_ENV */ +} diff --git a/ui/qt5/hostnamepage.hh b/ui/qt5/hostnamepage.hh new file mode 100644 index 0000000..980a601 --- /dev/null +++ b/ui/qt5/hostnamepage.hh @@ -0,0 +1,29 @@ +/* + * hostnamepage.hh - Definition of the UI.SysMeta.Hostname 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 HOSTNAMEPAGE_HH +#define HOSTNAMEPAGE_HH + +#include "horizonwizardpage.hh" + +#include + +class HostnamePage : public HorizonWizardPage { +public: + HostnamePage(QWidget *parent = nullptr); + + void initializePage(); +private: + QLineEdit *hostnameEdit; +}; + +#endif /* !HOSTNAMEPAGE_HH */ diff --git a/ui/qt5/resources/hostname-help.txt b/ui/qt5/resources/hostname-help.txt new file mode 100644 index 0000000..670c49f --- /dev/null +++ b/ui/qt5/resources/hostname-help.txt @@ -0,0 +1,16 @@ +

Computer Name

+ +

This page allows you to set the name of your computer. The name of your +computer will appear in various places, such as the system startup screen, +log files, and the Applications menu.

+ +

For home users, it's best to provide a descriptive name of the location +and/or owner of the computer. For example, Living-Room-PC or +Annas-PC. Note that if you have a home network, you will need to +make sure that each computer has a different name. Otherwise, some +applications may not function correctly.

+ +

For business and server installations, a computer name is typically +assigned by a network administrator. This may include a domain name, which +can be appended to the end of the name. For example, +wkst025.wilcox-tech.com or postgres02.chi.adelielinux.org.

-- cgit v1.2.3-60-g2f50