/*
# Copyright (c) 2013 - OpenSLX Project, Computer Center University of
# Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# ---------------------------------------------------------------------
# - Allow user to connect/disconnect to/from server
*/
#ifndef PVSCONNECTWINDOW_H_
#define PVSCONNECTWINDOW_H_
#include <QtWidgets>
#include <QMap>
#include <QUdpSocket>
#include <QSslSocket>
#include "../../shared/networkmessage.h"
#include "../net/serverdiscovery.h"
#include "../util/room.h"
namespace Ui
{
class ConnectWindow;
}
class ServerConnection;
/**
* Class for handling the client connection.
* Display toolbar with menu bar for connect or disconnect to pvs manager and
* show current connection status.
* For connecting with manager, user is able to set sessionName. If connection works
* correctly flashy green checkmark is shown.
*/
class ConnectWindow : public QWidget
{
Q_OBJECT
public:
enum ConnectionState {
Idle,
Scanning,
Connecting,
AwaitingChallenge,
AwaitingChallengeResponse,
LoggingIn,
InvalidSslHash, // Hash of challenge inside SSL connection invalid
InvalidCert,
Connected
};
explicit ConnectWindow(QWidget *parent = NULL);
virtual ~ConnectWindow();
void connectToSession(const QByteArray sessionName, QString mgrIP);
void setAvailableRooms(QList<Room> m);
private:
Ui::ConnectWindow *_ui;
int _hashSslErrorCount;
ServerDiscovery _serverDiscovery;
ServerConnection* _pendingConnection;
ConnectionState _state;
QByteArray _currentSession;
QString _currentIp;
QString _defaultSessionName;
NetworkMessage _packet;
bool _tryReconnect;
int _timerHide;
void updateUserInterface();
protected:
void timerEvent(QTimerEvent* event);
void closeEvent(QCloseEvent *e);
void showEvent(QShowEvent* event);
protected slots:
void doShow();
void onBtnConnection();
void onBtnCancel();
void onRoomSelection(int index);
void onConnectionStateChange(ConnectWindow::ConnectionState state);
void onConnectionClosed(QObject* connection);
void onConnectionDisconnected(ServerConnection* connection);
// void onUdpReadyRead();
void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void onComboBox_keyPressed(QKeyEvent* e);
public slots:
/** actually connects the connection **/
void DoConnect();
/** actually disconnects the connection **/
void DoDisconnect();
signals:
void disconnect();
void connected(ServerConnection* connection);
};
#endif