OSDN Git Service

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