diff options
-rw-r--r-- | src/fbgui/fbgui.cpp | 53 | ||||
-rw-r--r-- | src/fbgui/fbgui.h | 5 | ||||
-rwxr-xr-x | testApp.sh | 1 |
3 files changed, 44 insertions, 15 deletions
diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index 683538b..759c747 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -54,6 +54,8 @@ void fbgui::init() { // start fbgui LOG4CXX_DEBUG(coreLogger, "Initializing fbgui..."); + _watcher = new QFileSystemWatcher(this); + setupLayout(); createActions(); @@ -173,8 +175,9 @@ void fbgui::watchForTrigger() { } // watch the path to trigger file LOG4CXX_DEBUG(coreLogger, "[watcher] Watching " << fileToTriggerURL); - _watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this); -QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad())); + _watcher->addPath(fileToTriggerURL); + //_watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL, logFilePath), this); +QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad(const QString&))); } //------------------------------------------------------------------------------------------- @@ -188,14 +191,16 @@ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepa * @see fbgui::checkHost() * @see fbgui::loadURL() */ -void fbgui::prepareURLLoad() { - LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " changed!"); - // disconnect _watcher, his job is done - LOG4CXX_DEBUG(coreLogger, "[watcher] disconnected."); - _watcher->disconnect(this); - _watcher->deleteLater(); - // try to load URL - loadURL(); +void fbgui::prepareURLLoad(const QString& fileName) { + if (fileName == fileToTriggerURL) { + LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " changed!"); + // disconnect _watcher, his job is done + LOG4CXX_DEBUG(coreLogger, "[watcher] disconnected."); + _watcher->disconnect(this); + _watcher->deleteLater(); + // try to load URL + loadURL(); + } } //------------------------------------------------------------------------------------------- // Preparations for URL load @@ -471,16 +476,36 @@ void fbgui::createDebugConsole() { pal.setColor(QPalette::Base, Qt::black); _debugConsole->setPalette(pal); _debugConsole->setTextColor(Qt::white); - // enable custom coreLogger engine -// qxtLog->addLoggerEngine("fb_coreLogger", new LoggerEngine_fb(_debugConsole)); - //qxtLog->initLoggerEngine("fb_coreLogger"); -// qxtLog->setMinimumLevel("fb_coreLogger", QxtLogger::DebugLevel); // CTRL + D toggles debug window _toggleDebugConsole = new QAction(tr("&toggleDebug"), this); _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); addAction(_toggleDebugConsole); connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole())); + + // read from log file + _logFile = new QFile(logFilePath); + _logFileIn = new QTextStream(_logFile); + + if (!_logFile->open(QFile::ReadOnly | QFile::Text)) { + //do error + } + _debugConsole->setPlainText(_logFileIn->readAll()); + _debugConsole->moveCursor(QTextCursor::End); + LOG4CXX_DEBUG(coreLogger, "Log file opened."); + // watch log file + _watcher->addPath(logFilePath); + QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(refreshDebugConsole(const QString&))); + +} +//------------------------------------------------------------------------------------------- +void fbgui::refreshDebugConsole(const QString& fileName) { + if (fileName == logFilePath) { + while (!_logFileIn->atEnd()) { + _debugConsole->append(_logFileIn->readLine()); + } + _debugConsole->moveCursor(QTextCursor::End); + } } //------------------------------------------------------------------------------------------- /** diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h index c6d5a01..4891194 100644 --- a/src/fbgui/fbgui.h +++ b/src/fbgui/fbgui.h @@ -101,14 +101,17 @@ private: // watcher to detect changes in the observed directory. QFileSystemWatcher* _watcher; + QFile* _logFile; + QTextStream* _logFileIn; private slots: // toggles debug console when action _toggleDebugConsole happens. void toggleDebugConsole(); + void refreshDebugConsole(const QString&); // This function is triggered by fileChanged Signal of _watcher. // It deletes _watcher, since we don't need it anymore and tries to load URL. - void prepareURLLoad(); + void prepareURLLoad(const QString&); void loadURLDone(bool success); // shut off the system @@ -29,6 +29,7 @@ done # clean /tmp/fbgui [ -d /tmp/fbgui ] && rm -rf /tmp/fbgui +[ -f /tmp/fbgui.log ] && rm /tmp/fbgui.log [ -f /tmp/fbgui_trigger ] && rm /tmp/fbgui_trigger # path to script (including script name) |