summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-05-26 18:34:36 +0200
committerBjörn Hagemeister2014-05-26 18:34:36 +0200
commit494727e1e5f0e459153e8845168545ad4a72e598 (patch)
tree1d0328d6b7ea8d53aec693fa06681379cb20b998 /src/client
parentMerge branch 'master' of git.openslx.org:pvs2 (diff)
downloadpvs2-494727e1e5f0e459153e8845168545ad4a72e598.tar.gz
pvs2-494727e1e5f0e459153e8845168545ad4a72e598.tar.xz
pvs2-494727e1e5f0e459153e8845168545ad4a72e598.zip
Several changes:
Fixed segmentaion fault, which occured after streaming to all clients. Added sessionName as command line argument to client, so that it connects immediatly after running to given sessionName. If pvsclient shows connected status also display IP-Adress of the running pvsmanager.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/connectwindow/connectwindow.cpp32
-rw-r--r--src/client/connectwindow/connectwindow.h3
-rw-r--r--src/client/main.cpp65
-rw-r--r--src/client/net/serverconnection.h4
-rw-r--r--src/client/toolbar/toolbar.cpp6
-rw-r--r--src/client/toolbar/toolbar.h2
6 files changed, 71 insertions, 41 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp
index 4e92570..c8f7efd 100644
--- a/src/client/connectwindow/connectwindow.cpp
+++ b/src/client/connectwindow/connectwindow.cpp
@@ -97,7 +97,7 @@ void ConnectWindow::updateState()
{
_ui->btn_connection->setEnabled(true);
_ui->btn_connection->setText(tr("&Disconnect"));
- _ui->lblStatus->setText(tr("Connected."));
+ _ui->lblStatus->setText(tr("Connected to %1").arg(_connection->getPeerAdress()));
_ui->lineEditName->setEnabled(false);
_ui->stackedWidget->setCurrentIndex(1);
return;
@@ -175,7 +175,7 @@ void ConnectWindow::timerEvent(QTimerEvent* event)
_salt2[i] = qrand() & 0xff;
}
_packet.reset();
- _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist));
+ _packet.setField(_HASH, genSha1(&_sessionNameBytes, &salt1, &iplist));
_packet.setField(_SALT1, salt1);
_packet.setField(_SALT2, _salt2);
_packet.setField(_IPLIST, iplist);
@@ -227,6 +227,24 @@ void ConnectWindow::showEvent(QShowEvent* event)
_ui->lineEditName->setFocus();
}
+/**
+ * Public function connect to session.
+ * Check if currently connected to server,
+ * if not --> connect to given sessionName.
+ * @param sessionName
+ */
+void ConnectWindow::connectToSession(const QByteArray sessionName)
+{
+ if (_connected || _state != Idle)
+ return;
+
+ _discoveryInterval = 800;
+ _sessionNameBytes = sessionName;
+ _timerDiscover = startTimer(_discoveryInterval);
+ _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0;
+ this->setState(Scanning);
+}
+
/*
* Slots
*/
@@ -255,11 +273,7 @@ void ConnectWindow::onBtnConnection()
else
{
// Connect (scan for session)
- _discoveryInterval = 800;
- _nameBytes = _ui->lineEditName->text().toUtf8();
- _timerDiscover = startTimer(_discoveryInterval);
- _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0;
- this->setState(Scanning);
+ connectToSession(_ui->lineEditName->text().toUtf8());
}
}
@@ -303,7 +317,7 @@ void ConnectWindow::onUdpReadyRead()
continue;
}
// If so, check if the submitted hash seems valid
- if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash)
+ if (genSha1(&_sessionNameBytes, &_salt2, &iplist, &port, &cert) != hash)
{
// did not match local session name, or other data was spoofed
++_hashErrorCount;
@@ -312,7 +326,7 @@ void ConnectWindow::onUdpReadyRead()
continue;
}
// Otherwise it's a valid reply, try to connect
- _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert);
+ _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _sessionNameBytes, cert);
connect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState)));
connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*)));
}
diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h
index 299a339..9319e45 100644
--- a/src/client/connectwindow/connectwindow.h
+++ b/src/client/connectwindow/connectwindow.h
@@ -63,7 +63,7 @@ private:
int _hashErrorCount, _hashSslErrorCount, _certErrorCount, _ipErrorCount;
int _discoveryInterval;
- QByteArray _nameBytes;
+ QByteArray _sessionNameBytes;
QByteArray _salt2;
QUdpSocket _discoverySocket;
NetworkMessage _packet;
@@ -76,6 +76,7 @@ public:
virtual ~ConnectWindow();
void setConnected(const bool connected);
+ void connectToSession(const QByteArray sessionName);
protected:
/*
diff --git a/src/client/main.cpp b/src/client/main.cpp
index cea9ae8..ebc6375 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -3,39 +3,46 @@
int main(int argc, char** argv)
{
- QApplication app(argc, argv);
- app.setOrganizationName("openslx");
- app.setOrganizationDomain("openslx.org");
- app.setApplicationName("pvsclient");
+ QByteArray sessionName;
+ if (argc != 2)
+ {
+ sessionName = "";
+ }
+ else
+ sessionName = argv[1];
+ QApplication app(argc, argv);
+ app.setOrganizationName("openslx");
+ app.setOrganizationDomain("openslx.org");
+ app.setApplicationName("pvsclient");
- qsrand((uint)QDateTime::currentMSecsSinceEpoch());
+ qsrand((uint)QDateTime::currentMSecsSinceEpoch());
- // Make sure settings directory exists
- do {
- USER_SETTINGS(settings);
- QFileInfo fi(settings.fileName());
- QDir path(fi.path());
- qDebug() << "Settings directory is " << fi.path();
- if (!path.exists())
- path.mkpath(path.absolutePath());
- // Now check if settings file exists. If not, copy system default (if available)
- if (!fi.exists())
+ // Make sure settings directory exists
+ do {
+ USER_SETTINGS(settings);
+ QFileInfo fi(settings.fileName());
+ QDir path(fi.path());
+ qDebug() << "Settings directory is " << fi.path();
+ if (!path.exists())
+ path.mkpath(path.absolutePath());
+ // Now check if settings file exists. If not, copy system default (if available)
+ if (!fi.exists())
+ {
+ SYSTEM_SETTINGS(sys);
+ QFileInfo sysfi(sys.fileName());
+ if (sysfi.exists())
{
- SYSTEM_SETTINGS(sys);
- QFileInfo sysfi(sys.fileName());
- if (sysfi.exists())
- {
- if (!QFile::copy(sys.fileName(), settings.fileName()))
- qDebug() << "Copying default settings from " << sys.fileName() << " to " << settings.fileName() << " failed.";
- }
+ if (!QFile::copy(sys.fileName(), settings.fileName()))
+ qDebug() << "Copying default settings from " << sys.fileName() << " to " << settings.fileName() << " failed.";
}
- } while (0);
+ }
+ } while (0);
- // use system locale as language to translate gui
- QTranslator translator;
- translator.load(":pvsclient");
- app.installTranslator(&translator);
+ // use system locale as language to translate gui
+ QTranslator translator;
+ translator.load(":pvsclient");
+ app.installTranslator(&translator);
- Toolbar pvsclient;
- return app.exec();
+ Toolbar pvsclient(sessionName);
+ return app.exec();
}
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index 6af2b15..a45d434 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -37,6 +37,10 @@ public:
return _socket != NULL && _socket->state() == QAbstractSocket::ConnectedState;
}
+ const inline QString getPeerAdress() const
+ {
+ return _socket->peerAddress().toString();
+ }
void sendMessage(NetworkMessage& message);
protected:
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp
index bfe4e24..88d4b2a 100644
--- a/src/client/toolbar/toolbar.cpp
+++ b/src/client/toolbar/toolbar.cpp
@@ -22,7 +22,7 @@
* another widget, this widget becomes a child window inside parent. The new
* widget is deleted when its parent is deleted.
*/
-Toolbar::Toolbar(QWidget *parent) :
+Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) :
QWidget(parent), _ui(new Ui::Toolbar), _hideTimer(this), _connection(NULL),
_blinkTimer(this),_cam32(":cam32.svg"), _beWatchedEye(":eye")
{
@@ -40,6 +40,10 @@ Toolbar::Toolbar(QWidget *parent) :
/* Create the connect window */
_connectWindow = new ConnectWindow(NULL);
+ if (!sessionName.isEmpty())
+ {
+ _connectWindow->connectToSession(sessionName);
+ }
// Connect the signals
connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect()));
connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*)));
diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h
index f01e4ef..c85c501 100644
--- a/src/client/toolbar/toolbar.h
+++ b/src/client/toolbar/toolbar.h
@@ -30,7 +30,7 @@ class Toolbar : public QWidget
Q_OBJECT
public:
- explicit Toolbar(QWidget *parent = 0);
+ explicit Toolbar(const QByteArray sessionName, QWidget *parent = 0);
virtual ~Toolbar();
private: