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.
10 // This file is part of OpenTween.
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)
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
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.
28 using System.Collections.Generic;
29 using System.ComponentModel;
34 using System.Windows.Forms;
35 using System.Threading;
37 using System.Resources;
39 using OpenTween.Connection;
40 using OpenTween.Thumbnail;
41 using System.Threading.Tasks;
42 using OpenTween.Setting.Panel;
46 public partial class AppendSettingDialog : OTBaseForm
48 private static AppendSettingDialog _instance = new AppendSettingDialog();
51 private bool _ValidationError = false;
52 private MyCommon.EVENTTYPE _MyEventNotifyFlag;
53 private MyCommon.EVENTTYPE _isMyEventNotifyFlag;
55 public List<UserAccount> UserAccounts;
56 private long? InitialUserId;
57 public bool IsRemoveSameEvent;
59 public TwitterConfiguration TwitterConfiguration = TwitterConfiguration.DefaultConfiguration();
63 public event EventHandler<IntervalChangedEventArgs> IntervalChanged;
65 public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
67 this.GetPeriodPanel.LoadConfig(settingCommon);
68 this.StartupPanel.LoadConfig(settingCommon);
69 this.TweetPrvPanel.LoadConfig(settingCommon);
70 this.TweetActPanel.LoadConfig(settingCommon, settingLocal);
71 this.ActionPanel.LoadConfig(settingCommon, settingLocal);
72 this.FontPanel.LoadConfig(settingLocal);
73 this.FontPanel2.LoadConfig(settingLocal);
74 this.PreviewPanel.LoadConfig(settingCommon);
75 this.GetCountPanel.LoadConfig(settingCommon);
76 this.ShortUrlPanel.LoadConfig(settingCommon);
77 this.ProxyPanel.LoadConfig(settingLocal);
78 this.CooperatePanel.LoadConfig(settingCommon);
79 this.ConnectionPanel.LoadConfig(settingCommon);
82 public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
84 this.GetPeriodPanel.SaveConfig(settingCommon);
85 this.StartupPanel.SaveConfig(settingCommon);
86 this.TweetPrvPanel.SaveConfig(settingCommon);
87 this.TweetActPanel.SaveConfig(settingCommon, settingLocal);
88 this.ActionPanel.SaveConfig(settingCommon, settingLocal);
89 this.FontPanel.SaveConfig(settingLocal);
90 this.FontPanel2.SaveConfig(settingLocal);
91 this.PreviewPanel.SaveConfig(settingCommon);
92 this.GetCountPanel.SaveConfig(settingCommon);
93 this.ShortUrlPanel.SaveConfig(settingCommon);
94 this.ProxyPanel.SaveConfig(settingLocal);
95 this.CooperatePanel.SaveConfig(settingCommon);
96 this.ConnectionPanel.SaveConfig(settingCommon);
99 private void TreeViewSetting_BeforeSelect(object sender, TreeViewCancelEventArgs e)
101 if (this.TreeViewSetting.SelectedNode == null) return;
102 var pnl = (SettingPanelBase)this.TreeViewSetting.SelectedNode.Tag;
103 if (pnl == null) return;
108 private void TreeViewSetting_AfterSelect(object sender, TreeViewEventArgs e)
110 if (e.Node == null) return;
111 var pnl = (SettingPanelBase)e.Node.Tag;
112 if (pnl == null) return;
116 if (pnl.Name == "PreviewPanel")
118 if (GrowlHelper.IsDllExists)
120 this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = true;
124 this.PreviewPanel.IsNotifyUseGrowlCheckBox.Enabled = false;
129 private void Save_Click(object sender, EventArgs e)
131 if (MyCommon.IsNetworkAvailable() &&
132 (this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || this.ShortUrlPanel.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
134 // bit.ly 短縮機能実装のプライバシー問題の暫定対応
135 // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
136 // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
137 if (string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyId.Text) || string.IsNullOrEmpty(this.ShortUrlPanel.TextBitlyPw.Text))
139 MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
140 _ValidationError = true;
141 TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
142 TreeViewSetting.Select();
143 this.ShortUrlPanel.TextBitlyId.Focus();
147 if (!BitlyValidation(this.ShortUrlPanel.TextBitlyId.Text, this.ShortUrlPanel.TextBitlyPw.Text))
149 MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
150 _ValidationError = true;
151 TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
152 TreeViewSetting.Select();
153 this.ShortUrlPanel.TextBitlyId.Focus();
158 _ValidationError = false;
163 _ValidationError = false;
166 this.UserAccounts.Clear();
167 foreach (object u in this.BasedPanel.AuthUserCombo.Items)
169 this.UserAccounts.Add((UserAccount)u);
171 if (this.BasedPanel.AuthUserCombo.SelectedIndex > -1)
173 foreach (UserAccount u in this.UserAccounts)
175 if (u.Username.ToLower() == ((UserAccount)this.BasedPanel.AuthUserCombo.SelectedItem).Username.ToLower())
177 tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
180 tw.VerifyCredentials();
181 u.UserId = tw.UserId;
190 tw.Initialize("", "", "", 0);
195 if (this.FollowCheckBox.Checked)
198 HttpConnection.ProxyType ptype;
199 if (RadioProxyNone.Checked)
201 ptype = HttpConnection.ProxyType.None;
203 else if (RadioProxyIE.Checked)
205 ptype = HttpConnection.ProxyType.IE;
209 ptype = HttpConnection.ProxyType.Specified;
211 string padr = TextProxyAddress.Text.Trim();
212 int pport = int.Parse(TextProxyPort.Text.Trim());
213 string pusr = TextProxyUser.Text.Trim();
214 string ppw = TextProxyPassword.Text.Trim();
215 HttpConnection.InitializeConnection(20, ptype, padr, pport, pusr, ppw);
217 string ret = tw.PostFollowCommand(ApplicationSettings.FeedbackTwitterName);
222 EventNotifyEnabled = this.NotifyPanel.CheckEventNotify.Checked;
223 GetEventNotifyFlag(ref _MyEventNotifyFlag, ref _isMyEventNotifyFlag);
224 ForceEventNotify = this.NotifyPanel.CheckForceEventNotify.Checked;
225 FavEventUnread = this.NotifyPanel.CheckFavEventUnread.Checked;
226 EventSoundFile = (string)this.NotifyPanel.ComboBoxEventNotifySound.SelectedItem;
227 this.IsRemoveSameEvent = this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked;
231 MessageBox.Show(Properties.Resources.Save_ClickText3);
232 this.DialogResult = DialogResult.Cancel;
237 private void Setting_FormClosing(object sender, FormClosingEventArgs e)
239 if (MyCommon._endingFlag) return;
241 if (this.DialogResult == DialogResult.Cancel)
243 //キャンセル時は画面表示時のアカウントに戻す
244 //キャンセル時でも認証済みアカウント情報は保存する
245 this.UserAccounts.Clear();
246 foreach (object u in this.BasedPanel.AuthUserCombo.Items)
248 this.UserAccounts.Add((UserAccount)u);
250 //アクティブユーザーを起動時のアカウントに戻す(起動時アカウントなければ何もしない)
251 bool userSet = false;
252 if (this.InitialUserId != null)
254 foreach (UserAccount u in this.UserAccounts)
256 if (u.UserId == this.InitialUserId)
258 tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
264 //認証済みアカウントが削除されていた場合、もしくは起動時アカウントがなかった場合は、
269 tw.Initialize("", "", "", 0);
273 if (tw != null && string.IsNullOrEmpty(tw.Username) && e.CloseReason == CloseReason.None)
275 if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
280 if (_ValidationError)
284 if (e.Cancel == false && TreeViewSetting.SelectedNode != null)
286 var curPanel = (SettingPanelBase)TreeViewSetting.SelectedNode.Tag;
287 curPanel.Visible = false;
288 curPanel.Enabled = false;
292 private void Setting_Load(object sender, EventArgs e)
294 tw = ((TweenMain)this.Owner).TwitterInstance;
295 //this.AuthStateLabel.Enabled = true;
296 //this.AuthUserLabel.Enabled = true;
297 this.BasedPanel.AuthClearButton.Enabled = true;
299 //if (tw.Username == "")
301 // //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4
302 // //this.AuthUserLabel.Text = ""
303 // //this.Save.Enabled = false
307 // //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
308 // //if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWrite)
310 // // this.AuthStateLabel.Text += "(xAuth)";
312 // //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
314 // // this.AuthStateLabel.Text += "(OAuth)";
316 // //this.AuthUserLabel.Text = tw.Username;
319 this.BasedPanel.AuthUserCombo.Items.Clear();
320 if (this.UserAccounts.Count > 0)
322 this.BasedPanel.AuthUserCombo.Items.AddRange(this.UserAccounts.ToArray());
323 foreach (UserAccount u in this.UserAccounts)
325 if (u.UserId == tw.UserId)
327 this.BasedPanel.AuthUserCombo.SelectedItem = u;
328 this.InitialUserId = u.UserId;
334 ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
335 this.NotifyPanel.CheckForceEventNotify.Checked = ForceEventNotify;
336 this.NotifyPanel.CheckFavEventUnread.Checked = FavEventUnread;
339 this.NotifyPanel.IsRemoveSameFavEventCheckBox.Checked = this.IsRemoveSameEvent;
341 this.TreeViewSetting.Nodes["BasedNode"].Tag = BasedPanel;
342 this.TreeViewSetting.Nodes["BasedNode"].Nodes["PeriodNode"].Tag = GetPeriodPanel;
343 this.TreeViewSetting.Nodes["BasedNode"].Nodes["StartUpNode"].Tag = StartupPanel;
344 this.TreeViewSetting.Nodes["BasedNode"].Nodes["GetCountNode"].Tag = GetCountPanel;
345 //this.TreeViewSetting.Nodes["BasedNode"].Nodes["UserStreamNode"].Tag = UserStreamPanel;
346 this.TreeViewSetting.Nodes["ActionNode"].Tag = ActionPanel;
347 this.TreeViewSetting.Nodes["ActionNode"].Nodes["TweetActNode"].Tag = TweetActPanel;
348 this.TreeViewSetting.Nodes["PreviewNode"].Tag = PreviewPanel;
349 this.TreeViewSetting.Nodes["PreviewNode"].Nodes["TweetPrvNode"].Tag = TweetPrvPanel;
350 this.TreeViewSetting.Nodes["PreviewNode"].Nodes["NotifyNode"].Tag = NotifyPanel;
351 this.TreeViewSetting.Nodes["FontNode"].Tag = FontPanel;
352 this.TreeViewSetting.Nodes["FontNode"].Nodes["FontNode2"].Tag = FontPanel2;
353 this.TreeViewSetting.Nodes["ConnectionNode"].Tag = ConnectionPanel;
354 this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ProxyNode"].Tag = ProxyPanel;
355 this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["CooperateNode"].Tag = CooperatePanel;
356 this.TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"].Tag = ShortUrlPanel;
358 this.TreeViewSetting.SelectedNode = this.TreeViewSetting.Nodes[0];
359 this.TreeViewSetting.ExpandAll();
361 //TreeViewSetting.SelectedNode = TreeViewSetting.TopNode;
362 ActiveControl = BasedPanel.StartAuthButton;
365 private void UReadMng_CheckedChanged(object sender, EventArgs e)
367 if (this.ActionPanel.UReadMng.Checked == true)
369 this.StartupPanel.StartupReaded.Enabled = true;
373 this.StartupPanel.StartupReaded.Enabled = false;
377 private void btnFontAndColor_Click(object sender, EventArgs e) // Handles btnUnread.Click, btnDetail.Click, btnListFont.Click, btnInputFont.Click
379 Button Btn = (Button) sender;
382 FontDialog1.AllowVerticalFonts = false;
383 FontDialog1.AllowScriptChange = true;
384 FontDialog1.AllowSimulations = true;
385 FontDialog1.AllowVectorFonts = true;
386 FontDialog1.FixedPitchOnly = false;
387 FontDialog1.FontMustExist = true;
388 FontDialog1.ScriptsOnly = false;
389 FontDialog1.ShowApply = false;
390 FontDialog1.ShowEffects = true;
391 FontDialog1.ShowColor = true;
396 FontDialog1.Color = this.FontPanel.lblUnread.ForeColor;
397 FontDialog1.Font = this.FontPanel.lblUnread.Font;
400 FontDialog1.Color = this.FontPanel.lblDetail.ForeColor;
401 FontDialog1.Font = this.FontPanel.lblDetail.Font;
404 FontDialog1.Color = this.FontPanel.lblListFont.ForeColor;
405 FontDialog1.Font = this.FontPanel.lblListFont.Font;
408 FontDialog1.Color = this.FontPanel2.lblInputFont.ForeColor;
409 FontDialog1.Font = this.FontPanel2.lblInputFont.Font;
415 rtn = FontDialog1.ShowDialog();
417 catch(ArgumentException ex)
419 MessageBox.Show(ex.Message);
423 if (rtn == DialogResult.Cancel) return;
428 this.FontPanel.lblUnread.ForeColor = FontDialog1.Color;
429 this.FontPanel.lblUnread.Font = FontDialog1.Font;
432 this.FontPanel.lblDetail.ForeColor = FontDialog1.Color;
433 this.FontPanel.lblDetail.Font = FontDialog1.Font;
436 this.FontPanel.lblListFont.ForeColor = FontDialog1.Color;
437 this.FontPanel.lblListFont.Font = FontDialog1.Font;
440 this.FontPanel2.lblInputFont.ForeColor = FontDialog1.Color;
441 this.FontPanel2.lblInputFont.Font = FontDialog1.Font;
447 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
449 Button Btn = (Button)sender;
452 ColorDialog1.AllowFullOpen = true;
453 ColorDialog1.AnyColor = true;
454 ColorDialog1.FullOpen = false;
455 ColorDialog1.SolidColorOnly = false;
460 ColorDialog1.Color = this.FontPanel2.lblSelf.BackColor;
463 ColorDialog1.Color = this.FontPanel2.lblAtSelf.BackColor;
466 ColorDialog1.Color = this.FontPanel2.lblTarget.BackColor;
469 ColorDialog1.Color = this.FontPanel2.lblAtTarget.BackColor;
471 case "btnAtFromTarget":
472 ColorDialog1.Color = this.FontPanel2.lblAtFromTarget.BackColor;
475 ColorDialog1.Color = this.FontPanel.lblFav.ForeColor;
478 ColorDialog1.Color = this.FontPanel.lblOWL.ForeColor;
481 ColorDialog1.Color = this.FontPanel.lblRetweet.ForeColor;
483 case "btnInputBackcolor":
484 ColorDialog1.Color = this.FontPanel2.lblInputBackcolor.BackColor;
487 ColorDialog1.Color = this.FontPanel2.lblAtTo.BackColor;
490 ColorDialog1.Color = this.FontPanel2.lblListBackcolor.BackColor;
492 case "btnDetailBack":
493 ColorDialog1.Color = this.FontPanel.lblDetailBackcolor.BackColor;
495 case "btnDetailLink":
496 ColorDialog1.Color = this.FontPanel.lblDetailLink.ForeColor;
500 rtn = ColorDialog1.ShowDialog();
502 if (rtn == DialogResult.Cancel) return;
507 this.FontPanel2.lblSelf.BackColor = ColorDialog1.Color;
510 this.FontPanel2.lblAtSelf.BackColor = ColorDialog1.Color;
513 this.FontPanel2.lblTarget.BackColor = ColorDialog1.Color;
516 this.FontPanel2.lblAtTarget.BackColor = ColorDialog1.Color;
518 case "btnAtFromTarget":
519 this.FontPanel2.lblAtFromTarget.BackColor = ColorDialog1.Color;
522 this.FontPanel.lblFav.ForeColor = ColorDialog1.Color;
525 this.FontPanel.lblOWL.ForeColor = ColorDialog1.Color;
528 this.FontPanel.lblRetweet.ForeColor = ColorDialog1.Color;
530 case "btnInputBackcolor":
531 this.FontPanel2.lblInputBackcolor.BackColor = ColorDialog1.Color;
534 this.FontPanel2.lblAtTo.BackColor = ColorDialog1.Color;
537 this.FontPanel2.lblListBackcolor.BackColor = ColorDialog1.Color;
539 case "btnDetailBack":
540 this.FontPanel.lblDetailBackcolor.BackColor = ColorDialog1.Color;
542 case "btnDetailLink":
543 this.FontPanel.lblDetailLink.ForeColor = ColorDialog1.Color;
548 public string RecommendStatusText { get; set; }
550 public bool EventNotifyEnabled { get; set; }
552 public MyCommon.EVENTTYPE EventNotifyFlag
556 return _MyEventNotifyFlag;
560 _MyEventNotifyFlag = value;
564 public MyCommon.EVENTTYPE IsMyEventNotifyFlag
568 return _isMyEventNotifyFlag;
572 _isMyEventNotifyFlag = value;
576 public bool ForceEventNotify { get; set; }
577 public bool FavEventUnread { get; set; }
579 public string EventSoundFile { get; set; }
581 private bool StartAuth()
585 if (this.ProxyPanel.RadioProxyNone.Checked)
587 ptype = ProxyType.None;
589 else if (this.ProxyPanel.RadioProxyIE.Checked)
591 ptype = ProxyType.IE;
595 ptype = ProxyType.Specified;
597 string padr = this.ProxyPanel.TextProxyAddress.Text.Trim();
598 int pport = int.Parse(this.ProxyPanel.TextProxyPort.Text.Trim());
599 string pusr = this.ProxyPanel.TextProxyUser.Text.Trim();
600 string ppw = this.ProxyPanel.TextProxyPassword.Text.Trim();
603 Networking.DefaultTimeout = TimeSpan.FromSeconds(20);
604 Networking.SetWebProxy(ptype, padr, pport, pusr, ppw);
605 HttpTwitter.TwitterUrl = this.ConnectionPanel.TwitterAPIText.Text.Trim();
606 tw.Initialize("", "", "", 0);
607 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
608 //this.AuthUserLabel.Text = "";
609 string pinPageUrl = "";
610 string rslt = tw.StartAuthentication(ref pinPageUrl);
611 if (string.IsNullOrEmpty(rslt))
613 string pin = AuthDialog.DoAuth(this, pinPageUrl);
614 if (!string.IsNullOrEmpty(pin))
626 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
631 private bool PinAuth()
633 string pin = this._pin; //PIN Code
635 string rslt = tw.Authenticate(pin);
636 if (string.IsNullOrEmpty(rslt))
638 MessageBox.Show(Properties.Resources.AuthorizeButton_Click1, "Authenticate", MessageBoxButtons.OK);
639 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
640 //this.AuthUserLabel.Text = tw.Username;
642 UserAccount user = new UserAccount();
643 user.Username = tw.Username;
644 user.UserId = tw.UserId;
645 user.Token = tw.AccessToken;
646 user.TokenSecret = tw.AccessTokenSecret;
648 foreach (object u in this.BasedPanel.AuthUserCombo.Items)
650 if (((UserAccount)u).Username.ToLower() == tw.Username.ToLower())
652 idx = this.BasedPanel.AuthUserCombo.Items.IndexOf(u);
658 this.BasedPanel.AuthUserCombo.Items.RemoveAt(idx);
659 this.BasedPanel.AuthUserCombo.Items.Insert(idx, user);
660 this.BasedPanel.AuthUserCombo.SelectedIndex = idx;
664 this.BasedPanel.AuthUserCombo.SelectedIndex = this.BasedPanel.AuthUserCombo.Items.Add(user);
666 //if (TwitterApiInfo.AccessLevel = ApiAccessLevel.ReadWrite)
668 // this.AuthStateLabel.Text += "(xAuth)";
670 //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
672 // this.AuthStateLabel.Text += "(OAuth)";
678 MessageBox.Show(Properties.Resources.AuthorizeButton_Click2 + Environment.NewLine + rslt, "Authenticate", MessageBoxButtons.OK);
679 //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4;
680 //this.AuthUserLabel.Text = "";
685 private void StartAuthButton_Click(object sender, EventArgs e)
687 //this.Save.Enabled = false;
692 //this.Save.Enabled = true;
697 private void CheckPostAndGet_CheckedChanged(object sender, EventArgs e)
699 this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
702 private void Setting_Shown(object sender, EventArgs e)
707 if (this.Disposing || this.IsDisposed) return;
708 } while (!this.IsHandleCreated);
709 this.TopMost = this.PreviewPanel.CheckAlwaysTop.Checked;
711 this.GetPeriodPanel.LabelPostAndGet.Visible = this.GetPeriodPanel.CheckPostAndGet.Checked && !tw.UserStreamEnabled;
712 this.GetPeriodPanel.LabelUserStreamActive.Visible = tw.UserStreamEnabled;
715 public static AppendSettingDialog Instance
717 get { return _instance; }
720 private bool BitlyValidation(string id, string apikey)
722 if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(apikey))
727 string req = "http://api.bit.ly/v3/validate";
729 Dictionary<string, string> param = new Dictionary<string, string>();
731 param.Add("login", ApplicationSettings.BitlyLoginId);
732 param.Add("apiKey", ApplicationSettings.BitlyApiKey);
733 param.Add("x_login", id);
734 param.Add("x_apiKey", apikey);
735 param.Add("format", "txt");
737 if (!(new HttpVarious()).PostData(req, param, out content))
739 return true; // 通信エラーの場合はとりあえずチェックを通ったことにする
741 else if (content.Trim() == "1")
745 else if (content.Trim() == "0")
747 return false; // 検証失敗 APIキーとIDの組み合わせが違う
751 return true; // 規定外応答:通信エラーの可能性があるためとりあえずチェックを通ったことにする
755 private void Cancel_Click(object sender, EventArgs e)
757 _ValidationError = false;
760 //private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
761 // Handles CheckEventNotify.CheckedChanged, CheckFavoritesEvent.CheckStateChanged,
762 // CheckUnfavoritesEvent.CheckStateChanged, CheckFollowEvent.CheckStateChanged,
763 // CheckListMemberAddedEvent.CheckStateChanged, CheckListMemberRemovedEvent.CheckStateChanged,
764 // CheckListCreatedEvent.CheckStateChanged, CheckUserUpdateEvent.CheckStateChanged
766 // EventNotifyEnabled = CheckEventNotify.Checked;
767 // GetEventNotifyFlag(EventNotifyFlag, IsMyEventNotifyFlag);
768 // ApplyEventNotifyFlag(EventNotifyEnabled, EventNotifyFlag, IsMyEventNotifyFlag);
771 private class EventCheckboxTblElement
773 public CheckBox CheckBox;
774 public MyCommon.EVENTTYPE Type;
777 private EventCheckboxTblElement[] GetEventCheckboxTable()
779 EventCheckboxTblElement[] _eventCheckboxTable = new EventCheckboxTblElement[8];
781 _eventCheckboxTable[0] = new EventCheckboxTblElement();
782 _eventCheckboxTable[0].CheckBox = this.NotifyPanel.CheckFavoritesEvent;
783 _eventCheckboxTable[0].Type = MyCommon.EVENTTYPE.Favorite;
785 _eventCheckboxTable[1] = new EventCheckboxTblElement();
786 _eventCheckboxTable[1].CheckBox = this.NotifyPanel.CheckUnfavoritesEvent;
787 _eventCheckboxTable[1].Type = MyCommon.EVENTTYPE.Unfavorite;
789 _eventCheckboxTable[2] = new EventCheckboxTblElement();
790 _eventCheckboxTable[2].CheckBox = this.NotifyPanel.CheckFollowEvent;
791 _eventCheckboxTable[2].Type = MyCommon.EVENTTYPE.Follow;
793 _eventCheckboxTable[3] = new EventCheckboxTblElement();
794 _eventCheckboxTable[3].CheckBox = this.NotifyPanel.CheckListMemberAddedEvent;
795 _eventCheckboxTable[3].Type = MyCommon.EVENTTYPE.ListMemberAdded;
797 _eventCheckboxTable[4] = new EventCheckboxTblElement();
798 _eventCheckboxTable[4].CheckBox = this.NotifyPanel.CheckListMemberRemovedEvent;
799 _eventCheckboxTable[4].Type = MyCommon.EVENTTYPE.ListMemberRemoved;
801 _eventCheckboxTable[5] = new EventCheckboxTblElement();
802 _eventCheckboxTable[5].CheckBox = this.NotifyPanel.CheckBlockEvent;
803 _eventCheckboxTable[5].Type = MyCommon.EVENTTYPE.Block;
805 _eventCheckboxTable[6] = new EventCheckboxTblElement();
806 _eventCheckboxTable[6].CheckBox = this.NotifyPanel.CheckUserUpdateEvent;
807 _eventCheckboxTable[6].Type = MyCommon.EVENTTYPE.UserUpdate;
809 _eventCheckboxTable[7] = new EventCheckboxTblElement();
810 _eventCheckboxTable[7].CheckBox = this.NotifyPanel.CheckListCreatedEvent;
811 _eventCheckboxTable[7].Type = MyCommon.EVENTTYPE.ListCreated;
813 return _eventCheckboxTable;
816 private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
818 MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
819 MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
821 foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
823 switch (tbl.CheckBox.CheckState)
825 case CheckState.Checked:
826 evt = evt | tbl.Type;
827 myevt = myevt | tbl.Type;
829 case CheckState.Indeterminate:
830 evt = evt | tbl.Type;
832 case CheckState.Unchecked:
836 eventnotifyflag = evt;
837 isMyeventnotifyflag = myevt;
840 private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
842 MyCommon.EVENTTYPE evt = eventnotifyflag;
843 MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
845 this.NotifyPanel.CheckEventNotify.Checked = rootEnabled;
847 foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
849 if ((evt & tbl.Type) != 0)
851 if ((myevt & tbl.Type) != 0)
853 tbl.CheckBox.CheckState = CheckState.Checked;
857 tbl.CheckBox.CheckState = CheckState.Indeterminate;
862 tbl.CheckBox.CheckState = CheckState.Unchecked;
864 tbl.CheckBox.Enabled = rootEnabled;
869 private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
871 foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
873 tbl.CheckBox.Enabled = this.NotifyPanel.CheckEventNotify.Checked;
877 //private void CheckForceEventNotify_CheckedChanged(object sender, EventArgs e)
879 // _MyForceEventNotify = CheckEventNotify.Checked;
882 //private void CheckFavEventUnread_CheckedChanged(object sender, EventArgs e)
884 // _MyFavEventUnread = CheckFavEventUnread.Checked;
887 //private void ComboBoxTranslateLanguage_SelectedIndexChanged(object sender, EventArgs e)
889 // _MyTranslateLanguage = (new Google()).GetLanguageEnumFromIndex(ComboBoxTranslateLanguage.SelectedIndex);
892 private void SoundFileListup()
894 if (EventSoundFile == null) EventSoundFile = "";
895 this.NotifyPanel.ComboBoxEventNotifySound.Items.Clear();
896 this.NotifyPanel.ComboBoxEventNotifySound.Items.Add("");
897 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
898 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
900 oDir = oDir.GetDirectories("Sounds")[0];
902 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
904 this.NotifyPanel.ComboBoxEventNotifySound.Items.Add(oFile.Name);
906 int idx = this.NotifyPanel.ComboBoxEventNotifySound.Items.IndexOf(EventSoundFile);
907 if (idx == -1) idx = 0;
908 this.NotifyPanel.ComboBoxEventNotifySound.SelectedIndex = idx;
911 //private void ComboBoxEventNotifySound_VisibleChanged(object sender, EventArgs e)
913 // SoundFileListup();
916 //private void ComboBoxEventNotifySound_SelectedIndexChanged(object sender, EventArgs e)
918 // if (_soundfileListup) return;
920 // _MyEventSoundFile = (string)ComboBoxEventNotifySound.SelectedItem;
923 private void OpenUrl(string url)
926 string path = this.ActionPanel.BrowserPathText.Text;
929 if (!string.IsNullOrEmpty(path))
931 if (path.StartsWith("\"") && path.Length > 2 && path.IndexOf("\"", 2) > -1)
933 int sep = path.IndexOf("\"", 2);
934 string browserPath = path.Substring(1, sep - 1);
936 if (sep < path.Length - 1)
938 arg = path.Substring(sep + 1);
940 myPath = arg + " " + myPath;
941 System.Diagnostics.Process.Start(browserPath, myPath);
945 System.Diagnostics.Process.Start(path, myPath);
950 System.Diagnostics.Process.Start(myPath);
955 // MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
959 private void CreateAccountButton_Click(object sender, EventArgs e)
961 this.OpenUrl("https://twitter.com/signup");
964 public AppendSettingDialog()
966 InitializeComponent();
968 this.BasedPanel.StartAuthButton.Click += this.StartAuthButton_Click;
969 this.BasedPanel.CreateAccountButton.Click += this.CreateAccountButton_Click;
970 this.NotifyPanel.CheckEventNotify.CheckedChanged += this.CheckEventNotify_CheckedChanged;
971 this.GetPeriodPanel.CheckPostAndGet.CheckedChanged += this.CheckPostAndGet_CheckedChanged;
972 this.ActionPanel.UReadMng.CheckedChanged += this.UReadMng_CheckedChanged;
973 this.FontPanel.btnUnread.Click += this.btnFontAndColor_Click;
974 this.FontPanel.btnDetail.Click += this.btnFontAndColor_Click;
975 this.FontPanel.btnListFont.Click += this.btnFontAndColor_Click;
976 this.FontPanel.btnFav.Click += this.btnColor_Click;
977 this.FontPanel.btnOWL.Click += this.btnColor_Click;
978 this.FontPanel.btnRetweet.Click += this.btnColor_Click;
979 this.FontPanel.btnDetailBack.Click += this.btnColor_Click;
980 this.FontPanel.btnDetailLink.Click += this.btnColor_Click;
981 this.FontPanel2.btnInputFont.Click += this.btnFontAndColor_Click;
982 this.FontPanel2.btnSelf.Click += this.btnColor_Click;
983 this.FontPanel2.btnAtSelf.Click += this.btnColor_Click;
984 this.FontPanel2.btnTarget.Click += this.btnColor_Click;
985 this.FontPanel2.btnAtTarget.Click += this.btnColor_Click;
986 this.FontPanel2.btnAtFromTarget.Click += this.btnColor_Click;
987 this.FontPanel2.btnInputBackcolor.Click += this.btnColor_Click;
988 this.FontPanel2.btnAtTo.Click += this.btnColor_Click;
989 this.FontPanel2.btnListBack.Click += this.btnColor_Click;
991 this.Icon = Properties.Resources.MIcon;
994 private void GetPeriodPanel_IntervalChanged(object sender, IntervalChangedEventArgs e)
996 if (this.IntervalChanged != null)
997 this.IntervalChanged(sender, e);
1001 public class IntervalChangedEventArgs : EventArgs
1003 public bool UserStream;
1004 public bool Timeline;
1006 public bool DirectMessage;
1007 public bool PublicSearch;
1009 public bool UserTimeline;