summaryrefslogblamecommitdiffstats
path: root/src/fbbrowser.cpp
blob: 009aae7754b2616f4f54777f8f64592f3df8d10f (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;

	qs = "test.php";
	dm->get(qs);
	qs = "blacklist.txt";
	dm->get(qs);
	qs = "whitelist.tar.gz";
	dm->get(qs);
	// **** TEST ****
	qDebug() << "DM blocking app?";

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

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