From 3b81d83bf449ef6242489805af15b7da7b197d58 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 21 Sep 2011 16:59:09 +0200 Subject: gui is now html based. still some problems with the jQuery stuff. it does not display anything. --- LogReceiver/ndgui.cpp | 228 +++++++++++++++++++++++++++++++------------------- 1 file changed, 143 insertions(+), 85 deletions(-) (limited to 'LogReceiver/ndgui.cpp') diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp index 7d638c0..7514d8a 100644 --- a/LogReceiver/ndgui.cpp +++ b/LogReceiver/ndgui.cpp @@ -1,60 +1,64 @@ #include "ndgui.h" -#include "chooseinterfacedialog.h" -#include "abortbootdialog.h" -ndgui::ndgui(QWidget *parent) - : QWidget(parent) -{ - ui.setupUi(this); +ndgui::ndgui(QMainWindow *parent) : + QMainWindow(parent) { - connect(&logReceiver, SIGNAL(addNewInterface(QString)), this, SLOT(addNewInterface(QString))); - connect(&logReceiver, SIGNAL(changeProgressBarValue(QString , int )), this, SLOT(handleProgress(QString, int))); - connect(&logReceiver, SIGNAL(connectionEstablished(QString, QString)), this, SLOT(handleConnectionEstablished(QString, QString))); - connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString))); - connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString))); - connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); + connect(&logReceiver, SIGNAL(addInterface(const QString &)), this, SLOT(addInterface( const QString &))); + connect(&logReceiver, SIGNAL(changeProgressBarValue(const QString & , const int& )), this, SLOT(updateIfProgressBar(const QString & , const int&))); + //connect(&logReceiver, SIGNAL(connectionEstablished(interfaceconfiguration*)), this, SLOT(handleConnectionEstablished(interfaceconfiguration*))); + //connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString))); + //connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString))); + //connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); - buildGui(); - logReceiver.initAndRun("/var/tmp/qt_c_socket_custom"); - numberOfInterfaces = 0; + _webView = new QWebView(this); + connect(_webView, SIGNAL(loadFinished(bool)), this, + SLOT(loadFinished(bool))); + connect(_webView->page()->mainFrame(), SIGNAL( + javaScriptWindowObjectCleared()), this, SLOT(attachToDOM())); + setCentralWidget(_webView); + _webView->load(QUrl("qrc:html/networkdiscovery.html")); + _webView->show(); setWindowTitle(tr("NetD")); + setAttribute(Qt::WA_QuitOnClose, true); + setWindowFlags(Qt::FramelessWindowHint); + + logReceiver.initAndRun("/var/tmp/qt_c_socket_custom"); + numberOfInterfaces = 0; + + } -ndgui::~ndgui() -{ +ndgui::~ndgui() { } void ndgui::buildGui() { ndStatusLabel = new QLabel(tr("test")); - ndStatusLabel->setSizePolicy(QSizePolicy::Expanding, - QSizePolicy::Expanding); + 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); - - mainLayout = new QVBoxLayout; - mainLayout->addWidget(ndStatusLabel); - mainLayout->addWidget(interfaceGroupBox); - - setLayout(mainLayout); + setLayout(mainLayout); } -void ndgui::createInterfaceGroupBox(){ - interfaceGroupBox = new QGroupBox(tr("Interfaces")); +void ndgui::createInterfaceGroupBox() { + interfaceGroupBox = new QGroupBox(tr("Interfaces")); - interfaceGroupBoxLayout = new QVBoxLayout; - /* add interfaces via addInterfacesToGroupBox()*/ + interfaceGroupBoxLayout = new QVBoxLayout; + /* add interfaces via addInterfacesToGroupBox()*/ - interfaceGroupBox->setLayout(interfaceGroupBoxLayout); + interfaceGroupBox->setLayout(interfaceGroupBoxLayout); } void ndgui::addNewInterface(QString ifName) { @@ -79,19 +83,18 @@ void ndgui::addNewInterface(QString ifName) { } void ndgui::handleProgress(QString ifName, int newValue) { - qDebug() << "<[---]> SLOT handleProgress activated with: " << ifName << newValue; - QProgressBar * pBar = progressBars.value(ifName); - if(newValue >= pBar->value()) { - pBar->setValue(newValue); - } - else { - qDebug() << "Error: new value is smaller than the old value!"; - } + qDebug() << "<[---]> SLOT handleProgress activated with: " << ifName + << newValue; + QProgressBar * pBar = progressBars.value(ifName); + if (newValue >= pBar->value()) { + pBar->setValue(newValue); + } else { + qDebug() << "Error: new value is smaller than the old value!"; + } } -void ndgui::handleConnectionEstablished(QString ifName, QString gateway) { - finalUsableInterfaces.append(ifName); - // TODO:: Fix this!! use a interfaceconfiguration object instead!!! +void ndgui::handleConnectionEstablished(interfaceconfiguration *ifConf) { + finalUsableIntefacesMap.insert(ifConf->getInterface(), ifConf); } void ndgui::handleAbortBoot(QString msg) { @@ -107,7 +110,7 @@ void ndgui::handleUpdateStatusLabel(QString ifName, QString status) { void ndgui::handleAllProcessesFinished() { qDebug() << "all Processes finished"; - if (finalUsableInterfaces.size() > 0) { + if (finalUsableIntefacesMap.size() > 0) { showChooseInterfaceDialog(); } else { showAbortBootDialog(); @@ -124,7 +127,8 @@ void ndgui::showAbortBootDialog() { } void ndgui::showChooseInterfaceDialog() { - cID = new ChooseInterfaceDialog(finalUsableInterfaces, this); + QStringList list(finalUsableIntefacesMap.keys()); + cID = new ChooseInterfaceDialog(list, this); connect(cID, SIGNAL(continueSignal(QString)), this, SLOT(continueBoot(QString))); connect(cID, SIGNAL(restartSignal()), this, SLOT(restartSystem())); @@ -133,61 +137,115 @@ void ndgui::showChooseInterfaceDialog() { 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::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) - { +void ndgui::shutDownSystem() { + if (qobject_cast (QObject::sender()) > 0) { - aBD->closeDialog(); - } - else if(qobject_cast(QObject::sender())>0) - { + aBD->closeDialog(); + } else if (qobject_cast (QObject::sender()) > 0) { - cID->close(); - } - else - { - qDebug() << "unknown sender" << QObject::sender(); - } + cID->close(); + } else { + qDebug() << "unknown sender" << QObject::sender(); + } } -void ndgui::continueBoot(QString ifName) -{ - QString text = "continue with interface: " + ifName; - cID->close(); +void ndgui::continueBoot(QString ifName) { + QString text = "continue with interface: " + ifName; + cID->close(); } -void ndgui::showLog() -{ - qDebug() << "show log"; +void ndgui::showLog() { + qDebug() << "show log"; } /*test html gui version*/ /* slots */ -void ndgui::addInterface() { - QWebView *view; - view->page()->mainFrame(); - QWebElement element; + +void ndgui::loadFinished(bool ok) { + qDebug() << "load finished:" << ok; +} + +/************************************************/ +////////////////////////////////////////////////// +/************************************************/ + +void ndgui::attachToDOM(){ + _webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("fbgui"), this); + loadJQuery(); +} +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") { + //qDebug()<< fi.fileName(); + //qxtLog->debug() << 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); + //qxtLog->debug() << "evaluated " + fi.fileName(); + } + } + } +} + +//diese methoden müssen später in die javascriptInterface Klasse eingefügt werden. + +// dieser code muss später in die javascriptInterface klasse der fbgui eingefügt werden +// tausche dazu ndgui zu javascriptinterface +// und _webView->page()->mainFrame() zu _parent +void ndgui::updateStatus(const QString &status) { + if (status == "") + return; + QString code = QString("updateStatus('\%1')").arg(status); + _webView->page()->mainFrame()->evaluateJavaScript(code); +} +void ndgui::updateIfProgressBar(const QString &ifName, const int& percent) { + if (percent == 0) + return; + qDebug() << "call updateIfProgressBar"; + QString code = QString("updateIfProgressBar('\%1',\%2)").arg(ifName).arg(percent); + _webView->page()->mainFrame()->evaluateJavaScript(code); +} +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); +} +void ndgui::addInterface(const QString &ifName) { + if (ifName == "") + return; + qDebug() << "call addInterface"; + QString code = QString("addInterface('\%1')").arg(ifName); + _webView->page()->mainFrame()->evaluateJavaScript(code); +} +void ndgui::notifyCall(){ + qDebug() << "------ called"; } -- cgit v1.2.3-55-g7522