summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorKiyoshi Aman <adelie@aerdan.vulpine.house>2020-02-10 08:57:09 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-10 08:57:09 -0600
commit89934d31b65f070b1954ae2f6201841bfd90d3e2 (patch)
tree5019930dad6c28b4183a0aec74fbda6e3f408125 /ui
parent423c4fd6e25cc9306b84abceb8f79e8c1a469a7b (diff)
downloadhorizon-89934d31b65f070b1954ae2f6201841bfd90d3e2.tar.gz
horizon-89934d31b65f070b1954ae2f6201841bfd90d3e2.tar.bz2
horizon-89934d31b65f070b1954ae2f6201841bfd90d3e2.tar.xz
horizon-89934d31b65f070b1954ae2f6201841bfd90d3e2.zip
Qt UI: Add subnet input widget
Diffstat (limited to 'ui')
-rw-r--r--ui/qt5/CMakeLists.txt1
-rw-r--r--ui/qt5/subnetbox.cc65
-rw-r--r--ui/qt5/subnetbox.hh40
3 files changed, 106 insertions, 0 deletions
diff --git a/ui/qt5/CMakeLists.txt b/ui/qt5/CMakeLists.txt
index 22391c4..cc56ed4 100644
--- a/ui/qt5/CMakeLists.txt
+++ b/ui/qt5/CMakeLists.txt
@@ -8,6 +8,7 @@ set(UI_SOURCES
main.cc
${CMAKE_SOURCE_DIR}/3rdparty/Section.cpp
stepprogresswidget.cc
+ subnetbox.cc
useraccountwidget.cc
avatardialog.cc
crypt_sha512.c
diff --git a/ui/qt5/subnetbox.cc b/ui/qt5/subnetbox.cc
new file mode 100644
index 0000000..54f1732
--- /dev/null
+++ b/ui/qt5/subnetbox.cc
@@ -0,0 +1,65 @@
+/*
+ * subnetbox.cc - Implementation of a widget for inputting an IPv4 subnet mask
+ * 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 "subnetbox.hh"
+#include "util/net.hh"
+
+SubnetBox::SubnetBox(QWidget *parent) : QWidget(parent) {
+ SubnetBox::layout = new QHBoxLayout(this);
+ SubnetBox::subnet = new QLineEdit(this);
+ SubnetBox::cidr = new QSpinBox(this);
+
+ this->setLayout(layout);
+
+ layout->addWidget(subnet);
+ layout->addWidget(cidr);
+ layout->setMargin(0);
+
+ subnet->setInputMask("000.000.000.000;_");
+ cidr->setRange(1, 32);
+
+ connect(subnet, &QLineEdit::textEdited, this, &SubnetBox::subnetEdited);
+ connect(cidr, QOverload<int>::of(&QSpinBox::valueChanged),
+ this, &SubnetBox::cidrEdited);
+}
+
+QString SubnetBox::subnetMask(void) const {
+ return subnet->text();
+}
+
+int SubnetBox::subnetCIDR(void) const {
+ return cidr->value();
+}
+
+void SubnetBox::subnetEdited(const QString &text) {
+ int value = subnet_mask_to_cidr(text.toUtf8());
+ if(value > 0) {
+ cidr->setValue(value);
+ }
+}
+
+void SubnetBox::cidrEdited(int value) {
+ int bytes = value / 8, bits = value % 8, lastfilled = 0;
+ QString data;
+ char temp[4];
+
+ for(int i = 0; i < bytes; i++) {
+ data.append("255.");
+ }
+ for(int i = bits; i > 0; i--) {
+ lastfilled |= (1 << (8 - i));
+ }
+ snprintf(temp, 4, "%d", lastfilled);
+ data.append(temp);
+
+ subnet->setText(data);
+}
diff --git a/ui/qt5/subnetbox.hh b/ui/qt5/subnetbox.hh
new file mode 100644
index 0000000..9f2edbf
--- /dev/null
+++ b/ui/qt5/subnetbox.hh
@@ -0,0 +1,40 @@
+/*
+ * subnetbox.hh - Definition of a widget for inputting an IPv4 subnet mask
+ * 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 SUBNETBOX_HH
+#define SUBNETBOX_HH
+
+#include <QWidget>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QSpinBox>
+#include <QString>
+
+class SubnetBox : public QWidget {
+ Q_OBJECT
+
+public:
+ SubnetBox(QWidget *parent = nullptr);
+ QString subnetMask() const;
+ int subnetCIDR() const;
+
+public slots:
+ void subnetEdited(const QString &text);
+ void cidrEdited(int value);
+
+private:
+ QHBoxLayout *layout;
+ QLineEdit *subnet;
+ QSpinBox *cidr;
+};
+
+#endif