From 3c429677e0d34c2de3d2270842b28744f91c63dd Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 18 Jul 2011 16:57:52 +0200 Subject: made a small gui. Interfac names and progressbars will be added dynamicaly. --- workspace/LogReceiver/logreceiver.cpp | 106 +++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 9 deletions(-) (limited to 'workspace/LogReceiver/logreceiver.cpp') diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 5c695e5..82d24a2 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -16,7 +16,7 @@ LogReceiver::LogReceiver(QWidget *parent) : QDialog(parent) { - //ui.setupUi(this); + ui.setupUi(this); statusLabel = new QLabel; quitButton = new QPushButton(tr("Quit")); @@ -44,9 +44,17 @@ LogReceiver::LogReceiver(QWidget *parent) : QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); - setLayout(mainLayout); + //setLayout(mainLayout); - setWindowTitle(tr("Fortune Server")); + getListOfNetworkInterfaces(); + buildGui(); + addInterfacesToGroupBox(interfacesMap); + pathToDhcpcdExe = "/home/niklas/fbgui/workspace/customdhcpcd/src/dhcpcd"; + QString ifName("eth0"); + runDHCPCD(ifName); + + + setWindowTitle(tr("NetD")); } LogReceiver::~LogReceiver() { @@ -89,18 +97,19 @@ void LogReceiver::handleNewInput() { qDebug() << "received stat_ok"; switch (sst) { case DHCP_DISCOVER: + handleProgress(0,10); break; case DHCP_OFFER: - + handleProgress(0,20); break; case DHCP_REQUEST: - + handleProgress(0,30); break; case DHCP_DECLINE: break; case DHCP_ACK: - + handleProgress(0,40); break; case DHCP_NAK: @@ -128,6 +137,7 @@ void LogReceiver::handleNewInput() { QList LogReceiver::getListOfNetworkInterfaces() { QList nIList = QNetworkInterface::allInterfaces(); QList result; + int i = 0; foreach(QNetworkInterface nI, nIList) { if (((!(nI.flags() & QNetworkInterface::CanBroadcast)|| nI.flags() & QNetworkInterface::IsLoopBack) || @@ -137,35 +147,113 @@ QList LogReceiver::getListOfNetworkInterfaces() { } qDebug() << nI.humanReadableName(); result.append(nI); + interfacesMap.insert(i, nI); + i++; } return result; } void LogReceiver::runDHCPCD(QList &interfaces) { foreach(QNetworkInterface ni, interfaces) { + dhcpcdArguments.append(ni.humanReadableName()); QProcess * p = new QProcess(this); clientProcesses.insert(p->pid(),p); p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(handleProcessFinished(int, QProcess::ExitStatus))); + dhcpcdArguments.removeLast(); } } +void LogReceiver::runDHCPCD(QString interface) { + dhcpcdArguments.append(interface); + QProcess * p = new QProcess(this); + clientProcesses.insert(p->pid(),p); + p->start(pathToDhcpcdExe,dhcpcdArguments); + connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); + connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(handleProcessFinished(int, QProcess::ExitStatus))); + dhcpcdArguments.removeLast(); +} + void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { QObject* sender = const_cast (QObject::sender()); QProcess* process = static_cast (sender); + QProcess* p = qobject_cast(QObject::sender()); QProcess * client = clientProcesses.value(process->pid()); + + qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; } void LogReceiver::handleProcessStarted() { - QObject* sender = const_cast (QObject::sender()); - QProcess* process = static_cast (sender); +/* + //QObject* sender = const_cast (QObject::sender()); + QProcess* process = static_cast (QObject::sender()); +*/ + //QProcess* p = qobject_cast(QObject::sender()); + //QProcess * client = clientProcesses.value(process->pid()); - QProcess * client = clientProcesses.value(process->pid()); + + qDebug() << "process started: "; +} + +void LogReceiver::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 LogReceiver::createInterfaceGroupBox(){ + interfaceGroupBox = new QGroupBox(tr("Interfaces")); + + interfaceGroupBoxLayout = new QVBoxLayout; + /* add interfaces via addInterfacesToGroupBox()*/ + + interfaceGroupBox->setLayout(interfaceGroupBoxLayout); +} + +void LogReceiver::addInterfacesToGroupBox(QMap &interfaces) { + for(int i = 0; i < interfaces.size(); i++) { + QHBoxLayout *hBoxLayout = new QHBoxLayout; + QLabel *label = new QLabel(interfaces.value(i).humanReadableName()); + QProgressBar *pBar = new QProgressBar(this); + pBar->setRange(1,100); + pBar->setMaximumSize(200,20); + + progressBars.insert(i,pBar); + + hBoxLayout->addWidget(label, Qt::AlignLeft); + hBoxLayout->addWidget(pBar, Qt::AlignRight); + + interfaceGroupBoxLayout->addLayout(hBoxLayout,2); + } +} + +void LogReceiver::handleProgress(int iFaceIndex, int newValue) { + QProgressBar * pBar = progressBars.value(iFaceIndex); + if(newValue >= pBar->value()) { + pBar->setValue(newValue); + } + else { + qDebug() << "Error: new value is smaller than the old value!"; + } } +int LogReceiver::checkBlackList() -- cgit v1.2.3-55-g7522