X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=OpenTween%2FToolStripAPIGauge.cs;h=8143ebcae579be1fbfc0ae62f67a506a5a302cca;hb=03835b2189cd3a42bd2c9e3413b4161e3786b455;hp=5a17b413626074a563de55f8ecf5422d0ea4d424;hpb=f27e01d81eb617748376590e3a1aa776accdb6dc;p=opentween%2Fopen-tween.git diff --git a/OpenTween/ToolStripAPIGauge.cs b/OpenTween/ToolStripAPIGauge.cs index 5a17b413..8143ebca 100644 --- a/OpenTween/ToolStripAPIGauge.cs +++ b/OpenTween/ToolStripAPIGauge.cs @@ -19,6 +19,8 @@ // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, // Boston, MA 02110-1301, USA. +#nullable enable + using System; using System.Collections.Generic; using System.Linq; @@ -38,10 +40,8 @@ namespace OpenTween public class ToolStripAPIGauge : ToolStripStatusLabel { public ToolStripAPIGauge() - : base() { - this.Text = "API ???/???"; - this.ToolTipText = "API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)"; + UpdateText(); this.DisplayStyle = ToolStripItemDisplayStyle.Text; } @@ -53,7 +53,7 @@ namespace OpenTween [RefreshProperties(RefreshProperties.Repaint)] public int GaugeHeight { - get { return this._GaugeHeight; } + get => this._GaugeHeight; set { this._GaugeHeight = value; @@ -68,10 +68,10 @@ namespace OpenTween /// API 実行回数制限の値 /// [Browsable(false)] - public ApiLimit ApiLimit + public ApiLimit? ApiLimit { - get { return this._ApiLimit; } - set + get => this._ApiLimit; + private set { this._ApiLimit = value; @@ -81,30 +81,68 @@ namespace OpenTween this.Invalidate(); } } - private ApiLimit _ApiLimit = null; + private ApiLimit? _ApiLimit = null; + + /// + /// API エンドポイント名 + /// + [Browsable(false)] + public string? ApiEndpoint + { + get => this._ApiEndpoint; + set + { + if (MyCommon.IsNullOrEmpty(value)) + { + // リセット + this._ApiEndpoint = null; + this.ApiLimit = null; + return; + } + + var apiLimit = MyCommon.TwitterApiInfo.AccessLimit[value]; + + if (this._ApiEndpoint != value) + { + // ApiEndpointが変更されているので更新する + this._ApiEndpoint = value; + this.ApiLimit = apiLimit; + } + else + { + // ApiLimitが変更されていれば更新する + if (this._ApiLimit == null || + !this._ApiLimit.Equals(apiLimit)) + { + this.ApiLimit = apiLimit; + } + } + } + } + private string? _ApiEndpoint = null; [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new string Text { - get { return base.Text; } - set { base.Text = value; } + get => base.Text; + set => base.Text = value; } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new string ToolTipText { - get { return base.ToolTipText; } - set { base.ToolTipText = value; } + get => base.ToolTipText; + set => base.ToolTipText = value; } [DefaultValue(ToolStripItemDisplayStyle.Text)] [RefreshProperties(RefreshProperties.Repaint)] public new ToolStripItemDisplayStyle DisplayStyle { - get { return base.DisplayStyle; } - set { base.DisplayStyle = value; } + get => base.DisplayStyle; + set => base.DisplayStyle = value; } protected double remainMinutes = -1; @@ -112,7 +150,7 @@ namespace OpenTween protected virtual void UpdateRemainMinutes() { if (this._ApiLimit != null) - this.remainMinutes = (this._ApiLimit.AccessLimitResetDate - DateTime.Now).TotalMinutes; + this.remainMinutes = (this._ApiLimit.AccessLimitResetDate - DateTimeUtc.Now).TotalMinutes; else this.remainMinutes = -1; } @@ -156,7 +194,7 @@ namespace OpenTween this._GaugeHeight ); - var timeGaugeValue = this.remainMinutes >= 60 ? 1.00 : this.remainMinutes / 60; + var timeGaugeValue = this.remainMinutes >= 15 ? 1.00 : this.remainMinutes / 15; this.timeGaugeBounds = new Rectangle( 0, this.apiGaugeBounds.Top + this._GaugeHeight, @@ -171,7 +209,7 @@ namespace OpenTween string maxCountText; string minuteText; - if (this._ApiLimit == null) + if (this._ApiLimit == null || this.remainMinutes < 0) { remainCountText = "???"; maxCountText = "???"; @@ -184,14 +222,16 @@ namespace OpenTween minuteText = Math.Ceiling(this.remainMinutes).ToString(); } + var endpointText = MyCommon.IsNullOrEmpty(this._ApiEndpoint) ? "unknown" : this._ApiEndpoint; + var textFormat = "API {0}/{1}"; this.Text = string.Format(textFormat, remainCountText, maxCountText); var toolTipTextFormat = - "API rest {0}/{1}" + Environment.NewLine + - "(reset after {2} minutes)"; + "API rest {0} {1}/{2}" + Environment.NewLine + + "(reset after {3} minutes)"; - this.ToolTipText = String.Format(toolTipTextFormat, remainCountText, maxCountText, minuteText); + this.ToolTipText = string.Format(toolTipTextFormat, endpointText, remainCountText, maxCountText, minuteText); } #endregion