Add a filtering tool to only show only certain release group types #252
@ -138,6 +138,7 @@ pub enum AlbumSecondaryType {
|
||||
}
|
||||
|
||||
/// The album's ownership status.
|
||||
#[derive(Debug)]
|
||||
pub enum AlbumOwnership {
|
||||
None,
|
||||
Owned(TrackFormat),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::core::{
|
||||
interface::{database::IDatabase, library::ILibrary},
|
||||
musichoard::{database::IMusicHoardDatabase, Error, MusicHoard, NoDatabase, NoLibrary},
|
||||
musichoard::{database::IMusicHoardDatabase, Error, MusicHoard, NoDatabase, NoLibrary, CollectionFilter},
|
||||
};
|
||||
|
||||
/// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of
|
||||
@ -62,6 +62,8 @@ impl MusicHoard<NoDatabase, NoLibrary> {
|
||||
/// Create a new [`MusicHoard`] without any library or database.
|
||||
pub fn empty() -> Self {
|
||||
MusicHoard {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database: NoDatabase,
|
||||
@ -83,6 +85,8 @@ impl<Library: ILibrary> MusicHoard<NoDatabase, Library> {
|
||||
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and no database.
|
||||
pub fn library(library: Library) -> Self {
|
||||
MusicHoard {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database: NoDatabase,
|
||||
@ -104,6 +108,8 @@ impl<Database: IDatabase> MusicHoard<Database, NoLibrary> {
|
||||
/// Create a new [`MusicHoard`] with the provided [`IDatabase`] and no library.
|
||||
pub fn database(database: Database) -> Result<Self, Error> {
|
||||
let mut mh = MusicHoard {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database,
|
||||
@ -127,6 +133,8 @@ impl<Database: IDatabase, Library: ILibrary> MusicHoard<Database, Library> {
|
||||
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and [`IDatabase`].
|
||||
pub fn new(database: Database, library: Library) -> Result<Self, Error> {
|
||||
let mut mh = MusicHoard {
|
||||
filter: CollectionFilter::default(),
|
||||
filtered: vec![],
|
||||
collection: vec![],
|
||||
pre_commit: vec![],
|
||||
database,
|
||||
|
@ -12,11 +12,16 @@ pub use library::IMusicHoardLibrary;
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use crate::core::collection::Collection;
|
||||
|
||||
use crate::core::interface::{
|
||||
database::{LoadError as DatabaseLoadError, SaveError as DatabaseSaveError},
|
||||
library::Error as LibraryError,
|
||||
use crate::core::{
|
||||
collection::{
|
||||
album::{AlbumOwnership, AlbumPrimaryType, AlbumSecondaryType},
|
||||
track::TrackFormat,
|
||||
Collection,
|
||||
},
|
||||
interface::{
|
||||
database::{LoadError as DatabaseLoadError, SaveError as DatabaseSaveError},
|
||||
library::Error as LibraryError,
|
||||
},
|
||||
};
|
||||
|
||||
/// The Music Hoard. It is responsible for pulling information from both the library and the
|
||||
@ -24,6 +29,8 @@ use crate::core::interface::{
|
||||
// TODO: Split into inner and external/interfaces to facilitate building.
|
||||
#[derive(Debug)]
|
||||
pub struct MusicHoard<Database, Library> {
|
||||
filter: CollectionFilter,
|
||||
filtered: Collection,
|
||||
collection: Collection,
|
||||
pre_commit: Collection,
|
||||
database: Database,
|
||||
@ -32,6 +39,32 @@ pub struct MusicHoard<Database, Library> {
|
||||
library_cache: Collection,
|
||||
}
|
||||
|
||||
/// Filter for a specifying subsets of the entire collection (e.g., for display).
|
||||
// Filter is inclusive, not exclusive. To include something in the filtered collection, the filter
|
||||
// must select it. It also means that the options below are additive - the more options are set, the
|
||||
// more items will be included.
|
||||
#[derive(Debug)]
|
||||
pub struct CollectionFilter {
|
||||
primary_types: Vec<AlbumPrimaryType>,
|
||||
secondary_types: Vec<AlbumSecondaryType>,
|
||||
include_untyped: bool,
|
||||
ownership: Vec<AlbumOwnership>,
|
||||
}
|
||||
|
||||
impl Default for CollectionFilter {
|
||||
fn default() -> Self {
|
||||
CollectionFilter {
|
||||
primary_types: vec![AlbumPrimaryType::Ep, AlbumPrimaryType::Album],
|
||||
secondary_types: vec![],
|
||||
include_untyped: true,
|
||||
ownership: vec![
|
||||
AlbumOwnership::Owned(TrackFormat::Mp3),
|
||||
AlbumOwnership::Owned(TrackFormat::Flac),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Phantom type for when a library implementation is not needed.
|
||||
#[derive(Debug)]
|
||||
pub struct NoLibrary;
|
||||
|
Loading…
x
Reference in New Issue
Block a user