diff --git a/src/core/filesystemmusicstorage.cpp b/src/core/filesystemmusicstorage.cpp index 7c63b70ca..2b836e7ce 100644 --- a/src/core/filesystemmusicstorage.cpp +++ b/src/core/filesystemmusicstorage.cpp @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,6 +45,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) { const QFileInfo src = QFileInfo(job.source_); const QFileInfo dest = QFileInfo(root_ + "/" + job.destination_); + QFileInfo cover_src; + QFileInfo cover_dest; + if (job.albumcover_ && !job.cover_source_.isEmpty() && !job.cover_dest_.isEmpty()) { + cover_src = QFileInfo(job.cover_source_); + cover_dest = QFileInfo(root_ + "/" + job.cover_dest_); + } + // Don't do anything if the destination is the same as the source if (src == dest) return true; @@ -55,13 +63,29 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) { } // Remove the destination file if it exists and we want to overwrite - if (job.overwrite_ && dest.exists()) QFile::remove(dest.absoluteFilePath()); + if (job.overwrite_) { + if (dest.exists()) QFile::remove(dest.absoluteFilePath()); + if (!cover_dest.filePath().isEmpty() && cover_dest.exists()) QFile::remove(cover_dest.absoluteFilePath()); + } // Copy or move - if (job.remove_original_) - return QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath()); - else - return QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath()); + bool result(true); + if (job.remove_original_) { + result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath()); + if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) { + QFile::rename(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath()); + } + } + else { + if (!dest.exists()) { + result = QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath()); + } + if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty() && !cover_dest.exists()) { + QFile::copy(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath()); + } + } + + return result; } @@ -76,4 +100,3 @@ bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) { return QFile::remove(path); } - diff --git a/src/core/filesystemmusicstorage.h b/src/core/filesystemmusicstorage.h index b8c0dac3a..4921d0d4a 100644 --- a/src/core/filesystemmusicstorage.h +++ b/src/core/filesystemmusicstorage.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,4 +44,3 @@ private: }; #endif // FILESYSTEMMUSICSTORAGE_H - diff --git a/src/core/musicstorage.cpp b/src/core/musicstorage.cpp index bf7e3b695..16dc284c0 100644 --- a/src/core/musicstorage.cpp +++ b/src/core/musicstorage.cpp @@ -20,6 +20,4 @@ #include "musicstorage.h" -MusicStorage::MusicStorage() -{ -} +MusicStorage::MusicStorage() {} diff --git a/src/core/musicstorage.h b/src/core/musicstorage.h index 05b2dbd02..047ded76b 100644 --- a/src/core/musicstorage.h +++ b/src/core/musicstorage.h @@ -61,6 +61,9 @@ class MusicStorage { bool overwrite_; bool mark_as_listened_; bool remove_original_; + bool albumcover_; + QString cover_source_; + QString cover_dest_; ProgressFunction progress_; }; diff --git a/src/device/devicemanager.cpp b/src/device/devicemanager.cpp index fdfa7cda0..4ec6534cb 100644 --- a/src/device/devicemanager.cpp +++ b/src/device/devicemanager.cpp @@ -135,12 +135,12 @@ DeviceManager::DeviceManager(Application *app, QObject *parent) AddLister(new iLister); #endif - AddDeviceClass(); - #if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER) AddDeviceClass(); #endif + AddDeviceClass(); + #ifdef HAVE_LIBGPOD AddDeviceClass(); #endif diff --git a/src/device/gpoddevice.cpp b/src/device/gpoddevice.cpp index 41343fca5..68bcb31b9 100644 --- a/src/device/gpoddevice.cpp +++ b/src/device/gpoddevice.cpp @@ -146,26 +146,27 @@ bool GPodDevice::CopyToStorage(const CopyJob &job) { Itdb_Track *track = AddTrackToITunesDb(job.metadata_); - bool result(false); - if (!job.metadata_.image().isNull()) { + if (job.albumcover_) { + bool result = false; + if (!job.metadata_.image().isNull()) { #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().sizeInBytes()); + result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().sizeInBytes()); + track->has_artwork = 1; #else - result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().byteCount()); + result = itdb_track_set_thumbnails_from_data(track, job.metadata_.image().constBits(), job.metadata_.image().byteCount()); + track->has_artwork = 1; #endif - } - else if (!job.metadata_.art_manual().isEmpty()) { - result = itdb_track_set_thumbnails(track, QDir::toNativeSeparators(job.metadata_.art_manual()).toLocal8Bit().constData()); - } - else if (!job.metadata_.art_automatic().isEmpty()) { - result = itdb_track_set_thumbnails(track, QDir::toNativeSeparators(job.metadata_.art_automatic()).toLocal8Bit().constData()); - } - if (result) { - track->has_artwork = 1; - } - else { - track->has_artwork = 0; - qLog(Error) << "failed to set album cover image"; + } + else if (!job.cover_source_.isEmpty()) { + result = itdb_track_set_thumbnails(track, job.cover_source_.toLocal8Bit().constData()); + track->has_artwork = 1; + } + else { + result = true; + } + if (!result) { + qLog(Error) << "failed to set album cover image"; + } } // Copy the file diff --git a/src/organise/organise.cpp b/src/organise/organise.cpp index 884e8832b..28381273a 100644 --- a/src/organise/organise.cpp +++ b/src/organise/organise.cpp @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,7 +51,7 @@ const int Organise::kBatchSize = 10; const int Organise::kTranscodeProgressInterval = 500; #endif -Organise::Organise(TaskManager *task_manager, std::shared_ptr destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, const NewSongInfoList &songs_info, bool eject_after) +Organise::Organise(TaskManager *task_manager, std::shared_ptr destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, bool albumcover, const NewSongInfoList &songs_info, bool eject_after) : thread_(nullptr), task_manager_(task_manager), #ifdef HAVE_GSTREAMER @@ -61,6 +62,7 @@ Organise::Organise(TaskManager *task_manager, std::shared_ptr dest copy_(copy), overwrite_(overwrite), mark_as_listened_(mark_as_listened), + albumcover_(albumcover), eject_after_(eject_after), task_count_(songs_info.count()), tasks_complete_(0), @@ -195,7 +197,19 @@ void Organise::ProcessSomeFiles() { job.metadata_ = song; job.overwrite_ = overwrite_; job.mark_as_listened_ = mark_as_listened_; + job.albumcover_ = albumcover_; job.remove_original_ = !copy_; + + if (!task.song_info_.song_.art_manual().isEmpty()) { + job.cover_source_ = task.song_info_.song_.art_manual(); + } + else if (!task.song_info_.song_.art_automatic().isEmpty()) { + job.cover_source_ = task.song_info_.song_.art_automatic(); + } + if (!job.cover_source_.isEmpty()) { + job.cover_dest_ = QFileInfo(job.destination_).path() + "/" + QFileInfo(job.cover_source_).fileName(); + } + job.progress_ = std::bind(&Organise::SetSongProgress, this, _1, !task.transcoded_filename_.isEmpty()); if (!destination_->CopyToStorage(job)) { diff --git a/src/organise/organise.h b/src/organise/organise.h index 7fe32c65c..2dfa3a326 100644 --- a/src/organise/organise.h +++ b/src/organise/organise.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,7 +60,7 @@ class Organise : public QObject { }; typedef QList NewSongInfoList; - Organise(TaskManager *task_manager, std::shared_ptr destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, const NewSongInfoList &songs, bool eject_after); + Organise(TaskManager *task_manager, std::shared_ptr destination, const OrganiseFormat &format, bool copy, bool overwrite, bool mark_as_listened, bool albumcover, const NewSongInfoList &songs, bool eject_after); static const int kBatchSize; #ifdef HAVE_GSTREAMER @@ -116,6 +117,7 @@ class Organise : public QObject { const bool copy_; const bool overwrite_; const bool mark_as_listened_; + const bool albumcover_; const bool eject_after_; int task_count_; diff --git a/src/organise/organisedialog.cpp b/src/organise/organisedialog.cpp index 1a40bbfd4..3a2de93a9 100644 --- a/src/organise/organisedialog.cpp +++ b/src/organise/organisedialog.cpp @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -250,6 +251,7 @@ Organise::NewSongInfoList OrganiseDialog::ComputeNewSongsFilenames(const SongLis for (const Song &song : songs) { QString new_filename = format.GetFilenameForSong(song); + //QString new_cover_filename = format.GetCoverFilenameForSong(song); if (filenames.contains(new_filename)) { QString song_number = QString::number(++filenames[new_filename]); new_filename = Utilities::PathWithoutFilenameExtension(new_filename) + "(" + song_number + ")." + QFileInfo(new_filename).suffix(); @@ -335,6 +337,7 @@ void OrganiseDialog::Reset() { ui_->replace_spaces->setChecked(true); ui_->overwrite->setChecked(false); ui_->mark_as_listened->setChecked(false); + ui_->albumcover->setChecked(true); ui_->eject_after->setChecked(false); } @@ -350,6 +353,7 @@ void OrganiseDialog::showEvent(QShowEvent*) { ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool()); ui_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool()); ui_->overwrite->setChecked(s.value("overwrite", false).toBool()); + ui_->albumcover->setChecked(s.value("albumcover", true).toBool()); ui_->mark_as_listened->setChecked(s.value("mark_as_listened", false).toBool()); ui_->eject_after->setChecked(s.value("eject_after", false).toBool()); @@ -372,6 +376,7 @@ void OrganiseDialog::accept() { s.setValue("replace_spaces", ui_->replace_spaces->isChecked()); s.setValue("overwrite", ui_->overwrite->isChecked()); s.setValue("mark_as_listened", ui_->overwrite->isChecked()); + s.setValue("albumcover", ui_->albumcover->isChecked()); s.setValue("destination", ui_->destination->currentText()); s.setValue("eject_after", ui_->eject_after->isChecked()); @@ -382,7 +387,7 @@ void OrganiseDialog::accept() { // It deletes itself when it's finished. const bool copy = ui_->aftercopying->currentIndex() == 0; - Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), new_songs_info_, ui_->eject_after->isChecked()); + Organise *organise = new Organise(task_manager_, storage, format_, copy, ui_->overwrite->isChecked(), ui_->mark_as_listened->isChecked(), ui_->albumcover->isChecked(), new_songs_info_, ui_->eject_after->isChecked()); connect(organise, SIGNAL(Finished(QStringList, QStringList)), SLOT(OrganiseFinished(QStringList, QStringList))); connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int))); organise->Start(); diff --git a/src/organise/organisedialog.h b/src/organise/organisedialog.h index 164d75d1c..ce0e4d7c7 100644 --- a/src/organise/organisedialog.h +++ b/src/organise/organisedialog.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/organise/organisedialog.ui b/src/organise/organisedialog.ui index dfef70fca..e2bf33c14 100644 --- a/src/organise/organisedialog.ui +++ b/src/organise/organisedialog.ui @@ -126,6 +126,13 @@ + + + + Copy album cover artwork + + + diff --git a/src/organise/organiseerrordialog.cpp b/src/organise/organiseerrordialog.cpp index fd61a0cae..39d053061 100644 --- a/src/organise/organiseerrordialog.cpp +++ b/src/organise/organiseerrordialog.cpp @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/organise/organiseerrordialog.h b/src/organise/organiseerrordialog.h index 396428d6a..5448811f3 100644 --- a/src/organise/organiseerrordialog.h +++ b/src/organise/organiseerrordialog.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by