mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-25 20:22:39 +01:00
Add IPAdress feature to show v4 and v6 address
This commit is contained in:
parent
d1b4896c0a
commit
3781f6ef17
@ -21,7 +21,7 @@ set(QML # cmake-format: sortable
|
||||
src/TestMain.qml)
|
||||
|
||||
set(QML_PLUGIN_SOURCES # cmake-format: sortable
|
||||
src/sysinfo.cpp src/cpu.cpp src/ram.cpp src/storage.cpp src/uptime.cpp src/gpu.cpp)
|
||||
src/sysinfo.cpp src/cpu.cpp src/ram.cpp src/storage.cpp src/uptime.cpp src/gpu.cpp src/ipaddress.cpp)
|
||||
|
||||
set(QML_PLUGIN_HEADER
|
||||
# cmake-format: sortable
|
||||
@ -31,7 +31,8 @@ set(QML_PLUGIN_HEADER
|
||||
src/mathhelper.h
|
||||
src/storage.h
|
||||
src/uptime.h
|
||||
src/gpu.h)
|
||||
src/gpu.h
|
||||
src/ipaddress.h)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Quick infoware)
|
||||
|
@ -17,164 +17,231 @@ Window {
|
||||
property int fontPointSize: 16
|
||||
|
||||
SysInfo {
|
||||
id:sysInfo
|
||||
id: sysInfo
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: wrapper
|
||||
anchors.margins: -50
|
||||
color: "#212128"
|
||||
border.color: root.accentColor
|
||||
border.width: 10
|
||||
IpAddress {
|
||||
id: ipAddress
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: wrapper
|
||||
anchors {
|
||||
horizontalCenter: parent.horizontalCenter
|
||||
verticalCenter: parent.verticalCenter
|
||||
function stringListToString(list) {
|
||||
let out = ""
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
out += "\n" + list[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtGPU
|
||||
text: "GPU"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
RowLayout {
|
||||
spacing: 40
|
||||
anchors.fill: parent
|
||||
anchors.margins: 20
|
||||
|
||||
RowLayout {
|
||||
ColumnLayout {
|
||||
id: wrapperLeft
|
||||
Text {
|
||||
id: name
|
||||
text: sysInfo.gpu.vendor
|
||||
text: "IpAddress"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: "Fira Code"
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: sysInfo.gpu.name
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: root.fontFamily
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtUptime
|
||||
text: "UPTIME"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: valuesLayout
|
||||
spacing: 20
|
||||
Text {
|
||||
id: txtYears
|
||||
text: "YEARS " + sysInfo.uptime.years
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "DAYS " + sysInfo.uptime.days
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "HOURS " + sysInfo.uptime.hours
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "MINUTES " + sysInfo.uptime.minutes
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtSeconds
|
||||
text: "SECONDS " + sysInfo.uptime.seconds
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: txtCPU
|
||||
text: "CPU"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
Row {
|
||||
id: row
|
||||
spacing: 10
|
||||
Layout.fillWidth: true
|
||||
Text {
|
||||
id: txtCPUValue
|
||||
text: Math.floor(sysInfo.cpu.usage)
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
width: 70
|
||||
}
|
||||
ProgressBar {
|
||||
from: 0
|
||||
to: 100
|
||||
value: Math.floor(sysInfo.cpu.usage)
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtStorage
|
||||
text: "STORAGE"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 20
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: storageListView
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 100
|
||||
model: sysInfo.storage
|
||||
delegate: Item {
|
||||
width: storageListView.width
|
||||
height: 40
|
||||
Row {
|
||||
spacing: 10
|
||||
Text {
|
||||
id: txtStorageName
|
||||
text: name
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
width: 70
|
||||
ColumnLayout {
|
||||
Text {
|
||||
text: root.stringListToString(
|
||||
ipAddress.privateIpV4AddressList)
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: "Fira Code"
|
||||
}
|
||||
ProgressBar {
|
||||
from: 0
|
||||
to: bytesTotal
|
||||
value: bytesAvailable
|
||||
width: storageListView.width - txtStorageName.width - row.spacing
|
||||
}
|
||||
Text {
|
||||
text: root.stringListToString(
|
||||
ipAddress.privateIpV6AddressList)
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: "Fira Code"
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
color: root.accentColor
|
||||
Layout.preferredHeight: 5
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Text {
|
||||
text: ipAddress.publicIpV4Address
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: root.fontFamily
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: ipAddress.publicIpV6Address
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: root.fontFamily
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
color: root.accentColor
|
||||
Layout.fillHeight: true
|
||||
width: 10
|
||||
}
|
||||
ColumnLayout {
|
||||
id: wrapperRight
|
||||
|
||||
Text {
|
||||
id: txtGPU
|
||||
text: "GPU"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Text {
|
||||
text: sysInfo.gpu.vendor
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: "Fira Code"
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: sysInfo.gpu.name
|
||||
color: root.accentColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font {
|
||||
pointSize: 16
|
||||
family: root.fontFamily
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtUptime
|
||||
text: "UPTIME"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: valuesLayout
|
||||
spacing: 20
|
||||
Text {
|
||||
id: txtYears
|
||||
text: "YEARS " + sysInfo.uptime.years
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "DAYS " + sysInfo.uptime.days
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "HOURS " + sysInfo.uptime.hours
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
Text {
|
||||
text: "MINUTES " + sysInfo.uptime.minutes
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtSeconds
|
||||
text: "SECONDS " + sysInfo.uptime.seconds
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: root.fontPointSize
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: txtCPU
|
||||
text: "CPU"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
Row {
|
||||
id: row
|
||||
spacing: 10
|
||||
Layout.fillWidth: true
|
||||
Text {
|
||||
id: txtCPUValue
|
||||
text: Math.floor(sysInfo.cpu.usage)
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
width: 70
|
||||
}
|
||||
ProgressBar {
|
||||
from: 0
|
||||
to: 100
|
||||
value: Math.floor(sysInfo.cpu.usage)
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: txtStorage
|
||||
text: "STORAGE"
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
font.pointSize: 60
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 20
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: storageListView
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 100
|
||||
model: sysInfo.storage
|
||||
delegate: Item {
|
||||
width: storageListView.width
|
||||
height: 40
|
||||
Row {
|
||||
spacing: 10
|
||||
Text {
|
||||
id: txtStorageName
|
||||
text: name
|
||||
color: root.accentColor
|
||||
font.family: root.fontFamily
|
||||
width: 70
|
||||
}
|
||||
ProgressBar {
|
||||
from: 0
|
||||
to: bytesTotal
|
||||
value: bytesAvailable
|
||||
width: storageListView.width - txtStorageName.width - row.spacing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
ScreenPlaySysInfo/src/ipaddress.cpp
Normal file
49
ScreenPlaySysInfo/src/ipaddress.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "ipaddress.h"
|
||||
|
||||
IpAddress::IpAddress(QObject* parent)
|
||||
: QObject { parent }
|
||||
{
|
||||
const QHostAddress& localhost = QHostAddress(QHostAddress::LocalHost);
|
||||
QStringList privateIpV4Addresses;
|
||||
QStringList privateIpV6Addresses;
|
||||
for (const QHostAddress& address : QNetworkInterface::allAddresses()) {
|
||||
if (address == localhost)
|
||||
continue;
|
||||
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
privateIpV4Addresses.append(address.toString());
|
||||
}
|
||||
if (address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
privateIpV6Addresses.append(address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
setPrivateIpV4AddressList(privateIpV4Addresses);
|
||||
setPrivateIpV6AddressList(privateIpV6Addresses);
|
||||
|
||||
{
|
||||
|
||||
QNetworkReply* replyV4 = m_networkAccessManager.get(QNetworkRequest(m_ipV4hostCheck));
|
||||
QObject::connect(replyV4, &QNetworkReply::readyRead, this, [this, replyV4]() {
|
||||
const QByteArray data = replyV4->readAll();
|
||||
if (data.size() <= 0)
|
||||
return;
|
||||
|
||||
QString address(data);
|
||||
QHostAddress hostAddress(address);
|
||||
setPublicIpV4Address(address);
|
||||
});
|
||||
}
|
||||
{
|
||||
QNetworkReply* replyV6 = m_networkAccessManager.get(QNetworkRequest(m_ipV6hostCheck));
|
||||
QObject::connect(replyV6, &QNetworkReply::readyRead, this, [this, replyV6]() {
|
||||
const QByteArray data = replyV6->readAll();
|
||||
if (data.size() <= 0)
|
||||
return;
|
||||
|
||||
QString address(data);
|
||||
QHostAddress hostAddress(address);
|
||||
setPublicIpV6Address(address);
|
||||
});
|
||||
}
|
||||
}
|
76
ScreenPlaySysInfo/src/ipaddress.h
Normal file
76
ScreenPlaySysInfo/src/ipaddress.h
Normal file
@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkInterface>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
|
||||
class IpAddress : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList privateIpV4AddressList READ privateIpV4AddressList WRITE setPrivateIpV4AddressList NOTIFY privateIpV4AddressListChanged)
|
||||
Q_PROPERTY(QStringList privateIpV6AddressList READ privateIpV6AddressList WRITE setPrivateIpV6AddressList NOTIFY privateIpV6AddressListChanged)
|
||||
Q_PROPERTY(QString publicIpV4Address READ publicIpV4Address WRITE setPublicIpV4Address NOTIFY publicIpV4AddressChanged)
|
||||
Q_PROPERTY(QString publicIpV6Address READ publicIpV6Address WRITE setPublicIpV6Address NOTIFY publicIpV6AddressChanged)
|
||||
QML_ELEMENT
|
||||
|
||||
public:
|
||||
explicit IpAddress(QObject* parent = nullptr);
|
||||
|
||||
const QStringList& privateIpV4AddressList() const { return m_privateIpV4AddressList; }
|
||||
const QStringList& privateIpV6AddressList() const { return m_privateIpV6AddressList; }
|
||||
const QString& publicIpV4Address() const { return m_publicIpV4Address; }
|
||||
const QString& publicIpV6Address() const { return m_publicIpV6Address; }
|
||||
|
||||
public slots:
|
||||
void setPrivateIpV4AddressList(const QStringList& privateIpV4AddressList)
|
||||
{
|
||||
if (m_privateIpV4AddressList == privateIpV4AddressList)
|
||||
return;
|
||||
m_privateIpV4AddressList = privateIpV4AddressList;
|
||||
emit privateIpV4AddressListChanged(privateIpV4AddressList);
|
||||
}
|
||||
|
||||
void setPrivateIpV6AddressList(const QStringList& privateIpV6AddressList)
|
||||
{
|
||||
if (m_privateIpV6AddressList == privateIpV6AddressList)
|
||||
return;
|
||||
m_privateIpV6AddressList = privateIpV6AddressList;
|
||||
emit privateIpV6AddressListChanged(m_privateIpV6AddressList);
|
||||
}
|
||||
|
||||
void setPublicIpV4Address(const QString& publicIpV4Address)
|
||||
{
|
||||
if (m_publicIpV4Address == publicIpV4Address)
|
||||
return;
|
||||
m_publicIpV4Address = publicIpV4Address;
|
||||
emit publicIpV4AddressChanged(m_publicIpV4Address);
|
||||
}
|
||||
|
||||
void setPublicIpV6Address(const QString& publicIpV6Address)
|
||||
{
|
||||
if (m_publicIpV6Address == publicIpV6Address)
|
||||
return;
|
||||
m_publicIpV6Address = publicIpV6Address;
|
||||
emit publicIpV6AddressChanged(m_publicIpV6Address);
|
||||
}
|
||||
|
||||
signals:
|
||||
void privateIpV4AddressListChanged(const QStringList& privateIpAddressesList);
|
||||
void privateIpV6AddressListChanged(const QStringList& privateIpV6AddressList);
|
||||
void publicIpV4AddressChanged(const QString& publicIpV4Address);
|
||||
void publicIpV6AddressChanged(const QString& publicIpV6Address);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager m_networkAccessManager;
|
||||
QStringList m_privateIpV4AddressList;
|
||||
QStringList m_privateIpV6AddressList;
|
||||
QString m_publicIpV4Address = "UNKNOWN";
|
||||
QString m_publicIpV6Address = "UNKNOWN";
|
||||
const QString m_ipV4hostCheck = "https://ipv4.icanhazip.com/";
|
||||
const QString m_ipV6hostCheck = "https://ipv6.icanhazip.com/";
|
||||
};
|
@ -64,9 +64,7 @@ qt_add_qml_module(
|
||||
${SOURCES}
|
||||
${HEADER}
|
||||
VERSION
|
||||
1.0
|
||||
OUTPUT_DIRECTORY
|
||||
${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME})
|
||||
1.0)
|
||||
|
||||
if(${SCREENPLAY_STEAM})
|
||||
if(APPLE)
|
||||
@ -89,3 +87,9 @@ endif()
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC src/)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Quick ${STEAM_LIB} ScreenPlayUtil SteamSDK SteamSDKQtEnums)
|
||||
|
||||
if(${tst_ScreenPlayWorkshop})
|
||||
qt_add_executable(tst_ScreenPlayWorkshop src/TestMain.cpp)
|
||||
target_link_libraries(tst_ScreenPlayWorkshop PRIVATE Qt6::Quick ${PROJECT_NAME}plugin)
|
||||
target_compile_definitions(tst_ScreenPlayWorkshop PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user