Reformat HelpMessageSender

remotes/origin/HEAD
markuspg 6 years ago
parent f423daf50c
commit bc345ff4d3

@ -2,7 +2,9 @@
#include <iostream>
lcHelpMessageWindow::lcHelpMessageWindow( const QString &argServerIP, const unsigned short int &argServerPort, QWidget *argParent ) :
lcHelpMessageWindow::lcHelpMessageWindow(const QString &argServerIP,
const unsigned short int &argServerPort,
QWidget *argParent) :
QMainWindow{argParent},
helpMessageSocket {new QTcpSocket{this}},
serverPort{argServerPort},
@ -10,8 +12,10 @@ lcHelpMessageWindow::lcHelpMessageWindow( const QString &argServerIP, const unsi
ui{new Ui::HelpMessageWindow}
{
ui->setupUi(this);
connect( ui->PBAskForHelp, &QPushButton::clicked, this, &lcHelpMessageWindow::RequestHelp );
connect( helpMessageSocket, &QTcpSocket::readyRead, this, &lcHelpMessageWindow::ReadHelpReply );
connect(ui->PBAskForHelp, &QPushButton::clicked,
this, &lcHelpMessageWindow::RequestHelp);
connect(helpMessageSocket, &QTcpSocket::readyRead,
this, &lcHelpMessageWindow::ReadHelpReply);
connect(helpMessageSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(DisplayError(QAbstractSocket::SocketError)));
@ -20,17 +24,20 @@ lcHelpMessageWindow::lcHelpMessageWindow( const QString &argServerIP, const unsi
// Get saved network configuration
QSettings settings{QSettings::UserScope, QLatin1String{"QtProject"}};
settings.beginGroup(QLatin1String{"QtNetwork"});
const QString id = settings.value( QLatin1String{ "DefaultNetworkConfiguration" } ).toString();
const QString id
= settings.value(QLatin1String{"DefaultNetworkConfiguration"}).toString();
settings.endGroup();
// If the saved network configuration is not currently discovered use the system default
QNetworkConfiguration config = manager.configurationFromIdentifier( id );
if ( ( config.state() & QNetworkConfiguration::Discovered ) != QNetworkConfiguration::Discovered ) {
if ((config.state() & QNetworkConfiguration::Discovered)
!= QNetworkConfiguration::Discovered) {
config = manager.defaultConfiguration();
}
networkSession = new QNetworkSession{config, this};
connect( networkSession, &QNetworkSession::opened, this, &lcHelpMessageWindow::OpenedSession );
connect(networkSession, &QNetworkSession::opened,
this, &lcHelpMessageWindow::OpenedSession);
networkSession->open();
}
@ -46,10 +53,12 @@ void lcHelpMessageWindow::DisplayError( QAbstractSocket::SocketError socketError
case QAbstractSocket::RemoteHostClosedError:
return;
case QAbstractSocket::HostNotFoundError:
errorMessage = tr( "An error occurred: The server could not be found for error reporting:\n" );
errorMessage = tr("An error occurred: The server could not be found for"
" error reporting:\n");
break;
case QAbstractSocket::ConnectionRefusedError:
errorMessage = tr( "An error occurred: The connection was refused by the laboratory server:\n" );
errorMessage = tr("An error occurred: The connection was refused by the"
" laboratory server:\n");
break;
default:
errorMessage = tr("The following error occured:\n");
@ -63,10 +72,12 @@ void lcHelpMessageWindow::OpenedSession() {
// Save the used configuration
QNetworkConfiguration config = networkSession->configuration();
QString id;
if ( config.type() == QNetworkConfiguration::UserChoice )
id = networkSession->sessionProperty( QLatin1String{ "UserChoiceConfiguration" } ).toString();
else
if (config.type() == QNetworkConfiguration::UserChoice) {
id = networkSession->sessionProperty(
QLatin1String{"UserChoiceConfiguration"}).toString();
} else {
id = config.identifier();
}
QSettings settings{QSettings::UserScope, QLatin1String{"QtProject"}};
settings.beginGroup(QLatin1String{"QtNetwork"});
@ -79,8 +90,9 @@ void lcHelpMessageWindow::ReadHelpReply() {
in.setVersion(QDataStream::Qt_5_2);
if (blockSize == 0) {
if ( helpMessageSocket->bytesAvailable() < ( int )sizeof( quint16 ) )
if (helpMessageSocket->bytesAvailable() < (int)sizeof(quint16)) {
return;
}
in >> blockSize;
}
@ -93,10 +105,14 @@ void lcHelpMessageWindow::ReadHelpReply() {
in >> serverAnswer;
if (serverAnswer == "Help demand retrieved.") {
ui->LSendingSuccess->setText( tr( "Help message successfully sent.\nPlease wait for the experimenter to show up at your booth." ) );
ui->LSendingSuccess->setText(tr("Help message successfully"
" sent.\nPlease wait for the"
" experimenter to show up at your booth."));
ui->PBAskForHelp->setEnabled(false);
} else {
ui->LSendingSuccess->setText( tr( "An error occurred sending the help message. Please raise your arm.\n\n'%1'" ).arg( serverAnswer ) );
ui->LSendingSuccess->setText(tr("An error occurred sending the help"
" message. Please raise your"
" arm.\n\n'%1'").arg(serverAnswer));
}
}

@ -9,14 +9,16 @@
namespace Ui {
class HelpMessageWindow;
}
} // namespace Ui
class lcHelpMessageWindow : public QMainWindow
{
Q_OBJECT
public:
explicit lcHelpMessageWindow( const QString &argServerIP, const unsigned short int &argServerPort, QWidget *argParent = nullptr );
explicit lcHelpMessageWindow(const QString &argServerIP,
const unsigned short int &argServerPort,
QWidget *argParent = nullptr);
~lcHelpMessageWindow();
private:

@ -1,11 +1,13 @@
#include "helpmessagewindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSettings labSettings{"Economic Laboratory", "Labcontrol"};
lcHelpMessageWindow w{ labSettings.value( "server_ip", "127.0.0.1" ).toString(), labSettings.value( "client_help_server_port", "0" ).toUInt() };
lcHelpMessageWindow w{labSettings.value("server_ip", "127.0.0.1").toString(),
labSettings.value("client_help_server_port", "0").toUInt()};
w.show();
return a.exec();

Loading…
Cancel
Save