OSDN Git Service

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