summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-04-16 18:15:28 +0200
committerBjörn Hagemeister2014-04-16 18:15:28 +0200
commit6d6041f03cd0e70563f12d5332050588ad6858e7 (patch)
treec8777d1421062c15d99c804aa2aa56142822876b
parentChanged exit text to be "exit?" instead of "Beenden?". (diff)
downloadpvs2-6d6041f03cd0e70563f12d5332050588ad6858e7.tar.gz
pvs2-6d6041f03cd0e70563f12d5332050588ad6858e7.tar.xz
pvs2-6d6041f03cd0e70563f12d5332050588ad6858e7.zip
New feature. Download of tutor-ip-list and automated assingment.
TODO: Make source url configurable.
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/server/mainwindow/mainwindow.cpp45
-rw-r--r--src/server/mainwindow/mainwindow.h4
-rw-r--r--src/server/net/filedownloader.cpp36
-rw-r--r--src/server/net/filedownloader.h44
5 files changed, 116 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c68b274..6842581 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -81,6 +81,7 @@ SET(PVSMGR_MOC_HDRS
src/server/clicklabel/clicklabel.h
src/server/connectionframe/connectionframe.h
src/server/mainwindow/mainwindow.h
+ src/server/net/filedownloader.h
src/server/sessionnamewindow/sessionnamewindow.h
src/server/net/sslserver.h
src/server/net/listenserver.h
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<ConnectionFrame*>::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 <QtGui>
#include <QMainWindow>
#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();
diff --git a/src/server/net/filedownloader.cpp b/src/server/net/filedownloader.cpp
new file mode 100644
index 0000000..70e1520
--- /dev/null
+++ b/src/server/net/filedownloader.cpp
@@ -0,0 +1,36 @@
+/*
+ * FileDownloader.cpp
+ *
+ * Created on: Mar 7, 2014
+ * Author: nils
+ */
+
+#include <QFileInfo>
+
+#include "filedownloader.h"
+
+FileDownloader::FileDownloader(QObject *parent) :
+ QObject(parent) {
+ connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
+ SLOT(fileDownloaded(QNetworkReply*)));
+}
+
+FileDownloader::~FileDownloader() {
+
+}
+
+void FileDownloader::connectSlot(QObject* obj, const char* slot) {
+ QObject::connect(this, SIGNAL(downloaded(QByteArray&)),
+ obj, slot);
+}
+
+void FileDownloader::fileDownloaded(QNetworkReply* pReply) {
+ QByteArray downloadedData = pReply->readAll();
+ //emit a signal
+ pReply->deleteLater();
+ emit downloaded(downloadedData);
+}
+
+void FileDownloader::downloadFile(const QUrl& fileUrl) {
+ m_WebCtrl.get(QNetworkRequest(fileUrl));
+}
diff --git a/src/server/net/filedownloader.h b/src/server/net/filedownloader.h
new file mode 100644
index 0000000..68eaa39
--- /dev/null
+++ b/src/server/net/filedownloader.h
@@ -0,0 +1,44 @@
+/*
+ * filedownloader.h
+ *
+ * Created on: Mar 7, 2014
+ * Author: nils
+ */
+
+#ifndef FILEDOWNLOADER_H_
+#define FILEDOWNLOADER_H_
+
+#include <QObject>
+#include <QByteArray>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+
+class FileDownloader : public QObject
+{
+ Q_OBJECT
+public:
+ explicit FileDownloader(QObject *parent = 0);
+
+ virtual ~FileDownloader();
+
+ void downloadFile(const QUrl& fileUrl);
+
+ void connectSlot(QObject* obj, const char* slot);
+
+ QByteArray downloadedData() const;
+
+signals:
+ void downloaded(QByteArray& downloadedData);
+
+private slots:
+
+ void fileDownloaded(QNetworkReply* pReply);
+
+private:
+
+ QNetworkAccessManager m_WebCtrl;
+
+};
+
+#endif /* FILEDOWNLOADER_H_ */