diff options
author | Jonathan Bauer | 2012-02-23 10:03:25 +0100 |
---|---|---|
committer | Jonathan Bauer | 2012-02-23 10:03:25 +0100 |
commit | 259a2e0ff8984325b59bc6dd7d9611867557865d (patch) | |
tree | 96ba68a14afdbfb3011a417a947a8b34358b6c6d | |
parent | connected interfaces saved in networkdiscovery class and now accessed by gett... (diff) | |
download | fbgui-259a2e0ff8984325b59bc6dd7d9611867557865d.tar.gz fbgui-259a2e0ff8984325b59bc6dd7d9611867557865d.tar.xz fbgui-259a2e0ff8984325b59bc6dd7d9611867557865d.zip |
improved user choice coding...
-rw-r--r-- | src/fbgui/ndgui.cpp | 30 | ||||
-rw-r--r-- | src/fbgui/ndgui.h | 6 | ||||
-rw-r--r-- | src/fbgui/networkdiscovery.cpp | 48 | ||||
-rw-r--r-- | src/fbgui/networkdiscovery.h | 8 |
4 files changed, 43 insertions, 49 deletions
diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index ad7ff5f..c74ae82 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -43,9 +43,6 @@ void ndgui::init() { setWindowTitle(tr("NetD")); _started = false; - _userChoice = false; - - addActions(); _networkDiscovery = new NetworkDiscovery(); _jsi = new JavascriptInterfaceNDGUI(_webView->page()->mainFrame(), _networkDiscovery); @@ -62,8 +59,8 @@ void ndgui::init() { connect(_networkDiscovery, SIGNAL(changeProgressBarValue(const QString & , const int& )), _jsi, SLOT(updateIfProgressBar(const QString & , const int&))); - connect(_networkDiscovery, SIGNAL(allProcessesFinished()), this, - SLOT(handleAllProcessesFinished())); + connect(_networkDiscovery, SIGNAL(allProcessesFinished(bool)), this, + SLOT(handleAllProcessesFinished(bool))); connect(_jsi, SIGNAL(startFbgui(const QString&)), this, SLOT(continueBoot(const QString&))); connect(_networkDiscovery, SIGNAL(continueBootWithoutCheck(QString )), @@ -79,6 +76,9 @@ void ndgui::init() { } else { _webView->load(QUrl("qrc:html/networkdiscovery.html")); } + + addActions(); + showFullScreen(); } @@ -91,7 +91,8 @@ void ndgui::init() { void ndgui::addActions() { _allowUserChoice = new QAction(tr("&userChoice"), this); _allowUserChoice->setShortcut(QKeySequence(Qt::Key_F5)); - connect(_allowUserChoice, SIGNAL(triggered()), this, SLOT(setUserChoiceTrue())); + connect(_allowUserChoice, SIGNAL(triggered()), + this->_networkDiscovery, SLOT(activateUserChoice())); this->addAction(_allowUserChoice); _tryAgain = new QAction(tr("&tryAgain"), this); _tryAgain->setShortcut(QKeySequence(Qt::Key_F9)); @@ -100,16 +101,6 @@ void ndgui::addActions() { } /** - * @brief set userChoice true - * - * is the connected to the triggered action pressing the F5 button. - * set the _userChoice member true - */ -void ndgui::setUserChoiceTrue() { - _userChoice = true; -} - -/** * @brief start the network discovery * * main starting point of the whole procedure. @@ -119,7 +110,7 @@ void ndgui::setUserChoiceTrue() { void ndgui::startNetworkDiscovery() { if (!_started) { _started = true; - _networkDiscovery->initAndRun(_userChoice); + _networkDiscovery->init(); } else { LOG4CXX_DEBUG(ndLogger, "NetworkDiscovery already started"); } @@ -135,12 +126,12 @@ void ndgui::startNetworkDiscovery() { * choose interface dialog (one or more interface names in the list (add with * handleConnectionEstablished)). */ -void ndgui::handleAllProcessesFinished() { +void ndgui::handleAllProcessesFinished(bool userChoice) { LOG4CXX_DEBUG(ndLogger, "all Processes finished"); _allowUserChoice->setEnabled(false); QList<QString> ifConnectedList = _networkDiscovery->getIfConnectedList(); if (ifConnectedList.size() > 0) { - if (_userChoice) { + if (userChoice) { _jsi->chooseInterfaceDialog(ifConnectedList); } else { foreach(QString i, ifConnectedList) @@ -194,7 +185,6 @@ void ndgui::tryAgain() { LOG4CXX_DEBUG(ndLogger, " try again "); _networkDiscovery->prepareTryAgain(); delete _allowUserChoice; - delete _tryAgain; delete _networkDiscovery; _ifNameList.clear(); diff --git a/src/fbgui/ndgui.h b/src/fbgui/ndgui.h index 3686c90..b884fb0 100644 --- a/src/fbgui/ndgui.h +++ b/src/fbgui/ndgui.h @@ -35,7 +35,7 @@ public slots: void startNetworkDiscovery(); - void handleAllProcessesFinished(); + void handleAllProcessesFinished(bool userChoice); void continueBootWithoutCheck(QString ifName); void continueBoot(const QString& ifName); @@ -45,9 +45,6 @@ public slots: signals: void initFbgui(); -private slots: - void setUserChoiceTrue(); - private: void addActions(); @@ -57,7 +54,6 @@ private: QAction* _allowUserChoice; QAction* _tryAgain; - bool _userChoice; bool _started; QList<QString> _ifNameList; diff --git a/src/fbgui/networkdiscovery.cpp b/src/fbgui/networkdiscovery.cpp index 7b75ec5..da9a148 100644 --- a/src/fbgui/networkdiscovery.cpp +++ b/src/fbgui/networkdiscovery.cpp @@ -46,31 +46,16 @@ NetworkDiscovery::~NetworkDiscovery() { /** * initialize all important class members and start the main work. * - * @param userChoice - * true if the user wishes to have a user choice. true: the chooseInterfaceDialog will be showed. - * * @param args * additional arguments for the customdhcpcd client. (default value: NULL) */ -void NetworkDiscovery::initAndRun(bool userChoice, QStringList* args) { +void NetworkDiscovery::init(QStringList* args) { - _userChoice = userChoice; _blocked = false; _numberOfProcesses = 0; _ifUpCountdown = 10; - _errorStr = ""; - - _clientProcessToIfNameMap.clear(); - _clients.clear(); - _dhcpcdArguments.clear(); - _ifDownList.clear(); - _ifNameToClient.clear(); - _ifUpList.clear(); - _ifcMap.clear(); - - _server = new QLocalServer(); _networkManager = new NetworkManager(); @@ -120,8 +105,9 @@ void NetworkDiscovery::initAndRun(bool userChoice, QStringList* args) { _dhcpcdArguments.append(*args); } emit updateStatus("start mainwork"); - mainWork(); + run(); } + //------------------------------------------------------------------------- // Main Network Discovery Flow //------------------------------------------------------------------------- @@ -132,7 +118,7 @@ void NetworkDiscovery::initAndRun(bool userChoice, QStringList* args) { * check every second the IsRunning state. Do this as long the counter (@see _ifUpCountdown) is greater than 0. * Default: _ifUpCountdown = 10. */ -void NetworkDiscovery::mainWork() { +void NetworkDiscovery::run() { gAutoUp ? emit updateStatus("search for usable interfaces (with auto Up)") : emit updateStatus("search for usable interfaces"); @@ -377,7 +363,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, if (!_userChoice) { // blockiere jeden weiteren check _blocked = true; - emit allProcessesFinished(); + emit allProcessesFinished(_userChoice); } } } @@ -389,7 +375,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, } //_numberOfProcesses = _numberOfProcesses - 1; && _userChoice if (_numberOfProcesses <= 0) { - emit allProcessesFinished(); + emit allProcessesFinished(_userChoice); } } } else { @@ -498,6 +484,17 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { //------------------------------------------------------------------------- /** +* @brief set userChoice true +* +* is the connected to the triggered action pressing the F5 button. +* set the _userChoice member true +*/ +void NetworkDiscovery::activateUserChoice() { + LOG4CXX_DEBUG(ndcLogger, "Activating user dialog..."); + _userChoice = true; +} + +/** * replace the dhcp configuration with the manual config, entered by the user. * if we can not establish a connection with the entered values, reset to the old * dhcp values. @@ -782,13 +779,22 @@ const QString& NetworkDiscovery::getErrorStr() { */ void NetworkDiscovery::tryAgain() { prepareTryAgain(); - initAndRun(_userChoice); + init(); } /**/ void NetworkDiscovery::prepareTryAgain() { // kill all cdhcpcd processes killDHCPCD(); + _clientProcessToIfNameMap.clear(); + _clients.clear(); + _dhcpcdArguments.clear(); + _ifDownList.clear(); + _ifNameToClient.clear(); + _ifUpList.clear(); + _ifcMap.clear(); + _errorStr = ""; + /* foreach(Q_PID pid , _pidsList) { if (kill(pid,SIGKILL) <= -1) diff --git a/src/fbgui/networkdiscovery.h b/src/fbgui/networkdiscovery.h index 3675120..3fb73a3 100644 --- a/src/fbgui/networkdiscovery.h +++ b/src/fbgui/networkdiscovery.h @@ -39,7 +39,7 @@ public: NetworkDiscovery(QObject *parent = 0); ~NetworkDiscovery(); - void initAndRun(bool userChoice, QStringList* args = NULL); + void init(QStringList* args = NULL); bool checkConnectivity(QString ifName); bool checkConnectivityViaTcp(); @@ -68,6 +68,8 @@ public slots: void handleProcessStarted(); void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); + void activateUserChoice(); + signals: void updateStatus(QString status); @@ -75,13 +77,13 @@ signals: void updateIfStatus(QString ifName, QString status); void changeProgressBarValue(const QString & ifName, const int $newValue); - void allProcessesFinished(); + void allProcessesFinished(bool userChoice); void continueBootWithoutCheck(QString ifName); void abortBoot(QString msg); private: - void mainWork(); + void run(); void getListOfNetworkInterfaces(); void getListOfNetworkInterfacesWithAutoUp(); |