heic2jpg

git clone git://archive.git.mtrnord.blog/MTRNord/heic2jpg.git
Log | Files | Refs | README | LICENSE

progressing_page.rs (2256B)


      1 use gettextrs::gettext;
      2 use relm4::{
      3     adw,
      4     gtk::{
      5         self,
      6         prelude::{BoxExt, OrientableExt, WidgetExt},
      7     },
      8     ComponentParts, ComponentSender, SimpleComponent,
      9 };
     10 
     11 pub struct ProgressingPage {
     12     file_count: usize,
     13     progress: f64,
     14 }
     15 
     16 #[derive(Debug)]
     17 pub enum ProgressingPageMsg {
     18     SetFileCount(usize),
     19     SetProgress(f64),
     20 }
     21 
     22 #[relm4::component(pub)]
     23 impl SimpleComponent for ProgressingPage {
     24     type Init = ();
     25     type Input = ProgressingPageMsg;
     26     type Output = ();
     27 
     28     view! {
     29         adw::StatusPage {
     30             set_hexpand: true,
     31             set_vexpand: true,
     32             set_title: &gettext("Converting"),
     33             set_description: Some(&gettext("Please wait while the conversion is in progress")),
     34             set_icon_name: Some("pocket-knife"),
     35             gtk::Box {
     36                 set_halign: gtk::Align::Center,
     37                 set_orientation: gtk::Orientation::Vertical,
     38                 set_spacing: 8,
     39 
     40                 gtk::Label {
     41                     set_xalign: 0.5,
     42                     #[watch]
     43                     set_visible: model.file_count > 0,
     44                     #[watch]
     45                     set_label: &format!(
     46                         "{} / {}",
     47                         model.file_count as u32 * model.progress as u32,
     48                         model.file_count
     49                     ),
     50                 },
     51                 gtk::ProgressBar {
     52                     set_hexpand: true,
     53                     #[watch]
     54                     set_fraction: model.progress,
     55                 }
     56             }
     57         }
     58     }
     59 
     60     fn init(
     61         _init: Self::Init,
     62         root: Self::Root,
     63         _sender: ComponentSender<Self>,
     64     ) -> ComponentParts<Self> {
     65         let model = Self {
     66             file_count: 0,
     67             progress: 0.0,
     68         };
     69 
     70         let widgets = view_output!();
     71         ComponentParts { model, widgets }
     72     }
     73 
     74     fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
     75         match message {
     76             ProgressingPageMsg::SetFileCount(file_count) => {
     77                 self.file_count = file_count;
     78             }
     79             ProgressingPageMsg::SetProgress(progress) => {
     80                 self.progress = progress;
     81             }
     82         }
     83     }
     84 }