Add new method for updating songs based on song ID
Show status updating database. Fixes #750
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <QMap>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -66,6 +67,24 @@ QString QobuzFavoriteRequest::FavoriteText(const FavoriteType type) {
|
||||
|
||||
}
|
||||
|
||||
QString QobuzFavoriteRequest::FavoriteMethod(const FavoriteType type) {
|
||||
|
||||
switch (type) {
|
||||
case FavoriteType_Artists:
|
||||
return "artist_ids";
|
||||
break;
|
||||
case FavoriteType_Albums:
|
||||
return "album_ids";
|
||||
break;
|
||||
case FavoriteType_Songs:
|
||||
return "track_ids";
|
||||
break;
|
||||
}
|
||||
|
||||
return QString();
|
||||
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::AddArtists(const SongList &songs) {
|
||||
AddFavorites(FavoriteType_Artists, songs);
|
||||
}
|
||||
@@ -74,27 +93,12 @@ void QobuzFavoriteRequest::AddAlbums(const SongList &songs) {
|
||||
AddFavorites(FavoriteType_Albums, songs);
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::AddSongs(const SongList &songs) {
|
||||
AddFavorites(FavoriteType_Songs, songs);
|
||||
void QobuzFavoriteRequest::AddSongs(const SongMap &songs) {
|
||||
AddFavoritesRequest(FavoriteType_Songs, songs.keys(), songs.values());
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::AddFavorites(const FavoriteType type, const SongList &songs) {
|
||||
|
||||
if (songs.isEmpty()) return;
|
||||
|
||||
QString text;
|
||||
switch (type) {
|
||||
case FavoriteType_Artists:
|
||||
text = "artist_ids";
|
||||
break;
|
||||
case FavoriteType_Albums:
|
||||
text = "album_ids";
|
||||
break;
|
||||
case FavoriteType_Songs:
|
||||
text = "track_ids";
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList ids_list;
|
||||
for (const Song &song : songs) {
|
||||
QString id;
|
||||
@@ -112,18 +116,22 @@ void QobuzFavoriteRequest::AddFavorites(const FavoriteType type, const SongList
|
||||
id = song.song_id();
|
||||
break;
|
||||
}
|
||||
if (id.isEmpty()) continue;
|
||||
if (!ids_list.contains(id)) {
|
||||
if (!id.isEmpty() && !ids_list.contains(id)) {
|
||||
ids_list << id;
|
||||
}
|
||||
}
|
||||
|
||||
if (ids_list.isEmpty()) return;
|
||||
|
||||
QString ids = ids_list.join(',');
|
||||
AddFavoritesRequest(type, ids_list, songs);
|
||||
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::AddFavoritesRequest(const FavoriteType type, const QStringList &ids_list, const SongList &songs) {
|
||||
|
||||
ParamList params = ParamList() << Param("app_id", app_id())
|
||||
<< Param("user_auth_token", user_auth_token())
|
||||
<< Param(text, ids);
|
||||
<< Param(FavoriteMethod(type), ids_list.join(','));
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
@@ -180,23 +188,12 @@ void QobuzFavoriteRequest::RemoveSongs(const SongList &songs) {
|
||||
RemoveFavorites(FavoriteType_Songs, songs);
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::RemoveSongs(const SongMap &songs) {
|
||||
RemoveFavoritesRequest(FavoriteType_Songs, songs.keys(), songs.values());
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::RemoveFavorites(const FavoriteType type, const SongList &songs) {
|
||||
|
||||
if (songs.isEmpty()) return;
|
||||
|
||||
QString text;
|
||||
switch (type) {
|
||||
case FavoriteType_Artists:
|
||||
text = "artist_ids";
|
||||
break;
|
||||
case FavoriteType_Albums:
|
||||
text = "album_ids";
|
||||
break;
|
||||
case FavoriteType_Songs:
|
||||
text = "track_ids";
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList ids_list;
|
||||
for (const Song &song : songs) {
|
||||
QString id;
|
||||
@@ -214,18 +211,22 @@ void QobuzFavoriteRequest::RemoveFavorites(const FavoriteType type, const SongLi
|
||||
id = song.song_id();
|
||||
break;
|
||||
}
|
||||
if (id.isEmpty()) continue;
|
||||
if (!ids_list.contains(id)) {
|
||||
if (!id.isEmpty() && !ids_list.contains(id)) {
|
||||
ids_list << id;
|
||||
}
|
||||
}
|
||||
|
||||
if (ids_list.isEmpty()) return;
|
||||
|
||||
QString ids = ids_list.join(',');
|
||||
RemoveFavoritesRequest(type, ids_list, songs);
|
||||
|
||||
}
|
||||
|
||||
void QobuzFavoriteRequest::RemoveFavoritesRequest(const FavoriteType type, const QStringList &ids_list, const SongList &songs) {
|
||||
|
||||
ParamList params = ParamList() << Param("app_id", app_id())
|
||||
<< Param("user_auth_token", user_auth_token())
|
||||
<< Param(text, ids);
|
||||
<< Param(FavoriteMethod(type), ids_list.join(','));
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
@@ -62,16 +63,20 @@ class QobuzFavoriteRequest : public QobuzBaseRequest {
|
||||
public slots:
|
||||
void AddArtists(const SongList &songs);
|
||||
void AddAlbums(const SongList &songs);
|
||||
void AddSongs(const SongList &songs);
|
||||
void AddSongs(const SongMap &songs);
|
||||
void RemoveArtists(const SongList &songs);
|
||||
void RemoveAlbums(const SongList &songs);
|
||||
void RemoveSongs(const SongList &songs);
|
||||
void RemoveSongs(const SongMap &songs);
|
||||
|
||||
private:
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
static QString FavoriteText(const FavoriteType type);
|
||||
static QString FavoriteMethod(const FavoriteType type);
|
||||
void AddFavorites(const FavoriteType type, const SongList &songs);
|
||||
void AddFavoritesRequest(const FavoriteType type, const QStringList &ids_list, const SongList &songs);
|
||||
void RemoveFavorites(const FavoriteType type, const SongList &songs);
|
||||
void RemoveFavoritesRequest(const FavoriteType type, const QStringList &ids_list, const SongList &songs);
|
||||
|
||||
QobuzService *service_;
|
||||
NetworkAccessManager *network_;
|
||||
|
||||
@@ -1315,15 +1315,15 @@ void QobuzRequest::FinishCheck() {
|
||||
finished_ = true;
|
||||
if (no_results_ && songs_.isEmpty()) {
|
||||
if (IsSearch())
|
||||
emit Results(query_id_, SongList(), tr("No match."));
|
||||
emit Results(query_id_, SongMap(), tr("No match."));
|
||||
else
|
||||
emit Results(query_id_, SongList(), QString());
|
||||
emit Results(query_id_, SongMap(), QString());
|
||||
}
|
||||
else {
|
||||
if (songs_.isEmpty() && errors_.isEmpty())
|
||||
emit Results(query_id_, songs_.values(), tr("Unknown error"));
|
||||
emit Results(query_id_, songs_, tr("Unknown error"));
|
||||
else
|
||||
emit Results(query_id_, songs_.values(), ErrorsToHTML(errors_));
|
||||
emit Results(query_id_, songs_, ErrorsToHTML(errors_));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class QobuzRequest : public QobuzBaseRequest {
|
||||
signals:
|
||||
void LoginSuccess();
|
||||
void LoginFailure(QString failure_reason);
|
||||
void Results(int id, SongList songs, QString error);
|
||||
void Results(int id, SongMap songs, QString error);
|
||||
void UpdateStatus(int id, QString text);
|
||||
void ProgressSetMaximum(int id, int max);
|
||||
void UpdateProgress(int id, int max);
|
||||
@@ -191,7 +191,7 @@ class QobuzRequest : public QobuzBaseRequest {
|
||||
int album_covers_requested_;
|
||||
int album_covers_received_;
|
||||
|
||||
QMap<QString, Song> songs_;
|
||||
SongMap songs_;
|
||||
QStringList errors_;
|
||||
bool no_results_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
@@ -111,15 +112,15 @@ QobuzService::QobuzService(Application *app, QObject *parent)
|
||||
|
||||
artists_collection_backend_ = new CollectionBackend();
|
||||
artists_collection_backend_->moveToThread(app_->database()->thread());
|
||||
artists_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kArtistsSongsTable, kArtistsSongsFtsTable);
|
||||
artists_collection_backend_->Init(app_->database(), app->task_manager(), Song::Source_Qobuz, kArtistsSongsTable, kArtistsSongsFtsTable);
|
||||
|
||||
albums_collection_backend_ = new CollectionBackend();
|
||||
albums_collection_backend_->moveToThread(app_->database()->thread());
|
||||
albums_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kAlbumsSongsTable, kAlbumsSongsFtsTable);
|
||||
albums_collection_backend_->Init(app_->database(), app->task_manager(), Song::Source_Qobuz, kAlbumsSongsTable, kAlbumsSongsFtsTable);
|
||||
|
||||
songs_collection_backend_ = new CollectionBackend();
|
||||
songs_collection_backend_->moveToThread(app_->database()->thread());
|
||||
songs_collection_backend_->Init(app_->database(), Song::Source_Qobuz, kSongsTable, kSongsFtsTable);
|
||||
songs_collection_backend_->Init(app_->database(), app->task_manager(), Song::Source_Qobuz, kSongsTable, kSongsFtsTable);
|
||||
|
||||
artists_collection_model_ = new CollectionModel(artists_collection_backend_, app_, this);
|
||||
albums_collection_model_ = new CollectionModel(albums_collection_backend_, app_, this);
|
||||
@@ -160,7 +161,8 @@ QobuzService::QobuzService(Application *app, QObject *parent)
|
||||
|
||||
QObject::connect(this, &QobuzService::RemoveArtists, favorite_request_, &QobuzFavoriteRequest::RemoveArtists);
|
||||
QObject::connect(this, &QobuzService::RemoveAlbums, favorite_request_, &QobuzFavoriteRequest::RemoveAlbums);
|
||||
QObject::connect(this, &QobuzService::RemoveSongs, favorite_request_, &QobuzFavoriteRequest::RemoveSongs);
|
||||
QObject::connect(this, QOverload<SongList>::of(&QobuzService::RemoveSongs), favorite_request_, QOverload<const SongList&>::of(&QobuzFavoriteRequest::RemoveSongs));
|
||||
QObject::connect(this, QOverload<SongMap>::of(&QobuzService::RemoveSongs), favorite_request_, QOverload<const SongMap&>::of(&QobuzFavoriteRequest::RemoveSongs));
|
||||
|
||||
QObject::connect(favorite_request_, &QobuzFavoriteRequest::ArtistsAdded, artists_collection_backend_, &CollectionBackend::AddOrUpdateSongs);
|
||||
QObject::connect(favorite_request_, &QobuzFavoriteRequest::AlbumsAdded, albums_collection_backend_, &CollectionBackend::AddOrUpdateSongs);
|
||||
@@ -285,7 +287,7 @@ void QobuzService::SendLoginWithCredentials(const QString &app_id, const QString
|
||||
QObject::connect(reply, &QNetworkReply::sslErrors, this, &QobuzService::HandleLoginSSLErrors);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { HandleAuthReply(reply); });
|
||||
|
||||
qLog(Debug) << "Qobuz: Sending request" << url << query;
|
||||
//qLog(Debug) << "Qobuz: Sending request" << url << query;
|
||||
|
||||
}
|
||||
|
||||
@@ -496,12 +498,12 @@ void QobuzService::ResetArtistsRequest() {
|
||||
void QobuzService::GetArtists() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit ArtistsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
emit ArtistsResults(SongMap(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit ArtistsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
emit ArtistsResults(SongMap(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -518,7 +520,7 @@ void QobuzService::GetArtists() {
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::ArtistsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
void QobuzService::ArtistsResultsReceived(const int id, const SongMap &songs, const QString &error) {
|
||||
Q_UNUSED(id);
|
||||
emit ArtistsResults(songs, error);
|
||||
}
|
||||
@@ -551,12 +553,12 @@ void QobuzService::ResetAlbumsRequest() {
|
||||
void QobuzService::GetAlbums() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit AlbumsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
emit AlbumsResults(SongMap(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit AlbumsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
emit AlbumsResults(SongMap(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -571,7 +573,7 @@ void QobuzService::GetAlbums() {
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::AlbumsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
void QobuzService::AlbumsResultsReceived(const int id, const SongMap &songs, const QString &error) {
|
||||
Q_UNUSED(id);
|
||||
emit AlbumsResults(songs, error);
|
||||
}
|
||||
@@ -604,12 +606,12 @@ void QobuzService::ResetSongsRequest() {
|
||||
void QobuzService::GetSongs() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit SongsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
emit SongsResults(SongMap(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit SongsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
emit SongsResults(SongMap(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -624,7 +626,7 @@ void QobuzService::GetSongs() {
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::SongsResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
void QobuzService::SongsResultsReceived(const int id, const SongMap &songs, const QString &error) {
|
||||
Q_UNUSED(id);
|
||||
emit SongsResults(songs, error);
|
||||
}
|
||||
@@ -669,7 +671,7 @@ void QobuzService::StartSearch() {
|
||||
search_text_ = pending_search_text_;
|
||||
|
||||
if (app_id_.isEmpty()) { // App ID is the only thing needed to search.
|
||||
emit SearchResults(search_id_, SongList(), tr("Missing Qobuz app ID."));
|
||||
emit SearchResults(search_id_, SongMap(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -708,7 +710,7 @@ void QobuzService::SendSearch() {
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::SearchResultsReceived(const int id, const SongList &songs, const QString &error) {
|
||||
void QobuzService::SearchResultsReceived(const int id, const SongMap &songs, const QString &error) {
|
||||
emit SearchResults(id, songs, error);
|
||||
}
|
||||
|
||||
|
||||
@@ -125,10 +125,10 @@ class QobuzService : public InternetService {
|
||||
void HandleAuthReply(QNetworkReply *reply);
|
||||
void ResetLoginAttempts();
|
||||
void StartSearch();
|
||||
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 ArtistsResultsReceived(const int id, const SongMap &songs, const QString &error);
|
||||
void AlbumsResultsReceived(const int id, const SongMap &songs, const QString &error);
|
||||
void SongsResultsReceived(const int id, const SongMap &songs, const QString &error);
|
||||
void SearchResultsReceived(const int id, const SongMap &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);
|
||||
|
||||
Reference in New Issue
Block a user