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

                                                                                             
 

















                                                                          
                                  
                    
                                               
                               
 
                                             
                                                                                         
                                                                        
                                                                                               
                                                                            
 
                                         
                                                    
                                                                                                              
                                                                                               
                                                                                                                               
                                                                                                   
 
                                
                                               

                                                
                                  
                         
               
 
 
                                                                                             

                             

                                                                 
                                                                                   

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

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

QUrl baseURL(DEFAULT_URL);
QString binPath("");
QString downloadPath(binPath + "/downloads");
int updateInterval = DEFAULT_UPDATE_INTERVAL;
bool debug = false;

//-------------------------------------------------------------------------------------------
fbgui::fbgui()
{
	/* debug console tests */
	logViewer *logView = new logViewer(this);
	/* dock on bottom */
	QDockWidget *dw = new QDockWidget(QString("debug console"), this);
	dw->setAllowedAreas(Qt::BottomDockWidgetArea);
	dw->setWidget(logView);
	addDockWidget(Qt::BottomDockWidgetArea, dw);
	/* TEST
	QWidget *dummy = new QWidget();
	QVBoxLayout *layout = new QVBoxLayout();
	layout->addWidget(webView);
	layout->addWidget(logView);
	dummy->setLayout(layout);
	TEST */




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

	/* initialize 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()));

	/* initialize download manager */
	downloadManager* dm = new downloadManager();
	QObject::connect(dm, SIGNAL(downloadInfo(QString, double)), jsi, SLOT(downloadInfo(QString, double)));
	QObject::connect(jsi, SIGNAL(requestFile(QString&)), dm, SLOT(downloadFile(QString&)));
	QObject::connect(dm, SIGNAL(updateProgress(int, double, QString)), jsi, SLOT(updateProgressBar(int, double, QString)));
	QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished()));

	setWindowTitle("fbgui");
	setAttribute(Qt::WA_QuitOnClose, true);
	setWindowFlags(Qt::FramelessWindowHint);
	resize(QSize(800, 600));
	setCentralWidget(webView);
	showFullScreen();
	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);
	}
}