summaryrefslogblamecommitdiffstats
path: root/fbbrowser/fbbrowser.cpp
blob: 813b14e92d907157800396f11ce12d4b9815bb96 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                      
                       
 
 

                                      

 
 
                                  






















                                                             

















                                                                                                                        

                             


                                                                                            

                                       






                                                               




                                  
#include "fbbrowser.h"
#include <QtGui>
#include <QtWebKit>
#include <QApplication>


fbbrowser::fbbrowser(const QUrl & url)
{



	view = new QWebView(this);

	// check Internet connection
	manager = new QNetworkAccessManager(this);
	QNetworkRequest request;
	request.setUrl(url);

	QNetworkReply *reply = manager->get(request);
	//connect(reply, SIGNAL(error()), this, SLOT());
	//connect(reply, SIGNAL(finished()), this, SLOT());

	qDebug() << reply->error();

	//TODO: error differentiation
	if(reply->error()!=0)
	{
		qDebug() << "show errorPage";
		view->load(QUrl("qrc:/html/errorPage.html"));
	}
	else
	{
		qDebug() << "show Page";
		view->load(url);
	}

	//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);
}

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";
}

void fbbrowser::quitAll()
{
	//emit lastWindowClosed();
}