summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/mainwindow/mainwindow.cpp82
-rw-r--r--src/server/mainwindow/mainwindow.h6
-rw-r--r--src/server/reloadroomwindow/reloadroomwindow.cpp16
-rw-r--r--src/server/reloadroomwindow/reloadroomwindow.h8
4 files changed, 82 insertions, 30 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 7c9d210..17e821a 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -24,6 +24,8 @@
#include "../sessionnamewindow/sessionnamewindow.h"
#include "../connectionframe/connectionframe.h"
#include "../helpwindow/helpwindow.h"
+#include "../reloadroomwindow/reloadroomwindow.h"
+#include "ui_reloadroom.h"
// Network
#include "../net/listenserver.h"
#include "../net/client.h"
@@ -61,6 +63,8 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
_sessionNameWindow = new SessionNameWindow(this);
_helpWindow = new HelpWindow(this);
_helpWindow->setWindowTitle("Help");
+ _reloadWindow = new ReloadRoomWindow(this);
+ _reloadWindow->setWindowTitle("Reload Room");
ui->setupUi(this);
Global::setSessionName();
@@ -312,16 +316,23 @@ void MainWindow::tryToUseRoomTemplate()
for (auto i : rooms)
{
- if (!_rooms.contains(i)) {
- QList<QPair<QString, QPoint>> posIpConfig;
- _rooms.insert(i, posIpConfig);
- }
+ qDebug() << "i: " << i;
conf.beginGroup(i);
if (!conf.contains("mgrIP")) {
qDebug() << "Invalid config file!";
return;
}
- // Find the room that list the ip of this host as mgr
+
+ // First store all room configurations in _rooms.
+ int size = conf.beginReadArray("client");
+ for (int j = 0; j < size; j++) {
+ conf.setArrayIndex(j);
+ // qDebug() << "ip: " << conf.value("ip").toString() << " pos: " << conf.value("pos").toPoint();
+ _rooms[i].append(qMakePair(conf.value("ip").toString(), conf.value("pos").toPoint()));
+ }
+ conf.endArray();
+
+ // Find the managerIP of current room.
QString mgrIP = conf.value("mgrIP").toString();
foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
{
@@ -343,7 +354,6 @@ void MainWindow::tryToUseRoomTemplate()
// Position is given in grid coordinates, createFrame take pixels
QString computerId = conf.value("ip").toString();
QPoint coord = conf.value("pos").toPoint();
- _rooms[i].append(qMakePair(computerId, coord));
qDebug() << computerId;
qDebug() << coord;
qDebug() << _tileWidth ;
@@ -685,9 +695,69 @@ void MainWindow::startVncServerIfNecessary(int from)
void MainWindow::onButtonReloadRoomConfig()
{
+ connect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk()));
+ connect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel()));
+ qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << _rooms.size();
+ QList<QString> keyList = _rooms.keys();
+ for (QList<QString>::iterator it = keyList.begin(); it != keyList.end() ; it++) {
+ _reloadWindow->ui->roomList->addItem(*it);
+ }
_reloadWindow->show();
}
+void MainWindow::onReloadRoomCancel()
+{
+ disconnect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk()));
+ disconnect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel()));
+ _reloadWindow->ui->roomList->clear();
+ _reloadWindow->hide();
+}
+
+void MainWindow::onReloadRoomOk()
+{
+ int ret = QMessageBox::QMessageBox::question(this, "Warning", tr("Are you sure you want to reload the room?\n"
+ "Note that all clients will be deleted."), 0, 1, 2);
+
+ if (ret == 1) {
+ disconnect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk()));
+ disconnect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel()));
+ // Delete all clients.
+ for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); it++)
+ {
+ (*it)->hide();
+ (*it)->deleteLater();
+ }
+ _clientFrames.clear();
+
+ // Load new room configuration.
+ QString roomToReload = _reloadWindow->ui->roomList->currentItem()->data(0).toString();
+ // qDebug() << roomToReload;
+
+ _reloadWindow->ui->roomList->clear();
+ _reloadWindow->hide();
+
+ QList<QPair<QString, QPoint>> room = _rooms[roomToReload];
+ // qDebug() << " Room: " << room;
+ // qDebug() << "_rooms: " << _rooms;
+ for (QList<QPair<QString, QPoint>>::iterator it = room.begin(); it != room.end(); ++it)
+ {
+ QString computerId = (*it).first;
+ QPoint pos = (*it).second;
+
+ qDebug() << "ComputerID: " << computerId;
+ qDebug() << "Pos: " << pos;
+
+ // Transform to pixels for createFrame(computerId, position).
+ pos.setX(pos.x() * _tileWidth);
+ pos.setY(pos.y() * _tileHeight);
+
+ ConnectionFrame *cf = createFrame(computerId, pos);
+ cf->move(cf->getCurrentPosition());
+ onPlaceFrame(false, cf);
+ }
+ }
+}
+
/***************************************************************************//**
* Display popup which explains possible actions about the buttons.
*/
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 5349903..f8d0164 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -11,7 +11,7 @@ class ConnectionFrame;
class ListenServer;
class DiscoveryListener;
class HelpWindow;
-class ReloadWindow;
+class ReloadRoomWindow;
namespace Ui{
class MainWindow;
@@ -36,7 +36,7 @@ private:
Ui::MainWindow *ui;
SessionNameWindow *_sessionNameWindow;
HelpWindow *_helpWindow;
- ReloadWindow *_reloadWindow;
+ ReloadRoomWindow *_reloadWindow;
QLabel *_sessionNameLabel;
int _tbIconSize;
Qt::ToolBarArea _tbArea;
@@ -110,6 +110,8 @@ protected slots:
void onButtonSetAsTutor();
void onButtonReloadRoomConfig();
+ void onReloadRoomOk();
+ void onReloadRoomCancel();
void onButtonExit();
void onButtonHelp();
diff --git a/src/server/reloadroomwindow/reloadroomwindow.cpp b/src/server/reloadroomwindow/reloadroomwindow.cpp
index 77219a7..3070148 100644
--- a/src/server/reloadroomwindow/reloadroomwindow.cpp
+++ b/src/server/reloadroomwindow/reloadroomwindow.cpp
@@ -5,25 +5,9 @@ ReloadRoomWindow::ReloadRoomWindow(QWidget *parent) :
QDialog(parent), ui(new Ui::ReloadRoom)
{
ui->setupUi(this);
- connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onButtonOk()));
- connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onButtonCancel()));
}
ReloadRoomWindow::~ReloadRoomWindow()
{
delete ui;
}
-
-/*
- * Slots
- */
-
-void ReloadRoomWindow::onButtonOk()
-{
-
-}
-
-void ReloadRoomWindow::onButtonCancel()
-{
- this->hide();
-}
diff --git a/src/server/reloadroomwindow/reloadroomwindow.h b/src/server/reloadroomwindow/reloadroomwindow.h
index e918736..9ce0aba 100644
--- a/src/server/reloadroomwindow/reloadroomwindow.h
+++ b/src/server/reloadroomwindow/reloadroomwindow.h
@@ -14,16 +14,12 @@ class ReloadRoomWindow : public QDialog
public:
explicit ReloadRoomWindow(QWidget *parent = 0);
~ReloadRoomWindow();
+ Ui::ReloadRoom *ui;
// void show();
private:
- Ui::ReloadRoom *ui;
-
-
-private slots:
- void onButtonCancel();
- void onButtonOk();
};
+
#endif