diff options
Diffstat (limited to 'src')
24 files changed, 193 insertions, 185 deletions
diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp index 2f65bd1..962ec42 100644 --- a/src/client/clientapp/clientapp.cpp +++ b/src/client/clientapp/clientapp.cpp @@ -5,7 +5,7 @@ #include "../net/serverconnection.h" ClientApp::ClientApp(int& argc, char** argv) - : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false), _connection(NULL), _isManagerPc(false) + : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false), _connection(nullptr), _isManagerPc(false) { /* some values */ setOrganizationName("openslx"); @@ -31,7 +31,7 @@ ClientApp::ClientApp(int& argc, char** argv) readIsManagerPc(); - _connectWindow = new ConnectWindow(NULL); + _connectWindow = new ConnectWindow(nullptr); connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(connected(ServerConnection*))); if (_connectionMode == ConnectionMode::Auto) { _toolbar = new Toolbar(true); // auto connect client without session ID. @@ -114,10 +114,10 @@ void ClientApp::connected(ServerConnection* connection) void ClientApp::disconnected(ServerConnection* connection) { - if (connection != NULL) + if (connection != nullptr) connection->blockSignals(true); if (_connection == connection) { - _connection = NULL; + _connection = nullptr; } } diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h index 0f7cb5b..91dccf3 100644 --- a/src/client/clientapp/clientapp.h +++ b/src/client/clientapp/clientapp.h @@ -58,7 +58,7 @@ public: bool isConfiguredAsManager() { return _isManagerPc; } - bool isConnectedToLocalManager() { return _connection != NULL && _connection->isLocalConnection(); } + bool isConnectedToLocalManager() { return _connection != nullptr && _connection->isLocalConnection(); } private slots: diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index b1f583a..c77a5e6 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -27,7 +27,7 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) _timerHide = 0; _state = Idle; _hashSslErrorCount = 0; - _pendingConnection = NULL; + _pendingConnection = nullptr; // Initialize the GUI _ui->setupUi(this); @@ -320,7 +320,7 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state QObject::disconnect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); QObject::disconnect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); emit connected(_pendingConnection); - _pendingConnection = NULL; + _pendingConnection = nullptr; this->updateUserInterface(); @@ -341,12 +341,12 @@ void ConnectWindow::onComboBox_keyPressed(QKeyEvent* e) } /***************************************************************************//** - * If connection is closed set _pendingConnection = NULL. + * If connection is closed set _pendingConnection = nullptr. * @param connection */ void ConnectWindow::onConnectionClosed(QObject* /* connection */ ) { - _pendingConnection = NULL; + _pendingConnection = nullptr; } /***************************************************************************//** diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 51b1bf2..af45db6 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -54,7 +54,7 @@ public: Connected }; - explicit ConnectWindow(QWidget *parent = NULL); + explicit ConnectWindow(QWidget *parent = nullptr); virtual ~ConnectWindow(); void connectToSession(const QByteArray sessionName, QString mgrIP); diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index 0cbd4c2..6350418 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -19,7 +19,7 @@ #define CHALLENGE_LEN 20 ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) : - QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _autoConnect(autoConnect), _isLocalConnection(-1), _sessionName(sessionName), _certHash(certHash) + QObject(nullptr), _timerDelete(0), _jpegQuality(80), _authed(0), _autoConnect(autoConnect), _isLocalConnection(-1), _sessionName(sessionName), _certHash(certHash) { _socket = new QSslSocket(); _blank = new BlankScreen(); @@ -46,13 +46,13 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons ServerConnection::~ServerConnection() { this->disconnectFromServer(); - if (_socket != NULL) { + if (_socket != nullptr) { qCritical("**** SOCKET DELETE IN DESTRUCTOR"); _socket->deleteLater(); } qDebug("*** Server connection destroyed."); _blank->deleteLater(); - _blank = NULL; + _blank = nullptr; } /** @@ -60,7 +60,7 @@ ServerConnection::~ServerConnection() */ void ServerConnection::sendMessage(NetworkMessage& message) { - if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) + if (_socket == nullptr || _socket->state() != QAbstractSocket::ConnectedState) return; message.writeMessage(_socket); if (!message.writeComplete()) { @@ -89,7 +89,7 @@ void ServerConnection::disconnectFromServer() emit disconnected(this); _timerDelete = startTimer(500); qDebug("Closing connection to server"); - if (_socket != NULL) { + if (_socket != nullptr) { _socket->blockSignals(true); _socket->abort(); } @@ -144,11 +144,11 @@ void ServerConnection::handleMsg() } emit stateChange(ConnectWindow::LoggingIn); const char *user = getpwuid(getuid())->pw_name; - if (user == NULL || *user == '\0') + if (user == nullptr || *user == '\0') user = getenv("USER"); - if (user == NULL || *user == '\0') + if (user == nullptr || *user == '\0') user = getenv("USERNAME"); - if (user == NULL || *user == '\0') + if (user == nullptr || *user == '\0') user = "Hans Affe"; _toServer.reset(); _toServer.setField(_ID, _LOGIN); @@ -269,7 +269,7 @@ void ServerConnection::handleMsg() void ServerConnection::checkLocalConnection() { - if (_socket == NULL) { + if (_socket == nullptr) { return; } if (_socket->peerAddress() == _socket->localAddress()) { @@ -297,10 +297,10 @@ void ServerConnection::timerEvent(QTimerEvent *event) _timerId = 0; this->disconnectFromServer(); } else if (event->timerId() == _timerDelete) { - if (_socket == NULL || _socket->state() == QAbstractSocket::UnconnectedState) { - if (_socket != NULL) + if (_socket == nullptr || _socket->state() == QAbstractSocket::UnconnectedState) { + if (_socket != nullptr) _socket->deleteLater(); - _socket = NULL; + _socket = nullptr; killTimer(_timerDelete); this->deleteLater(); return; @@ -375,7 +375,7 @@ void ServerConnection::sslErrors(const QList<QSslError> & errors) void ServerConnection::sock_dataArrival() { - if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) { + if (_socket == nullptr || _socket->state() != QAbstractSocket::ConnectedState) { qDebug("dataArrival called in bad state"); return; } @@ -390,7 +390,7 @@ void ServerConnection::sock_dataArrival() return; if (_fromServer.readComplete()) { // message is complete this->handleMsg(); - if (_socket == NULL) + if (_socket == nullptr) return; _fromServer.reset(); } diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h index 9db9b02..f5f6264 100644 --- a/src/client/net/serverconnection.h +++ b/src/client/net/serverconnection.h @@ -38,7 +38,7 @@ public: ~ServerConnection(); inline bool isConnected() const { - return _socket != NULL && _socket->state() == QAbstractSocket::ConnectedState; + return _socket != nullptr && _socket->state() == QAbstractSocket::ConnectedState; } const inline QString getPeerAdress() const diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index 33ddbf5..799fcbe 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -145,12 +145,12 @@ void ServerDiscovery::onUdpReadyRead() while (_discoverySocket.hasPendingDatagrams()) { // Discard any packets if discovery is stopped if (!this->isActive()) { - _discoverySocket.readDatagram(NULL, 0); + _discoverySocket.readDatagram(nullptr, 0); continue; } const qint64 size = _discoverySocket.readDatagram(data, UDPBUFSIZ, &addr, &port); - if (size <= 0) //|| clientApp->connection() != NULL) // TODO CHECK + if (size <= 0) //|| clientApp->connection() != nullptr) // TODO CHECK continue; _packet.reset(); diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 955731a..a8e50e9 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -99,7 +99,7 @@ void Toolbar::init() setAttribute(Qt::WA_DeleteOnClose, false); /* Create the VNC Window */ - _vnc = new VncWindow(NULL); + _vnc = new VncWindow(nullptr); /* Create the connect window */ clientApp->connectWindow()->setAvailableRooms(myRooms()); @@ -353,7 +353,7 @@ void Toolbar::onVncServerIsRunning(int port) */ void Toolbar::onDisconnected(ServerConnection* connection) { - if (connection != NULL) { + if (connection != nullptr) { disconnect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); } _ui->lblStatus->setStyleSheet("color:red"); @@ -398,7 +398,7 @@ void Toolbar::onConnected(ServerConnection* connection) */ void Toolbar::onDoDisconnect() { - if (clientApp->connection() != NULL) + if (clientApp->connection() != nullptr) clientApp->connection()->disconnectFromServer(); } @@ -486,12 +486,12 @@ void Toolbar::showInformationDialog() void Toolbar::onBtnAttention() { - const bool on = clientApp->connection() != NULL && _ui->btnAttention->isChecked(); + const bool on = clientApp->connection() != nullptr && _ui->btnAttention->isChecked(); if (on != _ui->btnAttention->isChecked()) { _ui->btnAttention->setChecked(on); return; } - if (clientApp->connection() != NULL) { + if (clientApp->connection() != nullptr) { clientApp->connection()->sendAttention(on); } } diff --git a/src/client/util/platform/blankscreen.cpp b/src/client/util/platform/blankscreen.cpp index ee644ca..bf34614 100644 --- a/src/client/util/platform/blankscreen.cpp +++ b/src/client/util/platform/blankscreen.cpp @@ -16,11 +16,11 @@ struct BlankScreen_Sysdep { Display *dpy; }; -BlankScreen::BlankScreen() : QDialog(NULL) +BlankScreen::BlankScreen() : QDialog(nullptr) { _sysdep = new BlankScreen_Sysdep; - _sysdep->dpy = XOpenDisplay(NULL); - if (_sysdep->dpy == NULL) + _sysdep->dpy = XOpenDisplay(nullptr); + if (_sysdep->dpy == nullptr) return; setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); @@ -35,7 +35,7 @@ BlankScreen::BlankScreen() : QDialog(NULL) BlankScreen::~BlankScreen() { unlock(); - if (_sysdep->dpy != NULL) { + if (_sysdep->dpy != nullptr) { XCloseDisplay(_sysdep->dpy); } delete _sysdep; @@ -45,7 +45,7 @@ bool BlankScreen::lock(const QString& message) { if (_locked) return true; - if (_sysdep->dpy == NULL) + if (_sysdep->dpy == nullptr) return false; _message = message; @@ -73,7 +73,7 @@ bool BlankScreen::unlock() this->hide(); if (!_locked) return true; - if (_sysdep->dpy == NULL) + if (_sysdep->dpy == nullptr) return false; // ungrabbing of keyboard and mouse diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp index 165ba6d..a016f08 100644 --- a/src/client/vnc/vncserver.cpp +++ b/src/client/vnc/vncserver.cpp @@ -12,7 +12,7 @@ #include "vncserver.h" #include "../util/util.h" -VncServer* VncServer::me = NULL; +VncServer* VncServer::me = nullptr; /***************************************************************************//** * @brief VncServer::instance @@ -20,7 +20,7 @@ VncServer* VncServer::me = NULL; */ VncServer* VncServer::instance() { - if (me == NULL) + if (me == nullptr) me = new VncServer(); return me; } @@ -32,10 +32,10 @@ VncServer* VncServer::instance() */ static QString makePassword(int len = 10) { - char pass[len]; + QString ret(len, Qt::Uninitialized); for (int i = 0; i < len; ++i) - pass[i] = (char)(43 + qrand() % 80); - return QString::fromUtf8(pass, len); + ret[i] = QChar(43 + qrand() % 80); + return ret; } /***************************************************************************//** @@ -48,7 +48,7 @@ struct Sleeper : public QThread { /***************************************************************************//** * @brief VncServer::VncServer */ -VncServer::VncServer() : _process(NULL), _port(0), _timerId(0) {} +VncServer::VncServer() : _process(nullptr), _port(0), _timerId(0) {} /***************************************************************************//** * @brief VncServer::~VncServer @@ -73,7 +73,7 @@ QSharedPointer<QFile> VncServer::createPwFile(const QDir& dir) void VncServer::start() { // Keep things clean - if (_process != NULL) { + if (_process != nullptr) { disconnect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError))); disconnect(_process, SIGNAL(finished(int)), this, SLOT(onFinished(int))); } @@ -138,13 +138,13 @@ void VncServer::stop() killTimer(_timerId); _timerId = 0; } - if (_process == NULL) + if (_process == nullptr) return; qDebug("Stopping old VNC server."); disconnect(_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStdOut())); disconnect(_process, SIGNAL(readyReadStandardError()), this, SLOT(onStdErr())); QProcess *process = _process; - _process = NULL; + _process = nullptr; _port = 0; process->terminate(); for (int i = 0; i < 10 && process->state() != QProcess::NotRunning; ++i) @@ -185,7 +185,7 @@ void VncServer::timerEvent(QTimerEvent * /* event */ ) */ void VncServer::onStdOut() { - if (_process == NULL) { + if (_process == nullptr) { qDebug("VncServer::onStdOut() called in bad state."); return; } @@ -211,7 +211,7 @@ void VncServer::onStdOut() */ void VncServer::onStdErr() { - if (_process == NULL) { + if (_process == nullptr) { qDebug("VncServer::onStdErr() called in bad state."); return; } diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp index 1dbe005..e399e9b 100644 --- a/src/client/vnc/vncthread.cpp +++ b/src/client/vnc/vncthread.cpp @@ -36,7 +36,7 @@ VncThread::VncThread(QString host, int port, QString passwd, int quality) : _port = port; _passwd = passwd; _quality = quality; - _client = NULL; + _client = nullptr; _connected = false; moveToThread(this); } @@ -45,7 +45,7 @@ VncThread::~VncThread() { qDebug("VNC worker destructor called."); Q_ASSERT(_run == false); - if (_client != NULL) { + if (_client != nullptr) { if (_client->sock != -1) ::close(_client->sock); _client->sock = -1; @@ -82,27 +82,27 @@ void VncThread::run() _client->canHandleNewFBSize = true; free(_client->serverHost); // in rfbGetClient, serverHost is assigned strdup(""), so free that first. _client->serverHost = strdup(_host.toUtf8().constData()); - _client->desktopName = NULL; + _client->desktopName = nullptr; _client->serverPort = _port; _client->GetPassword = &passwdHandler; _client->GotFrameBufferUpdate = &updateImage; - _client->frameBuffer = NULL; + _client->frameBuffer = nullptr; // save this instance in vnc-struct for callbacks rfbClientSetClientData(_client, 0, this); // start client - if (rfbInitClient(_client, NULL, NULL)) { + if (rfbInitClient(_client, nullptr, nullptr)) { break; // Success! } // Connection failed - _client = NULL; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around + _client = nullptr; // InitClient frees the client on failure, so make sure we don't keep an invalid pointer around if (!_run) break; // error, let's try again this->msleep(10 + qrand() % 50); } - if (_client != NULL) { + if (_client != nullptr) { qDebug("[%s] Connection successful!", metaObject()->className()); int one = 1; setsockopt(_client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)); @@ -136,7 +136,7 @@ void VncThread::run() */ const QString VncThread::getDesktopName() const { - if (_client == NULL || _client->desktopName == NULL) + if (_client == nullptr || _client->desktopName == nullptr) return QString(); return QString(_client->desktopName); } @@ -189,6 +189,11 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) const int width = client->width, height = client->height, depth = 32; const int size = width * height * (depth / 8); qDebug("[%s] Remote desktop: %ix%ix%i", t->metaObject()->className(), width, height, depth); + if (width < 0 || height < 0 || size < 0) { + qWarning() << "IGNORING INVALID FRAMEBUFFER SIZE"; + client->frameBuffer = nullptr; + return false; + } t->_img = QSharedPointer<QImage>(new QImage(width, height, QImage::Format_RGB32)); if (size > t->_img->byteCount()) { @@ -196,7 +201,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) ::exit(1); } client->frameBuffer = t->_img->bits(); - memset(client->frameBuffer, '\0', size); + memset(client->frameBuffer, '\0', (size_t)size); client->format.trueColour = 1; client->format.bitsPerPixel = depth; client->format.redShift = 16; diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp index 79352ae..a9d85f4 100644 --- a/src/client/vnc/vncwindow.cpp +++ b/src/client/vnc/vncwindow.cpp @@ -37,7 +37,7 @@ static int gcd(int a, int b) VncWindow::VncWindow(QWidget *parent) : QWidget(parent), _srcStepX(1), _srcStepY(1), _dstStepX(1), _dstStepY(1), - _vncWorker(NULL), _viewOnly(true), _multiScreen(false), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0) + _vncWorker(nullptr), _viewOnly(true), _multiScreen(false), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0) { QTimer *upper = new QTimer(this); connect(upper, SIGNAL(timeout()), this, SLOT(timer_moveToTop())); @@ -55,13 +55,13 @@ VncWindow::~VncWindow() /** * Terminates the vnc worker thread and stops all related timers. * The thread will be signalled to stop, but we don't wait for it - * to actually terminate. All signals of the thread are blocked, and we NULL + * to actually terminate. All signals of the thread are blocked, and we nullptr * our reference to it. It will finish running in a detached state and finally * delete itself upon completion. */ void VncWindow::terminateVncThread() { - if (_vncWorker == NULL) + if (_vncWorker == nullptr) return; disconnect(_vncWorker, SIGNAL(projectionStopped()), this, SLOT(onProjectionStopped())); @@ -69,7 +69,7 @@ void VncWindow::terminateVncThread() disconnect(_vncWorker, SIGNAL(imageUpdated(const int, const int, const int, const int)), this, SLOT(onUpdateImage(const int, const int, const int, const int))); _vncWorker->stop(); - _vncWorker = NULL; + _vncWorker = nullptr; if (_redrawTimer != 0) { killTimer(_redrawTimer); _redrawTimer = 0; @@ -96,7 +96,7 @@ void VncWindow::deleteVncThread() */ void VncWindow::draw(const int x, const int y, const int w, const int h) { - if (_vncWorker == NULL) + if (_vncWorker == nullptr) return; QSharedPointer<QImage> buffer = _vncWorker->getFrameBuffer(); if (buffer.isNull()) @@ -147,10 +147,10 @@ void VncWindow::draw(const int x, const int y, const int w, const int h) bool VncWindow::calcScaling(const QImage *remote) { if (this->size() == _desiredSize && - (remote == NULL || remote->size() == _remoteSize)) + (remote == nullptr || remote->size() == _remoteSize)) return false; const QSize mySize = this->size(); - const QSize remoteSize = remote == NULL ? _remoteSize : remote->size(); + const QSize remoteSize = remote == nullptr ? _remoteSize : remote->size(); if (mySize.isEmpty()) return false; if (remoteSize.isEmpty()) @@ -270,7 +270,7 @@ void VncWindow::closeEvent(QCloseEvent * /* e */ ) */ void VncWindow::onUpdateImage(const int x, const int y, const int w, const int h) { - if (_vncWorker == NULL) + if (_vncWorker == nullptr) return; if (!this->calcScaling(_vncWorker->getFrameBuffer().data()) && !_remoteSize.isEmpty()) { if (_srcStepX > 1 || _srcStepY > 1) { @@ -345,7 +345,7 @@ void VncWindow::timerEvent(QTimerEvent *event) } else if (event->timerId() == _tcpTimeoutTimer) { killTimer(_tcpTimeoutTimer); _tcpTimeoutTimer = 0; - if (_vncWorker != NULL && !_vncWorker->isConnected()) { + if (_vncWorker != nullptr && !_vncWorker->isConnected()) { this->close(); } } else @@ -362,7 +362,7 @@ void VncWindow::timerEvent(QTimerEvent *event) */ void VncWindow::paintEvent(QPaintEvent *event) { - if (_vncWorker == NULL || !_vncWorker->isConnected()) { + if (_vncWorker == nullptr || !_vncWorker->isConnected()) { QPainter painter(this); if (!_remoteThumb.isNull() && _remoteThumb.height() > 0) { painter.drawPixmap(0, 0, this->width(), this->height(), _remoteThumb); diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp index 875e031..e8d8349 100644 --- a/src/server/connectionframe/connectionframe.cpp +++ b/src/server/connectionframe/connectionframe.cpp @@ -58,7 +58,7 @@ static QString style_disconnected( QGroupBox { background-color: #7F7F7F; margin: 1px; border-radius: 4px}" ); -static QIcon *term = NULL, *cam = NULL, *eye = NULL, *lock = NULL; +static QIcon *term = nullptr, *cam = nullptr, *eye = nullptr, *lock = nullptr; bool ConnectionFrame::paintDisabled = false; @@ -69,13 +69,13 @@ bool ConnectionFrame::paintDisabled = false; * @param height */ ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent, bool fromRoomplan) : - QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false), + QGroupBox(parent), _client(nullptr), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false), _isFromRoomplan(fromRoomplan), _mainWindow(main) { //defines the ui-stuff // load icons first - if (term == NULL) { + if (term == nullptr) { term = new QIcon(":terminal"); cam = new QIcon(":cf_cam"); eye = new QIcon(":cf_eye"); @@ -88,7 +88,7 @@ ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent, bool fromRoo _mainLayout->setAlignment(Qt::AlignHCenter); this->setStyleSheet(style_student); - _iconLayout = new QBoxLayout(QBoxLayout::RightToLeft, NULL); + _iconLayout = new QBoxLayout(QBoxLayout::RightToLeft, nullptr); _iconLayout->setSpacing(1); _iconLayout->setMargin(3); @@ -124,7 +124,7 @@ ConnectionFrame::ConnectionFrame(MainWindow* main, QWidget *parent, bool fromRoo ConnectionFrame::~ConnectionFrame() { - if (_client != NULL) { + if (_client != nullptr) { _client->deleteLater(); } _iconLayout->deleteLater(); @@ -145,7 +145,7 @@ void ConnectionFrame::updateGeometry() { const QRect rect = _mainWindow->calcFrameGeometry(this); setGeometry(rect); - if (this->_client == NULL) + if (this->_client == nullptr) showDefaultThumb(); } @@ -171,7 +171,7 @@ QLabel* ConnectionFrame::addIcon(const QIcon* icon) */ void ConnectionFrame::assignClient(Client* client) { - assert(_client == NULL); + assert(_client == nullptr); connect( client, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()) ); connect( client, SIGNAL(thumbUpdated(Client*, const QImage&)), this, SLOT(onThumbUpdated(Client*, const QImage&)) ); connect( client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(updateAppearance())); @@ -206,7 +206,7 @@ void ConnectionFrame::calcDesiredThumbSize(const QSize &frameSize) void ConnectionFrame::updateLabels() { _lblHostName->setText(_computerId); - if (_client == NULL) { + if (_client == nullptr) { _lblUserName->setText(QString()); _lblUserName->hide(); } else { @@ -331,7 +331,7 @@ void ConnectionFrame::paintEvent(QPaintEvent *event) */ void ConnectionFrame::timerEvent(QTimerEvent* /* event */ ) { - if (_client == NULL) + if (_client == nullptr) return; ++_timerCounter; if (_client->isActiveVncServer() && _timerCounter % 5 != 0) @@ -357,7 +357,7 @@ void ConnectionFrame::setSelection(bool selected) */ void ConnectionFrame::setTutor(bool b) { - if (_isTutor != b && _client != NULL) + if (_isTutor != b && _client != nullptr) _client->setTutor(b); _isTutor = b; this->updateAppearance(); @@ -369,7 +369,7 @@ void ConnectionFrame::setTutor(bool b) */ void ConnectionFrame::updateAppearance() { - if (_client == NULL) { + if (_client == nullptr) { // Unconnected Frame if (_isSelected) { this->setStyleSheet(style_selectedStudent); @@ -426,7 +426,7 @@ void ConnectionFrame::onClientDisconnected() killTimer(_timerId); _timerId = 0; } - _client = NULL; + _client = nullptr; updateLabels(); updateAppearance(); showDefaultThumb(); diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h index 898d97a..ba5f235 100644 --- a/src/server/connectionframe/connectionframe.h +++ b/src/server/connectionframe/connectionframe.h @@ -66,7 +66,7 @@ public: inline bool isSelected() { return _isSelected; } const QString& computerId() const { return _computerId; } - void setComputerId(QString computerId) { if (_client != NULL) return; _computerId = computerId; updateLabels(); } + void setComputerId(QString computerId) { if (_client != nullptr) return; _computerId = computerId; updateLabels(); } Client* client() const { return _client; } inline bool isTutor() { return _isTutor; } diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 5daade4..dcf8973 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -190,7 +190,7 @@ void MainWindow::clientCountChanged() for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) { Client* c = (*it)->client(); - if (c != NULL) { + if (c != nullptr) { bool b = c->isExamMode(); examClientCount += b ? 1 : 0; clientCount++; @@ -262,7 +262,7 @@ int distance(QPointF a, QPointF b) QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore) { const bool pickFirstOne = ( preferredPixels == QPoint(-1, -1) ); - if (!pickFirstOne && toIgnore != NULL) { + if (!pickFirstOne && toIgnore != nullptr) { // Check if we're already in the desired location and skip all the checks QPoint desired = QPoint(preferredPixels.x() / getTileWidthPx(), preferredPixels.y() / getTileHeightPx()); if (desired == toIgnore->getGridPosition()) { @@ -270,8 +270,9 @@ QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIg } } const QSize& clientSize = serverApp->getCurrentRoom()->clientSize; - bool grid[_tilesX][_tilesY]; - memset(grid, 0, sizeof(bool) * _tilesX * _tilesY); /* set everything to false */ +#define GRID(X,Y) (grid[X * _tilesX + Y]) + bool *grid = new bool[_tilesX * _tilesY]; + memset(grid, 0, sizeof(bool) * size_t(_tilesX * _tilesY)); /* set everything to false */ /* fill grid */ for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) { @@ -282,7 +283,7 @@ QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIg for (int x = p.x(); x < p.x() + clientSize.width(); x++) { for (int y = p.y(); y < p.y() + clientSize.height(); y++) { - grid[x][y] = true; + GRID(x, y) = true; } } } @@ -295,7 +296,7 @@ QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIg bool isFree = true; for (int dx = 0; dx < clientSize.width(); dx++) { for (int dy = 0; dy < clientSize.height(); dy++) { - if (grid[x + dx][y + dy]) { + if (GRID(x + dx, y + dy)) { isFree = false; goto endLoop; // double-break } @@ -311,6 +312,8 @@ endLoop: ; } } endSearch: ; +#undef GRID + delete[] grid; /* among all the free positions, find the closest */ int min_distance = 1000000; QPoint bestPosition = QPoint(0, 0); @@ -342,7 +345,7 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferredPi ConnectionFrame* MainWindow::createFrame(const QString &computerId, const QPoint* gridPosition, bool fromRoomplan) { ConnectionFrame *cf = new ConnectionFrame(this, ui->frmRoom, fromRoomplan); - if (gridPosition == NULL) { + if (gridPosition == nullptr) { placeFrameInFreeSlot(cf); } else { cf->setGridPosition(*gridPosition); @@ -378,47 +381,47 @@ void MainWindow::tellClientCurrentSituation(Client* client) * Returns connected client which belongs to given id. * Iterating over ConnectionFrames and comparing id to given id. * @param id - * @return Client with given id, if not NULL. + * @return Client with given id, if not nullptr. */ Client* MainWindow::getClientFromId(int id) { for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if ((*it)->client() != NULL) { + if ((*it)->client() != nullptr) { if ((*it)->client()->id() == id) return (*it)->client(); } } - return NULL; + return nullptr; } /***************************************************************************//** * Return the Frame, which is currently beeing Tutor. * Iterating over all ConnectionFrames, and looking for flag _isTutor. * @return Frame with flag _isTutor = true, - * else NULL if no Tutor is available. + * else nullptr if no Tutor is available. */ ConnectionFrame* MainWindow::getTutorFrame() { for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if (((*it) != NULL) && ((*it)->isTutor())) + if (((*it) != nullptr) && ((*it)->isTutor())) return (*it); } - return NULL; + return nullptr; } /***************************************************************************//** * Return the Frame, which is currently selected by user. * Iterating over all ConnectionFrame and looking for flag _isSelected. * @return Frame with flag _isSelected = true, - * else NULL if no frame is selected. + * else nullptr if no frame is selected. */ ConnectionFrame* MainWindow::getSelectedFrame() { for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if (((*it) != NULL) && ((*it)->isSelected())) + if (((*it) != nullptr) && ((*it)->isSelected())) return (*it); } - return NULL; + return nullptr; } /* @@ -527,7 +530,7 @@ void MainWindow::resizeEvent(QResizeEvent* /* e */ ) } /* update background image label */ - if (_backgroundImage != NULL) { + if (_backgroundImage != nullptr) { int w = ui->frmRoom->width() - 5; /* to make sure that we don't enlarge the window */ int h = ui->frmRoom->height() - 5; ui->imageLabel->hide(); @@ -553,10 +556,10 @@ void MainWindow::unlockContextButtons() (*it)->setEnabled(true); } /* and disable some again based on special rules */ - if (getSelectedFrame()->client() != NULL) { + if (getSelectedFrame()->client() != nullptr) { ui->action_DeleteClient->setEnabled(false); } - if (getSelectedFrame()->client() == NULL) { + if (getSelectedFrame()->client() == nullptr) { ui->action_SetAsTutor->setEnabled(false); ui->action_StudentToTutorExclusive->setEnabled(false); ui->action_StudentToTutor->setEnabled(false); @@ -583,7 +586,7 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e) const QSize frame(ui->frmRoom->size()); if (frame.width() > pos.x() && frame.height() > pos.y()) { lockContextButtons(); - if (getSelectedFrame() != NULL) { + if (getSelectedFrame() != nullptr) { getSelectedFrame()->setSelection(false); } } @@ -598,13 +601,13 @@ void MainWindow::reset(bool lock) // Unlock all clients for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) { + if ((*it)->client() != nullptr) { (*it)->client()->lockScreen(lock); (*it)->client()->removeAttention(); } // Stop server (Clients get stopped on ACK) - if (getClientFromId(_streamingSource) != NULL) + if (getClientFromId(_streamingSource) != nullptr) getClientFromId(_streamingSource)->stopVncServer(); } @@ -623,7 +626,7 @@ void MainWindow::onPlaceFrame(ConnectionFrame* connectionFrame) const QPoint preferredPixels = connectionFrame->pos(); placeFrameInFreeSlot(connectionFrame, preferredPixels); - //resizeEvent(NULL); + //resizeEvent(nullptr); } /***************************************************************************//** @@ -638,7 +641,7 @@ void MainWindow::onFrameClicked(ConnectionFrame* frame) // If another frame has been selected, unselect it // Set the ui selected and set a new reference - if (getSelectedFrame() != NULL) { + if (getSelectedFrame() != nullptr) { getSelectedFrame()->setSelection(false); } frame->setSelection(true); @@ -698,14 +701,14 @@ void MainWindow::startVncServerIfNecessary(int from) Client* ns = getClientFromId(from); // if there is a server running which is not "from" stop it. - if (os != NULL && _streamingSource != from) + if (os != nullptr && _streamingSource != from) os->stopVncServer(); // Set new streaming source _streamingSource = from; // If streaming source is already active avoid a restart - if (ns != NULL) { + if (ns != nullptr) { if (ns->isActiveVncServer()) { this->onVncServerStateChange(ns); } else { // Could not take shortcut, (re)start VNC server on source @@ -737,11 +740,11 @@ void MainWindow::onReloadRoomCancel() void MainWindow::reloadCurrentRoom() { /* delete old image */ - if (_backgroundImage != NULL) {delete _backgroundImage; } - _backgroundImage = NULL; + if (_backgroundImage != nullptr) {delete _backgroundImage; } + _backgroundImage = nullptr; const Room *room = serverApp->getCurrentRoom(); - if (room != NULL) { + if (room != nullptr) { /* set tiles */ _tilesX = room->gridSize.width(); _tilesY = room->gridSize.height(); @@ -756,7 +759,7 @@ void MainWindow::reloadCurrentRoom() onPlaceFrame(cf); if (computerId == room->tutorIP) { qDebug() << "set computer with id " << computerId << " as tutor per configuration"; - if (getTutorFrame() != NULL) { + if (getTutorFrame() != nullptr) { getTutorFrame()->setTutor(false); } cf->setTutor(true); @@ -785,12 +788,12 @@ void MainWindow::reloadCurrentRoom() } /* and force a resize event (this scales the image) */ - resizeEvent(NULL); + resizeEvent(nullptr); } void MainWindow::onReloadRoomOk() { - if (_reloadWindow->ui->roomList->currentItem() == NULL) { + if (_reloadWindow->ui->roomList->currentItem() == nullptr) { QMessageBox::critical(this, "Warning", tr("No item selected, please select room!"), 0, 1); return; } @@ -855,9 +858,9 @@ void MainWindow::onButtonTutorToAll() { ui->action_Lock->setChecked(false); - if (getTutorFrame() == NULL) + if (getTutorFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorNdef); - else if (getTutorFrame()->client() == NULL) + else if (getTutorFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else if (_clientFrames.size() == 1) QMessageBox::critical(this, tr("Projection"), sStrNoDestAv); @@ -870,7 +873,7 @@ void MainWindow::onButtonTutorToAll() // Set all clients as watchers of tutor. Except for the tutors desired source, which hase to be none for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) + if ((*it)->client() != nullptr) (*it)->client()->setDesiredProjectionSource((*it)->client() == getTutorFrame()->client() ? NO_SOURCE : getTutorFrame()->client()->id()); disableButtons(); @@ -887,21 +890,21 @@ void MainWindow::onButtonTutorToStudent() { ui->action_Lock->setChecked(false); - if (getSelectedFrame() == NULL) + if (getSelectedFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrDestNdef); - else if (getTutorFrame() == NULL) + else if (getTutorFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorNdef); else if (getSelectedFrame() == getTutorFrame()) QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame); - else if (getSelectedFrame()->client() == NULL) + else if (getSelectedFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrDestOffline); - else if (getTutorFrame()->client() == NULL) + else if (getTutorFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else { // If this is the first call in this mode clear the watchers if (_mode != Mode::Multicast) { for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) + if ((*it)->client() != nullptr) (*it)->client()->setDesiredProjectionSource(NO_SOURCE); } @@ -925,15 +928,15 @@ void MainWindow::onButtonStudentToTutor() { ui->action_Lock->setChecked(false); - if (getSelectedFrame() == NULL) + if (getSelectedFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrSourceNdef); - else if (getTutorFrame() == NULL) + else if (getTutorFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorNdef); else if (getTutorFrame() == getSelectedFrame()) QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame); - else if (getSelectedFrame()->client() == NULL) + else if (getSelectedFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrSourceOffline); - else if (getTutorFrame()->client() == NULL) + else if (getTutorFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else { // If this is not the first run in this mode and the current source is selected, stop the streaming. @@ -946,7 +949,7 @@ void MainWindow::onButtonStudentToTutor() // Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) + if ((*it)->client() != nullptr) (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id() : NO_SOURCE); disableButtons(); @@ -963,15 +966,15 @@ void MainWindow::onButtonStudentToTutorExclusive() { ui->action_Lock->setChecked(false); - if (getSelectedFrame() == NULL) + if (getSelectedFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrSourceNdef); - else if (getTutorFrame() == NULL) + else if (getTutorFrame() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorNdef); else if (getTutorFrame() == getSelectedFrame()) QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame); - else if (getSelectedFrame()->client() == NULL) + else if (getSelectedFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrSourceOffline); - else if (getTutorFrame()->client() == NULL) + else if (getTutorFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else { Client *selectedClient = getSelectedFrame()->client(); @@ -986,7 +989,7 @@ void MainWindow::onButtonStudentToTutorExclusive() // Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) + if ((*it)->client() != nullptr) (*it)->client()->setDesiredProjectionSource(tutorClient->id() == (*it)->client()->id() ? selectedClient->id() : NO_SOURCE); disableButtons(); @@ -1022,14 +1025,14 @@ void MainWindow::onButtonLock(bool checked) void MainWindow::onButtonLockSingle() { // If no frame is selected, warning. - if (getSelectedFrame() == NULL) { + if (getSelectedFrame() == nullptr) { QMessageBox::critical(this, tr("Selection"), tr("No client is selected.")); return; } Client *client = getSelectedFrame()->client(); // If frame of inactive client has been selected unselect it - if (client == NULL) { + if (client == nullptr) { QMessageBox::critical(this, tr("Selection"), tr("The selected client is not connected.")); return; } else { // If selected client is locked, first unlock @@ -1038,7 +1041,7 @@ void MainWindow::onButtonLockSingle() if (!newState) { // If no more clients are locked, reset button for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if ((*it)->client() == NULL) + if ((*it)->client() == nullptr) continue; if ((*it)->client()->isLocked()) return; @@ -1063,13 +1066,13 @@ void MainWindow::onButtonExit() void MainWindow::onButtonSetAsTutor() { // If no frame is selected, warning. - if (getSelectedFrame() == NULL) { + if (getSelectedFrame() == 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() == NULL) { + if (getSelectedFrame()->client() == nullptr) { QMessageBox::critical(this, tr("Selection"), tr("The selected client is not connected.")); return; } else { // If selected client is locked, first unlock @@ -1081,7 +1084,7 @@ void MainWindow::onButtonSetAsTutor() return; // Else unset the old and set the new tutor - if (getTutorFrame() != NULL) { + if (getTutorFrame() != nullptr) { getTutorFrame()->setTutor(false); } getSelectedFrame()->setTutor(true); @@ -1122,7 +1125,7 @@ void MainWindow::onClientAuthenticating(Client* client, ClientLogin* request) inuse = false; for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { Client *c = (**it).client(); - if (c == NULL) + if (c == nullptr) continue; if (!c->isAuthed()) continue; @@ -1158,8 +1161,8 @@ void MainWindow::onClientAuthenticated(Client* client) disconnect(client, SIGNAL(authenticated(Client*)), this, SLOT(onClientAuthenticated(Client*))); connect(client, SIGNAL(vncServerStateChange(Client*)), this, SLOT(onVncServerStateChange(Client*))); connect(client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(onVncClientStateChange(Client*))); - ConnectionFrame *existing = NULL; - ConnectionFrame *cf = NULL; + ConnectionFrame *existing = nullptr; + ConnectionFrame *cf = nullptr; for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { if ((*it)->computerId() == client->ip()) { existing = *it; @@ -1167,7 +1170,7 @@ void MainWindow::onClientAuthenticated(Client* client) } // Clients ip already exists, but was not active. - if (existing != NULL) { + if (existing != nullptr) { cf = existing; } else { cf = createFrame(); @@ -1193,7 +1196,7 @@ void MainWindow::onVncServerStateChange(Client* client) if (client->isActiveVncServer()) { // apply the desired projection sources for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ( (*it)->client() != NULL) { // Ignore offline clients + if ( (*it)->client() != nullptr) { // Ignore offline clients if ( (*it)->client()->desiredProjectionSource() == client->id() ) (*it)->client()->startVncClient(client); else @@ -1206,7 +1209,7 @@ void MainWindow::onVncServerStateChange(Client* client) } else { // VNC server stopped on some client or failed to start - reset local pending projection information for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if ((*it)->client() != NULL) { + if ((*it)->client() != nullptr) { if ((*it)->client()->desiredProjectionSource() == client->id()) { (*it)->client()->setDesiredProjectionSource(NO_SOURCE); (*it)->client()->stopVncClient(); @@ -1234,7 +1237,7 @@ void MainWindow::onVncServerStateChange(Client* client) */ void MainWindow::onVncClientStateChange(Client* client) { - if (client != NULL) { + if (client != nullptr) { // VNC Client stopped -> remove from watchers if (!client->isActiveVncClient()) { // Only unset a desired Projection source if it has not changed meanwhile @@ -1252,7 +1255,7 @@ void MainWindow::onVncClientStateChange(Client* client) */ bool serverHasWatchers = false; for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL) + if ((*it)->client() != nullptr) if ((*it)->client()->desiredProjectionSource() == client->projectionSource()) { serverHasWatchers = true; break; @@ -1260,7 +1263,7 @@ void MainWindow::onVncClientStateChange(Client* client) if ( !serverHasWatchers ) { Client* c = getClientFromId(client->projectionSource()); - if (c != NULL) + if (c != nullptr) c->stopVncServer(); } } @@ -1296,11 +1299,11 @@ void MainWindow::onDeleteClient() { // If no frame is selected, warning. ConnectionFrame* frame = getSelectedFrame(); - if (frame == NULL) { + if (frame == nullptr) { QMessageBox::critical(this, tr("Selection"), tr("No client is selected.")); return; } - if (frame->client() != NULL) { + if (frame->client() != nullptr) { QMessageBox::critical(this, tr("Selection"), tr("This client is still connected.")); return; } diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 4e99747..43804a7 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -44,8 +44,8 @@ private: Qt::ToolBarArea _tbArea; int _tilesX; int _tilesY; - QImage* _backgroundImage = NULL; - QLabel* _examModeLabel = NULL; + QImage* _backgroundImage = nullptr; + QLabel* _examModeLabel = nullptr; /* virtual columns to preserve the aspect ratio of the loaded room */ @@ -79,7 +79,7 @@ private: QPoint closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore); void placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred = QPoint(-1, -1)); - ConnectionFrame* createFrame(const QString &computerId = QString(), const QPoint *gridPosition = NULL, bool fromRoomplan = false); + ConnectionFrame* createFrame(const QString &computerId = QString(), const QPoint *gridPosition = nullptr, bool fromRoomplan = false); void savePosition(ConnectionFrame *cf); void startVncServerIfNecessary(int from); void tellClientCurrentSituation(Client* client); diff --git a/src/server/net/certmanager.cpp b/src/server/net/certmanager.cpp index a7df6cc..a503088 100644 --- a/src/server/net/certmanager.cpp +++ b/src/server/net/certmanager.cpp @@ -66,7 +66,7 @@ bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &ce void fatal() { - QMessageBox::critical(NULL, QCoreApplication::trUtf8("OpenSSL error", "CertManager"), + QMessageBox::critical(nullptr, QCoreApplication::trUtf8("OpenSSL error", "CertManager"), QCoreApplication::trUtf8("Could not generate certificates for secure connections.\n" "PVS will not work.\n\n" "Press OK to quit.", "CertManager")); diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index c11cb63..9e96dec 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -19,7 +19,7 @@ int Client::_clientIdCounter = 0; /******************************************************************************/ Client::Client(QTcpSocket* socket) : _socket(socket) { - assert(socket != NULL); + assert(socket != nullptr); _authed = 0; _projectionSource = 0; _desiredSource = 0; diff --git a/src/server/net/listenserver.cpp b/src/server/net/listenserver.cpp index 0a585c7..628b62d 100644 --- a/src/server/net/listenserver.cpp +++ b/src/server/net/listenserver.cpp @@ -31,7 +31,7 @@ ListenServer::~ListenServer() void ListenServer::newClientConnection() { QTcpSocket* sock; - while ((sock = _server.nextPendingConnection()) != NULL) { + while ((sock = _server.nextPendingConnection()) != nullptr) { Client* client = new Client(sock); // TODO: what happens with disconnected clients emit newClient(client); } diff --git a/src/server/net/sslserver.cpp b/src/server/net/sslserver.cpp index 0e0639e..c11f0ae 100644 --- a/src/server/net/sslserver.cpp +++ b/src/server/net/sslserver.cpp @@ -20,7 +20,7 @@ #include "certmanager.h" #include <unistd.h> -SslServer::SslServer() : QTcpServer(NULL) +SslServer::SslServer() : QTcpServer(nullptr) { _tmr = startTimer(5123); } @@ -43,10 +43,10 @@ void SslServer::incomingConnection(qintptr socketDescriptor) if (++certFails > 5) { CertManager::fatal(); } - ::close(socketDescriptor); + ::close((int)socketDescriptor); return; } - QSslSocket *serverSocket = new QSslSocket(NULL); + QSslSocket *serverSocket = new QSslSocket(nullptr); connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &))); connect(serverSocket, SIGNAL(disconnected()), this, SLOT(sock_closed())); connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sock_error(QAbstractSocket::SocketError))); @@ -70,7 +70,7 @@ void SslServer::incomingConnection(qintptr socketDescriptor) } } -void SslServer::sslErrors(const QList<QSslError> &errors) +void SslServer::sslErrors(const QList<QSslError>& /* errors */) { /* qDebug() << "Client caused sslErrors before connection:"; @@ -134,6 +134,6 @@ QTcpSocket* SslServer::nextPendingConnection() return sock; } } - return NULL; + return nullptr; } diff --git a/src/server/serverapp/serverapp.cpp b/src/server/serverapp/serverapp.cpp index 7ee06e0..f680f89 100644 --- a/src/server/serverapp/serverapp.cpp +++ b/src/server/serverapp/serverapp.cpp @@ -7,7 +7,7 @@ static QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize ServerApp::ServerApp(int& argc, char** argv) : QApplication(argc, argv), - _mainWindow(NULL), + _mainWindow(nullptr), _managerOnly(false), _isExam(false) { @@ -132,8 +132,8 @@ const Room* ServerApp::getCurrentRoom() if (_rooms.contains(_currentRoom)) { return _rooms[_currentRoom]; } else { - static Room* defaultRoom = NULL; - if (defaultRoom == NULL) { + static Room* defaultRoom = nullptr; + if (defaultRoom == nullptr) { defaultRoom = new Room(QMap<QString, QPoint>(), QSize(8, 6), QSize(1, 1), "", ""); } diff --git a/src/server/util/platform/screensaver.cpp b/src/server/util/platform/screensaver.cpp index efffba9..cdd6ee1 100644 --- a/src/server/util/platform/screensaver.cpp +++ b/src/server/util/platform/screensaver.cpp @@ -14,17 +14,17 @@ namespace { - Display *display = NULL; + Display *display = nullptr; bool extensionSupported = false; bool dpmsSupported = false; bool init() { - if (display != NULL) { + if (display != nullptr) { return true; } display = QX11Info::display(); - if (display == NULL) { + if (display == nullptr) { return false; } #ifdef X11_Xscreensaver_FOUND diff --git a/src/shared/networkmessage.cpp b/src/shared/networkmessage.cpp index 64e02e7..0bdf3c5 100644 --- a/src/shared/networkmessage.cpp +++ b/src/shared/networkmessage.cpp @@ -22,32 +22,32 @@ ((((x) & 0xFF00u) >> 8) | \ (((x) & 0x00FFu) << 8)) -static quint16 _htons(quint16 x) +static quint16 _htons(const quint16 x) { if (QSysInfo::ByteOrder == QSysInfo::BigEndian) return x; return (quint16)BYTE_SWAP2(x); } -static quint16 _ntohs(quint16 x) +static quint32 _htonl(const quint32 x) { if (QSysInfo::ByteOrder == QSysInfo::BigEndian) return x; - return (quint16)BYTE_SWAP2(x); + return (quint32)BYTE_SWAP4(x); } -static quint32 _htonl(quint32 x) +static quint16 _ntohs(const char *in) { - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - return x; - return (quint32)BYTE_SWAP4(x); + return quint16(quint8(in[0]) << 8 + | quint8(in[1])); } -static quint32 _ntohl(quint32 x) +static quint32 _ntohl(const char *in) { - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - return x; - return (quint32)BYTE_SWAP4(x); + return quint32(quint8(in[0])) << 24 + | quint32(quint8(in[1])) << 16 + | quint32(quint8(in[2])) << 8 + | quint32(quint8(in[3])); } /* @@ -56,7 +56,7 @@ static quint32 _ntohl(quint32 x) */ NetworkMessage::NetworkMessage() : - _buffer(NULL), _bufferSize(0), _bufferPos(0), _lastBufferSize(0), _mode(0) + _buffer(nullptr), _bufferSize(0), _bufferPos(0), _lastBufferSize(0), _mode(0) { // } @@ -69,7 +69,7 @@ NetworkMessage::~NetworkMessage() inline void NetworkMessage::allocBuffer() { - if (_lastBufferSize < _bufferSize || _buffer == NULL) { + if (_lastBufferSize < _bufferSize || _buffer == nullptr) { if (_buffer) delete[] _buffer; _lastBufferSize = _bufferSize; @@ -150,7 +150,7 @@ bool NetworkMessage::parseHeader(char *header) return false; } _bufferPos = 0; - _bufferSize = _ntohl(*(quint32*)(header + 4)); + _bufferSize = _ntohl(header + 4); if (_bufferSize > MAX_MSG_LEN) { qDebug("Disconnecting Client: MAX_MSG_LEN exceeded."); return false; @@ -166,9 +166,9 @@ bool NetworkMessage::parseMessage(char *buffer) { char *ptr = buffer; while (_bufferSize - (ptr - buffer) >= 4) { - const quint16 keyLen = _ntohs(*(quint16*)(ptr)); + const quint16 keyLen = _ntohs(ptr); ptr += 2; - const quint16 valLen = _ntohs(*(quint16*)(ptr)); + const quint16 valLen = _ntohs(ptr); ptr += 2; if (_bufferSize - (ptr - buffer) < keyLen + valLen) { qDebug() << "Warning: Error parsing message. key(" << keyLen << ")+value(" << valLen @@ -237,7 +237,7 @@ void NetworkMessage::serializeMessage() { QByteArray buf; //qDebug() << "Default size: " << buf.capacity(); - buf.reserve(_lastBufferSize > 0 ? _lastBufferSize : 200); + buf.reserve(_lastBufferSize > 0 ? int(_lastBufferSize) : 200); for (QHash<QByteArray, QByteArray>::const_iterator it = _fields.begin(); it != _fields.end(); ++it) { const QByteArray &ba = it.key(); const QByteArray &val = it.value(); @@ -249,9 +249,9 @@ void NetworkMessage::serializeMessage() buf.append(ba); buf.append(val); } - _bufferSize = buf.length() + HEADER_LEN; + _bufferSize = quint32(buf.length() + HEADER_LEN); allocBuffer(); - memcpy(_buffer + HEADER_LEN, buf.data(), buf.size()); + memcpy(_buffer + HEADER_LEN, buf.data(), size_t(buf.size())); _buffer[0] = 'P'; _buffer[1] = 'V'; _buffer[2] = 'S'; diff --git a/src/shared/util.h b/src/shared/util.h index c2e5145..e9530a8 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -10,6 +10,6 @@ #include <QByteArray> -QByteArray genSha1(const QByteArray* a, const QByteArray* b = NULL, const QByteArray* c = NULL, const QByteArray* d = NULL, const QByteArray* e = NULL); +QByteArray genSha1(const QByteArray* a, const QByteArray* b = nullptr, const QByteArray* c = nullptr, const QByteArray* d = nullptr, const QByteArray* e = nullptr); #endif /* UTIL_H_ */ |