[gnome-boxes] Add TransferPopover
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add TransferPopover
- Date: Mon, 5 Feb 2018 14:56:43 +0000 (UTC)
commit 44ae83785f353a0426311ec946bc4ee36c5a8c89
Author: Visarion Alexandru <viorel visarion gmail com>
Date: Thu Dec 14 19:26:09 2017 +0200
Add TransferPopover
Add a popover capable of letting users visualize/manage
ongoing transfers between the host and a guest machine,
using the previously introduced TransferInfoRow
https://bugzilla.gnome.org/show_bug.cgi?id=762321
data/gnome-boxes.gresource.xml | 1 +
data/ui/transfer-popover.ui | 21 +++++++++
src/Makefile.am | 1 +
src/meson.build | 1 +
src/transfer-popover.vala | 96 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 120 insertions(+)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index df3de724..01c72d59 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -31,6 +31,7 @@
<file preprocess="xml-stripblanks">ui/snapshot-list-row.ui</file>
<file preprocess="xml-stripblanks">ui/topbar.ui</file>
<file preprocess="xml-stripblanks">ui/transfer-info-row.ui</file>
+ <file preprocess="xml-stripblanks">ui/transfer-popover.ui</file>
<file preprocess="xml-stripblanks">ui/troubleshoot-log.ui</file>
<file preprocess="xml-stripblanks">ui/troubleshoot-view.ui</file>
<file preprocess="xml-stripblanks">ui/unattended-setup-box.ui</file>
diff --git a/data/ui/transfer-popover.ui b/data/ui/transfer-popover.ui
new file mode 100644
index 00000000..ddbbc084
--- /dev/null
+++ b/data/ui/transfer-popover.ui
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="BoxesTransferPopover" parent="GtkPopover">
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+ <property name="max-content-height">270</property>
+ <property name="propagate-natural-height">True</property>
+ <child>
+ <object class="GtkBox" id="transfers_container">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <property name="margin">12</property>
+ <property name="spacing">10</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 7ecb62e9..a6d8eace 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -161,6 +161,7 @@ gnome_boxes_SOURCES = \
empty-boxes.vala \
tracker-iso-query.vala \
transfer-info-row.vala \
+ transfer-popover.vala \
troubleshoot-log.vala \
troubleshoot-view.vala \
shared-folder-popover.vala \
diff --git a/src/meson.build b/src/meson.build
index 4b9c66ec..7716668d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -87,6 +87,7 @@ vala_sources = [
'shared-folder-popover.vala',
'spice-display.vala',
'transfer-info-row.vala',
+ 'transfer-popover.vala',
'troubleshoot-view.vala',
'topbar.vala',
'ui.vala',
diff --git a/src/transfer-popover.vala b/src/transfer-popover.vala
new file mode 100644
index 00000000..d9a0d395
--- /dev/null
+++ b/src/transfer-popover.vala
@@ -0,0 +1,96 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/transfer-popover.ui")]
+private class Boxes.TransferPopover: Gtk.Popover {
+ [GtkChild]
+ public Gtk.Box transfers_container;
+
+ public signal void all_finished ();
+ public GLib.List<Spice.FileTransferTask> spice_tasks;
+ public double progress { get; set; }
+
+ private const uint remove_id_timeout = 5000; // 5 seconds
+ private ulong total_bytes_id = 0;
+ private Boxes.DisplayToolbar display_toolbar;
+
+ public TransferPopover (Boxes.DisplayToolbar toolbar) {
+ display_toolbar = toolbar;
+ }
+
+ public void add_transfer (Object transfer_task) {
+ if (transfer_task is Spice.FileTransferTask) {
+ var spice_transfer_task = transfer_task as Spice.FileTransferTask;
+
+ add_spice_transfer (spice_transfer_task);
+ } else {
+ warning ("File transfer of unsupported type.");
+ }
+ }
+
+ public void add_spice_transfer (Spice.FileTransferTask transfer_task) {
+ spice_tasks.append (transfer_task);
+
+ var row = new Boxes.TransferInfoRow (transfer_task.file.get_basename ());
+ transfer_task.bind_property ("transferred-bytes", row, "transferred-bytes",
BindingFlags.SYNC_CREATE);
+
+ total_bytes_id = transfer_task.notify["total-bytes"].connect ( (t, p) => {
+ row.total_bytes = transfer_task.total_bytes;
+
+ transfer_task.disconnect (total_bytes_id);
+ });
+
+ transfer_task.notify["progress"].connect ( (t, p) => {
+ row.progress = transfer_task.progress;
+
+ double total = 0;
+ double transferred = 0;
+ foreach (var task in spice_tasks) {
+ total += task.get_total_bytes ();
+ transferred += task.get_transferred_bytes ();
+ }
+
+ progress = transferred/total;
+ });
+ transfer_task.finished.connect ( (transfer_task, error) => {
+ if (error != null)
+ warning (error.message);
+
+ row.finalize_transfer ();
+ spice_tasks.remove (transfer_task);
+
+ if (spice_tasks.length () == 0) {
+ Timeout.add (remove_id_timeout, () => {
+ all_finished ();
+
+ return false;
+ });
+ }
+
+ });
+ row.finished.connect (() => {
+ spice_tasks.remove(transfer_task);
+
+ if (spice_tasks.length () == 0) {
+ Timeout.add (remove_id_timeout, () => {
+ all_finished ();
+
+ return false;
+ });
+ }
+ });
+
+ transfers_container.pack_start (row);
+ row.show ();
+ }
+
+ public void clean_up () {
+ foreach (var row in transfers_container.get_children ()) {
+ transfers_container.remove (row);
+ }
+
+ popdown ();
+ display_toolbar.progress = 0;
+ display_toolbar.transfers_button.hide ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]