From e361357e513b8a3ed044dd22c548dae5fefe8ad5 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 29 Apr 2014 19:59:11 +0200 Subject: Disable all buttons if one is clicked and enable them after a specified time --- src/server/mainwindow/mainwindow.cpp | 56 +++++++++++++++++++----------------- src/server/mainwindow/mainwindow.h | 4 ++- 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 3ed2b57..ba5cdbc 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -461,20 +461,6 @@ bool MainWindow::isValidClient(Client* client) return false; } -/** - * Check if buttons are blocked. - * @return If buttons are blocked or not. - */ -bool MainWindow::areButtonsBlocked() -{ - bool result; - static qint64 buttonsBlockedUntil = 0; - qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (!(result = now < buttonsBlockedUntil)) - buttonsBlockedUntil = now + _buttonBlockTime; - return result; -} - /** * Handle VNC settings for a projection from "from" to "to". * Check if projection source is active vnc client. @@ -571,8 +557,8 @@ void MainWindow::prepareForProjection(Client * const from, Client * const to) */ void MainWindow::onButtonStudentToAll() { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); Client *from = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) @@ -601,8 +587,8 @@ void MainWindow::onButtonStudentToAll() */ void MainWindow::onButtonStudentToTutor() { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); Client *from = NULL; Client *to = NULL; @@ -643,8 +629,8 @@ void MainWindow::onButtonStudentToTutor() */ void MainWindow::onButtonTutorToAll() { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); // Client *from = NULL; @@ -674,8 +660,8 @@ void MainWindow::onButtonTutorToAll() */ void MainWindow::onButtonTutorToStudent() { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); Client *from = NULL; Client *to = NULL; @@ -715,8 +701,8 @@ void MainWindow::onButtonTutorToStudent() */ void MainWindow::onButtonStopProjection() { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { @@ -748,8 +734,8 @@ void MainWindow::onButtonStopProjection() */ void MainWindow::onButtonLock(bool checked) { - if (areButtonsBlocked()) - return; + DisableButtons(); + QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); NetworkMessage msg; msg.setField(_ID, _LOCK); @@ -1060,3 +1046,21 @@ void MainWindow::onVncClientStateChange(Client* client, int lastProjectionSource if (!inUse && server != NULL) server->stopVncServer(); } + +void MainWindow::DisableButtons() +{ + ui->action_BroadcastScreen->setDisabled(true); + ui->action_TutorToAll->setDisabled(true); + ui->action_StudentToTutor->setDisabled(true); + ui->action_TutorToStudent->setDisabled(true); + ui->action_StopProjection->setDisabled(true); +} + +void MainWindow::EnableButtons() +{ + ui->action_BroadcastScreen->setEnabled(true); + ui->action_TutorToAll->setEnabled(true); + ui->action_StudentToTutor->setEnabled(true); + ui->action_TutorToStudent->setEnabled(true); + ui->action_StopProjection->setEnabled(true); +} diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index e5179ed..38b0f83 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -61,7 +61,6 @@ private: void savePosition(ConnectionFrame *cf); void prepareForProjection(Client * const from, Client * const to); bool isValidClient(Client* client); - bool areButtonsBlocked(); public: MainWindow(QString ipListUrl, QWidget *parent = 0); @@ -98,5 +97,8 @@ protected slots: void onClientAuthenticated(Client* client); void onVncServerStateChange(Client* client); void onVncClientStateChange(Client* client, int lastProjectionSource); + //Buttons + void DisableButtons(); + void EnableButtons(); }; #endif -- cgit v1.2.3-55-g7522