HamBook – Diff between revs 53 and 54

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