From f168862cc755324906531bd19c20de58b22499ea Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sun, 22 Jan 2023 11:56:56 +0200 Subject: [PATCH] Components list: added working "recommended only" switcher --- src/ui/components/group.rs | 39 +++++++---- src/ui/components/list.rs | 39 +++++++---- src/ui/components/mod.rs | 43 +++++++++++- src/ui/components/version.rs | 22 +++++-- src/ui/preferences/general.rs | 8 ++- src/ui/preferences/main.rs | 120 +++++++++++++--------------------- 6 files changed, 163 insertions(+), 108 deletions(-) diff --git a/src/ui/components/group.rs b/src/ui/components/group.rs index 81d2f94..57730b1 100644 --- a/src/ui/components/group.rs +++ b/src/ui/components/group.rs @@ -3,13 +3,15 @@ use relm4::prelude::*; use adw::prelude::*; pub struct ComponentGroup { - pub title: String + pub title: String, + pub show_recommended_only: bool, + + pub versions: Vec> } #[derive(Debug)] pub enum AppMsg { - Install, - Remove + ShowRecommendedOnly(bool) } #[relm4::component(pub)] @@ -30,16 +32,22 @@ impl SimpleComponent for ComponentGroup { _sender: ComponentSender, ) -> ComponentParts { let model = ComponentGroup { - title: init.title + title: init.title, + show_recommended_only: true, + + versions: init.versions + .into_iter() + .map(|version| { + super::ComponentVersion::builder() + .launch(version) + .detach() + }) + .collect() }; let widgets = view_output!(); - for version in init.versions { - let version = super::ComponentVersion::builder() - .launch(version) - .detach(); - + for version in &model.versions { widgets.group.add_row(version.widget()); } @@ -47,8 +55,17 @@ impl SimpleComponent for ComponentGroup { } fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { - tracing::debug!("Called about dialog event: {:?}", msg); + tracing::debug!("Called component group [{}] event: {:?}", self.title, msg); - // todo + match msg { + AppMsg::ShowRecommendedOnly(state) => { + self.show_recommended_only = state; + + // todo + for version in &self.versions { + version.sender().send(super::version::AppMsg::ShowRecommendedOnly(state)).unwrap(); + } + } + } } } diff --git a/src/ui/components/list.rs b/src/ui/components/list.rs index 716ac11..9a91bec 100644 --- a/src/ui/components/list.rs +++ b/src/ui/components/list.rs @@ -3,13 +3,15 @@ use relm4::prelude::*; use adw::prelude::*; pub struct ComponentsList { - _download_folder: String + pub _download_folder: String, + pub show_recommended_only: bool, + + pub groups: Vec> } #[derive(Debug)] pub enum AppMsg { - Install, - Remove + ShowRecommendedOnly(bool) } #[relm4::component(pub)] @@ -28,16 +30,22 @@ impl SimpleComponent for ComponentsList { _sender: ComponentSender, ) -> ComponentParts { let model = ComponentsList { - _download_folder: init.download_folder + _download_folder: init.download_folder, + show_recommended_only: true, + + groups: init.groups + .into_iter() + .map(|group| { + super::ComponentGroup::builder() + .launch(group) + .detach() + }) + .collect() }; let widgets = view_output!(); - for group in init.groups { - let group = super::ComponentGroup::builder() - .launch(group) - .detach(); - + for group in &model.groups { widgets.group.add(group.widget()); } @@ -45,8 +53,17 @@ impl SimpleComponent for ComponentsList { } fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { - tracing::debug!("Called about dialog event: {:?}", msg); + tracing::debug!("Called components list event: {:?}", msg); - // todo + match msg { + AppMsg::ShowRecommendedOnly(state) => { + self.show_recommended_only = state; + + // todo + for group in &self.groups { + group.sender().send(super::group::AppMsg::ShowRecommendedOnly(state)).unwrap(); + } + } + } } } diff --git a/src/ui/components/mod.rs b/src/ui/components/mod.rs index 0ee9164..1b8aa47 100644 --- a/src/ui/components/mod.rs +++ b/src/ui/components/mod.rs @@ -6,6 +6,8 @@ pub use list::*; pub use group::*; pub use version::*; +use anime_launcher_sdk::components::*; + #[derive(Debug, Clone, PartialEq, Eq)] pub struct ComponentsListPattern { pub download_folder: String, @@ -18,8 +20,47 @@ pub struct ComponentsListGroup { pub versions: Vec } +impl From for ComponentsListGroup { + fn from(group: wine::Group) -> Self { + Self { + title: group.name, + versions: group.versions.into_iter().map(|version| version.into()).collect() + } + } +} + +impl From for ComponentsListGroup { + fn from(group: dxvk::Group) -> Self { + Self { + title: group.name, + versions: group.versions.into_iter().map(|version| version.into()).collect() + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct ComponentsListVersion { pub title: String, - pub url: String + pub uri: String, + pub recommended: bool +} + +impl From for ComponentsListVersion { + fn from(version: wine::Version) -> Self { + Self { + title: version.title, + uri: version.uri, + recommended: version.recommended + } + } +} + +impl From for ComponentsListVersion { + fn from(version: dxvk::Version) -> Self { + Self { + title: version.name, + uri: version.uri, + recommended: version.recommended + } + } } diff --git a/src/ui/components/version.rs b/src/ui/components/version.rs index a173cc1..cf0e0dd 100644 --- a/src/ui/components/version.rs +++ b/src/ui/components/version.rs @@ -3,13 +3,14 @@ use relm4::prelude::*; use adw::prelude::*; pub struct ComponentVersion { - pub title: String + pub title: String, + pub recommended: bool, + pub show_recommended_only: bool } #[derive(Debug)] pub enum AppMsg { - Install, - Remove + ShowRecommendedOnly(bool) } #[relm4::component(pub)] @@ -20,7 +21,10 @@ impl SimpleComponent for ComponentVersion { view! { row = adw::ActionRow { - set_title: &model.title + set_title: &model.title, + + #[watch] + set_visible: !model.show_recommended_only || model.recommended } } @@ -30,7 +34,9 @@ impl SimpleComponent for ComponentVersion { _sender: ComponentSender, ) -> ComponentParts { let model = ComponentVersion { - title: init.title + title: init.title, + recommended: init.recommended, + show_recommended_only: true }; let widgets = view_output!(); @@ -39,8 +45,10 @@ impl SimpleComponent for ComponentVersion { } fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { - tracing::debug!("Called about dialog event: {:?}", msg); + tracing::debug!("Called component version [{}] event: {:?}", self.title, msg); - // todo + match msg { + AppMsg::ShowRecommendedOnly(state) => self.show_recommended_only = state + } } } diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index f1b4cfd..af4eaba 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -142,8 +142,10 @@ impl WidgetTemplate for General { set_title: &tr("recommended-only"), set_subtitle: &tr("wine-recommended-description"), + #[name(wine_recommended_only)] add_suffix = >k::Switch { - set_valign: gtk::Align::Center + set_valign: gtk::Align::Center, + set_state: true } } }, @@ -162,8 +164,10 @@ impl WidgetTemplate for General { set_title: &tr("recommended-only"), set_subtitle: &tr("dxvk-recommended-description"), + #[name(dxvk_recommended_only)] add_suffix = >k::Switch { - set_valign: gtk::Align::Center + set_valign: gtk::Align::Center, + set_state: true } } }, diff --git a/src/ui/preferences/main.rs b/src/ui/preferences/main.rs index 89b88ed..a213e9a 100644 --- a/src/ui/preferences/main.rs +++ b/src/ui/preferences/main.rs @@ -3,7 +3,9 @@ use relm4::prelude::*; use gtk::prelude::*; use adw::prelude::*; -use crate::ui::components::*; +use anime_launcher_sdk::components::*; + +use crate::ui::components::{self, *}; use crate::i18n::tr; @@ -12,10 +14,16 @@ pub struct App { dxvk_components: Controller } +#[derive(Debug)] +pub enum AppMsg { + WineRecommendedOnly(bool), + DxvkRecommendedOnly(bool) +} + #[relm4::component(pub)] impl SimpleComponent for App { type Init = gtk::Window; - type Input = (); + type Input = AppMsg; type Output = (); view! { @@ -36,10 +44,24 @@ impl SimpleComponent for App { add = model.wine_components.widget(), }, + #[template_child] + wine_recommended_only { + connect_state_notify[sender] => move |switch| { + sender.input(AppMsg::WineRecommendedOnly(switch.state())); + } + }, + #[template_child] dxvk_versions { add = model.dxvk_components.widget(), - } + }, + + #[template_child] + dxvk_recommended_only { + connect_state_notify[sender] => move |switch| { + sender.input(AppMsg::DxvkRecommendedOnly(switch.state())); + } + }, }, #[template] @@ -56,90 +78,20 @@ impl SimpleComponent for App { fn init( parent: Self::Init, root: &Self::Root, - _sender: ComponentSender, + sender: ComponentSender, ) -> ComponentParts { let model = App { wine_components: ComponentsList::builder() .launch(ComponentsListPattern { download_folder: String::from("/tmp"), - groups: vec![ - ComponentsListGroup { - title: String::from("Test group 1"), - versions: vec![ - ComponentsListVersion { - title: String::from("Test version 1"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 2"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 3"), - url: String::from("/") - } - ] - }, - ComponentsListGroup { - title: String::from("Test group 2"), - versions: vec![ - ComponentsListVersion { - title: String::from("Test version 1"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 2"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 3"), - url: String::from("/") - } - ] - } - ] + groups: wine::get_groups().into_iter().map(|group| group.into()).collect() }) .detach(), dxvk_components: ComponentsList::builder() .launch(ComponentsListPattern { download_folder: String::from("/tmp"), - groups: vec![ - ComponentsListGroup { - title: String::from("Test group 1"), - versions: vec![ - ComponentsListVersion { - title: String::from("Test version 1"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 2"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 3"), - url: String::from("/") - } - ] - }, - ComponentsListGroup { - title: String::from("Test group 2"), - versions: vec![ - ComponentsListVersion { - title: String::from("Test version 1"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 2"), - url: String::from("/") - }, - ComponentsListVersion { - title: String::from("Test version 3"), - url: String::from("/") - } - ] - } - ] + groups: dxvk::get_groups().into_iter().map(|group| group.into()).collect() }) .detach(), }; @@ -150,4 +102,20 @@ impl SimpleComponent for App { ComponentParts { model, widgets } } + + fn update(&mut self, msg: Self::Input, _sender: ComponentSender) { + tracing::debug!("Called preferences window event: {:?}", msg); + + match msg { + AppMsg::WineRecommendedOnly(state) => { + // todo + self.wine_components.sender().send(components::list::AppMsg::ShowRecommendedOnly(state)).unwrap(); + } + + AppMsg::DxvkRecommendedOnly(state) => { + // todo + self.dxvk_components.sender().send(components::list::AppMsg::ShowRecommendedOnly(state)).unwrap(); + } + } + } }