From 9fabc0bd3cb496dc77c872993ea2b54cbd2e71bf Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 21 Feb 2012 19:06:08 +0100 Subject: globals in extra class, new javascript interface classes for fbgui and ndgui, various cleanups in ndgui... --- src/fbgui/ndgui.cpp | 309 +++++++--------------------------------------------- 1 file changed, 37 insertions(+), 272 deletions(-) (limited to 'src/fbgui/ndgui.cpp') diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index a95d884..40c7cea 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -10,6 +10,7 @@ #include "ndgui.h" +#include "javascriptinterfacendgui.h" #include #include "qlog4cxx.h" @@ -18,63 +19,51 @@ using namespace log4cxx; using namespace log4cxx::helpers; LoggerPtr ndLogger(Logger::getLogger("fbgui.nd")); - -QString gServerIp(""); -bool gAutoUp = true; -QString gSocketServerPath(""); -QString gPathToDhcpExe(""); -QString interfaceName(""); - - /** * constructor */ ndgui::ndgui() : agui() { -} - +} /** * destructor */ ndgui::~ndgui() { - delete _allowUserChoice; delete _tryAgain; delete _networkDiscovery; - } - - /** * @brief initialize all variables and prepare everything for a successful run */ void ndgui::init() { - LOG4CXX_DEBUG(ndLogger, "Initializing ndgui..."); + setWindowTitle(tr("NetD")); _started = false; _userChoice = false; - _ifNameList.clear(); - _manConfList.clear(); addActions(); _networkDiscovery = new NetworkDiscovery(); - connect(_networkDiscovery, SIGNAL(addInterface(const QString &)), this, + _jsi = new JavascriptInterfaceNDGUI(_webView->page()->mainFrame(), _networkDiscovery); + + + connect(_networkDiscovery, SIGNAL(addInterface(const QString &)), _jsi, SLOT(addInterface( const QString &))); connect(_networkDiscovery, SIGNAL(changeProgressBarValue(const QString & , const int& )), - this, SLOT(updateIfProgressBar(const QString & , const int&))); + _jsi, SLOT(updateIfProgressBar(const QString & , const int&))); connect(_networkDiscovery, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString))); - connect(_networkDiscovery, SIGNAL(abortBoot(QString)), this, + connect(_networkDiscovery, SIGNAL(abortBoot(QString)), _jsi, SLOT(abortBoot(const QString))); - connect(_networkDiscovery, SIGNAL(updateIfStatus(QString,QString)), this, + connect(_networkDiscovery, SIGNAL(updateIfStatus(QString,QString)), _jsi, SLOT(updateIfStatus(const QString &, const QString &))); - connect(_networkDiscovery, SIGNAL(updateStatus(QString)), this, + connect(_networkDiscovery, SIGNAL(updateStatus(QString)), _jsi, SLOT(updateStatus(const QString&))); connect(_networkDiscovery, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); @@ -84,8 +73,8 @@ void ndgui::init() { this, SLOT(continueBootWithoutCheck(QString))); connect(_webView->page()->mainFrame(), SIGNAL( - javaScriptWindowObjectCleared()), this, SLOT(attachToDOM())); - connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(startSingleShot())); + javaScriptWindowObjectCleared()), _jsi, SLOT(attachToDOM())); + connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(startNetworkDiscovery())); if (debugMode > -1) { @@ -93,11 +82,9 @@ void ndgui::init() { } else { _webView->load(QUrl("qrc:html/networkdiscovery.html")); } - - setWindowTitle(tr("NetD")); showFullScreen(); -} +} /** * @brief Add actions @@ -125,25 +112,6 @@ void ndgui::setUserChoiceTrue() { _userChoice = true; } - - -/** - * @brief starts a singleshot event. - * - * is connected to the singleShot event. Triggering this method means - * that we go on with the main NetworkDiscovery screen. - * connects the loadFinished signal of the _webView with the - * startNetworkDiscovery slot and removes the - * action. - */ -void ndgui::startSingleShot() { - - LOG4CXX_DEBUG(ndLogger, "start single shot"); - QTimer::singleShot(3000, this, SLOT(startNetworkDiscovery())); -} - - - /** * @brief start the network discovery * @@ -152,19 +120,15 @@ void ndgui::startSingleShot() { * and starts the networkDiscovery. */ void ndgui::startNetworkDiscovery() { - disconnect(_webView, SIGNAL(loadFinished(bool)), this, - SLOT(startSingleShot())); + //disconnect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(startSingleShot())); if (!_started) { _started = true; - _networkDiscovery->initAndRun(gServerIp, _userChoice, gAutoUp, - logFilePath, gSocketServerPath, gPathToDhcpExe); + _networkDiscovery->initAndRun(_userChoice); } else { LOG4CXX_DEBUG(ndLogger, "NetworkDiscovery already started"); } } - - /** * @brief handle if a interface is able to connect * @@ -192,12 +156,7 @@ void ndgui::handleAllProcessesFinished() { _allowUserChoice->setEnabled(false); if (_ifNameList.size() > 0) { if (_userChoice) { - QString jsonArr = "["; - for (int i = 0; i < _ifNameList.size() - 1; i++) { - jsonArr += "\"" + _ifNameList.value(i) + "\","; - } - jsonArr += "\"" + _ifNameList.last() + "\"]"; - chooseInterfaceDialog(jsonArr); + _jsi->chooseInterfaceDialog(_ifNameList); } else { foreach(QString i, _ifNameList) { @@ -210,12 +169,11 @@ void ndgui::handleAllProcessesFinished() { } else { LOG4CXX_DEBUG(ndLogger, " No usable interfaces found!: " << _networkDiscovery->GetErrorStr()); LOG4CXX_DEBUG(ndLogger, " list is empty"); - abortBoot("No usable interfaces found!" + _jsi->abortBoot("No usable interfaces found!" + _networkDiscovery->GetErrorStr()); } } - /** * @brief continue the boot sequence * @@ -223,43 +181,44 @@ void ndgui::handleAllProcessesFinished() { * will start the fbgui screen. All networkDiscovery signals * will be ignored after this point. */ -//void ndgui::continueBoot(QString ifName, int userChoice) { void ndgui::continueBoot(QString ifName) { if (_networkDiscovery->checkConnectivity(ifName)) { LOG4CXX_DEBUG(ndLogger, " continue with interface: " << ifName); - interfaceName = ifName; + gInterfaceName = ifName; emit initFbgui(); this->close(); } else { - abortBoot( - "Interface was suddenly made unusable. Please check the log and try again."); + _jsi->abortBoot("Interface was suddenly made unusable. Please check the log and try again."); } - } - /** * @brief continue the boot sequence without further checking if the connection is still possible. */ void ndgui::continueBootWithoutCheck(QString ifName) { LOG4CXX_DEBUG(ndLogger, " continue with interface: " << ifName); - interfaceName = ifName; + gInterfaceName = ifName; emit initFbgui(); this->close(); } - +/* slots */ /** - * @brief read the log file. Log File will be presented inside of a dialog. + * @brief adds an interface to the DOM tree. Creates its progress bar and it's status label. + * + * @param ifName + * name of the new interface. */ -QString ndgui::readLogFile() { - LOG4CXX_DEBUG(ndLogger, "show log"); - return _networkDiscovery->readLogFile(); -} - +//void ndgui::addInterface(const QString &ifName) { +// if (ifName == "") +// return; +// _manConfList.append(ifName); +// QString code = QString("addInterface('\%1')").arg(ifName); +// _webView->page()->mainFrame()->evaluateJavaScript(code); +//} /** - * @brief starts the whole application again. + * @brief crashes everything :) */ void ndgui::tryAgain() { LOG4CXX_DEBUG(ndLogger, " try again "); @@ -269,202 +228,8 @@ void ndgui::tryAgain() { //delete _webView; delete _networkDiscovery; - init(); - -} - - -/*test html gui version*/ - -/** - * @brief fills the drop down box of the manual interface configuration - * dialog. - */ -QVariantList ndgui::getManualConfInterfaces() { - LOG4CXX_DEBUG(ndLogger, "call getManualConfInterfaces"); - QVariantList jsonArr; - QString debugOut; - foreach (QString s, _manConfList) { - QVariant e(s); - jsonArr << e; - debugOut += s + "; "; - } - LOG4CXX_DEBUG(ndLogger, "value of jsonArr:" << debugOut); - return jsonArr; -} - - -/** - * @brief return a json formated interface configuration - * - * @param ifName - * the name of the interface - */ -QVariantMap ndgui::getInterfaceConf(QString ifName) { - - return _networkDiscovery->getInterfaceConfig(ifName); -} - - - -/** - * @brief takes the entered manual configuration dates and delivers it - * to the networkDiscovery for further actions. - * - * @param jsonArr - * a jsonArr which contains the manual entered interface configuration - */ -int ndgui::ip4_setManualConfiguration(QVariantMap jsonArr) { - return _networkDiscovery->ip4_setManualConfiguration(jsonArr); - -} - - - -/* slots */ -/************************************************/ -////////////////////////////////////////////////// -/************************************************/ - -/** - * @brief stellt ein ndgui/fbgui Objekt zur verwendung durch die html bereit. - */ -void ndgui::attachToDOM(){ - _webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("fbgui"), this); - loadJQuery(); -} - - - -/** - * @brief load jQuery and js scripts into the page so that all javascript functions will work. - */ -void ndgui::loadJQuery() { - QString js; - QString pathToJsDir(":/html"); - pathToJsDir.append("/js"); - - QDir qrcJSDir(pathToJsDir); - QFileInfoList fiList = qrcJSDir.entryInfoList(); - QFileInfo fi; - foreach(fi, fiList) - { - if (fi.suffix() == "js") { - //LOG4CXX_DEBUG(ndLogger, fi.fileName()); - //LOG4CXX_DEBUG(ndLogger, fi.fileName()); - //if (fi.fileName() != "test.js" && fi.fileName() != "nd-functions.js") { - QFile file; - file.setFileName(pathToJsDir + "/" + fi.fileName()); - file.open(QIODevice::ReadOnly); - js = file.readAll(); - file.close(); - - _webView->page()->mainFrame()->evaluateJavaScript(js); - //LOG4CXX_DEBUG(ndLogger, "evaluated " + fi.fileName()); - //} - } - } -} - - - - -/** - * @brief show abortBoot dialog - * - * @param msg - * the message, displayed in the dialog. - */ -void ndgui::abortBoot(const QString msg) { - QString code = QString("abortBootDialog('\%1')").arg(msg); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - - -/** - * @brief opens ths chooseInterfaceDialog - * - * @param msg - * the interfaces as json formated string. will be displayed in a select box. - */ -void ndgui::chooseInterfaceDialog(const QString msg) { - QString code = QString("chooseInterfaceDialog(\%1)").arg(msg); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - - -/** - * @brief updates the over all status - * - * @param status - * the new status message - */ -void ndgui::updateStatus(const QString &status) { - if (status == "") - return; - QString code = QString("updateStatus('\%1')").arg(status); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - - -/** - * @brief updates the progress bar for each interface. - * - * @param ifname - * the name ot the interface to update - * - * @param percent - * the progress in percent - */ -void ndgui::updateIfProgressBar(const QString &ifName, const int& percent) { - if (percent == 0) - return; - QString code = QString("updateIfProgressBar('\%1',\%2)").arg(ifName).arg(percent); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - - -/** - * @brief update the status for each interface - * - * @param ifName - * the name ot the interface to update - * - * @param status - * the new status of the interface. - */ -void ndgui::updateIfStatus(const QString &ifName, const QString &status) { - if (ifName == "") - return; - QString code = QString("updateIfStatus('\%1','\%2')").arg(ifName).arg(status); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - - -/** - * @brief adds an interface to the DOM tree. Creates its progress bar and it's status label. - * - * @param ifName - * name of the new interface. - */ -void ndgui::addInterface(const QString &ifName) { - if (ifName == "") - return; - _manConfList.append(ifName); - QString code = QString("addInterface('\%1')").arg(ifName); - _webView->page()->mainFrame()->evaluateJavaScript(code); -} - - + _ifNameList.clear(); + _manConfList.clear(); -/** - * @brief just for debugging. - */ -void ndgui::notifyCall(QString msg){ - LOG4CXX_DEBUG(ndLogger, "------ called:" << msg); + init(); } -- cgit v1.2.3-55-g7522