OSDN Git Service

設定ファイルの読み込み・保存に関するコードをSettingManagerクラスに移動
[opentween/open-tween.git] / OpenTween / Setting / SettingCommon.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.Xml.Serialization;
29 using System.Collections.Generic;
30 using System.Windows.Forms;
31 using OpenTween.Thumbnail;
32 using OpenTween.Setting;
33
34 namespace OpenTween
35 {
36     public class SettingCommon : SettingBase<SettingCommon>
37     {
38         public static SettingCommon Instance => SettingManager.Common;
39
40         #region "Settingクラス基本"
41         public static SettingCommon Load()
42         {
43             return LoadSettings();
44         }
45
46         public void Save()
47         {
48             SaveSettings(this);
49         }
50         #endregion
51
52         public List<UserAccount> UserAccounts;
53         public string UserName = "";
54
55         [XmlIgnore]
56         public string Password = "";
57         public string EncryptPassword
58         {
59             get { return Encrypt(Password); }
60             set { Password = Decrypt(value); }
61         }
62
63         public string Token = "";
64         [XmlIgnore]
65         public string TokenSecret = "";
66         public string EncryptTokenSecret
67         {
68             get { return Encrypt(TokenSecret); }
69             set { TokenSecret = Decrypt(value); }
70         }
71
72         private string Encrypt(string password)
73         {
74             if (String.IsNullOrEmpty(password)) password = "";
75             if (password.Length > 0)
76             {
77                 try
78                 {
79                     return MyCommon.EncryptString(password);
80                 }
81                 catch (Exception)
82                 {
83                     return "";
84                 }
85             }
86             else
87             {
88                 return "";
89             }
90         }
91         private string Decrypt(string password)
92         {
93             if (String.IsNullOrEmpty(password)) password = "";
94             if (password.Length > 0)
95             {
96                 try
97                 {
98                     password = MyCommon.DecryptString(password);
99                 }
100                 catch (Exception)
101                 {
102                     password = "";
103                 }
104             }
105             return password;
106         }
107
108         public long UserId = 0;
109         public List<string> TabList;
110         public int TimelinePeriod = 90;
111         public int ReplyPeriod = 180;
112         public int DMPeriod = 600;
113         public int PubSearchPeriod = 180;
114         public int ListsPeriod = 180;
115
116         /// <summary>
117         /// 起動時読み込み分を既読にするか。trueなら既読として処理
118         /// </summary>
119         public bool Read = true;
120
121         public bool ListLock = false;
122         public MyCommon.IconSizes IconSize = MyCommon.IconSizes.Icon16;
123         public bool NewAllPop = true;
124         public bool EventNotifyEnabled = true;
125         public MyCommon.EVENTTYPE EventNotifyFlag = MyCommon.EVENTTYPE.All;
126         public MyCommon.EVENTTYPE IsMyEventNotifyFlag = MyCommon.EVENTTYPE.All;
127         public bool ForceEventNotify = false;
128         public bool FavEventUnread = true;
129         public string TranslateLanguage = Properties.Resources.TranslateDefaultLanguage;
130         public string EventSoundFile = "";
131
132         /// <summary>
133         /// サウンド再生(タブ別設定より優先)
134         /// </summary>
135         public bool PlaySound = false;
136
137         /// <summary>
138         /// 未読管理。trueなら未読管理する
139         /// </summary>
140         public bool UnreadManage = true;
141
142         /// <summary>
143         /// 片思い表示。trueなら片思い表示する
144         /// </summary>
145         public bool OneWayLove = true;
146
147         public MyCommon.NameBalloonEnum NameBalloon = MyCommon.NameBalloonEnum.NickName;
148         public bool PostCtrlEnter = false;
149         public bool PostShiftEnter = false;
150         public int CountApi = 60;
151         public int CountApiReply = 40;
152         public bool PostAndGet = true;
153         public bool DispUsername = false;
154         public bool MinimizeToTray = false;
155         public bool CloseToExit = false;
156         public MyCommon.DispTitleEnum DispLatestPost = MyCommon.DispTitleEnum.Post;
157         public bool SortOrderLock = false;
158
159         /// <summary>
160         /// タブを下部に表示するかどうか
161         /// </summary>
162         public bool ViewTabBottom = true;
163
164         public bool TinyUrlResolve = true;
165         public bool StartupVersion = true;
166         public bool StartupFollowers = true;
167         public bool RestrictFavCheck = false;
168         public bool AlwaysTop = false;
169         public string CultureCode = "";
170         public bool UrlConvertAuto = false;
171         public int SortColumn = 3;
172         public int SortOrder = 1;
173         public bool IsMonospace = false;
174         public bool ReadOldPosts = false;
175         public string Language = "OS";
176         public bool Nicoms = false;
177         public List<string> HashTags = new List<string>();
178         public string HashSelected = "";
179         public bool HashIsPermanent = false;
180         public bool HashIsHead = false;
181         public bool HashIsNotAddToAtReply = true;
182         public bool PreviewEnable = true;
183         public bool StatusAreaAtBottom = true;
184
185         public MyCommon.UrlConverter AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
186         public bool UseUnreadStyle = true;
187         public string DateTimeFormat = "yyyy/MM/dd H:mm:ss";
188         public int DefaultTimeOut = 20;
189
190         /// <summary>画像アップロードのタイムアウト設定 (秒)</summary>
191         public int UploadImageTimeout { get; set; } = 60;
192
193         public bool RetweetNoConfirm = false;
194         public bool LimitBalloon = false;
195         public bool TabIconDisp = true;
196         public MyCommon.REPLY_ICONSTATE ReplyIconState = MyCommon.REPLY_ICONSTATE.StaticIcon;
197         public bool WideSpaceConvert = true;
198         public bool ReadOwnPost = false;
199         public bool GetFav = true;
200         public string BilyUser = "";
201         public string BitlyPwd = "";
202         public bool ShowGrid = false;
203         public bool UseAtIdSupplement = true;
204         public bool UseHashSupplement = true;
205
206         [XmlElement(ElementName = "TwitterUrl")]
207         public string TwitterApiHost = "api.twitter.com";
208
209         public bool HotkeyEnabled = false;
210         public Keys HotkeyModifier = Keys.None;
211         public Keys HotkeyKey = Keys.None;
212         public int HotkeyValue = 0;
213         public bool BlinkNewMentions = false;
214         public bool FocusLockToStatusText = false;
215         public bool UseAdditionalCount = false;
216         public int MoreCountApi = 200;
217         public int FirstCountApi = 100;
218         public int SearchCountApi = 100;
219         public int FavoritesCountApi = 40;
220         public string TrackWord = "";
221         public bool AllAtReply = false;
222         public bool UserstreamStartup = true;
223         public int UserstreamPeriod = 0;
224         public int UserTimelineCountApi = 20;
225         public int UserTimelinePeriod = 600;
226         public bool OpenUserTimeline = true;
227         public int ListCountApi = 100;
228         public int UseImageService = 0;
229         public string UseImageServiceName = "";
230         public int ListDoubleClickAction = 0;
231         public string UserAppointUrl = "";
232         public bool HideDuplicatedRetweets = false;
233         public bool EnableImgAzyobuziNet = true;
234         public bool ImgAzyobuziNetDisabledInDM = true;
235         public int MapThumbnailHeight = 200;
236         public int MapThumbnailWidth = 200;
237         public int MapThumbnailZoom = 15;
238         public MapProvider MapThumbnailProvider = MapProvider.OpenStreetMap;
239         public bool IsListsIncludeRts = false;
240         public bool TabMouseLock = false;
241         public bool IsRemoveSameEvent = false;
242         public bool IsUseNotifyGrowl = false;
243         public bool ForceIPv4 = false;
244         public bool ErrorReportAnonymous = true;
245
246         /// <summary>pic.twitter.com への画像アップロード時に JPEG への変換を回避する</summary>
247         public bool AlphaPNGWorkaround { get; set; } = false;
248     }
249
250     public class UserAccount
251     {
252         public string Username = "";
253         public long UserId = 0;
254         public string Token = "";
255         [XmlIgnore]
256         public string TokenSecret = "";
257         public string EncryptTokenSecret
258         {
259             get { return Encrypt(TokenSecret); }
260             set { TokenSecret = Decrypt(value); }
261         }
262         private string Encrypt(string password)
263         {
264             if (String.IsNullOrEmpty(password)) password = "";
265             if (password.Length > 0)
266             {
267                 try
268                 {
269                     return MyCommon.EncryptString(password);
270                 }
271                 catch (Exception)
272                 {
273                     return "";
274                 }
275             }
276             else
277             {
278                 return "";
279             }
280         }
281         private string Decrypt(string password)
282         {
283             if (String.IsNullOrEmpty(password)) password = "";
284             if (password.Length > 0)
285             {
286                 try
287                 {
288                     password = MyCommon.DecryptString(password);
289                 }
290                 catch (Exception)
291                 {
292                     password = "";
293                 }
294             }
295             return password;
296         }
297         public override string ToString()
298         {
299             return this.Username;
300         }
301     }
302 }