From 65cb7d51b2b5aa136fa73777a83fa6792e459743 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 24 Mar 2011 16:17:22 +0100 Subject: 2nd batch --- src/fbgui.cpp | 306 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 153 insertions(+), 153 deletions(-) (limited to 'src') diff --git a/src/fbgui.cpp b/src/fbgui.cpp index a155616..c5d3385 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -22,71 +22,71 @@ int debugMode = -1; //------------------------------------------------------------------------------------------- fbgui::fbgui() { - // test for libsys function - SysInfoLibsysfs* sil = new SysInfoLibsysfs(); - sil->getInfoAboutNetworkInterface(); - sil->getInfoAboutClassNet(); + // test for libsys function + SysInfoLibsysfs* sil = new SysInfoLibsysfs(); + sil->getInfoAboutNetworkInterface(); + sil->getInfoAboutClassNet(); - setupBasicDebug(); - setupLayout(); - createActions(); + setupBasicDebug(); + setupLayout(); + createActions(); - // initialize javascript interface - JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame()); - QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); - QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), - jsi, SLOT(attachToDOM())); + // initialize javascript interface + JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame()); + QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); + QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), + jsi, SLOT(attachToDOM())); - // initialize download manager - DownloadManager* dm = new DownloadManager(); - QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), - jsi, SLOT(downloadInfo(const QString&, const double&))); - QObject::connect(dm, SIGNAL(notify(const QString&)), - jsi, SLOT(notify(const QString&))); - QObject::connect(jsi, SIGNAL(requestFile(const QString&)), - dm, SLOT(downloadFile(const QString&))); - QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)), - jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); - QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); + // initialize download manager + DownloadManager* dm = new DownloadManager(); + QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), + jsi, SLOT(downloadInfo(const QString&, const double&))); + QObject::connect(dm, SIGNAL(notify(const QString&)), + jsi, SLOT(notify(const QString&))); + QObject::connect(jsi, SIGNAL(requestFile(const QString&)), + dm, SLOT(downloadFile(const QString&))); + QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)), + jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); + QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); - // show filler page - _webView->load(QUrl("qrc:/html/loadAbout.html")); - // start watching for fileToTriggerURL - watchForTrigger(); + // show filler page + _webView->load(QUrl("qrc:/html/loadAbout.html")); + // start watching for fileToTriggerURL + watchForTrigger(); - // set properties - setWindowTitle("fbgui"); - setAttribute(Qt::WA_QuitOnClose, true); - setWindowFlags(Qt::FramelessWindowHint); - showFullScreen(); + // set properties + setWindowTitle("fbgui"); + setAttribute(Qt::WA_QuitOnClose, true); + setWindowFlags(Qt::FramelessWindowHint); + showFullScreen(); } //------------------------------------------------------------------------------------------- // Layout / actions setup //------------------------------------------------------------------------------------------- void fbgui::setupLayout() { - // setup layout of the gui: debug split or browser - _webView = new QWebView(this); - if (debugMode == 1){ - // split main window in browser & debug console - createDebugConsole(); - _splitter = new QSplitter(Qt::Vertical, this); - _splitter->addWidget(_webView); - _splitter->addWidget(_debugConsole); - setCentralWidget(_splitter); - } - else - setCentralWidget(_webView); + // setup layout of the gui: debug split or browser + _webView = new QWebView(this); + if (debugMode == 1){ + // split main window in browser & debug console + createDebugConsole(); + _splitter = new QSplitter(Qt::Vertical, this); + _splitter->addWidget(_webView); + _splitter->addWidget(_debugConsole); + setCentralWidget(_splitter); + } + else + setCentralWidget(_webView); } //------------------------------------------------------------------------------------------- void fbgui::createActions() { - // CTRL + X to kill the gui - _quit = new QAction(tr("&quit"), this); - _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); - this->addAction(_quit); - connect(_quit, SIGNAL(triggered()), this, SLOT(close())); + // CTRL + X to kill the gui + _quit = new QAction(tr("&quit"), this); + _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); + this->addAction(_quit); + connect(_quit, SIGNAL(triggered()), this, SLOT(close())); } //------------------------------------------------------------------------------------------- // File system watching @@ -96,153 +96,153 @@ void fbgui::watchForTrigger() // check if the directory to fileToTriggerURL exists QFileInfo fi(fileToTriggerURL); if (!fi.absoluteDir().exists()){ - qxtLog->debug() << "[watcher] " << fi.absolutePath() << " does not exists!"; - if (QDir::home().mkdir(fi.absolutePath())) - qxtLog->debug() << "[watcher] Successfully created " << fi.absolutePath(); - else - qxtLog->debug() << "[watcher] Failed to create " << fi.absolutePath(); + qxtLog->debug() << "[watcher] " << fi.absolutePath() << " does not exists!"; + if (QDir::home().mkdir(fi.absolutePath())) + qxtLog->debug() << "[watcher] Successfully created " << fi.absolutePath(); + else + qxtLog->debug() << "[watcher] Failed to create " << fi.absolutePath(); } else - qxtLog->debug() << "[watcher] " << fi.absolutePath() << " exists!"; + qxtLog->debug() << "[watcher] " << fi.absolutePath() << " exists!"; // check if fileToTriggerURL already exists if (fi.exists()){ - qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!"; - // try to remove it - QFile file(fi.absoluteFilePath()); - if (file.remove()) - qxtLog->debug() << "[watcher] Purged: " << file.fileName(); - else{ - qxtLog->debug() << "[watcher] Could not remove: " << file.fileName(); - exit(EXIT_FAILURE); - } + qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!"; + // try to remove it + QFile file(fi.absoluteFilePath()); + if (file.remove()) + qxtLog->debug() << "[watcher] Purged: " << file.fileName(); + else{ + qxtLog->debug() << "[watcher] Could not remove: " << file.fileName(); + exit(EXIT_FAILURE); + } } else { - // watch the path where trigger file is expected - qxtLog->debug() << "[watcher] Watching " << fi.absolutePath() - << " for file: " << fi.fileName(); + // watch the path where trigger file is expected + qxtLog->debug() << "[watcher] Watching " << fi.absolutePath() + << " for file: " << fi.fileName(); QStringList pathToWatch(fi.absolutePath()); _watcher = new QFileSystemWatcher(pathToWatch, this); QObject::connect(_watcher, SIGNAL(directoryChanged(const QString&)), - this, SLOT(checkForTrigger(const QString&))); + this, SLOT(checkForTrigger(const QString&))); } } //------------------------------------------------------------------------------------------- void fbgui::checkForTrigger(const QString& dirname) { - // check if fileToTriggerURL exists in the directory where the change occured - QFileInfo tfi(fileToTriggerURL); - QFileInfo fi(dirname + "/" + tfi.fileName()); - if (fi.exists()){ - qxtLog->debug() << "[watcher] " << fileToTriggerURL << " detected."; - loadURL(); - } - else - // do nothing / keep watching - qxtLog->debug() << "[watcher] weird file!"; + // check if fileToTriggerURL exists in the directory where the change occured + QFileInfo tfi(fileToTriggerURL); + QFileInfo fi(dirname + "/" + tfi.fileName()); + if (fi.exists()){ + qxtLog->debug() << "[watcher] " << fileToTriggerURL << " detected."; + loadURL(); + } + else + // do nothing / keep watching + qxtLog->debug() << "[watcher] weird file!"; } //------------------------------------------------------------------------------------------- // Preparations for URL load //------------------------------------------------------------------------------------------- bool fbgui::checkHost() const { - QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); - if (hostInfo.error() != QHostInfo::NoError){ - qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed. Exiting..."; - return false; - } - else{ - qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded."; - return true; - } + QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); + if (hostInfo.error() != QHostInfo::NoError){ + qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed. Exiting..."; + return false; + } + else{ + qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded."; + return true; + } } //------------------------------------------------------------------------------------------- void fbgui::loadURL() { - // load if host is valid - if (checkHost()){ - qxtLog->debug() << "[gui] Loading URL..."; - QByteArray postData = generatePOSTData(); - qxtLog->debug() << "[gui] POST data: " << postData; - QNetworkRequest req(baseURL); - _webView->load(req, QNetworkAccessManager::PostOperation, postData); - } - // disconnect _watcher, his job is done - qxtLog->debug() << "[watcher] see you soon!"; - _watcher->disconnect(this); + // load if host is valid + if (checkHost()){ + qxtLog->debug() << "[gui] Loading URL..."; + QByteArray postData = generatePOSTData(); + qxtLog->debug() << "[gui] POST data: " << postData; + QNetworkRequest req(baseURL); + _webView->load(req, QNetworkAccessManager::PostOperation, postData); + } + // disconnect _watcher, his job is done + qxtLog->debug() << "[watcher] see you soon!"; + _watcher->disconnect(this); } //------------------------------------------------------------------------------------------- QByteArray fbgui::generatePOSTData() { - qxtLog->debug() << "[gui] Generating POST data..."; - // hash testing - SysInfo si; - QByteArray data(si.getInfo("mac").toUtf8()); - qxtLog->debug() << "[post] Hashing: " << data; - QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); - qxtLog->debug() << "[post] MD5 Hash: " << hash.toHex(); + qxtLog->debug() << "[gui] Generating POST data..."; + // hash testing + SysInfo si; + QByteArray data(si.getInfo("mac").toUtf8()); + qxtLog->debug() << "[post] Hashing: " << data; + QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5); + qxtLog->debug() << "[post] MD5 Hash: " << hash.toHex(); - // fetch serial number from usb rootfs - QByteArray serial; - QFile file(serialLocation); - if (!file.open(QIODevice::ReadOnly)){ - qxtLog->debug() << "[post] No such file: " << file.fileName(); - serial = "10-23-43-55-67"; // tests - } - // everything ok, read data - serial = file.readAll(); - file.close(); - serial.chop(1); // chop EOF - qxtLog->debug() << "[post] Serial number is: " << serial; + // fetch serial number from usb rootfs + QByteArray serial; + QFile file(serialLocation); + if (!file.open(QIODevice::ReadOnly)){ + qxtLog->debug() << "[post] No such file: " << file.fileName(); + serial = "10-23-43-55-67"; // tests + } + // everything ok, read data + serial = file.readAll(); + file.close(); + serial.chop(1); // chop EOF + qxtLog->debug() << "[post] Serial number is: " << serial; - // construct final byte array - QByteArray postData("bootisoID=1"); - postData.append("&mac=" + si.getInfo("mac")); - postData.append("&hardwarehash=" + hash.toHex()); - postData.append("&serial=" + serial); - return postData; + // construct final byte array + QByteArray postData("bootisoID=1"); + postData.append("&mac=" + si.getInfo("mac")); + postData.append("&hardwarehash=" + hash.toHex()); + postData.append("&serial=" + serial); + return postData; } //------------------------------------------------------------------------------------------- // Debug setup / control //------------------------------------------------------------------------------------------- void fbgui::setupBasicDebug() { - // start basic console debug log - if (debugMode == 0 || debugMode == 1){ - qxtLog->disableLoggerEngine("DEFAULT"); - qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); - qxtLog->initLoggerEngine("std_logger"); - qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); - qxtLog->enableLogLevels(QxtLogger::DebugLevel); - qxtLog->debug() << "Initializing fbgui..."; - } + // start basic console debug log + if (debugMode == 0 || debugMode == 1){ + qxtLog->disableLoggerEngine("DEFAULT"); + qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); + qxtLog->initLoggerEngine("std_logger"); + qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); + qxtLog->enableLogLevels(QxtLogger::DebugLevel); + qxtLog->debug() << "Initializing fbgui..."; + } } //------------------------------------------------------------------------------------------- void fbgui::createDebugConsole() { - // create the debug console widget - _debugConsole = new QTextEdit(this); - _debugConsole->setWindowFlags(Qt::FramelessWindowHint); - // fanciness - QPalette pal; - pal.setColor(QPalette::Base, Qt::black); - _debugConsole->setPalette(pal); - _debugConsole->setTextColor(Qt::white); - // enable custom logger engine - qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole)); - //qxtLog->initLoggerEngine("fb_logger"); - qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); - // CTRL + D toggles debug window - _toggleDebugConsole = new QAction(tr("&toggleDebug"), this); - _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - addAction(_toggleDebugConsole); - connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole())); + // create the debug console widget + _debugConsole = new QTextEdit(this); + _debugConsole->setWindowFlags(Qt::FramelessWindowHint); + // fanciness + QPalette pal; + pal.setColor(QPalette::Base, Qt::black); + _debugConsole->setPalette(pal); + _debugConsole->setTextColor(Qt::white); + // enable custom logger engine + qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole)); + //qxtLog->initLoggerEngine("fb_logger"); + qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); + // CTRL + D toggles debug window + _toggleDebugConsole = new QAction(tr("&toggleDebug"), this); + _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + addAction(_toggleDebugConsole); + connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole())); } //------------------------------------------------------------------------------------------- void fbgui::toggleDebugConsole() { - if (_debugConsole->isVisible()) - _debugConsole->hide(); - else - _debugConsole->show(); + if (_debugConsole->isVisible()) + _debugConsole->hide(); + else + _debugConsole->show(); } -- cgit v1.2.3-55-g7522