From a758dd113c91b7b2b670e22ef69f607e43d1b52b Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Fri, 21 Feb 2025 16:07:35 +0100 Subject: [PATCH] Pass media tracks and subs file to Celluloid, improve modal spacing --- src/application.css | 3 --- src/data_manager.rs | 34 +++++++++++++++------------------- src/ui/mod.rs | 32 +++++++++++++++++++++++++++++++- src/utility.rs | 19 +++++++++++++++++++ 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/application.css b/src/application.css index fd5507b..a0ae4fa 100644 --- a/src/application.css +++ b/src/application.css @@ -14,6 +14,3 @@ .media-modal { padding : 100px ; } -.media-modal .top-padding { - padding-top : 40px ; -} diff --git a/src/data_manager.rs b/src/data_manager.rs index 56e0efe..c2973d1 100644 --- a/src/data_manager.rs +++ b/src/data_manager.rs @@ -64,11 +64,10 @@ impl DataManager { films . runtime_minutes , films . poster_file_path , films . source , - sources . video_file_path , - sources . video_track , - sources . audio_file_path , - sources . audio_track , + sources . file_path , sources . subtitle_file_path , + sources . video_track , + sources . audio_track , sources . subtitle_track from films left join sources on films . source = sources . uuid @@ -170,7 +169,7 @@ fn row_to_series_overview ( row : & Row ) -> rusqlite :: Result -pub struct FilmDetails { +# [ derive (Clone) ] pub struct FilmDetails { pub uuid : String , pub name : String , pub original_name : Option , @@ -179,12 +178,11 @@ pub struct FilmDetails { pub poster_file_path : Option , pub source : Option , } -pub struct SourceDetails { - pub video_file_path : PathBuf , - pub video_track : Option , - pub audio_file_path : PathBuf , - pub audio_track : Option , +# [ derive (Clone) ] pub struct SourceDetails { + pub file_path : PathBuf , pub subtitle_file_path : Option , + pub video_track : Option , + pub audio_track : Option , pub subtitle_track : Option , } @@ -199,19 +197,17 @@ fn row_to_film_details ( row : & Row ) -> rusqlite :: Result { let source_uuid = row . get :: < _ , Option > (6) ? ; let source = match source_uuid { Some (_) => { - let video_file_path = PathBuf :: from ( row . get :: < _ , String > (7) ? ) ; - let video_track = row . get (8) ? ; - let audio_file_path = PathBuf :: from ( row . get :: < _ , String > (9) ? ) ; + let file_path = PathBuf :: from ( row . get :: < _ , String > (7) ? ) ; + let subtitle_file_path = row . get :: < _ , Option > (8) ? . map ( PathBuf :: from ) ; + let video_track = row . get (9) ? ; let audio_track = row . get (10) ? ; - let subtitle_file_path = row . get :: < _ , Option > (11) ? . map ( PathBuf :: from ) ; - let subtitle_track = row . get (12) ? ; + let subtitle_track = row . get (11) ? ; Some ( SourceDetails { - video_file_path , - video_track , - audio_file_path , - audio_track , + file_path , subtitle_file_path , + video_track , + audio_track , subtitle_track , } ) } , diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 9c26cfe..d2ef8b1 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -9,6 +9,7 @@ use gtk4 :: prelude :: * ; use libadwaita :: * ; use libadwaita :: prelude :: * ; use libadwaita :: ViewSwitcherPolicy :: * ; +use std :: process :: * ; use crate :: data_manager :: * ; use crate :: ui :: collatable_container :: * ; @@ -38,6 +39,7 @@ impl UI { & g_box ! ( @ option_children ; @ orientation : Vertical ; + @ spacing : 40 ; @ css_classes : & [ "media-modal" ] ; Some ( label ! ( @@ -50,9 +52,37 @@ impl UI { ) . as_ref () , Some ( label ! ( - @ css_classes : & [ "top-padding" ] ; & format ! ( "Release date: {}" , film_details . release_date ) , ) ) . as_ref () , + + film_details . source . map ( + |source| button ! ( + @ css_classes : & [ "suggested-action" , "circular" ] ; + @ connect_clicked : move |_| { + let source = source . clone () ; + + let arguments = [ + Some ( source . file_path . as_os_str () . to_owned () ) , + source . subtitle_file_path . map ( + |subtitle_file_path| concat_os_str ! ( "--mpv-sub-file=" , subtitle_file_path ) , + ) , + source . video_track . map ( + |video_track| concat_os_str ! ( "--mpv-vid=" , to_os_string (video_track) ) , + ) , + source . audio_track . map ( + |audio_track| concat_os_str ! ( "--mpv-aid=" , to_os_string (audio_track) ) , + ) , + source . subtitle_track . map ( + |subtitle_track| concat_os_str ! ( "--mpv-sid=" , to_os_string (subtitle_track) ) , + ) , + ] . iter () . filter_map ( Option :: clone ) . collect :: < Vec <_> > () ; + + Command :: new ("/usr/bin/celluloid") . args (arguments) . spawn () + . unwrap () ; // TODO: Better error handling for UI callbacks in general + } ; + & image ! ( @ icon_name : "media-playback-start-symbolic" ; ) , + ) , + ) . as_ref () , ) , ) . present ( Some ( & window . libadwaita_window ) ) diff --git a/src/utility.rs b/src/utility.rs index fc922a0..b6ba4ec 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -1,3 +1,17 @@ +use std :: ffi :: * ; +use std :: fmt :: * ; + + + +macro_rules ! concat_os_str { ( + $ base : expr , + $ ( $ suffix : expr ) , + +) => { { + let mut base = std :: ffi :: OsString :: from ( $ base ) ; + $ ( base . push ( $ suffix ) ; ) + + base +} } } + pub fn leak < 'l , Type > ( inner : Type ) -> & 'l Type { Box :: leak ( Box :: new (inner) ) } @@ -14,6 +28,11 @@ macro_rules ! pinned_async { ( } ) } } +pub fn to_os_string ( value : impl Display + Sized ) -> OsString { + OsString :: from ( ToString :: to_string ( & value ) ) +} + +pub (crate) use concat_os_str ; pub (crate) use pinned_async ;