Make marking songs unavailable optional

This commit is contained in:
Jonas Kvinge 2019-08-11 22:30:28 +02:00
parent 79d963fd65
commit 42e7f64856
6 changed files with 36 additions and 28 deletions

View File

@ -97,7 +97,8 @@ void SCollection::Init() {
connect(backend_, SIGNAL(DirectoryDeleted(Directory)), watcher_, SLOT(RemoveDirectory(Directory)));
connect(watcher_, SIGNAL(NewOrUpdatedSongs(SongList)), backend_, SLOT(AddOrUpdateSongs(SongList)));
connect(watcher_, SIGNAL(SongsMTimeUpdated(SongList)), backend_, SLOT(UpdateMTimesOnly(SongList)));
connect(watcher_, SIGNAL(SongsDeleted(SongList)), backend_, SLOT(MarkSongsUnavailable(SongList)));
connect(watcher_, SIGNAL(SongsDeleted(SongList)), backend_, SLOT(DeleteSongs(SongList)));
connect(watcher_, SIGNAL(SongsUnavailable(SongList)), backend_, SLOT(MarkSongsUnavailable(SongList)));
connect(watcher_, SIGNAL(SongsReadded(SongList, bool)), backend_, SLOT(MarkSongsUnavailable(SongList, bool)));
connect(watcher_, SIGNAL(SubdirsDiscovered(SubdirectoryList)), backend_, SLOT(AddOrUpdateSubdirs(SubdirectoryList)));
connect(watcher_, SIGNAL(SubdirsMTimeUpdated(SubdirectoryList)), backend_, SLOT(AddOrUpdateSubdirs(SubdirectoryList)));

View File

@ -2,6 +2,7 @@
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -76,8 +77,8 @@ CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent)
fs_watcher_(FileSystemWatcherInterface::Create(this)),
scan_on_startup_(true),
monitor_(true),
mark_songs_unavailable_(false),
live_scanning_(false),
prevent_delete_(false),
stop_requested_(false),
rescan_in_progress_(false),
rescan_timer_(new QTimer(this)),
@ -115,13 +116,13 @@ void CollectionWatcher::Exit() {
}
CollectionWatcher::ScanTransaction::ScanTransaction(CollectionWatcher *watcher, const int dir, const bool incremental, const bool ignores_mtime, const bool prevent_delete)
CollectionWatcher::ScanTransaction::ScanTransaction(CollectionWatcher *watcher, const int dir, const bool incremental, const bool ignores_mtime, const bool mark_songs_unavailable)
: progress_(0),
progress_max_(0),
dir_(dir),
incremental_(incremental),
ignores_mtime_(ignores_mtime),
prevent_delete_(prevent_delete),
mark_songs_unavailable_(mark_songs_unavailable),
watcher_(watcher),
cached_songs_dirty_(true),
known_subdirs_dirty_(true)
@ -176,8 +177,13 @@ void CollectionWatcher::ScanTransaction::CommitNewOrUpdatedSongs() {
touched_songs.clear();
}
if (!deleted_songs.isEmpty() && !prevent_delete_) {
emit watcher_->SongsDeleted(deleted_songs);
if (!deleted_songs.isEmpty()) {
if (mark_songs_unavailable_) {
emit watcher_->SongsUnavailable(deleted_songs);
}
else {
emit watcher_->SongsDeleted(deleted_songs);
}
deleted_songs.clear();
}
@ -279,14 +285,14 @@ void CollectionWatcher::AddDirectory(const Directory &dir, const SubdirectoryLis
if (subdirs.isEmpty()) {
// This is a new directory that we've never seen before. Scan it fully.
ScanTransaction transaction(this, dir.id, false, false, prevent_delete_);
ScanTransaction transaction(this, dir.id, false, false, mark_songs_unavailable_);
transaction.SetKnownSubdirs(subdirs);
transaction.AddToProgressMax(1);
ScanSubdirectory(dir.path, Subdirectory(), &transaction);
}
else {
// We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed.
ScanTransaction transaction(this, dir.id, true, false, prevent_delete_);
ScanTransaction transaction(this, dir.id, true, false, mark_songs_unavailable_);
transaction.SetKnownSubdirs(subdirs);
transaction.AddToProgressMax(subdirs.count());
for (const Subdirectory &subdir : subdirs) {
@ -711,7 +717,7 @@ void CollectionWatcher::RescanPathsNow() {
for (int dir : rescan_queue_.keys()) {
if (stop_requested_) break;
ScanTransaction transaction(this, dir, false, false, prevent_delete_);
ScanTransaction transaction(this, dir, false, false, mark_songs_unavailable_);
transaction.AddToProgressMax(rescan_queue_[dir].count());
for (const QString &path : rescan_queue_[dir]) {
@ -807,8 +813,8 @@ void CollectionWatcher::ReloadSettings() {
s.beginGroup(CollectionSettingsPage::kSettingsGroup);
scan_on_startup_ = s.value("startup_scan", true).toBool();
monitor_ = s.value("monitor", true).toBool();
mark_songs_unavailable_ = s.value("mark_songs_unavailable", false).toBool();
live_scanning_ = s.value("live_scanning", false).toBool();
prevent_delete_ = s.value("prevent_delete", false).toBool();
QStringList filters = s.value("cover_art_patterns", QStringList() << "front" << "cover").toStringList();
s.endGroup();
@ -886,7 +892,7 @@ void CollectionWatcher::RescanTracksNow() {
QString songdir = song.url().toLocalFile().section('/', 0, -2);
if (!scanned_dirs.contains(songdir)) {
qLog(Debug) << "Song" << song.title() << "dir id" << song.directory_id() << "dir" << songdir;
ScanTransaction transaction(this, song.directory_id(), false, false, prevent_delete_);
ScanTransaction transaction(this, song.directory_id(), false, false, mark_songs_unavailable_);
ScanSubdirectory(songdir, Subdirectory(), &transaction);
scanned_dirs << songdir;
emit CompilationsNeedUpdating();
@ -907,7 +913,7 @@ void CollectionWatcher::PerformScan(bool incremental, bool ignore_mtimes) {
for (const Directory &dir : watched_dirs_.values()) {
if (stop_requested_) break;
ScanTransaction transaction(this, dir.id, incremental, ignore_mtimes, prevent_delete_);
ScanTransaction transaction(this, dir.id, incremental, ignore_mtimes, mark_songs_unavailable_);
SubdirectoryList subdirs(transaction.GetAllSubdirs());
transaction.AddToProgressMax(subdirs.count());

View File

@ -2,6 +2,7 @@
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -66,6 +67,7 @@ signals:
void NewOrUpdatedSongs(const SongList &songs);
void SongsMTimeUpdated(const SongList &songs);
void SongsDeleted(const SongList &songs);
void SongsUnavailable(const SongList &songs);
void SongsReadded(const SongList &songs, bool unavailable = false);
void SubdirsDiscovered(const SubdirectoryList &subdirs);
void SubdirsMTimeUpdated(const SubdirectoryList &subdirs);
@ -89,7 +91,7 @@ signals:
// Multiple calls to FindSongsInSubdirectory during one transaction will only result in one call to CollectionBackend::FindSongsInDirectory.
class ScanTransaction {
public:
ScanTransaction(CollectionWatcher *watcher, const int dir, const bool incremental, const bool ignores_mtime, const bool prevent_delete);
ScanTransaction(CollectionWatcher *watcher, const int dir, const bool incremental, const bool ignores_mtime, const bool mark_songs_unavailable);
~ScanTransaction();
SongList FindSongsInSubdirectory(const QString &path);
@ -134,7 +136,7 @@ signals:
// Set this to true to prevent deleting missing files from database.
// Useful for unstable network connections.
bool prevent_delete_;
bool mark_songs_unavailable_;
CollectionWatcher *watcher_;
@ -191,8 +193,8 @@ signals:
bool scan_on_startup_;
bool monitor_;
bool mark_songs_unavailable_;
bool live_scanning_;
bool prevent_delete_;
bool stop_requested_;
bool rescan_in_progress_; // True if RescanTracksNow() has been called and is working.

View File

@ -2,6 +2,7 @@
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -111,8 +112,8 @@ void CollectionSettingsPage::Load() {
ui_->show_dividers->setChecked(s.value("show_dividers", true).toBool());
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
ui_->monitor->setChecked(s.value("monitor", true).toBool());
ui_->mark_songs_unavailable->setChecked(s.value("mark_songs_unavailable", false).toBool());
ui_->live_scanning->setChecked(s.value("live_scanning", false).toBool());
ui_->prevent_delete->setChecked(s.value("prevent_delete", false).toBool());
QStringList filters = s.value("cover_art_patterns", QStringList() << "front" << "cover").toStringList();
ui_->cover_art_patterns->setText(filters.join(","));
@ -143,8 +144,8 @@ void CollectionSettingsPage::Save() {
s.setValue("show_dividers", ui_->show_dividers->isChecked());
s.setValue("startup_scan", ui_->startup_scan->isChecked());
s.setValue("monitor", ui_->monitor->isChecked());
s.setValue("mark_songs_unavailable", ui_->mark_songs_unavailable->isChecked());
s.setValue("live_scanning", ui_->live_scanning->isChecked());
s.setValue("prevent_delete", ui_->prevent_delete->isChecked());
QString filter_text = ui_->cover_art_patterns->text();
QStringList filters = filter_text.split(',', QString::SkipEmptyParts);

View File

@ -2,6 +2,7 @@
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,19 +19,16 @@
*
*/
#ifndef LIBRARYSETTINGSPAGE_H
#define LIBRARYSETTINGSPAGE_H
#ifndef COLLECTIONSETTINGSPAGE_H
#define COLLECTIONSETTINGSPAGE_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QString>
#include "settingspage.h"
class QModelIndex;
class SettingsDialog;
class Ui_CollectionSettingsPage;
@ -63,4 +61,4 @@ private:
bool initialised_model_;
};
#endif // LIBRARYSETTINGSPAGE_H
#endif // COLLECTIONSETTINGSPAGE_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>509</width>
<height>697</height>
<height>746</height>
</rect>
</property>
<property name="windowTitle">
@ -93,16 +93,16 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="live_scanning">
<widget class="QCheckBox" name="mark_songs_unavailable">
<property name="text">
<string>Use live scanning</string>
<string>Mark disappeared songs unavailable</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="prevent_delete">
<widget class="QCheckBox" name="live_scanning">
<property name="text">
<string>Never delete songs from the collection</string>
<string>Use live scanning</string>
</property>
</widget>
</item>