Add option to customize library tabs

New option is called `library_tabs`. By default all tabs are enabled.

Fixes #798
This commit is contained in:
Henrik Friedrichsen
2022-05-10 22:59:49 +02:00
parent f931624a5b
commit cef6eb43b0
3 changed files with 74 additions and 49 deletions

View File

@@ -307,28 +307,29 @@ runtime use the command prompt by typing `:reload`.
Possible configuration values are: Possible configuration values are:
| Name | Description | Possible values | Default | | Name | Description | Possible values | Default |
| :----------------------- | :------------------------------------------ |:--------------------------------------------------|:-----------:| |--------------------------|---------------------------------------------|-----------------------------------------------------------------|-------------|
| `command_key` | Key to open command line | Single character | `:` | | `command_key` | Key to open command line | Single character | `:` |
| `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[^2] | `"library"` | | `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[^2] | `"library"` |
| `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` | | `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` |
| `flip_status_indicators` | Reverse play/pause icon meaning[^1] | `true`, `false` | `false` | | `flip_status_indicators` | Reverse play/pause icon meaning[^1] | `true`, `false` | `false` |
| `backend` | Audio backend to use | String [^3] | | | `backend` | Audio backend to use | String [^3] | |
| `backend_device` | Audio device to configure the backend | String | | | `backend_device` | Audio device to configure the backend | String | |
| `audio_cache` | Enable caching of audio files | `true`, `false` | `true` | | `audio_cache` | Enable caching of audio files | `true`, `false` | `true` |
| `audio_cache_size` | Maximum size of audio cache in MiB | Number | | | `audio_cache_size` | Maximum size of audio cache in MiB | Number | |
| `volnorm` | Enable volume normalization | `true`, `false` | `false` | | `volnorm` | Enable volume normalization | `true`, `false` | `false` |
| `volnorm_pregain` | Normalization pregain to apply (if enabled) | Number | 0 | | `volnorm_pregain` | Normalization pregain to apply (if enabled) | Number | `0` |
| `default_keybindings` | Enable default keybindings | `true`, `false` | `false` | | `default_keybindings` | Enable default keybindings | `true`, `false` | `false` |
| `notify` | Enable desktop notifications | `true`, `false` | `false` | | `notify` | Enable desktop notifications | `true`, `false` | `false` |
| `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` | | `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` |
| `album_column` | Show album column for tracks | `true`, `false` | `true` | | `album_column` | Show album column for tracks | `true`, `false` | `true` |
| `gapless` | Enable gapless playback | `true`, `false` | `true` | | `gapless` | Enable gapless playback | `true`, `false` | `true` |
| `shuffle` | Set default shuffle state | `true`, `false` | `false` | | `shuffle` | Set default shuffle state | `true`, `false` | `false` |
| `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` | | `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` |
| `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` | | `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` |
| `[theme]` | Custom theme | See [custom theme](#theming) | | | `library_tabs` | Tabs to show in library screen | Array of `tracks`, `albums`, `artists`, `playlists`, `podcasts` | All tabs |
| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | | | `[theme]` | Custom theme | See [custom theme](#theming) | |
| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | |
[^1]: [^1]:
By default the statusbar will show a play icon when a track is playing and By default the statusbar will show a play icon when a track is playing and

View File

@@ -23,6 +23,16 @@ pub enum PlaybackState {
Default, 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)] #[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct ConfigValues { pub struct ConfigValues {
pub command_key: Option<char>, pub command_key: Option<char>,
@@ -46,6 +56,7 @@ pub struct ConfigValues {
pub repeat: Option<queue::RepeatSetting>, pub repeat: Option<queue::RepeatSetting>,
pub cover_max_scale: Option<f32>, pub cover_max_scale: Option<f32>,
pub playback_state: Option<PlaybackState>, pub playback_state: Option<PlaybackState>,
pub library_tabs: Option<Vec<LibraryTab>>,
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@@ -2,9 +2,11 @@ use std::sync::Arc;
use cursive::view::ViewWrapper; use cursive::view::ViewWrapper;
use cursive::Cursive; use cursive::Cursive;
use strum::IntoEnumIterator;
use crate::command::Command; use crate::command::Command;
use crate::commands::CommandResult; use crate::commands::CommandResult;
use crate::config::LibraryTab;
use crate::library::Library; use crate::library::Library;
use crate::queue::Queue; use crate::queue::Queue;
use crate::traits::ViewExt; use crate::traits::ViewExt;
@@ -19,35 +21,46 @@ pub struct LibraryView {
impl LibraryView { impl LibraryView {
pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> Self { pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> Self {
let tabs = TabView::new() let mut tabview = TabView::new();
.tab( let selected_tabs = library
"tracks", .cfg
"Tracks", .values()
ListView::new(library.tracks.clone(), queue.clone(), library.clone()), .library_tabs
) .clone()
.tab( .unwrap_or(Vec::from_iter(LibraryTab::iter()));
"albums",
"Albums", for tab in selected_tabs {
ListView::new(library.albums.clone(), queue.clone(), library.clone()), match tab {
) LibraryTab::Tracks => tabview.add_tab(
.tab( "tracks",
"artists", "Tracks",
"Artists", ListView::new(library.tracks.clone(), queue.clone(), library.clone()),
ListView::new(library.artists.clone(), queue.clone(), library.clone()), ),
) LibraryTab::Albums => tabview.add_tab(
.tab( "albums",
"playlists", "Albums",
"Playlists", ListView::new(library.albums.clone(), queue.clone(), library.clone()),
PlaylistsView::new(queue.clone(), library.clone()), ),
) LibraryTab::Artists => tabview.add_tab(
.tab( "artists",
"podcasts", "Artists",
"Podcasts", ListView::new(library.artists.clone(), queue.clone(), library.clone()),
ListView::new(library.shows.clone(), queue, 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 { Self {
tabs, tabs: tabview,
display_name: library.display_name.clone(), display_name: library.display_name.clone(),
} }
} }