From 56d26edb3692d114b0e7aba102a026156dbce074 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Sat, 3 Feb 2018 16:03:06 +0100 Subject: [PATCH] Add a progress bar to the context menu. NOTE: currently any update to the progress bar will also re-display the balloon tooltip. These two things should be separated! Refers to #2 --- ATxTray/AutoTxTray.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ATxTray/AutoTxTray.cs b/ATxTray/AutoTxTray.cs index c07d377..0bd82b4 100644 --- a/ATxTray/AutoTxTray.cs +++ b/ATxTray/AutoTxTray.cs @@ -36,6 +36,7 @@ namespace ATxTray private static bool _txInProgress = false; private static long _txSize; + private static int _txProgressPct; private readonly NotifyIcon _notifyIcon = new NotifyIcon(); private readonly Icon _tiDefault = new Icon("icon-default.ico"); @@ -51,6 +52,8 @@ namespace ATxTray private readonly ToolStripMenuItem _miTxProgress = new ToolStripMenuItem(); private readonly ToolStripMenuItem _miTxEnqueue = new ToolStripMenuItem(); + private readonly ToolStripProgressBar _miTxProgressBar = new ToolStripProgressBar(); + public AutoTxTray() { #region logging configuration @@ -129,11 +132,19 @@ namespace ATxTray _miTxEnqueue.Text = @"+++ Add new directory for transfer. +++"; _miTxEnqueue.Click += StartNewTransfer; + _miTxProgressBar.Text = @"Current Transfer Progress"; + _miTxProgressBar.ToolTipText = _miTxProgressBar.Text; + _miTxProgressBar.Value = 0; + var size = _miTxProgressBar.Size; + size.Width = 300; + _miTxProgressBar.Size = size; + _cmStrip.Items.AddRange(new ToolStripItem[] { _miTitle, _miSvcRunning, _miSvcSuspended, _miTxProgress, + _miTxProgressBar, new ToolStripSeparator(), _miTxEnqueue, new ToolStripSeparator(), @@ -225,7 +236,7 @@ namespace ATxTray if (age == _statusAge) return; - Log.Debug("Status file was updated, trying to re-read..."); + Log.Trace("Status file was updated, trying to re-read..."); _statusAge = age; _status = ServiceStatus.Deserialize(StatusFile, _config); } @@ -292,12 +303,14 @@ namespace ATxTray private void UpdateTxInProgress() { if (_txInProgress == _status.TransferInProgress && - _txSize == _status.CurrentTransferSize) + _txSize == _status.CurrentTransferSize && + _txProgressPct == _status.CurrentTransferPercent) return; _statusChanged = true; _txInProgress = _status.TransferInProgress; _txSize = _status.CurrentTransferSize; + _txProgressPct = _status.CurrentTransferPercent; if (_txInProgress) { _miTxProgress.Text = @"Transfer in progress (size: " + Conv.BytesToString(_txSize) + ")"; @@ -305,11 +318,17 @@ namespace ATxTray _notifyIcon.ShowBalloonTip(500, AppTitle, "New transfer started (size: " + Conv.BytesToString(_txSize) + ").", ToolTipIcon.Info); + Log.Debug("Transfer progress: {0}%", _txProgressPct); + _miTxProgressBar.Visible = true; + _miTxProgressBar.Value = _txProgressPct; + _miTxProgressBar.Text = _txProgressPct.ToString(); } else { _miTxProgress.Text = @"No transfer running."; _miTxProgress.ResetBackColor(); _notifyIcon.ShowBalloonTip(500, AppTitle, - "Transfer completed.", ToolTipIcon.Info); + "Transfer completed.", ToolTipIcon.Info); + _miTxProgressBar.Value = 0; + _miTxProgressBar.Visible = false; } } -- GitLab