Stop scanning the library straight away if we're asked to quit. Fixes issue #114
This commit is contained in:
parent
95252ccc71
commit
088d298c7d
@ -24,6 +24,7 @@ const char* AlbumCoverLoader::kManuallyUnsetCover = "(unset)";
|
||||
|
||||
AlbumCoverLoader::AlbumCoverLoader(QObject* parent)
|
||||
: QObject(parent),
|
||||
stop_requested_(false),
|
||||
height_(120),
|
||||
next_id_(0)
|
||||
{
|
||||
@ -58,6 +59,8 @@ quint64 AlbumCoverLoader::LoadImageAsync(const QString& art_automatic,
|
||||
|
||||
void AlbumCoverLoader::ProcessTasks() {
|
||||
forever {
|
||||
if (stop_requested_) return;
|
||||
|
||||
// Get the next task
|
||||
Task task;
|
||||
{
|
||||
|
@ -29,6 +29,8 @@ class AlbumCoverLoader : public QObject {
|
||||
|
||||
public:
|
||||
AlbumCoverLoader(QObject* parent = 0);
|
||||
|
||||
void Stop() { stop_requested_ = true; }
|
||||
|
||||
static QString ImageCacheDir();
|
||||
|
||||
@ -55,6 +57,8 @@ class AlbumCoverLoader : public QObject {
|
||||
QString art_manual;
|
||||
};
|
||||
|
||||
bool stop_requested_;
|
||||
|
||||
int height_;
|
||||
|
||||
QMutex mutex_;
|
||||
|
@ -137,6 +137,9 @@ BackgroundThread<InterfaceType>::BackgroundThread(QObject *parent)
|
||||
template <typename InterfaceType>
|
||||
BackgroundThread<InterfaceType>::~BackgroundThread() {
|
||||
if (isRunning()) {
|
||||
if (worker_) // Possible race condition here
|
||||
worker_->Stop();
|
||||
|
||||
quit();
|
||||
if (wait(10000))
|
||||
return;
|
||||
|
@ -52,6 +52,8 @@ class LibraryBackendInterface : public QObject {
|
||||
};
|
||||
typedef QList<Album> AlbumList;
|
||||
|
||||
virtual void Stop() {};
|
||||
|
||||
// Get a list of directories in the library. Emits DirectoriesDiscovered.
|
||||
virtual void LoadDirectoriesAsync() = 0;
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
LibraryWatcher::LibraryWatcher(QObject* parent)
|
||||
: QObject(parent),
|
||||
stop_requested_(false),
|
||||
fs_watcher_(new QFileSystemWatcher(this)),
|
||||
rescan_timer_(new QTimer(this)),
|
||||
total_watches_(0)
|
||||
@ -47,8 +48,10 @@ void LibraryWatcher::AddDirectories(const DirectoryList& directories) {
|
||||
// could be music.
|
||||
|
||||
foreach (const Directory& dir, directories) {
|
||||
if (stop_requested_) return;
|
||||
paths_watched_[dir.path] = dir;
|
||||
ScanDirectory(dir.path);
|
||||
if (stop_requested_) return;
|
||||
|
||||
// Start monitoring this directory for more changes
|
||||
fs_watcher_->addPath(dir.path);
|
||||
@ -118,6 +121,8 @@ void LibraryWatcher::ScanDirectory(const QString& path) {
|
||||
album_art[dir] << path;
|
||||
else if (engine_->canDecode(QUrl::fromLocalFile(path)))
|
||||
files_on_disk << path;
|
||||
|
||||
if (stop_requested_) return;
|
||||
}
|
||||
|
||||
// Ask the database for a list of files in this directory
|
||||
@ -127,6 +132,8 @@ void LibraryWatcher::ScanDirectory(const QString& path) {
|
||||
SongList new_songs;
|
||||
SongList touched_songs;
|
||||
foreach (const QString& file, files_on_disk) {
|
||||
if (stop_requested_) return;
|
||||
|
||||
Song matching_song;
|
||||
if (FindSongByPath(songs_in_db, file, &matching_song)) {
|
||||
// The song is in the database and still on disk.
|
||||
@ -185,6 +192,8 @@ void LibraryWatcher::ScanDirectory(const QString& path) {
|
||||
}
|
||||
}
|
||||
|
||||
if (stop_requested_) return;
|
||||
|
||||
if (!new_songs.isEmpty())
|
||||
emit NewOrUpdatedSongs(new_songs);
|
||||
|
||||
@ -200,6 +209,8 @@ void LibraryWatcher::ScanDirectory(const QString& path) {
|
||||
}
|
||||
}
|
||||
|
||||
if (stop_requested_) return;
|
||||
|
||||
if (!deleted_songs.isEmpty())
|
||||
emit SongsDeleted(deleted_songs);
|
||||
|
||||
@ -226,8 +237,11 @@ void LibraryWatcher::DirectoryChanged(const QString &path) {
|
||||
}
|
||||
|
||||
void LibraryWatcher::RescanPathsNow() {
|
||||
foreach (const QString& path, paths_needing_rescan_)
|
||||
foreach (const QString& path, paths_needing_rescan_) {
|
||||
if (stop_requested_) return;
|
||||
ScanDirectory(path);
|
||||
}
|
||||
|
||||
paths_needing_rescan_.clear();
|
||||
|
||||
qDebug() << "Updating compilations...";
|
||||
|
@ -41,6 +41,8 @@ class LibraryWatcher : public QObject {
|
||||
void SetBackend(boost::shared_ptr<LibraryBackendInterface> backend) { backend_ = backend; }
|
||||
void SetEngine(EngineBase* engine) { engine_ = engine; } // TODO: shared_ptr
|
||||
|
||||
void Stop() { stop_requested_ = true; }
|
||||
|
||||
signals:
|
||||
void NewOrUpdatedSongs(const SongList& songs);
|
||||
void SongsMTimeUpdated(const SongList& songs);
|
||||
@ -68,6 +70,7 @@ class LibraryWatcher : public QObject {
|
||||
private:
|
||||
EngineBase* engine_;
|
||||
boost::shared_ptr<LibraryBackendInterface> backend_;
|
||||
bool stop_requested_;
|
||||
|
||||
QFileSystemWatcher* fs_watcher_;
|
||||
QTimer* rescan_timer_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user