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 | Bin 35272 -> 55619 bytes workspace/LogReceiver/LogReceiver.pro | 2 + workspace/LogReceiver/logreceiver.cpp | 106 +++++++++++++++++++++++++++++++--- workspace/LogReceiver/logreceiver.h | 26 ++++++++- workspace/LogReceiver/logreceiver.ui | 88 ---------------------------- 5 files changed, 124 insertions(+), 98 deletions(-) diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver index 4fa7468..282159d 100755 Binary files a/workspace/LogReceiver/LogReceiver and b/workspace/LogReceiver/LogReceiver differ diff --git a/workspace/LogReceiver/LogReceiver.pro b/workspace/LogReceiver/LogReceiver.pro index 1be2ccd..566983d 100644 --- a/workspace/LogReceiver/LogReceiver.pro +++ b/workspace/LogReceiver/LogReceiver.pro @@ -9,3 +9,5 @@ SOURCES += main.cpp \ logreceiver.cpp FORMS += logreceiver.ui RESOURCES += +CFLAGS = -g -Wall +CXXFLAGS = -g -Wall \ No newline at end of file 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() diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index 0c9df48..2457933 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -3,6 +3,11 @@ #include #include +#include +#include +#include +#include +#include #include "ui_logreceiver.h" class QLabel; @@ -22,6 +27,7 @@ private slots: void handleNewInput(); void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void handleProcessStarted(); + void handleProgress(int iFaceIndex, int newValue); private: Ui::LogReceiverClass ui; @@ -29,13 +35,31 @@ private: QPushButton *quitButton; QLocalServer *server; quint16 blockSize; + QMap interfacesMap; QMap clients; QMap clientProcesses; QString pathToDhcpcdExe; QStringList dhcpcdArguments; + /**/ + QStringList blackList; + + /*gui elements*/ + QMap progressBars; + QLabel *ndStatusLabel; + QGroupBox *interfaceGroupBox; + QVBoxLayout *mainLayout; + QVBoxLayout *interfaceGroupBoxLayout; + /**/ + void runDHCPCD(QList &interfaces); - void getListOfNetworkInterfaces(); + void runDHCPCD(QString interface); + QList getListOfNetworkInterfaces(); + + /*gui functions*/ + void buildGui(); + void createInterfaceGroupBox(); + void addInterfacesToGroupBox(QMap &interfaces); }; #endif // LOGRECEIVER_H diff --git a/workspace/LogReceiver/logreceiver.ui b/workspace/LogReceiver/logreceiver.ui index d8c1d46..0010c64 100644 --- a/workspace/LogReceiver/logreceiver.ui +++ b/workspace/LogReceiver/logreceiver.ui @@ -18,94 +18,6 @@ background:grey; } - - - - 10 - 10 - 131 - 17 - - - - NetworkDiscovery - - - - - - 30 - 60 - 151 - 17 - - - - verfügbare Interfaces - - - - - - 40 - 190 - 311 - 81 - - - - - - - 10 - 150 - 71 - 17 - - - - StatusLog - - - - - - 10 - 140 - 371 - 16 - - - - Qt::Horizontal - - - - - - 40 - 90 - 67 - 17 - - - - i_Name - - - - - - 230 - 90 - 67 - 17 - - - - status - - -- cgit v1.2.3-55-g7522