From 8d0b0fb4c52ea32750e180ea483ece04e5704287 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 24 Oct 2021 11:35:13 -0500 Subject: [PATCH] Fix next song in status bar --- src/mainwindow.cpp | 2 +- src/openlpclient.cpp | 15 ++++++++++++--- src/openlpclient.hpp | 6 +++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 53a806a..68112a9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -108,7 +108,7 @@ void MainWindow::obsConnectionLost() { void MainWindow::refreshStatusBar() { const auto openLpStatus = m_openLpConnected ? tr("OpenLP: Connected") : tr("OpenLP: Not Connected"); const auto obsStatus = m_obsConnected ? tr("OBS: Connected") : tr("OBS: Not Connected"); - const auto nextSong = m_slideView->getNextSong(); + const auto nextSong = m_openlpClient.getNextSong(); const auto nextSongTxt = m_openLpConnected ? " | Next Song: " + nextSong : ""; statusBar()->showMessage(openLpStatus + " | " + obsStatus + nextSongTxt); } diff --git a/src/openlpclient.cpp b/src/openlpclient.cpp index c316f2f..dbfa439 100644 --- a/src/openlpclient.cpp +++ b/src/openlpclient.cpp @@ -24,6 +24,15 @@ OpenLPClient::OpenLPClient(QObject *parent): QObject(parent) { connect(m_pollingNam, &QNetworkAccessManager::finished, this, &OpenLPClient::handlePollResponse); } +QString OpenLPClient::getNextSong() { + const auto currentSong = m_songNameMap[m_currentSongId]; + const auto songIdx = m_songList.indexOf(currentSong) + 1; + if (songIdx < m_songList.size()) { + return m_songList[songIdx]; + } + return ""; +} + void OpenLPClient::nextSlide() { get("/api/controller/live/next"); } @@ -131,18 +140,18 @@ void OpenLPClient::handleSongListResponse(QNetworkReply *reply) { if (data.isEmpty()) { return; } - QStringList songList; auto doc = QJsonDocument::fromJson(data); auto items = doc.object()["results"].toObject()["items"].toArray(); m_songNameMap.clear(); + m_songList.clear(); for (const auto &item : items) { auto song = item.toObject(); auto name = song["title"].toString(); auto id = song["id"].toString(); m_songNameMap[id] = name; - songList.push_back(name); + m_songList.push_back(name); } - emit songListUpdate(songList); + emit songListUpdate(m_songList); } void OpenLPClient::handleSlideListResponse(QNetworkReply *reply) { diff --git a/src/openlpclient.hpp b/src/openlpclient.hpp index 6452cbd..6d2ffb8 100644 --- a/src/openlpclient.hpp +++ b/src/openlpclient.hpp @@ -30,13 +30,17 @@ class OpenLPClient: public QObject { QNetworkAccessManager *m_slideListNam = new QNetworkAccessManager(this); QTimer m_pollTimer; QHash m_songNameMap; + QStringList m_songList; int m_currentServiceId = -1; QString m_currentSongId; public: explicit OpenLPClient(QObject *parent = nullptr); - public slots: + [[nodiscard]] + QString getNextSong(); + + public slots: void nextSlide(); void prevSlide();