summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-08-01 12:31:12 +0200
committerNiklas2011-08-01 12:31:12 +0200
commit2a04cb4147eb9c583fae8d0b3120a74eaf1af68a (patch)
tree90329cb02eb9435e6f1410cf251677eaf089197c
parentbetter version of the logwriter.c and started to devide gui and logic (diff)
downloadfbgui-2a04cb4147eb9c583fae8d0b3120a74eaf1af68a.tar.gz
fbgui-2a04cb4147eb9c583fae8d0b3120a74eaf1af68a.tar.xz
fbgui-2a04cb4147eb9c583fae8d0b3120a74eaf1af68a.zip
seperation of logic and gui completed.
-rwxr-xr-xworkspace/LogReceiver/LogReceiverbin65044 -> 65367 bytes
-rw-r--r--workspace/LogReceiver/LogReceiver.pro1
-rw-r--r--workspace/LogReceiver/logreceiver.cpp77
-rw-r--r--workspace/LogReceiver/logreceiver.h8
-rw-r--r--workspace/LogReceiver/main.cpp2
-rw-r--r--workspace/LogReceiver/ndgui.cpp29
-rw-r--r--workspace/LogReceiver/ndgui.h10
7 files changed, 70 insertions, 57 deletions
diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver
index f08dc0a..ac7b336 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 ef51cfb..97c9067 100644
--- a/workspace/LogReceiver/LogReceiver.pro
+++ b/workspace/LogReceiver/LogReceiver.pro
@@ -4,6 +4,7 @@ QT += core \
gui \
network
LIBS += -lsysfs
+INCLUDEPATH += ../customdhcpcd/src
HEADERS += ndgui.h \
status.h \
logreceiver.h
diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp
index 554b721..1bbdec0 100644
--- a/workspace/LogReceiver/logreceiver.cpp
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -19,12 +19,20 @@
LogReceiver::LogReceiver() {
server = new QLocalServer(this);
+}
+
+LogReceiver::~LogReceiver() {
+
+}
+
+void LogReceiver::initAndRun() {
+
if (!server->listen("/var/tmp/qt_c_socket_default")) {
/*
- QMessageBox::critical(this, tr("LogReceiver"), tr(
- "Unable to start the server: %1.") .arg(server->errorString()));
- close();
- */
+ QMessageBox::critical(this, tr("LogReceiver"), tr(
+ "Unable to start the server: %1.") .arg(server->errorString()));
+ close();
+ */
// emit signal to the gui that a critial error occoured
return;
}
@@ -41,14 +49,8 @@ LogReceiver::LogReceiver() {
dhcpcdArguments.append("-d");
QString ifName("eth1");
runDHCPCD(ifName);
-
-}
-
-LogReceiver::~LogReceiver() {
-
}
-
void LogReceiver::handleNewConnection() {
qDebug() << "New Connection arrived";
@@ -84,14 +86,14 @@ void LogReceiver::handleNewInputLine(QString data) {
QString s_subState = logMsg.section(";", 2, 2);
QString msg = logMsg.section(";", 3, 3);
- int pBar = indexToIfaceNameMap.value(interface);
+ int pBar = indexToIfaceNameMap.value(interface.trimmed());
//qDebug() << logMsg;
//qDebug() << msg;
- int st = s_state.toInt();
- int sst = s_subState.toInt();
+ int st = s_state.trimmed().toInt();
+ int sst = s_subState.trimmed().toInt();
switch (st) {
case LOG_INFO:
@@ -99,19 +101,19 @@ void LogReceiver::handleNewInputLine(QString data) {
qDebug() << sst;
switch (sst) {
case DHCP_DISCOVER:
- handleProgress(pBar,10);
+ emit changeProgressBarValue(pBar,10);
break;
case DHCP_OFFER:
- handleProgress(pBar,20);
+ emit changeProgressBarValue(pBar,20);
break;
case DHCP_REQUEST:
- handleProgress(pBar,30);
+ emit changeProgressBarValue(pBar,30);
break;
case DHCP_DECLINE:
break;
case DHCP_ACK:
- handleProgress(pBar,40);
+ emit changeProgressBarValue(pBar,100);
break;
case DHCP_NAK:
@@ -151,40 +153,15 @@ QList<QNetworkInterface> LogReceiver::getListOfNetworkInterfaces() {
{
continue;
}
- /*
- if(!(nI.flags() & QNetworkInterface::IsUp)) {
- qDebug() << nI.humanReadableName() + " is DOWN ";
-
- QProcess * p = new QProcess(this);
- QStringList args;
- args.append(nI.humanReadableName());
- args.append("up");
- p->start("ifconfig",args);
- connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted()));
- p->waitForFinished();
- qDebug() << nI.humanReadableName() + " is UP ";
-/*
- QNetworkConfigurationManager manager;
- QList<QNetworkConfiguration> confList = manager.allConfigurations();
- foreach(QNetworkConfiguration nC, confList){
- if( nC.name() == "Auto eth1") {
- QNetworkConfiguration conf = manager.configurationFromIdentifier(nC.identifier());
- if(conf.isValid()) {
- QNetworkSession *session = new QNetworkSession(conf);
- session->open();
- }
- qDebug() << "conf is not valid";
- }
- qDebug() << nC.name();
- qDebug() << nC.identifier();
- }
-*/
+ if (!checkCarrierState(nI.humanReadableName())) {
+ continue;
+ }
- //}
- qDebug() << nI.humanReadableName();
+ // qDebug() << nI.humanReadableName();
result.append(nI);
interfacesMap.insert(i, nI);
indexToIfaceNameMap.insert(nI.humanReadableName(), i);
+ emit addNewInterface(nI.humanReadableName(), i);
i++;
}
return result;
@@ -278,11 +255,11 @@ bool LogReceiver::checkCarrierState(QString interface) {
void LogReceiver::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
- 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*> (sender);
QProcess* p = qobject_cast<QProcess * >(QObject::sender());
- QProcess * client = clientProcesses.value(process->pid());
+ QProcess * client = clientProcesses.value(p->pid());
qDebug() << "process finished: " << client->pid() << exitCode << exitStatus;
}
diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h
index e4592c0..26a3934 100644
--- a/workspace/LogReceiver/logreceiver.h
+++ b/workspace/LogReceiver/logreceiver.h
@@ -4,8 +4,6 @@
#include <qprocess.h>
#include <qnetworkinterface.h>
-class QLabel;
-class QPushButton;
class QLocalServer;
class QLocalSocket;
@@ -16,6 +14,8 @@ public:
LogReceiver();
~LogReceiver();
+ void initAndRun();
+
private slots:
void handleNewConnection();
void handleNewInput();
@@ -23,6 +23,9 @@ private slots:
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void handleProcessStarted();
+signals:
+ void addNewInterface(QString ifName, int index);
+ void changeProgressBarValue(int index, int newValue);
private:
QLocalServer *server;
@@ -34,6 +37,7 @@ private:
QString pathToDhcpcdExe;
QStringList dhcpcdArguments;
+
void runDHCPCD(QList<QNetworkInterface> &interfaces);
void runDHCPCD(QString interface);
void checkCarrierState(QList<QNetworkInterface> &interfaces);
diff --git a/workspace/LogReceiver/main.cpp b/workspace/LogReceiver/main.cpp
index 52d0ac9..a8cd960 100644
--- a/workspace/LogReceiver/main.cpp
+++ b/workspace/LogReceiver/main.cpp
@@ -1,4 +1,4 @@
-#include "logreceiver.h"
+#include "ndgui.h"
#include <QtGui>
#include <QApplication>
diff --git a/workspace/LogReceiver/ndgui.cpp b/workspace/LogReceiver/ndgui.cpp
index 0d4c505..e838a8c 100644
--- a/workspace/LogReceiver/ndgui.cpp
+++ b/workspace/LogReceiver/ndgui.cpp
@@ -5,8 +5,12 @@ ndgui::ndgui(QWidget *parent)
{
ui.setupUi(this);
- buildGui();
- addInterfacesToGroupBox(list);
+ connect(&logReceiver, SIGNAL(addNewInterface(QString, int)), this, SLOT(addNewInterface(QString, int)));
+ connect(&logReceiver, SIGNAL(changeProgressBarValue(int , int )), this, SLOT(handleProgress(int, int)));
+
+ buildGui();
+
+ logReceiver.initAndRun();
setWindowTitle(tr("NetD"));
@@ -19,6 +23,8 @@ ndgui::~ndgui()
void ndgui::buildGui() {
+
+
ndStatusLabel = new QLabel(tr("test"));
ndStatusLabel->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
@@ -28,6 +34,8 @@ void ndgui::buildGui() {
// create interface group box
createInterfaceGroupBox();
+
+
mainLayout = new QVBoxLayout;
mainLayout->addWidget(ndStatusLabel);
mainLayout->addWidget(interfaceGroupBox);
@@ -44,6 +52,21 @@ void ndgui::createInterfaceGroupBox(){
interfaceGroupBox->setLayout(interfaceGroupBoxLayout);
}
+void ndgui::addNewInterface(QString ifName, int index) {
+ QHBoxLayout *hBoxLayout = new QHBoxLayout;
+ QLabel *label = new QLabel(ifName);
+ QProgressBar *pBar = new QProgressBar(this);
+ pBar->setRange(1, 100);
+ pBar->setMaximumSize(200, 20);
+
+ progressBars.insert(index, pBar);
+
+ hBoxLayout->addWidget(label, Qt::AlignLeft);
+ hBoxLayout->addWidget(pBar, Qt::AlignRight);
+
+ interfaceGroupBoxLayout->addLayout(hBoxLayout, 2);
+}
+/*
void ndgui::addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces) {
foreach(QNetworkInterface nI, interfaces){
int index = indexToIfaceNameMap.value(nI.humanReadableName());
@@ -61,7 +84,7 @@ void ndgui::addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces) {
interfaceGroupBoxLayout->addLayout(hBoxLayout,2);
}
}
-
+*/
void ndgui::handleProgress(int iFaceIndex, int newValue) {
QProgressBar * pBar = progressBars.value(iFaceIndex);
if(newValue >= pBar->value()) {
diff --git a/workspace/LogReceiver/ndgui.h b/workspace/LogReceiver/ndgui.h
index 01b9d01..990a6b9 100644
--- a/workspace/LogReceiver/ndgui.h
+++ b/workspace/LogReceiver/ndgui.h
@@ -2,7 +2,12 @@
#define NDGUI_H
#include <QtGui/QWidget>
+#include "qprogressbar.h"
+#include "qlabel.h"
+#include "qgroupbox.h"
+#include "qboxlayout.h"
#include "ui_ndgui.h"
+#include "logreceiver.h"
class ndgui: public QWidget {
Q_OBJECT
@@ -13,10 +18,13 @@ public:
public slots:
void handleProgress(int iFaceIndex, int newValue);
+ void addNewInterface(QString ifName, int index);
private:
Ui::ndguiClass ui;
+ LogReceiver logReceiver;
+
/*gui elements*/
QMap<int, QProgressBar *> progressBars;
QLabel *ndStatusLabel;
@@ -28,7 +36,7 @@ private:
/*gui functions*/
void buildGui();
void createInterfaceGroupBox();
- void addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces);
+ //void addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces);