[gnome-boxes/downloads-fixups: 1/2] wizard-downloads: Load recommended downloads from an XML file
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/downloads-fixups: 1/2] wizard-downloads: Load recommended downloads from an XML file
- Date: Wed, 14 Nov 2018 13:42:09 +0000 (UTC)
commit eb3af034b5cda6ce1fa6812624b531ea53f90f72
Author: Felipe Borges <felipeborges gnome org>
Date: Tue Nov 13 14:26:12 2018 +0100
wizard-downloads: Load recommended downloads from an XML file
This way downstreams (vendors, distros) could easily tweak the
list and offer the Osinfo downloads that they prefer, with the
sorting they want.
data/gnome-boxes.gresource.xml | 1 +
data/recommended-downloads.xml | 18 ++++++++++++++++++
src/util-app.vala | 41 +++++++++++++++++++++++++++++++++++++++++
src/wizard-downloads-page.vala | 29 ++---------------------------
4 files changed, 62 insertions(+), 27 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 84086d4a..d44415f3 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/Boxes">
<file>gtk-style.css</file>
<file preprocess="xml-stripblanks">ui/menus.ui</file>
+ <file preprocess="xml-stripblanks">recommended-downloads.xml</file>
<file>icons/boxes-arrow.svg</file>
<file>icons/boxes-create.png</file>
<file>icons/empty-boxes.png</file>
diff --git a/data/recommended-downloads.xml b/data/recommended-downloads.xml
new file mode 100644
index 00000000..4f1aed16
--- /dev/null
+++ b/data/recommended-downloads.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ These are OSes listed in the recommended section of the "Download an OS" page.
+
+ This list is powered by libosinfo, therefore the URLs are unique identifiers
+ for each OS in osinfo-db.
+
+ Downstreams are encouraged to tweak the list as they wish. Sorting is also
+ available.
+ -->
+<list>
+ <os_id>http://redhat.com/rhel/7.5</os_id>
+ <os_id>http://fedoraproject.org/fedora/28</os_id>
+ <os_id>http://fedoraproject.org/silverblue/28</os_id>
+ <os_id>http://ubuntu.com/ubuntu/18.04</os_id>
+ <os_id>http://opensuse.org/opensuse/42.3</os_id>
+ <os_id>http://debian.org/debian/9</os_id>
+</list>
\ No newline at end of file
diff --git a/src/util-app.vala b/src/util-app.vala
index 81fe47c3..253d1b74 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -141,6 +141,47 @@ else if (media.url.contains ("dvd"))
return title.replace (" ", "");
}
+ public async GLib.List<Osinfo.Media>? get_recommended_downloads () {
+ uint8[] contents;
+
+ try {
+ File file = File.new_for_uri ("resource:///org/gnome/Boxes/recommended-downloads.xml");
+
+ file.load_contents (null, out contents, null);
+ } catch (GLib.Error e) {
+ warning ("Failed to load recommended downloads file: %s", e.message);
+
+ return null;
+ }
+
+ Xml.Doc* doc = Xml.Parser.parse_doc ((string)contents);
+ if (doc == null)
+ return null;
+
+ Xml.Node* root = doc->get_root_element ();
+ if (root == null || root->name != "list") {
+ warning ("Failed to parse recommended downloads");
+
+ return null;
+ }
+
+ GLib.List<Osinfo.Media> list = new GLib.List<Osinfo.Media> ();
+ var os_db = MediaManager.get_instance ().os_db;
+ for (Xml.Node* iter = root->children; iter != null; iter = iter->next) {
+ var os_id = iter->get_content ();
+ try {
+ var os = yield os_db.get_os_by_id (os_id);
+ var media = os.get_media_list ().get_nth (0) as Osinfo.Media;
+
+ list.append (media);
+ } catch (OSDatabaseError error) {
+ warning ("Failed to find OS with id: '%s': %s", os_id, error.message);
+ }
+ }
+
+ return list;
+ }
+
public async GVir.StoragePool ensure_storage_pool (GVir.Connection connection) throws GLib.Error {
var pool = get_storage_pool (connection);
if (pool == null) {
diff --git a/src/wizard-downloads-page.vala b/src/wizard-downloads-page.vala
index 435aaf5d..0b77a9cb 100644
--- a/src/wizard-downloads-page.vala
+++ b/src/wizard-downloads-page.vala
@@ -22,24 +22,6 @@
private GLib.ListStore recommended_model;
- /* These are OSes listed in the recommended section of the
- * "Download an OS" page.
- *
- * This list is powered by libosinfo, therefore the URLs are
- * unique identifiers for each OS in osinfo-db.
- *
- * Downstreams are encouraged to tweak the list as they wish.
- * Sorting is also available.
- */
- private string[] recommended_downloads = {
- "http://redhat.com/rhel/7.5",
- "http://fedoraproject.org/fedora/28",
- "http://fedoraproject.org/silverblue/28",
- "http://ubuntu.com/ubuntu/18.04",
- "http://opensuse.org/opensuse/42.3",
- "http://debian.org/debian/9",
- };
-
private WizardDownloadsPageView _page;
public WizardDownloadsPageView page {
get { return _page; }
@@ -86,15 +68,8 @@ private void set_visible_view () {
}
private async void populate_recommended_list () {
- foreach (var os_id in recommended_downloads) {
- try {
- var os = yield os_db.get_os_by_id (os_id);
- var media = os.get_media_list ().get_nth (0) as Osinfo.Media;
-
- recommended_model.append (media);
- } catch (OSDatabaseError error) {
- warning ("Failed to find OS with id: '%s': %s", os_id, error.message);
- }
+ foreach (var media in yield get_recommended_downloads ()) {
+ recommended_model.append (media);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]