summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-09-27 15:38:39 +0200
committerChristian Klinger2016-09-27 15:38:39 +0200
commit1f6493e319016f8c375b62f2109ee57f5cea828d (patch)
treeac1635d23eaaf7090f6cc21767536ddcc9c76dae /src/server/mainwindow/mainwindow.cpp
parentclients in exam-mode no longer send a screenshot. Also some refactoring. (diff)
downloadpvs2-1f6493e319016f8c375b62f2109ee57f5cea828d.tar.gz
pvs2-1f6493e319016f8c375b62f2109ee57f5cea828d.tar.xz
pvs2-1f6493e319016f8c375b62f2109ee57f5cea828d.zip
Implemented 'majority vote' to determine the toolbar options.
clients in exam-mode are also displayed differently.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp84
1 files changed, 64 insertions, 20 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index ae83dfb..ff34911 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -102,6 +102,15 @@ MainWindow::MainWindow(QWidget* parent) :
ui->action_Exit->setStatusTip(tr("Exit"));
ui->action_Lock->setStatusTip(tr("Lock or Unlock all Clients"));
+ /* the label */
+ _examModeLabel = new QLabel("Klausur-\nModus");
+ _examModeLabel->setObjectName("examModeLabel");
+ _examModeLabel->setAlignment(Qt::AlignCenter);
+ _examModeLabel->setFixedHeight(400);
+ ui->toolBar->insertWidget(ui->action_TutorToStudent, _examModeLabel);
+
+ Global::setExam(false);
+ updateExamMode();
// Close button in tool bar
connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(onButtonExit()));
@@ -117,26 +126,11 @@ MainWindow::MainWindow(QWidget* parent) :
connect(ui->actionReload_Room_Configuration, SIGNAL(triggered()), this, SLOT(onButtonReloadRoomConfig()));
connect(ui->action_DeleteClient, SIGNAL(triggered()), this, SLOT(onDeleteClient()));
- /* In exam-mode: disable most features */
- QSharedPointer<QSettings> conf = Global::getSettings();
- if (conf->contains("examMode")) {
- Global::setExam(conf->value("examMode").toBool());
- }
-
- if (Global::isExam()) {
- qDebug() << "Exam-Mode!";
- ui->action_TutorToAll->setVisible(false);
- ui->action_StudentToTutor->setVisible(false);
- ui->action_StudentToTutorExclusive->setVisible(false);
- ui->action_TutorToStudent->setVisible(false);
- ui->action_StopProjection->setVisible(false);
-
- QLabel* examModeLabel = new QLabel("Klausur-\nModus");
- examModeLabel->setObjectName("examModeLabel");
- examModeLabel->setAlignment(Qt::AlignCenter);
- examModeLabel->setFixedHeight(400);
- ui->toolBar->insertWidget(ui->action_TutorToStudent, examModeLabel);
- }
+ // /* In exam-mode: disable most features */
+ // QSharedPointer<QSettings> conf = Global::getSettings();
+ // if (conf->contains("examMode")) {
+ // Global::setExam(conf->value("examMode").toBool());
+ // }
/* disable context-sensitive buttons by default */
@@ -186,6 +180,48 @@ MainWindow::MainWindow(QWidget* parent) :
tryToUseRoomTemplate();
}
+/** this function determines if the number of clients in exam mode comprise
+* more than 50%. In that case the whole manager switches to exam mode,
+* disabling many features in the toolbar **/
+void MainWindow::updateExamMode() {
+ /* TODO */
+ int numerator = 0;
+ int denominator = 0;
+
+
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
+ Client* c = (*it)->client();
+ if (c != NULL) {
+ bool b = c->isExamMode();
+ numerator += b ? 1 : 0;
+ denominator++;
+ }
+
+ }
+ qDebug() << "updateExamMode(), ratio: " << numerator << "/" << denominator;
+
+ /* TODO: Find clients */
+ // static const QMap<QString, Room*> rooms = getRooms();
+ // for (auto k : rooms.keys()) {
+ // Room* r = rooms.value(k);
+ // numerator += r->examMode;
+ // denominator++;
+ // }
+ Global::setExam(numerator * 2 >= denominator && denominator > 0);
+ bool e = Global::isExam();
+ qDebug() << "isExam is " << e;
+ ui->action_TutorToAll->setVisible(!e);
+ ui->action_StudentToTutor->setVisible(!e);
+ ui->action_StudentToTutorExclusive->setVisible(!e);
+ ui->action_TutorToStudent->setVisible(!e);
+ ui->action_StopProjection->setVisible(!e);
+ _examModeLabel->setVisible(e);
+ _examModeLabel->setFixedHeight(e ? 400 : 0);
+
+
+
+}
+
MainWindow::~MainWindow()
{
_sessionNameLabel->deleteLater();
@@ -1184,6 +1220,9 @@ void MainWindow::onClientConnected(Client* client)
void MainWindow::onClientAuthenticating(Client* client, ClientLogin* request)
{
disconnect(client, SIGNAL(authenticating(Client*, ClientLogin*)), this, SLOT(onClientAuthenticating(Client*, ClientLogin*)));
+ /* copy examMode */
+ client->setExamMode(request->examMode);
+
if (!request->accept) // Another receiver of that signal already rejected the client, so nothing to do
return;
bool inuse;
@@ -1251,6 +1290,7 @@ void MainWindow::onClientAuthenticated(Client* client)
}
}
+
bool isTutor = false;
if (!hasActiveTutor)
{
@@ -1271,6 +1311,7 @@ void MainWindow::onClientAuthenticated(Client* client)
existing->setTutor(isTutor);
existing->assignClient(client);
tellClientCurrentSituation(client);
+ updateExamMode();
return;
}
@@ -1307,6 +1348,7 @@ void MainWindow::onClientAuthenticated(Client* client)
resizeEvent(NULL); // This is where all the positioning should be
tellClientCurrentSituation(client);
+ updateExamMode();
}
@@ -1448,9 +1490,11 @@ void MainWindow::onDeleteClient() {
frame->deleteLater();
_clientFrames.removeOne(frame);
lockContextButtons();
+ updateExamMode();
return;
} else {
frame->move(frame->getPreviousPosition());
+ updateExamMode();
return;
}
}