Use QStringLiteral
This commit is contained in:
@@ -49,7 +49,7 @@
|
||||
constexpr int QobuzCoverProvider::kLimit = 10;
|
||||
|
||||
QobuzCoverProvider::QobuzCoverProvider(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, network, parent),
|
||||
: JsonCoverProvider(QStringLiteral("Qobuz"), true, true, 2.0, true, true, app, network, parent),
|
||||
service_(app->internet_services()->Service<QobuzService>()) {}
|
||||
|
||||
QobuzCoverProvider::~QobuzCoverProvider() {
|
||||
@@ -70,12 +70,12 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
|
||||
QString resource;
|
||||
QString query = artist;
|
||||
if (album.isEmpty() && !title.isEmpty()) {
|
||||
resource = "track/search";
|
||||
resource = QStringLiteral("track/search");
|
||||
if (!query.isEmpty()) query.append(" ");
|
||||
query.append(title);
|
||||
}
|
||||
else {
|
||||
resource = "album/search";
|
||||
resource = QStringLiteral("album/search");
|
||||
if (!album.isEmpty()) {
|
||||
if (!query.isEmpty()) query.append(" ");
|
||||
query.append(album);
|
||||
@@ -93,7 +93,7 @@ bool QobuzCoverProvider::StartSearch(const QString &artist, const QString &album
|
||||
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
||||
}
|
||||
|
||||
QUrl url(QString(QobuzService::kApiUrl) + QString("/") + resource);
|
||||
QUrl url(QString(QobuzService::kApiUrl) + QStringLiteral("/") + resource);
|
||||
url.setQuery(url_query);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
@@ -121,7 +121,7 @@ QByteArray QobuzCoverProvider::GetReplyData(QNetworkReply *reply) {
|
||||
else {
|
||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
||||
// This is a network error, there is nothing more to do.
|
||||
Error(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
}
|
||||
else {
|
||||
// See if there is Json data containing "status", "code" and "message" - then use that instead.
|
||||
@@ -131,18 +131,18 @@ QByteArray QobuzCoverProvider::GetReplyData(QNetworkReply *reply) {
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &parse_error);
|
||||
if (parse_error.error == QJsonParseError::NoError && !json_doc.isEmpty() && json_doc.isObject()) {
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (!json_obj.isEmpty() && json_obj.contains("status") && json_obj.contains("code") && json_obj.contains("message")) {
|
||||
int code = json_obj["code"].toInt();
|
||||
QString message = json_obj["message"].toString();
|
||||
error = QString("%1 (%2)").arg(message).arg(code);
|
||||
if (!json_obj.isEmpty() && json_obj.contains(QStringLiteral("status")) && json_obj.contains(QStringLiteral("code")) && json_obj.contains(QStringLiteral("message"))) {
|
||||
int code = json_obj[QStringLiteral("code")].toInt();
|
||||
QString message = json_obj[QStringLiteral("message")].toString();
|
||||
error = QStringLiteral("%1 (%2)").arg(message).arg(code);
|
||||
}
|
||||
}
|
||||
if (error.isEmpty()) {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
error = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
error = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
else {
|
||||
error = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
error = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
}
|
||||
Error(error);
|
||||
@@ -176,34 +176,34 @@ void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
||||
}
|
||||
|
||||
QJsonValue value_type;
|
||||
if (json_obj.contains("albums")) {
|
||||
value_type = json_obj["albums"];
|
||||
if (json_obj.contains(QStringLiteral("albums"))) {
|
||||
value_type = json_obj[QStringLiteral("albums")];
|
||||
}
|
||||
else if (json_obj.contains("tracks")) {
|
||||
value_type = json_obj["tracks"];
|
||||
else if (json_obj.contains(QStringLiteral("tracks"))) {
|
||||
value_type = json_obj[QStringLiteral("tracks")];
|
||||
}
|
||||
else {
|
||||
Error("Json reply is missing albums and tracks object.", json_obj);
|
||||
Error(QStringLiteral("Json reply is missing albums and tracks object."), json_obj);
|
||||
emit SearchFinished(id, results);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!value_type.isObject()) {
|
||||
Error("Json albums or tracks is not a object.", value_type);
|
||||
Error(QStringLiteral("Json albums or tracks is not a object."), value_type);
|
||||
emit SearchFinished(id, results);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_type = value_type.toObject();
|
||||
|
||||
if (!obj_type.contains("items")) {
|
||||
Error("Json albums or tracks object does not contain items.", obj_type);
|
||||
if (!obj_type.contains(QStringLiteral("items"))) {
|
||||
Error(QStringLiteral("Json albums or tracks object does not contain items."), obj_type);
|
||||
emit SearchFinished(id, results);
|
||||
return;
|
||||
}
|
||||
QJsonValue value_items = obj_type["items"];
|
||||
QJsonValue value_items = obj_type[QStringLiteral("items")];
|
||||
|
||||
if (!value_items.isArray()) {
|
||||
Error("Json albums or track object items is not a array.", value_items);
|
||||
Error(QStringLiteral("Json albums or track object items is not a array."), value_items);
|
||||
emit SearchFinished(id, results);
|
||||
return;
|
||||
}
|
||||
@@ -212,55 +212,55 @@ void QobuzCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
||||
for (const QJsonValueRef value : array_items) {
|
||||
|
||||
if (!value.isObject()) {
|
||||
Error("Invalid Json reply, value in items is not a object.");
|
||||
Error(QStringLiteral("Invalid Json reply, value in items is not a object."));
|
||||
continue;
|
||||
}
|
||||
QJsonObject item_obj = value.toObject();
|
||||
|
||||
QJsonObject obj_album;
|
||||
if (item_obj.contains("album")) {
|
||||
if (!item_obj["album"].isObject()) {
|
||||
Error("Invalid Json reply, items album is not a object.", item_obj);
|
||||
if (item_obj.contains(QStringLiteral("album"))) {
|
||||
if (!item_obj[QStringLiteral("album")].isObject()) {
|
||||
Error(QStringLiteral("Invalid Json reply, items album is not a object."), item_obj);
|
||||
continue;
|
||||
}
|
||||
obj_album = item_obj["album"].toObject();
|
||||
obj_album = item_obj[QStringLiteral("album")].toObject();
|
||||
}
|
||||
else {
|
||||
obj_album = item_obj;
|
||||
}
|
||||
|
||||
if (!obj_album.contains("artist") || !obj_album.contains("image") || !obj_album.contains("title")) {
|
||||
Error("Invalid Json reply, item is missing artist, title or image.", obj_album);
|
||||
if (!obj_album.contains(QStringLiteral("artist")) || !obj_album.contains(QStringLiteral("image")) || !obj_album.contains(QStringLiteral("title"))) {
|
||||
Error(QStringLiteral("Invalid Json reply, item is missing artist, title or image."), obj_album);
|
||||
continue;
|
||||
}
|
||||
|
||||
QString album = obj_album["title"].toString();
|
||||
QString album = obj_album[QStringLiteral("title")].toString();
|
||||
|
||||
// Artist
|
||||
QJsonValue value_artist = obj_album["artist"];
|
||||
QJsonValue value_artist = obj_album[QStringLiteral("artist")];
|
||||
if (!value_artist.isObject()) {
|
||||
Error("Invalid Json reply, items (album) artist is not a object.", value_artist);
|
||||
Error(QStringLiteral("Invalid Json reply, items (album) artist is not a object."), value_artist);
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_artist = value_artist.toObject();
|
||||
if (!obj_artist.contains("name")) {
|
||||
Error("Invalid Json reply, items (album) artist is missing name.", obj_artist);
|
||||
if (!obj_artist.contains(QStringLiteral("name"))) {
|
||||
Error(QStringLiteral("Invalid Json reply, items (album) artist is missing name."), obj_artist);
|
||||
continue;
|
||||
}
|
||||
QString artist = obj_artist["name"].toString();
|
||||
QString artist = obj_artist[QStringLiteral("name")].toString();
|
||||
|
||||
// Image
|
||||
QJsonValue value_image = obj_album["image"];
|
||||
QJsonValue value_image = obj_album[QStringLiteral("image")];
|
||||
if (!value_image.isObject()) {
|
||||
Error("Invalid Json reply, items (album) image is not a object.", value_image);
|
||||
Error(QStringLiteral("Invalid Json reply, items (album) image is not a object."), value_image);
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_image = value_image.toObject();
|
||||
if (!obj_image.contains("large")) {
|
||||
Error("Invalid Json reply, items (album) image is missing large.", obj_image);
|
||||
if (!obj_image.contains(QStringLiteral("large"))) {
|
||||
Error(QStringLiteral("Invalid Json reply, items (album) image is missing large."), obj_image);
|
||||
continue;
|
||||
}
|
||||
QUrl cover_url(obj_image["large"].toString());
|
||||
QUrl cover_url(obj_image[QStringLiteral("large")].toString());
|
||||
|
||||
CoverProviderSearchResult cover_result;
|
||||
cover_result.artist = artist;
|
||||
|
||||
Reference in New Issue
Block a user