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

                       
 

                                                                                           
                                             
                          
                   
                                             

                                                                                             
 
                         
 
                            
                    

                                               
 
                                       
                                                                                         
                                                                        
 
                                                                                               
                                                                            
                                   
                                                    
                                                                                               
                                                                                                             
                                                                                                   

                                               

                                  
               
 

                                                                                             

                             

                                                                 
                                                                                        

                                   
 
#include "fbgui.h"
#include "downloadManager.h"
#include "javascriptInterface.h"

#include <iostream>
#include <QUrl>
#include <QDir>
#include <QHostInfo>
#include <QtWebKit>
#include <QApplication>

// Note: Absolute paths. binPath empty init, set in main() after QApplication instanciated.
QString binPath("");
QString downloadPath(binPath + "/downloads");
QUrl baseURL(DEFAULT_URL);
bool debug = false;
int updateInterval = DEFAULT_UPDATE_INTERVAL;
//-------------------------------------------------------------------------------------------
fbgui::fbgui()
{
	//grabKeyboard();

	/* Init "browser" */
	checkHost();
	QWebView* webView = new QWebView(this);
	webView->load(baseURL);

	/* Init JavaScript interface */
	javascriptInterface* jsi = new javascriptInterface(webView->page()->mainFrame());
	QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));

	QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
						  jsi, SLOT(attachToDOM()));
	/* Init Download Manager */
	downloadManager* dm = new downloadManager();
	QObject::connect(jsi, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&)));
	QObject::connect(dm, SIGNAL(updateProgress(int, double)), jsi, SLOT(updateProgressBar(int, double)));
	QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished()));

	setAttribute(Qt::WA_QuitOnClose, true);
	showFullScreen();
	setCentralWidget(webView);
	show();

}
//-------------------------------------------------------------------------------------------
void fbgui::checkHost() const
{
	QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
	if (hostInfo.error() != QHostInfo::NoError){
		qDebug() << "Lookup of " << baseURL.host() << "failed." << "Exiting...";
		exit(EXIT_FAILURE);
	}
}