From 7cb508eb877ae0a696427073b1105ee8d9c19876 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 21 Apr 2011 23:35:02 +0200 Subject: uniformed ident 3-spaced.... --- src/downloadmanager.cpp | 338 ++++++++++++++++++++++++------------------------ 1 file changed, 167 insertions(+), 171 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index c772776..1be8964 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -4,216 +4,212 @@ int DownloadManager::downloaded = 0; // ------------------------------------------------------------------------------------------------------- DownloadManager::DownloadManager() { - qxtLog->debug() << "Initializing download manager..."; - checkDownloadDirectory(); - _qnam = new QNetworkAccessManager(); - //_qnam->moveToThread(&dmThread); - dip = false; + qxtLog->debug() << "Initializing download manager..."; + checkDownloadDirectory(); + _qnam = new QNetworkAccessManager(); + //_qnam->moveToThread(&dmThread); + dip = false; } DownloadManager::~DownloadManager() { - delete _qnam; + delete _qnam; } // ------------------------------------------------------------------------------------------------------- void DownloadManager::checkDownloadDirectory() { - // check if downloadPath exists, if not create it. - 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(); - else { - qxtLog->debug() << "[dm] Failed to create directory: " - << downloadDir.path(); - // try to save to /tmp/fbgui - downloadDir.setPath(QDir::tempPath() + "/fbgui"); - if (!downloadDir.exists()) { - if (QDir::current().mkdir(QDir::tempPath() + "/fbgui")) - qxtLog->debug() << "[dm] Successfully created: " - << downloadDir.absolutePath(); - else { - // just in case - qxtLog->debug() << "[dm] Failed to create: " - << downloadDir.absolutePath(); - qxtLog->debug() << "[dm] Exiting..."; - exit( EXIT_FAILURE); - } - } else - qxtLog->debug() << "[dm] " << downloadDir.absolutePath() - << " already exists."; - } - } else - qxtLog->debug() << "[dm] Download directory: " - << downloadDir.absolutePath() << " already exists."; + // check if downloadPath exists, if not create it. + 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(); + else { + qxtLog->debug() << "[dm] Failed to create directory: " + << downloadDir.path(); + // try to save to /tmp/fbgui + downloadDir.setPath(QDir::tempPath() + "/fbgui"); + if (!downloadDir.exists()) { + if (QDir::current().mkdir(QDir::tempPath() + "/fbgui")) + qxtLog->debug() << "[dm] Successfully created: " + << downloadDir.absolutePath(); + else { + // just in case + qxtLog->debug() << "[dm] Failed to create: " + << downloadDir.absolutePath(); + qxtLog->debug() << "[dm] Exiting..."; + exit( EXIT_FAILURE); + } + } else + qxtLog->debug() << "[dm] " << downloadDir.absolutePath() + << " already exists."; + } + } else + 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 // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadFile(const QString& filename) { - QUrl fileUrl(baseURL.resolved(QUrl(filename))); - this->processDownloadRequest(fileUrl); + QUrl fileUrl(baseURL.resolved(QUrl(filename))); + this->processDownloadRequest(fileUrl); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadFile(const QUrl& fileUrl) { - this->processDownloadRequest(fileUrl); + this->processDownloadRequest(fileUrl); } // ------------------------------------------------------------------------------------------------------- // Private functions handling download requests and queueing // ------------------------------------------------------------------------------------------------------- void DownloadManager::processDownloadRequest(const QUrl& url) { - if (url.isEmpty()) { - qxtLog->debug() << "[dm] No URL specified for download."; - return; - } - qxtLog->debug() << "[dm] Enqueueing: " << url.toString(); - dlQ.enqueue(url); - if (dip) { - // download in progress, return. - qxtLog->debug() << "[dm] Download in progress! Queued:" - << url.toString() << "(" << dlQ.size() << " in queue)"; - return; - } - // no running downloads: start next in queue - startNextDownload(); + if (url.isEmpty()) { + qxtLog->debug() << "[dm] No URL specified for download."; + return; + } + qxtLog->debug() << "[dm] Enqueueing: " << url.toString(); + dlQ.enqueue(url); + if (dip) { + // download in progress, return. + qxtLog->debug() << "[dm] Download in progress! Queued:" << url.toString() + << "(" << dlQ.size() << " in queue)"; + return; + } + // no running downloads: start next in queue + startNextDownload(); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::startNextDownload() { - QWSServer::instance()->setCursorVisible(false); - if (dlQ.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.)"; + QWSServer::instance()->setCursorVisible(false); + if (dlQ.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.)"; - // dequeue next URL to download. - QUrl url = dlQ.dequeue(); + // dequeue next URL to download. + QUrl url = dlQ.dequeue(); - // get filename from URL. - QString tmp = url.path(); - tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); + // 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)); - } else - outfile.setFileName(downloadDir.absoluteFilePath(tmp)); - qxtLog->debug() << "[dm] Saving to: " << outfile.fileName(); + // 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)); + } else + 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() - << " . Skipping download..."; - return; - } + // try to open for writing + 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(downloadReady())); - 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(downloadFinished())); + // 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( + downloadReady())); + 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( + downloadFinished())); } // ------------------------------------------------------------------------------------------------------- // Private slots to handle a download in progress // ------------------------------------------------------------------------------------------------------- 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() << ")"; - emit downloadInfo(fi.fileName(), clinfo.toDouble()); + // 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() << ")"; + emit downloadInfo(fi.fileName(), clinfo.toDouble()); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadReady() { - // data ready, save it - outfile.write(currentDownload->readAll()); + // data ready, save it + 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; - return; - } - // calculate current speed - double speed = bytesIn * 1000 / _time.elapsed(); - QString unit; - if (speed < 1024) { - unit = "bytes/sec"; - } else if (speed < 1024 * 1024) { - speed /= 1024; - unit = "KB/s"; - } else { - speed /= 1024 * 1024; - unit = "MB/s"; - } - // update progress only if difference higher than the updateInterval setting - 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 << "\%)"; - } + if (bytesIn > bytesTotal || bytesTotal <= 0) { + qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" + << bytesIn << " / Total: " << bytesTotal; + return; + } + // calculate current speed + double speed = bytesIn * 1000 / _time.elapsed(); + QString unit; + if (speed < 1024) { + unit = "bytes/sec"; + } else if (speed < 1024 * 1024) { + speed /= 1024; + unit = "KB/s"; + } else { + speed /= 1024 * 1024; + unit = "MB/s"; + } + // update progress only if difference higher than the updateInterval setting + 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 << "\%)"; + } } // ------------------------------------------------------------------------------------------------------- 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() - << " failed with HTTP error code: " << statusCode; - emit - notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode)); - currentDownload->deleteLater(); - } else { - // end download - 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(); - } - dip = false; - // process next in queue, if any - if (dlQ.isEmpty()) { - emit downloadQueueEmpty(); - qxtLog->debug() << "[dm] Download manager ready. (2)"; - return; - } - startNextDownload(); + // 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() + << " failed with HTTP error code: " << statusCode; + emit notify(QString("Download failed! HTTP Status Code: %1").arg( + statusCode)); + currentDownload->deleteLater(); + } else { + // end download + 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(); + } + dip = false; + // process next in queue, if any + if (dlQ.isEmpty()) { + emit downloadQueueEmpty(); + qxtLog->debug() << "[dm] Download manager ready. (2)"; + return; + } + startNextDownload(); } -- cgit v1.2.3-55-g7522 From ce42f447314d241d725f77d4dd12b00f7ca5a7b6 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 02:22:03 +0200 Subject: download manager threaded again, debug preload page --- src/downloadmanager.cpp | 2 +- src/fbgui.cpp | 38 +++++++++++++++++++++++++++----------- src/fbgui.h | 3 ++- src/fbgui.qrc | 2 ++ src/html/preload-debug.html | 8 ++++---- 5 files changed, 36 insertions(+), 17 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 1be8964..7458b4c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -7,7 +7,7 @@ DownloadManager::DownloadManager() { qxtLog->debug() << "Initializing download manager..."; checkDownloadDirectory(); _qnam = new QNetworkAccessManager(); - //_qnam->moveToThread(&dmThread); + _qnam->moveToThread(&dmThread); dip = false; } DownloadManager::~DownloadManager() { diff --git a/src/fbgui.cpp b/src/fbgui.cpp index bd0c508..63f6983 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -10,7 +10,7 @@ #include #include -//QThread dmThread; +QThread dmThread; QString ipConfigFilePath(""); QString binPath(""); QUrl baseURL(""); @@ -68,16 +68,20 @@ fbgui::fbgui() { SLOT(updateProgressBar(const int&, const double&, const QString&))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT( callbackOnFinished())); - QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, - SLOT(prepareKexec())); + QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, SLOT(loadSystem())); // move download manager to its own thread - //dm->moveToThread(&dmThread); - //dmThread.start(); + dm->moveToThread(&dmThread); + dmThread.start(); // show "waiting for internet" page until triggered. - _webView->load(QUrl("qrc:/html/preload.html")); + if (debugMode > -1) { + _webView->load(QUrl("qrc:/html/preload-debug.html")); + } else { + _webView->load(QUrl("qrc:/html/preload.html")); + } //statusBar()->showMessage("Waiting for internet..."); + // start watching for fileToTriggerURL watchForTrigger(); @@ -88,7 +92,7 @@ fbgui::fbgui() { showFullScreen(); } fbgui::~fbgui() { - //dmThread.quit(); + dmThread.quit(); } //------------------------------------------------------------------------------------------- // Layout / actions setup @@ -186,9 +190,10 @@ void fbgui::prepareURLLoad() { // Preparations for URL load //------------------------------------------------------------------------------------------- /** - * This method checks if is connected to the internet. + * This method checks the existance of the host. * - * This method checks if is connected to the internet. + * This method checks if the host exists / can be found. + * The host is from the URL given through the configuration. */ bool fbgui::checkHost() const { QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); @@ -203,7 +208,7 @@ bool fbgui::checkHost() const { } //------------------------------------------------------------------------------------------- /** - * This method loads the main screen. + * This method tries loads the URL. * * This method loads the main screen via an POST request. If also disconnects the watcher * of the file, (Watcher is set in the fbgui::watchForTrigger() method). @@ -224,6 +229,7 @@ void fbgui::loadURL() { QWSServer::instance()->setCursorVisible(true); _webView->load(req, QNetworkAccessManager::PostOperation, postData); } + // TODO: error page if no host. } //------------------------------------------------------------------------------------------- /** @@ -234,6 +240,8 @@ void fbgui::loadURL() { * The hardwarehash is a MD5 hash over the MAC address and the * mainboard serial number. * The specific serial number is set at the creation of the usb boot stick. + * This file has to be present on the directory specified in + * the configuration for this to work. * * @see SysInfo::getMACAddress() * @see SysInfo::getMainboardSerial() @@ -277,7 +285,7 @@ QByteArray fbgui::generatePOSTData() { } //------------------------------------------------------------------------------------------- -// System Calls Functions +// Shutdown / Reboot of the client //------------------------------------------------------------------------------------------- // TODO One function for reboot and shutdown, with parameter for the action. // for example: doSystemCall(_REBOOT_); @@ -453,3 +461,11 @@ void fbgui::createDebugConsole() { void fbgui::toggleDebugConsole() { (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); } +//------------------------------------------------------------------------------------------- +// +//------------------------------------------------------------------------------------------- +void fbgui::loadSystem() { + //show loading system page. + _webView->load(QUrl("qrc:/html/loadsystem.html")); + prepareKexec(); +} diff --git a/src/fbgui.h b/src/fbgui.h index 664eea4..48ddce4 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -109,7 +109,8 @@ private slots: void performShutDown(); // reboot the system void performReboot(); - // prepareKexec + // Kexec + void loadSystem(); void prepareKexec(); void runKexec(); }; diff --git a/src/fbgui.qrc b/src/fbgui.qrc index 10a8bd6..8f576cc 100644 --- a/src/fbgui.qrc +++ b/src/fbgui.qrc @@ -8,5 +8,7 @@ html/preload.html html/bg.png html/preload-debug.html + html/loadsystem.css + html/loadsystem.html diff --git a/src/html/preload-debug.html b/src/html/preload-debug.html index cc69aa1..0aad6c5 100644 --- a/src/html/preload-debug.html +++ b/src/html/preload-debug.html @@ -13,13 +13,13 @@ function quitgui(){

Preboot GUI

+

Waiting on internet... + -

Waiting on internet...i -

-- cgit v1.2.3-55-g7522 From 518ab031c29f36095578c8819e0befa503d1ae1d Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 17:28:07 +0200 Subject: new logger engine to output in file, configurable per cmdline / config file --- fbgui.conf | 1 + src/downloadmanager.cpp | 1 - src/fbgui.cpp | 1 + src/fbgui.h | 4 +++- src/loggerengine.cpp | 8 +++++--- src/loggerengine.h | 4 +++- src/main.cpp | 43 +++++++++++++++++++++++++++++-------------- 7 files changed, 42 insertions(+), 20 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/fbgui.conf b/fbgui.conf index ac2cecb..8c79c8f 100644 --- a/fbgui.conf +++ b/fbgui.conf @@ -5,3 +5,4 @@ update_interval=5 file_trigger=/tmp/fbgui_trigger serial_location=/serial ip_config=/tmp/ip_config +log_file=/tmp/fbgui.log diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 7458b4c..adbedd1 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1,5 +1,4 @@ #include "downloadmanager.h" -#include "fbgui.h" int DownloadManager::downloaded = 0; // ------------------------------------------------------------------------------------------------------- diff --git a/src/fbgui.cpp b/src/fbgui.cpp index e3c2d3a..3494b83 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -11,6 +11,7 @@ #include QThread dmThread; +QString logFilePath(""); QString ipConfigFilePath(""); QString binPath(""); QUrl baseURL(""); diff --git a/src/fbgui.h b/src/fbgui.h index 48ddce4..98ab4c4 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -26,13 +26,15 @@ // Internal default settings #define DEFAULT_URL "http://www.google.com" -#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads" +#define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui" #define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" +#define DEFAULT_LOG_FILE_PATH "/tmp/fbgui.log" #define DEFAULT_UPDATE_INTERVAL 1; #define DEFAULT_QRC_HTML_DIR ":/html" #define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger" // Global settings variables +extern QString logFilePath; extern QString ipConfigFilePath; extern QThread dmThread; extern QString serialLocation; diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index 3a44159..fd44633 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -92,14 +92,16 @@ void LoggerEngine_std::writeToStdOut(const QString& level, //--------------------------------------------------------------------------------------------------- // slighty modified QxtBasicFileLoggerEngine //--------------------------------------------------------------------------------------------------- -LoggerEngine_file::LoggerEngine_file() : - QxtBasicFileLoggerEngine() { +LoggerEngine_file::LoggerEngine_file(const QString& logFileName) : + QxtBasicFileLoggerEngine(logFileName) { + //setLogFileName(logFileName); } LoggerEngine_file::~LoggerEngine_file() { } -LoggerEngine_file::initLoggerEngine() {} +void LoggerEngine_file::initLoggerEngine() { +} void LoggerEngine_file::writeToFile(const QString& str_level, const QList &msgs) { diff --git a/src/loggerengine.h b/src/loggerengine.h index 45f6827..94cf59e 100644 --- a/src/loggerengine.h +++ b/src/loggerengine.h @@ -20,6 +20,7 @@ #include #include #include + //--------------------------------------------------------------------------------------------------- // base of a custom logger engine for the framebuffer //--------------------------------------------------------------------------------------------------- @@ -58,8 +59,9 @@ public: //--------------------------------------------------------------------------------------------------- class LoggerEngine_file: public QxtBasicFileLoggerEngine { public: - LoggerEngine_file(); + LoggerEngine_file(const QString& logFileName); ~LoggerEngine_file(); + void initLoggerEngine(); // reimplemented virtual functions of QxtBasicFileLoggerEngine void writeToFile(const QString& level, const QList &msgs); diff --git a/src/main.cpp b/src/main.cpp index 601a62e..24e0430 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,13 +54,17 @@ int main(int argc, char *argv[]) { 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' } }; + required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { + "logfile", required_argument, NULL, 'l' } }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); while (opt != -1) { switch (opt) { case 'c': clOpts.insert("configFile", optarg); break; + case 'l': + clOpts.insert("logFile", optarg); + break; case 'u': clOpts.insert("url", optarg); break; @@ -90,18 +94,10 @@ int main(int argc, char *argv[]) { debugMode = clOpts.value("debug").toInt(); // start basic debug output on terminal qxtLog->disableLoggerEngine("DEFAULT"); + qxtLog->enableLogLevels(QxtLogger::DebugLevel); 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 debug logging to file. - qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file); - - //qxtLog->initLoggerEngine("std_logger"); - //qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); - //qxtLog->enableLogLevels(QxtLogger::DebugLevel); - } else debugMode = -1; @@ -175,12 +171,27 @@ int main(int argc, char *argv[]) { // save ip config location (file generated by uchpc) if (confFileSettings.contains("default/ip_config")) ipConfigFilePath = confFileSettings.value("default/ip_config").toString(); - //else - // ipConfigFilePath = QString("/tmp/ip_config"); + + // save path to log file + if (clOpts.contains("logFile")) + logFilePath = clOpts.value("logFile"); + else if (confFileSettings.contains("default/log_file")) + logFilePath = confFileSettings.value("default/log_file").toString(); + else + logFilePath = DEFAULT_LOG_FILE_PATH; + + // activate file logger if debug mode activated. + if (debugMode > -1) { + // start debug logging to file. + qxtLog->addLoggerEngine("file_logger", + new LoggerEngine_file(logFilePath)); + qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); + } // print config qxtLog->debug() << "************* CONFIG INFO *************"; qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); + qxtLog->debug() << "logFilePath: " << logFilePath.toUtf8(); qxtLog->debug() << "ipConfigFilePath:" << ipConfigFilePath.toUtf8(); qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); @@ -190,9 +201,13 @@ int main(int argc, char *argv[]) { // set invisible cursor QWSServer::instance()->setCursorVisible(false); - QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); - QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + + // set default keyboard / mouse drivers. TODO: fix this, doesn't work... + //QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); + //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + // start fbgui + qxtLog->debug() << "Initializing fbgui..."; fbgui gui; gui.show(); return app.exec(); -- cgit v1.2.3-55-g7522 From e1e2bc138cafa1e5f26b377b36d31812f59c5e35 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 18:10:03 +0200 Subject: old test --- build.sh | 2 +- src/downloadmanager.cpp | 18 +++++++++++------- src/fbgui.h | 2 +- src/javascriptinterface.cpp | 30 +++++++++++++++--------------- src/main.cpp | 24 ++++++++++++------------ 5 files changed, 40 insertions(+), 36 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/build.sh b/build.sh index 8ea3fc5..2eabc4f 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash QT_VERSION=QtEmbedded-4.7.2 -rm fbgui.tgz +[ -f fbgui.tgz ] && rm fbgui.tgz mkdir -p pkg diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index adbedd1..22c1c09 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -103,8 +103,9 @@ void DownloadManager::startNextDownload() { if (downloadDir.exists(tmp)) { qxtLog->debug() << "[dm] File already exists: " << downloadDir.absoluteFilePath(tmp); - outfile.setFileName(QString(downloadDir.absolutePath() + "/" + tmp - + ".\%1").arg(downloaded)); + outfile.setFileName( + QString(downloadDir.absolutePath() + "/" + tmp + ".\%1").arg( + downloaded)); } else outfile.setFileName(downloadDir.absoluteFilePath(tmp)); qxtLog->debug() << "[dm] Saving to: " << outfile.fileName(); @@ -172,7 +173,8 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { currentProgress = ((bytesIn * 100) / bytesTotal); if (currentProgress - lastProgress >= updateInterval) { lastProgress = currentProgress; - emit updateProgress(currentProgress, speed, unit); + emit + updateProgress(currentProgress, speed, unit); qxtLog->debug() << "[dm] Download progress of " << currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal << "(" << currentProgress << "\%)"; @@ -189,8 +191,8 @@ void DownloadManager::downloadFinished() { 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)); + emit + notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode)); currentDownload->deleteLater(); } else { // end download @@ -199,8 +201,10 @@ void DownloadManager::downloadFinished() { qxtLog->debug() << "[dm] Download of " << currentDownload->url().toString() << " finished. (downloaded = " << downloaded << ")"; - emit notify(QString("Successfully downloaded %1").arg( - currentDownload->url().toString())); + emit + notify( + QString("Successfully downloaded %1").arg( + currentDownload->url().toString())); currentDownload->deleteLater(); } dip = false; diff --git a/src/fbgui.h b/src/fbgui.h index 5c3247d..98ab4c4 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -28,7 +28,7 @@ #define DEFAULT_URL "http://www.google.com" #define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui" #define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" -#define DEFAULT_LOG_FILE_PATH "/tmp/fbgui.log2" +#define DEFAULT_LOG_FILE_PATH "/tmp/fbgui.log" #define DEFAULT_UPDATE_INTERVAL 1; #define DEFAULT_QRC_HTML_DIR ":/html" #define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger" diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index eba4027..18949ae 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -56,23 +56,23 @@ void JavascriptInterface::loadJQuery() { 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") { - QFile file; - file.setFileName(pathToJsDir + "/" + fi.fileName()); - file.open(QIODevice::ReadOnly); - js = file.readAll(); - file.close(); + foreach(fi, fiList) + { + if (fi.suffix() == "js") { + //qDebug()<< fi.fileName(); + //qxtLog->debug() << fi.fileName(); + if (fi.fileName() != "test.js") { + QFile file; + file.setFileName(pathToJsDir + "/" + fi.fileName()); + file.open(QIODevice::ReadOnly); + js = file.readAll(); + file.close(); - _parent->evaluateJavaScript(js); - //qxtLog->debug() << "evaluated " + fi.fileName(); + _parent->evaluateJavaScript(js); + //qxtLog->debug() << "evaluated " + fi.fileName(); + } + } } - } -} } //------------------------------------------------------------------------------------------------------- // Javascript functions for webpage diff --git a/src/main.cpp b/src/main.cpp index d51bc02..c913b40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,9 +174,10 @@ int main(int argc, char *argv[]) { ipConfigFilePath = confFileSettings.value("default/ip_config").toString(); // save path to log file - if (clOpts.contains("logFile")){ - logFilePath = clOpts.value("logFile");qxtLog->debug() << "LOG FILE: " << clOpts.value("logFile");} - else if (confFileSettings.contains("default/log_file")) + if (clOpts.contains("logFile")) { + logFilePath = clOpts.value("logFile"); + qxtLog->debug() << "LOG FILE: " << clOpts.value("logFile"); + } else if (confFileSettings.contains("default/log_file")) logFilePath = confFileSettings.value("default/log_file").toString(); else logFilePath = DEFAULT_LOG_FILE_PATH; @@ -184,20 +185,19 @@ int main(int argc, char *argv[]) { // activate file logger if debug mode activated. if (debugMode > -1) { // start debug logging to file. - qxtLog->addLoggerEngine("file_logger", - new LoggerEngine_file(logFilePath)); + qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath)); qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); } // print config qxtLog->debug() << "************* CONFIG INFO *************"; - qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); - qxtLog->debug() << "logFilePath: " << logFilePath.toUtf8(); - qxtLog->debug() << "ipConfigFilePath:" << ipConfigFilePath.toUtf8(); - qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); - qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); - qxtLog->debug() << "trigger: " << fileToTriggerURL.toUtf8(); - qxtLog->debug() << "serialLocation: " << serialLocation.toUtf8(); + qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); + qxtLog->debug() << "logFilePath: " << logFilePath.toUtf8(); + qxtLog->debug() << "ipConfigFilePath: " << ipConfigFilePath.toUtf8(); + qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); + qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); + qxtLog->debug() << "trigger: " << fileToTriggerURL.toUtf8(); + qxtLog->debug() << "serialLocation: " << serialLocation.toUtf8(); qxtLog->debug() << "*******************************************"; // set invisible cursor -- cgit v1.2.3-55-g7522 From 03ac351f38316d8f923f3797aa7dd0deade7ed5d Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 24 Apr 2011 21:36:26 +0200 Subject: url status handling, 5sec delay before closing gui when exiting with failure (not actually returning 1 atm), lots of formatting... --- src/downloadmanager.cpp | 160 ++++++++++++++++++++------------------------ src/downloadmanager.h | 57 ++++++++-------- src/fbgui.cpp | 82 ++++++++++++----------- src/fbgui.h | 34 +++++----- src/fbgui.qrc | 4 +- src/html/background.png | Bin 0 -> 316905 bytes src/html/bg.png | Bin 316905 -> 0 bytes src/html/preload-debug.html | 2 +- src/html/preload.css | 97 +++++++++++++++++++++++++++ src/html/preload.html | 2 +- src/html/style.css | 97 --------------------------- src/javascriptinterface.cpp | 20 +++--- src/javascriptinterface.h | 36 +++++----- src/loggerengine.cpp | 16 ++--- src/loggerengine.h | 31 +++++---- src/main.cpp | 39 +++++------ src/sysinfo.cpp | 30 +++------ src/sysinfo.h | 28 ++++---- src/sysinfolibsysfs.cpp | 15 ++--- src/sysinfolibsysfs.h | 36 +++++----- 20 files changed, 377 insertions(+), 409 deletions(-) create mode 100644 src/html/background.png delete mode 100644 src/html/bg.png create mode 100644 src/html/preload.css delete mode 100644 src/html/style.css (limited to 'src/downloadmanager.cpp') 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 dlQ; - QNetworkReply* currentDownload; - QFile outfile; - QDir downloadDir; + QQueue _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 @@ html/js/jquery-1.5.1.min.js html/js/jquery-ui-1.8.11.min.js html/js/test.js - html/style.css + html/background.png + html/preload.css html/preload.html - html/bg.png html/preload-debug.html html/loadsystem.css html/loadsystem.html diff --git a/src/html/background.png b/src/html/background.png new file mode 100644 index 0000000..84dd7b3 Binary files /dev/null and b/src/html/background.png differ diff --git a/src/html/bg.png b/src/html/bg.png deleted file mode 100644 index 84dd7b3..0000000 Binary files a/src/html/bg.png and /dev/null differ 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 @@ - +