summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-07-18 16:57:52 +0200
committerNiklas2011-07-18 16:57:52 +0200
commit3c429677e0d34c2de3d2270842b28744f91c63dd (patch)
treecb4edc15dc664d3948e0fd45aaea32b780fc7a70
parentcustomdhcpcd is now compiling and can communicate with the LogReceiver (diff)
downloadfbgui-3c429677e0d34c2de3d2270842b28744f91c63dd.tar.gz
fbgui-3c429677e0d34c2de3d2270842b28744f91c63dd.tar.xz
fbgui-3c429677e0d34c2de3d2270842b28744f91c63dd.zip
made a small gui. Interfac names and progressbars will be added dynamicaly.
-rwxr-xr-xworkspace/LogReceiver/LogReceiverbin35272 -> 55619 bytes
-rw-r--r--workspace/LogReceiver/LogReceiver.pro2
-rw-r--r--workspace/LogReceiver/logreceiver.cpp106
-rw-r--r--workspace/LogReceiver/logreceiver.h26
-rw-r--r--workspace/LogReceiver/logreceiver.ui88
5 files changed, 124 insertions, 98 deletions
diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver
index 4fa7468..282159d 100755
--- a/workspace/LogReceiver/LogReceiver
+++ b/workspace/LogReceiver/LogReceiver
Binary files 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<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()
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 <QDialog>
#include <QtGui/QWidget>
+#include <qprocess.h>
+#include <qnetworkinterface.h>
+#include <qprogressbar.h>
+#include <qboxlayout.h>
+#include <qgroupbox.h>
#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<int, QNetworkInterface > interfacesMap;
QMap<QLocalSocket *, QLocalSocket *> clients;
QMap<Q_PID, QProcess * > clientProcesses;
QString pathToDhcpcdExe;
QStringList dhcpcdArguments;
+ /**/
+ QStringList blackList;
+
+ /*gui elements*/
+ QMap<int , QProgressBar *> progressBars;
+ QLabel *ndStatusLabel;
+ QGroupBox *interfaceGroupBox;
+ QVBoxLayout *mainLayout;
+ QVBoxLayout *interfaceGroupBoxLayout;
+ /**/
+
void runDHCPCD(QList<QNetworkInterface> &interfaces);
- void getListOfNetworkInterfaces();
+ void runDHCPCD(QString interface);
+ QList<QNetworkInterface> getListOfNetworkInterfaces();
+
+ /*gui functions*/
+ void buildGui();
+ void createInterfaceGroupBox();
+ void addInterfacesToGroupBox(QMap<int, QNetworkInterface > &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;
}</string>
</property>
- <widget class="QLabel" name="label">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>10</y>
- <width>131</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>NetworkDiscovery</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_2">
- <property name="geometry">
- <rect>
- <x>30</x>
- <y>60</y>
- <width>151</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>verfügbare Interfaces</string>
- </property>
- </widget>
- <widget class="QListView" name="listView_2">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>190</y>
- <width>311</width>
- <height>81</height>
- </rect>
- </property>
- </widget>
- <widget class="QLabel" name="label_3">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>150</y>
- <width>71</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>StatusLog</string>
- </property>
- </widget>
- <widget class="Line" name="line">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>140</y>
- <width>371</width>
- <height>16</height>
- </rect>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- <widget class="QLabel" name="label_4">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>90</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>i_Name</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_5">
- <property name="geometry">
- <rect>
- <x>230</x>
- <y>90</y>
- <width>67</width>
- <height>17</height>
- </rect>
- </property>
- <property name="text">
- <string>status</string>
- </property>
- </widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>