diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index 308e901..95dbefb 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -138,6 +138,7 @@ pub enum AlbumSecondaryType { } /// The album's ownership status. +#[derive(Debug)] pub enum AlbumOwnership { None, Owned(TrackFormat), diff --git a/src/core/musichoard/builder.rs b/src/core/musichoard/builder.rs index 5ea72ce..a68aac9 100644 --- a/src/core/musichoard/builder.rs +++ b/src/core/musichoard/builder.rs @@ -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 { /// 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 MusicHoard { /// 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 MusicHoard { /// Create a new [`MusicHoard`] with the provided [`IDatabase`] and no library. pub fn database(database: Database) -> Result { let mut mh = MusicHoard { + filter: CollectionFilter::default(), + filtered: vec![], collection: vec![], pre_commit: vec![], database, @@ -127,6 +133,8 @@ impl MusicHoard { /// Create a new [`MusicHoard`] with the provided [`ILibrary`] and [`IDatabase`]. pub fn new(database: Database, library: Library) -> Result { let mut mh = MusicHoard { + filter: CollectionFilter::default(), + filtered: vec![], collection: vec![], pre_commit: vec![], database, diff --git a/src/core/musichoard/mod.rs b/src/core/musichoard/mod.rs index f6ba502..8fb7026 100644 --- a/src/core/musichoard/mod.rs +++ b/src/core/musichoard/mod.rs @@ -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 { + filter: CollectionFilter, + filtered: Collection, collection: Collection, pre_commit: Collection, database: Database, @@ -32,6 +39,32 @@ pub struct MusicHoard { 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, + secondary_types: Vec, + include_untyped: bool, + ownership: Vec, +} + +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;