#include "fbbrowser.h" #include #include #include #include "jsObject.h" // This function is not used at the moment. // TODO: Fix function or find another way... void fbbrowser::httpReqFinished() { // This slot listens to readyRead() signal from our QNetworkReply. qDebug() << "finished() signal emmited!" << endl; if(reply->error() == QNetworkReply::NoError) { qDebug() << "No error, loading given URL..."; view->load(this->baseUrl); } } void fbbrowser::saveData() { QFile outfile(filename); if (!outfile.open(QIODevice::WriteOnly)) { qDebug() << "Couldnt open file! exiting..."; exit(1); } outfile.write(qiod->readAll()); outfile.close(); } // This function requires the file name of the file to download. void fbbrowser::download(const QString &file) { // This function is in developement... QUrl u = baseUrl.resolved(file); req.setUrl(u); rep = manager->get(req); QIODevice* qiod2 = rep; qiod = rep; QObject::connect(rep, SIGNAL(finished()), this, SLOT(saveData())); } fbbrowser::fbbrowser(const QUrl & url) { view = new QWebView(this); baseUrl = url; // Create QNetworkAccessManager which is needed to send/receive requests. manager = new QNetworkAccessManager(this); // Create a QNetworkRequest object and set its URL. //* QNetworkRequest request; request.setUrl(url); // Check Internet connection // Let the manager send the request and receive the reply. // QNetworkReply *reply = manager->get(request); reply = manager->get(request); // connect(reply, SIGNAL(finished()), this, SLOT(httpReqFinished())); // Check if the reply is an error message. qDebug() << "QNetworkReply error code is: " << reply->error(); // TODO: error differentiation // reply->error() returns 0 even for invalid URL. // A possibility to check for validity, is to listen to readyRead() // signal, haven't found a better way yet ... if(reply->error() == QNetworkReply::NoError) { qDebug() << "No error, loading given URL..."; view->load(url); } else { qDebug() << "Error occured, loading error page..."; view->load(QUrl("qrc:/html/errorPage.html")); } // **** TEST **** // This part is just a test call of download()... DownloadManager* dm = new DownloadManager(); dm->print(); //dm.setUrl(baseUrl); //dm.downloadFile("test.php"); filename = "test.php"; download(filename); // **** TEST **** //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() { jsObject *jso = new jsObject(); view->page()->mainFrame()->addToJavaScriptWindowObject(QString("jsObject"), jso); } 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::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() */ }