summaryrefslogtreecommitdiffstats
path: root/workspace/LogReceiver/logreceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'workspace/LogReceiver/logreceiver.cpp')
-rw-r--r--workspace/LogReceiver/logreceiver.cpp106
1 files changed, 97 insertions, 9 deletions
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<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
QList<QNetworkInterface> result;
+ int i = 0;
foreach(QNetworkInterface nI, nIList) {
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)||
nI.flags() & QNetworkInterface::IsLoopBack) ||
@@ -137,35 +147,113 @@ QList<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
}
qDebug() << nI.humanReadableName();
result.append(nI);
+ interfacesMap.insert(i, nI);
+ i++;
}
return result;
}
void LogReceiver::runDHCPCD(QList<QNetworkInterface> &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*> (QObject::sender());
QProcess* process = static_cast<QProcess*> (sender);
+ QProcess* p = qobject_cast<QProcess * >(QObject::sender());
QProcess * client = clientProcesses.value(process->pid());
+
+ qDebug() << "process finished: " << client->pid() << exitCode << exitStatus;
}
void LogReceiver::handleProcessStarted() {
- QObject* sender = const_cast<QObject*> (QObject::sender());
- QProcess* process = static_cast<QProcess*> (sender);
+/*
+ //QObject* sender = const_cast<QObject*> (QObject::sender());
+ QProcess* process = static_cast<QProcess*> (QObject::sender());
+*/
+ //QProcess* p = qobject_cast<QProcess * >(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<int , QNetworkInterface> &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()