Winify – Blame information for rev 59

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