Improve handling of song source
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "core/thread.h"
|
||||
#include "core/utilities.h"
|
||||
#include "core/song.h"
|
||||
#include "collection.h"
|
||||
#include "collectionwatcher.h"
|
||||
#include "collectionbackend.h"
|
||||
@@ -51,7 +52,7 @@ SCollection::SCollection(Application *app, QObject *parent)
|
||||
watcher_(nullptr),
|
||||
watcher_thread_(nullptr) {
|
||||
|
||||
backend_ = new CollectionBackend;
|
||||
backend_ = new CollectionBackend();
|
||||
backend()->moveToThread(app->database()->thread());
|
||||
|
||||
backend_->Init(app->database(), kSongsTable, kDirsTable, kSubdirsTable, kFtsTable);
|
||||
@@ -71,7 +72,7 @@ SCollection::~SCollection() {
|
||||
|
||||
void SCollection::Init() {
|
||||
|
||||
watcher_ = new CollectionWatcher;
|
||||
watcher_ = new CollectionWatcher(Song::Source_Collection);
|
||||
watcher_thread_ = new Thread(this);
|
||||
watcher_thread_->SetIoPriority(Utilities::IOPRIO_CLASS_IDLE);
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
|
||||
class SqlRow;
|
||||
|
||||
CollectionPlaylistItem::CollectionPlaylistItem(const Song::Source &source)
|
||||
: PlaylistItem(source) {}
|
||||
CollectionPlaylistItem::CollectionPlaylistItem() : PlaylistItem(Song::Source_Collection) {
|
||||
song_.set_source(Song::Source_Collection);
|
||||
}
|
||||
|
||||
CollectionPlaylistItem::CollectionPlaylistItem(const Song &song)
|
||||
: PlaylistItem(Song::Source_Collection), song_(song) {
|
||||
CollectionPlaylistItem::CollectionPlaylistItem(const Song &song) : PlaylistItem(Song::Source_Collection), song_(song) {
|
||||
song_.set_source(Song::Source_Collection);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ void CollectionPlaylistItem::Reload() {
|
||||
bool CollectionPlaylistItem::InitFromQuery(const SqlRow &query) {
|
||||
// Rows from the songs tables come first
|
||||
song_.InitFromQuery(query, true);
|
||||
song_.set_source(Song::Source_Collection);
|
||||
return song_.is_valid();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SqlRow;
|
||||
|
||||
class CollectionPlaylistItem : public PlaylistItem {
|
||||
public:
|
||||
CollectionPlaylistItem(const Song::Source &source);
|
||||
CollectionPlaylistItem();
|
||||
CollectionPlaylistItem(const Song &song);
|
||||
|
||||
bool InitFromQuery(const SqlRow &query);
|
||||
@@ -51,6 +51,7 @@ class CollectionPlaylistItem : public PlaylistItem {
|
||||
|
||||
protected:
|
||||
QVariant DatabaseValue(DatabaseColumn column) const;
|
||||
Song DatabaseSongMetadata() const { return Song(Song::Source_Collection); }
|
||||
|
||||
protected:
|
||||
Song song_;
|
||||
|
||||
@@ -59,13 +59,14 @@
|
||||
|
||||
namespace {
|
||||
static const char *kNoMediaFile = ".nomedia";
|
||||
static const char *kNoMusicFile = ".nomusic";
|
||||
static const char *kNoMusicFile = ".nomusic";
|
||||
}
|
||||
|
||||
QStringList CollectionWatcher::sValidImages;
|
||||
|
||||
CollectionWatcher::CollectionWatcher(QObject *parent)
|
||||
CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent)
|
||||
: QObject(parent),
|
||||
source_(source),
|
||||
backend_(nullptr),
|
||||
task_manager_(nullptr),
|
||||
fs_watcher_(FileSystemWatcherInterface::Create(this)),
|
||||
@@ -387,7 +388,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory
|
||||
QString image = ImageForSong(file, album_art);
|
||||
|
||||
for (Song song : song_list) {
|
||||
song.set_source(Song::Source_Collection);
|
||||
song.set_source(source_);
|
||||
song.set_directory_id(t->dir());
|
||||
if (song.art_automatic().isEmpty()) song.set_art_automatic(image);
|
||||
t->new_songs << song;
|
||||
@@ -441,7 +442,7 @@ void CollectionWatcher::UpdateCueAssociatedSongs(const QString &file, const QStr
|
||||
|
||||
// Update every song that's in the cue and collection
|
||||
for (Song cue_song : cue_parser_->Load(&cue, matching_cue, path)) {
|
||||
cue_song.set_source(Song::Source_Collection);
|
||||
cue_song.set_source(source_);
|
||||
cue_song.set_directory_id(t->dir());
|
||||
|
||||
Song matching = sections_map[cue_song.beginning_nanosec()];
|
||||
@@ -477,7 +478,7 @@ void CollectionWatcher::UpdateNonCueAssociatedSong(const QString &file, const So
|
||||
}
|
||||
|
||||
Song song_on_disk;
|
||||
song_on_disk.set_source(Song::Source_Collection);
|
||||
song_on_disk.set_source(source_);
|
||||
song_on_disk.set_directory_id(t->dir());
|
||||
TagReaderClient::Instance()->ReadFileBlocking(file, &song_on_disk);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class CollectionWatcher : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CollectionWatcher(QObject *parent = nullptr);
|
||||
CollectionWatcher(Song::Source source, QObject *parent = nullptr);
|
||||
|
||||
void set_backend(CollectionBackend *backend) { backend_ = backend; }
|
||||
void set_task_manager(TaskManager *task_manager) { task_manager_ = task_manager; }
|
||||
@@ -162,6 +162,7 @@ signals:
|
||||
SongList ScanNewFile(const QString &file, const QString &path, const QString &matching_cue, QSet<QString> *cues_processed);
|
||||
|
||||
private:
|
||||
Song::Source source_;
|
||||
CollectionBackend *backend_;
|
||||
TaskManager *task_manager_;
|
||||
QString device_name_;
|
||||
|
||||
Reference in New Issue
Block a user