Change to const references, make search progress and status pass search id
This commit is contained in:
parent
9d222e2c57
commit
bf4001968e
|
@ -61,14 +61,13 @@ InternetSearch::InternetSearch(Application *app, Song::Source source, QObject *p
|
|||
cover_loader_options_.pad_output_image_ = true;
|
||||
cover_loader_options_.scale_output_image_ = true;
|
||||
|
||||
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)), SLOT(AlbumArtLoaded(quint64, QImage)));
|
||||
connect(this, SIGNAL(SearchAsyncSig(int, QString, SearchType)), this, SLOT(DoSearchAsync(int, QString, SearchType)));
|
||||
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)), SLOT(AlbumArtLoaded(const quint64, const QImage&)));
|
||||
connect(this, SIGNAL(SearchAsyncSig(const int, const QString&, const SearchType)), this, SLOT(DoSearchAsync(const int, const QString&, const SearchType)));
|
||||
|
||||
connect(service_, SIGNAL(SearchUpdateStatus(QString)), SLOT(UpdateStatusSlot(QString)));
|
||||
connect(service_, SIGNAL(SearchProgressSetMaximum(int)), SLOT(ProgressSetMaximumSlot(int)));
|
||||
connect(service_, SIGNAL(SearchUpdateProgress(int)), SLOT(UpdateProgressSlot(int)));
|
||||
connect(service_, SIGNAL(SearchResults(int, SongList)), SLOT(SearchDone(int, SongList)));
|
||||
connect(service_, SIGNAL(SearchError(int, QString)), SLOT(HandleError(int, QString)));
|
||||
connect(service_, SIGNAL(SearchUpdateStatus(const int, const QString&)), SLOT(UpdateStatusSlot(const int, const QString&)));
|
||||
connect(service_, SIGNAL(SearchProgressSetMaximum(const int, const int)), SLOT(ProgressSetMaximumSlot(const int, const int)));
|
||||
connect(service_, SIGNAL(SearchUpdateProgress(const int, const int)), SLOT(UpdateProgressSlot(const int, const int)));
|
||||
connect(service_, SIGNAL(SearchResults(const int, const SongList&, const QString&)), SLOT(SearchDone(const int, const SongList&, const QString&)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,7 +104,7 @@ bool InternetSearch::Matches(const QStringList &tokens, const QString &string) {
|
|||
|
||||
}
|
||||
|
||||
int InternetSearch::SearchAsync(const QString &query, SearchType type) {
|
||||
int InternetSearch::SearchAsync(const QString &query, const SearchType type) {
|
||||
|
||||
const int id = searches_next_id_++;
|
||||
|
||||
|
@ -115,14 +114,14 @@ int InternetSearch::SearchAsync(const QString &query, SearchType type) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::SearchAsync(int id, const QString &query, SearchType type) {
|
||||
void InternetSearch::SearchAsync(const int id, const QString &query, const SearchType type) {
|
||||
|
||||
const int service_id = service_->Search(query, type);
|
||||
pending_searches_[service_id] = PendingState(id, TokenizeQuery(query));
|
||||
|
||||
}
|
||||
|
||||
void InternetSearch::DoSearchAsync(int id, const QString &query, SearchType type) {
|
||||
void InternetSearch::DoSearchAsync(const int id, const QString &query, const SearchType type) {
|
||||
|
||||
int timer_id = startTimer(kDelayedSearchTimeoutMs);
|
||||
delayed_searches_[timer_id].id_ = id;
|
||||
|
@ -131,12 +130,19 @@ void InternetSearch::DoSearchAsync(int id, const QString &query, SearchType type
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::SearchDone(int service_id, const SongList &songs) {
|
||||
void InternetSearch::SearchDone(const int service_id, const SongList &songs, const QString &error) {
|
||||
|
||||
if (!pending_searches_.contains(service_id)) return;
|
||||
|
||||
// Map back to the original id.
|
||||
const PendingState state = pending_searches_.take(service_id);
|
||||
const int search_id = state.orig_id_;
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
emit SearchError(search_id, error);
|
||||
return;
|
||||
}
|
||||
|
||||
ResultList results;
|
||||
for (const Song &song : songs) {
|
||||
Result result;
|
||||
|
@ -157,13 +163,7 @@ void InternetSearch::SearchDone(int service_id, const SongList &songs) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::HandleError(const int id, const QString error) {
|
||||
|
||||
emit SearchError(id, error);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearch::MaybeSearchFinished(int id) {
|
||||
void InternetSearch::MaybeSearchFinished(const int id) {
|
||||
|
||||
if (pending_searches_.keys(PendingState(id, QStringList())).isEmpty()) {
|
||||
emit SearchFinished(id);
|
||||
|
@ -171,7 +171,7 @@ void InternetSearch::MaybeSearchFinished(int id) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::CancelSearch(int id) {
|
||||
void InternetSearch::CancelSearch(const int id) {
|
||||
|
||||
QMap<int, DelayedSearch>::iterator it;
|
||||
for (it = delayed_searches_.begin(); it != delayed_searches_.end(); ++it) {
|
||||
|
@ -219,7 +219,7 @@ int InternetSearch::LoadArtAsync(const InternetSearch::Result &result) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::AlbumArtLoaded(quint64 id, const QImage &image) {
|
||||
void InternetSearch::AlbumArtLoaded(const quint64 id, const QImage &image) {
|
||||
|
||||
if (!cover_loader_tasks_.contains(id)) return;
|
||||
int orig_id = cover_loader_tasks_.take(id);
|
||||
|
@ -289,14 +289,29 @@ MimeData *InternetSearch::LoadTracks(const ResultList &results) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearch::UpdateStatusSlot(QString text) {
|
||||
emit UpdateStatus(text);
|
||||
void InternetSearch::UpdateStatusSlot(const int service_id, const QString &text) {
|
||||
|
||||
if (!pending_searches_.contains(service_id)) return;
|
||||
const PendingState state = pending_searches_[service_id];
|
||||
const int search_id = state.orig_id_;
|
||||
emit UpdateStatus(search_id, text);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearch::ProgressSetMaximumSlot(int max) {
|
||||
emit ProgressSetMaximum(max);
|
||||
void InternetSearch::ProgressSetMaximumSlot(const int service_id, const int max) {
|
||||
|
||||
if (!pending_searches_.contains(service_id)) return;
|
||||
const PendingState state = pending_searches_[service_id];
|
||||
const int search_id = state.orig_id_;
|
||||
emit ProgressSetMaximum(search_id, max);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearch::UpdateProgressSlot(int progress) {
|
||||
emit UpdateProgress(progress);
|
||||
void InternetSearch::UpdateProgressSlot(const int service_id, const int progress) {
|
||||
|
||||
if (!pending_searches_.contains(service_id)) return;
|
||||
const PendingState state = pending_searches_[service_id];
|
||||
const int search_id = state.orig_id_;
|
||||
emit UpdateProgress(search_id, progress);
|
||||
|
||||
}
|
||||
|
|
|
@ -69,24 +69,24 @@ class InternetSearch : public QObject {
|
|||
int SearchAsync(const QString &query, SearchType type);
|
||||
int LoadArtAsync(const InternetSearch::Result &result);
|
||||
|
||||
void CancelSearch(int id);
|
||||
void CancelArt(int id);
|
||||
void CancelSearch(const int id);
|
||||
void CancelArt(const int id);
|
||||
|
||||
// Loads tracks for results that were previously emitted by ResultsAvailable.
|
||||
// The implementation creates a SongMimeData with one Song for each Result.
|
||||
MimeData *LoadTracks(const ResultList &results);
|
||||
|
||||
signals:
|
||||
void SearchAsyncSig(int id, const QString &query, SearchType type);
|
||||
void ResultsAvailable(int id, const InternetSearch::ResultList &results);
|
||||
void AddResults(int id, const InternetSearch::ResultList &results);
|
||||
void SearchError(const int id, const QString error);
|
||||
void SearchFinished(int id);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int progress);
|
||||
void UpdateProgress(int max);
|
||||
void SearchAsyncSig(const int id, const QString &query, const SearchType type);
|
||||
void ResultsAvailable(const int id, const InternetSearch::ResultList &results);
|
||||
void AddResults(const int id, const InternetSearch::ResultList &results);
|
||||
void SearchError(const int id, const QString &error);
|
||||
void SearchFinished(const int id);
|
||||
void UpdateStatus(const int id, const QString &text);
|
||||
void ProgressSetMaximum(const int id, const int progress);
|
||||
void UpdateProgress(const int id, const int max);
|
||||
|
||||
void ArtLoaded(int id, const QPixmap &pixmap);
|
||||
void ArtLoaded(const int id, const QPixmap &pixmap);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -114,22 +114,20 @@ class InternetSearch : public QObject {
|
|||
static bool Matches(const QStringList &tokens, const QString &string);
|
||||
|
||||
private slots:
|
||||
void DoSearchAsync(int id, const QString &query, SearchType type);
|
||||
void SearchDone(int id, const SongList &songs);
|
||||
void HandleError(const int id, const QString error);
|
||||
void DoSearchAsync(const int id, const QString &query, const SearchType type);
|
||||
void SearchDone(const int service_id, const SongList &songs, const QString &error);
|
||||
|
||||
void AlbumArtLoaded(quint64 id, const QImage &image);
|
||||
void AlbumArtLoaded(const quint64 id, const QImage &image);
|
||||
|
||||
void UpdateStatusSlot(QString text);
|
||||
void ProgressSetMaximumSlot(int progress);
|
||||
void UpdateProgressSlot(int max);
|
||||
void UpdateStatusSlot(const int id, const QString &text);
|
||||
void ProgressSetMaximumSlot(const int id, const int progress);
|
||||
void UpdateProgressSlot(const int id, const int max);
|
||||
|
||||
private:
|
||||
void SearchAsync(int id, const QString &query, SearchType type);
|
||||
void HandleLoadedArt(int id, const QImage &image);
|
||||
void SearchAsync(const int id, const QString &query, const SearchType type);
|
||||
bool FindCachedPixmap(const InternetSearch::Result &result, QPixmap *pixmap) const;
|
||||
QString PixmapCacheKey(const InternetSearch::Result &result) const;
|
||||
void MaybeSearchFinished(int id);
|
||||
void MaybeSearchFinished(const int id);
|
||||
void ShowConfig() {}
|
||||
static QImage ScaleAndPad(const QImage &image);
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ InternetSearchView::InternetSearchView(QWidget *parent)
|
|||
|
||||
InternetSearchView::~InternetSearchView() { delete ui_; }
|
||||
|
||||
void InternetSearchView::Init(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, const bool artists, const bool albums, const bool songs) {
|
||||
void InternetSearchView::Init(Application *app, InternetSearch *engine, const QString &settings_group, const SettingsDialog::Page settings_page, const bool artists, const bool albums, const bool songs) {
|
||||
|
||||
app_ = app;
|
||||
engine_ = engine;
|
||||
|
@ -167,13 +167,13 @@ void InternetSearchView::Init(Application *app, InternetSearch *engine, QString
|
|||
|
||||
// These have to be queued connections because they may get emitted before our call to Search() (or whatever) returns and we add the ID to the map.
|
||||
|
||||
connect(engine_, SIGNAL(UpdateStatus(QString)), SLOT(UpdateStatus(QString)));
|
||||
connect(engine_, SIGNAL(ProgressSetMaximum(int)), SLOT(ProgressSetMaximum(int)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(UpdateProgress(int)), SLOT(UpdateProgress(int)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(UpdateStatus(const int, const QString&)), SLOT(UpdateStatus(const int, const QString&)));
|
||||
connect(engine_, SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(ProgressSetMaximum(const int, const int)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(UpdateProgress(const int, const int)), SLOT(UpdateProgress(const int, const int)), Qt::QueuedConnection);
|
||||
|
||||
connect(engine_, SIGNAL(AddResults(int, InternetSearch::ResultList)), SLOT(AddResults(int, InternetSearch::ResultList)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(SearchError(int, QString)), SLOT(SearchError(int, QString)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(ArtLoaded(int, QPixmap)), SLOT(ArtLoaded(int, QPixmap)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(AddResults(const int, InternetSearch::ResultList)), SLOT(AddResults(const int, const InternetSearch::ResultList)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(SearchError(const int, const QString&)), SLOT(SearchError(const int, const QString&)), Qt::QueuedConnection);
|
||||
connect(engine_, SIGNAL(ArtLoaded(const int, const QPixmap&)), SLOT(ArtLoaded(const int, const QPixmap&)), Qt::QueuedConnection);
|
||||
|
||||
ReloadSettings();
|
||||
|
||||
|
@ -253,7 +253,7 @@ void InternetSearchView::TextEdited(const QString &text) {
|
|||
|
||||
}
|
||||
|
||||
void InternetSearchView::AddResults(int id, const InternetSearch::ResultList &results) {
|
||||
void InternetSearchView::AddResults(const int id, const InternetSearch::ResultList &results) {
|
||||
|
||||
if (id != last_search_id_) return;
|
||||
if (results.isEmpty()) return;
|
||||
|
@ -264,8 +264,9 @@ void InternetSearchView::AddResults(int id, const InternetSearch::ResultList &re
|
|||
|
||||
}
|
||||
|
||||
void InternetSearchView::SearchError(const int id, const QString error) {
|
||||
void InternetSearchView::SearchError(const int id, const QString &error) {
|
||||
|
||||
if (id != last_search_id_) return;
|
||||
error_ = true;
|
||||
ui_->label_helptext->setText(error);
|
||||
ui_->label_status->clear();
|
||||
|
@ -594,17 +595,26 @@ void InternetSearchView::SetSearchType(InternetSearch::SearchType type) {
|
|||
TextEdited(ui_->search->text());
|
||||
}
|
||||
|
||||
void InternetSearchView::UpdateStatus(QString text) {
|
||||
void InternetSearchView::UpdateStatus(const int id, const QString &text) {
|
||||
|
||||
if (id != last_search_id_) return;
|
||||
ui_->progressbar->show();
|
||||
ui_->label_status->setText(text);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearchView::ProgressSetMaximum(int max) {
|
||||
void InternetSearchView::ProgressSetMaximum(const int id, const int max) {
|
||||
|
||||
if (id != last_search_id_) return;
|
||||
ui_->progressbar->setMaximum(max);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearchView::UpdateProgress(int progress) {
|
||||
void InternetSearchView::UpdateProgress(const int id, const int progress) {
|
||||
|
||||
if (id != last_search_id_) return;
|
||||
ui_->progressbar->setValue(progress);
|
||||
|
||||
}
|
||||
|
||||
void InternetSearchView::AddArtists() {
|
||||
|
|
|
@ -59,7 +59,7 @@ class InternetSearchView : public QWidget {
|
|||
InternetSearchView(QWidget *parent = nullptr);
|
||||
~InternetSearchView();
|
||||
|
||||
void Init(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, const bool artists = false, const bool albums = false, const bool songs = false);
|
||||
void Init(Application *app, InternetSearch *engine, const QString &settings_group, const SettingsDialog::Page settings_page, const bool artists = false, const bool albums = false, const bool songs = false);
|
||||
|
||||
static const int kSwapModelsTimeoutMsec;
|
||||
|
||||
|
@ -84,12 +84,12 @@ class InternetSearchView : public QWidget {
|
|||
private slots:
|
||||
void SwapModels();
|
||||
void TextEdited(const QString &text);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int progress);
|
||||
void UpdateProgress(int max);
|
||||
void AddResults(int id, const InternetSearch::ResultList &results);
|
||||
void SearchError(const int id, const QString error);
|
||||
void ArtLoaded(int id, const QPixmap &pixmap);
|
||||
void UpdateStatus(const int id, const QString &text);
|
||||
void ProgressSetMaximum(const int id, const int progress);
|
||||
void UpdateProgress(const int id, const int max);
|
||||
void AddResults(const int id, const InternetSearch::ResultList &results);
|
||||
void SearchError(const int id, const QString &error);
|
||||
void ArtLoaded(const int id, const QPixmap &pixmap);
|
||||
|
||||
void FocusOnFilter(QKeyEvent *event);
|
||||
|
||||
|
|
|
@ -87,35 +87,31 @@ class InternetService : public QObject {
|
|||
void TestFailure(QString failure_reason);
|
||||
void TestComplete(bool success, QString error = QString());
|
||||
|
||||
void Error(QString message);
|
||||
void Results(SongList songs);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int max);
|
||||
void UpdateProgress(int max);
|
||||
void Error(const QString &error);
|
||||
void Results(const SongList &songs, const QString &error);
|
||||
void UpdateStatus(const QString &text);
|
||||
void ProgressSetMaximum(const int max);
|
||||
void UpdateProgress(const int max);
|
||||
|
||||
void ArtistsError(QString message);
|
||||
void ArtistsResults(SongList songs);
|
||||
void ArtistsUpdateStatus(QString text);
|
||||
void ArtistsProgressSetMaximum(int max);
|
||||
void ArtistsUpdateProgress(int max);
|
||||
void ArtistsResults(const SongList &songs, const QString &error);
|
||||
void ArtistsUpdateStatus(const QString &text);
|
||||
void ArtistsProgressSetMaximum(const int max);
|
||||
void ArtistsUpdateProgress(const int max);
|
||||
|
||||
void AlbumsError(QString message);
|
||||
void AlbumsResults(SongList songs);
|
||||
void AlbumsUpdateStatus(QString text);
|
||||
void AlbumsProgressSetMaximum(int max);
|
||||
void AlbumsUpdateProgress(int max);
|
||||
void AlbumsResults(const SongList &songs, const QString &error);
|
||||
void AlbumsUpdateStatus(const QString &text);
|
||||
void AlbumsProgressSetMaximum(const int max);
|
||||
void AlbumsUpdateProgress(const int max);
|
||||
|
||||
void SongsError(QString message);
|
||||
void SongsResults(SongList songs);
|
||||
void SongsUpdateStatus(QString text);
|
||||
void SongsProgressSetMaximum(int max);
|
||||
void SongsUpdateProgress(int max);
|
||||
void SongsResults(const SongList &songs, const QString &error);
|
||||
void SongsUpdateStatus(const QString &text);
|
||||
void SongsProgressSetMaximum(const int max);
|
||||
void SongsUpdateProgress(const int max);
|
||||
|
||||
void SearchResults(int id, SongList songs);
|
||||
void SearchError(int id, QString message);
|
||||
void SearchUpdateStatus(QString text);
|
||||
void SearchProgressSetMaximum(int max);
|
||||
void SearchUpdateProgress(int max);
|
||||
void SearchResults(const int id, const SongList &songs, const QString &error);
|
||||
void SearchUpdateStatus(const int id, const QString &text);
|
||||
void SearchProgressSetMaximum(const int id, const int max);
|
||||
void SearchUpdateProgress(const int id, const int max);
|
||||
|
||||
void AddArtists(const SongList& songs);
|
||||
void AddAlbums(const SongList& songs);
|
||||
|
|
|
@ -57,11 +57,10 @@ InternetSongsView::InternetSongsView(Application *app, InternetService *service,
|
|||
connect(ui_->refresh, SIGNAL(clicked()), SLOT(GetSongs()));
|
||||
connect(ui_->close, SIGNAL(clicked()), SLOT(AbortGetSongs()));
|
||||
connect(ui_->abort, SIGNAL(clicked()), SLOT(AbortGetSongs()));
|
||||
connect(service_, SIGNAL(SongsResults(SongList)), SLOT(SongsFinished(SongList)));
|
||||
connect(service_, SIGNAL(SongsError(QString)), SLOT(SongsError(QString)));
|
||||
connect(service_, SIGNAL(SongsUpdateStatus(QString)), ui_->status, SLOT(setText(QString)));
|
||||
connect(service_, SIGNAL(SongsProgressSetMaximum(int)), ui_->progressbar, SLOT(setMaximum(int)));
|
||||
connect(service_, SIGNAL(SongsUpdateProgress(int)), ui_->progressbar, SLOT(setValue(int)));
|
||||
connect(service_, SIGNAL(SongsResults(const SongList&, const QString&)), SLOT(SongsFinished(const SongList&, const QString&)));
|
||||
connect(service_, SIGNAL(SongsUpdateStatus(const QString&)), ui_->status, SLOT(setText(const QString&)));
|
||||
connect(service_, SIGNAL(SongsProgressSetMaximum(const int)), ui_->progressbar, SLOT(setMaximum(const int)));
|
||||
connect(service_, SIGNAL(SongsUpdateProgress(const int)), ui_->progressbar, SLOT(setValue(const int)));
|
||||
|
||||
connect(service_->songs_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->view, SLOT(TotalArtistCountUpdated(int)));
|
||||
connect(service_->songs_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->view, SLOT(TotalAlbumCountUpdated(int)));
|
||||
|
@ -104,21 +103,20 @@ void InternetSongsView::AbortGetSongs() {
|
|||
|
||||
}
|
||||
|
||||
void InternetSongsView::SongsError(QString error) {
|
||||
void InternetSongsView::SongsFinished(const SongList &songs, const QString &error) {
|
||||
|
||||
ui_->status->setText(error);
|
||||
ui_->progressbar->setValue(0);
|
||||
ui_->progressbar->hide();
|
||||
ui_->abort->hide();
|
||||
ui_->close->show();
|
||||
|
||||
}
|
||||
|
||||
void InternetSongsView::SongsFinished(SongList songs) {
|
||||
|
||||
service_->songs_collection_backend()->DeleteAll();
|
||||
ui_->stacked->setCurrentWidget(ui_->internetcollection_page);
|
||||
ui_->status->clear();
|
||||
service_->songs_collection_backend()->AddOrUpdateSongs(songs);
|
||||
if (songs.isEmpty() && !error.isEmpty()) {
|
||||
ui_->status->setText(error);
|
||||
ui_->progressbar->setValue(0);
|
||||
ui_->progressbar->hide();
|
||||
ui_->abort->hide();
|
||||
ui_->close->show();
|
||||
}
|
||||
else {
|
||||
service_->songs_collection_backend()->DeleteAll();
|
||||
ui_->stacked->setCurrentWidget(ui_->internetcollection_page);
|
||||
ui_->status->clear();
|
||||
service_->songs_collection_backend()->AddOrUpdateSongs(songs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,8 +52,7 @@ class InternetSongsView : public QWidget {
|
|||
void contextMenuEvent(QContextMenuEvent *e);
|
||||
void GetSongs();
|
||||
void AbortGetSongs();;
|
||||
void SongsError(QString error);
|
||||
void SongsFinished(SongList songs);
|
||||
void SongsFinished(const SongList &songs, const QString &error);
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
|
|
|
@ -65,11 +65,10 @@ InternetTabsView::InternetTabsView(Application *app, InternetService *service, I
|
|||
connect(ui_->artists_collection->button_refresh(), SIGNAL(clicked()), SLOT(GetArtists()));
|
||||
connect(ui_->artists_collection->button_close(), SIGNAL(clicked()), SLOT(AbortGetArtists()));
|
||||
connect(ui_->artists_collection->button_abort(), SIGNAL(clicked()), SLOT(AbortGetArtists()));
|
||||
connect(service_, SIGNAL(ArtistsResults(SongList)), SLOT(ArtistsFinished(SongList)));
|
||||
connect(service_, SIGNAL(ArtistsError(QString)), SLOT(ArtistsError(QString)));
|
||||
connect(service_, SIGNAL(ArtistsUpdateStatus(QString)), ui_->artists_collection->status(), SLOT(setText(QString)));
|
||||
connect(service_, SIGNAL(ArtistsProgressSetMaximum(int)), ui_->artists_collection->progressbar(), SLOT(setMaximum(int)));
|
||||
connect(service_, SIGNAL(ArtistsUpdateProgress(int)), ui_->artists_collection->progressbar(), SLOT(setValue(int)));
|
||||
connect(service_, SIGNAL(ArtistsResults(const SongList&, const QString&)), SLOT(ArtistsFinished(const SongList&, const QString&)));
|
||||
connect(service_, SIGNAL(ArtistsUpdateStatus(const QString&)), ui_->artists_collection->status(), SLOT(setText(const QString&)));
|
||||
connect(service_, SIGNAL(ArtistsProgressSetMaximum(const int)), ui_->artists_collection->progressbar(), SLOT(setMaximum(const int)));
|
||||
connect(service_, SIGNAL(ArtistsUpdateProgress(const int)), ui_->artists_collection->progressbar(), SLOT(setValue(const int)));
|
||||
|
||||
connect(service_->artists_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->artists_collection->view(), SLOT(TotalArtistCountUpdated(int)));
|
||||
connect(service_->artists_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->artists_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
|
||||
|
@ -97,11 +96,10 @@ InternetTabsView::InternetTabsView(Application *app, InternetService *service, I
|
|||
connect(ui_->albums_collection->button_refresh(), SIGNAL(clicked()), SLOT(GetAlbums()));
|
||||
connect(ui_->albums_collection->button_close(), SIGNAL(clicked()), SLOT(AbortGetAlbums()));
|
||||
connect(ui_->albums_collection->button_abort(), SIGNAL(clicked()), SLOT(AbortGetAlbums()));
|
||||
connect(service_, SIGNAL(AlbumsResults(SongList)), SLOT(AlbumsFinished(SongList)));
|
||||
connect(service_, SIGNAL(AlbumsError(QString)), SLOT(AlbumsError(QString)));
|
||||
connect(service_, SIGNAL(AlbumsUpdateStatus(QString)), ui_->albums_collection->status(), SLOT(setText(QString)));
|
||||
connect(service_, SIGNAL(AlbumsProgressSetMaximum(int)), ui_->albums_collection->progressbar(), SLOT(setMaximum(int)));
|
||||
connect(service_, SIGNAL(AlbumsUpdateProgress(int)), ui_->albums_collection->progressbar(), SLOT(setValue(int)));
|
||||
connect(service_, SIGNAL(AlbumsResults(const SongList&, const QString&)), SLOT(AlbumsFinished(const SongList&, const QString&)));
|
||||
connect(service_, SIGNAL(AlbumsUpdateStatus(const QString&)), ui_->albums_collection->status(), SLOT(setText(const QString&)));
|
||||
connect(service_, SIGNAL(AlbumsProgressSetMaximum(const int)), ui_->albums_collection->progressbar(), SLOT(setMaximum(const int)));
|
||||
connect(service_, SIGNAL(AlbumsUpdateProgress(const int)), ui_->albums_collection->progressbar(), SLOT(setValue(const int)));
|
||||
|
||||
connect(service_->albums_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->albums_collection->view(), SLOT(TotalArtistCountUpdated(int)));
|
||||
connect(service_->albums_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->albums_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
|
||||
|
@ -129,11 +127,10 @@ InternetTabsView::InternetTabsView(Application *app, InternetService *service, I
|
|||
connect(ui_->songs_collection->button_refresh(), SIGNAL(clicked()), SLOT(GetSongs()));
|
||||
connect(ui_->songs_collection->button_close(), SIGNAL(clicked()), SLOT(AbortGetSongs()));
|
||||
connect(ui_->songs_collection->button_abort(), SIGNAL(clicked()), SLOT(AbortGetSongs()));
|
||||
connect(service_, SIGNAL(SongsResults(SongList)), SLOT(SongsFinished(SongList)));
|
||||
connect(service_, SIGNAL(SongsError(QString)), SLOT(SongsError(QString)));
|
||||
connect(service_, SIGNAL(SongsUpdateStatus(QString)), ui_->songs_collection->status(), SLOT(setText(QString)));
|
||||
connect(service_, SIGNAL(SongsProgressSetMaximum(int)), ui_->songs_collection->progressbar(), SLOT(setMaximum(int)));
|
||||
connect(service_, SIGNAL(SongsUpdateProgress(int)), ui_->songs_collection->progressbar(), SLOT(setValue(int)));
|
||||
connect(service_, SIGNAL(SongsResults(const SongList&, const QString&)), SLOT(SongsFinished(const SongList&, const QString&)));
|
||||
connect(service_, SIGNAL(SongsUpdateStatus(const QString&)), ui_->songs_collection->status(), SLOT(setText(const QString&)));
|
||||
connect(service_, SIGNAL(SongsProgressSetMaximum(const int)), ui_->songs_collection->progressbar(), SLOT(setMaximum(const int)));
|
||||
connect(service_, SIGNAL(SongsUpdateProgress(const int)), ui_->songs_collection->progressbar(), SLOT(setValue(const int)));
|
||||
|
||||
connect(service_->songs_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->songs_collection->view(), SLOT(TotalArtistCountUpdated(int)));
|
||||
connect(service_->songs_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->songs_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
|
||||
|
@ -208,22 +205,21 @@ void InternetTabsView::AbortGetArtists() {
|
|||
|
||||
}
|
||||
|
||||
void InternetTabsView::ArtistsError(QString error) {
|
||||
void InternetTabsView::ArtistsFinished(const SongList &songs, const QString &error) {
|
||||
|
||||
ui_->artists_collection->status()->setText(error);
|
||||
ui_->artists_collection->progressbar()->setValue(0);
|
||||
ui_->artists_collection->progressbar()->hide();
|
||||
ui_->artists_collection->button_abort()->hide();
|
||||
ui_->artists_collection->button_close()->show();
|
||||
|
||||
}
|
||||
|
||||
void InternetTabsView::ArtistsFinished(SongList songs) {
|
||||
|
||||
service_->artists_collection_backend()->DeleteAll();
|
||||
ui_->artists_collection->stacked()->setCurrentWidget(ui_->artists_collection->internetcollection_page());
|
||||
ui_->artists_collection->status()->clear();
|
||||
service_->artists_collection_backend()->AddOrUpdateSongs(songs);
|
||||
if (songs.isEmpty() && !error.isEmpty()) {
|
||||
ui_->artists_collection->status()->setText(error);
|
||||
ui_->artists_collection->progressbar()->setValue(0);
|
||||
ui_->artists_collection->progressbar()->hide();
|
||||
ui_->artists_collection->button_abort()->hide();
|
||||
ui_->artists_collection->button_close()->show();
|
||||
}
|
||||
else {
|
||||
service_->artists_collection_backend()->DeleteAll();
|
||||
ui_->artists_collection->stacked()->setCurrentWidget(ui_->artists_collection->internetcollection_page());
|
||||
ui_->artists_collection->status()->clear();
|
||||
service_->artists_collection_backend()->AddOrUpdateSongs(songs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -252,22 +248,21 @@ void InternetTabsView::AbortGetAlbums() {
|
|||
|
||||
}
|
||||
|
||||
void InternetTabsView::AlbumsError(QString error) {
|
||||
void InternetTabsView::AlbumsFinished(const SongList &songs, const QString &error) {
|
||||
|
||||
ui_->albums_collection->status()->setText(error);
|
||||
ui_->albums_collection->progressbar()->setValue(0);
|
||||
ui_->albums_collection->progressbar()->hide();
|
||||
ui_->albums_collection->button_abort()->hide();
|
||||
ui_->albums_collection->button_close()->show();
|
||||
|
||||
}
|
||||
|
||||
void InternetTabsView::AlbumsFinished(SongList songs) {
|
||||
|
||||
service_->albums_collection_backend()->DeleteAll();
|
||||
ui_->albums_collection->stacked()->setCurrentWidget(ui_->albums_collection->internetcollection_page());
|
||||
ui_->albums_collection->status()->clear();
|
||||
service_->albums_collection_backend()->AddOrUpdateSongs(songs);
|
||||
if (songs.isEmpty() && !error.isEmpty()) {
|
||||
ui_->albums_collection->status()->setText(error);
|
||||
ui_->albums_collection->progressbar()->setValue(0);
|
||||
ui_->albums_collection->progressbar()->hide();
|
||||
ui_->albums_collection->button_abort()->hide();
|
||||
ui_->albums_collection->button_close()->show();
|
||||
}
|
||||
else {
|
||||
service_->albums_collection_backend()->DeleteAll();
|
||||
ui_->albums_collection->stacked()->setCurrentWidget(ui_->albums_collection->internetcollection_page());
|
||||
ui_->albums_collection->status()->clear();
|
||||
service_->albums_collection_backend()->AddOrUpdateSongs(songs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -296,21 +291,20 @@ void InternetTabsView::AbortGetSongs() {
|
|||
|
||||
}
|
||||
|
||||
void InternetTabsView::SongsError(QString error) {
|
||||
void InternetTabsView::SongsFinished(const SongList &songs, const QString &error) {
|
||||
|
||||
ui_->songs_collection->status()->setText(error);
|
||||
ui_->songs_collection->progressbar()->setValue(0);
|
||||
ui_->songs_collection->progressbar()->hide();
|
||||
ui_->songs_collection->button_abort()->hide();
|
||||
ui_->songs_collection->button_close()->show();
|
||||
|
||||
}
|
||||
|
||||
void InternetTabsView::SongsFinished(SongList songs) {
|
||||
|
||||
service_->songs_collection_backend()->DeleteAll();
|
||||
ui_->songs_collection->stacked()->setCurrentWidget(ui_->songs_collection->internetcollection_page());
|
||||
ui_->songs_collection->status()->clear();
|
||||
service_->songs_collection_backend()->AddOrUpdateSongs(songs);
|
||||
if (songs.isEmpty() && !error.isEmpty()) {
|
||||
ui_->songs_collection->status()->setText(error);
|
||||
ui_->songs_collection->progressbar()->setValue(0);
|
||||
ui_->songs_collection->progressbar()->hide();
|
||||
ui_->songs_collection->button_abort()->hide();
|
||||
ui_->songs_collection->button_close()->show();
|
||||
}
|
||||
else {
|
||||
service_->songs_collection_backend()->DeleteAll();
|
||||
ui_->songs_collection->stacked()->setCurrentWidget(ui_->songs_collection->internetcollection_page());
|
||||
ui_->songs_collection->status()->clear();
|
||||
service_->songs_collection_backend()->AddOrUpdateSongs(songs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,12 +62,9 @@ class InternetTabsView : public QWidget {
|
|||
void AbortGetArtists();
|
||||
void AbortGetAlbums();
|
||||
void AbortGetSongs();
|
||||
void ArtistsError(QString error);
|
||||
void AlbumsError(QString error);
|
||||
void SongsError(QString error);
|
||||
void ArtistsFinished(SongList songs);
|
||||
void AlbumsFinished(SongList songs);
|
||||
void SongsFinished(SongList songs);
|
||||
void ArtistsFinished(const SongList &songs, const QString &error);
|
||||
void AlbumsFinished(const SongList &songs, const QString &error);
|
||||
void SongsFinished(const SongList &songs, const QString &error);
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
|
|
|
@ -53,7 +53,7 @@ QobuzRequest::QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler,
|
|||
url_handler_(url_handler),
|
||||
network_(network),
|
||||
type_(type),
|
||||
search_id_(-1),
|
||||
query_id_(-1),
|
||||
finished_(false),
|
||||
artists_requests_active_(0),
|
||||
artists_total_(0),
|
||||
|
@ -110,15 +110,15 @@ void QobuzRequest::Process() {
|
|||
|
||||
}
|
||||
|
||||
void QobuzRequest::Search(const int search_id, const QString &search_text) {
|
||||
search_id_ = search_id;
|
||||
void QobuzRequest::Search(const int query_id, const QString &search_text) {
|
||||
query_id_ = query_id;
|
||||
search_text_ = search_text;
|
||||
}
|
||||
|
||||
void QobuzRequest::GetArtists() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving artists..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving artists..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddArtistsRequest();
|
||||
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ void QobuzRequest::FlushArtistsRequests() {
|
|||
reply = CreateRequest("artist/search", params);
|
||||
}
|
||||
if (!reply) continue;
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,8 +164,8 @@ void QobuzRequest::FlushArtistsRequests() {
|
|||
|
||||
void QobuzRequest::GetAlbums() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving albums..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving albums..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddAlbumsRequest();
|
||||
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ void QobuzRequest::FlushAlbumsRequests() {
|
|||
reply = CreateRequest("album/search", params);
|
||||
}
|
||||
if (!reply) continue;
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
|
||||
|
||||
}
|
||||
|
||||
|
@ -211,8 +211,8 @@ void QobuzRequest::FlushAlbumsRequests() {
|
|||
|
||||
void QobuzRequest::GetSongs() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving songs..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving songs..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddSongsRequest();
|
||||
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ void QobuzRequest::FlushSongsRequests() {
|
|||
reply = CreateRequest("track/search", params);
|
||||
}
|
||||
if (!reply) continue;
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(SongsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(SongsReplyReceived(QNetworkReply*, const int, const int)), reply, request.limit, request.offset);
|
||||
|
||||
}
|
||||
|
||||
|
@ -258,8 +258,8 @@ void QobuzRequest::FlushSongsRequests() {
|
|||
|
||||
void QobuzRequest::ArtistsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddArtistsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -272,8 +272,8 @@ void QobuzRequest::AddArtistsSearchRequest(const int offset) {
|
|||
|
||||
void QobuzRequest::AlbumsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddAlbumsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -286,8 +286,8 @@ void QobuzRequest::AddAlbumsSearchRequest(const int offset) {
|
|||
|
||||
void QobuzRequest::SongsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddSongsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ void QobuzRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
ArtistsFinishCheck();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!json_obj.contains("artists")) {
|
||||
ArtistsFinishCheck();
|
||||
Error("Json object is missing artists.", json_obj);
|
||||
|
@ -359,8 +359,8 @@ void QobuzRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
}
|
||||
|
||||
if (offset_requested == 0) {
|
||||
emit ProgressSetMaximum(artists_total_);
|
||||
emit UpdateProgress(artists_received_);
|
||||
emit ProgressSetMaximum(query_id_, artists_total_);
|
||||
emit UpdateProgress(query_id_, artists_received_);
|
||||
}
|
||||
|
||||
QJsonValue json_value = ExtractItems(json_obj_artists, error);
|
||||
|
@ -371,7 +371,7 @@ void QobuzRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) { // Empty array means no results
|
||||
no_results_ = true;
|
||||
if (offset_requested == 0) no_results_ = true;
|
||||
ArtistsFinishCheck();
|
||||
return;
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ void QobuzRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
}
|
||||
artists_received_ += artists_received;
|
||||
|
||||
if (offset_requested != 0) emit UpdateProgress(artists_received_);
|
||||
if (offset_requested != 0) emit UpdateProgress(query_id_, artists_received_);
|
||||
|
||||
ArtistsFinishCheck(limit_requested, offset, artists_received);
|
||||
|
||||
|
@ -438,10 +438,10 @@ void QobuzRequest::ArtistsFinishCheck(const int limit, const int offset, const i
|
|||
artist_albums_requests_pending_.clear();
|
||||
|
||||
if (artist_albums_requested_ > 0) {
|
||||
if (artist_albums_requested_ == 1) emit UpdateStatus(tr("Retrieving albums for %1 artist...").arg(artist_albums_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving albums for %1 artists...").arg(artist_albums_requested_));
|
||||
emit ProgressSetMaximum(artist_albums_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (artist_albums_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving albums for %1 artist...").arg(artist_albums_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving albums for %1 artists...").arg(artist_albums_requested_));
|
||||
emit ProgressSetMaximum(query_id_, artist_albums_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ void QobuzRequest::FlushArtistAlbumsRequests() {
|
|||
|
||||
if (request.offset > 0) params << Param("offset", QString::number(request.offset));
|
||||
QNetworkReply *reply = CreateRequest(QString("artist/get"), params);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistAlbumsReplyReceived(QNetworkReply*, const qint64, int)), reply, request.artist_id, request.offset);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistAlbumsReplyReceived(QNetworkReply*, const qint64, const int)), reply, request.artist_id, request.offset);
|
||||
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ void QobuzRequest::ArtistAlbumsReplyReceived(QNetworkReply *reply, const qint64
|
|||
|
||||
--artist_albums_requests_active_;
|
||||
++artist_albums_received_;
|
||||
emit UpdateProgress(artist_albums_received_);
|
||||
emit UpdateProgress(query_id_, artist_albums_received_);
|
||||
AlbumsReceived(reply, artist_id, 0, offset_requested);
|
||||
if (!artist_albums_requests_queue_.isEmpty() && artist_albums_requests_active_ < kMaxConcurrentArtistAlbumsRequests) FlushArtistAlbumsRequests();
|
||||
|
||||
|
@ -512,9 +512,19 @@ void QobuzRequest::AlbumsReceived(QNetworkReply *reply, const qint64 artist_id_r
|
|||
return;
|
||||
}
|
||||
|
||||
qint64 artist_id = 0;
|
||||
qint64 album_artist_id = artist_id_requested;
|
||||
if (json_obj.contains("id")) {
|
||||
artist_id = json_obj["id"].toInt();
|
||||
album_artist_id = json_obj["id"].toInt();
|
||||
}
|
||||
QString album_artist;
|
||||
if (json_obj.contains("name")) {
|
||||
album_artist = json_obj["name"].toString();
|
||||
}
|
||||
|
||||
if (album_artist_id != artist_id_requested) {
|
||||
AlbumsFinishCheck(artist_id_requested);
|
||||
Error("Artist id returned does not match artist id requested.", json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("albums")) {
|
||||
|
@ -556,7 +566,9 @@ void QobuzRequest::AlbumsReceived(QNetworkReply *reply, const qint64 artist_id_r
|
|||
}
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) {
|
||||
no_results_ = true;
|
||||
if ((type_ == QueryType_Albums || type_ == QueryType_SearchAlbums) && offset_requested == 0) {
|
||||
no_results_ = true;
|
||||
}
|
||||
AlbumsFinishCheck(artist_id_requested);
|
||||
return;
|
||||
}
|
||||
|
@ -593,16 +605,15 @@ void QobuzRequest::AlbumsReceived(QNetworkReply *reply, const qint64 artist_id_r
|
|||
continue;
|
||||
}
|
||||
|
||||
artist_id = json_artist["id"].toInt();
|
||||
qint64 artist_id = json_artist["id"].toInt();
|
||||
QString artist = json_artist["name"].toString();
|
||||
if (artist_id_requested != 0 && artist_id != artist_id_requested) {
|
||||
qLog(Debug) << "Skipping artist" << "artist" << artist << artist_id << "does not match album artist" << album_artist_id << album_artist;
|
||||
continue;
|
||||
}
|
||||
|
||||
Request request;
|
||||
if (artist_id_requested == 0) {
|
||||
request.artist_id = artist_id;
|
||||
}
|
||||
else {
|
||||
request.artist_id = artist_id_requested;
|
||||
}
|
||||
request.artist_id = artist_id;
|
||||
request.album_id = album_id;
|
||||
request.album_artist = artist;
|
||||
request.album = album;
|
||||
|
@ -650,15 +661,15 @@ void QobuzRequest::AlbumsFinishCheck(const qint64 artist_id, const int limit, co
|
|||
QHash<QString, Request> ::iterator i;
|
||||
for (i = album_songs_requests_pending_.begin() ; i != album_songs_requests_pending_.end() ; ++i) {
|
||||
Request request = i.value();
|
||||
AddAlbumSongsRequest(request.artist_id, request.album_id, request.album_artist);
|
||||
AddAlbumSongsRequest(request.artist_id, request.album_id, request.album_artist, request.album);
|
||||
}
|
||||
album_songs_requests_pending_.clear();
|
||||
|
||||
if (album_songs_requested_ > 0) {
|
||||
if (album_songs_requested_ == 1) emit UpdateStatus(tr("Retrieving songs for %1 album...").arg(album_songs_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving songs for %1 albums...").arg(album_songs_requested_));
|
||||
emit ProgressSetMaximum(album_songs_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (album_songs_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving songs for %1 album...").arg(album_songs_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving songs for %1 albums...").arg(album_songs_requested_));
|
||||
emit ProgressSetMaximum(query_id_, album_songs_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,12 +684,13 @@ void QobuzRequest::SongsReplyReceived(QNetworkReply *reply, const int limit_requ
|
|||
|
||||
}
|
||||
|
||||
void QobuzRequest::AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const int offset) {
|
||||
void QobuzRequest::AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const QString &album, const int offset) {
|
||||
|
||||
Request request;
|
||||
request.artist_id = artist_id;
|
||||
request.album_id = album_id;
|
||||
request.album_artist = album_artist;
|
||||
request.album = album;
|
||||
request.offset = offset;
|
||||
album_songs_requests_queue_.enqueue(request);
|
||||
++album_songs_requested_;
|
||||
|
@ -695,24 +707,24 @@ void QobuzRequest::FlushAlbumSongsRequests() {
|
|||
ParamList params = ParamList() << Param("album_id", request.album_id);
|
||||
if (request.offset > 0) params << Param("offset", QString::number(request.offset));
|
||||
QNetworkReply *reply = CreateRequest(QString("album/get"), params);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, const qint64, const QString&, int, const QString&)), reply, request.artist_id, request.album_id, request.offset, request.album_artist);
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, const qint64, const QString&, const int, const QString&, const QString&)), reply, request.artist_id, request.album_id, request.offset, request.album_artist, request.album);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QobuzRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const QString &album_id, const int offset_requested, const QString &album_artist) {
|
||||
void QobuzRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const QString &album_id, const int offset_requested, const QString &album_artist, const QString &album) {
|
||||
|
||||
--album_songs_requests_active_;
|
||||
++album_songs_received_;
|
||||
if (offset_requested == 0) {
|
||||
emit UpdateProgress(album_songs_received_);
|
||||
emit UpdateProgress(query_id_, album_songs_received_);
|
||||
}
|
||||
SongsReceived(reply, artist_id, album_id, 0, offset_requested, album_artist);
|
||||
SongsReceived(reply, artist_id, album_id, 0, offset_requested, album_artist, album);
|
||||
|
||||
}
|
||||
|
||||
void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_requested, const QString &album_id_requested, const int limit_requested, const int offset_requested, const QString &album_artist_requested) {
|
||||
void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_requested, const QString &album_id_requested, const int limit_requested, const int offset_requested, const QString &album_artist_requested, const QString &album_requested) {
|
||||
|
||||
QString error;
|
||||
QByteArray data = GetReplyData(reply, error);
|
||||
|
@ -720,28 +732,26 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
if (finished_) return;
|
||||
|
||||
if (data.isEmpty()) {
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested, album_requested);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(data, error);
|
||||
if (json_obj.isEmpty()) {
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested, album_requested);
|
||||
return;
|
||||
}
|
||||
|
||||
//qLog(Debug) << json_obj;
|
||||
|
||||
if (!json_obj.contains("tracks")) {
|
||||
Error("Json object is missing tracks.", json_obj);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested, album_requested);
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 artist_id = 0;
|
||||
QString album_artist;
|
||||
QString album_id;
|
||||
QString album;
|
||||
qint64 artist_id = artist_id_requested;
|
||||
QString album_artist = album_artist_requested;
|
||||
QString album_id = album_id_requested;
|
||||
QString album = album_requested;
|
||||
QUrl cover_url;
|
||||
|
||||
if (json_obj.contains("id")) {
|
||||
|
@ -756,13 +766,13 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
QJsonValue json_artist = json_obj["artist"];
|
||||
if (!json_artist.isObject()) {
|
||||
Error("Invalid Json reply, album artist is not a object.", json_artist);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
QJsonObject json_obj_artist = json_artist.toObject();
|
||||
if (!json_obj_artist.contains("id") || !json_obj_artist.contains("name")) {
|
||||
Error("Invalid Json reply, album artist is missing id or name.", json_obj_artist);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
artist_id = json_obj_artist["id"].toInt();
|
||||
|
@ -773,13 +783,13 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
QJsonValue json_image = json_obj["image"];
|
||||
if (!json_image.isObject()) {
|
||||
Error("Invalid Json reply, album image is not a object.", json_image);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
QJsonObject json_obj_image = json_image.toObject();
|
||||
if (!json_obj_image.contains("large")) {
|
||||
Error("Invalid Json reply, album image is missing large.", json_obj_image);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
QString album_image = json_obj_image["large"].toString();
|
||||
|
@ -791,7 +801,7 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
QJsonValue json_tracks = json_obj["tracks"];
|
||||
if (!json_tracks.isObject()) {
|
||||
Error("Json tracks is not an object.", json_obj);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
QJsonObject json_obj_tracks = json_tracks.toObject();
|
||||
|
@ -800,7 +810,7 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
!json_obj_tracks.contains("offset") ||
|
||||
!json_obj_tracks.contains("total") ||
|
||||
!json_obj_tracks.contains("items")) {
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist_requested);
|
||||
SongsFinishCheck(artist_id_requested, album_id_requested, limit_requested, offset_requested, 0, 0, album_artist, album);
|
||||
Error("Json songs object is missing values.", json_obj);
|
||||
return;
|
||||
}
|
||||
|
@ -811,20 +821,22 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
|
||||
if (offset != offset_requested) {
|
||||
Error(QString("Offset returned does not match offset requested! %1 != %2").arg(offset).arg(offset_requested));
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist);
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue json_value = ExtractItems(json_obj_tracks, error);
|
||||
if (!json_value.isArray()) {
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist);
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) {
|
||||
no_results_ = true;
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist);
|
||||
if ((type_ == QueryType_Songs || type_ == QueryType_SearchSongs) && offset_requested == 0) {
|
||||
no_results_ = true;
|
||||
}
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist, album);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -858,11 +870,11 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id_re
|
|||
songs_ << song;
|
||||
}
|
||||
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, songs_received, album_artist);
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, songs_received, album_artist, album);
|
||||
|
||||
}
|
||||
|
||||
void QobuzRequest::SongsFinishCheck(const qint64 artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist) {
|
||||
void QobuzRequest::SongsFinishCheck(const qint64 artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist, const QString &album) {
|
||||
|
||||
if (finished_) return;
|
||||
|
||||
|
@ -874,16 +886,13 @@ void QobuzRequest::SongsFinishCheck(const qint64 artist_id, const QString &album
|
|||
AddSongsRequest(offset_next);
|
||||
break;
|
||||
case QueryType_SearchSongs:
|
||||
// If artist_id and album_id isn't zero it means that it's a songs search where we fetch all albums too. So pass through.
|
||||
if (artist_id == 0 && album_id == 0) {
|
||||
AddSongsSearchRequest(offset_next);
|
||||
break;
|
||||
}
|
||||
AddSongsSearchRequest(offset_next);
|
||||
break;
|
||||
case QueryType_Artists:
|
||||
case QueryType_SearchArtists:
|
||||
case QueryType_Albums:
|
||||
case QueryType_SearchAlbums:
|
||||
AddAlbumSongsRequest(artist_id, album_id, album_artist, offset_next);
|
||||
AddAlbumSongsRequest(artist_id, album_id, album_artist, album, offset_next);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1055,10 +1064,10 @@ void QobuzRequest::GetAlbumCovers() {
|
|||
}
|
||||
FlushAlbumCoverRequests();
|
||||
|
||||
if (album_covers_requested_ == 1) emit UpdateStatus(tr("Retrieving album cover for %1 album...").arg(album_covers_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving album covers for %1 albums...").arg(album_covers_requested_));
|
||||
emit ProgressSetMaximum(album_covers_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (album_covers_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving album cover for %1 album...").arg(album_covers_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving album covers for %1 albums...").arg(album_covers_requested_));
|
||||
emit ProgressSetMaximum(query_id_, album_covers_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1115,7 +1124,7 @@ void QobuzRequest::AlbumCoverReceived(QNetworkReply *reply, const QUrl &cover_ur
|
|||
|
||||
if (finished_) return;
|
||||
|
||||
emit UpdateProgress(album_covers_received_);
|
||||
emit UpdateProgress(query_id_, album_covers_received_);
|
||||
|
||||
if (!album_covers_requests_sent_.contains(cover_url)) {
|
||||
AlbumCoverFinishCheck();
|
||||
|
@ -1225,27 +1234,18 @@ void QobuzRequest::FinishCheck() {
|
|||
album_covers_received_ >= album_covers_requested_
|
||||
) {
|
||||
finished_ = true;
|
||||
if (songs_.isEmpty()) {
|
||||
if (IsSearch()) {
|
||||
if (no_results_) emit ErrorSignal(search_id_, tr("No match"));
|
||||
else if (errors_.isEmpty()) emit ErrorSignal(search_id_, tr("Unknown error"));
|
||||
else emit ErrorSignal(search_id_, errors_);
|
||||
}
|
||||
else {
|
||||
if (no_results_) emit Results(songs_);
|
||||
else if (errors_.isEmpty()) emit ErrorSignal(tr("Unknown error"));
|
||||
else emit ErrorSignal(errors_);
|
||||
}
|
||||
if (no_results_ && songs_.isEmpty()) {
|
||||
if (IsSearch())
|
||||
emit Results(query_id_, SongList(), tr("No match."));
|
||||
else
|
||||
emit Results(query_id_, SongList(), QString());
|
||||
}
|
||||
else {
|
||||
if (IsSearch()) {
|
||||
emit SearchResults(search_id_, songs_);
|
||||
}
|
||||
else {
|
||||
emit Results(songs_);
|
||||
}
|
||||
if (songs_.isEmpty() && errors_.isEmpty())
|
||||
emit Results(query_id_, songs_, tr("Unknown error"));
|
||||
else
|
||||
emit Results(query_id_, songs_, errors_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,13 +62,10 @@ class QobuzRequest : public QobuzBaseRequest {
|
|||
void Login(const QString &username, const QString &password, const QString &token);
|
||||
void LoginSuccess();
|
||||
void LoginFailure(QString failure_reason);
|
||||
void Results(SongList songs);
|
||||
void SearchResults(int id, SongList songs);
|
||||
void ErrorSignal(QString message);
|
||||
void ErrorSignal(int id, QString message);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int max);
|
||||
void UpdateProgress(int max);
|
||||
void Results(const int id, const SongList &songs, const QString &error);
|
||||
void UpdateStatus(const int id, const QString &text);
|
||||
void ProgressSetMaximum(const int id, const int max);
|
||||
void UpdateProgress(const int id, const int max);
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl url, const Song::FileType, QString error = QString());
|
||||
|
||||
private slots:
|
||||
|
@ -79,10 +76,10 @@ class QobuzRequest : public QobuzBaseRequest {
|
|||
void AlbumsReceived(QNetworkReply *reply, const qint64 artist_id_requested, const int limit_requested, const int offset_requested);
|
||||
|
||||
void SongsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested);
|
||||
void SongsReceived(QNetworkReply *reply, const qint64 artist_id_requested, const QString &album_id_requested, const int limit_requested, const int offset_requested, const QString &album_artist_requested = QString());
|
||||
void SongsReceived(QNetworkReply *reply, const qint64 artist_id_requested, const QString &album_id_requested, const int limit_requested, const int offset_requested, const QString &album_artist_requested = QString(), const QString &album_requested = QString());
|
||||
|
||||
void ArtistAlbumsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const int offset_requested);
|
||||
void AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const QString &album_id, const int offset_requested, const QString &album_artist);
|
||||
void AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const QString &album_id, const int offset_requested, const QString &album_artist, const QString &album);
|
||||
void AlbumCoverReceived(QNetworkReply *reply, const QUrl &cover_url, const QString &filename);
|
||||
|
||||
private:
|
||||
|
@ -126,12 +123,12 @@ class QobuzRequest : public QobuzBaseRequest {
|
|||
|
||||
void ArtistsFinishCheck(const int limit = 0, const int offset = 0, const int artists_received = 0);
|
||||
void AlbumsFinishCheck(const qint64 artist_id, const int limit = 0, const int offset = 0, const int albums_total = 0, const int albums_received = 0);
|
||||
void SongsFinishCheck(const qint64 artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist);
|
||||
void SongsFinishCheck(const qint64 artist_id, const QString &album_id, const int limit, const int offset, const int songs_total, const int songs_received, const QString &album_artist, const QString &album);
|
||||
|
||||
void AddArtistAlbumsRequest(const qint64 artist_id, const int offset = 0);
|
||||
void FlushArtistAlbumsRequests();
|
||||
|
||||
void AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const int offset = 0);
|
||||
void AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const QString &album, const int offset = 0);
|
||||
void FlushAlbumSongsRequests();
|
||||
|
||||
int ParseSong(Song &song, const QJsonObject &json_obj, qint64 artist_id, QString album_id, QString album_artist, QString album, QUrl cover_url);
|
||||
|
@ -159,8 +156,7 @@ class QobuzRequest : public QobuzBaseRequest {
|
|||
NetworkAccessManager *network_;
|
||||
|
||||
QueryType type_;
|
||||
|
||||
int search_id_;
|
||||
int query_id_;
|
||||
QString search_text_;
|
||||
|
||||
bool finished_;
|
||||
|
|
|
@ -398,26 +398,29 @@ void QobuzService::GetArtists() {
|
|||
|
||||
artists_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Artists, this));
|
||||
|
||||
connect(artists_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(ArtistsErrorReceived(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(SongList)), SLOT(ArtistsResultsReceived(SongList)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(ArtistsUpdateStatus(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(ArtistsProgressSetMaximum(int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(ArtistsUpdateProgress(int)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(ArtistsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(ArtistsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(ArtistsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(ArtistsUpdateProgressReceived(const int, const int)));
|
||||
|
||||
artists_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::ArtistsResultsReceived(SongList songs) {
|
||||
|
||||
emit ArtistsResults(songs);
|
||||
|
||||
void QobuzService::ArtistsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit ArtistsResults(songs, error);
|
||||
}
|
||||
|
||||
void QobuzService::ArtistsErrorReceived(QString error) {
|
||||
void QobuzService::ArtistsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit ArtistsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit ArtistsError(error);
|
||||
void QobuzService::ArtistsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit ArtistsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void QobuzService::ArtistsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit ArtistsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
void QobuzService::ResetAlbumsRequest() {
|
||||
|
@ -434,26 +437,29 @@ void QobuzService::GetAlbums() {
|
|||
|
||||
ResetAlbumsRequest();
|
||||
albums_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Albums, this));
|
||||
connect(albums_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(AlbumsErrorReceived(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(SongList)), SLOT(AlbumsResultsReceived(SongList)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(AlbumsUpdateStatus(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(AlbumsProgressSetMaximum(int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(AlbumsUpdateProgress(int)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(AlbumsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(AlbumsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(AlbumsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(AlbumsUpdateProgressReceived(const int, const int)));
|
||||
|
||||
albums_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::AlbumsResultsReceived(SongList songs) {
|
||||
|
||||
emit AlbumsResults(songs);
|
||||
|
||||
void QobuzService::AlbumsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit AlbumsResults(songs, error);
|
||||
}
|
||||
|
||||
void QobuzService::AlbumsErrorReceived(QString error) {
|
||||
void QobuzService::AlbumsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit AlbumsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit AlbumsError(error);
|
||||
void QobuzService::AlbumsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit AlbumsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void QobuzService::AlbumsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit AlbumsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
void QobuzService::ResetSongsRequest() {
|
||||
|
@ -470,26 +476,29 @@ void QobuzService::GetSongs() {
|
|||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Songs, this));
|
||||
connect(songs_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(SongsErrorReceived(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(SongList)), SLOT(SongsResultsReceived(SongList)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SongsUpdateStatus(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SongsProgressSetMaximum(int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SongsUpdateProgress(int)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SongsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(SongsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(SongsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(SongsUpdateProgressReceived(const int, const int)));
|
||||
|
||||
songs_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::SongsResultsReceived(SongList songs) {
|
||||
|
||||
emit SongsResults(songs);
|
||||
|
||||
void QobuzService::SongsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit SongsResults(songs, error);
|
||||
}
|
||||
|
||||
void QobuzService::SongsErrorReceived(QString error) {
|
||||
void QobuzService::SongsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit SongsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit SongsError(error);
|
||||
void QobuzService::SongsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit SongsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void QobuzService::SongsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit SongsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
int QobuzService::Search(const QString &text, InternetSearch::SearchType type) {
|
||||
|
@ -514,7 +523,7 @@ int QobuzService::Search(const QString &text, InternetSearch::SearchType type) {
|
|||
void QobuzService::StartSearch() {
|
||||
|
||||
if (app_id_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SearchError(pending_search_id_, tr("Not authenticated."));
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Not authenticated."));
|
||||
next_pending_search_id_ = 1;
|
||||
ShowConfig();
|
||||
return;
|
||||
|
@ -551,17 +560,20 @@ void QobuzService::SendSearch() {
|
|||
|
||||
search_request_.reset(new QobuzRequest(this, url_handler_, network_, type, this));
|
||||
|
||||
connect(search_request_.get(), SIGNAL(SearchResults(int, SongList)), SIGNAL(SearchResults(int, SongList)));
|
||||
connect(search_request_.get(), SIGNAL(ErrorSignal(int, QString)), SIGNAL(SearchError(int, QString)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SearchUpdateStatus(QString)));
|
||||
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SearchProgressSetMaximum(int)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SearchUpdateProgress(int)));
|
||||
connect(search_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SearchResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SIGNAL(SearchUpdateStatus(const int, const QString&)));
|
||||
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SIGNAL(SearchProgressSetMaximum(const int, const int)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SIGNAL(SearchUpdateProgress(const int, const int)));
|
||||
|
||||
search_request_->Search(search_id_, search_text_);
|
||||
search_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::SearchResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit SearchResults(id, songs, error);
|
||||
}
|
||||
|
||||
void QobuzService::GetStreamURL(const QUrl &url) {
|
||||
|
||||
QobuzStreamURLRequest *stream_url_req = new QobuzStreamURLRequest(this, network_, url, this);
|
||||
|
|
|
@ -127,12 +127,19 @@ class QobuzService : public InternetService {
|
|||
void HandleAuthReply(QNetworkReply *reply);
|
||||
void ResetLoginAttempts();
|
||||
void StartSearch();
|
||||
void ArtistsResultsReceived(SongList songs);
|
||||
void ArtistsErrorReceived(QString error);
|
||||
void AlbumsResultsReceived(SongList songs);
|
||||
void AlbumsErrorReceived(QString error);
|
||||
void SongsResultsReceived(SongList songs);
|
||||
void SongsErrorReceived(QString error);
|
||||
void ArtistsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void AlbumsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void SongsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void SearchResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void ArtistsUpdateStatusReceived(const int id, const QString &text);
|
||||
void AlbumsUpdateStatusReceived(const int id, const QString &text);
|
||||
void SongsUpdateStatusReceived(const int id, const QString &text);
|
||||
void ArtistsProgressSetMaximumReceived(const int id, const int max);
|
||||
void AlbumsProgressSetMaximumReceived(const int id, const int max);
|
||||
void SongsProgressSetMaximumReceived(const int id, const int max);
|
||||
void ArtistsUpdateProgressReceived(const int id, const int progress);
|
||||
void AlbumsUpdateProgressReceived(const int id, const int progress);
|
||||
void SongsUpdateProgressReceived(const int id, const int progress);
|
||||
void HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private:
|
||||
|
|
|
@ -722,15 +722,8 @@ void SubsonicRequest::FinishCheck() {
|
|||
album_covers_received_ >= album_covers_requested_
|
||||
) {
|
||||
finished_ = true;
|
||||
if (songs_.isEmpty()) {
|
||||
if (no_results_) emit Results(songs_);
|
||||
else if (errors_.isEmpty()) emit ErrorSignal(tr("Unknown error"));
|
||||
else emit ErrorSignal(errors_);
|
||||
}
|
||||
else {
|
||||
emit Results(songs_);
|
||||
}
|
||||
|
||||
if (no_results_) emit Results(SongList(), QString());
|
||||
else emit Results(songs_, errors_);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,12 +58,10 @@ class SubsonicRequest : public SubsonicBaseRequest {
|
|||
void Reset();
|
||||
|
||||
signals:
|
||||
void Results(SongList songs);
|
||||
void ErrorSignal(QString message);
|
||||
void ErrorSignal(int id, QString message);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int max);
|
||||
void UpdateProgress(int max);
|
||||
void Results(const SongList &songs, const QString &error);
|
||||
void UpdateStatus(const QString &text);
|
||||
void ProgressSetMaximum(const int max);
|
||||
void UpdateProgress(const int max);
|
||||
|
||||
private slots:
|
||||
|
||||
|
|
|
@ -321,25 +321,18 @@ void SubsonicService::GetSongs() {
|
|||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new SubsonicRequest(this, url_handler_, network_, this));
|
||||
connect(songs_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(SongsErrorReceived(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(SongList)), SLOT(SongsResultsReceived(SongList)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SongsUpdateStatus(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SongsProgressSetMaximum(int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SongsUpdateProgress(int)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const SongList&, const QString&)), SLOT(SongsResultsReceived(const SongList&, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(const QString&)), SIGNAL(SongsUpdateStatus(const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(const int)), SIGNAL(SongsProgressSetMaximum(const int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(const int)), SIGNAL(SongsUpdateProgress(const int)));
|
||||
|
||||
songs_request_->GetAlbums();
|
||||
|
||||
}
|
||||
|
||||
void SubsonicService::SongsResultsReceived(SongList songs) {
|
||||
void SubsonicService::SongsResultsReceived(const SongList &songs, const QString &error) {
|
||||
|
||||
emit SongsResults(songs);
|
||||
|
||||
}
|
||||
|
||||
void SubsonicService::SongsErrorReceived(QString error) {
|
||||
|
||||
emit SongsError(error);
|
||||
emit SongsResults(songs, error);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,7 @@ class SubsonicService : public InternetService {
|
|||
|
||||
private slots:
|
||||
void HandlePingReply(QNetworkReply *reply);
|
||||
void SongsResultsReceived(SongList songs);
|
||||
void SongsErrorReceived(QString error);
|
||||
void SongsResultsReceived(const SongList &songs, const QString &error);
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
|
|
|
@ -90,8 +90,6 @@ class TidalBaseRequest : public QObject {
|
|||
int artistssearchlimit() { return service_->artistssearchlimit(); }
|
||||
int albumssearchlimit() { return service_->albumssearchlimit(); }
|
||||
int songssearchlimit() { return service_->songssearchlimit(); }
|
||||
bool fetchalbums() { return service_->fetchalbums(); }
|
||||
QString coversize() { return service_->coversize(); }
|
||||
|
||||
QString access_token() { return service_->access_token(); }
|
||||
QString session_id() { return service_->session_id(); }
|
||||
|
|
|
@ -53,7 +53,9 @@ TidalRequest::TidalRequest(TidalService *service, TidalUrlHandler *url_handler,
|
|||
url_handler_(url_handler),
|
||||
network_(network),
|
||||
type_(type),
|
||||
search_id_(-1),
|
||||
fetchalbums_(service->fetchalbums()),
|
||||
coversize_(service_->coversize()),
|
||||
query_id_(-1),
|
||||
finished_(false),
|
||||
artists_requests_active_(0),
|
||||
artists_total_(0),
|
||||
|
@ -100,6 +102,7 @@ void TidalRequest::LoginComplete(bool success, QString error) {
|
|||
void TidalRequest::Process() {
|
||||
|
||||
if (!service_->authenticated()) {
|
||||
emit UpdateStatus(query_id_, tr("Authenticating..."));
|
||||
need_login_ = true;
|
||||
service_->TryLogin();
|
||||
return;
|
||||
|
@ -131,15 +134,15 @@ void TidalRequest::Process() {
|
|||
|
||||
}
|
||||
|
||||
void TidalRequest::Search(const int search_id, const QString &search_text) {
|
||||
search_id_ = search_id;
|
||||
void TidalRequest::Search(const int query_id, const QString &search_text) {
|
||||
query_id_ = query_id;
|
||||
search_text_ = search_text;
|
||||
}
|
||||
|
||||
void TidalRequest::GetArtists() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving artists..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving artists..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddArtistsRequest();
|
||||
|
||||
}
|
||||
|
@ -180,8 +183,8 @@ void TidalRequest::FlushArtistsRequests() {
|
|||
|
||||
void TidalRequest::GetAlbums() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving albums..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving albums..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddAlbumsRequest();
|
||||
|
||||
}
|
||||
|
@ -222,8 +225,8 @@ void TidalRequest::FlushAlbumsRequests() {
|
|||
|
||||
void TidalRequest::GetSongs() {
|
||||
|
||||
emit UpdateStatus(tr("Retrieving songs..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Retrieving songs..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddSongsRequest();
|
||||
|
||||
}
|
||||
|
@ -264,8 +267,8 @@ void TidalRequest::FlushSongsRequests() {
|
|||
|
||||
void TidalRequest::ArtistsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddArtistsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -278,8 +281,8 @@ void TidalRequest::AddArtistsSearchRequest(const int offset) {
|
|||
|
||||
void TidalRequest::AlbumsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddAlbumsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -292,8 +295,8 @@ void TidalRequest::AddAlbumsSearchRequest(const int offset) {
|
|||
|
||||
void TidalRequest::SongsSearch() {
|
||||
|
||||
emit UpdateStatus(tr("Searching..."));
|
||||
emit UpdateProgress(0);
|
||||
emit UpdateStatus(query_id_, tr("Searching..."));
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
AddSongsSearchRequest();
|
||||
|
||||
}
|
||||
|
@ -352,11 +355,11 @@ void TidalRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
}
|
||||
|
||||
if (offset_requested == 0) {
|
||||
emit ProgressSetMaximum(artists_total_);
|
||||
emit UpdateProgress(artists_received_);
|
||||
emit ProgressSetMaximum(query_id_, artists_total_);
|
||||
emit UpdateProgress(query_id_, artists_received_);
|
||||
}
|
||||
|
||||
QJsonValue json_value = ExtractItems(data, error);
|
||||
QJsonValue json_value = ExtractItems(json_obj, error);
|
||||
if (!json_value.isArray()) {
|
||||
ArtistsFinishCheck();
|
||||
return;
|
||||
|
@ -364,7 +367,7 @@ void TidalRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) { // Empty array means no results
|
||||
no_results_ = true;
|
||||
if (offset_requested == 0) no_results_ = true;
|
||||
ArtistsFinishCheck();
|
||||
return;
|
||||
}
|
||||
|
@ -401,7 +404,7 @@ void TidalRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
|
|||
}
|
||||
artists_received_ += artists_received;
|
||||
|
||||
if (offset_requested != 0) emit UpdateProgress(artists_received_);
|
||||
if (offset_requested != 0) emit UpdateProgress(query_id_, artists_received_);
|
||||
|
||||
ArtistsFinishCheck(limit_requested, offset, artists_received);
|
||||
|
||||
|
@ -431,10 +434,10 @@ void TidalRequest::ArtistsFinishCheck(const int limit, const int offset, const i
|
|||
artist_albums_requests_pending_.clear();
|
||||
|
||||
if (artist_albums_requested_ > 0) {
|
||||
if (artist_albums_requested_ == 1) emit UpdateStatus(tr("Retrieving albums for %1 artist...").arg(artist_albums_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving albums for %1 artists...").arg(artist_albums_requested_));
|
||||
emit ProgressSetMaximum(artist_albums_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (artist_albums_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving albums for %1 artist...").arg(artist_albums_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving albums for %1 artists...").arg(artist_albums_requested_));
|
||||
emit ProgressSetMaximum(query_id_, artist_albums_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -479,7 +482,7 @@ void TidalRequest::ArtistAlbumsReplyReceived(QNetworkReply *reply, const qint64
|
|||
|
||||
--artist_albums_requests_active_;
|
||||
++artist_albums_received_;
|
||||
emit UpdateProgress(artist_albums_received_);
|
||||
emit UpdateProgress(query_id_, artist_albums_received_);
|
||||
AlbumsReceived(reply, artist_id, 0, offset_requested, false);
|
||||
if (!artist_albums_requests_queue_.isEmpty() && artist_albums_requests_active_ < kMaxConcurrentArtistAlbumsRequests) FlushArtistAlbumsRequests();
|
||||
|
||||
|
@ -529,7 +532,9 @@ void TidalRequest::AlbumsReceived(QNetworkReply *reply, const qint64 artist_id_r
|
|||
}
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) {
|
||||
no_results_ = true;
|
||||
if ((type_ == QueryType_Albums || type_ == QueryType_SearchAlbums || (type_ == QueryType_SearchSongs && fetchalbums_)) && offset_requested == 0) {
|
||||
no_results_ = true;
|
||||
}
|
||||
AlbumsFinishCheck(artist_id_requested);
|
||||
return;
|
||||
}
|
||||
|
@ -667,10 +672,10 @@ void TidalRequest::AlbumsFinishCheck(const qint64 artist_id, const int limit, co
|
|||
album_songs_requests_pending_.clear();
|
||||
|
||||
if (album_songs_requested_ > 0) {
|
||||
if (album_songs_requested_ == 1) emit UpdateStatus(tr("Retrieving songs for %1 album...").arg(album_songs_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving songs for %1 albums...").arg(album_songs_requested_));
|
||||
emit ProgressSetMaximum(album_songs_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (album_songs_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving songs for %1 album...").arg(album_songs_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving songs for %1 albums...").arg(album_songs_requested_));
|
||||
emit ProgressSetMaximum(query_id_, album_songs_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -681,7 +686,7 @@ void TidalRequest::AlbumsFinishCheck(const qint64 artist_id, const int limit, co
|
|||
void TidalRequest::SongsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested) {
|
||||
|
||||
--songs_requests_active_;
|
||||
if (type_ == QueryType_SearchSongs && service_->fetchalbums()) {
|
||||
if (type_ == QueryType_SearchSongs && fetchalbums_) {
|
||||
AlbumsReceived(reply, 0, limit_requested, offset_requested, (offset_requested == 0));
|
||||
}
|
||||
else {
|
||||
|
@ -723,7 +728,7 @@ void TidalRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 ar
|
|||
--album_songs_requests_active_;
|
||||
++album_songs_received_;
|
||||
if (offset_requested == 0) {
|
||||
emit UpdateProgress(album_songs_received_);
|
||||
emit UpdateProgress(query_id_, album_songs_received_);
|
||||
}
|
||||
SongsReceived(reply, artist_id, album_id, 0, offset_requested, false, album_artist);
|
||||
|
||||
|
@ -766,7 +771,7 @@ void TidalRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id, c
|
|||
return;
|
||||
}
|
||||
|
||||
QJsonValue json_value = ExtractItems(data, error);
|
||||
QJsonValue json_value = ExtractItems(json_obj, error);
|
||||
if (!json_value.isArray()) {
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist);
|
||||
return;
|
||||
|
@ -774,7 +779,9 @@ void TidalRequest::SongsReceived(QNetworkReply *reply, const qint64 artist_id, c
|
|||
|
||||
QJsonArray json_items = json_value.toArray();
|
||||
if (json_items.isEmpty()) {
|
||||
no_results_ = true;
|
||||
if ((type_ == QueryType_Songs || type_ == QueryType_SearchSongs) && offset_requested == 0) {
|
||||
no_results_ = true;
|
||||
}
|
||||
SongsFinishCheck(artist_id, album_id, limit_requested, offset_requested, songs_total, 0, album_artist);
|
||||
return;
|
||||
}
|
||||
|
@ -960,7 +967,7 @@ int TidalRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qint6
|
|||
}
|
||||
|
||||
cover = cover.replace("-", "/");
|
||||
QUrl cover_url (QString("%1/images/%2/%3.jpg").arg(kResourcesUrl).arg(cover).arg(service_->coversize()));
|
||||
QUrl cover_url (QString("%1/images/%2/%3.jpg").arg(kResourcesUrl).arg(cover).arg(coversize_));
|
||||
|
||||
title.remove(Song::kTitleRemoveMisc);
|
||||
|
||||
|
@ -998,10 +1005,10 @@ void TidalRequest::GetAlbumCovers() {
|
|||
}
|
||||
FlushAlbumCoverRequests();
|
||||
|
||||
if (album_covers_requested_ == 1) emit UpdateStatus(tr("Retrieving album cover for %1 album...").arg(album_covers_requested_));
|
||||
else emit UpdateStatus(tr("Retrieving album covers for %1 albums...").arg(album_covers_requested_));
|
||||
emit ProgressSetMaximum(album_covers_requested_);
|
||||
emit UpdateProgress(0);
|
||||
if (album_covers_requested_ == 1) emit UpdateStatus(query_id_, tr("Retrieving album cover for %1 album...").arg(album_covers_requested_));
|
||||
else emit UpdateStatus(query_id_, tr("Retrieving album covers for %1 albums...").arg(album_covers_requested_));
|
||||
emit ProgressSetMaximum(query_id_, album_covers_requested_);
|
||||
emit UpdateProgress(query_id_, 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1062,7 @@ void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const QString &album
|
|||
|
||||
if (finished_) return;
|
||||
|
||||
emit UpdateProgress(album_covers_received_);
|
||||
emit UpdateProgress(query_id_, album_covers_received_);
|
||||
|
||||
if (!album_covers_requests_sent_.contains(album_id)) {
|
||||
AlbumCoverFinishCheck();
|
||||
|
@ -1137,27 +1144,18 @@ void TidalRequest::FinishCheck() {
|
|||
album_covers_received_ >= album_covers_requested_
|
||||
) {
|
||||
finished_ = true;
|
||||
if (songs_.isEmpty()) {
|
||||
if (IsSearch()) {
|
||||
if (no_results_) emit ErrorSignal(search_id_, tr("No match"));
|
||||
else if (errors_.isEmpty()) emit ErrorSignal(search_id_, tr("Unknown error"));
|
||||
else emit ErrorSignal(search_id_, errors_);
|
||||
}
|
||||
else {
|
||||
if (no_results_) emit Results(songs_);
|
||||
else if (errors_.isEmpty()) emit ErrorSignal(tr("Unknown error"));
|
||||
else emit ErrorSignal(errors_);
|
||||
}
|
||||
if (no_results_ && songs_.isEmpty()) {
|
||||
if (IsSearch())
|
||||
emit Results(query_id_, SongList(), tr("No match."));
|
||||
else
|
||||
emit Results(query_id_, SongList(), QString());
|
||||
}
|
||||
else {
|
||||
if (IsSearch()) {
|
||||
emit SearchResults(search_id_, songs_);
|
||||
}
|
||||
else {
|
||||
emit Results(songs_);
|
||||
}
|
||||
if (songs_.isEmpty() && errors_.isEmpty())
|
||||
emit Results(query_id_, songs_, tr("Unknown error"));
|
||||
else
|
||||
emit Results(query_id_, songs_, errors_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,13 +63,10 @@ class TidalRequest : public TidalBaseRequest {
|
|||
void Login(const QString &username, const QString &password, const QString &token);
|
||||
void LoginSuccess();
|
||||
void LoginFailure(QString failure_reason);
|
||||
void Results(SongList songs);
|
||||
void SearchResults(int id, SongList songs);
|
||||
void ErrorSignal(QString message);
|
||||
void ErrorSignal(int id, QString message);
|
||||
void UpdateStatus(QString text);
|
||||
void ProgressSetMaximum(int max);
|
||||
void UpdateProgress(int max);
|
||||
void Results(const int id, const SongList &songs, const QString &error);
|
||||
void UpdateStatus(const int id, const QString &text);
|
||||
void ProgressSetMaximum(const int id, const int max);
|
||||
void UpdateProgress(const int id, const int max);
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl url, const Song::FileType, QString error = QString());
|
||||
|
||||
private slots:
|
||||
|
@ -160,8 +157,10 @@ class TidalRequest : public TidalBaseRequest {
|
|||
NetworkAccessManager *network_;
|
||||
|
||||
QueryType type_;
|
||||
bool fetchalbums_;
|
||||
QString coversize_;
|
||||
|
||||
int search_id_;
|
||||
int query_id_;
|
||||
QString search_text_;
|
||||
|
||||
bool finished_;
|
||||
|
|
|
@ -452,8 +452,6 @@ void TidalService::SendLogin() {
|
|||
|
||||
void TidalService::SendLogin(const QString &username, const QString &password, const QString &token) {
|
||||
|
||||
emit UpdateStatus(tr("Authenticating..."));
|
||||
|
||||
login_sent_ = true;
|
||||
++login_attempts_;
|
||||
if (timer_login_attempt_->isActive()) timer_login_attempt_->stop();
|
||||
|
@ -639,27 +637,30 @@ void TidalService::GetArtists() {
|
|||
|
||||
artists_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Artists, this));
|
||||
|
||||
connect(artists_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(ArtistsErrorReceived(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(SongList)), SLOT(ArtistsResultsReceived(SongList)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(ArtistsUpdateStatus(QString)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(ArtistsProgressSetMaximum(int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(ArtistsUpdateProgress(int)));
|
||||
connect(artists_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(ArtistsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(ArtistsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(ArtistsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(ArtistsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), artists_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
artists_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::ArtistsResultsReceived(SongList songs) {
|
||||
|
||||
emit ArtistsResults(songs);
|
||||
|
||||
void TidalService::ArtistsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit ArtistsResults(songs, error);
|
||||
}
|
||||
|
||||
void TidalService::ArtistsErrorReceived(QString error) {
|
||||
void TidalService::ArtistsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit ArtistsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit ArtistsError(error);
|
||||
void TidalService::ArtistsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit ArtistsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void TidalService::ArtistsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit ArtistsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
void TidalService::ResetAlbumsRequest() {
|
||||
|
@ -676,27 +677,30 @@ void TidalService::GetAlbums() {
|
|||
|
||||
ResetAlbumsRequest();
|
||||
albums_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Albums, this));
|
||||
connect(albums_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(AlbumsErrorReceived(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(SongList)), SLOT(AlbumsResultsReceived(SongList)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(AlbumsUpdateStatus(QString)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(AlbumsProgressSetMaximum(int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(AlbumsUpdateProgress(int)));
|
||||
connect(albums_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(AlbumsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(AlbumsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(AlbumsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(AlbumsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), albums_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
albums_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::AlbumsResultsReceived(SongList songs) {
|
||||
|
||||
emit AlbumsResults(songs);
|
||||
|
||||
void TidalService::AlbumsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit AlbumsResults(songs, error);
|
||||
}
|
||||
|
||||
void TidalService::AlbumsErrorReceived(QString error) {
|
||||
void TidalService::AlbumsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit AlbumsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit AlbumsError(error);
|
||||
void TidalService::AlbumsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit AlbumsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void TidalService::AlbumsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit AlbumsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
void TidalService::ResetSongsRequest() {
|
||||
|
@ -713,27 +717,30 @@ void TidalService::GetSongs() {
|
|||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Songs, this));
|
||||
connect(songs_request_.get(), SIGNAL(ErrorSignal(QString)), SLOT(SongsErrorReceived(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(SongList)), SLOT(SongsResultsReceived(SongList)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SongsUpdateStatus(QString)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SongsProgressSetMaximum(int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SongsUpdateProgress(int)));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SongsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(SongsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(SongsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(SongsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), songs_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
songs_request_->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::SongsResultsReceived(SongList songs) {
|
||||
|
||||
emit SongsResults(songs);
|
||||
|
||||
void TidalService::SongsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit SongsResults(songs, error);
|
||||
}
|
||||
|
||||
void TidalService::SongsErrorReceived(QString error) {
|
||||
void TidalService::SongsUpdateStatusReceived(const int id, const QString &text) {
|
||||
emit SongsUpdateStatus(text);
|
||||
}
|
||||
|
||||
emit SongsError(error);
|
||||
void TidalService::SongsProgressSetMaximumReceived(const int id, const int max) {
|
||||
emit SongsProgressSetMaximum(max);
|
||||
}
|
||||
|
||||
void TidalService::SongsUpdateProgressReceived(const int id, const int progress) {
|
||||
emit SongsUpdateProgress(progress);
|
||||
}
|
||||
|
||||
int TidalService::Search(const QString &text, InternetSearch::SearchType type) {
|
||||
|
@ -758,7 +765,7 @@ int TidalService::Search(const QString &text, InternetSearch::SearchType type) {
|
|||
void TidalService::StartSearch() {
|
||||
|
||||
if ((oauth_ && !authenticated()) || api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SearchError(pending_search_id_, tr("Not authenticated."));
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Not authenticated."));
|
||||
next_pending_search_id_ = 1;
|
||||
ShowConfig();
|
||||
return;
|
||||
|
@ -795,11 +802,10 @@ void TidalService::SendSearch() {
|
|||
|
||||
search_request_.reset(new TidalRequest(this, url_handler_, network_, type, this));
|
||||
|
||||
connect(search_request_.get(), SIGNAL(SearchResults(int, SongList)), SIGNAL(SearchResults(int, SongList)));
|
||||
connect(search_request_.get(), SIGNAL(ErrorSignal(int, QString)), SIGNAL(SearchError(int, QString)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateStatus(QString)), SIGNAL(SearchUpdateStatus(QString)));
|
||||
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(int)), SIGNAL(SearchProgressSetMaximum(int)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateProgress(int)), SIGNAL(SearchUpdateProgress(int)));
|
||||
connect(search_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SearchResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SIGNAL(SearchUpdateStatus(const int, const QString&)));
|
||||
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SIGNAL(SearchProgressSetMaximum(const int, const int)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SIGNAL(SearchUpdateProgress(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), search_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
|
||||
search_request_->Search(search_id_, search_text_);
|
||||
|
@ -807,6 +813,10 @@ void TidalService::SendSearch() {
|
|||
|
||||
}
|
||||
|
||||
void TidalService::SearchResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
emit SearchResults(id, songs, error);
|
||||
}
|
||||
|
||||
void TidalService::GetStreamURL(const QUrl &url) {
|
||||
|
||||
TidalStreamURLRequest *stream_url_req = new TidalStreamURLRequest(this, network_, url, this);
|
||||
|
|
|
@ -137,12 +137,19 @@ class TidalService : public InternetService {
|
|||
void HandleAuthReply(QNetworkReply *reply);
|
||||
void ResetLoginAttempts();
|
||||
void StartSearch();
|
||||
void ArtistsResultsReceived(SongList songs);
|
||||
void ArtistsErrorReceived(QString error);
|
||||
void AlbumsResultsReceived(SongList songs);
|
||||
void AlbumsErrorReceived(QString error);
|
||||
void SongsResultsReceived(SongList songs);
|
||||
void SongsErrorReceived(QString error);
|
||||
void ArtistsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void AlbumsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void SongsResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void SearchResultsReceived(const int id, const SongList &songs, const QString &error);
|
||||
void ArtistsUpdateStatusReceived(const int id, const QString &text);
|
||||
void AlbumsUpdateStatusReceived(const int id, const QString &text);
|
||||
void SongsUpdateStatusReceived(const int id, const QString &text);
|
||||
void ArtistsProgressSetMaximumReceived(const int id, const int max);
|
||||
void AlbumsProgressSetMaximumReceived(const int id, const int max);
|
||||
void SongsProgressSetMaximumReceived(const int id, const int max);
|
||||
void ArtistsUpdateProgressReceived(const int id, const int progress);
|
||||
void AlbumsUpdateProgressReceived(const int id, const int progress);
|
||||
void SongsUpdateProgressReceived(const int id, const int progress);
|
||||
void HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue