File: revert-use-licenses.diff

package info (click to toggle)
warp 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,652 kB
  • sloc: python: 391; sh: 177; makefile: 28
file content (443 lines) | stat: -rw-r--r-- 13,103 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
commit ab58416fa0bdbd7f14bba21f4ecfffbf111e1b06
Author: Matthias Geiger <werdahias@debian.org>
Date:   Sat Oct 26 13:53:51 2024 +0200

    Revert "ci: Add cargo-about information to about screen"

    This reverts commit b9e83fb3baac207ec28cfc2371ba62d80a652e75
Forwarded: not-needed

From 41f582a6ef5075f9f855e3bc53dc2dea537a65f8 Mon Sep 17 00:00:00 2001
From: Matthias Geiger <werdahias@debian.org>
Date: Sat, 22 Mar 2025 18:31:06 +0100
Subject: [PATCH] d

---
 Cargo.toml         |   1 -
 data/meson.build   |   3 -
 meson.build        |   8 +-
 po/POTFILES.in     |   1 -
 src/ui/licenses.rs | 325 ---------------------------------------------
 5 files changed, 1 insertion(+), 337 deletions(-)
 delete mode 100644 src/ui/licenses.rs

--- a/Cargo.toml
+++ b/Cargo.toml
@@ -56,7 +56,6 @@
 async_zip = "0.0.17"
 memmap2 = "0.9"
 aperture = { version = "0.9", optional = true }
-license = { version = "3", features = ["offline"] }
 strum = { version = "0.27", features = ["derive", "strum_macros"] }

 [target.'cfg(unix)'.dependencies]
--- a/data/meson.build
+++ b/data/meson.build
@@ -29,7 +29,6 @@
 # Appdata
 appdata_conf = configuration_data()
 appdata_conf.set('app-id', application_id)
-appdata_conf.set('license', meson.project_license()[0])
 appdata_conf.set('gettext-package', gettext_package)
 appdata_conf.set('homepage', homepage)
 appdata_conf.set('issuetracker', issuetracker)
@@ -57,7 +56,5 @@
   )
 endif

-# Licenses metadata
-install_data('licenses.json', install_dir: datadir / meson.project_name())

 subdir('resources')
--- a/meson.build
+++ b/meson.build
@@ -13,12 +13,6 @@
     check: true,
   ).stdout(),
   meson_version: '>= 1.1.0',
-  license: run_command(
-    find_program(meson.global_source_root() / 'build-aux/meson-cargo-manifest.py'),
-    'package',
-    'license',
-    check: true,
-  ).stdout(),
 )

 homepage = run_command(
@@ -140,4 +134,4 @@
   gtk_update_icon_cache: true,
   glib_compile_schemas: false,
   update_desktop_database: true,
-)
\ No newline at end of file
+)
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,7 +14,6 @@
 src/ui/camera.ui
 src/ui/camera_row.rs
 src/ui/fs.rs
-src/ui/licenses.rs
 src/ui/preferences.rs
 src/ui/preferences.ui
 src/ui/pride.rs
--- a/src/ui/licenses.rs
+++ /dev/null
@@ -1,325 +0,0 @@
-use std::{
-    collections::{BTreeMap, BTreeSet, HashMap, HashSet},
-    hash::Hash,
-    rc::Rc,
-    sync::OnceLock,
-};
-
-use futures::channel::oneshot;
-use glib::GString;
-use serde::Deserialize;
-
-use crate::gettext::*;
-
-#[derive(Clone, Debug, Deserialize)]
-struct Crate {
-    name: String,
-    version: String,
-    authors: Vec<String>,
-    license: String,
-}
-
-#[derive(Clone, Debug, Deserialize)]
-struct UsedBy {
-    #[serde(rename = "crate")]
-    c: Crate,
-}
-
-#[derive(Clone, Debug, Deserialize)]
-struct License {
-    id: String,
-    name: String,
-    text: String,
-    used_by: Vec<UsedBy>,
-}
-
-#[derive(Clone, Debug, Deserialize)]
-struct Licenses {
-    #[serde(rename = "licenses")]
-    licenses: Vec<License>,
-}
-
-#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
-pub struct LegalSection {
-    pub title: GString,
-    pub copyright: Option<String>,
-    pub license_type: gtk::License,
-    pub license: Option<String>,
-}
-
-#[derive(Debug)]
-struct AboutLicense {
-    spdx: String,
-    name: String,
-    license: Option<&'static dyn license::License>,
-    escaped_text: Option<String>,
-}
-
-impl PartialEq for AboutLicense {
-    fn eq(&self, other: &Self) -> bool {
-        self.name == other.name
-            && self.id() == other.id()
-            && self.escaped_text == other.escaped_text
-    }
-}
-
-impl Eq for AboutLicense {}
-
-impl PartialOrd for AboutLicense {
-    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-        Some(self.cmp(other))
-    }
-}
-
-impl Hash for AboutLicense {
-    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
-        self.spdx.hash(state);
-        self.name.hash(state);
-        self.id().hash(state);
-        self.escaped_text.hash(state);
-    }
-}
-
-impl Ord for AboutLicense {
-    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-        match self.spdx.cmp(&other.spdx) {
-            core::cmp::Ordering::Equal => {}
-            ord => return ord,
-        }
-        match self.name.cmp(&other.name) {
-            core::cmp::Ordering::Equal => {}
-            ord => return ord,
-        }
-        match self.id().cmp(other.id()) {
-            core::cmp::Ordering::Equal => {}
-            ord => return ord,
-        }
-        self.escaped_text.cmp(&other.escaped_text)
-    }
-}
-
-impl AboutLicense {
-    pub fn from_spdx(spdx: &str, name: &str, text: &str) -> Self {
-        let license: Option<&dyn license::License> = spdx.parse().ok();
-        let text = Self::parse_extra_text(license, text);
-
-        Self {
-            spdx: spdx.to_owned(),
-            name: name.to_owned(),
-            license,
-            escaped_text: text,
-        }
-    }
-
-    pub fn id(&self) -> &str {
-        if let Some(license) = &self.license {
-            license.id()
-        } else {
-            &self.spdx
-        }
-    }
-
-    fn parse_extra_text(license: Option<&dyn license::License>, text: &str) -> Option<String> {
-        let need_text = !matches!(
-            license.map(license::License::id),
-            Some(
-                "Apache-2.0"
-                    | "GPL-3.0"
-                    | "GPL-3.0-or-later"
-                    | "EUPL-1.0"
-                    | "EUPL-1.1"
-                    | "EUPL-1.2"
-                    | "MPL-2.0"
-                    | "Unicode-DFS-2016"
-                    | "Unicode-3.0",
-            ),
-        );
-
-        need_text.then(|| glib::markup_escape_text(text.trim()).to_string())
-    }
-}
-
-impl std::fmt::Display for AboutLicense {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        let parsed: Result<&dyn license::License, _> = self.spdx.parse();
-        let info = if let Ok(license) = parsed {
-            let url = format!("https://spdx.org/licenses/{}.html", license.id());
-
-            // Translators: License information with a link to the software license
-            gettextf(
-                "Licensed under the <a href=\"{}\">{}</a>.",
-                &[&url, &license.name()],
-            )
-        } else {
-            // Translators: License information without a link to the software license
-            gettextf("Licensed under the {}.", &[&self.name])
-        };
-
-        if let Some(text) = &self.escaped_text {
-            write!(f, "{info}\n\n{text}")
-        } else {
-            write!(f, "{info}")
-        }
-    }
-}
-
-fn license_info() -> Vec<License> {
-    let paths = glib::system_data_dirs()
-        .into_iter()
-        .map(|p| p.join(crate::globals::APP_NAME).join("licenses.json"))
-        .collect::<Vec<_>>();
-
-    for path in &paths {
-        if let Ok(file) = std::fs::File::open(path) {
-            log::debug!("Loading licenses.json from {}", path.display());
-            let licenses: std::result::Result<Licenses, _> = serde_json::from_reader(file);
-            return match licenses {
-                Ok(licenses) => licenses.licenses,
-                Err(err) => {
-                    log::warn!("Error loading licenses.json: {}", err);
-                    Vec::new()
-                }
-            };
-        }
-    }
-
-    log::warn!(
-        "Error loading licenses.json: File not found in system data directories: {:?}",
-        &paths
-    );
-
-    Vec::new()
-}
-
-#[derive(Debug, Hash, PartialEq, Eq)]
-struct SectionKey {
-    authors: Vec<String>,
-    spdx: String,
-}
-
-#[derive(Debug, Default)]
-struct SectionValue {
-    crates: BTreeMap<String, HashSet<Rc<AboutLicense>>>,
-}
-
-pub fn about_sections() -> &'static BTreeSet<LegalSection> {
-    static SECTIONS: OnceLock<BTreeSet<LegalSection>> = OnceLock::new();
-
-    SECTIONS.get_or_init(|| {
-        // Collect the license info into a hashmap to deduplicate authors + licenses
-        let mut licenses: HashMap<SectionKey, SectionValue> = HashMap::new();
-        for license in license_info() {
-            let about_license = Rc::new(AboutLicense::from_spdx(
-                &license.id,
-                &license.name,
-                &license.text,
-            ));
-
-            for used in &license.used_by {
-                let entry = licenses
-                    .entry(SectionKey {
-                        authors: used.c.authors.clone(),
-                        spdx: used.c.license.clone(),
-                    })
-                    .or_default();
-
-                entry
-                    .crates
-                    .entry(format!("{} {}", used.c.name, used.c.version))
-                    .or_default()
-                    .insert(about_license.clone());
-            }
-        }
-
-        licenses
-            .into_iter()
-            .flat_map(|(key, value)| {
-                value.crates.into_iter().map(move |(c, licenses)| {
-                    let licenses = licenses
-                        .into_iter()
-                        .enumerate()
-                        .map(|(i, c)| {
-                            if i > 0 {
-                                format!("\n\n{c}")
-                            } else {
-                                c.to_string()
-                            }
-                        })
-                        .collect::<String>();
-
-                    let copyright = if key.authors.is_empty() {
-                        None
-                    } else {
-                        Some(glib::markup_escape_text(&key.authors.join("\n")).to_string())
-                    };
-
-                    LegalSection {
-                        title: glib::markup_escape_text(&c),
-                        copyright,
-                        license_type: gtk::License::Custom,
-                        license: Some(licenses),
-                    }
-                })
-            })
-            .collect::<BTreeSet<_>>()
-    })
-}
-
-pub trait AboutDialogLicenseExt {
-    async fn add_embedded_license_information(&self);
-}
-
-impl AboutDialogLicenseExt for adw::AboutDialog {
-    async fn add_embedded_license_information(&self) {
-        let (sender, receiver) = oneshot::channel();
-
-        gio::spawn_blocking(glib::clone!(move || {
-            let res = sender.send(crate::ui::licenses::about_sections());
-            if res.is_err() {
-                log::error!("channel is closed");
-            }
-        }));
-
-        let Ok(about_sections) = receiver.await else {
-            return;
-        };
-
-        let mut peekable = about_sections.iter().peekable();
-        let mut titles = Vec::with_capacity(10);
-
-        // Add legal sections asynchronously, layouting them takes quite a bit of time
-        glib::idle_add_local_full(
-            glib::Priority::LOW,
-            glib::clone!(
-                #[weak(rename_to = dialog)]
-                self,
-                #[upgrade_or]
-                glib::ControlFlow::Break,
-                move || {
-                    if let Some(legal) = peekable.next() {
-                        titles.push(legal.title.as_str());
-
-                        if !peekable.peek().is_some_and(|peek| {
-                            peek.copyright == legal.copyright
-                                && peek.license_type == legal.license_type
-                                && peek.license == legal.license
-                        }) {
-                            dialog.add_legal_section(
-                                &titles.join(", "),
-                                legal.copyright.as_deref(),
-                                legal.license_type,
-                                legal.license.as_deref(),
-                            );
-                            titles.clear();
-                        }
-
-                        glib::ControlFlow::Continue
-                    } else {
-                        log::debug!("Finished adding legal sections to about dialog");
-                        glib::ControlFlow::Break
-                    }
-                }
-            ),
-        );
-    }
-}
--- a/src/ui/window.rs
+++ b/src/ui/window.rs
@@ -20,7 +20,6 @@
     future::main_async_local_infallible, TransferDirection, WormholeTransferURI,
 };

-use super::licenses::AboutDialogLicenseExt;

 mod imp {
     use super::*;
@@ -314,11 +313,6 @@
             // Translators: This is a promotion and should match the short app summary as seen at https://apps.gnome.org/PikaBackup/
             &gettext("Keep your data safe"),
         );
-        glib::spawn_future_local(glib::clone!(
-            #[weak]
-            dialog,
-            async move { dialog.add_embedded_license_information().await }
-        ));

         dialog.present(Some(self));
     }
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -1,7 +1,6 @@
 mod action_view;
 pub mod application;
 mod fs;
-mod licenses;
 mod preferences;
 mod pride;
 mod progress;