fix queue deletion & make get_full_path return an option
This commit is contained in:
parent
66a1cfccf4
commit
6b66a44ed0
29
src/app.rs
29
src/app.rs
|
|
@ -113,11 +113,11 @@ impl App {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_remove_or_from_current_playlist(&mut self) -> AppResult<()> {
|
pub fn handle_add_or_remove_from_current_playlist(&mut self) -> AppResult<()> {
|
||||||
match self.selected_tab {
|
match self.selected_tab {
|
||||||
SelectedTab::DirectoryBrowser => {
|
SelectedTab::DirectoryBrowser => {
|
||||||
let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap();
|
let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap();
|
||||||
self.browser.selected += 1;
|
|
||||||
let mut status = false;
|
let mut status = false;
|
||||||
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
||||||
if song.contains(file) {
|
if song.contains(file) {
|
||||||
|
|
@ -127,14 +127,21 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !status {
|
if !status {
|
||||||
let song = self
|
if let Some(full_path) = &self.conn.get_full_path(&file) {
|
||||||
.conn
|
let song = self.conn.get_song_with_only_filename(full_path);
|
||||||
.get_song_with_only_filename(&self.conn.get_full_path(&file).unwrap());
|
self.conn.conn.push(&song)?;
|
||||||
self.conn.conn.push(&song)?;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.browser.selected != self.browser.filetree.len() - 1 {
|
||||||
|
self.browser.selected += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedTab::Queue => {
|
SelectedTab::Queue => {
|
||||||
|
if self.queue_list.list.len() == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let file = self
|
let file = self
|
||||||
.queue_list
|
.queue_list
|
||||||
.list
|
.list
|
||||||
|
|
@ -145,6 +152,9 @@ impl App {
|
||||||
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
||||||
if song.contains(&file) {
|
if song.contains(&file) {
|
||||||
self.conn.conn.delete(i as u32).unwrap();
|
self.conn.conn.delete(i as u32).unwrap();
|
||||||
|
if self.queue_list.index != 0 {
|
||||||
|
self.queue_list.index -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -205,9 +215,10 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search_song(&mut self) -> AppResult<()> {
|
pub fn search_song(&mut self) -> AppResult<()> {
|
||||||
let filename = self.conn.get_full_path(&self.search_input)?;
|
if let Some(filename) = self.conn.get_full_path(&self.search_input) {
|
||||||
let song = self.conn.get_song_with_only_filename(&filename);
|
let song = self.conn.get_song_with_only_filename(&filename);
|
||||||
self.conn.push(&song)?;
|
self.conn.push(&song)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,18 +188,26 @@ impl Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a song name from a directory, it returns the full path of the song in the database
|
/// Given a song name from a directory, it returns the full path of the song in the database
|
||||||
pub fn get_full_path(&self, short_path: &str) -> AppResult<String> {
|
pub fn get_full_path(&self, short_path: &str) -> Option<String> {
|
||||||
let list = self
|
// let list = self
|
||||||
.songs_filenames
|
// .songs_filenames
|
||||||
.iter()
|
// .iter()
|
||||||
.map(|f| f.as_str())
|
// .map(|f| f.as_str())
|
||||||
.collect::<Vec<&str>>();
|
// .collect::<Vec<&str>>();
|
||||||
let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&short_path, &list)
|
// let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&short_path, &list)
|
||||||
.get(0)
|
// .get(0)
|
||||||
.unwrap()
|
// .unwrap()
|
||||||
.clone();
|
// .clone();
|
||||||
|
|
||||||
Ok(filename.to_string())
|
for (i, f) in self.songs_filenames.iter().enumerate() {
|
||||||
|
if f.contains(short_path) {
|
||||||
|
return Some(self.songs_filenames.get(i).unwrap().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
// Ok(filename.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print status to stdout
|
/// Print status to stdout
|
||||||
|
|
|
||||||
|
|
@ -137,16 +137,16 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let full_path = app.conn.get_full_path(&short_path)?;
|
if let Some(full_path) = app.conn.get_full_path(&short_path) {
|
||||||
let song = app.conn.get_song_with_only_filename(&full_path);
|
let song = app.conn.get_song_with_only_filename(&full_path);
|
||||||
|
|
||||||
if pl_name == "Current Playlist" {
|
if pl_name == "Current Playlist" {
|
||||||
app.conn.conn.push(&song)?;
|
app.conn.conn.push(&song)?;
|
||||||
app.update_queue();
|
app.update_queue();
|
||||||
} else {
|
} else {
|
||||||
app.conn.add_to_playlist(pl_name, &song)?;
|
app.conn.add_to_playlist(pl_name, &song)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide the playlist popup
|
// hide the playlist popup
|
||||||
app.playlist_popup = false;
|
app.playlist_popup = false;
|
||||||
app.append_list.index = 0;
|
app.append_list.index = 0;
|
||||||
|
|
@ -156,7 +156,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
} else {
|
} else {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
// Quit
|
// Quit
|
||||||
KeyCode::Char('q') => app.quit(),
|
KeyCode::Char('q') => app.quit(),
|
||||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||||
if key_event.modifiers == KeyModifiers::CONTROL {
|
if key_event.modifiers == KeyModifiers::CONTROL {
|
||||||
app.quit();
|
app.quit();
|
||||||
|
|
@ -237,7 +237,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
// add to queue
|
// add to queue
|
||||||
KeyCode::Char('a') => app.playlist_popup = true,
|
KeyCode::Char('a') => app.playlist_popup = true,
|
||||||
|
|
||||||
|
|
||||||
// Fast forward
|
// Fast forward
|
||||||
KeyCode::Char('f') => {
|
KeyCode::Char('f') => {
|
||||||
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
|
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
|
||||||
|
|
@ -319,7 +318,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
|
|
||||||
// Remove from Current Playlsit
|
// Remove from Current Playlsit
|
||||||
KeyCode::Char(' ') | KeyCode::Backspace => {
|
KeyCode::Char(' ') | KeyCode::Backspace => {
|
||||||
app.handle_remove_or_from_current_playlist()?;
|
app.handle_add_or_remove_from_current_playlist()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change playlist name
|
// Change playlist name
|
||||||
|
|
|
||||||
Reference in New Issue