1- //! # Common Types for Video Editor UI
2- //!
3- //! This module provides type conversions between Slint UI types and Rust-native types.
4- //!
5- //! ## Design Philosophy
6- //!
7- //! **These types are NOT duplicates** of `video_editor` library types. They serve as an
8- //! **adaptation layer** with specific purposes:
9- //!
10- //! 1. **UI Bridge**: Convert between Slint UI types (which require special serialization)
11- //! and Rust-native types for backend logic
12- //!
13- //! 2. **Serialization Support**: Provide `Serialize`/`Deserialize` for project persistence
14- //! through serde, while UI types are Slint-specific and cannot be serialized directly
15- //!
16- //! 3. **UI-Specific Fields**: Include UI-only data like thumbnails (`Image`), audio samples,
17- //! and screenshots that don't belong in the core `video_editor` library
18- //!
19- //! ## Type Mapping
20- //!
21- //! - `VideoEditorTracksManager` ↔ `video_editor::tracks::manager::Manager`
22- //! - `VideoEditorTrack` ↔ `video_editor::tracks::track::Track`
23- //! - `VideoEditorTrackSegment` ↔ `video_editor::tracks::segment::Segment`
24- //!
25- //! See `conversion.rs` for the actual conversion logic.
26- //!
27- //! ## Priority: video_editor Library First
28- //!
29- //! Core video editing logic uses `video_editor` library types directly.
30- //! These common types are ONLY used for:
31- //! - UI state serialization/deserialization
32- //! - Temporary data transfer between UI and backend
33- //! - UI-specific features (thumbnails, screenshots, audio visualization)
34-
351use super :: project:: UI_STATE_ID ;
362use crate :: slint_generatedAppWindow:: {
373 AudioChannels as UIAudioChannels , AudioFormat as UIAudioFormat ,
384 AudioSampleRate as UIAudioSampleRate , Fps as UIFps , MediaType as UIMediaType ,
39- RecentEntry as UIRecentEntry , Resolution as UIResolution , SegmentFilter as UISegmentFilter ,
40- SubtitleType as UISubtitleType , VideoEditorExportAudioConfig as UIVideoEditorExportAudioConfig ,
5+ Resolution as UIResolution , SegmentFilter as UISegmentFilter , SubtitleType as UISubtitleType ,
6+ VideoEditorExportAudioConfig as UIVideoEditorExportAudioConfig ,
417 VideoEditorExportQueueItem as UIVideoEditorExportQueueItem ,
428 VideoEditorExportVideoConfig as UIVideoEditorExportVideoConfig ,
43- VideoEditorFilter as UIVideoEditorFilter ,
44- VideoEditorNewProjectConfig as UIVideoEditorNewProjectConfig ,
45- VideoEditorPlaylistItem as UIVideoEditorPlaylistItem ,
46- VideoEditorPreviewConfig as UIVideoEditorPreviewConfig ,
9+ VideoEditorFilter as UIVideoEditorFilter , VideoEditorPlaylistItem as UIVideoEditorPlaylistItem ,
10+ VideoEditorRecentEntry as UIVideoEditorRecentEntry ,
4711 VideoEditorSubtitle as UIVideoEditorSubtitle , VideoEditorTrack as UIVideoEditorTrack ,
4812 VideoEditorTrackSegment as UIVideoEditorTrackSegment ,
4913 VideoEditorTrackType as UIVideoEditorTrackType ,
@@ -54,11 +18,13 @@ use derivative::Derivative;
5418use pmacro:: SlintFromConvert ;
5519use serde:: { Deserialize , Serialize } ;
5620use slint:: { Image , Model } ;
21+ use std:: time:: SystemTime ;
22+ use video_editor:: project:: recent:: RecentFile ;
5723
58- crate :: impl_slint_enum_serde!( UIVideoEditorTrackType , Audio , Video , Subtitle , Overlay ) ;
5924crate :: impl_slint_enum_serde!( UISubtitleType , Srt , Vtt , Ass ) ;
60- crate :: impl_slint_enum_serde!( UIMediaType , Video , Audio , Image , Subtitle , Text ) ;
6125crate :: impl_slint_enum_serde!( UIAudioFormat , Aac , Mp3 , Ogg , Wav , Flac ) ;
26+ crate :: impl_slint_enum_serde!( UIMediaType , Video , Audio , Image , Subtitle , Text ) ;
27+ crate :: impl_slint_enum_serde!( UIVideoEditorTrackType , Audio , Video , Subtitle , Overlay ) ;
6228crate :: impl_slint_enum_serde!( UIAudioChannels , Mono , Stereo ) ;
6329crate :: impl_slint_enum_serde!(
6430 UIAudioSampleRate ,
@@ -190,31 +156,6 @@ pub struct VideoEditorTracksManager {
190156 pub tracks : Vec < VideoEditorTrack > ,
191157}
192158
193- #[ derive( Serialize , Deserialize , Debug , Clone , Derivative , SlintFromConvert ) ]
194- #[ derivative( Default ) ]
195- #[ from( "UIVideoEditorPreviewConfig" ) ]
196- #[ serde( default ) ]
197- pub struct VideoEditorPreviewConfig {
198- #[ from( "fps" ) ]
199- pub fps : UIFps ,
200- #[ from( "resolution" ) ]
201- pub resolution : UIResolution ,
202- #[ from( "channels" ) ]
203- pub channels : UIAudioChannels ,
204- #[ from( "sample_rate" ) ]
205- pub sample_rate : UIAudioSampleRate ,
206- }
207-
208- #[ derive( Serialize , Deserialize , Debug , Clone , Derivative , SlintFromConvert ) ]
209- #[ derivative( Default ) ]
210- #[ from( "UIVideoEditorNewProjectConfig" ) ]
211- #[ serde( default ) ]
212- pub struct VideoEditorNewProjectConfig {
213- pub name : String ,
214- #[ from( "preview_config" ) ]
215- pub preview_config : VideoEditorPreviewConfig ,
216- }
217-
218159#[ derive( Serialize , Deserialize , Debug , Clone , Derivative , SlintFromConvert ) ]
219160#[ derivative( Default ) ]
220161#[ from( "UIVideoEditorPlaylistItem" ) ]
@@ -292,12 +233,21 @@ pub struct VideoEditorSubtitle {
292233 pub subtitle : String ,
293234}
294235
295- #[ derive( Serialize , Deserialize , Debug , Clone , Derivative , SlintFromConvert ) ]
296- #[ derivative( Default ) ]
297- #[ from( "UIRecentEntry" ) ]
298- #[ serde( default ) ]
299- pub struct RecentEntry {
300- pub name : String ,
301- pub path : String ,
302- pub modify_at : String ,
236+ impl From < RecentFile > for UIVideoEditorRecentEntry {
237+ fn from ( rf : RecentFile ) -> Self {
238+ let modified_at = if let Ok ( modified) =
239+ rf. last_modified . duration_since ( SystemTime :: UNIX_EPOCH )
240+ && let Some ( datetime) = chrono:: DateTime :: from_timestamp ( modified. as_secs ( ) as i64 , 0 )
241+ {
242+ datetime. format ( "%Y-%m-%d" ) . to_string ( ) . into ( )
243+ } else {
244+ "--:--:--" . to_string ( ) . into ( )
245+ } ;
246+
247+ UIVideoEditorRecentEntry {
248+ name : rf. name . into ( ) ,
249+ path : rf. path . to_string_lossy ( ) . to_string ( ) . into ( ) ,
250+ modified_at,
251+ }
252+ }
303253}
0 commit comments