Organize: Update collection directory ID and song path immediately

Fixes #781
This commit is contained in:
Jonas Kvinge 2021-09-27 19:29:12 +02:00
parent 62e53b53f0
commit 8c6ad52437
8 changed files with 24 additions and 8 deletions

View File

@ -21,6 +21,8 @@
#include "config.h"
#include <optional>
#include <QtGlobal>
#include <QObject>
#include <QApplication>
@ -429,7 +431,7 @@ SongList CollectionBackend::SongsWithMissingFingerprint(const int id) {
}
void CollectionBackend::SongPathChanged(const Song &song, const QFileInfo &new_file) {
void CollectionBackend::SongPathChanged(const Song &song, const QFileInfo &new_file, const std::optional<int> new_collection_directory_id) {
// Take a song and update its path
Song updated_song = song;
@ -437,6 +439,9 @@ void CollectionBackend::SongPathChanged(const Song &song, const QFileInfo &new_f
updated_song.set_url(QUrl::fromLocalFile(new_file.absoluteFilePath()));
updated_song.set_basefilename(new_file.fileName());
updated_song.InitArtManual();
if (updated_song.is_collection_song() && new_collection_directory_id) {
updated_song.set_directory_id(new_collection_directory_id.value());
}
AddOrUpdateSongs(SongList() << updated_song);

View File

@ -24,6 +24,8 @@
#include "config.h"
#include <optional>
#include <QtGlobal>
#include <QObject>
#include <QFileInfo>
@ -228,7 +230,7 @@ class CollectionBackend : public CollectionBackendInterface {
void IncrementPlayCount(const int id);
void IncrementSkipCount(const int id, const float progress);
void ResetStatistics(const int id);
void SongPathChanged(const Song &song, const QFileInfo &new_file);
void SongPathChanged(const Song &song, const QFileInfo &new_file, const std::optional<int> new_collection_directory_id);
SongList GetSongsBy(const QString &artist, const QString &album, const QString &title);
void UpdateLastPlayed(const QString &artist, const QString &album, const QString &title, const qint64 lastplayed);

View File

@ -51,7 +51,7 @@ void CollectionDirectoryModel::DirectoryDiscovered(const Directory &dir) {
QStandardItem *item = new QStandardItem(dir.path);
item->setData(dir.id, kIdRole);
item->setIcon(dir_icon_);
storage_ << std::make_shared<FilesystemMusicStorage>(dir.path);
storage_ << std::make_shared<FilesystemMusicStorage>(dir.path, dir.id);
appendRow(item);
}

View File

@ -21,6 +21,8 @@
#include "config.h"
#include <optional>
#include <QDir>
#include <QFile>
#include <QFileInfo>
@ -35,7 +37,7 @@
#include "filesystemmusicstorage.h"
FilesystemMusicStorage::FilesystemMusicStorage(const QString &root) : root_(root) {}
FilesystemMusicStorage::FilesystemMusicStorage(const QString &root, const std::optional<int> collection_directory_id) : root_(root), collection_directory_id_(collection_directory_id) {}
bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {

View File

@ -24,21 +24,25 @@
#include "config.h"
#include <optional>
#include <QString>
#include "musicstorage.h"
class FilesystemMusicStorage : public virtual MusicStorage {
public:
explicit FilesystemMusicStorage(const QString &root);
explicit FilesystemMusicStorage(const QString &root, const std::optional<int> collection_directory_id = std::optional<int>());
QString LocalPath() const override { return root_; }
std::optional<int> collection_directory_id() const { return collection_directory_id_; }
bool CopyToStorage(const CopyJob &job) override;
bool DeleteFromStorage(const DeleteJob &job) override;
private:
QString root_;
std::optional<int> collection_directory_id_;
Q_DISABLE_COPY(FilesystemMusicStorage)
};

View File

@ -28,6 +28,7 @@
#include <functional>
#include <memory>
#include <optional>
#include <QMetaType>
#include <QString>
@ -78,6 +79,7 @@ class MusicStorage {
};
virtual QString LocalPath() const { return QString(); }
virtual std::optional<int> collection_directory_id() const { return std::optional<int>(); }
virtual TranscodeMode GetTranscodeMode() const { return Transcode_Never; }
virtual Song::FileType GetTranscodeFormat() const { return Song::FileType_Unknown; }

View File

@ -256,11 +256,11 @@ void Organize::ProcessSomeFiles() {
files_with_errors_ << task.song_info_.song_.basefilename();
}
else {
if (job.remove_original_ && song.source() == Song::Source_Device) {
if (job.remove_original_) {
// Notify other aspects of system that song has been invalidated
QString root = destination_->LocalPath();
QFileInfo new_file = QFileInfo(root + "/" + task.song_info_.new_filename_);
emit SongPathChanged(song, new_file);
emit SongPathChanged(song, new_file, destination_->collection_directory_id());
}
if (job.mark_as_listened_) {
emit FileCopied(job.metadata_.id());

View File

@ -25,6 +25,7 @@
#include "config.h"
#include <memory>
#include <optional>
#include <QObject>
#include <QBasicTimer>
@ -73,7 +74,7 @@ class Organize : public QObject {
signals:
void Finished(QStringList files_with_errors, QStringList);
void FileCopied(int database_id);
void SongPathChanged(Song song, QFileInfo new_file);
void SongPathChanged(Song song, QFileInfo new_file, std::optional<int> new_collection_directory_id);
protected:
void timerEvent(QTimerEvent *e) override;