[gnome-boxes/update-ui-when-agent-is-connected] actions-popover, display: Update UI when guest agent is connected



commit fdd5a6297a89922ecad47144addb9e7ca4b76ac8
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jun 9 11:23:18 2020 +0200

    actions-popover, display: Update UI when guest agent is connected
    
    Specifically the "Send File" ActionsPopover entry which should be
    only active when the Spice guest agent is connected.
    
    Fixes #483

 src/actions-popover.vala | 3 +++
 src/display.vala         | 1 +
 src/spice-display.vala   | 7 +++++++
 3 files changed, 11 insertions(+)
---
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
index 9ba9b955..c953532f 100644
--- a/src/actions-popover.vala
+++ b/src/actions-popover.vala
@@ -50,6 +50,9 @@ public void update_for_item (CollectionItem item) {
             section.append (_("Send Fileā€¦"), "box.send_file");
             var action = action_group.lookup_action ("send_file") as GLib.SimpleAction;
             action.set_enabled (machine.display.can_transfer_files);
+            machine.display.notify["is-guest-agent-connected"].connect (() => {
+                action.set_enabled (machine.display.can_transfer_files);
+            });
 
             // Take Screenshot
             section.append (_("Take Screenshot"), "box.take_screenshot");
diff --git a/src/display.vala b/src/display.vala
index cddf640b..8c5a95dd 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -10,6 +10,7 @@
     public bool can_grab_mouse { get; protected set; }
     public bool mouse_grabbed { get; protected set; }
     public bool keyboard_grabbed { get; protected set; }
+    public bool is_guest_agent_connected { get; protected set; }
     public bool need_password { get; protected set; }
     public bool need_username { get; protected set; }
     public string? password { get; set; }
diff --git a/src/spice-display.vala b/src/spice-display.vala
index b4c7ba00..78ccd455 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -84,11 +84,16 @@ private string get_box_name () {
 
                 can_grab_mouse = main_channel.mouse_mode != 2;
                 new_file_transfer_id = main_channel.new_file_transfer.connect (on_new_file_transfer);
+
+                agent_connected_id = main_channel.notify["agent-connected"].connect (() => {
+                    is_guest_agent_connected = main_channel.agent_connected;
+                });
             }
     }
     ulong main_event_id;
     ulong main_mouse_mode_id;
     ulong new_file_transfer_id;
+    ulong agent_connected_id;
 
     private void main_cleanup () {
         if (main_channel == null)
@@ -101,6 +106,8 @@ private void main_cleanup () {
         main_mouse_mode_id = 0;
         o.disconnect (new_file_transfer_id);
         new_file_transfer_id = 0;
+        o.disconnect (agent_connected_id);
+        agent_connected_id = 0;
         main_channel = null;
     }
 


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