OSDN Git Service

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