Winify – Blame information for rev 75
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
75 | office | 2 | using System.IO; |
4 | office | 3 | using System.Linq; |
30 | office | 4 | using System.Threading; |
1 | office | 5 | using System.Windows.Forms; |
15 | office | 6 | using Announcements; |
6 | office | 7 | using Servers; |
1 | office | 8 | |
25 | office | 9 | namespace Winify.Settings |
1 | office | 10 | { |
11 | public partial class SettingsForm : Form |
||
12 | { |
||
25 | office | 13 | #region Public Events & Delegates |
14 | |||
15 | public event EventHandler<SettingsSavedEventArgs> Save; |
||
16 | |||
17 | #endregion |
||
18 | |||
4 | office | 19 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
20 | |||
21 | office | 21 | private readonly BindingSource _announcementBindingSource; |
15 | office | 22 | |
55 | office | 23 | private Announcements.Announcements _announcements; |
21 | office | 24 | |
25 | private readonly BindingSource _serverBindingSource; |
||
26 | |||
55 | office | 27 | private Servers.Servers _servers; |
4 | office | 28 | |
21 | office | 29 | private Announcement _announcement; |
30 | |||
31 | private Server _server; |
||
30 | office | 32 | private readonly MainForm _mainForm; |
33 | private readonly CancellationToken _cancellationToken; |
||
44 | office | 34 | private readonly BindingSource _configurationBindingSource; |
50 | office | 35 | private readonly BindingSource _configurationProxyBindingSource; |
21 | office | 36 | |
4 | office | 37 | #endregion |
38 | |||
1 | office | 39 | #region Constructors, Destructors and Finalizers |
40 | |||
30 | office | 41 | public SettingsForm() |
1 | office | 42 | { |
43 | InitializeComponent(); |
||
44 | } |
||
45 | |||
55 | office | 46 | public SettingsForm(MainForm mainForm, Servers.Servers servers, Announcements.Announcements announcements, |
47 | CancellationToken cancellationToken) : this() |
||
4 | office | 48 | { |
30 | office | 49 | _mainForm = mainForm; |
4 | office | 50 | _servers = servers; |
55 | office | 51 | _announcements = announcements; |
30 | office | 52 | _cancellationToken = cancellationToken; |
7 | office | 53 | |
44 | office | 54 | _configurationBindingSource = new BindingSource(); |
55 | _configurationBindingSource.DataSource = _mainForm.Configuration; |
||
55 | office | 56 | |
50 | office | 57 | _configurationProxyBindingSource = new BindingSource(); |
58 | _configurationProxyBindingSource.DataSource = _mainForm.Configuration.Proxy; |
||
21 | office | 59 | |
58 | office | 60 | switch (_servers?.Server == null) |
61 | { |
||
62 | case true: |
||
63 | _servers = new Servers.Servers(); |
||
64 | _server = new Server(); |
||
65 | _servers.Server.Add(_server); |
||
66 | break; |
||
67 | default: |
||
68 | _server = _servers.Server.FirstOrDefault(); |
||
69 | if (_server == null) |
||
70 | { |
||
71 | _server = new Server(); |
||
72 | _servers.Server.Add(_server); |
||
73 | } |
||
74 | break; |
||
75 | } |
||
76 | |||
55 | office | 77 | _serverBindingSource = new BindingSource(); |
78 | _serverBindingSource.DataSource = _server; |
||
50 | office | 79 | |
58 | office | 80 | switch (_announcements?.Announcement == null) |
81 | { |
||
82 | case true: |
||
83 | _announcements = new Announcements.Announcements(); |
||
84 | _announcement = new Announcement(); |
||
85 | _announcements.Announcement.Add(_announcement); |
||
86 | break; |
||
87 | default: |
||
88 | _announcement = _announcements.Announcement.FirstOrDefault(); |
||
89 | if (_announcement == null) |
||
90 | { |
||
91 | _announcement = new Announcement(); |
||
92 | _announcements.Announcement.Add(_announcement); |
||
93 | } |
||
94 | break; |
||
95 | } |
||
96 | |||
21 | office | 97 | _announcementBindingSource = new BindingSource(); |
98 | _announcementBindingSource.DataSource = _announcement; |
||
4 | office | 99 | } |
100 | |||
1 | office | 101 | #endregion |
102 | |||
103 | #region Event Handlers |
||
104 | |||
4 | office | 105 | private void Button1_Click(object sender, EventArgs e) |
106 | { |
||
21 | office | 107 | var server = new Server(); |
48 | office | 108 | server.Name = "New Server"; |
4 | office | 109 | |
21 | office | 110 | _servers.Server.Add(server); |
48 | office | 111 | _serverBindingSource.DataSource = server; |
25 | office | 112 | |
43 | office | 113 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
114 | |||
25 | office | 115 | listBox1.SelectedItem = server; |
4 | office | 116 | } |
117 | |||
118 | private void Button2_Click(object sender, EventArgs e) |
||
119 | { |
||
48 | office | 120 | var index = -1; |
121 | |||
122 | if (listBox1.SelectedItem is Server server) |
||
123 | { |
||
124 | index = listBox1.Items.IndexOf(server); |
||
125 | _servers.Server.Remove(server); |
||
126 | } |
||
127 | |||
128 | if (index >= listBox1.Items.Count) |
||
129 | { |
||
130 | --index; |
||
131 | } |
||
132 | |||
133 | listBox1.SelectedIndex = index; |
||
4 | office | 134 | } |
135 | |||
136 | private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) |
||
137 | { |
||
48 | office | 138 | |
28 | office | 139 | var listBox = (ListBox)sender; |
48 | office | 140 | if (listBox.SelectedIndex == -1) |
141 | { |
||
142 | _serverBindingSource.DataSource = new |
||
143 | { Name = string.Empty, Url = string.Empty, Username = string.Empty, Password = string.Empty }; |
||
144 | return; |
||
145 | } |
||
4 | office | 146 | |
21 | office | 147 | if (listBox.SelectedItem is Server server) |
4 | office | 148 | { |
21 | office | 149 | _server = server; |
4 | office | 150 | |
21 | office | 151 | _serverBindingSource.DataSource = _server; |
4 | office | 152 | } |
153 | } |
||
154 | |||
15 | office | 155 | private void Button3_Click(object sender, EventArgs e) |
156 | { |
||
44 | office | 157 | if (listBox2.SelectedItem is Announcement announcement) _announcements.Announcement.Remove(announcement); |
15 | office | 158 | } |
159 | |||
160 | private void Button4_Click(object sender, EventArgs e) |
||
161 | { |
||
21 | office | 162 | var announcement = new Announcement(); |
44 | office | 163 | if (int.TryParse(appIdTextBox.Text, out var appId)) announcement.AppId = appId; |
15 | office | 164 | |
21 | office | 165 | _announcements.Announcement.Add(announcement); |
25 | office | 166 | |
43 | office | 167 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
168 | |||
25 | office | 169 | listBox2.SelectedItem = announcement; |
15 | office | 170 | } |
171 | |||
172 | private void ListBox2_SelectedIndexChanged(object sender, EventArgs e) |
||
173 | { |
||
28 | office | 174 | var listBox = (ListBox)sender; |
15 | office | 175 | |
21 | office | 176 | if (listBox.SelectedItem is Announcement announcement) |
15 | office | 177 | { |
21 | office | 178 | _announcement = announcement; |
15 | office | 179 | |
21 | office | 180 | _announcementBindingSource.DataSource = _announcement; |
15 | office | 181 | } |
182 | } |
||
183 | |||
25 | office | 184 | private void Button6_Click(object sender, EventArgs e) |
185 | { |
||
186 | Close(); |
||
187 | } |
||
188 | |||
189 | private void Button5_Click(object sender, EventArgs e) |
||
190 | { |
||
191 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
||
30 | office | 192 | |
25 | office | 193 | Close(); |
194 | } |
||
195 | |||
55 | office | 196 | #endregion |
197 | |||
198 | private void checkBox4_CheckedStateChanged(object sender, EventArgs e) |
||
30 | office | 199 | { |
55 | office | 200 | var checkBox = (CheckBox)sender; |
201 | var state = checkBox.Checked; |
||
202 | if (state) |
||
203 | { |
||
204 | ToggleTableRow(tableLayoutPanel13, 0, false); |
||
205 | |||
206 | return; |
||
207 | } |
||
208 | |||
209 | ToggleTableRow(tableLayoutPanel13, 0, true); |
||
30 | office | 210 | } |
211 | |||
55 | office | 212 | private static void ToggleTableRow(TableLayoutPanel tableLayoutPanel, int row, bool enable) |
213 | { |
||
214 | var count = tableLayoutPanel.RowCount; |
||
215 | foreach (var i in Enumerable.Range(0, count)) |
||
216 | { |
||
217 | var control = tableLayoutPanel.GetControlFromPosition(i, row); |
||
218 | control.Enabled = enable; |
||
219 | } |
||
220 | } |
||
44 | office | 221 | |
55 | office | 222 | private void SettingsForm_Load(object sender, EventArgs e) |
44 | office | 223 | { |
69 | office | 224 | Utilities.WindowState.FormTracker.Track(this); |
225 | |||
55 | office | 226 | // Databindings. |
59 | office | 227 | trackBar1.DataBindings.Add(new Binding("Value", _configurationBindingSource, |
228 | nameof(_mainForm.Configuration.RetrievePastNotificationHours), true, |
||
229 | DataSourceUpdateMode.OnPropertyChanged)); |
||
230 | |||
231 | textBox4.DataBindings.Add(new Binding("Text", _configurationBindingSource, |
||
232 | nameof(_mainForm.Configuration.RetrievePastNotificationHours), true, |
||
233 | DataSourceUpdateMode.OnPropertyChanged)); |
||
234 | |||
55 | office | 235 | numericUpDown1.DataBindings.Add(new Binding("Value", _configurationBindingSource, |
236 | nameof(_mainForm.Configuration.ToastDuration), true, |
||
237 | DataSourceUpdateMode.OnPropertyChanged)); |
||
44 | office | 238 | |
55 | office | 239 | checkBox4.DataBindings.Add( |
240 | new Binding("Checked", _configurationBindingSource, nameof(_mainForm.Configuration.InfiniteToastDuration), true, |
||
241 | DataSourceUpdateMode.OnPropertyChanged)); |
||
242 | |||
243 | checkBox1.DataBindings.Add(new Binding("Checked", _configurationBindingSource, |
||
244 | nameof(_mainForm.Configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged)); |
||
245 | |||
246 | checkBox2.DataBindings.Add(new Binding("Checked", _configurationBindingSource, |
||
247 | nameof(_mainForm.Configuration.IgnoreSelfSignedCertificates), true, |
||
248 | DataSourceUpdateMode.OnPropertyChanged)); |
||
249 | |||
250 | checkBox3.DataBindings.Add( |
||
251 | new Binding("Checked", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Enable), true, |
||
252 | DataSourceUpdateMode.OnPropertyChanged)); |
||
253 | textBox1.DataBindings.Add( |
||
254 | new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Url), true, |
||
255 | DataSourceUpdateMode.OnPropertyChanged)); |
||
256 | textBox2.DataBindings.Add( |
||
257 | new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Username), true, |
||
258 | DataSourceUpdateMode.OnPropertyChanged)); |
||
259 | textBox3.DataBindings.Add( |
||
260 | new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Password), true, |
||
261 | DataSourceUpdateMode.OnPropertyChanged)); |
||
262 | |||
263 | serverNameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Name), true, |
||
264 | DataSourceUpdateMode.OnPropertyChanged)); |
||
265 | serverUrlTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Url), true, |
||
266 | DataSourceUpdateMode.OnPropertyChanged)); |
||
267 | serverUsernameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Username), |
||
268 | true, |
||
269 | DataSourceUpdateMode.OnPropertyChanged)); |
||
270 | serverPasswordTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Password), |
||
271 | true, |
||
272 | DataSourceUpdateMode.OnPropertyChanged)); |
||
273 | |||
274 | listBox1.DataSource = _servers.Server; |
||
275 | listBox1.DisplayMember = "Name"; |
||
276 | listBox1.DataBindings.Add(new Binding("Text", _servers.Server, "Name", true, |
||
277 | DataSourceUpdateMode.OnPropertyChanged)); |
||
278 | |||
279 | appIdTextBox.DataBindings.Add(new Binding("Text", _announcementBindingSource, nameof(_announcement.AppId), |
||
280 | true, |
||
281 | DataSourceUpdateMode.OnPropertyChanged)); |
||
71 | office | 282 | numericUpDown2.DataBindings.Add(new Binding("Value", _announcementBindingSource, |
55 | office | 283 | nameof(_announcement.LingerTime), true, |
284 | DataSourceUpdateMode.OnPropertyChanged)); |
||
71 | office | 285 | checkBox5.DataBindings.Add( |
286 | new Binding("Checked", _announcementBindingSource, nameof(_announcement.Ignore), true, |
||
287 | DataSourceUpdateMode.OnPropertyChanged)); |
||
73 | office | 288 | checkBox6.DataBindings.Add( |
289 | new Binding("Checked", _announcementBindingSource, nameof(_announcement.EnableChime), true, |
||
290 | DataSourceUpdateMode.OnPropertyChanged)); |
||
55 | office | 291 | |
292 | listBox2.DataSource = _announcements.Announcement; |
||
293 | listBox2.DisplayMember = "Id"; |
||
294 | listBox2.DataBindings.Add(new Binding("Text", _announcements.Announcement, "Id", true, |
||
295 | DataSourceUpdateMode.OnPropertyChanged)); |
||
296 | |||
297 | // Miscellaneous. |
||
298 | ToggleTableRow(tableLayoutPanel13, 0, !_mainForm.Configuration.InfiniteToastDuration); |
||
44 | office | 299 | } |
59 | office | 300 | |
301 | private void trackBar1_ValueChanged(object sender, EventArgs e) |
||
302 | { |
||
303 | |||
304 | } |
||
75 | office | 305 | |
306 | private void button7_Click(object sender, EventArgs e) |
||
307 | { |
||
308 | globalChimeOpenFileDialog1.FileOk += GlobalChimeOpenFileDialog1FileOk; |
||
309 | globalChimeOpenFileDialog1.ShowDialog(); |
||
310 | } |
||
311 | |||
312 | private void GlobalChimeOpenFileDialog1FileOk(object sender, System.ComponentModel.CancelEventArgs e) |
||
313 | { |
||
314 | globalChimeOpenFileDialog1.FileOk -= GlobalChimeOpenFileDialog1FileOk; |
||
315 | |||
316 | if (string.IsNullOrEmpty(globalChimeOpenFileDialog1.FileName) || |
||
317 | !File.Exists(globalChimeOpenFileDialog1.FileName)) |
||
318 | { |
||
319 | return; |
||
320 | } |
||
321 | |||
322 | _mainForm.Configuration.Chime = File.ReadAllBytes(globalChimeOpenFileDialog1.FileName); |
||
323 | } |
||
324 | |||
325 | private void button8_Click(object sender, EventArgs e) |
||
326 | { |
||
327 | announcementsChimeOpenFileDialog1.FileOk += AnnouncementsChimeOpenFileDialog1_FileOk; |
||
328 | announcementsChimeOpenFileDialog1.ShowDialog(); |
||
329 | } |
||
330 | |||
331 | private void AnnouncementsChimeOpenFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e) |
||
332 | { |
||
333 | if (string.IsNullOrEmpty(announcementsChimeOpenFileDialog1.FileName) || |
||
334 | !File.Exists(announcementsChimeOpenFileDialog1.FileName)) |
||
335 | { |
||
336 | return; |
||
337 | } |
||
338 | |||
339 | _announcement.Chime = File.ReadAllBytes(announcementsChimeOpenFileDialog1.FileName); |
||
340 | } |
||
1 | office | 341 | } |
342 | } |