OSDN Git Service

NotifyPanelに対する設定値の設定・取得を LoadConfing/SaveConfig メソッドに移動
[opentween/open-tween.git] / OpenTween / Setting / Panel / NotifyPanel.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2014      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 //
10 // This file is part of OpenTween.
11 //
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 //
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 using System;
28 using System.Collections.Generic;
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Data;
32 using System.Linq;
33 using System.Text;
34 using System.Windows.Forms;
35 using System.IO;
36
37 namespace OpenTween.Setting.Panel
38 {
39     public partial class NotifyPanel : SettingPanelBase
40     {
41         public NotifyPanel()
42         {
43             InitializeComponent();
44         }
45
46         public void LoadConfig(SettingCommon settingCommon)
47         {
48             this.ApplyEventNotifyFlag(settingCommon.EventNotifyEnabled, settingCommon.EventNotifyFlag, settingCommon.IsMyEventNotifyFlag);
49             this.CheckForceEventNotify.Checked = settingCommon.ForceEventNotify;
50             this.CheckFavEventUnread.Checked = settingCommon.FavEventUnread;
51
52             this.SoundFileListup();
53             var soundFileIdx = this.ComboBoxEventNotifySound.Items.IndexOf(settingCommon.EventSoundFile);
54             if (soundFileIdx != -1)
55                 this.ComboBoxEventNotifySound.SelectedIndex = soundFileIdx;
56
57             this.IsRemoveSameFavEventCheckBox.Checked = settingCommon.IsRemoveSameEvent;
58         }
59
60         public void SaveConfig(SettingCommon settingCommon)
61         {
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;
68         }
69
70         private void SoundFileListup()
71         {
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")))
76             {
77                 oDir = oDir.GetDirectories("Sounds")[0];
78             }
79             foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
80             {
81                 this.ComboBoxEventNotifySound.Items.Add(oFile.Name);
82             }
83         }
84
85         private class EventCheckboxTblElement
86         {
87             public CheckBox CheckBox;
88             public MyCommon.EVENTTYPE Type;
89         }
90
91         private EventCheckboxTblElement[] GetEventCheckboxTable()
92         {
93             return new[]
94             {
95                 new EventCheckboxTblElement
96                 {
97                     CheckBox = this.CheckFavoritesEvent,
98                     Type = MyCommon.EVENTTYPE.Favorite,
99                 },
100                 new EventCheckboxTblElement
101                 {
102                     CheckBox = this.CheckUnfavoritesEvent,
103                     Type = MyCommon.EVENTTYPE.Unfavorite,
104                 },
105                 new EventCheckboxTblElement
106                 {
107                     CheckBox = this.CheckFollowEvent,
108                     Type = MyCommon.EVENTTYPE.Follow,
109                 },
110                 new EventCheckboxTblElement
111                 {
112                     CheckBox = this.CheckListMemberAddedEvent,
113                     Type = MyCommon.EVENTTYPE.ListMemberAdded,
114                 },
115                 new EventCheckboxTblElement
116                 {
117                     CheckBox = this.CheckListMemberRemovedEvent,
118                     Type = MyCommon.EVENTTYPE.ListMemberRemoved,
119                 },
120                 new EventCheckboxTblElement
121                 {
122                     CheckBox = this.CheckBlockEvent,
123                     Type = MyCommon.EVENTTYPE.Block,
124                 },
125                 new EventCheckboxTblElement
126                 {
127                     CheckBox = this.CheckUserUpdateEvent,
128                     Type = MyCommon.EVENTTYPE.UserUpdate,
129                 },
130                 new EventCheckboxTblElement
131                 {
132                     CheckBox = this.CheckListCreatedEvent,
133                     Type = MyCommon.EVENTTYPE.ListCreated,
134                 },
135             };
136         }
137
138         private void GetEventNotifyFlag(ref MyCommon.EVENTTYPE eventnotifyflag, ref MyCommon.EVENTTYPE isMyeventnotifyflag)
139         {
140             MyCommon.EVENTTYPE evt = MyCommon.EVENTTYPE.None;
141             MyCommon.EVENTTYPE myevt = MyCommon.EVENTTYPE.None;
142
143             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
144             {
145                 switch (tbl.CheckBox.CheckState)
146                 {
147                     case CheckState.Checked:
148                         evt = evt | tbl.Type;
149                         myevt = myevt | tbl.Type;
150                         break;
151                     case CheckState.Indeterminate:
152                         evt = evt | tbl.Type;
153                         break;
154                     case CheckState.Unchecked:
155                         break;
156                 }
157             }
158             eventnotifyflag = evt;
159             isMyeventnotifyflag = myevt;
160         }
161
162         private void ApplyEventNotifyFlag(bool rootEnabled, MyCommon.EVENTTYPE eventnotifyflag, MyCommon.EVENTTYPE isMyeventnotifyflag)
163         {
164             MyCommon.EVENTTYPE evt = eventnotifyflag;
165             MyCommon.EVENTTYPE myevt = isMyeventnotifyflag;
166
167             this.CheckEventNotify.Checked = rootEnabled;
168
169             foreach (EventCheckboxTblElement tbl in GetEventCheckboxTable())
170             {
171                 if ((evt & tbl.Type) != 0)
172                 {
173                     if ((myevt & tbl.Type) != 0)
174                     {
175                         tbl.CheckBox.CheckState = CheckState.Checked;
176                     }
177                     else
178                     {
179                         tbl.CheckBox.CheckState = CheckState.Indeterminate;
180                     }
181                 }
182                 else
183                 {
184                     tbl.CheckBox.CheckState = CheckState.Unchecked;
185                 }
186                 tbl.CheckBox.Enabled = rootEnabled;
187             }
188         }
189
190         private void CheckEventNotify_CheckedChanged(object sender, EventArgs e)
191         {
192             foreach (var tbl in this.GetEventCheckboxTable())
193             {
194                 tbl.CheckBox.Enabled = this.CheckEventNotify.Checked;
195             }
196         }
197     }
198 }