OSDN Git Service

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