summaryrefslogblamecommitdiffstats
path: root/src/fbgui.cpp
blob: 5209ad16d3a8c35c33709d0d6cb7d8283fda7b6b (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;
//-------------------------------------------------------------------------------------------
fbgui::fbgui()
{
	if (debug) qDebug() << "Application dir path: " << QApplication::applicationDirPath();

	checkHost();

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

	/* Init JavaScript interface */
	javascriptInterface* jsi = new javascriptInterface(webView->page()->mainFrame());
	// this still looks bad..
	QObject::connect(jsi, SIGNAL(signalQuitAll()), 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)), jsi, SLOT(updateProgressBar(int)));

	//setWindowFlags(Qt::Window);
	showFullScreen();
	qDebug() << "Width: " << width() << " // Height: " << height();
	QSize size(800, 600);
	resize(size);
	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);
	}
}
void fbgui::anim() {}