rmptui414e9fb
comply with clippy
+28 −33
5 files changed
- M src/app.rs +13 −15
- M src/browser.rs +3 −3
- M src/event/handler.rs +3 −4
- M src/event/pl_append_keys.rs +5 −7
- M src/ui.rs +4 −4
| @@ -29,7 +29,7 @@ pub struct App { | |||
| 29 | 29 | pub pl_newname_input: String, // Stores the new name of the playlist | |
| 30 | 30 | pub pl_cursor_pos: usize, // Stores the cursor position for renaming playlist | |
| 31 | 31 | ||
| 32 | − | pub pl_new_pl_input: String, // Stores the name of new playlist to be created | |
| 32 | + | pub pl_new_pl_input: String, // Stores the name of new playlist to be created | |
| 33 | 33 | pub pl_new_pl_cursor_pos: usize, // Stores the cursor position of new playlist to be created | |
| 34 | 34 | pub pl_new_pl_songs_buffer: Vec<Song>, // Buffer for songs that need to be added to the newly created playlist | |
| 35 | 35 | ||
| @@ -101,8 +101,7 @@ impl App { | |||
| 101 | 101 | self.update_queue(); | |
| 102 | 102 | ||
| 103 | 103 | // Deals with database update | |
| 104 | − | if self.should_update_song_list { | |
| 105 | − | if let None = self.conn.status.updating_db { | |
| 104 | + | if self.should_update_song_list && self.conn.status.updating_db.is_none() { | |
| 106 | 105 | // Update the songs list | |
| 107 | 106 | self.conn.songs_filenames = self | |
| 108 | 107 | .conn | |
| @@ -115,7 +114,6 @@ impl App { | |||
| 115 | 114 | self.browser.update_directory(&mut self.conn)?; | |
| 116 | 115 | ||
| 117 | 116 | self.should_update_song_list = false; | |
| 118 | − | } | |
| 119 | 117 | } | |
| 120 | 118 | ||
| 121 | 119 | Ok(()) | |
| @@ -163,22 +161,22 @@ impl App { | |||
| 163 | 161 | let file = format!("{}/{}", self.browser.path, content); | |
| 164 | 162 | let songs = self.conn.conn.listfiles(&file).unwrap_or_default(); | |
| 165 | 163 | for (t, f) in songs.iter() { | |
| 166 | − | if t == "file" { | |
| 167 | − | if Path::new(&f).has_extension(&[ | |
| 164 | + | if t == "file" | |
| 165 | + | && Path::new(&f).has_extension(&[ | |
| 168 | 166 | "mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma", | |
| 169 | 167 | "mpc", "aiff", "dff", "mp2", "mka", | |
| 170 | − | ]) { | |
| 171 | − | let path = file.clone() + "/" + f; | |
| 172 | − | let full_path = path.strip_prefix("./").unwrap_or_else(|| ""); | |
| 173 | − | let song = self.conn.get_song_with_only_filename(&full_path); | |
| 174 | − | self.conn.conn.push(&song)?; | |
| 175 | − | } | |
| 168 | + | ]) | |
| 169 | + | { | |
| 170 | + | let path = file.clone() + "/" + f; | |
| 171 | + | let full_path = path.strip_prefix("./").unwrap_or(""); | |
| 172 | + | let song = self.conn.get_song_with_only_filename(full_path); | |
| 173 | + | self.conn.conn.push(&song)?; | |
| 176 | 174 | } | |
| 177 | 175 | } | |
| 178 | 176 | } else if content_type == "file" { | |
| 179 | 177 | let mut status = false; | |
| 180 | 178 | for (i, song) in self.queue_list.list.clone().iter().enumerate() { | |
| 181 | − | let song_path = song.file.split("/").last().unwrap_or_default(); | |
| 179 | + | let song_path = song.file.split('/').last().unwrap_or_default(); | |
| 182 | 180 | if song_path.eq(content) { | |
| 183 | 181 | self.conn.conn.delete(i as u32).unwrap(); | |
| 184 | 182 | status = true; | |
| @@ -253,7 +251,7 @@ impl App { | |||
| 253 | 251 | let (t, path) = browser.filetree.get(browser.selected).unwrap(); | |
| 254 | 252 | if t == "directory" { | |
| 255 | 253 | if path != "." { | |
| 256 | − | browser.prev_path = browser.path.clone(); | |
| 254 | + | browser.prev_path.clone_from(&browser.path); | |
| 257 | 255 | browser.path = browser.prev_path.clone() + "/" + path; | |
| 258 | 256 | browser.update_directory(&mut self.conn)?; | |
| 259 | 257 | browser.prev_selected = browser.selected; | |
| @@ -261,7 +259,7 @@ impl App { | |||
| 261 | 259 | } | |
| 262 | 260 | } else { | |
| 263 | 261 | let index = self.queue_list.list.iter().position(|x| { | |
| 264 | − | let file = x.file.split("/").last().unwrap_or_default(); | |
| 262 | + | let file = x.file.split('/').last().unwrap_or_default(); | |
| 265 | 263 | file.eq(path) | |
| 266 | 264 | }); | |
| 267 | 265 | ||
| @@ -32,7 +32,7 @@ impl FileBrowser { | |||
| 32 | 32 | let mut file_vec: Vec<(String, String)> = vec![]; | |
| 33 | 33 | let mut dir_vec: Vec<(String, String)> = vec![]; | |
| 34 | 34 | for (t, f) in conn.conn.listfiles(self.path.as_str())?.into_iter() { | |
| 35 | − | if t == "directory" && !f.starts_with(".") { | |
| 35 | + | if t == "directory" && !f.starts_with('.') { | |
| 36 | 36 | dir_vec.push((t, f)); | |
| 37 | 37 | } else if t == "file" | |
| 38 | 38 | && Path::new(&f).has_extension(&[ | |
| @@ -73,7 +73,7 @@ impl FileBrowser { | |||
| 73 | 73 | .lsinfo(Song { | |
| 74 | 74 | file: (self.path.clone() + "/" + song) | |
| 75 | 75 | .strip_prefix("./") | |
| 76 | − | .unwrap_or_else(|| "") | |
| 76 | + | .unwrap_or("") | |
| 77 | 77 | .to_string(), | |
| 78 | 78 | ..Default::default() | |
| 79 | 79 | }) | |
| @@ -121,7 +121,7 @@ impl FileBrowser { | |||
| 121 | 121 | self.update_directory(conn)?; | |
| 122 | 122 | } | |
| 123 | 123 | } else { | |
| 124 | − | self.path = self.prev_path.clone(); | |
| 124 | + | self.path.clone_from(&self.prev_path); | |
| 125 | 125 | self.update_directory(conn)?; | |
| 126 | 126 | } | |
| 127 | 127 | ||
| @@ -6,7 +6,7 @@ use crate::{ | |||
| 6 | 6 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}; | |
| 7 | 7 | use std::time::Duration; | |
| 8 | 8 | ||
| 9 | − | use super::{pl_append_keys, pl_rename_keys, new_pl_keys, search_keys}; | |
| 9 | + | use super::{new_pl_keys, pl_append_keys, pl_rename_keys, search_keys}; | |
| 10 | 10 | ||
| 11 | 11 | pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |
| 12 | 12 | // searching, playlist renaming, playlist appending | |
| @@ -325,9 +325,8 @@ pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult< | |||
| 325 | 325 | MouseEventKind::ScrollDown => app.handle_scroll_down(), | |
| 326 | 326 | MouseEventKind::Down(button) => { | |
| 327 | 327 | let (x, y) = (mouse_event.column, mouse_event.row); | |
| 328 | − | match button { | |
| 329 | − | crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?, | |
| 330 | − | _ => {} | |
| 328 | + | if button == crossterm::event::MouseButton::Left { | |
| 329 | + | app.handle_mouse_left_click(x, y)?; | |
| 331 | 330 | } | |
| 332 | 331 | } | |
| 333 | 332 | _ => {} | |
| @@ -29,14 +29,14 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> | |||
| 29 | 29 | let option_song = songs.first(); | |
| 30 | 30 | if let Some(song) = option_song { | |
| 31 | 31 | if *pl_name == "Current Playlist" { | |
| 32 | − | app.conn.conn.push(&song)?; | |
| 32 | + | app.conn.conn.push(song)?; | |
| 33 | 33 | app.update_queue(); | |
| 34 | 34 | } else if *pl_name == "New Playlist" { | |
| 35 | 35 | app.pl_new_pl_songs_buffer.clear(); | |
| 36 | 36 | app.pl_new_pl_songs_buffer.push(song.clone()); | |
| 37 | 37 | app.inputmode = InputMode::NewPlaylist; | |
| 38 | 38 | } else { | |
| 39 | − | app.conn.add_to_playlist(pl_name, &song)?; | |
| 39 | + | app.conn.add_to_playlist(pl_name, song)?; | |
| 40 | 40 | } | |
| 41 | 41 | } | |
| 42 | 42 | } | |
| @@ -47,7 +47,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> | |||
| 47 | 47 | if t == "file" { | |
| 48 | 48 | let short_path = f; | |
| 49 | 49 | if let Some(full_path) = app.conn.get_full_path(short_path) { | |
| 50 | − | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 50 | + | let song = app.conn.get_song_with_only_filename(full_path); | |
| 51 | 51 | ||
| 52 | 52 | if *pl_name == "Current Playlist" { | |
| 53 | 53 | app.conn.conn.push(&song)?; | |
| @@ -72,7 +72,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> | |||
| 72 | 72 | ]) | |
| 73 | 73 | { | |
| 74 | 74 | let full_path = app.conn.get_full_path(f).unwrap_or_default(); | |
| 75 | − | let song = app.conn.get_song_with_only_filename(&full_path); | |
| 75 | + | let song = app.conn.get_song_with_only_filename(full_path); | |
| 76 | 76 | if *pl_name == "Current Playlist" { | |
| 77 | 77 | app.conn.conn.push(&song)?; | |
| 78 | 78 | } else if *pl_name == "New Playlist" { | |
| @@ -98,9 +98,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> | |||
| 98 | 98 | for song in songs { | |
| 99 | 99 | // We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore. | |
| 100 | 100 | // So instead of panicking, we just ignore if the song does not exists | |
| 101 | − | app.conn | |
| 102 | − | .add_to_playlist(*pl_name, &song) | |
| 103 | − | .unwrap_or_else(|_| {}); | |
| 101 | + | app.conn.add_to_playlist(pl_name, &song).unwrap_or(()); | |
| 104 | 102 | } | |
| 105 | 103 | } | |
| 106 | 104 | } | |
| @@ -83,7 +83,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 83 | 83 | ||
| 84 | 84 | let mut status: bool = false; | |
| 85 | 85 | for sn in app.queue_list.list.iter() { | |
| 86 | − | let file = sn.file.split("/").last().unwrap_or_default(); | |
| 86 | + | let file = sn.file.split('/').last().unwrap_or_default(); | |
| 87 | 87 | if file.eq(s) { | |
| 88 | 88 | status = true; | |
| 89 | 89 | } | |
| @@ -137,7 +137,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 137 | 137 | .alignment(Alignment::Right) | |
| 138 | 138 | } | |
| 139 | 139 | VolumeStatus::Muted(_v) => { | |
| 140 | − | Title::from(format!("Muted").red()).alignment(Alignment::Right) | |
| 140 | + | Title::from("Muted".red()).alignment(Alignment::Right) | |
| 141 | 141 | } | |
| 142 | 142 | }) | |
| 143 | 143 | .borders(Borders::ALL), | |
| @@ -235,7 +235,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 235 | 235 | .alignment(Alignment::Right) | |
| 236 | 236 | } | |
| 237 | 237 | VolumeStatus::Muted(_v) => { | |
| 238 | − | Title::from(format!("Muted").red()).alignment(Alignment::Right) | |
| 238 | + | Title::from("Muted".red()).alignment(Alignment::Right) | |
| 239 | 239 | } | |
| 240 | 240 | }) | |
| 241 | 241 | .borders(Borders::ALL), | |
| @@ -288,7 +288,7 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) { | |||
| 288 | 288 | // Get the current playing state | |
| 289 | 289 | let mut state: String = String::new(); | |
| 290 | 290 | if !app.queue_list.list.is_empty() { | |
| 291 | − | state = app.conn.state.clone(); | |
| 291 | + | state.clone_from(&app.conn.state); | |
| 292 | 292 | state.push(':'); | |
| 293 | 293 | } | |
| 294 | 294 | ||