OSDN Git Service

API使用回数計算を削除
[opentween/open-tween.git] / OpenTween / AppendSettingDialog.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.Collections.Generic;
29 using System.ComponentModel;
30 using System.Data;
31 using System.Drawing;
32 using System.Linq;
33 using System.Text;
34 using System.Windows.Forms;
35 using System.Threading;
36 using System.IO;
37 using System.Resources;
38 using OpenTween.Thumbnail;
39 using System.Threading.Tasks;
40
41 namespace OpenTween
42 {
43     public partial class AppendSettingDialog : Form
44     {
45         private static AppendSettingDialog _instance = new AppendSettingDialog();
46         private Twitter tw;
47         private HttpConnection.ProxyType _MyProxyType;
48
49         private bool _ValidationError = false;
50         private MyCommon.EVENTTYPE _MyEventNotifyFlag;
51         private MyCommon.EVENTTYPE _isMyEventNotifyFlag;
52         private string _MyTranslateLanguage;
53
54         public bool HideDuplicatedRetweets;
55
56         public bool IsPreviewFoursquare;
57         public MapProvider MapThumbnailProvider;
58         public int MapThumbnailHeight;
59         public int MapThumbnailWidth;
60         public int MapThumbnailZoom;
61         public bool IsListStatusesIncludeRts;
62         public List<UserAccount> UserAccounts;
63         private long? InitialUserId;
64         public bool TabMouseLock;
65         public bool IsRemoveSameEvent;
66         public bool IsNotifyUseGrowl;
67
68         public TwitterDataModel.Configuration TwitterConfiguration = new TwitterDataModel.Configuration();
69
70         private string _pin;
71
72         public class IntervalChangedEventArgs : EventArgs
73         {
74             public bool UserStream;
75             public bool Timeline;
76             public bool Reply;
77             public bool DirectMessage;
78             public bool PublicSearch;
79             public bool Lists;
80             public bool UserTimeline;
81         }
82
83         public delegate void IntervalChangedEventHandler(object sender, IntervalChangedEventArgs e);
84         public event IntervalChangedEventHandler IntervalChanged;
85
86         private void TreeViewSetting_BeforeSelect(object sender, TreeViewCancelEventArgs e)
87         {
88             if (this.TreeViewSetting.SelectedNode == null) return;
89             Panel pnl = (Panel)this.TreeViewSetting.SelectedNode.Tag;
90             if (pnl == null) return;
91             pnl.Enabled = false;
92             pnl.Visible = false;
93         }
94
95         private void TreeViewSetting_AfterSelect(object sender, TreeViewEventArgs e)
96         {
97             if (e.Node == null) return;
98             Panel pnl = (Panel)e.Node.Tag;
99             if (pnl == null) return;
100             pnl.Enabled = true;
101             pnl.Visible = true;
102
103             if (pnl.Name == "PreviewPanel")
104             {
105                 if (GrowlHelper.IsDllExists)
106                 {
107                     IsNotifyUseGrowlCheckBox.Enabled = true;
108                 }
109                 else
110                 {
111                     IsNotifyUseGrowlCheckBox.Enabled = false;
112                 }
113             }
114         }
115
116         private void Save_Click(object sender, EventArgs e)
117         {
118             if (MyCommon.IsNetworkAvailable() &&
119                 (ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
120             {
121                 // bit.ly 短縮機能実装のプライバシー問題の暫定対応
122                 // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
123                 // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
124                 if (string.IsNullOrEmpty(TextBitlyId.Text) || string.IsNullOrEmpty(TextBitlyPw.Text))
125                 {
126                     MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
127                     _ValidationError = true;
128                     TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
129                     TreeViewSetting.Select();
130                     TextBitlyId.Focus();
131                     return;
132                 }
133
134                 if (!BitlyValidation(TextBitlyId.Text, TextBitlyPw.Text))
135                 {
136                     MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
137                     _ValidationError = true;
138                     TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
139                     TreeViewSetting.Select();
140                     TextBitlyId.Focus();
141                     return;
142                 }
143                 else
144                 {
145                     _ValidationError = false;
146                 }
147             }
148             else
149             {
150                 _ValidationError = false;
151             }
152
153             this.UserAccounts.Clear();
154             foreach (object u in this.AuthUserCombo.Items)
155             {
156                 this.UserAccounts.Add((UserAccount)u);
157             }
158             if (this.AuthUserCombo.SelectedIndex > -1)
159             {
160                 foreach (UserAccount u in this.UserAccounts)
161                 {
162                     if (u.Username.ToLower() == ((UserAccount)this.AuthUserCombo.SelectedItem).Username.ToLower())
163                     {
164                         tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
165                         if (u.UserId == 0)
166                         {
167                             tw.VerifyCredentials();
168                             u.UserId = tw.UserId;
169                         }
170                         break;
171                     }
172                 }
173             }
174             else
175             {
176                 tw.ClearAuthInfo();
177                 tw.Initialize("", "", "", 0);
178             }
179
180 #if UA
181             //フォロー
182             if (this.FollowCheckBox.Checked)
183             {
184                 //現在の設定内容で通信
185                 HttpConnection.ProxyType ptype;
186                 if (RadioProxyNone.Checked)
187                 {
188                     ptype = HttpConnection.ProxyType.None;
189                 }
190                 else if (RadioProxyIE.Checked)
191                 {
192                     ptype = HttpConnection.ProxyType.IE;
193                 }
194                 else
195                 {
196                     ptype = HttpConnection.ProxyType.Specified;
197                 }
198                 string padr = TextProxyAddress.Text.Trim();
199                 int pport = int.Parse(TextProxyPort.Text.Trim());
200                 string pusr = TextProxyUser.Text.Trim();
201                 string ppw = TextProxyPassword.Text.Trim();
202                 HttpConnection.InitializeConnection(20, ptype, padr, pport, pusr, ppw);
203
204                 string ret = tw.PostFollowCommand(ApplicationSettings.FeedbackTwitterName);
205             }
206 #endif
207             IntervalChangedEventArgs arg = new IntervalChangedEventArgs();
208             bool isIntervalChanged = false;
209
210             try
211             {
212                 UserstreamStartup = this.StartupUserstreamCheck.Checked;
213
214                 if (UserstreamPeriodInt != int.Parse(UserstreamPeriod.Text))
215                 {
216                     UserstreamPeriodInt = int.Parse(UserstreamPeriod.Text);
217                     arg.UserStream = true;
218                     isIntervalChanged = true;
219                 }
220                 if (TimelinePeriodInt != int.Parse(TimelinePeriod.Text))
221                 {
222                     TimelinePeriodInt = int.Parse(TimelinePeriod.Text);
223                     arg.Timeline = true;
224                     isIntervalChanged = true;
225                 }
226                 if (DMPeriodInt != int.Parse(DMPeriod.Text))
227                 {
228                     DMPeriodInt = int.Parse(DMPeriod.Text);
229                     arg.DirectMessage = true;
230                     isIntervalChanged = true;
231                 }
232                 if (PubSearchPeriodInt != int.Parse(PubSearchPeriod.Text))
233                 {
234                     PubSearchPeriodInt = int.Parse(PubSearchPeriod.Text);
235                     arg.PublicSearch = true;
236                     isIntervalChanged = true;
237                 }
238
239                 if (ListsPeriodInt != int.Parse(ListsPeriod.Text))
240                 {
241                     ListsPeriodInt = int.Parse(ListsPeriod.Text);
242                     arg.Lists = true;
243                     isIntervalChanged = true;
244                 }
245                 if (ReplyPeriodInt != int.Parse(ReplyPeriod.Text))
246                 {
247                     ReplyPeriodInt = int.Parse(ReplyPeriod.Text);
248                     arg.Reply = true;
249                     isIntervalChanged = true;
250                 }
251                 if (UserTimelinePeriodInt != int.Parse(UserTimelinePeriod.Text))
252                 {
253                     UserTimelinePeriodInt = int.Parse(UserTimelinePeriod.Text);
254                     arg.UserTimeline = true;
255                     isIntervalChanged = true;
256                 }
257
258                 if (isIntervalChanged && IntervalChanged != null)
259                 {
260                     IntervalChanged(this, arg);
261                 }
262
263                 Readed = StartupReaded.Checked;
264                 switch (IconSize.SelectedIndex)
265                 {
266                     case 0:
267                         IconSz = MyCommon.IconSizes.IconNone;
268                         break;
269                     case 1:
270                         IconSz = MyCommon.IconSizes.Icon16;
271                         break;
272                     case 2:
273                         IconSz = MyCommon.IconSizes.Icon24;
274                         break;
275                     case 3:
276                         IconSz = MyCommon.IconSizes.Icon48;
277                         break;
278                     case 4:
279                         IconSz = MyCommon.IconSizes.Icon48_2;
280                         break;
281                 }
282                 Status = StatusText.Text;
283                 PlaySound = PlaySnd.Checked;
284                 UnreadManage = UReadMng.Checked;
285                 OneWayLove = OneWayLv.Checked;
286
287                 FontUnread = lblUnread.Font;     //未使用
288                 ColorUnread = lblUnread.ForeColor;
289                 FontReaded = lblListFont.Font;     //リストフォントとして使用
290                 ColorReaded = lblListFont.ForeColor;
291                 ColorFav = lblFav.ForeColor;
292                 ColorOWL = lblOWL.ForeColor;
293                 ColorRetweet = lblRetweet.ForeColor;
294                 FontDetail = lblDetail.Font;
295                 ColorSelf = lblSelf.BackColor;
296                 ColorAtSelf = lblAtSelf.BackColor;
297                 ColorTarget = lblTarget.BackColor;
298                 ColorAtTarget = lblAtTarget.BackColor;
299                 ColorAtFromTarget = lblAtFromTarget.BackColor;
300                 ColorAtTo = lblAtTo.BackColor;
301                 ColorInputBackcolor = lblInputBackcolor.BackColor;
302                 ColorInputFont = lblInputFont.ForeColor;
303                 ColorListBackcolor = lblListBackcolor.BackColor;
304                 ColorDetailBackcolor = lblDetailBackcolor.BackColor;
305                 ColorDetail = lblDetail.ForeColor;
306                 ColorDetailLink = lblDetailLink.ForeColor;
307                 FontInputFont = lblInputFont.Font;
308                 switch (cmbNameBalloon.SelectedIndex)
309                 {
310                     case 0:
311                         NameBalloon = MyCommon.NameBalloonEnum.None;
312                         break;
313                     case 1:
314                         NameBalloon = MyCommon.NameBalloonEnum.UserID;
315                         break;
316                     case 2:
317                         NameBalloon = MyCommon.NameBalloonEnum.NickName;
318                         break;
319                 }
320
321                 switch (ComboBoxPostKeySelect.SelectedIndex)
322                 {
323                     case 2:
324                         PostShiftEnter = true;
325                         PostCtrlEnter = false;
326                         break;
327                     case 1:
328                         PostCtrlEnter = true;
329                         PostShiftEnter = false;
330                         break;
331                     case 0:
332                         PostCtrlEnter = false;
333                         PostShiftEnter = false;
334                         break;
335                 }
336                 CountApi = int.Parse(TextCountApi.Text);
337                 CountApiReply = int.Parse(TextCountApiReply.Text);
338                 BrowserPath = BrowserPathText.Text.Trim();
339                 PostAndGet = CheckPostAndGet.Checked;
340                 UseRecommendStatus = CheckUseRecommendStatus.Checked;
341                 DispUsername = CheckDispUsername.Checked;
342                 CloseToExit = CheckCloseToExit.Checked;
343                 MinimizeToTray = CheckMinimizeToTray.Checked;
344                 switch (ComboDispTitle.SelectedIndex)
345                 {
346                     case 0:  //None
347                         DispLatestPost = MyCommon.DispTitleEnum.None;
348                         break;
349                     case 1:  //Ver
350                         DispLatestPost = MyCommon.DispTitleEnum.Ver;
351                         break;
352                     case 2:  //Post
353                         DispLatestPost = MyCommon.DispTitleEnum.Post;
354                         break;
355                     case 3:  //RepCount
356                         DispLatestPost = MyCommon.DispTitleEnum.UnreadRepCount;
357                         break;
358                     case 4:  //AllCount
359                         DispLatestPost = MyCommon.DispTitleEnum.UnreadAllCount;
360                         break;
361                     case 5:  //Rep+All
362                         DispLatestPost = MyCommon.DispTitleEnum.UnreadAllRepCount;
363                         break;
364                     case 6:  //Unread/All
365                         DispLatestPost = MyCommon.DispTitleEnum.UnreadCountAllCount;
366                         break;
367                     case 7: //Count of Status/Follow/Follower
368                         DispLatestPost = MyCommon.DispTitleEnum.OwnStatus;
369                         break;
370                 }
371                 SortOrderLock = CheckSortOrderLock.Checked;
372                 ViewTabBottom = CheckViewTabBottom.Checked;
373                 TinyUrlResolve = CheckTinyURL.Checked;
374                 ShortUrlForceResolve = CheckForceResolve.Checked;
375                 ShortUrl.IsResolve = TinyUrlResolve;
376                 ShortUrl.IsForceResolve = ShortUrlForceResolve;
377                 if (RadioProxyNone.Checked)
378                 {
379                     _MyProxyType = HttpConnection.ProxyType.None;
380                 }
381                 else if (RadioProxyIE.Checked)
382                 {
383                     _MyProxyType = HttpConnection.ProxyType.IE;
384                 }
385                 else
386                 {
387                     _MyProxyType = HttpConnection.ProxyType.Specified;
388                 }
389                 ProxyAddress = TextProxyAddress.Text.Trim();
390                 ProxyPort = int.Parse(TextProxyPort.Text.Trim());
391                 ProxyUser = TextProxyUser.Text.Trim();
392                 ProxyPassword = TextProxyPassword.Text.Trim();
393                 StartupVersion = CheckStartupVersion.Checked;
394                 StartupFollowers = CheckStartupFollowers.Checked;
395                 RestrictFavCheck = CheckFavRestrict.Checked;
396                 AlwaysTop = CheckAlwaysTop.Checked;
397                 UrlConvertAuto = CheckAutoConvertUrl.Checked;
398                 ShortenTco = ShortenTcoCheck.Checked;
399                 OutputzEnabled = CheckOutputz.Checked;
400                 OutputzKey = TextBoxOutputzKey.Text.Trim();
401
402                 switch (ComboBoxOutputzUrlmode.SelectedIndex)
403                 {
404                     case 0:
405                         OutputzUrlmode = MyCommon.OutputzUrlmode.twittercom;
406                         break;
407                     case 1:
408                         OutputzUrlmode = MyCommon.OutputzUrlmode.twittercomWithUsername;
409                         break;
410                 }
411
412                 Nicoms = CheckNicoms.Checked;
413                 UseUnreadStyle = chkUnreadStyle.Checked;
414                 DateTimeFormat = CmbDateTimeFormat.Text;
415                 DefaultTimeOut = int.Parse(ConnectionTimeOut.Text);
416                 RetweetNoConfirm = CheckRetweetNoConfirm.Checked;
417                 LimitBalloon = CheckBalloonLimit.Checked;
418                 EventNotifyEnabled = CheckEventNotify.Checked;
419                 GetEventNotifyFlag(ref _MyEventNotifyFlag, ref _isMyEventNotifyFlag);
420                 ForceEventNotify = CheckForceEventNotify.Checked;
421                 FavEventUnread = CheckFavEventUnread.Checked;
422                 TranslateLanguage = (new Bing()).GetLanguageEnumFromIndex(ComboBoxTranslateLanguage.SelectedIndex);
423                 EventSoundFile = (string)ComboBoxEventNotifySound.SelectedItem;
424                 AutoShortUrlFirst = (MyCommon.UrlConverter)ComboBoxAutoShortUrlFirst.SelectedIndex;
425                 TabIconDisp = chkTabIconDisp.Checked;
426                 ReadOwnPost = chkReadOwnPost.Checked;
427                 GetFav = chkGetFav.Checked;
428                 IsMonospace = CheckMonospace.Checked;
429                 ReadOldPosts = CheckReadOldPosts.Checked;
430                 UseSsl = CheckUseSsl.Checked;
431                 BitlyUser = TextBitlyId.Text;
432                 BitlyPwd = TextBitlyPw.Text;
433                 ShowGrid = CheckShowGrid.Checked;
434                 UseAtIdSupplement = CheckAtIdSupple.Checked;
435                 UseHashSupplement = CheckHashSupple.Checked;
436                 PreviewEnable = CheckPreviewEnable.Checked;
437                 TwitterApiUrl = TwitterAPIText.Text.Trim();
438                 switch (ReplyIconStateCombo.SelectedIndex)
439                 {
440                     case 0:
441                         ReplyIconState = MyCommon.REPLY_ICONSTATE.None;
442                         break;
443                     case 1:
444                         ReplyIconState = MyCommon.REPLY_ICONSTATE.StaticIcon;
445                         break;
446                     case 2:
447                         ReplyIconState = MyCommon.REPLY_ICONSTATE.BlinkIcon;
448                         break;
449                 }
450                 switch (LanguageCombo.SelectedIndex)
451                 {
452                     case 0:
453                         Language = "OS";
454                         break;
455                     case 1:
456                         Language = "ja";
457                         break;
458                     case 2:
459                         Language = "en";
460                         break;
461                     case 3:
462                         Language = "zh-CN";
463                         break;
464                     default:
465                         Language = "en";
466                         break;
467                 }
468                 HotkeyEnabled = this.HotkeyCheck.Checked;
469                 HotkeyMod = Keys.None;
470                 if (this.HotkeyAlt.Checked) HotkeyMod = HotkeyMod | Keys.Alt;
471                 if (this.HotkeyShift.Checked) HotkeyMod = HotkeyMod | Keys.Shift;
472                 if (this.HotkeyCtrl.Checked) HotkeyMod = HotkeyMod | Keys.Control;
473                 if (this.HotkeyWin.Checked) HotkeyMod = HotkeyMod | Keys.LWin;
474                 int.TryParse(HotkeyCode.Text, out HotkeyValue);
475                 HotkeyKey = (Keys)HotkeyText.Tag;
476                 BlinkNewMentions = ChkNewMentionsBlink.Checked;
477                 UseAdditionalCount = UseChangeGetCount.Checked;
478                 MoreCountApi = int.Parse(GetMoreTextCountApi.Text);
479                 FirstCountApi = int.Parse(FirstTextCountApi.Text);
480                 SearchCountApi = int.Parse(SearchTextCountApi.Text);
481                 FavoritesCountApi = int.Parse(FavoritesTextCountApi.Text);
482                 UserTimelineCountApi = int.Parse(UserTimelineTextCountApi.Text);
483                 ListCountApi = int.Parse(ListTextCountApi.Text);
484                 OpenUserTimeline = CheckOpenUserTimeline.Checked;
485                 ListDoubleClickAction = ListDoubleClickActionComboBox.SelectedIndex;
486                 UserAppointUrl = UserAppointUrlText.Text;
487                 this.HideDuplicatedRetweets = this.HideDuplicatedRetweetsCheck.Checked;
488                 this.IsPreviewFoursquare = this.IsPreviewFoursquareCheckBox.Checked;
489                 this.MapThumbnailProvider = (MapProvider)this.MapThumbnailProviderComboBox.SelectedIndex;
490                 this.MapThumbnailHeight = int.Parse(this.MapThumbnailHeightTextBox.Text);
491                 this.MapThumbnailWidth = int.Parse(this.MapThumbnailWidthTextBox.Text);
492                 this.MapThumbnailZoom = int.Parse(this.MapThumbnailZoomTextBox.Text);
493                 this.IsListStatusesIncludeRts = this.IsListsIncludeRtsCheckBox.Checked;
494                 this.TabMouseLock = this.TabMouseLockCheck.Checked;
495                 this.IsRemoveSameEvent = this.IsRemoveSameFavEventCheckBox.Checked;
496                 this.IsNotifyUseGrowl = this.IsNotifyUseGrowlCheckBox.Checked;
497             }
498             catch(Exception)
499             {
500                 MessageBox.Show(Properties.Resources.Save_ClickText3);
501                 this.DialogResult = DialogResult.Cancel;
502                 return;
503             }
504         }
505
506         private void Setting_FormClosing(object sender, FormClosingEventArgs e)
507         {
508             if (MyCommon._endingFlag) return;
509
510             if (this.DialogResult == DialogResult.Cancel)
511             {
512                 //キャンセル時は画面表示時のアカウントに戻す
513                 //キャンセル時でも認証済みアカウント情報は保存する
514                 this.UserAccounts.Clear();
515                 foreach (object u in this.AuthUserCombo.Items)
516                 {
517                     this.UserAccounts.Add((UserAccount)u);
518                 }
519                 //アクティブユーザーを起動時のアカウントに戻す(起動時アカウントなければ何もしない)
520                 bool userSet = false;
521                 if (this.InitialUserId != null)
522                 {
523                     foreach (UserAccount u in this.UserAccounts)
524                     {
525                         if (u.UserId == this.InitialUserId)
526                         {
527                             tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
528                             userSet = true;
529                             break;
530                         }
531                     }
532                 }
533                 //認証済みアカウントが削除されていた場合、もしくは起動時アカウントがなかった場合は、
534                 //アクティブユーザーなしとして初期化
535                 if (!userSet)
536                 {
537                     tw.ClearAuthInfo();
538                     tw.Initialize("", "", "", 0);
539                 }
540             }
541
542             if (tw != null && string.IsNullOrEmpty(tw.Username) && e.CloseReason == CloseReason.None)
543             {
544                 if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
545                 {
546                     e.Cancel = true;
547                 }
548             }
549             if (_ValidationError)
550             {
551                 e.Cancel = true;
552             }
553             if (e.Cancel == false && TreeViewSetting.SelectedNode != null)
554             {
555                 Panel curPanel = (Panel)TreeViewSetting.SelectedNode.Tag;
556                 curPanel.Visible = false;
557                 curPanel.Enabled = false;
558             }
559         }
560
561         private void Setting_Load(object sender, EventArgs e)
562         {
563 #if UA
564             this.FollowCheckBox.Text = string.Format(this.FollowCheckBox.Text, ApplicationSettings.FeedbackTwitterName);
565             this.GroupBox2.Visible = true;
566 #else
567             this.GroupBox2.Visible = false;
568 #endif
569             tw = ((TweenMain)this.Owner).TwitterInstance;
570             string uname = tw.Username;
571             string pw = tw.Password;
572             string tk = tw.AccessToken;
573             string tks = tw.AccessTokenSecret;
574             //this.AuthStateLabel.Enabled = true;
575             //this.AuthUserLabel.Enabled = true;
576             this.AuthClearButton.Enabled = true;
577
578             //if (tw.Username == "")
579             //{
580             //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4
581             //    //this.AuthUserLabel.Text = ""
582             //    //this.Save.Enabled = false
583             //}
584             //else
585             //{
586             //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
587             //    //if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWrite)
588             //    //{
589             //    //    this.AuthStateLabel.Text += "(xAuth)";
590             //    //}
591             //    //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
592             //    //{
593             //    //    this.AuthStateLabel.Text += "(OAuth)";
594             //    //}
595             //    //this.AuthUserLabel.Text = tw.Username;
596             //}
597
598             this.AuthUserCombo.Items.Clear();
599             if (this.UserAccounts.Count > 0)
600             {
601                 this.AuthUserCombo.Items.AddRange(this.UserAccounts.ToArray());
602                 foreach (UserAccount u in this.UserAccounts)
603                 {
604                     if (u.UserId == tw.UserId)
605                     {
606                         this.AuthUserCombo.SelectedItem = u;
607                         this.InitialUserId = u.UserId;
608                         break;
609                     }
610                 }
611             }
612
613             this.StartupUserstreamCheck.Checked = UserstreamStartup;
614             UserstreamPeriod.Text = UserstreamPeriodInt.ToString();
615             TimelinePeriod.Text = TimelinePeriodInt.ToString();
616             ReplyPeriod.Text = ReplyPeriodInt.ToString();
617             DMPeriod.Text = DMPeriodInt.ToString();
618             PubSearchPeriod.Text = PubSearchPeriodInt.ToString();
619             ListsPeriod.Text = ListsPeriodInt.ToString();
620             UserTimelinePeriod.Text = UserTimelinePeriodInt.ToString();
621
622             StartupReaded.Checked = Readed;
623             switch (IconSz)
624             {
625                 case MyCommon.IconSizes.IconNone:
626                     IconSize.SelectedIndex = 0;
627                     break;
628                 case MyCommon.IconSizes.Icon16:
629                     IconSize.SelectedIndex = 1;
630                     break;
631                 case MyCommon.IconSizes.Icon24:
632                     IconSize.SelectedIndex = 2;
633                     break;
634                 case MyCommon.IconSizes.Icon48:
635                     IconSize.SelectedIndex = 3;
636                     break;
637                 case MyCommon.IconSizes.Icon48_2:
638                     IconSize.SelectedIndex = 4;
639                     break;
640             }
641             StatusText.Text = Status;
642             UReadMng.Checked = UnreadManage;
643             if (UnreadManage == false)
644             {
645                 StartupReaded.Enabled = false;
646             }
647             else
648             {
649                 StartupReaded.Enabled = true;
650             }
651             PlaySnd.Checked = PlaySound;
652             OneWayLv.Checked = OneWayLove;
653
654             lblListFont.Font = FontReaded;
655             lblUnread.Font = FontUnread;
656             lblUnread.ForeColor = ColorUnread;
657             lblListFont.ForeColor = ColorReaded;
658             lblFav.ForeColor = ColorFav;
659             lblOWL.ForeColor = ColorOWL;
660             lblRetweet.ForeColor = ColorRetweet;
661             lblDetail.Font = FontDetail;
662             lblSelf.BackColor = ColorSelf;
663             lblAtSelf.BackColor = ColorAtSelf;
664             lblTarget.BackColor = ColorTarget;
665             lblAtTarget.BackColor = ColorAtTarget;
666             lblAtFromTarget.BackColor = ColorAtFromTarget;
667             lblAtTo.BackColor = ColorAtTo;
668             lblInputBackcolor.BackColor = ColorInputBackcolor;
669             lblInputFont.ForeColor = ColorInputFont;
670             lblInputFont.Font = FontInputFont;
671             lblListBackcolor.BackColor = ColorListBackcolor;
672             lblDetailBackcolor.BackColor = ColorDetailBackcolor;
673             lblDetail.ForeColor = ColorDetail;
674             lblDetailLink.ForeColor = ColorDetailLink;
675
676             switch (NameBalloon)
677             {
678                 case MyCommon.NameBalloonEnum.None:
679                     cmbNameBalloon.SelectedIndex = 0;
680                     break;
681                 case MyCommon.NameBalloonEnum.UserID:
682                     cmbNameBalloon.SelectedIndex = 1;
683                     break;
684                 case MyCommon.NameBalloonEnum.NickName:
685                     cmbNameBalloon.SelectedIndex = 2;
686                     break;
687             }
688
689             if (PostCtrlEnter)
690             {
691                 ComboBoxPostKeySelect.SelectedIndex = 1;
692             }
693             else if (PostShiftEnter)
694             {
695                 ComboBoxPostKeySelect.SelectedIndex = 2;
696             }
697             else
698             {
699                 ComboBoxPostKeySelect.SelectedIndex = 0;
700             }
701
702             TextCountApi.Text = CountApi.ToString();
703             TextCountApiReply.Text = CountApiReply.ToString();
704             BrowserPathText.Text = BrowserPath;
705             CheckPostAndGet.Checked = PostAndGet;
706             CheckUseRecommendStatus.Checked = UseRecommendStatus;
707             CheckDispUsername.Checked = DispUsername;
708             CheckCloseToExit.Checked = CloseToExit;
709             CheckMinimizeToTray.Checked = MinimizeToTray;
710             switch (DispLatestPost)
711             {
712                 case MyCommon.DispTitleEnum.None:
713                     ComboDispTitle.SelectedIndex = 0;
714                     break;
715                 case MyCommon.DispTitleEnum.Ver:
716                     ComboDispTitle.SelectedIndex = 1;
717                     break;
718                 case MyCommon.DispTitleEnum.Post:
719                     ComboDispTitle.SelectedIndex = 2;
720                     break;
721                 case MyCommon.DispTitleEnum.UnreadRepCount:
722                     ComboDispTitle.SelectedIndex = 3;
723                     break;
724                 case MyCommon.DispTitleEnum.UnreadAllCount:
725                     ComboDispTitle.SelectedIndex = 4;
726                     break;
727                 case MyCommon.DispTitleEnum.UnreadAllRepCount:
728                     ComboDispTitle.SelectedIndex = 5;
729                     break;
730                 case MyCommon.DispTitleEnum.UnreadCountAllCount:
731                     ComboDispTitle.SelectedIndex = 6;
732                     break;
733                 case MyCommon.DispTitleEnum.OwnStatus:
734                     ComboDispTitle.SelectedIndex = 7;
735                     break;
736             }
737             CheckSortOrderLock.Checked = SortOrderLock;
738             CheckViewTabBottom.Checked = ViewTabBottom;
739             CheckTinyURL.Checked = TinyUrlResolve;
740             CheckForceResolve.Checked = ShortUrlForceResolve;
741             switch (_MyProxyType)
742             {
743                 case HttpConnection.ProxyType.None:
744                     RadioProxyNone.Checked = true;
745                     break;
746                 case HttpConnection.ProxyType.IE:
747                     RadioProxyIE.Checked = true;
748                     break;
749                 default:
750                     RadioProxySpecified.Checked = true;
751                     break;
752             }
753             bool chk = RadioProxySpecified.Checked;
754             LabelProxyAddress.Enabled = chk;
755             TextProxyAddress.Enabled = chk;
756             LabelProxyPort.Enabled = chk;
757             TextProxyPort.Enabled = chk;
758             LabelProxyUser.Enabled = chk;
759             TextProxyUser.Enabled = chk;
760             LabelProxyPassword.Enabled = chk;
761             TextProxyPassword.Enabled = chk;
762
763             TextProxyAddress.Text = ProxyAddress;
764             TextProxyPort.Text = ProxyPort.ToString();
765             TextProxyUser.Text = ProxyUser;
766             TextProxyPassword.Text = ProxyPassword;
767
768             CheckStartupVersion.Checked = StartupVersion;
769             if (ApplicationSettings.VersionInfoUrl == null)
770                 CheckStartupVersion.Enabled = false; // 更新チェック無効化
771             CheckStartupFollowers.Checked = StartupFollowers;
772             CheckFavRestrict.Checked = RestrictFavCheck;
773             CheckAlwaysTop.Checked = AlwaysTop;
774             CheckAutoConvertUrl.Checked = UrlConvertAuto;
775             ShortenTcoCheck.Checked = ShortenTco;
776             ShortenTcoCheck.Enabled = CheckAutoConvertUrl.Checked;
777             CheckOutputz.Checked = OutputzEnabled;
778             TextBoxOutputzKey.Text = OutputzKey;
779
780             switch (OutputzUrlmode)
781             {
782                 case MyCommon.OutputzUrlmode.twittercom:
783                     ComboBoxOutputzUrlmode.SelectedIndex = 0;
784                     break;
785                 case MyCommon.OutputzUrlmode.twittercomWithUsername:
786                     ComboBoxOutputzUrlmode.SelectedIndex = 1;
787                     break;
788             }
789
790             CheckNicoms.Checked = Nicoms;
791             chkUnreadStyle.Checked = UseUnreadStyle;
792             CmbDateTimeFormat.Text = DateTimeFormat;
793             ConnectionTimeOut.Text = DefaultTimeOut.ToString();
794             CheckRetweetNoConfirm.Checked = RetweetNoConfirm;
795             CheckBalloonLimit.Checked = LimitBalloon;
796
797             ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
798             CheckForceEventNotify.Checked = ForceEventNotify;
799             CheckFavEventUnread.Checked = FavEventUnread;
800             ComboBoxTranslateLanguage.SelectedIndex = (new Bing()).GetIndexFromLanguageEnum(TranslateLanguage);
801             SoundFileListup();
802             ComboBoxAutoShortUrlFirst.SelectedIndex = (int)AutoShortUrlFirst;
803             chkTabIconDisp.Checked = TabIconDisp;
804             chkReadOwnPost.Checked = ReadOwnPost;
805             chkGetFav.Checked = GetFav;
806             CheckMonospace.Checked = IsMonospace;
807             CheckReadOldPosts.Checked = ReadOldPosts;
808             CheckUseSsl.Checked = UseSsl;
809             TextBitlyId.Text = BitlyUser;
810             TextBitlyPw.Text = BitlyPwd;
811             TextBitlyId.Modified = false;
812             TextBitlyPw.Modified = false;
813             CheckShowGrid.Checked = ShowGrid;
814             CheckAtIdSupple.Checked = UseAtIdSupplement;
815             CheckHashSupple.Checked = UseHashSupplement;
816             CheckPreviewEnable.Checked = PreviewEnable;
817             TwitterAPIText.Text = TwitterApiUrl;
818             switch (ReplyIconState)
819             {
820                 case MyCommon.REPLY_ICONSTATE.None:
821                     ReplyIconStateCombo.SelectedIndex = 0;
822                     break;
823                 case MyCommon.REPLY_ICONSTATE.StaticIcon:
824                     ReplyIconStateCombo.SelectedIndex = 1;
825                     break;
826                 case MyCommon.REPLY_ICONSTATE.BlinkIcon:
827                     ReplyIconStateCombo.SelectedIndex = 2;
828                     break;
829             }
830             switch (Language)
831             {
832                 case "OS":
833                     LanguageCombo.SelectedIndex = 0;
834                     break;
835                 case "ja":
836                     LanguageCombo.SelectedIndex = 1;
837                     break;
838                 case "en":
839                     LanguageCombo.SelectedIndex = 2;
840                     break;
841                 case "zh-CN":
842                     LanguageCombo.SelectedIndex = 3;
843                     break;
844                 default:
845                     LanguageCombo.SelectedIndex = 0;
846                     break;
847             }
848             HotkeyCheck.Checked = HotkeyEnabled;
849             HotkeyAlt.Checked = ((HotkeyMod & Keys.Alt) == Keys.Alt);
850             HotkeyCtrl.Checked = ((HotkeyMod & Keys.Control) == Keys.Control);
851             HotkeyShift.Checked = ((HotkeyMod & Keys.Shift) == Keys.Shift);
852             HotkeyWin.Checked = ((HotkeyMod & Keys.LWin) == Keys.LWin);
853             HotkeyCode.Text = HotkeyValue.ToString();
854             HotkeyText.Text = HotkeyKey.ToString();
855             HotkeyText.Tag = HotkeyKey;
856             HotkeyAlt.Enabled = HotkeyEnabled;
857             HotkeyShift.Enabled = HotkeyEnabled;
858             HotkeyCtrl.Enabled = HotkeyEnabled;
859             HotkeyWin.Enabled = HotkeyEnabled;
860             HotkeyText.Enabled = HotkeyEnabled;
861             HotkeyCode.Enabled = HotkeyEnabled;
862             ChkNewMentionsBlink.Checked = BlinkNewMentions;
863
864             CheckOutputz_CheckedChanged(sender, e);
865
866             GetMoreTextCountApi.Text = MoreCountApi.ToString();
867             FirstTextCountApi.Text = FirstCountApi.ToString();
868             SearchTextCountApi.Text = SearchCountApi.ToString();
869             FavoritesTextCountApi.Text = FavoritesCountApi.ToString();
870             UserTimelineTextCountApi.Text = UserTimelineCountApi.ToString();
871             ListTextCountApi.Text = ListCountApi.ToString();
872             UseChangeGetCount.Checked = UseAdditionalCount;
873             Label28.Enabled = UseChangeGetCount.Checked;
874             Label30.Enabled = UseChangeGetCount.Checked;
875             Label53.Enabled = UseChangeGetCount.Checked;
876             Label66.Enabled = UseChangeGetCount.Checked;
877             Label17.Enabled = UseChangeGetCount.Checked;
878             Label25.Enabled = UseChangeGetCount.Checked;
879             GetMoreTextCountApi.Enabled = UseChangeGetCount.Checked;
880             FirstTextCountApi.Enabled = UseChangeGetCount.Checked;
881             SearchTextCountApi.Enabled = UseChangeGetCount.Checked;
882             FavoritesTextCountApi.Enabled = UseChangeGetCount.Checked;
883             UserTimelineTextCountApi.Enabled = UseChangeGetCount.Checked;
884             ListTextCountApi.Enabled = UseChangeGetCount.Checked;
885             CheckOpenUserTimeline.Checked = OpenUserTimeline;
886             ListDoubleClickActionComboBox.SelectedIndex = ListDoubleClickAction;
887             UserAppointUrlText.Text = UserAppointUrl;
888             this.HideDuplicatedRetweetsCheck.Checked = this.HideDuplicatedRetweets;
889             this.IsPreviewFoursquareCheckBox.Checked = this.IsPreviewFoursquare;
890             this.MapThumbnailProviderComboBox.SelectedIndex = (int)this.MapThumbnailProvider;
891             this.MapThumbnailHeightTextBox.Text = this.MapThumbnailHeight.ToString();
892             this.MapThumbnailWidthTextBox.Text = this.MapThumbnailWidth.ToString();
893             this.MapThumbnailZoomTextBox.Text = this.MapThumbnailZoom.ToString();
894             this.IsListsIncludeRtsCheckBox.Checked = this.IsListStatusesIncludeRts;
895             this.TabMouseLockCheck.Checked = this.TabMouseLock;
896             this.IsRemoveSameFavEventCheckBox.Checked = this.IsRemoveSameEvent;
897             this.IsNotifyUseGrowlCheckBox.Checked = this.IsNotifyUseGrowl;
898
899             if (GrowlHelper.IsDllExists)
900             {
901                 IsNotifyUseGrowlCheckBox.Enabled = true;
902             }
903             else
904             {
905                 IsNotifyUseGrowlCheckBox.Enabled = false;
906             }
907
908             this.TreeViewSetting.Nodes["BasedNode"].Tag = BasedPanel;
909             this.TreeViewSetting.Nodes["BasedNode"].Nodes["PeriodNode"].Tag = GetPeriodPanel;
910             this.TreeViewSetting.Nodes["BasedNode"].Nodes["StartUpNode"].Tag = StartupPanel;
911             this.TreeViewSetting.Nodes["BasedNode"].Nodes["GetCountNode"].Tag = GetCountPanel;
912             //this.TreeViewSetting.Nodes["BasedNode"].Nodes["UserStreamNode"].Tag = UserStreamPanel;
913             this.TreeViewSetting.Nodes["ActionNode"].Tag = ActionPanel;
914             this.TreeViewSetting.Nodes["ActionNode"].Nodes["TweetActNode"].Tag = TweetActPanel;
915             this.TreeViewSetting.Nodes["PreviewNode"].Tag = PreviewPanel;
916             this.TreeViewSetting.Nodes["PreviewNode"].Nodes["TweetPrvNode"].Tag = TweetPrvPanel;
917             this.TreeViewSetting.Nodes["PreviewNode"].Nodes["NotifyNode"].Tag = NotifyPanel;
918             this.TreeViewSetting.Nodes["FontNode"].Tag = FontPanel;
919             this.TreeViewSetting.Nodes["FontNode"].Nodes["FontNode2"].Tag = FontPanel2;
920             this.TreeViewSetting.Nodes["ConnectionNode"].Tag = ConnectionPanel;
921             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ProxyNode"].Tag = ProxyPanel;
922             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["CooperateNode"].Tag = CooperatePanel;
923             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"].Tag = ShortUrlPanel;
924
925             this.TreeViewSetting.SelectedNode = this.TreeViewSetting.Nodes[0];
926             this.TreeViewSetting.ExpandAll();
927
928             //TreeViewSetting.SelectedNode = TreeViewSetting.TopNode;
929             ActiveControl = StartAuthButton;
930         }
931
932         private void UserstreamPeriod_Validating(object sender, CancelEventArgs e)
933         {
934             int prd;
935             try
936             {
937                 prd = int.Parse(UserstreamPeriod.Text);
938             }
939             catch(Exception)
940             {
941                 MessageBox.Show(Properties.Resources.UserstreamPeriod_ValidatingText1);
942                 e.Cancel = true;
943                 return;
944             }
945
946             if (prd < 0 || prd > 60)
947             {
948                 MessageBox.Show(Properties.Resources.UserstreamPeriod_ValidatingText1);
949                 e.Cancel = true;
950                 return;
951             }
952         }
953
954         private void TimelinePeriod_Validating(object sender, CancelEventArgs e)
955         {
956             int prd;
957             try
958             {
959                 prd = int.Parse(TimelinePeriod.Text);
960             }
961             catch(Exception)
962             {
963                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
964                 e.Cancel = true;
965                 return;
966             }
967
968             if (prd != 0 && (prd < 15 || prd > 6000))
969             {
970                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
971                 e.Cancel = true;
972                 return;
973             }
974         }
975
976         private void ReplyPeriod_Validating(object sender, CancelEventArgs e)
977         {
978             int prd;
979             try
980             {
981                 prd = int.Parse(ReplyPeriod.Text);
982             }
983             catch(Exception)
984             {
985                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText1);
986                 e.Cancel = true;
987                 return;
988             }
989
990             if (prd != 0 && (prd < 15 || prd > 6000))
991             {
992                 MessageBox.Show(Properties.Resources.TimelinePeriod_ValidatingText2);
993                 e.Cancel = true;
994                 return;
995             }
996         }
997
998         private void DMPeriod_Validating(object sender, CancelEventArgs e)
999         {
1000             int prd;
1001             try
1002             {
1003                 prd = int.Parse(DMPeriod.Text);
1004             }
1005             catch(Exception)
1006             {
1007                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
1008                 e.Cancel = true;
1009                 return;
1010             }
1011
1012             if (prd != 0 && (prd < 15 || prd > 6000))
1013             {
1014                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
1015                 e.Cancel = true;
1016                 return;
1017             }
1018         }
1019
1020         private void PubSearchPeriod_Validating(object sender, CancelEventArgs e)
1021         {
1022             int prd;
1023             try
1024             {
1025                 prd = int.Parse(PubSearchPeriod.Text);
1026             }
1027             catch(Exception)
1028             {
1029                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText1);
1030                 e.Cancel = true;
1031                 return;
1032             }
1033
1034             if (prd != 0 && (prd < 30 || prd > 6000))
1035             {
1036                 MessageBox.Show(Properties.Resources.PubSearchPeriod_ValidatingText2);
1037                 e.Cancel = true;
1038             }
1039         }
1040
1041         private void ListsPeriod_Validating(object sender, CancelEventArgs e)
1042         {
1043             int prd;
1044             try
1045             {
1046                 prd = int.Parse(ListsPeriod.Text);
1047             }
1048             catch(Exception)
1049             {
1050                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
1051                 e.Cancel = true;
1052                 return;
1053             }
1054
1055             if (prd != 0 && (prd < 15 || prd > 6000))
1056             {
1057                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
1058                 e.Cancel = true;
1059                 return;
1060             }
1061         }
1062
1063         private void UserTimeline_Validating(object sender, CancelEventArgs e)
1064         {
1065             int prd;
1066             try
1067             {
1068                 prd = int.Parse(UserTimelinePeriod.Text);
1069             }
1070             catch(Exception)
1071             {
1072                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText1);
1073                 e.Cancel = true;
1074                 return;
1075             }
1076
1077             if (prd != 0 && (prd < 15 || prd > 6000))
1078             {
1079                 MessageBox.Show(Properties.Resources.DMPeriod_ValidatingText2);
1080                 e.Cancel = true;
1081                 return;
1082             }
1083         }
1084
1085         private void UReadMng_CheckedChanged(object sender, EventArgs e)
1086         {
1087             if (UReadMng.Checked == true)
1088             {
1089                 StartupReaded.Enabled = true;
1090             }
1091             else
1092             {
1093                 StartupReaded.Enabled = false;
1094             }
1095         }
1096
1097         private void btnFontAndColor_Click(object sender, EventArgs e) // Handles btnUnread.Click, btnDetail.Click, btnListFont.Click, btnInputFont.Click
1098         {
1099             Button Btn = (Button) sender;
1100             DialogResult rtn;
1101
1102             FontDialog1.AllowVerticalFonts = false;
1103             FontDialog1.AllowScriptChange = true;
1104             FontDialog1.AllowSimulations = true;
1105             FontDialog1.AllowVectorFonts = true;
1106             FontDialog1.FixedPitchOnly = false;
1107             FontDialog1.FontMustExist = true;
1108             FontDialog1.ScriptsOnly = false;
1109             FontDialog1.ShowApply = false;
1110             FontDialog1.ShowEffects = true;
1111             FontDialog1.ShowColor = true;
1112
1113             switch (Btn.Name)
1114             {
1115                 case "btnUnread":
1116                     FontDialog1.Color = lblUnread.ForeColor;
1117                     FontDialog1.Font = lblUnread.Font;
1118                     break;
1119                 case "btnDetail":
1120                     FontDialog1.Color = lblDetail.ForeColor;
1121                     FontDialog1.Font = lblDetail.Font;
1122                     break;
1123                 case "btnListFont":
1124                     FontDialog1.Color = lblListFont.ForeColor;
1125                     FontDialog1.Font = lblListFont.Font;
1126                     break;
1127                 case "btnInputFont":
1128                     FontDialog1.Color = lblInputFont.ForeColor;
1129                     FontDialog1.Font = lblInputFont.Font;
1130                     break;
1131             }
1132
1133             try
1134             {
1135                 rtn = FontDialog1.ShowDialog();
1136             }
1137             catch(ArgumentException ex)
1138             {
1139                 MessageBox.Show(ex.Message);
1140                 return;
1141             }
1142
1143             if (rtn == DialogResult.Cancel) return;
1144
1145             switch (Btn.Name)
1146             {
1147                 case "btnUnread":
1148                     lblUnread.ForeColor = FontDialog1.Color;
1149                     lblUnread.Font = FontDialog1.Font;
1150                     break;
1151                 case "btnDetail":
1152                     lblDetail.ForeColor = FontDialog1.Color;
1153                     lblDetail.Font = FontDialog1.Font;
1154                     break;
1155                 case "btnListFont":
1156                     lblListFont.ForeColor = FontDialog1.Color;
1157                     lblListFont.Font = FontDialog1.Font;
1158                     break;
1159                 case "btnInputFont":
1160                     lblInputFont.ForeColor = FontDialog1.Color;
1161                     lblInputFont.Font = FontDialog1.Font;
1162                     break;
1163             }
1164
1165         }
1166
1167         private void btnColor_Click(object sender, EventArgs e) //Handles btnSelf.Click, btnAtSelf.Click, btnTarget.Click, btnAtTarget.Click, btnAtFromTarget.Click, btnFav.Click, btnOWL.Click, btnInputBackcolor.Click, btnAtTo.Click, btnListBack.Click, btnDetailBack.Click, btnDetailLink.Click, btnRetweet.Click
1168         {
1169             Button Btn = (Button)sender;
1170             DialogResult rtn;
1171
1172             ColorDialog1.AllowFullOpen = true;
1173             ColorDialog1.AnyColor = true;
1174             ColorDialog1.FullOpen = false;
1175             ColorDialog1.SolidColorOnly = false;
1176
1177             switch (Btn.Name)
1178             {
1179                 case "btnSelf":
1180                     ColorDialog1.Color = lblSelf.BackColor;
1181                     break;
1182                 case "btnAtSelf":
1183                     ColorDialog1.Color = lblAtSelf.BackColor;
1184                     break;
1185                 case "btnTarget":
1186                     ColorDialog1.Color = lblTarget.BackColor;
1187                     break;
1188                 case "btnAtTarget":
1189                     ColorDialog1.Color = lblAtTarget.BackColor;
1190                     break;
1191                 case "btnAtFromTarget":
1192                     ColorDialog1.Color = lblAtFromTarget.BackColor;
1193                     break;
1194                 case "btnFav":
1195                     ColorDialog1.Color = lblFav.ForeColor;
1196                     break;
1197                 case "btnOWL":
1198                     ColorDialog1.Color = lblOWL.ForeColor;
1199                     break;
1200                 case "btnRetweet":
1201                     ColorDialog1.Color = lblRetweet.ForeColor;
1202                     break;
1203                 case "btnInputBackcolor":
1204                     ColorDialog1.Color = lblInputBackcolor.BackColor;
1205                     break;
1206                 case "btnAtTo":
1207                     ColorDialog1.Color = lblAtTo.BackColor;
1208                     break;
1209                 case "btnListBack":
1210                     ColorDialog1.Color = lblListBackcolor.BackColor;
1211                     break;
1212                 case "btnDetailBack":
1213                     ColorDialog1.Color = lblDetailBackcolor.BackColor;
1214                     break;
1215                 case "btnDetailLink":
1216                     ColorDialog1.Color = lblDetailLink.ForeColor;
1217                     break;
1218             }
1219
1220             rtn = ColorDialog1.ShowDialog();
1221
1222             if (rtn == DialogResult.Cancel) return;
1223
1224             switch (Btn.Name)
1225             {
1226                 case "btnSelf":
1227                     lblSelf.BackColor = ColorDialog1.Color;
1228                     break;
1229                 case "btnAtSelf":
1230                     lblAtSelf.BackColor = ColorDialog1.Color;
1231                     break;
1232                 case "btnTarget":
1233                     lblTarget.BackColor = ColorDialog1.Color;
1234                     break;
1235                 case "btnAtTarget":
1236                     lblAtTarget.BackColor = ColorDialog1.Color;
1237                     break;
1238                 case "btnAtFromTarget":
1239                     lblAtFromTarget.BackColor = ColorDialog1.Color;
1240                     break;
1241                 case "btnFav":
1242                     lblFav.ForeColor = ColorDialog1.Color;
1243                     break;
1244                 case "btnOWL":
1245                     lblOWL.ForeColor = ColorDialog1.Color;
1246                     break;
1247                 case "btnRetweet":
1248                     lblRetweet.ForeColor = ColorDialog1.Color;
1249                     break;
1250                 case "btnInputBackcolor":
1251                     lblInputBackcolor.BackColor = ColorDialog1.Color;
1252                     break;
1253                 case "btnAtTo":
1254                     lblAtTo.BackColor = ColorDialog1.Color;
1255                     break;
1256                 case "btnListBack":
1257                     lblListBackcolor.BackColor = ColorDialog1.Color;
1258                     break;
1259                 case "btnDetailBack":
1260                     lblDetailBackcolor.BackColor = ColorDialog1.Color;
1261                     break;
1262                 case "btnDetailLink":
1263                     lblDetailLink.ForeColor = ColorDialog1.Color;
1264                     break;
1265             }
1266         }
1267
1268         public int UserstreamPeriodInt { get; set; }
1269         public bool UserstreamStartup { get; set; }
1270         public int TimelinePeriodInt { get; set; }
1271         public int ReplyPeriodInt { get; set; }
1272         public int DMPeriodInt { get; set; }
1273         public int PubSearchPeriodInt { get; set; }
1274         public int ListsPeriodInt { get; set; }
1275         public int UserTimelinePeriodInt { get; set; }
1276         public bool Readed { get; set; }
1277         public MyCommon.IconSizes IconSz { get; set; }
1278         public string Status { get; set; }
1279         public bool UnreadManage { get; set; }
1280         public bool PlaySound { get; set; }
1281         public bool OneWayLove { get; set; }
1282         public Font FontUnread { get; set; } /////未使用
1283         public Color ColorUnread { get; set; }
1284         public Font FontReaded { get; set; } /////リストフォントとして使用
1285         public Color ColorReaded { get; set; }
1286         public Color ColorFav { get; set; }
1287         public Color ColorOWL { get; set; }
1288         public Color ColorRetweet { get; set; }
1289         public Font FontDetail { get; set; }
1290         public Color ColorDetail { get; set; }
1291         public Color ColorDetailLink { get; set; }
1292         public Color ColorSelf { get; set; }
1293         public Color ColorAtSelf { get; set; }
1294         public Color ColorTarget { get; set; }
1295         public Color ColorAtTarget { get; set; }
1296         public Color ColorAtFromTarget { get; set; }
1297         public Color ColorAtTo { get; set; }
1298         public Color ColorInputBackcolor { get; set; }
1299         public Color ColorInputFont { get; set; }
1300         public Font FontInputFont { get; set; }
1301         public Color ColorListBackcolor { get; set; }
1302         public Color ColorDetailBackcolor { get; set; }
1303         public MyCommon.NameBalloonEnum NameBalloon { get; set; }
1304         public bool PostCtrlEnter { get; set; }
1305         public bool PostShiftEnter { get; set; }
1306         public int CountApi { get; set; }
1307         public int CountApiReply { get; set; }
1308         public int MoreCountApi { get; set; }
1309         public int FirstCountApi { get; set; }
1310         public int SearchCountApi { get; set; }
1311         public int FavoritesCountApi { get; set; }
1312         public int UserTimelineCountApi { get; set; }
1313         public int ListCountApi { get; set; }
1314         public bool PostAndGet { get; set; }
1315         public bool UseRecommendStatus { get; set; }
1316         public string RecommendStatusText { get; set; }
1317         public bool DispUsername { get; set; }
1318         public bool CloseToExit { get; set; }
1319         public bool MinimizeToTray { get; set; }
1320         public MyCommon.DispTitleEnum DispLatestPost { get; set; }
1321         public string BrowserPath { get; set; }
1322         public bool TinyUrlResolve { get; set; }
1323         public bool ShortUrlForceResolve { get; set; }
1324
1325         private void CheckUseRecommendStatus_CheckedChanged(object sender, EventArgs e)
1326         {
1327             if (CheckUseRecommendStatus.Checked == true)
1328             {
1329                 StatusText.Enabled = false;
1330             }
1331             else
1332             {
1333                 StatusText.Enabled = true;
1334             }
1335         }
1336
1337         public bool SortOrderLock { get; set; }
1338         public HttpConnection.ProxyType SelectedProxyType
1339         {
1340             get {
1341                 return _MyProxyType;
1342             }
1343             set {
1344                 _MyProxyType = value;
1345             }
1346         }
1347         /// <summary>
1348         /// タブを下部に表示するかどうかを取得または設定する
1349         /// </summary>
1350         public bool ViewTabBottom { get; set; }
1351
1352         public string ProxyAddress { get; set; }
1353         public int ProxyPort { get; set; }
1354         public string ProxyUser { get; set; }
1355         public string ProxyPassword { get; set; }
1356         public bool StartupVersion { get; set; }
1357         public bool StartupFollowers { get; set; }
1358         public bool RestrictFavCheck { get; set; }
1359         public bool AlwaysTop { get; set; }
1360         public bool UrlConvertAuto { get; set; }
1361         public bool ShortenTco { get; set; }
1362         public bool OutputzEnabled { get; set; }
1363         public string OutputzKey { get; set; }
1364         public MyCommon.OutputzUrlmode OutputzUrlmode { get; set; }
1365         public bool Nicoms { get; set; }
1366         public MyCommon.UrlConverter AutoShortUrlFirst { get; set; }
1367         public bool UseUnreadStyle { get; set; }
1368         public string DateTimeFormat { get; set; }
1369         public int DefaultTimeOut { get; set; }
1370         public bool RetweetNoConfirm { get; set; }
1371         public bool TabIconDisp { get; set; }
1372         public MyCommon.REPLY_ICONSTATE ReplyIconState { get; set; }
1373         public bool ReadOwnPost { get; set; }
1374         public bool GetFav { get; set; }
1375         public bool IsMonospace { get; set; }
1376         public bool ReadOldPosts { get; set; }
1377         public bool UseSsl { get; set; }
1378         public string BitlyUser { get; set; }
1379         public string BitlyPwd { get; set; }
1380         public bool ShowGrid { get; set; }
1381         public bool UseAtIdSupplement { get; set; }
1382         public bool UseHashSupplement { get; set; }
1383         public bool PreviewEnable { get; set; }
1384         public bool UseAdditionalCount { get; set; }
1385         public bool OpenUserTimeline { get; set; }
1386         public string TwitterApiUrl { get; set; }
1387         public string Language { get; set; }
1388
1389         private void Button3_Click(object sender, EventArgs e)
1390         {
1391             using (OpenFileDialog filedlg = new OpenFileDialog())
1392             {
1393                 filedlg.Filter = Properties.Resources.Button3_ClickText1;
1394                 filedlg.FilterIndex = 1;
1395                 filedlg.Title = Properties.Resources.Button3_ClickText2;
1396                 filedlg.RestoreDirectory = true;
1397
1398                 if (filedlg.ShowDialog() == DialogResult.OK)
1399                 {
1400                     BrowserPathText.Text = filedlg.FileName;
1401                 }
1402             }
1403         }
1404
1405         private void RadioProxySpecified_CheckedChanged(object sender, EventArgs e)
1406         {
1407             bool chk = RadioProxySpecified.Checked;
1408             LabelProxyAddress.Enabled = chk;
1409             TextProxyAddress.Enabled = chk;
1410             LabelProxyPort.Enabled = chk;
1411             TextProxyPort.Enabled = chk;
1412             LabelProxyUser.Enabled = chk;
1413             TextProxyUser.Enabled = chk;
1414             LabelProxyPassword.Enabled = chk;
1415             TextProxyPassword.Enabled = chk;
1416         }
1417
1418         private void TextProxyPort_Validating(object sender, CancelEventArgs e)
1419         {
1420             int port;
1421             if (string.IsNullOrWhiteSpace(TextProxyPort.Text)) TextProxyPort.Text = "0";
1422             if (int.TryParse(TextProxyPort.Text.Trim(), out port) == false)
1423             {
1424                 MessageBox.Show(Properties.Resources.TextProxyPort_ValidatingText1);
1425                 e.Cancel = true;
1426                 return;
1427             }
1428             if (port < 0 || port > 65535)
1429             {
1430                 MessageBox.Show(Properties.Resources.TextProxyPort_ValidatingText2);
1431                 e.Cancel = true;
1432                 return;
1433             }
1434         }
1435
1436         private void CheckOutputz_CheckedChanged(object sender, EventArgs e)
1437         {
1438             if (CheckOutputz.Checked == true)
1439             {
1440                 Label59.Enabled = true;
1441                 Label60.Enabled = true;
1442                 TextBoxOutputzKey.Enabled = true;
1443                 ComboBoxOutputzUrlmode.Enabled = true;
1444             }
1445             else
1446             {
1447                 Label59.Enabled = false;
1448                 Label60.Enabled = false;
1449                 TextBoxOutputzKey.Enabled = false;
1450                 ComboBoxOutputzUrlmode.Enabled = false;
1451             }
1452         }
1453
1454         private void TextBoxOutputzKey_Validating(object sender, CancelEventArgs e)
1455         {
1456             if (CheckOutputz.Checked)
1457             {
1458                 TextBoxOutputzKey.Text = TextBoxOutputzKey.Text.Trim();
1459                 if (TextBoxOutputzKey.Text.Length == 0)
1460                 {
1461                     MessageBox.Show(Properties.Resources.TextBoxOutputzKey_Validating);
1462                     e.Cancel = true;
1463                     return;
1464                 }
1465             }
1466         }
1467
1468         private bool CreateDateTimeFormatSample()
1469         {
1470             try
1471             {
1472                 LabelDateTimeFormatApplied.Text = DateTime.Now.ToString(CmbDateTimeFormat.Text);
1473             }
1474             catch(FormatException)
1475             {
1476                 LabelDateTimeFormatApplied.Text = Properties.Resources.CreateDateTimeFormatSampleText1;
1477                 return false;
1478             }
1479             return true;
1480         }
1481
1482         private void CmbDateTimeFormat_TextUpdate(object sender, EventArgs e)
1483         {
1484             CreateDateTimeFormatSample();
1485         }
1486
1487         private void CmbDateTimeFormat_SelectedIndexChanged(object sender, EventArgs e)
1488         {
1489             CreateDateTimeFormatSample();
1490         }
1491
1492         private void CmbDateTimeFormat_Validating(object sender, CancelEventArgs e)
1493         {
1494             if (!CreateDateTimeFormatSample())
1495             {
1496                 MessageBox.Show(Properties.Resources.CmbDateTimeFormat_Validating);
1497                 e.Cancel = true;
1498             }
1499         }
1500
1501         private void ConnectionTimeOut_Validating(object sender, CancelEventArgs e)
1502         {
1503             int tm;
1504             try
1505             {
1506                 tm = int.Parse(ConnectionTimeOut.Text);
1507             }
1508             catch(Exception)
1509             {
1510                 MessageBox.Show(Properties.Resources.ConnectionTimeOut_ValidatingText1);
1511                 e.Cancel = true;
1512                 return;
1513             }
1514
1515             if (tm < (int)MyCommon.HttpTimeOut.MinValue || tm > (int)MyCommon.HttpTimeOut.MaxValue)
1516             {
1517                 MessageBox.Show(Properties.Resources.ConnectionTimeOut_ValidatingText1);
1518                 e.Cancel = true;
1519             }
1520         }
1521
1522         private void LabelDateTimeFormatApplied_VisibleChanged(object sender, EventArgs e)
1523         {
1524             CreateDateTimeFormatSample();
1525         }
1526
1527         private void TextCountApi_Validating(object sender, CancelEventArgs e)
1528         {
1529             int cnt;
1530             try
1531             {
1532                 cnt = int.Parse(TextCountApi.Text);
1533             }
1534             catch(Exception)
1535             {
1536                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1537                 e.Cancel = true;
1538                 return;
1539             }
1540
1541             if (cnt < 20 || cnt > 200)
1542             {
1543                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1544                 e.Cancel = true;
1545                 return;
1546             }
1547         }
1548
1549         private void TextCountApiReply_Validating(object sender, CancelEventArgs e)
1550         {
1551             int cnt;
1552             try
1553             {
1554                 cnt = int.Parse(TextCountApiReply.Text);
1555             }
1556             catch(Exception)
1557             {
1558                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1559                 e.Cancel = true;
1560                 return;
1561             }
1562
1563             if (cnt < 20 || cnt > 200)
1564             {
1565                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1566                 e.Cancel = true;
1567                 return;
1568             }
1569         }
1570
1571         public bool LimitBalloon { get; set; }
1572         public bool EventNotifyEnabled { get; set; }
1573
1574         public MyCommon.EVENTTYPE EventNotifyFlag
1575         {
1576             get
1577             {
1578                 return _MyEventNotifyFlag;
1579             }
1580             set
1581             {
1582                 _MyEventNotifyFlag = value;
1583             }
1584         }
1585
1586         public MyCommon.EVENTTYPE IsMyEventNotifyFlag
1587         {
1588             get
1589             {
1590                 return _isMyEventNotifyFlag;
1591             }
1592             set
1593             {
1594                 _isMyEventNotifyFlag = value;
1595             }
1596         }
1597
1598         public bool ForceEventNotify { get; set; }
1599         public bool FavEventUnread { get; set; }
1600
1601         public string TranslateLanguage
1602         {
1603             get
1604             {
1605                 return _MyTranslateLanguage;
1606             }
1607             set
1608             {
1609                 _MyTranslateLanguage = value;
1610                 ComboBoxTranslateLanguage.SelectedIndex = (new Bing()).GetIndexFromLanguageEnum(value);
1611             }
1612         }
1613
1614         public string EventSoundFile { get; set; }
1615         public int ListDoubleClickAction { get; set; }
1616         public string UserAppointUrl { get; set; }
1617
1618         private void ComboBoxAutoShortUrlFirst_SelectedIndexChanged(object sender, EventArgs e)
1619         {
1620             if (ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly ||
1621                ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp)
1622             {
1623                 Label76.Enabled = true;
1624                 Label77.Enabled = true;
1625                 TextBitlyId.Enabled = true;
1626                 TextBitlyPw.Enabled = true;
1627             }
1628             else
1629             {
1630                 Label76.Enabled = false;
1631                 Label77.Enabled = false;
1632                 TextBitlyId.Enabled = false;
1633                 TextBitlyPw.Enabled = false;
1634             }
1635         }
1636
1637         private void ButtonBackToDefaultFontColor_Click(object sender, EventArgs e) //Handles ButtonBackToDefaultFontColor.Click, ButtonBackToDefaultFontColor2.Click
1638         {
1639             lblUnread.ForeColor = SystemColors.ControlText;
1640             lblUnread.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
1641
1642             lblListFont.ForeColor = System.Drawing.SystemColors.ControlText;
1643             lblListFont.Font = System.Drawing.SystemFonts.DefaultFont;
1644
1645             lblDetail.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
1646             lblDetail.Font = System.Drawing.SystemFonts.DefaultFont;
1647
1648             lblInputFont.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.ControlText);
1649             lblInputFont.Font = System.Drawing.SystemFonts.DefaultFont;
1650
1651             lblSelf.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue);
1652
1653             lblAtSelf.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.AntiqueWhite);
1654
1655             lblTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
1656
1657             lblAtTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LavenderBlush);
1658
1659             lblAtFromTarget.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Honeydew);
1660
1661             lblFav.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Red);
1662
1663             lblOWL.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
1664
1665             lblInputBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.LemonChiffon);
1666
1667             lblAtTo.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Pink);
1668
1669             lblListBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
1670
1671             lblDetailBackcolor.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Window);
1672
1673             lblDetailLink.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Blue);
1674
1675             lblRetweet.ForeColor = Color.FromKnownColor(System.Drawing.KnownColor.Green);
1676         }
1677
1678         private bool StartAuth()
1679         {
1680             //現在の設定内容で通信
1681             HttpConnection.ProxyType ptype;
1682             if (RadioProxyNone.Checked)
1683             {
1684                 ptype = HttpConnection.ProxyType.None;
1685             }
1686             else if (RadioProxyIE.Checked)
1687             {
1688                 ptype = HttpConnection.ProxyType.IE;
1689             }
1690             else
1691             {
1692                 ptype = HttpConnection.ProxyType.Specified;
1693             }
1694             string padr = TextProxyAddress.Text.Trim();
1695             int pport = int.Parse(TextProxyPort.Text.Trim());
1696             string pusr = TextProxyUser.Text.Trim();
1697             string ppw = TextProxyPassword.Text.Trim();
1698
1699             //通信基底クラス初期化
1700             HttpConnection.InitializeConnection(20, ptype, padr, pport, pusr, ppw);
1701             HttpTwitter.TwitterUrl = TwitterAPIText.Text.Trim();
1702             tw.Initialize("", "", "", 0);
1703             //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
1704             //this.AuthUserLabel.Text = "";
1705             string pinPageUrl = "";
1706             string rslt = tw.StartAuthentication(ref pinPageUrl);
1707             if (string.IsNullOrEmpty(rslt))
1708             {
1709                 string pin = AuthDialog.DoAuth(this, pinPageUrl);
1710                 if (!string.IsNullOrEmpty(pin))
1711                 {
1712                     this._pin = pin;
1713                     return true;
1714                 }
1715                 else
1716                 {
1717                     return false;
1718                 }
1719             }
1720             else
1721             {
1722                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
1723                 return false;
1724             }
1725         }
1726
1727         private bool PinAuth()
1728         {
1729             string pin = this._pin;   //PIN Code
1730
1731             string rslt = tw.Authenticate(pin);
1732             if (string.IsNullOrEmpty(rslt))
1733             {
1734                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click1, "Authenticate", MessageBoxButtons.OK);
1735                 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
1736                 //this.AuthUserLabel.Text = tw.Username;
1737                 int idx = -1;
1738                 UserAccount user = new UserAccount();
1739                 user.Username = tw.Username;
1740                 user.UserId = tw.UserId;
1741                 user.Token = tw.AccessToken;
1742                 user.TokenSecret = tw.AccessTokenSecret;
1743
1744                 foreach (object u in this.AuthUserCombo.Items)
1745                 {
1746                     if (((UserAccount)u).Username.ToLower() == tw.Username.ToLower())
1747                     {
1748                         idx = this.AuthUserCombo.Items.IndexOf(u);
1749                         break;
1750                     }
1751                 }
1752                 if (idx > -1)
1753                 {
1754                     this.AuthUserCombo.Items.RemoveAt(idx);
1755                     this.AuthUserCombo.Items.Insert(idx, user);
1756                     this.AuthUserCombo.SelectedIndex = idx;
1757                 }
1758                 else
1759                 {
1760                     this.AuthUserCombo.SelectedIndex = this.AuthUserCombo.Items.Add(user);
1761                 }
1762                 //if (TwitterApiInfo.AccessLevel = ApiAccessLevel.ReadWrite)
1763                 //{
1764                 //    this.AuthStateLabel.Text += "(xAuth)";
1765                 //}
1766                 //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
1767                 //{
1768                 //    this.AuthStateLabel.Text += "(OAuth)";
1769                 //}
1770                 return true;
1771             }
1772             else
1773             {
1774                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
1775                 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
1776                 //this.AuthUserLabel.Text = "";
1777                 return false;
1778             }
1779         }
1780
1781         private void StartAuthButton_Click(object sender, EventArgs e)
1782         {
1783             //this.Save.Enabled = false;
1784             if (StartAuth())
1785             {
1786                 if (PinAuth())
1787                 {
1788                     //this.Save.Enabled = true;
1789                 }
1790             }
1791         }
1792
1793         private void AuthClearButton_Click(object sender, EventArgs e)
1794         {
1795             //tw.ClearAuthInfo();
1796             //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
1797             //this.AuthUserLabel.Text = "";
1798             if (this.AuthUserCombo.SelectedIndex > -1)
1799             {
1800                 this.AuthUserCombo.Items.RemoveAt(this.AuthUserCombo.SelectedIndex);
1801                 if (this.AuthUserCombo.Items.Count > 0)
1802                 {
1803                     this.AuthUserCombo.SelectedIndex = 0;
1804                 }
1805                 else
1806                 {
1807                     this.AuthUserCombo.SelectedIndex = -1;
1808                 }
1809             }
1810             //this.Save.Enabled = false;
1811         }
1812
1813         private void CheckPostAndGet_CheckedChanged(object sender, EventArgs e)
1814         {
1815             LabelPostAndGet.Visible = CheckPostAndGet.Checked && !tw.UserStreamEnabled;
1816         }
1817
1818         private void Setting_Shown(object sender, EventArgs e)
1819         {
1820             do
1821             {
1822                 Thread.Sleep(10);
1823                 if (this.Disposing || this.IsDisposed) return;
1824             } while (!this.IsHandleCreated);
1825             this.TopMost = this.AlwaysTop;
1826
1827             LabelPostAndGet.Visible = CheckPostAndGet.Checked && !tw.UserStreamEnabled;
1828             LabelUserStreamActive.Visible = tw.UserStreamEnabled;
1829         }
1830
1831         public static AppendSettingDialog Instance
1832         {
1833             get { return _instance; }
1834         }
1835
1836         private bool BitlyValidation(string id, string apikey)
1837         {
1838             if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(apikey))
1839             {
1840                 return false;
1841             }
1842
1843             string req = "http://api.bit.ly/v3/validate";
1844             string content = "";
1845             Dictionary<string, string> param = new Dictionary<string, string>();
1846
1847             param.Add("login", ApplicationSettings.BitlyLoginId);
1848             param.Add("apiKey", ApplicationSettings.BitlyApiKey);
1849             param.Add("x_login", id);
1850             param.Add("x_apiKey", apikey);
1851             param.Add("format", "txt");
1852
1853             if (!(new HttpVarious()).PostData(req, param, out content))
1854             {
1855                 return true;             // 通信エラーの場合はとりあえずチェックを通ったことにする
1856             }
1857             else if (content.Trim() == "1")
1858             {
1859                 return true;             // 検証成功
1860             }
1861             else if (content.Trim() == "0")
1862             {
1863                 return false;            // 検証失敗 APIキーとIDの組み合わせが違う
1864             }
1865             else
1866             {
1867                 return true;             // 規定外応答:通信エラーの可能性があるためとりあえずチェックを通ったことにする
1868             }
1869         }
1870
1871         private void Cancel_Click(object sender, EventArgs e)
1872         {
1873             _ValidationError = false;
1874         }
1875
1876         public bool HotkeyEnabled;
1877         public Keys HotkeyKey;
1878         public int HotkeyValue;
1879         public Keys HotkeyMod;
1880
1881         private void HotkeyText_KeyDown(object sender, KeyEventArgs e)
1882         {
1883             //KeyValueで判定する。
1884             //表示文字とのテーブルを用意すること
1885             HotkeyText.Text = e.KeyCode.ToString();
1886             HotkeyCode.Text = e.KeyValue.ToString();
1887             HotkeyText.Tag = e.KeyCode;
1888             e.Handled = true;
1889             e.SuppressKeyPress = true;
1890         }
1891
1892         private void HotkeyCheck_CheckedChanged(object sender, EventArgs e)
1893         {
1894             HotkeyCtrl.Enabled = HotkeyCheck.Checked;
1895             HotkeyAlt.Enabled = HotkeyCheck.Checked;
1896             HotkeyShift.Enabled = HotkeyCheck.Checked;
1897             HotkeyWin.Enabled = HotkeyCheck.Checked;
1898             HotkeyText.Enabled = HotkeyCheck.Checked;
1899             HotkeyCode.Enabled = HotkeyCheck.Checked;
1900         }
1901
1902         public bool BlinkNewMentions;
1903
1904         private void GetMoreTextCountApi_Validating(object sender, CancelEventArgs e)
1905         {
1906             int cnt;
1907             try
1908             {
1909                 cnt = int.Parse(GetMoreTextCountApi.Text);
1910             }
1911             catch(Exception)
1912             {
1913                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1914                 e.Cancel = true;
1915                 return;
1916             }
1917
1918             if (cnt != 0 && (cnt < 20 || cnt > 200))
1919             {
1920                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1921                 e.Cancel = true;
1922                 return;
1923             }
1924         }
1925
1926         private void UseChangeGetCount_CheckedChanged(object sender, EventArgs e)
1927         {
1928             GetMoreTextCountApi.Enabled = UseChangeGetCount.Checked;
1929             FirstTextCountApi.Enabled = UseChangeGetCount.Checked;
1930             Label28.Enabled = UseChangeGetCount.Checked;
1931             Label30.Enabled = UseChangeGetCount.Checked;
1932             Label53.Enabled = UseChangeGetCount.Checked;
1933             Label66.Enabled = UseChangeGetCount.Checked;
1934             Label17.Enabled = UseChangeGetCount.Checked;
1935             Label25.Enabled = UseChangeGetCount.Checked;
1936             SearchTextCountApi.Enabled = UseChangeGetCount.Checked;
1937             FavoritesTextCountApi.Enabled = UseChangeGetCount.Checked;
1938             UserTimelineTextCountApi.Enabled = UseChangeGetCount.Checked;
1939             ListTextCountApi.Enabled = UseChangeGetCount.Checked;
1940         }
1941
1942         private void FirstTextCountApi_Validating(object sender, CancelEventArgs e)
1943         {
1944             int cnt;
1945             try
1946             {
1947                 cnt = int.Parse(FirstTextCountApi.Text);
1948             }
1949             catch(Exception)
1950             {
1951                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1952                 e.Cancel = true;
1953                 return;
1954             }
1955
1956             if (cnt != 0 && (cnt < 20 || cnt > 200))
1957             {
1958                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1959                 e.Cancel = true;
1960                 return;
1961             }
1962         }
1963
1964         private void SearchTextCountApi_Validating(object sender, CancelEventArgs e)
1965         {
1966             int cnt;
1967             try
1968             {
1969                 cnt = int.Parse(SearchTextCountApi.Text);
1970             }
1971             catch (Exception)
1972             {
1973                 MessageBox.Show(Properties.Resources.TextSearchCountApi_Validating1);
1974                 e.Cancel = true;
1975                 return;
1976             }
1977
1978             if (cnt != 0 && (cnt < 20 || cnt > 100))
1979             {
1980                 MessageBox.Show(Properties.Resources.TextSearchCountApi_Validating1);
1981                 e.Cancel = true;
1982                 return;
1983             }
1984         }
1985
1986         private void FavoritesTextCountApi_Validating(object sender, CancelEventArgs e)
1987         {
1988             int cnt;
1989             try
1990             {
1991                 cnt = int.Parse(FavoritesTextCountApi.Text);
1992             }
1993             catch (Exception)
1994             {
1995                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
1996                 e.Cancel = true;
1997                 return;
1998             }
1999
2000             if (cnt != 0 && (cnt < 20 || cnt > 200))
2001             {
2002                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
2003                 e.Cancel = true;
2004                 return;
2005             }
2006         }
2007
2008         private void UserTimelineTextCountApi_Validating(object sender, CancelEventArgs e)
2009         {
2010             int cnt;
2011             try
2012             {
2013                 cnt = int.Parse(UserTimelineTextCountApi.Text);
2014             }
2015             catch (Exception)
2016             {
2017                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
2018                 e.Cancel = true;
2019                 return;
2020             }
2021
2022             if (cnt != 0 && (cnt < 20 || cnt > 200))
2023             {
2024                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
2025                 e.Cancel = true;
2026                 return;
2027             }
2028         }
2029
2030         private void ListTextCountApi_Validating(object sender, CancelEventArgs e)
2031         {
2032             int cnt;
2033             try
2034             {
2035                 cnt = int.Parse(ListTextCountApi.Text);
2036             }
2037             catch (Exception)
2038             {
2039                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
2040                 e.Cancel = true;
2041                 return;
2042             }
2043
2044             if (cnt != 0 && (cnt < 20 || cnt > 200))
2045             {
2046                 MessageBox.Show(Properties.Resources.TextCountApi_Validating1);
2047                 e.Cancel = true;
2048                 return;
2049             }
2050         }
2051
2052         //private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
2053         //                Handles CheckEventNotify.CheckedChanged, CheckFavoritesEvent.CheckStateChanged,
2054         //                        CheckUnfavoritesEvent.CheckStateChanged, CheckFollowEvent.CheckStateChanged,
2055         //                        CheckListMemberAddedEvent.CheckStateChanged, CheckListMemberRemovedEvent.CheckStateChanged,
2056         //                        CheckListCreatedEvent.CheckStateChanged, CheckUserUpdateEvent.CheckStateChanged
2057         //{
2058         //    EventNotifyEnabled = CheckEventNotify.Checked;
2059         //    GetEventNotifyFlag(EventNotifyFlag, IsMyEventNotifyFlag);
2060         //    ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
2061         //}
2062
2063         private class EventCheckboxTblElement
2064         {
2065             public CheckBox CheckBox;
2066             public MyCommon.EVENTTYPE Type;
2067         }
2068
2069         private EventCheckboxTblElement[] GetEventCheckboxTable()
2070         {
2071             EventCheckboxTblElement[] _eventCheckboxTable = new EventCheckboxTblElement[8];
2072
2073             _eventCheckboxTable[0] = new EventCheckboxTblElement();
2074             _eventCheckboxTable[0].CheckBox = CheckFavoritesEvent;
2075             _eventCheckboxTable[0].Type = MyCommon.EVENTTYPE.Favorite;
2076
2077             _eventCheckboxTable[1] = new EventCheckboxTblElement();
2078             _eventCheckboxTable[1].CheckBox = CheckUnfavoritesEvent;
2079             _eventCheckboxTable[1].Type = MyCommon.EVENTTYPE.Unfavorite;
2080
2081             _eventCheckboxTable[2] = new EventCheckboxTblElement();
2082             _eventCheckboxTable[2].CheckBox = CheckFollowEvent;
2083             _eventCheckboxTable[2].Type = MyCommon.EVENTTYPE.Follow;
2084
2085             _eventCheckboxTable[3] = new EventCheckboxTblElement();
2086             _eventCheckboxTable[3].CheckBox = CheckListMemberAddedEvent;
2087             _eventCheckboxTable[3].Type = MyCommon.EVENTTYPE.ListMemberAdded;
2088
2089             _eventCheckboxTable[4] = new EventCheckboxTblElement();
2090             _eventCheckboxTable[4].CheckBox = CheckListMemberRemovedEvent;
2091             _eventCheckboxTable[4].Type = MyCommon.EVENTTYPE.ListMemberRemoved;
2092
2093             _eventCheckboxTable[5] = new EventCheckboxTblElement();
2094             _eventCheckboxTable[5].CheckBox = CheckBlockEvent;
2095             _eventCheckboxTable[5].Type = MyCommon.EVENTTYPE.Block;
2096
2097             _eventCheckboxTable[6] = new EventCheckboxTblElement();
2098             _eventCheckboxTable[6].CheckBox = CheckUserUpdateEvent;
2099             _eventCheckboxTable[6].Type = MyCommon.EVENTTYPE.UserUpdate;
2100
2101             _eventCheckboxTable[7] = new EventCheckboxTblElement();
2102             _eventCheckboxTable[7].CheckBox = CheckListCreatedEvent;
2103             _eventCheckboxTable[7].Type = MyCommon.EVENTTYPE.ListCreated;
2104
2105             return _eventCheckboxTable;
2106         }
2107
2108         private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
2109         {
2110             MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
2111             MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
2112
2113             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
2114             {
2115                 switch (tbl.CheckBox.CheckState)
2116                 {
2117                     case CheckState.Checked:
2118                         evt = evt | tbl.Type;
2119                         myevt = myevt | tbl.Type;
2120                         break;
2121                     case CheckState.Indeterminate:
2122                         evt = evt | tbl.Type;
2123                         break;
2124                     case CheckState.Unchecked:
2125                         break;
2126                 }
2127             }
2128             eventnotifyflag = evt;
2129             isMyeventnotifyflag = myevt;
2130         }
2131
2132         private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
2133         {
2134             MyCommon.EVENTTYPE evt = eventnotifyflag;
2135             MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
2136
2137             CheckEventNotify.Checked = rootEnabled;
2138
2139             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
2140             {
2141                 if ((evt & tbl.Type) != 0)
2142                 {
2143                     if ((myevt & tbl.Type) != 0)
2144                     {
2145                         tbl.CheckBox.CheckState = CheckState.Checked;
2146                     }
2147                     else
2148                     {
2149                         tbl.CheckBox.CheckState = CheckState.Indeterminate;
2150                     }
2151                 }
2152                 else
2153                 {
2154                     tbl.CheckBox.CheckState = CheckState.Unchecked;
2155                 }
2156                 tbl.CheckBox.Enabled = rootEnabled;
2157             }
2158
2159         }
2160
2161         private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
2162         {
2163             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
2164             {
2165                 tbl.CheckBox.Enabled = CheckEventNotify.Checked;
2166             }
2167         }
2168
2169         //private void CheckForceEventNotify_CheckedChanged(object sender, EventArgs e)
2170         //{
2171         //    _MyForceEventNotify = CheckEventNotify.Checked;
2172         //}
2173
2174         //private void CheckFavEventUnread_CheckedChanged(object sender, EventArgs e)
2175         //{
2176         //    _MyFavEventUnread = CheckFavEventUnread.Checked;
2177         //}
2178
2179         //private void ComboBoxTranslateLanguage_SelectedIndexChanged(object sender, EventArgs e)
2180         //{
2181         //    _MyTranslateLanguage = (new Google()).GetLanguageEnumFromIndex(ComboBoxTranslateLanguage.SelectedIndex);
2182         //}
2183
2184         private void SoundFileListup()
2185         {
2186             if (EventSoundFile == null) EventSoundFile = "";
2187             ComboBoxEventNotifySound.Items.Clear();
2188             ComboBoxEventNotifySound.Items.Add("");
2189             DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
2190             if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
2191             {
2192                 oDir = oDir.GetDirectories("Sounds")[0];
2193             }
2194             foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
2195             {
2196                 ComboBoxEventNotifySound.Items.Add(oFile.Name);
2197             }
2198             int idx = ComboBoxEventNotifySound.Items.IndexOf(EventSoundFile);
2199             if (idx == -1) idx = 0;
2200             ComboBoxEventNotifySound.SelectedIndex = idx;
2201         }
2202
2203         //private void ComboBoxEventNotifySound_VisibleChanged(object sender, EventArgs e)
2204         //{
2205         //    SoundFileListup();
2206         //}
2207
2208         //private void ComboBoxEventNotifySound_SelectedIndexChanged(object sender, EventArgs e)
2209         //{
2210         //   if (_soundfileListup) return;
2211
2212         //    _MyEventSoundFile = (string)ComboBoxEventNotifySound.SelectedItem;
2213         //}
2214
2215         private void UserAppointUrlText_Validating(object sender, CancelEventArgs e)
2216         {
2217             if (!UserAppointUrlText.Text.StartsWith("http") && !string.IsNullOrEmpty(UserAppointUrlText.Text))
2218             {
2219                 MessageBox.Show("Text Error:正しいURLではありません");
2220             }
2221         }
2222
2223         private void OpenUrl(string url)
2224         {
2225             string myPath = url;
2226             string path = this.BrowserPathText.Text;
2227             try
2228             {
2229                 if (!string.IsNullOrEmpty(BrowserPath))
2230                 {
2231                     if (path.StartsWith("\"") && path.Length > 2 && path.IndexOf("\"", 2) > -1)
2232                     {
2233                         int sep = path.IndexOf("\"", 2);
2234                         string browserPath = path.Substring(1, sep - 1);
2235                         string arg = "";
2236                         if (sep < path.Length - 1)
2237                         {
2238                             arg = path.Substring(sep + 1);
2239                         }
2240                         myPath = arg + " " + myPath;
2241                         System.Diagnostics.Process.Start(browserPath, myPath);
2242                     }
2243                     else
2244                     {
2245                         System.Diagnostics.Process.Start(path, myPath);
2246                     }
2247                 }
2248                 else
2249                 {
2250                     System.Diagnostics.Process.Start(myPath);
2251                 }
2252             }
2253             catch(Exception)
2254             {
2255 //              MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
2256             }
2257         }
2258
2259         private void CreateAccountButton_Click(object sender, EventArgs e)
2260         {
2261             this.OpenUrl("https://twitter.com/signup");
2262         }
2263
2264         private void CheckAutoConvertUrl_CheckedChanged(object sender, EventArgs e)
2265         {
2266             ShortenTcoCheck.Enabled = CheckAutoConvertUrl.Checked;
2267         }
2268
2269         public AppendSettingDialog()
2270         {
2271             InitializeComponent();
2272
2273             this.Icon = Properties.Resources.MIcon;
2274         }
2275     }
2276 }