OSDN Git Service

varを使用する (IDE0007)
[opentween/open-tween.git] / OpenTween / AppendSettingDialog.cs
index 095023e..5f21754 100644 (file)
@@ -30,6 +30,7 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Net.Http;
 using System.Text;
 using System.Windows.Forms;
 using System.Threading;
@@ -45,34 +46,26 @@ namespace OpenTween
 {
     public partial class AppendSettingDialog : OTBaseForm
     {
-        private static AppendSettingDialog _instance = new AppendSettingDialog();
-        private Twitter tw;
-        private ProxyType _MyProxyType;
-
-        private bool _ValidationError = false;
-        private MyCommon.EVENTTYPE _MyEventNotifyFlag;
-        private MyCommon.EVENTTYPE _isMyEventNotifyFlag;
-        private string _MyTranslateLanguage;
+        public event EventHandler<IntervalChangedEventArgs> IntervalChanged;
 
-        public bool EnableImgAzyobuziNet { get; set; }
-        public bool ImgAzyobuziNetDisabledInDM { get; set; }
-        public MapProvider MapThumbnailProvider;
-        public int MapThumbnailHeight;
-        public int MapThumbnailWidth;
-        public int MapThumbnailZoom;
-        public List<UserAccount> UserAccounts;
-        private long? InitialUserId;
-        public bool IsRemoveSameEvent;
-        public bool IsNotifyUseGrowl;
+        internal Twitter tw;
+        internal TwitterApi twitterApi;
 
-        public TwitterConfiguration TwitterConfiguration = TwitterConfiguration.DefaultConfiguration();
+        public AppendSettingDialog()
+        {
+            this.InitializeComponent();
 
-        private string _pin;
+            this.BasedPanel.StartAuthButton.Click += this.StartAuthButton_Click;
+            this.BasedPanel.CreateAccountButton.Click += this.CreateAccountButton_Click;
+            this.GetPeriodPanel.CheckPostAndGet.CheckedChanged += this.CheckPostAndGet_CheckedChanged;
+            this.ActionPanel.UReadMng.CheckedChanged += this.UReadMng_CheckedChanged;
 
-        public event EventHandler<IntervalChangedEventArgs> IntervalChanged;
+            this.Icon = Properties.Resources.MIcon;
+        }
 
         public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
         {
+            this.BasedPanel.LoadConfig(settingCommon);
             this.GetPeriodPanel.LoadConfig(settingCommon);
             this.StartupPanel.LoadConfig(settingCommon);
             this.TweetPrvPanel.LoadConfig(settingCommon);
@@ -80,10 +73,24 @@ namespace OpenTween
             this.ActionPanel.LoadConfig(settingCommon, settingLocal);
             this.FontPanel.LoadConfig(settingLocal);
             this.FontPanel2.LoadConfig(settingLocal);
+            this.PreviewPanel.LoadConfig(settingCommon);
+            this.GetCountPanel.LoadConfig(settingCommon);
+            this.ShortUrlPanel.LoadConfig(settingCommon);
+            this.ProxyPanel.LoadConfig(settingLocal);
+            this.CooperatePanel.LoadConfig(settingCommon);
+            this.ConnectionPanel.LoadConfig(settingCommon);
+            this.NotifyPanel.LoadConfig(settingCommon);
+
+            var activeUser = settingCommon.UserAccounts.FirstOrDefault(x => x.UserId == this.tw.UserId);
+            if (activeUser != null)
+            {
+                this.BasedPanel.AuthUserCombo.SelectedItem = activeUser;
+            }
         }
 
         public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
         {
+            this.BasedPanel.SaveConfig(settingCommon);
             this.GetPeriodPanel.SaveConfig(settingCommon);
             this.StartupPanel.SaveConfig(settingCommon);
             this.TweetPrvPanel.SaveConfig(settingCommon);
@@ -91,6 +98,25 @@ namespace OpenTween
             this.ActionPanel.SaveConfig(settingCommon, settingLocal);
             this.FontPanel.SaveConfig(settingLocal);
             this.FontPanel2.SaveConfig(settingLocal);
+            this.PreviewPanel.SaveConfig(settingCommon);
+            this.GetCountPanel.SaveConfig(settingCommon);
+            this.ShortUrlPanel.SaveConfig(settingCommon);
+            this.ProxyPanel.SaveConfig(settingLocal);
+            this.CooperatePanel.SaveConfig(settingCommon);
+            this.ConnectionPanel.SaveConfig(settingCommon);
+            this.NotifyPanel.SaveConfig(settingCommon);
+
+            var userAccountIdx = this.BasedPanel.AuthUserCombo.SelectedIndex;
+            if (userAccountIdx != -1)
+            {
+                var u = settingCommon.UserAccounts[userAccountIdx];
+                this.tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
+            }
+            else
+            {
+                this.tw.ClearAuthInfo();
+                this.tw.Initialize("", "", "", 0);
+            }
         }
 
         private void TreeViewSetting_BeforeSelect(object sender, TreeViewCancelEventArgs e)
@@ -123,284 +149,17 @@ namespace OpenTween
             }
         }
 
-        private void Save_Click(object sender, EventArgs e)
-        {
-            if (MyCommon.IsNetworkAvailable() &&
-                (this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
-            {
-                // bit.ly 短縮機能実装のプライバシー問題の暫定対応
-                // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
-                // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
-                if (string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyId.Text) || string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyPw.Text))
-                {
-                    MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
-                    _ValidationError = true;
-                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
-                    TreeViewSetting.Select();
-                    this.ShortUrlPanel.TextBitlyId.Focus();
-                    return;
-                }
-
-                if (!BitlyValidation(this.ShortUrlPanel.TextBitlyId.Text, this.ShortUrlPanel.TextBitlyPw.Text))
-                {
-                    MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
-                    _ValidationError = true;
-                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
-                    TreeViewSetting.Select();
-                    this.ShortUrlPanel.TextBitlyId.Focus();
-                    return;
-                }
-                else
-                {
-                    _ValidationError = false;
-                }
-            }
-            else
-            {
-                _ValidationError = false;
-            }
-
-            this.UserAccounts.Clear();
-            foreach (object u in this.BasedPanel.AuthUserCombo.Items)
-            {
-                this.UserAccounts.Add((UserAccount)u);
-            }
-            if (this.BasedPanel.AuthUserCombo.SelectedIndex > -1)
-            {
-                foreach (UserAccount u in this.UserAccounts)
-                {
-                    if (u.Username.ToLower() == ((UserAccount)this.BasedPanel.AuthUserCombo.SelectedItem).Username.ToLower())
-                    {
-                        tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
-                        if (u.UserId == 0)
-                        {
-                            tw.VerifyCredentials();
-                            u.UserId = tw.UserId;
-                        }
-                        break;
-                    }
-                }
-            }
-            else
-            {
-                tw.ClearAuthInfo();
-                tw.Initialize("", "", "", 0);
-            }
-
-#if UA
-            //フォロー
-            if (this.FollowCheckBox.Checked)
-            {
-                //現在の設定内容で通信
-                HttpConnection.ProxyType ptype;
-                if (RadioProxyNone.Checked)
-                {
-                    ptype = HttpConnection.ProxyType.None;
-                }
-                else if (RadioProxyIE.Checked)
-                {
-                    ptype = HttpConnection.ProxyType.IE;
-                }
-                else
-                {
-                    ptype = HttpConnection.ProxyType.Specified;
-                }
-                string padr = TextProxyAddress.Text.Trim();
-                int pport = int.Parse(TextProxyPort.Text.Trim());
-                string pusr = TextProxyUser.Text.Trim();
-                string ppw = TextProxyPassword.Text.Trim();
-                HttpConnection.InitializeConnection(20, ptype, padr, pport, pusr, ppw);
-
-                string ret = tw.PostFollowCommand(ApplicationSettings.FeedbackTwitterName);
-            }
-#endif
-            try
-            {
-                switch (this.PreviewPanel.cmbNameBalloon.SelectedIndex)
-                {
-                    case 0:
-                        NameBalloon = MyCommon.NameBalloonEnum.None;
-                        break;
-                    case 1:
-                        NameBalloon = MyCommon.NameBalloonEnum.UserID;
-                        break;
-                    case 2:
-                        NameBalloon = MyCommon.NameBalloonEnum.NickName;
-                        break;
-                }
-
-                CountApi = int.Parse(this.GetCountPanel.TextCountApi.Text);
-                CountApiReply = int.Parse(this.GetCountPanel.TextCountApiReply.Text);
-                DispUsername = this.PreviewPanel.CheckDispUsername.Checked;
-                switch (this.PreviewPanel.ComboDispTitle.SelectedIndex)
-                {
-                    case 0:  //None
-                        DispLatestPost = MyCommon.DispTitleEnum.None;
-                        break;
-                    case 1:  //Ver
-                        DispLatestPost = MyCommon.DispTitleEnum.Ver;
-                        break;
-                    case 2:  //Post
-                        DispLatestPost = MyCommon.DispTitleEnum.Post;
-                        break;
-                    case 3:  //RepCount
-                        DispLatestPost = MyCommon.DispTitleEnum.UnreadRepCount;
-                        break;
-                    case 4:  //AllCount
-                        DispLatestPost = MyCommon.DispTitleEnum.UnreadAllCount;
-                        break;
-                    case 5:  //Rep+All
-                        DispLatestPost = MyCommon.DispTitleEnum.UnreadAllRepCount;
-                        break;
-                    case 6:  //Unread/All
-                        DispLatestPost = MyCommon.DispTitleEnum.UnreadCountAllCount;
-                        break;
-                    case 7: //Count of Status/Follow/Follower
-                        DispLatestPost = MyCommon.DispTitleEnum.OwnStatus;
-                        break;
-                }
-                TinyUrlResolve = this.ShortUrlPanel.CheckTinyURL.Checked;
-                ShortUrl.Instance.DisableExpanding = !TinyUrlResolve;
-                if (this.ProxyPanel.RadioProxyNone.Checked)
-                {
-                    _MyProxyType = ProxyType.None;
-                }
-                else if (this.ProxyPanel.RadioProxyIE.Checked)
-                {
-                    _MyProxyType = ProxyType.IE;
-                }
-                else
-                {
-                    _MyProxyType = ProxyType.Specified;
-                }
-                ProxyAddress = this.ProxyPanel.TextProxyAddress.Text.Trim();
-                ProxyPort = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
-                ProxyUser = this.ProxyPanel.TextProxyUser.Text.Trim();
-                ProxyPassword = this.ProxyPanel.TextProxyPassword.Text.Trim();
-                AlwaysTop = this.PreviewPanel.CheckAlwaysTop.Checked;
-                UrlConvertAuto = this.ShortUrlPanel.CheckAutoConvertUrl.Checked;
-                ShortenTco = this.ShortUrlPanel.ShortenTcoCheck.Checked;
-
-                Nicoms = this.CooperatePanel.CheckNicoms.Checked;
-                DefaultTimeOut = int.Parse(this.ConnectionPanel.ConnectionTimeOut.Text);
-                LimitBalloon = this.PreviewPanel.CheckBalloonLimit.Checked;
-                EventNotifyEnabled = this.NotifyPanel.CheckEventNotify.Checked;
-                GetEventNotifyFlag(ref _MyEventNotifyFlag, ref _isMyEventNotifyFlag);
-                ForceEventNotify = this.NotifyPanel.CheckForceEventNotify.Checked;
-                FavEventUnread = this.NotifyPanel.CheckFavEventUnread.Checked;
-                TranslateLanguage = Bing.GetLanguageEnumFromIndex(this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex);
-                EventSoundFile = (string)this.NotifyPanel.ComboBoxEventNotifySound.SelectedItem;
-                AutoShortUrlFirst = (MyCommon.UrlConverter)this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex;
-                TabIconDisp = this.PreviewPanel.chkTabIconDisp.Checked;
-                IsMonospace = this.PreviewPanel.CheckMonospace.Checked;
-                BitlyUser = this.ShortUrlPanel.TextBitlyId.Text;
-                BitlyPwd = this.ShortUrlPanel.TextBitlyPw.Text;
-                PreviewEnable = this.PreviewPanel.CheckPreviewEnable.Checked;
-                StatusAreaAtBottom = this.PreviewPanel.CheckStatusAreaAtBottom.Checked;
-                TwitterApiUrl = this.ConnectionPanel.TwitterAPIText.Text.Trim();
-                switch (this.PreviewPanel.ReplyIconStateCombo.SelectedIndex)
-                {
-                    case 0:
-                        ReplyIconState = MyCommon.REPLY_ICONSTATE.None;
-                        break;
-                    case 1:
-                        ReplyIconState = MyCommon.REPLY_ICONSTATE.StaticIcon;
-                        break;
-                    case 2:
-                        ReplyIconState = MyCommon.REPLY_ICONSTATE.BlinkIcon;
-                        break;
-                }
-                switch (this.PreviewPanel.LanguageCombo.SelectedIndex)
-                {
-                    case 0:
-                        Language = "OS";
-                        break;
-                    case 1:
-                        Language = "ja";
-                        break;
-                    case 2:
-                        Language = "en";
-                        break;
-                    case 3:
-                        Language = "zh-CN";
-                        break;
-                    default:
-                        Language = "en";
-                        break;
-                }
-                BlinkNewMentions = this.PreviewPanel.ChkNewMentionsBlink.Checked;
-                UseAdditionalCount = this.GetCountPanel.UseChangeGetCount.Checked;
-                MoreCountApi = int.Parse(this.GetCountPanel.GetMoreTextCountApi.Text);
-                FirstCountApi = int.Parse(this.GetCountPanel.FirstTextCountApi.Text);
-                SearchCountApi = int.Parse(this.GetCountPanel.SearchTextCountApi.Text);
-                FavoritesCountApi = int.Parse(this.GetCountPanel.FavoritesTextCountApi.Text);
-                UserTimelineCountApi = int.Parse(this.GetCountPanel.UserTimelineTextCountApi.Text);
-                ListCountApi = int.Parse(this.GetCountPanel.ListTextCountApi.Text);
-                UserAppointUrl = this.CooperatePanel.UserAppointUrlText.Text;
-                this.EnableImgAzyobuziNet = this.CooperatePanel.EnableImgAzyobuziNetCheckBox.Checked;
-                this.ImgAzyobuziNetDisabledInDM = this.CooperatePanel.ImgAzyobuziNetDisabledInDMCheckBox.Checked;
-                this.MapThumbnailProvider = (MapProvider)this.CooperatePanel.MapThumbnailProviderComboBox.SelectedIndex;
-                this.MapThumbnailHeight = int.Parse(this.CooperatePanel.MapThumbnailHeightTextBox.Text);
-                this.MapThumbnailWidth = int.Parse(this.CooperatePanel.MapThumbnailWidthTextBox.Text);
-                this.MapThumbnailZoom = int.Parse(this.CooperatePanel.MapThumbnailZoomTextBox.Text);
-                this.IsRemoveSameEvent = this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked;
-                this.IsNotifyUseGrowl = this.PreviewPanel.IsNotifyUseGrowlCheckBox.Checked;
-            }
-            catch(Exception)
-            {
-                MessageBox.Show(Properties.Resources.Save_ClickText3);
-                this.DialogResult = DialogResult.Cancel;
-                return;
-            }
-        }
-
         private void Setting_FormClosing(object sender, FormClosingEventArgs e)
         {
             if (MyCommon._endingFlag) return;
 
-            if (this.DialogResult == DialogResult.Cancel)
-            {
-                //キャンセル時は画面表示時のアカウントに戻す
-                //キャンセル時でも認証済みアカウント情報は保存する
-                this.UserAccounts.Clear();
-                foreach (object u in this.BasedPanel.AuthUserCombo.Items)
-                {
-                    this.UserAccounts.Add((UserAccount)u);
-                }
-                //アクティブユーザーを起動時のアカウントに戻す(起動時アカウントなければ何もしない)
-                bool userSet = false;
-                if (this.InitialUserId != null)
-                {
-                    foreach (UserAccount u in this.UserAccounts)
-                    {
-                        if (u.UserId == this.InitialUserId)
-                        {
-                            tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
-                            userSet = true;
-                            break;
-                        }
-                    }
-                }
-                //認証済みアカウントが削除されていた場合、もしくは起動時アカウントがなかった場合は、
-                //アクティブユーザーなしとして初期化
-                if (!userSet)
-                {
-                    tw.ClearAuthInfo();
-                    tw.Initialize("", "", "", 0);
-                }
-            }
-
-            if (tw != null && string.IsNullOrEmpty(tw.Username) && e.CloseReason == CloseReason.None)
+            if (this.BasedPanel.AuthUserCombo.SelectedIndex == -1 && e.CloseReason == CloseReason.None)
             {
                 if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                 {
                     e.Cancel = true;
                 }
             }
-            if (_ValidationError)
-            {
-                e.Cancel = true;
-            }
             if (e.Cancel == false && TreeViewSetting.SelectedNode != null)
             {
                 var curPanel = (SettingPanelBase)TreeViewSetting.SelectedNode.Tag;
@@ -411,216 +170,10 @@ namespace OpenTween
 
         private void Setting_Load(object sender, EventArgs e)
         {
-            tw = ((TweenMain)this.Owner).TwitterInstance;
-            //this.AuthStateLabel.Enabled = true;
-            //this.AuthUserLabel.Enabled = true;
-            this.BasedPanel.AuthClearButton.Enabled = true;
-
-            //if (tw.Username == "")
-            //{
-            //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4
-            //    //this.AuthUserLabel.Text = ""
-            //    //this.Save.Enabled = false
-            //}
-            //else
-            //{
-            //    //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
-            //    //if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWrite)
-            //    //{
-            //    //    this.AuthStateLabel.Text += "(xAuth)";
-            //    //}
-            //    //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
-            //    //{
-            //    //    this.AuthStateLabel.Text += "(OAuth)";
-            //    //}
-            //    //this.AuthUserLabel.Text = tw.Username;
-            //}
-
-            this.BasedPanel.AuthUserCombo.Items.Clear();
-            if (this.UserAccounts.Count > 0)
-            {
-                this.BasedPanel.AuthUserCombo.Items.AddRange(this.UserAccounts.ToArray());
-                foreach (UserAccount u in this.UserAccounts)
-                {
-                    if (u.UserId == tw.UserId)
-                    {
-                        this.BasedPanel.AuthUserCombo.SelectedItem = u;
-                        this.InitialUserId = u.UserId;
-                        break;
-                    }
-                }
-            }
-
-            switch (NameBalloon)
-            {
-                case MyCommon.NameBalloonEnum.None:
-                    this.PreviewPanel.cmbNameBalloon.SelectedIndex = 0;
-                    break;
-                case MyCommon.NameBalloonEnum.UserID:
-                    this.PreviewPanel.cmbNameBalloon.SelectedIndex = 1;
-                    break;
-                case MyCommon.NameBalloonEnum.NickName:
-                    this.PreviewPanel.cmbNameBalloon.SelectedIndex = 2;
-                    break;
-            }
-
-            this.GetCountPanel.TextCountApi.Text = CountApi.ToString();
-            this.GetCountPanel.TextCountApiReply.Text = CountApiReply.ToString();
-            this.PreviewPanel.CheckDispUsername.Checked = DispUsername;
-            switch (DispLatestPost)
-            {
-                case MyCommon.DispTitleEnum.None:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 0;
-                    break;
-                case MyCommon.DispTitleEnum.Ver:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 1;
-                    break;
-                case MyCommon.DispTitleEnum.Post:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 2;
-                    break;
-                case MyCommon.DispTitleEnum.UnreadRepCount:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 3;
-                    break;
-                case MyCommon.DispTitleEnum.UnreadAllCount:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 4;
-                    break;
-                case MyCommon.DispTitleEnum.UnreadAllRepCount:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 5;
-                    break;
-                case MyCommon.DispTitleEnum.UnreadCountAllCount:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 6;
-                    break;
-                case MyCommon.DispTitleEnum.OwnStatus:
-                    this.PreviewPanel.ComboDispTitle.SelectedIndex = 7;
-                    break;
-            }
-            this.ShortUrlPanel.CheckTinyURL.Checked = TinyUrlResolve;
-            switch (_MyProxyType)
-            {
-                case ProxyType.None:
-                    this.ProxyPanel.RadioProxyNone.Checked = true;
-                    break;
-                case ProxyType.IE:
-                    this.ProxyPanel.RadioProxyIE.Checked = true;
-                    break;
-                default:
-                    this.ProxyPanel.RadioProxySpecified.Checked = true;
-                    break;
-            }
-            bool chk = this.ProxyPanel.RadioProxySpecified.Checked;
-            this.ProxyPanel.LabelProxyAddress.Enabled = chk;
-            this.ProxyPanel.TextProxyAddress.Enabled = chk;
-            this.ProxyPanel.LabelProxyPort.Enabled = chk;
-            this.ProxyPanel.TextProxyPort.Enabled = chk;
-            this.ProxyPanel.LabelProxyUser.Enabled = chk;
-            this.ProxyPanel.TextProxyUser.Enabled = chk;
-            this.ProxyPanel.LabelProxyPassword.Enabled = chk;
-            this.ProxyPanel.TextProxyPassword.Enabled = chk;
-
-            this.ProxyPanel.TextProxyAddress.Text = ProxyAddress;
-            this.ProxyPanel.TextProxyPort.Text = ProxyPort.ToString();
-            this.ProxyPanel.TextProxyUser.Text = ProxyUser;
-            this.ProxyPanel.TextProxyPassword.Text = ProxyPassword;
-
-            this.PreviewPanel.CheckAlwaysTop.Checked = AlwaysTop;
-            this.ShortUrlPanel.CheckAutoConvertUrl.Checked = UrlConvertAuto;
-            this.ShortUrlPanel.ShortenTcoCheck.Checked = ShortenTco;
-            this.ShortUrlPanel.ShortenTcoCheck.Enabled = this.ShortUrlPanel.CheckAutoConvertUrl.Checked;
-
-            this.CooperatePanel.CheckNicoms.Checked = Nicoms;
-            this.ConnectionPanel.ConnectionTimeOut.Text = DefaultTimeOut.ToString();
-            this.PreviewPanel.CheckBalloonLimit.Checked = LimitBalloon;
-
-            ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
-            this.NotifyPanel.CheckForceEventNotify.Checked = ForceEventNotify;
-            this.NotifyPanel.CheckFavEventUnread.Checked = FavEventUnread;
-            this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex = Bing.GetIndexFromLanguageEnum(TranslateLanguage);
-            SoundFileListup();
-            this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex = (int)AutoShortUrlFirst;
-            this.PreviewPanel.chkTabIconDisp.Checked = TabIconDisp;
-            this.PreviewPanel.CheckMonospace.Checked = IsMonospace;
-            this.ShortUrlPanel.TextBitlyId.Text = BitlyUser;
-            this.ShortUrlPanel.TextBitlyPw.Text = BitlyPwd;
-            this.ShortUrlPanel.TextBitlyId.Modified = false;
-            this.ShortUrlPanel.TextBitlyPw.Modified = false;
-            this.PreviewPanel.CheckPreviewEnable.Checked = PreviewEnable;
-            this.PreviewPanel.CheckStatusAreaAtBottom.Checked = StatusAreaAtBottom;
-            this.ConnectionPanel.TwitterAPIText.Text = TwitterApiUrl;
-            switch (ReplyIconState)
-            {
-                case MyCommon.REPLY_ICONSTATE.None:
-                    this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 0;
-                    break;
-                case MyCommon.REPLY_ICONSTATE.StaticIcon:
-                    this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 1;
-                    break;
-                case MyCommon.REPLY_ICONSTATE.BlinkIcon:
-                    this.PreviewPanel.ReplyIconStateCombo.SelectedIndex = 2;
-                    break;
-            }
-            switch (Language)
-            {
-                case "OS":
-                    this.PreviewPanel.LanguageCombo.SelectedIndex = 0;
-                    break;
-                case "ja":
-                    this.PreviewPanel.LanguageCombo.SelectedIndex = 1;
-                    break;
-                case "en":
-                    this.PreviewPanel.LanguageCombo.SelectedIndex = 2;
-                    break;
-                case "zh-CN":
-                    this.PreviewPanel.LanguageCombo.SelectedIndex = 3;
-                    break;
-                default:
-                    this.PreviewPanel.LanguageCombo.SelectedIndex = 0;
-                    break;
-            }
-            this.PreviewPanel.ChkNewMentionsBlink.Checked = BlinkNewMentions;
-
-            this.GetCountPanel.GetMoreTextCountApi.Text = MoreCountApi.ToString();
-            this.GetCountPanel.FirstTextCountApi.Text = FirstCountApi.ToString();
-            this.GetCountPanel.SearchTextCountApi.Text = SearchCountApi.ToString();
-            this.GetCountPanel.FavoritesTextCountApi.Text = FavoritesCountApi.ToString();
-            this.GetCountPanel.UserTimelineTextCountApi.Text = UserTimelineCountApi.ToString();
-            this.GetCountPanel.ListTextCountApi.Text = ListCountApi.ToString();
-            this.GetCountPanel.UseChangeGetCount.Checked = UseAdditionalCount;
-            this.GetCountPanel.Label28.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.Label30.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.Label53.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.Label66.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.Label17.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.Label25.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.GetMoreTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.FirstTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.SearchTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.FavoritesTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.UserTimelineTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.GetCountPanel.ListTextCountApi.Enabled = this.GetCountPanel.UseChangeGetCount.Checked;
-            this.CooperatePanel.UserAppointUrlText.Text = UserAppointUrl;
-            this.CooperatePanel.EnableImgAzyobuziNetCheckBox.Checked = this.EnableImgAzyobuziNet;
-            this.CooperatePanel.ImgAzyobuziNetDisabledInDMCheckBox.Checked = this.ImgAzyobuziNetDisabledInDM;
-            this.CooperatePanel.MapThumbnailProviderComboBox.SelectedIndex = (int)this.MapThumbnailProvider;
-            this.CooperatePanel.MapThumbnailHeightTextBox.Text = this.MapThumbnailHeight.ToString();
-            this.CooperatePanel.MapThumbnailWidthTextBox.Text = this.MapThumbnailWidth.ToString();
-            this.CooperatePanel.MapThumbnailZoomTextBox.Text = this.MapThumbnailZoom.ToString();
-            this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked = this.IsRemoveSameEvent;
-            this.PreviewPanel.IsNotifyUseGrowlCheckBox.Checked = this.IsNotifyUseGrowl;
-
-            if (GrowlHelper.IsDllExists)
-            {
-                this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = true;
-            }
-            else
-            {
-                this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = false;
-            }
-
             this.TreeViewSetting.Nodes["BasedNode"].Tag = BasedPanel;
             this.TreeViewSetting.Nodes["BasedNode"].Nodes["PeriodNode"].Tag = GetPeriodPanel;
             this.TreeViewSetting.Nodes["BasedNode"].Nodes["StartUpNode"].Tag = StartupPanel;
             this.TreeViewSetting.Nodes["BasedNode"].Nodes["GetCountNode"].Tag = GetCountPanel;
-            //this.TreeViewSetting.Nodes["BasedNode"].Nodes["UserStreamNode"].Tag = UserStreamPanel;
             this.TreeViewSetting.Nodes["ActionNode"].Tag = ActionPanel;
             this.TreeViewSetting.Nodes["ActionNode"].Nodes["TweetActNode"].Tag = TweetActPanel;
             this.TreeViewSetting.Nodes["PreviewNode"].Tag = PreviewPanel;
@@ -636,7 +189,6 @@ namespace OpenTween
             this.TreeViewSetting.SelectedNode = this.TreeViewSetting.Nodes[0];
             this.TreeViewSetting.ExpandAll();
 
-            //TreeViewSetting.SelectedNode = TreeViewSetting.TopNode;
             ActiveControl = BasedPanel.StartAuthButton;
         }
 
@@ -652,388 +204,100 @@ namespace OpenTween
             }
         }
 
-        private void btnFontAndColor_Click(object sender, EventArgs e) // Handles btnUnread.Click, btnDetail.Click, btnListFont.Click, btnInputFont.Click
+        private async void StartAuthButton_Click(object sender, EventArgs e)
         {
-            Button Btn = (Button) sender;
-            DialogResult rtn;
-
-            FontDialog1.AllowVerticalFonts = false;
-            FontDialog1.AllowScriptChange = true;
-            FontDialog1.AllowSimulations = true;
-            FontDialog1.AllowVectorFonts = true;
-            FontDialog1.FixedPitchOnly = false;
-            FontDialog1.FontMustExist = true;
-            FontDialog1.ScriptsOnly = false;
-            FontDialog1.ShowApply = false;
-            FontDialog1.ShowEffects = true;
-            FontDialog1.ShowColor = true;
-
-            switch (Btn.Name)
+            using (ControlTransaction.Disabled(this.BasedPanel.StartAuthButton))
             {
-                case "btnUnread":
-                    FontDialog1.Color = this.FontPanel.lblUnread.ForeColor;
-                    FontDialog1.Font = this.FontPanel.lblUnread.Font;
-                    break;
-                case "btnDetail":
-                    FontDialog1.Color = this.FontPanel.lblDetail.ForeColor;
-                    FontDialog1.Font = this.FontPanel.lblDetail.Font;
-                    break;
-                case "btnListFont":
-                    FontDialog1.Color = this.FontPanel.lblListFont.ForeColor;
-                    FontDialog1.Font = this.FontPanel.lblListFont.Font;
-                    break;
-                case "btnInputFont":
-                    FontDialog1.Color = this.FontPanel2.lblInputFont.ForeColor;
-                    FontDialog1.Font = this.FontPanel2.lblInputFont.Font;
-                    break;
-            }
-
-            try
-            {
-                rtn = FontDialog1.ShowDialog();
-            }
-            catch(ArgumentException ex)
-            {
-                MessageBox.Show(ex.Message);
-                return;
-            }
-
-            if (rtn == DialogResult.Cancel) return;
-
-            switch (Btn.Name)
-            {
-                case "btnUnread":
-                    this.FontPanel.lblUnread.ForeColor = FontDialog1.Color;
-                    this.FontPanel.lblUnread.Font = FontDialog1.Font;
-                    break;
-                case "btnDetail":
-                    this.FontPanel.lblDetail.ForeColor = FontDialog1.Color;
-                    this.FontPanel.lblDetail.Font = FontDialog1.Font;
-                    break;
-                case "btnListFont":
-                    this.FontPanel.lblListFont.ForeColor = FontDialog1.Color;
-                    this.FontPanel.lblListFont.Font = FontDialog1.Font;
-                    break;
-                case "btnInputFont":
-                    this.FontPanel2.lblInputFont.ForeColor = FontDialog1.Color;
-                    this.FontPanel2.lblInputFont.Font = FontDialog1.Font;
-                    break;
-            }
-
-        }
+                try
+                {
+                    this.ApplyNetworkSettings();
 
-        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
-        {
-            Button Btn = (Button)sender;
-            DialogResult rtn;
+                    var newAccount = await this.PinAuth();
+                    if (newAccount == null)
+                        return;
 
-            ColorDialog1.AllowFullOpen = true;
-            ColorDialog1.AnyColor = true;
-            ColorDialog1.FullOpen = false;
-            ColorDialog1.SolidColorOnly = false;
+                    var authUserCombo = this.BasedPanel.AuthUserCombo;
 
-            switch (Btn.Name)
-            {
-                case "btnSelf":
-                    ColorDialog1.Color = this.FontPanel2.lblSelf.BackColor;
-                    break;
-                case "btnAtSelf":
-                    ColorDialog1.Color = this.FontPanel2.lblAtSelf.BackColor;
-                    break;
-                case "btnTarget":
-                    ColorDialog1.Color = this.FontPanel2.lblTarget.BackColor;
-                    break;
-                case "btnAtTarget":
-                    ColorDialog1.Color = this.FontPanel2.lblAtTarget.BackColor;
-                    break;
-                case "btnAtFromTarget":
-                    ColorDialog1.Color = this.FontPanel2.lblAtFromTarget.BackColor;
-                    break;
-                case "btnFav":
-                    ColorDialog1.Color = this.FontPanel.lblFav.ForeColor;
-                    break;
-                case "btnOWL":
-                    ColorDialog1.Color = this.FontPanel.lblOWL.ForeColor;
-                    break;
-                case "btnRetweet":
-                    ColorDialog1.Color = this.FontPanel.lblRetweet.ForeColor;
-                    break;
-                case "btnInputBackcolor":
-                    ColorDialog1.Color = this.FontPanel2.lblInputBackcolor.BackColor;
-                    break;
-                case "btnAtTo":
-                    ColorDialog1.Color = this.FontPanel2.lblAtTo.BackColor;
-                    break;
-                case "btnListBack":
-                    ColorDialog1.Color = this.FontPanel2.lblListBackcolor.BackColor;
-                    break;
-                case "btnDetailBack":
-                    ColorDialog1.Color = this.FontPanel.lblDetailBackcolor.BackColor;
-                    break;
-                case "btnDetailLink":
-                    ColorDialog1.Color = this.FontPanel.lblDetailLink.ForeColor;
-                    break;
-            }
+                    var oldAccount = authUserCombo.Items.Cast<UserAccount>()
+                        .FirstOrDefault(x => x.UserId == newAccount.UserId);
 
-            rtn = ColorDialog1.ShowDialog();
+                    int idx;
+                    if (oldAccount != null)
+                    {
+                        idx = authUserCombo.Items.IndexOf(oldAccount);
+                        authUserCombo.Items[idx] = newAccount;
+                    }
+                    else
+                    {
+                        idx = authUserCombo.Items.Add(newAccount);
+                    }
 
-            if (rtn == DialogResult.Cancel) return;
+                    authUserCombo.SelectedIndex = idx;
 
-            switch (Btn.Name)
-            {
-                case "btnSelf":
-                    this.FontPanel2.lblSelf.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnAtSelf":
-                    this.FontPanel2.lblAtSelf.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnTarget":
-                    this.FontPanel2.lblTarget.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnAtTarget":
-                    this.FontPanel2.lblAtTarget.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnAtFromTarget":
-                    this.FontPanel2.lblAtFromTarget.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnFav":
-                    this.FontPanel.lblFav.ForeColor = ColorDialog1.Color;
-                    break;
-                case "btnOWL":
-                    this.FontPanel.lblOWL.ForeColor = ColorDialog1.Color;
-                    break;
-                case "btnRetweet":
-                    this.FontPanel.lblRetweet.ForeColor = ColorDialog1.Color;
-                    break;
-                case "btnInputBackcolor":
-                    this.FontPanel2.lblInputBackcolor.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnAtTo":
-                    this.FontPanel2.lblAtTo.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnListBack":
-                    this.FontPanel2.lblListBackcolor.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnDetailBack":
-                    this.FontPanel.lblDetailBackcolor.BackColor = ColorDialog1.Color;
-                    break;
-                case "btnDetailLink":
-                    this.FontPanel.lblDetailLink.ForeColor = ColorDialog1.Color;
-                    break;
+                    MessageBox.Show(this, Properties.Resources.AuthorizeButton_Click1,
+                        "Authenticate", MessageBoxButtons.OK);
+                }
+                catch (WebApiException ex)
+                {
+                    var message = Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + ex.Message;
+                    MessageBox.Show(this, message, "Authenticate", MessageBoxButtons.OK);
+                }
             }
         }
 
-        public MyCommon.NameBalloonEnum NameBalloon { get; set; }
-        public int CountApi { get; set; }
-        public int CountApiReply { get; set; }
-        public int MoreCountApi { get; set; }
-        public int FirstCountApi { get; set; }
-        public int SearchCountApi { get; set; }
-        public int FavoritesCountApi { get; set; }
-        public int UserTimelineCountApi { get; set; }
-        public int ListCountApi { get; set; }
-        public string RecommendStatusText { get; set; }
-        public bool DispUsername { get; set; }
-        public MyCommon.DispTitleEnum DispLatestPost { get; set; }
-        public bool TinyUrlResolve { get; set; }
-
-        public ProxyType SelectedProxyType
+        /// <summary>
+        /// 現在設定画面に入力されているネットワーク関係の設定を適用します
+        /// </summary>
+        public void ApplyNetworkSettings()
         {
-            get {
-                return _MyProxyType;
-            }
-            set {
-                _MyProxyType = value;
-            }
-        }
-
-        public string ProxyAddress { get; set; }
-        public int ProxyPort { get; set; }
-        public string ProxyUser { get; set; }
-        public string ProxyPassword { get; set; }
-        public bool AlwaysTop { get; set; }
-        public bool UrlConvertAuto { get; set; }
-        public bool ShortenTco { get; set; }
-        public bool Nicoms { get; set; }
-        public MyCommon.UrlConverter AutoShortUrlFirst { get; set; }
-        public int DefaultTimeOut { get; set; }
-        public bool TabIconDisp { get; set; }
-        public MyCommon.REPLY_ICONSTATE ReplyIconState { get; set; }
-        public bool IsMonospace { get; set; }
-        public string BitlyUser { get; set; }
-        public string BitlyPwd { get; set; }
-        public bool PreviewEnable { get; set; }
-        public bool StatusAreaAtBottom { get; set; }
-        public bool UseAdditionalCount { get; set; }
-        public string TwitterApiUrl { get; set; }
-        public string Language { get; set; }
+            ProxyType proxyType;
+            if (this.ProxyPanel.RadioProxyNone.Checked)
+                proxyType = ProxyType.None;
+            else if (this.ProxyPanel.RadioProxyIE.Checked)
+                proxyType = ProxyType.IE;
+            else
+                proxyType = ProxyType.Specified;
 
-        public bool LimitBalloon { get; set; }
-        public bool EventNotifyEnabled { get; set; }
+            var proxyAddress = this.ProxyPanel.TextProxyAddress.Text.Trim();
+            var proxyPort = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
+            var proxyUser = this.ProxyPanel.TextProxyUser.Text.Trim();
+            var proxyPassword = this.ProxyPanel.TextProxyPassword.Text.Trim();
+            Networking.SetWebProxy(proxyType, proxyAddress, proxyPort, proxyUser, proxyPassword);
 
-        public MyCommon.EVENTTYPE EventNotifyFlag
-        {
-            get
-            {
-                return _MyEventNotifyFlag;
-            }
-            set
-            {
-                _MyEventNotifyFlag = value;
-            }
-        }
+            var timeout = int.Parse(this.ConnectionPanel.ConnectionTimeOut.Text.Trim());
+            Networking.DefaultTimeout = TimeSpan.FromSeconds(timeout);
 
-        public MyCommon.EVENTTYPE IsMyEventNotifyFlag
-        {
-            get
-            {
-                return _isMyEventNotifyFlag;
-            }
-            set
-            {
-                _isMyEventNotifyFlag = value;
-            }
-        }
+            var uploadImageTimeout = int.Parse(this.ConnectionPanel.UploadImageTimeout.Text.Trim());
+            Networking.UploadImageTimeout = TimeSpan.FromSeconds(uploadImageTimeout);
 
-        public bool ForceEventNotify { get; set; }
-        public bool FavEventUnread { get; set; }
+            Networking.ForceIPv4 = this.ConnectionPanel.checkBoxForceIPv4.Checked;
 
-        public string TranslateLanguage
-        {
-            get
-            {
-                return _MyTranslateLanguage;
-            }
-            set
-            {
-                _MyTranslateLanguage = value;
-                this.CooperatePanel.ComboBoxTranslateLanguage.SelectedIndex = Bing.GetIndexFromLanguageEnum(value);
-            }
+            TwitterApiConnection.RestApiHost = this.ConnectionPanel.TwitterAPIText.Text.Trim();
         }
 
-        public string EventSoundFile { get; set; }
-        public string UserAppointUrl { get; set; }
-
-        private bool StartAuth()
+        private async Task<UserAccount> PinAuth()
         {
-            //現在の設定内容で通信
-            ProxyType ptype;
-            if (this.ProxyPanel.RadioProxyNone.Checked)
-            {
-                ptype = ProxyType.None;
-            }
-            else if (this.ProxyPanel.RadioProxyIE.Checked)
-            {
-                ptype = ProxyType.IE;
-            }
-            else
-            {
-                ptype = ProxyType.Specified;
-            }
-            string padr = this.ProxyPanel.TextProxyAddress.Text.Trim();
-            int pport = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
-            string pusr = this.ProxyPanel.TextProxyUser.Text.Trim();
-            string ppw = this.ProxyPanel.TextProxyPassword.Text.Trim();
-
-            //通信基底クラス初期化
-            Networking.DefaultTimeout = TimeSpan.FromSeconds(20);
-            Networking.SetWebProxy(ptype, padr, pport, pusr, ppw);
-            HttpTwitter.TwitterUrl = this.ConnectionPanel.TwitterAPIText.Text.Trim();
-            tw.Initialize("", "", "", 0);
-            //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
-            //this.AuthUserLabel.Text = "";
-            string pinPageUrl = "";
-            string rslt = tw.StartAuthentication(ref pinPageUrl);
-            if (string.IsNullOrEmpty(rslt))
-            {
-                string pin = AuthDialog.DoAuth(this, pinPageUrl);
-                if (!string.IsNullOrEmpty(pin))
-                {
-                    this._pin = pin;
-                    return true;
-                }
-                else
-                {
-                    return false;
-                }
-            }
-            else
-            {
-                MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
-                return false;
-            }
-        }
+            var requestToken = await TwitterApiConnection.GetRequestTokenAsync();
 
-        private bool PinAuth()
-        {
-            string pin = this._pin;   //PIN Code
+            var pinPageUrl = TwitterApiConnection.GetAuthorizeUri(requestToken);
 
-            string rslt = tw.Authenticate(pin);
-            if (string.IsNullOrEmpty(rslt))
-            {
-                MessageBox.Show(Properties.Resources.AuthorizeButton_Click1, "Authenticate", MessageBoxButtons.OK);
-                //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
-                //this.AuthUserLabel.Text = tw.Username;
-                int idx = -1;
-                UserAccount user = new UserAccount();
-                user.Username = tw.Username;
-                user.UserId = tw.UserId;
-                user.Token = tw.AccessToken;
-                user.TokenSecret = tw.AccessTokenSecret;
+            var pin = AuthDialog.DoAuth(this, pinPageUrl);
+            if (string.IsNullOrEmpty(pin))
+                return null; // キャンセルされた場合
 
-                foreach (object u in this.BasedPanel.AuthUserCombo.Items)
-                {
-                    if (((UserAccount)u).Username.ToLower() == tw.Username.ToLower())
-                    {
-                        idx = this.BasedPanel.AuthUserCombo.Items.IndexOf(u);
-                        break;
-                    }
-                }
-                if (idx > -1)
-                {
-                    this.BasedPanel.AuthUserCombo.Items.RemoveAt(idx);
-                    this.BasedPanel.AuthUserCombo.Items.Insert(idx, user);
-                    this.BasedPanel.AuthUserCombo.SelectedIndex = idx;
-                }
-                else
-                {
-                    this.BasedPanel.AuthUserCombo.SelectedIndex = this.BasedPanel.AuthUserCombo.Items.Add(user);
-                }
-                //if (TwitterApiInfo.AccessLevel = ApiAccessLevel.ReadWrite)
-                //{
-                //    this.AuthStateLabel.Text += "(xAuth)";
-                //}
-                //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
-                //{
-                //    this.AuthStateLabel.Text += "(OAuth)";
-                //}
-                return true;
-            }
-            else
-            {
-                MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
-                //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
-                //this.AuthUserLabel.Text = "";
-                return false;
-            }
-        }
+            var accessTokenResponse = await TwitterApiConnection.GetAccessTokenAsync(requestToken, pin);
 
-        private void StartAuthButton_Click(object sender, EventArgs e)
-        {
-            //this.Save.Enabled = false;
-            if (StartAuth())
+            return new UserAccount
             {
-                if (PinAuth())
-                {
-                    //this.Save.Enabled = true;
-                }
-            }
+                Username = accessTokenResponse["screen_name"],
+                UserId = long.Parse(accessTokenResponse["user_id"]),
+                Token = accessTokenResponse["oauth_token"],
+                TokenSecret = accessTokenResponse["oauth_token_secret"],
+            };
         }
 
         private void CheckPostAndGet_CheckedChanged(object sender, EventArgs e)
-        {
-            this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
-        }
+            => this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamActive;
 
         private void Setting_Shown(object sender, EventArgs e)
         {
@@ -1042,235 +306,25 @@ namespace OpenTween
                 Thread.Sleep(10);
                 if (this.Disposing || this.IsDisposed) return;
             } while (!this.IsHandleCreated);
-            this.TopMost = this.AlwaysTop;
-
-            this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
-            this.GetPeriodPanel.LabelUserStreamActive.Visible = tw.UserStreamEnabled;
-        }
-
-        public static AppendSettingDialog Instance
-        {
-            get { return _instance; }
-        }
-
-        private bool BitlyValidation(string id, string apikey)
-        {
-            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(apikey))
-            {
-                return false;
-            }
-
-            string req = "http://api.bit.ly/v3/validate";
-            string content = "";
-            Dictionary<string, string> param = new Dictionary<string, string>();
-
-            param.Add("login", ApplicationSettings.BitlyLoginId);
-            param.Add("apiKey", ApplicationSettings.BitlyApiKey);
-            param.Add("x_login", id);
-            param.Add("x_apiKey", apikey);
-            param.Add("format", "txt");
-
-            if (!(new HttpVarious()).PostData(req, param, out content))
-            {
-                return true;             // 通信エラーの場合はとりあえずチェックを通ったことにする
-            }
-            else if (content.Trim() == "1")
-            {
-                return true;             // 検証成功
-            }
-            else if (content.Trim() == "0")
-            {
-                return false;            // 検証失敗 APIキーとIDの組み合わせが違う
-            }
-            else
-            {
-                return true;             // 規定外応答:通信エラーの可能性があるためとりあえずチェックを通ったことにする
-            }
-        }
-
-        private void Cancel_Click(object sender, EventArgs e)
-        {
-            _ValidationError = false;
-        }
-
-        public bool BlinkNewMentions;
-
-        //private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
-        //                Handles CheckEventNotify.CheckedChanged, CheckFavoritesEvent.CheckStateChanged,
-        //                        CheckUnfavoritesEvent.CheckStateChanged, CheckFollowEvent.CheckStateChanged,
-        //                        CheckListMemberAddedEvent.CheckStateChanged, CheckListMemberRemovedEvent.CheckStateChanged,
-        //                        CheckListCreatedEvent.CheckStateChanged, CheckUserUpdateEvent.CheckStateChanged
-        //{
-        //    EventNotifyEnabled = CheckEventNotify.Checked;
-        //    GetEventNotifyFlag(EventNotifyFlag, IsMyEventNotifyFlag);
-        //    ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
-        //}
-
-        private class EventCheckboxTblElement
-        {
-            public CheckBox CheckBox;
-            public MyCommon.EVENTTYPE Type;
-        }
-
-        private EventCheckboxTblElement[] GetEventCheckboxTable()
-        {
-            EventCheckboxTblElement[] _eventCheckboxTable = new EventCheckboxTblElement[8];
-
-            _eventCheckboxTable[0] = new EventCheckboxTblElement();
-            _eventCheckboxTable[0].CheckBox = this.NotifyPanel.CheckFavoritesEvent;
-            _eventCheckboxTable[0].Type = MyCommon.EVENTTYPE.Favorite;
-
-            _eventCheckboxTable[1] = new EventCheckboxTblElement();
-            _eventCheckboxTable[1].CheckBox = this.NotifyPanel.CheckUnfavoritesEvent;
-            _eventCheckboxTable[1].Type = MyCommon.EVENTTYPE.Unfavorite;
-
-            _eventCheckboxTable[2] = new EventCheckboxTblElement();
-            _eventCheckboxTable[2].CheckBox = this.NotifyPanel.CheckFollowEvent;
-            _eventCheckboxTable[2].Type = MyCommon.EVENTTYPE.Follow;
-
-            _eventCheckboxTable[3] = new EventCheckboxTblElement();
-            _eventCheckboxTable[3].CheckBox = this.NotifyPanel.CheckListMemberAddedEvent;
-            _eventCheckboxTable[3].Type = MyCommon.EVENTTYPE.ListMemberAdded;
-
-            _eventCheckboxTable[4] = new EventCheckboxTblElement();
-            _eventCheckboxTable[4].CheckBox = this.NotifyPanel.CheckListMemberRemovedEvent;
-            _eventCheckboxTable[4].Type = MyCommon.EVENTTYPE.ListMemberRemoved;
-
-            _eventCheckboxTable[5] = new EventCheckboxTblElement();
-            _eventCheckboxTable[5].CheckBox = this.NotifyPanel.CheckBlockEvent;
-            _eventCheckboxTable[5].Type = MyCommon.EVENTTYPE.Block;
-
-            _eventCheckboxTable[6] = new EventCheckboxTblElement();
-            _eventCheckboxTable[6].CheckBox = this.NotifyPanel.CheckUserUpdateEvent;
-            _eventCheckboxTable[6].Type = MyCommon.EVENTTYPE.UserUpdate;
-
-            _eventCheckboxTable[7] = new EventCheckboxTblElement();
-            _eventCheckboxTable[7].CheckBox = this.NotifyPanel.CheckListCreatedEvent;
-            _eventCheckboxTable[7].Type = MyCommon.EVENTTYPE.ListCreated;
-
-            return _eventCheckboxTable;
-        }
-
-        private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
-        {
-            MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
-            MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
-
-            foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
-            {
-                switch (tbl.CheckBox.CheckState)
-                {
-                    case CheckState.Checked:
-                        evt = evt | tbl.Type;
-                        myevt = myevt | tbl.Type;
-                        break;
-                    case CheckState.Indeterminate:
-                        evt = evt | tbl.Type;
-                        break;
-                    case CheckState.Unchecked:
-                        break;
-                }
-            }
-            eventnotifyflag = evt;
-            isMyeventnotifyflag = myevt;
-        }
-
-        private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
-        {
-            MyCommon.EVENTTYPE evt = eventnotifyflag;
-            MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
-
-            this.NotifyPanel.CheckEventNotify.Checked = rootEnabled;
-
-            foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
-            {
-                if ((evt & tbl.Type) != 0)
-                {
-                    if ((myevt & tbl.Type) != 0)
-                    {
-                        tbl.CheckBox.CheckState = CheckState.Checked;
-                    }
-                    else
-                    {
-                        tbl.CheckBox.CheckState = CheckState.Indeterminate;
-                    }
-                }
-                else
-                {
-                    tbl.CheckBox.CheckState = CheckState.Unchecked;
-                }
-                tbl.CheckBox.Enabled = rootEnabled;
-            }
+            this.TopMost = this.PreviewPanel.CheckAlwaysTop.Checked;
 
+            this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamActive;
+            this.GetPeriodPanel.LabelUserStreamActive.Visible = tw.UserStreamActive;
         }
 
-        private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
-        {
-            foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
-            {
-                tbl.CheckBox.Enabled = this.NotifyPanel.CheckEventNotify.Checked;
-            }
-        }
-
-        //private void CheckForceEventNotify_CheckedChanged(object sender, EventArgs e)
-        //{
-        //    _MyForceEventNotify = CheckEventNotify.Checked;
-        //}
-
-        //private void CheckFavEventUnread_CheckedChanged(object sender, EventArgs e)
-        //{
-        //    _MyFavEventUnread = CheckFavEventUnread.Checked;
-        //}
-
-        //private void ComboBoxTranslateLanguage_SelectedIndexChanged(object sender, EventArgs e)
-        //{
-        //    _MyTranslateLanguage = (new Google()).GetLanguageEnumFromIndex(ComboBoxTranslateLanguage.SelectedIndex);
-        //}
-
-        private void SoundFileListup()
-        {
-            if (EventSoundFile == null) EventSoundFile = "";
-            this.NotifyPanel.ComboBoxEventNotifySound.Items.Clear();
-            this.NotifyPanel.ComboBoxEventNotifySound.Items.Add("");
-            DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
-            if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
-            {
-                oDir = oDir.GetDirectories("Sounds")[0];
-            }
-            foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
-            {
-                this.NotifyPanel.ComboBoxEventNotifySound.Items.Add(oFile.Name);
-            }
-            int idx = this.NotifyPanel.ComboBoxEventNotifySound.Items.IndexOf(EventSoundFile);
-            if (idx == -1) idx = 0;
-            this.NotifyPanel.ComboBoxEventNotifySound.SelectedIndex = idx;
-        }
-
-        //private void ComboBoxEventNotifySound_VisibleChanged(object sender, EventArgs e)
-        //{
-        //    SoundFileListup();
-        //}
-
-        //private void ComboBoxEventNotifySound_SelectedIndexChanged(object sender, EventArgs e)
-        //{
-        //   if (_soundfileListup) return;
-
-        //    _MyEventSoundFile = (string)ComboBoxEventNotifySound.SelectedItem;
-        //}
-
         private void OpenUrl(string url)
         {
-            string myPath = url;
-            string path = this.ActionPanel.BrowserPathText.Text;
+            var myPath = url;
+            var path = this.ActionPanel.BrowserPathText.Text;
             try
             {
                 if (!string.IsNullOrEmpty(path))
                 {
-                    if (path.StartsWith("\"") && path.Length > 2 && path.IndexOf("\"", 2) > -1)
+                    if (path.StartsWith("\"", StringComparison.Ordinal) && path.Length > 2 && path.IndexOf("\"", 2, StringComparison.Ordinal) > -1)
                     {
-                        int sep = path.IndexOf("\"", 2);
-                        string browserPath = path.Substring(1, sep - 1);
-                        string arg = "";
+                        var sep = path.IndexOf("\"", 2, StringComparison.Ordinal);
+                        var browserPath = path.Substring(1, sep - 1);
+                        var arg = "";
                         if (sep < path.Length - 1)
                         {
                             arg = path.Substring(sep + 1);
@@ -1290,50 +344,14 @@ namespace OpenTween
             }
             catch(Exception)
             {
-//              MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
             }
         }
 
         private void CreateAccountButton_Click(object sender, EventArgs e)
-        {
-            this.OpenUrl("https://twitter.com/signup");
-        }
-
-        public AppendSettingDialog()
-        {
-            InitializeComponent();
-
-            this.BasedPanel.StartAuthButton.Click += this.StartAuthButton_Click;
-            this.BasedPanel.CreateAccountButton.Click += this.CreateAccountButton_Click;
-            this.NotifyPanel.CheckEventNotify.CheckedChanged += this.CheckEventNotify_CheckedChanged;
-            this.GetPeriodPanel.CheckPostAndGet.CheckedChanged += this.CheckPostAndGet_CheckedChanged;
-            this.ActionPanel.UReadMng.CheckedChanged += this.UReadMng_CheckedChanged;
-            this.FontPanel.btnUnread.Click += this.btnFontAndColor_Click;
-            this.FontPanel.btnDetail.Click += this.btnFontAndColor_Click;
-            this.FontPanel.btnListFont.Click += this.btnFontAndColor_Click;
-            this.FontPanel.btnFav.Click += this.btnColor_Click;
-            this.FontPanel.btnOWL.Click += this.btnColor_Click;
-            this.FontPanel.btnRetweet.Click += this.btnColor_Click;
-            this.FontPanel.btnDetailBack.Click += this.btnColor_Click;
-            this.FontPanel.btnDetailLink.Click += this.btnColor_Click;
-            this.FontPanel2.btnInputFont.Click += this.btnFontAndColor_Click;
-            this.FontPanel2.btnSelf.Click += this.btnColor_Click;
-            this.FontPanel2.btnAtSelf.Click += this.btnColor_Click;
-            this.FontPanel2.btnTarget.Click += this.btnColor_Click;
-            this.FontPanel2.btnAtTarget.Click += this.btnColor_Click;
-            this.FontPanel2.btnAtFromTarget.Click += this.btnColor_Click;
-            this.FontPanel2.btnInputBackcolor.Click += this.btnColor_Click;
-            this.FontPanel2.btnAtTo.Click += this.btnColor_Click;
-            this.FontPanel2.btnListBack.Click += this.btnColor_Click;
-
-            this.Icon = Properties.Resources.MIcon;
-        }
+            => this.OpenUrl("https://twitter.com/signup");
 
         private void GetPeriodPanel_IntervalChanged(object sender, IntervalChangedEventArgs e)
-        {
-            if (this.IntervalChanged != null)
-                this.IntervalChanged(sender, e);
-        }
+            => this.IntervalChanged?.Invoke(sender, e);
     }
 
     public class IntervalChangedEventArgs : EventArgs
@@ -1345,5 +363,16 @@ namespace OpenTween
         public bool PublicSearch;
         public bool Lists;
         public bool UserTimeline;
+
+        public static IntervalChangedEventArgs ResetAll => new IntervalChangedEventArgs
+        {
+            UserStream = true,
+            Timeline = true,
+            Reply = true,
+            DirectMessage = true,
+            PublicSearch = true,
+            Lists = true,
+            UserTimeline = true,
+        };
     }
 }