From d92814187a7bd2f6c3a377edccff3fa8782cdc89 Mon Sep 17 00:00:00 2001 From: Martchus Date: Wed, 25 Sep 2019 18:18:06 +0200 Subject: [PATCH] Hide progress indication before showing cover/lyrics dialog --- dbquery/dbquery.cpp | 49 +++++++++++++++++++++++------------------ dbquery/lyricswikia.cpp | 5 ++++- gui/dbquerywidget.cpp | 16 +++----------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/dbquery/dbquery.cpp b/dbquery/dbquery.cpp index 6fb7118..9691dcb 100644 --- a/dbquery/dbquery.cpp +++ b/dbquery/dbquery.cpp @@ -358,39 +358,46 @@ void HttpResultsModel::handleCoverReplyFinished(QNetworkReply *reply, const QStr if (!data.isEmpty()) { parseCoverResults(albumId, row, data); } - setResultsAvailable(true); + if (!m_resultsAvailable) { + setResultsAvailable(true); + } } void HttpResultsModel::parseCoverResults(const QString &albumId, int row, const QByteArray &data) { + setFetchingCover(false); + // add cover -> determine album ID and row if (albumId.isEmpty() || row >= m_results.size()) { m_errorList << tr("Internal error: context for cover reply invalid"); setResultsAvailable(true); return; } - if (!data.isEmpty()) { - // cache the fetched cover - const auto currentCachedCoverCount = s_coverData.size(); - s_coverData[albumId] = data; - if (s_coverData.size() > currentCachedCoverCount) { - s_coverNames.emplace_back(albumId); - // keep only the last 20 cover images around - while (s_coverNames.size() > 20) { - s_coverData.erase(s_coverNames.front()); - s_coverNames.pop_front(); - } - } else if (s_coverNames.back() != albumId) { - s_coverNames.remove(albumId); - s_coverNames.emplace_back(albumId); - } - - // add the cover to the results - m_results[row].cover = data; - emit coverAvailable(index(row, 0)); + if (data.isEmpty()) { + return; } - setFetchingCover(false); + + // cache the fetched cover + const auto currentCachedCoverCount = s_coverData.size(); + s_coverData[albumId] = data; + if (s_coverData.size() > currentCachedCoverCount) { + s_coverNames.emplace_back(albumId); + + // keep only the last 20 cover images around + while (s_coverNames.size() > 20) { + s_coverData.erase(s_coverNames.front()); + s_coverNames.pop_front(); + } + } else if (s_coverNames.back() != albumId) { + s_coverNames.remove(albumId); + s_coverNames.emplace_back(albumId); + } + + // add the cover to the results + m_results[row].cover = data; + setResultsAvailable(true); + emit coverAvailable(index(row, 0)); } } // namespace QtGui diff --git a/dbquery/lyricswikia.cpp b/dbquery/lyricswikia.cpp index 4de0221..d17030e 100644 --- a/dbquery/lyricswikia.cpp +++ b/dbquery/lyricswikia.cpp @@ -313,7 +313,9 @@ void LyricsWikiaResultsModel::handleLyricsReplyFinished(QNetworkReply *reply, in if (!data.isEmpty()) { parseLyricsResults(row, data); } - setResultsAvailable(true); + if (!m_resultsAvailable) { + setResultsAvailable(true); + } } void LyricsWikiaResultsModel::parseLyricsResults(int row, const QByteArray &data) @@ -341,6 +343,7 @@ void LyricsWikiaResultsModel::parseLyricsResults(int row, const QByteArray &data textDoc.setHtml(html.mid(lyricsStart, (lyricsEnd > lyricsStart) ? (lyricsEnd - lyricsStart) : -1)); assocDesc.lyrics = textDoc.toPlainText(); + setResultsAvailable(true); emit lyricsAvailable(index(row, 0)); } diff --git a/gui/dbquerywidget.cpp b/gui/dbquerywidget.cpp index 66c2287..aed57bd 100644 --- a/gui/dbquerywidget.cpp +++ b/gui/dbquerywidget.cpp @@ -603,13 +603,8 @@ void DbQueryWidget::fetchAndShowCoverForSelection() return; } - if (const QByteArray *const cover = m_model->cover(selectedIndex)) { - showCover(*cover); - return; - } - if (m_model->fetchCover(selectedIndex)) { - if (const QByteArray *const cover = m_model->cover(selectedIndex)) { + if (const auto *const cover = m_model->cover(selectedIndex)) { showCover(*cover); } else { // cover couldn't be fetched, error tracked via resultsAvailable() signal so nothing to do @@ -632,14 +627,9 @@ void DbQueryWidget::fetchAndShowLyricsForSelection() return; } - if (const QString *const lyrics = m_model->lyrics(selectedIndex)) { - showLyrics(*lyrics); - return; - } - if (m_model->fetchLyrics(selectedIndex)) { - if (const QByteArray *cover = m_model->cover(selectedIndex)) { - showLyrics(*cover); + if (const auto *const lyrics = m_model->lyrics(selectedIndex)) { + showLyrics(*lyrics); } else { // lyrics couldn't be fetched, error tracked via resultsAvailable() signal so nothing to do }