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