diff options
author | Jonathan Bauer | 2011-04-24 21:36:26 +0200 |
---|---|---|
committer | Jonathan Bauer | 2011-04-24 21:36:26 +0200 |
commit | 03ac351f38316d8f923f3797aa7dd0deade7ed5d (patch) | |
tree | c01e300c7a92ce728df907fd85e1a514876b6037 /src | |
parent | more old tests... (diff) | |
download | fbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.tar.gz fbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.tar.xz fbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.zip |
url status handling, 5sec delay before closing gui when exiting with failure (not actually returning 1 atm), lots of formatting...
Diffstat (limited to 'src')
-rw-r--r-- | src/downloadmanager.cpp | 160 | ||||
-rw-r--r-- | src/downloadmanager.h | 57 | ||||
-rw-r--r-- | src/fbgui.cpp | 82 | ||||
-rw-r--r-- | src/fbgui.h | 34 | ||||
-rw-r--r-- | src/fbgui.qrc | 4 | ||||
-rw-r--r-- | src/html/background.png (renamed from src/html/bg.png) | bin | 316905 -> 316905 bytes | |||
-rw-r--r-- | src/html/preload-debug.html | 2 | ||||
-rw-r--r-- | src/html/preload.css (renamed from src/html/style.css) | 2 | ||||
-rw-r--r-- | src/html/preload.html | 2 | ||||
-rw-r--r-- | src/javascriptinterface.cpp | 20 | ||||
-rw-r--r-- | src/javascriptinterface.h | 36 | ||||
-rw-r--r-- | src/loggerengine.cpp | 16 | ||||
-rw-r--r-- | src/loggerengine.h | 31 | ||||
-rw-r--r-- | src/main.cpp | 39 | ||||
-rw-r--r-- | src/sysinfo.cpp | 30 | ||||
-rw-r--r-- | src/sysinfo.h | 28 | ||||
-rw-r--r-- | src/sysinfolibsysfs.cpp | 15 | ||||
-rw-r--r-- | src/sysinfolibsysfs.h | 36 |
18 files changed, 281 insertions, 313 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 22c1c09..8f7d8bb 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1,55 +1,48 @@ #include "downloadmanager.h" -int DownloadManager::downloaded = 0; +int DownloadManager::_downloaded = 0; // ------------------------------------------------------------------------------------------------------- DownloadManager::DownloadManager() { qxtLog->debug() << "Initializing download manager..."; - checkDownloadDirectory(); + check_downloadDirectory(); _qnam = new QNetworkAccessManager(); _qnam->moveToThread(&dmThread); - dip = false; + _dip = false; } DownloadManager::~DownloadManager() { delete _qnam; } // ------------------------------------------------------------------------------------------------------- -void DownloadManager::checkDownloadDirectory() { +void DownloadManager::check_downloadDirectory() { // check if downloadPath exists, if not create it. - downloadDir = QDir(downloadPath); - if (!downloadDir.exists()) { - qxtLog->debug() << "[dm] Download directory: " << downloadDir.path() - << " doesn't exist."; + _downloadDir = QDir(downloadPath); + if (!_downloadDir.exists()) { + qxtLog->debug() << "[dm] Download directory: " << _downloadDir.path() << " doesn't exist."; // try to create the directory if (QDir::current().mkdir(downloadPath)) - qxtLog->debug() << "[dm] Created download directory: " - << downloadDir.path(); + qxtLog->debug() << "[dm] Created download directory: " << _downloadDir.path(); else { - qxtLog->debug() << "[dm] Failed to create directory: " - << downloadDir.path(); + qxtLog->debug() << "[dm] Failed to create directory: " << _downloadDir.path(); // try to save to /tmp/fbgui - downloadDir.setPath(QDir::tempPath() + "/fbgui"); - if (!downloadDir.exists()) { + _downloadDir.setPath(QDir::tempPath() + "/fbgui"); + if (!_downloadDir.exists()) { if (QDir::current().mkdir(QDir::tempPath() + "/fbgui")) - qxtLog->debug() << "[dm] Successfully created: " - << downloadDir.absolutePath(); + qxtLog->debug() << "[dm] Successfully created: " << _downloadDir.absolutePath(); else { // just in case - qxtLog->debug() << "[dm] Failed to create: " - << downloadDir.absolutePath(); + qxtLog->debug() << "[dm] Failed to create: " << _downloadDir.absolutePath(); qxtLog->debug() << "[dm] Exiting..."; exit( EXIT_FAILURE); } } else - qxtLog->debug() << "[dm] " << downloadDir.absolutePath() - << " already exists."; + qxtLog->debug() << "[dm] " << _downloadDir.absolutePath() << " already exists."; } } else - qxtLog->debug() << "[dm] Download directory: " - << downloadDir.absolutePath() << " already exists."; + qxtLog->debug() << "[dm] Download directory: " << _downloadDir.absolutePath() + << " already exists."; - qxtLog->debug() << "[dm] Saving downloads to: " - << downloadDir.absolutePath(); - downloadPath = downloadDir.absolutePath(); + qxtLog->debug() << "[dm] Saving downloads to: " << _downloadDir.absolutePath(); + downloadPath = _downloadDir.absolutePath(); } // ------------------------------------------------------------------------------------------------------- // Public access @@ -71,11 +64,11 @@ void DownloadManager::processDownloadRequest(const QUrl& url) { return; } qxtLog->debug() << "[dm] Enqueueing: " << url.toString(); - dlQ.enqueue(url); - if (dip) { + _downloadQueue.enqueue(url); + if (_dip) { // download in progress, return. - qxtLog->debug() << "[dm] Download in progress! Queued:" << url.toString() - << "(" << dlQ.size() << " in queue)"; + qxtLog->debug() << "[dm] Download in progress! Queued:" << url.toString() << "(" + << _downloadQueue.size() << " in queue)"; return; } // no running downloads: start next in queue @@ -84,53 +77,51 @@ void DownloadManager::processDownloadRequest(const QUrl& url) { // ------------------------------------------------------------------------------------------------------- void DownloadManager::startNextDownload() { QWSServer::instance()->setCursorVisible(false); - if (dlQ.isEmpty()) { + if (_downloadQueue.isEmpty()) { emit downloadQueueEmpty(); qxtLog->debug() << "[dm] Download manager ready. (1)"; return; } - qxtLog->debug() << "[dm] Starting next download: " << dlQ.head().toString() - << " (" << dlQ.size() - 1 << " in queue.)"; + qxtLog->debug() << "[dm] Starting next download: " << _downloadQueue.head().toString() << " (" + << _downloadQueue.size() - 1 << " in queue.)"; // dequeue next URL to download. - QUrl url = dlQ.dequeue(); + QUrl url = _downloadQueue.dequeue(); // get filename from URL. QString tmp = url.path(); tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); // check if filename exists on target file system - if (downloadDir.exists(tmp)) { - qxtLog->debug() << "[dm] File already exists: " - << downloadDir.absoluteFilePath(tmp); - outfile.setFileName( - QString(downloadDir.absolutePath() + "/" + tmp + ".\%1").arg( - downloaded)); + if (_downloadDir.exists(tmp)) { + qxtLog->debug() << "[dm] File already exists: " << _downloadDir.absoluteFilePath(tmp); + _outfile.setFileName( + QString(_downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(_downloaded)); } else - outfile.setFileName(downloadDir.absoluteFilePath(tmp)); - qxtLog->debug() << "[dm] Saving to: " << outfile.fileName(); + _outfile.setFileName(_downloadDir.absoluteFilePath(tmp)); + qxtLog->debug() << "[dm] Saving to: " << _outfile.fileName(); // try to open for writing - if (!outfile.open(QIODevice::WriteOnly)) { - qxtLog->debug() << "[dm] No write access to " << outfile.fileName() + if (!_outfile.open(QIODevice::WriteOnly)) { + qxtLog->debug() << "[dm] No write access to " << _outfile.fileName() << " . Skipping download..."; return; } // send the request for the file QNetworkRequest request(url); - currentDownload = _qnam->get(request); - lastProgress = 0; - currentProgress = 0; - dip = true; - _time.start(); - QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT( + _currentDownload = _qnam->get(request); + _lastProgress = 0; + _currentProgress = 0; + _dip = true; + time.start(); + QObject::connect(_currentDownload, SIGNAL(readyRead()), this, SLOT( downloadReady())); - QObject::connect(currentDownload, SIGNAL(metaDataChanged()), this, SLOT( + QObject::connect(_currentDownload, SIGNAL(metaDataChanged()), this, SLOT( processMetaInfo())); - QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)), - this, SLOT(downloadProgress(qint64, qint64))); - QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT( + QObject::connect(_currentDownload, SIGNAL(downloadProgress(qint64, qint64)), this, + SLOT(downloadProgress(qint64, qint64))); + QObject::connect(_currentDownload, SIGNAL(finished()), this, SLOT( downloadFinished())); } // ------------------------------------------------------------------------------------------------------- @@ -139,26 +130,26 @@ void DownloadManager::startNextDownload() { void DownloadManager::processMetaInfo() { // fetch filesize from header & filename from URL (for now) const QByteArray cltag = "Content-Length"; - QByteArray clinfo = currentDownload->rawHeader(cltag); - QFileInfo fi(outfile); - qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " - << clinfo.toDouble() << ")"; + QByteArray clinfo = _currentDownload->rawHeader(cltag); + QFileInfo fi(_outfile); + qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() + << ")"; emit downloadInfo(fi.fileName(), clinfo.toDouble()); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadReady() { // data ready, save it - outfile.write(currentDownload->readAll()); + _outfile.write(_currentDownload->readAll()); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { if (bytesIn > bytesTotal || bytesTotal <= 0) { - qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" - << bytesIn << " / Total: " << bytesTotal; + qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" << bytesIn + << " / Total: " << bytesTotal; return; } // calculate current speed - double speed = bytesIn * 1000 / _time.elapsed(); + double speed = bytesIn * 1000 / time.elapsed(); QString unit; if (speed < 1024) { unit = "bytes/sec"; @@ -170,46 +161,41 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { unit = "MB/s"; } // update progress only if difference higher than the updateInterval setting - currentProgress = ((bytesIn * 100) / bytesTotal); - if (currentProgress - lastProgress >= updateInterval) { - lastProgress = currentProgress; + _currentProgress = ((bytesIn * 100) / bytesTotal); + if (_currentProgress - _lastProgress >= updateInterval) { + _lastProgress = _currentProgress; emit - updateProgress(currentProgress, speed, unit); - qxtLog->debug() << "[dm] Download progress of " - << currentDownload->url().toString() << ": " << bytesIn << "/" - << bytesTotal << "(" << currentProgress << "\%)"; + updateProgress(_currentProgress, speed, unit); + qxtLog->debug() << "[dm] Download progress of " << _currentDownload->url().toString() << ": " + << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)"; } } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadFinished() { // check for errors - if (currentDownload->error()) { - outfile.close(); - outfile.remove(); - int statusCode = currentDownload->attribute( - QNetworkRequest::HttpStatusCodeAttribute).toInt(); - qxtLog->debug() << "[dm] Download of " - << currentDownload->url().toString() + if (_currentDownload->error()) { + _outfile.close(); + _outfile.remove(); + int statusCode = + _currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString() << " failed with HTTP error code: " << statusCode; emit notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode)); - currentDownload->deleteLater(); + _currentDownload->deleteLater(); } else { // end download - outfile.close(); - downloaded++; - qxtLog->debug() << "[dm] Download of " - << currentDownload->url().toString() << " finished. (downloaded = " - << downloaded << ")"; + _outfile.close(); + _downloaded++; + qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString() + << " finished. (_downloaded = " << _downloaded << ")"; emit - notify( - QString("Successfully downloaded %1").arg( - currentDownload->url().toString())); - currentDownload->deleteLater(); + notify(QString("Successfully _downloaded %1").arg(_currentDownload->url().toString())); + _currentDownload->deleteLater(); } - dip = false; + _dip = false; // process next in queue, if any - if (dlQ.isEmpty()) { + if (_downloadQueue.isEmpty()) { emit downloadQueueEmpty(); qxtLog->debug() << "[dm] Download manager ready. (2)"; return; diff --git a/src/downloadmanager.h b/src/downloadmanager.h index dfb4d03..58bcd53 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -1,21 +1,21 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Class managing download requests: - # - provides queueing functionality - # - static info: filename, filesize - # - dynamic info: download progress, current speed - # + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Class managing download requests: + * - provides queueing functionality + * - static info: filename, filesize + * - dynamic info: download progress, current speed + * */ #ifndef DOWNLOADMANAGER_H @@ -35,35 +35,34 @@ Q_OBJECT public: DownloadManager(); ~DownloadManager(); - QTime _time; + QTime time; private: // checks for valid download directory, ran once in constructor - void checkDownloadDirectory(); + void check_downloadDirectory(); // private control function for queueing mechanism. void processDownloadRequest(const QUrl& url); // base objects for downloading QNetworkAccessManager* _qnam; - QQueue<QUrl> dlQ; - QNetworkReply* currentDownload; - QFile outfile; - QDir downloadDir; + QQueue<QUrl> _downloadQueue; + QNetworkReply* _currentDownload; + QFile _outfile; + QDir _downloadDir; // download progress variables - int currentProgress, lastProgress; + int _currentProgress, _lastProgress; // download in progress flag - bool dip; + bool _dip; // static counter - static int downloaded; + static int _downloaded; - signals: +signals: // notify sends a message to the javascript interface to be evaluated there void notify(const QString& msg); // downloadInfo sends static information (name, size) to the interface. void downloadInfo(const QString& filename, const double& filesize); // updateProgress sends download progress information to the interface. - void updateProgress(const int& percent, const double& speed, - const QString& unit); + void updateProgress(const int& percent, const double& speed, const QString& unit); // signal emitted when download queue is empty. void downloadQueueEmpty(); diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 3494b83..9a0ee1d 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -34,10 +34,8 @@ int debugMode = -1; * @see DownloadManager */ fbgui::fbgui() { + // test for libsys function - //SysInfoLibsysfs* sil = new SysInfoLibsysfs(); - //sil->getInfoAboutNetworkInterface(); - //sil->getInfoMainboardSerial(); //SysInfo si; //qxtLog->debug() << si.getInfo("mbserial"); //si.getInfo("usb"); @@ -46,28 +44,22 @@ fbgui::fbgui() { createActions(); // initialize javascript interface - JavascriptInterface* jsi = new JavascriptInterface( - _webView->page()->mainFrame()); + JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame()); QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); - QObject::connect(jsi, SIGNAL(shutDownClient()), this, - SLOT(performShutDown())); + QObject::connect(jsi, SIGNAL(shutDownClient()), this, SLOT(performShutDown())); 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(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, + 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())); + QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, SLOT(loadSystem())); // move download manager to its own thread @@ -80,7 +72,6 @@ fbgui::fbgui() { } else { _webView->load(QUrl("qrc:/html/preload.html")); } - //statusBar()->showMessage("Waiting for internet..."); // start watching for fileToTriggerURL watchForTrigger(); @@ -92,7 +83,7 @@ fbgui::fbgui() { showFullScreen(); } fbgui::~fbgui() { - //dmThread.quit(); + dmThread.quit(); } //------------------------------------------------------------------------------------------- // Layout / actions setup @@ -154,16 +145,15 @@ void fbgui::watchForTrigger() { qxtLog->debug() << "[gui] Created: " << fileToTriggerURL; file.close(); } else { - qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL - << " failed! Exiting..."; - exit( EXIT_FAILURE); + qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed!"; + qxtLog->debug() << "[gui] Exiting in 5 seconds..."; + QTimer::singleShot(5000, this, SLOT(close())); } } // watch the path to trigger file qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL; _watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this); - QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, - SLOT(prepareURLLoad())); + QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad())); } //------------------------------------------------------------------------------------------- @@ -198,8 +188,8 @@ void fbgui::prepareURLLoad() { bool fbgui::checkHost() const { QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); if (hostInfo.error() != QHostInfo::NoError) { - qxtLog->debug() << "[gui] Lookup of " << baseURL.host() - << "failed. Exiting..."; + qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed."; + qxtLog->debug() << "[gui] Host can not be reached."; return false; } else { qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded."; @@ -219,7 +209,7 @@ bool fbgui::checkHost() const { */ void fbgui::loadURL() { if (checkHost()) { - qxtLog->debug() << "[gui] Loading URL..."; + qxtLog->debug() << "[gui] Loading URL: " << baseURL.toString() << " ..."; // Generate POST identification data needed by PBS. QByteArray postData = generatePOSTData(); @@ -227,10 +217,22 @@ void fbgui::loadURL() { // show cursor again since user is about to interact. QWSServer::instance()->setCursorVisible(true); + QObject::connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadURLDone(bool))); _webView->load(req, QNetworkAccessManager::PostOperation, postData); } // TODO: error page if no host. } +void fbgui::loadURLDone(bool success) { + // done contains the success of the loading: false / true + if (!success) { + qxtLog->debug() << "[gui] Loading failed. URL: " << _webView->url().toString(); + qxtLog->debug() << "[gui] Exiting in 5 seconds..."; + QTimer::singleShot(5000, this, SLOT(close())); + } + else { + qxtLog->debug() << "[gui] Loaded URL: " << _webView->url().toString(); + } +} //------------------------------------------------------------------------------------------- /** * This method generates the POST data body. @@ -382,24 +384,22 @@ void fbgui::prepareKexec() { // load the kernel + initramfs + append of kcl into kexec. QProcess *process = new QProcess(this); QString cmdline = "kexec -l " + downloadPath.toUtf8() + "/kernel --initrd=" - + downloadPath.toUtf8() + "/initramfs --append=\"" + kcl.toUtf8() - + "\""; + + downloadPath.toUtf8() + "/initramfs --append=\"" + kcl.toUtf8() + "\""; qxtLog->debug() << "[gui] kexec cmdline: " << cmdline; process->start(cmdline); bool ret = process->waitForFinished(); if (!ret) { - qxtLog->debug() << "[sysinfo] Failed to load kexec! Exiting..."; - exit( EXIT_FAILURE); + qxtLog->debug() << "[gui] Failed to execute: " << cmdline; + qxtLog->debug() << "[gui] Exiting in 5 seconds..."; + QTimer::singleShot(5000, this, SLOT(close())); } else { - qxtLog->debug() << "[gui] Kexec load successfull."; + qxtLog->debug() << "[gui] Kexec load was successfull."; if (debugMode < 0) { // if process successfully finished, try to run kexec -e runKexec(); } else { - qxtLog->debug() - << "[gui] Skipping execution of kexec - open debug shell."; - qxtLog->debug() - << "[gui] To start the system execute \"kexec -e\" in your shell."; + qxtLog->debug() << "[gui] Skipping execution of kexec - open debug shell."; + qxtLog->debug() << "[gui] To start the system execute \"kexec -e\" in your shell."; close(); } } @@ -416,7 +416,8 @@ void fbgui::runKexec() { process->startDetached("kexec -e"); if (!process->waitForStarted()) { qxtLog->debug() << "[gui] Failed to execute: kexec -e"; - exit( EXIT_FAILURE); + qxtLog->debug() << "[gui] Exiting in 5 seconds..."; + QTimer::singleShot(5000, this, SLOT(close())); //TODO: Handle failure properly... } } @@ -466,11 +467,12 @@ void fbgui::toggleDebugConsole() { // //------------------------------------------------------------------------------------------- void fbgui::loadSystem() { - // stop the thread for the download manager - qxtLog->debug() << "[gui] Stopping download manager's thread..."; - dmThread.quit(); - //show loading system page. _webView->load(QUrl("qrc:/html/loadsystem.html")); prepareKexec(); } +//------------------------------------------------------------------------------------------- +void fbgui::quitFailure() { +} +void fbgui::quitSuccess() { +} diff --git a/src/fbgui.h b/src/fbgui.h index 98ab4c4..80cbb25 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -1,19 +1,19 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Main class of the fbgui: - # - Manages display of components and their communications - # + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Main class of the fbgui: + * - Manages display of components and their communications + * */ #ifndef FBGUI_H @@ -106,6 +106,7 @@ private slots: // triggered by fileChanged Signal of _watcher // deletes _watcher, since we don't need it anymore and tries to load URL. void prepareURLLoad(); + void loadURLDone(bool success); // shut off the system void performShutDown(); @@ -115,6 +116,9 @@ private slots: void loadSystem(); void prepareKexec(); void runKexec(); + void quitSuccess(); + void quitFailure(); + }; #endif // FBGUI_H diff --git a/src/fbgui.qrc b/src/fbgui.qrc index 8f576cc..e378bed 100644 --- a/src/fbgui.qrc +++ b/src/fbgui.qrc @@ -4,9 +4,9 @@ <file>html/js/jquery-1.5.1.min.js</file> <file>html/js/jquery-ui-1.8.11.min.js</file> <file>html/js/test.js</file> - <file>html/style.css</file> + <file>html/background.png</file> + <file>html/preload.css</file> <file>html/preload.html</file> - <file>html/bg.png</file> <file>html/preload-debug.html</file> <file>html/loadsystem.css</file> <file>html/loadsystem.html</file> diff --git a/src/html/bg.png b/src/html/background.png Binary files differindex 84dd7b3..84dd7b3 100644 --- a/src/html/bg.png +++ b/src/html/background.png diff --git a/src/html/preload-debug.html b/src/html/preload-debug.html index 0aad6c5..8c0f481 100644 --- a/src/html/preload-debug.html +++ b/src/html/preload-debug.html @@ -1,6 +1,6 @@ <html> <head> -<link rel="stylesheet" type="text/css" href="style.css"> +<link rel="stylesheet" type="text/css" href="preload.css"> <script type="text/javascript"> function gogo(){ fbgui.trigger(); diff --git a/src/html/style.css b/src/html/preload.css index 817a7ee..51ef421 100644 --- a/src/html/style.css +++ b/src/html/preload.css @@ -5,7 +5,7 @@ body{ margin:0; padding:0; background-color:black; - background-image:url('bg.png'); + background-image:url('background.png'); background-repeat: no-repeat; background-size:100%; } diff --git a/src/html/preload.html b/src/html/preload.html index bb63050..831322c 100644 --- a/src/html/preload.html +++ b/src/html/preload.html @@ -1,6 +1,6 @@ <html> <head> -<link rel="stylesheet" type="text/css" href="style.css"> +<link rel="stylesheet" type="text/css" href="preload.css"> <script type="text/javascript"> function gogo(){ fbgui.trigger(); diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index 18949ae..b480635 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -178,10 +178,8 @@ void JavascriptInterface::reboot() { * * @todo add some more informations */ -void JavascriptInterface::downloadInfo(const QString& filename, - const double& filesize) { - QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg( - filesize); +void JavascriptInterface::downloadInfo(const QString& filename, const double& filesize) { + QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize); _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- @@ -193,12 +191,11 @@ void JavascriptInterface::downloadInfo(const QString& filename, * * @todo add some more informations */ -void JavascriptInterface::updateProgressBar(const int& percent, - const double& speed, const QString& unit) { +void JavascriptInterface::updateProgressBar(const int& percent, const double& speed, + const QString& unit) { if (percent == 0) return; - QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg( - speed).arg(unit); + QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(speed).arg(unit); _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- @@ -223,7 +220,7 @@ void JavascriptInterface::callbackOnFinished() { //------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- /** - * This method triggers the arriving of the IP address + * This method triggers the arriving of the IP address *FOR TESTING PURPOSES* * * Used for testing. This method triggers the arriving of the IP address. * Not needed in the final version since the here simulated event will be @@ -244,3 +241,8 @@ void JavascriptInterface::trigger() { } file.close(); } +//------------------------------------------------------------------------------------------------------- +void JavascriptInterface::alert(const QString& message) { + // expects a formatted message. + _parent->evaluateJavaScript(QString("alert(").append(message)); +} diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h index ce07d93..8826e46 100644 --- a/src/javascriptinterface.h +++ b/src/javascriptinterface.h @@ -1,18 +1,18 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Interface for javascript. - # + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Interface for javascript. + * */ #ifndef JAVASCRIPTINTERFACE_H_ @@ -34,7 +34,7 @@ private: // loads jQuery code void loadJQuery(); - signals: +signals: // request the file from download manager void requestFile(const QString& filename); // quit the application @@ -60,13 +60,13 @@ public slots: void callbackOnFinished(); // slots for information exchange with the download manager. - void updateProgressBar(const int& percent, const double& speed, - const QString& unit); + void updateProgressBar(const int& percent, const double& speed, const QString& unit); void downloadInfo(const QString& filename, const double& filesize); void notify(const QString& msg); - // test stuff + // functions to help test functionality void trigger(); + void alert(const QString& message); }; #endif // JAVASCRIPTINTERFACE_H_ diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index fd44633..8a0991d 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -22,8 +22,7 @@ void LoggerEngine_fb::killLoggerEngine() { return; } -void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, - bool enable) { +void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels, bool) { //QxtLoggerEngine::setLogLevelsEnabled(level, enable); //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel); } @@ -32,8 +31,7 @@ bool LoggerEngine_fb::isInitialized() const { return true; } -void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, - const QList<QVariant> & msgs) { +void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs) { // ignore in case no messages was passed. if (msgs.isEmpty()) @@ -68,8 +66,7 @@ LoggerEngine_std::LoggerEngine_std() : LoggerEngine_std::~LoggerEngine_std() { } -void LoggerEngine_std::writeToStdErr(const QString& str_level, - const QList<QVariant> &msgs) { +void LoggerEngine_std::writeToStdErr(const QString&, const QList<QVariant> &msgs) { if (msgs.isEmpty()) return; @@ -84,8 +81,8 @@ void LoggerEngine_std::writeToStdErr(const QString& str_level, } *errstream << endl; } -void LoggerEngine_std::writeToStdOut(const QString& level, - const QList<QVariant> & msgs) { +void LoggerEngine_std::writeToStdOut(const QString&, const QList<QVariant> &) { + // (level, msgs) // reimplementing this is needed for compiling, // we only need write to std::err, so this function is not needed } @@ -103,8 +100,7 @@ LoggerEngine_file::~LoggerEngine_file() { void LoggerEngine_file::initLoggerEngine() { } -void LoggerEngine_file::writeToFile(const QString& str_level, - const QList<QVariant> &msgs) { +void LoggerEngine_file::writeToFile(const QString&, const QList<QVariant> &msgs) { if (msgs.isEmpty()) return; diff --git a/src/loggerengine.h b/src/loggerengine.h index 94cf59e..1dfae4e 100644 --- a/src/loggerengine.h +++ b/src/loggerengine.h @@ -1,18 +1,18 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Base for custom logger engines based on QxtLogger libs. - # + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Base for custom logger engines based on QxtLogger libs. + * */ #ifndef LOGGERENGINE_H_ #define LOGGERENGINE_H_ @@ -36,8 +36,7 @@ public: // reimplemented virtual functions of QxtLoggerEngine void initLoggerEngine(); void killLoggerEngine(); - void writeFormatted(QxtLogger::LogLevel level, - const QList<QVariant> & messages); + void writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & messages); void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true); bool isInitialized() const; diff --git a/src/main.cpp b/src/main.cpp index a319ae4..f3d4201 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,20 +11,16 @@ void printHelp() { QTextStream qout(stdout); qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; - qout << "-c <path>, --config=<path> " << QObject::tr( - "Path to configuration file.") << endl; - qout << "-u <URL>, --url=<URL> " << QObject::tr( - "Sets the URL to be loaded.") << endl; - qout << "-d <path>, --download=<path> " << QObject::tr( - "Specify the download directory.") << endl; + qout << "-c <path>, --config=<path> " << QObject::tr("Path to configuration file.") << endl; + qout << "-u <URL>, --url=<URL> " << QObject::tr("Sets the URL to be loaded.") << endl; + qout << "-d <path>, --download=<path> " << QObject::tr("Specify the download directory.") + << endl; qout << "-t <path, --trigger=<path> " << QObject::tr( "Specify location of the file triggering the URL load.") << endl; qout << "-s <path, --serial=<path> " << QObject::tr( "Specify location of the file containing the serial number.") << endl; - qout << "-D <level>, --debug=<level> " << QObject::tr( - "Activate debug mode. [0,1]") << endl; - qout << "-h, --help " << QObject::tr( - "Prints this help.") << endl; + qout << "-D <level>, --debug=<level> " << QObject::tr("Activate debug mode. [0,1]") << endl; + qout << "-h, --help " << QObject::tr("Prints this help.") << endl; qout.flush(); exit( EXIT_SUCCESS); } @@ -50,12 +46,11 @@ int main(int argc, char *argv[]) { QMap<QString, QString> clOpts; int longIndex = 0; static const char *optString = "c:u:d:s:t:D:hl:"; - static const struct option longOpts[] = { { "config", required_argument, - NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", - required_argument, NULL, 'd' }, { "serial", required_argument, NULL, - 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", - required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { - "log", required_argument, NULL, 'l' } }; + static const struct option longOpts[] = { { "config", required_argument, NULL, 'c' }, { "url", + required_argument, NULL, 'u' }, { "download", required_argument, NULL, 'd' }, { "serial", + required_argument, NULL, 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", + required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "log", + required_argument, NULL, 'l' } }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); while (opt != -1) { switch (opt) { @@ -139,15 +134,13 @@ int main(int argc, char *argv[]) { if (clOpts.contains("downloadDir")) downloadPath = clOpts.value("downloadDir"); else if (confFileSettings.contains("default/download_directory")) - downloadPath - = confFileSettings.value("default/download_directory").toString(); + downloadPath = confFileSettings.value("default/download_directory").toString(); else downloadPath = DEFAULT_DOWNLOAD_DIR; // set update interval for download progress functions of download manager. if (confFileSettings.contains("default/update_interval")) - updateInterval - = confFileSettings.value("default/update_interval").toInt(); + updateInterval = confFileSettings.value("default/update_interval").toInt(); else updateInterval = DEFAULT_UPDATE_INTERVAL; @@ -155,8 +148,7 @@ int main(int argc, char *argv[]) { if (clOpts.contains("trigger")) fileToTriggerURL = clOpts.value("trigger"); else if (confFileSettings.contains("default/file_trigger")) - fileToTriggerURL - = confFileSettings.value("default/file_trigger").toString(); + fileToTriggerURL = confFileSettings.value("default/file_trigger").toString(); else fileToTriggerURL = DEFAULT_FILE_TRIGGER; @@ -164,8 +156,7 @@ int main(int argc, char *argv[]) { if (clOpts.contains("serialLocation")) serialLocation = clOpts.value("serialLocation"); else if (confFileSettings.contains("default/serial_location")) - serialLocation - = confFileSettings.value("default/serial_location").toString(); + serialLocation = confFileSettings.value("default/serial_location").toString(); else serialLocation = QString("/serial"); // tests diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp index 2de7b92..4797a86 100644 --- a/src/sysinfo.cpp +++ b/src/sysinfo.cpp @@ -69,11 +69,9 @@ const QString SysInfo::getInfo(const QString& infoName) { */ const QString SysInfo::getMACAddress() { // Returns MAC address of eth0 for now - QNetworkInterface qni = - QNetworkInterface::interfaceFromName(QString("eth0")); + QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); if (!qni.isValid()) { - qxtLog->debug() - << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; + qxtLog->debug() << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; return "no_eth0"; } //eth0_index = qni.index(); @@ -96,17 +94,15 @@ const QString SysInfo::getMACAddress() { const QString SysInfo::getIPAddress() { // Again for eth0 only at the moment. // TODO: this doesn't quite work yet... - QNetworkInterface qni = - QNetworkInterface::interfaceFromName(QString("eth0")); + QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); QList<QHostAddress> addrlist = qni.allAddresses(); // This is does not return the right IP atm... foreach(QHostAddress addr, addrlist) - { - if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr - != QHostAddress::LocalHost) { - return addr.toString(); + { + if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr != QHostAddress::LocalHost) { + return addr.toString(); + } } - } // still here? qxtLog->debug() << "[sysinfo] IP Address: ip_error"; return "ip_error"; @@ -171,8 +167,7 @@ QString SysInfo::getAllInfos() { */ const QString SysInfo::getMainboardSerial() { QString out = ""; - struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", - "id"); + struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id"); struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); struct sysfs_device *device = sysfs_get_classdev_device(class_device); @@ -253,22 +248,19 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { qxtLog->debug() << tag + "failed to get handler / fail to open device"; return "error"; } - re = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, - string, sizeof(string)); + re = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string)); if (re < 0) { qxtLog->debug() << tag + "failed to get SerialNumber"; return "error"; } infos.insert("serialnumber", QString((const char *) string)); - re = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, - sizeof(string)); + re = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); if (re < 0) { qxtLog->debug() << tag + "failed to get Product"; return "error"; } infos.insert("product", QString((const char *) string)); - re = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, - string, sizeof(string)); + re = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string)); if (re < 0) { qxtLog->debug() << tag + "failed to get Product"; return "error"; diff --git a/src/sysinfo.h b/src/sysinfo.h index f4fa3b2..131b369 100644 --- a/src/sysinfo.h +++ b/src/sysinfo.h @@ -1,18 +1,18 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Helper class to get system information. - # + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Helper class to get system information. + * */ #ifndef SYSINFO_H diff --git a/src/sysinfolibsysfs.cpp b/src/sysinfolibsysfs.cpp index 5c89bde..6dcbcd2 100644 --- a/src/sysinfolibsysfs.cpp +++ b/src/sysinfolibsysfs.cpp @@ -23,9 +23,8 @@ SysInfoLibsysfs::~SysInfoLibsysfs() { } void SysInfoLibsysfs::getInfoAboutNetworkInterface() { - struct sysfs_class_device *class_device = sysfs_open_class_device("net", - "eth0"); - struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); + struct sysfs_class_device *class_device = sysfs_open_class_device("net", "eth0"); + //struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); struct sysfs_device *device = sysfs_get_classdev_device(class_device); //struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device); if (device == NULL) { @@ -42,10 +41,9 @@ void SysInfoLibsysfs::getInfoMbSerial() { QJson::Serializer serializer; QVariantList listOfDevices; - struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", - "id"); + struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id"); struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); - struct sysfs_device *device = sysfs_get_classdev_device(class_device); + //struct sysfs_device *device = sysfs_get_classdev_device(class_device); if (attrlist != NULL) { struct sysfs_attribute *attr = NULL; @@ -72,10 +70,9 @@ void SysInfoLibsysfs::getInfoMbSerial() { QString SysInfoLibsysfs::getInfoMainboardSerial() { QString out = ""; - struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", - "id"); + struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id"); struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); - struct sysfs_device *device = sysfs_get_classdev_device(class_device); + //struct sysfs_device *device = sysfs_get_classdev_device(class_device); if (attrlist != NULL) { struct sysfs_attribute *attr = NULL; diff --git a/src/sysinfolibsysfs.h b/src/sysinfolibsysfs.h index df746f3..c933efa 100644 --- a/src/sysinfolibsysfs.h +++ b/src/sysinfolibsysfs.h @@ -1,22 +1,22 @@ /* - # Copyright (c) 2010,2011 - RZ Uni Freiburg - # Copyright (c) 2010,2011 - OpenSLX Project - # - # This program/file is free software distributed under the GPL version 2. - # See http://openslx.org/COPYING - # - # If you have any feedback please consult http://openslx.org/feedback and - # send your feedback to feedback@openslx.org - # - # General information about OpenSLX can be found under http://openslx.org - # - # - # Class collects informations about hardware devices of the client: - # - ip address - # - mac address - # - # - # All methods return the collected informations as json- parsable object. + * Copyright (c) 2010,2011 - RZ Uni Freiburg + * Copyright (c) 2010,2011 - OpenSLX Project + * + * This program/file is free software distributed under the GPL version 2. + * See http://openslx.org/COPYING + * + * If you have any feedback please consult http://openslx.org/feedback and + * send your feedback to feedback@openslx.org + * + * General information about OpenSLX can be found under http://openslx.org + * + * + * Class collects informations about hardware devices of the client: + * - ip address + * - mac address + * + * + * All methods return the collected informations as json- parsable object. * sysinfolibsysfs.h * |