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