From 82aa92021583cbeefe6c0a29181680f3ca1e4242 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 24 Aug 2011 13:58:14 +0200 Subject: added to dialogs. one for the critical error case (abot boot dialog), one for the succesful case (choose interface dialog). also added a new function for testing the connectivity via tcpsocket (or http request). --- workspace/LogReceiver/LogReceiver | Bin 78251 -> 107903 bytes workspace/LogReceiver/LogReceiver.pro | 8 +- workspace/LogReceiver/abortbootdialog.cpp | 98 ++++++++++++++++++++++++ workspace/LogReceiver/abortbootdialog.h | 46 +++++++++++ workspace/LogReceiver/chooseinterfacedialog.cpp | 98 ++++++++++++++++++++++++ workspace/LogReceiver/chooseinterfacedialog.h | 44 +++++++++++ workspace/LogReceiver/logreceiver.cpp | 43 ++++++++--- workspace/LogReceiver/logreceiver.h | 1 + workspace/LogReceiver/ndgui.cpp | 79 ++++++++++++++++++- workspace/LogReceiver/ndgui.h | 18 ++++- 10 files changed, 421 insertions(+), 14 deletions(-) create mode 100644 workspace/LogReceiver/abortbootdialog.cpp create mode 100644 workspace/LogReceiver/abortbootdialog.h create mode 100644 workspace/LogReceiver/chooseinterfacedialog.cpp create mode 100644 workspace/LogReceiver/chooseinterfacedialog.h diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver index d0aab5a..8ada72f 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 81c48f6..19300fa 100644 --- a/workspace/LogReceiver/LogReceiver.pro +++ b/workspace/LogReceiver/LogReceiver.pro @@ -6,10 +6,14 @@ QT += core \ LIBS += -lsysfs INCLUDEPATH += ../customdhcpcd/src HEADERS += ndgui.h \ - logreceiver.h + logreceiver.h \ + abortbootdialog.h \ + chooseinterfacedialog.h SOURCES += ndgui.cpp \ main.cpp \ - logreceiver.cpp + logreceiver.cpp \ + abortbootdialog.cpp \ + chooseinterfacedialog.cpp FORMS += ndgui.ui \ logreceiver.ui RESOURCES += diff --git a/workspace/LogReceiver/abortbootdialog.cpp b/workspace/LogReceiver/abortbootdialog.cpp new file mode 100644 index 0000000..1614f6b --- /dev/null +++ b/workspace/LogReceiver/abortbootdialog.cpp @@ -0,0 +1,98 @@ +#include + +#include "abortbootdialog.h" + +AbortBootDialog::AbortBootDialog(QWidget *parent) : + QDialog(parent) +{ + oneMinuteCountdown = 60; + + createContentGroupBox(); + createButtonGroupBox(); + + createTimer(); + + mainLayout = new QVBoxLayout; + mainLayout->addWidget(contentGroupBox); + mainLayout->addWidget(buttonGroupBox); + + setLayout(mainLayout); + setWindowTitle(tr("Abort Boot")); +} +void AbortBootDialog::createContentGroupBox() +{ + contentGroupBox = new QGroupBox; + timerLabel = new QLabel(QString::number(oneMinuteCountdown)); + QHBoxLayout *layout = new QHBoxLayout; + + + layout->addWidget(new QLabel(tr("test"))); + layout->addWidget(timerLabel); + contentGroupBox->setLayout(layout); +} + +void AbortBootDialog::createButtonGroupBox() +{ + buttonGroupBox = new QGroupBox; + QHBoxLayout *layout = new QHBoxLayout; + + QPushButton *shutDownButton = new QPushButton(tr("Shut Down")); + shutDownButton->setDefault(true); + QPushButton *restartButton = new QPushButton(tr("Restart")); + restartButton->setAutoDefault(false); + QPushButton *showLogButton = new QPushButton(tr("Show Log")); + showLogButton->setAutoDefault(false); + + connect(showLogButton, SIGNAL(clicked()),this, SLOT(showLogButtonClicked())); + connect(shutDownButton, SIGNAL(clicked()), this, SLOT(shutDownButtonClicked())); + connect(restartButton, SIGNAL(clicked()), this, SLOT(restartButtonClicked())); + + layout->addWidget(showLogButton); + layout->addWidget(restartButton); + layout->addWidget(shutDownButton); + buttonGroupBox->setLayout(layout); +} + +void AbortBootDialog::createTimer() +{ + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()),this, SLOT(timerLabelUpdate())); + timer->start(1000); +} + +void AbortBootDialog::showLogButtonClicked() +{ + qDebug() << "show log button clicked"; + emit showLogSignal(); +} + +void AbortBootDialog::shutDownButtonClicked() +{ + qDebug() << "shut down button clicked"; + emit shutDownSignal(); +} + +void AbortBootDialog::restartButtonClicked() +{ + qDebug() << "restart button clicked"; + emit restartSignal(); +} + +void AbortBootDialog::timerLabelUpdate() +{ + oneMinuteCountdown = oneMinuteCountdown -1; + timerLabel->setText(QString::number(oneMinuteCountdown)); + if(oneMinuteCountdown <= 0) + { + timer->stop(); + emit shutDownSignal(); + } + +} + +void AbortBootDialog::closeDialog() +{ + this->hide(); + this->killTimer(timer->timerId()); + this->close(); +} diff --git a/workspace/LogReceiver/abortbootdialog.h b/workspace/LogReceiver/abortbootdialog.h new file mode 100644 index 0000000..157331b --- /dev/null +++ b/workspace/LogReceiver/abortbootdialog.h @@ -0,0 +1,46 @@ +#ifndef ABORTBOOTDIALOG_H +#define ABORTBOOTDIALOG_H + +#include +#include "qboxlayout.h" +#include "qgroupbox.h" +#include "qcombobox.h" +#include "qlabel.h" + + +class AbortBootDialog : public QDialog +{ + Q_OBJECT +public: + explicit AbortBootDialog(QWidget *parent = 0); + + void closeDialog(); +private slots: + void showLogButtonClicked(); + void shutDownButtonClicked(); + void restartButtonClicked(); + void timerLabelUpdate(); + +private: + QVBoxLayout *mainLayout; + QGroupBox *contentGroupBox; + QGroupBox *buttonGroupBox; + QLabel *timerLabel; + QTimer *timer; + int oneMinuteCountdown; + + void createContentGroupBox(); + void createButtonGroupBox(); + void createTimer(); + + +signals: + void showLogSignal(); + void shutDownSignal(); + void restartSignal(); + +public slots: + +}; + +#endif // ABORTBOOTDIALOG_H diff --git a/workspace/LogReceiver/chooseinterfacedialog.cpp b/workspace/LogReceiver/chooseinterfacedialog.cpp new file mode 100644 index 0000000..b7a37e8 --- /dev/null +++ b/workspace/LogReceiver/chooseinterfacedialog.cpp @@ -0,0 +1,98 @@ +#include + +#include "chooseinterfacedialog.h" + +ChooseInterfaceDialog::ChooseInterfaceDialog(QStringList &interfaces, QWidget *parent) : + QDialog(parent) +{ + oneMinuteCountdown = 60; + + createContentGroupBox(interfaces); + createButtonGroupBox(); + + createTimer(); + + mainLayout = new QVBoxLayout; + mainLayout->addWidget(contentGroupBox); + mainLayout->addWidget(buttonGroupBox); + + setLayout(mainLayout); + setWindowTitle(tr("Choose Interface")); +} + +void ChooseInterfaceDialog::createContentGroupBox(QStringList &interfaces) +{ + contentGroupBox = new QGroupBox; + timerLabel = new QLabel(QString::number(oneMinuteCountdown)); + QVBoxLayout *groupBoxLayout = new QVBoxLayout; + QHBoxLayout *layout = new QHBoxLayout; + + comboBox = new QComboBox; + comboBox->addItems(interfaces); + + layout->addWidget(new QLabel(tr("test"))); + layout->addWidget(comboBox); + + groupBoxLayout->addWidget(timerLabel); + groupBoxLayout->addLayout(layout); + contentGroupBox->setLayout(groupBoxLayout); +} + +void ChooseInterfaceDialog::createButtonGroupBox() +{ + buttonGroupBox = new QGroupBox; + QHBoxLayout *layout = new QHBoxLayout; + + QPushButton *continueButton = new QPushButton(tr("Continue")); + continueButton->setDefault(true); + QPushButton *shutDownButton = new QPushButton(tr("Shut Down")); + shutDownButton->setAutoDefault(false); + QPushButton *restartButton = new QPushButton(tr("Restart")); + restartButton->setAutoDefault(false); + + connect(continueButton, SIGNAL(clicked()),this, SLOT(continueButtonClicked())); + connect(shutDownButton, SIGNAL(clicked()), this, SLOT(shutDownButtonClicked())); + connect(restartButton, SIGNAL(clicked()), this, SLOT(restartButtonClicked())); + + layout->addWidget(restartButton); + layout->addWidget(shutDownButton); + layout->addWidget(continueButton); + buttonGroupBox->setLayout(layout); +} + +void ChooseInterfaceDialog::createTimer() +{ + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()),this, SLOT(timerLabelUpdate())); + timer->start(1000); +} + +void ChooseInterfaceDialog::continueButtonClicked() +{ + qDebug() << "continue button clicked"; + emit continueSignal(comboBox->currentText()); +} + +void ChooseInterfaceDialog::shutDownButtonClicked() +{ + qDebug() << "shut down button clicked"; + emit shutDownSignal(); +} + +void ChooseInterfaceDialog::restartButtonClicked() +{ + qDebug() << "restart button clicked"; + emit restartSignal(); +} + +void ChooseInterfaceDialog::timerLabelUpdate() +{ + oneMinuteCountdown = oneMinuteCountdown -1; + timerLabel->setText(QString::number(oneMinuteCountdown)); + if(oneMinuteCountdown <= 0) + { + timer->stop(); + emit continueSignal(comboBox->currentText()); + } + +} diff --git a/workspace/LogReceiver/chooseinterfacedialog.h b/workspace/LogReceiver/chooseinterfacedialog.h new file mode 100644 index 0000000..48ee038 --- /dev/null +++ b/workspace/LogReceiver/chooseinterfacedialog.h @@ -0,0 +1,44 @@ +#ifndef CHOOSEINTERFACEDIALOG_H +#define CHOOSEINTERFACEDIALOG_H + +#include +#include "qboxlayout.h" +#include "qgroupbox.h" +#include "qcombobox.h" +#include "qlabel.h" + +class ChooseInterfaceDialog : public QDialog +{ + Q_OBJECT +public: + explicit ChooseInterfaceDialog(QStringList &interfaces, QWidget *parent = 0); +private slots: + void continueButtonClicked(); + void shutDownButtonClicked(); + void restartButtonClicked(); + void timerLabelUpdate(); + +private: + QVBoxLayout *mainLayout; + QGroupBox *contentGroupBox; + QGroupBox *buttonGroupBox; + QComboBox *comboBox; + QLabel *timerLabel; + QTimer *timer; + int oneMinuteCountdown; + + void createContentGroupBox(QStringList &interfaces); + void createButtonGroupBox(); + void createTimer(); + +signals: + void continueSignal(QString ifName); + void shutDownSignal(); + void restartSignal(); + + +public slots: + +}; + +#endif // CHOOSEINTERFACEDIALOG_H diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 70d49e6..93e8373 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -207,6 +207,29 @@ void LogReceiver::checkInternetConnection(QList &interfaces) { checkInternetConnection(nI); } } +void LogReceiver::checkInternetConnectionViaTCP(QString ifName) { + + const bool canStartIAP = (configurationManager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces); + QList configs = configurationManager.allConfigurations(); + QNetworkConfiguration cfg; + foreach(QNetworkConfiguration nC, configs) { + if(nC.name() == ifName) { + cfg = nC; + } + } + + if(!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) { + + return; + } + session = new QNetworkSession(cfg, this); + session->open(); + session->waitForOpened(-1); + + + QTcpSocket *tcpSocket = new QTcpSocket(this); + tcpSocket->connectToHost(); +} void LogReceiver::handleNewConnection() { qDebug() << "New Connection arrived"; @@ -249,25 +272,25 @@ void LogReceiver::handleNewInputLine(QString data) { case LOG_INFO: switch (sst) { case DHCP_DISCOVER: - //emit changeProgressBarValue(pBar, 10); + emit changeProgressBarValue(interface, 10); break; case DHCP_OFFER: - //emit changeProgressBarValue(pBar, 20); + emit changeProgressBarValue(interface, 20); break; case DHCP_REQUEST: - //emit changeProgressBarValue(pBar, 30); + emit changeProgressBarValue(interface, 30); break; case DHCP_ACK: - //emit changeProgressBarValue(pBar, 40); + emit changeProgressBarValue(interface, 40); break; case DHCP_NAK: - //emit changeProgressBarValue(pBar, 40); + emit changeProgressBarValue(interface, 40); break; case DHCPCD_ARP_TEST: - //emit changeProgressBarValue(pBar, 50); + emit changeProgressBarValue(interface, 50); break; case DHCP_DECLINE: - //emit changeProgressBarValue(pBar, 60); + emit changeProgressBarValue(interface, 60); break; case DHCP_RELEASE: @@ -275,13 +298,13 @@ void LogReceiver::handleNewInputLine(QString data) { case DHCP_INFORM: break; case DHCPCD_CONFIGURE: - //emit changeProgressBarValue(pBar, 70); + emit changeProgressBarValue(interface, 70); break; case DHCPCD_WRITE: - //emit changeProgressBarValue(pBar, 80); + emit changeProgressBarValue(interface, 80); break; case DHCPCD_EXIT: - //emit changeProgressBarValue(pBar, 100); + emit changeProgressBarValue(interface, 100); break; case DHCPCD_LOG: diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index c4e165d..143cbef 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -61,6 +61,7 @@ private: bool checkCarrierState(QString interface); void checkInternetConnection(QString ifName); void checkInternetConnection(QList &interfaces); + void checkInternetConnectionViaTCP(QString ifName); QList getListOfNetworkInterfaces(); bool checkBlackList(QString i); diff --git a/workspace/LogReceiver/ndgui.cpp b/workspace/LogReceiver/ndgui.cpp index 78aa280..a839aef 100644 --- a/workspace/LogReceiver/ndgui.cpp +++ b/workspace/LogReceiver/ndgui.cpp @@ -1,4 +1,6 @@ #include "ndgui.h" +#include "chooseinterfacedialog.h" +#include "abortbootdialog.h" ndgui::ndgui(QWidget *parent) : QWidget(parent) @@ -93,6 +95,7 @@ void ndgui::handleConnectionEstablished(QString ifName) { void ndgui::handleAbortBoot(QString msg) { qDebug() << "abort boot. reason:" << msg; + showAbortBootDialog(); } void ndgui::handleUpdateStatusLabel(QString ifName, QString status) { @@ -103,5 +106,79 @@ void ndgui::handleUpdateStatusLabel(QString ifName, QString status) { void ndgui::handleAllProcessesFinished() { qDebug() << "all Processes finished"; - mainLayout-> + if (finalUsableInterfaces.size() > 0) { + showChooseInterfaceDialog(); + } else { + showAbortBootDialog(); + } +} + +void ndgui::showAbortBootDialog() { + aBD = new AbortBootDialog(this); + connect(aBD, SIGNAL(showLogSignal()), this, SLOT(showLog())); + connect(aBD, SIGNAL(restartSignal()), this, SLOT(restartSystem())); + connect(aBD, SIGNAL(shutDownSignal()), this, SLOT(shutDownSystem())); + aBD->setModal(true); + aBD->show(); +} + +void ndgui::showChooseInterfaceDialog() { + cID = new ChooseInterfaceDialog(finalUsableInterfaces, this); + connect(cID, SIGNAL(continueSignal(QString)), this, + SLOT(continueBoot(QString))); + connect(cID, SIGNAL(restartSignal()), this, SLOT(restartSystem())); + connect(cID, SIGNAL(shutDownSignal()), this, SLOT(shutDownSystem())); + cID->setModal(true); + cID->show(); +} + +void ndgui::restartSystem() +{ + + if(qobject_cast(QObject::sender())>0) + { + qDebug() << "received Signal restart abd"; + aBD->closeDialog(); + } + else if(qobject_cast(QObject::sender())>0) + { + qDebug() << "received Signal restart cid"; + cID->close(); + } + else + { + qDebug() << "unknown sender" << QObject::sender(); + } + + +} + +void ndgui::shutDownSystem() +{ + if(qobject_cast(QObject::sender())>0) + { + + aBD->closeDialog(); + } + else if(qobject_cast(QObject::sender())>0) + { + + cID->close(); + } + else + { + qDebug() << "unknown sender" << QObject::sender(); + } + +} + +void ndgui::continueBoot(QString ifName) +{ + QString text = "continue with interface: " + ifName; + cID->close(); +} + +void ndgui::showLog() +{ + qDebug() << "show log"; } diff --git a/workspace/LogReceiver/ndgui.h b/workspace/LogReceiver/ndgui.h index a3b1e70..e8b0b85 100644 --- a/workspace/LogReceiver/ndgui.h +++ b/workspace/LogReceiver/ndgui.h @@ -8,6 +8,8 @@ #include "qboxlayout.h" #include "ui_ndgui.h" #include "logreceiver.h" +#include "chooseinterfacedialog.h" +#include "abortbootdialog.h" class ndgui: public QWidget { Q_OBJECT @@ -24,15 +26,26 @@ public slots: void handleUpdateStatusLabel(QString ifName, QString status); void handleAllProcessesFinished(); + void restartSystem(); + void shutDownSystem(); + void continueBoot(QString ifName); + void showLog(); + + void showAbortBootDialog(); + void showChooseInterfaceDialog(); + private: Ui::ndguiClass ui; LogReceiver logReceiver; - QList finalUsableInterfaces; + QStringList finalUsableInterfaces; int numberOfInterfaces; + ChooseInterfaceDialog *cID; + AbortBootDialog *aBD; + /*gui elements*/ QMap progressBars; QMap statusLabels; @@ -42,6 +55,9 @@ private: QVBoxLayout *interfaceGroupBoxLayout; /**/ + + + /*gui functions*/ void buildGui(); void createInterfaceGroupBox(); -- cgit v1.2.3-55-g7522