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


                    
                   
                     



                                      
                      
                                                                                 
                                                  
                                                           

                            
                                                                  
                                      
 
                                      


                                                                           






                                                             
                                                                              


                                                                   
                         
                                                           

                                
                         












                                                                                                                        
             

                       

 
  

                             
                             
                                                                                         

















                                                                                                                       
                                                                                           

 

                                       






                                                               
 
                             

                         


                             
































                                                   
                                               
                                                                 



                                                            




                                                                   






                                                                                

 







                                                                       
 
#include "fbbrowser.h"

#include <QFile>
#include <QFileInfo>
#include <QtWebKit>
#include "jsObject.h"

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.
	request.setUrl(url);

	// Let the manager send the request and receive the reply.
        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()
        // signal, haven't found a better way yet ...
	if(reply->error() == QNetworkReply::NoError)
	{
		qDebug() << "No error, loading given URL...";
		view->load(url);
	}
	else 
	{
	        qDebug() << "QNetworkReply error code is: " << reply->error();
		qDebug() << "Error occured, loading error page...";
		view->load(QUrl("qrc:/html/errorPage.html"));
	}
	// **** TEST ****
	DownloadManager* dm = new DownloadManager(baseUrl);
	QString qs = "test.php";
	dm->downloadFile(qs);
	// **** 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()
{
	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()), this, SLOT(startDownload_Slot()));
	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()));
}

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()
{

}

void fbbrowser::getMacAddress_Slot()
{

}
	
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<QHostAddress> ipList = QNetworkInterface::allAddresses();
	QString macAddress = QNetworkInterface::hardwareAddress()
	*/
}