From 2a450fc7c14c8b3be5940a08633228bf9360526b Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Thu, 11 Jan 2018 11:22:47 +0100
Subject: [PATCH] Add transfer progress information to menu and tooltips.

Refers to #2
---
 ATXTray/AutoTxTray.cs | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/ATXTray/AutoTxTray.cs b/ATXTray/AutoTxTray.cs
index 4120866..8c2fd77 100644
--- a/ATXTray/AutoTxTray.cs
+++ b/ATXTray/AutoTxTray.cs
@@ -24,6 +24,9 @@ namespace ATXTray
         private static bool _svcRunning = false;
         private static bool _svcSuspended = true;
         private static string _svcSuspendReason;
+
+        private static bool _txInProgress = false;
+        private static long _txSize;
         
         private readonly NotifyIcon _notifyIcon = new NotifyIcon();
         private readonly ContextMenuStrip _cmStrip = new ContextMenuStrip();
@@ -31,6 +34,7 @@ namespace ATXTray
         private readonly ToolStripMenuItem _miTitle = new ToolStripMenuItem();
         private readonly ToolStripMenuItem _miSvcRunning = new ToolStripMenuItem();
         private readonly ToolStripMenuItem _miSvcSuspended = new ToolStripMenuItem();
+        private readonly ToolStripMenuItem _miTxProgress = new ToolStripMenuItem();
 
         public AutoTxTray() {
             _notifyIcon.Visible = true;
@@ -66,10 +70,14 @@ namespace ATXTray
             _miSvcSuspended.Text = @"No limits apply, service active.";
             _miSvcSuspended.Click += ShowContextMenu;
 
+            _miTxProgress.Text = "No transfer running.";
+            _miTxProgress.Click += ShowContextMenu;
+
             _cmStrip.Items.AddRange(new ToolStripItem[] {
                 _miTitle,
                 _miSvcRunning,
                 _miSvcSuspended,
+                _miTxProgress,
                 _miExit
             });
 
@@ -101,10 +109,11 @@ namespace ATXTray
                 serviceRunning = "OK";
                 ReadStatus();
                 UpdateSvcSuspended();
+                UpdateTxInProgress();
                 if ((DateTime.Now - _status.LastStatusUpdate).TotalSeconds < 60)
                     heartBeat = "OK";
-                if (_status.TransferInProgress)
-                    txInProgress = "Yes";
+                if (_txInProgress)
+                    txProgress = _txSize.ToString();
             }
 
             if (!_statusChanged)
@@ -196,5 +205,26 @@ namespace ATXTray
                  */
             }
         }
+
+        private void UpdateTxInProgress() {
+            if (_txInProgress == _status.TransferInProgress &&
+                _txSize == _status.CurrentTransferSize)
+                return;
+
+            _statusChanged = true;
+            _txInProgress = _status.TransferInProgress;
+            _txSize = _status.CurrentTransferSize;
+            if (_txInProgress) {
+                _miTxProgress.Text = @"Transfer in progress (size: " + _txSize + ")";
+                _miTxProgress.BackColor = Color.LightGreen;
+                _notifyIcon.ShowBalloonTip(500, AppTitle,
+                    "New transfer started (size: " + _txSize + ").", ToolTipIcon.Info);
+            } else {
+                _miTxProgress.Text = @"No transfer running.";
+                _miTxProgress.ResetBackColor();
+                _notifyIcon.ShowBalloonTip(500, AppTitle,
+                    "Transfer completed.", ToolTipIcon.Info);                
+            }
+        }
     }
 }
-- 
GitLab