summaryrefslogtreecommitdiffstats
path: root/src/gui/projectionDialog.cpp
blob: 32e4651b96022f0d198c6143fd307b858e1f2be9 (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
/*
# 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/
# -----------------------------------------------------------------------------
# projectionDialog.cpp
	Dialog to select client for the projection
# -----------------------------------------------------------------------------
*/

#include "projectionDialog.h"
#include "ui_projectionDialog.h"
#include <src/gui/mainWindow.h>
#include <QtGui>
#include <iostream>

ProjectionDialog::ProjectionDialog(QWidget *parent) :
    QDialog(parent),
    pui(new Ui::projectionDialog)
{
    pui->setupUi(this);
    this->setWindowTitle(tr("Target for Projection"));

    source = MainWindow::getConnectionList()->getSelectedClients()->front();
    setupContent(MainWindow::getWindow()->getConnectionList()->getTargetToDisplay(source));

	pui->send->setDisabled(true);

    connect( pui->send, SIGNAL( clicked() ), this, SLOT( sendListToProject() ) );
    connect( pui->cancel, SIGNAL( clicked() ), this, SLOT( cancelProject() ) );
    connect( pui->checkBox, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
}

ProjectionDialog::~ProjectionDialog()
{
	delete pui;
	QCheckBox* cbox;
	foreach(cbox, checkList)
	{
		disconnect( cbox, SIGNAL( clicked() ), this, SLOT( sendState() ) );
	}
}

void ProjectionDialog::setupContent(QList<QString> content)
{
	if (!content.isEmpty())
	{
		// get a list of all dozent machines
		QStringList dozentList;
		QList<ConnectionFrame*> clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow();
		foreach (ConnectionFrame *client, clients)
			if (client->isDozent())
				dozentList.append(client->getTaskbarTitle());

		QString item;
		foreach(item, content)
		{
			// FIXME: Projection on tutor PC does not work bc. we change his name here...
			// if (dozentList.contains(item)) item.append(" (Tutor PC)");
			QCheckBox *checkbox = new QCheckBox(item,this);
			pui->verticalLayout_2->addWidget(checkbox);
			checkList.push_back(checkbox);
			connect( checkbox, SIGNAL( clicked() ), this, SLOT( sendState() ) );
		}
	}
	else
	{
		QLabel *textInfo = new QLabel(this);
		textInfo->setText("No Target available");
		pui->verticalLayout_2->addWidget(textInfo);
		pui->checkBox->setDisabled(true);
	}
}

void ProjectionDialog::sendListToProject()
{
	MainWindow::getConnectionList()->setProjectProporties(source);
	QCheckBox* cbox;

	foreach(cbox, checkList)
	{
		if (cbox->isChecked())
		{
			MainWindow::getConnectionList()->addTargetToProjectList(cbox->text());
		}
	}
	emit accept();
}

void ProjectionDialog::cancelProject()
{
	emit reject();
}

void ProjectionDialog::sendState()
{
	QCheckBox* cbox;
	bool set = false;

	foreach(cbox, checkList)
	{
		if (cbox->isChecked())
		{
			pui->send->setDisabled(false);
			set = true;
			break;
		}
	}

	if (!set)
		pui->send->setDisabled(true);

}

void ProjectionDialog::selectAll()
{
	if(pui->checkBox->isChecked())
	{
		QCheckBox* cbox;
		foreach(cbox, checkList)
			cbox->setChecked(true);
		pui->send->setDisabled(false);
	}
	else
	{
		QCheckBox* cbox;
		foreach(cbox, checkList)
			cbox->setChecked(false);
		pui->send->setDisabled(true);
	}
}

void ProjectionDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        pui->retranslateUi(this);
        break;
    default:
        break;
    }
}