summaryrefslogtreecommitdiffstats
path: root/src/client/informationdialog/informationdialog.cpp
blob: fb3e87c7b4612c704979b0bb248c8ce9929b36b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "informationdialog.h"
#include <QNetworkInterface>
#include <QHostInfo>
#include <QDir>
#include <QDirIterator>

InformationDialog::InformationDialog()  : QDialog()
{

	/* widgets */
	_lblTitle = new QLabel(tr("<h1>system information</h1>"));
	_tableWidget = new QWidget();

	/* layouts */
	_layout = new QVBoxLayout();
	_tableLayout = new QFormLayout();

	/* */
	_tableWidget->setLayout(_tableLayout);
	_layout->addWidget(_lblTitle);
	_layout->addWidget(_tableWidget);
	this->setLayout(_layout);

	initTable();

	qDebug() << "create information dialog";
}

void InformationDialog::initTable()
{
	/* NETWORK*/
	/* hostnames */
	_tableLayout->addRow(new QLabel("<b>" + tr("hostname") + "</b>"), new QLabel(QHostInfo::localHostName()));
	/* ips */
	QStringList interfaceFilter;
	QString bridgeDevicePath("/sys/devices/virtual/net/");
	QDirIterator it(bridgeDevicePath, QStringList() << "brif", QDir::Dirs, QDirIterator::Subdirectories);
	while (it.hasNext()) {
		it.next();
		QDir dir = it.filePath();
		dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
		interfaceFilter += dir.entryList();
	}

	for (QNetworkInterface interface : QNetworkInterface::allInterfaces()) {

		if (interfaceFilter.contains(interface.name()) || interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
			qDebug() << "interface filtered: " << interface.name();
			continue;
		}

		_tableLayout->addRow("<u><b>" + interface.name() + "</b></u>", new QLabel(""));

		for (QNetworkAddressEntry entry : interface.addressEntries()) {
			QLabel* label;
			QLabel* value;
			QHostAddress hostAddr = entry.ip();

			if (hostAddr == QHostAddress::Null || hostAddr == QHostAddress::Broadcast || hostAddr == QHostAddress::LocalHost
			        || hostAddr == QHostAddress::AnyIPv6)
				continue;

			if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol)  {
				label = new QLabel("IPv6");
				value = new QLabel(hostAddr.toString().split("%").first());
			} else {
				label = new QLabel("IPv4");
				value = new QLabel(hostAddr.toString());
			}

			_tableLayout->addRow(label, value);
		}
		_tableLayout->addRow("MAC", new QLabel(interface.hardwareAddress()));
	}

	/* TODO: Add other information */
}