From 4e1b9faba7503f99ee2fbcd7458f66ade42fa309 Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 1 Sep 2011 09:31:39 +0200 Subject: tried to clean the git. deleted old unused files and folders. moved customdhcpcd and LogReceiver to the fbgui folder --- LogReceiver/ndgui.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 LogReceiver/ndgui.cpp (limited to 'LogReceiver/ndgui.cpp') diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp new file mode 100644 index 0000000..a839aef --- /dev/null +++ b/LogReceiver/ndgui.cpp @@ -0,0 +1,184 @@ +#include "ndgui.h" +#include "chooseinterfacedialog.h" +#include "abortbootdialog.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; + showAbortBootDialog(); +} + +void ndgui::handleUpdateStatusLabel(QString ifName, QString status) { + QLabel* label = statusLabels.value(ifName); + label->setText(status); +} + +void ndgui::handleAllProcessesFinished() { + qDebug() << "all Processes finished"; + + if (finalUsableInterfaces.size() > 0) { + showChooseInterfaceDialog(); + } else { + showAbortBootDialog(); + } +} + +void ndgui::showAbortBootDialog() { + aBD = new AbortBootDialog(this); + connect(aBD, SIGNAL(showLogSignal()), this, SLOT(showLog())); + connect(aBD, SIGNAL(restartSignal()), this, SLOT(restartSystem())); + connect(aBD, SIGNAL(shutDownSignal()), this, SLOT(shutDownSystem())); + aBD->setModal(true); + aBD->show(); +} + +void ndgui::showChooseInterfaceDialog() { + cID = new ChooseInterfaceDialog(finalUsableInterfaces, this); + connect(cID, SIGNAL(continueSignal(QString)), this, + SLOT(continueBoot(QString))); + connect(cID, SIGNAL(restartSignal()), this, SLOT(restartSystem())); + connect(cID, SIGNAL(shutDownSignal()), this, SLOT(shutDownSystem())); + cID->setModal(true); + cID->show(); +} + +void ndgui::restartSystem() +{ + + if(qobject_cast(QObject::sender())>0) + { + qDebug() << "received Signal restart abd"; + aBD->closeDialog(); + } + else if(qobject_cast(QObject::sender())>0) + { + qDebug() << "received Signal restart cid"; + cID->close(); + } + else + { + qDebug() << "unknown sender" << QObject::sender(); + } + + +} + +void ndgui::shutDownSystem() +{ + if(qobject_cast(QObject::sender())>0) + { + + aBD->closeDialog(); + } + else if(qobject_cast(QObject::sender())>0) + { + + cID->close(); + } + else + { + qDebug() << "unknown sender" << QObject::sender(); + } + +} + +void ndgui::continueBoot(QString ifName) +{ + QString text = "continue with interface: " + ifName; + cID->close(); +} + +void ndgui::showLog() +{ + qDebug() << "show log"; +} -- cgit v1.2.3-55-g7522