Replace QStringLiteral with u""_s operator

This commit is contained in:
Jonas Kvinge
2024-09-07 05:09:12 +02:00
parent 4270b12cd1
commit 255623bbfd
5 changed files with 657 additions and 656 deletions

View File

@@ -40,104 +40,103 @@ struct IconProperties {
static const QMap<QString, IconProperties> iconmapper_ = { // clazy:exclude=non-pod-global-static static const QMap<QString, IconProperties> iconmapper_ = { // clazy:exclude=non-pod-global-static
{ QStringLiteral("albums"), { {QStringLiteral("media-optical")}} }, { u"albums"_s, { {u"media-optical"_s}} },
{ QStringLiteral("alsa"), { {}} }, { u"alsa"_s, { {}} },
{ QStringLiteral("application-exit"), { {}} }, { u"application-exit"_s, { {}} },
{ QStringLiteral("applications-internet"), { {}} }, { u"applications-internet"_s, { {}} },
{ QStringLiteral("bluetooth"), { {QStringLiteral("preferences-system-bluetooth"), QStringLiteral("bluetooth-active")}} }, { u"bluetooth"_s, { {u"preferences-system-bluetooth"_s, u"bluetooth-active"_s}} },
{ QStringLiteral("cdcase"), { {QStringLiteral("cdcover"), QStringLiteral("media-optical")}} }, { u"cdcase"_s, { {u"cdcover"_s, u"media-optical"_s}} },
{ QStringLiteral("media-optical"), { {QStringLiteral("cd")}} }, { u"media-optical"_s, { {u"cd"_s}} },
{ QStringLiteral("configure"), { {}} }, { u"configure"_s, { {}} },
{ QStringLiteral("device-ipod-nano"), { {}} }, { u"device-ipod-nano"_s, { {}} },
{ QStringLiteral("device-ipod"), { {}} }, { u"device-ipod"_s, { {}} },
{ QStringLiteral("device-phone"), { {}} }, { u"device-phone"_s, { {}} },
{ QStringLiteral("device"), { {QStringLiteral("drive-removable-media-usb-pendrive")}} }, { u"device"_s, { {u"drive-removable-media-usb-pendrive"_s}} },
{ QStringLiteral("device-usb-drive"), { {}} }, { u"device-usb-drive"_s, { {}} },
{ QStringLiteral("device-usb-flash"), { {}} }, { u"device-usb-flash"_s, { {}} },
{ QStringLiteral("dialog-error"), { {}} }, { u"dialog-error"_s, { {}} },
{ QStringLiteral("dialog-information"), { {}} }, { u"dialog-information"_s, { {}} },
{ QStringLiteral("dialog-ok-apply"), { {}} }, { u"dialog-ok-apply"_s, { {}} },
{ QStringLiteral("dialog-password"), { {}} }, { u"dialog-password"_s, { {}} },
{ QStringLiteral("dialog-warning"), { {}} }, { u"dialog-warning"_s, { {}} },
{ QStringLiteral("document-download"), { {QStringLiteral("download")}} }, { u"document-download"_s, { {u"download"_s}} },
{ QStringLiteral("document-new"), { {}} }, { u"document-new"_s, { {}} },
{ QStringLiteral("document-open-folder"), { {}} }, { u"document-open-folder"_s, { {}} },
{ QStringLiteral("document-open"), { {}} }, { u"document-open"_s, { {}} },
{ QStringLiteral("document-save"), { {}} }, { u"document-save"_s, { {}} },
{ QStringLiteral("document-search"), { {}} }, { u"document-search"_s, { {}} },
{ QStringLiteral("document-open-remote"), { {}} }, { u"document-open-remote"_s, { {}} },
{ QStringLiteral("download"), { {QStringLiteral("applications-internet"), QStringLiteral("network-workgroup")}} }, { u"download"_s, { {u"applications-internet"_s, u"network-workgroup"_s}} },
{ QStringLiteral("edit-clear-list"), { {QStringLiteral("edit-clear-list"), QStringLiteral("edit-clear-all")}} }, { u"edit-clear-list"_s, { {u"edit-clear-list"_s, u"edit-clear-all"_s}} },
{ QStringLiteral("edit-clear-locationbar-ltr"), { {QStringLiteral("edit-clear-locationbar-ltr")}} }, { u"edit-clear-locationbar-ltr"_s, { {u"edit-clear-locationbar-ltr"_s}} },
{ QStringLiteral("edit-copy"), { {}} }, { u"edit-copy"_s, { {}} },
{ QStringLiteral("edit-delete"), { {}} }, { u"edit-delete"_s, { {}} },
{ QStringLiteral("edit-find"), { {}} }, { u"edit-find"_s, { {}} },
{ QStringLiteral("edit-redo"), { {}} }, { u"edit-redo"_s, { {}} },
{ QStringLiteral("edit-rename"), { {}} }, { u"edit-rename"_s, { {}} },
{ QStringLiteral("edit-undo"), { {}} }, { u"edit-undo"_s, { {}} },
{ QStringLiteral("electrocompaniet"), { {}} }, { u"electrocompaniet"_s, { {}} },
{ QStringLiteral("equalizer"), { {QStringLiteral("view-media-equalizer")}} }, { u"equalizer"_s, { {u"view-media-equalizer"_s}} },
{ QStringLiteral("folder-new"), { {}} }, { u"folder-new"_s, { {}} },
{ QStringLiteral("folder"), { {}} }, { u"folder"_s, { {}} },
{ QStringLiteral("folder-sound"), { {QStringLiteral("folder-music")}} }, { u"folder-sound"_s, { {u"folder-music"_s}} },
{ QStringLiteral("footsteps"), { {QStringLiteral("go-jump")}} }, { u"footsteps"_s, { {u"go-jump"_s}} },
{ QStringLiteral("go-down"), { {}} }, { u"go-down"_s, { {}} },
{ QStringLiteral("go-home"), { {}} }, { u"go-home"_s, { {}} },
{ QStringLiteral("go-jump"), { {}} }, { u"go-jump"_s, { {}} },
{ QStringLiteral("go-next"), { {}} }, { u"go-next"_s, { {}} },
{ QStringLiteral("go-previous"), { {}} }, { u"go-previous"_s, { {}} },
{ QStringLiteral("go-up"), { {}} }, { u"go-up"_s, { {}} },
{ QStringLiteral("gstreamer"), { {QStringLiteral("phonon-gstreamer")}} }, { u"gstreamer"_s, { {u"phonon-gstreamer"_s}} },
{ QStringLiteral("headset"), { {QStringLiteral("audio-headset")}} }, { u"headset"_s, { {u"audio-headset"_s}} },
{ QStringLiteral("help-hint"), { {}} }, { u"help-hint"_s, { {}} },
{ QStringLiteral("intel"), { {}} }, { u"intel"_s, { {}} },
{ QStringLiteral("jack"), { {QStringLiteral("audio-input-line")}} }, { u"jack"_s, { {u"audio-input-line"_s}} },
{ QStringLiteral("keyboard"), { {QStringLiteral("input-keyboard")}} }, { u"keyboard"_s, { {u"input-keyboard"_s}} },
{ QStringLiteral("list-add"), { {}} }, { u"list-add"_s, { {}} },
{ QStringLiteral("list-remove"), { {}} }, { u"list-remove"_s, { {}} },
{ QStringLiteral("love"), { {QStringLiteral("heart"), QStringLiteral("emblem-favorite")}} }, { u"love"_s, { {u"heart"_s, u"emblem-favorite"_s}} },
{ QStringLiteral("mcintosh-player"), { {}} }, { u"mcintosh-player"_s, { {}} },
{ QStringLiteral("mcintosh"), { {}} }, { u"mcintosh"_s, { {}} },
{ QStringLiteral("mcintosh-text"), { {}} }, { u"mcintosh-text"_s, { {}} },
{ QStringLiteral("media-eject"), { {}} }, { u"media-eject"_s, { {}} },
{ QStringLiteral("media-playback-pause"), { {QStringLiteral("media-pause")}} }, { u"media-playback-pause"_s, { {u"media-pause"_s}} },
{ QStringLiteral("media-playlist-repeat"), { {}} }, { u"media-playlist-repeat"_s, { {}} },
{ QStringLiteral("media-playlist-shuffle"), { {""_L1}} }, { u"media-playlist-shuffle"_s, { {""_L1}} },
{ QStringLiteral("media-playback-start"), { {QStringLiteral("media-play"), QStringLiteral("media-playback-playing")}} }, { u"media-playback-start"_s, { {u"media-play"_s, u"media-playback-playing"_s}} },
{ QStringLiteral("media-seek-backward"), { {}} }, { u"media-seek-backward"_s, { {}} },
{ QStringLiteral("media-seek-forward"), { {}} }, { u"media-seek-forward"_s, { {}} },
{ QStringLiteral("media-skip-backward"), { {}} }, { u"media-skip-backward"_s, { {}} },
{ QStringLiteral("media-skip-forward"), { {}} }, { u"media-skip-forward"_s, { {}} },
{ QStringLiteral("media-playback-stop"), { {QStringLiteral("media-stop")}} }, { u"media-playback-stop"_s, { {u"media-stop"_s}} },
{ QStringLiteral("moodbar"), { {QStringLiteral("preferences-desktop-icons")}} }, { u"moodbar"_s, { {u"preferences-desktop-icons"_s}} },
{ QStringLiteral("nvidia"), { {}} }, { u"nvidia"_s, { {}} },
{ QStringLiteral("pulseaudio"), { {}} }, { u"pulseaudio"_s, { {}} },
{ QStringLiteral("realtek"), { {}} }, { u"realtek"_s, { {}} },
{ QStringLiteral("scrobble-disabled"), { {}} }, { u"scrobble-disabled"_s, { {}} },
{ QStringLiteral("scrobble"), { {QStringLiteral("love")}} }, { u"scrobble"_s, { {u"love"_s}} },
{ QStringLiteral("search"), { {}} }, { u"search"_s, { {}} },
{ QStringLiteral("soundcard"), { {QStringLiteral("audiocard"), QStringLiteral("audio-card")}} }, { u"soundcard"_s, { {u"audiocard"_s, u"audio-card"_s}} },
{ QStringLiteral("speaker"), { {}} }, { u"speaker"_s, { {}} },
{ QStringLiteral("star-grey"), { {}} }, { u"star-grey"_s, { {}} },
{ QStringLiteral("star"), { {}} }, { u"star"_s, { {}} },
{ QStringLiteral("strawberry"), { {}} }, { u"strawberry"_s, { {}} },
{ QStringLiteral("subsonic"), { {}} }, { u"subsonic"_s, { {}} },
{ QStringLiteral("tidal"), { {}} }, { u"tidal"_s, { {}} },
{ QStringLiteral("tools-wizard"), { {}} }, { u"tools-wizard"_s, { {}} },
{ QStringLiteral("view-choose"), { {}} }, { u"view-choose"_s, { {}} },
{ QStringLiteral("view-fullscreen"), { {}} }, { u"view-fullscreen"_s, { {}} },
{ QStringLiteral("view-media-lyrics"), { {}} }, { u"view-media-lyrics"_s, { {}} },
{ QStringLiteral("view-media-playlist"), { {}} }, { u"view-media-playlist"_s, { {}} },
{ QStringLiteral("view-media-visualization"), { {QStringLiteral("preferences-desktop-theme")}} }, { u"view-media-visualization"_s, { {u"preferences-desktop-theme"_s}} },
{ QStringLiteral("view-refresh"), { {}} }, { u"view-refresh"_s, { {}} },
{ QStringLiteral("library-music"), { {QStringLiteral("vinyl")}} }, { u"library-music"_s, { {u"vinyl"_s}} },
{ QStringLiteral("vlc"), { {}} }, { u"vlc"_s, { {}} },
{ QStringLiteral("zoom-in"), { {}} }, { u"zoom-in"_s, { {}} },
{ QStringLiteral("zoom-out"), { {}, 0, 0 } } { u"zoom-out"_s, { {}, 0, 0 } }
}; };
} // namespace IconMapper } // namespace IconMapper
#endif // ICONMAPPER_H #endif // ICONMAPPER_H

File diff suppressed because it is too large Load Diff

View File

@@ -41,29 +41,29 @@ using namespace Qt::StringLiterals;
const char OrganizeFormat::kBlockPattern[] = "\\{([^{}]+)\\}"; const char OrganizeFormat::kBlockPattern[] = "\\{([^{}]+)\\}";
const char OrganizeFormat::kTagPattern[] = "\\%([a-zA-Z]*)"; const char OrganizeFormat::kTagPattern[] = "\\%([a-zA-Z]*)";
const QStringList OrganizeFormat::kKnownTags = QStringList() << QStringLiteral("title") const QStringList OrganizeFormat::kKnownTags = QStringList() << u"title"_s
<< QStringLiteral("album") << u"album"_s
<< QStringLiteral("artist") << u"artist"_s
<< QStringLiteral("artistinitial") << u"artistinitial"_s
<< QStringLiteral("albumartist") << u"albumartist"_s
<< QStringLiteral("composer") << u"composer"_s
<< QStringLiteral("track") << u"track"_s
<< QStringLiteral("disc") << u"disc"_s
<< QStringLiteral("year") << u"year"_s
<< QStringLiteral("originalyear") << u"originalyear"_s
<< QStringLiteral("genre") << u"genre"_s
<< QStringLiteral("comment") << u"comment"_s
<< QStringLiteral("length") << u"length"_s
<< QStringLiteral("bitrate") << u"bitrate"_s
<< QStringLiteral("samplerate") << u"samplerate"_s
<< QStringLiteral("bitdepth") << u"bitdepth"_s
<< QStringLiteral("extension") << u"extension"_s
<< QStringLiteral("performer") << u"performer"_s
<< QStringLiteral("grouping") << u"grouping"_s
<< QStringLiteral("lyrics"); << u"lyrics"_s;
const QStringList OrganizeFormat::kUniqueTags = QStringList() << QStringLiteral("title") const QStringList OrganizeFormat::kUniqueTags = QStringList() << u"title"_s
<< QStringLiteral("track"); << u"track"_s;
OrganizeFormat::OrganizeFormat(const QString &format) OrganizeFormat::OrganizeFormat(const QString &format)
: format_(format), : format_(format),
@@ -184,12 +184,12 @@ OrganizeFormat::GetFilenameForSongResult OrganizeFormat::GetFilenameForSong(cons
filepath = parts_new.join(u'/'); filepath = parts_new.join(u'/');
if (replace_spaces_) { if (replace_spaces_) {
static const QRegularExpression regex_whitespaces(QStringLiteral("\\s")); static const QRegularExpression regex_whitespaces(u"\\s"_s);
filepath.replace(regex_whitespaces, QStringLiteral("_")); filepath.replace(regex_whitespaces, u"_"_s);
} }
if (!extension.isEmpty()) { if (!extension.isEmpty()) {
filepath.append(QStringLiteral(".%1").arg(extension)); filepath.append(u".%1"_s.arg(extension));
} }
return GetFilenameForSongResult(filepath, unique_filename); return GetFilenameForSongResult(filepath, unique_filename);
@@ -302,13 +302,13 @@ QString OrganizeFormat::TagValue(const QString &tag, const Song &song) const {
else if (tag == "artistinitial"_L1) { else if (tag == "artistinitial"_L1) {
value = song.effective_albumartist().trimmed(); value = song.effective_albumartist().trimmed();
if (!value.isEmpty()) { if (!value.isEmpty()) {
static const QRegularExpression regex_the(QStringLiteral("^the\\s+"), QRegularExpression::CaseInsensitiveOption); static const QRegularExpression regex_the(u"^the\\s+"_s, QRegularExpression::CaseInsensitiveOption);
value = value.remove(regex_the); value = value.remove(regex_the);
value = value[0].toUpper(); value = value[0].toUpper();
} }
} }
else if (tag == "albumartist"_L1) { else if (tag == "albumartist"_L1) {
value = song.is_compilation() ? QStringLiteral("Various Artists") : song.effective_albumartist(); value = song.is_compilation() ? u"Various Artists"_s : song.effective_albumartist();
} }
if (value == u'0' || value == "-1"_L1) value = ""_L1; if (value == u'0' || value == "-1"_L1) value = ""_L1;

View File

@@ -209,8 +209,8 @@ void ScrobblingAPI20::Authenticate() {
} }
QUrlQuery url_query; QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("api_key"), QLatin1String(kApiKey)); url_query.addQueryItem(u"api_key"_s, QLatin1String(kApiKey));
url_query.addQueryItem(QStringLiteral("cb"), server_->url().toString()); url_query.addQueryItem(u"cb"_s, server_->url().toString());
QUrl url(auth_url_); QUrl url(auth_url_);
url.setQuery(url_query); url.setQuery(url_query);
@@ -252,8 +252,8 @@ void ScrobblingAPI20::RedirectArrived() {
QUrl url = server_->request_url(); QUrl url = server_->request_url();
if (url.isValid()) { if (url.isValid()) {
QUrlQuery url_query(url); QUrlQuery url_query(url);
if (url_query.hasQueryItem(QStringLiteral("token"))) { if (url_query.hasQueryItem(u"token"_s)) {
QString token = url_query.queryItemValue(QStringLiteral("token")); QString token = url_query.queryItemValue(u"token"_s);
RequestSession(token); RequestSession(token);
} }
else { else {
@@ -278,9 +278,9 @@ void ScrobblingAPI20::RequestSession(const QString &token) {
QUrl session_url(api_url_); QUrl session_url(api_url_);
QUrlQuery session_url_query; QUrlQuery session_url_query;
session_url_query.addQueryItem(QStringLiteral("api_key"), QLatin1String(kApiKey)); session_url_query.addQueryItem(u"api_key"_s, QLatin1String(kApiKey));
session_url_query.addQueryItem(QStringLiteral("method"), QStringLiteral("auth.getSession")); session_url_query.addQueryItem(u"method"_s, u"auth.getSession"_s);
session_url_query.addQueryItem(QStringLiteral("token"), token); session_url_query.addQueryItem(u"token"_s, token);
QString data_to_sign; QString data_to_sign;
const ParamList params = session_url_query.queryItems(); const ParamList params = session_url_query.queryItems();
for (const Param &param : params) { for (const Param &param : params) {
@@ -289,8 +289,8 @@ void ScrobblingAPI20::RequestSession(const QString &token) {
data_to_sign += QLatin1String(kSecret); data_to_sign += QLatin1String(kSecret);
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5); QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
const QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, u'0').toLower(); const QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, u'0').toLower();
session_url_query.addQueryItem(QStringLiteral("api_sig"), signature); session_url_query.addQueryItem(u"api_sig"_s, signature);
session_url_query.addQueryItem(QString::fromLatin1(QUrl::toPercentEncoding(QStringLiteral("format"))), QString::fromLatin1(QUrl::toPercentEncoding(QStringLiteral("json")))); session_url_query.addQueryItem(QString::fromLatin1(QUrl::toPercentEncoding(u"format"_s)), QString::fromLatin1(QUrl::toPercentEncoding(u"json"_s)));
session_url.setQuery(session_url_query); session_url.setQuery(session_url_query);
QNetworkRequest req(session_url); QNetworkRequest req(session_url);
@@ -316,22 +316,22 @@ void ScrobblingAPI20::AuthenticateReplyFinished(QNetworkReply *reply) {
} }
if (!json_obj.contains("session"_L1)) { if (!json_obj.contains("session"_L1)) {
AuthError(QStringLiteral("Json reply from server is missing session.")); AuthError(u"Json reply from server is missing session."_s);
return; return;
} }
QJsonValue json_session = json_obj["session"_L1]; QJsonValue json_session = json_obj["session"_L1];
if (!json_session.isObject()) { if (!json_session.isObject()) {
AuthError(QStringLiteral("Json session is not an object.")); AuthError(u"Json session is not an object."_s);
return; return;
} }
json_obj = json_session.toObject(); json_obj = json_session.toObject();
if (json_obj.isEmpty()) { if (json_obj.isEmpty()) {
AuthError(QStringLiteral("Json session object is empty.")); AuthError(u"Json session object is empty."_s);
return; return;
} }
if (!json_obj.contains("subscriber"_L1) || !json_obj.contains("name"_L1) || !json_obj.contains("key"_L1)) { if (!json_obj.contains("subscriber"_L1) || !json_obj.contains("name"_L1) || !json_obj.contains("key"_L1)) {
AuthError(QStringLiteral("Json session object is missing values.")); AuthError(u"Json session object is missing values."_s);
return; return;
} }
@@ -355,9 +355,9 @@ void ScrobblingAPI20::AuthenticateReplyFinished(QNetworkReply *reply) {
QNetworkReply *ScrobblingAPI20::CreateRequest(const ParamList &request_params) { QNetworkReply *ScrobblingAPI20::CreateRequest(const ParamList &request_params) {
ParamList params = ParamList() ParamList params = ParamList()
<< Param(QStringLiteral("api_key"), QLatin1String(kApiKey)) << Param(u"api_key"_s, QLatin1String(kApiKey))
<< Param(QStringLiteral("sk"), session_key_) << Param(u"sk"_s, session_key_)
<< Param(QStringLiteral("lang"), QLocale().name().left(2).toLower()) << Param(u"lang"_s, QLocale().name().left(2).toLower())
<< request_params; << request_params;
std::sort(params.begin(), params.end()); std::sort(params.begin(), params.end());
@@ -374,13 +374,13 @@ QNetworkReply *ScrobblingAPI20::CreateRequest(const ParamList &request_params) {
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5); QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
const QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, u'0').toLower(); const QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, u'0').toLower();
url_query.addQueryItem(QStringLiteral("api_sig"), QString::fromLatin1(QUrl::toPercentEncoding(signature))); url_query.addQueryItem(u"api_sig"_s, QString::fromLatin1(QUrl::toPercentEncoding(signature)));
url_query.addQueryItem(QStringLiteral("format"), QStringLiteral("json")); url_query.addQueryItem(u"format"_s, u"json"_s);
QUrl url(api_url_); QUrl url(api_url_);
QNetworkRequest req(url); QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); req.setHeader(QNetworkRequest::ContentTypeHeader, u"application/x-www-form-urlencoded"_s);
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8(); QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query); QNetworkReply *reply = network_->post(req, query);
replies_ << reply; replies_ << reply;
@@ -402,16 +402,16 @@ void ScrobblingAPI20::UpdateNowPlaying(const Song &song) {
if (!authenticated() || !song.is_metadata_good() || settings_->offline()) return; if (!authenticated() || !song.is_metadata_good() || settings_->offline()) return;
ParamList params = ParamList() ParamList params = ParamList()
<< Param(QStringLiteral("method"), QStringLiteral("track.updateNowPlaying")) << Param(u"method"_s, u"track.updateNowPlaying"_s)
<< Param(QStringLiteral("artist"), prefer_albumartist_ ? song.effective_albumartist() : song.artist()) << Param(u"artist"_s, prefer_albumartist_ ? song.effective_albumartist() : song.artist())
<< Param(QStringLiteral("track"), StripTitle(song.title())); << Param(u"track"_s, StripTitle(song.title()));
if (!song.album().isEmpty()) { if (!song.album().isEmpty()) {
params << Param(QStringLiteral("album"), StripAlbum(song.album())); params << Param(u"album"_s, StripAlbum(song.album()));
} }
if (!prefer_albumartist_ && !song.albumartist().isEmpty()) { if (!prefer_albumartist_ && !song.albumartist().isEmpty()) {
params << Param(QStringLiteral("albumArtist"), song.albumartist()); params << Param(u"albumArtist"_s, song.albumartist());
} }
QNetworkReply *reply = CreateRequest(params); QNetworkReply *reply = CreateRequest(params);
@@ -434,7 +434,7 @@ void ScrobblingAPI20::UpdateNowPlayingRequestFinished(QNetworkReply *reply) {
} }
if (!json_obj.contains("nowplaying"_L1)) { if (!json_obj.contains("nowplaying"_L1)) {
Error(QStringLiteral("Json reply from server is missing nowplaying."), json_obj); Error(u"Json reply from server is missing nowplaying."_s, json_obj);
return; return;
} }
@@ -494,7 +494,7 @@ void ScrobblingAPI20::Submit() {
qLog(Debug) << name_ << "Submitting scrobbles."; qLog(Debug) << name_ << "Submitting scrobbles.";
ParamList params = ParamList() << Param(QStringLiteral("method"), QStringLiteral("track.scrobble")); ParamList params = ParamList() << Param(u"method"_s, u"track.scrobble"_s);
int i = 0; int i = 0;
const ScrobblerCacheItemPtrList all_cache_items = cache_->List(); const ScrobblerCacheItemPtrList all_cache_items = cache_->List();
@@ -507,18 +507,18 @@ void ScrobblingAPI20::Submit() {
continue; continue;
} }
cache_items_sent << cache_item; cache_items_sent << cache_item;
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("artist")).arg(i), prefer_albumartist_ ? cache_item->metadata.effective_albumartist() : cache_item->metadata.artist); params << Param(u"%1[%2]"_s.arg(u"artist"_s).arg(i), prefer_albumartist_ ? cache_item->metadata.effective_albumartist() : cache_item->metadata.artist);
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("track")).arg(i), StripTitle(cache_item->metadata.title)); params << Param(u"%1[%2]"_s.arg(u"track"_s).arg(i), StripTitle(cache_item->metadata.title));
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("timestamp")).arg(i), QString::number(cache_item->timestamp)); params << Param(u"%1[%2]"_s.arg(u"timestamp"_s).arg(i), QString::number(cache_item->timestamp));
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("duration")).arg(i), QString::number(cache_item->metadata.length_nanosec / kNsecPerSec)); params << Param(u"%1[%2]"_s.arg(u"duration"_s).arg(i), QString::number(cache_item->metadata.length_nanosec / kNsecPerSec));
if (!cache_item->metadata.album.isEmpty()) { if (!cache_item->metadata.album.isEmpty()) {
params << Param(QStringLiteral("%1[%2]").arg("album"_L1).arg(i), StripAlbum(cache_item->metadata.album)); params << Param(u"%1[%2]"_s.arg("album"_L1).arg(i), StripAlbum(cache_item->metadata.album));
} }
if (!prefer_albumartist_ && !cache_item->metadata.albumartist.isEmpty()) { if (!prefer_albumartist_ && !cache_item->metadata.albumartist.isEmpty()) {
params << Param(QStringLiteral("%1[%2]").arg("albumArtist"_L1).arg(i), cache_item->metadata.albumartist); params << Param(u"%1[%2]"_s.arg("albumArtist"_L1).arg(i), cache_item->metadata.albumartist);
} }
if (cache_item->metadata.track > 0) { if (cache_item->metadata.track > 0) {
params << Param(QStringLiteral("%1[%2]").arg("trackNumber"_L1).arg(i), QString::number(cache_item->metadata.track)); params << Param(u"%1[%2]"_s.arg("trackNumber"_L1).arg(i), QString::number(cache_item->metadata.track));
} }
++i; ++i;
if (cache_items_sent.count() >= kScrobblesPerRequest) break; if (cache_items_sent.count() >= kScrobblesPerRequest) break;
@@ -556,43 +556,43 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
submit_error_ = false; submit_error_ = false;
if (!json_obj.contains("scrobbles"_L1)) { if (!json_obj.contains("scrobbles"_L1)) {
Error(QStringLiteral("Json reply from server is missing scrobbles."), json_obj); Error(u"Json reply from server is missing scrobbles."_s, json_obj);
StartSubmit(); StartSubmit();
return; return;
} }
QJsonValue value_scrobbles = json_obj["scrobbles"_L1]; QJsonValue value_scrobbles = json_obj["scrobbles"_L1];
if (!value_scrobbles.isObject()) { if (!value_scrobbles.isObject()) {
Error(QStringLiteral("Json scrobbles is not an object."), json_obj); Error(u"Json scrobbles is not an object."_s, json_obj);
StartSubmit(); StartSubmit();
return; return;
} }
json_obj = value_scrobbles.toObject(); json_obj = value_scrobbles.toObject();
if (json_obj.isEmpty()) { if (json_obj.isEmpty()) {
Error(QStringLiteral("Json scrobbles object is empty."), value_scrobbles); Error(u"Json scrobbles object is empty."_s, value_scrobbles);
StartSubmit(); StartSubmit();
return; return;
} }
if (!json_obj.contains("@attr"_L1) || !json_obj.contains("scrobble"_L1)) { if (!json_obj.contains("@attr"_L1) || !json_obj.contains("scrobble"_L1)) {
Error(QStringLiteral("Json scrobbles object is missing values."), json_obj); Error(u"Json scrobbles object is missing values."_s, json_obj);
StartSubmit(); StartSubmit();
return; return;
} }
QJsonValue value_attr = json_obj["@attr"_L1]; QJsonValue value_attr = json_obj["@attr"_L1];
if (!value_attr.isObject()) { if (!value_attr.isObject()) {
Error(QStringLiteral("Json scrobbles attr is not an object."), value_attr); Error(u"Json scrobbles attr is not an object."_s, value_attr);
StartSubmit(); StartSubmit();
return; return;
} }
QJsonObject obj_attr = value_attr.toObject(); QJsonObject obj_attr = value_attr.toObject();
if (obj_attr.isEmpty()) { if (obj_attr.isEmpty()) {
Error(QStringLiteral("Json scrobbles attr is empty."), value_attr); Error(u"Json scrobbles attr is empty."_s, value_attr);
StartSubmit(); StartSubmit();
return; return;
} }
if (!obj_attr.contains("accepted"_L1) || !obj_attr.contains("ignored"_L1)) { if (!obj_attr.contains("accepted"_L1) || !obj_attr.contains("ignored"_L1)) {
Error(QStringLiteral("Json scrobbles attr is missing values."), obj_attr); Error(u"Json scrobbles attr is missing values."_s, obj_attr);
StartSubmit(); StartSubmit();
return; return;
} }
@@ -607,7 +607,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
if (value_scrobble.isObject()) { if (value_scrobble.isObject()) {
QJsonObject obj_scrobble = value_scrobble.toObject(); QJsonObject obj_scrobble = value_scrobble.toObject();
if (obj_scrobble.isEmpty()) { if (obj_scrobble.isEmpty()) {
Error(QStringLiteral("Json scrobbles scrobble object is empty."), obj_scrobble); Error(u"Json scrobbles scrobble object is empty."_s, obj_scrobble);
StartSubmit(); StartSubmit();
return; return;
} }
@@ -616,13 +616,13 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
else if (value_scrobble.isArray()) { else if (value_scrobble.isArray()) {
array_scrobble = value_scrobble.toArray(); array_scrobble = value_scrobble.toArray();
if (array_scrobble.isEmpty()) { if (array_scrobble.isEmpty()) {
Error(QStringLiteral("Json scrobbles scrobble array is empty."), value_scrobble); Error(u"Json scrobbles scrobble array is empty."_s, value_scrobble);
StartSubmit(); StartSubmit();
return; return;
} }
} }
else { else {
Error(QStringLiteral("Json scrobbles scrobble is not an object or array."), value_scrobble); Error(u"Json scrobbles scrobble is not an object or array."_s, value_scrobble);
StartSubmit(); StartSubmit();
return; return;
} }
@@ -630,7 +630,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
for (const QJsonValue &value : std::as_const(array_scrobble)) { for (const QJsonValue &value : std::as_const(array_scrobble)) {
if (!value.isObject()) { if (!value.isObject()) {
Error(QStringLiteral("Json scrobbles scrobble array value is not an object.")); Error(u"Json scrobbles scrobble array value is not an object."_s);
continue; continue;
} }
QJsonObject json_track = value.toObject(); QJsonObject json_track = value.toObject();
@@ -645,7 +645,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
!json_track.contains("timestamp"_L1) || !json_track.contains("timestamp"_L1) ||
!json_track.contains("ignoredMessage"_L1) !json_track.contains("ignoredMessage"_L1)
) { ) {
Error(QStringLiteral("Json scrobbles scrobble is missing values."), json_track); Error(u"Json scrobbles scrobble is missing values."_s, json_track);
continue; continue;
} }
@@ -653,10 +653,10 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
QJsonValue value_album = json_track["album"_L1]; QJsonValue value_album = json_track["album"_L1];
QJsonValue value_song = json_track["track"_L1]; QJsonValue value_song = json_track["track"_L1];
QJsonValue value_ignoredmessage = json_track["ignoredMessage"_L1]; QJsonValue value_ignoredmessage = json_track["ignoredMessage"_L1];
//quint64 timestamp = json_track[QLatin1String("timestamp")].toVariant().toULongLong(); //quint64 timestamp = json_track[u"timestamp"_s].toVariant().toULongLong();
if (!value_artist.isObject() || !value_album.isObject() || !value_song.isObject() || !value_ignoredmessage.isObject()) { if (!value_artist.isObject() || !value_album.isObject() || !value_song.isObject() || !value_ignoredmessage.isObject()) {
Error(QStringLiteral("Json scrobbles scrobble values are not objects."), json_track); Error(u"Json scrobbles scrobble values are not objects."_s, json_track);
continue; continue;
} }
@@ -666,7 +666,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
QJsonObject obj_ignoredmessage = value_ignoredmessage.toObject(); QJsonObject obj_ignoredmessage = value_ignoredmessage.toObject();
if (obj_artist.isEmpty() || obj_album.isEmpty() || obj_song.isEmpty() || obj_ignoredmessage.isEmpty()) { if (obj_artist.isEmpty() || obj_album.isEmpty() || obj_song.isEmpty() || obj_ignoredmessage.isEmpty()) {
Error(QStringLiteral("Json scrobbles scrobble values objects are empty."), json_track); Error(u"Json scrobbles scrobble values objects are empty."_s, json_track);
continue; continue;
} }
@@ -681,7 +681,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
QString ignoredmessage_text = obj_ignoredmessage["#text"_L1].toString(); QString ignoredmessage_text = obj_ignoredmessage["#text"_L1].toString();
if (ignoredmessage) { if (ignoredmessage) {
Error(QStringLiteral("Scrobble for \"%1\" ignored: %2").arg(song, ignoredmessage_text)); Error(u"Scrobble for \"%1\" ignored: %2"_s.arg(song, ignoredmessage_text));
} }
else { else {
qLog(Debug) << name_ << "Scrobble for" << song << "accepted"; qLog(Debug) << name_ << "Scrobble for" << song << "accepted";
@@ -696,20 +696,20 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
void ScrobblingAPI20::SendSingleScrobble(ScrobblerCacheItemPtr item) { void ScrobblingAPI20::SendSingleScrobble(ScrobblerCacheItemPtr item) {
ParamList params = ParamList() ParamList params = ParamList()
<< Param(QStringLiteral("method"), QStringLiteral("track.scrobble")) << Param(u"method"_s, u"track.scrobble"_s)
<< Param(QStringLiteral("artist"), prefer_albumartist_ ? item->metadata.effective_albumartist() : item->metadata.artist) << Param(u"artist"_s, prefer_albumartist_ ? item->metadata.effective_albumartist() : item->metadata.artist)
<< Param(QStringLiteral("track"), StripTitle(item->metadata.title)) << Param(u"track"_s, StripTitle(item->metadata.title))
<< Param(QStringLiteral("timestamp"), QString::number(item->timestamp)) << Param(u"timestamp"_s, QString::number(item->timestamp))
<< Param(QStringLiteral("duration"), QString::number(item->metadata.length_nanosec / kNsecPerSec)); << Param(u"duration"_s, QString::number(item->metadata.length_nanosec / kNsecPerSec));
if (!item->metadata.album.isEmpty()) { if (!item->metadata.album.isEmpty()) {
params << Param(QStringLiteral("album"), StripAlbum(item->metadata.album)); params << Param(u"album"_s, StripAlbum(item->metadata.album));
} }
if (!prefer_albumartist_ && !item->metadata.albumartist.isEmpty()) { if (!prefer_albumartist_ && !item->metadata.albumartist.isEmpty()) {
params << Param(QStringLiteral("albumArtist"), item->metadata.albumartist); params << Param(u"albumArtist"_s, item->metadata.albumartist);
} }
if (item->metadata.track > 0) { if (item->metadata.track > 0) {
params << Param(QStringLiteral("trackNumber"), QString::number(item->metadata.track)); params << Param(u"trackNumber"_s, QString::number(item->metadata.track));
} }
QNetworkReply *reply = CreateRequest(params); QNetworkReply *reply = CreateRequest(params);
@@ -733,7 +733,7 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
} }
if (!json_obj.contains("scrobbles"_L1)) { if (!json_obj.contains("scrobbles"_L1)) {
Error(QStringLiteral("Json reply from server is missing scrobbles."), json_obj); Error(u"Json reply from server is missing scrobbles."_s, json_obj);
cache_item->sent = false; cache_item->sent = false;
return; return;
} }
@@ -742,48 +742,48 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
QJsonValue value_scrobbles = json_obj["scrobbles"_L1]; QJsonValue value_scrobbles = json_obj["scrobbles"_L1];
if (!value_scrobbles.isObject()) { if (!value_scrobbles.isObject()) {
Error(QStringLiteral("Json scrobbles is not an object."), json_obj); Error(u"Json scrobbles is not an object."_s, json_obj);
return; return;
} }
json_obj = value_scrobbles.toObject(); json_obj = value_scrobbles.toObject();
if (json_obj.isEmpty()) { if (json_obj.isEmpty()) {
Error(QStringLiteral("Json scrobbles object is empty."), value_scrobbles); Error(u"Json scrobbles object is empty."_s, value_scrobbles);
return; return;
} }
if (!json_obj.contains("@attr"_L1) || !json_obj.contains("scrobble"_L1)) { if (!json_obj.contains("@attr"_L1) || !json_obj.contains("scrobble"_L1)) {
Error(QStringLiteral("Json scrobbles object is missing values."), json_obj); Error(u"Json scrobbles object is missing values."_s, json_obj);
return; return;
} }
QJsonValue value_attr = json_obj["@attr"_L1]; QJsonValue value_attr = json_obj["@attr"_L1];
if (!value_attr.isObject()) { if (!value_attr.isObject()) {
Error(QStringLiteral("Json scrobbles attr is not an object."), value_attr); Error(u"Json scrobbles attr is not an object."_s, value_attr);
return; return;
} }
QJsonObject obj_attr = value_attr.toObject(); QJsonObject obj_attr = value_attr.toObject();
if (obj_attr.isEmpty()) { if (obj_attr.isEmpty()) {
Error(QStringLiteral("Json scrobbles attr is empty."), value_attr); Error(u"Json scrobbles attr is empty."_s, value_attr);
return; return;
} }
QJsonValue value_scrobble = json_obj["scrobble"_L1]; QJsonValue value_scrobble = json_obj["scrobble"_L1];
if (!value_scrobble.isObject()) { if (!value_scrobble.isObject()) {
Error(QStringLiteral("Json scrobbles scrobble is not an object."), value_scrobble); Error(u"Json scrobbles scrobble is not an object."_s, value_scrobble);
return; return;
} }
QJsonObject json_obj_scrobble = value_scrobble.toObject(); QJsonObject json_obj_scrobble = value_scrobble.toObject();
if (json_obj_scrobble.isEmpty()) { if (json_obj_scrobble.isEmpty()) {
Error(QStringLiteral("Json scrobbles scrobble is empty."), value_scrobble); Error(u"Json scrobbles scrobble is empty."_s, value_scrobble);
return; return;
} }
if (!obj_attr.contains("accepted"_L1) || !obj_attr.contains("ignored"_L1)) { if (!obj_attr.contains("accepted"_L1) || !obj_attr.contains("ignored"_L1)) {
Error(QStringLiteral("Json scrobbles attr is missing values."), obj_attr); Error(u"Json scrobbles attr is missing values."_s, obj_attr);
return; return;
} }
if (!json_obj_scrobble.contains("artist"_L1) || !json_obj_scrobble.contains("album"_L1) || !json_obj_scrobble.contains("albumArtist"_L1) || !json_obj_scrobble.contains("track"_L1) || !json_obj_scrobble.contains("timestamp"_L1)) { if (!json_obj_scrobble.contains("artist"_L1) || !json_obj_scrobble.contains("album"_L1) || !json_obj_scrobble.contains("albumArtist"_L1) || !json_obj_scrobble.contains("track"_L1) || !json_obj_scrobble.contains("timestamp"_L1)) {
Error(QStringLiteral("Json scrobbles scrobble is missing values."), json_obj_scrobble); Error(u"Json scrobbles scrobble is missing values."_s, json_obj_scrobble);
return; return;
} }
@@ -792,7 +792,7 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
QJsonValue json_value_song = json_obj_scrobble["track"_L1]; QJsonValue json_value_song = json_obj_scrobble["track"_L1];
if (!json_value_artist.isObject() || !json_value_album.isObject() || !json_value_song.isObject()) { if (!json_value_artist.isObject() || !json_value_album.isObject() || !json_value_song.isObject()) {
Error(QStringLiteral("Json scrobbles scrobble values are not objects."), json_obj_scrobble); Error(u"Json scrobbles scrobble values are not objects."_s, json_obj_scrobble);
return; return;
} }
@@ -801,12 +801,12 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
QJsonObject json_obj_song = json_value_song.toObject(); QJsonObject json_obj_song = json_value_song.toObject();
if (json_obj_artist.isEmpty() || json_obj_album.isEmpty() || json_obj_song.isEmpty()) { if (json_obj_artist.isEmpty() || json_obj_album.isEmpty() || json_obj_song.isEmpty()) {
Error(QStringLiteral("Json scrobbles scrobble values objects are empty."), json_obj_scrobble); Error(u"Json scrobbles scrobble values objects are empty."_s, json_obj_scrobble);
return; return;
} }
if (!json_obj_artist.contains("#text"_L1) || !json_obj_album.contains("#text"_L1) || !json_obj_song.contains("#text"_L1)) { if (!json_obj_artist.contains("#text"_L1) || !json_obj_album.contains("#text"_L1) || !json_obj_song.contains("#text"_L1)) {
Error(QStringLiteral("Json scrobbles scrobble values objects are missing #text."), json_obj_artist); Error(u"Json scrobbles scrobble values objects are missing #text."_s, json_obj_artist);
return; return;
} }
@@ -833,16 +833,16 @@ void ScrobblingAPI20::Love() {
qLog(Debug) << name_ << "Sending love for song" << song_playing_.artist() << song_playing_.album() << song_playing_.title(); qLog(Debug) << name_ << "Sending love for song" << song_playing_.artist() << song_playing_.album() << song_playing_.title();
ParamList params = ParamList() ParamList params = ParamList()
<< Param(QStringLiteral("method"), QStringLiteral("track.love")) << Param(u"method"_s, u"track.love"_s)
<< Param(QStringLiteral("artist"), prefer_albumartist_ ? song_playing_.effective_albumartist() : song_playing_.artist()) << Param(u"artist"_s, prefer_albumartist_ ? song_playing_.effective_albumartist() : song_playing_.artist())
<< Param(QStringLiteral("track"), song_playing_.title()); << Param(u"track"_s, song_playing_.title());
if (!song_playing_.album().isEmpty()) { if (!song_playing_.album().isEmpty()) {
params << Param(QStringLiteral("album"), song_playing_.album()); params << Param(u"album"_s, song_playing_.album());
} }
if (!prefer_albumartist_ && !song_playing_.albumartist().isEmpty()) { if (!prefer_albumartist_ && !song_playing_.albumartist().isEmpty()) {
params << Param(QStringLiteral("albumArtist"), song_playing_.albumartist()); params << Param(u"albumArtist"_s, song_playing_.albumartist());
} }
QNetworkReply *reply = CreateRequest(params); QNetworkReply *reply = CreateRequest(params);
@@ -867,12 +867,12 @@ void ScrobblingAPI20::LoveRequestFinished(QNetworkReply *reply) {
if (json_obj.contains("error"_L1)) { if (json_obj.contains("error"_L1)) {
QJsonValue json_value = json_obj["error"_L1]; QJsonValue json_value = json_obj["error"_L1];
if (!json_value.isObject()) { if (!json_value.isObject()) {
Error(QStringLiteral("Error is not on object.")); Error(u"Error is not on object."_s);
return; return;
} }
QJsonObject json_obj_error = json_value.toObject(); QJsonObject json_obj_error = json_value.toObject();
if (json_obj_error.isEmpty()) { if (json_obj_error.isEmpty()) {
Error(QStringLiteral("Received empty json error object."), json_obj); Error(u"Received empty json error object."_s, json_obj);
return; return;
} }
if (json_obj_error.contains("code"_L1) && json_obj_error.contains("#text"_L1)) { if (json_obj_error.contains("code"_L1) && json_obj_error.contains("#text"_L1)) {
@@ -919,64 +919,64 @@ QString ScrobblingAPI20::ErrorString(const ScrobbleErrorCode error) {
switch (error) { switch (error) {
case ScrobbleErrorCode::NoError: case ScrobbleErrorCode::NoError:
return QStringLiteral("This error does not exist."); return u"This error does not exist."_s;
case ScrobbleErrorCode::InvalidService: case ScrobbleErrorCode::InvalidService:
return QStringLiteral("Invalid service - This service does not exist."); return u"Invalid service - This service does not exist."_s;
case ScrobbleErrorCode::InvalidMethod: case ScrobbleErrorCode::InvalidMethod:
return QStringLiteral("Invalid Method - No method with that name in this package."); return u"Invalid Method - No method with that name in this package."_s;
case ScrobbleErrorCode::AuthenticationFailed: case ScrobbleErrorCode::AuthenticationFailed:
return QStringLiteral("Authentication Failed - You do not have permissions to access the service."); return u"Authentication Failed - You do not have permissions to access the service."_s;
case ScrobbleErrorCode::InvalidFormat: case ScrobbleErrorCode::InvalidFormat:
return QStringLiteral("Invalid format - This service doesn't exist in that format."); return u"Invalid format - This service doesn't exist in that format."_s;
case ScrobbleErrorCode::InvalidParameters: case ScrobbleErrorCode::InvalidParameters:
return QStringLiteral("Invalid parameters - Your request is missing a required parameter."); return u"Invalid parameters - Your request is missing a required parameter."_s;
case ScrobbleErrorCode::InvalidResourceSpecified: case ScrobbleErrorCode::InvalidResourceSpecified:
return QStringLiteral("Invalid resource specified"); return u"Invalid resource specified"_s;
case ScrobbleErrorCode::OperationFailed: case ScrobbleErrorCode::OperationFailed:
return QStringLiteral("Operation failed - Most likely the backend service failed. Please try again."); return u"Operation failed - Most likely the backend service failed. Please try again."_s;
case ScrobbleErrorCode::InvalidSessionKey: case ScrobbleErrorCode::InvalidSessionKey:
return QStringLiteral("Invalid session key - Please re-authenticate."); return u"Invalid session key - Please re-authenticate."_s;
case ScrobbleErrorCode::InvalidApiKey: case ScrobbleErrorCode::InvalidApiKey:
return QStringLiteral("Invalid API key - You must be granted a valid key by last.fm."); return u"Invalid API key - You must be granted a valid key by last.fm."_s;
case ScrobbleErrorCode::ServiceOffline: case ScrobbleErrorCode::ServiceOffline:
return QStringLiteral("Service Offline - This service is temporarily offline. Try again later."); return u"Service Offline - This service is temporarily offline. Try again later."_s;
case ScrobbleErrorCode::SubscribersOnly: case ScrobbleErrorCode::SubscribersOnly:
return QStringLiteral("Subscribers Only - This station is only available to paid last.fm subscribers."); return u"Subscribers Only - This station is only available to paid last.fm subscribers."_s;
case ScrobbleErrorCode::InvalidMethodSignature: case ScrobbleErrorCode::InvalidMethodSignature:
return QStringLiteral("Invalid method signature supplied."); return u"Invalid method signature supplied."_s;
case ScrobbleErrorCode::UnauthorizedToken: case ScrobbleErrorCode::UnauthorizedToken:
return QStringLiteral("Unauthorized Token - This token has not been authorized."); return u"Unauthorized Token - This token has not been authorized."_s;
case ScrobbleErrorCode::ItemUnavailable: case ScrobbleErrorCode::ItemUnavailable:
return QStringLiteral("This item is not available for streaming."); return u"This item is not available for streaming."_s;
case ScrobbleErrorCode::TemporarilyUnavailable: case ScrobbleErrorCode::TemporarilyUnavailable:
return QStringLiteral("The service is temporarily unavailable, please try again."); return u"The service is temporarily unavailable, please try again."_s;
case ScrobbleErrorCode::LoginRequired: case ScrobbleErrorCode::LoginRequired:
return QStringLiteral("Login: User requires to be logged in."); return u"Login: User requires to be logged in."_s;
case ScrobbleErrorCode::TrialExpired: case ScrobbleErrorCode::TrialExpired:
return QStringLiteral("Trial Expired - This user has no free radio plays left. Subscription required."); return u"Trial Expired - This user has no free radio plays left. Subscription required."_s;
case ScrobbleErrorCode::ErrorDoesNotExist: case ScrobbleErrorCode::ErrorDoesNotExist:
return QStringLiteral("This error does not exist."); return u"This error does not exist."_s;
case ScrobbleErrorCode::NotEnoughContent: case ScrobbleErrorCode::NotEnoughContent:
return QStringLiteral("Not Enough Content - There is not enough content to play this station."); return u"Not Enough Content - There is not enough content to play this station."_s;
case ScrobbleErrorCode::NotEnoughMembers: case ScrobbleErrorCode::NotEnoughMembers:
return QStringLiteral("Not Enough Members - This group does not have enough members for radio."); return u"Not Enough Members - This group does not have enough members for radio."_s;
case ScrobbleErrorCode::NotEnoughFans: case ScrobbleErrorCode::NotEnoughFans:
return QStringLiteral("Not Enough Fans - This artist does not have enough fans for for radio."); return u"Not Enough Fans - This artist does not have enough fans for for radio."_s;
case ScrobbleErrorCode::NotEnoughNeighbours: case ScrobbleErrorCode::NotEnoughNeighbours:
return QStringLiteral("Not Enough Neighbours - There are not enough neighbours for radio."); return u"Not Enough Neighbours - There are not enough neighbours for radio."_s;
case ScrobbleErrorCode::NoPeakRadio: case ScrobbleErrorCode::NoPeakRadio:
return QStringLiteral("No Peak Radio - This user is not allowed to listen to radio during peak usage."); return u"No Peak Radio - This user is not allowed to listen to radio during peak usage."_s;
case ScrobbleErrorCode::RadioNotFound: case ScrobbleErrorCode::RadioNotFound:
return QStringLiteral("Radio Not Found - Radio station not found."); return u"Radio Not Found - Radio station not found."_s;
case ScrobbleErrorCode::APIKeySuspended: case ScrobbleErrorCode::APIKeySuspended:
return QStringLiteral("Suspended API key - Access for your account has been suspended, please contact Last.fm"); return u"Suspended API key - Access for your account has been suspended, please contact Last.fm"_s;
case ScrobbleErrorCode::Deprecated: case ScrobbleErrorCode::Deprecated:
return QStringLiteral("Deprecated - This type of request is no longer supported."); return u"Deprecated - This type of request is no longer supported."_s;
case ScrobbleErrorCode::RateLimitExceeded: case ScrobbleErrorCode::RateLimitExceeded:
return QStringLiteral("Rate limit exceeded - Your IP has made too many requests in a short period."); return u"Rate limit exceeded - Your IP has made too many requests in a short period."_s;
} }
return QStringLiteral("Unknown error."); return u"Unknown error."_s;
} }

View File

@@ -32,6 +32,8 @@
namespace Utilities { namespace Utilities {
using namespace Qt::Literals::StringLiterals;
QString PrettyTime(int seconds) { QString PrettyTime(int seconds) {
// last.fm sometimes gets the track length wrong, so you end up with negative times. // last.fm sometimes gets the track length wrong, so you end up with negative times.
@@ -82,8 +84,8 @@ QString Ago(const qint64 seconds_since_epoch, const QLocale &locale) {
const qint64 days_ago = then.date().daysTo(now.date()); const qint64 days_ago = then.date().daysTo(now.date());
const QString time = then.time().toString(locale.timeFormat(QLocale::ShortFormat)); const QString time = then.time().toString(locale.timeFormat(QLocale::ShortFormat));
if (days_ago == 0) return QObject::tr("Today") + QLatin1Char(' ') + time; if (days_ago == 0) return QObject::tr("Today") + u' ' + time;
if (days_ago == 1) return QObject::tr("Yesterday") + QLatin1Char(' ') + time; if (days_ago == 1) return QObject::tr("Yesterday") + u' ' + time;
if (days_ago <= 7) return QObject::tr("%1 days ago").arg(days_ago); if (days_ago <= 7) return QObject::tr("%1 days ago").arg(days_ago);
return then.date().toString(locale.dateFormat(QLocale::ShortFormat)); return then.date().toString(locale.dateFormat(QLocale::ShortFormat));
@@ -107,7 +109,7 @@ QString PrettyFutureDate(const QDate date) {
QDateTime ParseRFC822DateTime(const QString &text) { QDateTime ParseRFC822DateTime(const QString &text) {
static const QRegularExpression regexp(QStringLiteral("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})")); static const QRegularExpression regexp(u"(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"_s);
QRegularExpressionMatch re_match = regexp.match(text); QRegularExpressionMatch re_match = regexp.match(text);
if (!re_match.hasMatch()) { if (!re_match.hasMatch()) {
return QDateTime(); return QDateTime();
@@ -116,30 +118,30 @@ QDateTime ParseRFC822DateTime(const QString &text) {
enum class MatchNames { DAYS = 1, MONTHS, YEARS, HOURS, MINUTES, SECONDS }; enum class MatchNames { DAYS = 1, MONTHS, YEARS, HOURS, MINUTES, SECONDS };
QMap<QString, int> monthmap; QMap<QString, int> monthmap;
monthmap[QStringLiteral("Jan")] = 1; monthmap[u"Jan"_s] = 1;
monthmap[QStringLiteral("Feb")] = 2; monthmap[u"Feb"_s] = 2;
monthmap[QStringLiteral("Mar")] = 3; monthmap[u"Mar"_s] = 3;
monthmap[QStringLiteral("Apr")] = 4; monthmap[u"Apr"_s] = 4;
monthmap[QStringLiteral("May")] = 5; monthmap[u"May"_s] = 5;
monthmap[QStringLiteral("Jun")] = 6; monthmap[u"Jun"_s] = 6;
monthmap[QStringLiteral("Jul")] = 7; monthmap[u"Jul"_s] = 7;
monthmap[QStringLiteral("Aug")] = 8; monthmap[u"Aug"_s] = 8;
monthmap[QStringLiteral("Sep")] = 9; monthmap[u"Sep"_s] = 9;
monthmap[QStringLiteral("Oct")] = 10; monthmap[u"Oct"_s] = 10;
monthmap[QStringLiteral("Nov")] = 11; monthmap[u"Nov"_s] = 11;
monthmap[QStringLiteral("Dec")] = 12; monthmap[u"Dec"_s] = 12;
monthmap[QStringLiteral("January")] = 1; monthmap[u"January"_s] = 1;
monthmap[QStringLiteral("February")] = 2; monthmap[u"February"_s] = 2;
monthmap[QStringLiteral("March")] = 3; monthmap[u"March"_s] = 3;
monthmap[QStringLiteral("April")] = 4; monthmap[u"April"_s] = 4;
monthmap[QStringLiteral("May")] = 5; monthmap[u"May"_s] = 5;
monthmap[QStringLiteral("June")] = 6; monthmap[u"June"_s] = 6;
monthmap[QStringLiteral("July")] = 7; monthmap[u"July"_s] = 7;
monthmap[QStringLiteral("August")] = 8; monthmap[u"August"_s] = 8;
monthmap[QStringLiteral("September")] = 9; monthmap[u"September"_s] = 9;
monthmap[QStringLiteral("October")] = 10; monthmap[u"October"_s] = 10;
monthmap[QStringLiteral("November")] = 11; monthmap[u"November"_s] = 11;
monthmap[QStringLiteral("December")] = 12; monthmap[u"December"_s] = 12;
const QDate date(re_match.captured(static_cast<int>(MatchNames::YEARS)).toInt(), monthmap[re_match.captured(static_cast<int>(MatchNames::MONTHS))], re_match.captured(static_cast<int>(MatchNames::DAYS)).toInt()); const QDate date(re_match.captured(static_cast<int>(MatchNames::YEARS)).toInt(), monthmap[re_match.captured(static_cast<int>(MatchNames::MONTHS))], re_match.captured(static_cast<int>(MatchNames::DAYS)).toInt());