diff options
Diffstat (limited to 'src/client')
24 files changed, 514 insertions, 588 deletions
diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp index 6e1a555..18ef0de 100644 --- a/src/client/clientapp/clientapp.cpp +++ b/src/client/clientapp/clientapp.cpp @@ -1,54 +1,57 @@ #include "clientapp.h" ClientApp::ClientApp(int& argc, char** argv) - : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false) { - /* some values */ - setOrganizationName("openslx"); - setOrganizationDomain("openslx.org"); - setApplicationName("pvsclient"); - - /* configuration */ - QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); - - _arguments = parseParameters(); - - - /* TODO: Move the connection handling to ClientApp */ - if (_connectionMode == ConnectionMode::Auto) { - _toolbar = new Toolbar(true); // auto connect client without session ID. - } else if (_connectionMode == ConnectionMode::Session) { - _toolbar = new Toolbar(_sessionName.toUtf8()); // connect client with given session ID. - } else { - _toolbar = new Toolbar(); // create normal client. - } - _toolbar->setVisible(!_examMode); - - /* set translator */ - /* use system locale as language to translate gui */ - QTranslator translator; - translator.load(":pvsclient"); - installTranslator(&translator); + : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false) +{ + /* some values */ + setOrganizationName("openslx"); + setOrganizationDomain("openslx.org"); + setApplicationName("pvsclient"); + + /* configuration */ + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); + + _arguments = parseParameters(); + + + /* TODO: Move the connection handling to ClientApp */ + if (_connectionMode == ConnectionMode::Auto) { + _toolbar = new Toolbar(true); // auto connect client without session ID. + } else if (_connectionMode == ConnectionMode::Session) { + _toolbar = new Toolbar(_sessionName.toUtf8()); // connect client with given session ID. + } else { + _toolbar = new Toolbar(); // create normal client. + } + _toolbar->setVisible(!_examMode); + + /* set translator */ + /* use system locale as language to translate gui */ + QTranslator translator; + translator.load(":pvsclient"); + installTranslator(&translator); }; /* parse arguments and return a list with the unused arguments */ -QStringList ClientApp::parseParameters() { - QStringList rest; - for (QString a : QApplication::arguments()) { - if (a == "--exam-mode") { - _examMode = true; - } else if (a == "--auto") { - _connectionMode = ConnectionMode::Auto; - } else if (a.startsWith("--session=")) { - _connectionMode = ConnectionMode::Session; - _sessionName = a.replace("--session=", ""); - } else { - rest << a; - } - } - return rest; +QStringList ClientApp::parseParameters() +{ + QStringList rest; + for (QString a : QApplication::arguments()) { + if (a == "--exam-mode") { + _examMode = true; + } else if (a == "--auto") { + _connectionMode = ConnectionMode::Auto; + } else if (a.startsWith("--session=")) { + _connectionMode = ConnectionMode::Session; + _sessionName = a.replace("--session=", ""); + } else { + rest << a; + } + } + return rest; } -QStringList ClientApp::arguments() { - return _arguments; +QStringList ClientApp::arguments() +{ + return _arguments; } diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h index 996d48d..910eba2 100644 --- a/src/client/clientapp/clientapp.h +++ b/src/client/clientapp/clientapp.h @@ -14,27 +14,28 @@ * several widgets. With this class information access will also be easier as * it is possible to access the current ClientApp instance from anywhere with * the clientApp macro (like qApp) macro */ -class ClientApp : public QApplication { +class ClientApp : public QApplication +{ - Q_OBJECT + Q_OBJECT - public: - enum ConnectionMode { None, Auto, Session }; +public: + enum ConnectionMode { None, Auto, Session }; - private: - bool _examMode; - ConnectionMode _connectionMode; /* way of automatically connection to a session on startup*/ - QString _sessionName; /* only set when _connectionMode == Session */ - Toolbar* _toolbar; - QStringList _arguments; +private: + bool _examMode; + ConnectionMode _connectionMode; /* way of automatically connection to a session on startup*/ + QString _sessionName; /* only set when _connectionMode == Session */ + Toolbar* _toolbar; + QStringList _arguments; - QStringList parseParameters(); + QStringList parseParameters(); - public: +public: - ClientApp(int& argc, char** argv); + ClientApp(int& argc, char** argv); - bool isExamMode() const { return _examMode; }; + bool isExamMode() const { return _examMode; }; - virtual QStringList arguments(); + virtual QStringList arguments(); }; diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 712691e..fed4256 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -21,7 +21,7 @@ * @param parent */ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) -{ +{ _ui = new Ui::ConnectWindow; _timerHide = 0; _connection = NULL; @@ -41,17 +41,17 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) connect(_ui->btn_connection, SIGNAL(clicked()), this, SLOT(onBtnConnection())); connect(_ui->btn_hide, SIGNAL(clicked()), this, SLOT(onBtnCancel())); - connect(_ui->comboBox_rooms, SIGNAL(currentIndexChanged(int)), this, SLOT(onRoomSelection(int))); + connect(_ui->comboBox_rooms, SIGNAL(currentIndexChanged(int)), this, SLOT(onRoomSelection(int))); // React on discovery signal - connect(&_serverDiscovery, SIGNAL(serverDetected(QString,quint16,QByteArray,QByteArray,bool)), - this, SLOT(onServerDetected(QString,quint16,QByteArray,QByteArray,bool))); + connect(&_serverDiscovery, SIGNAL(serverDetected(QString, quint16, QByteArray, QByteArray, bool)), + this, SLOT(onServerDetected(QString, quint16, QByteArray, QByteArray, bool))); - /* finally the most requested feature: connect on press of the enter key */ - connect(_ui->lineEditName, SIGNAL(returnPressed()),_ui->btn_connection, SIGNAL(clicked())); + /* finally the most requested feature: connect on press of the enter key */ + connect(_ui->lineEditName, SIGNAL(returnPressed()), _ui->btn_connection, SIGNAL(clicked())); - /* by default don't show the manual connection box */ - _ui->box_manual->setVisible(false); + /* by default don't show the manual connection box */ + _ui->box_manual->setVisible(false); this->updateUserInterface(); } @@ -59,7 +59,7 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) /***************************************************************************//** * @brief ConnectWindow::~ConnectWindow */ -ConnectWindow::~ConnectWindow(){} +ConnectWindow::~ConnectWindow() {} @@ -71,8 +71,7 @@ void ConnectWindow::updateUserInterface() { _ui->lineEditName->setEnabled(_state == Idle); - if (_state == Connected) - { + if (_state == Connected) { _ui->btn_connection->setEnabled(true); _ui->btn_connection->setText(tr("&Disconnect")); _ui->lblStatus->setText(tr("Connected to %1").arg(_connection->getPeerAdress())); @@ -86,8 +85,7 @@ void ConnectWindow::updateUserInterface() else _ui->btn_connection->setText(tr("&Connect")); - switch (_state) - { + switch (_state) { case Idle: _ui->lblStatus->setText(tr("Ready to connect.")); break; @@ -128,14 +126,12 @@ void ConnectWindow::updateUserInterface() */ void ConnectWindow::timerEvent(QTimerEvent* event) { - if(event->timerId() == _timerHide) - { + if (event->timerId() == _timerHide) { killTimer(_timerHide); _timerHide = 0; this->hide(); _ui->stackedWidget->setCurrentIndex(0); - } - else + } else // Unknown/Old timer id, kill it ??? PALM -> FACE killTimer(event->timerId()); } @@ -152,9 +148,9 @@ void ConnectWindow::closeEvent(QCloseEvent *e) void ConnectWindow::doShow() { - /* reset to automatic connect window */ - _ui->stackedWidget->setCurrentIndex(0); - _ui->comboBox_rooms->setCurrentIndex(0); + /* reset to automatic connect window */ + _ui->stackedWidget->setCurrentIndex(0); + _ui->comboBox_rooms->setCurrentIndex(0); show(); showNormal(); activateWindow(); @@ -196,29 +192,31 @@ void ConnectWindow::connectToSession(const QByteArray sessionName, QString mgrIP -void ConnectWindow::DoConnect() { - qDebug() << "DoConnect()"; - // Connect (scan for session) - // qDebug() << _ui->lineEditName->text().toUtf8(); - int index = _ui->comboBox_rooms->currentIndex(); - QString selectedMgrIP =_ui->comboBox_rooms->itemData(index).toString(); - - if (selectedMgrIP == "manual_connection") { - qDebug() << "connect to sessionName by manual connection"; - QByteArray sessionName = _ui->lineEditName->text().toUtf8(); - connectToSession(sessionName, ""); - } else { - qDebug() << "connect to mgrIP (through room selection) " << selectedMgrIP; - connectToSession("", selectedMgrIP); - } +void ConnectWindow::DoConnect() +{ + qDebug() << "DoConnect()"; + // Connect (scan for session) + // qDebug() << _ui->lineEditName->text().toUtf8(); + int index = _ui->comboBox_rooms->currentIndex(); + QString selectedMgrIP = _ui->comboBox_rooms->itemData(index).toString(); + + if (selectedMgrIP == "manual_connection") { + qDebug() << "connect to sessionName by manual connection"; + QByteArray sessionName = _ui->lineEditName->text().toUtf8(); + connectToSession(sessionName, ""); + } else { + qDebug() << "connect to mgrIP (through room selection) " << selectedMgrIP; + connectToSession("", selectedMgrIP); + } } -void ConnectWindow::DoDisconnect() { - qDebug() << "DoDisconnect()"; - _tryReconnect = false; - // Stop or disconnect - emit disconnect(); - _state = Idle; +void ConnectWindow::DoDisconnect() +{ + qDebug() << "DoDisconnect()"; + _tryReconnect = false; + // Stop or disconnect + emit disconnect(); + _state = Idle; } @@ -229,7 +227,7 @@ void ConnectWindow::DoDisconnect() { */ void ConnectWindow::onBtnConnection() { - if (_timerHide){ + if (_timerHide) { killTimer(_timerHide); _timerHide = 0; _ui->stackedWidget->setCurrentIndex(0); @@ -239,23 +237,24 @@ void ConnectWindow::onBtnConnection() _serverDiscovery.stop(); if (_state != Idle) { - DoDisconnect(); + DoDisconnect(); } else { - DoConnect(); + DoConnect(); } - this->updateUserInterface(); + this->updateUserInterface(); } /** set the available rooms. * If the list of rooms is empty, switches automatically to the "manual * connection" page */ -void ConnectWindow::setAvailableRooms(QList<Room> m) { - _ui->comboBox_rooms->clear(); - foreach (Room r, m) { - _ui->comboBox_rooms->addItem(tr("Room ") + r.name, r.mgr); - } - /* also add a pseudo-room "manual choice" */ - _ui->comboBox_rooms->addItem(tr("Session Name..."), "manual_connection"); +void ConnectWindow::setAvailableRooms(QList<Room> m) +{ + _ui->comboBox_rooms->clear(); + foreach (Room r, m) { + _ui->comboBox_rooms->addItem(tr("Room ") + r.name, r.mgr); + } + /* also add a pseudo-room "manual choice" */ + _ui->comboBox_rooms->addItem(tr("Session Name..."), "manual_connection"); } /***************************************************************************//** * Handle click on Cancel/Hide Button. @@ -268,17 +267,18 @@ void ConnectWindow::onBtnCancel() /** check if "manual_connection" is selected, then switch to manual * connection page */ -void ConnectWindow::onRoomSelection(int index) { - QString sessionName = _ui->comboBox_rooms->itemData(index).toString(); - if (sessionName == "manual_connection") { - qDebug() << "switch to manual connection"; - _ui->box_manual->setVisible(true); - //this->setSize(QSize(300,200)); - this->resize(300, 200); - } else { - _ui->box_manual->setVisible(false); - this->resize(300, 140); - } +void ConnectWindow::onRoomSelection(int index) +{ + QString sessionName = _ui->comboBox_rooms->itemData(index).toString(); + if (sessionName == "manual_connection") { + qDebug() << "switch to manual connection"; + _ui->box_manual->setVisible(true); + //this->setSize(QSize(300,200)); + this->resize(300, 200); + } else { + _ui->box_manual->setVisible(false); + this->resize(300, 140); + } } /***************************************************************************//** @@ -313,8 +313,7 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state if (reset) { _state = Scanning; } - if (state == Connected) - { + if (state == Connected) { QObject::disconnect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); QObject::disconnect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); emit connected(_connection); @@ -326,11 +325,12 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state } } -void ConnectWindow::onComboBox_keyPressed(QKeyEvent* e) { - qDebug() << "key released"; - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) { - qDebug() << "enter pressed"; - } +void ConnectWindow::onComboBox_keyPressed(QKeyEvent* e) +{ + qDebug() << "key released"; + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) { + qDebug() << "enter pressed"; + } } diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 3eed6e0..aa89094 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -24,7 +24,8 @@ #include "../net/serverdiscovery.h" #include "../util/room.h" -namespace Ui{ +namespace Ui +{ class ConnectWindow; } class ServerConnection; @@ -38,7 +39,7 @@ class ServerConnection; */ class ConnectWindow : public QWidget { -Q_OBJECT + Q_OBJECT public: enum ConnectionState { @@ -55,9 +56,9 @@ public: explicit ConnectWindow(QWidget *parent = NULL); virtual ~ConnectWindow(); - + void connectToSession(const QByteArray sessionName, QString mgrIP); - void setAvailableRooms(QList<Room> m); + void setAvailableRooms(QList<Room> m); private: Ui::ConnectWindow *_ui; @@ -67,7 +68,7 @@ private: ConnectionState _state; QByteArray _currentSession; QString _currentIp; - QString _defaultSessionName; + QString _defaultSessionName; NetworkMessage _packet; bool _tryReconnect; int _timerHide; @@ -84,7 +85,7 @@ protected slots: void onBtnConnection(); void onBtnCancel(); - void onRoomSelection(int index); + void onRoomSelection(int index); void onConnectionStateChange(ConnectWindow::ConnectionState state); void onConnectionClosed(QObject* connection); @@ -92,13 +93,13 @@ protected slots: // void onUdpReadyRead(); void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); - void onComboBox_keyPressed(QKeyEvent* e); + void onComboBox_keyPressed(QKeyEvent* e); public slots: - /** actually connects the connection **/ - void DoConnect(); - /** actually disconnects the connection **/ - void DoDisconnect(); + /** actually connects the connection **/ + void DoConnect(); + /** actually disconnects the connection **/ + void DoDisconnect(); signals: void disconnect(); void connected(ServerConnection* connection); diff --git a/src/client/informationdialog/informationdialog.cpp b/src/client/informationdialog/informationdialog.cpp index bc53ee9..6a8a6b7 100644 --- a/src/client/informationdialog/informationdialog.cpp +++ b/src/client/informationdialog/informationdialog.cpp @@ -2,7 +2,8 @@ #include <QNetworkInterface> #include <QHostInfo> -InformationDialog::InformationDialog() : QDialog() { +InformationDialog::InformationDialog() : QDialog() +{ /* widgets */ _lblTitle = new QLabel(tr("<h1>system information</h1>")); @@ -23,12 +24,13 @@ InformationDialog::InformationDialog() : QDialog() { qDebug() << "create information dialog"; } -void InformationDialog::initTable() { +void InformationDialog::initTable() +{ /* NETWORK*/ /* hostnames */ _tableLayout->addRow(new QLabel(tr("hostname")), new QLabel(QHostInfo::localHostName())); /* ips */ - for (QHostAddress a: QNetworkInterface::allAddresses()) { + for (QHostAddress a : QNetworkInterface::allAddresses()) { QString ip = a.toString(); if (ip == "::1" || ip == "127.0.0.1") { continue;} diff --git a/src/client/informationdialog/informationdialog.h b/src/client/informationdialog/informationdialog.h index 6bbf41c..f1a32a5 100644 --- a/src/client/informationdialog/informationdialog.h +++ b/src/client/informationdialog/informationdialog.h @@ -8,9 +8,10 @@ #include <QStringList> -class InformationDialog : public QDialog { +class InformationDialog : public QDialog +{ - private: +private: QLayout* _layout; QFormLayout* _tableLayout; QLabel* _lblTitle; @@ -18,7 +19,7 @@ class InformationDialog : public QDialog { void initTable(); - public: +public: InformationDialog(); }; diff --git a/src/client/main.cpp b/src/client/main.cpp index d0c6bd9..61ca0e9 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -8,20 +8,20 @@ int main(int argc, char** argv) { - ClientApp app(argc, argv); - qsrand((uint)QDateTime::currentMSecsSinceEpoch()); + ClientApp app(argc, argv); + qsrand((uint)QDateTime::currentMSecsSinceEpoch()); - /* here we handle the arguments that were not handled by ClientApp */ - for (QString a : app.arguments()) { - if (a == "--usage" || a == "--help") { - qStdout() << "Usage: pvsclient [--exam-mode] [--auto|--session=xxx|\"\"]" << endl; - exit(0); - } else if (a.contains("pvsclient")) { - /* do nothing */ - } else { - qStdout() << "Unknown argument: " << a << endl; - exit(1); - } - } - return app.exec(); + /* here we handle the arguments that were not handled by ClientApp */ + for (QString a : app.arguments()) { + if (a == "--usage" || a == "--help") { + qStdout() << "Usage: pvsclient [--exam-mode] [--auto|--session=xxx|\"\"]" << endl; + exit(0); + } else if (a.contains("pvsclient")) { + /* do nothing */ + } else { + qStdout() << "Unknown argument: " << a << endl; + exit(1); + } + } + return app.exec(); } diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index f4a6fd6..5c812d5 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -24,17 +24,17 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons { _socket = new QSslSocket(); _blank = new BlankScreen(); - connect(_socket, SIGNAL(encrypted()), this, SLOT(sock_connected())); - connect(_socket, SIGNAL(readyRead()), this, SLOT(sock_dataArrival())); - connect(_socket, SIGNAL(disconnected()), this, SLOT(sock_closed())); - connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sock_error(QAbstractSocket::SocketError))); - connect(_socket, - SIGNAL(sslErrors(const QList<QSslError> &)), - this, - SLOT(sslErrors(const QList<QSslError> &)) - ); - qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port); - _socket->connectToHostEncrypted(host, port); + connect(_socket, SIGNAL(encrypted()), this, SLOT(sock_connected())); + connect(_socket, SIGNAL(readyRead()), this, SLOT(sock_dataArrival())); + connect(_socket, SIGNAL(disconnected()), this, SLOT(sock_closed())); + connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sock_error(QAbstractSocket::SocketError))); + connect(_socket, + SIGNAL(sslErrors(const QList<QSslError> &)), + this, + SLOT(sslErrors(const QList<QSslError> &)) + ); + qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port); + _socket->connectToHostEncrypted(host, port); _timerId = startTimer(4000); _lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; _timerConnectionCheck = startTimer(5000); @@ -44,8 +44,7 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons ServerConnection::~ServerConnection() { - if (_socket != NULL) - { + if (_socket != NULL) { qCritical("**** SOCKET DELETE IN DESTRUCTOR"); _socket->deleteLater(); } @@ -62,8 +61,7 @@ void ServerConnection::sendMessage(NetworkMessage& message) if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) return; message.writeMessage(_socket); - if (!message.writeComplete()) - { + if (!message.writeComplete()) { qCritical() << "SendMessage to server failed!"; } } @@ -75,15 +73,13 @@ void ServerConnection::sendMessage(NetworkMessage& message) */ void ServerConnection::disconnectFromServer() { - if (_timerDelete == 0) - { + if (_timerDelete == 0) { VncServer::instance()->stop(); emit closeVnc(); emit disconnected(); _timerDelete = startTimer(500); qDebug("Closing connection to server"); - if (_socket != NULL) - { + if (_socket != NULL) { _socket->blockSignals(true); _socket->abort(); } @@ -100,10 +96,8 @@ void ServerConnection::handleMsg() _lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; const QString &id = _fromServer.getFieldString(_ID); - if (_authed == 0) - { - if (id == _CHALLENGE) - { + if (_authed == 0) { + if (id == _CHALLENGE) { // Initial challenge request by server emit stateChange(ConnectWindow::AwaitingChallengeResponse); _myChallenge.resize(CHALLENGE_LEN); @@ -121,21 +115,17 @@ void ServerConnection::handleMsg() return; } - if (_authed == 1) - { - if (id == _CHALLENGE) - { + if (_authed == 1) { + if (id == _CHALLENGE) { qDebug("Received challenge reply"); - if (_timerId != 0) - { + if (_timerId != 0) { killTimer(_timerId); _timerId = 0; } // Check challenge response QByteArray serverhash(_fromServer.getFieldBytes(_HASH)); if (serverhash != genSha1(&_sessionName, &_myChallenge) - && !_autoConnect) - { + && !_autoConnect) { qDebug("invalid. STOP."); emit stateChange(ConnectWindow::InvalidSslHash); this->disconnectFromServer(); @@ -157,23 +147,18 @@ void ServerConnection::handleMsg() _toServer.setField(_EXAMMODE, clientApp->isExamMode() ? __TRUE : __FALSE); /* TODO: (Question) Why is this here not using sendMessage() ? */ qDebug("Sending login request!"); - if (_toServer.writeMessage(_socket)) - { + if (_toServer.writeMessage(_socket)) { _authed = 2; qDebug("valid, step <- 2"); - } - else - { + } else { this->disconnectFromServer(); } } return; } - if (_authed == 2) - { - if (id == _LOGIN) - { + if (_authed == 2) { + if (id == _LOGIN) { qDebug("login accepted, step <- 3"); _authed = 3; emit stateChange(ConnectWindow::Connected); @@ -182,8 +167,7 @@ void ServerConnection::handleMsg() } // message THUMB - server requests screenshot as thumbnail - if (id == _THUMB) - { + if (id == _THUMB) { if (clientApp->isExamMode()) { QByteArray emptyArray; _toServer.setField(_ID, _THUMB); @@ -207,34 +191,31 @@ void ServerConnection::handleMsg() const QRect primaryRect = primary.screenGeometry(); QPixmap desktop( - QPixmap::grabWindow( - QApplication::desktop()->winId(), - primaryRect.x(), - primaryRect.y(), - primaryRect.width(), - primaryRect.height() - ).scaled( - x, y, - Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + QPixmap::grabWindow( + QApplication::desktop()->winId(), + primaryRect.x(), + primaryRect.y(), + primaryRect.width(), + primaryRect.height() + ).scaled( + x, y, + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); QByteArray bytes; QBuffer jpgBuffer(&bytes); jpgBuffer.open(QIODevice::WriteOnly); - if (desktop.save(&jpgBuffer, "JPG", _jpegQuality)) // writes pixmap into bytes in JPG format - { + if (desktop.save(&jpgBuffer, "JPG", _jpegQuality)) { // writes pixmap into bytes in JPG format // Try to adjust quality so we stay between 3 and 4.5 KB if (_jpegQuality < 90 && bytes.size() < 3000) _jpegQuality += 7; else if (_jpegQuality > 40 && bytes.size() > 4500) _jpegQuality -= 7; - } - else - { // FALLBACK + } else { + // FALLBACK bytes.clear(); QBuffer pngBuffer(&bytes); pngBuffer.open(QIODevice::WriteOnly); - if (!desktop.save(&pngBuffer, "PNG")) // writes pixmap into bytes in PNG format - { + if (!desktop.save(&pngBuffer, "PNG")) { // writes pixmap into bytes in PNG format qDebug("Could not convert screenshot to PNG nor JPG"); return; // Failed :-( } @@ -244,42 +225,31 @@ void ServerConnection::handleMsg() _toServer.setField(_IMG, bytes); sendMessage(_toServer); } // message VNCSERVER - start local vncserver - else if (id == _VNCSERVER) - { + else if (id == _VNCSERVER) { if (clientApp->isExamMode()) { qDebug() << "denied request for vnc server (exam mode)"; return; } const bool enable = (_fromServer.getFieldString("ENABLE").toInt() != 0); - if (enable) - { + if (enable) { emit closeVnc(); // In case we are watching some other client, stop doing so VncServer::instance()->start(); - } - else - { + } else { VncServer::instance()->stop(); } - } - else if (id == _VNCCLIENT) - { + } else if (id == _VNCCLIENT) { if (clientApp->isExamMode()) { qDebug() << "denied request for vnc projection (exam mode)"; return; } const QString host(_fromServer.getFieldString("HOST")); const int port = _fromServer.getFieldString("PORT").toInt(); - if (host.isEmpty() || port <= 0) - { + if (host.isEmpty() || port <= 0) { emit closeVnc(); - } - else - { + } else { emit openVnc(host, port, _fromServer.getFieldString("ROPASS"), true, true, _fromServer.getFieldString("CAPTION"), _fromServer.getFieldString("CLIENTID").toInt(), _fromServer.getFieldBytes(_THUMB)); } - } - else if (id == _LOCK) - { + } else if (id == _LOCK) { const bool enable = (_fromServer.getFieldString("ENABLE").toInt() != 0); if (enable) _blank->lock(_fromServer.getFieldString("MESSAGE")); @@ -294,24 +264,17 @@ void ServerConnection::handleMsg() void ServerConnection::timerEvent(QTimerEvent *event) { - if (event->timerId() == _timerConnectionCheck) - { - if (_lastData < QDateTime::currentMSecsSinceEpoch()) - { + if (event->timerId() == _timerConnectionCheck) { + if (_lastData < QDateTime::currentMSecsSinceEpoch()) { this->disconnectFromServer(); killTimer(_timerConnectionCheck); } - } - else if (event->timerId() == _timerId) - { + } else if (event->timerId() == _timerId) { killTimer(_timerId); _timerId = 0; this->disconnectFromServer(); - } - else if (event->timerId() == _timerDelete) - { - if (_socket == NULL || _socket->state() == QAbstractSocket::UnconnectedState) - { + } else if (event->timerId() == _timerDelete) { + if (_socket == NULL || _socket->state() == QAbstractSocket::UnconnectedState) { if (_socket != NULL) _socket->deleteLater(); _socket = NULL; @@ -321,8 +284,7 @@ void ServerConnection::timerEvent(QTimerEvent *event) } _socket->abort(); qDebug("A socket is still pending..."); - } - else + } else killTimer(event->timerId()); } @@ -339,12 +301,9 @@ void ServerConnection::onVncServerStartStop(int port, QString& ropass, QString& { _toServer.reset(); _toServer.setField(_ID, _VNCSERVER); - if (port <= 0) - { + if (port <= 0) { _toServer.setField("PORT", QByteArray("0")); - } - else - { + } else { _toServer.setField("PORT", QString::number(port)); _toServer.setField("ROPASS", ropass); _toServer.setField("RWPASS", rwpass); @@ -374,8 +333,7 @@ void ServerConnection::onVncViewerStartStop(const bool started, const int client */ void ServerConnection::sslErrors(const QList<QSslError> & errors) { - for (QList<QSslError>::const_iterator it = errors.begin(); it != errors.end(); it++) - { + for (QList<QSslError>::const_iterator it = errors.begin(); it != errors.end(); it++) { QSslError err = *it; qDebug("Connect SSL: %s", qPrintable(err.errorString())); if (err.error() == QSslError::HostNameMismatch) @@ -392,25 +350,21 @@ void ServerConnection::sslErrors(const QList<QSslError> & errors) void ServerConnection::sock_dataArrival() { - if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) - { + if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState) { qDebug("dataArrival called in bad state"); return; } - while (_socket->bytesAvailable() > 0) - { + while (_socket->bytesAvailable() > 0) { bool retval; retval = _fromServer.readMessage(_socket); // let the message read data from socket - if (retval == NM_READ_FAILED) // error parsing msg, disconnect client! - { + if (retval == NM_READ_FAILED) { // error parsing msg, disconnect client! this->disconnectFromServer(); return; } if (retval == NM_READ_INCOMPLETE) return; - if (_fromServer.readComplete()) // message is complete - { + if (_fromServer.readComplete()) { // message is complete this->handleMsg(); if (_socket == NULL) return; @@ -435,9 +389,8 @@ void ServerConnection::sock_error(QAbstractSocket::SocketError errcode) void ServerConnection::sock_connected() { - QByteArray cert(_socket->peerCertificate().digest(QCryptographicHash::Sha1)); - if (_certHash != cert) - { + QByteArray cert(_socket->peerCertificate().digest(QCryptographicHash::Sha1)); + if (_certHash != cert) { emit stateChange(ConnectWindow::InvalidCert); this->disconnectFromServer(); return; diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h index 5e2631f..aa1d0b4 100644 --- a/src/client/net/serverconnection.h +++ b/src/client/net/serverconnection.h @@ -9,7 +9,7 @@ class BlankScreen; class ServerConnection : public QObject { -Q_OBJECT + Q_OBJECT private: QSslSocket *_socket; diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index 1d1e891..4a69e91 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -12,16 +12,15 @@ */ ServerDiscovery::ServerDiscovery(QObject *parent) : QObject(parent), - _minDiscoveryInterval(500), - _maxDiscoveryInterval(5000) + _minDiscoveryInterval(500), + _maxDiscoveryInterval(5000) { _hashErrorCount = 0; _ipErrorCount = 0; /* Try to get a UDP port for server discovery */ int tries = 10; - while (tries-- != 0) - { + while (tries-- != 0) { const quint16 port = (quint16)(qrand() % 10000) + 10000; if (_discoverySocket.bind(QHostAddress::Any, port)) break; @@ -109,19 +108,14 @@ void ServerDiscovery::doDiscovery() _packet.setField(_IPLIST, iplist); // Check if specifig manager IP is given. If not broadcast in whole network. - if (_mgrIP != QHostAddress::Null) - { + if (_mgrIP != QHostAddress::Null) { qDebug() << "Broadcasting to " << _mgrIP.toString(); if (!_packet.writeMessage(&_discoverySocket, _mgrIP, SERVICE_DISCOVERY_PORT)) qDebug("Failed"); - } else - { - foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) - { - foreach (QNetworkAddressEntry entry, interface.addressEntries()) - { - if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) - { + } else { + foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) { + foreach (QNetworkAddressEntry entry, interface.addressEntries()) { + if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) { qDebug() << "Broadcasting to " << entry.broadcast().toString(); if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT)) qDebug("FAILED"); @@ -148,10 +142,9 @@ void ServerDiscovery::onUdpReadyRead() char data[UDPBUFSIZ]; QHostAddress addr; quint16 port; - while (_discoverySocket.hasPendingDatagrams()) - { + while (_discoverySocket.hasPendingDatagrams()) { // Discard any packets if discovery is stopped - if (!this->isActive()){ + if (!this->isActive()) { _discoverySocket.readDatagram(NULL, 0); continue; } @@ -171,16 +164,14 @@ void ServerDiscovery::onUdpReadyRead() const QByteArray cert(_packet.getFieldBytes(_CERT)); // Check if the source IP of the packet matches any of the addresses given in the IP list - if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString())) - { + if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString())) { ++_ipErrorCount; emit error(ErrorType::InvalidIpList, _hashErrorCount); continue; } // If so, check if the submitted hash seems valid - if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash && _mgrIP != addr) - { + if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash && _mgrIP != addr) { // did not match local session name, or other data was spoofed ++_hashErrorCount; emit error(ErrorType::InvalidHash, _ipErrorCount); @@ -189,7 +180,7 @@ void ServerDiscovery::onUdpReadyRead() /* Otherwise it's a valid reply */ qDebug() << "Server detected:" - << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes; + << addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes; // Tell that a server hs been found emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr)); diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h index a41c946..d7d6010 100644 --- a/src/client/net/serverdiscovery.h +++ b/src/client/net/serverdiscovery.h @@ -8,46 +8,47 @@ class ServerDiscovery : public QObject { - Q_OBJECT - - public: - enum class ErrorType{ - InvalidIpList, - InvalidHash - }; - - explicit ServerDiscovery(QObject *parent = 0); - ~ServerDiscovery(); - - void start(const QByteArray& sessionName, QString mgrIP); - void stop(); - inline bool isActive(){ return _discoveryTimer.isActive(); } - - private: - QTimer _discoveryTimer; - const int _minDiscoveryInterval; - const int _maxDiscoveryInterval; - int _hashErrorCount; - int _ipErrorCount; - QByteArray _nameBytes; - QByteArray _salt2; - QUdpSocket _discoverySocket; - NetworkMessage _packet; - - QHostAddress _mgrIP; - - static const int UDPBUFSIZ = 9000; - static const int SALT_LEN = 18; - - signals: - void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); - void error(ErrorType e, int count); - - public slots: - - private slots: - void doDiscovery(); - void onUdpReadyRead(); + Q_OBJECT + +public: + enum class ErrorType + { + InvalidIpList, + InvalidHash + }; + + explicit ServerDiscovery(QObject *parent = 0); + ~ServerDiscovery(); + + void start(const QByteArray& sessionName, QString mgrIP); + void stop(); + inline bool isActive() { return _discoveryTimer.isActive(); } + +private: + QTimer _discoveryTimer; + const int _minDiscoveryInterval; + const int _maxDiscoveryInterval; + int _hashErrorCount; + int _ipErrorCount; + QByteArray _nameBytes; + QByteArray _salt2; + QUdpSocket _discoverySocket; + NetworkMessage _packet; + + QHostAddress _mgrIP; + + static const int UDPBUFSIZ = 9000; + static const int SALT_LEN = 18; + +signals: + void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); + void error(ErrorType e, int count); + +public slots: + +private slots: + void doDiscovery(); + void onUdpReadyRead(); }; diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 0b97f31..724836f 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -78,7 +78,8 @@ Toolbar::Toolbar(QWidget *parent) { init(); } -void Toolbar::exit() { +void Toolbar::exit() +{ this->close(); this->deleteLater(); qApp->quit(); @@ -90,7 +91,7 @@ void Toolbar::init() /* Initialize the GUI */ _ui->setupUi(this); - _onWorkspace2 = false; + _onWorkspace2 = false; /* Set window properties */ setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); @@ -102,27 +103,27 @@ void Toolbar::init() /* Create the connect window */ _connectWindow = new ConnectWindow(NULL); - _connectWindow->setAvailableRooms(myRooms()); + _connectWindow->setAvailableRooms(myRooms()); // Connect the signals connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); - /* Setup menu */ - initMenu(); + /* Setup menu */ + initMenu(); - /* setup manager button */ - _isManagerPc = isManagerPc(); - _ui->btnManager->setVisible(_isManagerPc); - connect(_ui->btnManager, SIGNAL(clicked()), this, SLOT(onBtnManager())); + /* setup manager button */ + _isManagerPc = isManagerPc(); + _ui->btnManager->setVisible(_isManagerPc); + connect(_ui->btnManager, SIGNAL(clicked()), this, SLOT(onBtnManager())); - /* setup lock desktop button*/ + /* setup lock desktop button*/ SYSTEM_SETTINGS(conf); - bool showLock = conf.value("showLockDesktopButton").toBool(); - if (showLock) { - connect(_ui->btnLockDesktop, SIGNAL(clicked()), this, SLOT(onBtnLockDesktop())); - } else { - _ui->btnLockDesktop->setVisible(false); - } + bool showLock = conf.value("showLockDesktopButton").toBool(); + if (showLock) { + connect(_ui->btnLockDesktop, SIGNAL(clicked()), this, SLOT(onBtnLockDesktop())); + } else { + _ui->btnLockDesktop->setVisible(false); + } /* Connect the signals from vnc server */ connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int))); @@ -130,7 +131,7 @@ void Toolbar::init() /* Set position */ const QDesktopWidget desktop; const QRect primaryScreen = desktop.screenGeometry(); - move(primaryScreen.left() + (primaryScreen.width() - this->width())/2 , primaryScreen.top()); + move(primaryScreen.left() + (primaryScreen.width() - this->width()) / 2 , primaryScreen.top()); /* Setup hide timer */ _hideTimer.setInterval(500); @@ -149,16 +150,17 @@ void Toolbar::init() * This function should be called once from the main init() function which in * turn should only be called by the constructor. **/ -void Toolbar::initMenu() { +void Toolbar::initMenu() +{ _menu = new QMenu(this); _acnConnect = new QAction(tr("&Connect..."), this); - _acnDisconnect = new QAction(tr("&Disconnect"), this); - _acnDisconnect->setEnabled(false); + _acnDisconnect = new QAction(tr("&Disconnect"), this); + _acnDisconnect->setEnabled(false); _acnInformation = new QAction(tr("&Information..."), this); - _acnAbout= new QAction(tr("&What's this?"), this); + _acnAbout = new QAction(tr("&What's this?"), this); _acnQuit = new QAction(tr("&Quit"), this); - _menu->addAction(_acnConnect); + _menu->addAction(_acnConnect); _menu->addAction(_acnDisconnect); _menu->addSeparator(); _menu->addAction(_acnInformation); @@ -167,16 +169,16 @@ void Toolbar::initMenu() { _menu->addAction(_acnQuit); _ui->cmdMenu->setMenu(_menu); - /* only add a "quit"-button when the configuration allows it. */ + /* only add a "quit"-button when the configuration allows it. */ SYSTEM_SETTINGS(conf); - bool allow = conf.value("allowClientQuit").toBool(); - _acnQuit->setVisible(allow); + bool allow = conf.value("allowClientQuit").toBool(); + _acnQuit->setVisible(allow); // Connect the signals connect(_menu, SIGNAL(aboutToHide()), this, SLOT(hideBar())); connect(_acnConnect, SIGNAL(triggered()), _connectWindow, SLOT(doShow())); - connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(DoDisconnect())); + connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(DoDisconnect())); connect(_acnInformation, SIGNAL(triggered()), this, SLOT(showInformationDialog())); connect(_acnAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(_acnQuit, SIGNAL(triggered()), this, SLOT(exit())); @@ -232,82 +234,85 @@ void Toolbar::enterEvent(QEvent* e) /* returns true when the pc of this client is also eligible to be a manager */ -bool Toolbar::isManagerPc(){ - QList<Room> myRooms; +bool Toolbar::isManagerPc() +{ + QList<Room> myRooms; SYSTEM_SETTINGS(conf); QStringList roomNames = conf.value("rooms").toStringList(); - /* go through all rooms and check if this client is a manager of the room. */ + /* go through all rooms and check if this client is a manager of the room. */ for (auto roomName : roomNames) { conf.beginGroup(roomName); - QString mgrIP = conf.value("mgrIP").toString(); + QString mgrIP = conf.value("mgrIP").toString(); - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { - QString ip = conf.value("ip").toString(); - if (address.toString() == mgrIP) { - return true; - } + foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) { + QString ip = conf.value("ip").toString(); + if (address.toString() == mgrIP) { + return true; + } } conf.endGroup(); } - return false; + return false; } /* returns a sorted list of available rooms. * (Available means that this client is configured to be in that room) */ -QList<Room> Toolbar::myRooms() { +QList<Room> Toolbar::myRooms() +{ - QList<Room> myRooms; + QList<Room> myRooms; SYSTEM_SETTINGS(conf); if (!conf.contains("rooms")) { qDebug() << "Invalid config file!"; - return myRooms; + return myRooms; } QStringList roomNames = conf.value("rooms").toStringList(); - /* go through all rooms and check if this client is a member of the room. */ + /* go through all rooms and check if this client is a member of the room. */ for (auto roomName : roomNames) { conf.beginGroup(roomName); if (!conf.contains("mgrIP")) { qDebug() << "Invalid config file!"; return myRooms; } - QString mgrIP = conf.value("mgrIP").toString(); - int priority = conf.value("priority").toInt(); + QString mgrIP = conf.value("mgrIP").toString(); + int priority = conf.value("priority").toInt(); - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { + foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) { int size = conf.beginReadArray("client"); for (int j = 0; j < size; ++j) { conf.setArrayIndex(j); QString ip = conf.value("ip").toString(); if (address != QHostAddress(QHostAddress::LocalHost) - && ip == address.toString() ) { - /* add this room to the list */ - Room r(roomName, mgrIP, priority); - myRooms << r; - break; + && ip == address.toString() ) { + /* add this room to the list */ + Room r(roomName, mgrIP, priority); + myRooms << r; + break; } } conf.endArray(); } conf.endGroup(); } - /* sort */ - qStableSort(myRooms.begin(), myRooms.end(), qGreater<Room>()); - return myRooms; + /* sort */ + qStableSort(myRooms.begin(), myRooms.end(), qGreater<Room>()); + return myRooms; } /** Identifies the responsible manager for this client by searching through the * configuration file. The manager whose room has the highest priority is chosen. */ -QString Toolbar::identifyMgrIP() { - QList<Room> rooms = myRooms(); - if (!rooms.empty()) { - return rooms.first().mgr; - } else { - return ""; - } +QString Toolbar::identifyMgrIP() +{ + QList<Room> rooms = myRooms(); + if (!rooms.empty()) { + return rooms.first().mgr; + } else { + return ""; + } } /* @@ -321,13 +326,10 @@ QString Toolbar::identifyMgrIP() { void Toolbar::cameraBlink() { static bool showEye = false; - if (!showEye) - { + if (!showEye) { _ui->icon_cam->setPixmap(_beWatchedEye); showEye = true; - } - else - { + } else { _ui->icon_cam->setPixmap(QPixmap()); // set empty pixmap for blinking effect showEye = false; } @@ -358,15 +360,16 @@ void Toolbar::onVncServerIsRunning(int port) * A slot for the onDisconnected signal of the ConnectWindow. This slot will * change the UI according to the state fo the connection. */ -void Toolbar::onDisconnected() { +void Toolbar::onDisconnected() +{ if (_connection != NULL) _connection->blockSignals(true); _connection = NULL; _ui->lblStatus->setStyleSheet("color:red"); _ui->lblStatus->setText(tr("Offline")); - this->_acnConnect->setEnabled(true); - this->_acnDisconnect->setEnabled(false); + this->_acnConnect->setEnabled(true); + this->_acnDisconnect->setEnabled(false); } /***************************************************************************//** @@ -377,15 +380,14 @@ void Toolbar::onDisconnected() { */ void Toolbar::onConnected(ServerConnection* connection) { - this->_acnConnect->setEnabled(false); - this->_acnDisconnect->setEnabled(true); + this->_acnConnect->setEnabled(false); + this->_acnDisconnect->setEnabled(true); _ui->lblStatus->setStyleSheet("color:green"); _ui->lblStatus->setText(tr("Online")); // - if (_connection != NULL) - { + if (_connection != NULL) { disconnect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); _connection->blockSignals(true); _connection->disconnectFromServer(); @@ -393,7 +395,7 @@ void Toolbar::onConnected(ServerConnection* connection) _connection = connection; connect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(_connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)), - _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&))); + _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&))); connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close())); connect(_vnc, SIGNAL(running(const bool, const int)), _connection, SLOT(onVncViewerStartStop(const bool, const int))); } @@ -427,20 +429,21 @@ void Toolbar::hideBar() void Toolbar::showAboutDialog() { QMessageBox msgBox( - QMessageBox::NoIcon, - tr("About PVS Client"), - tr("The PVS - client is part of a software system for managing the "\ - "virtual data traffic within the computer pools, between the tutor's "\ - "and student's PCs. It has been developed to simplify the information "\ - "traffic in seminars and general eLearning."), - QMessageBox::NoButton, - this, - Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint|Qt::WindowStaysOnTopHint); - msgBox.setIconPixmap(QIcon(":cam32.svg").pixmap(64,64)); + QMessageBox::NoIcon, + tr("About PVS Client"), + tr("The PVS - client is part of a software system for managing the "\ + "virtual data traffic within the computer pools, between the tutor's "\ + "and student's PCs. It has been developed to simplify the information "\ + "traffic in seminars and general eLearning."), + QMessageBox::NoButton, + this, + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); + msgBox.setIconPixmap(QIcon(":cam32.svg").pixmap(64, 64)); msgBox.exec(); } -void Toolbar::showInformationDialog() { +void Toolbar::showInformationDialog() +{ InformationDialog* d = new InformationDialog(); d->exec(); } @@ -454,19 +457,21 @@ void Toolbar::showBar() move(x(), primaryScreen.top()); } /** call script to switch to workspace of the manager */ -void Toolbar::onBtnManager() { - QProcess switchP; - if (_onWorkspace2) { - switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh"); - } else { - switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh"); - } - _ui->btnManager->setDown(_onWorkspace2); - _onWorkspace2 = !_onWorkspace2; - switchP.waitForFinished(); +void Toolbar::onBtnManager() +{ + QProcess switchP; + if (_onWorkspace2) { + switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh"); + } else { + switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh"); + } + _ui->btnManager->setDown(_onWorkspace2); + _onWorkspace2 = !_onWorkspace2; + switchP.waitForFinished(); } -void Toolbar::onBtnLockDesktop() { +void Toolbar::onBtnLockDesktop() +{ qDebug() << "onBtnLockDesktop()"; if (this->lockDesktopP.state() == QProcess::NotRunning) { _ui->btnLockDesktop->setEnabled(false); @@ -479,7 +484,8 @@ void Toolbar::onBtnLockDesktop() { } } -void Toolbar::enableLockBtn() { +void Toolbar::enableLockBtn() +{ _ui->btnLockDesktop->setEnabled(true); } diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index fe2eb0b..eb05f5f 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -23,7 +23,8 @@ class ConnectWindow; class BlankScreen; -namespace Ui{ +namespace Ui +{ class Toolbar; } @@ -50,17 +51,17 @@ private: ServerConnection *_connection; QTimer _blinkTimer; VncWindow *_vnc; - bool _onWorkspace2; - bool _isManagerPc; + bool _onWorkspace2; + bool _isManagerPc; const QPixmap _cam32, _beWatchedEye; void leaveEvent(QEvent* e); void enterEvent(QEvent* e); - QList<Room> myRooms(); - bool isManagerPc(); + QList<Room> myRooms(); + bool isManagerPc(); QString identifyMgrIP(); void init(); - void initMenu(); + void initMenu(); QProcess lockDesktopP; @@ -69,8 +70,8 @@ private slots: void onDisconnected(); void onConnected(ServerConnection* connection); void onDoDisconnect(); - void onBtnManager(); - void onBtnLockDesktop(); + void onBtnManager(); + void onBtnLockDesktop(); void exit(); void cameraBlink(); void showBar(); diff --git a/src/client/util/platform/blankscreen.h b/src/client/util/platform/blankscreen.h index e42043c..35cf297 100755..100644 --- a/src/client/util/platform/blankscreen.h +++ b/src/client/util/platform/blankscreen.h @@ -11,16 +11,16 @@ class BlankScreen : public QDialog { Q_OBJECT public: - BlankScreen(); - virtual ~BlankScreen(); - void draw(bool force = false); - bool lock(const QString& message); - bool unlock(); + BlankScreen(); + virtual ~BlankScreen(); + void draw(bool force = false); + bool lock(const QString& message); + bool unlock(); private: - bool _locked; - QString _message; - BlankScreen_Sysdep* _sysdep; + bool _locked; + QString _message; + BlankScreen_Sysdep* _sysdep; }; #endif diff --git a/src/client/util/platform/blankscreen_Win32.cpp b/src/client/util/platform/blankscreen_Win32.cpp index 2bba1cf..1d1dd12 100755..100644 --- a/src/client/util/platform/blankscreen_Win32.cpp +++ b/src/client/util/platform/blankscreen_Win32.cpp @@ -1,41 +1,41 @@ -
-#include "blankscreen.h"
-#include <qwidget.h>
-
-struct BlankScreen_Sysdep {
-
- bool locked;
- QWidget* blankwin;
-
- QString lockMsg;
- int blackColor, whiteColor;
- int offX, offY;
-};
-
-BlankScreen::BlankScreen()
-{
- _sysdep = new BlankScreen_Sysdep;
- _sysdep->blankwin = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
- _sysdep->blankwin->setWindowState(Qt::WindowFullScreen);
- _sysdep->blankwin->show();
-}
-
-BlankScreen::~BlankScreen()
-{
- delete _sysdep;
-}
-
-void BlankScreen::draw(bool force)
-{
-
-}
-
-bool BlankScreen::lock(const QString& message)
-{
- return true;
-}
-
-bool BlankScreen::unlock()
-{
- return true;
-}
+ +#include "blankscreen.h" +#include <qwidget.h> + +struct BlankScreen_Sysdep { + + bool locked; + QWidget* blankwin; + + QString lockMsg; + int blackColor, whiteColor; + int offX, offY; +}; + +BlankScreen::BlankScreen() +{ + _sysdep = new BlankScreen_Sysdep; + _sysdep->blankwin = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + _sysdep->blankwin->setWindowState(Qt::WindowFullScreen); + _sysdep->blankwin->show(); +} + +BlankScreen::~BlankScreen() +{ + delete _sysdep; +} + +void BlankScreen::draw(bool force) +{ + +} + +bool BlankScreen::lock(const QString& message) +{ + return true; +} + +bool BlankScreen::unlock() +{ + return true; +} diff --git a/src/client/util/platform/blankscreen_X11.cpp b/src/client/util/platform/blankscreen_X11.cpp index db8873b..66c9f1f 100755..100644 --- a/src/client/util/platform/blankscreen_X11.cpp +++ b/src/client/util/platform/blankscreen_X11.cpp @@ -11,8 +11,7 @@ #include <cassert> #include <cstring> -struct BlankScreen_Sysdep -{ +struct BlankScreen_Sysdep { Display *dpy; }; @@ -55,9 +54,9 @@ bool BlankScreen::lock(const QString& message) XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime); - QProcess ungrabP; - ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh"); - ungrabP.waitForFinished(); + QProcess ungrabP; + ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh"); + ungrabP.waitForFinished(); _locked = true; return true; @@ -77,10 +76,10 @@ bool BlankScreen::unlock() XFlush(_sysdep->dpy); - /* start the kb-unlock.sh script */ - QProcess regrabP; - regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh"); - regrabP.waitForFinished(); + /* start the kb-unlock.sh script */ + QProcess regrabP; + regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh"); + regrabP.waitForFinished(); _locked = false; return true; diff --git a/src/client/util/room.h b/src/client/util/room.h index bfc70d0..86939f7 100644 --- a/src/client/util/room.h +++ b/src/client/util/room.h @@ -2,22 +2,25 @@ #define ROOM_H struct Room { - QString mgr; - QString name; - int priority; - Room (QString _name, QString _mgr, int _priority) { - mgr = _mgr; - name = _name; - priority = _priority; - }; + QString mgr; + QString name; + int priority; + Room (QString _name, QString _mgr, int _priority) + { + mgr = _mgr; + name = _name; + priority = _priority; + }; }; -inline QDebug operator<<(QDebug debug, const Room& r) { - debug << r.name << "{mgr=" << r.mgr << ",prio=" << r.priority << "}"; - return debug; +inline QDebug operator<<(QDebug debug, const Room& r) +{ + debug << r.name << "{mgr=" << r.mgr << ",prio=" << r.priority << "}"; + return debug; } -inline bool operator<(const Room& a, const Room& b) { - return a.priority < b.priority; +inline bool operator<(const Room& a, const Room& b) +{ + return a.priority < b.priority; } #endif diff --git a/src/client/util/util.h b/src/client/util/util.h index b47d3b1..dc604e8 100644 --- a/src/client/util/util.h +++ b/src/client/util/util.h @@ -26,8 +26,8 @@ QDir settingsDir(); inline QTextStream& qStdout() { - static QTextStream r{stdout}; - return r; + static QTextStream r {stdout}; + return r; } diff --git a/src/client/vnc/vncserver.cpp b/src/client/vnc/vncserver.cpp index aa7a89e..9d647f0 100644 --- a/src/client/vnc/vncserver.cpp +++ b/src/client/vnc/vncserver.cpp @@ -41,20 +41,19 @@ static QString makePassword(int len = 10) /***************************************************************************//** * @brief Ugly hack to get an el-cheapo platform independent sleep */ -struct Sleeper : public QThread -{ +struct Sleeper : public QThread { static void msleep(unsigned long msecs) { QThread::msleep(msecs); } }; /***************************************************************************//** * @brief VncServer::VncServer */ -VncServer::VncServer() : _process(NULL), _port(0), _timerId(0){} +VncServer::VncServer() : _process(NULL), _port(0), _timerId(0) {} /***************************************************************************//** * @brief VncServer::~VncServer */ -VncServer::~VncServer(){} +VncServer::~VncServer() {} /***************************************************************************//** * @brief VncServer::start @@ -62,8 +61,7 @@ VncServer::~VncServer(){} void VncServer::start() { // Keep things clean - if (_process != NULL) - { + if (_process != NULL) { disconnect(_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError))); disconnect(_process, SIGNAL(finished(int)), this, SLOT(onFinished(int))); } @@ -77,8 +75,7 @@ void VncServer::start() QFile pwhandle(pwfile); if (pwhandle.exists()) pwhandle.remove(); - if (!pwhandle.open(QIODevice::WriteOnly)) - { + if (!pwhandle.open(QIODevice::WriteOnly)) { qDebug() << "Could not open " << pwfile << " for writing"; emit started(0, _ropass, _rwpass); return; @@ -112,9 +109,9 @@ void VncServer::start() args << "-clip"; QString rect; rect = QString::number(primaryRect.width()) - + "x" + QString::number(primaryRect.height()) - + "+" + QString::number(primaryRect.x()) - + "+" + QString::number(primaryRect.y()); + + "x" + QString::number(primaryRect.height()) + + "+" + QString::number(primaryRect.x()) + + "+" + QString::number(primaryRect.y()); args << rect; qDebug() << "Arguments are: " << args; @@ -126,8 +123,7 @@ void VncServer::start() */ void VncServer::stop() { - if (_timerId != 0) - { + if (_timerId != 0) { killTimer(_timerId); _timerId = 0; } @@ -178,24 +174,20 @@ void VncServer::timerEvent(QTimerEvent *event) */ void VncServer::onStdOut() { - if (_process == NULL) - { + if (_process == NULL) { qDebug("VncServer::onStdOut() called in bad state."); return; } QByteArray data(_process->readAllStandardOutput()); qDebug() << "x11vnc: " << data; - if (_port <= 0) - { + if (_port <= 0) { const int pos = data.indexOf("PORT=", 0); - if (pos != -1) - { + if (pos != -1) { _port = atoi(data.constData() + pos + 5); qDebug() << "Got VNC port " << _port << ", ro " << _ropass << ", rw " << _rwpass; emit started(_port, _ropass, _rwpass); // Kill error timer, but only if port seemed valid - if (_timerId != 0 && _port > 0) - { + if (_timerId != 0 && _port > 0) { killTimer(_timerId); _timerId = 0; } @@ -208,8 +200,7 @@ void VncServer::onStdOut() */ void VncServer::onStdErr() { - if (_process == NULL) - { + if (_process == NULL) { qDebug("VncServer::onStdErr() called in bad state."); return; } diff --git a/src/client/vnc/vncserver.h b/src/client/vnc/vncserver.h index ac45822..61e6d21 100644 --- a/src/client/vnc/vncserver.h +++ b/src/client/vnc/vncserver.h @@ -31,7 +31,7 @@ private: public: static VncServer *instance(); - inline bool isVncServerRunning(){ return _port > 0; } + inline bool isVncServerRunning() { return _port > 0; } void start(); void stop(); diff --git a/src/client/vnc/vncthread.cpp b/src/client/vnc/vncthread.cpp index dfa35af..b710a2c 100644 --- a/src/client/vnc/vncthread.cpp +++ b/src/client/vnc/vncthread.cpp @@ -62,8 +62,7 @@ VncThread::~VncThread() Q_ASSERT(_run == false); if (_frameBuffer) delete[] _frameBuffer; - if (_client != NULL) - { + if (_client != NULL) { if (_client->sock != -1) ::close(_client->sock); _client->sock = -1; @@ -134,7 +133,7 @@ void VncThread::run() { qDebug("[%s] VNC client started.", metaObject()->className()); qDebug("[%s] Host: '%s' Port: %i Passwd: '%s' Quality: %i", metaObject()->className(), qPrintable(_host), _port, - qPrintable(_passwd), _quality); + qPrintable(_passwd), _quality); // setup network for (int retry = 0; retry < 5 && _run; ++retry) { @@ -156,8 +155,7 @@ void VncThread::run() rfbClientSetClientData(_client, 0, this); // start client - if (rfbInitClient(_client, NULL, NULL)) - { + if (rfbInitClient(_client, NULL, NULL)) { break; // Success! } // Connection failed @@ -167,8 +165,7 @@ void VncThread::run() // error, let's try again this->msleep(10 + qrand() % 50); } - if(_client != NULL) - { + if (_client != NULL) { qDebug("[%s] Connection successful!", metaObject()->className()); int one = 1; setsockopt(_client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)); @@ -180,16 +177,14 @@ void VncThread::run() _connected = true; emit projectionStarted(); } - while (_run) - { + while (_run) { const int i = WaitForMessage(_client, 100 * 1000); // wait 100ms for message. returns -1 on error/disconnect, 0 if nothing happened, 1 if new data arrived if (i < 0) break; if (i > 0 && !HandleRFBServerMessage(_client)) break; - if (_hasNewLocalSize) - { + if (_hasNewLocalSize) { QMutexLocker lock(&_mutex); _hasNewLocalSize = false; _localSize = _newLocalSize; @@ -235,8 +230,7 @@ const QString VncThread::getDesktopName() const */ void VncThread::processImageUpdate(const int x, const int y, const int w, const int h) { - if (_srcStepX > 1 || _srcStepY > 1) - { + if (_srcStepX > 1 || _srcStepY > 1) { // Scaling is required as vnc server and client are using different resolutions // Calc section offsets first const int startX = x / _srcStepX; @@ -256,17 +250,14 @@ void VncThread::processImageUpdate(const int x, const int y, const int w, const // Rescale { QMutexLocker lock(&_mutex); - if (_painter != NULL) - { + if (_painter != NULL) { QImage scaled( - _img.copy(srcX, srcY, srcW, srcH).scaled(dstW, dstH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + _img.copy(srcX, srcY, srcW, srcH).scaled(dstW, dstH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); _painter->drawImage(dstX, dstY, scaled, 0, 0, dstW, dstH); } } emit imageUpdated(dstX, dstY, dstW, dstH); - } - else - { + } else { // Same resolution, nothing to do emit imageUpdated(x, y, w, h); } @@ -318,8 +309,7 @@ rfbBool VncThread::frameBufferHandler(rfbClient *client) client->format.blueMax = 0xff; const int quality = t->_quality; - switch (quality) - { + switch (quality) { case VncThread::HIGH: client->appData.useBGR233 = 0; client->appData.encodingsString = "copyrect zlib hextile raw"; diff --git a/src/client/vnc/vncthread.h b/src/client/vnc/vncthread.h index a5b52b1..a75ca0f 100644 --- a/src/client/vnc/vncthread.h +++ b/src/client/vnc/vncthread.h @@ -34,7 +34,7 @@ extern "C" */ class VncThread : public QThread { -Q_OBJECT + Q_OBJECT private: rfbClient *_client; diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp index f18fadc..818b22f 100644 --- a/src/client/vnc/vncwindow.cpp +++ b/src/client/vnc/vncwindow.cpp @@ -41,19 +41,17 @@ VncWindow::~VncWindow() */ void VncWindow::terminateVncThread() { - if(_vncWorker == NULL) + if (_vncWorker == NULL) return; _vncWorker->blockSignals(true); _vncWorker->stop(); _vncWorker = NULL; - if(_redrawTimer != 0) - { + if (_redrawTimer != 0) { killTimer(_redrawTimer); _redrawTimer = 0; } - if(_tcpTimeoutTimer != 0) - { + if (_tcpTimeoutTimer != 0) { killTimer(_tcpTimeoutTimer); _tcpTimeoutTimer = 0; } @@ -101,8 +99,8 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool connect(_vncWorker, SIGNAL(projectionStopped()), this, SLOT(onProjectionStopped()), Qt::QueuedConnection); connect(_vncWorker, SIGNAL(projectionStarted()), this, SLOT(onProjectionStarted()), Qt::QueuedConnection); connect(_vncWorker, SIGNAL(imageUpdated(const int, const int, const int, const int)), this, - SLOT(onUpdateImage(const int, const int, const int, const int)), - Qt::QueuedConnection); + SLOT(onUpdateImage(const int, const int, const int, const int)), + Qt::QueuedConnection); setWindowTitle(caption); @@ -110,15 +108,12 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool _remoteThumb.loadFromData(rawThumb); - if (fullscreen) - { + if (fullscreen) { setWindowFlags(Qt::WindowStaysOnTopHint); showFullScreen(); activateWindow(); raise(); - } - else - { + } else { resize(800, 600); showNormal(); } @@ -207,23 +202,18 @@ void VncWindow::onProjectionStopped() */ void VncWindow::timerEvent(QTimerEvent *event) { - if (event->timerId() == _redrawTimer) - { + if (event->timerId() == _redrawTimer) { killTimer(_redrawTimer); _redrawTimer = 0; if (this->isVisible()) this->repaint(); - } - else if (event->timerId() == _tcpTimeoutTimer) - { + } else if (event->timerId() == _tcpTimeoutTimer) { killTimer(_tcpTimeoutTimer); _tcpTimeoutTimer = 0; - if (_vncWorker != NULL && !_vncWorker->isConnected()) - { + if (_vncWorker != NULL && !_vncWorker->isConnected()) { this->close(); } - } - else + } else killTimer(event->timerId()); } @@ -237,24 +227,18 @@ void VncWindow::timerEvent(QTimerEvent *event) */ void VncWindow::paintEvent(QPaintEvent *event) { - if (_vncWorker == NULL || !_vncWorker->isConnected()) - { + if (_vncWorker == NULL || !_vncWorker->isConnected()) { QPainter painter(this); - if (!_remoteThumb.isNull() && _remoteThumb.height() > 0) - { + if (!_remoteThumb.isNull() && _remoteThumb.height() > 0) { painter.drawPixmap(0, 0, this->width(), this->height(), _remoteThumb); - } - else - { + } else { painter.fillRect(event->rect(), QColor(60, 63, 66)); } QFontInfo fi = painter.fontInfo(); painter.setPen(QColor(200, 100, 10)); painter.setFont(QFont(fi.family(), 28, fi.weight(), fi.italic())); painter.drawText(this->contentsRect(), Qt::AlignCenter, tr("Connecting...")); - } - else - { + } else { const QRect &r = event->rect(); this->draw(r.left(), r.top(), r.width(), r.height()); } @@ -268,8 +252,7 @@ void VncWindow::paintEvent(QPaintEvent *event) */ void VncWindow::resizeEvent(QResizeEvent* event) { - if (_vncWorker != NULL) - { + if (_vncWorker != NULL) { _vncWorker->setTargetSize(event->size()); } this->repaint(); diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h index 797ca90..2b91c0e 100644 --- a/src/client/vnc/vncwindow.h +++ b/src/client/vnc/vncwindow.h @@ -21,7 +21,7 @@ class QPainter; class VncWindow : public QWidget { -Q_OBJECT + Q_OBJECT public: VncWindow(QWidget *parent = 0); |