OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Setting / Panel / GetCountPanel.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 GetCountPanel : SettingPanelBase
41     {
42         public GetCountPanel()
43             => this.InitializeComponent();
44
45         public void LoadConfig(SettingCommon settingCommon)
46         {
47             this.TextCountApi.Text = settingCommon.CountApi.ToString();
48             this.TextCountApiReply.Text = settingCommon.CountApiReply.ToString();
49             this.GetMoreTextCountApi.Text = settingCommon.MoreCountApi.ToString();
50             this.FirstTextCountApi.Text = settingCommon.FirstCountApi.ToString();
51             this.SearchTextCountApi.Text = settingCommon.SearchCountApi.ToString();
52             this.FavoritesTextCountApi.Text = settingCommon.FavoritesCountApi.ToString();
53             this.UserTimelineTextCountApi.Text = settingCommon.UserTimelineCountApi.ToString();
54             this.ListTextCountApi.Text = settingCommon.ListCountApi.ToString();
55             this.UseChangeGetCount.Checked = settingCommon.UseAdditionalCount;
56
57             this.Label28.Enabled = this.UseChangeGetCount.Checked;
58             this.Label30.Enabled = this.UseChangeGetCount.Checked;
59             this.Label53.Enabled = this.UseChangeGetCount.Checked;
60             this.Label66.Enabled = this.UseChangeGetCount.Checked;
61             this.Label17.Enabled = this.UseChangeGetCount.Checked;
62             this.Label25.Enabled = this.UseChangeGetCount.Checked;
63             this.GetMoreTextCountApi.Enabled = this.UseChangeGetCount.Checked;
64             this.FirstTextCountApi.Enabled = this.UseChangeGetCount.Checked;
65             this.SearchTextCountApi.Enabled = this.UseChangeGetCount.Checked;
66             this.FavoritesTextCountApi.Enabled = this.UseChangeGetCount.Checked;
67             this.UserTimelineTextCountApi.Enabled = this.UseChangeGetCount.Checked;
68             this.ListTextCountApi.Enabled = this.UseChangeGetCount.Checked;
69         }
70
71         public void SaveConfig(SettingCommon settingCommon)
72         {
73             settingCommon.CountApi = int.Parse(this.TextCountApi.Text);
74             settingCommon.CountApiReply = int.Parse(this.TextCountApiReply.Text);
75             settingCommon.UseAdditionalCount = this.UseChangeGetCount.Checked;
76             settingCommon.MoreCountApi = int.Parse(this.GetMoreTextCountApi.Text);
77             settingCommon.FirstCountApi = int.Parse(this.FirstTextCountApi.Text);
78             settingCommon.SearchCountApi = int.Parse(this.SearchTextCountApi.Text);
79             settingCommon.FavoritesCountApi = int.Parse(this.FavoritesTextCountApi.Text);
80             settingCommon.UserTimelineCountApi = int.Parse(this.UserTimelineTextCountApi.Text);
81             settingCommon.ListCountApi = int.Parse(this.ListTextCountApi.Text);
82         }
83
84         private void TextCountApi_Validating(object sender, CancelEventArgs e)
85         {
86             int cnt;
87             try
88             {
89                 cnt = int.Parse(TextCountApi.Text);
90             }
91             catch (Exception)
92             {
93                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
94                 e.Cancel = true;
95                 return;
96             }
97
98             if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, cnt))
99             {
100                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
101                 e.Cancel = true;
102                 return;
103             }
104         }
105
106         private void TextCountApiReply_Validating(object sender, CancelEventArgs e)
107         {
108             int cnt;
109             try
110             {
111                 cnt = int.Parse(TextCountApiReply.Text);
112             }
113             catch (Exception)
114             {
115                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
116                 e.Cancel = true;
117                 return;
118             }
119
120             if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, cnt))
121             {
122                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
123                 e.Cancel = true;
124                 return;
125             }
126         }
127
128         private void GetMoreTextCountApi_Validating(object sender, CancelEventArgs e)
129         {
130             int cnt;
131             try
132             {
133                 cnt = int.Parse(GetMoreTextCountApi.Text);
134             }
135             catch (Exception)
136             {
137                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
138                 e.Cancel = true;
139                 return;
140             }
141
142             if (cnt != 0 && !Twitter.VerifyMoreApiResultCount(cnt))
143             {
144                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
145                 e.Cancel = true;
146                 return;
147             }
148         }
149
150         private void UseChangeGetCount_CheckedChanged(object sender, EventArgs e)
151         {
152             GetMoreTextCountApi.Enabled = UseChangeGetCount.Checked;
153             FirstTextCountApi.Enabled = UseChangeGetCount.Checked;
154             Label28.Enabled = UseChangeGetCount.Checked;
155             Label30.Enabled = UseChangeGetCount.Checked;
156             Label53.Enabled = UseChangeGetCount.Checked;
157             Label66.Enabled = UseChangeGetCount.Checked;
158             Label17.Enabled = UseChangeGetCount.Checked;
159             Label25.Enabled = UseChangeGetCount.Checked;
160             SearchTextCountApi.Enabled = UseChangeGetCount.Checked;
161             FavoritesTextCountApi.Enabled = UseChangeGetCount.Checked;
162             UserTimelineTextCountApi.Enabled = UseChangeGetCount.Checked;
163             ListTextCountApi.Enabled = UseChangeGetCount.Checked;
164         }
165
166         private void FirstTextCountApi_Validating(object sender, CancelEventArgs e)
167         {
168             int cnt;
169             try
170             {
171                 cnt = int.Parse(FirstTextCountApi.Text);
172             }
173             catch (Exception)
174             {
175                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
176                 e.Cancel = true;
177                 return;
178             }
179
180             if (cnt != 0 && !Twitter.VerifyFirstApiResultCount(cnt))
181             {
182                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
183                 e.Cancel = true;
184                 return;
185             }
186         }
187
188         private void SearchTextCountApi_Validating(object sender, CancelEventArgs e)
189         {
190             int cnt;
191             try
192             {
193                 cnt = int.Parse(SearchTextCountApi.Text);
194             }
195             catch (Exception)
196             {
197                 MessageBox.Show(Properties.Resources.TextSearchCountApi_Validating1);
198                 e.Cancel = true;
199                 return;
200             }
201
202             if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, cnt))
203             {
204                 MessageBox.Show(Properties.Resources.TextSearchCountApi_Validating1);
205                 e.Cancel = true;
206                 return;
207             }
208         }
209
210         private void FavoritesTextCountApi_Validating(object sender, CancelEventArgs e)
211         {
212             int cnt;
213             try
214             {
215                 cnt = int.Parse(FavoritesTextCountApi.Text);
216             }
217             catch (Exception)
218             {
219                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
220                 e.Cancel = true;
221                 return;
222             }
223
224             if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, cnt))
225             {
226                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
227                 e.Cancel = true;
228                 return;
229             }
230         }
231
232         private void UserTimelineTextCountApi_Validating(object sender, CancelEventArgs e)
233         {
234             int cnt;
235             try
236             {
237                 cnt = int.Parse(UserTimelineTextCountApi.Text);
238             }
239             catch (Exception)
240             {
241                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
242                 e.Cancel = true;
243                 return;
244             }
245
246             if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, cnt))
247             {
248                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
249                 e.Cancel = true;
250                 return;
251             }
252         }
253
254         private void ListTextCountApi_Validating(object sender, CancelEventArgs e)
255         {
256             int cnt;
257             try
258             {
259                 cnt = int.Parse(ListTextCountApi.Text);
260             }
261             catch (Exception)
262             {
263                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
264                 e.Cancel = true;
265                 return;
266             }
267
268             if (cnt != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.List, cnt))
269             {
270                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
271                 e.Cancel = true;
272                 return;
273             }
274         }
275     }
276 }