Skip to content

Commit

Permalink
Add license information, part of #160
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Sep 26, 2024
1 parent 8e564ab commit 1634f2d
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 23 deletions.
90 changes: 68 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ freedesktop_entry_parser = "1"
lazy_static = "1"
log = "0.4"
notify-rust = "4"
open = "5"
paste = "1"
rayon = "1"
regex = "1"
reqwest = "0.11"
serde = { version = "1", features = ["rc", "serde_derive"] }
spdx = { git = "https://github.com/jackpot51/spdx.git" }
tokio = { version = "1", features = ["sync"] }
xdg = "2"
# Internationalization
Expand Down Expand Up @@ -70,3 +72,9 @@ members = ["flathub-stats"]
# libcosmic = { path = "../libcosmic" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }

# [patch.'https://github.com/jackpot51/appstream.git']
# appstream = { path = "../../appstream" }

# [patch.'https://github.com/jackpot51/spdx.git']
# spdx = { path = "../../spdx" }
1 change: 1 addition & 0 deletions i18n/en/cosmic_store.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ source-installed = {$source} (installed)
developer = Developer
app-developers = {$app} Developers
monthly-downloads = Flathub Monthly Downloads
licenses = Licenses
# Context Pages

Expand Down
2 changes: 2 additions & 0 deletions src/app_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub struct AppInfo {
pub summary: String,
pub developer_name: String,
pub description: String,
pub license_opt: Option<String>,
pub pkgnames: Vec<String>,
pub categories: Vec<String>,
pub desktop_ids: Vec<String>,
Expand Down Expand Up @@ -282,6 +283,7 @@ impl AppInfo {
summary: summary.to_string(),
developer_name: developer_name.to_string(),
description,
license_opt: component.project_license.map(|x| x.to_string()),
pkgnames: component.pkgname.map_or(Vec::new(), |x| vec![x]),
categories,
desktop_ids,
Expand Down
1 change: 1 addition & 0 deletions src/backend/flatpak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl Flatpak {
summary,
developer_name: String::new(),
description,
license_opt: None,
pkgnames: Vec::new(),
categories: Vec::new(),
desktop_ids: Vec::new(),
Expand Down
2 changes: 2 additions & 0 deletions src/backend/packagekit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl Packagekit {
summary: tx_detail.summary.clone(),
developer_name: String::new(),
description: tx_detail.description.clone(),
license_opt: None,
pkgnames: vec![package_name.to_string()],
categories: Vec::new(),
desktop_ids: Vec::new(),
Expand Down Expand Up @@ -284,6 +285,7 @@ impl Packagekit {
summary,
developer_name: String::new(),
description,
license_opt: None,
pkgnames,
categories: Vec::new(),
desktop_ids: Vec::new(),
Expand Down
53 changes: 52 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub enum Message {
Installed(Vec<(&'static str, Package)>),
InstalledResults(Vec<SearchResult>),
Key(Modifiers, Key),
LaunchUrl(String),
MaybeExit,
Notification(Arc<Mutex<notify_rust::NotificationHandle>>),
OpenDesktopId(String),
Expand Down Expand Up @@ -1482,7 +1483,8 @@ impl App {
AppTheme::Light => 2,
AppTheme::System => 0,
};
widget::settings::view_column(vec![widget::settings::view_section(fl!("appearance"))
widget::settings::view_column(vec![widget::settings::section()
.title(fl!("appearance"))
.add(
widget::settings::item::builder(fl!("theme")).control(widget::dropdown(
&self.app_themes,
Expand Down Expand Up @@ -1850,6 +1852,49 @@ impl App {
break;
}

if let Some(license) = &selected.info.license_opt {
let mut license_col = widget::column::with_capacity(2).spacing(space_xxxs);
license_col = license_col.push(widget::text::title4(fl!("licenses")));
match spdx::Expression::parse_mode(license, spdx::ParseMode::LAX) {
Ok(expr) => {
for item in expr.requirements() {
match &item.req.license {
spdx::LicenseItem::Spdx { id, .. } => {
license_col =
license_col.push(widget::text::body(id.full_name));
}
spdx::LicenseItem::Other { lic_ref, .. } => {
let mut license_row = widget::row::with_capacity(2)
.spacing(space_xxxs)
.align_items(Alignment::Center);
let mut parts = lic_ref.splitn(2, '=');
if let Some(id) = parts.next() {
license_row = license_row
.push(widget::text::body(format!("Custom: {id}")));
if let Some(url) = parts.next() {
license_row = license_row.push(
widget::button::link(url.to_string()).on_press(
Message::LaunchUrl(url.to_string()),
),
)
}
} else {
license_row = license_row
.push(widget::text::body(format!("Custom")));
}
license_col = license_col.push(license_row);
}
}
}
}
Err(err) => {
license_col = license_col.push(widget::text::body(license));
license_col = license_col.push(widget::text::body(format!("{}", err)));
}
}
column = column.push(license_col);
}

column.into()
}
None => match &self.search_results {
Expand Down Expand Up @@ -2445,6 +2490,12 @@ impl Application for App {
}
}
}
Message::LaunchUrl(url) => match open::that_detached(&url) {
Ok(()) => {}
Err(err) => {
log::warn!("failed to open {:?}: {}", url, err);
}
},
Message::MaybeExit => {
if self.window_id_opt.is_none() && self.pending_operations.is_empty() {
// Exit if window is closed and there are no pending operations
Expand Down

0 comments on commit 1634f2d

Please sign in to comment.