make album column for tracks configurable

introduces new config variable `album_column`

fixes #267
This commit is contained in:
Henrik Friedrichsen
2020-10-17 23:56:23 +02:00
parent 9fbbc7921e
commit e1b4892b8a
12 changed files with 22 additions and 11 deletions

View File

@@ -141,6 +141,7 @@ Possible configuration values are:
by default <true/false>
* `notify`: Enable or disable desktop notifications, off by default <true/false>
* `bitrate`: The audio bitrate to use for streaming, can be 96, 160, or 320 (default is 320)
* `album_column`: Show album column for tracks, on by default <true/false>
Keybindings can be configured in `[keybindings]` section in `config.toml`, e.g. as such:

View File

@@ -176,7 +176,7 @@ impl ListItem for Album {
format!("{}", self)
}
fn display_center(&self) -> String {
fn display_center(&self, _library: Arc<Library>) -> String {
"".to_string()
}

View File

@@ -148,7 +148,7 @@ impl ListItem for Artist {
format!("{}", self)
}
fn display_center(&self) -> String {
fn display_center(&self, _library: Arc<Library>) -> String {
"".to_string()
}

View File

@@ -21,6 +21,7 @@ pub struct Config {
pub volnorm_pregain: Option<f32>,
pub notify: Option<bool>,
pub bitrate: Option<u32>,
pub album_column: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@@ -71,7 +71,7 @@ impl ListItem for Episode {
self.name.clone()
}
fn display_center(&self) -> String {
fn display_center(&self, _library: Arc<Library>) -> String {
"".to_string()
}

View File

@@ -12,6 +12,7 @@ use serde::Serialize;
use crate::album::Album;
use crate::artist::Artist;
use crate::config;
use crate::config::Config;
use crate::events::EventManager;
use crate::playable::Playable;
use crate::playlist::Playlist;
@@ -65,6 +66,10 @@ impl Library {
.expect("could not readlock listview content")
}
pub fn config(&self) -> &Config {
&self.spotify.cfg
}
fn load_cache<T: DeserializeOwned>(&self, cache_path: PathBuf, store: Arc<RwLock<Vec<T>>>) {
if let Ok(contents) = std::fs::read_to_string(&cache_path) {
debug!("loading cache from {}", cache_path.display());

View File

@@ -76,8 +76,8 @@ impl ListItem for Playable {
self.as_listitem().display_left()
}
fn display_center(&self) -> String {
self.as_listitem().display_center()
fn display_center(&self, library: Arc<Library>) -> String {
self.as_listitem().display_center(library)
}
fn display_right(&self, library: Arc<Library>) -> String {

View File

@@ -128,7 +128,7 @@ impl ListItem for Playlist {
self.name.clone()
}
fn display_center(&self) -> String {
fn display_center(&self, _library: Arc<Library>) -> String {
"".to_string()
}

View File

@@ -92,7 +92,7 @@ impl ListItem for Show {
format!("{}", self)
}
fn display_center(&self) -> String {
fn display_center(&self, _library: Arc<Library>) -> String {
"".to_string()
}

View File

@@ -153,8 +153,12 @@ impl ListItem for Track {
format!("{}", self)
}
fn display_center(&self) -> String {
self.album.to_string()
fn display_center(&self, library: Arc<Library>) -> String {
if library.config().album_column.unwrap_or(true) {
self.album.to_string()
} else {
"".to_string()
}
}
fn display_right(&self, library: Arc<Library>) -> String {

View File

@@ -15,7 +15,7 @@ use crate::track::Track;
pub trait ListItem: Sync + Send + 'static {
fn is_playing(&self, queue: Arc<Queue>) -> bool;
fn display_left(&self) -> String;
fn display_center(&self) -> String;
fn display_center(&self, library: Arc<Library>) -> String;
fn display_right(&self, library: Arc<Library>) -> String;
fn play(&mut self, queue: Arc<Queue>);
fn queue(&mut self, queue: Arc<Queue>);

View File

@@ -229,7 +229,7 @@ impl<I: ListItem> View for ListView<I> {
};
let left = item.display_left();
let center = item.display_center();
let center = item.display_center(self.library.clone());
let right = item.display_right(self.library.clone());
let draw_center = !center.is_empty();