#include "fbgui.h" #include "downloadManager.h" #include "javascriptInterface.h" #include #include #include #include #include #include // 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; int updateInterval = DEFAULT_UPDATE_INTERVAL; //------------------------------------------------------------------------------------------- fbgui::fbgui() { /* debug console test */ if (debug){ logView = new logViewer(this); } /* logView = new QTextEdit(this); logView->resize(QSize(640, 480)); QPalette qp; qp.setColor(QPalette::Base, Qt::black); logView->setPalette(qp); logView->setTextColor(Qt::green); logView->setVisible(false); logView->setPlainText("empty console."); */ /* initialize "browser" */ checkHost(); webView = new QWebView(this); webView->load(baseURL); /* 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))); 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::keyPressEvent(QKeyEvent *event){ /* test */ if (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::checkHost() const { QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); if (hostInfo.error() != QHostInfo::NoError){ qDebug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; exit(EXIT_FAILURE); } }