HamBook – Blame information for rev 53

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