rmptuifd371e8
use mpd's load() to load playlists
+15 −24
2 files changed
- M src/connection.rs +3 −10
- M src/handler.rs +12 −14
| @@ -160,16 +160,9 @@ impl Connection { | |||
| 160 | 160 | } | |
| 161 | 161 | ||
| 162 | 162 | /// Push all songs of a playlist into queue | |
| 163 | − | pub fn push_playlist(&mut self, playlist: &str) -> Result<()> { | |
| 164 | − | let songs: Vec<Song> = self.conn.playlist(playlist)?; | |
| 165 | − | ||
| 166 | − | for song in songs { | |
| 167 | − | if self.songs_filenames.contains(&song.file) { | |
| 168 | − | let song = self.get_song_with_only_filename(&song.file); | |
| 169 | − | self.conn.push(&song)?; | |
| 170 | − | self.conn.play()?; | |
| 171 | − | } | |
| 172 | − | } | |
| 163 | + | pub fn load_playlist(&mut self, playlist: &str) -> Result<()> { | |
| 164 | + | self.conn.load(playlist, ..)?; | |
| 165 | + | self.conn.play()?; | |
| 173 | 166 | Ok(()) | |
| 174 | 167 | } | |
| 175 | 168 | ||
| @@ -197,7 +197,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 197 | 197 | ||
| 198 | 198 | SelectedTab::Playlists => { | |
| 199 | 199 | app.conn | |
| 200 | − | .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; | |
| 200 | + | .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; | |
| 201 | 201 | } | |
| 202 | 202 | } | |
| 203 | 203 | app.conn.update_status(); | |
| @@ -330,22 +330,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 330 | 330 | KeyCode::Char('e') => if app.selected_tab == SelectedTab::Playlists {}, | |
| 331 | 331 | ||
| 332 | 332 | // go to top of list | |
| 333 | − | KeyCode::Char('g') => { | |
| 334 | − | match app.selected_tab { | |
| 335 | − | SelectedTab::Queue => app.queue_list.index = 0, | |
| 336 | − | SelectedTab::DirectoryBrowser => app.browser.selected = 0, | |
| 337 | − | SelectedTab::Playlists => app.pl_list.index = 0 | |
| 338 | − | } | |
| 339 | − | } | |
| 333 | + | KeyCode::Char('g') => match app.selected_tab { | |
| 334 | + | SelectedTab::Queue => app.queue_list.index = 0, | |
| 335 | + | SelectedTab::DirectoryBrowser => app.browser.selected = 0, | |
| 336 | + | SelectedTab::Playlists => app.pl_list.index = 0, | |
| 337 | + | }, | |
| 340 | 338 | ||
| 341 | 339 | // go to bottom of list | |
| 342 | − | KeyCode::Char('G') => { | |
| 343 | − | match app.selected_tab { | |
| 344 | − | SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1, | |
| 345 | − | SelectedTab::DirectoryBrowser => app.browser.selected = app.browser.filetree.len() - 1, | |
| 346 | − | SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1 | |
| 340 | + | KeyCode::Char('G') => match app.selected_tab { | |
| 341 | + | SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1, | |
| 342 | + | SelectedTab::DirectoryBrowser => { | |
| 343 | + | app.browser.selected = app.browser.filetree.len() - 1 | |
| 347 | 344 | } | |
| 348 | − | } | |
| 345 | + | SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1, | |
| 346 | + | }, | |
| 349 | 347 | _ => {} | |
| 350 | 348 | } | |
| 351 | 349 | } | |