[gnome-boxes/downloads-hub-ux-improvements: 1/6] downloads-hub: Draw a pie chart to indicate progress
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/downloads-hub-ux-improvements: 1/6] downloads-hub: Draw a pie chart to indicate progress
- Date: Wed, 4 Dec 2019 11:58:43 +0000 (UTC)
commit dcd7d23645901f0ed10e9a1f947c741ac6feadcc
Author: Felipe Borges <felipeborges gnome org>
Date: Wed Dec 4 12:22:52 2019 +0100
downloads-hub: Draw a pie chart to indicate progress
Fixes #306
data/ui/collection-toolbar.ui | 4 +--
src/downloads-hub.vala | 67 +++++++++++++++++++++++++++++++++++++------
2 files changed, 60 insertions(+), 11 deletions(-)
---
diff --git a/data/ui/collection-toolbar.ui b/data/ui/collection-toolbar.ui
index 5a13191d..2e1d0ce1 100644
--- a/data/ui/collection-toolbar.ui
+++ b/data/ui/collection-toolbar.ui
@@ -75,10 +75,8 @@
</object>
</child>
<child>
- <object class="GtkImage">
+ <object class="GtkDrawingArea">
<property name="visible">True</property>
- <property name="icon-name">media-record-symbolic</property>
- <property name="icon-size">1</property>
</object>
</child>
</object>
diff --git a/src/downloads-hub.vala b/src/downloads-hub.vala
index e4740fd1..59f6a7f1 100644
--- a/src/downloads-hub.vala
+++ b/src/downloads-hub.vala
@@ -13,35 +13,61 @@ public static DownloadsHub get_instance () {
[GtkChild]
private ListBox listbox;
+ private Widget button { get { return relative_to; } }
- private bool ongoing_downloads {
- get { return (listbox.get_children ().length () > 0); }
+ private uint n_items = 0;
+ private double progress {
+ get {
+ double total = 0;
+ foreach (var row in listbox.get_children ()) {
+ total += (row as DownloadsHubRow).progress.progress / n_items;
+ }
+
+ return total;
+ }
}
+ private uint redraw_progress_pie_id = 0;
- // TODO: inhibit suspend
+ private bool ongoing_downloads {
+ get { return (n_items > 0); }
+ }
public void add_item (WizardDownloadableEntry entry) {
+ n_items+=1;
+
var row = new DownloadsHubRow.from_entry (entry);
- if (!relative_to.visible)
- relative_to.visible = true;
+ if (!button.visible)
+ button.visible = true;
+
+ var drawing_area = (button as Bin).get_child ();
+ drawing_area.draw.connect (draw_button_pie);
row.destroy.connect (on_row_deleted);
row.download_complete.connect (on_download_complete);
- if (!ongoing_downloads) {
+ if (ongoing_downloads) {
var reason = _("Downloading media");
App.app.inhibit (App.app.main_window, null, reason);
+
+ redraw_progress_pie_id = Timeout.add_seconds (1, () => {
+ drawing_area.queue_draw ();
+
+ return true;
+ });
}
listbox.prepend (row);
}
private void on_row_deleted () {
+ n_items-= 1;
if (!ongoing_downloads) {
// Hide the Downloads Hub when there aren't ongoing downloads
- relative_to.visible = false;
+ button.visible = false;
+
+ GLib.Source.remove (redraw_progress_pie_id);
}
}
@@ -67,6 +93,31 @@ private void on_row_activated (Gtk.ListBoxRow _row) {
popup ();
}
}
+
+ private bool draw_button_pie (Widget drawing_area, Cairo.Context context) {
+ var width = drawing_area.get_allocated_width ();
+ var height = drawing_area.get_allocated_height ();
+
+ context.set_line_join (Cairo.LineJoin.ROUND);
+
+ var style_context = button.get_style_context ();
+ var foreground = style_context.get_color (button.get_state_flags ());
+ var background = foreground;
+
+ background.alpha *= 0.3;
+ context.set_source_rgba (background.red, background.green, background.blue, background.alpha);
+ context.arc (width / 2, height / 2, height / 3, - Math.PI / 2, 3 * Math.PI / 2);
+ context.fill ();
+
+ context.move_to (width / 2, height / 2);
+ context.set_source_rgba (foreground.red, foreground.green, foreground.blue, foreground.alpha);
+
+ double radians = - Math.PI / 2 + 2 * Math.PI * progress;
+ context.arc (width / 2, height / 2, height / 3, - Math.PI / 2, radians);
+ context.fill ();
+
+ return true;
+ }
}
[GtkTemplate (ui= "/org/gnome/Boxes/ui/downloads-hub-row.ui")]
@@ -78,7 +129,7 @@ private void on_row_activated (Gtk.ListBoxRow _row) {
[GtkChild]
private ProgressBar progress_bar;
- private ActivityProgress progress = new ActivityProgress ();
+ public ActivityProgress progress = new ActivityProgress ();
private ulong progress_notify_id;
private Cancellable cancellable = new Cancellable ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]