mirror of
				https://github.com/gtalent/sc9k.git
				synced 2025-11-03 19:29:08 -06:00 
			
		
		
		
	Cleanup connection status check and reset SlideView on disconnect
This commit is contained in:
		@@ -5,6 +5,7 @@
 | 
				
			|||||||
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
					 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
				
			||||||
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QFormLayout>
 | 
					#include <QFormLayout>
 | 
				
			||||||
#include <QHBoxLayout>
 | 
					#include <QHBoxLayout>
 | 
				
			||||||
#include <QLabel>
 | 
					#include <QLabel>
 | 
				
			||||||
@@ -58,6 +59,7 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {
 | 
				
			|||||||
	connect(&m_openlpClient, &OpenLPClient::pollUpdate, slideView, &SlideView::pollUpdate);
 | 
						connect(&m_openlpClient, &OpenLPClient::pollUpdate, slideView, &SlideView::pollUpdate);
 | 
				
			||||||
	connect(&m_openlpClient, &OpenLPClient::songListUpdate, slideView, &SlideView::songListUpdate);
 | 
						connect(&m_openlpClient, &OpenLPClient::songListUpdate, slideView, &SlideView::songListUpdate);
 | 
				
			||||||
	connect(&m_openlpClient, &OpenLPClient::slideListUpdate, slideView, &SlideView::slideListUpdate);
 | 
						connect(&m_openlpClient, &OpenLPClient::slideListUpdate, slideView, &SlideView::slideListUpdate);
 | 
				
			||||||
 | 
						connect(&m_openlpClient, &OpenLPClient::pollFailed, slideView, &SlideView::reset);
 | 
				
			||||||
	connect(slideView, &SlideView::songChanged, &m_openlpClient, &OpenLPClient::changeSong);
 | 
						connect(slideView, &SlideView::songChanged, &m_openlpClient, &OpenLPClient::changeSong);
 | 
				
			||||||
	connect(slideView, &SlideView::slideChanged, &m_openlpClient, &OpenLPClient::changeSlide);
 | 
						connect(slideView, &SlideView::slideChanged, &m_openlpClient, &OpenLPClient::changeSlide);
 | 
				
			||||||
	// setup scene selector
 | 
						// setup scene selector
 | 
				
			||||||
@@ -72,14 +74,9 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {
 | 
				
			|||||||
	connect(btnObsShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::showSlides);
 | 
						connect(btnObsShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::showSlides);
 | 
				
			||||||
	connect(btnObsShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
 | 
						connect(btnObsShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
 | 
				
			||||||
	// setup status bar
 | 
						// setup status bar
 | 
				
			||||||
	auto statusBar = new QStatusBar(this);
 | 
						setStatusBar(new QStatusBar(this));
 | 
				
			||||||
	setStatusBar(statusBar);
 | 
					 | 
				
			||||||
	connect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
						connect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
				
			||||||
	connect(&m_openlpClient, &OpenLPClient::pollUpdate, [this] { ++m_openLPUpdates; });
 | 
					 | 
				
			||||||
	connect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
						connect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
				
			||||||
	connect(&m_obsClient, &OBSClient::pollUpdate, [this] { ++m_obsUpdates; });
 | 
					 | 
				
			||||||
	m_statusBarTimer.start(5000);
 | 
					 | 
				
			||||||
	connect(&m_statusBarTimer, &QTimer::timeout, this, &MainWindow::refreshStatusBar);
 | 
					 | 
				
			||||||
	refreshStatusBar();
 | 
						refreshStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -88,38 +85,34 @@ MainWindow::~MainWindow() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void MainWindow::openLpConnectionInit() {
 | 
					void MainWindow::openLpConnectionInit() {
 | 
				
			||||||
	disconnect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
						disconnect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
				
			||||||
	++m_openLPUpdates;
 | 
						connect(&m_openlpClient, &OpenLPClient::pollFailed, this, &MainWindow::openLpConnectionLost);
 | 
				
			||||||
 | 
						m_openLpConnected = true;
 | 
				
			||||||
	refreshStatusBar();
 | 
						refreshStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::openLpConnectionLost() {
 | 
					void MainWindow::openLpConnectionLost() {
 | 
				
			||||||
 | 
						disconnect(&m_openlpClient, &OpenLPClient::pollFailed, this, &MainWindow::openLpConnectionLost);
 | 
				
			||||||
	connect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
						connect(&m_openlpClient, &OpenLPClient::pollUpdate, this, &MainWindow::openLpConnectionInit);
 | 
				
			||||||
 | 
						m_openLpConnected = false;
 | 
				
			||||||
 | 
						refreshStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::obsConnectionInit() {
 | 
					void MainWindow::obsConnectionInit() {
 | 
				
			||||||
	disconnect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
						disconnect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
				
			||||||
	++m_obsUpdates;
 | 
						connect(&m_obsClient, &OBSClient::pollFailed, this, &MainWindow::obsConnectionLost);
 | 
				
			||||||
 | 
						m_obsConnected = true;
 | 
				
			||||||
	refreshStatusBar();
 | 
						refreshStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::obsConnectionLost() {
 | 
					void MainWindow::obsConnectionLost() {
 | 
				
			||||||
 | 
						disconnect(&m_obsClient, &OBSClient::pollFailed, this, &MainWindow::obsConnectionLost);
 | 
				
			||||||
	connect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
						connect(&m_obsClient, &OBSClient::pollUpdate, this, &MainWindow::obsConnectionInit);
 | 
				
			||||||
 | 
						m_obsConnected = false;
 | 
				
			||||||
 | 
						refreshStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::refreshStatusBar() {
 | 
					void MainWindow::refreshStatusBar() {
 | 
				
			||||||
	QString openLpStatus;
 | 
						const auto openLpStatus = m_openLpConnected ? tr("OpenLP: Connected") : tr("OpenLP: Not Connected");
 | 
				
			||||||
	QString obsStatus;
 | 
						const auto obsStatus = m_obsConnected ? tr("OBS: Connected") : tr("OBS: Not Connected");
 | 
				
			||||||
	if (m_openLPUpdates > 0) {
 | 
					 | 
				
			||||||
		openLpStatus = tr("OpenLP: Connected");
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		openLpStatus = tr("OpenLP: Not Connected");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (m_obsUpdates > 0) {
 | 
					 | 
				
			||||||
		obsStatus = tr("OBS: Connected");
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		obsStatus = tr("OBS: Not Connected");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	m_openLPUpdates = 0;
 | 
					 | 
				
			||||||
	m_obsUpdates = 0;
 | 
					 | 
				
			||||||
	statusBar()->showMessage(openLpStatus + " | " + obsStatus);
 | 
						statusBar()->showMessage(openLpStatus + " | " + obsStatus);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,6 @@
 | 
				
			|||||||
#include <cstdint>
 | 
					#include <cstdint>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QMainWindow>
 | 
					#include <QMainWindow>
 | 
				
			||||||
#include <QTimer>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "obsclient.hpp"
 | 
					#include "obsclient.hpp"
 | 
				
			||||||
#include "openlpclient.hpp"
 | 
					#include "openlpclient.hpp"
 | 
				
			||||||
@@ -21,9 +20,8 @@ class MainWindow: public QMainWindow {
 | 
				
			|||||||
   private:
 | 
					   private:
 | 
				
			||||||
	   OBSClient m_obsClient;
 | 
						   OBSClient m_obsClient;
 | 
				
			||||||
		OpenLPClient m_openlpClient;
 | 
							OpenLPClient m_openlpClient;
 | 
				
			||||||
		QTimer m_statusBarTimer;
 | 
							bool m_openLpConnected = false;
 | 
				
			||||||
		uint64_t m_openLPUpdates = 0;
 | 
							bool m_obsConnected = false;
 | 
				
			||||||
		uint64_t m_obsUpdates = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
   public:
 | 
					   public:
 | 
				
			||||||
		MainWindow(QWidget *parent = nullptr);
 | 
							MainWindow(QWidget *parent = nullptr);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
					 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
				
			||||||
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QJsonArray>
 | 
					#include <QJsonArray>
 | 
				
			||||||
#include <QJsonDocument>
 | 
					#include <QJsonDocument>
 | 
				
			||||||
#include <QJsonObject>
 | 
					#include <QJsonObject>
 | 
				
			||||||
@@ -15,7 +16,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
OpenLPClient::OpenLPClient(QObject *parent): QObject(parent) {
 | 
					OpenLPClient::OpenLPClient(QObject *parent): QObject(parent) {
 | 
				
			||||||
	poll();
 | 
						poll();
 | 
				
			||||||
	m_pollTimer.start(500);
 | 
						m_pollTimer.start(250);
 | 
				
			||||||
	connect(&m_pollTimer, &QTimer::timeout, this, &OpenLPClient::poll);
 | 
						connect(&m_pollTimer, &QTimer::timeout, this, &OpenLPClient::poll);
 | 
				
			||||||
	connect(m_nam, &QNetworkAccessManager::finished, this, &OpenLPClient::handleGeneralResponse);
 | 
						connect(m_nam, &QNetworkAccessManager::finished, this, &OpenLPClient::handleGeneralResponse);
 | 
				
			||||||
	connect(m_songListNam, &QNetworkAccessManager::finished, this, &OpenLPClient::handleSongListResponse);
 | 
						connect(m_songListNam, &QNetworkAccessManager::finished, this, &OpenLPClient::handleSongListResponse);
 | 
				
			||||||
@@ -93,6 +94,9 @@ void OpenLPClient::handlePollResponse(QNetworkReply *reply) {
 | 
				
			|||||||
	if (reply->error()) {
 | 
						if (reply->error()) {
 | 
				
			||||||
		qDebug() << reply->errorString();
 | 
							qDebug() << reply->errorString();
 | 
				
			||||||
		emit pollFailed();
 | 
							emit pollFailed();
 | 
				
			||||||
 | 
							m_currentServiceId = -1;
 | 
				
			||||||
 | 
							m_currentSongId = "";
 | 
				
			||||||
 | 
							m_songNameMap.clear();
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	auto data = reply->readAll();
 | 
						auto data = reply->readAll();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
					 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
				
			||||||
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QComboBox>
 | 
					#include <QComboBox>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QHeaderView>
 | 
					#include <QHeaderView>
 | 
				
			||||||
@@ -23,8 +24,6 @@ SlideView::SlideView(QWidget *parent): QWidget(parent) {
 | 
				
			|||||||
	m_slideTable->setSelectionBehavior(QTableWidget::SelectionBehavior::SelectRows);
 | 
						m_slideTable->setSelectionBehavior(QTableWidget::SelectionBehavior::SelectRows);
 | 
				
			||||||
	m_slideTable->setSelectionMode(QTableWidget::SelectionMode::SingleSelection);
 | 
						m_slideTable->setSelectionMode(QTableWidget::SelectionMode::SingleSelection);
 | 
				
			||||||
	m_slideTable->setColumnCount(1);
 | 
						m_slideTable->setColumnCount(1);
 | 
				
			||||||
	connect(header, &QHeaderView::sectionResized, m_slideTable, &QTableWidget::resizeRowsToContents);
 | 
					 | 
				
			||||||
	m_slideTable->resizeRowsToContents();
 | 
					 | 
				
			||||||
	m_slideTable->verticalHeader()->setDefaultSectionSize(300);
 | 
						m_slideTable->verticalHeader()->setDefaultSectionSize(300);
 | 
				
			||||||
#ifndef _WIN32
 | 
					#ifndef _WIN32
 | 
				
			||||||
	m_slideTable->setAlternatingRowColors(true);
 | 
						m_slideTable->setAlternatingRowColors(true);
 | 
				
			||||||
@@ -61,6 +60,14 @@ void SlideView::slideListUpdate(QStringList tagList, QStringList slideList) {
 | 
				
			|||||||
		m_slideTable->setItem(i, 0, item);
 | 
							m_slideTable->setItem(i, 0, item);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m_slideTable->setVerticalHeaderLabels(tagList);
 | 
						m_slideTable->setVerticalHeaderLabels(tagList);
 | 
				
			||||||
 | 
						m_slideTable->resizeRowsToContents();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SlideView::reset() {
 | 
				
			||||||
 | 
						m_songSelector->clear();
 | 
				
			||||||
 | 
						m_slideTable->setRowCount(0);
 | 
				
			||||||
 | 
						m_currentSong = "";
 | 
				
			||||||
 | 
						m_currentSlide = -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SlideView::songListUpdate(QStringList songList) {
 | 
					void SlideView::songListUpdate(QStringList songList) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,8 @@ class SlideView : public QWidget
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		void slideListUpdate(QStringList tagList, QStringList songList);
 | 
							void slideListUpdate(QStringList tagList, QStringList songList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							void reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   private slots:
 | 
					   private slots:
 | 
				
			||||||
		void changeSong(int song);
 | 
							void changeSong(int song);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user