1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 03:45:56 +01:00

Sort music brainz releases according to status

This commit is contained in:
Arnaud Bienner 2014-12-06 17:54:13 +01:00
parent f34f868c0f
commit 16b2ac547c
2 changed files with 34 additions and 1 deletions

View File

@ -295,6 +295,7 @@ MusicBrainzClient::ResultList MusicBrainzClient::ParseTrack(
if (releases.isEmpty()) {
ret << result;
} else {
qStableSort(releases);
for (const Release& release : releases) {
ret << release.CopyAndMergeInto(result);
}
@ -336,6 +337,8 @@ MusicBrainzClient::Release MusicBrainzClient::ParseRelease(
QStringRef name = reader->name();
if (name == "title") {
ret.album_ = reader->readElementText();
} else if (name == "status") {
ret.SetStatusFromString(reader->readElementText());
} else if (name == "date") {
QRegExp regex(kDateRegex);
if (regex.indexIn(reader->readElementText()) == 0) {

View File

@ -110,7 +110,16 @@ signals:
};
struct Release {
Release() : track_(0), year_(0) {}
enum Status {
Status_Unknown = 0,
Status_PseudoRelease,
Status_Bootleg,
Status_Promotional,
Status_Official
};
Release() : track_(0), year_(0), status_(Status_Unknown) {}
Result CopyAndMergeInto(const Result& orig) const {
Result ret(orig);
@ -120,9 +129,30 @@ signals:
return ret;
}
void SetStatusFromString(const QString& s) {
if (s.compare("Official", Qt::CaseInsensitive) == 0) {
status_ = Status_Official;
} else if (s.compare("Promotion", Qt::CaseInsensitive) == 0) {
status_ = Status_Promotional;
} else if (s.compare("Bootleg", Qt::CaseInsensitive) == 0) {
status_ = Status_Bootleg;
} else if (s.compare("Pseudo-release", Qt::CaseInsensitive) == 0) {
status_ = Status_PseudoRelease;
} else {
status_ = Status_Unknown;
}
}
bool operator<(const Release& other) const {
// Compare status so that "best" status (e.g. Official) will be first
// when sorting a list of releases.
return status_ > other.status_;
}
QString album_;
int track_;
int year_;
Status status_;
};
struct PendingResults {