rmptuiebc4428
remove unnecessary variables from Connection
+9 −29
2 files changed
- M src/connection.rs +4 −24
- M src/ui.rs +5 −5
| @@ -13,9 +13,6 @@ pub struct Connection { | |||
| 13 | 13 | pub state: String, | |
| 14 | 14 | pub elapsed: Duration, | |
| 15 | 15 | pub total_duration: Duration, | |
| 16 | − | pub volume: u8, | |
| 17 | − | pub repeat: bool, | |
| 18 | − | pub random: bool, | |
| 19 | 16 | pub current_song: Song, | |
| 20 | 17 | pub stats: mpd::Stats, | |
| 21 | 18 | pub status: mpd::Status, | |
| @@ -34,17 +31,10 @@ impl Connection { | |||
| 34 | 31 | ..Default::default() | |
| 35 | 32 | }; | |
| 36 | 33 | ||
| 37 | − | let songs_filenames: Vec<String> = conn | |
| 38 | − | .listall()? | |
| 39 | − | .into_iter() | |
| 40 | − | .map(|x| x.file) | |
| 41 | − | .collect(); | |
| 34 | + | let songs_filenames: Vec<String> = conn.listall()?.into_iter().map(|x| x.file).collect(); | |
| 42 | 35 | ||
| 43 | 36 | let status = conn.status().unwrap(); | |
| 44 | 37 | let (elapsed, total) = status.time.unwrap_or_default(); | |
| 45 | − | let volume: u8 = status.volume as u8; | |
| 46 | − | let repeat = status.repeat; | |
| 47 | − | let random = status.random; | |
| 48 | 38 | let stats = conn.stats().unwrap_or_default(); | |
| 49 | 39 | ||
| 50 | 40 | let current_song = conn | |
| @@ -57,9 +47,6 @@ impl Connection { | |||
| 57 | 47 | state: "Stopped".to_string(), | |
| 58 | 48 | elapsed, | |
| 59 | 49 | total_duration: total, | |
| 60 | − | volume, | |
| 61 | − | repeat, | |
| 62 | − | random, | |
| 63 | 50 | current_song, | |
| 64 | 51 | stats, | |
| 65 | 52 | status, | |
| @@ -84,13 +71,15 @@ impl Connection { | |||
| 84 | 71 | /// Update status | |
| 85 | 72 | pub fn update_status(&mut self) { | |
| 86 | 73 | let status = self.conn.status().unwrap(); | |
| 74 | + | let stats = self.conn.stats().unwrap_or_default(); | |
| 75 | + | ||
| 87 | 76 | let empty_song = self.get_song_with_only_filename("No Song playing or in Queue"); | |
| 77 | + | ||
| 88 | 78 | let current_song = self | |
| 89 | 79 | .conn | |
| 90 | 80 | .currentsong() | |
| 91 | 81 | .unwrap_or_else(|_| Some(empty_song.clone())) | |
| 92 | 82 | .unwrap_or(empty_song); | |
| 93 | − | let stats = self.conn.stats().unwrap_or_default(); | |
| 94 | 83 | ||
| 95 | 84 | // Status | |
| 96 | 85 | self.status = status.clone(); | |
| @@ -107,15 +96,6 @@ impl Connection { | |||
| 107 | 96 | self.elapsed = elapsed; | |
| 108 | 97 | self.total_duration = total; | |
| 109 | 98 | ||
| 110 | − | // Volume | |
| 111 | − | self.volume = status.volume as u8; | |
| 112 | − | ||
| 113 | − | // Repeat mode | |
| 114 | − | self.repeat = status.repeat; | |
| 115 | − | ||
| 116 | − | // Random mode | |
| 117 | − | self.random = status.random; | |
| 118 | − | ||
| 119 | 99 | // Current song | |
| 120 | 100 | self.current_song = current_song; | |
| 121 | 101 | ||
| @@ -126,7 +126,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 126 | 126 | .alignment(Alignment::Center), | |
| 127 | 127 | ) | |
| 128 | 128 | .title( | |
| 129 | − | Title::from(format!("Volume: {}%", app.conn.volume).green()) | |
| 129 | + | Title::from(format!("Volume: {}%", app.conn.status.volume).green()) | |
| 130 | 130 | .alignment(Alignment::Right), | |
| 131 | 131 | ) | |
| 132 | 132 | .borders(Borders::ALL), | |
| @@ -220,7 +220,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 220 | 220 | format!("({} items)", app.queue_list.list.len()).bold(), | |
| 221 | 221 | )) | |
| 222 | 222 | .title( | |
| 223 | − | Title::from(format!("Volume: {}%", app.conn.volume).green()) | |
| 223 | + | Title::from(format!("Volume: {}%", app.conn.status.volume).green()) | |
| 224 | 224 | .alignment(Alignment::Right), | |
| 225 | 225 | ) | |
| 226 | 226 | .borders(Borders::ALL), | |
| @@ -280,17 +280,17 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 280 | 280 | // Get the current modes | |
| 281 | 281 | let mut modes_bottom: String = String::new(); | |
| 282 | 282 | // we do this to check if at least one mode is enabled so we can push "[]" | |
| 283 | − | if app.conn.repeat | app.conn.random { | |
| 283 | + | if app.conn.status.repeat | app.conn.status.random { | |
| 284 | 284 | modes_bottom.push('r'); | |
| 285 | 285 | } | |
| 286 | 286 | ||
| 287 | 287 | if !modes_bottom.is_empty() { | |
| 288 | 288 | modes_bottom.clear(); | |
| 289 | 289 | modes_bottom.push('['); | |
| 290 | − | if app.conn.repeat { | |
| 290 | + | if app.conn.status.repeat { | |
| 291 | 291 | modes_bottom.push('r'); | |
| 292 | 292 | } | |
| 293 | − | if app.conn.random { | |
| 293 | + | if app.conn.status.random { | |
| 294 | 294 | modes_bottom.push('z'); | |
| 295 | 295 | } | |
| 296 | 296 | modes_bottom.push(']'); | |