From db5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 15 Apr 2011 16:47:09 +0200 Subject: fixes & misc --- src/downloadmanager.cpp | 24 ++++++++++++++++-------- src/downloadmanager.h | 5 +++-- src/fbgui.cpp | 21 +++++++++------------ src/fbgui.qrc | 1 + 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index eb00354..9faad88 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -6,10 +6,13 @@ int DownloadManager::downloaded = 0; DownloadManager::DownloadManager(){ qxtLog->debug() << "Initializing download manager..."; checkDownloadDirectory(); - qnam = new QNetworkAccessManager(); - qnam->moveToThread(&dmThread); + _qnam = new QNetworkAccessManager(); + //_qnam->moveToThread(&dmThread); dip = false; } +DownloadManager::~DownloadManager(){ + delete _qnam; +} // ------------------------------------------------------------------------------------------------------- void DownloadManager::checkDownloadDirectory() { @@ -66,7 +69,7 @@ void DownloadManager::processDownloadRequest(const QUrl& url) qxtLog->debug() << "[dm] No URL specified for download."; return; } - qxtLog->debug() << "[dm] Enqueueing:" << url.toString(); + qxtLog->debug() << "[dm] Enqueueing: " << url.toString(); dlQ.enqueue(url); if (dip){ // download in progress, return. @@ -112,11 +115,11 @@ void DownloadManager::startNextDownload() // send the request for the file QNetworkRequest request(url); - currentDownload = qnam->get(request); + currentDownload = _qnam->get(request); lastProgress = 0; currentProgress = 0; dip = true; - dltime.start(); + _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)), @@ -132,7 +135,8 @@ void DownloadManager::processMetaInfo() const QByteArray cltag = "Content-Length"; QByteArray clinfo = currentDownload->rawHeader(cltag); QFileInfo fi(outfile); - emit downloadInfo(outfile.fileName(), clinfo.toDouble()); + qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() << ")"; + emit downloadInfo(fi.fileName(), clinfo.toDouble()); } // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadReady() @@ -143,9 +147,13 @@ void DownloadManager::downloadReady() // ------------------------------------------------------------------------------------------------------- void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { - if (bytesIn > bytesTotal) return; + if (bytesIn > bytesTotal || bytesTotal <= 0){ + qxtLog->debug() << "[dm] downloadProgress invalid values:" + << "In:" << bytesIn << " / Total: " << bytesTotal; + return; + } // calculate current speed - double speed = bytesIn * 1000 / dltime.elapsed(); + double speed = bytesIn * 1000 / _time.elapsed(); QString unit; if (speed < 1024){ unit = "bytes/sec"; diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 1b7d8af..44194d3 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -36,6 +36,8 @@ class DownloadManager : public QObject public: DownloadManager(); + ~DownloadManager(); + QTime _time; private: // checks for valid download directory, ran once in constructor @@ -44,13 +46,12 @@ private: void processDownloadRequest(const QUrl& url); // base objects for downloading - QNetworkAccessManager* qnam; + QNetworkAccessManager* _qnam; QQueue dlQ; QNetworkReply* currentDownload; QFile outfile; QDir downloadDir; // download progress variables - QTime dltime; int currentProgress, lastProgress; // download in progress flag bool dip; diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 4dbbc58..d991556 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -10,7 +10,7 @@ #include #include -QThread dmThread; +//QThread dmThread; QString binPath(""); QUrl baseURL(""); QString downloadPath(""); @@ -65,10 +65,11 @@ fbgui::fbgui() QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); // move download manager to its own thread - dm->moveToThread(&dmThread); - dmThread.start(); + //dm->moveToThread(&dmThread); + //dmThread.start(); - // show filler page + //_webView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar); + // show page _webView->load(QUrl("qrc:/html/preload.html")); // start watching for fileToTriggerURL watchForTrigger(); @@ -81,7 +82,7 @@ fbgui::fbgui() showFullScreen(); } fbgui::~fbgui(){ - dmThread.quit(); + //dmThread.quit(); } //------------------------------------------------------------------------------------------- // Layout / actions setup @@ -140,7 +141,7 @@ void fbgui::watchForTrigger() if (file.exists()){ qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!"; // try to load URL - if (checkHost()) loadURL(); + loadURL(); } else { // create it @@ -179,7 +180,7 @@ void fbgui::prepareURLLoad() _watcher->disconnect(this); _watcher->deleteLater(); // try to load URL - if (checkHost()) loadURL(); + loadURL(); } //------------------------------------------------------------------------------------------- // Preparations for URL load @@ -254,7 +255,6 @@ QByteArray fbgui::generatePOSTData() QFile file(serialLocation); if (!file.open(QIODevice::ReadOnly)){ qxtLog->debug() << "[post] No such file: " << file.fileName(); - serial = "10-23-43-55-67"; // tests } // everything ok, read data serial = file.readAll(); @@ -296,8 +296,5 @@ void fbgui::createDebugConsole() //------------------------------------------------------------------------------------------- void fbgui::toggleDebugConsole() { - if (_debugConsole->isVisible()) - _debugConsole->hide(); - else - _debugConsole->show(); + (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); } diff --git a/src/fbgui.qrc b/src/fbgui.qrc index bb25211..10a8bd6 100644 --- a/src/fbgui.qrc +++ b/src/fbgui.qrc @@ -7,5 +7,6 @@ html/style.css html/preload.html html/bg.png + html/preload-debug.html -- cgit v1.2.3-55-g7522 From 4378d39ea8866b9446685cb6140bc632d22a9a16 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sat, 16 Apr 2011 13:12:13 +0200 Subject: cursor hidden by QWSServer, added loading animation for preload page, started preload-debug page --- fbgui.conf | 2 +- src/downloadmanager.cpp | 1 + src/fbgui.cpp | 3 ++- src/fbgui.h | 1 + src/html/preload-debug.html | 32 ++++++++++++++++++++++ src/html/preload.html | 22 +++++++++++++++ src/html/style.css | 65 +++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 4 +-- src/testApp.sh | 1 + 9 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 src/html/preload-debug.html diff --git a/fbgui.conf b/fbgui.conf index 168c1ac..e450443 100644 --- a/fbgui.conf +++ b/fbgui.conf @@ -2,5 +2,5 @@ pbs_url=http://132.230.4.27 download_directory=/tmp/fbgui update_interval=5 -file_trigger=/tmp/fbgui/trigger +file_trigger=/tmp/fbgui_trigger serial_location=/serial diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 9faad88..aa0682c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -83,6 +83,7 @@ void DownloadManager::processDownloadRequest(const QUrl& url) // ------------------------------------------------------------------------------------------------------- void DownloadManager::startNextDownload() { + QWSServer::instance()->setCursorVisible(false); if (dlQ.isEmpty()){ emit downloadQueueEmpty(); qxtLog->debug() << "[dm] Download manager ready. (1)"; diff --git a/src/fbgui.cpp b/src/fbgui.cpp index d991556..f27a698 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -220,7 +220,8 @@ void fbgui::loadURL() QByteArray postData = generatePOSTData(); QNetworkRequest req(baseURL); // show arrow cursor - qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); + QWSServer::instance()->setCursorVisible(true); + //qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); _webView->load(req, QNetworkAccessManager::PostOperation, postData); } } diff --git a/src/fbgui.h b/src/fbgui.h index 287b295..f3c2a77 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -19,6 +19,7 @@ #ifndef FBGUI_H #define FBGUI_H +#include #include #include #include diff --git a/src/html/preload-debug.html b/src/html/preload-debug.html new file mode 100644 index 0000000..cc69aa1 --- /dev/null +++ b/src/html/preload-debug.html @@ -0,0 +1,32 @@ + + + + + + +
+

Preboot GUI

+ +

Waiting on internet...i + +

+
+
+ +
+ + + diff --git a/src/html/preload.html b/src/html/preload.html index a01dbd7..bb63050 100644 --- a/src/html/preload.html +++ b/src/html/preload.html @@ -5,6 +5,18 @@ function gogo(){ fbgui.trigger(); } +//simple script to rotate all spinners 45 degrees on each tick +//this works differently from the css transforms, which is smooth +var count = 0; +function rotate() { + var elem4 = document.getElementById('div4'); + elem4.style.MozTransform = 'scale(0.5) rotate('+count+'deg)'; + elem4.style.WebkitTransform = 'scale(0.5) rotate('+count+'deg)'; + if (count==360) { count = 0 } + count+=45; + window.setTimeout(rotate, 100); +} +window.setTimeout(rotate, 100); @@ -13,6 +25,16 @@ function gogo(){

Waiting on internet...

+
+
+
+
+
+
+
+
+
+
diff --git a/src/html/style.css b/src/html/style.css index 8ebfa3d..817a7ee 100644 --- a/src/html/style.css +++ b/src/html/style.css @@ -30,3 +30,68 @@ h1, p{ #footer{ height:30px; } +/* position the bars and balls correctly (rotate them and translate them outward)*/ +.bar1 { + -moz-transform:rotate(0deg) translate(0, -40px); + -webkit-transform:rotate(0deg) translate(0, -40px);opacity:0.12; +} +.bar2 { + -moz-transform:rotate(45deg) translate(0, -40px); + -webkit-transform:rotate(45deg) translate(0, -40px);opacity:0.25; +} +.bar3 { + -moz-transform:rotate(90deg) translate(0, -40px); + -webkit-transform:rotate(90deg) translate(0, -40px);opacity:0.37; +} +.bar4 { + -moz-transform:rotate(135deg) translate(0, -40px); + -webkit-transform:rotate(135deg) translate(0, -40px);opacity:0.50; +} +.bar5 { + -moz-transform:rotate(180deg) translate(0, -40px); + -webkit-transform:rotate(180deg) translate(0, -40px);opacity:0.62; +} +.bar6 { + -moz-transform:rotate(225deg) translate(0, -40px); + -webkit-transform:rotate(225deg) translate(0, -40px);opacity:0.75; +} +.bar7 { + -moz-transform:rotate(270deg) translate(0, -40px); + -webkit-transform:rotate(270deg) translate(0, -40px);opacity:0.87; +} +.bar8 { + -moz-transform:rotate(315deg) translate(0, -40px); + -webkit-transform:rotate(315deg) translate(0, -40px);opacity:1; +} +#div4 { + position:absolute; + left:50%; + top:50%; + margin-left:-50px; + margin-top:-50px; + width:100px; + height:100px; + -moz-border-radius:100px; + -webkit-border-radius:100px; + -moz-transform:scale(0.5); + -webkit-transform:scale(0.5); + -webkit-animation-name: rotateThis; + -webkit-animation-duration:2s; + -webkit-animation-iteration-count:infinite; + -webkit-animation-timing-function:linear; +} +#div4 div { + width:20px; + height:20px; + background:#fff; + -moz-border-radius:40px; + -webkit-border-radius:40px; + position:absolute; + left:40px; + top:40px; +} +/* add a shadow to the first */ +#div4 div { + -moz-box-shadow:black 0 0 4px; + -webkit-box-shadow:black 0 0 4px; +} diff --git a/src/main.cpp b/src/main.cpp index a07a8f4..7d73754 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,8 +174,8 @@ int main(int argc, char *argv[]) qxtLog->debug() << "*******************************************"; // set invisible cursor - qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); - + //qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); + QWSServer::instance()->setCursorVisible(false); // start fbgui fbgui gui; gui.show(); diff --git a/src/testApp.sh b/src/testApp.sh index c924500..9b46385 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -14,6 +14,7 @@ # clean /tmp/fbgui rm -rf /tmp/fbgui +rm /tmp/fbgui_trigger # path to script (including script name) script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" -- cgit v1.2.3-55-g7522 From e512c756586d5509ac11759bae40f7911fe0f948 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 18 Apr 2011 02:13:18 +0200 Subject: uniformed formatting... --- src/downloadmanager.cpp | 342 +++++++++++++++++++++++--------------------- src/downloadmanager.h | 115 ++++++++------- src/fbgui.cpp | 116 ++++++++------- src/fbgui.h | 129 ++++++++--------- src/javascriptinterface.cpp | 95 ++++++------ src/javascriptinterface.h | 84 +++++------ src/loggerengine.cpp | 102 +++++++------ src/loggerengine.h | 63 ++++---- src/main.cpp | 123 ++++++++-------- src/sysinfo.cpp | 330 +++++++++++++++++++++--------------------- src/sysinfo.h | 61 ++++---- src/sysinfolibsysfs.cpp | 240 +++++++++++++++---------------- src/sysinfolibsysfs.h | 36 ++--- 13 files changed, 932 insertions(+), 904 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index aa0682c..c9fc7fc 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -3,207 +3,217 @@ int DownloadManager::downloaded = 0; // ------------------------------------------------------------------------------------------------------- -DownloadManager::DownloadManager(){ - qxtLog->debug() << "Initializing download manager..."; - checkDownloadDirectory(); - _qnam = new QNetworkAccessManager(); - //_qnam->moveToThread(&dmThread); - dip = false; +DownloadManager::DownloadManager() { + qxtLog->debug() << "Initializing download manager..."; + checkDownloadDirectory(); + _qnam = new QNetworkAccessManager(); + //_qnam->moveToThread(&dmThread); + dip = false; } -DownloadManager::~DownloadManager(){ +DownloadManager::~DownloadManager() { 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."; +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."; - 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); +void DownloadManager::downloadFile(const QString& filename) { + QUrl fileUrl(baseURL.resolved(QUrl(filename))); + this->processDownloadRequest(fileUrl); } // ------------------------------------------------------------------------------------------------------- -void DownloadManager::downloadFile(const QUrl& fileUrl) -{ - this->processDownloadRequest(fileUrl); +void DownloadManager::downloadFile(const QUrl& 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(); +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(); } // ------------------------------------------------------------------------------------------------------- -void DownloadManager::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.)"; + 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()); +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()); } // ------------------------------------------------------------------------------------------------------- -void DownloadManager::downloadReady() -{ - // data ready, save it - outfile.write(currentDownload->readAll()); +void DownloadManager::downloadReady() { + // 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){ +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; + } 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 << "\%)"; - } + } + // 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)); +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(); + } 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(); } diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 44194d3..a7afe23 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.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 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 #define DOWNLOADMANAGER_H @@ -29,58 +29,57 @@ extern QString binPath; extern QString downloadPath; extern int updateInterval; - -class DownloadManager : public QObject -{ - Q_OBJECT +class DownloadManager: public QObject { +Q_OBJECT public: - DownloadManager(); - ~DownloadManager(); + DownloadManager(); + ~DownloadManager(); QTime _time; private: - // checks for valid download directory, ran once in constructor - void checkDownloadDirectory(); - // private control function for queueing mechanism. - void processDownloadRequest(const QUrl& url); + // checks for valid download directory, ran once in constructor + void checkDownloadDirectory(); + // 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; - // download progress variables - int currentProgress, lastProgress; - // download in progress flag - bool dip; - // static counter - static int downloaded; + // base objects for downloading + QNetworkAccessManager* _qnam; + QQueue dlQ; + QNetworkReply* currentDownload; + QFile outfile; + QDir downloadDir; + // download progress variables + int currentProgress, lastProgress; + // download in progress flag + bool dip; + // static counter + static int downloaded; 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); - // signal emitted when download queue is empty. - void downloadQueueEmpty(); + // 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); + // signal emitted when download queue is empty. + void downloadQueueEmpty(); public slots: - // public slots to receive download requests. - void downloadFile(const QUrl& fileUrl); - // convenience function - void downloadFile(const QString& fileUrl); + // public slots to receive download requests. + void downloadFile(const QUrl& fileUrl); + // convenience function + void downloadFile(const QString& fileUrl); private slots: - // private slots to manage the downloading process - void startNextDownload(); - void processMetaInfo(); - void downloadReady(); - void downloadProgress(qint64 bytesIn, qint64 bytesTotal); - void downloadFinished(); + // private slots to manage the downloading process + void startNextDownload(); + void processMetaInfo(); + void downloadReady(); + void downloadProgress(qint64 bytesIn, qint64 bytesTotal); + void downloadFinished(); }; #endif // DOWNLOADMANAGER_H diff --git a/src/fbgui.cpp b/src/fbgui.cpp index f27a698..add6cfc 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -31,38 +31,41 @@ int debugMode = -1; * @see JavascriptInterface * @see DownloadManager */ -fbgui::fbgui() -{ +fbgui::fbgui() { // test for libsys function //SysInfoLibsysfs* sil = new SysInfoLibsysfs(); //sil->getInfoAboutNetworkInterface(); //sil->getInfoMainboardSerial(); - //SysInfo si; - //qxtLog->debug() << si.getInfo("mbserial"); - //si.getInfo("usb"); + //SysInfo si; + //qxtLog->debug() << si.getInfo("mbserial"); + //si.getInfo("usb"); setupLayout(); 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(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), - jsi, SLOT(attachToDOM())); - + QObject::connect(_webView->page()->mainFrame(), + SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM())); // initialize download manager DownloadManager* dm = new DownloadManager(); QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), - jsi, SLOT(downloadInfo(const QString&, const double&))); - QObject::connect(dm, SIGNAL(notify(const QString&)), - jsi, SLOT(notify(const QString&))); - QObject::connect(jsi, SIGNAL(requestFile(const QString&)), - dm, SLOT(downloadFile(const QString&))); - QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)), - jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); - QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); + jsi, SLOT(downloadInfo(const QString&, const double&))); + QObject::connect(dm, SIGNAL(notify(const QString&)), jsi, + SLOT(notify(const QString&))); + QObject::connect(jsi, SIGNAL(requestFile(const QString&)), dm, + SLOT(downloadFile(const QString&))); + QObject::connect( + dm, + SIGNAL(updateProgress(const int&, const double&, const QString&)), + jsi, + SLOT(updateProgressBar(const int&, const double&, const QString&))); + QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, + SLOT(callbackOnFinished())); // move download manager to its own thread //dm->moveToThread(&dmThread); @@ -81,7 +84,7 @@ fbgui::fbgui() setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); } -fbgui::~fbgui(){ +fbgui::~fbgui() { //dmThread.quit(); } //------------------------------------------------------------------------------------------- @@ -95,27 +98,24 @@ fbgui::~fbgui(){ * - debug mode: the screen is divided into the browser and a debug * out console */ -void fbgui::setupLayout() -{ +void fbgui::setupLayout() { // setup layout of the gui: debug split or browser _webView = new QWebView(this); - if (debugMode == 1){ + if (debugMode == 1) { // split main window in browser & debug console createDebugConsole(); _splitter = new QSplitter(Qt::Vertical, this); _splitter->addWidget(_webView); _splitter->addWidget(_debugConsole); setCentralWidget(_splitter); - } - else + } else setCentralWidget(_webView); } //------------------------------------------------------------------------------------------- /** * This method enables a shortcut for closing the program. */ -void fbgui::createActions() -{ +void fbgui::createActions() { // CTRL + X to kill the gui _quit = new QAction(tr("&quit"), this); _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); @@ -134,31 +134,30 @@ void fbgui::createActions() * fbgui::checkForTrigger(const QString& dirname) method will be called. * */ -void fbgui::watchForTrigger() -{ +void fbgui::watchForTrigger() { // check if fileToTriggerURL already exists QFile file(fileToTriggerURL); - if (file.exists()){ - qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!"; + if (file.exists()) { + qxtLog->debug() << "[watcher] " << fileToTriggerURL + << " exists already!"; // try to load URL loadURL(); - } - else { + } else { // create it - if (file.open(QIODevice::WriteOnly)){ + if (file.open(QIODevice::WriteOnly)) { qxtLog->debug() << "[gui] Created: " << fileToTriggerURL; file.close(); - } - else { - qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed! Exiting..."; - exit(EXIT_FAILURE); + } else { + qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL + << " failed! Exiting..."; + exit( EXIT_FAILURE); } } // watch the path where trigger file is expected 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())); } //------------------------------------------------------------------------------------------- @@ -172,8 +171,7 @@ void fbgui::watchForTrigger() * @see fbgui::checkHost() * @see fbgui::loadURL() */ -void fbgui::prepareURLLoad() -{ +void fbgui::prepareURLLoad() { qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!"; // disconnect _watcher, his job is done qxtLog->debug() << "[watcher] disconnected."; @@ -190,15 +188,15 @@ void fbgui::prepareURLLoad() * * This method checks if is connected to the internet. */ -bool fbgui::checkHost() const -{ +bool fbgui::checkHost() const { QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); - if (hostInfo.error() != QHostInfo::NoError){ - qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed. Exiting..."; + if (hostInfo.error() != QHostInfo::NoError) { + qxtLog->debug() << "[gui] Lookup of " << baseURL.host() + << "failed. Exiting..."; return false; - } - else{ - qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded."; + } else { + qxtLog->debug() << "[gui] Lookup of " << baseURL.host() + << " succeeded."; return true; } } @@ -213,9 +211,8 @@ bool fbgui::checkHost() const * @see fbgui::watchForTrigger() * @see fbgui::generatePOSTData() */ -void fbgui::loadURL() -{ - if (checkHost()){ +void fbgui::loadURL() { + if (checkHost()) { qxtLog->debug() << "[gui] Loading URL..."; QByteArray postData = generatePOSTData(); QNetworkRequest req(baseURL); @@ -238,8 +235,7 @@ void fbgui::loadURL() * @see SysInfo::getMACAddress() * @see SysInfo::getMainboardSerial() */ -QByteArray fbgui::generatePOSTData() -{ +QByteArray fbgui::generatePOSTData() { qxtLog->debug() << "[gui] Generating POST data..."; // use MAC address as base data SysInfo si; @@ -254,14 +250,14 @@ QByteArray fbgui::generatePOSTData() // fetch serial number from usb QByteArray serial; QFile file(serialLocation); - if (!file.open(QIODevice::ReadOnly)){ + if (!file.open(QIODevice::ReadOnly)) { qxtLog->debug() << "[post] No such file: " << file.fileName(); } // everything ok, read data serial = file.readAll(); file.close(); serial.chop(1); // chop EOF - qxtLog->debug() << "[post] Serial number is: " << serial; + qxtLog->debug() << "[post] Serial number is: " << serial; // construct final byte array QByteArray postData("mac="); @@ -274,8 +270,7 @@ QByteArray fbgui::generatePOSTData() //------------------------------------------------------------------------------------------- // Debug console setup / control //------------------------------------------------------------------------------------------- -void fbgui::createDebugConsole() -{ +void fbgui::createDebugConsole() { // create the debug console widget _debugConsole = new QTextEdit(this); _debugConsole->setWindowFlags(Qt::FramelessWindowHint); @@ -292,10 +287,11 @@ void fbgui::createDebugConsole() _toggleDebugConsole = new QAction(tr("&toggleDebug"), this); _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); addAction(_toggleDebugConsole); - connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole())); + connect(_toggleDebugConsole, SIGNAL(triggered()), this, + SLOT(toggleDebugConsole())); } //------------------------------------------------------------------------------------------- -void fbgui::toggleDebugConsole() -{ - (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); +void fbgui::toggleDebugConsole() { + (_debugConsole->isVisible()) ? _debugConsole->hide() + : _debugConsole->show(); } diff --git a/src/fbgui.h b/src/fbgui.h index f3c2a77..a703d6e 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -1,20 +1,20 @@ /* -# 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 #define FBGUI_H @@ -24,7 +24,6 @@ #include #include - // Internal default settings #define DEFAULT_URL "http://www.google.com" #define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads" @@ -33,7 +32,6 @@ #define DEFAULT_QRC_HTML_DIR ":/html" #define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger" - // Global settings variables extern QThread dmThread; extern QString serialLocation; @@ -45,67 +43,66 @@ extern QUrl baseURL; extern int debugMode; extern int updateInterval; -class fbgui : public QMainWindow -{ - Q_OBJECT +class fbgui: public QMainWindow { +Q_OBJECT public: - fbgui(); - ~fbgui(); + fbgui(); + ~fbgui(); private: - //------------------- - // layout setup: - //------------------- - // Sets the layout depending on the debug mode: - // no debug or debugMode = 0 -> only browser shown. - // debugMode = 1 -> split main window in browser and debug console. - void setupLayout(); - // Create all actions for the GUI. (Currently only quit.) - void createActions(); - // Create a debug console widget as QTextEdit in order to print debug messages - // directly within the GUI. This was needed since ttys can't really be used - // for debugging purposes in the preboot environment. + //------------------- + // layout setup: + //------------------- + // Sets the layout depending on the debug mode: + // no debug or debugMode = 0 -> only browser shown. + // debugMode = 1 -> split main window in browser and debug console. + void setupLayout(); + // Create all actions for the GUI. (Currently only quit.) + void createActions(); + // Create a debug console widget as QTextEdit in order to print debug messages + // directly within the GUI. This was needed since ttys can't really be used + // for debugging purposes in the preboot environment. void createDebugConsole(); //---------------------------------------- - // control the display of components: + // control the display of components: //---------------------------------------- // watches for the file triggering the loading of the URL. // the file can be specified by the corresponding option. - void watchForTrigger(); - bool checkHost() const; - void loadURL(); - QByteArray generatePOSTData(); - - //---------------------------------- - // widgets constituing the gui: - //---------------------------------- - // QWebView for displaying internet content - QWebView* _webView; - // QSplitter to split the main window in two resizable frames. - QSplitter* _splitter; - // QTextEdit implementing a minimalistic debug console. - QTextEdit* _debugConsole; - - //------------------ - // action list: - //------------------ - // closes the main window provoking the application to quit. - QAction* _quit; - // triggers toggleDebugConsole() - QAction* _toggleDebugConsole; - - // watcher to detect changes in the observed directory. - QFileSystemWatcher* _watcher; + void watchForTrigger(); + bool checkHost() const; + void loadURL(); + QByteArray generatePOSTData(); + + //---------------------------------- + // widgets constituing the gui: + //---------------------------------- + // QWebView for displaying internet content + QWebView* _webView; + // QSplitter to split the main window in two resizable frames. + QSplitter* _splitter; + // QTextEdit implementing a minimalistic debug console. + QTextEdit* _debugConsole; + + //------------------ + // action list: + //------------------ + // closes the main window provoking the application to quit. + QAction* _quit; + // triggers toggleDebugConsole() + QAction* _toggleDebugConsole; + + // watcher to detect changes in the observed directory. + QFileSystemWatcher* _watcher; private slots: - // toggles debug console when action _toggleDebugConsole happens. - void toggleDebugConsole(); + // toggles debug console when action _toggleDebugConsole happens. + void toggleDebugConsole(); - // triggered by fileChanged Signal of _watcher - // deletes _watcher, since we don't need it anymore and tries to load URL. - void prepareURLLoad(); + // triggered by fileChanged Signal of _watcher + // deletes _watcher, since we don't need it anymore and tries to load URL. + void prepareURLLoad(); }; #endif // FBGUI_H diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index 634b478..ea25855 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -2,7 +2,6 @@ #include "javascriptinterface.h" #include "sysinfo.h" - //------------------------------------------------------------------------------------------------------- // Initialisation //------------------------------------------------------------------------------------------------------- @@ -12,15 +11,16 @@ * @param parent * Is of type QWebFrame. */ -JavascriptInterface::JavascriptInterface(QWebFrame *parent){ - qxtLog->debug() << "Initializing javascript interface..."; - _parent = parent; +JavascriptInterface::JavascriptInterface(QWebFrame *parent) { + qxtLog->debug() << "Initializing javascript interface..."; + _parent = parent; } //------------------------------------------------------------------------------------------------------- /** * An empty destructor. */ -JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ } +JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ +} //------------------------------------------------------------------------------------------------------- /** * Attaches an instance of this class to the DOM of the HTML page. @@ -32,9 +32,9 @@ JavascriptInterface::~JavascriptInterface() { /* destructor dummy */ } * * @see JavascriptInterface::loadJQuery() */ -void JavascriptInterface::attachToDOM(){ - _parent->addToJavaScriptWindowObject(QString("fbgui"), this); - loadJQuery(); +void JavascriptInterface::attachToDOM() { + _parent->addToJavaScriptWindowObject(QString("fbgui"), this); + loadJQuery(); } //------------------------------------------------------------------------------------------------------- /** @@ -48,7 +48,7 @@ void JavascriptInterface::attachToDOM(){ * * @see JavascriptInterface::attachToDOM() */ -void JavascriptInterface::loadJQuery(){ +void JavascriptInterface::loadJQuery() { QString js; QString pathToJsDir(DEFAULT_QRC_HTML_DIR); pathToJsDir.append("/js"); @@ -57,24 +57,22 @@ void JavascriptInterface::loadJQuery(){ 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(); + 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 @@ -86,13 +84,13 @@ void JavascriptInterface::loadJQuery(){ * Can be called from inside a JavaScript function of the HTML page. * Emits the JavascriptInterface::requestFile(const QString) signal. */ -void JavascriptInterface::startDownload(const QString& filename){ - // ignore if empty filename - if (filename.isEmpty()){ - _parent->evaluateJavaScript("alert(\"No filename!\")"); - return; - } - emit requestFile(filename); +void JavascriptInterface::startDownload(const QString& filename) { + // ignore if empty filename + if (filename.isEmpty()) { + _parent->evaluateJavaScript("alert(\"No filename!\")"); + return; + } + emit requestFile(filename); } //------------------------------------------------------------------------------------------------------- /** @@ -103,7 +101,7 @@ void JavascriptInterface::startDownload(const QString& filename){ * * @todo add some more informations */ -void JavascriptInterface::setCallbackOnFinished(const QString& function){ +void JavascriptInterface::setCallbackOnFinished(const QString& function) { qxtLog->debug() << "[jsi] Callback set: " << function; _callbackOnDownloadsFinished = QString(function); } @@ -128,7 +126,7 @@ void JavascriptInterface::setCallbackOnFinished(const QString& function){ * * @see SysInfo::getInfo(const QString& infoName) */ -const QString JavascriptInterface::getSysInfo(const QString& info){ +const QString JavascriptInterface::getSysInfo(const QString& info) { SysInfo si; return si.getInfo(info); } @@ -140,7 +138,7 @@ const QString JavascriptInterface::getSysInfo(const QString& info){ * Can be called from inside a JavaScript function of the HTML page. * Emits JavascriptInterface::quitFbgui() signal */ -void JavascriptInterface::quit(){ +void JavascriptInterface::quit() { emit quitFbgui(); } //------------------------------------------------------------------------------------------------------- @@ -153,9 +151,11 @@ void JavascriptInterface::quit(){ * * @todo add some more informations */ -void JavascriptInterface::downloadInfo(const QString& filename, const double& filesize){ - QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize); - _parent->evaluateJavaScript(code); +void JavascriptInterface::downloadInfo(const QString& filename, + const double& filesize) { + QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg( + filesize); + _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- /** @@ -166,10 +166,13 @@ void JavascriptInterface::downloadInfo(const QString& filename, const double& fi * * @todo add some more informations */ -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); - _parent->evaluateJavaScript(code); +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); + _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- /** @@ -177,7 +180,7 @@ void JavascriptInterface::updateProgressBar(const int& percent, const double& sp * * @todo add some more informations. */ -void JavascriptInterface::notify(const QString& msg){ +void JavascriptInterface::notify(const QString& msg) { qxtLog->debug() << "[jsi] Notifying: " << msg; QString code = QString("notify('\%1')").arg(msg); _parent->evaluateJavaScript(code); @@ -186,9 +189,9 @@ void JavascriptInterface::notify(const QString& msg){ /** * @todo add some more informations */ -void JavascriptInterface::callbackOnFinished(){ - QString code = QString("\%1").arg(_callbackOnDownloadsFinished); - _parent->evaluateJavaScript(code); +void JavascriptInterface::callbackOnFinished() { + QString code = QString("\%1").arg(_callbackOnDownloadsFinished); + _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------- @@ -206,9 +209,9 @@ void JavascriptInterface::callbackOnFinished(){ * @see bool fbgui::checkHost() * @see void fbgui::loadURL() */ -void JavascriptInterface::trigger(){ +void JavascriptInterface::trigger() { QFile file(fileToTriggerURL); - if (file.open(QIODevice::WriteOnly)){ + if (file.open(QIODevice::WriteOnly)) { file.write("data\n"); qxtLog->debug() << "[jsi] *trigger watcher*"; } diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h index e686b77..9d7bd37 100644 --- a/src/javascriptinterface.h +++ b/src/javascriptinterface.h @@ -1,66 +1,66 @@ /* -# 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_ #define JAVASCRIPTINTERFACE_H_ #include "fbgui.h" -class JavascriptInterface : public QObject -{ - Q_OBJECT +class JavascriptInterface: public QObject { +Q_OBJECT public: - JavascriptInterface(QWebFrame* parent); - ~JavascriptInterface(); + JavascriptInterface(QWebFrame* parent); + ~JavascriptInterface(); private: - // pointer to parent - QWebFrame* _parent; - // function to be called withint javascript when downloads are done. - QString _callbackOnDownloadsFinished; - // loads jQuery code - void loadJQuery(); + // pointer to parent + QWebFrame* _parent; + // function to be called withint javascript when downloads are done. + QString _callbackOnDownloadsFinished; + // loads jQuery code + void loadJQuery(); signals: // request the file from download manager - void requestFile(const QString& filename); - // quit the application - void quitFbgui(); + void requestFile(const QString& filename); + // quit the application + void quitFbgui(); public slots: // make sure the interface stays attached on webpage reload - void attachToDOM(); + void attachToDOM(); - // slots for calling from the webpage - void startDownload(const QString& filename); - void setCallbackOnFinished(const QString& function); - const QString getSysInfo(const QString& info); - void quit(); + // slots for calling from the webpage + void startDownload(const QString& filename); + void setCallbackOnFinished(const QString& function); + const QString getSysInfo(const QString& info); + void quit(); - // callback when downloads are done. + // callback when downloads are done. void callbackOnFinished(); - // slots for information exchange with the download manager. - void updateProgressBar(const int& percent, const double& speed, const QString& unit); - void downloadInfo(const QString& filename, const double& filesize); - void notify(const QString& msg); + // slots for information exchange with the download manager. + 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 - void trigger(); + // test stuff + void trigger(); }; #endif // JAVASCRIPTINTERFACE_H_ diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index 8f051c8..d37999d 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -3,72 +3,84 @@ // -------------------------------------------------------------------------------------------------- // base of a custom logger engine for the framebuffer //--------------------------------------------------------------------------------------------------- -LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){ - // TODO: silly parent storing ... to change! - _debugConsole = parent; - //_initialized = false; - //setLogLevelsEnabled(QxtLogger::DebugLevel); - //enableLogging(); +LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : + QxtLoggerEngine() { + _debugConsole = parent; + //_initialized = false; + //setLogLevelsEnabled(QxtLogger::DebugLevel); + //enableLogging(); +} +LoggerEngine_fb::~LoggerEngine_fb() { } -LoggerEngine_fb::~LoggerEngine_fb(){} -void LoggerEngine_fb::initLoggerEngine(){ - //_initialized = true; - return; +void LoggerEngine_fb::initLoggerEngine() { + //_initialized = true; + return; } -void LoggerEngine_fb::killLoggerEngine(){ - return; +void LoggerEngine_fb::killLoggerEngine() { + return; } -void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){ +void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, + bool enable) { //QxtLoggerEngine::setLogLevelsEnabled(level, enable); //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel); } -bool LoggerEngine_fb::isInitialized() const{ - //return _initialized; - return true; +bool LoggerEngine_fb::isInitialized() const { + //return _initialized; + return true; } -void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList & msgs){ - // TODO: handle different log levels - if (msgs.isEmpty()) return; - QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] "; - _debugConsole->insertPlainText(header); - // only write to console for debug level - if (level == QxtLogger::DebugLevel){ - Q_FOREACH(const QVariant& out, msgs){ - if (!out.isNull()) - _debugConsole->insertPlainText(out.toString()); - } - _debugConsole->insertPlainText(QString("\n")); - // autoscroll - QTextCursor c = _debugConsole->textCursor(); - c.movePosition(QTextCursor::End); - _debugConsole->setTextCursor(c); - } +void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, + const QList & msgs) { + + if (msgs.isEmpty()) + return; + QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] "; + _debugConsole->insertPlainText(header); + // only write to console for debug level + if (level == QxtLogger::DebugLevel) { + Q_FOREACH(const QVariant& out, msgs) + { + if (!out.isNull()) + _debugConsole->insertPlainText(out.toString()); + } + _debugConsole->insertPlainText(QString("\n")); + // autoscroll + QTextCursor c = _debugConsole->textCursor(); + c.movePosition(QTextCursor::End); + _debugConsole->setTextCursor(c); + } } //--------------------------------------------------------------------------------------------------- // slighty modified QxtBasicSTDLoggerEngine //--------------------------------------------------------------------------------------------------- -LoggerEngine_std::LoggerEngine_std() : QxtBasicSTDLoggerEngine(){} +LoggerEngine_std::LoggerEngine_std() : + QxtBasicSTDLoggerEngine() { +} -LoggerEngine_std::~LoggerEngine_std(){} +LoggerEngine_std::~LoggerEngine_std() { +} + +void LoggerEngine_std::writeToStdErr(const QString& str_level, + const QList &msgs) { -void LoggerEngine_std::writeToStdErr(const QString& str_level, const QList &msgs){ - if (msgs.isEmpty()) return; - QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] "; + if (msgs.isEmpty()) + return; + QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] "; QTextStream* errstream = stdErrStream(); Q_ASSERT(errstream); *errstream << header; Q_FOREACH(const QVariant& out, msgs) - { - if (!out.isNull()) - *errstream << out.toString(); - } + { + if (!out.isNull()) + *errstream << out.toString(); + } *errstream << endl; } -void LoggerEngine_std::writeToStdOut(const QString& level, const QList & msgs){ - // reimplementing this is needed for compiling, - // we only need write to std::err, so this function is not needed +void LoggerEngine_std::writeToStdOut(const QString& level, + const QList & msgs) { + // reimplementing this is needed for compiling, + // we only need write to std::err, so this function is not needed } diff --git a/src/loggerengine.h b/src/loggerengine.h index 8e4a818..9c3ab96 100644 --- a/src/loggerengine.h +++ b/src/loggerengine.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 -# -# -# 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_ @@ -23,19 +23,20 @@ //--------------------------------------------------------------------------------------------------- // base of a custom logger engine for the framebuffer //--------------------------------------------------------------------------------------------------- -class LoggerEngine_fb : public QxtLoggerEngine { +class LoggerEngine_fb: public QxtLoggerEngine { public: - LoggerEngine_fb(QTextEdit* parent); - ~LoggerEngine_fb(); + LoggerEngine_fb(QTextEdit* parent); + ~LoggerEngine_fb(); - // parent widget, target of messages - QTextEdit *_debugConsole; - bool _initialized; + // parent widget, target of messages + QTextEdit *_debugConsole; + bool _initialized; - // reimplemented virtual functions of QxtLoggerEngine - void initLoggerEngine(); - void killLoggerEngine(); - void writeFormatted(QxtLogger::LogLevel level, const QList & messages); + // reimplemented virtual functions of QxtLoggerEngine + void initLoggerEngine(); + void killLoggerEngine(); + void writeFormatted(QxtLogger::LogLevel level, + const QList & messages); void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true); bool isInitialized() const; @@ -43,14 +44,14 @@ public: //--------------------------------------------------------------------------------------------------- // slighty modified QxtBasicSTDLoggerEngine //--------------------------------------------------------------------------------------------------- -class LoggerEngine_std : public QxtBasicSTDLoggerEngine { +class LoggerEngine_std: public QxtBasicSTDLoggerEngine { public: - LoggerEngine_std(); - ~LoggerEngine_std(); + LoggerEngine_std(); + ~LoggerEngine_std(); - // reimplemented virtual functions of QxtBasicSTDLoggerEngineqqq - void writeToStdOut(const QString& level, const QList &msgs); - void writeToStdErr(const QString& str_level, const QList &msgs); + // reimplemented virtual functions of QxtBasicSTDLoggerEngineqqq + void writeToStdOut(const QString& level, const QList &msgs); + void writeToStdErr(const QString& str_level, const QList &msgs); }; #endif // LOGGERENGINE_H_ diff --git a/src/main.cpp b/src/main.cpp index 7d73754..0e7957c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,24 +7,30 @@ #include "loggerengine.h" #include "fbgui.h" -void printHelp() -{ +void printHelp() { QTextStream qout(stdout); qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; - qout << "-c , --config= " << QObject::tr("Path to configuration file.") << endl; - qout << "-u , --url= " << QObject::tr("Sets the URL to be loaded.") << endl; - qout << "-d , --download= " << QObject::tr("Specify the download directory.") << endl; - qout << "-t " << QObject::tr("Specify location of the file triggering the URL load.") << endl; - qout << "-s " << QObject::tr("Specify location of the file containing the serial number.") << endl; - qout << "-D , --debug= " << QObject::tr("Activate debug mode. [0,1]") << endl; - qout << "-h, --help " << QObject::tr("Prints this help.") << endl; + qout << "-c , --config= " << QObject::tr( + "Path to configuration file.") << endl; + qout << "-u , --url= " << QObject::tr( + "Sets the URL to be loaded.") << endl; + qout << "-d , --download= " << QObject::tr( + "Specify the download directory.") << endl; + qout << "-t " << QObject::tr( + "Specify location of the file triggering the URL load.") << endl; + qout << "-s " << QObject::tr( + "Specify location of the file containing the serial number.") + << endl; + qout << "-D , --debug= " << QObject::tr( + "Activate debug mode. [0,1]") << endl; + qout << "-h, --help " << QObject::tr( + "Prints this help.") << endl; qout.flush(); - exit(EXIT_SUCCESS); + exit( EXIT_SUCCESS); } -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { // Initialisation of the QApplication: // In QT, every application is composed of two separate // components: the GUI-Client and the GUI-Server. @@ -45,42 +51,36 @@ int main(int argc, char *argv[]) QMap clOpts; int longIndex = 0; static const char *optString = "c:u:d:s:t:D:h"; - 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'} - }; + 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' } }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - while (opt != -1) - { - switch(opt) - { - case 'c': - clOpts.insert("configFile", optarg); - break; - case 'u': - clOpts.insert("url", optarg); - break; - case 'd': - clOpts.insert("downloadDir", optarg); - break; - case 's': - clOpts.insert("serialLocation", optarg); - break; - case 't': - clOpts.insert("trigger", optarg); - break; - case 'D': - clOpts.insert("debug", optarg); - break; - case 'h': - clOpts.insert("help", "help"); - break; + while (opt != -1) { + switch (opt) { + case 'c': + clOpts.insert("configFile", optarg); + break; + case 'u': + clOpts.insert("url", optarg); + break; + case 'd': + clOpts.insert("downloadDir", optarg); + break; + case 's': + clOpts.insert("serialLocation", optarg); + break; + case 't': + clOpts.insert("trigger", optarg); + break; + case 'D': + clOpts.insert("debug", optarg); + break; + case 'h': + clOpts.insert("help", "help"); + break; } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) if (clOpts.contains("help")) printHelp(); - if (clOpts.contains("debug")){ + if (clOpts.contains("debug")) { debugMode = clOpts.value("debug").toInt(); // start basic debug log qxtLog->disableLoggerEngine("DEFAULT"); @@ -97,8 +97,7 @@ int main(int argc, char *argv[]) qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); qxtLog->enableLogLevels(QxtLogger::DebugLevel); qxtLog->debug() << "Initializing fbgui..."; - } - else + } else debugMode = -1; // look for config file either in: @@ -111,7 +110,7 @@ int main(int argc, char *argv[]) if (clOpts.contains("configFile")) configFilePath = clOpts.value("configFile"); else { - confInfo = QFileInfo(QDir::home(), ".fbgui.conf"); + confInfo = QFileInfo(QDir::home(), ".fbgui.conf"); if (confInfo.exists()) configFilePath = confInfo.absoluteFilePath(); else { @@ -131,28 +130,31 @@ int main(int argc, char *argv[]) if (clOpts.contains("url")) baseURL = QUrl(clOpts.value("url")); else if (confFileSettings.contains("default/pbs_url")) - baseURL = confFileSettings.value("default/pbs_url").toUrl(); - else - baseURL = DEFAULT_URL; + baseURL = confFileSettings.value("default/pbs_url").toUrl(); + else + baseURL = DEFAULT_URL; // set directory for downloads 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; if (confFileSettings.contains("default/update_interval")) - updateInterval = confFileSettings.value("default/update_interval").toInt(); - else - updateInterval = DEFAULT_UPDATE_INTERVAL; + updateInterval + = confFileSettings.value("default/update_interval").toInt(); + else + updateInterval = DEFAULT_UPDATE_INTERVAL; // set which file to watch to trigger loading of URL 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; @@ -160,7 +162,8 @@ 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 569fd06..ef7dc04 100644 --- a/src/sysinfo.cpp +++ b/src/sysinfo.cpp @@ -1,16 +1,17 @@ #include "sysinfo.h" - // ------------------------------------------------------------------------------------------------ /** * A empty constructor. */ -SysInfo::SysInfo(){} +SysInfo::SysInfo() { +} // ------------------------------------------------------------------------------------------------ /** * A empty destructor. */ -SysInfo::~SysInfo(){} +SysInfo::~SysInfo() { +} // ------------------------------------------------------------------------------------------------ /** * This method returns system informations. @@ -32,23 +33,23 @@ SysInfo::~SysInfo(){} * * @see JavascriptInterface::getSysInfo(const QString& info) */ -const QString SysInfo::getInfo(const QString& infoName){ - qxtLog->debug() << "[sysinfo] requested " << infoName; - if (infoName == QString("mac")) - return getMACAddress(); - else if (infoName == QString("ip")) - return getIPAddress(); - else if (infoName == QString("all")) - return getAllInfos(); - else if (infoName == QString("mbserial")) - return getMainboardSerial(); - else if (infoName == QString("usb")) - return getUsbVendorIdProductIdSerialNumber(); - else if (infoName == QString("json")) - return getNames(); - /* unknown code */ - qxtLog->debug() << "[sysinfo] unknown requested"; - return "info_error"; +const QString SysInfo::getInfo(const QString& infoName) { + qxtLog->debug() << "[sysinfo] requested " << infoName; + if (infoName == QString("mac")) + return getMACAddress(); + else if (infoName == QString("ip")) + return getIPAddress(); + else if (infoName == QString("all")) + return getAllInfos(); + else if (infoName == QString("mbserial")) + return getMainboardSerial(); + else if (infoName == QString("usb")) + return getUsbVendorIdProductIdSerialNumber(); + else if (infoName == QString("json")) + return getNames(); + /* unknown code */ + qxtLog->debug() << "[sysinfo] unknown requested"; + return "info_error"; } // ------------------------------------------------------------------------------------------------ /** @@ -66,15 +67,17 @@ const QString SysInfo::getInfo(const QString& infoName){ * @see fbgui::generatePOSTData() * @see SysInfo::getInfo(const QString& infoName) */ -const QString SysInfo::getMACAddress(){ - // Returns MAC address of eth0 for now - QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); - if (!qni.isValid()){ - qxtLog->debug() << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; - return "no_eth0"; - } - //eth0_index = qni.index(); - return qni.hardwareAddress(); +const QString SysInfo::getMACAddress() { + // Returns MAC address of eth0 for now + QNetworkInterface qni = QNetworkInterface::interfaceFromName( + QString("eth0")); + if (!qni.isValid()) { + qxtLog->debug() + << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; + return "no_eth0"; + } + //eth0_index = qni.index(); + return qni.hardwareAddress(); } // ------------------------------------------------------------------------------------------------ /** @@ -90,61 +93,64 @@ const QString SysInfo::getMACAddress(){ * * @see SysInfo::getInfo(const QString& infoName) */ -const QString SysInfo::getIPAddress(){ - // Again for eth0 only at the moment. - // TODO: this doesn't quite work yet... - QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); - QList 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(); - } - } - // still here? - qxtLog->debug() << "[sysinfo] IP Address: ip_error"; - return "ip_error"; +const QString SysInfo::getIPAddress() { + // Again for eth0 only at the moment. + // TODO: this doesn't quite work yet... + QNetworkInterface qni = QNetworkInterface::interfaceFromName( + QString("eth0")); + QList 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(); + } + } + // still here? + qxtLog->debug() << "[sysinfo] IP Address: ip_error"; + return "ip_error"; } // ------------------------------------------------------------------------------------------------ /** * just a test method for json. */ -const QByteArray SysInfo::getNames(){ +const QByteArray SysInfo::getNames() { - QVariantMap foo; - foo.insert("name", "foo"); - foo.insert("type", 123); + QVariantMap foo; + foo.insert("name", "foo"); + foo.insert("type", 123); - QVariantMap fooo; - fooo.insert("name", "boo"); - fooo.insert("type", 321); + QVariantMap fooo; + fooo.insert("name", "boo"); + fooo.insert("type", 321); - QVariantList jsonV; - jsonV << foo << fooo; + QVariantList jsonV; + jsonV << foo << fooo; - QJson::Serializer serializer; - QByteArray json = serializer.serialize(jsonV); + QJson::Serializer serializer; + QByteArray json = serializer.serialize(jsonV); - qxtLog->debug() << json; - return json; + qxtLog->debug() << json; + return json; } // ------------------------------------------------------------------------------------------------ /** * just a test method for json. */ -QString SysInfo::getAllInfos(){ - QVariantMap infos; - infos.insert("mac", getMACAddress()); - infos.insert("ip", getIPAddress()); - infos.insert("whoami", getScriptOutput("whoami")); - //infos.insert("pwd", getScriptOutput("pwd")); +QString SysInfo::getAllInfos() { + QVariantMap infos; + infos.insert("mac", getMACAddress()); + infos.insert("ip", getIPAddress()); + infos.insert("whoami", getScriptOutput("whoami")); + //infos.insert("pwd", getScriptOutput("pwd")); - //QJson::Serializer serializer; - QByteArray json = serializer.serialize(infos); + //QJson::Serializer serializer; + QByteArray json = serializer.serialize(infos); - qxtLog->debug() << json; - return json; + qxtLog->debug() << json; + return json; } // ------------------------------------------------------------------------------------------------ @@ -163,26 +169,28 @@ QString SysInfo::getAllInfos(){ * @see fbgui::generatePOSTData() * @see SysInfo::getInfo(const QString& infoName) */ -const QString SysInfo::getMainboardSerial(){ - QString out = ""; - 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); +const QString SysInfo::getMainboardSerial() { + QString out = ""; + 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); - if(attrlist != NULL){ - struct sysfs_attribute *attr = NULL; - dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { - QVariantMap a; - if(QString(attr->name) == QString("board_serial")){ - out = QString(attr->value); - } - } - qxtLog->debug()<< "[sysinfo] Mainboard Serial: " + out; - return out; - } - qxtLog->debug()<< "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error"; - sysfs_close_class_device(class_device); - return "mainboard_serial_error"; + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { + QVariantMap a; + if(QString(attr->name) == QString("board_serial")) { + out = QString(attr->value); + } + } + qxtLog->debug() << "[sysinfo] Mainboard Serial: " + out; + return out; + } + qxtLog->debug() + << "[sysinfo] Mainboard Serial: attrlist is null! return: mainboard_serial_error"; + sysfs_close_class_device(class_device); + return "mainboard_serial_error"; } // ------------------------------------------------------------------------------------------------ /** @@ -206,74 +214,77 @@ const QString SysInfo::getMainboardSerial(){ * * @see SysInfo::getInfo(const QString& infoName) */ -const QString SysInfo::getUsbVendorIdProductIdSerialNumber() -{ - QString tag = "[sysinfo] Usb Serial:"; - QString out = ""; - QVariantList list; +const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { + QString tag = "[sysinfo] Usb Serial:"; + QString out = ""; + QVariantList list; - libusb_device **devs; - libusb_context *ctx = NULL; //a libusb session - ssize_t cnt; //holding number of devices in list - int r = 1; - r = libusb_init(&ctx); - if(r<0){ - qxtLog->debug()<< tag + "failed to initialise libusb"; - return "error"; - } - cnt = libusb_get_device_list(ctx, &devs); //get the list of devices - if(cnt < 0) { - qxtLog->debug()<< tag + "Get Device Error"; //there was an error - } - qxtLog->debug()<< tag + cnt + " Devices in list."; //print total number of usb devices - ssize_t i; //for iterating through the list# - for(i=0; i < cnt; i++){ - //printdev(devs[i]); //print specs of this device - QVariantMap infos; - libusb_device *dev = devs[i]; - libusb_device_descriptor desc; - int re = libusb_get_device_descriptor(dev, &desc); - if (re < 0) { - qxtLog->debug()<< tag + "failed to get device descriptor"; - return "error"; - } - infos.insert("vendorId",desc.idVendor); - infos.insert("productId",desc.idProduct); - unsigned char string[256]; - libusb_device_handle *handle; - re = libusb_open(dev, &handle); - if (re != 0) { - 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)); - 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)); - 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)); - if (re < 0) { - qxtLog->debug()<< tag + "failed to get Product"; - return "error"; - } - infos.insert("manuacturer",QString((const char *)string)); + libusb_device **devs; + libusb_context *ctx = NULL; //a libusb session + ssize_t cnt; //holding number of devices in list + int r = 1; + r = libusb_init(&ctx); + if (r < 0) { + qxtLog->debug() << tag + "failed to initialise libusb"; + return "error"; + } + cnt = libusb_get_device_list(ctx, &devs); //get the list of devices + if (cnt < 0) { + qxtLog->debug() << tag + "Get Device Error"; //there was an error + } + qxtLog->debug() << tag + cnt + " Devices in list."; //print total number of usb devices + ssize_t i; //for iterating through the list# + for (i = 0; i < cnt; i++) { + //printdev(devs[i]); //print specs of this device + QVariantMap infos; + libusb_device *dev = devs[i]; + libusb_device_descriptor desc; + int re = libusb_get_device_descriptor(dev, &desc); + if (re < 0) { + qxtLog->debug() << tag + "failed to get device descriptor"; + return "error"; + } + infos.insert("vendorId", desc.idVendor); + infos.insert("productId", desc.idProduct); + unsigned char string[256]; + libusb_device_handle *handle; + re = libusb_open(dev, &handle); + if (re != 0) { + 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)); + 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)); + 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)); + if (re < 0) { + qxtLog->debug() << tag + "failed to get Product"; + return "error"; + } + infos.insert("manuacturer", QString((const char *) string)); - list << infos; - libusb_close(handle); - } - libusb_free_device_list(devs, 1); //free the list, unref the devices in it - libusb_exit(ctx); //close the session + list << infos; + libusb_close(handle); + } + libusb_free_device_list(devs, 1); //free the list, unref the devices in it + libusb_exit(ctx); //close the session - QByteArray json = serializer.serialize(list); - qxtLog->debug()<< tag + "json object: " + json; - return json; + QByteArray json = serializer.serialize(list); + qxtLog->debug() << tag + "json object: " + json; + return json; } // ------------------------------------------------------------------------------------------------ @@ -290,28 +301,27 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() * @return QString * output of the script. */ -QString SysInfo::getScriptOutput(QString cmd) -{ +QString SysInfo::getScriptOutput(QString cmd) { QProcess *process = new QProcess(); - qxtLog->debug()<<"[sysinfo] Script Output: try to open: "<debug() << "[sysinfo] Script Output: try to open: " << cmd; process->start(cmd, QIODevice::ReadOnly); - if (!process->waitForStarted() ) - qxtLog->debug()<<"[sysinfo] Script Output: process couldn't get opened"; + if (!process->waitForStarted()) + qxtLog->debug() + << "[sysinfo] Script Output: process couldn't get opened"; QString output; process->waitForFinished(); QTextStream *txt_stream = new QTextStream(process); - while(!txt_stream->atEnd() ) - { - qxtLog->debug()<<"[sysinfo] Script Output: read output: "; + while (!txt_stream->atEnd()) { + qxtLog->debug() << "[sysinfo] Script Output: read output: "; QString tmp_str = txt_stream->readLine(); output += tmp_str; - qxtLog->debug()<< "[sysinfo] Script Output: " <debug() << "[sysinfo] Script Output: " << tmp_str; } - qxtLog->debug()<<"[sysinfo] Script Output: process finished: "; + qxtLog->debug() << "[sysinfo] Script Output: process finished: "; return output; } diff --git a/src/sysinfo.h b/src/sysinfo.h index f4968e8..7b9cf17 100644 --- a/src/sysinfo.h +++ b/src/sysinfo.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 -# -# -# 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 #define SYSINFO_H @@ -33,24 +33,23 @@ extern "C" { class SysInfo { public: - SysInfo(); - ~SysInfo(); - // public access, valid infoName: "mac", "ip", ... - const QString getInfo(const QString& infoName); + SysInfo(); + ~SysInfo(); + // public access, valid infoName: "mac", "ip", ... + const QString getInfo(const QString& infoName); private: - // private system information readers - const QString getMACAddress(); - const QString getIPAddress(); - const QString getMainboardSerial(); - const QString getUsbVendorIdProductIdSerialNumber(); - QString getAllInfos(); - QString getScriptOutput(QString cmd); - - - // JSon testing - QJson::Serializer serializer; - const QByteArray getNames(); + // private system information readers + const QString getMACAddress(); + const QString getIPAddress(); + const QString getMainboardSerial(); + const QString getUsbVendorIdProductIdSerialNumber(); + QString getAllInfos(); + QString getScriptOutput(QString cmd); + + // JSon testing + QJson::Serializer serializer; + const QByteArray getNames(); }; #endif // SYSTINFO_H diff --git a/src/sysinfolibsysfs.cpp b/src/sysinfolibsysfs.cpp index 2c9aafc..9030155 100644 --- a/src/sysinfolibsysfs.cpp +++ b/src/sysinfolibsysfs.cpp @@ -14,137 +14,135 @@ // Initialisation //------------------------------------------------------------------------------------------------------- SysInfoLibsysfs::SysInfoLibsysfs() { - // TODO Auto-generated constructor stub + // TODO Auto-generated constructor stub } SysInfoLibsysfs::~SysInfoLibsysfs() { - // TODO Auto-generated destructor stub + // TODO Auto-generated destructor stub } -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_device *device = sysfs_get_classdev_device(class_device); - //struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device); - if(device == NULL) { - //qxtLog->debug() << "[libsysfs] device is NULL!"; - } - else { - qDebug() << "--- print eth0 device path:"; - qDebug() << QString(device->path); - } - - sysfs_close_class_device(class_device); +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_device *device = sysfs_get_classdev_device(class_device); + //struct sysfs_driver *driver = sysfs_get_classdev_driver(class_device); + if (device == NULL) { + //qxtLog->debug() << "[libsysfs] device is NULL!"; + } else { + qDebug() << "--- print eth0 device path:"; + qDebug() << QString(device->path); + } + + sysfs_close_class_device(class_device); } -void SysInfoLibsysfs::getInfoMbSerial() -{ - QJson::Serializer serializer; - QVariantList listOfDevices; - - 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); - - if(attrlist != NULL){ - struct sysfs_attribute *attr = NULL; - QVariantList list; - dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { - QVariantMap a; - if(QString(attr->name) == QString("board_serial")){ - a.insert("name", QString(attr->name)); - a.insert("value", QString(attr->value)); - a.insert("len", QString(attr->len)); - a.insert("path", QString(attr->path)); - a.insert("method", QString(attr->method)); - list << a; - } - } - QByteArray json = serializer.serialize(list); - - qDebug() << json; - return; - } - qDebug() << "attrlist is null!"; - sysfs_close_class_device(class_device); +void SysInfoLibsysfs::getInfoMbSerial() { + QJson::Serializer serializer; + QVariantList listOfDevices; + + 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); + + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + QVariantList list; + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { + QVariantMap a; + if(QString(attr->name) == QString("board_serial")) { + a.insert("name", QString(attr->name)); + a.insert("value", QString(attr->value)); + a.insert("len", QString(attr->len)); + a.insert("path", QString(attr->path)); + a.insert("method", QString(attr->method)); + list << a; + } + } + QByteArray json = serializer.serialize(list); + + qDebug() << json; + return; + } + qDebug() << "attrlist is null!"; + sysfs_close_class_device(class_device); } -QString SysInfoLibsysfs::getInfoMainboardSerial(){ - QString out = ""; - 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); - - if(attrlist != NULL){ - struct sysfs_attribute *attr = NULL; - dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { - QVariantMap a; - if(QString(attr->name) == QString("board_serial")){ - out = QString(attr->value); - } - } - - qDebug() << out; - return out; - } - qDebug() << "attrlist is null!"; - sysfs_close_class_device(class_device); - return NULL; +QString SysInfoLibsysfs::getInfoMainboardSerial() { + QString out = ""; + 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); + + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { + QVariantMap a; + if(QString(attr->name) == QString("board_serial")) { + out = QString(attr->value); + } + } + + qDebug() << out; + return out; + } + qDebug() << "attrlist is null!"; + sysfs_close_class_device(class_device); + return NULL; } -void SysInfoLibsysfs::getInfoAboutClassNet() -{ - QJson::Serializer serializer; - QVariantList listOfDevices; - - struct sysfs_class *sysfsclass = sysfs_open_class("net"); - struct dlist *devices = sysfs_get_class_devices(sysfsclass); - struct sysfs_device *dev = NULL; - dlist_for_each_data(devices,dev, struct sysfs_device) { - if(dev == NULL) { - qDebug() << "device is NULL!"; - //qxtLog->debug() << "[libsysfs] device is NULL!"; - } - else { - - qDebug() << "--- print device:"; - - QVariantMap infos; - infos.insert("name", QString(dev->name)); - infos.insert("bus", QString(dev->bus)); - infos.insert("bus_id", QString(dev->bus_id)); - infos.insert("driver_name", QString(dev->driver_name)); - infos.insert("path", QString(dev->path)); - infos.insert("subsystem", QString(dev->subsystem)); - struct dlist *attrlist = dev->attrlist; - if (attrlist != NULL) { - struct sysfs_attribute *attr = NULL; - QVariantList list; - dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { - QVariantMap a; - a.insert("name", QString(attr->name)); - a.insert("value", QString(attr->value)); - a.insert("len", QString(attr->len)); - a.insert("path", QString(attr->path)); - a.insert("method", QString(attr->method)); - list << a; - } - QByteArray json = serializer.serialize(list); - - qDebug() << json; - infos.insert("attrlist", list); - } - listOfDevices << infos; - } - - } - - sysfs_close_class(sysfsclass); - - - QByteArray json = serializer.serialize(listOfDevices); - - qDebug() << json; +void SysInfoLibsysfs::getInfoAboutClassNet() { + QJson::Serializer serializer; + QVariantList listOfDevices; + + struct sysfs_class *sysfsclass = sysfs_open_class("net"); + struct dlist *devices = sysfs_get_class_devices(sysfsclass); + struct sysfs_device *dev = NULL; + dlist_for_each_data(devices,dev, struct sysfs_device) { + if(dev == NULL) { + qDebug() << "device is NULL!"; + //qxtLog->debug() << "[libsysfs] device is NULL!"; + } + else { + + qDebug() << "--- print device:"; + + QVariantMap infos; + infos.insert("name", QString(dev->name)); + infos.insert("bus", QString(dev->bus)); + infos.insert("bus_id", QString(dev->bus_id)); + infos.insert("driver_name", QString(dev->driver_name)); + infos.insert("path", QString(dev->path)); + infos.insert("subsystem", QString(dev->subsystem)); + struct dlist *attrlist = dev->attrlist; + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + QVariantList list; + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { + QVariantMap a; + a.insert("name", QString(attr->name)); + a.insert("value", QString(attr->value)); + a.insert("len", QString(attr->len)); + a.insert("path", QString(attr->path)); + a.insert("method", QString(attr->method)); + list << a; + } + QByteArray json = serializer.serialize(list); + + qDebug() << json; + infos.insert("attrlist", list); + } + listOfDevices << infos; + } + + } + + sysfs_close_class(sysfsclass); + + QByteArray json = serializer.serialize(listOfDevices); + + qDebug() << json; } diff --git a/src/sysinfolibsysfs.h b/src/sysinfolibsysfs.h index 3da58ce..d45b0f1 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 * -- cgit v1.2.3-55-g7522