summaryrefslogblamecommitdiffstats
path: root/src/fbgui.cpp
blob: 96265d295f537427d71e3566863bcedd8f45a5a5 (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("/tmp/fbgui/downloads");
int updateInterval = DEFAULT_UPDATE_INTERVAL;
bool debug = false;

//-------------------------------------------------------------------------------------------
fbgui::fbgui()
{
	/* initialize "browser" */
	checkHost();
	_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);

	/* TEST */
	if (debug){
		_logView = new logViewer(this);
		_splitter = new QSplitter(Qt::Vertical, this);
		_splitter->addWidget(_webView);
		_splitter->addWidget(_logView);
		/* CTRL + D  toggles debug window */
		_toggleDebug = new QAction(tr("&toggleDebug"), this);
		_toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
		this->addAction(_toggleDebug);
		connect(_toggleDebug, SIGNAL(triggered()), this, SLOT(toggleDebug()));
		//createToggleDebugAction();
		setCentralWidget(_splitter);
	}
	else
		setCentralWidget(_webView);
	/* TEST */

	showFullScreen();
}
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
void fbgui::toggleDebug(){
	if (_logView->isVisibleTo(_splitter))
		_logView->hide();
	else
		_logView->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);
	}
}