OSDN Git Service

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