#include "ndgui.h" ndgui::ndgui(QWidget *parent) : QWidget(parent) { ui.setupUi(this); connect(&logReceiver, SIGNAL(addNewInterface(QString)), this, SLOT(addNewInterface(QString))); connect(&logReceiver, SIGNAL(changeProgressBarValue(QString , int )), this, SLOT(handleProgress(QString, int))); connect(&logReceiver, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString))); connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString))); connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString))); connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); buildGui(); logReceiver.initAndRun("/var/tmp/qt_c_socket_custom"); numberOfInterfaces = 0; setWindowTitle(tr("NetD")); } ndgui::~ndgui() { } void ndgui::buildGui() { ndStatusLabel = new QLabel(tr("test")); ndStatusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ndStatusLabel->setAlignment(Qt::AlignCenter); ndStatusLabel->setMinimumSize(100, 20); // create interface group box createInterfaceGroupBox(); mainLayout = new QVBoxLayout; mainLayout->addWidget(ndStatusLabel); mainLayout->addWidget(interfaceGroupBox); setLayout(mainLayout); } void ndgui::createInterfaceGroupBox(){ interfaceGroupBox = new QGroupBox(tr("Interfaces")); interfaceGroupBoxLayout = new QVBoxLayout; /* add interfaces via addInterfacesToGroupBox()*/ interfaceGroupBox->setLayout(interfaceGroupBoxLayout); } void ndgui::addNewInterface(QString ifName) { qDebug() << "receive interface to add:" << ifName; QHBoxLayout *hBoxLayout = new QHBoxLayout; QLabel *label = new QLabel(ifName); QLabel *labelStatus = new QLabel("waiting"); QProgressBar *pBar = new QProgressBar(this); pBar->setRange(1, 100); pBar->setMaximumSize(200, 20); statusLabels.insert(ifName, labelStatus); progressBars.insert(ifName, pBar); hBoxLayout->addWidget(label, Qt::AlignLeft); hBoxLayout->addWidget(labelStatus, Qt::AlignCenter); hBoxLayout->addWidget(pBar, Qt::AlignRight); numberOfInterfaces++; interfaceGroupBoxLayout->addLayout(hBoxLayout, 2); } void ndgui::handleProgress(QString ifName, int newValue) { qDebug() << "<[---]> SLOT handleProgress activated with: " << ifName << newValue; QProgressBar * pBar = progressBars.value(ifName); if(newValue >= pBar->value()) { pBar->setValue(newValue); } else { qDebug() << "Error: new value is smaller than the old value!"; } } void ndgui::handleConnectionEstablished(QString ifName) { finalUsableInterfaces.append(ifName); } void ndgui::handleAbortBoot(QString msg) { qDebug() << "abort boot. reason:" << msg; } void ndgui::handleUpdateStatusLabel(QString ifName, QString status) { QLabel* label = statusLabels.value(ifName); label->setText(status); } void ndgui::handleAllProcessesFinished() { qDebug() << "all Processes finished"; mainLayout-> }