[gnome-boxes/transfer-popover-encapsulate-setup: 3/3] transfer-popover: Encapsulate widget setup internally




commit 6329621438912ea63288866a2003436246216cd9
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Jul 7 15:23:33 2021 +0200

    transfer-popover: Encapsulate widget setup internally
    
    Instead of publicly exposing the object properties and signals for
    tasks that can be encapsulated internally.

 src/display-page.vala     |  8 --------
 src/display-toolbar.vala  |  7 -------
 src/transfer-popover.vala | 22 +++++++++++++++++++---
 3 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/src/display-page.vala b/src/display-page.vala
index ea0e5636..1fc1b4a1 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -80,13 +80,6 @@ public void setup_ui (AppWindow window) {
 
         drag_dest_set (transfer_message_box, Gtk.DestDefaults.DROP, target_list, DragAction.ASK);
         transfer_popover = new Boxes.TransferPopover (window.topbar.display_toolbar);
-        transfer_popover.bind_property ("progress", window.topbar.display_toolbar, "progress", 
BindingFlags.DEFAULT);
-        transfer_popover.relative_to = window.topbar.display_toolbar.transfers_button;
-
-        transfer_popover.all_finished.connect (() => {
-            transfer_popover.clean_up ();
-            transfer_popover.popdown ();
-        });
     }
 
      private void update_toolbar_visible() {
@@ -100,7 +93,6 @@ private void update_toolbar_visible() {
 
      public void add_transfer (Object transfer_task) {
         transfer_popover.add_transfer (transfer_task);
-        transfer_popover.popup ();
      }
 
      private void set_overlay_toolbar_visible(bool visible) {
diff --git a/src/display-toolbar.vala b/src/display-toolbar.vala
index 91214b84..4f75cc61 100644
--- a/src/display-toolbar.vala
+++ b/src/display-toolbar.vala
@@ -90,13 +90,6 @@ public void setup_ui (AppWindow window) {
         });
         keys_menu_button.popover = new KeysInputPopover (window);
         transfers_drawing_area.draw.connect (on_draw);
-        transfers_button.clicked.connect ( () => {
-            var popover = window.display_page.transfer_popover;
-            if (popover.visible)
-                popover.popdown ();
-            else
-                popover.popup ();
-        });
     }
 
     private bool on_draw (Widget da, Cairo.Context ctx) {
diff --git a/src/transfer-popover.vala b/src/transfer-popover.vala
index ae50bc30..b66a19f0 100644
--- a/src/transfer-popover.vala
+++ b/src/transfer-popover.vala
@@ -6,7 +6,6 @@
     [GtkChild]
     public unowned Gtk.Box transfers_container;
 
-    public signal void all_finished ();
     public GLib.List<Spice.FileTransferTask> spice_tasks;
     public double progress { get; set; }
 
@@ -16,6 +15,16 @@
 
     public TransferPopover (Boxes.DisplayToolbar toolbar) {
         display_toolbar = toolbar;
+        relative_to = display_toolbar.transfers_button;
+
+        display_toolbar.transfers_button.clicked.connect (() => {
+            if (visible)
+                popdown ();
+            else
+                popup ();
+        });
+
+        bind_property ("progress", display_toolbar, "progress", BindingFlags.DEFAULT);
     }
 
     public void add_transfer (Object transfer_task) {
@@ -26,6 +35,8 @@ public void add_transfer (Object transfer_task) {
         } else {
             warning ("File transfer of unsupported type.");
         }
+
+        popup ();
     }
 
     public void add_spice_transfer (Spice.FileTransferTask transfer_task) {
@@ -61,7 +72,7 @@ public void add_spice_transfer (Spice.FileTransferTask transfer_task) {
 
             if (spice_tasks.length () == 0) {
                 Timeout.add (remove_id_timeout, () => {
-                    all_finished ();
+                    on_transfer_finished ();
 
                     return false;
                 });
@@ -73,7 +84,7 @@ public void add_spice_transfer (Spice.FileTransferTask transfer_task) {
 
             if (spice_tasks.length () == 0) {
                 Timeout.add (remove_id_timeout, () => {
-                        all_finished ();
+                        on_transfer_finished ();
 
                         return false;
                     });
@@ -93,4 +104,9 @@ public void clean_up () {
         display_toolbar.progress = 0;
         display_toolbar.transfers_button.hide ();
     }
+
+    private void on_transfer_finished () {
+        clean_up ();
+        popdown ();
+    }
 }


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