1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 03:27:40 +01:00

None was OK to achieve what I want. Should be better now

This commit is contained in:
Arnaud Bienner 2014-08-10 14:22:42 +02:00
parent bc7bc9910d
commit 80d272f3d0
2 changed files with 29 additions and 7 deletions

View File

@ -142,9 +142,7 @@ void MusicBrainzClient::DiscIdRequestFinished(const QString& discid,
}
}
ResultList unique_ret = UniqueResults(ret);
qSort(unique_ret);
emit Finished(artist, album, unique_ret);
emit Finished(artist, album, UniqueResults(ret, SortResults));
}
void MusicBrainzClient::RequestFinished(QNetworkReply* reply, int id, int request_number) {
@ -185,7 +183,7 @@ void MusicBrainzClient::RequestFinished(QNetworkReply* reply, int id, int reques
for (const PendingResults& result_list : result_list_list) {
ret << result_list.results_;
}
emit Finished(id, UniqueResults(ret));
emit Finished(id, UniqueResults(ret, KeepOriginalOrder));
}
}
@ -347,7 +345,23 @@ MusicBrainzClient::Release MusicBrainzClient::ParseRelease(
return ret;
}
MusicBrainzClient::ResultList MusicBrainzClient::UniqueResults(const ResultList& results) {
ResultList ret = QSet<Result>::fromList(results).toList();
MusicBrainzClient::ResultList MusicBrainzClient::UniqueResults(
const ResultList& results, UniqueResultsSortOption opt) {
ResultList ret;
if (opt == SortResults) {
ret = QSet<Result>::fromList(results).toList();
qSort(ret);
} else { // KeepOriginalOrder
// Qt doesn't provide a ordered set (QSet "stores values in an unspecified
// order" according to Qt documentation).
// We might use std::set instead, but it's probably faster to use ResultList
// directly to avoid converting from one structure to another.
for (const Result& res : results) {
if (!ret.contains(res)) {
ret << res;
}
}
}
return ret;
}

View File

@ -103,6 +103,12 @@ signals:
void DiscIdRequestFinished(const QString& discid, QNetworkReply* reply);
private:
// Used as parameter for UniqueResults
enum UniqueResultsSortOption {
SortResults = 0,
KeepOriginalOrder
};
struct Release {
Release() : track_(0), year_(0) {}
@ -137,7 +143,9 @@ signals:
static ResultList ParseTrack(QXmlStreamReader* reader);
static void ParseArtist(QXmlStreamReader* reader, QString* artist);
static Release ParseRelease(QXmlStreamReader* reader);
static ResultList UniqueResults(const ResultList& results);
static ResultList UniqueResults(const ResultList& results,
UniqueResultsSortOption opt = SortResults);
private:
static const char* kTrackUrl;