From ae64f731765ba4f745f4867f408ab124e965cde1 Mon Sep 17 00:00:00 2001 From: jane400 Date: Wed, 28 Aug 2024 15:09:18 +0200 Subject: [PATCH] feat: more details button in SendungsVerfolgung --- icons.toml | 3 + paket/Cargo.toml | 1 + paket/src/main.rs | 8 +++ paket/src/tracking.rs | 125 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 icons.toml diff --git a/icons.toml b/icons.toml new file mode 100644 index 0000000..44351fe --- /dev/null +++ b/icons.toml @@ -0,0 +1,3 @@ +app_id = "de.j4ne.Paket" + +icons = ["plus", "minus"] \ No newline at end of file diff --git a/paket/Cargo.toml b/paket/Cargo.toml index d820655..040853c 100644 --- a/paket/Cargo.toml +++ b/paket/Cargo.toml @@ -16,3 +16,4 @@ reqwest = "0.12" libpaket = { path = "../libpaket" } glycin = { version = "2.0.0-beta", features = ["gdk4"] } oo7 = { version = "0.3" } +relm4-icons = { version = "0.9" } \ No newline at end of file diff --git a/paket/src/main.rs b/paket/src/main.rs index a6b8e50..012de53 100644 --- a/paket/src/main.rs +++ b/paket/src/main.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use login::{Login, LoginOutput, LoginSharedState}; use ready::{Ready, ReadyOutput}; use relm4::{ + RELM_THREADS, adw, gtk, main_adw_application, prelude::*, tokio::sync::Mutex, AsyncComponentSender, SharedState, }; @@ -289,6 +290,13 @@ fn convert_ready_response(response: ReadyOutput) -> AppInput { } fn main() { + RELM_THREADS.set(4).unwrap(); + gtk::init().unwrap(); + let display = gtk::gdk::Display::default().unwrap(); + let theme = gtk::IconTheme::for_display(&display); + theme.add_resource_path("/de/j4ne/Paket/icons/"); + theme.add_resource_path("/de/j4ne/Paket/scalable/actions/"); + relm4_icons::initialize_icons(); let app = RelmApp::new(constants::APP_ID); app.run_async::(()); } diff --git a/paket/src/tracking.rs b/paket/src/tracking.rs index 725d467..3fd8bf8 100644 --- a/paket/src/tracking.rs +++ b/paket/src/tracking.rs @@ -6,6 +6,20 @@ use relm4::{adw, gtk}; pub struct ShipmentView { model: Shipment, + + // model abstraction + have_events: bool, + + // state + expanded: bool, + + // workarounds + list_box_history: gtk::ListBox, +} + +#[derive(Debug)] +pub enum ViewInput { + ToggleExpand, } #[relm4::factory(pub)] @@ -13,7 +27,7 @@ impl FactoryComponent for ShipmentView { type CommandOutput = (); type Init = Shipment; type Output = (); - type Input = (); + type Input = ViewInput; type ParentWidget = gtk::Box; type Index = String; @@ -23,14 +37,26 @@ impl FactoryComponent for ShipmentView { add_css_class: relm4::css::CARD, set_hexpand: true, set_margin_all: 8, + set_orientation: gtk::Orientation::Vertical, + + gtk::ProgressBar { + add_css_class: relm4::css::OSD, + set_margin_start: 8, + set_margin_end: 8, + set_margin_bottom: 1, + + set_fraction: f64::from(self.model.history.maximal_fortschritt) / f64::from(self.model.history.fortschritt), + }, // title box gtk::Box { - set_orientation: gtk::Orientation::Vertical, + set_orientation: gtk::Orientation::Horizontal, + set_hexpand: true, set_margin_all: 8, gtk::Box { set_orientation: gtk::Orientation::Vertical, + set_hexpand: true, set_halign: gtk::Align::Start, gtk::Label { @@ -61,9 +87,52 @@ impl FactoryComponent for ShipmentView { } } } + }, + + gtk::Button { + set_halign: gtk::Align::End, + add_css_class: relm4::css::FLAT, + + #[watch] + set_icon_name: { + if self.expanded { + relm4_icons::icon_names::MINUS + } else { + relm4_icons::icon_names::PLUS + } + }, + + connect_clicked => ViewInput::ToggleExpand, } - } + }, // title box end + + gtk::Revealer { + #[watch] + set_reveal_child: self.expanded, + + #[wrap(Some)] + set_child = >k::Box { + // history viewstack + adw::StatusPage { + set_visible: !self.have_events, + + set_title: "No events", + + }, + + append = &self.list_box_history.clone() { + set_visible: self.have_events, + + add_css_class: relm4::css::BOXED_LIST, + + set_selection_mode: gtk::SelectionMode::None, + + }, + + } + }, } + } fn init_model( @@ -71,8 +140,54 @@ impl FactoryComponent for ShipmentView { index: &Self::Index, sender: relm4::FactorySender, ) -> Self { - let model = ShipmentView { model: init }; + let have_events = init.history.events.as_ref().is_some_and(|a| a.len() > 0); - model + let list_box_history = gtk::ListBox::new(); + + let _self = ShipmentView { + have_events, + model: init, + list_box_history, + expanded: false, + }; + + for elem in _self.model.history.events.as_ref().unwrap() { + let label_datum = gtk::Label::builder() + .css_classes([relm4::css::NUMERIC]) + .label(&elem.datum) + .halign(gtk::Align::Start) + .valign(gtk::Align::Start) + .build(); + + // TODO: is html, parse it + let label_status = gtk::Label::builder() + .wrap(true) + .halign(gtk::Align::Start) + .valign(gtk::Align::Start) + .build(); + label_status.set_markup(&elem.status); + + let boxie = gtk::Box::builder() + .orientation(gtk::Orientation::Horizontal) + .margin_start(8) + .margin_end(8) + .spacing(8) + .build(); + + boxie.append(&label_datum); + boxie.append(&label_status); + + _self.list_box_history.append(&boxie); + } + + _self + } + + fn update(&mut self, message: Self::Input, sender: FactorySender) { + match message { + ViewInput::ToggleExpand => { + self.expanded = !self.expanded; + } + } } }