summaryrefslogtreecommitdiffstats
path: root/src/fbbrowser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbbrowser.cpp')
-rw-r--r--src/fbbrowser.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/fbbrowser.cpp b/src/fbbrowser.cpp
new file mode 100644
index 0000000..50fc86a
--- /dev/null
+++ b/src/fbbrowser.cpp
@@ -0,0 +1,89 @@
+#include "fbbrowser.h"
+#include <QtGui>
+#include <QtWebKit>
+#include <QApplication>
+
+void fbbrowser::httpReadyRead()
+{
+ // This slot listens to readyRead() signal from our QNetworkReply.
+ qDebug() << "readyRead() signal emmited!" << endl;
+ if(reply->error() == QNetworkReply::NoError)
+ {
+ qDebug() << "No error, loading given URL...";
+ view->load(url);
+ }
+}
+
+fbbrowser::fbbrowser(const QUrl & url)
+{
+ view = new QWebView(this);
+
+ // 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(readyRead()), this, SLOT(httpReadyRead()));
+ //connect(reply, SIGNAL(finished()), this, SLOT());
+
+ // Check if the reply is an error message.
+ qDebug() << "QNetworkReply error code: " << 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"));
+ //}
+
+ //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()
+{
+ view->page()->mainFrame()->addToJavaScriptWindowObject(QString("webkitTest"), this);
+}
+
+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 lastWindowClosed();
+}