[Spice-devel] [PATCH spice-html5 v2 2/2] main: Add event to alert file transfer error messages

Tomáš Bohdálek tom.bohdalek at gmail.com
Mon Sep 18 09:16:11 UTC 2017


---
 main.js         | 79 +++++++++++++++++++++++++++++++++++++--------------------
 spice.html      |  5 ++++
 spice_auto.html |  5 ++++
 3 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/main.js b/main.js
index 6a04da9..e93536b 100644
--- a/main.js
+++ b/main.js
@@ -375,36 +375,49 @@ SpiceMainConn.prototype.handle_file_xfer_status = function(file_xfer_status)
         return;
     }
     xfer_task = this.file_xfer_tasks[file_xfer_status.id];
-    switch (file_xfer_status.result)
+
+    if (file_xfer_status.result != VD_AGENT_FILE_XFER_STATUS_SUCCESS)
     {
-        case VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:
-            this.file_xfer_read(xfer_task);
-            return;
-        case VD_AGENT_FILE_XFER_STATUS_CANCELLED:
-            xfer_error = "transfer is cancelled by spice agent";
-            break;
-        case VD_AGENT_FILE_XFER_STATUS_ERROR:
-            xfer_error = "some errors occurred in the spice agent";
-            break;
-        case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE:
-            xfer_error = "not enough space in the remote system";
-            break;
-        case VD_AGENT_FILE_XFER_STATUS_SESSION_LOCKED:
-            xfer_error = "remote system is locked";
-            break;
-        case VD_AGENT_FILE_XFER_STATUS_AGENT_NOT_CONNECTED:
-            xfer_error = "spice angent is not connected";
-            break;
-        case VD_AGENT_FILE_XFER_STATUS_DISABLED:
-            xfer_error = "file transfer is disabled on the remote system";
-            break;
-        default:
-            xfer_error = "unhandled status type: " + file_xfer_status.result;
-            break;
-    }
+        switch (file_xfer_status.result)
+        {
+            case VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:
+                this.file_xfer_read(xfer_task);
+                return;
+            case VD_AGENT_FILE_XFER_STATUS_CANCELLED:
+                xfer_error = "transfer is cancelled by spice agent";
+                break;
+            case VD_AGENT_FILE_XFER_STATUS_ERROR:
+                xfer_error = "some errors occurred in the spice agent";
+                this.file_xfer_detailed_errors(xfer_error);
+                break;
+            case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE:
+                xfer_error = "not enough space in the remote system";
+                this.file_xfer_detailed_errors(xfer_error);
+                break;
+            case VD_AGENT_FILE_XFER_STATUS_SESSION_LOCKED:
+                xfer_error = "remote system is locked";
+                this.file_xfer_detailed_errors(xfer_error);
+                break;
+            case VD_AGENT_FILE_XFER_STATUS_AGENT_NOT_CONNECTED:
+                xfer_error = "spice agent is not connected";
+                this.file_xfer_detailed_errors(xfer_error);
+                break;
+            case VD_AGENT_FILE_XFER_STATUS_DISABLED:
+                xfer_error = "file transfer is disabled on the remote system";
+                this.file_xfer_detailed_errors(xfer_error);
+                break;
+            default:
+                xfer_error = "unhandled status type: " + file_xfer_status.result;
+                break;
+        }
 
-    xfer_error = "File transfer: " + xfer_error;
-    this.file_xfer_completed(xfer_task, xfer_error)
+        xfer_error = "File transfer: " + xfer_error;
+        this.file_xfer_completed(xfer_task, xfer_error);
+    }
+    else
+    {
+        this.file_xfer_completed(xfer_task);
+    }
 }
 
 SpiceMainConn.prototype.file_xfer_read = function(file_xfer_task, start_byte)
@@ -504,3 +517,13 @@ SpiceMainConn.prototype.relative_now = function()
     var ret = (Date.now() - this.our_mm_time) + this.mm_time;
     return ret;
 }
+
+SpiceMainConn.prototype.file_xfer_detailed_errors = function(status)
+{
+    var event = new CustomEvent('xfer-error', {
+            detail: {
+                data: "File transfer: " + status
+            }
+        });
+    window.dispatchEvent(event);
+}
diff --git a/spice.html b/spice.html
index 3a74e21..1e78e81 100644
--- a/spice.html
+++ b/spice.html
@@ -173,6 +173,11 @@
             });
             */
 
+            window.addEventListener('xfer-error', function(event)
+            {
+                alert(event.detail.data);
+            });
+
         </script>
 
     </head>
diff --git a/spice_auto.html b/spice_auto.html
index 10f5508..92e75f1 100644
--- a/spice_auto.html
+++ b/spice_auto.html
@@ -196,6 +196,11 @@
             });
             */
 
+            window.addEventListener('xfer-error', function(event)
+            {
+                alert(event.detail.data);
+            });
+
             connect();
         </script>
 
-- 
2.9.5



More information about the Spice-devel mailing list