muda/src/about_metadata.rs

177 lines
4.9 KiB
Rust
Raw Normal View History

2023-07-18 11:59:47 +10:00
use crate::icon::Icon;
2023-07-18 12:00:38 +10:00
/// Application metadata for the [`PredefinedMenuItem::about`](crate::PredefinedMenuItem::about).
2023-07-18 11:59:47 +10:00
#[derive(Debug, Clone, Default)]
pub struct AboutMetadata {
/// Sets the application name.
pub name: Option<String>,
/// The application version.
pub version: Option<String>,
/// The short version, e.g. "1.0".
///
/// ## Platform-specific
///
/// - **Windows / Linux:** Appended to the end of `version` in parentheses.
pub short_version: Option<String>,
/// The authors of the application.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub authors: Option<Vec<String>>,
/// Application comments.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub comments: Option<String>,
/// The copyright of the application.
pub copyright: Option<String>,
/// The license of the application.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub license: Option<String>,
/// The application website.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub website: Option<String>,
/// The website label.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub website_label: Option<String>,
/// The credits.
///
/// ## Platform-specific
///
/// - **Windows / Linux:** Unsupported.
pub credits: Option<String>,
/// The application icon.
///
/// ## Platform-specific
///
/// - **Windows:** Unsupported.
pub icon: Option<Icon>,
}
impl AboutMetadata {
#[allow(unused)]
pub(crate) fn full_version(&self) -> Option<String> {
Some(format!(
"{}{}",
(self.version.as_ref())?,
(self.short_version.as_ref())
.map(|v| format!(" ({v})"))
.unwrap_or_default()
))
}
}
/// A builder type for [`AboutMetadata`].
#[derive(Clone, Debug, Default)]
pub struct AboutMetadataBuilder(AboutMetadata);
impl AboutMetadataBuilder {
pub fn new() -> Self {
Default::default()
}
/// Sets the application name.
pub fn name<S: Into<String>>(mut self, name: Option<S>) -> Self {
self.0.name = name.map(|s| s.into());
self
}
/// Sets the application version.
pub fn version<S: Into<String>>(mut self, version: Option<S>) -> Self {
self.0.version = version.map(|s| s.into());
self
}
/// Sets the short version, e.g. "1.0".
///
/// ## Platform-specific
///
/// - **Windows / Linux:** Appended to the end of `version` in parentheses.
pub fn short_version<S: Into<String>>(mut self, short_version: Option<S>) -> Self {
self.0.short_version = short_version.map(|s| s.into());
self
}
/// Sets the authors of the application.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub fn authors(mut self, authors: Option<Vec<String>>) -> Self {
self.0.authors = authors;
self
}
/// Application comments.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub fn comments<S: Into<String>>(mut self, comments: Option<S>) -> Self {
self.0.comments = comments.map(|s| s.into());
self
}
/// Sets the copyright of the application.
pub fn copyright<S: Into<String>>(mut self, copyright: Option<S>) -> Self {
self.0.copyright = copyright.map(|s| s.into());
self
}
/// Sets the license of the application.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub fn license<S: Into<String>>(mut self, license: Option<S>) -> Self {
self.0.license = license.map(|s| s.into());
self
}
/// Sets the application website.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub fn website<S: Into<String>>(mut self, website: Option<S>) -> Self {
self.0.website = website.map(|s| s.into());
self
}
/// Sets the website label.
///
/// ## Platform-specific
///
/// - **macOS:** Unsupported.
pub fn website_label<S: Into<String>>(mut self, website_label: Option<S>) -> Self {
self.0.website_label = website_label.map(|s| s.into());
self
}
/// Sets the credits.
///
/// ## Platform-specific
///
/// - **Windows / Linux:** Unsupported.
pub fn credits<S: Into<String>>(mut self, credits: Option<S>) -> Self {
self.0.credits = credits.map(|s| s.into());
self
}
/// Sets the application icon.
///
/// ## Platform-specific
///
/// - **Windows:** Unsupported.
pub fn icon(mut self, icon: Option<Icon>) -> Self {
self.0.icon = icon;
self
}
/// Construct the final [`AboutMetadata`]
pub fn build(self) -> AboutMetadata {
self.0
}
}