OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Setting / SettingLocal.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.Drawing;
34 using System.Xml.Serialization;
35 using OpenTween.Connection;
36
37 namespace OpenTween
38 {
39     public class SettingLocal : SettingBase<SettingLocal>, IDisposable
40     {
41         #region Settingクラス基本
42         public static SettingLocal Load()
43             => LoadSettings();
44
45         public void Save()
46             => SaveSettings(this);
47         #endregion
48
49         /// <summary>
50         /// ウィンドウサイズ等の保存時のDPI
51         /// </summary>
52         public SizeF ScaleDimension = SizeF.Empty;
53
54         public Point FormLocation = new Point(0, 0);
55         public int SplitterDistance = 200;
56         public Size FormSize = new Size(600, 500);
57
58         /// <summary>
59         /// 文末ステータス
60         /// </summary>
61         public string StatusText = "";
62
63         public bool UseRecommendStatus = false;
64         public int Width1 = 48;
65         public int Width2 = 80;
66         public int Width3 = 290;
67         public int Width4 = 120;
68         public int Width5 = 50;
69         public int Width6 = 16;
70         public int Width7 = 32;
71         public int Width8 = 50;
72         public int DisplayIndex1 = 2;
73         public int DisplayIndex2 = 3;
74         public int DisplayIndex3 = 4;
75         public int DisplayIndex4 = 5;
76         public int DisplayIndex5 = 6;
77         public int DisplayIndex6 = 1;
78         public int DisplayIndex7 = 0;
79         public int DisplayIndex8 = 7;
80         public string BrowserPath = "";
81         public ProxyType ProxyType = ProxyType.IE;
82         public string ProxyAddress = "127.0.0.1";
83         public int ProxyPort = 80;
84         public string ProxyUser = "";
85         public bool StatusMultiline = false;
86         public int StatusTextHeight = 38;
87         public int PreviewDistance = -1;
88
89         [XmlIgnore]
90         public Font FontUnread = new Font(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
91         public string FontUnreadStr
92         {
93             get => this.FontToString(this.FontUnread);
94             set => this.FontUnread = this.StringToFont(value);
95         }
96
97         [XmlIgnore]
98         public Color ColorUnread = System.Drawing.SystemColors.ControlText;
99         public string ColorUnreadStr
100         {
101             get => this.ColorToString(this.ColorUnread);
102             set => this.ColorUnread = this.StringToColor(value);
103         }
104
105         [XmlIgnore]
106         public Font FontRead = System.Drawing.SystemFonts.DefaultFont;
107         public string FontReadStr
108         {
109             get => this.FontToString(this.FontRead);
110             set => this.FontRead = this.StringToFont(value);
111         }
112
113         [XmlIgnore]
114         public Color ColorRead = System.Drawing.SystemColors.ControlText;
115         public string ColorReadStr
116         {
117             get => this.ColorToString(this.ColorRead);
118             set => this.ColorRead = this.StringToColor(value);
119         }
120
121         [XmlIgnore]
122         public Color ColorFav = Color.FromKnownColor(System.Drawing.KnownColor.Red);
123         public string ColorFavStr
124         {
125             get => this.ColorToString(this.ColorFav);
126             set => this.ColorFav = this.StringToColor(value);
127         }
128
129         [XmlIgnore]
130         public Color ColorOWL = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
131         public string ColorOWLStr
132         {
133             get => this.ColorToString(this.ColorOWL);
134             set => this.ColorOWL = this.StringToColor(value);
135         }
136
137         [XmlIgnore]
138         public Color ColorRetweet = Color.FromKnownColor(System.Drawing.KnownColor.Green);
139         public string ColorRetweetStr
140         {
141             get => this.ColorToString(this.ColorRetweet);
142             set => this.ColorRetweet = this.StringToColor(value);
143         }
144
145         [XmlIgnore]
146         public Font FontDetail = System.Drawing.SystemFonts.DefaultFont;
147         public string FontDetailStr
148         {
149             get => this.FontToString(this.FontDetail);
150             set => this.FontDetail = this.StringToFont(value);
151         }
152
153         [XmlIgnore]
154         public Color ColorSelf = Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue);
155         public string ColorSelfStr
156         {
157             get => this.ColorToString(this.ColorSelf);
158             set => this.ColorSelf = this.StringToColor(value);
159         }
160
161         [XmlIgnore]
162         public Color ColorAtSelf = Color.FromKnownColor(System.Drawing.KnownColor.AntiqueWhite);
163         public string ColorAtSelfStr
164         {
165             get => this.ColorToString(this.ColorAtSelf);
166             set => this.ColorAtSelf = this.StringToColor(value);
167         }
168
169         [XmlIgnore]
170         public Color ColorTarget = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
171         public string ColorTargetStr
172         {
173             get => this.ColorToString(this.ColorTarget);
174             set => this.ColorTarget = this.StringToColor(value);
175         }
176
177         [XmlIgnore]
178         public Color ColorAtTarget = Color.FromKnownColor(System.Drawing.KnownColor.LavenderBlush);
179         public string ColorAtTargetStr
180         {
181             get => this.ColorToString(this.ColorAtTarget);
182             set => this.ColorAtTarget = this.StringToColor(value);
183         }
184
185         [XmlIgnore]
186         public Color ColorAtFromTarget = Color.FromKnownColor(System.Drawing.KnownColor.Honeydew);
187         public string ColorAtFromTargetStr
188         {
189             get => this.ColorToString(this.ColorAtFromTarget);
190             set => this.ColorAtFromTarget = this.StringToColor(value);
191         }
192
193         [XmlIgnore]
194         public Color ColorAtTo = Color.FromKnownColor(System.Drawing.KnownColor.Pink);
195         public string ColorAtToStr
196         {
197             get => this.ColorToString(this.ColorAtTo);
198             set => this.ColorAtTo = this.StringToColor(value);
199         }
200
201         [XmlIgnore]
202         public Color ColorInputBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
203         public string ColorInputBackcolorStr
204         {
205             get => this.ColorToString(this.ColorInputBackcolor);
206             set => this.ColorInputBackcolor = this.StringToColor(value);
207         }
208
209         [XmlIgnore]
210         public Color ColorInputFont = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
211         public string ColorInputFontStr
212         {
213             get => this.ColorToString(this.ColorInputFont);
214             set => this.ColorInputFont = this.StringToColor(value);
215         }
216
217         [XmlIgnore]
218         public Font FontInputFont = System.Drawing.SystemFonts.DefaultFont;
219         public string FontInputFontStr
220         {
221             get => this.FontToString(this.FontInputFont);
222             set => this.FontInputFont = this.StringToFont(value);
223         }
224
225         [XmlIgnore]
226         public Color ColorListBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
227         public string ColorListBackcolorStr
228         {
229             get => this.ColorToString(this.ColorListBackcolor);
230             set => this.ColorListBackcolor = this.StringToColor(value);
231         }
232
233         [XmlIgnore]
234         public Color ColorDetailBackcolor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
235         public string ColorDetailBackcolorStr
236         {
237             get => this.ColorToString(this.ColorDetailBackcolor);
238             set => this.ColorDetailBackcolor = this.StringToColor(value);
239         }
240
241         [XmlIgnore]
242         public Color ColorDetail = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
243         public string ColorDetailStr
244         {
245             get => this.ColorToString(this.ColorDetail);
246             set => this.ColorDetail = this.StringToColor(value);
247         }
248
249         [XmlIgnore]
250         public Color ColorDetailLink = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
251         public string ColorDetailLinkStr
252         {
253             get => this.ColorToString(this.ColorDetailLink);
254             set => this.ColorDetailLink = this.StringToColor(value);
255         }
256
257         [XmlIgnore]
258         public Font? FontUIGlobal = null;
259
260         /// <summary>
261         /// [隠し設定] UI フォントを指定します
262         /// </summary>
263         /// <remarks>
264         /// フォントによっては一部レイアウトが崩れるためこっそり追加
265         /// </remarks>
266         public string? FontUIGlobalStr
267         {
268             get => this.FontUIGlobal != null ? this.FontToString(this.FontUIGlobal) : null;
269             set => this.FontUIGlobal = value != null ? this.StringToFont(value) : null;
270         }
271
272         [XmlIgnore]
273         public string ProxyPassword = "";
274         public string EncryptProxyPassword
275         {
276             get
277             {
278                 var pwd = ProxyPassword;
279                 if (string.IsNullOrEmpty(pwd)) pwd = "";
280                 if (pwd.Length > 0)
281                 {
282                     try
283                     {
284                         return MyCommon.EncryptString(pwd);
285                     }
286                     catch (Exception)
287                     {
288                         return "";
289                     }
290                 }
291                 else
292                 {
293                     return "";
294                 }
295             }
296             set
297             {
298                 var pwd = value;
299                 if (string.IsNullOrEmpty(pwd)) pwd = "";
300                 if (pwd.Length > 0)
301                 {
302                     try
303                     {
304                         pwd = MyCommon.DecryptString(pwd);
305                     }
306                     catch (Exception)
307                     {
308                         pwd = "";
309                     }
310                 }
311                 ProxyPassword = pwd;
312             }
313         }
314
315         /// <summary>
316         /// 絵文字の表示に Twemoji (https://github.com/twitter/twemoji) を使用するか
317         /// </summary>
318         public bool UseTwemoji = true;
319
320         [XmlIgnore]
321         private readonly FontConverter fontConverter = new FontConverter();
322
323         protected string FontToString(Font font)
324             => this.fontConverter.ConvertToString(font);
325
326         protected Font StringToFont(string str)
327             => (Font)this.fontConverter.ConvertFromString(str);
328
329         [XmlIgnore]
330         private readonly ColorConverter colorConverter = new ColorConverter();
331
332         protected string ColorToString(Color color)
333             => this.colorConverter.ConvertToString(color);
334
335         protected Color StringToColor(string str)
336             => (Color)this.colorConverter.ConvertFromString(str);
337
338         /// <summary>
339         /// 指定されたスケールと SettingLocal.ScaleDimension のスケールとの拡大比を返します
340         /// </summary>
341         public SizeF GetConfigScaleFactor(SizeF currentSizeDimension)
342             => new SizeF(
343                 currentSizeDimension.Width / this.ScaleDimension.Width,
344                 currentSizeDimension.Height / this.ScaleDimension.Height);
345
346         public void Dispose()
347         {
348             this.Dispose(true);
349             GC.SuppressFinalize(this);
350         }
351
352         protected virtual void Dispose(bool disposing)
353         {
354             if (disposing)
355             {
356                 this.FontUnread?.Dispose();
357                 this.FontRead?.Dispose();
358                 this.FontDetail?.Dispose();
359                 this.FontInputFont?.Dispose();
360             }
361         }
362     }
363 }