[gnome-boxes/download-uri-from-assistant] assistant, downloads-hub: Restore support to download from URI



commit bb0e600c9931d053d85f684953ec4aa2c20b7584
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Jun 24 15:35:00 2020 +0200

    assistant, downloads-hub: Restore support to download from URI
    
    Fixes #520

 src/assistant/downloads-page.vala |  9 +++++++++
 src/assistant/index-page.vala     |  1 +
 src/downloads-hub.vala            | 25 +++++++++++++++++++++----
 3 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/src/assistant/downloads-page.vala b/src/assistant/downloads-page.vala
index 41b93581..98086cee 100644
--- a/src/assistant/downloads-page.vala
+++ b/src/assistant/downloads-page.vala
@@ -20,6 +20,7 @@
     private GLib.ListStore recommended_model;
 
     public signal void media_selected (Gtk.ListBoxRow row);
+    public signal void url_entered ();
 
     private AssistantDownloadsPageView _page;
     public AssistantDownloadsPageView page {
@@ -105,6 +106,14 @@ private void on_search_changed () {
         if (text == null)
             return;
 
+        var uri = Xml.URI.parse (text);
+        if (uri.scheme.has_prefix ("http")) {
+            DownloadsHub.get_instance ().add_url (text);
+
+            url_entered ();
+            return;
+        }
+
         search.text = text;
     }
 
diff --git a/src/assistant/index-page.vala b/src/assistant/index-page.vala
index 097220be..c7637407 100644
--- a/src/assistant/index-page.vala
+++ b/src/assistant/index-page.vala
@@ -37,6 +37,7 @@
 
         source_medias.set_header_func (use_list_box_separator);
         featured_medias.set_header_func (use_list_box_separator);
+        recommended_downloads_page.url_entered.connect (() => { dialog.hide (); });
     }
 
     public void setup (VMAssistant dialog) {
diff --git a/src/downloads-hub.vala b/src/downloads-hub.vala
index 3b1bc8ef..61c1e53f 100644
--- a/src/downloads-hub.vala
+++ b/src/downloads-hub.vala
@@ -33,10 +33,12 @@ public static DownloadsHub get_instance () {
     }
 
     public void add_item (WizardDownloadableEntry entry) {
-        n_items+=1;
-
         var row = new DownloadsHubRow.from_entry (entry);
+        add_row (row);
+    }
 
+    private void add_row (DownloadsHubRow row) {
+        n_items+=1;
         if (!button.visible)
             button.visible = true;
 
@@ -62,6 +64,11 @@ public void add_item (WizardDownloadableEntry entry) {
         popup ();
     }
 
+    public void add_url (string url) {
+       var row = new DownloadsHubRow.from_url (url);
+       add_row (row);
+    }
+
     private void on_row_deleted () {
         n_items-= 1;
         if (!ongoing_downloads) {
@@ -163,17 +170,27 @@ private bool draw_button_pie (Widget drawing_area, Cairo.Context context) {
 
         Downloader.fetch_os_logo.begin (image, entry.os, 64);
 
+        setup (entry.url);
+    }
+
+    public DownloadsHubRow.from_url (string url) {
+        label.label = url;
+
+        setup (url);
+    }
+
+    private void setup (string url) {
         progress_notify_id = progress.notify["progress"].connect (() => {
             progress_bar.fraction = progress.progress;
         });
         progress_bar.fraction = progress.progress = 0;
 
-        var soup_download_uri = new Soup.URI (entry.url);
+        var soup_download_uri = new Soup.URI (url);
         var download_path = soup_download_uri.get_path ();
 
         var filename = GLib.Path.get_basename (download_path);
 
-        download.begin (entry.url, filename);
+        download.begin (url, filename);
     }
 
     private async void download (string url, string filename) {


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