library: Add option to ignore files by extension

Add a new skip option in library settings that takes a comma separated
list of file extensions. Skip files with the specified extensions when
scanning the library.
This commit is contained in:
Jim Broadus 2021-03-13 22:45:42 -08:00 committed by John Maguire
parent cef1d7e745
commit 3bd15aea0d
4 changed files with 35 additions and 6 deletions

View File

@ -98,6 +98,10 @@ void LibrarySettingsPage::Save() {
QStringList filters = filter_text.split(',', QString::SkipEmptyParts); QStringList filters = filter_text.split(',', QString::SkipEmptyParts);
s.setValue("cover_art_patterns", filters); s.setValue("cover_art_patterns", filters);
QString skip_extensions = ui_->skip_extensions->text();
QStringList extensions = skip_extensions.split(',', QString::SkipEmptyParts);
s.setValue("skip_file_extensions", extensions);
s.endGroup(); s.endGroup();
s.beginGroup(LibraryBackend::kSettingsGroup); s.beginGroup(LibraryBackend::kSettingsGroup);
@ -139,6 +143,9 @@ void LibrarySettingsPage::Load() {
.toStringList(); .toStringList();
ui_->cover_art_patterns->setText(filters.join(",")); ui_->cover_art_patterns->setText(filters.join(","));
QStringList extensions = s.value("skip_file_extensions").toStringList();
ui_->skip_extensions->setText(extensions.join(","));
s.endGroup(); s.endGroup();
s.beginGroup(LibraryBackend::kSettingsGroup); s.beginGroup(LibraryBackend::kSettingsGroup);

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>509</width> <width>509</width>
<height>452</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -137,7 +137,17 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="skip_extensions_label">
<property name="text">
<string>Skip files with these extensions (comma separated, case insensitive)</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="skip_extensions"/>
</item>
<item>
<widget class="QLabel" name="cover_art_patterns_label">
<property name="text"> <property name="text">
<string>Preferred album art filenames (comma separated)</string> <string>Preferred album art filenames (comma separated)</string>
</property> </property>

View File

@ -330,10 +330,12 @@ void LibraryWatcher::ScanSubdirectory(const QString& path,
QString ext_part(ExtensionPart(child)); QString ext_part(ExtensionPart(child));
QString dir_part(DirectoryPart(child)); QString dir_part(DirectoryPart(child));
if (sValidImages.contains(ext_part)) if (!skip_file_extensions_.contains(ext_part)) {
album_art[dir_part] << child; if (sValidImages.contains(ext_part))
else if (!child_info.isHidden()) album_art[dir_part] << child;
files_on_disk << child; else if (!child_info.isHidden())
files_on_disk << child;
}
} }
} }
@ -832,6 +834,13 @@ void LibraryWatcher::ReloadSettings() {
if (!s.isEmpty()) best_image_filters_ << s; if (!s.isEmpty()) best_image_filters_ << s;
} }
skip_file_extensions_.clear();
QStringList extensions = s.value("skip_file_extensions").toStringList();
for (const QString& extension : extensions) {
QString s = extension.trimmed().toLower();
if (!s.isEmpty()) skip_file_extensions_ << s;
}
if (!monitor_ && was_monitoring_before) { if (!monitor_ && was_monitoring_before) {
fs_watcher_->Clear(); fs_watcher_->Clear();
} else if (monitor_ && !was_monitoring_before) { } else if (monitor_ && !was_monitoring_before) {

View File

@ -217,6 +217,9 @@ class LibraryWatcher : public QObject {
*/ */
QStringList best_image_filters_; QStringList best_image_filters_;
// List of file extensions that should be ingored during a scan.
QStringList skip_file_extensions_;
bool scan_on_startup_; bool scan_on_startup_;
bool monitor_; bool monitor_;