This repository was archived by the owner on Apr 2, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Implement downloads #201
Open
alcinnz
wants to merge
26
commits into
cassidyjames:main
Choose a base branch
from
alcinnz:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement downloads #201
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
645a844
Draft downloads UI.
alcinnz 63f5f75
Integrate and fix downloads button.
alcinnz d1032d9
Fix download click handling.
alcinnz 70fc006
Fix 'Show in folder' button.
alcinnz 0b9ba67
Merge branch 'master' into master
cassidyjames 6d06bd3
Merge branch 'master' into master
cassidyjames c266dd0
Update src/Widgets/DownloadsButton.vala
alcinnz 8c6eece
Update src/Widgets/DownloadsButton.vala
alcinnz efee568
Update src/Widgets/DownloadsButton.vala
alcinnz 8f8607f
Update src/Widgets/DownloadsButton.vala
alcinnz 9c770a2
Update src/Widgets/DownloadsButton.vala
alcinnz 144cede
Update src/Widgets/DownloadsButton.vala
alcinnz b777d07
Update src/Widgets/DownloadsButton.vala
alcinnz 43d95d9
Update src/Widgets/DownloadsButton.vala
alcinnz 37a5c55
Update src/Widgets/DownloadsButton.vala
alcinnz 55ec83f
Update src/MainWindow.vala
alcinnz ea467c9
Update src/MainWindow.vala
alcinnz 8790da9
Update src/MainWindow.vala
alcinnz 5cadfc7
Update src/Widgets/DownloadsButton.vala
alcinnz b60300b
Update src/Widgets/DownloadsButton.vala
alcinnz a918ec7
Update src/Widgets/DownloadsButton.vala
alcinnz d6d6b1e
Update src/Widgets/DownloadsButton.vala
alcinnz 9694abb
Write namespace in Downloads class names, for consistancy.
alcinnz c98e482
Codestyle fix (space before function parens).
alcinnz 3cbf1e9
Merge branch 'master' into master
cassidyjames 09b6e4c
Merge branch 'master' into master
cassidyjames File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| /* | ||
| * Copyright © 2019 Adrian Cochrane (https://adrian.geek.nz) | ||
alcinnz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public | ||
| * License along with this program; if not, write to the | ||
| * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| * Boston, MA 02110-1301 USA | ||
| * | ||
| * Authored by: Adrian Cochrane <alcinnz@lavabit.com> | ||
| */ | ||
| namespace Ephemeral { | ||
|
||
| public class DownloadsButton : Gtk.Revealer { | ||
| Gtk.ListBox downloads_list; | ||
|
|
||
| public DownloadsButton() { | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Object (); | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| construct { | ||
| tooltip_text = _("Downloads"); | ||
| tooltip_markup = Granite.markup_accel_tooltip ({"<Ctrl>j"}, tooltip_text); | ||
|
|
||
| reveal_child = false; | ||
|
|
||
| var button = new Gtk.MenuButton (); | ||
| button.image = new Gtk.Image.from_icon_name ( | ||
| "folder-download", Application.instance.icon_size | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| var popover = new Gtk.Popover (null); | ||
| button.popover = popover; | ||
|
|
||
| downloads_list = new Gtk.ListBox (); | ||
| downloads_list.activate_on_single_click = true; | ||
| downloads_list.selection_mode = Gtk.SelectionMode.SINGLE; | ||
| downloads_list.show (); | ||
|
|
||
| downloads_list.row_activated.connect ((row) => { | ||
| var download = (DownloadRow) row; | ||
| if (download == null) return; | ||
| download.open (); | ||
| }); | ||
|
|
||
| popover.add (downloads_list); | ||
| add (button); | ||
| } | ||
|
|
||
| public void add_download(WebKit.Download download) { | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var row = new DownloadRow (download); | ||
| row.build_ui (); | ||
|
|
||
| row.show_all (); | ||
| downloads_list.add (row); | ||
| reveal_child = true; | ||
| } | ||
| } | ||
|
|
||
| public class DownloadRow : Gtk.ListBoxRow { | ||
| public WebKit.Download download; | ||
|
|
||
| public DownloadRow(WebKit.Download download) {this.download = download;} | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public void build_ui() { | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var image = new Gtk.Image.from_icon_name ( | ||
| "document-save-as", Gtk.IconSize.DND | ||
| ); | ||
|
|
||
| var label = new Gtk.Label (""); | ||
| label.hexpand = true; | ||
| label.xalign = 0; | ||
|
|
||
| var progressbar = new Gtk.ProgressBar (); | ||
| progressbar.get_style_context ().add_class ("osd"); | ||
| progressbar.fraction = 0; | ||
| download.received_data.connect (() => { | ||
| progressbar.fraction = download.estimated_progress; | ||
| }); | ||
|
|
||
| var overlay = new Gtk.Overlay (); | ||
| overlay.add (label); | ||
| overlay.add_overlay (progressbar); | ||
|
|
||
| var folder_button = new Gtk.Button.from_icon_name ( | ||
| "folder-open", Gtk.IconSize.MENU | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| folder_button.tooltip_text = _("Open in folder"); | ||
| folder_button.clicked.connect (() => { | ||
| if (download.estimated_progress == 1.0) | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| DBus.Files.show_files ({download.destination}); | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| var cancel_button = new Gtk.Button.from_icon_name ( | ||
| "process-stop", Gtk.IconSize.MENU | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| cancel_button.tooltip_text = _("Cancel download"); | ||
| var cancelled = false; | ||
| cancel_button.clicked.connect (() => { | ||
| download.cancel (); | ||
| cancelled = true; | ||
| this.destroy (); | ||
| }); | ||
|
|
||
| var secondary_stack = new Gtk.Stack (); | ||
| secondary_stack.halign = Gtk.Align.END; | ||
| secondary_stack.margin_start = secondary_stack.margin_end = 6; | ||
| secondary_stack.add (folder_button); | ||
| secondary_stack.add (cancel_button); | ||
| secondary_stack.show_all (); | ||
| secondary_stack.visible_child = cancel_button; | ||
|
|
||
| download.finished.connect (() => { | ||
| download.received_data (uint64.MAX); // To ensure initial data is displayed. | ||
| if (cancelled) return; | ||
|
|
||
| this.selectable = this.activatable = true; | ||
| secondary_stack.visible_child = folder_button; | ||
| }); | ||
|
|
||
| var grid = new Gtk.Grid (); | ||
| grid.orientation = Gtk.Orientation.HORIZONTAL; | ||
| grid.column_spacing = 3; | ||
| grid.add (image); | ||
| grid.add (overlay); | ||
| grid.add (secondary_stack); | ||
|
|
||
| add (grid); | ||
| tooltip_text = download.destination; | ||
| selectable = activatable = false; | ||
|
|
||
| ulong download_started = 0; | ||
| download_started = download.received_data.connect(() => { | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var mimetype = download.response.mime_type; | ||
| if (mimetype == "application/octet-stream") { | ||
| mimetype = ContentType.guess (download.response.uri, null, null); | ||
| } | ||
|
|
||
| image.gicon = ContentType.get_icon (mimetype); | ||
| image.tooltip_text = ContentType.get_description (mimetype); | ||
|
|
||
| label.label = Filename.display_basename (download.destination); | ||
|
|
||
| download.disconnect (download_started); | ||
| }); | ||
| } | ||
|
|
||
| public void open () { | ||
| var mimetype = download.response.mime_type; | ||
| if (mimetype == "application/octet-stream") { | ||
| mimetype = ContentType.guess (download.response.uri, null, null); | ||
| } | ||
|
|
||
| var app = AppInfo.get_default_for_type (mimetype, false); | ||
| if (app == null) return; // TODO It'd be nice to integrate AppCenter here. | ||
alcinnz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var uris = new List<string>(); | ||
| uris.append (download.destination); | ||
| try { | ||
| app.launch_uris (uris, null); | ||
| } catch (Error err) { | ||
| warning ("%s", err.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [DBus (name = "org.freedesktop.FileManager1")] | ||
| interface DBus.Files : Object { | ||
| const string FILES_DBUS_ID = "org.freedesktop.FileManager1"; | ||
| const string FILES_DBUS_PATH = "/org/freedesktop/FileManager1"; | ||
|
|
||
| public abstract void show_items (string[] uris, string startup_id) throws IOError, DBusError; | ||
| public abstract void show_folders (string[] uris, string startup_id) throws IOError, DBusError; | ||
|
|
||
| public static void show_files (string[] uris) { | ||
| try { | ||
|
|
||
| DBus.Files files = Bus.get_proxy_sync (BusType.SESSION, FILES_DBUS_ID, FILES_DBUS_PATH); | ||
| files.show_items (uris, "ephemeral"); | ||
|
|
||
| } catch (DBusError err) { | ||
|
|
||
| // Fallback to just opening the Downloads folder | ||
| var path = Environment.get_user_special_dir (UserDirectory.DOWNLOAD); | ||
| AppInfo.launch_default_for_uri (File.new_for_path (path).get_uri (), null); | ||
|
|
||
| } catch (Error err) { | ||
| warning ("Failed to open file manager: %s", err.message); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.