aboutsummaryrefslogtreecommitdiff
path: root/src/subtitle_view.rs
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2025-12-05 15:35:38 +0100
committerMalte Voos <git@mal.tc>2025-12-05 15:43:58 +0100
commitc347b6133365dcf1b7da4e77890b20d04d6cfba4 (patch)
treec83aac6f7d1e6edc57e607f01e5d3eeee8da4a0e /src/subtitle_view.rs
parent652b1c2a0ce7db4885ebc51f7f09133a43401442 (diff)
downloadlleap-c347b6133365dcf1b7da4e77890b20d04d6cfba4.tar.gz
lleap-c347b6133365dcf1b7da4e77890b20d04d6cfba4.zip
implement machine translation; various fixes and refactorings
Diffstat (limited to 'src/subtitle_view.rs')
-rw-r--r--src/subtitle_view.rs57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/subtitle_view.rs b/src/subtitle_view.rs
index fd98c60..4de73dd 100644
--- a/src/subtitle_view.rs
+++ b/src/subtitle_view.rs
@@ -1,17 +1,22 @@
use crate::cue_view::{CueView, CueViewMsg, CueViewOutput};
-use crate::util::Tracker;
+use crate::subtitle_selection_dialog::SubtitleSettings;
+use crate::subtitles::state::CueAddress;
use gtk::prelude::*;
use relm4::prelude::*;
pub struct SubtitleView {
primary_cue: Controller<CueView>,
- secondary_cue: Tracker<Option<String>>,
+ secondary_cue: Option<String>,
+ machine_translation: Option<String>,
+ show_secondary: bool,
+ show_machine_translation: bool,
}
#[derive(Debug)]
pub enum SubtitleViewMsg {
- SetPrimaryCue(Option<String>),
- SetSecondaryCue(Option<String>),
+ SetPrimaryCue(Option<CueAddress>),
+ SetSecondaryCue(Option<CueAddress>),
+ ApplySubtitleSettings(SubtitleSettings),
}
#[derive(Debug)]
@@ -39,12 +44,30 @@ impl SimpleComponent for SubtitleView {
model.primary_cue.widget(),
gtk::Box {
+ #[watch]
+ set_visible: model.show_secondary,
set_vexpand: true,
},
gtk::Label {
- #[track = "model.secondary_cue.is_dirty()"]
- set_text: model.secondary_cue.get().as_ref().map(|val| val.as_str()).unwrap_or(""),
+ #[watch]
+ set_text: model.secondary_cue.as_ref().map(|val| val.as_str()).unwrap_or(""),
+ #[watch]
+ set_visible: model.show_secondary,
+ set_justify: gtk::Justification::Center,
+ },
+
+ gtk::Box {
+ #[watch]
+ set_visible: model.show_machine_translation,
+ set_vexpand: true,
+ },
+
+ gtk::Label {
+ #[watch]
+ set_text: model.machine_translation.as_ref().map(|val| val.as_str()).unwrap_or(""),
+ #[watch]
+ set_visible: model.show_machine_translation,
set_justify: gtk::Justification::Center,
},
@@ -67,7 +90,10 @@ impl SimpleComponent for SubtitleView {
CueViewOutput::MouseEnter => SubtitleViewOutput::SetHoveringCue(true),
CueViewOutput::MouseLeave => SubtitleViewOutput::SetHoveringCue(false),
}),
- secondary_cue: Tracker::new(None),
+ secondary_cue: None,
+ machine_translation: None,
+ show_secondary: false,
+ show_machine_translation: false,
};
let widgets = view_output!();
@@ -76,18 +102,21 @@ impl SimpleComponent for SubtitleView {
}
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
- // Reset trackers
- self.secondary_cue.reset();
-
match msg {
- SubtitleViewMsg::SetPrimaryCue(value) => {
+ SubtitleViewMsg::SetPrimaryCue(addr) => {
self.primary_cue
.sender()
- .send(CueViewMsg::SetText(value))
+ .send(CueViewMsg::SetCue(addr))
.unwrap();
+ self.machine_translation = addr.and_then(|a| a.resolve_translation())
+ }
+ SubtitleViewMsg::SetSecondaryCue(addr) => {
+ let text = addr.map(|addr| addr.resolve_text());
+ self.secondary_cue = text;
}
- SubtitleViewMsg::SetSecondaryCue(value) => {
- self.secondary_cue.set(value);
+ SubtitleViewMsg::ApplySubtitleSettings(settings) => {
+ self.show_secondary = settings.show_secondary;
+ self.show_machine_translation = settings.show_machine_translation;
}
}
}