HamBook – Blame information for rev 32

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using Configuration;
10 office 2 using NAudio.CoreAudioApi;
3 using NAudio.Wave;
1 office 4 using System;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.Data;
10 office 8 using System.Diagnostics;
1 office 9 using System.Drawing;
12 office 10 using System.IO;
1 office 11 using System.IO.Ports;
12 using System.Linq;
12 office 13 using System.Reflection;
1 office 14 using System.Text;
15 using System.Threading;
16 using System.Threading.Tasks;
17 using System.Windows.Forms;
18  
19 namespace HamBook
20 {
21 public partial class SettingsForm : Form
22 {
23 public bool SaveOnClose { get; private set; }
24  
25 private Configuration.Configuration _configuration;
26  
27 public SettingsForm()
28 {
29 InitializeComponent();
30 }
31 public SettingsForm(Configuration.Configuration configuration, CancellationToken cancellationToken) : this()
32 {
33 _configuration = configuration;
34 }
35  
36 private void SettingsForm_Load(object sender, EventArgs e)
37 {
38 var ports = SerialPort.GetPortNames();
39  
40 if (ports != null && ports.Length != 0)
41 {
42 foreach (var port in ports)
43 {
44 comboBox1.Items.Add(port);
45 }
46  
47 comboBox1.Text = ports[0];
48 }
49  
50 // Create data bindings.
8 office 51 checkBox1.DataBindings.Add(nameof(checkBox1.Checked), _configuration, nameof(_configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
52  
5 office 53 comboBox1.DataBindings.Add(nameof(comboBox1.Text), _configuration, nameof(_configuration.Port), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
54 comboBox2.DataBindings.Add(nameof(comboBox2.Text), _configuration, nameof(_configuration.Speed), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
55 comboBox3.DataBindings.Add(nameof(comboBox3.Text), _configuration, nameof(_configuration.DataBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
56 comboBox4.DataBindings.Add(nameof(comboBox4.Text), _configuration, nameof(_configuration.Parity), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
57 comboBox5.DataBindings.Add(nameof(comboBox5.Text), _configuration, nameof(_configuration.StopBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
1 office 58  
5 office 59 comboBox7.DataBindings.Add(nameof(comboBox7.Text), _configuration, nameof(_configuration.Radio), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
7 office 60 comboBox8.DataBindings.Add(nameof(comboBox8.Text), _configuration, nameof(_configuration.Handshake), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
5 office 61  
62 var bandBindingSource = new BindingSource();
63 bandBindingSource.DataSource = _configuration.Definitions.Bands;
64 comboBox6.DataSource = bandBindingSource;
12 office 65 comboBox6.DisplayMember = "Meters";
5 office 66  
67 textBox1.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Min), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
68 textBox2.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Max), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
7 office 69  
21 office 70 numericUpDown6.DataBindings.Add(nameof(numericUpDown6.Value), _configuration.SerialPortTimeout, nameof(_configuration.SerialPortTimeout.Read), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
71 numericUpDown7.DataBindings.Add(nameof(numericUpDown7.Value), _configuration.SerialPortTimeout, nameof(_configuration.SerialPortTimeout.Write), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
10 office 72  
73 comboBox9.DataBindings.Add(nameof(comboBox9.Text), _configuration.Audio, nameof(_configuration.Audio.InputDeviceFriendlyName), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
74 comboBox10.DataBindings.Add(nameof(comboBox10.Text), _configuration.Audio, nameof(_configuration.Audio.OutputDeviceFriendlyName), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
75  
76 foreach (var deviceNumber in Enumerable.Range(0, WaveIn.DeviceCount))
77 {
78 var capabilities = WaveIn.GetCapabilities(deviceNumber);
79  
80 comboBox9.Items.Add(capabilities.ProductName);
81 }
82  
83 foreach (var deviceNumber in Enumerable.Range(0, WaveOut.DeviceCount))
84 {
85 var capabilities = WaveOut.GetCapabilities(deviceNumber);
86 comboBox10.Items.Add(capabilities.ProductName);
87 }
12 office 88  
89 foreach(var notificationState in _configuration.Notifications.State)
90 {
13 office 91 switch(notificationState.Type)
92 {
93 case NotificationType.None:
94 continue;
95 }
96  
12 office 97 var index = dataGridView1.Rows.Add();
98  
13 office 99 var nameTextBox = (DataGridViewTextBoxCell)dataGridView1.Rows[index].Cells["DescriptionColumn"];
100 nameTextBox.Value = Utilities.Miscellaneous.GetDescriptionFromEnumValue(notificationState.Type);
12 office 101  
102 var enableCheckBox = (DataGridViewCheckBoxCell)dataGridView1.Rows[index].Cells["EnableColumn"];
103 enableCheckBox.Value= notificationState.Enabled;
104  
105 var lingerTextBox = (DataGridViewTextBoxCell)dataGridView1.Rows[index].Cells["LingerColumn"];
106 lingerTextBox.Value = notificationState.LingerTime;
107 }
14 office 108  
109 numericUpDown1.DataBindings.Add(nameof(numericUpDown1.Value), _configuration.Visualisations.Spectrogram, nameof(_configuration.Visualisations.Spectrogram.SampleRate), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
110 numericUpDown2.DataBindings.Add(nameof(numericUpDown2.Value), _configuration.Visualisations.Spectrogram, nameof(_configuration.Visualisations.Spectrogram.FFTSamples), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
111 numericUpDown3.DataBindings.Add(nameof(numericUpDown3.Value), _configuration.Visualisations.Spectrogram, nameof(_configuration.Visualisations.Spectrogram.AudioBufferTimespan), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
112 numericUpDown4.DataBindings.Add(nameof(numericUpDown4.Value), _configuration.Visualisations.Spectrogram, nameof(_configuration.Visualisations.Spectrogram.SpectrumIntensity), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
21 office 113  
114 numericUpDown5.DataBindings.Add(nameof(numericUpDown5.Value), _configuration.Navigation, nameof(_configuration.Navigation.FrequencyStep), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
32 office 115  
116 checkBox2.DataBindings.Add(nameof(checkBox2.Checked), _configuration.Navigation, nameof(_configuration.Navigation.MouseScrollSound), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
1 office 117 }
118  
119 private void button1_Click(object sender, EventArgs e)
120 {
121 SaveOnClose = true;
122 Close();
123 }
124  
125 private void button2_Click(object sender, EventArgs e)
126 {
127 SaveOnClose = false;
128 Close();
129 }
5 office 130  
131 private void textBox1_TextChanged(object sender, EventArgs e)
132 {
133 var textBox = (TextBox)sender;
134 if(string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency))
135 {
136 return;
137 }
138  
139 var band = (Band)comboBox6.SelectedValue;
140 band.Min = frequency;
141 }
142  
143 private void textBox2_TextChanged(object sender, EventArgs e)
144 {
145 var textBox = (TextBox)sender;
146 if (string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency))
147 {
148 return;
149 }
150  
151 var band = (Band)comboBox6.SelectedValue;
152 band.Max = frequency;
153 }
12 office 154  
155 private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
156 {
157 var dataGridView = (DataGridView)sender;
158  
159 if (dataGridView.CurrentCell is DataGridViewCheckBoxCell)
160 {
161 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
162 }
163 }
164  
165 private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
166 {
167 var dataGridView = (DataGridView)sender;
168  
169 dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
170 }
171  
172 private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
173 {
174 var dataGridView = (DataGridView)sender;
175  
176 if (dataGridView.CurrentCell is DataGridViewCheckBoxCell)
177 {
178 if (dataGridView.CurrentCell.IsInEditMode)
179 {
180 if (dataGridView.IsCurrentCellDirty)
181 {
182 dataGridView.EndEdit();
183 }
184 }
185 }
186 }
187  
188 private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
189 {
190 var dataGridView = (DataGridView)sender;
191  
192 if (e.RowIndex == -1 || e.ColumnIndex == -1)
193 {
194 return;
195 }
196  
197 switch (dataGridView.Columns[e.ColumnIndex].Name)
198 {
199 case "EnableColumn":
200 ProcessEnable(dataGridView.Rows[e.RowIndex]);
201 break;
202 }
203 }
204  
205 private void DataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
206 {
207 var dataGridView = (DataGridView)sender;
208  
209 if (e.RowIndex == -1 || e.ColumnIndex == -1 ||
210 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
211 {
212 return;
213 }
214  
215 dataGridView.EndEdit();
216 }
217  
218 private void DataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
219 {
220 var dataGridView = (DataGridView)sender;
221  
222 if (e.RowIndex == -1 || e.ColumnIndex == -1 ||
223 !(dataGridView.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
224 {
225 return;
226 }
227  
228 dataGridView.EndEdit();
229 }
230  
231 private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
232 {
233 // Do not allow errors.
234 }
235  
15 office 236 private void ProcessEnable(DataGridViewRow dataGridViewRow)
237 {
238 var enableCheckBoxCell =
239 (DataGridViewCheckBoxCell)dataGridViewRow.Cells["EnableColumn"];
240  
241 foreach (var notificationState in _configuration.Notifications.State)
242 {
243 switch (notificationState.Type)
244 {
245 case NotificationType.SignalScanDetect:
246 notificationState.Enabled = (bool)enableCheckBoxCell.Value;
247 break;
248 }
249 }
250 }
251  
1 office 252 }
253 }