[gnome-boxes/refactor-some-download-an-os-bits: 7/8] wizard: Make RHEL row an WizardDownloadableEntry



commit 3b023445a35a99136828d734f9a6f14c74b915ee
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Mar 1 13:08:45 2018 +0100

    wizard: Make RHEL row an WizardDownloadableEntry
    
    This way it can match the styling of the other rows and it can be
    searched in the "Download an OS" page.

 data/ui/wizard-source.ui | 79 ---------------------------------------
 src/wizard-source.vala   | 96 +++++++++++++++++++++++-------------------------
 src/wizard-window.vala   | 25 ++-----------
 3 files changed, 48 insertions(+), 152 deletions(-)
---
diff --git a/data/ui/wizard-source.ui b/data/ui/wizard-source.ui
index 1cf199ab..b59fccfc 100644
--- a/data/ui/wizard-source.ui
+++ b/data/ui/wizard-source.ui
@@ -395,83 +395,4 @@
       </packing>
     </child>
   </template>
-
-  <object class="GtkListBoxRow" id="install_rhel_button">
-    <property name="visible">True</property>
-    <property name="activatable">False</property>
-    <style>
-      <class name="boxes-menu-row"/>
-    </style>
-    <child>
-      <object class="GtkButton">
-      <property name="visible">True</property>
-      <signal name="clicked" handler="on_install_rhel_button_clicked"/>
-      <style>
-        <class name="flat"/>
-      </style>
-      <child>
-        <object class="GtkBox" id="install_rhel_hbox">
-          <property name="visible">True</property>
-          <property name="margin-start">15</property>
-          <property name="margin-end">15</property>
-          <property name="spacing">20</property>
-          <property name="orientation">horizontal</property>
-          <child>
-            <object class="GtkImage" id="install_rhel_image">
-              <property name="icon-size">0</property>
-              <property name="no-show-all">True</property>
-              <property name="pixel-size">64</property>
-            </object>
-            <packing>
-              <property name="expand">False</property>
-              <property name="fill">False</property>
-            </packing>
-          </child>
-          <child>
-            <object class="GtkBox" id="install_rhel_vbox">
-              <property name="visible">True</property>
-              <property name="homogeneous">True</property>
-              <property name="orientation">vertical</property>
-              <child>
-                <object class="GtkLabel" id="install_rhel_label">
-                  <property name="visible">True</property>
-                  <property name="ellipsize">end</property>
-                  <property name="halign">start</property>
-                  <property name="valign">end</property>
-                  <property name="use-underline">True</property>
-                  <property name="label" translatable="yes">Red Hat Enterprise Linux</property>
-                </object>
-                <packing>
-                  <property name="expand">True</property>
-                  <property name="fill">True</property>
-                </packing>
-              </child>
-              <child>
-                  <object class="GtkLabel" id="install_rhel_details_label">
-                    <property name="visible">True</property>
-                    <property name="ellipsize">end</property>
-                    <property name="halign">start</property>
-                    <property name="valign">start</property>
-                    <property name="label" translatable="yes">Available with a free Red Hat developer 
account</property>
-                    <style>
-                      <class name="boxes-step-label"/>
-                      <class name="dim-label"/>
-                    </style>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-              </packing>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
-  </object>
 </interface>
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 8830e18a..9202c326 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -60,6 +60,8 @@ public override void get_preferred_height (out int minimum_height, out int natur
 
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-downloadable-entry.ui")]
 private class Boxes.WizardDownloadableEntry : Gtk.ListBoxRow {
+    public Osinfo.Os? os;
+
     [GtkChild]
     private Gtk.Image media_image;
     [GtkChild]
@@ -68,15 +70,18 @@ public override void get_preferred_height (out int minimum_height, out int natur
     private Gtk.Label details_label;
 
     public string title {
-        get {
-            return title_label.get_text ();
-        }
+        get { return title_label.get_text (); }
+        set { title_label.label = value; }
     }
 
+    public string details {
+        get { return details_label.get_text (); }
+        set { details_label.label = value; }
+    }
     public string url;
 
     public WizardDownloadableEntry (Osinfo.Media media) {
-        Downloader.fetch_os_logo.begin (media_image, media.os, 64);
+        this.from_os (media.os);
 
         setup_label (media);
         details_label.label = media.os.vendor;
@@ -84,6 +89,12 @@ public WizardDownloadableEntry (Osinfo.Media media) {
         url = media.url;
     }
 
+    public WizardDownloadableEntry.from_os (Osinfo.Os os) {
+        Downloader.fetch_os_logo.begin (media_image, os, 64);
+
+        this.os = os;
+    }
+
     private void setup_label (Osinfo.Media media) {
         /* Libosinfo lacks some OS variant names, so we do some
            parsing here to compose a unique human-readable media
@@ -295,10 +306,6 @@ private void on_notify_estimated_load_progress () {
     [GtkChild]
     private Gtk.Label libvirt_sys_import_label;
     [GtkChild]
-    private Gtk.ListBoxRow install_rhel_button;
-    [GtkChild]
-    private Gtk.Image install_rhel_image;
-    [GtkChild]
     private Boxes.WizardWebView rhel_web_view;
 
     private AppWindow window;
@@ -307,7 +314,6 @@ private void on_notify_estimated_load_progress () {
     private Gtk.ListBox downloads_vbox;
 
     private Cancellable? rhel_cancellable;
-    private Osinfo.Os? rhel_os;
 
     public MediaManager media_manager;
 
@@ -383,6 +389,27 @@ private void on_notify_estimated_load_progress () {
         update_libvirt_sytem_entry_visibility.begin ();
         add_media_entries.begin ();
 
+        // We manually add the custom download entries. Custom download entries
+        // are items which require special handling such as an authentication
+        // page before we obtain a direct image URL.
+        var os_db = media_manager.os_db;
+        var rhel_id = "http://redhat.com/rhel/7.4";;
+        os_db.get_os_by_id.begin (rhel_id, (obj, res) => {
+            try {
+                var os = os_db.get_os_by_id.end (res);
+
+                var rhel_row = new WizardDownloadableEntry.from_os (os);
+                rhel_row.title = "Red Hat Enterprise Linux";
+                rhel_row.details = _("Available with a free Red Hat developer account");
+
+                // TODO: Sort by release date
+                window.wizard_window.downloads_list.insert (rhel_row, 0);
+            } catch (OSDatabaseError error) {
+                warning ("Failed to find OS with ID '%s': %s", rhel_id, error.message);
+                return;
+            }
+        });
+
         rhel_web_view.view.decide_policy.connect (on_rhel_web_view_decide_policy);
     }
 
@@ -399,36 +426,6 @@ public void setup_ui (AppWindow window) {
         assert (window != null);
 
         this.window = window;
-
-        var os_db = media_manager.os_db;
-
-        // We need a Shadowman logo and libosinfo mandates that we specify an
-        // OsinfoOs to get a logo. However, we don't have an OsinfoOs to begin
-        // with, and by the time we get one from the Red Hat developer portal
-        // it will be too late.
-        //
-        // To work around this, we specify the ID of a RHEL release and use it
-        // to get an OsinfoOs. Since all RHEL releases have the same Shadowman,
-        // the exact version of the RHEL release doesn't matter.
-        //
-        // Ideally, distributions would be a first-class object in libosinfo, so
-        // that we could query for RHEL instead of a specific version of it.
-        var rhel_id = "http://redhat.com/rhel/7.4";;
-
-        os_db.get_os_by_id.begin (rhel_id, (obj, res) => {
-            try {
-                rhel_os = os_db.get_os_by_id.end (res);
-            } catch (OSDatabaseError error) {
-                warning ("Failed to find OS with ID '%s': %s", rhel_id, error.message);
-                return;
-            }
-
-            Downloader.fetch_os_logo.begin (install_rhel_image, rhel_os, 64, (obj, res) => {
-                Downloader.fetch_os_logo.end (res);
-                var pixbuf = install_rhel_image.pixbuf;
-                install_rhel_image.visible = pixbuf != null;
-            });
-        });
     }
 
     [GtkCallback]
@@ -589,21 +586,20 @@ private void on_media_selected (InstallerMedia media) {
 
     [GtkCallback]
     private void on_download_an_os_button_clicked () {
-        window.wizard_window.show_downloads_page (media_manager.os_db, (uri) => {
-            this.uri = uri;
+        window.wizard_window.show_downloads_page (media_manager.os_db, (entry) => {
+            // Handle custom downloads
+            if (entry.os.id == "http://redhat.com/rhel/7.4";) {
+                on_install_rhel_button_clicked ();
 
-            activated ();
-        });
+                return;
+            }
 
-        // We manually add the custom download entries. Custom download entries
-        // are items which require special handling such as an authentication
-        // page before we obtain a direct image URL.
-        window.wizard_window.add_custom_download (install_rhel_button, () => {
-            on_install_rhel_button_clicked ();
+            this.uri = entry.url;
+
+            activated ();
         });
     }
 
-    [GtkCallback]
     private void on_install_rhel_button_clicked () {
         page = SourcePage.RHEL_WEB_VIEW;
 
@@ -666,8 +662,6 @@ private bool on_rhel_web_view_decide_policy (WebKit.WebView web_view,
         uri = download_uri;
         activated ();
 
-        selected = install_rhel_button;
-
         decision.ignore ();
         return true;
     }
diff --git a/src/wizard-window.vala b/src/wizard-window.vala
index 03ca8c64..ecd4706e 100644
--- a/src/wizard-window.vala
+++ b/src/wizard-window.vala
@@ -13,8 +13,7 @@
     public const string[] page_names = { "main", "customization", "file_chooser", "downloads" };
 
     public delegate void FileChosenFunc (string uri);
-    public delegate void DownloadChosenFunc (string uri);
-    public delegate void CustomDownloadChosenFunc ();
+    public delegate void DownloadChosenFunc (WizardDownloadableEntry entry);
 
     private HashTable<string,Osinfo.Os> logos_table;
 
@@ -54,7 +53,7 @@
     [GtkChild]
     public Notificationbar notificationbar;
     [GtkChild]
-    private Gtk.ListBox downloads_list;
+    public Gtk.ListBox downloads_list;
 
     private GLib.List<Boxes.Property> resource_properties;
 
@@ -119,21 +118,6 @@ public void show_file_chooser (owned FileChosenFunc file_chosen_func) {
         page = WizardWindowPage.FILE_CHOOSER;
     }
 
-    public void add_custom_download (Gtk.ListBoxRow row, owned CustomDownloadChosenFunc 
custom_download_chosen_func) {
-        if (row.get_parent () != null)
-            return;
-
-        // TODO: insert sorted based on release date.
-        downloads_list.insert (row, -1);
-
-        var button = row.get_child () as Gtk.Button;
-        button.clicked.connect (() => {
-            custom_download_chosen_func ();
-
-            page = WizardWindowPage.MAIN;
-        });
-    }
-
     public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc download_chosen_func) {
         page = WizardWindowPage.DOWNLOADS;
 
@@ -141,7 +125,7 @@ public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc down
         activated_id = downloads_list.row_activated.connect ((row) => {
             var entry = row as WizardDownloadableEntry;
 
-            download_chosen_func (entry.url);
+            download_chosen_func (entry);
             downloads_list.disconnect (activated_id);
 
             page = WizardWindowPage.MAIN;
@@ -149,9 +133,6 @@ public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc down
         page = WizardWindowPage.DOWNLOADS;
         topbar.downloads_search.grab_focus ();
 
-        if (downloads_list.get_children ().length () > 0)
-            return;
-
         os_db.list_downloadable_oses.begin ((db, result) => {
             try {
                 var media_list = os_db.list_downloadable_oses.end (result);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]