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) 2014 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.
30 using System.Collections.Generic;
31 using System.ComponentModel;
36 using System.Windows.Forms;
39 namespace OpenTween.Setting.Panel
41 public partial class NotifyPanel : SettingPanelBase
44 => this.InitializeComponent();
46 public void LoadConfig(SettingCommon settingCommon)
48 this.ApplyEventNotifyFlag(settingCommon.EventNotifyEnabled, settingCommon.EventNotifyFlag, settingCommon.IsMyEventNotifyFlag);
49 this.CheckForceEventNotify.Checked = settingCommon.ForceEventNotify;
50 this.CheckFavEventUnread.Checked = settingCommon.FavEventUnread;
52 this.SoundFileListup();
54 var soundFile = settingCommon.EventSoundFile ?? "";
55 var soundFileIdx = this.ComboBoxEventNotifySound.Items.IndexOf(soundFile);
56 if (soundFileIdx != -1)
57 this.ComboBoxEventNotifySound.SelectedIndex = soundFileIdx;
59 this.IsRemoveSameFavEventCheckBox.Checked = settingCommon.IsRemoveSameEvent;
62 public void SaveConfig(SettingCommon settingCommon)
64 settingCommon.EventNotifyEnabled = this.CheckEventNotify.Checked;
65 this.GetEventNotifyFlag(ref settingCommon.EventNotifyFlag, ref settingCommon.IsMyEventNotifyFlag);
66 settingCommon.ForceEventNotify = this.CheckForceEventNotify.Checked;
67 settingCommon.FavEventUnread = this.CheckFavEventUnread.Checked;
68 settingCommon.EventSoundFile = (string)this.ComboBoxEventNotifySound.SelectedItem;
69 settingCommon.IsRemoveSameEvent = this.IsRemoveSameFavEventCheckBox.Checked;
72 private void SoundFileListup()
74 this.ComboBoxEventNotifySound.Items.Clear();
75 this.ComboBoxEventNotifySound.Items.Add("");
76 var oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
77 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
79 oDir = oDir.GetDirectories("Sounds")[0];
81 foreach (var oFile in oDir.GetFiles("*.wav"))
83 this.ComboBoxEventNotifySound.Items.Add(oFile.Name);
87 private class EventCheckboxTblElement
89 public CheckBox CheckBox = null!;
90 public MyCommon.EVENTTYPE Type;
93 private EventCheckboxTblElement[] GetEventCheckboxTable()
97 new EventCheckboxTblElement
99 CheckBox = this.CheckFavoritesEvent,
100 Type = MyCommon.EVENTTYPE.Favorite,
102 new EventCheckboxTblElement
104 CheckBox = this.CheckUnfavoritesEvent,
105 Type = MyCommon.EVENTTYPE.Unfavorite,
107 new EventCheckboxTblElement
109 CheckBox = this.CheckFollowEvent,
110 Type = MyCommon.EVENTTYPE.Follow,
112 new EventCheckboxTblElement
114 CheckBox = this.CheckListMemberAddedEvent,
115 Type = MyCommon.EVENTTYPE.ListMemberAdded,
117 new EventCheckboxTblElement
119 CheckBox = this.CheckListMemberRemovedEvent,
120 Type = MyCommon.EVENTTYPE.ListMemberRemoved,
122 new EventCheckboxTblElement
124 CheckBox = this.CheckBlockEvent,
125 Type = MyCommon.EVENTTYPE.Block,
127 new EventCheckboxTblElement
129 CheckBox = this.CheckUserUpdateEvent,
130 Type = MyCommon.EVENTTYPE.UserUpdate,
132 new EventCheckboxTblElement
134 CheckBox = this.CheckListCreatedEvent,
135 Type = MyCommon.EVENTTYPE.ListCreated,
137 new EventCheckboxTblElement
139 CheckBox = this.CheckQuotedTweetEvent,
140 Type = MyCommon.EVENTTYPE.QuotedTweet,
142 new EventCheckboxTblElement
144 CheckBox = this.CheckRetweetEvent,
145 Type = MyCommon.EVENTTYPE.Retweet,
150 private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
152 var evt = MyCommon.EVENTTYPE.None;
153 var myevt = MyCommon.EVENTTYPE.None;
155 foreach (var tbl in GetEventCheckboxTable())
157 switch (tbl.CheckBox.CheckState)
159 case CheckState.Checked:
163 case CheckState.Indeterminate:
166 case CheckState.Unchecked:
170 eventnotifyflag = evt;
171 isMyeventnotifyflag = myevt;
174 private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
176 var evt = eventnotifyflag;
177 var myevt = isMyeventnotifyflag;
179 this.CheckEventNotify.Checked = rootEnabled;
181 foreach (var tbl in GetEventCheckboxTable())
183 if ((evt & tbl.Type) != 0)
185 if ((myevt & tbl.Type) != 0)
187 tbl.CheckBox.CheckState = CheckState.Checked;
191 tbl.CheckBox.CheckState = CheckState.Indeterminate;
196 tbl.CheckBox.CheckState = CheckState.Unchecked;
198 tbl.CheckBox.Enabled = rootEnabled;
202 private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
204 foreach (var tbl in this.GetEventCheckboxTable())
206 tbl.CheckBox.Enabled = this.CheckEventNotify.Checked;