summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-08-01 18:40:26 +0200
committerSimon Rettberg2018-08-01 18:40:26 +0200
commit4d4d3dadfb0614471aa949b8fa66b07ee6b3a289 (patch)
tree47e2864dec4b60176329f007035db679e47c77b1
parent[server] Fix message box when deleting client (diff)
downloadpvs2-4d4d3dadfb0614471aa949b8fa66b07ee6b3a289.tar.gz
pvs2-4d4d3dadfb0614471aa949b8fa66b07ee6b3a289.tar.xz
pvs2-4d4d3dadfb0614471aa949b8fa66b07ee6b3a289.zip
[server] Improved disabling of toolbar buttons depending on context
* Disable tutor to student / student to tutor if no tutor online * Disable above buttons if selected frame is tutor * Disable lock single client button if selected client is tutor ... And many more Closes #3399
-rw-r--r--src/server/mainwindow/mainwindow.cpp125
-rw-r--r--src/server/mainwindow/mainwindow.h8
2 files changed, 56 insertions, 77 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index e23e755..a7648b9 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -110,7 +110,6 @@ MainWindow::MainWindow(QWidget* parent) :
ui->toolBar->insertWidget(ui->action_TutorToStudent, _examModeLabel);
serverApp->setExam(false);
- clientCountChanged();
// Close button in tool bar
connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(onButtonExit()));
@@ -127,37 +126,23 @@ 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());
- // }
-
- /* disable context-sensitive buttons by default */
- _contextButtons
- << ui->action_DeleteClient
- << ui->action_StudentToTutor
- << ui->action_StudentToTutorExclusive
- << ui->action_SetAsTutor
- << ui->action_TutorToStudent
- << ui->action_LockSingle;
-
- lockContextButtons();
-
/* Stuff for the button lock */
//Setup a timeout
_buttonLockTimer = new QTimer(this);
_buttonLockTimer->setSingleShot(true);
- _buttonLockTimer->setInterval(_buttonBlockTime);
+ _buttonLockTimer->setInterval(BUTTON_BLOCK_TIME);
connect(_buttonLockTimer, SIGNAL(timeout()), this, SLOT(enableButtons()));
// Define the locking buttons
_lockingButtons
+ << ui->action_DeleteClient
+ << ui->action_StudentToTutor
+ << ui->action_StudentToTutorExclusive
+ << ui->action_SetAsTutor
+ << ui->action_TutorToStudent
+ << ui->action_LockSingle
<< ui->action_Lock
- << ui->action_TutorToAll
- << ui->action_StudentToTutor
- << ui->action_TutorToStudent
- << ui->action_StopProjection
- << ui->action_SetAsTutor;
+ << ui->action_TutorToAll
+ << ui->action_StopProjection;
// Clicking the session name label shows the edit field for it
connect(_sessionNameLabel, SIGNAL(clicked()), this, SLOT(onSessionNameClick()));
@@ -221,6 +206,9 @@ void MainWindow::clientCountChanged()
// Remember client count
_lastClientCount = clientCount;
}
+ // Also we might have to enable/disable buttons in the toolbar if the
+ // client frame is currently selected
+ updateContextButtonStates();
}
MainWindow::~MainWindow()
@@ -544,33 +532,27 @@ void MainWindow::resizeEvent(QResizeEvent* /* e */ )
}
}
-
-void MainWindow::lockContextButtons()
+void MainWindow::updateContextButtonStates()
{
- for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
- (*it)->setEnabled(false);
- }
+ if (_buttonLockTimer->isActive()) // If buttons are disabled for cooldown, don't do anything
+ return;
+ const ConnectionFrame *selected = getSelectedFrame();
+ const ConnectionFrame *tutor = getTutorFrame();
+ const bool somethingSelected = (selected != nullptr);
+ const bool selectedOnline = (selected != nullptr && selected->client() != nullptr);
+ const bool tutorOnline = (tutor != nullptr && tutor->client() != nullptr);
+ // Deletion only for offline clients, tutor if anything is selected, locking only for online clients
+ ui->action_DeleteClient->setEnabled(somethingSelected && !selectedOnline);
+ ui->action_SetAsTutor->setEnabled(somethingSelected);
+ ui->action_LockSingle->setEnabled(selectedOnline && selected != tutor);
+ // Don't allow projection to self
+ ui->action_StudentToTutorExclusive->setEnabled(somethingSelected && selected != tutor && tutorOnline);
+ ui->action_StudentToTutor->setEnabled(somethingSelected && selected != tutor && tutorOnline);
+ ui->action_TutorToStudent->setEnabled(somethingSelected && selected != tutor && tutorOnline);
+ // Only allow tutor broadcast if they're online
+ ui->action_TutorToAll->setEnabled(tutorOnline);
}
-void MainWindow::unlockContextButtons()
-{
- for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
- (*it)->setEnabled(true);
- }
- /* and disable some again based on special rules */
- if (getSelectedFrame()->client() != nullptr) {
- ui->action_DeleteClient->setEnabled(false);
- }
- if (getSelectedFrame()->client() == nullptr) {
- ui->action_SetAsTutor->setEnabled(false);
- ui->action_StudentToTutorExclusive->setEnabled(false);
- ui->action_StudentToTutor->setEnabled(false);
- ui->action_TutorToStudent->setEnabled(false);
- ui->action_LockSingle->setEnabled(false);
- }
-
-
-}
/***************************************************************************//**
* Handle Mouse Release Event.
* Check if click was inside the frame and if that is the case, set the selection of each connected
@@ -587,9 +569,9 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e)
return;
const QSize frame(ui->frmRoom->size());
if (frame.width() > pos.x() && frame.height() > pos.y()) {
- lockContextButtons();
if (getSelectedFrame() != nullptr) {
getSelectedFrame()->setSelection(false);
+ updateContextButtonStates();
}
}
}
@@ -640,18 +622,18 @@ void MainWindow::onPlaceFrame(ConnectionFrame* connectionFrame)
*/
void MainWindow::onFrameClicked(ConnectionFrame* frame)
{
+ ConnectionFrame *current = getSelectedFrame();
// If same frame is clicked again,, do nothing
- if (getSelectedFrame() == frame)
+ if (current == frame)
return;
// If another frame has been selected, unselect it
// Set the ui selected and set a new reference
- if (getSelectedFrame() != nullptr) {
- getSelectedFrame()->setSelection(false);
+ if (current != nullptr) {
+ current->setSelection(false);
}
frame->setSelection(true);
-
- unlockContextButtons();
+ updateContextButtonStates();
}
/***************************************************************************//**
@@ -794,6 +776,7 @@ void MainWindow::reloadCurrentRoom()
/* and force a resize event (this scales the image) */
resizeEvent(nullptr);
+ clientCountChanged();
}
void MainWindow::onReloadRoomOk()
@@ -1057,26 +1040,27 @@ void MainWindow::onButtonExit()
*/
void MainWindow::onButtonSetAsTutor()
{
- // If no frame is selected, warning.
- if (getSelectedFrame() == nullptr) {
+ ConnectionFrame *selected = getSelectedFrame();
+ ConnectionFrame *tutor = getTutorFrame();
+
+ if (selected == nullptr) {
QMessageBox::critical(this, tr("Selection"), tr("No client is selected."));
return;
}
- // If frame of inactive client has been selected unselect it
- if (getSelectedFrame()->client() != nullptr) {
- getSelectedFrame()->client()->lockScreen(false);
+ // Unlock client about to become a tutor, just in case
+ if (selected->client() != nullptr) {
+ selected->client()->lockScreen(false);
}
-
// If same frame is already tutor, do nothing
- if (getSelectedFrame() == getTutorFrame())
+ if (selected == tutor)
return;
-
// Else unset the old and set the new tutor
- if (getTutorFrame() != nullptr) {
- getTutorFrame()->setTutor(false);
+ if (tutor != nullptr) {
+ tutor->setTutor(false);
}
- getSelectedFrame()->setTutor(true);
+ selected->setTutor(true);
+ updateContextButtonStates();
}
/***************************************************************************//**
@@ -1179,8 +1163,9 @@ void MainWindow::onClientAuthenticated(Client* client)
*/
void MainWindow::onVncServerStateChange(Client* client)
{
- if (client == getClientFromId(_streamingSource))
+ if (client == getClientFromId(_streamingSource)) {
enableButtons();
+ }
if (client->isActiveVncServer()) {
// apply the desired projection sources
@@ -1265,9 +1250,8 @@ void MainWindow::onVncClientStateChange(Client* client)
*/
void MainWindow::disableButtons()
{
- qDebug() << "DisableButtons()";
_buttonLockTimer->start();
- foreach (QAction * a, _lockingButtons) {
+ for (QAction *a : _lockingButtons) {
a->setDisabled(true);
}
}
@@ -1277,11 +1261,11 @@ void MainWindow::disableButtons()
*/
void MainWindow::enableButtons()
{
- qDebug() << "EnableButtons()";
_buttonLockTimer->stop();
- foreach (QAction * a, _lockingButtons) {
+ for (QAction *a : _lockingButtons) {
a->setEnabled(true);
}
+ updateContextButtonStates(); // In case user changed selection while buttons were disabled
}
@@ -1303,7 +1287,6 @@ void MainWindow::onDeleteClient()
frame->hide();
frame->deleteLater();
_clientFrames.removeAll(frame);
- lockContextButtons();
clientCountChanged();
return;
}
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 59d50fc..f42fc73 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -55,10 +55,7 @@ private:
// Button block stuff
QTimer *_buttonLockTimer;
QList<QAction*> _lockingButtons;
- static const qint64 _buttonBlockTime = 2000;
-
- /* Context-sensitive Buttons */
- QList<QAction*> _contextButtons;
+ static const qint64 BUTTON_BLOCK_TIME = 2000;
// Management stuff
enum class Mode
@@ -96,8 +93,7 @@ private:
int getTileWidthPx() const;
int getTileHeightPx() const;
- void lockContextButtons();
- void unlockContextButtons();
+ void updateContextButtonStates();
void reloadCurrentRoom();