diff options
-rw-r--r-- | src/DownloadManager.cpp | 26 | ||||
-rw-r--r-- | src/DownloadManager.h | 1 | ||||
-rw-r--r-- | src/JSObject.cpp | 69 | ||||
-rw-r--r-- | src/JSObject.h | 61 | ||||
-rw-r--r-- | src/fbbrowser.cpp | 90 | ||||
-rw-r--r-- | src/fbbrowser.h | 36 | ||||
-rw-r--r-- | src/fbgui.cpp | 32 | ||||
-rw-r--r-- | src/fbgui.h | 8 | ||||
-rw-r--r-- | src/fbgui.pro | 4 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rwxr-xr-x | src/testApp.sh | 2 |
11 files changed, 61 insertions, 272 deletions
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index 600fed6..61b63d7 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -1,12 +1,13 @@ #include "DownloadManager.h" void DownloadManager::downloadFile(QString& filename){ + if (debug) qDebug() << "DM received signal for: " << filename; QUrl fileUrl; fileUrl = baseURL.resolved(QUrl(filename)); this->processDownloadRequest(fileUrl); } void DownloadManager::downloadFile(QUrl& fileUrl){ - qDebug() << "Received downloadFile signal for:" << fileUrl; + if (debug) qDebug() << "Received downloadFile signal for:" << fileUrl; this->processDownloadRequest(fileUrl); } // ---------------------------------------------------------------------------------------- @@ -16,25 +17,25 @@ void DownloadManager::processDownloadRequest(QUrl& url) // If download in progress, enqueue file and return. if (dip) { - qDebug() << "Download in progress! Enqueueing:" << url.toString() + if (debug) qDebug() << "Download in progress! Enqueueing:" << url.toString() << "(" << dlQ.size() << "in queue)"; dlQ.enqueue(url); return; } // No running downloads: enqueue and start next download. dlQ.enqueue(url); - qDebug() << "Enqueueing:" << url.toString() << endl; + if (debug) qDebug() << "Enqueueing:" << url.toString() << endl; startNextDownload(); } // ---------------------------------------------------------------------------------------- void DownloadManager::startNextDownload() { - qDebug() << "Starting next download: " << dlQ.head().toString() + if (debug) qDebug() << "Starting next download: " << dlQ.head().toString() << "(" << dlQ.size() << "in queue.)"; if (dlQ.isEmpty()) { - qDebug() << "Download queue empty! Exiting..."; + if (debug) qDebug() << "Download queue empty! Exiting..."; return; } // Dequeue next URL to download. @@ -46,7 +47,7 @@ void DownloadManager::startNextDownload() // If error upon opening, skip this file. if (!outfile.open(QIODevice::WriteOnly)) { - qDebug() << "Couldn't open file! Exiting..."; + if (debug) qDebug() << "Couldn't open file! Exiting..."; startNextDownload(); return; } @@ -56,7 +57,7 @@ void DownloadManager::startNextDownload() // TODO: Error handling not working properly... if (currentDownload->error() != QNetworkReply::NoError) { - qDebug() << "Network reply error, skipping download..."; + if (debug) qDebug() << "Network reply error, skipping download..."; return; } dip = true; @@ -80,7 +81,7 @@ void DownloadManager::downloadReady() void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { - qDebug() << "Download progress of " << currentDownload->url().toString() + if (debug) qDebug() << "Download progress of " << currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal; qint64 tmp = ((bytesIn * 100) / bytesTotal); emit updateProgress((int)tmp); @@ -92,8 +93,8 @@ void DownloadManager::downloadFinished() { // Second check if the download actually is finished. if (currentDownload->isFinished()) - qDebug() << "Download of " << currentDownload->url().toString() - << "finished." << endl; + if (debug) qDebug() << "Download of " << currentDownload->url().toString() + << "finished." << endl; // Close output file. outfile.close(); currentDownload->deleteLater(); @@ -113,8 +114,3 @@ DownloadManager::DownloadManager() dip = false; downloaded = 0; } -// Destructor. -DownloadManager::~DownloadManager() -{ - delete[] qnam; -} diff --git a/src/DownloadManager.h b/src/DownloadManager.h index 6e55012..0607cf5 100644 --- a/src/DownloadManager.h +++ b/src/DownloadManager.h @@ -15,7 +15,6 @@ class DownloadManager : public QObject public: DownloadManager(); - ~DownloadManager(); private: diff --git a/src/JSObject.cpp b/src/JSObject.cpp index 98c8d48..8650451 100644 --- a/src/JSObject.cpp +++ b/src/JSObject.cpp @@ -7,6 +7,9 @@ #include "JSObject.h" +extern QUrl baseURL; +extern bool debug; + //------------------------------------------------------------------------------------------------------- JSObject::JSObject(QWebFrame *parent) { _parent = parent; @@ -15,10 +18,14 @@ JSObject::JSObject(QWebFrame *parent) { JSObject::~JSObject() {} //------------------------------------------------------------------------------------------------------- /* TEST */ -void JSObject::doAction(QString action) +QString JSObject::getInfo(QString info) { - JSAction _action = QUIT; - emit processAction(action); + //qDebug() << "Parent name: " << this->parent()->getMAC(); + if (debug) qDebug() << "Requested info: " << info; + if (info == QString("mac")) + return "MAC_ADDRESS"; + else + return "no value"; } //------------------------------------------------------------------------------------------------------- void JSObject::attachToDOM() @@ -35,9 +42,7 @@ void JSObject::startDownload(QString filename) _parent->evaluateJavaScript("alert(\"No filename!\")"); return; } - - QUrl fileUrl; - fileUrl = baseURL.resolved(QUrl(filename)); + if (debug) qDebug() << "Request download: " << baseURL.resolved(QUrl(filename)).toString(); emit requestFile(filename); } @@ -50,60 +55,10 @@ void JSObject::updateProgressBar(int i) _parent->evaluateJavaScript(code); } //------------------------------------------------------------------------------------------------------- -void JSObject::getMacAddress() -{ - emit getMAC(); -} -//------------------------------------------------------------------------------------------------------- -void JSObject::printMAC(QString& macAddress) -{ - QString code = QString("printMacAddress(\"%1\")").arg(macAddress); - _parent->evaluateJavaScript(code); -} -//------------------------------------------------------------------------------------------------------- -void JSObject::showTime() -{ - emit getTime(); -} -//------------------------------------------------------------------------------------------------------- -void JSObject::printTime(QString& time) -{ - QString code; - code = QString("printTime(\"%1\")").arg(time); - _parent->evaluateJavaScript(code); -} -void JSObject::showDate() -{ - QString date = QDate::currentDate().toString("dd.MM.yyyy"); - //TODO:: edit jsFunction name - _parent->evaluateJavaScript(""); -} -//------------------------------------------------------------------------------------------------------- -void JSObject::showHelloWorld() -{ - _parent->evaluateJavaScript("alert(\"Hello World\")"); -} -//------------------------------------------------------------------------------------------------------- void JSObject::quitAll() { + qDebug() << "Quit signal."; emit signalQuitAll(); } -//------------------------------------------------------------------------------------------------------- -void JSObject::getSysInfo(){ - /* - QString time = QTime::currentTime().toString("hh:mm:ss"); - QString date = QDate::currentDate().toString("dd.MM.yyyy"); - QList<QHostAddress> ipList = QNetworkInterface::allAddresses(); - QString macAddress = QNetworkInterface::hardwareAddress(); - */ -} -//------------------------------------------------------------------------------------------------------- -void JSObject::getIpAddress(){} -//------------------------------------------------------------------------------------------------------- -void JSObject::getIntegratedHardwareDevices(){} -//------------------------------------------------------------------------------------------------------- -void JSObject::getUsbDevices(){} -//------------------------------------------------------------------------------------------------------- -void JSObject::getHardDrives(){} diff --git a/src/JSObject.h b/src/JSObject.h index e700ec8..f54ae39 100644 --- a/src/JSObject.h +++ b/src/JSObject.h @@ -10,7 +10,7 @@ #ifndef JSOBJECT_H_ #define JSOBJECT_H_ -#include "fbbrowser.h" +#include "fbgui.h" typedef enum { @@ -23,8 +23,8 @@ typedef enum SHOW_DATE } JSAction; -class fbbrowser; -class QWebFrame; +class fbgui; +//class QWebFrame; class JSObject : public QObject { Q_OBJECT @@ -33,70 +33,23 @@ private: QWebFrame* _parent; public: - JSObject(QWebFrame *parent); + JSObject(QWebFrame* parent); virtual ~JSObject(); -// no slots needed. class provides only signals -// private slots: -// void performAction(jsAction a); - -// define all the needed signals. -// every action gets its own signal. (the former enum is not needed anymore) -// the signals will be connected in the fbbrowser class with slots of the fbbrowser class signals: - void processAction(QString action); void requestFile(QString& filename); - void getMAC(); - void getTime(); void signalQuitAll(); - /* - // should be the last signal to be emited. - // Will close the browser and continues the boot sequence - void closeBrowser(); - // will start the download of all needed files for the following boot sequence - void startDownload(QString filename); - // starts the slot which is responsible for extracting the MAC address of the machine - // the MAC Address will be the parameter of a javascript function which will present it on the webpage - void getMacAddress(); - // starts the slot which is responsible for extracting the IP address of the machine - // the IP address will be the parameter of a javascript function which will present it on the webpage - void getIpAddress(); - // starts the slot which is responsible for extracting the integrated hardware devices of the machine - // the array of integrated hardware devices will be the parameter of a javascript function which will present // it on the webpage - void getIntegratedHardwareDevices(); - // starts the slot which is responsible for extracting the usb devices of the machine - // the array of usb devices will be the parameter of a javascript function which will present it on the webpag - void getUsbDevices(); - // starts the slot which is responsible for extracting the hard drive devices of the machine - // the array of hard rive devices will be the parameter of a javascript function which will present it on the // webpag - void getHardDrives(); - */ public slots: - /* Slots to commucate with fbbrowser. */ + void attachToDOM(); + QString getInfo(QString info); + void startDownload(QString filename); void updateProgressBar(int i); - void printMAC(QString& macAddress); - void printTime(QString& time); - - /* Slots for calling from within Javascript. */ - void doAction(QString action); void quitAll(); - void startDownload(QString filename); - void getMacAddress(); - void showTime(); - void showHelloWorld(); - // Not yet implemented. - void getSysInfo(); - void getIpAddress(); - void getIntegratedHardwareDevices(); - void getUsbDevices(); - void getHardDrives(); - // for testing reasons - void showDate(); }; #endif /* JSOBJECT_H_ */ diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp deleted file mode 100644 index f4c18f9..0000000 --- a/src/fbbrowser.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "fbbrowser.h" -#include "JSObject.h" -#include "DownloadManager.h" - -#include <QDateTime> -#include <QFile> -#include <QFileInfo> -#include <QNetworkInterface> -#include <QtWebKit> - -// ------------------------------------------------------------------------------------------- -void fbbrowser::processAction(QString action){ - // Do stuff -} -// ------------------------------------------------------------------------------------------- -fbbrowser::fbbrowser() -{ - // Initialise Browser Window. - QWebView* view = new QWebView(this); - - QNetworkRequest request; - QNetworkReply *reply; - QNetworkAccessManager *manager; - - manager = new QNetworkAccessManager(this); - request.setUrl(baseURL); - reply = manager->get(request); - // TODO: error differentiation - if(reply->error() == QNetworkReply::NoError) - { - qDebug() << "Loading: " << baseURL.toString(); - view->load(baseURL); - qDebug() << "Loaded."; - } - else - { - qDebug() << "QNetworkReply error code is: " << reply->error(); - qDebug() << "Error occured, loading error page..."; - view->load(QUrl("qrc:/html/errorPage.html")); - } - - // Enable Javascript through JSObject. - QWebFrame* qwf = view->page()->mainFrame(); - JSObject* jso = new JSObject(qwf); - /* ACTION TESTING */ - QObject::connect(jso, SIGNAL(processAction(QString)), this, SLOT(processAction(QString))); - - QObject::connect(qwf, SIGNAL(javaScriptWindowObjectCleared()), - jso, SLOT(attachToDOM())); - QObject::connect(jso, SIGNAL(getMAC()), this, SLOT(getMAC())); - QObject::connect(this, SIGNAL(printMAC(QString&)), jso, SLOT(printMAC(QString&))); - QObject::connect(jso, SIGNAL(getTime()), this, SLOT(getTime())); - QObject::connect(this, SIGNAL(printTime(QString&)), jso, SLOT(printTime(QString&))); - QObject::connect(jso, SIGNAL(signalQuitAll()), this, SLOT(quit())); - - // Initialize Download Manager. - DownloadManager* dm = new DownloadManager(); - QObject::connect(jso, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&))); - QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgressBar(int))); - -} - -// ------------------------------------------------------------------------------------------- -void fbbrowser::getMAC() -{ - QNetworkInterface *qNetI = new QNetworkInterface(); - QList<QNetworkInterface> list; - list=qNetI->allInterfaces(); - QString str; - QString macAddress; - for (int i = 0; i < list.size(); ++i) { - str = list.at(i).name(); - macAddress = list.at(i).hardwareAddress(); - qDebug() << str; - qDebug() << macAddress; - } - emit printMAC(macAddress); -} -// ------------------------------------------------------------------------------------------- -void fbbrowser::getTime() -{ - qDebug() << "---- call: showTime_Slot"; - QString time = QTime::currentTime().toString("hh:mm:ss"); - emit printTime(time); -} -// ------------------------------------------------------------------------------------------- -void fbbrowser::quit() -{ - emit killApp(); -} diff --git a/src/fbbrowser.h b/src/fbbrowser.h deleted file mode 100644 index 023d76b..0000000 --- a/src/fbbrowser.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FBBROWSER_H -#define FBBROWSER_H - -#include <QString> -#include <QtGui> -#include <QtWebKit> - -#include "JSObject.h" -#include "DownloadManager.h" - -extern QUrl baseURL; - -class fbbrowser : public QWidget -{ - Q_OBJECT - -public: - fbbrowser(); - -private: - -signals: - void printMAC(QString& macAddress); - void printTime(QString& time); - void downloadFile(QUrl& fileUrl); - void updateProgress(int progress); - void killApp(); - -public slots: - void processAction(QString action); - void getMAC(); - void getTime(); - void quit(); -}; - -#endif // FBBROWSER_H diff --git a/src/fbgui.cpp b/src/fbgui.cpp index a9e3951..8f6fc88 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -1,25 +1,41 @@ #include "fbgui.h" -#include "fbbrowser.h" +#include "DownloadManager.h" +#include "JSObject.h" #include <iostream> #include <QUrl> #include <QMap> +#include <QtWebKit> +#include <QApplication> QUrl baseURL; bool debug; fbgui::fbgui(QApplication *parent) { + _parent = parent; /* Browser init. */ - fbbrowser* _fbb = new fbbrowser(); - setWindowFlags(Qt::SplashScreen); - showFullScreen(); - setCentralWidget(_fbb); - + QWebView* webView = new QWebView(this); + webView->load(baseURL); /* Connect fbb with app for killing the app from browser. */ - QObject::connect(_fbb, SIGNAL(killApp()), parent, SLOT(quit())); - // JSO init + /* Init JavaScript interface */ + JSObject* jso = new JSObject(webView->page()->mainFrame()); + + QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), jso, SLOT(attachToDOM())); + QObject::connect(jso, SIGNAL(signalQuitAll()), parent, SLOT(quit())); + + /* Init Download Manager */ + DownloadManager* dm = new DownloadManager(); + QObject::connect(jso, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&))); + QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgressBar(int))); + setWindowFlags(Qt::SplashScreen); + showFullScreen(); + setCentralWidget(webView); + +} +void fbgui::quit(){ + //parent.quit(); } diff --git a/src/fbgui.h b/src/fbgui.h index f72db44..70fa02b 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -2,7 +2,8 @@ #define FBGUI_H #include <QtCore> -#include "fbbrowser.h" +#include <QMainWindow> +#include <QtWebKit> #define DEFAULT_URL "http://www.google.com" @@ -12,9 +13,10 @@ class fbgui : public QMainWindow public: fbgui(QApplication *parent); + void quit(); -signals: - void quitApp(); +private: + QApplication* _parent; }; #endif // FBGUI_H diff --git a/src/fbgui.pro b/src/fbgui.pro index 6ed7dec..5e908ed 100644 --- a/src/fbgui.pro +++ b/src/fbgui.pro @@ -7,15 +7,11 @@ QT += core \ webkit \ network HEADERS += fbgui.h \ - fbbrowser.h \ JSObject.h \ DownloadManager.h - SOURCES += main.cpp \ fbgui.cpp \ - fbbrowser.cpp \ JSObject.cpp \ DownloadManager.cpp - FORMS += fbbrowser.ui RESOURCES += fbgui.qrc diff --git a/src/main.cpp b/src/main.cpp index 0144b9f..891f497 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) /* Parse cmdline argus. */ QMap<QString, QString> clo; int longIndex = 0; - static const char *optString = "u:h"; + static const char *optString = "u:hd"; static const struct option longOpts[] = { {"url", required_argument, NULL, 'u'}, @@ -86,7 +86,5 @@ int main(int argc, char *argv[]) // Start fbgui. fbgui gui(&app); gui.show(); - - return app.exec(); } diff --git a/src/testApp.sh b/src/testApp.sh index a529d7e..0d31830 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -18,7 +18,7 @@ display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}') # Wait for it to load (needed?) Probably not ;o sleep 0.1 # Start fbgui. -$working_path/fbgui -display QVFb:$display_id -u $url +$working_path/fbgui -display QVFb:$display_id -d -u $url # Check if fbbrowser is not running, if so kill the qvfb. if [ $(ps aux | grep -v grep | grep -c fbgui) -eq 1 ] then |