Other crap i added months ago
This commit is contained in:
@@ -15,6 +15,8 @@ pub struct JsonStore {
|
||||
playlists: HashMap<Uuid, Playlist>
|
||||
}
|
||||
|
||||
impl super::StoreExtras for JsonStore {}
|
||||
|
||||
impl super::BaseStore for JsonStore {
|
||||
fn get_default_file_contents() -> &'static str {
|
||||
&DEFAULT_TEXT
|
||||
|
||||
@@ -40,3 +40,55 @@ pub trait BaseStore {
|
||||
fn get_original_path(&self) -> &Path;
|
||||
}
|
||||
|
||||
pub trait StoreExtras: BaseStore {
|
||||
fn get_songs_sorted(&self) -> Vec<(&Uuid, &Song)> {
|
||||
let mut songs: Vec<_> = self.get_songs().iter().collect();
|
||||
songs.sort_by(|a, b| {
|
||||
let a = a.1.name().to_lowercase();
|
||||
let b = b.1.name().to_lowercase();
|
||||
a.cmp(&b)
|
||||
});
|
||||
songs
|
||||
}
|
||||
|
||||
fn get_songs_sorted_cloned(&self) -> Vec<(Uuid, Song)> {
|
||||
let mut songs = Vec::new();
|
||||
for song in self.get_songs_sorted() {
|
||||
songs.push((song.0.clone(), song.1.clone()));
|
||||
}
|
||||
songs
|
||||
}
|
||||
|
||||
fn get_playlists_sorted(&self) -> Vec<(&Uuid, &Playlist)> {
|
||||
let mut songs: Vec<_> = self.get_playlists().iter().collect();
|
||||
songs.sort_by(|a, b| {
|
||||
let a = a.1.name().to_lowercase();
|
||||
let b = b.1.name().to_lowercase();
|
||||
a.cmp(&b)
|
||||
});
|
||||
songs
|
||||
}
|
||||
fn get_playlist_songs_sorted(&self, pid: uuid::Uuid) -> Option<Vec<(&Uuid, &Song)>> {
|
||||
let songs_ids: Vec<_> = self.get_playlist(&pid)?.songs().iter().collect();
|
||||
let mut songs = Vec::new();
|
||||
|
||||
for sid in songs_ids {
|
||||
songs.push((sid, self.get_song(sid)?));
|
||||
}
|
||||
|
||||
songs.sort_by(|a, b| {
|
||||
let a = a.1.name().to_lowercase();
|
||||
let b = b.1.name().to_lowercase();
|
||||
a.cmp(&b)
|
||||
});
|
||||
Some(songs)
|
||||
}
|
||||
fn get_playlist_songs_sorted_cloned(&self, pid: uuid::Uuid) -> Option<Vec<(Uuid, Song)>> {
|
||||
let mut songs = Vec::new();
|
||||
for song in self.get_playlist_songs_sorted(pid)? {
|
||||
songs.push((song.0.clone(), song.1.clone()));
|
||||
}
|
||||
Some(songs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ pub struct TomlStore {
|
||||
playlists: HashMap<Uuid, Playlist>
|
||||
}
|
||||
|
||||
impl super::StoreExtras for TomlStore {}
|
||||
|
||||
impl super::BaseStore for TomlStore {
|
||||
fn get_default_file_contents() -> &'static str {
|
||||
&DEFAULT_TEXT
|
||||
|
||||
Reference in New Issue
Block a user