Add support for saving embedded album covers

Fixes #286
This commit is contained in:
Jonas Kvinge
2021-02-26 21:03:51 +01:00
parent e4c89c1aed
commit 133f094d72
79 changed files with 3509 additions and 1804 deletions

View File

@@ -393,7 +393,7 @@ bool Playlist::setData(const QModelIndex &idx, const QVariant &value, int role)
TagReaderReply *reply = TagReaderClient::Instance()->SaveFile(song.url().toLocalFile(), song);
QPersistentModelIndex persistent_index = QPersistentModelIndex(idx);
QObject::connect(reply, &TagReaderReply::Finished, this, [this, reply, persistent_index]() { SongSaveComplete(reply, persistent_index); });
QObject::connect(reply, &TagReaderReply::Finished, this, [this, reply, persistent_index]() { SongSaveComplete(reply, persistent_index); }, Qt::QueuedConnection);
return true;
@@ -418,7 +418,8 @@ void Playlist::SongSaveComplete(TagReaderReply *reply, const QPersistentModelInd
emit Error(tr("An error occurred writing metadata to '%1'").arg(QString::fromStdString(reply->request_message().save_file_request().filename())));
}
}
reply->deleteLater();
metaObject()->invokeMethod(reply, "deleteLater", Qt::QueuedConnection);
}
@@ -755,7 +756,7 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
else if (const PlaylistItemMimeData *item_data = qobject_cast<const PlaylistItemMimeData*>(data)) {
InsertItems(item_data->items_, row, play_now, enqueue_now, enqueue_next_now);
}
else if (const InternetSongMimeData* internet_song_data = qobject_cast<const InternetSongMimeData*>(data)) {
else if (const InternetSongMimeData *internet_song_data = qobject_cast<const InternetSongMimeData*>(data)) {
InsertInternetItems(internet_song_data->service, internet_song_data->songs, row, play_now, enqueue_now, enqueue_next_now);
}
else if (const PlaylistGeneratorMimeData *generator_data = qobject_cast<const PlaylistGeneratorMimeData*>(data)) {
@@ -2186,11 +2187,11 @@ void Playlist::UpdateScrobblePoint(const qint64 seek_point_nanosec) {
void Playlist::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &result) {
// Update art_manual for local songs that are not in the collection.
if (((result.type == AlbumCoverLoaderResult::Type_Manual && result.cover_url.isLocalFile()) || result.type == AlbumCoverLoaderResult::Type_ManuallyUnset) && (song.source() == Song::Source_LocalFile || song.source() == Song::Source_CDDA || song.source() == Song::Source_Device)) {
if (((result.type == AlbumCoverLoaderResult::Type_Manual && result.album_cover.cover_url.isLocalFile()) || result.type == AlbumCoverLoaderResult::Type_ManuallyUnset) && (song.source() == Song::Source_LocalFile || song.source() == Song::Source_CDDA || song.source() == Song::Source_Device)) {
PlaylistItemPtr item = current_item();
if (item && item->Metadata() == song && (!item->Metadata().art_manual_is_valid() || (result.type == AlbumCoverLoaderResult::Type_ManuallyUnset && !item->Metadata().has_manually_unset_cover()))) {
qLog(Debug) << "Updating art manual for local song" << song.title() << song.album() << song.title() << "to" << result.cover_url << "in playlist.";
item->SetArtManual(result.cover_url);
qLog(Debug) << "Updating art manual for local song" << song.title() << song.album() << song.title() << "to" << result.album_cover.cover_url << "in playlist.";
item->SetArtManual(result.album_cover.cover_url);
Save();
}
}

View File

@@ -600,15 +600,20 @@ void PlaylistView::StartGlowing() {
}
void PlaylistView::hideEvent(QHideEvent *) { glow_timer_.stop(); }
void PlaylistView::hideEvent(QHideEvent *e) {
glow_timer_.stop();
QTreeView::hideEvent(e);
}
void PlaylistView::showEvent(QShowEvent *) {
void PlaylistView::showEvent(QShowEvent *e) {
if (currently_glowing_ && glow_enabled_)
glow_timer_.start(1500 / kGlowIntensitySteps, this);
MaybeAutoscroll(Playlist::AutoScroll_Maybe);
QTreeView::showEvent(e);
}
namespace {
@@ -1087,6 +1092,8 @@ void PlaylistView::paintEvent(QPaintEvent *event) {
p.setPen(line_pen);
p.drawLine(QPoint(0, drop_pos), QPoint(width(), drop_pos));
QTreeView::paintEvent(event);
}
void PlaylistView::dragMoveEvent(QDragMoveEvent *event) {
@@ -1260,6 +1267,7 @@ void PlaylistView::StretchChanged(const bool stretch) {
void PlaylistView::resizeEvent(QResizeEvent *e) {
QTreeView::resizeEvent(e);
if (dynamic_controls_->isVisible()) {
RepositionDynamicControls();
}
@@ -1379,9 +1387,9 @@ void PlaylistView::Stopped() {
void PlaylistView::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResult result) {
if ((song != Song() && song_playing_ == Song()) || result.image_original == current_song_cover_art_) return;
if ((song != Song() && song_playing_ == Song()) || result.album_cover.image == current_song_cover_art_) return;
current_song_cover_art_ = result.image_original;
current_song_cover_art_ = result.album_cover.image;
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Album) {
if (song.art_automatic().isEmpty() && song.art_manual().isEmpty()) {
set_background_image(QImage());

View File

@@ -29,7 +29,7 @@
#include "playlistitem.h"
#include "songplaylistitem.h"
SongPlaylistItem::SongPlaylistItem(const Song::Source &source) : PlaylistItem(source) {}
SongPlaylistItem::SongPlaylistItem(const Song::Source source) : PlaylistItem(source) {}
SongPlaylistItem::SongPlaylistItem(const Song &song) : PlaylistItem(song.source()), song_(song) {}
bool SongPlaylistItem::InitFromQuery(const SqlRow &query) {

View File

@@ -32,12 +32,12 @@
class SongPlaylistItem : public PlaylistItem {
public:
explicit SongPlaylistItem(const Song::Source &source);
explicit SongPlaylistItem(const Song::Source source);
explicit SongPlaylistItem(const Song &song);
// Restores a stream- or file-related playlist item using query row.
// If it's a file related playlist item, this will restore it's CUE attributes (if any) but won't parse the CUE!
bool InitFromQuery(const SqlRow& query) override;
bool InitFromQuery(const SqlRow &query) override;
void Reload() override;
Song Metadata() const override;