From e19dcdfed2da5405c714bc0af56927fa8e4c2442 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 26 Oct 2016 18:31:21 +0200 Subject: [client] Move ServerConnection instance to ClientApp --- src/client/clientapp/clientapp.cpp | 19 +++++++++++++++++++ src/client/clientapp/clientapp.h | 20 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'src/client/clientapp') diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp index 3b90dee..5528c65 100644 --- a/src/client/clientapp/clientapp.cpp +++ b/src/client/clientapp/clientapp.cpp @@ -1,5 +1,8 @@ #include "clientapp.h" #include +#include "../connectwindow/connectwindow.h" +#include "../toolbar/toolbar.h" +#include "../net/serverconnection.h" ClientApp::ClientApp(int& argc, char** argv) : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false), _isManagerPc(false) @@ -26,6 +29,8 @@ ClientApp::ClientApp(int& argc, char** argv) translator->load(":pvsclient"); installTranslator(translator); + _connectWindow = new ConnectWindow(NULL); + connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(connected(ServerConnection*))); /* TODO: Move the connection handling to ClientApp */ if (_connectionMode == ConnectionMode::Auto) { _toolbar = new Toolbar(true); // auto connect client without session ID. @@ -103,3 +108,17 @@ void ClientApp::readIsManagerPc() } } +void ClientApp::connected(ServerConnection* connection) +{ + _connection = connection; +} + +void ClientApp::disconnected(ServerConnection* connection) +{ + if (connection != NULL) + connection->blockSignals(true); + if (_connection == connection) { + _connection = NULL; + } +} + diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h index 31b2399..8a7fd83 100644 --- a/src/client/clientapp/clientapp.h +++ b/src/client/clientapp/clientapp.h @@ -1,7 +1,7 @@ #include -#include "../toolbar/toolbar.h" #include "../util/util.h" - +#include +#include /* define a macro `clientApp` that can be used anywhere in the program and returns a reference to the current ClientApp instance */ #if defined(clientApp) @@ -9,6 +9,10 @@ #endif #define clientApp (static_cast(QCoreApplication::instance())) +class Toolbar; +class ConnectWindow; +class ServerConnection; + /* this class is supposed to (after complete refactoring) to encapsulate all * state of the application. At the moment, the state is distributed within * several widgets. With this class information access will also be easier as @@ -27,6 +31,8 @@ private: bool _examMode; QString _sessionName; /* only set when _connectionMode == Session */ Toolbar* _toolbar; + ConnectWindow* _connectWindow; + ServerConnection* _connection; QStringList _arguments; QString _iniPath; bool _isManagerPc; @@ -45,5 +51,15 @@ public: QSharedPointer getSettings(); + ServerConnection* connection() const { return _connection; } + + ConnectWindow* connectWindow() const { return _connectWindow; } + const bool isManagerPc() const { return _isManagerPc; } + +private slots: + + void connected(ServerConnection* connection); + void disconnected(ServerConnection* connection); + }; -- cgit v1.2.3-55-g7522