From 46061aa2dbc20edcf98f26dfff5f8c23fcaae4eb Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 16 Mar 2011 20:13:40 +0100 Subject: (WIP) logViewer wont stay like this, just to show layout possibilities..(WIP) logViewer wont stay like this, just to show layout possibilities.... --- src/logViewer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/logViewer.cpp') diff --git a/src/logViewer.cpp b/src/logViewer.cpp index 2c302f8..4f2b42d 100644 --- a/src/logViewer.cpp +++ b/src/logViewer.cpp @@ -2,13 +2,14 @@ #include logViewer::logViewer(QWidget *parent) : QTextEdit(parent) { + setWindowFlags(Qt::FramelessWindowHint); QPalette qp; qp.setColor(QPalette::Base, Qt::black); setPalette(qp); setTextColor(Qt::green); setPlainText("Debug console loaded."); - resize(QSize(640, 480)); - setVisible(false); + //resize(QSize(640, 480)); + //setVisible(false); } void logViewer::write(QString text){ -- cgit v1.2.3-55-g7522 From db94cf6c69e5c8c9f2b1b5dcf77879c425fbd1b4 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 18 Mar 2011 11:31:51 +0100 Subject: layout: logViewer as a bottom widget, resizeable, toggle with crtl + D, stil for demonstration purposes mostly... --- src/fbgui.cpp | 44 ++++++++++++++++++++++++++------------------ src/fbgui.h | 6 ++++++ src/logViewer.cpp | 14 ++++---------- src/logViewer.h | 4 ++-- 4 files changed, 38 insertions(+), 30 deletions(-) (limited to 'src/logViewer.cpp') diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 9bde450..52462cb 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -9,30 +9,26 @@ #include QUrl baseURL(DEFAULT_URL); -QString binPath(""); -QString downloadPath(binPath + "/downloads"); +QString binPath(QApplication::applicationDirPath()); +QString downloadPath("/tmp/fbgui/downloads"); int updateInterval = DEFAULT_UPDATE_INTERVAL; bool debug = false; //------------------------------------------------------------------------------------------- fbgui::fbgui() { - /* debug console tests */ + /* TEST CODE */ logViewer *logView = new logViewer(this); - /* dock on bottom */ + /* Dock widget to place logView on bottom */ QDockWidget *dw = new QDockWidget(QString("debug console"), this); dw->setAllowedAreas(Qt::BottomDockWidgetArea); dw->setWidget(logView); + /* Create toggle action (F4) and add to fbgui's action list */ + QAction *toggleLog = dw->toggleViewAction(); + toggleLog->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + this->addAction(toggleLog); + /* Dock logView to bottom */ addDockWidget(Qt::BottomDockWidgetArea, dw); - /* TEST - QWidget *dummy = new QWidget(); - QVBoxLayout *layout = new QVBoxLayout(); - layout->addWidget(webView); - layout->addWidget(logView); - dummy->setLayout(layout); - TEST */ - - /* initialize "browser" */ @@ -48,20 +44,32 @@ fbgui::fbgui() /* initialize download manager */ downloadManager* dm = new downloadManager(); - QObject::connect(dm, SIGNAL(downloadInfo(QString, double)), jsi, SLOT(downloadInfo(QString, double))); + QObject::connect(dm, SIGNAL(downloadInfo(QString, double)), + jsi, SLOT(downloadInfo(QString, double))); QObject::connect(jsi, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&))); - QObject::connect(dm, SIGNAL(updateProgress(int, double, QString)), jsi, SLOT(updateProgressBar(int, double, QString))); + QObject::connect(dm, SIGNAL(updateProgress(int, double, QString)), + jsi, SLOT(updateProgressBar(int, double, QString))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished())); + setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); - resize(QSize(800, 600)); setCentralWidget(webView); showFullScreen(); - show(); -} +} +//------------------------------------------------------------------------------------------- +void fbgui::createActions(){ + _act = new QAction(tr("&test"), this); + _act->setShortcut(QKeySequence(Qt::Key_F5)); + this->addAction(_act); + connect(_act, SIGNAL(triggered()), this, SLOT(testAct())); +} +//------------------------------------------------------------------------------------------- +void fbgui::testAct(){ + qDebug() << "Action triggered!"; +} //------------------------------------------------------------------------------------------- void fbgui::checkHost() const { diff --git a/src/fbgui.h b/src/fbgui.h index b62e5ab..fc9a86b 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -42,8 +42,14 @@ public: fbgui(); private: + void createActions(); void checkHost() const; + QAction* _act; + +private slots: + void testAct(); + }; #endif // FBGUI_H diff --git a/src/logViewer.cpp b/src/logViewer.cpp index 4f2b42d..ac93f39 100644 --- a/src/logViewer.cpp +++ b/src/logViewer.cpp @@ -3,15 +3,9 @@ logViewer::logViewer(QWidget *parent) : QTextEdit(parent) { setWindowFlags(Qt::FramelessWindowHint); - QPalette qp; - qp.setColor(QPalette::Base, Qt::black); - setPalette(qp); + QPalette pal; + pal.setColor(QPalette::Base, Qt::black); + setPalette(pal); setTextColor(Qt::green); - setPlainText("Debug console loaded."); - //resize(QSize(640, 480)); - //setVisible(false); -} - -void logViewer::write(QString text){ - if (debug) this->append(text); + setPlainText("Debug console initialized."); } diff --git a/src/logViewer.h b/src/logViewer.h index 7c61baf..b123f05 100644 --- a/src/logViewer.h +++ b/src/logViewer.h @@ -11,7 +11,8 @@ # General information about OpenSLX can be found under http://openslx.org # # -# Simple logfile viewer / debug console. +# Simple log viewer. (experimental) +# Requires: Logger engine (to implement) # */ #ifndef LOGVIEWER_H @@ -23,7 +24,6 @@ class logViewer : public QTextEdit { public: logViewer(QWidget *parent); - void write(QString text); }; #endif // LOGVIEWER_H -- cgit v1.2.3-55-g7522 From 3e76f5ca4439ae87f436080b840dba180fb842d3 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 20 Mar 2011 19:37:58 +0100 Subject: debug console now powered by qxt, custom engines, updated debug msgs. Download manager now uses notify(message) to send error/status to the javascript interface, checks for download errors (still some missing) --- build.sh | 2 +- src/downloadManager.cpp | 90 ++++++++++++++++++++++----------------------- src/downloadManager.h | 14 +++---- src/fbgui.cpp | 79 +++++++++++++++++++++++---------------- src/fbgui.h | 8 ++-- src/fbgui.pro | 16 +++++--- src/javascriptInterface.cpp | 35 ++++++++---------- src/javascriptInterface.h | 1 + src/logViewer.cpp | 11 ------ src/logViewer.h | 29 --------------- src/loggerEngine.cpp | 76 ++++++++++++++++++++++++++++++++++++++ src/loggerEngine.h | 49 ++++++++++++++++++++++++ src/main.cpp | 20 +++------- src/sysInfo.cpp | 13 +++---- src/sysInfo.h | 2 - src/testApp.sh | 2 +- 16 files changed, 267 insertions(+), 180 deletions(-) delete mode 100644 src/logViewer.cpp delete mode 100644 src/logViewer.h create mode 100644 src/loggerEngine.cpp create mode 100644 src/loggerEngine.h (limited to 'src/logViewer.cpp') diff --git a/build.sh b/build.sh index f401c87..9d5ce6b 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -QT_VERSION=QtEmbedded-4.7.1 +QT_VERSION=QtEmbedded-4.7.2 mkdir -p pkg diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp index 01769ef..3d47990 100644 --- a/src/downloadManager.cpp +++ b/src/downloadManager.cpp @@ -1,72 +1,72 @@ #include "downloadManager.h" #include "fbgui.h" -#include -#include int downloadManager::downloaded = 0; // ---------------------------------------------------------------------------------------- downloadManager::downloadManager() { - //logView->write(QString("testing @ DM init")); + qxtLog->debug() << "Initializing download manager..."; + checkDownloadDirectory(); qnam = new QNetworkAccessManager(); dip = false; - downloadDir = QDir(downloadPath); +} +// ---------------------------------------------------------------------------------------- +void downloadManager::checkDownloadDirectory(){ /* check if downloadPath exists, if not create it. */ + QDir downloadDir = QDir(downloadPath); if (!downloadDir.exists()){ - if (debug) qDebug() << "Download directory: " << downloadDir.path() << "doesn't exist."; + qxtLog->debug() << "Download directory: " << downloadDir.path() << " doesn't exist."; QDir::current().mkdir(downloadPath); - if (downloadDir.exists() && debug) - qDebug() << "Created download directory: " << downloadDir.path(); + if (downloadDir.exists()){ + qxtLog->debug() << "Created download directory: " << downloadDir.path(); + } + else { + qxtLog->debug() << "Failed to create directory: " << downloadDir.path(); + emit notify(QString("Failed to create download directory!")); + } } - else if (debug) qDebug() << "Download directory: " << downloadDir.path() << "exists."; + else qxtLog->debug() << "Download directory: " << downloadDir.path() << " exists."; } // ---------------------------------------------------------------------------------------- void downloadManager::downloadFile(QString& filename) { - if (debug) qDebug() << "Received downloadFile signal for:" << filename; - QUrl fileUrl; - fileUrl = baseURL.resolved(QUrl(filename)); - if (debug) qDebug() << "fileUrl: " << fileUrl; + QUrl fileUrl(baseURL.resolved(QUrl(filename))); this->processDownloadRequest(fileUrl); } // ---------------------------------------------------------------------------------------- void downloadManager::downloadFile(QUrl& fileUrl) { - if (debug) qDebug() << "Received downloadFile signal for:" << fileUrl; this->processDownloadRequest(fileUrl); } // ---------------------------------------------------------------------------------------- void downloadManager::processDownloadRequest(QUrl& url) { if (url.isEmpty()){ - if (debug) qDebug() << "No URL specified for download."; + qxtLog->debug() << "No URL specified for download."; return; } /* if download in progress, enqueue file and return. */ - if (dip) - { - if (debug) qDebug() << "Download in progress! Enqueueing:" << url.toString() - << "(" << dlQ.size() << "in queue)"; + if (dip){ + qxtLog->debug() << "Download in progress! Enqueueing:" << url.toString() + << "(" << dlQ.size() << " in queue)"; dlQ.enqueue(url); return; } /* no running downloads: enqueue and start next download. */ dlQ.enqueue(url); - if (debug) qDebug() << "Enqueueing:" << url.toString() << endl; + qxtLog->debug() << "Enqueueing:" << url.toString(); startNextDownload(); } // ---------------------------------------------------------------------------------------- void downloadManager::startNextDownload() { - - if (dlQ.isEmpty()) - { + if (dlQ.isEmpty()){ emit downloadQueueEmpty(); - if (debug) qDebug() << "Download manager ready. (1)"; + qxtLog->debug() << "Download manager ready. (1)"; return; } - if (debug) qDebug() << "Starting next download: " << dlQ.head().toString() - << "(" << dlQ.size() << "in queue.)"; + qxtLog->debug() << "Starting next download: " << dlQ.head().toString() + << " (" << dlQ.size() - 1 << " in queue.)"; /* dequeue next URL to download. */ QUrl url = dlQ.dequeue(); @@ -85,7 +85,8 @@ void downloadManager::startNextDownload() outfile.setFileName(downloadPath + "/" + tmp); if (!outfile.open(QIODevice::WriteOnly)){ - if (debug) qDebug() << "Couldn't open file! Skipping..."; + qxtLog->debug() << "Couldn't open file! Skipping..."; + emit notify(QString("Couldn't open " + downloadPath + "/" + tmp + "! Skipping...")); return; } @@ -121,9 +122,7 @@ void downloadManager::downloadReady() // ---------------------------------------------------------------------------------------- void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { - // "fix" for the weird bytesTotal = -1 initial reading... - if (bytesIn > bytesTotal) - return; + if (bytesIn > bytesTotal) return; /* calculate current speed */ double speed = bytesIn * 1000 / dltime.elapsed(); QString unit; @@ -143,7 +142,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) if (currentProgress - lastProgress >= updateInterval){ lastProgress = currentProgress; emit updateProgress(currentProgress, speed, unit); - if (debug) qDebug() << "Download progress of " << currentDownload->url().toString() + qxtLog->debug() << "Download progress of " << currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal << "(" << currentProgress << "\%)"; } return; @@ -153,25 +152,26 @@ void downloadManager::downloadFinished() { /* check for errors */ if (currentDownload->error()){ - if (debug) qDebug() << "Download of" << currentDownload->url().toString() - << "failed with status code: " << currentDownload->error(); currentDownload->deleteLater(); outfile.remove(); - return; + int statusCode = currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + qxtLog->debug() << "Download of " << currentDownload->url().toString() + << " failed with HTTP error code: " << statusCode; + emit notify(QString("HTTP Error: %1").arg(statusCode)); + } + else{ + /* end download */ + currentDownload->deleteLater(); + outfile.close(); + downloaded++; + qxtLog->debug() << "Download of " << currentDownload->url().toString() + << " finished. (downloaded = "<< downloaded << ")"; } - // TODO Handle errors. - if (debug) qDebug() << "NetworkCode: " << currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - /* end download */ - outfile.close(); - currentDownload->deleteLater(); - downloaded++; dip = false; - if (debug) qDebug() << "Download of " << currentDownload->url().toString() - << "finished. (dlcount = "<< downloaded << ")"; + /* process next in queue */ if (dlQ.isEmpty()){ emit downloadQueueEmpty(); - if (debug) qDebug() << "Download manager ready. (2)"; + qxtLog->debug() << "Download manager ready. (2)"; return; } startNextDownload(); @@ -194,9 +194,9 @@ tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); qDebug() << "Trying to rename " << tmp << " to --> " << currentTargetFilename; if (outfile.rename(downloadPath + "/" + currentTargetFilename)) { - if (debug) qDebug() << "Renamed file!"; + qxtLog->debug() << "Renamed file!"; } else { - if (debug) qDebug() << "Failure to rename file!"; + qxtLog->debug() << "Failure to rename file!"; } */ diff --git a/src/downloadManager.h b/src/downloadManager.h index 2e26b70..2ee980a 100644 --- a/src/downloadManager.h +++ b/src/downloadManager.h @@ -19,11 +19,6 @@ #define DOWNLOADMANAGER_H #include "fbgui.h" -#include -#include -#include -#include -#include extern bool debug; extern QUrl baseURL; @@ -40,23 +35,24 @@ public: downloadManager(); private: + void checkDownloadDirectory(); void processDownloadRequest(QUrl& url); QNetworkAccessManager* qnam; QQueue dlQ; - QNetworkRequest request; QNetworkReply* currentDownload; QFile outfile; - QDir downloadDir; + QString currentTargetFilename; QTime dltime; - bool dip; int currentProgress, lastProgress; + bool dip; static int downloaded; - QString currentTargetFilename; + signals: void finished(); void downloadInfo(QString filename, double filesize); + void notify(QString msg); void updateProgress(int percent, double speed, QString unit); void downloadQueueEmpty(); diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 96265d2..f642da2 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -1,12 +1,11 @@ #include "fbgui.h" +#include "loggerEngine.h" #include "downloadManager.h" #include "javascriptInterface.h" #include -#include -#include -#include #include +#include QUrl baseURL(DEFAULT_URL); QString binPath(""); @@ -14,14 +13,25 @@ QString downloadPath("/tmp/fbgui/downloads"); int updateInterval = DEFAULT_UPDATE_INTERVAL; bool debug = false; + //------------------------------------------------------------------------------------------- -fbgui::fbgui() -{ - /* initialize "browser" */ +fbgui::fbgui(){ + /* setup qxt logger and enable custom std engine*/ + qxtLog->disableLoggerEngine("DEFAULT"); + qxtLog->addLoggerEngine("std_logger", new loggerEngine_std); + qxtLog->initLoggerEngine("std_logger"); + qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); + qxtLog->debug() << "Initializing fbgui..."; + + /* initliaze browser */ checkHost(); _webView = new QWebView(this); _webView->load(baseURL); + /* debug split if debug mode, normal browser else */ + if (debug) setupDebugSplit(); + else setCentralWidget(_webView); + /* initialize javascript interface */ javascriptInterface* jsi = new javascriptInterface(_webView->page()->mainFrame()); QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); @@ -32,50 +42,55 @@ fbgui::fbgui() downloadManager* dm = new downloadManager(); QObject::connect(dm, SIGNAL(downloadInfo(QString, double)), jsi, SLOT(downloadInfo(QString, double))); + QObject::connect(dm, SIGNAL(notify(QString)), + jsi, SLOT(notify(QString))); QObject::connect(jsi, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&))); QObject::connect(dm, SIGNAL(updateProgress(int, double, QString)), jsi, SLOT(updateProgressBar(int, double, QString))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished())); - setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); - - /* TEST */ - if (debug){ - _logView = new logViewer(this); - _splitter = new QSplitter(Qt::Vertical, this); - _splitter->addWidget(_webView); - _splitter->addWidget(_logView); - /* CTRL + D toggles debug window */ - _toggleDebug = new QAction(tr("&toggleDebug"), this); - _toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - this->addAction(_toggleDebug); - connect(_toggleDebug, SIGNAL(triggered()), this, SLOT(toggleDebug())); - //createToggleDebugAction(); - setCentralWidget(_splitter); - } - else - setCentralWidget(_webView); - /* TEST */ - showFullScreen(); } //------------------------------------------------------------------------------------------- +void fbgui::setupDebugSplit(){ + _debugConsole = new QTextEdit(this); + _debugConsole->setWindowFlags(Qt::FramelessWindowHint); + QPalette pal; + pal.setColor(QPalette::Base, Qt::black); + _debugConsole->setPalette(pal); + _debugConsole->setTextColor(Qt::cyan); + _debugConsole->insertPlainText("Debug console initialized.\n"); + /* switch engine to custom engine class "logger" */ + qxtLog->addLoggerEngine("fb_logger", new loggerEngine_fb(_debugConsole)); + qxtLog->initLoggerEngine("fb_logger"); + qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); + /* display browser and debug in a splitter */ + _splitter = new QSplitter(Qt::Vertical, this); + _splitter->addWidget(_webView); + _splitter->addWidget(_debugConsole); + /* CTRL + D toggles debug window */ + _toggleDebug = new QAction(tr("&toggleDebug"), this); + _toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + addAction(_toggleDebug); + connect(_toggleDebug, SIGNAL(triggered()), this, SLOT(toggleDebug())); + setCentralWidget(_splitter); +} //------------------------------------------------------------------------------------------- void fbgui::toggleDebug(){ - if (_logView->isVisibleTo(_splitter)) - _logView->hide(); + if (_debugConsole->isVisible()) + _debugConsole->hide(); else - _logView->show(); + _debugConsole->show(); } //------------------------------------------------------------------------------------------- -void fbgui::checkHost() const -{ +void fbgui::checkHost() const{ + // TODO instead of closing app, show error page from qrc QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); if (hostInfo.error() != QHostInfo::NoError){ - qDebug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; + qxtLog->debug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; exit(EXIT_FAILURE); } } diff --git a/src/fbgui.h b/src/fbgui.h index be0cf4e..f310127 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -19,13 +19,14 @@ #define FBGUI_H #include -#include #include +#include -#include "logViewer.h" +/* Internal default settings */ #define DEFAULT_URL "http://www.google.com" #define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads" +#define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" #define DEFAULT_UPDATE_INTERVAL 1; extern QString binPath; @@ -42,12 +43,13 @@ public: fbgui(); private: + void setupDebugSplit(); void createActions(); void checkHost() const; QSplitter* _splitter; QWebView* _webView; - logViewer* _logView; + QTextEdit* _debugConsole; QAction* _toggleDebug; diff --git a/src/fbgui.pro b/src/fbgui.pro index 1b8d1f8..0ca0078 100644 --- a/src/fbgui.pro +++ b/src/fbgui.pro @@ -1,20 +1,26 @@ TEMPLATE = app TARGET = fbgui CONFIG += qt \ + qxt \ debug -LIBS += -L/usr/local/qjson/lib \ - -lqjson -INCLUDEPATH += -I/usr/local/qjson/include QT += core \ gui \ webkit \ network -HEADERS += logViewer.h \ +QXT += core +LIBS += -L/usr/local/qjson/lib \ + -lqjson \ + -L/usr/local/Qxt/lib \ + -lQxtCore +INCLUDEPATH += /usr/local/qjson/include \ + /usr/local/Qxt/include \ + /usr/local/Qxt/include/QxtCore +HEADERS += loggerEngine.h \ downloadManager.h \ fbgui.h \ javascriptInterface.h \ sysInfo.h -SOURCES += logViewer.cpp \ +SOURCES += loggerEngine.cpp \ downloadManager.cpp \ main.cpp \ fbgui.cpp \ diff --git a/src/javascriptInterface.cpp b/src/javascriptInterface.cpp index c4dd61b..1a9b470 100644 --- a/src/javascriptInterface.cpp +++ b/src/javascriptInterface.cpp @@ -5,26 +5,23 @@ //------------------------------------------------------------------------------------------------------- javascriptInterface::javascriptInterface(QWebFrame *parent) { + qxtLog->debug() << "Initializing javascript interface..."; //TODO: check for better way to use evaluateJavaScript() _parent = parent; } //------------------------------------------------------------------------------------------------------- javascriptInterface::~javascriptInterface() {} //------------------------------------------------------------------------------------------------------- -QString javascriptInterface::getSysInfo(QString info) -{ +QString javascriptInterface::getSysInfo(QString info){ sysInfo si; - if (debug) qDebug() << "Requested info: " << info << endl; return si.getInfo(info); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::attachToDOM() -{ +void javascriptInterface::attachToDOM(){ _parent->addToJavaScriptWindowObject(QString("fbgui"), this); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::startDownload(QString filename) -{ +void javascriptInterface::startDownload(QString filename){ /* ignore if empty filename */ if (filename.isEmpty()){ _parent->evaluateJavaScript("alert(\"No filename!\")"); @@ -33,33 +30,33 @@ void javascriptInterface::startDownload(QString filename) emit requestFile(filename); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::downloadInfo(QString filename, double filesize) -{ +void javascriptInterface::downloadInfo(QString filename, double filesize){ QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize); _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::updateProgressBar(int percent, double speed, QString unit) -{ +void javascriptInterface::notify(QString msg){ + + QString code = QString("notify('\%1')").arg(msg); + _parent->evaluateJavaScript(code); + return; +} +//------------------------------------------------------------------------------------------------------- +void javascriptInterface::updateProgressBar(int percent, double speed, QString unit){ if (percent == 0) return; QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(speed).arg(unit); - if (debug) qDebug() << "To JS: " << code; _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::setCallbackOnDlQueueFinished(QString jsFunction) -{ +void javascriptInterface::setCallbackOnDlQueueFinished(QString jsFunction){ callBackOnDownloadsFinished = jsFunction; } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::callbackOnDlQueueFinished() -{ +void javascriptInterface::callbackOnDlQueueFinished(){ QString code = QString("\%1").arg(callBackOnDownloadsFinished); _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::quit() -{ - if (debug) qDebug() << "Quit signal."; +void javascriptInterface::quit(){ emit quitFbgui(); } diff --git a/src/javascriptInterface.h b/src/javascriptInterface.h index 457254b..5c6f1cf 100644 --- a/src/javascriptInterface.h +++ b/src/javascriptInterface.h @@ -41,6 +41,7 @@ public slots: void callbackOnDlQueueFinished(); void updateProgressBar(int percent, double speed, QString unit); void downloadInfo(QString filename, double filesize); + void notify(QString msg); QString getSysInfo(QString info); void quit(); }; diff --git a/src/logViewer.cpp b/src/logViewer.cpp deleted file mode 100644 index ac93f39..0000000 --- a/src/logViewer.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -logViewer::logViewer(QWidget *parent) : QTextEdit(parent) { - setWindowFlags(Qt::FramelessWindowHint); - QPalette pal; - pal.setColor(QPalette::Base, Qt::black); - setPalette(pal); - setTextColor(Qt::green); - setPlainText("Debug console initialized."); -} diff --git a/src/logViewer.h b/src/logViewer.h deleted file mode 100644 index b123f05..0000000 --- a/src/logViewer.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -# 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 -# -# -# Simple log viewer. (experimental) -# Requires: Logger engine (to implement) -# -*/ -#ifndef LOGVIEWER_H -#define LOGVIEWER_H - -#include - -class logViewer : public QTextEdit { - - public: - logViewer(QWidget *parent); -}; - -#endif // LOGVIEWER_H diff --git a/src/loggerEngine.cpp b/src/loggerEngine.cpp new file mode 100644 index 0000000..c6c60e4 --- /dev/null +++ b/src/loggerEngine.cpp @@ -0,0 +1,76 @@ +#include "loggerEngine.h" + +loggerEngine_fb::loggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){ + _debugConsole = parent; + _initialized = false; + setLogLevelsEnabled(QxtLogger::DebugLevel); + enableLogging(); +} +loggerEngine_fb::~loggerEngine_fb(){} + +void loggerEngine_fb::initLoggerEngine(){ + _initialized = true; + return; +} + +void loggerEngine_fb::killLoggerEngine(){ + return; +} + +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; +} + +void loggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList & msgs){ + /* TODO: handle different log levels */ + /* write the messages to the debug console */ + if (msgs.isEmpty()) return; + Q_FOREACH(const QVariant& out, msgs) + { + if (!out.isNull()) + _debugConsole->insertPlainText(out.toString()); + } + _debugConsole->insertPlainText(QString("\n")); + /* move to end of the document */ + QTextCursor c = _debugConsole->textCursor(); + c.movePosition(QTextCursor::End); + _debugConsole->setTextCursor(c); +} +//---------------------------------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------------------------------- +loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){ + setLogLevelsEnabled(QxtLogger::DebugLevel); + enableLogging(); +} +loggerEngine_std::~loggerEngine_std(){} +void loggerEngine_std::writeToStdErr(const QString& str_level, const QList &msgs){ + if (msgs.isEmpty()) return; + QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + str_level + "] "; + QTextStream* errstream = stdErrStream(); + Q_ASSERT(errstream); + *errstream << header; + Q_FOREACH(const QVariant& out, msgs) + { + if (!out.isNull()) + *errstream << out.toString(); + } + *errstream << endl; + +} +void loggerEngine_std::writeToStdOut(const QString& level, const QList & msgs){ + if (msgs.isEmpty()) return; + QString header = '[' + QTime::currentTime().toString("hh:mm:ss.zzz") + "] [" + level + "] "; + QTextStream* outstream = stdOutStream(); + Q_ASSERT(outstream); + *outstream << header; + Q_FOREACH(const QVariant& out, msgs){ + if (!out.isNull()){ + *outstream << out.toString(); + } + } + *outstream << endl; +} diff --git a/src/loggerEngine.h b/src/loggerEngine.h new file mode 100644 index 0000000..5c62691 --- /dev/null +++ b/src/loggerEngine.h @@ -0,0 +1,49 @@ +/* +# 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 +# +# +# Custom logger engines based on Qxt library. +# +*/ +#ifndef LOGGERENGINE_H_ +#define LOGGERENGINE_H_ + +#include +#include +#include + +class loggerEngine_fb : public QxtLoggerEngine { + +public: + loggerEngine_fb(QTextEdit* parent); + ~loggerEngine_fb(); + QTextEdit *_debugConsole; + bool _initialized; + + void initLoggerEngine(); + void killLoggerEngine(); + void writeFormatted(QxtLogger::LogLevel level, const QList & messages); + + void setLogLevelEnabled(QxtLogger::LogLevels level, bool enable = true); + bool isInitialized() const; +}; +/*********************************************************************************************/ +class loggerEngine_std : public QxtBasicSTDLoggerEngine { + +public: + loggerEngine_std(); + ~loggerEngine_std(); + 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 689b3e4..ae59d79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,8 +71,9 @@ int main(int argc, char *argv[]) printHelp(); if (clOpts.contains("debug")){ + /* init qxt logger & set debug level */ + qxtLog->enableLogLevels(QxtLogger::DebugLevel); debug = true; - qDebug() << "Debug mode activated."; } /* "search" config file */ QString configFilePath; @@ -88,11 +89,9 @@ int main(int argc, char *argv[]) if (confInfo.exists()) configFilePath = QString("/etc/fbgui.conf"); else - /* temporary */ - configFilePath = QApplication::applicationDirPath() + "/fbgui.conf"; + configFilePath = DEFAULT_CONFIG_PATH; } } - if (debug) qDebug() << "Config file is: " << configFilePath; /* read the config file */ QSettings confFileSettings(configFilePath, QSettings::IniFormat); @@ -100,40 +99,31 @@ int main(int argc, char *argv[]) if (clOpts.contains("url")) { baseURL = QUrl(clOpts.value("url")); - if (debug) qDebug() << "URL loaded from cmdline."; } else if (confFileSettings.contains("default/url")) { baseURL = confFileSettings.value("default/url").toUrl(); - if (debug) qDebug() << "URL loaded from config file."; } else { baseURL = DEFAULT_URL; - if (debug) qDebug() << "URL set by default."; } - if (debug) qDebug() << "Base URL: " << baseURL.toString(); /* setting directory for downloads*/ if (clOpts.contains("downloadDir")){ downloadPath = clOpts.value("downloadDir"); - if (debug) qDebug() << "Download directory loaded from cmdline."; } else if (confFileSettings.contains("default/downloadDirectory")){ downloadPath = confFileSettings.value("default/downloadDirectory").toString(); - if (debug) qDebug() << "Download directory loaded from config file."; } - else - { + else { downloadPath = DEFAULT_DOWNLOAD_DIR; - if (debug) qDebug() << "Download directory set by default."; } - if (debug) qDebug() << "Download directory: " << downloadPath; if (confFileSettings.contains("default/updateInterval")){ updateInterval = confFileSettings.value("default/updateInterval").toInt(); - if (debug) qDebug() << "Read updateInterval from confFile: " << updateInterval; } else updateInterval = DEFAULT_UPDATE_INTERVAL; fbgui gui; + gui.show(); return app.exec(); } diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp index ca20b95..a261fe5 100644 --- a/src/sysInfo.cpp +++ b/src/sysInfo.cpp @@ -8,14 +8,12 @@ // ------------------------------------------------------------------------------------------------ sysInfo::sysInfo(){ - if (debug) qDebug() << "sysInfo created."; - // Maybe search for eth0, etc } // ------------------------------------------------------------------------------------------------ sysInfo::~sysInfo(){} // ------------------------------------------------------------------------------------------------ QString sysInfo::getInfo(QString& infoName){ - if (debug) qDebug() << "sysInfo : getInfo(" << infoName << ")"; + qxtLog->debug() << "[sysInfo] requested " << infoName; if (infoName == QString("mac")) return getMACAddress(); else if (infoName == QString("ip")) @@ -32,7 +30,7 @@ QString sysInfo::getMACAddress(){ /* Returns MAC address of eth0 for now. */ QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); if (!qni.isValid()){ - if (debug) qDebug() << "No interface matching \"eth0\" found."; + qxtLog->debug() << "No interface matching \"eth0\" found."; return "no_eth0"; } //eth0_index = qni.index(); @@ -47,12 +45,11 @@ QString sysInfo::getIPAddress(){ // This is does not return the right IP atm... foreach(QHostAddress addr, addrlist){ if (addr.protocol() == QAbstractSocket::IPv4Protocol && addr != QHostAddress::LocalHost){ - if (debug) qDebug() << "eth0: IPv4 Address: " << addr.toString(); return addr.toString(); } } // still here? - if (debug) qDebug() << "ip_error"; + qxtLog->debug() << "ip_error"; return "ip_error"; } // ------------------------------------------------------------------------------------------------ @@ -72,7 +69,7 @@ QByteArray sysInfo::getNames(){ QJson::Serializer serializer; QByteArray json = serializer.serialize(jsonV); - if (debug) qDebug() << json; + qxtLog->debug() << json; return json; } @@ -87,7 +84,7 @@ QString sysInfo::getAllInfos(){ //QJson::Serializer serializer; QByteArray json = serializer.serialize(infos); - if (debug) qDebug() << json; + qxtLog->debug() << json; return json; } // ------------------------------------------------------------------------------------------------ diff --git a/src/sysInfo.h b/src/sysInfo.h index 3a6c217..49a37b8 100644 --- a/src/sysInfo.h +++ b/src/sysInfo.h @@ -20,8 +20,6 @@ #include "fbgui.h" #include -#include -#include class sysInfo { public: diff --git a/src/testApp.sh b/src/testApp.sh index 444636b..890122d 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -11,7 +11,7 @@ script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" working_path=`dirname "$script_path"` display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}') # Start QT's virtual framebuffer with proper displayID -/usr/local/Trolltech/Qt-4.7.1/bin/qvfb -width 800 -height 600 -qwsdisplay :$display_id & +/usr/local/Trolltech/Qt-4.7.2/bin/qvfb -width 800 -height 600 -qwsdisplay :$display_id & sleep 0.1 # Start fbgui. $working_path/fbgui -display QVFb:$display_id $@ -- cgit v1.2.3-55-g7522