From 0d711f2fc464eb05866cd9c329b57ec279a98971 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 4 Mar 2011 23:51:45 +0100 Subject: Code cleanup, JSO class continued, added webkitTest.html for reference --- src/fbbrowser.cpp | 167 +++++++----------------------------------------------- 1 file changed, 22 insertions(+), 145 deletions(-) (limited to 'src/fbbrowser.cpp') diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp index 4deca61..535907e 100644 --- a/src/fbbrowser.cpp +++ b/src/fbbrowser.cpp @@ -1,11 +1,17 @@ #include "fbbrowser.h" +#include "JSObject.h" #include "DownloadManager.h" #include #include #include -#include "jsObject.h" +// ------------------------------------------------------------------------------------------- +void fbbrowser::quit() +{ + emit killApp(); +} +// ------------------------------------------------------------------------------------------- fbbrowser::fbbrowser(const QUrl & url) { view = new QWebView(this); @@ -14,10 +20,8 @@ fbbrowser::fbbrowser(const QUrl & url) manager = new QNetworkAccessManager(this); // Create a QNetworkRequest object and set its URL. request.setUrl(url); - // Let the manager send the request and receive the reply. - reply = manager->get(request); - + reply = manager->get(request); // TODO: error differentiation // reply->error() returns 0 even for invalid URL. // A possibility to check for validity, is to listen to readyRead() @@ -34,156 +38,29 @@ fbbrowser::fbbrowser(const QUrl & url) view->load(QUrl("qrc:/html/errorPage.html")); } + // Enable Javascript through JSObject. + qwf = view->page()->mainFrame(); + jso = new JSObject(qwf); + QObject::connect(qwf, SIGNAL(javaScriptWindowObjectCleared()), + jso, SLOT(enableJavascriptAccess())); + QObject::connect(jso, SIGNAL(signalQuitAll()), this, SLOT(quit())); + // Initialize Download Manager. dm = new DownloadManager(baseUrl); - QObject::connect(this, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString))); + QObject::connect(jso, SIGNAL(downloadFile(QString)), dm, SLOT(downloadFile(QString))); + QObject::connect(dm, SIGNAL(updateProgress(int)), jso, SLOT(updateProgressSlot(int))); //remove the window decoration this->setWindowFlags(Qt::SplashScreen); - - //enable JavaScript access to qt objects - QObject::connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject())); - //set form to fullscreen this->showFullScreen(); - setCentralWidget(view); } - -// Destructor +// ------------------------------------------------------------------------------------------- fbbrowser::~fbbrowser() { -} - -// -void fbbrowser::addJSObject() -{ - jso = new jsObject(); - view->page()->mainFrame()->addToJavaScriptWindowObject(QString("jsObject"), jso); - - // connect the signals of the jsObject to the slots of the fbbrowser - connectJsSignalsToSlots(); -} - -void fbbrowser::connectJsSignalsToSlots() -{ - QObject::connect(jso, SIGNAL(closeBrowser()), this, SLOT(quitAll())); - QObject::connect(jso, SIGNAL(startDownload(QString)), this, SLOT(startDownload_Slot(QString))); - QObject::connect(jso, SIGNAL(getMacAddress()), this, SLOT(getMacAddress_Slot())); - QObject::connect(jso, SIGNAL(getIpAddress()), this, SLOT(getIpAddress_Slot())); - QObject::connect(jso, SIGNAL(getIntegratedHardwareDevices()), this, SLOT(getIntegratedHardwareDevices_Slot())); - QObject::connect(jso, SIGNAL(getUsbDevices()), this, SLOT(getUsbDevices_Slot())); - QObject::connect(jso, SIGNAL(getHardDrives()), this, SLOT(getHardDrives_Slot())); - - // for testing reasons - QObject::connect(jso, SIGNAL(showTime()), this, SLOT(showTime_Slot())); - QObject::connect(jso, SIGNAL(showDate()), this, SLOT(showDate_Slot())); - QObject::connect(jso, SIGNAL(showHelloWorld()), this, SLOT(showHelloWorld_Slot())); - // further tests - QObject::connect(dm, SIGNAL(updateProgress(int)), this, SLOT(updateProgressSlot(int))); -} -// -void fbbrowser::updateProgressSlot(int i) -{ - QString code = QString("updateProgress(\%1\)").arg(i); - view->page()->mainFrame()->evaluateJavaScript(code); -} -void fbbrowser::writeText(QString text) -{ - QFile file("out.txt"); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - - QTextStream out(&file); - out << text << "\n"; -} - -// This function needed now ? -void fbbrowser::quitAll() -{ - emit signalQuitAll(); -} - - -void fbbrowser::startDownload_Slot(QString filename) -{ - - qDebug() << "Returned from JS: " << filename; - // Start download. - emit downloadFile(filename); - -} - -void fbbrowser::getMacAddress_Slot() -{ - - QNetworkInterface *qNetI = new QNetworkInterface(); - QList 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; - } - - //TODO:: edit jsFunction name - QString code; - code = QString("printMacAddress(\"%1\")").arg(macAddress); - view->page()->mainFrame()->evaluateJavaScript(code); -} - -void fbbrowser::getIpAddress_Slot() -{ - -} - -void fbbrowser::getIntegratedHardwareDevices_Slot() -{ - -} - -void fbbrowser::getUsbDevices_Slot() -{ - -} - -void fbbrowser::getHardDrives_Slot() -{ - -} - -// for testing reasons -void fbbrowser::showTime_Slot() -{ - qDebug() << "---- call: showTime_Slot"; - QString time = QTime::currentTime().toString("hh:mm:ss"); - - //TODO:: edit jsFunction name - QString code; - code = QString("printTime(\"%1\")").arg(time); - view->page()->mainFrame()->evaluateJavaScript(code); -} - -void fbbrowser::showDate_Slot() -{ - QString date = QDate::currentDate().toString("dd.MM.yyyy"); - //TODO:: edit jsFunction name - //view->page()->mainFrame()->evaluateJavaScript(""); -} - -void fbbrowser::showHelloWorld_Slot() -{ - view->page()->mainFrame()->evaluateJavaScript("alert(\"Hello World\")"); -} - -void fbbrowser::getSysInfo(){ -/* - QString time = QTime::currentTime().toString("hh:mm:ss"); - QString date = QDate::currentDate().toString("dd.MM.yyyy"); - QList ipList = QNetworkInterface::allAddresses(); - QString macAddress = QNetworkInterface::hardwareAddress(); - */ + delete view; + delete manager; + delete dm; + delete jso; } -- cgit v1.2.3-55-g7522