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.
28 using System.Collections.Generic;
29 using System.ComponentModel;
34 using System.Windows.Forms;
37 namespace OpenTween.Setting.Panel
39 public partial class NotifyPanel : SettingPanelBase
43 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();
53 var soundFileIdx = this.ComboBoxEventNotifySound.Items.IndexOf(settingCommon.EventSoundFile);
54 if (soundFileIdx != -1)
55 this.ComboBoxEventNotifySound.SelectedIndex = soundFileIdx;
57 this.IsRemoveSameFavEventCheckBox.Checked = settingCommon.IsRemoveSameEvent;
60 public void SaveConfig(SettingCommon settingCommon)
62 settingCommon.EventNotifyEnabled = this.CheckEventNotify.Checked;
63 this.GetEventNotifyFlag(ref settingCommon.EventNotifyFlag, ref settingCommon.IsMyEventNotifyFlag);
64 settingCommon.ForceEventNotify = this.CheckForceEventNotify.Checked;
65 settingCommon.FavEventUnread = this.CheckFavEventUnread.Checked;
66 settingCommon.EventSoundFile = (string)this.ComboBoxEventNotifySound.SelectedItem;
67 settingCommon.IsRemoveSameEvent = this.IsRemoveSameFavEventCheckBox.Checked;
70 private void SoundFileListup()
72 this.ComboBoxEventNotifySound.Items.Clear();
73 this.ComboBoxEventNotifySound.Items.Add("");
74 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
75 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
77 oDir = oDir.GetDirectories("Sounds")[0];
79 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
81 this.ComboBoxEventNotifySound.Items.Add(oFile.Name);
85 private class EventCheckboxTblElement
87 public CheckBox CheckBox;
88 public MyCommon.EVENTTYPE Type;
91 private EventCheckboxTblElement[] GetEventCheckboxTable()
95 new EventCheckboxTblElement
97 CheckBox = this.CheckFavoritesEvent,
98 Type = MyCommon.EVENTTYPE.Favorite,
100 new EventCheckboxTblElement
102 CheckBox = this.CheckUnfavoritesEvent,
103 Type = MyCommon.EVENTTYPE.Unfavorite,
105 new EventCheckboxTblElement
107 CheckBox = this.CheckFollowEvent,
108 Type = MyCommon.EVENTTYPE.Follow,
110 new EventCheckboxTblElement
112 CheckBox = this.CheckListMemberAddedEvent,
113 Type = MyCommon.EVENTTYPE.ListMemberAdded,
115 new EventCheckboxTblElement
117 CheckBox = this.CheckListMemberRemovedEvent,
118 Type = MyCommon.EVENTTYPE.ListMemberRemoved,
120 new EventCheckboxTblElement
122 CheckBox = this.CheckBlockEvent,
123 Type = MyCommon.EVENTTYPE.Block,
125 new EventCheckboxTblElement
127 CheckBox = this.CheckUserUpdateEvent,
128 Type = MyCommon.EVENTTYPE.UserUpdate,
130 new EventCheckboxTblElement
132 CheckBox = this.CheckListCreatedEvent,
133 Type = MyCommon.EVENTTYPE.ListCreated,
138 private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
140 MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
141 MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
143 foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
145 switch (tbl.CheckBox.CheckState)
147 case CheckState.Checked:
148 evt = evt | tbl.Type;
149 myevt = myevt | tbl.Type;
151 case CheckState.Indeterminate:
152 evt = evt | tbl.Type;
154 case CheckState.Unchecked:
158 eventnotifyflag = evt;
159 isMyeventnotifyflag = myevt;
162 private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
164 MyCommon.EVENTTYPE evt = eventnotifyflag;
165 MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
167 this.CheckEventNotify.Checked = rootEnabled;
169 foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
171 if ((evt & tbl.Type) != 0)
173 if ((myevt & tbl.Type) != 0)
175 tbl.CheckBox.CheckState = CheckState.Checked;
179 tbl.CheckBox.CheckState = CheckState.Indeterminate;
184 tbl.CheckBox.CheckState = CheckState.Unchecked;
186 tbl.CheckBox.Enabled = rootEnabled;
190 private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
192 foreach (var tbl in this.GetEventCheckboxTable())
194 tbl.CheckBox.Enabled = this.CheckEventNotify.Checked;