OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Setting / Panel / GetPeriodPanel.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) 2014      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 #nullable enable
28
29 using System;
30 using System.Collections.Generic;
31 using System.ComponentModel;
32 using System.Drawing;
33 using System.Data;
34 using System.Linq;
35 using System.Text;
36 using System.Windows.Forms;
37
38 namespace OpenTween.Setting.Panel
39 {
40     public partial class GetPeriodPanel : SettingPanelBase
41     {
42         public event EventHandler<IntervalChangedEventArgs> IntervalChanged;
43
44         public GetPeriodPanel()
45             => this.InitializeComponent();
46
47         public void LoadConfig(SettingCommon settingCommon)
48         {
49             this.StartupUserstreamCheck.Checked = settingCommon.UserstreamStartup;
50             this.CheckPostAndGet.Checked = settingCommon.PostAndGet;
51             this.UserstreamPeriod.Text = settingCommon.UserstreamPeriod.ToString();
52             this.TimelinePeriod.Text = settingCommon.TimelinePeriod.ToString();
53             this.ReplyPeriod.Text = settingCommon.ReplyPeriod.ToString();
54             this.DMPeriod.Text = settingCommon.DMPeriod.ToString();
55             this.PubSearchPeriod.Text = settingCommon.PubSearchPeriod.ToString();
56             this.ListsPeriod.Text = settingCommon.ListsPeriod.ToString();
57             this.UserTimelinePeriod.Text = settingCommon.UserTimelinePeriod.ToString();
58         }
59
60         public void SaveConfig(SettingCommon settingCommon)
61         {
62             settingCommon.UserstreamStartup = this.StartupUserstreamCheck.Checked;
63             settingCommon.PostAndGet = this.CheckPostAndGet.Checked;
64
65             var arg = new IntervalChangedEventArgs();
66             var isIntervalChanged = false;
67
68             var userstreamPeriod = int.Parse(this.UserstreamPeriod.Text);
69             if (settingCommon.UserstreamPeriod != userstreamPeriod)
70             {
71                 settingCommon.UserstreamPeriod = userstreamPeriod;
72                 arg.UserStream = true;
73                 isIntervalChanged = true;
74             }
75
76             var timelinePeriod = int.Parse(this.TimelinePeriod.Text);
77             if (settingCommon.TimelinePeriod != timelinePeriod)
78             {
79                 settingCommon.TimelinePeriod = timelinePeriod;
80                 arg.Timeline = true;
81                 isIntervalChanged = true;
82             }
83
84             var dmPeriod = int.Parse(this.DMPeriod.Text);
85             if (settingCommon.DMPeriod != dmPeriod)
86             {
87                 settingCommon.DMPeriod = dmPeriod;
88                 arg.DirectMessage = true;
89                 isIntervalChanged = true;
90             }
91
92             var pubSearchPeriod = int.Parse(this.PubSearchPeriod.Text);
93             if (settingCommon.PubSearchPeriod != pubSearchPeriod)
94             {
95                 settingCommon.PubSearchPeriod = pubSearchPeriod;
96                 arg.PublicSearch = true;
97                 isIntervalChanged = true;
98             }
99
100             var listsPeriod = int.Parse(this.ListsPeriod.Text);
101             if (settingCommon.ListsPeriod != listsPeriod)
102             {
103                 settingCommon.ListsPeriod = listsPeriod;
104                 arg.Lists = true;
105                 isIntervalChanged = true;
106             }
107
108             var replyPeriod = int.Parse(this.ReplyPeriod.Text);
109             if (settingCommon.ReplyPeriod != replyPeriod)
110             {
111                 settingCommon.ReplyPeriod = replyPeriod;
112                 arg.Reply = true;
113                 isIntervalChanged = true;
114             }
115
116             var userTimelinePeriod = int.Parse(this.UserTimelinePeriod.Text);
117             if (settingCommon.UserTimelinePeriod != userTimelinePeriod)
118             {
119                 settingCommon.UserTimelinePeriod = userTimelinePeriod;
120                 arg.UserTimeline = true;
121                 isIntervalChanged = true;
122             }
123
124             if (isIntervalChanged)
125                 this.IntervalChanged?.Invoke(this, arg);
126         }
127
128         private void UserstreamPeriod_Validating(object sender, CancelEventArgs e)
129         {
130             int prd;
131             try
132             {
133                 prd = int.Parse(UserstreamPeriod.Text);
134             }
135             catch (Exception)
136             {
137                 MessageBox.Show(Properties.Resources.UserstreamPeriod_ValidatingText1);
138                 e.Cancel = true;
139                 return;
140             }
141
142             if (prd < 0 || prd > 60)
143             {
144                 MessageBox.Show(Properties.Resources.UserstreamPeriod_ValidatingText1);
145                 e.Cancel = true;
146                 return;
147             }
148         }
149
150         private void TimelinePeriod_Validating(object sender, CancelEventArgs e)
151         {
152             int prd;
153             try
154             {
155                 prd = int.Parse(TimelinePeriod.Text);
156             }
157             catch (Exception)
158             {
159                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
160                 e.Cancel = true;
161                 return;
162             }
163
164             if (prd != 0 && (prd < 15 || prd > 6000))
165             {
166                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
167                 e.Cancel = true;
168                 return;
169             }
170         }
171
172         private void ReplyPeriod_Validating(object sender, CancelEventArgs e)
173         {
174             int prd;
175             try
176             {
177                 prd = int.Parse(ReplyPeriod.Text);
178             }
179             catch (Exception)
180             {
181                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
182                 e.Cancel = true;
183                 return;
184             }
185
186             if (prd != 0 && (prd < 15 || prd > 6000))
187             {
188                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
189                 e.Cancel = true;
190                 return;
191             }
192         }
193
194         private void DMPeriod_Validating(object sender, CancelEventArgs e)
195         {
196             int prd;
197             try
198             {
199                 prd = int.Parse(DMPeriod.Text);
200             }
201             catch (Exception)
202             {
203                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
204                 e.Cancel = true;
205                 return;
206             }
207
208             if (prd != 0 && (prd < 15 || prd > 6000))
209             {
210                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
211                 e.Cancel = true;
212                 return;
213             }
214         }
215
216         private void PubSearchPeriod_Validating(object sender, CancelEventArgs e)
217         {
218             int prd;
219             try
220             {
221                 prd = int.Parse(PubSearchPeriod.Text);
222             }
223             catch (Exception)
224             {
225                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText1);
226                 e.Cancel = true;
227                 return;
228             }
229
230             if (prd != 0 && (prd < 30 || prd > 6000))
231             {
232                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText2);
233                 e.Cancel = true;
234             }
235         }
236
237         private void ListsPeriod_Validating(object sender, CancelEventArgs e)
238         {
239             int prd;
240             try
241             {
242                 prd = int.Parse(ListsPeriod.Text);
243             }
244             catch (Exception)
245             {
246                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
247                 e.Cancel = true;
248                 return;
249             }
250
251             if (prd != 0 && (prd < 15 || prd > 6000))
252             {
253                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
254                 e.Cancel = true;
255                 return;
256             }
257         }
258
259         private void UserTimeline_Validating(object sender, CancelEventArgs e)
260         {
261             int prd;
262             try
263             {
264                 prd = int.Parse(UserTimelinePeriod.Text);
265             }
266             catch (Exception)
267             {
268                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
269                 e.Cancel = true;
270                 return;
271             }
272
273             if (prd != 0 && (prd < 15 || prd > 6000))
274             {
275                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
276                 e.Cancel = true;
277                 return;
278             }
279         }
280     }
281 }