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') 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