mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-27 23:59:53 +01:00
Use QUrl::fromEncoded
This commit is contained in:
parent
c752d28c6a
commit
51462dee1e
@ -31,6 +31,7 @@
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QRegExp>
|
||||
#include <QUrl>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
@ -976,10 +977,24 @@ CollectionBackend::AlbumList CollectionBackend::GetAlbums(const QString &artist,
|
||||
info.artist = compilation ? QString() : query.Value(1).toString();
|
||||
info.album_artist = compilation ? QString() : query.Value(2).toString();
|
||||
info.album_name = query.Value(0).toString();
|
||||
info.art_automatic = query.Value(5).toUrl();
|
||||
info.art_manual = query.Value(6).toUrl();
|
||||
info.first_url = QUrl::fromEncoded(query.Value(7).toByteArray());
|
||||
|
||||
QString art_automatic = query.Value(5).toString();
|
||||
if (art_automatic.contains(QRegExp("..+:.*"))) {
|
||||
info.art_automatic = QUrl::fromEncoded(art_automatic.toUtf8());
|
||||
}
|
||||
else {
|
||||
info.art_automatic = QUrl::fromLocalFile(art_automatic.toUtf8());
|
||||
}
|
||||
|
||||
QString art_manual = query.Value(6).toString();
|
||||
if (art_manual.contains(QRegExp("..+:.*"))) {
|
||||
info.art_manual = QUrl::fromEncoded(art_manual.toUtf8());
|
||||
}
|
||||
else {
|
||||
info.art_manual = QUrl::fromLocalFile(art_manual.toUtf8());
|
||||
}
|
||||
|
||||
if ((info.artist == last_artist || info.album_artist == last_album_artist) && info.album_name == last_album)
|
||||
continue;
|
||||
|
||||
|
@ -737,18 +737,12 @@ QUrl CollectionWatcher::ImageForSong(const QString &path, QMap<QString, QStringL
|
||||
|
||||
if (album_art.contains(dir)) {
|
||||
if (album_art[dir].count() == 1) {
|
||||
QUrl url;
|
||||
url.setScheme("file");
|
||||
url.setPath(album_art[dir][0]);
|
||||
return url;
|
||||
return QUrl::fromLocalFile(album_art[dir][0]);
|
||||
}
|
||||
else {
|
||||
QString best_image = PickBestImage(album_art[dir]);
|
||||
album_art[dir] = QStringList() << best_image;
|
||||
QUrl url;
|
||||
url.setScheme("file");
|
||||
url.setPath(best_image);
|
||||
return url;
|
||||
return QUrl::fromLocalFile(best_image);
|
||||
}
|
||||
}
|
||||
return QUrl();
|
||||
|
@ -743,7 +743,7 @@ void Song::ToProtobuf(pb::tagreader::SongMetadata *pb) const {
|
||||
|
||||
}
|
||||
|
||||
#define tostr(n) (q.value(n).isNull() ? QString::null : q.value(n).toString())
|
||||
#define tostr(n) (q.value(n).isNull() ? QString() : q.value(n).toString())
|
||||
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
|
||||
#define tolonglong(n) (q.value(n).isNull() ? -1 : q.value(n).toLongLong())
|
||||
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
|
||||
@ -808,7 +808,7 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
|
||||
d->comment_ = tostr(x);
|
||||
}
|
||||
else if (Song::kColumns.value(i) == "lyrics") {
|
||||
d->comment_ = tostr(x);
|
||||
d->lyrics_ = tostr(x);
|
||||
}
|
||||
|
||||
else if (Song::kColumns.value(i) == "artist_id") {
|
||||
@ -887,10 +887,22 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
|
||||
}
|
||||
|
||||
else if (Song::kColumns.value(i) == "art_automatic") {
|
||||
set_art_automatic(QUrl::fromEncoded(tostr(x).toUtf8()));
|
||||
QString art_automatic = tostr(x);
|
||||
if (art_automatic.contains(QRegExp("..+:.*"))) {
|
||||
set_art_automatic(QUrl::fromEncoded(art_automatic.toUtf8()));
|
||||
}
|
||||
else {
|
||||
set_art_automatic(QUrl::fromLocalFile(art_automatic.toUtf8()));
|
||||
}
|
||||
}
|
||||
else if (Song::kColumns.value(i) == "art_manual") {
|
||||
set_art_manual(QUrl::fromEncoded(tostr(x).toUtf8()));
|
||||
QString art_manual = tostr(x);
|
||||
if (art_manual.contains(QRegExp("..+:.*"))) {
|
||||
set_art_manual(QUrl::fromEncoded(art_manual.toUtf8()));
|
||||
}
|
||||
else {
|
||||
set_art_manual(QUrl::fromLocalFile(art_manual.toUtf8()));
|
||||
}
|
||||
}
|
||||
|
||||
else if (Song::kColumns.value(i) == "effective_albumartist") {
|
||||
@ -948,8 +960,7 @@ void Song::InitArtManual() {
|
||||
QString filename(Utilities::Sha1CoverHash(effective_albumartist(), album).toHex() + ".jpg");
|
||||
QString path(AlbumCoverLoader::ImageCacheDir(d->source_) + "/" + filename);
|
||||
if (QFile::exists(path)) {
|
||||
d->art_manual_.setScheme("file");
|
||||
d->art_manual_.setPath(path);
|
||||
d->art_manual_ = QUrl::fromLocalFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1261,7 +1272,7 @@ QString Song::PrettyTitleWithArtist() const {
|
||||
|
||||
QString Song::PrettyLength() const {
|
||||
|
||||
if (length_nanosec() == -1) return QString::null;
|
||||
if (length_nanosec() == -1) return QString();
|
||||
|
||||
return Utilities::PrettyTimeNanosec(length_nanosec());
|
||||
|
||||
@ -1269,7 +1280,7 @@ QString Song::PrettyLength() const {
|
||||
|
||||
QString Song::PrettyYear() const {
|
||||
|
||||
if (d->year_ == -1) return QString::null;
|
||||
if (d->year_ == -1) return QString();
|
||||
|
||||
return QString::number(d->year_);
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QDir>
|
||||
@ -43,7 +45,6 @@
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QDesktopWidget>
|
||||
#include <QtEvents>
|
||||
|
||||
#include "core/utilities.h"
|
||||
@ -146,9 +147,7 @@ QUrl AlbumCoverChoiceController::LoadCoverFromFile(Song *song) {
|
||||
return QUrl();
|
||||
}
|
||||
else {
|
||||
QUrl cover_url;
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(cover_file);
|
||||
QUrl cover_url(QUrl::fromLocalFile(cover_file));
|
||||
SaveCoverToSong(song, cover_url);
|
||||
return cover_url;
|
||||
}
|
||||
@ -188,7 +187,7 @@ QString AlbumCoverChoiceController::GetInitialPathForFileDialog(const Song &song
|
||||
if (song.art_automatic().scheme().isEmpty() && QFile::exists(QFileInfo(song.art_automatic().path()).path())) {
|
||||
return song.art_automatic().path();
|
||||
}
|
||||
else if (song.art_automatic().scheme() == "file" && QFile::exists(QFileInfo(song.art_automatic().toLocalFile()).path())) {
|
||||
else if (song.art_automatic().isLocalFile() && QFile::exists(QFileInfo(song.art_automatic().toLocalFile()).path())) {
|
||||
return song.art_automatic().toLocalFile();
|
||||
}
|
||||
// If no automatic art, start in the song's folder
|
||||
@ -243,9 +242,7 @@ QUrl AlbumCoverChoiceController::SearchForCover(Song *song) {
|
||||
|
||||
QUrl AlbumCoverChoiceController::UnsetCover(Song *song) {
|
||||
|
||||
QUrl cover_url;
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(Song::kManuallyUnsetCover);
|
||||
QUrl cover_url(QUrl::fromLocalFile(Song::kManuallyUnsetCover));
|
||||
SaveCoverToSong(song, cover_url);
|
||||
|
||||
return cover_url;
|
||||
@ -288,10 +285,10 @@ void AlbumCoverChoiceController::ShowCover(const Song &song, const QPixmap &pixm
|
||||
title_text += " (" + QString::number(label->pixmap()->width()) + "x" + QString::number(label->pixmap()->height()) + "px)";
|
||||
|
||||
// If the cover is larger than the screen, resize the window 85% seems to be enough to account for title bar and taskbar etc.
|
||||
QDesktopWidget desktop;
|
||||
int current_screen = desktop.screenNumber(this);
|
||||
int desktop_height = desktop.screenGeometry(current_screen).height();
|
||||
int desktop_width = desktop.screenGeometry(current_screen).width();
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
QRect screenGeometry = screen->geometry();
|
||||
int desktop_height = screenGeometry.height();
|
||||
int desktop_width = screenGeometry.width();
|
||||
|
||||
// Resize differently if monitor is in portrait mode
|
||||
if (desktop_width < desktop_height) {
|
||||
@ -387,9 +384,7 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
|
||||
QString filepath = app_->album_cover_loader()->CoverFilePath(source, artist, album, album_id, album_dir, cover_url);
|
||||
if (filepath.isEmpty()) return QUrl();
|
||||
|
||||
QUrl new_cover_url;
|
||||
new_cover_url.setScheme("file");
|
||||
new_cover_url.setPath(filepath);
|
||||
QUrl new_cover_url(QUrl::fromLocalFile(filepath));
|
||||
|
||||
// Don't overwrite when saving in album dir if the filename is set to pattern unless the "overwrite" is set.
|
||||
if (source == Song::Source_Collection && QFile::exists(filepath) && !cover_overwrite_ && !overwrite && cover_album_dir_ && cover_filename_ == CollectionSettingsPage::SaveCover_Pattern) {
|
||||
|
@ -622,24 +622,18 @@ void AlbumCoverManager::SaveCoverToFile() {
|
||||
image = no_cover_image_;
|
||||
}
|
||||
else {
|
||||
if (!song.art_manual().isEmpty() && !song.art_manual().path().isEmpty() &&
|
||||
(
|
||||
(song.art_manual().scheme().isEmpty() && QFile::exists(song.art_manual().path()))
|
||||
||
|
||||
(song.art_manual().scheme() == "file" && QFile::exists(song.art_manual().toLocalFile()))
|
||||
)
|
||||
) {
|
||||
if (!song.art_manual().isEmpty() && !song.art_manual().isLocalFile() && QFile::exists(song.art_manual().toLocalFile())) {
|
||||
image = QImage(song.art_manual().toLocalFile());
|
||||
}
|
||||
if (!song.art_automatic().isEmpty() && !song.art_automatic().path().isEmpty() &&
|
||||
(
|
||||
(song.art_automatic().scheme().isEmpty() && QFile::exists(song.art_automatic().path()))
|
||||
||
|
||||
(song.art_automatic().scheme() == "file" && QFile::exists(song.art_automatic().toLocalFile()))
|
||||
)
|
||||
) {
|
||||
else if (!song.art_manual().isEmpty() && !song.art_manual().path().isEmpty() && song.art_manual().scheme().isEmpty() && QFile::exists(song.art_manual().path())) {
|
||||
image = QImage(song.art_manual().path());
|
||||
}
|
||||
else if (!song.art_automatic().isEmpty() && !song.art_automatic().isLocalFile() && QFile::exists(song.art_automatic().toLocalFile())) {
|
||||
image = QImage(song.art_automatic().toLocalFile());
|
||||
}
|
||||
else if (!song.art_automatic().isEmpty() && !song.art_automatic().path().isEmpty() && song.art_automatic().scheme().isEmpty() && QFile::exists(song.art_automatic().path())) {
|
||||
image = QImage(song.art_automatic().path());
|
||||
}
|
||||
else {
|
||||
image = no_cover_image_;
|
||||
}
|
||||
|
@ -85,11 +85,8 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, const QUrl
|
||||
thumbnail = image.scaledToHeight(120, Qt::SmoothTransformation);
|
||||
thumbnail.save(temp_cover_thumbnail_->fileName(), "JPEG");
|
||||
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(temp_cover_->fileName());
|
||||
|
||||
thumbnail_url.setScheme("file");
|
||||
thumbnail_url.setPath(temp_cover_thumbnail_->fileName());
|
||||
cover_url = QUrl::fromLocalFile(temp_cover_->fileName());
|
||||
thumbnail_url = QUrl::fromLocalFile(temp_cover_thumbnail_->fileName());
|
||||
}
|
||||
|
||||
emit AlbumCoverLoaded(last_song_, cover_url, image);
|
||||
|
@ -1153,10 +1153,7 @@ void QobuzRequest::AlbumCoverReceived(QNetworkReply *reply, const QUrl &cover_ur
|
||||
if (image.save(filename, "JPG")) {
|
||||
while (album_covers_requests_sent_.contains(cover_url)) {
|
||||
Song *song = album_covers_requests_sent_.take(cover_url);
|
||||
QUrl cover_url;
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(filename);
|
||||
song->set_art_automatic(cover_url);
|
||||
song->set_art_automatic(QUrl::fromLocalFile(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -649,10 +649,7 @@ void SubsonicRequest::AlbumCoverReceived(QNetworkReply *reply, const QString &al
|
||||
if (image.save(filename, "JPG")) {
|
||||
while (album_covers_requests_sent_.contains(album_id)) {
|
||||
Song *song = album_covers_requests_sent_.take(album_id);
|
||||
QUrl cover_url;
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(filename);
|
||||
song->set_art_automatic(cover_url);
|
||||
song->set_art_automatic(QUrl::fromLocalFile(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1092,10 +1092,7 @@ void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const QString &album
|
||||
if (image.save(filename, "JPG")) {
|
||||
while (album_covers_requests_sent_.contains(album_id)) {
|
||||
Song *song = album_covers_requests_sent_.take(album_id);
|
||||
QUrl cover_url;
|
||||
cover_url.setScheme("file");
|
||||
cover_url.setPath(filename);
|
||||
song->set_art_automatic(cover_url);
|
||||
song->set_art_automatic(QUrl::fromLocalFile(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user