improv: about api
This commit is contained in:
parent
ed5fe4bccc
commit
dd8f73f9ba
4 changed files with 77 additions and 81 deletions
|
|
@ -40,7 +40,7 @@ desktop = [
|
||||||
"process",
|
"process",
|
||||||
"dep:freedesktop-desktop-entry",
|
"dep:freedesktop-desktop-entry",
|
||||||
"dep:mime",
|
"dep:mime",
|
||||||
|
"dep:license",
|
||||||
"dep:shlex",
|
"dep:shlex",
|
||||||
"tokio?/io-util",
|
"tokio?/io-util",
|
||||||
"tokio?/net",
|
"tokio?/net",
|
||||||
|
|
@ -98,6 +98,7 @@ fraction = "0.15.3"
|
||||||
image = { version = "0.25.1", optional = true }
|
image = { version = "0.25.1", optional = true }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
libc = { version = "0.2.155", optional = true }
|
libc = { version = "0.2.155", optional = true }
|
||||||
|
license = { version = "3.5.1", optional = true }
|
||||||
mime = { version = "0.3.17", optional = true }
|
mime = { version = "0.3.17", optional = true }
|
||||||
palette = "0.7.3"
|
palette = "0.7.3"
|
||||||
rfd = { version = "0.14.0", optional = true }
|
rfd = { version = "0.14.0", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -64,14 +64,17 @@ impl cosmic::Application for App {
|
||||||
let nav_model = nav_bar::Model::default();
|
let nav_model = nav_bar::Model::default();
|
||||||
|
|
||||||
let about = About::default()
|
let about = About::default()
|
||||||
.set_application_name("About Demo")
|
.name("About Demo")
|
||||||
.set_application_icon(Self::APP_ID)
|
.icon(Self::APP_ID)
|
||||||
.set_developer_name("System 76")
|
.version("0.1.0")
|
||||||
.set_license_type("GPL-3.0")
|
.author("System 76")
|
||||||
.set_website("https://system76.com/cosmic")
|
.license("GPL-3.0-only")
|
||||||
.set_repository_url("https://github.com/pop-os/libcosmic")
|
.developers([("Michael Murphy", "mmstick@system76.com")])
|
||||||
.set_support_url("https://github.com/pop-os/libcosmic/issues")
|
.links([
|
||||||
.set_developers([("Michael Murphy".into(), "mmstick@system76.com".into())]);
|
("Website", "https://system76.com/cosmic"),
|
||||||
|
("Repository", "https://github.com/pop-os/libcosmic)"),
|
||||||
|
("Support", "https://github.com/pop-os/libcosmic/issues"),
|
||||||
|
]);
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
2
iced
2
iced
|
|
@ -1 +1 @@
|
||||||
Subproject commit a7e035cd852ab13ce0ef04671c1e683fc343aff6
|
Subproject commit 3297263977365a5d7e4c4cd9bbc13613b674763b
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use iced_widget::tooltip::Position;
|
||||||
|
use license::License;
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
|
|
@ -9,120 +11,108 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, derive_setters::Setters)]
|
#[derive(Debug, Default, Clone, derive_setters::Setters)]
|
||||||
#[setters(prefix = "set_", into, strip_option)]
|
#[setters(into, strip_option)]
|
||||||
/// Information about the application.
|
/// Information about the application.
|
||||||
pub struct About {
|
pub struct About {
|
||||||
/// The application's name.
|
/// The application's name.
|
||||||
pub application_name: Option<String>,
|
name: Option<String>,
|
||||||
/// The application's icon name.
|
/// The application's icon name.
|
||||||
pub application_icon: Option<String>,
|
icon: Option<String>,
|
||||||
|
/// The application’s version.
|
||||||
|
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 text.
|
||||||
|
license: Option<String>,
|
||||||
/// Artists who contributed to the application.
|
/// Artists who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub artists: BTreeMap<String, String>,
|
artists: BTreeMap<String, String>,
|
||||||
/// Comments about the application.
|
|
||||||
pub comments: Option<String>,
|
|
||||||
/// The application's copyright.
|
|
||||||
pub copyright: Option<String>,
|
|
||||||
/// Designers who contributed to the application.
|
/// Designers who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub designers: BTreeMap<String, String>,
|
designers: BTreeMap<String, String>,
|
||||||
/// Name of the application's developer.
|
|
||||||
pub developer_name: Option<String>,
|
|
||||||
/// Developers who contributed to the application.
|
/// Developers who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub developers: BTreeMap<String, String>,
|
developers: BTreeMap<String, String>,
|
||||||
/// Documenters who contributed to the application.
|
/// Documenters who contributed to the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub documenters: BTreeMap<String, String>,
|
documenters: BTreeMap<String, String>,
|
||||||
/// The license text.
|
|
||||||
pub license: Option<String>,
|
|
||||||
/// The license from a list of known licenses.
|
|
||||||
pub license_type: Option<String>,
|
|
||||||
/// The URL of the application’s support page.
|
|
||||||
#[setters(skip)]
|
|
||||||
pub support_url: Option<String>,
|
|
||||||
/// The URL of the application’s repository.
|
|
||||||
#[setters(skip)]
|
|
||||||
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>,
|
translators: BTreeMap<String, String>,
|
||||||
/// Links associated with the application.
|
/// Links associated with the application.
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub links: BTreeMap<String, String>,
|
links: BTreeMap<String, String>,
|
||||||
/// The application’s version.
|
|
||||||
pub version: Option<String>,
|
|
||||||
/// The application’s website.
|
|
||||||
#[setters(skip)]
|
|
||||||
pub website: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl About {
|
impl<'a> About {
|
||||||
pub fn set_repository_url(mut self, repository_url: impl Into<String>) -> Self {
|
pub fn links(mut self, links: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let repository_url = repository_url.into();
|
let links: BTreeMap<&'a str, &'a str> = links.into();
|
||||||
self.repository_url = Some(repository_url.clone());
|
self.links = links
|
||||||
self.links.insert("Repository".into(), repository_url);
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||||
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_support_url(mut self, support_url: impl Into<String>) -> Self {
|
pub fn artists(mut self, artists: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let support_url = support_url.into();
|
let artists: BTreeMap<&'a str, &'a str> = artists.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 {
|
|
||||||
let artists: BTreeMap<String, String> = artists.into();
|
|
||||||
self.artists = artists
|
self.artists = artists
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, format!("mailto:{v}")))
|
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_designers(mut self, designers: impl Into<BTreeMap<String, String>>) -> Self {
|
pub fn designers(mut self, designers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let designers: BTreeMap<String, String> = designers.into();
|
let designers: BTreeMap<&'a str, &'a str> = designers.into();
|
||||||
self.designers = designers
|
self.designers = designers
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, format!("mailto:{v}")))
|
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_developers(mut self, developers: impl Into<BTreeMap<String, String>>) -> Self {
|
pub fn developers(mut self, developers: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let developers: BTreeMap<String, String> = developers.into();
|
let developers: BTreeMap<&'a str, &'a str> = developers.into();
|
||||||
self.developers = developers
|
self.developers = developers
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, format!("mailto:{v}")))
|
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_documenters(mut self, documenters: impl Into<BTreeMap<String, String>>) -> Self {
|
pub fn documenters(mut self, documenters: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let documenters: BTreeMap<String, String> = documenters.into();
|
let documenters: BTreeMap<&'a str, &'a str> = documenters.into();
|
||||||
self.documenters = documenters
|
self.documenters = documenters
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, format!("mailto:{v}")))
|
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_translators(mut self, translators: impl Into<BTreeMap<String, String>>) -> Self {
|
pub fn translators(mut self, translators: impl Into<BTreeMap<&'a str, &'a str>>) -> Self {
|
||||||
let translators: BTreeMap<String, String> = translators.into();
|
let translators: BTreeMap<&'a str, &'a str> = translators.into();
|
||||||
self.translators = translators
|
self.translators = translators
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, format!("mailto:{v}")))
|
.map(|(k, v)| (k.to_string(), format!("mailto:{v}")))
|
||||||
.collect();
|
.collect();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn license_url(&self) -> Option<String> {
|
||||||
|
let license: &dyn License = match self.license.as_ref() {
|
||||||
|
Some(license) => license.parse().ok()?,
|
||||||
|
None => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.license
|
||||||
|
.as_ref()
|
||||||
|
.map(|_| format!("https://spdx.org/licenses/{}.html", license.id()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs the widget for the about section.
|
/// Constructs the widget for the about section.
|
||||||
|
|
@ -137,7 +127,7 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let developers: Vec<Element<Message>> = list
|
let developers: Vec<Element<Message>> = list
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|(name, url)| {
|
.map(|(name, url)| {
|
||||||
widget::button::custom(
|
widget::button::custom(
|
||||||
widget::row()
|
widget::row()
|
||||||
|
|
@ -148,7 +138,7 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
.align_y(Vertical::Center),
|
.align_y(Vertical::Center),
|
||||||
)
|
)
|
||||||
.class(crate::theme::Button::Text)
|
.class(crate::theme::Button::Text)
|
||||||
.on_press(on_url_press(url.clone()))
|
.on_press(on_url_press(url.to_string()))
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
|
|
@ -157,9 +147,9 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let application_name = about.application_name.as_ref().map(widget::text::title3);
|
let application_name = about.name.as_ref().map(widget::text::title3);
|
||||||
let application_icon = about
|
let application_icon = about
|
||||||
.application_icon
|
.icon
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
.map(|icon| crate::desktop::IconSource::Name(icon.clone()).as_cosmic_icon());
|
||||||
|
|
||||||
|
|
@ -170,9 +160,11 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
let translators_section = section(&about.translators, "Translators");
|
let translators_section = section(&about.translators, "Translators");
|
||||||
let documenters_section = section(&about.documenters, "Documenters");
|
let documenters_section = section(&about.documenters, "Documenters");
|
||||||
|
|
||||||
let developer_name = about.developer_name.as_ref().map(widget::text);
|
let author = about.author.as_ref().map(widget::text);
|
||||||
let version = about.version.as_ref().map(widget::button::standard);
|
let version = about.version.as_ref().map(widget::button::standard);
|
||||||
let license = about.license_type.as_ref().map(widget::button::standard);
|
let license = about.license.as_ref().map(|license| {
|
||||||
|
widget::button::standard(license).on_press_maybe(about.license_url().map(on_url_press))
|
||||||
|
});
|
||||||
let copyright = about.copyright.as_ref().map(widget::text::body);
|
let copyright = about.copyright.as_ref().map(widget::text::body);
|
||||||
let comments = about.comments.as_ref().map(widget::text::body);
|
let comments = about.comments.as_ref().map(widget::text::body);
|
||||||
|
|
||||||
|
|
@ -180,7 +172,7 @@ pub fn about<'a, Message: Clone + 'static>(
|
||||||
widget::column()
|
widget::column()
|
||||||
.push_maybe(application_icon)
|
.push_maybe(application_icon)
|
||||||
.push_maybe(application_name)
|
.push_maybe(application_name)
|
||||||
.push_maybe(developer_name)
|
.push_maybe(author)
|
||||||
.push(
|
.push(
|
||||||
widget::row()
|
widget::row()
|
||||||
.push_maybe(version)
|
.push_maybe(version)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue