2024-11-10 02:42:16 +01:00
|
|
|
use {
|
|
|
|
|
crate::{
|
2025-09-05 18:50:25 +02:00
|
|
|
Element, fl,
|
2024-11-10 17:18:58 +01:00
|
|
|
iced::{Alignment, Length},
|
2024-11-10 02:42:16 +01:00
|
|
|
widget::{self, horizontal_space},
|
|
|
|
|
},
|
|
|
|
|
license::License,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, derive_setters::Setters)]
|
|
|
|
|
#[setters(into, strip_option)]
|
|
|
|
|
/// Information about the application.
|
|
|
|
|
pub struct About {
|
|
|
|
|
/// The application's name.
|
|
|
|
|
name: Option<String>,
|
|
|
|
|
/// The application's icon name.
|
2025-07-28 16:33:22 +02:00
|
|
|
icon: Option<widget::icon::Handle>,
|
2025-04-01 21:02:12 +02:00
|
|
|
/// The application's version.
|
2024-11-10 02:42:16 +01:00
|
|
|
version: Option<String>,
|
|
|
|
|
/// Name of the application's author.
|
|
|
|
|
author: Option<String>,
|
|
|
|
|
/// Comments about the application.
|
|
|
|
|
comments: Option<String>,
|
|
|
|
|
/// The application's copyright.
|
|
|
|
|
copyright: Option<String>,
|
|
|
|
|
/// The license name.
|
|
|
|
|
license: Option<String>,
|
2025-09-03 12:49:35 +00:00
|
|
|
/// The license url. If None spdx.org url is used.
|
|
|
|
|
license_url: Option<String>,
|
2024-11-10 02:42:16 +01:00
|
|
|
/// Artists who contributed to the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
artists: Vec<(String, String)>,
|
|
|
|
|
/// Designers who contributed to the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
designers: Vec<(String, String)>,
|
|
|
|
|
/// Developers who contributed to the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
developers: Vec<(String, String)>,
|
|
|
|
|
/// Documenters who contributed to the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
documenters: Vec<(String, String)>,
|
|
|
|
|
/// Translators who contributed to the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
translators: Vec<(String, String)>,
|
|
|
|
|
/// Links associated with the application.
|
|
|
|
|
#[setters(skip)]
|
|
|
|
|
links: Vec<(String, String)>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 21:02:12 +02:00
|
|
|
fn add_contributors(contributors: Vec<(&str, &str)>) -> Vec<(String, String)> {
|
|
|
|
|
contributors
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(name, email)| (name.to_string(), format!("mailto:{email}")))
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-10 02:42:16 +01:00
|
|
|
impl<'a> About {
|
|
|
|
|
/// Artists who contributed to the application.
|
|
|
|
|
pub fn artists(mut self, artists: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
2025-04-01 21:02:12 +02:00
|
|
|
self.artists = add_contributors(artists.into());
|
2024-11-10 02:42:16 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Designers who contributed to the application.
|
|
|
|
|
pub fn designers(mut self, designers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
2025-04-01 21:02:12 +02:00
|
|
|
self.designers = add_contributors(designers.into());
|
2024-11-10 02:42:16 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Developers who contributed to the application.
|
|
|
|
|
pub fn developers(mut self, developers: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
2025-04-01 21:02:12 +02:00
|
|
|
self.developers = add_contributors(developers.into());
|
2024-11-10 02:42:16 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Documenters who contributed to the application.
|
|
|
|
|
pub fn documenters(mut self, documenters: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
2025-04-01 21:02:12 +02:00
|
|
|
self.documenters = add_contributors(documenters.into());
|
2024-11-10 02:42:16 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Translators who contributed to the application.
|
|
|
|
|
pub fn translators(mut self, translators: impl Into<Vec<(&'a str, &'a str)>>) -> Self {
|
2025-04-01 21:02:12 +02:00
|
|
|
self.translators = add_contributors(translators.into());
|
2024-11-10 02:42:16 +01:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Links associated with the application.
|
2025-04-01 21:02:12 +02:00
|
|
|
pub fn links<K: Into<String>, V: Into<String>>(
|
|
|
|
|
mut self,
|
|
|
|
|
links: impl IntoIterator<Item = (K, V)>,
|
|
|
|
|
) -> Self {
|
2024-11-10 02:42:16 +01:00
|
|
|
self.links = links
|
|
|
|
|
.into_iter()
|
2025-04-01 21:02:12 +02:00
|
|
|
.map(|(name, url)| (name.into(), url.into()))
|
2024-11-10 02:42:16 +01:00
|
|
|
.collect();
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 12:49:35 +00:00
|
|
|
fn get_license_url(&self) -> Option<String> {
|
|
|
|
|
self.license_url.clone().or_else(|| {
|
|
|
|
|
self.license.as_ref().and_then(|license_str| {
|
|
|
|
|
let license: &dyn License = license_str.parse().ok()?;
|
|
|
|
|
Some(format!("https://spdx.org/licenses/{}.html", license.id()))
|
|
|
|
|
})
|
2025-04-01 21:02:12 +02:00
|
|
|
})
|
2024-11-10 02:42:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Constructs the widget for the about section.
|
|
|
|
|
pub fn about<'a, Message: Clone + 'static>(
|
|
|
|
|
about: &'a About,
|
|
|
|
|
on_url_press: impl Fn(String) -> Message,
|
|
|
|
|
) -> Element<'a, Message> {
|
2024-11-10 17:18:58 +01:00
|
|
|
let cosmic_theme::Spacing {
|
2025-04-01 21:02:12 +02:00
|
|
|
space_xxs, space_m, ..
|
|
|
|
|
} = crate::theme::spacing();
|
2024-11-10 02:42:16 +01:00
|
|
|
|
2025-09-05 18:50:25 +02:00
|
|
|
let section = |list: &'a Vec<(String, String)>, title: String| {
|
2024-11-10 02:42:16 +01:00
|
|
|
(!list.is_empty()).then_some({
|
2025-04-01 21:02:12 +02:00
|
|
|
let items: Vec<Element<Message>> =
|
2024-11-10 02:42:16 +01:00
|
|
|
list.iter()
|
|
|
|
|
.map(|(name, url)| {
|
|
|
|
|
widget::button::custom(
|
|
|
|
|
widget::row()
|
|
|
|
|
.push(widget::text(name))
|
|
|
|
|
.push(horizontal_space())
|
|
|
|
|
.push_maybe((!url.is_empty()).then_some(
|
|
|
|
|
crate::widget::icon::from_name("link-symbolic").icon(),
|
|
|
|
|
))
|
2024-11-10 17:18:58 +01:00
|
|
|
.align_y(Alignment::Center),
|
2024-11-10 02:42:16 +01:00
|
|
|
)
|
2025-04-01 21:02:12 +02:00
|
|
|
.class(crate::theme::Button::Link)
|
2024-11-10 02:42:16 +01:00
|
|
|
.on_press(on_url_press(url.clone()))
|
|
|
|
|
.width(Length::Fill)
|
|
|
|
|
.into()
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
2025-04-01 21:02:12 +02:00
|
|
|
widget::settings::section().title(title).extend(items)
|
2024-11-10 02:42:16 +01:00
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let application_name = about.name.as_ref().map(widget::text::title3);
|
2025-08-20 17:33:55 +02:00
|
|
|
let application_icon = about.icon.as_ref().map(|i| {
|
|
|
|
|
i.clone()
|
|
|
|
|
.icon()
|
|
|
|
|
.content_fit(iced::ContentFit::Contain)
|
|
|
|
|
.width(Length::Fixed(128.))
|
|
|
|
|
.height(Length::Fixed(128.))
|
|
|
|
|
});
|
2025-04-01 21:02:12 +02:00
|
|
|
let author = about.author.as_ref().map(widget::text::body);
|
|
|
|
|
let version = about.version.as_ref().map(widget::button::standard);
|
2025-09-05 18:50:25 +02:00
|
|
|
let links_section = section(&about.links, fl!("links"));
|
|
|
|
|
let developers_section = section(&about.developers, fl!("developers"));
|
|
|
|
|
let designers_section = section(&about.designers, fl!("designers"));
|
|
|
|
|
let artists_section = section(&about.artists, fl!("artists"));
|
|
|
|
|
let translators_section = section(&about.translators, fl!("translators"));
|
|
|
|
|
let documenters_section = section(&about.documenters, fl!("documenters"));
|
2024-11-10 02:42:16 +01:00
|
|
|
let license = about.license.as_ref().map(|license| {
|
2025-09-03 12:49:35 +00:00
|
|
|
let url = about.get_license_url();
|
2025-09-05 18:50:25 +02:00
|
|
|
widget::settings::section().title(fl!("license")).add(
|
2024-11-10 02:42:16 +01:00
|
|
|
widget::button::custom(
|
|
|
|
|
widget::row()
|
|
|
|
|
.push(widget::text(license))
|
|
|
|
|
.push(horizontal_space())
|
|
|
|
|
.push_maybe(
|
|
|
|
|
url.is_some()
|
|
|
|
|
.then_some(crate::widget::icon::from_name("link-symbolic").icon()),
|
|
|
|
|
)
|
2024-11-10 17:18:58 +01:00
|
|
|
.align_y(Alignment::Center),
|
2024-11-10 02:42:16 +01:00
|
|
|
)
|
2025-04-01 21:02:12 +02:00
|
|
|
.class(crate::theme::Button::Link)
|
2025-03-14 11:56:21 -04:00
|
|
|
.on_press(on_url_press(url.unwrap_or_default()))
|
2024-11-10 02:42:16 +01:00
|
|
|
.width(Length::Fill),
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
let copyright = about.copyright.as_ref().map(widget::text::body);
|
|
|
|
|
let comments = about.comments.as_ref().map(widget::text::body);
|
|
|
|
|
|
2024-11-10 17:18:58 +01:00
|
|
|
widget::column()
|
2025-04-01 21:02:12 +02:00
|
|
|
.push(
|
|
|
|
|
widget::column()
|
|
|
|
|
.push_maybe(application_icon)
|
|
|
|
|
.push_maybe(application_name)
|
|
|
|
|
.push_maybe(author)
|
|
|
|
|
.push_maybe(version)
|
|
|
|
|
.align_x(Alignment::Center)
|
|
|
|
|
.spacing(space_xxs),
|
|
|
|
|
)
|
2024-11-10 17:18:58 +01:00
|
|
|
.push_maybe(license)
|
|
|
|
|
.push_maybe(links_section)
|
|
|
|
|
.push_maybe(developers_section)
|
|
|
|
|
.push_maybe(designers_section)
|
|
|
|
|
.push_maybe(artists_section)
|
|
|
|
|
.push_maybe(translators_section)
|
|
|
|
|
.push_maybe(documenters_section)
|
|
|
|
|
.push_maybe(comments)
|
|
|
|
|
.push_maybe(copyright)
|
|
|
|
|
.align_x(Alignment::Center)
|
2025-04-01 21:02:12 +02:00
|
|
|
.spacing(space_m)
|
2024-11-10 17:18:58 +01:00
|
|
|
.width(Length::Fill)
|
|
|
|
|
.into()
|
2024-11-10 02:42:16 +01:00
|
|
|
}
|