OSDN Git Service

pbs.twimg.com の画像URLのフォーマット変更に対応
[opentween/open-tween.git] / OpenTween / ToolStripLabelHistory.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2011      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 // 
10 // This file is part of OpenTween.
11 // 
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 // 
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details. 
21 // 
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 #nullable enable
28
29 using System;
30 using System.Collections.Generic;
31 using System.Linq;
32 using System.Text;
33 using System.Windows.Forms;
34
35 namespace OpenTween.OpenTweenCustomControl
36 {
37     public class ToolStripLabelHistory : ToolStripStatusLabel
38     {
39         public enum LogLevel
40         {
41             Lowest = 0,
42             Debug = 16,
43             Info = 32,
44             Notice = 64,
45             Warn = 128,
46             Err = 192,
47             Fatal = 255,
48             Highest = 256,
49         }
50
51         public class LogEntry
52         {
53             public LogLevel LogLevel { get; }
54             public DateTimeUtc Timestamp { get; }
55             public string Summary { get; }
56             public string Detail { get; }
57
58             public LogEntry(LogLevel logLevel, DateTimeUtc timestamp, string summary, string detail)
59             {
60                 this.LogLevel = logLevel;
61                 this.Timestamp = timestamp;
62                 this.Summary = summary;
63                 this.Detail = detail;
64             }
65
66             public LogEntry(DateTimeUtc timestamp, string summary) : this(LogLevel.Debug, timestamp, summary, summary)
67             {
68             }
69
70             public override string ToString()
71                 => Timestamp.ToLocalTime().ToString("T") + ": " + Summary;
72         }
73
74         readonly LinkedList<LogEntry> _logs;
75
76         const int MAXCNT = 20;
77
78         public override string Text
79         {
80             get => base.Text;
81             set
82             {
83                 var oneline = value.Replace("\n", " ");
84                 _logs.AddLast(new LogEntry(DateTimeUtc.Now, oneline));
85                 while (_logs.Count > MAXCNT)
86                 {
87                     _logs.RemoveFirst();
88                 }
89                 base.Text = oneline;
90             }
91         }
92
93         public string TextHistory
94         {
95             get
96             {
97                 var sb = new StringBuilder();
98                 foreach (var e in _logs)
99                 {
100                     sb.AppendLine(e.ToString());
101                 }
102                 return sb.ToString();
103             }
104         }
105
106         public ToolStripLabelHistory()
107             => this._logs = new LinkedList<LogEntry>();
108     }
109 }