diff --git a/src/collection/collectionbackend.cpp b/src/collection/collectionbackend.cpp index 39da069a6..6f127784a 100644 --- a/src/collection/collectionbackend.cpp +++ b/src/collection/collectionbackend.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/src/collection/collectionwatcher.cpp b/src/collection/collectionwatcher.cpp index 8df3b77cf..e167348df 100644 --- a/src/collection/collectionwatcher.cpp +++ b/src/collection/collectionwatcher.cpp @@ -737,18 +737,12 @@ QUrl CollectionWatcher::ImageForSong(const QString &path, QMapcomment_ = 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_); diff --git a/src/covermanager/albumcoverchoicecontroller.cpp b/src/covermanager/albumcoverchoicecontroller.cpp index fa9f3ab49..42d9854e0 100644 --- a/src/covermanager/albumcoverchoicecontroller.cpp +++ b/src/covermanager/albumcoverchoicecontroller.cpp @@ -22,6 +22,8 @@ #include "config.h" #include +#include +#include #include #include #include @@ -43,7 +45,6 @@ #include #include #include -#include #include #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) { diff --git a/src/covermanager/albumcovermanager.cpp b/src/covermanager/albumcovermanager.cpp index caaa12946..bb5d817ce 100644 --- a/src/covermanager/albumcovermanager.cpp +++ b/src/covermanager/albumcovermanager.cpp @@ -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_; } diff --git a/src/covermanager/currentalbumcoverloader.cpp b/src/covermanager/currentalbumcoverloader.cpp index baf142e81..08a64a68a 100644 --- a/src/covermanager/currentalbumcoverloader.cpp +++ b/src/covermanager/currentalbumcoverloader.cpp @@ -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); diff --git a/src/qobuz/qobuzrequest.cpp b/src/qobuz/qobuzrequest.cpp index 920d6ca26..cfb13a03a 100644 --- a/src/qobuz/qobuzrequest.cpp +++ b/src/qobuz/qobuzrequest.cpp @@ -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)); } } diff --git a/src/subsonic/subsonicrequest.cpp b/src/subsonic/subsonicrequest.cpp index 25c7cb339..c30093471 100644 --- a/src/subsonic/subsonicrequest.cpp +++ b/src/subsonic/subsonicrequest.cpp @@ -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)); } } } diff --git a/src/tidal/tidalrequest.cpp b/src/tidal/tidalrequest.cpp index c32291c00..6ad1816a1 100644 --- a/src/tidal/tidalrequest.cpp +++ b/src/tidal/tidalrequest.cpp @@ -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)); } }