diff --git a/Cargo.lock b/Cargo.lock index b8d247de53db1659f6c51de7f2dd7b287c8b96b3..ac60184105728b4360734684a19465dc70ff0406 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,7 @@ version = "3.0.1" dependencies = [ "anyhow", "async-trait", + "chrono", "futures", "hashbrown 0.14.2", "iced", diff --git a/amadeus/Cargo.toml b/amadeus/Cargo.toml index 7465d597cef60b6f7d2a76d63797e869d83e8976..de5b3c6a1cdd5a79d54f04caf4d12cc7b5ab7d2f 100644 --- a/amadeus/Cargo.toml +++ b/amadeus/Cargo.toml @@ -11,6 +11,7 @@ description = "Amadeus-RS, graphical interface for lektord" serde.workspace = true serde_json.workspace = true +chrono.workspace = true anyhow.workspace = true hashbrown.workspace = true diff --git a/amadeus/src/components/mod.rs b/amadeus/src/components/mod.rs index 7869487da622b9cc6d56c04fbff44b18b1e28cbc..2f76ee1b206f1e98733a571794713128e6b48c0a 100644 --- a/amadeus/src/components/mod.rs +++ b/amadeus/src/components/mod.rs @@ -24,6 +24,19 @@ pub fn loading_centered_shrink<'a, T: 'a>() -> iced::Element<'a, T> { .into() } +pub fn file_size<'a, T: 'a>(bytes: usize) -> iced::Element<'a, T> { + let kilos = bytes.div_euclid(1024); + let megas = kilos.div_euclid(1024); + iced::widget::text(if megas > 0 { + format!("File Size: {megas}MiB") + } else if kilos > 0 { + format!("File Size: {kilos}KiB") + } else { + format!("File Size: {bytes}B") + }) + .into() +} + macro_rules! tip { ($inner: expr => $position: ident | $tip: expr) => { iced::widget::tooltip($inner, $tip, iced::widget::tooltip::Position::$position) diff --git a/amadeus/src/components/modal/karainfos.rs b/amadeus/src/components/modal/karainfos.rs index 3b5ddb1327a829e04d7b060ce5501ac3670daf5e..889dae1e3254614eae8de8bc2e67215daff82e29 100644 --- a/amadeus/src/components/modal/karainfos.rs +++ b/amadeus/src/components/modal/karainfos.rs @@ -1,4 +1,8 @@ -use crate::style_sheet::{sizes::*, Color, RoundBadgeStyleSheet}; +use crate::{ + components::file_size, + style_sheet::{sizes::*, Color, RoundBadgeStyleSheet}, +}; +use chrono::TimeZone; use iced::{ widget::{column, container, horizontal_rule, text}, Element, @@ -94,19 +98,26 @@ impl State { .. } = self.0.as_ref(); + let mut column = column![text(format!( + "Remote Name: {}", + self.0.remote.remote_name() + ))]; + + if let Some(time) = chrono::Local.timestamp_opt(ts.created_at, 0).latest() { + let time = time.format("%Y-%m-%d %H:%M:%S"); + column = column.push(text(format!("Created at: {time}"))); + }; + + if let Some(time) = chrono::Local.timestamp_opt(ts.updated_at, 0).latest() { + let time = time.format("%Y-%m-%d %H:%M:%S"); + column = column.push(text(format!("Last Modified at: {time}"))); + }; + let aux_infos = match self.0.kara_status { - lektor_payloads::KaraStatus::Virtual => column![ - text(format!("Remote Name: {}", self.0.remote.remote_name())), - text(format!("Created at: {}", ts.created_at)), - text(format!("Last Modified at: {}", ts.updated_at)), - ], - lektor_payloads::KaraStatus::Physical { filesize, hash } => column![ - text(format!("Remote Name: {}", self.0.remote.remote_name())), - text(format!("Created at: {}", ts.created_at)), - text(format!("Last Modified at: {}", ts.updated_at)), - text(format!("File Size: {}B", filesize)), - text(format!("File Hash: {hash}")), - ], + lektor_payloads::KaraStatus::Virtual => column, + lektor_payloads::KaraStatus::Physical { filesize, hash } => column + .push(file_size(filesize as usize)) + .push(text(format!("File Hash: {hash}"))), }; container(