diff options
Diffstat (limited to 'src/fbgui.cpp')
| -rw-r--r-- | src/fbgui.cpp | 127 |
1 files changed, 84 insertions, 43 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 3408b1e..e21bdc6 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -1,22 +1,19 @@ #include "fbgui.h" #include "downloadManager.h" #include "javascriptInterface.h" -//#include "ipWatcher.h" +#include "loggerengine.h" +#include "downloadmanager.h" +#include "javascriptinterface.h" #include <iostream> -#include <QUrl> -#include <QDir> -#include <QHostInfo> #include <QtWebKit> -#include <QPlainTextEdit> +#include <QxtCore> -// Note: Absolute paths. binPath empty init, set in main() after QApplication instanciated. -QString binPath(""); -QString downloadPath(binPath + "/downloads"); QUrl baseURL(DEFAULT_URL); -bool debug = false; +QString binPath(""); +QString downloadPath("/tmp/fbgui/downloads"); int updateInterval = DEFAULT_UPDATE_INTERVAL; -logViewer *logView; +int debugMode = -1; //------------------------------------------------------------------------------------------- fbgui::fbgui() @@ -31,58 +28,102 @@ fbgui::fbgui() checkHost(); webView = new QWebView(this); + webView->load(baseURL); - /*show info page until the client has received an IP address*/ - /* - ipWatcher* ipw = new ipWatcher(QApplication::applicationDirPath()); - while(!ipw->ipReceived()){ - webView->load(QUrl("prc://html/loadAbout.html")); + // setup basic debug + qxtLog->disableLoggerEngine("DEFAULT"); + 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..."; } - */ - webView->load(baseURL); - /* initialize javascript interface */ - javascriptInterface* jsi = new javascriptInterface(webView->page()->mainFrame()); - QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); + // base of the gui + createActions(); + checkHost(); + _webView = new QWebView(this); + _webView->load(baseURL); + + // debug console split or normal browser + if (debugMode == 1) + setupDebugSplit(); + else + setCentralWidget(_webView); - QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), + // 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 */ - downloadManager* dm = new downloadManager(); - 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))); + + // 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(callbackOnDlQueueFinished())); + // set properties setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); - resize(QSize(800, 600)); - setCentralWidget(webView); showFullScreen(); - show(); } //------------------------------------------------------------------------------------------- -void fbgui::keyPressEvent(QKeyEvent *event){ - /* F4 toggles debug console */ - if (debug && event->key() == Qt::Key_F4){ - if (!logView->isVisible()){ - logView->append(QString("check passed.")); - logView->raise(); - logView->setVisible(true); - } - else { - logView->lower(); - logView->setVisible(false); - } - } +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); + QPalette pal; + pal.setColor(QPalette::Base, Qt::black); + _debugConsole->setPalette(pal); + _debugConsole->setTextColor(Qt::cyan); + _debugConsole->insertPlainText("Debug console initialized.\n"); + // 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 + _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 (_debugConsole->isVisible()) + _debugConsole->hide(); + else + _debugConsole->show(); } //------------------------------------------------------------------------------------------- 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); } } |
