From cef6eb43b038a2961a969a54b411a4d2f29fee72 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Tue, 10 May 2022 22:59:49 +0200 Subject: [PATCH] Add option to customize library tabs New option is called `library_tabs`. By default all tabs are enabled. Fixes #798 --- README.md | 45 +++++++++++++++---------------- src/config.rs | 11 ++++++++ src/ui/library.rs | 67 ++++++++++++++++++++++++++++------------------- 3 files changed, 74 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 3f83810..a05db25 100644 --- a/README.md +++ b/README.md @@ -307,28 +307,29 @@ runtime use the command prompt by typing `:reload`. Possible configuration values are: -| Name | Description | Possible values | Default | -| :----------------------- | :------------------------------------------ |:--------------------------------------------------|:-----------:| -| `command_key` | Key to open command line | Single character | `:` | -| `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[^2] | `"library"` | -| `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` | -| `flip_status_indicators` | Reverse play/pause icon meaning[^1] | `true`, `false` | `false` | -| `backend` | Audio backend to use | String [^3] | | -| `backend_device` | Audio device to configure the backend | String | | -| `audio_cache` | Enable caching of audio files | `true`, `false` | `true` | -| `audio_cache_size` | Maximum size of audio cache in MiB | Number | | -| `volnorm` | Enable volume normalization | `true`, `false` | `false` | -| `volnorm_pregain` | Normalization pregain to apply (if enabled) | Number | 0 | -| `default_keybindings` | Enable default keybindings | `true`, `false` | `false` | -| `notify` | Enable desktop notifications | `true`, `false` | `false` | -| `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` | -| `album_column` | Show album column for tracks | `true`, `false` | `true` | -| `gapless` | Enable gapless playback | `true`, `false` | `true` | -| `shuffle` | Set default shuffle state | `true`, `false` | `false` | -| `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` | -| `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` | -| `[theme]` | Custom theme | See [custom theme](#theming) | | -| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | | +| Name | Description | Possible values | Default | +|--------------------------|---------------------------------------------|-----------------------------------------------------------------|-------------| +| `command_key` | Key to open command line | Single character | `:` | +| `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[^2] | `"library"` | +| `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` | +| `flip_status_indicators` | Reverse play/pause icon meaning[^1] | `true`, `false` | `false` | +| `backend` | Audio backend to use | String [^3] | | +| `backend_device` | Audio device to configure the backend | String | | +| `audio_cache` | Enable caching of audio files | `true`, `false` | `true` | +| `audio_cache_size` | Maximum size of audio cache in MiB | Number | | +| `volnorm` | Enable volume normalization | `true`, `false` | `false` | +| `volnorm_pregain` | Normalization pregain to apply (if enabled) | Number | `0` | +| `default_keybindings` | Enable default keybindings | `true`, `false` | `false` | +| `notify` | Enable desktop notifications | `true`, `false` | `false` | +| `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` | +| `album_column` | Show album column for tracks | `true`, `false` | `true` | +| `gapless` | Enable gapless playback | `true`, `false` | `true` | +| `shuffle` | Set default shuffle state | `true`, `false` | `false` | +| `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` | +| `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` | +| `library_tabs` | Tabs to show in library screen | Array of `tracks`, `albums`, `artists`, `playlists`, `podcasts` | All tabs | +| `[theme]` | Custom theme | See [custom theme](#theming) | | +| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | | [^1]: By default the statusbar will show a play icon when a track is playing and diff --git a/src/config.rs b/src/config.rs index 94f7519..100701f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,16 @@ pub enum PlaybackState { Default, } +#[derive(Clone, Serialize, Deserialize, Debug, Hash, strum::EnumIter)] +#[serde(rename_all = "lowercase")] +pub enum LibraryTab { + Tracks, + Albums, + Artists, + Playlists, + Podcasts, +} + #[derive(Clone, Serialize, Deserialize, Debug, Default)] pub struct ConfigValues { pub command_key: Option, @@ -46,6 +56,7 @@ pub struct ConfigValues { pub repeat: Option, pub cover_max_scale: Option, pub playback_state: Option, + pub library_tabs: Option>, } #[derive(Serialize, Deserialize, Debug, Default, Clone)] diff --git a/src/ui/library.rs b/src/ui/library.rs index bbbc093..a532204 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -2,9 +2,11 @@ use std::sync::Arc; use cursive::view::ViewWrapper; use cursive::Cursive; +use strum::IntoEnumIterator; use crate::command::Command; use crate::commands::CommandResult; +use crate::config::LibraryTab; use crate::library::Library; use crate::queue::Queue; use crate::traits::ViewExt; @@ -19,35 +21,46 @@ pub struct LibraryView { impl LibraryView { pub fn new(queue: Arc, library: Arc) -> Self { - let tabs = TabView::new() - .tab( - "tracks", - "Tracks", - ListView::new(library.tracks.clone(), queue.clone(), library.clone()), - ) - .tab( - "albums", - "Albums", - ListView::new(library.albums.clone(), queue.clone(), library.clone()), - ) - .tab( - "artists", - "Artists", - ListView::new(library.artists.clone(), queue.clone(), library.clone()), - ) - .tab( - "playlists", - "Playlists", - PlaylistsView::new(queue.clone(), library.clone()), - ) - .tab( - "podcasts", - "Podcasts", - ListView::new(library.shows.clone(), queue, library.clone()), - ); + let mut tabview = TabView::new(); + let selected_tabs = library + .cfg + .values() + .library_tabs + .clone() + .unwrap_or(Vec::from_iter(LibraryTab::iter())); + + for tab in selected_tabs { + match tab { + LibraryTab::Tracks => tabview.add_tab( + "tracks", + "Tracks", + ListView::new(library.tracks.clone(), queue.clone(), library.clone()), + ), + LibraryTab::Albums => tabview.add_tab( + "albums", + "Albums", + ListView::new(library.albums.clone(), queue.clone(), library.clone()), + ), + LibraryTab::Artists => tabview.add_tab( + "artists", + "Artists", + ListView::new(library.artists.clone(), queue.clone(), library.clone()), + ), + LibraryTab::Playlists => tabview.add_tab( + "playlists", + "Playlists", + PlaylistsView::new(queue.clone(), library.clone()), + ), + LibraryTab::Podcasts => tabview.add_tab( + "podcasts", + "Podcasts", + ListView::new(library.shows.clone(), queue.clone(), library.clone()), + ), + } + } Self { - tabs, + tabs: tabview, display_name: library.display_name.clone(), } }