OSDN Git Service

FontPanelに対する設定値の設定・取得を LoadConfing/SaveConfig メソッドに移動
[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.Api;
39 using OpenTween.Connection;
40 using OpenTween.Thumbnail;
41 using System.Threading.Tasks;
42 using OpenTween.Setting.Panel;
43
44 namespace OpenTween
45 {
46     public partial class AppendSettingDialog : OTBaseForm
47     {
48         private static AppendSettingDialog _instance = new AppendSettingDialog();
49         private Twitter tw;
50         private ProxyType _MyProxyType;
51
52         private bool _ValidationError = false;
53         private MyCommon.EVENTTYPE _MyEventNotifyFlag;
54         private MyCommon.EVENTTYPE _isMyEventNotifyFlag;
55         private string _MyTranslateLanguage;
56
57         public bool EnableImgAzyobuziNet { get; set; }
58         public bool ImgAzyobuziNetDisabledInDM { get; set; }
59         public MapProvider MapThumbnailProvider;
60         public int MapThumbnailHeight;
61         public int MapThumbnailWidth;
62         public int MapThumbnailZoom;
63         public List<UserAccount> UserAccounts;
64         private long? InitialUserId;
65         public bool IsRemoveSameEvent;
66         public bool IsNotifyUseGrowl;
67
68         public TwitterConfiguration TwitterConfiguration = TwitterConfiguration.DefaultConfiguration();
69
70         private string _pin;
71
72         public event EventHandler<IntervalChangedEventArgs> IntervalChanged;
73
74         public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
75         {
76             this.GetPeriodPanel.LoadConfig(settingCommon);
77             this.StartupPanel.LoadConfig(settingCommon);
78             this.TweetPrvPanel.LoadConfig(settingCommon);
79             this.TweetActPanel.LoadConfig(settingCommon, settingLocal);
80             this.ActionPanel.LoadConfig(settingCommon, settingLocal);
81             this.FontPanel.LoadConfig(settingLocal);
82         }
83
84         public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
85         {
86             this.GetPeriodPanel.SaveConfig(settingCommon);
87             this.StartupPanel.SaveConfig(settingCommon);
88             this.TweetPrvPanel.SaveConfig(settingCommon);
89             this.TweetActPanel.SaveConfig(settingCommon, settingLocal);
90             this.ActionPanel.SaveConfig(settingCommon, settingLocal);
91             this.FontPanel.SaveConfig(settingLocal);
92         }
93
94         private void TreeViewSetting_BeforeSelect(object sender, TreeViewCancelEventArgs e)
95         {
96             if (this.TreeViewSetting.SelectedNode == null) return;
97             var pnl = (SettingPanelBase)this.TreeViewSetting.SelectedNode.Tag;
98             if (pnl == null) return;
99             pnl.Enabled = false;
100             pnl.Visible = false;
101         }
102
103         private void TreeViewSetting_AfterSelect(object sender, TreeViewEventArgs e)
104         {
105             if (e.Node == null) return;
106             var pnl = (SettingPanelBase)e.Node.Tag;
107             if (pnl == null) return;
108             pnl.Enabled = true;
109             pnl.Visible = true;
110
111             if (pnl.Name == "PreviewPanel")
112             {
113                 if (GrowlHelper.IsDllExists)
114                 {
115                     this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = true;
116                 }
117                 else
118                 {
119                     this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = false;
120                 }
121             }
122         }
123
124         private void Save_Click(object sender, EventArgs e)
125         {
126             if (MyCommon.IsNetworkAvailable() &&
127                 (this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
128             {
129                 // bit.ly 短縮機能実装のプライバシー問題の暫定対応
130                 // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
131                 // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
132                 if (string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyId.Text) || string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyPw.Text))
133                 {
134                     MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
135                     _ValidationError = true;
136                     TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
137                     TreeViewSetting.Select();
138                     this.ShortUrlPanel.TextBitlyId.Focus();
139                     return;
140                 }
141
142                 if (!BitlyValidation(this.ShortUrlPanel.TextBitlyId.Text, this.ShortUrlPanel.TextBitlyPw.Text))
143                 {
144                     MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
145                     _ValidationError = true;
146                     TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
147                     TreeViewSetting.Select();
148                     this.ShortUrlPanel.TextBitlyId.Focus();
149                     return;
150                 }
151                 else
152                 {
153                     _ValidationError = false;
154                 }
155             }
156             else
157             {
158                 _ValidationError = false;
159             }
160
161             this.UserAccounts.Clear();
162             foreach (object u in this.BasedPanel.AuthUserCombo.Items)
163             {
164                 this.UserAccounts.Add((UserAccount)u);
165             }
166             if (this.BasedPanel.AuthUserCombo.SelectedIndex > -1)
167             {
168                 foreach (UserAccount u in this.UserAccounts)
169                 {
170                     if (u.Username.ToLower() == ((UserAccount)this.BasedPanel.AuthUserCombo.SelectedItem).Username.ToLower())
171                     {
172                         tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
173                         if (u.UserId == 0)
174                         {
175                             tw.VerifyCredentials();
176                             u.UserId = tw.UserId;
177                         }
178                         break;
179                     }
180                 }
181             }
182             else
183             {
184                 tw.ClearAuthInfo();
185                 tw.Initialize("", "", "", 0);
186             }
187
188 #if UA
189             //フォロー
190             if (this.FollowCheckBox.Checked)
191             {
192                 //現在の設定内容で通信
193                 HttpConnection.ProxyType ptype;
194                 if (RadioProxyNone.Checked)
195                 {
196                     ptype = HttpConnection.ProxyType.None;
197                 }
198                 else if (RadioProxyIE.Checked)
199                 {
200                     ptype = HttpConnection.ProxyType.IE;
201                 }
202                 else
203                 {
204                     ptype = HttpConnection.ProxyType.Specified;
205                 }
206                 string padr = TextProxyAddress.Text.Trim();
207                 int pport = int.Parse(TextProxyPort.Text.Trim());
208                 string pusr = TextProxyUser.Text.Trim();
209                 string ppw = TextProxyPassword.Text.Trim();
210                 HttpConnection.InitializeConnection(20, ptype, padr, pport, pusr, ppw);
211
212                 string ret = tw.PostFollowCommand(ApplicationSettings.FeedbackTwitterName);
213             }
214 #endif
215             try
216             {
217                 ColorSelf = this.FontPanel2.lblSelf.BackColor;
218                 ColorAtSelf = this.FontPanel2.lblAtSelf.BackColor;
219                 ColorTarget = this.FontPanel2.lblTarget.BackColor;
220                 ColorAtTarget = this.FontPanel2.lblAtTarget.BackColor;
221                 ColorAtFromTarget = this.FontPanel2.lblAtFromTarget.BackColor;
222                 ColorAtTo = this.FontPanel2.lblAtTo.BackColor;
223                 ColorInputBackcolor = this.FontPanel2.lblInputBackcolor.BackColor;
224                 ColorInputFont = this.FontPanel2.lblInputFont.ForeColor;
225                 ColorListBackcolor = this.FontPanel2.lblListBackcolor.BackColor;
226                 FontInputFont = this.FontPanel2.lblInputFont.Font;
227                 switch (this.PreviewPanel.cmbNameBalloon.SelectedIndex)
228                 {
229                     case 0:
230                         NameBalloon = MyCommon.NameBalloonEnum.None;
231                         break;
232                     case 1:
233                         NameBalloon = MyCommon.NameBalloonEnum.UserID;
234                         break;
235                     case 2:
236                         NameBalloon = MyCommon.NameBalloonEnum.NickName;
237                         break;
238                 }
239
240                 CountApi = int.Parse(this.GetCountPanel.TextCountApi.Text);
241                 CountApiReply = int.Parse(this.GetCountPanel.TextCountApiReply.Text);
242                 DispUsername = this.PreviewPanel.CheckDispUsername.Checked;
243                 switch (this.PreviewPanel.ComboDispTitle.SelectedIndex)
244                 {
245                     case 0:  //None
246                         DispLatestPost = MyCommon.DispTitleEnum.None;
247                         break;
248                     case 1:  //Ver
249                         DispLatestPost = MyCommon.DispTitleEnum.Ver;
250                         break;
251                     case 2:  //Post
252                         DispLatestPost = MyCommon.DispTitleEnum.Post;
253                         break;
254                     case 3:  //RepCount
255                         DispLatestPost = MyCommon.DispTitleEnum.UnreadRepCount;
256                         break;
257                     case 4:  //AllCount
258                         DispLatestPost = MyCommon.DispTitleEnum.UnreadAllCount;
259                         break;
260                     case 5:  //Rep+All
261                         DispLatestPost = MyCommon.DispTitleEnum.UnreadAllRepCount;
262                         break;
263                     case 6:  //Unread/All
264                         DispLatestPost = MyCommon.DispTitleEnum.UnreadCountAllCount;
265                         break;
266                     case 7: //Count of Status/Follow/Follower
267                         DispLatestPost = MyCommon.DispTitleEnum.OwnStatus;
268                         break;
269                 }
270                 TinyUrlResolve = this.ShortUrlPanel.CheckTinyURL.Checked;
271                 ShortUrl.Instance.DisableExpanding = !TinyUrlResolve;
272                 if (this.ProxyPanel.RadioProxyNone.Checked)
273                 {
274                     _MyProxyType = ProxyType.None;
275                 }
276                 else if (this.ProxyPanel.RadioProxyIE.Checked)
277                 {
278                     _MyProxyType = ProxyType.IE;
279                 }
280                 else
281                 {
282                     _MyProxyType = ProxyType.Specified;
283                 }
284                 ProxyAddress = this.ProxyPanel.TextProxyAddress.Text.Trim();
285                 ProxyPort = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
286                 ProxyUser = this.ProxyPanel.TextProxyUser.Text.Trim();
287                 ProxyPassword = this.ProxyPanel.TextProxyPassword.Text.Trim();
288                 AlwaysTop = this.PreviewPanel.CheckAlwaysTop.Checked;
289                 UrlConvertAuto = this.ShortUrlPanel.CheckAutoConvertUrl.Checked;
290                 ShortenTco = this.ShortUrlPanel.ShortenTcoCheck.Checked;
291
292                 Nicoms = this.CooperatePanel.CheckNicoms.Checked;
293                 DefaultTimeOut = int.Parse(this.ConnectionPanel.ConnectionTimeOut.Text);
294                 LimitBalloon = this.PreviewPanel.CheckBalloonLimit.Checked;
295                 EventNotifyEnabled = this.NotifyPanel.CheckEventNotify.Checked;
296                 GetEventNotifyFlag(ref _MyEventNotifyFlag, ref _isMyEventNotifyFlag);
297                 ForceEventNotify = this.NotifyPanel.CheckForceEventNotify.Checked;
298                 FavEventUnread = this.NotifyPanel.CheckFavEventUnread.Checked;
299                 TranslateLanguage = Bing.GetLanguageEnumFromIndex(this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex);
300                 EventSoundFile = (string)this.NotifyPanel.ComboBoxEventNotifySound.SelectedItem;
301                 AutoShortUrlFirst = (MyCommon.UrlConverter)this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex;
302                 TabIconDisp = this.PreviewPanel.chkTabIconDisp.Checked;
303                 IsMonospace = this.PreviewPanel.CheckMonospace.Checked;
304                 BitlyUser = this.ShortUrlPanel.TextBitlyId.Text;
305                 BitlyPwd = this.ShortUrlPanel.TextBitlyPw.Text;
306                 PreviewEnable = this.PreviewPanel.CheckPreviewEnable.Checked;
307                 StatusAreaAtBottom = this.PreviewPanel.CheckStatusAreaAtBottom.Checked;
308                 TwitterApiUrl = this.ConnectionPanel.TwitterAPIText.Text.Trim();
309                 switch (this.PreviewPanel.ReplyIconStateCombo.SelectedIndex)
310                 {
311                     case 0:
312                         ReplyIconState = MyCommon.REPLY_ICONSTATE.None;
313                         break;
314                     case 1:
315                         ReplyIconState = MyCommon.REPLY_ICONSTATE.StaticIcon;
316                         break;
317                     case 2:
318                         ReplyIconState = MyCommon.REPLY_ICONSTATE.BlinkIcon;
319                         break;
320                 }
321                 switch (this.PreviewPanel.LanguageCombo.SelectedIndex)
322                 {
323                     case 0:
324                         Language = "OS";
325                         break;
326                     case 1:
327                         Language = "ja";
328                         break;
329                     case 2:
330                         Language = "en";
331                         break;
332                     case 3:
333                         Language = "zh-CN";
334                         break;
335                     default:
336                         Language = "en";
337                         break;
338                 }
339                 BlinkNewMentions = this.PreviewPanel.ChkNewMentionsBlink.Checked;
340                 UseAdditionalCount = this.GetCountPanel.UseChangeGetCount.Checked;
341                 MoreCountApi = int.Parse(this.GetCountPanel.GetMoreTextCountApi.Text);
342                 FirstCountApi = int.Parse(this.GetCountPanel.FirstTextCountApi.Text);
343                 SearchCountApi = int.Parse(this.GetCountPanel.SearchTextCountApi.Text);
344                 FavoritesCountApi = int.Parse(this.GetCountPanel.FavoritesTextCountApi.Text);
345                 UserTimelineCountApi = int.Parse(this.GetCountPanel.UserTimelineTextCountApi.Text);
346                 ListCountApi = int.Parse(this.GetCountPanel.ListTextCountApi.Text);
347                 UserAppointUrl = this.CooperatePanel.UserAppointUrlText.Text;
348                 this.EnableImgAzyobuziNet = this.CooperatePanel.EnableImgAzyobuziNetCheckBox.Checked;
349                 this.ImgAzyobuziNetDisabledInDM = this.CooperatePanel.ImgAzyobuziNetDisabledInDMCheckBox.Checked;
350                 this.MapThumbnailProvider = (MapProvider)this.CooperatePanel.MapThumbnailProviderComboBox.SelectedIndex;
351                 this.MapThumbnailHeight = int.Parse(this.CooperatePanel.MapThumbnailHeightTextBox.Text);
352                 this.MapThumbnailWidth = int.Parse(this.CooperatePanel.MapThumbnailWidthTextBox.Text);
353                 this.MapThumbnailZoom = int.Parse(this.CooperatePanel.MapThumbnailZoomTextBox.Text);
354                 this.IsRemoveSameEvent = this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked;
355                 this.IsNotifyUseGrowl = this.PreviewPanel.IsNotifyUseGrowlCheckBox.Checked;
356             }
357             catch(Exception)
358             {
359                 MessageBox.Show(Properties.Resources.Save_ClickText3);
360                 this.DialogResult = DialogResult.Cancel;
361                 return;
362             }
363         }
364
365         private void Setting_FormClosing(object sender, FormClosingEventArgs e)
366         {
367             if (MyCommon._endingFlag) return;
368
369             if (this.DialogResult == DialogResult.Cancel)
370             {
371                 //キャンセル時は画面表示時のアカウントに戻す
372                 //キャンセル時でも認証済みアカウント情報は保存する
373                 this.UserAccounts.Clear();
374                 foreach (object u in this.BasedPanel.AuthUserCombo.Items)
375                 {
376                     this.UserAccounts.Add((UserAccount)u);
377                 }
378                 //アクティブユーザーを起動時のアカウントに戻す(起動時アカウントなければ何もしない)
379                 bool userSet = false;
380                 if (this.InitialUserId != null)
381                 {
382                     foreach (UserAccount u in this.UserAccounts)
383                     {
384                         if (u.UserId == this.InitialUserId)
385                         {
386                             tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
387                             userSet = true;
388                             break;
389                         }
390                     }
391                 }
392                 //認証済みアカウントが削除されていた場合、もしくは起動時アカウントがなかった場合は、
393                 //アクティブユーザーなしとして初期化
394                 if (!userSet)
395                 {
396                     tw.ClearAuthInfo();
397                     tw.Initialize("", "", "", 0);
398                 }
399             }
400
401             if (tw != null && string.IsNullOrEmpty(tw.Username) && e.CloseReason == CloseReason.None)
402             {
403                 if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
404                 {
405                     e.Cancel = true;
406                 }
407             }
408             if (_ValidationError)
409             {
410                 e.Cancel = true;
411             }
412             if (e.Cancel == false && TreeViewSetting.SelectedNode != null)
413             {
414                 var curPanel = (SettingPanelBase)TreeViewSetting.SelectedNode.Tag;
415                 curPanel.Visible = false;
416                 curPanel.Enabled = false;
417             }
418         }
419
420         private void Setting_Load(object sender, EventArgs e)
421         {
422             tw = ((TweenMain)this.Owner).TwitterInstance;
423             //this.AuthStateLabel.Enabled = true;
424             //this.AuthUserLabel.Enabled = true;
425             this.BasedPanel.AuthClearButton.Enabled = true;
426
427             //if (tw.Username == "")
428             //{
429             //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4
430             //    //this.AuthUserLabel.Text = ""
431             //    //this.Save.Enabled = false
432             //}
433             //else
434             //{
435             //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
436             //    //if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWrite)
437             //    //{
438             //    //    this.AuthStateLabel.Text += "(xAuth)";
439             //    //}
440             //    //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
441             //    //{
442             //    //    this.AuthStateLabel.Text += "(OAuth)";
443             //    //}
444             //    //this.AuthUserLabel.Text = tw.Username;
445             //}
446
447             this.BasedPanel.AuthUserCombo.Items.Clear();
448             if (this.UserAccounts.Count > 0)
449             {
450                 this.BasedPanel.AuthUserCombo.Items.AddRange(this.UserAccounts.ToArray());
451                 foreach (UserAccount u in this.UserAccounts)
452                 {
453                     if (u.UserId == tw.UserId)
454                     {
455                         this.BasedPanel.AuthUserCombo.SelectedItem = u;
456                         this.InitialUserId = u.UserId;
457                         break;
458                     }
459                 }
460             }
461
462             this.FontPanel2.lblSelf.BackColor = ColorSelf;
463             this.FontPanel2.lblAtSelf.BackColor = ColorAtSelf;
464             this.FontPanel2.lblTarget.BackColor = ColorTarget;
465             this.FontPanel2.lblAtTarget.BackColor = ColorAtTarget;
466             this.FontPanel2.lblAtFromTarget.BackColor = ColorAtFromTarget;
467             this.FontPanel2.lblAtTo.BackColor = ColorAtTo;
468             this.FontPanel2.lblInputBackcolor.BackColor = ColorInputBackcolor;
469             this.FontPanel2.lblInputFont.ForeColor = ColorInputFont;
470             this.FontPanel2.lblInputFont.Font = FontInputFont;
471             this.FontPanel2.lblListBackcolor.BackColor = ColorListBackcolor;
472
473             switch (NameBalloon)
474             {
475                 case MyCommon.NameBalloonEnum.None:
476                     this.PreviewPanel.cmbNameBalloon.SelectedIndex = 0;
477                     break;
478                 case MyCommon.NameBalloonEnum.UserID:
479                     this.PreviewPanel.cmbNameBalloon.SelectedIndex = 1;
480                     break;
481                 case MyCommon.NameBalloonEnum.NickName:
482                     this.PreviewPanel.cmbNameBalloon.SelectedIndex = 2;
483                     break;
484             }
485
486             this.GetCountPanel.TextCountApi.Text = CountApi.ToString();
487             this.GetCountPanel.TextCountApiReply.Text = CountApiReply.ToString();
488             this.PreviewPanel.CheckDispUsername.Checked = DispUsername;
489             switch (DispLatestPost)
490             {
491                 case MyCommon.DispTitleEnum.None:
492                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 0;
493                     break;
494                 case MyCommon.DispTitleEnum.Ver:
495                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 1;
496                     break;
497                 case MyCommon.DispTitleEnum.Post:
498                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 2;
499                     break;
500                 case MyCommon.DispTitleEnum.UnreadRepCount:
501                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 3;
502                     break;
503                 case MyCommon.DispTitleEnum.UnreadAllCount:
504                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 4;
505                     break;
506                 case MyCommon.DispTitleEnum.UnreadAllRepCount:
507                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 5;
508                     break;
509                 case MyCommon.DispTitleEnum.UnreadCountAllCount:
510                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 6;
511                     break;
512                 case MyCommon.DispTitleEnum.OwnStatus:
513                     this.PreviewPanel.ComboDispTitle.SelectedIndex = 7;
514                     break;
515             }
516             this.ShortUrlPanel.CheckTinyURL.Checked = TinyUrlResolve;
517             switch (_MyProxyType)
518             {
519                 case ProxyType.None:
520                     this.ProxyPanel.RadioProxyNone.Checked = true;
521                     break;
522                 case ProxyType.IE:
523                     this.ProxyPanel.RadioProxyIE.Checked = true;
524                     break;
525                 default:
526                     this.ProxyPanel.RadioProxySpecified.Checked = true;
527                     break;
528             }
529             bool chk = this.ProxyPanel.RadioProxySpecified.Checked;
530             this.ProxyPanel.LabelProxyAddress.Enabled = chk;
531             this.ProxyPanel.TextProxyAddress.Enabled = chk;
532             this.ProxyPanel.LabelProxyPort.Enabled = chk;
533             this.ProxyPanel.TextProxyPort.Enabled = chk;
534             this.ProxyPanel.LabelProxyUser.Enabled = chk;
535             this.ProxyPanel.TextProxyUser.Enabled = chk;
536             this.ProxyPanel.LabelProxyPassword.Enabled = chk;
537             this.ProxyPanel.TextProxyPassword.Enabled = chk;
538
539             this.ProxyPanel.TextProxyAddress.Text = ProxyAddress;
540             this.ProxyPanel.TextProxyPort.Text = ProxyPort.ToString();
541             this.ProxyPanel.TextProxyUser.Text = ProxyUser;
542             this.ProxyPanel.TextProxyPassword.Text = ProxyPassword;
543
544             this.PreviewPanel.CheckAlwaysTop.Checked = AlwaysTop;
545             this.ShortUrlPanel.CheckAutoConvertUrl.Checked = UrlConvertAuto;
546             this.ShortUrlPanel.ShortenTcoCheck.Checked = ShortenTco;
547             this.ShortUrlPanel.ShortenTcoCheck.Enabled = this.ShortUrlPanel.CheckAutoConvertUrl.Checked;
548
549             this.CooperatePanel.CheckNicoms.Checked = Nicoms;
550             this.ConnectionPanel.ConnectionTimeOut.Text = DefaultTimeOut.ToString();
551             this.PreviewPanel.CheckBalloonLimit.Checked = LimitBalloon;
552
553             ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
554             this.NotifyPanel.CheckForceEventNotify.Checked = ForceEventNotify;
555             this.NotifyPanel.CheckFavEventUnread.Checked = FavEventUnread;
556             this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex = Bing.GetIndexFromLanguageEnum(TranslateLanguage);
557             SoundFileListup();
558             this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex = (int)AutoShortUrlFirst;
559             this.PreviewPanel.chkTabIconDisp.Checked = TabIconDisp;
560             this.PreviewPanel.CheckMonospace.Checked = IsMonospace;
561             this.ShortUrlPanel.TextBitlyId.Text = BitlyUser;
562             this.ShortUrlPanel.TextBitlyPw.Text = BitlyPwd;
563             this.ShortUrlPanel.TextBitlyId.Modified = false;
564             this.ShortUrlPanel.TextBitlyPw.Modified = false;
565             this.PreviewPanel.CheckPreviewEnable.Checked = PreviewEnable;
566             this.PreviewPanel.CheckStatusAreaAtBottom.Checked = StatusAreaAtBottom;
567             this.ConnectionPanel.TwitterAPIText.Text = TwitterApiUrl;
568             switch (ReplyIconState)
569             {
570                 case MyCommon.REPLY_ICONSTATE.None:
571                     this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 0;
572                     break;
573                 case MyCommon.REPLY_ICONSTATE.StaticIcon:
574                     this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 1;
575                     break;
576                 case MyCommon.REPLY_ICONSTATE.BlinkIcon:
577                     this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 2;
578                     break;
579             }
580             switch (Language)
581             {
582                 case "OS":
583                     this.PreviewPanel.LanguageCombo.SelectedIndex = 0;
584                     break;
585                 case "ja":
586                     this.PreviewPanel.LanguageCombo.SelectedIndex = 1;
587                     break;
588                 case "en":
589                     this.PreviewPanel.LanguageCombo.SelectedIndex = 2;
590                     break;
591                 case "zh-CN":
592                     this.PreviewPanel.LanguageCombo.SelectedIndex = 3;
593                     break;
594                 default:
595                     this.PreviewPanel.LanguageCombo.SelectedIndex = 0;
596                     break;
597             }
598             this.PreviewPanel.ChkNewMentionsBlink.Checked = BlinkNewMentions;
599
600             this.GetCountPanel.GetMoreTextCountApi.Text = MoreCountApi.ToString();
601             this.GetCountPanel.FirstTextCountApi.Text = FirstCountApi.ToString();
602             this.GetCountPanel.SearchTextCountApi.Text = SearchCountApi.ToString();
603             this.GetCountPanel.FavoritesTextCountApi.Text = FavoritesCountApi.ToString();
604             this.GetCountPanel.UserTimelineTextCountApi.Text = UserTimelineCountApi.ToString();
605             this.GetCountPanel.ListTextCountApi.Text = ListCountApi.ToString();
606             this.GetCountPanel.UseChangeGetCount.Checked = UseAdditionalCount;
607             this.GetCountPanel.Label28.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
608             this.GetCountPanel.Label30.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
609             this.GetCountPanel.Label53.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
610             this.GetCountPanel.Label66.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
611             this.GetCountPanel.Label17.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
612             this.GetCountPanel.Label25.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
613             this.GetCountPanel.GetMoreTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
614             this.GetCountPanel.FirstTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
615             this.GetCountPanel.SearchTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
616             this.GetCountPanel.FavoritesTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
617             this.GetCountPanel.UserTimelineTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
618             this.GetCountPanel.ListTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
619             this.CooperatePanel.UserAppointUrlText.Text = UserAppointUrl;
620             this.CooperatePanel.EnableImgAzyobuziNetCheckBox.Checked = this.EnableImgAzyobuziNet;
621             this.CooperatePanel.ImgAzyobuziNetDisabledInDMCheckBox.Checked = this.ImgAzyobuziNetDisabledInDM;
622             this.CooperatePanel.MapThumbnailProviderComboBox.SelectedIndex = (int)this.MapThumbnailProvider;
623             this.CooperatePanel.MapThumbnailHeightTextBox.Text = this.MapThumbnailHeight.ToString();
624             this.CooperatePanel.MapThumbnailWidthTextBox.Text = this.MapThumbnailWidth.ToString();
625             this.CooperatePanel.MapThumbnailZoomTextBox.Text = this.MapThumbnailZoom.ToString();
626             this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked = this.IsRemoveSameEvent;
627             this.PreviewPanel.IsNotifyUseGrowlCheckBox.Checked = this.IsNotifyUseGrowl;
628
629             if (GrowlHelper.IsDllExists)
630             {
631                 this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = true;
632             }
633             else
634             {
635                 this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = false;
636             }
637
638             this.TreeViewSetting.Nodes["BasedNode"].Tag = BasedPanel;
639             this.TreeViewSetting.Nodes["BasedNode"].Nodes["PeriodNode"].Tag = GetPeriodPanel;
640             this.TreeViewSetting.Nodes["BasedNode"].Nodes["StartUpNode"].Tag = StartupPanel;
641             this.TreeViewSetting.Nodes["BasedNode"].Nodes["GetCountNode"].Tag = GetCountPanel;
642             //this.TreeViewSetting.Nodes["BasedNode"].Nodes["UserStreamNode"].Tag = UserStreamPanel;
643             this.TreeViewSetting.Nodes["ActionNode"].Tag = ActionPanel;
644             this.TreeViewSetting.Nodes["ActionNode"].Nodes["TweetActNode"].Tag = TweetActPanel;
645             this.TreeViewSetting.Nodes["PreviewNode"].Tag = PreviewPanel;
646             this.TreeViewSetting.Nodes["PreviewNode"].Nodes["TweetPrvNode"].Tag = TweetPrvPanel;
647             this.TreeViewSetting.Nodes["PreviewNode"].Nodes["NotifyNode"].Tag = NotifyPanel;
648             this.TreeViewSetting.Nodes["FontNode"].Tag = FontPanel;
649             this.TreeViewSetting.Nodes["FontNode"].Nodes["FontNode2"].Tag = FontPanel2;
650             this.TreeViewSetting.Nodes["ConnectionNode"].Tag = ConnectionPanel;
651             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ProxyNode"].Tag = ProxyPanel;
652             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["CooperateNode"].Tag = CooperatePanel;
653             this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"].Tag = ShortUrlPanel;
654
655             this.TreeViewSetting.SelectedNode = this.TreeViewSetting.Nodes[0];
656             this.TreeViewSetting.ExpandAll();
657
658             //TreeViewSetting.SelectedNode = TreeViewSetting.TopNode;
659             ActiveControl = BasedPanel.StartAuthButton;
660         }
661
662         private void UReadMng_CheckedChanged(object sender, EventArgs e)
663         {
664             if (this.ActionPanel.UReadMng.Checked == true)
665             {
666                 this.StartupPanel.StartupReaded.Enabled = true;
667             }
668             else
669             {
670                 this.StartupPanel.StartupReaded.Enabled = false;
671             }
672         }
673
674         private void btnFontAndColor_Click(object sender, EventArgs e) // Handles btnUnread.Click, btnDetail.Click, btnListFont.Click, btnInputFont.Click
675         {
676             Button Btn = (Button) sender;
677             DialogResult rtn;
678
679             FontDialog1.AllowVerticalFonts = false;
680             FontDialog1.AllowScriptChange = true;
681             FontDialog1.AllowSimulations = true;
682             FontDialog1.AllowVectorFonts = true;
683             FontDialog1.FixedPitchOnly = false;
684             FontDialog1.FontMustExist = true;
685             FontDialog1.ScriptsOnly = false;
686             FontDialog1.ShowApply = false;
687             FontDialog1.ShowEffects = true;
688             FontDialog1.ShowColor = true;
689
690             switch (Btn.Name)
691             {
692                 case "btnUnread":
693                     FontDialog1.Color = this.FontPanel.lblUnread.ForeColor;
694                     FontDialog1.Font = this.FontPanel.lblUnread.Font;
695                     break;
696                 case "btnDetail":
697                     FontDialog1.Color = this.FontPanel.lblDetail.ForeColor;
698                     FontDialog1.Font = this.FontPanel.lblDetail.Font;
699                     break;
700                 case "btnListFont":
701                     FontDialog1.Color = this.FontPanel.lblListFont.ForeColor;
702                     FontDialog1.Font = this.FontPanel.lblListFont.Font;
703                     break;
704                 case "btnInputFont":
705                     FontDialog1.Color = this.FontPanel2.lblInputFont.ForeColor;
706                     FontDialog1.Font = this.FontPanel2.lblInputFont.Font;
707                     break;
708             }
709
710             try
711             {
712                 rtn = FontDialog1.ShowDialog();
713             }
714             catch(ArgumentException ex)
715             {
716                 MessageBox.Show(ex.Message);
717                 return;
718             }
719
720             if (rtn == DialogResult.Cancel) return;
721
722             switch (Btn.Name)
723             {
724                 case "btnUnread":
725                     this.FontPanel.lblUnread.ForeColor = FontDialog1.Color;
726                     this.FontPanel.lblUnread.Font = FontDialog1.Font;
727                     break;
728                 case "btnDetail":
729                     this.FontPanel.lblDetail.ForeColor = FontDialog1.Color;
730                     this.FontPanel.lblDetail.Font = FontDialog1.Font;
731                     break;
732                 case "btnListFont":
733                     this.FontPanel.lblListFont.ForeColor = FontDialog1.Color;
734                     this.FontPanel.lblListFont.Font = FontDialog1.Font;
735                     break;
736                 case "btnInputFont":
737                     this.FontPanel2.lblInputFont.ForeColor = FontDialog1.Color;
738                     this.FontPanel2.lblInputFont.Font = FontDialog1.Font;
739                     break;
740             }
741
742         }
743
744         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
745         {
746             Button Btn = (Button)sender;
747             DialogResult rtn;
748
749             ColorDialog1.AllowFullOpen = true;
750             ColorDialog1.AnyColor = true;
751             ColorDialog1.FullOpen = false;
752             ColorDialog1.SolidColorOnly = false;
753
754             switch (Btn.Name)
755             {
756                 case "btnSelf":
757                     ColorDialog1.Color = this.FontPanel2.lblSelf.BackColor;
758                     break;
759                 case "btnAtSelf":
760                     ColorDialog1.Color = this.FontPanel2.lblAtSelf.BackColor;
761                     break;
762                 case "btnTarget":
763                     ColorDialog1.Color = this.FontPanel2.lblTarget.BackColor;
764                     break;
765                 case "btnAtTarget":
766                     ColorDialog1.Color = this.FontPanel2.lblAtTarget.BackColor;
767                     break;
768                 case "btnAtFromTarget":
769                     ColorDialog1.Color = this.FontPanel2.lblAtFromTarget.BackColor;
770                     break;
771                 case "btnFav":
772                     ColorDialog1.Color = this.FontPanel.lblFav.ForeColor;
773                     break;
774                 case "btnOWL":
775                     ColorDialog1.Color = this.FontPanel.lblOWL.ForeColor;
776                     break;
777                 case "btnRetweet":
778                     ColorDialog1.Color = this.FontPanel.lblRetweet.ForeColor;
779                     break;
780                 case "btnInputBackcolor":
781                     ColorDialog1.Color = this.FontPanel2.lblInputBackcolor.BackColor;
782                     break;
783                 case "btnAtTo":
784                     ColorDialog1.Color = this.FontPanel2.lblAtTo.BackColor;
785                     break;
786                 case "btnListBack":
787                     ColorDialog1.Color = this.FontPanel2.lblListBackcolor.BackColor;
788                     break;
789                 case "btnDetailBack":
790                     ColorDialog1.Color = this.FontPanel.lblDetailBackcolor.BackColor;
791                     break;
792                 case "btnDetailLink":
793                     ColorDialog1.Color = this.FontPanel.lblDetailLink.ForeColor;
794                     break;
795             }
796
797             rtn = ColorDialog1.ShowDialog();
798
799             if (rtn == DialogResult.Cancel) return;
800
801             switch (Btn.Name)
802             {
803                 case "btnSelf":
804                     this.FontPanel2.lblSelf.BackColor = ColorDialog1.Color;
805                     break;
806                 case "btnAtSelf":
807                     this.FontPanel2.lblAtSelf.BackColor = ColorDialog1.Color;
808                     break;
809                 case "btnTarget":
810                     this.FontPanel2.lblTarget.BackColor = ColorDialog1.Color;
811                     break;
812                 case "btnAtTarget":
813                     this.FontPanel2.lblAtTarget.BackColor = ColorDialog1.Color;
814                     break;
815                 case "btnAtFromTarget":
816                     this.FontPanel2.lblAtFromTarget.BackColor = ColorDialog1.Color;
817                     break;
818                 case "btnFav":
819                     this.FontPanel.lblFav.ForeColor = ColorDialog1.Color;
820                     break;
821                 case "btnOWL":
822                     this.FontPanel.lblOWL.ForeColor = ColorDialog1.Color;
823                     break;
824                 case "btnRetweet":
825                     this.FontPanel.lblRetweet.ForeColor = ColorDialog1.Color;
826                     break;
827                 case "btnInputBackcolor":
828                     this.FontPanel2.lblInputBackcolor.BackColor = ColorDialog1.Color;
829                     break;
830                 case "btnAtTo":
831                     this.FontPanel2.lblAtTo.BackColor = ColorDialog1.Color;
832                     break;
833                 case "btnListBack":
834                     this.FontPanel2.lblListBackcolor.BackColor = ColorDialog1.Color;
835                     break;
836                 case "btnDetailBack":
837                     this.FontPanel.lblDetailBackcolor.BackColor = ColorDialog1.Color;
838                     break;
839                 case "btnDetailLink":
840                     this.FontPanel.lblDetailLink.ForeColor = ColorDialog1.Color;
841                     break;
842             }
843         }
844
845         public Color ColorSelf { get; set; }
846         public Color ColorAtSelf { get; set; }
847         public Color ColorTarget { get; set; }
848         public Color ColorAtTarget { get; set; }
849         public Color ColorAtFromTarget { get; set; }
850         public Color ColorAtTo { get; set; }
851         public Color ColorInputBackcolor { get; set; }
852         public Color ColorInputFont { get; set; }
853         public Font FontInputFont { get; set; }
854         public Color ColorListBackcolor { get; set; }
855         public MyCommon.NameBalloonEnum NameBalloon { get; set; }
856         public int CountApi { get; set; }
857         public int CountApiReply { get; set; }
858         public int MoreCountApi { get; set; }
859         public int FirstCountApi { get; set; }
860         public int SearchCountApi { get; set; }
861         public int FavoritesCountApi { get; set; }
862         public int UserTimelineCountApi { get; set; }
863         public int ListCountApi { get; set; }
864         public string RecommendStatusText { get; set; }
865         public bool DispUsername { get; set; }
866         public MyCommon.DispTitleEnum DispLatestPost { get; set; }
867         public bool TinyUrlResolve { get; set; }
868
869         public ProxyType SelectedProxyType
870         {
871             get {
872                 return _MyProxyType;
873             }
874             set {
875                 _MyProxyType = value;
876             }
877         }
878
879         public string ProxyAddress { get; set; }
880         public int ProxyPort { get; set; }
881         public string ProxyUser { get; set; }
882         public string ProxyPassword { get; set; }
883         public bool AlwaysTop { get; set; }
884         public bool UrlConvertAuto { get; set; }
885         public bool ShortenTco { get; set; }
886         public bool Nicoms { get; set; }
887         public MyCommon.UrlConverter AutoShortUrlFirst { get; set; }
888         public int DefaultTimeOut { get; set; }
889         public bool TabIconDisp { get; set; }
890         public MyCommon.REPLY_ICONSTATE ReplyIconState { get; set; }
891         public bool IsMonospace { get; set; }
892         public string BitlyUser { get; set; }
893         public string BitlyPwd { get; set; }
894         public bool PreviewEnable { get; set; }
895         public bool StatusAreaAtBottom { get; set; }
896         public bool UseAdditionalCount { get; set; }
897         public string TwitterApiUrl { get; set; }
898         public string Language { get; set; }
899
900         public bool LimitBalloon { get; set; }
901         public bool EventNotifyEnabled { get; set; }
902
903         public MyCommon.EVENTTYPE EventNotifyFlag
904         {
905             get
906             {
907                 return _MyEventNotifyFlag;
908             }
909             set
910             {
911                 _MyEventNotifyFlag = value;
912             }
913         }
914
915         public MyCommon.EVENTTYPE IsMyEventNotifyFlag
916         {
917             get
918             {
919                 return _isMyEventNotifyFlag;
920             }
921             set
922             {
923                 _isMyEventNotifyFlag = value;
924             }
925         }
926
927         public bool ForceEventNotify { get; set; }
928         public bool FavEventUnread { get; set; }
929
930         public string TranslateLanguage
931         {
932             get
933             {
934                 return _MyTranslateLanguage;
935             }
936             set
937             {
938                 _MyTranslateLanguage = value;
939                 this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex = Bing.GetIndexFromLanguageEnum(value);
940             }
941         }
942
943         public string EventSoundFile { get; set; }
944         public string UserAppointUrl { get; set; }
945
946         private bool StartAuth()
947         {
948             //現在の設定内容で通信
949             ProxyType ptype;
950             if (this.ProxyPanel.RadioProxyNone.Checked)
951             {
952                 ptype = ProxyType.None;
953             }
954             else if (this.ProxyPanel.RadioProxyIE.Checked)
955             {
956                 ptype = ProxyType.IE;
957             }
958             else
959             {
960                 ptype = ProxyType.Specified;
961             }
962             string padr = this.ProxyPanel.TextProxyAddress.Text.Trim();
963             int pport = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
964             string pusr = this.ProxyPanel.TextProxyUser.Text.Trim();
965             string ppw = this.ProxyPanel.TextProxyPassword.Text.Trim();
966
967             //通信基底クラス初期化
968             Networking.DefaultTimeout = TimeSpan.FromSeconds(20);
969             Networking.SetWebProxy(ptype, padr, pport, pusr, ppw);
970             HttpTwitter.TwitterUrl = this.ConnectionPanel.TwitterAPIText.Text.Trim();
971             tw.Initialize("", "", "", 0);
972             //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
973             //this.AuthUserLabel.Text = "";
974             string pinPageUrl = "";
975             string rslt = tw.StartAuthentication(ref pinPageUrl);
976             if (string.IsNullOrEmpty(rslt))
977             {
978                 string pin = AuthDialog.DoAuth(this, pinPageUrl);
979                 if (!string.IsNullOrEmpty(pin))
980                 {
981                     this._pin = pin;
982                     return true;
983                 }
984                 else
985                 {
986                     return false;
987                 }
988             }
989             else
990             {
991                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
992                 return false;
993             }
994         }
995
996         private bool PinAuth()
997         {
998             string pin = this._pin;   //PIN Code
999
1000             string rslt = tw.Authenticate(pin);
1001             if (string.IsNullOrEmpty(rslt))
1002             {
1003                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click1, "Authenticate", MessageBoxButtons.OK);
1004                 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
1005                 //this.AuthUserLabel.Text = tw.Username;
1006                 int idx = -1;
1007                 UserAccount user = new UserAccount();
1008                 user.Username = tw.Username;
1009                 user.UserId = tw.UserId;
1010                 user.Token = tw.AccessToken;
1011                 user.TokenSecret = tw.AccessTokenSecret;
1012
1013                 foreach (object u in this.BasedPanel.AuthUserCombo.Items)
1014                 {
1015                     if (((UserAccount)u).Username.ToLower() == tw.Username.ToLower())
1016                     {
1017                         idx = this.BasedPanel.AuthUserCombo.Items.IndexOf(u);
1018                         break;
1019                     }
1020                 }
1021                 if (idx > -1)
1022                 {
1023                     this.BasedPanel.AuthUserCombo.Items.RemoveAt(idx);
1024                     this.BasedPanel.AuthUserCombo.Items.Insert(idx, user);
1025                     this.BasedPanel.AuthUserCombo.SelectedIndex = idx;
1026                 }
1027                 else
1028                 {
1029                     this.BasedPanel.AuthUserCombo.SelectedIndex = this.BasedPanel.AuthUserCombo.Items.Add(user);
1030                 }
1031                 //if (TwitterApiInfo.AccessLevel = ApiAccessLevel.ReadWrite)
1032                 //{
1033                 //    this.AuthStateLabel.Text += "(xAuth)";
1034                 //}
1035                 //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
1036                 //{
1037                 //    this.AuthStateLabel.Text += "(OAuth)";
1038                 //}
1039                 return true;
1040             }
1041             else
1042             {
1043                 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
1044                 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
1045                 //this.AuthUserLabel.Text = "";
1046                 return false;
1047             }
1048         }
1049
1050         private void StartAuthButton_Click(object sender, EventArgs e)
1051         {
1052             //this.Save.Enabled = false;
1053             if (StartAuth())
1054             {
1055                 if (PinAuth())
1056                 {
1057                     //this.Save.Enabled = true;
1058                 }
1059             }
1060         }
1061
1062         private void CheckPostAndGet_CheckedChanged(object sender, EventArgs e)
1063         {
1064             this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
1065         }
1066
1067         private void Setting_Shown(object sender, EventArgs e)
1068         {
1069             do
1070             {
1071                 Thread.Sleep(10);
1072                 if (this.Disposing || this.IsDisposed) return;
1073             } while (!this.IsHandleCreated);
1074             this.TopMost = this.AlwaysTop;
1075
1076             this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
1077             this.GetPeriodPanel.LabelUserStreamActive.Visible = tw.UserStreamEnabled;
1078         }
1079
1080         public static AppendSettingDialog Instance
1081         {
1082             get { return _instance; }
1083         }
1084
1085         private bool BitlyValidation(string id, string apikey)
1086         {
1087             if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(apikey))
1088             {
1089                 return false;
1090             }
1091
1092             string req = "http://api.bit.ly/v3/validate";
1093             string content = "";
1094             Dictionary<string, string> param = new Dictionary<string, string>();
1095
1096             param.Add("login", ApplicationSettings.BitlyLoginId);
1097             param.Add("apiKey", ApplicationSettings.BitlyApiKey);
1098             param.Add("x_login", id);
1099             param.Add("x_apiKey", apikey);
1100             param.Add("format", "txt");
1101
1102             if (!(new HttpVarious()).PostData(req, param, out content))
1103             {
1104                 return true;             // 通信エラーの場合はとりあえずチェックを通ったことにする
1105             }
1106             else if (content.Trim() == "1")
1107             {
1108                 return true;             // 検証成功
1109             }
1110             else if (content.Trim() == "0")
1111             {
1112                 return false;            // 検証失敗 APIキーとIDの組み合わせが違う
1113             }
1114             else
1115             {
1116                 return true;             // 規定外応答:通信エラーの可能性があるためとりあえずチェックを通ったことにする
1117             }
1118         }
1119
1120         private void Cancel_Click(object sender, EventArgs e)
1121         {
1122             _ValidationError = false;
1123         }
1124
1125         public bool BlinkNewMentions;
1126
1127         //private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
1128         //                Handles CheckEventNotify.CheckedChanged, CheckFavoritesEvent.CheckStateChanged,
1129         //                        CheckUnfavoritesEvent.CheckStateChanged, CheckFollowEvent.CheckStateChanged,
1130         //                        CheckListMemberAddedEvent.CheckStateChanged, CheckListMemberRemovedEvent.CheckStateChanged,
1131         //                        CheckListCreatedEvent.CheckStateChanged, CheckUserUpdateEvent.CheckStateChanged
1132         //{
1133         //    EventNotifyEnabled = CheckEventNotify.Checked;
1134         //    GetEventNotifyFlag(EventNotifyFlag, IsMyEventNotifyFlag);
1135         //    ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
1136         //}
1137
1138         private class EventCheckboxTblElement
1139         {
1140             public CheckBox CheckBox;
1141             public MyCommon.EVENTTYPE Type;
1142         }
1143
1144         private EventCheckboxTblElement[] GetEventCheckboxTable()
1145         {
1146             EventCheckboxTblElement[] _eventCheckboxTable = new EventCheckboxTblElement[8];
1147
1148             _eventCheckboxTable[0] = new EventCheckboxTblElement();
1149             _eventCheckboxTable[0].CheckBox = this.NotifyPanel.CheckFavoritesEvent;
1150             _eventCheckboxTable[0].Type = MyCommon.EVENTTYPE.Favorite;
1151
1152             _eventCheckboxTable[1] = new EventCheckboxTblElement();
1153             _eventCheckboxTable[1].CheckBox = this.NotifyPanel.CheckUnfavoritesEvent;
1154             _eventCheckboxTable[1].Type = MyCommon.EVENTTYPE.Unfavorite;
1155
1156             _eventCheckboxTable[2] = new EventCheckboxTblElement();
1157             _eventCheckboxTable[2].CheckBox = this.NotifyPanel.CheckFollowEvent;
1158             _eventCheckboxTable[2].Type = MyCommon.EVENTTYPE.Follow;
1159
1160             _eventCheckboxTable[3] = new EventCheckboxTblElement();
1161             _eventCheckboxTable[3].CheckBox = this.NotifyPanel.CheckListMemberAddedEvent;
1162             _eventCheckboxTable[3].Type = MyCommon.EVENTTYPE.ListMemberAdded;
1163
1164             _eventCheckboxTable[4] = new EventCheckboxTblElement();
1165             _eventCheckboxTable[4].CheckBox = this.NotifyPanel.CheckListMemberRemovedEvent;
1166             _eventCheckboxTable[4].Type = MyCommon.EVENTTYPE.ListMemberRemoved;
1167
1168             _eventCheckboxTable[5] = new EventCheckboxTblElement();
1169             _eventCheckboxTable[5].CheckBox = this.NotifyPanel.CheckBlockEvent;
1170             _eventCheckboxTable[5].Type = MyCommon.EVENTTYPE.Block;
1171
1172             _eventCheckboxTable[6] = new EventCheckboxTblElement();
1173             _eventCheckboxTable[6].CheckBox = this.NotifyPanel.CheckUserUpdateEvent;
1174             _eventCheckboxTable[6].Type = MyCommon.EVENTTYPE.UserUpdate;
1175
1176             _eventCheckboxTable[7] = new EventCheckboxTblElement();
1177             _eventCheckboxTable[7].CheckBox = this.NotifyPanel.CheckListCreatedEvent;
1178             _eventCheckboxTable[7].Type = MyCommon.EVENTTYPE.ListCreated;
1179
1180             return _eventCheckboxTable;
1181         }
1182
1183         private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
1184         {
1185             MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
1186             MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
1187
1188             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
1189             {
1190                 switch (tbl.CheckBox.CheckState)
1191                 {
1192                     case CheckState.Checked:
1193                         evt = evt | tbl.Type;
1194                         myevt = myevt | tbl.Type;
1195                         break;
1196                     case CheckState.Indeterminate:
1197                         evt = evt | tbl.Type;
1198                         break;
1199                     case CheckState.Unchecked:
1200                         break;
1201                 }
1202             }
1203             eventnotifyflag = evt;
1204             isMyeventnotifyflag = myevt;
1205         }
1206
1207         private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
1208         {
1209             MyCommon.EVENTTYPE evt = eventnotifyflag;
1210             MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
1211
1212             this.NotifyPanel.CheckEventNotify.Checked = rootEnabled;
1213
1214             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
1215             {
1216                 if ((evt & tbl.Type) != 0)
1217                 {
1218                     if ((myevt & tbl.Type) != 0)
1219                     {
1220                         tbl.CheckBox.CheckState = CheckState.Checked;
1221                     }
1222                     else
1223                     {
1224                         tbl.CheckBox.CheckState = CheckState.Indeterminate;
1225                     }
1226                 }
1227                 else
1228                 {
1229                     tbl.CheckBox.CheckState = CheckState.Unchecked;
1230                 }
1231                 tbl.CheckBox.Enabled = rootEnabled;
1232             }
1233
1234         }
1235
1236         private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
1237         {
1238             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
1239             {
1240                 tbl.CheckBox.Enabled = this.NotifyPanel.CheckEventNotify.Checked;
1241             }
1242         }
1243
1244         //private void CheckForceEventNotify_CheckedChanged(object sender, EventArgs e)
1245         //{
1246         //    _MyForceEventNotify = CheckEventNotify.Checked;
1247         //}
1248
1249         //private void CheckFavEventUnread_CheckedChanged(object sender, EventArgs e)
1250         //{
1251         //    _MyFavEventUnread = CheckFavEventUnread.Checked;
1252         //}
1253
1254         //private void ComboBoxTranslateLanguage_SelectedIndexChanged(object sender, EventArgs e)
1255         //{
1256         //    _MyTranslateLanguage = (new Google()).GetLanguageEnumFromIndex(ComboBoxTranslateLanguage.SelectedIndex);
1257         //}
1258
1259         private void SoundFileListup()
1260         {
1261             if (EventSoundFile == null) EventSoundFile = "";
1262             this.NotifyPanel.ComboBoxEventNotifySound.Items.Clear();
1263             this.NotifyPanel.ComboBoxEventNotifySound.Items.Add("");
1264             DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
1265             if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
1266             {
1267                 oDir = oDir.GetDirectories("Sounds")[0];
1268             }
1269             foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
1270             {
1271                 this.NotifyPanel.ComboBoxEventNotifySound.Items.Add(oFile.Name);
1272             }
1273             int idx = this.NotifyPanel.ComboBoxEventNotifySound.Items.IndexOf(EventSoundFile);
1274             if (idx == -1) idx = 0;
1275             this.NotifyPanel.ComboBoxEventNotifySound.SelectedIndex = idx;
1276         }
1277
1278         //private void ComboBoxEventNotifySound_VisibleChanged(object sender, EventArgs e)
1279         //{
1280         //    SoundFileListup();
1281         //}
1282
1283         //private void ComboBoxEventNotifySound_SelectedIndexChanged(object sender, EventArgs e)
1284         //{
1285         //   if (_soundfileListup) return;
1286
1287         //    _MyEventSoundFile = (string)ComboBoxEventNotifySound.SelectedItem;
1288         //}
1289
1290         private void OpenUrl(string url)
1291         {
1292             string myPath = url;
1293             string path = this.ActionPanel.BrowserPathText.Text;
1294             try
1295             {
1296                 if (!string.IsNullOrEmpty(path))
1297                 {
1298                     if (path.StartsWith("\"") && path.Length > 2 && path.IndexOf("\"", 2) > -1)
1299                     {
1300                         int sep = path.IndexOf("\"", 2);
1301                         string browserPath = path.Substring(1, sep - 1);
1302                         string arg = "";
1303                         if (sep < path.Length - 1)
1304                         {
1305                             arg = path.Substring(sep + 1);
1306                         }
1307                         myPath = arg + " " + myPath;
1308                         System.Diagnostics.Process.Start(browserPath, myPath);
1309                     }
1310                     else
1311                     {
1312                         System.Diagnostics.Process.Start(path, myPath);
1313                     }
1314                 }
1315                 else
1316                 {
1317                     System.Diagnostics.Process.Start(myPath);
1318                 }
1319             }
1320             catch(Exception)
1321             {
1322 //              MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
1323             }
1324         }
1325
1326         private void CreateAccountButton_Click(object sender, EventArgs e)
1327         {
1328             this.OpenUrl("https://twitter.com/signup");
1329         }
1330
1331         public AppendSettingDialog()
1332         {
1333             InitializeComponent();
1334
1335             this.BasedPanel.StartAuthButton.Click += this.StartAuthButton_Click;
1336             this.BasedPanel.CreateAccountButton.Click += this.CreateAccountButton_Click;
1337             this.NotifyPanel.CheckEventNotify.CheckedChanged += this.CheckEventNotify_CheckedChanged;
1338             this.GetPeriodPanel.CheckPostAndGet.CheckedChanged += this.CheckPostAndGet_CheckedChanged;
1339             this.ActionPanel.UReadMng.CheckedChanged += this.UReadMng_CheckedChanged;
1340             this.FontPanel.btnUnread.Click += this.btnFontAndColor_Click;
1341             this.FontPanel.btnDetail.Click += this.btnFontAndColor_Click;
1342             this.FontPanel.btnListFont.Click += this.btnFontAndColor_Click;
1343             this.FontPanel.btnFav.Click += this.btnColor_Click;
1344             this.FontPanel.btnOWL.Click += this.btnColor_Click;
1345             this.FontPanel.btnRetweet.Click += this.btnColor_Click;
1346             this.FontPanel.btnDetailBack.Click += this.btnColor_Click;
1347             this.FontPanel.btnDetailLink.Click += this.btnColor_Click;
1348             this.FontPanel2.btnInputFont.Click += this.btnFontAndColor_Click;
1349             this.FontPanel2.btnSelf.Click += this.btnColor_Click;
1350             this.FontPanel2.btnAtSelf.Click += this.btnColor_Click;
1351             this.FontPanel2.btnTarget.Click += this.btnColor_Click;
1352             this.FontPanel2.btnAtTarget.Click += this.btnColor_Click;
1353             this.FontPanel2.btnAtFromTarget.Click += this.btnColor_Click;
1354             this.FontPanel2.btnInputBackcolor.Click += this.btnColor_Click;
1355             this.FontPanel2.btnAtTo.Click += this.btnColor_Click;
1356             this.FontPanel2.btnListBack.Click += this.btnColor_Click;
1357
1358             this.Icon = Properties.Resources.MIcon;
1359         }
1360
1361         private void GetPeriodPanel_IntervalChanged(object sender, IntervalChangedEventArgs e)
1362         {
1363             if (this.IntervalChanged != null)
1364                 this.IntervalChanged(sender, e);
1365         }
1366     }
1367
1368     public class IntervalChangedEventArgs : EventArgs
1369     {
1370         public bool UserStream;
1371         public bool Timeline;
1372         public bool Reply;
1373         public bool DirectMessage;
1374         public bool PublicSearch;
1375         public bool Lists;
1376         public bool UserTimeline;
1377     }
1378 }