OSDN Git Service

usingの順序を揃える (SA1208, SA1210)
[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.Data;
33 using System.Drawing;
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.CheckPostAndGet.Checked = settingCommon.PostAndGet;
50             this.TimelinePeriod.Text = settingCommon.TimelinePeriod.ToString();
51             this.ReplyPeriod.Text = settingCommon.ReplyPeriod.ToString();
52             this.DMPeriod.Text = settingCommon.DMPeriod.ToString();
53             this.PubSearchPeriod.Text = settingCommon.PubSearchPeriod.ToString();
54             this.ListsPeriod.Text = settingCommon.ListsPeriod.ToString();
55             this.UserTimelinePeriod.Text = settingCommon.UserTimelinePeriod.ToString();
56         }
57
58         public void SaveConfig(SettingCommon settingCommon)
59         {
60             settingCommon.PostAndGet = this.CheckPostAndGet.Checked;
61
62             var arg = new IntervalChangedEventArgs();
63             var isIntervalChanged = false;
64
65             var timelinePeriod = int.Parse(this.TimelinePeriod.Text);
66             if (settingCommon.TimelinePeriod != timelinePeriod)
67             {
68                 settingCommon.TimelinePeriod = timelinePeriod;
69                 arg.Timeline = true;
70                 isIntervalChanged = true;
71             }
72
73             var dmPeriod = int.Parse(this.DMPeriod.Text);
74             if (settingCommon.DMPeriod != dmPeriod)
75             {
76                 settingCommon.DMPeriod = dmPeriod;
77                 arg.DirectMessage = true;
78                 isIntervalChanged = true;
79             }
80
81             var pubSearchPeriod = int.Parse(this.PubSearchPeriod.Text);
82             if (settingCommon.PubSearchPeriod != pubSearchPeriod)
83             {
84                 settingCommon.PubSearchPeriod = pubSearchPeriod;
85                 arg.PublicSearch = true;
86                 isIntervalChanged = true;
87             }
88
89             var listsPeriod = int.Parse(this.ListsPeriod.Text);
90             if (settingCommon.ListsPeriod != listsPeriod)
91             {
92                 settingCommon.ListsPeriod = listsPeriod;
93                 arg.Lists = true;
94                 isIntervalChanged = true;
95             }
96
97             var replyPeriod = int.Parse(this.ReplyPeriod.Text);
98             if (settingCommon.ReplyPeriod != replyPeriod)
99             {
100                 settingCommon.ReplyPeriod = replyPeriod;
101                 arg.Reply = true;
102                 isIntervalChanged = true;
103             }
104
105             var userTimelinePeriod = int.Parse(this.UserTimelinePeriod.Text);
106             if (settingCommon.UserTimelinePeriod != userTimelinePeriod)
107             {
108                 settingCommon.UserTimelinePeriod = userTimelinePeriod;
109                 arg.UserTimeline = true;
110                 isIntervalChanged = true;
111             }
112
113             if (isIntervalChanged)
114                 this.IntervalChanged?.Invoke(this, arg);
115         }
116
117         private void TimelinePeriod_Validating(object sender, CancelEventArgs e)
118         {
119             int prd;
120             try
121             {
122                 prd = int.Parse(this.TimelinePeriod.Text);
123             }
124             catch (Exception)
125             {
126                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
127                 e.Cancel = true;
128                 return;
129             }
130
131             if (prd != 0 && (prd < 15 || prd > 6000))
132             {
133                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
134                 e.Cancel = true;
135                 return;
136             }
137         }
138
139         private void ReplyPeriod_Validating(object sender, CancelEventArgs e)
140         {
141             int prd;
142             try
143             {
144                 prd = int.Parse(this.ReplyPeriod.Text);
145             }
146             catch (Exception)
147             {
148                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
149                 e.Cancel = true;
150                 return;
151             }
152
153             if (prd != 0 && (prd < 15 || prd > 6000))
154             {
155                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
156                 e.Cancel = true;
157                 return;
158             }
159         }
160
161         private void DMPeriod_Validating(object sender, CancelEventArgs e)
162         {
163             int prd;
164             try
165             {
166                 prd = int.Parse(this.DMPeriod.Text);
167             }
168             catch (Exception)
169             {
170                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
171                 e.Cancel = true;
172                 return;
173             }
174
175             if (prd != 0 && (prd < 15 || prd > 6000))
176             {
177                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
178                 e.Cancel = true;
179                 return;
180             }
181         }
182
183         private void PubSearchPeriod_Validating(object sender, CancelEventArgs e)
184         {
185             int prd;
186             try
187             {
188                 prd = int.Parse(this.PubSearchPeriod.Text);
189             }
190             catch (Exception)
191             {
192                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText1);
193                 e.Cancel = true;
194                 return;
195             }
196
197             if (prd != 0 && (prd < 30 || prd > 6000))
198             {
199                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText2);
200                 e.Cancel = true;
201             }
202         }
203
204         private void ListsPeriod_Validating(object sender, CancelEventArgs e)
205         {
206             int prd;
207             try
208             {
209                 prd = int.Parse(this.ListsPeriod.Text);
210             }
211             catch (Exception)
212             {
213                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
214                 e.Cancel = true;
215                 return;
216             }
217
218             if (prd != 0 && (prd < 15 || prd > 6000))
219             {
220                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
221                 e.Cancel = true;
222                 return;
223             }
224         }
225
226         private void UserTimeline_Validating(object sender, CancelEventArgs e)
227         {
228             int prd;
229             try
230             {
231                 prd = int.Parse(this.UserTimelinePeriod.Text);
232             }
233             catch (Exception)
234             {
235                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
236                 e.Cancel = true;
237                 return;
238             }
239
240             if (prd != 0 && (prd < 15 || prd > 6000))
241             {
242                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
243                 e.Cancel = true;
244                 return;
245             }
246         }
247     }
248 }