summaryrefslogblamecommitdiffstats
path: root/src/client/toolbar/toolbar.cpp
blob: b0ded4431f7e6bb791607e27da6ffa38301f36cd (plain) (tree)
1
2
3
4
5
6
7






                          




                                    


                       

                                                                                
                                   
                                                                                  
 
                                

                           
                                   



                                                                                                            
 
                                   
                                   

                                       
                                                 


                                                                                                                  
 
                        
                                
                                                                  
                                                  


                                         
                                     



                                                                                   
 
                                                 
                                                                                                                                            
 
                          









                                                                                                                   

 
                                                                                




                                      
                   

 
                                                                                
  

           

                                   
                           


                               
                                                                                

                                   

                          


                               
                                                                                
  


        

                                                                








                                                             

 
                                                                                
                              
 
                                            

                                                
                           

                                                   

 
                                                                                

                                                       

                                                     


                                
                                                                                              



                                                    
                                                                                   






                                                                                                                              
                                                                                





                                                    

                                                                                
 















                                                                                                   
 
/*
 * toolbar.cpp
 *
 *  Created on: 21.01.2013
 *      Author: sr
 */

#include "../../shared/settings.h"
#include "../net/serverconnection.h"
#include "../vnc/vncwindow.h"
#include "../vnc/vncserver.h"

#include "toolbar.h"
#include "ui_toolbar.h"


//______________________________________________________________________________
Toolbar::Toolbar(QWidget *parent) :
	QWidget(parent), _ui(new Ui::Toolbar), _hideTimer(this), _connection(NULL)
{
	/* Initialize the GUI */
	_ui->setupUi(this);

	/* Set window properties */
	setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
	setAttribute(Qt::WA_AlwaysShowToolTips);
	setAttribute(Qt::WA_QuitOnClose);
	setVisible(true);

	/* Create the VNC Window */
	_vnc = new VncWindow(NULL);

	/* Create the connect window */
	_connectWindow = new ConnectWindow(NULL);
	// Connect the signals
	connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect()));
	connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*)));

	/* Setup menu */
	_menu = new QMenu(this);
	_acnDisconnect = new QAction(tr("Set &session ID"), this);
	_acnQuit = new QAction(tr("&Quit"), this);
	_menu->addAction(_acnDisconnect);
	_menu->addSeparator();
	_menu->addAction(_acnQuit);
	_ui->cmdMenu->setMenu(_menu);
	// Connect the signals
	connect(_menu, SIGNAL(aboutToHide()), this, SLOT(hideBar()));
	connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(show()));
	connect(_acnQuit, SIGNAL(triggered()), qApp, SLOT(quit()));

	/* Connect the signals from vnc server */
	connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int, QString&, QString&)));

	/* Set position */
	const QDesktopWidget desktop;
	const QRect primaryScreen = desktop.screenGeometry();
	move(primaryScreen.left() + (primaryScreen.width() - this->width())/2 , primaryScreen.top());
	qDebug() << primaryScreen.left() << primaryScreen.top() << primaryScreen.right() << primaryScreen.bottom();

	/* Setup hide timer */
	_hideTimer.setInterval(600);
	_hideTimer.setSingleShot(true);
	connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(hideBar()));
	_hideTimer.start(); // initially show PVS and hide later
}

//______________________________________________________________________________
Toolbar::~Toolbar()
{
	VncServer::instance()->stop();
	_vnc->deleteLater();
	_connectWindow->deleteLater();
	delete _ui;
}

//______________________________________________________________________________
/*
 * Override
 */
void Toolbar::leaveEvent(QEvent* e)
{
	_hideTimer.start();
	QWidget::leaveEvent(e);
}

//______________________________________________________________________________
void Toolbar::enterEvent(QEvent* e)
{
	_hideTimer.stop();
	showBar();
	QWidget::enterEvent(e);
}

//______________________________________________________________________________
/*
 * Slots
 */

void Toolbar::onVncServerIsRunning(int port, QString&, QString&)
{
	if (port > 0){
		_ui->lblStatus->setStyleSheet("color:red");
		_ui->lblStatus->setText(tr("Recording"));
		showBar();
	}	else {
		_ui->lblStatus->setStyleSheet("color:green");
		_ui->lblStatus->setText(tr("Online"));
		hideBar();
	}
}

//______________________________________________________________________________
void Toolbar::onDisconnected()
{
	_connectWindow->setConnected(false);
	if (_connection != NULL)
		_connection->blockSignals(true);
	_connection = NULL;
	_ui->lblStatus->setStyleSheet("color:red");
	_ui->lblStatus->setText(tr("Offline"));
}

//______________________________________________________________________________
void Toolbar::onConnected(ServerConnection* connection)
{
	_ui->lblStatus->setStyleSheet("color:green");
	_ui->lblStatus->setText(tr("Online"));
	//
	if (_connection != NULL)
	{
		disconnect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
		_connection->blockSignals(true);
		_connection->disconnectFromServer();
	}
	_connection = connection;
	connect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
	connect(_connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int)),
		_vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int)));
	connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close()));
	connect(_vnc, SIGNAL(running(const bool, const int)), _connection, SLOT(onVncViewerStartStop(const bool, const int)));
	_connectWindow->setConnected(true);
}

//______________________________________________________________________________
void Toolbar::onDoDisconnect()
{
	if (_connection != NULL)
		_connection->disconnectFromServer();
}

//______________________________________________________________________________
void Toolbar::hideBar()
{
	//	// Don't hide window if any menu is open or VNC Server is running from this client.
	if (_menu->isVisible() || VncServer::instance()->isVncServerRunning())
		return;
	const QDesktopWidget desktop;
	const QRect primaryScreen = desktop.screenGeometry();
	move(x(), primaryScreen.top() + 2 - height());
	//move(x(), primaryScreen.bottom() - 2);
}

//______________________________________________________________________________
void Toolbar::showBar()
{
	const QDesktopWidget desktop;
	const QRect primaryScreen = desktop.screenGeometry();
	move(x(), primaryScreen.top());
	//move(x(), primaryScreen.bottom() - height());
}