OSDN Git Service

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