From 6d6041f03cd0e70563f12d5332050588ad6858e7 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Wed, 16 Apr 2014 18:15:28 +0200 Subject: New feature. Download of tutor-ip-list and automated assingment. TODO: Make source url configurable. --- src/server/mainwindow/mainwindow.cpp | 45 +++++++++++++++++++++++++----------- src/server/mainwindow/mainwindow.h | 4 ++++ 2 files changed, 35 insertions(+), 14 deletions(-) (limited to 'src/server/mainwindow') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 00ac706..b02cef8 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -27,6 +27,7 @@ #include "../net/client.h" #include "../net/discoverylistener.h" #include "../../shared/networkmessage.h" +#include "../net/filedownloader.h" // Others #include "../../shared/settings.h" #include "../util/util.h" @@ -59,6 +60,10 @@ MainWindow::MainWindow(QWidget* parent) : ui->action_Exit->setStatusTip(tr("Exit")); ui->action_Lock->setStatusTip(tr("Lock or Unlock all Clients")); + // Initialize FileDownloader. + _fileDownloader.connectSlot(this, SLOT(onTutorListDownloaded(QByteArray&))); + _fileDownloader.downloadFile(QUrl("http://132.230.8.113/openslx/ips.txt")); + // Close button in tool bar connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(onButtonExit())); connect(ui->action_BroadcastScreen, SIGNAL(triggered()), this, SLOT(onButtonStudentToAll())); @@ -287,6 +292,13 @@ void MainWindow::timerEvent(QTimerEvent* event) * Slots */ +void MainWindow::onTutorListDownloaded(QByteArray& tutorList) +{ + // qDebug() << tutorList; + QString data = QString::fromUtf8(tutorList.constData(), tutorList.size()); + _tutorList = data.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); + qDebug() << _tutorList; +} void MainWindow::onPlaceFrame(ConnectionFrame* frame) { if (_tilesX <= 0 || _tilesY <= 0) @@ -665,29 +677,35 @@ void MainWindow::onClientAuthenticated(Client* client) connect(client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(onVncServerStateChange(Client*)), Qt::QueuedConnection); connect(client, SIGNAL(vncClientStateChange(Client*, int)), this, SLOT(onVncClientStateChange(Client*, int)), Qt::QueuedConnection); bool hasActiveTutor = false; - ConnectionFrame *deadTutor = NULL; - bool anyClient = false; ConnectionFrame *existing = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { if ((*it)->computerId() == client->computerId()) existing = *it; - if ((*it)->client() != NULL) - anyClient = true; if ((*it)->isTutor()) { - if ((*it)->client() == NULL) - deadTutor = *it; - else + if ((*it)->client() != NULL) hasActiveTutor = true; } } - if (!anyClient && deadTutor != NULL) - deadTutor->setTutor(false); + + bool isTutor = false; + if (!hasActiveTutor) + { + for (int i = 0; i < _tutorList.size(); i++) + { + // Check if client is possible tutor + if (client->computerId()== _tutorList[i]) + { + isTutor = true; + break; + } + } + } + if (existing != NULL) { - if (!anyClient && !hasActiveTutor) - existing->setTutor(true); + existing->setTutor(isTutor); existing->assignClient(client); return; } @@ -720,9 +738,8 @@ void MainWindow::onClientAuthenticated(Client* client) // Move to any free tile placeFrameInFreeSlot(cf); } - // Make first active client tutor - if (!anyClient && !hasActiveTutor) - cf->setTutor(true); + // Set Tutor option + cf->setTutor(isTutor); // Assign client instance cf->assignClient(client); // ################ diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 9b6c6d3..5d0bb18 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -4,6 +4,7 @@ #include #include #include "../net/client.h" +#include "../net/filedownloader.h" class SessionNameWindow; class ConnectionFrame; @@ -32,6 +33,8 @@ private: ListenServer *_listenServer; DiscoveryListener *_discoveryListener; qint64 _buttonBlockTime; + FileDownloader _fileDownloader; + QStringList _tutorList; void placeFrameInFreeSlot(ConnectionFrame* frame); ConnectionFrame* createFrame(); @@ -54,6 +57,7 @@ protected: protected slots: // This + void onTutorListDownloaded(QByteArray& tutorList); void onSessionNameClick(); void onSessionNameUpdate(); void onButtonSettings(); -- cgit v1.2.3-55-g7522