summaryrefslogtreecommitdiffstats
path: root/src/gui/connectionWindow.cpp
blob: ec6db1bdadbd867e69f3bb2de672393e1cbb0f65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/*
 # 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/connectionWindow.cpp
 # -----------------------------------------------------------------------------
 */

#include "connectionWindow.h"
#include <src/core/pvsConnectionManager.h>
#include <src/gui/mainWindow.h>

ConnectionWindow::ConnectionWindow(QWidget *parent) :
	QWidget(parent) {

	//initialize the position for the frame in the clientView
	posX = 4;
	posY = 4;

	_closeupFrame = NULL;
	hasDozent    = false; // at the begin we don't have a dozent machine

	QPalette newPalette = palette();
	newPalette.setColor(QPalette::Window, Qt::white);
	setPalette(newPalette);

	newDummy = new QAction(tr("&Add a dummy..."), this); // set a dummy
	connect(newDummy, SIGNAL(triggered()), this, SLOT(addDummy()));

	menu = new QMenu(this);
	menu->addAction(newDummy);

	setAcceptDrops(true); //drag&drop should be enabled

	setStyleSheet("background-color: #DCDCDC;");
}

ConnectionWindow::~ConnectionWindow() {
	//
}

void ConnectionWindow::addFrame(ConnectionFrame *cF) {
	bool found = false;
	foreach (ConnectionFrame* cFr, AllFrameOnWindow)
	{
		if (QString::compare(cF->getTaskbarTitle(), cFr->getTaskbarTitle(), Qt::CaseInsensitive) == 0)
		{
			QPoint cuP = currentPosition(cFr);
			cF->move(cuP);
			AllFrameOnWindow.append(cF);
			AllFrameOnWindow.removeOne(cFr); //we don't need this dummy any more
			cFr->deleteLater();
			found = true;
			return;
		}
	}

	/* If the Frame don't belong to the profile
	 * we have to move it at the default position for now.
	 * The user can move this later to his favorite position.
	 */
	if (!found)
	{
		foreach (clientLocation cur, ClientLocationList)
		{
			if (QString::compare(cF->getTaskbarTitle(), cur.first, Qt::CaseInsensitive) == 0)
			{
				cF->move(cur.second);
				found = true;
				return;
			}
		}
	}

	if (!found)
		cF->move(10, 10);
}

void ConnectionWindow::addFrameBySettings(QString client, QPoint pos) {
	clientLocation cur(client, pos);
	ClientLocationList.append(cur);
}

void ConnectionWindow::showFrameFromSettings() {
	foreach (clientLocation cur, ClientLocationList)
		{
			ConnectionFrame* dummy = new ConnectionFrame(
					MainWindow::getConnectionWindow());
			AllFrameOnWindow.append(dummy);
			dummy->setTheTitle("[No name]");
			dummy->setTaskbarTitle(cur.first);
			dummy->setDummy(true);
			dummy->move(cur.second);
		}
}

void ConnectionWindow::addDummy() { //function to add a dummy
	ConnectionFrame* dummy = new ConnectionFrame(
			MainWindow::getConnectionWindow());
	dummy->setTheTitle("[No name]");
	dummy->setTaskbarTitle("[0.0.0.0]");
	QPoint p = QPoint(10, 10);//the default move position, when created a dummy screen
	AllFrameOnWindow.append(dummy);
	clientLocation cur("[No name]", p);
	ClientLocationList.append(cur);
	dummy->setDummy(true);
	dummy->move(p);
	dummy->setStyleSheet(QString::fromUtf8(
			"background-color: rgb(150, 150, 168);"));
}

void ConnectionWindow::mousePressEvent(QMouseEvent *event) { //catch the mouse press event
	if (event->button() == Qt::RightButton)
		menu->exec(QCursor::pos());
}

QPoint ConnectionWindow::currentPosition(ConnectionFrame* cF) {
	QPoint pos = QPoint(10, 10);
	clientLocation cur;
	foreach (cur, ClientLocationList)
	{
		if (QString::compare(cF->getTaskbarTitle(), cur.first, Qt::CaseInsensitive) == 0)
			return cur.second;
	}
	return pos;
}

int ConnectionWindow::itemAt(ConnectionFrame* cf)
{
	for (int i = AllFrameOnWindow.size() - 1; i >= 0; --i)
	{
		ConnectionFrame* item = AllFrameOnWindow.at(i);
		if (cf->pos().x() == item->pos().x() && cf->pos().y() == item->pos().y())
			return i;
	}
	return -1;
}

void ConnectionWindow::removeFromList(ConnectionFrame* cF) {
	//dummyList.removeOne(cF);
	if(AllFrameOnWindow.contains(cF))
		AllFrameOnWindow.removeOne(cF);
	cF->deleteLater();
}

void ConnectionWindow::onChangeConnections() {

	//clear the view
	if (!frameList.empty()) {
		ConnectionFrame* tmpIt;
		foreach (tmpIt, frameList)
			{
				if (tmpIt != currentSingleFrame)
					tmpIt->setActive(false);
				tmpIt->hide();
			}
	}

}

bool ConnectionWindow::projectStations(QString sname) {
	QString password, hostname;
	int port, quality;
	ConsoleLog writeLine(QString("Projecting from: ").append(sname));
	//TODO add method parameter for this
	quality = 0;

	QList<QString> projectList =
			MainWindow::getConnectionList()->getTargetForTheProject(sname);

	if (!projectList.isEmpty()) {
		PVSClient* tmpSrcConnection =
				PVSConnectionManager::getManager()->getClientFromIp(sname);
		if (tmpSrcConnection) {
			if (!tmpSrcConnection->getVNCAllowed()) {
				ConsoleLog writeError(QString("VNC is not allowed on Projection Source: ").append(sname));
				ConsoleLog writeError(QString("Trying to start VNC-Server on Client: ").append(sname));
				tmpSrcConnection->setProject(true);
				return false;
			}
			password = tmpSrcConnection->getPassword();
			port = tmpSrcConnection->getPort();
			hostname = sname;
			tmpSrcConnection->getConnectionFrame()->setSource();
			ConsoleLog writeError (QString("port: ").append(int2String(port)));
			ConsoleLog writeError (QString("passwort: ").append(password));
			ConsoleLog writeError (QString("pr-sourcename: ").append(sname));

		}
		else
		{
			return false;
		}

		ConsoleLog writeError (QString("port as int: ").append(port));
		ConsoleLog writeError (QString("port as String: ").append(int2String(port)));

		QString item;
		foreach (item, projectList)
		{
			PVSClient* tmpConnection = PVSConnectionManager::getManager()->getClientFromIp(item);
			if (tmpConnection)
			{
				ConsoleLog writeError (QString("sending vnc data to: ").append(tmpConnection->getIp()));
				tmpConnection->sendMessage(PVSCOMMAND,"PROJECT", hostname + " " + int2String(port) + " " + password + " " + int2String(quality));
				tmpConnection->getConnectionFrame()->setTarget();
			}
			else
			{
				// scream in agony
			}
		}
	}
	return true;
}

bool ConnectionWindow::remoteHelp(QString sname) {

	//TODO Finish this...
	QString password, hostname;
	int port;

	PVSClient* tmpSrcConnection =
			PVSConnectionManager::getManager()->getClientFromIp(sname);
	QList<QString> projectList =
			MainWindow::getConnectionList()->getTargetForTheProject(sname);
	if (tmpSrcConnection) {
		if (!tmpSrcConnection->getVNCAllowed()) {
			tmpSrcConnection->requestVNCConnect();
			tmpSrcConnection->setProject(true);
			return false;
		}
		password = tmpSrcConnection->getRWPassword();
		port = tmpSrcConnection->getPort();
		hostname = sname;
		tmpSrcConnection->getConnectionFrame()->setSource();
	} else {
		return false;
	}

	QString item;
	foreach (item, projectList)
		{
			PVSClient
					* tmpConnection =
							PVSConnectionManager::getManager()->getClientFromIp(item);
			if (tmpConnection) {
				ConsoleLog writeError(QString("sending vnc data to: ").append(
						tmpConnection->getIp()));
				tmpConnection->sendMessage(PVSCOMMAND, "PROJECT", hostname
						+ " " + int2String(port) + " " + password);
				tmpConnection->getConnectionFrame()->setTarget();
			} else {
				// scream in agony
			}
		}
	return true;

}



bool ConnectionWindow::lockStations() {
	if (std::list<QString>* lockList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!lockList->empty()) {
			for (std::list<QString>::iterator tmpIt = lockList->begin(); tmpIt
					!= lockList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				if (tmpConnection->getConnectionFrame()->getFrame())
				{
					// we don't want to lock the dozent machine
					if (tmpConnection && !tmpConnection->getConnectionFrame()->getFrame()->isDozent()
								  && !tmpConnection->getConnectionFrame()->isOnProjekt())
						lockStation(tmpConnection);
					else {
						// scream in agony
					}
				}
			}
		}
		delete lockList;
	}
	return true;
}

void ConnectionWindow::lockStation(PVSClient* pvsCon) {
	if (pvsCon->getVNCConnection())
	{
		pvsCon->getConnectionFrame()->getFrame()->setLockStatus(true);
		// we call the update to force Qt to paint the lockicon on the frame
		pvsCon->getConnectionFrame()->getFrame()->update();
		pvsCon->sendMessage(PVSCOMMAND, "LOCKSTATION", "");
	}
}

bool ConnectionWindow::unlockStations() {
	if (std::list<QString>* unlockList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!unlockList->empty()) {
			for (std::list<QString>::iterator tmpIt = unlockList->begin(); tmpIt
					!= unlockList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				if (tmpConnection && tmpConnection->getConnectionFrame()->getFrame() &&
					tmpConnection->getVNCConnection()) {
					tmpConnection->getConnectionFrame()->getFrame()->setLockStatus(false);
					tmpConnection->getConnectionFrame()->getFrame()->update(); // we call the update to force Qt to paint the lock on the frame
					tmpConnection->sendMessage(PVSCOMMAND, "UNLOCKSTATION", "");
				} else {
					// scream in agony
				}
			}
		}
		delete unlockList;
	}
	return true;
}

void ConnectionWindow::unlockStation(PVSClient* pvsCon) {
	if (pvsCon->getVNCConnection())
	{
		pvsCon->getConnectionFrame()->getFrame()->setLockStatus(false);
		// we call the update to force Qt to paint the lockicon on the frame
		pvsCon->getConnectionFrame()->getFrame()->update();
		pvsCon->sendMessage(PVSCOMMAND, "UNLOCKSTATION", "");
	}
}

bool ConnectionWindow::lockAllStations()
{
	if (!hasDozent)
	{
		QString message = QString(tr("You have to set a Superclient-machine before performing this action."));
		QMessageBox::information(this, "PVS", message);
		return false;
	}
	std::list<PVSClient*> listAll =
			PVSConnectionManager::getManager()->getConnections();
	for (std::list<PVSClient*>::iterator it = listAll.begin(); it
			!= listAll.end(); it++)
	{
		if (*it == NULL || (*it)->getConnectionFrame() == NULL) continue;
		// we don't want to lock the superclient machine
		if ((*it)->getConnectionFrame()->getFrame() &&
				!(*it)->getConnectionFrame()->getFrame()->isDozent() &&
				(*it)->getVNCConnection())
			(*it)->sendMessage(PVSCOMMAND, "LOCKSTATION", "");
		else if (!(*it)->getConnectionFrame()->getFrame())
			ConsoleLog writeError(QString("The Frame connection from client: ").
					append((*it)->getConnectionFrame()->getTaskbarTitle()).
					append(QString(" is corrupted. Reconned the client it again.")));
	}
	return true;
}

bool ConnectionWindow::unlockAllStations() {
	std::list<PVSClient*> listAll =
			PVSConnectionManager::getManager()->getConnections();
	for (std::list<PVSClient*>::iterator it = listAll.begin(); it
			!= listAll.end(); it++)
	{
		if ((*it)->getVNCConnection())
		{
			(*it)->getConnectionFrame()->getFrame()->setLockStatus(false);
			(*it)->getConnectionFrame()->getFrame()->update(); // we call the update to force Qt to repaint the frame
			(*it)->sendMessage(PVSCOMMAND, "UNLOCKSTATION", "");
		}
		// otherwise this will get scattered all over the place
	}
	return true;
}

bool ConnectionWindow::unprojectStations(QString sname) {
	PVSClient* tmpConnection =
			PVSConnectionManager::getManager()->getClientFromIp(sname);
	if (tmpConnection && tmpConnection->getVNCConnection()) {
		tmpConnection->sendMessage(PVSCOMMAND, "UNPROJECT", "");
		tmpConnection->getConnectionFrame()->setUnproject();
	} else {
		// scream in agony
	}

	return true;
}

bool ConnectionWindow::unprojectAllStations() {
	std::list<PVSClient*> listAll =
			PVSConnectionManager::getManager()->getConnections();
	for (std::list<PVSClient*>::iterator it = listAll.begin(); it
			!= listAll.end(); it++)
	{
		if ((*it)->getVNCConnection())
		{
			(*it)->sendMessage(PVSCOMMAND, "UNPROJECT", "");
			(*it)->getConnectionFrame()->setUnproject();
		}
	}
	return true;
}

bool ConnectionWindow::lockInvertStations() {
	// ok, this method is highly imperformant i guess
	// we're going thru all existing connections, and if they dont equal one of the selected (another loop)
	// we lock them...
	if (std::list<QString>* lockList = MainWindow::getConnectionList()->getSelectedClients()) {
		std::list<PVSClient*> listAll =
				PVSConnectionManager::getManager()->getConnections();
		bool skip = false;
		for (std::list<PVSClient*>::iterator it = listAll.begin(); it
				!= listAll.end(); it++) {
			if (!lockList->empty()) {
				for (std::list<QString>::iterator tmpIt = lockList->begin(); tmpIt
						!= lockList->end(); tmpIt++) {
					PVSClient
							* tmpConnection =
									PVSConnectionManager::getManager()->getClientFromIp(
											(*tmpIt).toUtf8().data());
					if (tmpConnection == (*it)) {
						skip = true;
						break;
					}
				}
			}
			if (!skip)
				(*it)->sendMessage(PVSCOMMAND, "LOCKSTATION", "");//TODO define some standard to grab this from...
			// otherwise this will get scattered all over the place
		}
		delete lockList;
	}
	return true;
}

void ConnectionWindow::lockInvertStation(PVSClient* pvsCon) {
	pvsCon->sendMessage(PVSCOMMAND, "LOCKSTATION", "");
}

bool ConnectionWindow::messageStations(QString ident, QString message) {
	if (std::list<QString>* messageList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!messageList->empty()) {
			for (std::list<QString>::iterator tmpIt = messageList->begin(); tmpIt
					!= messageList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				// we don't want to lock the dozent machine
				if (tmpConnection && tmpConnection->getConnectionFrame()->getFrame() &&
						!tmpConnection->getConnectionFrame()->getFrame()->isDozent())
				{
					messageStation(ident, message, tmpConnection);
				} else {
					// scream in agony
				}
			}
		}
		delete messageList;
	}
	return true;
}

void ConnectionWindow::messageStation(QString ident, QString message,
		PVSClient* pvsCon) {
	pvsCon->sendMessage(PVSMESSAGE, ident, message);
}

/*
 * to send COMMAND instead of PVSMESSaGE
 */
bool ConnectionWindow::commandStations(QString ident, QString message) {
	if (std::list<QString>* messageList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!messageList->empty()) {
			for (std::list<QString>::iterator tmpIt = messageList->begin(); tmpIt
					!= messageList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				// we don't want to lock the dozent machine
				if (tmpConnection && tmpConnection->getConnectionFrame()->getFrame() &&
						!tmpConnection->getConnectionFrame()->getFrame()->isDozent())
				{
					//messageStation(ident, message, tmpConnection);
					tmpConnection->sendMessage(PVSCOMMAND, ident, message);
				} else {
					// scream in agony
				}
			}
		}
		delete messageList;
	}
	return true;
}


bool ConnectionWindow::lockStationsWithMessage(QString message)
{
	if (!hasDozent)
	{
		QString message = QString(tr("You have to set a Superclient-machine before performing this action."));
		QMessageBox::information(this, "PVS", message);
		return false;
	}
	if (std::list<QString>* messageList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!messageList->empty()) {
			for (std::list<QString>::iterator tmpIt = messageList->begin(); tmpIt
					!= messageList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				// we don't want to lock the dozent machine
				if (tmpConnection && !tmpConnection->getConnectionFrame()->getFrame()->isDozent())
				{
					lockStationsWithMessage(message, tmpConnection);

				} else {
					// scream in agony
				}
			}
		}
		delete messageList;
	}
	return true;
}

void ConnectionWindow::lockStationsWithMessage(QString message,
		PVSClient* pvsCon)
{
	pvsCon->sendMessage(PVSCOMMAND, "LOCKSTATION", message);
}

bool ConnectionWindow::lockAllStationsWithMessage(QString message) {

	if (!hasDozent)
	{
		QString message = QString(tr("You have to set a Superclient-machine before performing this action."));
		QMessageBox::information(this, "PVS", message);
		return false;
	}
	std::list<PVSClient*> listAll =
			PVSConnectionManager::getManager()->getConnections();
	for (std::list<PVSClient*>::iterator it = listAll.begin(); it
			!= listAll.end(); it++)
	{
		if ((*it) && !(*it)->getConnectionFrame()->getFrame()->isDozent()) // we don't want to lock the dozent machine
			(*it)->sendMessage(PVSCOMMAND, "LOCKSTATION", message);
	}
	return true;
}

void ConnectionWindow::addConnection(PVSClient* newCon) {
	if (newCon) {
		//  QList<QString> ClientList= MainWindow::getConnectionList()->getClientist();

		//Check if this client already in the list, before we add it.
		//We don't want to have two clients with the same names.
		//We comments it for test.
		/*if (!ClientList.contains(newCon->getHostString()))
		 {*/
		onVNCAdd(newCon);
		MainWindow::getConnectionList()->onAddClient(newCon);
		/*
		 * We check if the pvsmgr run a lockAll on the already connected
		 * clients. If yes, we lock the new conencted client too.
		 */
		if (MainWindow::getWindow()->isLockAllStatus() && newCon->getConnectionFrame()->getFrame())
		{
			newCon->getConnectionFrame()->getFrame()->setLockStatus(true);
			// we call the update to force Qt to paint the lockicon on the frame
			newCon->getConnectionFrame()->getFrame()->update();
			lockStation(newCon);
		}
		//}
	}
}

void ConnectionWindow::removeConnection(PVSClient* newCon) {
	if (newCon == NULL) return;
	ConnectionFrame* frame = newCon->getConnectionFrame();
	if (frame != NULL)
	{
		removeFromList(frame);
		//frame->deleteLater();
	}
	MainWindow::getConnectionList()->onRemoveClient(newCon);
}

void ConnectionWindow::onView() {
	if (std::list<QString>* selectedClient = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!selectedClient->empty()) {
			if (selectedClient->size() == 1)
				;//TODO

		}
	}
}

void ConnectionWindow::updateConnection(PVSClient* newCon) {
	if (newCon) {
		MainWindow::getConnectionList()->onUpdateClient(newCon);
	}
}

void ConnectionWindow::addVNC() {
	if (std::list<QString>* vncAddList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!vncAddList->empty()) {
			for (std::list<QString>::iterator tmpIt = vncAddList->begin(); tmpIt
					!= vncAddList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				if (tmpConnection) {
					tmpConnection->requestVNCConnect();
				} else {
					// scream in agony
				}
			}
		}
	}
}

void ConnectionWindow::onVNCAdd(PVSClient* newCon) {

	if (!newCon->getConnectionFrame()) {
		ConnectionFrame* newFrame = newConFrame(newCon);
		newFrame->setConnection(newCon);
		newFrame->setTaskbarTitle(newFrame->getTaskbarTitle());
		newFrame->setDummy(false);
		newFrame->setFrameRate(500);
		addFrame(newFrame);
		if (!frameList.contains(newFrame))
			frameList.append(newFrame);
		if (!AllFrameOnWindow.contains(newFrame))
			AllFrameOnWindow.append(newFrame);
		newFrame->show();
	} else
		// now we have already a pvsconnection, we should set the existing vncconnection to it
		newCon->getConnectionFrame()->setConnection(newCon);
	//	addFrame(newFrame);
}

void ConnectionWindow::removeVNC() {
	std::list<QString>* vncRemoveList =
			MainWindow::getConnectionList()->getSelectedClients();

	//	if(!vncRemoveList->empty())
	//	{
	for (std::list<QString>::iterator tmpIt = vncRemoveList->begin(); tmpIt
			!= vncRemoveList->end(); tmpIt++) {
		PVSClient* tmpConnection =
				PVSConnectionManager::getManager()->getClientFromIp(
						(*tmpIt).toUtf8().data());
		if (tmpConnection) {
			if (tmpConnection->getVNCConnection()) {
				ConnectionFrame* tmpFrame =
						tmpConnection->getVNCConnection()->getFrame();
				if (tmpFrame) {
					frameList.removeOne(tmpFrame);
					onChangeConnections();
					tmpFrame->setConnection(NULL);
					tmpFrame->initFrame();
					//delete tmpFrame;
				}
				tmpConnection->shutDownVNC();
			}
		} else {
			// scream in agony
		}
	}
	//
	//	}
}

void ConnectionWindow::onRemoveConnection() {
	if (std::list<QString>* removeList = MainWindow::getConnectionList()->getSelectedClients()) {
		if (!removeList->empty()) {
			for (std::list<QString>::iterator tmpIt = removeList->begin(); tmpIt
					!= removeList->end(); tmpIt++) {
				PVSClient
						* tmpConnection =
								PVSConnectionManager::getManager()->getClientFromIp(
										(*tmpIt).toUtf8().data());
				if (tmpConnection) {
					// removal should start from the CM, so hes linking back to the ConnectionWindow::onConnectionRemoved() method
					// to finish the removal procedure here
					PVSConnectionManager::getManager()->removeConnection(
							tmpConnection);
				} else {
					// scream in agony
				}
			}
			//			onChangeConnections();
		}
		delete removeList;
		return;
	}
}

void ConnectionWindow::onConnectionRemoved(PVSClient* newConnection) {


	if (newConnection->getVNCConnection())

		// check for associated frames!
		if (newConnection->getVNCConnection()) {
			ConnectionFrame* tmpFrame =
					newConnection->getVNCConnection()->getFrame();
			// now handle the case that the client disconnects while we are in fullscreen mode
			// the vncconnection would be cut nevertheless, so this:
			if (tmpFrame) {
				frameList.removeOne(tmpFrame);
				// now handle the case that the client disconnects while we are in fullscreen mode
				// the vncconnection would be cut nevertheless, so this:
				if (tmpFrame == currentSingleFrame) {
					currentSingleFrame = NULL;
				}

				// no longer needed
				delete tmpFrame;
				newConnection->getVNCConnection()->setFrame(NULL);
			}
		}
}

void ConnectionWindow::setSize(int width, int height, bool forceSquare) {
	if (height >= 100 && width >= 100) {
		MainWindow::getWindow()->setPrevWidth(width);
		MainWindow::getWindow()->setPrevHeight(height);
	}

	ignoreRatio = forceSquare;

	if (!frameList.empty()) {
		ConnectionFrame* item;
		foreach (item, frameList)
			{
				item->setIgnoreRatio(ignoreRatio);
			}
	}
}

void ConnectionWindow::getCloseupSize(int &width, int &height) {
	if (!onCloseup) {
		width = height = 0;
		return;
	}

	width = 150;
	height = 150;
}

bool ConnectionWindow::getShowDummies() {
	return _showDummies;
}

void ConnectionWindow::setShowDummies(bool show) {

}

ConnectionFrame* ConnectionWindow::newConFrame(PVSClient* newConnection) {
	if (newConnection->getConnectionFrame()) {
		return NULL;
	}
	ConnectionFrame* temp = new ConnectionFrame(
			MainWindow::getConnectionWindow());
	if (!temp) {
		return NULL;
	}
	return temp;
}

void ConnectionWindow::setCloseupFrame(ConnectionFrame* cFrame) {
	_closeupFrame = cFrame;
}

ConnectionFrame* ConnectionWindow::getCloseupFrame() {
	if (_closeupFrame)
		return _closeupFrame;

	return NULL;
}