Fix next song in status bar

This commit is contained in:
Gary Talent 2021-10-24 11:35:13 -05:00
parent f9122c2942
commit 8d0b0fb4c5
3 changed files with 18 additions and 5 deletions

View File

@ -108,7 +108,7 @@ void MainWindow::obsConnectionLost() {
void MainWindow::refreshStatusBar() { void MainWindow::refreshStatusBar() {
const auto openLpStatus = m_openLpConnected ? tr("OpenLP: Connected") : tr("OpenLP: Not Connected"); 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 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 : ""; const auto nextSongTxt = m_openLpConnected ? " | Next Song: " + nextSong : "";
statusBar()->showMessage(openLpStatus + " | " + obsStatus + nextSongTxt); statusBar()->showMessage(openLpStatus + " | " + obsStatus + nextSongTxt);
} }

View File

@ -24,6 +24,15 @@ OpenLPClient::OpenLPClient(QObject *parent): QObject(parent) {
connect(m_pollingNam, &QNetworkAccessManager::finished, this, &OpenLPClient::handlePollResponse); 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() { void OpenLPClient::nextSlide() {
get("/api/controller/live/next"); get("/api/controller/live/next");
} }
@ -131,18 +140,18 @@ void OpenLPClient::handleSongListResponse(QNetworkReply *reply) {
if (data.isEmpty()) { if (data.isEmpty()) {
return; return;
} }
QStringList songList;
auto doc = QJsonDocument::fromJson(data); auto doc = QJsonDocument::fromJson(data);
auto items = doc.object()["results"].toObject()["items"].toArray(); auto items = doc.object()["results"].toObject()["items"].toArray();
m_songNameMap.clear(); m_songNameMap.clear();
m_songList.clear();
for (const auto &item : items) { for (const auto &item : items) {
auto song = item.toObject(); auto song = item.toObject();
auto name = song["title"].toString(); auto name = song["title"].toString();
auto id = song["id"].toString(); auto id = song["id"].toString();
m_songNameMap[id] = name; 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) { void OpenLPClient::handleSlideListResponse(QNetworkReply *reply) {

View File

@ -30,12 +30,16 @@ class OpenLPClient: public QObject {
QNetworkAccessManager *m_slideListNam = new QNetworkAccessManager(this); QNetworkAccessManager *m_slideListNam = new QNetworkAccessManager(this);
QTimer m_pollTimer; QTimer m_pollTimer;
QHash<QString, QString> m_songNameMap; QHash<QString, QString> m_songNameMap;
QStringList m_songList;
int m_currentServiceId = -1; int m_currentServiceId = -1;
QString m_currentSongId; QString m_currentSongId;
public: public:
explicit OpenLPClient(QObject *parent = nullptr); explicit OpenLPClient(QObject *parent = nullptr);
[[nodiscard]]
QString getNextSong();
public slots: public slots:
void nextSlide(); void nextSlide();