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) --- src/main.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/main.cpp') 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(); } -- cgit v1.2.3-55-g7522 From 7b39c4944dd9c6fa0778305e1cbd7286ce6571b5 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Sun, 20 Mar 2011 23:36:34 +0100 Subject: debug modes. -D now needs an arg: 0 for regular terminal output, 1 for debug console widget (to use on clients). new action ctrl + x kills app --- src/fbgui.cpp | 40 ++++++++++++++++++++++++++++------------ src/fbgui.h | 10 ++++++++-- src/loggerEngine.cpp | 9 ++++----- src/main.cpp | 18 +++++++++--------- src/sysInfo.cpp | 7 +------ 5 files changed, 50 insertions(+), 34 deletions(-) (limited to 'src/main.cpp') diff --git a/src/fbgui.cpp b/src/fbgui.cpp index f642da2..b4c55aa 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -11,26 +11,32 @@ QUrl baseURL(DEFAULT_URL); QString binPath(""); QString downloadPath("/tmp/fbgui/downloads"); int updateInterval = DEFAULT_UPDATE_INTERVAL; -bool debug = false; - +int debugMode = -1; //------------------------------------------------------------------------------------------- fbgui::fbgui(){ - /* setup qxt logger and enable custom std engine*/ + + /* setup basic debug */ qxtLog->disableLoggerEngine("DEFAULT"); - qxtLog->addLoggerEngine("std_logger", new loggerEngine_std); - qxtLog->initLoggerEngine("std_logger"); - qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); - qxtLog->debug() << "Initializing fbgui..."; + qxtLog->enableLogLevels(QxtLogger::DebugLevel); + if (debugMode == 0){ + qxtLog->addLoggerEngine("std_logger", new loggerEngine_std); + qxtLog->initLoggerEngine("std_logger"); + qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); + qxtLog->debug() << "Initializing fbgui..."; + } - /* initliaze browser */ + /* base of the gui */ + createActions(); checkHost(); _webView = new QWebView(this); _webView->load(baseURL); - /* debug split if debug mode, normal browser else */ - if (debug) setupDebugSplit(); - else setCentralWidget(_webView); + /* debug console split or normal browser */ + if (debugMode == 1) + setupDebugSplit(); + else + setCentralWidget(_webView); /* initialize javascript interface */ javascriptInterface* jsi = new javascriptInterface(_webView->page()->mainFrame()); @@ -49,12 +55,22 @@ fbgui::fbgui(){ jsi, SLOT(updateProgressBar(int, double, QString))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished())); + /* set properties */ setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); } //------------------------------------------------------------------------------------------- +void fbgui::createActions(){ + /* CTRL + X to kill the gui */ + _quit = new QAction(tr("&quit"), this); + _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); + this->addAction(_quit); + connect(_quit, SIGNAL(triggered()), this, SLOT(close())); + +} +//------------------------------------------------------------------------------------------- void fbgui::setupDebugSplit(){ _debugConsole = new QTextEdit(this); _debugConsole->setWindowFlags(Qt::FramelessWindowHint); @@ -63,7 +79,7 @@ void fbgui::setupDebugSplit(){ _debugConsole->setPalette(pal); _debugConsole->setTextColor(Qt::cyan); _debugConsole->insertPlainText("Debug console initialized.\n"); - /* switch engine to custom engine class "logger" */ + /* enable custom logger engine */ qxtLog->addLoggerEngine("fb_logger", new loggerEngine_fb(_debugConsole)); qxtLog->initLoggerEngine("fb_logger"); qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); diff --git a/src/fbgui.h b/src/fbgui.h index f310127..ca5420d 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -29,10 +29,12 @@ #define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" #define DEFAULT_UPDATE_INTERVAL 1; + +/* global settings */ extern QString binPath; extern QString downloadPath; extern QUrl baseURL; -extern bool debug; +extern int debugMode; extern int updateInterval; class fbgui : public QMainWindow @@ -43,14 +45,18 @@ public: fbgui(); private: + /* setup procedures */ void setupDebugSplit(); void createActions(); void checkHost() const; - QSplitter* _splitter; + /* widgets constituing the gui */ QWebView* _webView; + QSplitter* _splitter; QTextEdit* _debugConsole; + /* action list */ + QAction* _quit; QAction* _toggleDebug; private slots: diff --git a/src/loggerEngine.cpp b/src/loggerEngine.cpp index e8c0184..004c268 100644 --- a/src/loggerEngine.cpp +++ b/src/loggerEngine.cpp @@ -50,18 +50,17 @@ loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){} 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 + "] "; + 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){ if (msgs.isEmpty()) return; diff --git a/src/main.cpp b/src/main.cpp index ae59d79..f415206 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,13 +35,13 @@ int main(int argc, char *argv[]) /* parse command line arguments */ QMap clOpts; int longIndex = 0; - static const char *optString = "u:d:c:Dh"; + static const char *optString = "u:d:c:D:h"; static const struct option longOpts[] = { {"url", required_argument, NULL, 'u'}, {"download", required_argument, NULL, 'd'}, {"config", required_argument, NULL, 'c'}, - {"debug", no_argument, NULL, 'D'}, + {"debug", required_argument, NULL, 'D'}, {"help", no_argument, NULL, 'h'} }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) case 'c': clOpts.insert("configFile", optarg); case 'D': - clOpts.insert("debug", "debug"); + clOpts.insert("debug", optarg); break; case 'h': clOpts.insert("help", "help"); @@ -70,12 +70,12 @@ int main(int argc, char *argv[]) if (clOpts.contains("help")) printHelp(); - if (clOpts.contains("debug")){ - /* init qxt logger & set debug level */ - qxtLog->enableLogLevels(QxtLogger::DebugLevel); - debug = true; - } - /* "search" config file */ + if (clOpts.contains("debug")) + debugMode = clOpts.value("debug").toInt(); + else + debugMode = -1; + + /* look for config file */ QString configFilePath; QFileInfo confInfo; if (clOpts.contains("configFile")) diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp index a261fe5..81e39f8 100644 --- a/src/sysInfo.cpp +++ b/src/sysInfo.cpp @@ -1,10 +1,5 @@ #include "sysInfo.h" -#include -#include -#include -#include -#include -#include + // ------------------------------------------------------------------------------------------------ sysInfo::sysInfo(){ -- cgit v1.2.3-55-g7522 From 635b5c64f3107d4c01ae314fb75e02c571b51c54 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 21 Mar 2011 10:51:51 +0100 Subject: transformed c syntax comments to c++ convention... --- src/downloadManager.cpp | 46 ++++++++++++++++++++++----------------------- src/downloadManager.h | 25 ++++++++++++++++-------- src/fbgui.cpp | 44 +++++++++++++++++++++++-------------------- src/fbgui.h | 11 ++++++----- src/javascriptInterface.cpp | 14 ++++++-------- src/javascriptInterface.h | 13 +++++++------ src/loggerEngine.cpp | 30 ++++++++++------------------- src/loggerEngine.h | 14 ++++++++++---- src/main.cpp | 9 ++++----- src/sysInfo.cpp | 4 ++-- src/sysInfo.h | 10 +++++----- src/testApp.sh | 2 +- 12 files changed, 115 insertions(+), 107 deletions(-) (limited to 'src/main.cpp') diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp index 4602c9d..9b4c162 100644 --- a/src/downloadManager.cpp +++ b/src/downloadManager.cpp @@ -3,16 +3,16 @@ int downloadManager::downloaded = 0; // ---------------------------------------------------------------------------------------- -downloadManager::downloadManager() -{ +downloadManager::downloadManager(){ qxtLog->debug() << "Initializing download manager..."; checkDownloadDirectory(); qnam = new QNetworkAccessManager(); dip = false; } // ---------------------------------------------------------------------------------------- -void downloadManager::checkDownloadDirectory(){ - /* check if downloadPath exists, if not create it. */ +void downloadManager::checkDownloadDirectory() +{ + // check if downloadPath exists, if not create it. downloadDir = QDir(downloadPath); if (!downloadDir.exists()){ qxtLog->debug() << "Download directory: " << downloadDir.path() << " doesn't exist."; @@ -22,13 +22,12 @@ void downloadManager::checkDownloadDirectory(){ } else { qxtLog->debug() << "Failed to create directory: " << downloadDir.path(); - emit notify(QString("Failed to create download directory!")); - /* try to save to /tmp/fbgui */ + // try to save to /tmp/fbgui downloadDir.setPath(QDir::tempPath () + "/fbgui"); if (!downloadDir.exists()){ QDir::current().mkdir(QDir::tempPath () + "/fbgui"); if (!downloadDir.exists()){ - /* TODO: dont exit, this shouldn't happen anyway (right?) */ + // TODO: dont exit, this shouldn't happen anyway (right?) qxtLog->debug() << "Fatal, no target for downloads. Exiting..."; exit(EXIT_FAILURE); } @@ -56,14 +55,14 @@ void downloadManager::processDownloadRequest(QUrl& url) qxtLog->debug() << "No URL specified for download."; return; } - /* if download in progress, enqueue file and return. */ + // if download in progress, enqueue file and return. if (dip){ dlQ.enqueue(url); qxtLog->debug() << "Download in progress! Queued:" << url.toString() << "(" << dlQ.size() << " in queue)"; return; } - /* no running downloads: enqueue and start next download. */ + // no running downloads: enqueue and start next download. dlQ.enqueue(url); qxtLog->debug() << "Enqueueing:" << url.toString(); startNextDownload(); @@ -79,14 +78,14 @@ void downloadManager::startNextDownload() qxtLog->debug() << "Starting next download: " << dlQ.head().toString() << " (" << dlQ.size() - 1 << " in queue.)"; - /* dequeue next URL to download. */ + // dequeue next URL to download. QUrl url = dlQ.dequeue(); - /* get filename from URL. */ + // get filename from URL. QString tmp = url.path(); tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); - /* check if filename exists on target file system */ + // check if filename exists on target file system if (downloadDir.exists(tmp)){ qxtLog->debug() << "File already exists: " << downloadDir.absoluteFilePath(tmp); outfile.setFileName(QString(downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(downloaded)); @@ -95,13 +94,13 @@ void downloadManager::startNextDownload() outfile.setFileName(downloadDir.absoluteFilePath(tmp)); qxtLog->debug() << "Saving to: " << outfile.fileName(); - /* try to open for writing */ + // try to open for writing if (!outfile.open(QIODevice::WriteOnly)){ qxtLog->debug() << "No write access to " << outfile.fileName() << " . Skipping download..."; return; } - /* send the request for the file */ + // send the request for the file QNetworkRequest request(url); currentDownload = qnam->get(request); lastProgress = 0; @@ -117,8 +116,9 @@ void downloadManager::startNextDownload() // ---------------------------------------------------------------------------------------- // Private slots to process downloads // ---------------------------------------------------------------------------------------- -void downloadManager::processMetaInfo(){ - /* fetch filesize from header & filename from url (for now) */ +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); @@ -127,14 +127,14 @@ void downloadManager::processMetaInfo(){ // ---------------------------------------------------------------------------------------- void downloadManager::downloadReady() { - /* data ready, save it */ + // data ready, save it outfile.write(currentDownload->readAll()); } // ---------------------------------------------------------------------------------------- void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { if (bytesIn > bytesTotal) return; - /* calculate current speed */ + // calculate current speed double speed = bytesIn * 1000 / dltime.elapsed(); QString unit; if (speed < 1024) { @@ -148,7 +148,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) speed /= 1024*1024; unit = "MB/s"; } - /* update progress only if difference higher than the updateInterval setting */ + // update progress only if difference higher than the updateInterval setting currentProgress = ((bytesIn * 100) / bytesTotal); if (currentProgress - lastProgress >= updateInterval){ lastProgress = currentProgress; @@ -161,7 +161,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) // ---------------------------------------------------------------------------------------- void downloadManager::downloadFinished() { - /* check for errors */ + // check for errors if (currentDownload->error()){ currentDownload->deleteLater(); outfile.remove(); @@ -171,7 +171,7 @@ void downloadManager::downloadFinished() emit notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode)); } else{ - /* end download */ + // end download currentDownload->deleteLater(); outfile.close(); downloaded++; @@ -180,7 +180,7 @@ void downloadManager::downloadFinished() emit notify(QString("Successfully downloaded %1").arg(currentDownload->url().toString())); } dip = false; - /* process next in queue */ + // process next in queue if (dlQ.isEmpty()){ emit downloadQueueEmpty(); qxtLog->debug() << "Download manager ready. (2)"; @@ -188,7 +188,7 @@ void downloadManager::downloadFinished() } startNextDownload(); } -/* ---------------------------------------------------------------------------------------- +/******************************************************************************************************** * ** dead code: Header filename fetching & renaming ** diff --git a/src/downloadManager.h b/src/downloadManager.h index afd0da3..8e11313 100644 --- a/src/downloadManager.h +++ b/src/downloadManager.h @@ -35,36 +35,45 @@ public: downloadManager(); private: + // checks for valid download directory, ran once in constructor void checkDownloadDirectory(); + // private control function for queueing mechanism. void processDownloadRequest(QUrl& url); + + // base objects for downloading QNetworkAccessManager* qnam; QQueue dlQ; QNetworkReply* currentDownload; QFile outfile; QDir downloadDir; - QString currentTargetFilename; + // download progress variables QTime dltime; int currentProgress, lastProgress; - + // download in progress flag bool dip; + // static counter static int downloaded; - signals: - void finished(); - void downloadInfo(QString filename, double filesize); - void notify(QString msg); - void updateProgress(int percent, double speed, QString unit); + // notify sends a message to the javascript interface. + 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(QUrl& fileUrl); void downloadFile(QString& fileUrl); private slots: + // private slots to manage the downloading process void startNextDownload(); - void downloadReady(); void processMetaInfo(); + void downloadReady(); void downloadProgress(qint64 bytesIn, qint64 bytesTotal); void downloadFinished(); }; diff --git a/src/fbgui.cpp b/src/fbgui.cpp index b4c55aa..e43d36e 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -14,9 +14,9 @@ int updateInterval = DEFAULT_UPDATE_INTERVAL; int debugMode = -1; //------------------------------------------------------------------------------------------- -fbgui::fbgui(){ - - /* setup basic debug */ +fbgui::fbgui() +{ + // setup basic debug qxtLog->disableLoggerEngine("DEFAULT"); qxtLog->enableLogLevels(QxtLogger::DebugLevel); if (debugMode == 0){ @@ -26,44 +26,45 @@ fbgui::fbgui(){ qxtLog->debug() << "Initializing fbgui..."; } - /* base of the gui */ + // base of the gui createActions(); checkHost(); _webView = new QWebView(this); _webView->load(baseURL); - /* debug console split or normal browser */ + // debug console split or normal browser if (debugMode == 1) setupDebugSplit(); else setCentralWidget(_webView); - /* initialize javascript interface */ + // initialize javascript interface javascriptInterface* jsi = new javascriptInterface(_webView->page()->mainFrame()); QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM())); - /* initialize download manager */ + // initialize download manager downloadManager* dm = new downloadManager(); - QObject::connect(dm, SIGNAL(downloadInfo(QString, double)), - jsi, SLOT(downloadInfo(QString, double))); + QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), + jsi, SLOT(downloadInfo(const QString&, const 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(updateProgress(const int&, const double&, const QString&)), + jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished())); - /* set properties */ + // set properties setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); } //------------------------------------------------------------------------------------------- -void fbgui::createActions(){ - /* CTRL + X to kill the gui */ +void fbgui::createActions() +{ + // CTRL + X to kill the gui _quit = new QAction(tr("&quit"), this); _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); this->addAction(_quit); @@ -71,7 +72,8 @@ void fbgui::createActions(){ } //------------------------------------------------------------------------------------------- -void fbgui::setupDebugSplit(){ +void fbgui::setupDebugSplit() +{ _debugConsole = new QTextEdit(this); _debugConsole->setWindowFlags(Qt::FramelessWindowHint); QPalette pal; @@ -79,15 +81,15 @@ void fbgui::setupDebugSplit(){ _debugConsole->setPalette(pal); _debugConsole->setTextColor(Qt::cyan); _debugConsole->insertPlainText("Debug console initialized.\n"); - /* enable custom logger engine */ + // enable custom logger engine 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 */ + // display browser and debug in a splitter _splitter = new QSplitter(Qt::Vertical, this); _splitter->addWidget(_webView); _splitter->addWidget(_debugConsole); - /* CTRL + D toggles debug window */ + // CTRL + D toggles debug window _toggleDebug = new QAction(tr("&toggleDebug"), this); _toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); addAction(_toggleDebug); @@ -95,14 +97,16 @@ void fbgui::setupDebugSplit(){ setCentralWidget(_splitter); } //------------------------------------------------------------------------------------------- -void fbgui::toggleDebug(){ +void fbgui::toggleDebug() +{ if (_debugConsole->isVisible()) _debugConsole->hide(); else _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){ diff --git a/src/fbgui.h b/src/fbgui.h index ca5420d..2d06afe 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -23,14 +23,14 @@ #include -/* Internal default settings */ +// 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; -/* global settings */ +// Global settings extern QString binPath; extern QString downloadPath; extern QUrl baseURL; @@ -45,21 +45,22 @@ public: fbgui(); private: - /* setup procedures */ + // setup procedures void setupDebugSplit(); void createActions(); void checkHost() const; - /* widgets constituing the gui */ + // widgets constituing the gui QWebView* _webView; QSplitter* _splitter; QTextEdit* _debugConsole; - /* action list */ + // action list QAction* _quit; QAction* _toggleDebug; private slots: + // slots for processing actions void toggleDebug(); }; diff --git a/src/javascriptInterface.cpp b/src/javascriptInterface.cpp index 1a9b470..c70347c 100644 --- a/src/javascriptInterface.cpp +++ b/src/javascriptInterface.cpp @@ -3,8 +3,7 @@ #include "sysInfo.h" //------------------------------------------------------------------------------------------------------- -javascriptInterface::javascriptInterface(QWebFrame *parent) -{ +javascriptInterface::javascriptInterface(QWebFrame *parent){ qxtLog->debug() << "Initializing javascript interface..."; //TODO: check for better way to use evaluateJavaScript() _parent = parent; @@ -12,7 +11,7 @@ javascriptInterface::javascriptInterface(QWebFrame *parent) //------------------------------------------------------------------------------------------------------- javascriptInterface::~javascriptInterface() {} //------------------------------------------------------------------------------------------------------- -QString javascriptInterface::getSysInfo(QString info){ +QString javascriptInterface::getSysInfo(const QString& info){ sysInfo si; return si.getInfo(info); } @@ -22,7 +21,7 @@ void javascriptInterface::attachToDOM(){ } //------------------------------------------------------------------------------------------------------- void javascriptInterface::startDownload(QString filename){ - /* ignore if empty filename */ + // ignore if empty filename if (filename.isEmpty()){ _parent->evaluateJavaScript("alert(\"No filename!\")"); return; @@ -30,19 +29,18 @@ void javascriptInterface::startDownload(QString filename){ emit requestFile(filename); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::downloadInfo(QString filename, double filesize){ +void javascriptInterface::downloadInfo(const QString& filename, const double& filesize){ QString code = QString("downloadInfo('\%1', \%2)").arg(filename).arg(filesize); _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::notify(QString msg){ +void javascriptInterface::notify(const QString& msg){ QString code = QString("notify('\%1')").arg(msg); _parent->evaluateJavaScript(code); - return; } //------------------------------------------------------------------------------------------------------- -void javascriptInterface::updateProgressBar(int percent, double speed, QString unit){ +void javascriptInterface::updateProgressBar(const int& percent, const double& speed, const QString& unit){ if (percent == 0) return; QString code = QString("updateProgress(\%1, \%2, '\%3')").arg(percent).arg(speed).arg(unit); _parent->evaluateJavaScript(code); diff --git a/src/javascriptInterface.h b/src/javascriptInterface.h index 5c6f1cf..a139780 100644 --- a/src/javascriptInterface.h +++ b/src/javascriptInterface.h @@ -20,7 +20,8 @@ #include "fbgui.h" -class javascriptInterface : public QObject{ +class javascriptInterface : public QObject +{ Q_OBJECT private: QWebFrame* _parent; @@ -39,11 +40,11 @@ public slots: void startDownload(QString filename); void setCallbackOnDlQueueFinished(QString fctOnDownloadsFinished); 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 updateProgressBar(const int& percent, const double& speed, const QString& unit); + void downloadInfo(const QString& filename, const double& filesize); + void notify(const QString& msg); + QString getSysInfo(const QString& info); void quit(); }; -#endif /* JAVASCRIPTINTERFACE_H_ */ +#endif // JAVASCRIPTINTERFACE_H_ diff --git a/src/loggerEngine.cpp b/src/loggerEngine.cpp index 004c268..9121af5 100644 --- a/src/loggerEngine.cpp +++ b/src/loggerEngine.cpp @@ -1,8 +1,8 @@ #include "loggerEngine.h" -/***************************************************************************************************** - Custom Logger Engine for debugging on framebuffer -*****************************************************************************************************/ +// -------------------------------------------------------------------------------------------------- +// Custom Logger Engine for debugging on framebuffer +//--------------------------------------------------------------------------------------------------- loggerEngine_fb::loggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){ // TODO: silly parent storing ... to change! _debugConsole = parent; @@ -28,8 +28,7 @@ bool loggerEngine_fb::isInitialized() const{ } void loggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList & msgs){ - /* TODO: handle different log levels */ - /* write the messages to the debug console */ + // TODO: handle different log levels if (msgs.isEmpty()) return; Q_FOREACH(const QVariant& out, msgs) { @@ -37,14 +36,14 @@ void loggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QListinsertPlainText(out.toString()); } _debugConsole->insertPlainText(QString("\n")); - /* move to end of the document */ + // autoscroll QTextCursor c = _debugConsole->textCursor(); c.movePosition(QTextCursor::End); _debugConsole->setTextCursor(c); } -/***************************************************************************************************** - Modified QxtBasicSTDLoggerEngine -*****************************************************************************************************/ +//--------------------------------------------------------------------------------------------------- +// Modified QxtBasicSTDLoggerEngine +//--------------------------------------------------------------------------------------------------- loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){} loggerEngine_std::~loggerEngine_std(){} @@ -63,15 +62,6 @@ void loggerEngine_std::writeToStdErr(const QString& str_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; + // 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 7b75112..be1ac87 100644 --- a/src/loggerEngine.h +++ b/src/loggerEngine.h @@ -20,7 +20,9 @@ #include #include #include - +//--------------------------------------------------------------------------------------------------- +// custom engine feeding the debug console widget +//--------------------------------------------------------------------------------------------------- class loggerEngine_fb : public QxtLoggerEngine { public: loggerEngine_fb(QTextEdit* parent); @@ -28,20 +30,24 @@ public: QTextEdit *_debugConsole; bool _initialized; + // 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; + }; -/*********************************************************************************************/ +//--------------------------------------------------------------------------------------------------- +// minor changes to QxtBasicSTDLoggerEngine +//--------------------------------------------------------------------------------------------------- class loggerEngine_std : public QxtBasicSTDLoggerEngine { public: 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); }; -#endif /* LOGGERENGINE_H_ */ +#endif // LOGGERENGINE_H_ diff --git a/src/main.cpp b/src/main.cpp index f415206..c5269a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,14 +25,13 @@ int main(int argc, char *argv[]) QApplication app(argc, argv, QApplication::GuiServer); app.setOrganizationName("team_projekt_2011"); app.setApplicationName("prebootGUI"); - app.setObjectName("test"); binPath = QApplication::applicationDirPath(); QTranslator translator; translator.load(":" + QLocale::system().name()); app.installTranslator(&translator); - /* parse command line arguments */ + // parse command line arguments QMap clOpts; int longIndex = 0; static const char *optString = "u:d:c:D:h"; @@ -75,7 +74,7 @@ int main(int argc, char *argv[]) else debugMode = -1; - /* look for config file */ + // look for config file QString configFilePath; QFileInfo confInfo; if (clOpts.contains("configFile")) @@ -93,7 +92,7 @@ int main(int argc, char *argv[]) } } - /* read the config file */ + // read the config file QSettings confFileSettings(configFilePath, QSettings::IniFormat); confFileSettings.setIniCodec("UTF-8"); @@ -107,7 +106,7 @@ int main(int argc, char *argv[]) baseURL = DEFAULT_URL; } - /* setting directory for downloads*/ + // setting directory for downloads if (clOpts.contains("downloadDir")){ downloadPath = clOpts.value("downloadDir"); } diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp index 81e39f8..ff114e8 100644 --- a/src/sysInfo.cpp +++ b/src/sysInfo.cpp @@ -7,7 +7,7 @@ sysInfo::sysInfo(){ // ------------------------------------------------------------------------------------------------ sysInfo::~sysInfo(){} // ------------------------------------------------------------------------------------------------ -QString sysInfo::getInfo(QString& infoName){ +QString sysInfo::getInfo(const QString& infoName){ qxtLog->debug() << "[sysInfo] requested " << infoName; if (infoName == QString("mac")) return getMACAddress(); @@ -22,7 +22,7 @@ QString sysInfo::getInfo(QString& infoName){ } // ------------------------------------------------------------------------------------------------ QString sysInfo::getMACAddress(){ - /* Returns MAC address of eth0 for now. */ + // Returns MAC address of eth0 for now QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); if (!qni.isValid()){ qxtLog->debug() << "No interface matching \"eth0\" found."; diff --git a/src/sysInfo.h b/src/sysInfo.h index 49a37b8..4e6988e 100644 --- a/src/sysInfo.h +++ b/src/sysInfo.h @@ -22,15 +22,15 @@ #include class sysInfo { - public: - sysInfo(); +public: + sysInfo(); ~sysInfo(); - QString getInfo(QString& infoName); + // public access. infoName + QString getInfo(const QString& infoName); - private: +private: QJson::Serializer serializer; - QByteArray getNames(); QString getMACAddress(); QString getIPAddress(); diff --git a/src/testApp.sh b/src/testApp.sh index 890122d..61f7c2d 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.2/bin/qvfb -width 800 -height 600 -qwsdisplay :$display_id & +/usr/local/Trolltech/Qt-4.7.1/bin/qvfb -width 1024 -height 768 -qwsdisplay :$display_id & sleep 0.1 # Start fbgui. $working_path/fbgui -display QVFb:$display_id $@ -- cgit v1.2.3-55-g7522