fix: return reference to About

This commit is contained in:
Eduardo Flores 2024-11-04 16:22:01 +00:00
parent 8b296ebe8f
commit 3dc8c49f40
2 changed files with 93 additions and 80 deletions

View file

@ -32,19 +32,46 @@ pub struct About {
/// The license from a list of known licenses. /// The license from a list of known licenses.
pub license_type: Option<String>, pub license_type: Option<String>,
/// The URL of the application’s support page. /// The URL of the application’s support page.
#[setters(skip)]
pub support_url: Option<String>, pub support_url: Option<String>,
/// The URL of the application’s repository. /// The URL of the application’s repository.
#[setters(skip)]
pub repository_url: Option<String>, pub repository_url: Option<String>,
/// Translators who contributed to the application. /// Translators who contributed to the application.
#[setters(skip)] #[setters(skip)]
pub translators: BTreeMap<String, String>, pub translators: BTreeMap<String, String>,
/// Links associated with the application.
#[setters(skip)]
pub links: BTreeMap<String, String>,
/// The application’s version. /// The application’s version.
pub version: Option<String>, pub version: Option<String>,
/// The application’s website. /// The application’s website.
#[setters(skip)]
pub website: Option<String>, pub website: Option<String>,
} }
impl About { impl About {
pub fn set_repository_url(mut self, repository_url: impl Into<String>) -> Self {
let repository_url = repository_url.into();
self.repository_url = Some(repository_url.clone());
self.links.insert("Repository".into(), repository_url);
self
}
pub fn set_support_url(mut self, support_url: impl Into<String>) -> Self {
let support_url = support_url.into();
self.support_url = Some(support_url.clone());
self.links.insert("Support".into(), support_url);
self
}
pub fn set_website(mut self, website: impl Into<String>) -> Self {
let website = website.into();
self.website = Some(website.clone());
self.links.insert("Website".into(), website);
self
}
pub fn set_artists(mut self, artists: impl Into<BTreeMap<String, String>>) -> Self { pub fn set_artists(mut self, artists: impl Into<BTreeMap<String, String>>) -> Self {
let artists: BTreeMap<String, String> = artists.into(); let artists: BTreeMap<String, String> = artists.into();
self.artists = artists self.artists = artists

View file

@ -604,17 +604,18 @@ where
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
/// Provides information about the application. /// Provides information about the application.
fn about(&self) -> Option<About> { fn about(&self) -> Option<&About> {
None None
} }
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
/// Constructs the view for the about section. /// Constructs the view for the about section.
fn about_view<'a>(&self) -> Element<'a, crate::app::cosmic::Message> { fn about_view<'a>(&'a self) -> Option<Element<'a, crate::app::cosmic::Message>> {
if let Some(about) = self.about() { let about = self.about()?;
let spacing = crate::theme::active().cosmic().spacing; let spacing = crate::theme::active().cosmic().spacing;
let section = |list: BTreeMap<String, String>, title: &'a str| { let section = |list: &'a BTreeMap<String, String>, title: &'a str| {
if list.is_empty() { if list.is_empty() {
None None
} else { } else {
@ -630,7 +631,7 @@ where
.align_y(Vertical::Center), .align_y(Vertical::Center),
) )
.class(crate::theme::Button::Text) .class(crate::theme::Button::Text)
.on_press(crate::app::cosmic::Message::OpenUrl(url)) .on_press(crate::app::cosmic::Message::OpenUrl(url.clone()))
.width(Length::Fill) .width(Length::Fill)
.into() .into()
}) })
@ -639,39 +640,26 @@ where
} }
}; };
let application_name = about.application_name.map(widget::text::title3); let application_name = about.application_name.as_ref().map(widget::text::title3);
let application_icon = about let application_icon = about
.application_icon .application_icon
.map(|icon| crate::desktop::IconSource::Name(icon).as_cosmic_icon()); .as_ref()
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
let mut links: BTreeMap<String, String> = BTreeMap::new(); let links_section = section(&about.links, "Links");
let developers_section = section(&about.developers, "Developers");
let designers_section = section(&about.designers, "Designers");
let artists_section = section(&about.artists, "Artists");
let translators_section = section(&about.translators, "Translators");
let documenters_section = section(&about.documenters, "Documenters");
if let Some(website) = about.website { let developer_name = about.developer_name.as_ref().map(widget::text);
links.insert("Website".into(), website); let version = about.version.as_ref().map(widget::button::standard);
} let license = about.license_type.as_ref().map(widget::button::standard);
let copyright = about.copyright.as_ref().map(widget::text::body);
let comments = about.comments.as_ref().map(widget::text::body);
if let Some(repository_url) = about.repository_url { let about = widget::column()
links.insert("Repository".into(), repository_url);
}
if let Some(support_url) = about.support_url {
links.insert("Support".into(), support_url);
}
let links_section = section(links, "Links");
let developers_section = section(about.developers, "Developers");
let designers_section = section(about.designers, "Designers");
let artists_section = section(about.artists, "Artists");
let translators_section = section(about.translators, "Translators");
let documenters_section = section(about.documenters, "Documenters");
let developer_name = about.developer_name.map(widget::text);
let version = about.version.map(widget::button::standard);
let license = about.license_type.map(widget::button::standard);
let copyright = about.copyright.map(widget::text::body);
let comments = about.comments.map(widget::text::body);
widget::column()
.push_maybe(application_icon) .push_maybe(application_icon)
.push_maybe(application_name) .push_maybe(application_name)
.push_maybe(developer_name) .push_maybe(developer_name)
@ -692,10 +680,8 @@ where
.align_x(Alignment::Center) .align_x(Alignment::Center)
.spacing(spacing.space_xs) .spacing(spacing.space_xs)
.width(Length::Fill) .width(Length::Fill)
.into() .into();
} else { Some(about)
crate::widget::text("Test").into()
}
} }
/// Overrides the default style for applications /// Overrides the default style for applications