diff options
author | qkzk <qu3nt1n@gmail.com> | 2024-11-08 12:42:52 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2024-11-08 12:42:52 +0100 |
commit | a5ed07e3fdb459c7d507b067d73e5d7220ea7d45 (patch) | |
tree | 7a3ff763cd062ceded413041ff451abea88fcd17 | |
parent | 1d9d05df81d520b1fc1e117fcac8e56796ce1534 (diff) |
WIP: previews for movies, still slow
-rw-r--r-- | src/app/pw2.rs | 12 | ||||
-rw-r--r-- | src/app/status.rs | 20 | ||||
-rw-r--r-- | src/modes/display/directory.rs | 14 | ||||
-rw-r--r-- | src/modes/display/mod.rs | 2 | ||||
-rw-r--r-- | src/modes/display/uber.rs | 10 |
5 files changed, 34 insertions, 24 deletions
diff --git a/src/app/pw2.rs b/src/app/pw2.rs index 69190f98..3ccc8757 100644 --- a/src/app/pw2.rs +++ b/src/app/pw2.rs @@ -100,6 +100,18 @@ impl PreviewManager { drop(locked_queue); } + pub fn collection<P: AsRef<Path>>(&self, tasks: &[P]) { + let Ok(mut locked_queue) = self.queue.lock() else { + log_info!("PreviewManager couldn't lock the queue"); + return; + }; + log_info!("PreviewManager collection"); + for task in tasks { + locked_queue.push(task.as_ref().to_path_buf()); + } + drop(locked_queue); + } + pub fn clear(&self) { let Ok(mut locked_queue) = self.queue.lock() else { return; diff --git a/src/app/status.rs b/src/app/status.rs index 21af48d0..b2ab2d59 100644 --- a/src/app/status.rs +++ b/src/app/status.rs @@ -26,11 +26,12 @@ use crate::io::{ Args, Extension, Internal, Kind, Opener, MIN_WIDTH_FOR_DUAL_PANE, }; use crate::modes::{ - copy_move, extract_extension, parse_line_output, regex_matcher, shell_command_parser, - BlockDeviceAction, Content, ContentWindow, CopyMove, Direction as FuzzyDirection, Display, - FileInfo, FileKind, FilterKind, FuzzyFinder, FuzzyKind, InputCompleted, InputSimple, IsoDevice, - Menu, MenuHolder, MountCommands, MountRepr, Navigate, NeedConfirmation, PasswordKind, - PasswordUsage, Permissions, PickerCaller, Preview, PreviewBuilder, Search, Selectable, Users, + copy_move, extract_extension, parse_line_output, path_is_video, regex_matcher, + shell_command_parser, BlockDeviceAction, Content, ContentWindow, CopyMove, + Direction as FuzzyDirection, Display, FileInfo, FileKind, FilterKind, FuzzyFinder, FuzzyKind, + InputCompleted, InputSimple, IsoDevice, Menu, MenuHolder, MountCommands, MountRepr, Navigate, + NeedConfirmation, PasswordKind, PasswordUsage, Permissions, PickerCaller, Preview, + PreviewBuilder, Search, Selectable, Users, }; use crate::{log_info, log_line}; @@ -585,8 +586,8 @@ impl Status { return Ok(()); }; log_info!("sending preview request"); - // self.previewer.build(fileinfo.path.to_path_buf(), 1)?; - self.preview_manager.enqueue(&fileinfo.path); + self.previewer.build(fileinfo.path.to_path_buf(), 1)?; + // self.preview_manager.enqueue(&fileinfo.path); Ok(()) } @@ -595,9 +596,10 @@ impl Status { self.clear_preview_queue(); self.tabs[self.index] .directory - .index_to_index() + .paths() .iter() - .for_each(|task| self.preview_manager.enqueue(task)); + .filter(|p| path_is_video(p)) + .for_each(|path| self.preview_manager.enqueue(path)); } pub fn clear_preview_queue(&mut self) { diff --git a/src/modes/display/directory.rs b/src/modes/display/directory.rs index 49a63b90..0b30a4d8 100644 --- a/src/modes/display/directory.rs +++ b/src/modes/display/directory.rs @@ -176,20 +176,6 @@ impl Directory { .collect() } - pub fn index_to_index(&self) -> Vec<&Path> { - self.content - .iter() - .map(|fileinfo| fileinfo.path.borrow()) - .skip(self.index) - .chain( - self.content - .iter() - .map(|fileinfo| fileinfo.path.borrow()) - .take(self.index), - ) - .collect() - } - /// True iff the selected path is ".." which is the parent dir. pub fn is_dotdot_selected(&self) -> bool { let Some(selected) = &self.selected() else { diff --git a/src/modes/display/mod.rs b/src/modes/display/mod.rs index e00d80ac..b30fb63c 100644 --- a/src/modes/display/mod.rs +++ b/src/modes/display/mod.rs @@ -14,4 +14,4 @@ pub use preview::{ // pub use skim::{parse_line_output, print_ansiq_str, Skimer}; pub use nucleo_picker::{highlighted_text, parse_line_output, Direction, FuzzyFinder, FuzzyKind}; pub use tree::{Go, Node, TLine, To, Tree, TreeBuilder, TreeLines}; -pub use uber::{Ueber, UeberBuilder}; +pub use uber::{path_is_video, Ueber, UeberBuilder}; diff --git a/src/modes/display/uber.rs b/src/modes/display/uber.rs index 032e8286..5f0d5d43 100644 --- a/src/modes/display/uber.rs +++ b/src/modes/display/uber.rs @@ -73,6 +73,16 @@ impl std::fmt::Display for Kind { } } +pub fn path_is_video<P: AsRef<Path>>(path: P) -> bool { + let Some(ext) = path.as_ref().extension() else { + return false; + }; + matches!( + ext.to_string_lossy().as_ref(), + "mkv" | "webm" | "mpeg" | "mp4" | "avi" | "flv" | "mpg" | "wmv" | "m4v" | "mov" + ) +} + /// Holds an instance of [`ueberzug::Ueberzug`] and a few information about the display. /// it's used to display the image itself, calling `draw` with parameters for its position and dimension. pub struct Ueber { |