HamBook – Blame information for rev 10
?pathlinks?
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; |
10 | using System.IO.Ports; |
||
11 | using System.Linq; |
||
12 | using System.Text; |
||
13 | using System.Threading; |
||
14 | using System.Threading.Tasks; |
||
15 | using System.Windows.Forms; |
||
16 | |||
17 | namespace HamBook |
||
18 | { |
||
19 | public partial class SettingsForm : Form |
||
20 | { |
||
21 | public bool SaveOnClose { get; private set; } |
||
22 | |||
23 | private Configuration.Configuration _configuration; |
||
24 | |||
25 | public SettingsForm() |
||
26 | { |
||
27 | InitializeComponent(); |
||
28 | } |
||
29 | public SettingsForm(Configuration.Configuration configuration, CancellationToken cancellationToken) : this() |
||
30 | { |
||
31 | _configuration = configuration; |
||
32 | } |
||
33 | |||
34 | private void SettingsForm_Load(object sender, EventArgs e) |
||
35 | { |
||
36 | var ports = SerialPort.GetPortNames(); |
||
37 | |||
38 | if (ports != null && ports.Length != 0) |
||
39 | { |
||
40 | foreach (var port in ports) |
||
41 | { |
||
42 | comboBox1.Items.Add(port); |
||
43 | } |
||
44 | |||
45 | comboBox1.Text = ports[0]; |
||
46 | } |
||
47 | |||
48 | // Create data bindings. |
||
8 | office | 49 | checkBox1.DataBindings.Add(nameof(checkBox1.Checked), _configuration, nameof(_configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
50 | |||
5 | office | 51 | comboBox1.DataBindings.Add(nameof(comboBox1.Text), _configuration, nameof(_configuration.Port), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
52 | comboBox2.DataBindings.Add(nameof(comboBox2.Text), _configuration, nameof(_configuration.Speed), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
53 | comboBox3.DataBindings.Add(nameof(comboBox3.Text), _configuration, nameof(_configuration.DataBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
54 | comboBox4.DataBindings.Add(nameof(comboBox4.Text), _configuration, nameof(_configuration.Parity), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
55 | comboBox5.DataBindings.Add(nameof(comboBox5.Text), _configuration, nameof(_configuration.StopBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
1 | office | 56 | |
5 | office | 57 | comboBox7.DataBindings.Add(nameof(comboBox7.Text), _configuration, nameof(_configuration.Radio), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
7 | office | 58 | comboBox8.DataBindings.Add(nameof(comboBox8.Text), _configuration, nameof(_configuration.Handshake), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
5 | office | 59 | |
60 | var bandBindingSource = new BindingSource(); |
||
61 | bandBindingSource.DataSource = _configuration.Definitions.Bands; |
||
62 | comboBox6.DataSource = bandBindingSource; |
||
63 | comboBox6.DisplayMember = nameof(Band.Meters); |
||
64 | |||
65 | textBox1.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Min), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
66 | textBox2.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Max), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
7 | office | 67 | |
68 | textBox3.DataBindings.Add(nameof(textBox3.Text), _configuration.SerialPortTimeout, nameof(SerialPortTimeout.Read), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
69 | textBox4.DataBindings.Add(nameof(textBox4.Text), _configuration.SerialPortTimeout, nameof(SerialPortTimeout.Write), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
9 | office | 70 | textBox5.DataBindings.Add(nameof(textBox5.Text), _configuration, nameof(_configuration.ScanDetectPause), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
10 | office | 71 | |
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 | } |
||
1 | office | 88 | } |
89 | |||
90 | private void button1_Click(object sender, EventArgs e) |
||
91 | { |
||
92 | SaveOnClose = true; |
||
93 | Close(); |
||
94 | } |
||
95 | |||
96 | private void button2_Click(object sender, EventArgs e) |
||
97 | { |
||
98 | SaveOnClose = false; |
||
99 | Close(); |
||
100 | } |
||
5 | office | 101 | |
102 | private void textBox1_TextChanged(object sender, EventArgs e) |
||
103 | { |
||
104 | var textBox = (TextBox)sender; |
||
105 | if(string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
106 | { |
||
107 | return; |
||
108 | } |
||
109 | |||
110 | var band = (Band)comboBox6.SelectedValue; |
||
111 | band.Min = frequency; |
||
112 | } |
||
113 | |||
114 | private void textBox2_TextChanged(object sender, EventArgs e) |
||
115 | { |
||
116 | var textBox = (TextBox)sender; |
||
117 | if (string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
118 | { |
||
119 | return; |
||
120 | } |
||
121 | |||
122 | var band = (Band)comboBox6.SelectedValue; |
||
123 | band.Max = frequency; |
||
124 | } |
||
1 | office | 125 | } |
126 | } |