summaryrefslogblamecommitdiffstats
path: root/src/client/informationdialog/informationdialog.cpp
blob: ff966414cbc960ec0d504342a7cf8de803573a9f (plain) (tree)
1
2
3
4
5
6
7
8
9
                              
 

                            

                       


                      
 

                                                   

                     

                                                                        

                     

                                             











                                                

                                   

                       

                                                                                               
                 

                                                              
                                                                                                         






                                                                 
                                                                          


                                                                                                                              
                                 

                 
                                                                                                 
 
                                                                      






                                                                                                                                        
 
                                                                                    

                                                                                                 
                                

                                                                              
                         
 

                                                           
                                                                                           


                                         
 
#include "informationdialog.h"

#include <QNetworkInterface>
#include <QHostInfo>
#include <QDir>
#include <QDirIterator>
#include <QLayout>
#include <QFormLayout>
#include <QLabel>

InformationDialog::InformationDialog()  : QDialog()
{

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

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

	/* */
	_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>", this),
						 new QLabel(QHostInfo::localHostName(), this));
	/* 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 (const auto& 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(this));

		for (const auto &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", this);
				value = new QLabel(hostAddr.toString().split("%").first(), this);
			} else {
				label = new QLabel("IPv4", this);
				value = new QLabel(hostAddr.toString(), this);
			}

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

	/* TODO: Add other information */
}