Use QStringLiteral

This commit is contained in:
Jonas Kvinge
2024-04-09 23:20:26 +02:00
parent 3cfffa5fbb
commit 58944993b8
233 changed files with 3885 additions and 3885 deletions

View File

@@ -80,10 +80,10 @@ QUrl SubsonicBaseRequest::CreateUrl(const QUrl &server_url, const SubsonicSettin
QUrl url(server_url);
if (!url.path().isEmpty() && url.path().right(1) == "/") {
url.setPath(url.path() + QString("rest/") + ressource_name + QString(".view"));
url.setPath(url.path() + QStringLiteral("rest/") + ressource_name + QStringLiteral(".view"));
}
else {
url.setPath(url.path() + QString("/rest/") + ressource_name + QString(".view"));
url.setPath(url.path() + QStringLiteral("/rest/") + ressource_name + QStringLiteral(".view"));
}
url.setQuery(url_query);
@@ -137,7 +137,7 @@ QByteArray SubsonicBaseRequest::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 {
@@ -148,24 +148,24 @@ QByteArray SubsonicBaseRequest::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("error")) {
QJsonValue json_error = json_obj["error"];
if (!json_obj.isEmpty() && json_obj.contains(QStringLiteral("error"))) {
QJsonValue json_error = json_obj[QStringLiteral("error")];
if (json_error.isObject()) {
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && 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("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);
@@ -182,34 +182,34 @@ QJsonObject SubsonicBaseRequest::ExtractJsonObj(QByteArray &data) {
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
Error("Reply from server missing Json data.", data);
Error(QStringLiteral("Reply from server missing Json data."), data);
return QJsonObject();
}
if (json_doc.isEmpty()) {
Error("Received empty Json document.", data);
Error(QStringLiteral("Received empty Json document."), data);
return QJsonObject();
}
if (!json_doc.isObject()) {
Error("Json document is not an object.", json_doc);
Error(QStringLiteral("Json document is not an object."), json_doc);
return QJsonObject();
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
Error("Received empty Json object.", json_doc);
Error(QStringLiteral("Received empty Json object."), json_doc);
return QJsonObject();
}
if (!json_obj.contains("subsonic-response")) {
Error("Json reply is missing subsonic-response.", json_obj);
if (!json_obj.contains(QStringLiteral("subsonic-response"))) {
Error(QStringLiteral("Json reply is missing subsonic-response."), json_obj);
return QJsonObject();
}
QJsonValue json_response = json_obj["subsonic-response"];
QJsonValue json_response = json_obj[QStringLiteral("subsonic-response")];
if (!json_response.isObject()) {
Error("Json response is not an object.", json_response);
Error(QStringLiteral("Json response is not an object."), json_response);
return QJsonObject();
}
json_obj = json_response.toObject();

View File

@@ -149,7 +149,7 @@ void SubsonicRequest::FlushAlbumsRequests() {
if (request.size > 0) params << Param("size", QString::number(request.size));
if (request.offset > 0) params << Param("offset", QString::number(request.offset));
QNetworkReply *reply = CreateGetRequest(QString("getAlbumList2"), params);
QNetworkReply *reply = CreateGetRequest(QStringLiteral("getAlbumList2"), params);
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumsReplyReceived(reply, request.offset, request.size); });
timeouts_->AddReply(reply);
@@ -182,38 +182,38 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
return;
}
if (json_obj.contains("error")) {
QJsonValue json_error = json_obj["error"];
if (json_obj.contains(QStringLiteral("error"))) {
QJsonValue json_error = json_obj[QStringLiteral("error")];
if (!json_error.isObject()) {
Error("Json error is not an object.", json_obj);
Error(QStringLiteral("Json error is not an object."), json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && 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("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));
AlbumsFinishCheck(offset_requested, size_requested);
}
else {
Error("Json error object is missing code or message.", json_obj);
Error(QStringLiteral("Json error object is missing code or message."), json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
}
return;
}
if (!json_obj.contains("albumList") && !json_obj.contains("albumList2")) {
Error("Json reply is missing albumList.", json_obj);
if (!json_obj.contains(QStringLiteral("albumList")) && !json_obj.contains(QStringLiteral("albumList2"))) {
Error(QStringLiteral("Json reply is missing albumList."), json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
QJsonValue value_albumlist;
if (json_obj.contains("albumList")) value_albumlist = json_obj["albumList"];
else if (json_obj.contains("albumList2")) value_albumlist = json_obj["albumList2"];
if (json_obj.contains(QStringLiteral("albumList"))) value_albumlist = json_obj[QStringLiteral("albumList")];
else if (json_obj.contains(QStringLiteral("albumList2"))) value_albumlist = json_obj[QStringLiteral("albumList2")];
if (!value_albumlist.isObject()) {
Error("Json album list is not an object.", value_albumlist);
Error(QStringLiteral("Json album list is not an object."), value_albumlist);
AlbumsFinishCheck(offset_requested, size_requested);
}
json_obj = value_albumlist.toObject();
@@ -223,18 +223,18 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
return;
}
if (!json_obj.contains("album")) {
Error("Json album list does not contain album array.", json_obj);
if (!json_obj.contains(QStringLiteral("album"))) {
Error(QStringLiteral("Json album list does not contain album array."), json_obj);
AlbumsFinishCheck(offset_requested, size_requested);
}
QJsonValue json_album = json_obj["album"];
QJsonValue json_album = json_obj[QStringLiteral("album")];
if (json_album.isNull()) {
if (offset_requested == 0) no_results_ = true;
AlbumsFinishCheck(offset_requested, size_requested);
return;
}
if (!json_album.isArray()) {
Error("Json album is not an array.", json_album);
Error(QStringLiteral("Json album is not an array."), json_album);
AlbumsFinishCheck(offset_requested, size_requested);
}
QJsonArray array_albums = json_album.toArray();
@@ -251,30 +251,30 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
++albums_received;
if (!value_album.isObject()) {
Error("Invalid Json reply, album is not an object.");
Error(QStringLiteral("Invalid Json reply, album is not an object."));
continue;
}
QJsonObject obj_album = value_album.toObject();
if (!obj_album.contains("id") || !obj_album.contains("artist")) {
Error("Invalid Json reply, album object in array is missing ID or artist.", obj_album);
if (!obj_album.contains(QStringLiteral("id")) || !obj_album.contains(QStringLiteral("artist"))) {
Error(QStringLiteral("Invalid Json reply, album object in array is missing ID or artist."), obj_album);
continue;
}
if (!obj_album.contains("album") && !obj_album.contains("name")) {
Error("Invalid Json reply, album object in array is missing album or name.", obj_album);
if (!obj_album.contains(QStringLiteral("album")) && !obj_album.contains(QStringLiteral("name"))) {
Error(QStringLiteral("Invalid Json reply, album object in array is missing album or name."), obj_album);
continue;
}
QString album_id = obj_album["id"].toString();
QString album_id = obj_album[QStringLiteral("id")].toString();
if (album_id.isEmpty()) {
album_id = QString::number(obj_album["id"].toInt());
album_id = QString::number(obj_album[QStringLiteral("id")].toInt());
}
QString artist = obj_album["artist"].toString();
QString artist = obj_album[QStringLiteral("artist")].toString();
QString album;
if (obj_album.contains("album")) album = obj_album["album"].toString();
else if (obj_album.contains("name")) album = obj_album["name"].toString();
if (obj_album.contains(QStringLiteral("album"))) album = obj_album[QStringLiteral("album")].toString();
else if (obj_album.contains(QStringLiteral("name"))) album = obj_album[QStringLiteral("name")].toString();
if (album_songs_requests_pending_.contains(album_id)) continue;
@@ -341,7 +341,7 @@ void SubsonicRequest::FlushAlbumSongsRequests() {
Request request = album_songs_requests_queue_.dequeue();
++album_songs_requests_active_;
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), ParamList() << Param("id", request.album_id));
QNetworkReply *reply = CreateGetRequest(QStringLiteral("getAlbum"), ParamList() << Param("id", request.album_id));
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); });
timeouts_->AddReply(reply);
@@ -377,57 +377,57 @@ void SubsonicRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const QStrin
return;
}
if (json_obj.contains("error")) {
QJsonValue json_error = json_obj["error"];
if (json_obj.contains(QStringLiteral("error"))) {
QJsonValue json_error = json_obj[QStringLiteral("error")];
if (!json_error.isObject()) {
Error("Json error is not an object.", json_obj);
Error(QStringLiteral("Json error is not an object."), json_obj);
SongsFinishCheck();
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && 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("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));
SongsFinishCheck();
}
else {
Error("Json error object missing code or message.", json_obj);
Error(QStringLiteral("Json error object missing code or message."), json_obj);
SongsFinishCheck();
}
return;
}
if (!json_obj.contains("album")) {
Error("Json reply is missing albumList.", json_obj);
if (!json_obj.contains(QStringLiteral("album"))) {
Error(QStringLiteral("Json reply is missing albumList."), json_obj);
SongsFinishCheck();
return;
}
QJsonValue value_album = json_obj["album"];
QJsonValue value_album = json_obj[QStringLiteral("album")];
if (!value_album.isObject()) {
Error("Json album is not an object.", value_album);
Error(QStringLiteral("Json album is not an object."), value_album);
SongsFinishCheck();
return;
}
QJsonObject obj_album = value_album.toObject();
if (!obj_album.contains("song")) {
Error("Json album object does not contain song array.", json_obj);
if (!obj_album.contains(QStringLiteral("song"))) {
Error(QStringLiteral("Json album object does not contain song array."), json_obj);
SongsFinishCheck();
return;
}
QJsonValue json_song = obj_album["song"];
QJsonValue json_song = obj_album[QStringLiteral("song")];
if (!json_song.isArray()) {
Error("Json song is not an array.", obj_album);
Error(QStringLiteral("Json song is not an array."), obj_album);
SongsFinishCheck();
return;
}
QJsonArray array_songs = json_song.toArray();
qint64 created = 0;
if (obj_album.contains("created")) {
created = QDateTime::fromString(obj_album["created"].toString(), Qt::ISODate).toSecsSinceEpoch();
if (obj_album.contains(QStringLiteral("created"))) {
created = QDateTime::fromString(obj_album[QStringLiteral("created")].toString(), Qt::ISODate).toSecsSinceEpoch();
}
bool compilation = false;
@@ -436,7 +436,7 @@ void SubsonicRequest::AlbumSongsReplyReceived(QNetworkReply *reply, const QStrin
for (const QJsonValueRef value_song : array_songs) {
if (!value_song.isObject()) {
Error("Invalid Json reply, track is not a object.");
Error(QStringLiteral("Invalid Json reply, track is not a object."));
continue;
}
QJsonObject obj_song = value_song.toObject();
@@ -489,133 +489,133 @@ QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, cons
Q_UNUSED(album_id_requested);
if (
!json_obj.contains("id") ||
!json_obj.contains("title") ||
!json_obj.contains("size") ||
!json_obj.contains("suffix") ||
!json_obj.contains("duration") ||
!json_obj.contains("type")
!json_obj.contains(QStringLiteral("id")) ||
!json_obj.contains(QStringLiteral("title")) ||
!json_obj.contains(QStringLiteral("size")) ||
!json_obj.contains(QStringLiteral("suffix")) ||
!json_obj.contains(QStringLiteral("duration")) ||
!json_obj.contains(QStringLiteral("type"))
) {
Error("Invalid Json reply, song is missing one or more values.", json_obj);
Error(QStringLiteral("Invalid Json reply, song is missing one or more values."), json_obj);
return QString();
}
QString song_id;
if (json_obj["id"].type() == QJsonValue::String) {
song_id = json_obj["id"].toString();
if (json_obj[QStringLiteral("id")].type() == QJsonValue::String) {
song_id = json_obj[QStringLiteral("id")].toString();
}
else {
song_id = QString::number(json_obj["id"].toInt());
song_id = QString::number(json_obj[QStringLiteral("id")].toInt());
}
QString album_id;
if (json_obj.contains("albumId")) {
if (json_obj["albumId"].type() == QJsonValue::String) {
album_id = json_obj["albumId"].toString();
if (json_obj.contains(QStringLiteral("albumId"))) {
if (json_obj[QStringLiteral("albumId")].type() == QJsonValue::String) {
album_id = json_obj[QStringLiteral("albumId")].toString();
}
else {
album_id = QString::number(json_obj["albumId"].toInt());
album_id = QString::number(json_obj[QStringLiteral("albumId")].toInt());
}
}
QString artist_id;
if (json_obj.contains("artistId")) {
if (json_obj["artistId"].type() == QJsonValue::String) {
artist_id = json_obj["artistId"].toString();
if (json_obj.contains(QStringLiteral("artistId"))) {
if (json_obj[QStringLiteral("artistId")].type() == QJsonValue::String) {
artist_id = json_obj[QStringLiteral("artistId")].toString();
}
else {
artist_id = QString::number(json_obj["artistId"].toInt());
artist_id = QString::number(json_obj[QStringLiteral("artistId")].toInt());
}
}
QString title = json_obj["title"].toString();
QString title = json_obj[QStringLiteral("title")].toString();
QString album;
if (json_obj.contains("album")) {
album = json_obj["album"].toString();
if (json_obj.contains(QStringLiteral("album"))) {
album = json_obj[QStringLiteral("album")].toString();
}
QString artist;
if (json_obj.contains("artist")) {
artist = json_obj["artist"].toString();
if (json_obj.contains(QStringLiteral("artist"))) {
artist = json_obj[QStringLiteral("artist")].toString();
}
int size = 0;
if (json_obj["size"].type() == QJsonValue::String) {
size = json_obj["size"].toString().toInt();
if (json_obj[QStringLiteral("size")].type() == QJsonValue::String) {
size = json_obj[QStringLiteral("size")].toString().toInt();
}
else {
size = json_obj["size"].toInt();
size = json_obj[QStringLiteral("size")].toInt();
}
qint64 duration = 0;
if (json_obj["duration"].type() == QJsonValue::String) {
duration = json_obj["duration"].toString().toInt() * kNsecPerSec;
if (json_obj[QStringLiteral("duration")].type() == QJsonValue::String) {
duration = json_obj[QStringLiteral("duration")].toString().toInt() * kNsecPerSec;
}
else {
duration = json_obj["duration"].toInt() * kNsecPerSec;
duration = json_obj[QStringLiteral("duration")].toInt() * kNsecPerSec;
}
int bitrate = 0;
if (json_obj.contains("bitRate")) {
if (json_obj["bitRate"].type() == QJsonValue::String) {
bitrate = json_obj["bitRate"].toString().toInt();
if (json_obj.contains(QStringLiteral("bitRate"))) {
if (json_obj[QStringLiteral("bitRate")].type() == QJsonValue::String) {
bitrate = json_obj[QStringLiteral("bitRate")].toString().toInt();
}
else {
bitrate = json_obj["bitRate"].toInt();
bitrate = json_obj[QStringLiteral("bitRate")].toInt();
}
}
QString mimetype;
if (json_obj.contains("contentType")) {
mimetype = json_obj["contentType"].toString();
if (json_obj.contains(QStringLiteral("contentType"))) {
mimetype = json_obj[QStringLiteral("contentType")].toString();
}
int year = 0;
if (json_obj.contains("year")) {
if (json_obj["year"].type() == QJsonValue::String) {
year = json_obj["year"].toString().toInt();
if (json_obj.contains(QStringLiteral("year"))) {
if (json_obj[QStringLiteral("year")].type() == QJsonValue::String) {
year = json_obj[QStringLiteral("year")].toString().toInt();
}
else {
year = json_obj["year"].toInt();
year = json_obj[QStringLiteral("year")].toInt();
}
}
int disc = 0;
if (json_obj.contains("discNumber")) {
if (json_obj["discNumber"].type() == QJsonValue::String) {
disc = json_obj["discNumber"].toString().toInt();
if (json_obj.contains(QStringLiteral("discNumber"))) {
if (json_obj[QStringLiteral("discNumber")].type() == QJsonValue::String) {
disc = json_obj[QStringLiteral("discNumber")].toString().toInt();
}
else {
disc = json_obj["discNumber"].toInt();
disc = json_obj[QStringLiteral("discNumber")].toInt();
}
}
int track = 0;
if (json_obj.contains("track")) {
if (json_obj["track"].type() == QJsonValue::String) {
track = json_obj["track"].toString().toInt();
if (json_obj.contains(QStringLiteral("track"))) {
if (json_obj[QStringLiteral("track")].type() == QJsonValue::String) {
track = json_obj[QStringLiteral("track")].toString().toInt();
}
else {
track = json_obj["track"].toInt();
track = json_obj[QStringLiteral("track")].toInt();
}
}
QString genre;
if (json_obj.contains("genre")) genre = json_obj["genre"].toString();
if (json_obj.contains(QStringLiteral("genre"))) genre = json_obj[QStringLiteral("genre")].toString();
QString cover_id;
if (json_obj.contains("coverArt")) {
if (json_obj["coverArt"].type() == QJsonValue::String) {
cover_id = json_obj["coverArt"].toString();
if (json_obj.contains(QStringLiteral("coverArt"))) {
if (json_obj[QStringLiteral("coverArt")].type() == QJsonValue::String) {
cover_id = json_obj[QStringLiteral("coverArt")].toString();
}
else {
cover_id = QString::number(json_obj["coverArt"].toInt());
cover_id = QString::number(json_obj[QStringLiteral("coverArt")].toInt());
}
}
qint64 created = 0;
if (json_obj.contains("created")) {
created = QDateTime::fromString(json_obj["created"].toString(), Qt::ISODate).toSecsSinceEpoch();
if (json_obj.contains(QStringLiteral("created"))) {
created = QDateTime::fromString(json_obj[QStringLiteral("created")].toString(), Qt::ISODate).toSecsSinceEpoch();
}
else {
created = album_created;
@@ -631,7 +631,7 @@ QString SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, cons
cover_url = cover_urls_[cover_id];
}
else {
cover_url = CreateUrl(server_url(), auth_method(), username(), password(), "getCoverArt", ParamList() << Param("id", cover_id));
cover_url = CreateUrl(server_url(), auth_method(), username(), password(), QStringLiteral("getCoverArt"), ParamList() << Param("id", cover_id));
cover_urls_.insert(cover_id, cover_url);
}
}
@@ -702,11 +702,11 @@ void SubsonicRequest::AddAlbumCoverRequest(const Song &song) {
QUrlQuery cover_url_query(cover_url);
if (!cover_url_query.hasQueryItem("id")) {
if (!cover_url_query.hasQueryItem(QStringLiteral("id"))) {
return;
}
QString cover_id = cover_url_query.queryItemValue("id");
QString cover_id = cover_url_query.queryItemValue(QStringLiteral("id"));
if (album_covers_requests_sent_.contains(cover_id)) {
album_covers_requests_sent_.insert(cover_id, song.song_id());
@@ -785,14 +785,14 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverR
}
if (reply->error() != QNetworkReply::NoError) {
Error(QString("%1 (%2) for %3").arg(reply->errorString()).arg(reply->error()).arg(request.url.toString()));
Error(QStringLiteral("%1 (%2) for %3").arg(reply->errorString()).arg(reply->error()).arg(request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
AlbumCoverFinishCheck();
return;
}
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
Error(QString("Received HTTP code %1 for %2.").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()).arg(request.url.toString()));
Error(QStringLiteral("Received HTTP code %1 for %2.").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()).arg(request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
AlbumCoverFinishCheck();
return;
@@ -803,7 +803,7 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverR
mimetype = mimetype.left(mimetype.indexOf(';'));
}
if (!ImageUtils::SupportedImageMimeTypes().contains(mimetype, Qt::CaseInsensitive) && !ImageUtils::SupportedImageFormats().contains(mimetype, Qt::CaseInsensitive)) {
Error(QString("Unsupported mimetype for image reader %1 for %2").arg(mimetype, request.url.toString()));
Error(QStringLiteral("Unsupported mimetype for image reader %1 for %2").arg(mimetype, request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
AlbumCoverFinishCheck();
return;
@@ -811,7 +811,7 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverR
QByteArray data = reply->readAll();
if (data.isEmpty()) {
Error(QString("Received empty image data for %1").arg(request.url.toString()));
Error(QStringLiteral("Received empty image data for %1").arg(request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
AlbumCoverFinishCheck();
return;
@@ -834,12 +834,12 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const AlbumCoverR
}
}
else {
Error(QString("Error saving image data to %1.").arg(request.filename));
Error(QStringLiteral("Error saving image data to %1.").arg(request.filename));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
}
}
else {
Error(QString("Error decoding image data from %1.").arg(request.url.toString()));
Error(QStringLiteral("Error decoding image data from %1.").arg(request.url.toString()));
if (album_covers_requests_sent_.contains(request.cover_id)) album_covers_requests_sent_.remove(request.cover_id);
}

View File

@@ -77,7 +77,7 @@ void SubsonicScrobbleRequest::FlushScrobbleRequests() {
<< Param("submission", QVariant(request.submission).toString())
<< Param("time", QVariant(request.time_ms).toString());
QNetworkReply *reply = CreateGetRequest("scrobble", params);
QNetworkReply *reply = CreateGetRequest(QStringLiteral("scrobble"), params);
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { ScrobbleReplyReceived(reply); });
@@ -109,22 +109,22 @@ void SubsonicScrobbleRequest::ScrobbleReplyReceived(QNetworkReply *reply) {
return;
}
if (json_obj.contains("error")) {
QJsonValue json_error = json_obj["error"];
if (json_obj.contains(QStringLiteral("error"))) {
QJsonValue json_error = json_obj[QStringLiteral("error")];
if (!json_error.isObject()) {
Error("Json error is not an object.", json_obj);
Error(QStringLiteral("Json error is not an object."), json_obj);
FinishCheck();
return;
}
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && 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("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));
FinishCheck();
}
else {
Error("Json error object is missing code or message.", json_obj);
Error(QStringLiteral("Json error object is missing code or message."), json_obj);
FinishCheck();
return;
}

View File

@@ -69,7 +69,7 @@ const char *SubsonicService::kSongsFtsTable = "subsonic_songs_fts";
const int SubsonicService::kMaxRedirects = 3;
SubsonicService::SubsonicService(Application *app, QObject *parent)
: InternetService(Song::Source::Subsonic, "Subsonic", "subsonic", SubsonicSettingsPage::kSettingsGroup, SettingsDialog::Page::Subsonic, app, parent),
: InternetService(Song::Source::Subsonic, QStringLiteral("Subsonic"), QStringLiteral("subsonic"), SubsonicSettingsPage::kSettingsGroup, SettingsDialog::Page::Subsonic, app, parent),
app_(app),
url_handler_(new SubsonicUrlHandler(app, this)),
collection_backend_(nullptr),
@@ -183,10 +183,10 @@ void SubsonicService::SendPingWithCredentials(QUrl url, const QString &username,
if (!redirect) {
if (!url.path().isEmpty() && url.path().right(1) == "/") {
url.setPath(url.path() + QString("rest/ping.view"));
url.setPath(url.path() + QStringLiteral("rest/ping.view"));
}
else {
url.setPath(url.path() + QString("/rest/ping.view"));
url.setPath(url.path() + QStringLiteral("/rest/ping.view"));
}
}
@@ -237,7 +237,7 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply, const QUrl &url, con
if (reply->error() != QNetworkReply::NoError || reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
// This is a network error, there is nothing more to do.
PingError(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
PingError(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
return;
}
else {
@@ -268,24 +268,24 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply, const QUrl &url, con
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("error")) {
QJsonValue json_error = json_obj["error"];
if (!json_obj.isEmpty() && json_obj.contains(QStringLiteral("error"))) {
QJsonValue json_error = json_obj[QStringLiteral("error")];
if (json_error.isObject()) {
json_obj = json_error.toObject();
if (!json_obj.isEmpty() && json_obj.contains("code") && json_obj.contains("message")) {
int code = json_obj["code"].toInt();
QString message = json_obj["message"].toString();
errors_ << QString("%1 (%2)").arg(message).arg(code);
if (!json_obj.isEmpty() && json_obj.contains(QStringLiteral("code")) && json_obj.contains(QStringLiteral("message"))) {
int code = json_obj[QStringLiteral("code")].toInt();
QString message = json_obj[QStringLiteral("message")].toString();
errors_ << QStringLiteral("%1 (%2)").arg(message).arg(code);
}
}
}
}
if (errors_.isEmpty()) {
if (reply->error() != QNetworkReply::NoError) {
errors_ << QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
errors_ << QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
}
else {
errors_ << QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
errors_ << QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
}
}
PingError();
@@ -301,62 +301,62 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply, const QUrl &url, con
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
if (json_error.error != QJsonParseError::NoError) {
PingError("Ping reply from server missing Json data.");
PingError(QStringLiteral("Ping reply from server missing Json data."));
return;
}
if (json_doc.isEmpty()) {
PingError("Ping reply from server has empty Json document.");
PingError(QStringLiteral("Ping reply from server has empty Json document."));
return;
}
if (!json_doc.isObject()) {
PingError("Ping reply from server has Json document that is not an object.", json_doc);
PingError(QStringLiteral("Ping reply from server has Json document that is not an object."), json_doc);
return;
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
PingError("Ping reply from server has empty Json object.", json_doc);
PingError(QStringLiteral("Ping reply from server has empty Json object."), json_doc);
return;
}
if (!json_obj.contains("subsonic-response")) {
PingError("Ping reply from server is missing subsonic-response", json_obj);
if (!json_obj.contains(QStringLiteral("subsonic-response"))) {
PingError(QStringLiteral("Ping reply from server is missing subsonic-response"), json_obj);
return;
}
QJsonValue value_response = json_obj["subsonic-response"];
QJsonValue value_response = json_obj[QStringLiteral("subsonic-response")];
if (!value_response.isObject()) {
PingError("Ping reply from server subsonic-response is not an object", value_response);
PingError(QStringLiteral("Ping reply from server subsonic-response is not an object"), value_response);
return;
}
QJsonObject obj_response = value_response.toObject();
if (obj_response.contains("error")) {
QJsonValue value_error = obj_response["error"];
if (obj_response.contains(QStringLiteral("error"))) {
QJsonValue value_error = obj_response[QStringLiteral("error")];
if (!value_error.isObject()) {
PingError("Authentication error reply from server is not an object", value_error);
PingError(QStringLiteral("Authentication error reply from server is not an object"), value_error);
return;
}
QJsonObject obj_error = value_error.toObject();
if (!obj_error.contains("code") || !obj_error.contains("message")) {
PingError("Authentication error reply from server is missing status or message", json_obj);
if (!obj_error.contains(QStringLiteral("code")) || !obj_error.contains(QStringLiteral("message"))) {
PingError(QStringLiteral("Authentication error reply from server is missing status or message"), json_obj);
return;
}
//int status = obj_error["code"].toInt();
QString message = obj_error["message"].toString();
QString message = obj_error[QStringLiteral("message")].toString();
emit TestComplete(false, message);
emit TestFailure(message);
return;
}
if (!obj_response.contains("status")) {
PingError("Ping reply from server is missing status", obj_response);
if (!obj_response.contains(QStringLiteral("status"))) {
PingError(QStringLiteral("Ping reply from server is missing status"), obj_response);
return;
}
QString status = obj_response["status"].toString().toLower();
QString message = obj_response["message"].toString();
QString status = obj_response[QStringLiteral("status")].toString().toLower();
QString message = obj_response[QStringLiteral("message")].toString();
if (status == "failed") {
emit TestComplete(false, message);
@@ -369,7 +369,7 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply, const QUrl &url, con
return;
}
else {
PingError("Ping reply status from server is unknown", json_obj);
PingError(QStringLiteral("Ping reply status from server is unknown"), json_obj);
return;
}
@@ -378,15 +378,15 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply, const QUrl &url, con
void SubsonicService::CheckConfiguration() {
if (server_url_.isEmpty()) {
emit TestComplete(false, "Missing Subsonic server url.");
emit TestComplete(false, QStringLiteral("Missing Subsonic server url."));
return;
}
if (username_.isEmpty()) {
emit TestComplete(false, "Missing Subsonic username.");
emit TestComplete(false, QStringLiteral("Missing Subsonic username."));
return;
}
if (password_.isEmpty()) {
emit TestComplete(false, "Missing Subsonic password.");
emit TestComplete(false, QStringLiteral("Missing Subsonic password."));
return;
}

View File

@@ -45,7 +45,7 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
using Param = QPair<QString, QString>;
using ParamList = QList<Param>;
const QUrl stream_url = SubsonicBaseRequest::CreateUrl(server_url(), auth_method(), username(), password(), "stream", ParamList() << Param("id", url.path()));
const QUrl stream_url = SubsonicBaseRequest::CreateUrl(server_url(), auth_method(), username(), password(), QStringLiteral("stream"), ParamList() << Param("id", url.path()));
return LoadResult(url, LoadResult::Type::TrackAvailable, stream_url);