#include "informationdialog.h" #include #include #include #include InformationDialog::InformationDialog() : QDialog() { /* widgets */ _lblTitle = new QLabel(tr("

system information

")); _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("" + tr("hostname") + ""), 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("" + interface.name() + "", 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 */ }