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 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') 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); +} -- cgit v1.2.3-55-g7522 From 8568fa8080d5466f271b1c916be0ebb58b0e89ea Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Wed, 30 Apr 2014 14:04:30 +0200 Subject: cant fire the timer inside the button slots since they are called somewhere wlse too --- src/server/mainwindow/mainwindow.cpp | 65 ++++++++++++++++++++---------------- src/server/mainwindow/mainwindow.h | 1 + 2 files changed, 38 insertions(+), 28 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index ba5cdbc..29f4bc5 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -80,6 +80,29 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : connect(ui->action_SetAsTutor, SIGNAL(triggered()), this, SLOT(onButtonSetAsTutor())); connect(ui->action_SetAsTutor, SIGNAL(triggered()), this, SLOT(onButtonStopProjection())); connect(ui->action_Lock, SIGNAL(toggled(bool)), this, SLOT(onButtonLock(bool))); + + /* Stuff for the button lock */ + _buttonLockTimer = new QTimer(this); + _buttonLockTimer->setSingleShot(true); + _buttonLockTimer->setInterval(_buttonBlockTime); + // Disable the buttons if a button is clicked + connect(ui->action_Lock, SIGNAL(triggered()), this, SLOT(DisableButtons())); + connect(ui->action_BroadcastScreen, SIGNAL(triggered()), this, SLOT(DisableButtons())); + connect(ui->action_TutorToAll, SIGNAL(triggered()), this, SLOT(DisableButtons())); + connect(ui->action_StudentToTutor, SIGNAL(triggered()), this, SLOT(DisableButtons())); + connect(ui->action_TutorToStudent, SIGNAL(triggered()), this, SLOT(DisableButtons())); + connect(ui->action_StopProjection, SIGNAL(triggered()), this, SLOT(DisableButtons())); + // Start the timer a button is clicked + connect(ui->action_Lock, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + connect(ui->action_BroadcastScreen, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + connect(ui->action_TutorToAll, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + connect(ui->action_StudentToTutor, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + connect(ui->action_TutorToStudent, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + connect(ui->action_StopProjection, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + // Enable the buttons if the timer fires + connect(_buttonLockTimer, SIGNAL(timeout()), this, SLOT(EnableButtons())); + + // Clicking the session name label shows the edit field for it connect(_sessionNameLabel, SIGNAL(clicked()), this, SLOT(onSessionNameClick())); // Listen to updates to the session name through the session name window @@ -557,9 +580,6 @@ void MainWindow::prepareForProjection(Client * const from, Client * const to) */ void MainWindow::onButtonStudentToAll() { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - Client *from = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { @@ -587,9 +607,6 @@ void MainWindow::onButtonStudentToAll() */ void MainWindow::onButtonStudentToTutor() { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - Client *from = NULL; Client *to = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) @@ -629,9 +646,6 @@ void MainWindow::onButtonStudentToTutor() */ void MainWindow::onButtonTutorToAll() { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - // Client *from = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) @@ -660,9 +674,6 @@ void MainWindow::onButtonTutorToAll() */ void MainWindow::onButtonTutorToStudent() { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - Client *from = NULL; Client *to = NULL; for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) @@ -701,9 +712,6 @@ void MainWindow::onButtonTutorToStudent() */ void MainWindow::onButtonStopProjection() { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { Client *c = (**it).client(); @@ -734,9 +742,6 @@ void MainWindow::onButtonStopProjection() */ void MainWindow::onButtonLock(bool checked) { - DisableButtons(); - QTimer::singleShot(_buttonBlockTime, this, SLOT(EnableButtons())); - NetworkMessage msg; msg.setField(_ID, _LOCK); if (checked) @@ -1049,18 +1054,22 @@ void MainWindow::onVncClientStateChange(Client* client, int lastProjectionSource 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); + ui->action_Lock->setDisabled(true); + 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); + ui->action_SetAsTutor->setEnabled(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); + ui->action_Lock->setEnabled(true); + 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); + ui->action_SetAsTutor->setEnabled(true); } diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 38b0f83..6e046e5 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -39,6 +39,7 @@ private: int _timerId, _timerTimeout; ListenServer *_listenServer; DiscoveryListener *_discoveryListener; + QTimer * _buttonLockTimer; /** * Downloader for IP - List of possible tutors. -- cgit v1.2.3-55-g7522 From adbc49a0e2ad1b03558c6495cea49307c3db0381 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Wed, 30 Apr 2014 14:50:56 +0200 Subject: KISS'n'DRY for more cohesion --- src/server/mainwindow/mainwindow.cpp | 42 ++++++++++++++---------------------- src/server/mainwindow/mainwindow.h | 5 ++++- 2 files changed, 20 insertions(+), 27 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 29f4bc5..3d0d167 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -85,20 +85,20 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _buttonLockTimer = new QTimer(this); _buttonLockTimer->setSingleShot(true); _buttonLockTimer->setInterval(_buttonBlockTime); + _lockingButtons + << ui->action_Lock + << ui->action_BroadcastScreen + << ui->action_TutorToAll + << ui->action_StudentToTutor + << ui->action_TutorToStudent + << ui->action_StopProjection + << ui->action_SetAsTutor; // Disable the buttons if a button is clicked - connect(ui->action_Lock, SIGNAL(triggered()), this, SLOT(DisableButtons())); - connect(ui->action_BroadcastScreen, SIGNAL(triggered()), this, SLOT(DisableButtons())); - connect(ui->action_TutorToAll, SIGNAL(triggered()), this, SLOT(DisableButtons())); - connect(ui->action_StudentToTutor, SIGNAL(triggered()), this, SLOT(DisableButtons())); - connect(ui->action_TutorToStudent, SIGNAL(triggered()), this, SLOT(DisableButtons())); - connect(ui->action_StopProjection, SIGNAL(triggered()), this, SLOT(DisableButtons())); + foreach (QAction* a, _lockingButtons) + connect(a, SIGNAL(triggered()), this, SLOT(DisableButtons())); // Start the timer a button is clicked - connect(ui->action_Lock, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); - connect(ui->action_BroadcastScreen, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); - connect(ui->action_TutorToAll, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); - connect(ui->action_StudentToTutor, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); - connect(ui->action_TutorToStudent, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); - connect(ui->action_StopProjection, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); + foreach (QAction* a, _lockingButtons) + connect(a, SIGNAL(triggered()), _buttonLockTimer, SLOT(start())); // Enable the buttons if the timer fires connect(_buttonLockTimer, SIGNAL(timeout()), this, SLOT(EnableButtons())); @@ -1054,22 +1054,12 @@ void MainWindow::onVncClientStateChange(Client* client, int lastProjectionSource void MainWindow::DisableButtons() { - ui->action_Lock->setDisabled(true); - 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); - ui->action_SetAsTutor->setEnabled(true); + foreach (QAction* a, _lockingButtons) + a->setDisabled(true); } void MainWindow::EnableButtons() { - ui->action_Lock->setEnabled(true); - 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); - ui->action_SetAsTutor->setEnabled(true); + foreach (QAction* a, _lockingButtons) + a->setEnabled(true); } diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 6e046e5..153eb5b 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -39,7 +39,11 @@ private: int _timerId, _timerTimeout; ListenServer *_listenServer; DiscoveryListener *_discoveryListener; + + // Button block stuff QTimer * _buttonLockTimer; + QList _lockingButtons; + static const qint64 _buttonBlockTime = 1000; /** * Downloader for IP - List of possible tutors. @@ -52,7 +56,6 @@ private: QStringList _tutorList; // Magic numbers - static const qint64 _buttonBlockTime = 1000; static const int _tilesX = 9; static const int _tilesY = 7; -- cgit v1.2.3-55-g7522