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() {
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);
}

View File

@ -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) {

View File

@ -30,13 +30,17 @@ class OpenLPClient: public QObject {
QNetworkAccessManager *m_slideListNam = new QNetworkAccessManager(this);
QTimer m_pollTimer;
QHash<QString, QString> 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();