Other crap i added months ago

This commit is contained in:
2025-03-11 21:35:12 +02:00
parent ad89b0c64d
commit 67a948bb66
10 changed files with 197 additions and 56 deletions

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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