Winify – Blame information for rev 67

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