summaryrefslogblamecommitdiffstats
path: root/src/gui/connectionFrame.cpp
blob: 32e20f77273d1c242c6070a118ddb8dc01101afb (plain) (tree)





























                                                                               
                              





















                                                                                  

                         

























































                                                                                               
                                           




















                                                                   

                                   





                                                                         
                            






                                               
                                         













                                          

                                            

















































































































































































                                                                                                            

                                                    











                                                                                                                   
                                            



















































































                                                                                                                   




                                  



























































                                                                                                                           
/*
# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# src/gui/connectionFrame.cpp
# -----------------------------------------------------------------------------
*/


#include <src/gui/connectionFrame.h>
#include <src/gui/dialog.h>
#include <src/gui/mainWindow.h>
#include <iostream>
extern "C"
{
#include <rfb/rfbclient.h>
}
#include <src/core/pvsConnectionManager.h>


ConnectionFrame::ConnectionFrame(QWidget *parent) :
        QGroupBox(parent)
{
	//defines the ui-stuff
    _layoutTop = new QVBoxLayout(this);
    _layoutTop->setMargin(0);
    _frame = new Frame("", this);
    _frame->setConFrame(this);
    _frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
    _layoutTop->addWidget(_frame);
    _layoutBottom = new QHBoxLayout(this);
    _layoutBottom->setMargin(0);
    _conFrameTaskbar = new QWidget(this);
    _conFrameTaskbar->setLayout(_layoutBottom);
    _conFrameTaskbar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
    _ip = new QLabel(_conFrameTaskbar);
    _layoutBottom->addStretch();
    _layoutBottom->addWidget(_ip);
    _layoutBottom->addStretch();
    _dozentContaimner  = new QLabel(_conFrameTaskbar);
    _dozentContaimner->setDisabled(true);
    _layoutBottom->addWidget(_dozentContaimner);
    _status  = new QLabel(_conFrameTaskbar);
    _layoutBottom->addWidget(_status);
    _layoutTop->addWidget(_conFrameTaskbar);
    this->setLayout(_layoutTop);

    setInitSize(190,168);
    initFrame();

    nat_height     = 0;
    nat_width      = 0;
    _ratio         = 100;
    overSized      = false;
    _fullscreen    = false;
    _closeup       = false;
    active         = false;
    _isOnProjekt   = false;
    isClientOnline = true;

    //slots and signals

    DelDummy    = new QAction(tr("&Remove dummy..."),this);
	connect(DelDummy, SIGNAL(triggered()), this, SLOT(delDummy()));
	lockClient  = new QAction(tr("&Lock Client(s)"),this);
	connect(lockClient, SIGNAL(triggered()), this, SLOT(on_lock()));
	uLockClient = new QAction(tr("&Unlock Client(s)"),this);
	connect(uLockClient, SIGNAL(triggered()), this, SLOT(on_unlock()));
	/*invertlockClient  = new QAction(tr("&Invertlock Client(s)"),this);
	connect(invertlockClient, SIGNAL(triggered()), this, SLOT(on_lock_invert()));
	LockAllClient  = new QAction(tr("&Lock all Client(s)"),this);
	connect(LockAllClient, SIGNAL(triggered()), this, SLOT(on_lock_all()));
	uLockAllClient  = new QAction(tr("&Unlock all Client(s)"),this);
	connect(uLockAllClient, SIGNAL(triggered()), this, SLOT(on_unlock_all()));*/
	msgLockClient    = new QAction(tr("&MsgLock Client(s)"),this);
	connect(msgLockClient, SIGNAL(triggered()), this, SLOT(on_lock_with_message()));
	msgLockAllClient = new QAction(tr("&MsgLock all Client(s)"),this);
	connect(msgLockAllClient, SIGNAL(triggered()), this, SLOT(on_lock_all_with_message()));
	msgClient        = new QAction(tr("&Message Client(s)"),this);
	connect(msgClient, SIGNAL(triggered()), this, SLOT(on_message()));
	project  = new QAction(tr("&Projection"),this);
	connect(project, SIGNAL(triggered()), this, SLOT(on_projection()));
	uproject = new QAction(tr("&Unprojection"),this);
	connect(uproject, SIGNAL(triggered()), this, SLOT(on_unprojection()));
	/*rHelp = new QAction(tr("&Remote Help"),this);
	connect(rHelp, SIGNAL(triggered()), this, SLOT(on_remoteHelp()));*/

	//connect(_frame, SIGNAL(clicked()), this, SLOT(on_click()));

	//menu entries

	menu = new QMenu(this);
	menu->addAction(DelDummy);
	menu->addSeparator();
	menu->addAction(lockClient);
	menu->addAction(uLockClient);
	/*menu->addAction(invertlockClient);
	menu->addAction(LockAllClient);
	menu->addAction(uLockAllClient);*/
	menu->addAction(msgLockClient);
	menu->addAction(msgLockAllClient);
	menu->addAction(msgClient);
	menu->addAction(project);
	menu->addAction(uproject);
	//menu->addAction(rHelp);

	this->setStyleSheet(STYLE_DEFAULT);
    this->show();
}

ConnectionFrame::~ConnectionFrame()
{

}

QString ConnectionFrame::getTitle() // get frame title
{
	return title();
}

void ConnectionFrame::setTheTitle(QString title) // set frame title
{
	if (title.isNull()) return;
	setTitle(title);
}

QString ConnectionFrame::getTaskbarTitle() // get taskbar title
{
	if (!_ip->text().isNull())
		return _ip->text();
	else
		return _myConnection->getIp();
}

void ConnectionFrame::setTaskbarTitle(QString title) // set taskbar title
{
	_ip->setText(title);
	_frame->ip = title;
}

void ConnectionFrame::setInitSize(int w, int h)
{
	resize(w, h);
	_frame->resize(w, h);
	//_conFrameTaskbar->resize(w, h);
    prev_height  = h;
    prev_width   = w;
    init_w       = w;
    init_h		 = h;
}

void ConnectionFrame::Resize(int w, int h)
{
	resize(w, h);
	_frame->resize(w, h);
}

void ConnectionFrame::initFrame()
{
	_clientStatus = QPixmap(":/online");
	_status->setDisabled(true);
	_clientDozent = QPixmap(":/dozent2");
	_dozentContaimner->setPixmap(_clientDozent.scaled(3*_dozentContaimner->size()/4,
            Qt::KeepAspectRatio, Qt::SmoothTransformation));
}


void ConnectionFrame::setConnection(PVSClient* newConnection)
{
    if (newConnection)
    {
        _myConnection = newConnection;
        _myConnection->setConnectionFrame(this);
        const QString userName = QString(
                                     _myConnection->getUserName().toUtf8().data());
        if (_myConnection->getVNCConnection() && _myConnection->getVNCConnection()->getVNCClientThread())
        {
            _myConnection->getVNCConnection()->setFrame(this);
            _frame->setVNCThreadConnection(_myConnection->getVNCConnection()->getVNCClientThread());
            setActive(true);
            setToolTip(userName);
            setTitle(userName);
        }
        else
        {
            setToolTip(userName);
            setTitle(userName);
        }
    }

}

/*
 * We set a new VNCConnection to the pvsmgr with a new quality.
 * To do this, that is very easy. At this point we have already a ruuning
 * Connection between the server an the client. This connection is controlled in a thread.
 * So we disconnect all Qt-Signals on this thread and we terminate the thread.
 * After do this we have to set a new thread(VNCClientThread) and connect the signals again.
 *
 * When you want to read about this, please check the developper's book.
 */
void ConnectionFrame::resetConnectionWithQuality(int quality)
{
	if (getFrame())
	{
		_myConnection->getVNCConnection()->reInitClientWithQuality(quality);
		getFrame()->stopVNCThreadConnection();
		getFrame()->setVNCThreadConnection(_myConnection->getVNCConnection()->getVNCClientThread());
		getFrame()->update();
	}
}

void ConnectionFrame::delDummy()
{
	MainWindow::getConnectionWindow()->removeFromList(this);
}

void ConnectionFrame::on_projection()
{
	MainWindow::getConnectionList()->on_projection();
}

void ConnectionFrame::on_unprojection()
{
	MainWindow::getConnectionList()->on_unprojection();
}

void ConnectionFrame::on_lock()
{
	if (_myConnection->getVNCConnection())
		MainWindow::getConnectionWindow()->lockStation(_myConnection);
}

void ConnectionFrame::on_unlock()
{
	if (_myConnection->getVNCConnection())
		MainWindow::getConnectionWindow()->unlockStation(_myConnection);
}

void ConnectionFrame::on_message()
{
	Dialog msgD;
	QString myString = NULL;
	int result  = msgD.exec();

	if (result == 1)
	{
		myString = MainWindow::getWindow()->getMsgDialog();
		if(!myString.isEmpty())
			MainWindow::getConnectionWindow()->messageStations("BROADCAST",myString);
	}
}

void ConnectionFrame::on_lock_with_message()
{
	Dialog msgD;
	QString myString = NULL;
	int result  = msgD.exec();

	if(result == 1)
	{
		myString = MainWindow::getWindow()->getMsgDialog();
		if(!myString.isEmpty())
		{
			MainWindow::getConnectionWindow()->lockStationsWithMessage(myString);
		}
	}
}

void ConnectionFrame::on_lock_all_with_message()
{
	QString myString = NULL;
	    Dialog msgD;
	    int result  = msgD.exec();

		if(result == 1)
		{
			myString = MainWindow::getWindow()->getMsgDialog();
			if(!myString.isEmpty())
			{
				MainWindow::getConnectionWindow()->lockAllStationsWithMessage(myString);
			}
		}
}

void ConnectionFrame::on_lock_all()
{
	MainWindow::getConnectionWindow()->lockAllStations();
}

void ConnectionFrame::on_unlock_all()
{
	MainWindow::getConnectionWindow()->unlockAllStations();
}

void ConnectionFrame::on_lock_invert()
{
	//MainWindow::getConnectionWindow()->lockInvertStations();
}

void ConnectionFrame::on_remoteHelp()
{

}

void ConnectionFrame::setIgnoreRatio(bool ignore)
{
    ignore_ratio = ignore;
}

void ConnectionFrame::setFullscreen(bool fs)
{
    _fullscreen = fs;
    setIgnoreRatio(!fs);
}

void ConnectionFrame::setCloseup(bool cu)
{
    _closeup = cu;
    setIgnoreRatio(false);
}

void ConnectionFrame::setInteractive(bool doit)
{
    viewOnly = !doit;
}

void ConnectionFrame::setActive(bool activate)
{
    active = activate;
}

void ConnectionFrame::setDummy(bool dummy)
{
        _dummy = dummy;
        if (_dummy)
        {
        	_clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen
        	_clientStatus.fill(Qt::white); // benöigt bevor man  drin zeichen
        	_clientStatus = QPixmap(":/online");
        	_status->setDisabled(true);
        	_status->setMaximumSize(QSize(30, 30));
        	_status->setPixmap(_clientStatus.scaled(29,27,
        		        			           Qt::KeepAspectRatio, Qt::SmoothTransformation));
        	//_status->setPixmap(clientStatus.scaled(3*_status->size()/4,
        		//	                           Qt::KeepAspectRatio, Qt::SmoothTransformation));
            //setConnection(NULL);
        }
        else
        {
        	_clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen
        	_clientStatus.fill(Qt::white); // benöigt bevor man  drin zeichen
        	_clientStatus = QPixmap(":/online");
        	_status->setDisabled(false);
        	_status->setMaximumSize(QSize(30, 30));
        	_status->setPixmap(_clientStatus.scaled(29,27,
        		        			           Qt::KeepAspectRatio, Qt::SmoothTransformation));
        	//_status->setPixmap(clientStatus.scaled(3*_status->size()/4,
        		//	                           Qt::KeepAspectRatio, Qt::SmoothTransformation));
        }
   // }
}

void ConnectionFrame::setFrameRate(int newRate)
{
    //newRate = 5000;
}

void ConnectionFrame::mouseReleaseEvent  ( QMouseEvent * e )
{
	if (e->button() == Qt::LeftButton)
	{
	   QPoint relPoint = mapToParent(e->pos());
	   QRect  r        = MainWindow::getConnectionWindow()->frameGeometry();
	   /*
	    * We don't want to move the client in a position where we can't catch it again!
	    */
	   if (relPoint.x() > r.width() || relPoint.y() > r.height() ||
			   relPoint.x() < 0 || relPoint.y() < 0)
		   move(_previousPoint);
	   QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor));
	}
}

void ConnectionFrame::enterEvent ( QEvent * event )
{
	update();
	QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor));
	if (!_dummy)
		_frame->setToolButtonListVisible(true);
}

void ConnectionFrame::leaveEvent ( QEvent * event )
{
	QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
	if (!_dummy)
			_frame->setToolButtonListVisible(false);
}

void ConnectionFrame::mousePressEvent(QMouseEvent *event)
{
	if (event->button() == Qt::RightButton)
	{
		if (!_dummy)
		{
			DelDummy->setDisabled(true);
			menu->exec(QCursor::pos());
		}
		else
		{
			foreach (QAction* a, menu->actions())
				a->setDisabled(true);
			DelDummy->setDisabled(false);
			menu->exec(QCursor::pos());
		}
	}
	else
	{
	    _clickPoint     = event->pos();
	    _previousPoint  = pos();
	    QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
	}
	/*
	 * On click, the window have to be on the top-level.
	 */
	activateWindow();
	raise();
	update();
}

void ConnectionFrame::mouseMoveEvent(QMouseEvent *event)
{
	QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
	move(mapToParent(event->pos()-_clickPoint));
}

void ConnectionFrame::paintCloseUp(int w, int h)
{
    if (!_frame->image().isNull())
    {
        //move(0,0);
        resize(w, h);
    }
}

void ConnectionFrame::setSource()
{
	_clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen
	_clientStatus.fill(Qt::white); // benöigt bevor man  drin zeichen
	_clientStatus = QPixmap(":/source");
	_status->setMaximumSize(QSize(62, 30));
	_status->setPixmap(_clientStatus.scaled(61,29,
									   Qt::KeepAspectRatio, Qt::SmoothTransformation));
	_isOnProjekt  = true;
}

void ConnectionFrame::setTarget()
{
	_clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen
	_clientStatus.fill(Qt::white); // benöigt bevor man  drin zeichen
	_clientStatus = QPixmap(":/target");
	_status->setMaximumSize(QSize(62, 30));
	_status->setPixmap(_clientStatus.scaled(61,29,
									   Qt::KeepAspectRatio, Qt::SmoothTransformation));
}

void ConnectionFrame::setUnproject()
{
	_clientStatus = QPixmap(0, 0); //ein leeres Pixmap erstellen
	_clientStatus.fill(Qt::white); // benöigt bevor man  drin zeichen
	_clientStatus = QPixmap(":/online");
	_status->setMaximumSize(QSize(30, 30));
	_status->setPixmap(_clientStatus.scaled(29,27,
	        			           Qt::KeepAspectRatio, Qt::SmoothTransformation));
	_isOnProjekt  = false;
}

void ConnectionFrame::setDozent(bool isDozent)
{
	if (isDozent)
		_dozentContaimner->setDisabled(false);
	else
		_dozentContaimner->setDisabled(true);
}

void ConnectionFrame::on_click()
{
	//std::cout << "HALLO! WAS?" << std::endl;
}

const QPixmap* ConnectionFrame::getFramePixmap()
{
	if (_frame == NULL) return NULL;
	return _frame->pixmap();
}

Frame* ConnectionFrame::getFrame()
{
	if(_myConnection && _myConnection->getVNCConnection()) return _frame;
	return NULL;
};

//Frame* ConnectionFrame::_frame 	= NULL;