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/toolbar/toolbar.cpp | 51 +++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'src/client/toolbar/toolbar.cpp') diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 3d370dd..d6bcf22 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -34,7 +34,7 @@ Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) qDebug() << "sessionName - constructor"; init(); - _connectWindow->connectToSession(sessionName, ""); + clientApp->connectWindow()->connectToSession(sessionName, ""); } /***************************************************************************//** @@ -58,7 +58,7 @@ Toolbar::Toolbar(const bool autoConnect, QWidget *parent) // Try getting manager ip. QString mgrIp = identifyMgrIP(); if (!mgrIp.isEmpty()) - _connectWindow->connectToSession("", mgrIp); + clientApp->connectWindow()->connectToSession("", mgrIp); } } @@ -87,7 +87,6 @@ void Toolbar::exit() void Toolbar::init() { _ui = new Ui::Toolbar; - _connection = NULL; /* Initialize the GUI */ _ui->setupUi(this); @@ -100,11 +99,10 @@ void Toolbar::init() _vnc = new VncWindow(NULL); /* Create the connect window */ - _connectWindow = new ConnectWindow(NULL); - _connectWindow->setAvailableRooms(myRooms()); + clientApp->connectWindow()->setAvailableRooms(myRooms()); // Connect the signals - connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); - connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); + connect(clientApp->connectWindow(), SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); + connect(clientApp->connectWindow(), SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); /* Setup menu */ initMenu(); @@ -183,8 +181,8 @@ void Toolbar::initMenu() // 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(_acnConnect, SIGNAL(triggered()), clientApp->connectWindow(), SLOT(doShow())); + connect(_acnDisconnect, SIGNAL(triggered()), clientApp->connectWindow(), SLOT(DoDisconnect())); connect(_acnInformation, SIGNAL(triggered()), this, SLOT(showInformationDialog())); connect(_acnAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(_acnQuit, SIGNAL(triggered()), this, SLOT(exit())); @@ -198,7 +196,6 @@ Toolbar::~Toolbar() { VncServer::instance()->stop(); _vnc->deleteLater(); - _connectWindow->deleteLater(); delete _ui; } @@ -348,11 +345,11 @@ 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(ServerConnection* connection) { - if (_connection != NULL) - _connection->blockSignals(true); - _connection = NULL; + if (connection != NULL) { + disconnect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); + } _ui->lblStatus->setStyleSheet("color:red"); _ui->lblStatus->setText(tr("Offline")); @@ -380,18 +377,12 @@ void Toolbar::onConnected(ServerConnection* connection) /* connected, show button */ _ui->btnAttention->setVisible(true); // - if (_connection != NULL) { - disconnect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); - _connection->blockSignals(true); - _connection->disconnectFromServer(); - } - _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&)), + connect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); + 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&))); - connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close())); - connect(_connection, SIGNAL(attentionChanged(const bool)), this, SLOT(onServerAttentionChanged(const bool))); - connect(_vnc, SIGNAL(running(const bool, const int)), _connection, SLOT(onVncViewerStartStop(const bool, const int))); + connect(connection, SIGNAL(closeVnc()), _vnc, SLOT(close())); + connect(connection, SIGNAL(attentionChanged(const bool)), this, SLOT(onServerAttentionChanged(const bool))); + connect(_vnc, SIGNAL(running(const bool, const int)), connection, SLOT(onVncViewerStartStop(const bool, const int))); } /***************************************************************************//** @@ -399,8 +390,8 @@ void Toolbar::onConnected(ServerConnection* connection) */ void Toolbar::onDoDisconnect() { - if (_connection != NULL) - _connection->disconnectFromServer(); + if (clientApp->connection() != NULL) + clientApp->connection()->disconnectFromServer(); } void Toolbar::onServerAttentionChanged(const bool on) @@ -463,13 +454,13 @@ void Toolbar::showBar() void Toolbar::onBtnAttention() { - const bool on = _connection != NULL && _ui->btnAttention->isChecked(); + const bool on = clientApp->connection() != NULL && _ui->btnAttention->isChecked(); if (on != _ui->btnAttention->isChecked()) { _ui->btnAttention->setChecked(on); return; } - if (_connection != NULL) { - _connection->sendAttention(on); + if (clientApp->connection() != NULL) { + clientApp->connection()->sendAttention(on); } } -- cgit v1.2.3-55-g7522