Skip to content

Commit

Permalink
Connected AboutPage Wifi address with NetworkManager for IP instead o…
Browse files Browse the repository at this point in the history
…f QProcess
  • Loading branch information
erinharrington-12 committed Nov 21, 2022
1 parent b152929 commit cf6168f
Show file tree
Hide file tree
Showing 16 changed files with 575 additions and 430 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ include_directories(



find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network Quick QuickWidgets QuickControls2)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network Quick QuickWidgets QuickControls2 SvgWidgets)



Expand Down Expand Up @@ -103,6 +103,7 @@ target_link_libraries(botui
Qt6::QuickWidgets
Qt6::Widgets
Qt6::QuickControls2
Qt6::SvgWidgets
network_manager_dbus
pcompiler
z
Expand Down
3 changes: 2 additions & 1 deletion dbus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(NETWORK_MANAGER_INTERFACES
org.freedesktop.NetworkManager.Settings.Connection
org.freedesktop.NetworkManager.Settings
org.freedesktop.NetworkManager.AccessPoint
org.freedesktop.NetworkManager.IP4Config
org.freedesktop.NetworkManager
)

Expand All @@ -20,4 +21,4 @@ endforeach()

add_library(network_manager_dbus STATIC ${NETWORK_MANAGER_SOURCES})
target_link_libraries(network_manager_dbus PUBLIC Qt::DBus)
target_include_directories(network_manager_dbus PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(network_manager_dbus PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
129 changes: 129 additions & 0 deletions dbus/org.freedesktop.NetworkManager.IP4Config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/freedesktop/NetworkManager/IP4Config">
<!--
org.freedesktop.NetworkManager.IP4Config:
@short_description: IPv4 Configuration Set.
-->
<interface name="org.freedesktop.NetworkManager.IP4Config">

<!--
Addresses:
Array of arrays of IPv4 address/prefix/gateway. All 3 elements of each
array are in network byte order. Essentially: [(addr, prefix, gateway),
(addr, prefix, gateway), ...] Deprecated: use AddressData and Gateway
-->
<property name="Addresses" type="aau" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;QVariantMap&gt;"/>
</property>
<!--
AddressData:
Array of IP address data objects. All addresses will include "address" (an
IP address string), and "prefix" (a uint). Some addresses may include
additional attributes.
-->
<property name="AddressData" type="aa{sv}" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;QVariantMap&gt;"/>
</property>

<!--
Gateway:
The gateway in use.
-->
<property name="Gateway" type="s" access="read"/>

<!--
Routes:
Arrays of IPv4 route/prefix/next-hop/metric. All 4 elements of each tuple
are in network byte order. 'route' and 'next hop' are IPv4 addresses,
while prefix and metric are simple unsigned integers. Essentially:
[(route, prefix, next-hop, metric), (route, prefix, next-hop, metric),
...] Deprecated: use RouteData
-->
<property name="Routes" type="aau" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;QVariantMap&gt;"/>
</property>

<!--
RouteData:
Array of IP route data objects. All routes will include "dest" (an IP
address string) and "prefix" (a uint). Some routes may include "next-hop"
(an IP address string), "metric" (a uint), and additional attributes.
-->
<property name="RouteData" type="aa{sv}" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;QVariantMap&gt;"/>
</property>

<!--
Nameservers:
The nameservers in use. Deprecated: use NameserverData
-->
<property name="Nameservers" type="au" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="<type>"/>
</property>
<!--
NameserverData:
@since: 1.14
The nameservers in use. Currently, only the value "address"
is recognized (with an IP address string).
-->
<property name="NameserverData" type="aa{sv}" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QList&lt;QVariantMap&gt;"/>
</property>

<!--
Domains:
A list of domains this address belongs to.
-->
<property name="Domains" type="as" access="read"/>

<!--
Searches:
A list of dns searches.
-->
<property name="Searches" type="as" access="read"/>

<!--
DnsOptions:
A list of DNS options that modify the behavior of the DNS resolver. See
resolv.conf(5) manual page for the list of supported options.
-->
<property name="DnsOptions" type="as" access="read"/>

<!--
DnsPriority:
The relative priority of DNS servers.
-->
<property name="DnsPriority" type="i" access="read"/>

<!--
WinsServers:
The Windows Internet Name Service servers associated with the connection.
Each address is in network byte order. Deprecated: use WinsServerData
-->
<property name="WinsServers" type="au" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="<type>"/>
</property>

<!--
WinsServerData:
@since: 1.14
The Windows Internet Name Service servers associated with the connection.
-->
<property name="WinsServerData" type="as" access="read"/>

</interface>
</node>
2 changes: 2 additions & 0 deletions include/botui/NetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Q_OBJECT

QString ipAddress() const;

QString ip4Address() const;

Connection createAPConfig() const ;

public slots:
Expand Down
2 changes: 2 additions & 0 deletions include/botui/NetworkManagerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

typedef QMap<QString, QVariant> StringVariantMap;
typedef QMap<QString, StringVariantMap> Connection;
typedef QList<StringVariantMap> ListStringVariantMap;
//Connection = QMap<QString, QMap<QString,QVariant>>
Q_DECLARE_METATYPE(StringVariantMap);
Q_DECLARE_METATYPE(Connection);
Q_DECLARE_METATYPE(ListStringVariantMap);

#endif

Expand Down
2 changes: 2 additions & 0 deletions rc/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,15 @@
<file>icons/webcam_delete.png</file>
<file>icons/webcam_error.png</file>
<file>icons/webcam.png</file>
<file>icons/wifi.png</file>
<file>icons/world_add.png</file>
<file>icons/world_delete.png</file>
<file>icons/world_edit.png</file>
<file>icons/world_go.png</file>
<file>icons/world_link.png</file>
<file>icons/world.png</file>
<file>icons/wrench_orange.png</file>
<file>icons/wrench1.png</file>
<file>icons/wrench.png</file>
<file>icons/xhtml_add.png</file>
<file>icons/xhtml_delete.png</file>
Expand Down
2 changes: 1 addition & 1 deletion rc/icons/fontawesome/solid/apple-alt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/icons/wifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/icons/wrench1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/tango/wifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 44 additions & 42 deletions src/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,71 @@
#include "ui_AboutWidget.h"
#include "Device.h"
#include "SystemUtils.h"
#include "NetworkManager.h"

#include <QDebug>
#include <QRegularExpression>

AboutWidget::AboutWidget(Device *device, QWidget *parent)
: StandardWidget(device, parent),
ui(new Ui::AboutWidget)
: StandardWidget(device, parent),
ui(new Ui::AboutWidget)
{
ui->setupUi(this);
ui->setupUi(this);

//Version Number
ui->version->setText("Version 27.0 (Quark)");
// Version Number
ui->version->setText("Version 27.0 (Quark)");

//ui->deviceName->setText(device->name() + " v" + device->version());
// ui->deviceName->setText(device->name() + " v" + device->version());

//Display Serial Number
const QString serial = device->serial();
ui->deviceName->setText("Wombat-" + serial);
// Display Serial Number
const QString serial = device->serial();
ui->deviceName->setText("Wombat-" + serial);


//Check if eth0 is active (/sys/class/net/eth0/carrier will output 1 if eth0 is active and 0 if it is not)
QProcess proc;
proc.start("cat /sys/class/net/eth0/carrier");
proc.waitForFinished();
QString output = proc.readAllStandardOutput();
//QDBusObjectPath ip4Config = m_device.ip4Config();
qDebug() << "IP Address: " << NetworkManager::ref().ip4Address();

//If eth0 is active
if (output.toInt() == 1){
//Pull network information
QProcess proc;
proc.start("hostname -I");
proc.waitForFinished();
QString output = proc.readAllStandardOutput();

//Parse the output and set as text for IP addresses
QStringList list = output.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
ui->WiFiaddr->setText(list[1]);
ui->LANaddr->setText(list[0]);
}
else{
ui->WiFiaddr->setText("192.168.125.1");
ui->LANaddr->setText("0.0.0.0");
}
// Check if eth0 is active (/sys/class/net/eth0/carrier will output 1 if eth0 is active and 0 if it is not)
QProcess proc;
proc.start("cat /sys/class/net/eth0/carrier");
proc.waitForFinished();
QString output = proc.readAllStandardOutput();

//Old
#ifdef WALLABY
const QString id = device-> id();
if(!id.isEmpty()) {
// If eth0 is active
if (output.toInt() == 1)
{
// Pull network information
QProcess proc;
proc.start("hostname -I");
proc.waitForFinished();
QString output = proc.readAllStandardOutput();

// Parse the output and set as text for IP addresses
QStringList list = output.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
ui->WiFiaddr->setText(list[1]);
ui->LANaddr->setText(list[0]);
}
else
{
ui->WiFiaddr->setText(NetworkManager::ref().ip4Address());
ui->LANaddr->setText("0.0.0.0");
}

// Old
const QString id = device->id();
if (!id.isEmpty())
{
const QString password = SystemUtils::sha256(id).left(6) + "00";
const QString ssid = device->serial() + "-wombat";
ui->ssid->setText(ssid);
ui->password->setText(password);
}

#else
ui->wifiBox->hide();
#endif

//Setup the UI
performStandardSetup(tr("About"));
// Setup the UI
performStandardSetup(tr("About"));
}

AboutWidget::~AboutWidget()
{
delete ui;
delete ui;
}
21 changes: 19 additions & 2 deletions src/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "org_freedesktop_NetworkManager_Device_Wireless.h"
#include "org_freedesktop_NetworkManager_Settings.h"
#include "org_freedesktop_NetworkManager_Settings_Connection.h"
#include "org_freedesktop_NetworkManager_IP4Config.h"

#include <stdio.h>

Expand Down Expand Up @@ -177,7 +178,7 @@ void NetworkManager::addNetwork(const Network &network)
{
APExist = true;
apPathConn = connectionPath;
//APuuid = detail["connection"]["uuid"].toString();
// APuuid = detail["connection"]["uuid"].toString();
qDebug() << "AP Path Connection already exists";
break;
}
Expand Down Expand Up @@ -435,6 +436,21 @@ QString NetworkManager::ipAddress() const
return ret;
}

QString NetworkManager::ip4Address() const
{
QString ipAddr;
QDBusObjectPath ip4Con = m_device->ip4Config(); // ip4Address path
qDebug() << "IP4 Config path: " << ip4Con.path();
OrgFreedesktopNetworkManagerIP4ConfigInterface ip4Object(
NM_SERVICE,
ip4Con.path(),
QDBusConnection::systemBus());

QList<QMap<QString,QVariant>> ip4conf = ip4Object.addressData();
ipAddr = ip4conf.value(0).value("address").toString();
return ipAddr;
}

NetworkManager::NetworkManager()
: m_nm(new OrgFreedesktopNetworkManagerInterface(
NM_SERVICE,
Expand All @@ -446,11 +462,12 @@ NetworkManager::NetworkManager()
// Register our metatype with dbus
qDBusRegisterMetaType<Connection>();
qDBusRegisterMetaType<StringVariantMap>();
qDBusRegisterMetaType<ListStringVariantMap>();
OrgFreedesktopNetworkManagerSettingsInterface settings(
NM_SERVICE,
NM_OBJECT "/Settings",
QDBusConnection::systemBus());

QDBusPendingReply<QList<QDBusObjectPath>> reply = m_nm->GetDevices();

if (reply.isError())
Expand Down
Loading

0 comments on commit cf6168f

Please sign in to comment.