Skip to content

Commit 849e1b2

Browse files
lovettchrismeee1
authored andcommitted
Create Settings class to wrap and manage application settings.
1 parent 4270928 commit 849e1b2

36 files changed

+872
-692
lines changed

Antenna/Tracker.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ public Tracker()
3838
BUT_connect.Text = "Disconnect";
3939
}
4040

41-
foreach (string value in MainV2.config.Keys)
41+
foreach (string key in Settings.Instance.Keys)
4242
{
43-
if (value.StartsWith("Tracker_"))
43+
if (key.StartsWith("Tracker_"))
4444
{
45-
var ctls = Controls.Find(value.Replace("Tracker_", ""), true);
45+
var ctls = Controls.Find(key.Replace("Tracker_", ""), true);
4646

4747
foreach (Control ctl in ctls)
4848
{
4949
if (typeof (TextBox) == ctl.GetType() ||
5050
typeof (ComboBox) == ctl.GetType())
5151
{
52-
ctl.Text = MainV2.config[value].ToString();
52+
ctl.Text = Settings.Instance[key];
5353
}
5454
else if (typeof (TrackBar) == ctl.GetType())
5555
{
56-
((TrackBar) ctl).Value = int.Parse(MainV2.config[value].ToString());
56+
((TrackBar)ctl).Value = Settings.Instance.GetInt32(key);
5757
}
5858
else if (typeof (CheckBox) == ctl.GetType())
5959
{
60-
((CheckBox) ctl).Checked = bool.Parse(MainV2.config[value].ToString());
60+
((CheckBox) ctl).Checked = Settings.Instance.GetBoolean(key);
6161
}
6262
}
6363
}
@@ -77,15 +77,15 @@ void saveconfig()
7777
if (typeof (TextBox) == ctl.GetType() ||
7878
typeof (ComboBox) == ctl.GetType())
7979
{
80-
MainV2.config["Tracker_" + ctl.Name] = ctl.Text;
80+
Settings.Instance["Tracker_" + ctl.Name] = ctl.Text;
8181
}
8282
if (typeof (TrackBar) == ctl.GetType())
8383
{
84-
MainV2.config["Tracker_" + ctl.Name] = ((TrackBar) ctl).Value;
84+
Settings.Instance["Tracker_" + ctl.Name] = ((TrackBar) ctl).Value.ToString();
8585
}
8686
if (typeof (CheckBox) == ctl.GetType())
8787
{
88-
MainV2.config["Tracker_" + ctl.Name] = ((CheckBox) ctl).Checked;
88+
Settings.Instance["Tracker_" + ctl.Name] = ((CheckBox) ctl).Checked.ToString();
8989
}
9090
}
9191
}

Common.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ public override void OnRender(Graphics g)
171171
base.OnRender(g);
172172

173173
var midw = LocalPosition.X + 10;
174-
var midh = LocalPosition.Y + 3;
175-
176-
if (txtsize.Width > 15)
174+
var midh = LocalPosition.Y + 3;
175+
176+
if (txtsize.Width > 15)
177177
midw -= 4;
178178

179179
if (IsMouseOver)
180180
{
181-
if (txtsize == SizeF.Empty)
181+
if (txtsize == SizeF.Empty)
182182
txtsize = g.MeasureString(wpno, SystemFonts.DefaultFont);
183183

184184
g.DrawString(wpno, SystemFonts.DefaultFont, Brushes.Black, new PointF(midw, midh));
@@ -785,7 +785,7 @@ public static DialogResult MessageShowAgain(string title, string promptText)
785785
chk.Checked = true;
786786
chk.Location = new Point(9, 80);
787787

788-
if (MainV2.config[(string) chk.Tag] != null && (string) MainV2.config[(string) chk.Tag] == "False")
788+
if (Settings.Instance.GetBoolean((string) chk.Tag) == false)
789789
// skip it
790790
{
791791
form.Dispose();
@@ -826,7 +826,7 @@ public static DialogResult MessageShowAgain(string title, string promptText)
826826

827827
static void chk_CheckStateChanged(object sender, EventArgs e)
828828
{
829-
MainV2.config[(string) ((CheckBox) (sender)).Tag] = ((CheckBox) (sender)).Checked.ToString();
829+
Settings.Instance[(string) ((CheckBox) (sender)).Tag] = ((CheckBox) (sender)).Checked.ToString();
830830
}
831831

832832
public static string speechConversion(string input)

Controls/ServoOptions.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Text;
88
using System.Windows.Forms;
9+
using MissionPlanner.Utilities;
910

1011
namespace MissionPlanner.Controls
1112
{
@@ -33,34 +34,34 @@ public ServoOptions()
3334

3435
void loadSettings()
3536
{
36-
string desc = MainV2.getConfig("Servo" + thisservo + "_desc");
37-
string low = MainV2.getConfig("Servo" + thisservo + "_low");
38-
string high = MainV2.getConfig("Servo" + thisservo + "_high");
37+
string desc = Settings.Instance["Servo" + thisservo + "_desc"];
38+
string low = Settings.Instance["Servo" + thisservo + "_low"];
39+
string high = Settings.Instance["Servo" + thisservo + "_high"];
3940

40-
string highdesc = MainV2.getConfig("Servo" + thisservo + "_highdesc");
41-
string lowdesc = MainV2.getConfig("Servo" + thisservo + "_lowdesc");
41+
string highdesc = Settings.Instance["Servo" + thisservo + "_highdesc"];
42+
string lowdesc = Settings.Instance["Servo" + thisservo + "_lowdesc"];
4243

43-
if (low != "")
44+
if (!string.IsNullOrEmpty(low))
4445
{
4546
TXT_pwm_low.Text = low;
4647
}
4748

48-
if (high != "")
49+
if (!string.IsNullOrEmpty(high))
4950
{
5051
TXT_pwm_high.Text = high;
5152
}
5253

53-
if (desc != "")
54+
if (!string.IsNullOrEmpty(desc))
5455
{
5556
TXT_rcchannel.Text = desc;
5657
}
5758

58-
if (highdesc != "")
59+
if (!string.IsNullOrEmpty(highdesc))
5960
{
6061
BUT_High.Text = highdesc;
6162
}
6263

63-
if (lowdesc != "")
64+
if (!string.IsNullOrEmpty(lowdesc))
6465
{
6566
BUT_Low.Text = lowdesc;
6667
}
@@ -143,12 +144,12 @@ private void BUT_Repeat_Click(object sender, EventArgs e)
143144

144145
private void TXT_pwm_low_TextChanged(object sender, EventArgs e)
145146
{
146-
MainV2.config["Servo" + thisservo + "_low"] = TXT_pwm_low.Text;
147+
Settings.Instance["Servo" + thisservo + "_low"] = TXT_pwm_low.Text;
147148
}
148149

149150
private void TXT_pwm_high_TextChanged(object sender, EventArgs e)
150151
{
151-
MainV2.config["Servo" + thisservo + "_high"] = TXT_pwm_high.Text;
152+
Settings.Instance["Servo" + thisservo + "_high"] = TXT_pwm_high.Text;
152153
}
153154

154155
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
@@ -161,15 +162,15 @@ private void renameToolStripMenuItem_Click(object sender, EventArgs e)
161162

162163
if (sourcectl == BUT_High)
163164
{
164-
MainV2.config["Servo" + thisservo + "_highdesc"] = desc;
165+
Settings.Instance["Servo" + thisservo + "_highdesc"] = desc;
165166
}
166167
else if (sourcectl == BUT_Low)
167168
{
168-
MainV2.config["Servo" + thisservo + "_lowdesc"] = desc;
169+
Settings.Instance["Servo" + thisservo + "_lowdesc"] = desc;
169170
}
170171
else if (sourcectl == TXT_rcchannel)
171172
{
172-
MainV2.config["Servo" + thisservo + "_desc"] = desc;
173+
Settings.Instance["Servo" + thisservo + "_desc"] = desc;
173174
}
174175
}
175176
}

Controls/ThemeColors.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using MissionPlanner.Utilities;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Data;
@@ -26,7 +27,7 @@ private void BUT_bg_Click(object sender, EventArgs e)
2627

2728
TXT_bg.BackColor = colorDialog1.Color;
2829

29-
MainV2.config["theme_bg"] = colorDialog1.Color.ToArgb().ToString();
30+
Settings.Instance["theme_bg"] = colorDialog1.Color.ToArgb().ToString();
3031
}
3132

3233
private void BUT_ctlbg_Click(object sender, EventArgs e)
@@ -37,7 +38,7 @@ private void BUT_ctlbg_Click(object sender, EventArgs e)
3738

3839
TXT_ctlbg.BackColor = colorDialog1.Color;
3940

40-
MainV2.config["theme_ctlbg"] = colorDialog1.Color.ToArgb().ToString();
41+
Settings.Instance["theme_ctlbg"] = colorDialog1.Color.ToArgb().ToString();
4142
}
4243

4344
private void BUT_text_Click(object sender, EventArgs e)
@@ -48,7 +49,7 @@ private void BUT_text_Click(object sender, EventArgs e)
4849

4950
TXT_text.BackColor = colorDialog1.Color;
5051

51-
MainV2.config["theme_text"] = colorDialog1.Color.ToArgb().ToString();
52+
Settings.Instance["theme_text"] = colorDialog1.Color.ToArgb().ToString();
5253
}
5354

5455
private void BUT_butbg_Click(object sender, EventArgs e)
@@ -59,7 +60,7 @@ private void BUT_butbg_Click(object sender, EventArgs e)
5960

6061
TXT_butbg.BackColor = colorDialog1.Color;
6162

62-
MainV2.config["theme_butbg"] = colorDialog1.Color.ToArgb().ToString();
63+
Settings.Instance["theme_butbg"] = colorDialog1.Color.ToArgb().ToString();
6364
}
6465

6566
private void BUT_butbord_Click(object sender, EventArgs e)
@@ -70,7 +71,7 @@ private void BUT_butbord_Click(object sender, EventArgs e)
7071

7172
TXT_butbord.BackColor = colorDialog1.Color;
7273

73-
MainV2.config["theme_butbord"] = colorDialog1.Color.ToArgb().ToString();
74+
Settings.Instance["theme_butbord"] = colorDialog1.Color.ToArgb().ToString();
7475
}
7576

7677
private void BUT_done_Click(object sender, EventArgs e)
@@ -82,11 +83,11 @@ private void ThemeColors_Load(object sender, EventArgs e)
8283
{
8384
try
8485
{
85-
TXT_bg.BackColor = Color.FromArgb(int.Parse(MainV2.config["theme_bg"].ToString()));
86-
TXT_ctlbg.BackColor = Color.FromArgb(int.Parse(MainV2.config["theme_ctlbg"].ToString()));
87-
TXT_text.BackColor = Color.FromArgb(int.Parse(MainV2.config["theme_text"].ToString()));
88-
TXT_butbg.BackColor = Color.FromArgb(int.Parse(MainV2.config["theme_butbg"].ToString()));
89-
TXT_butbord.BackColor = Color.FromArgb(int.Parse(MainV2.config["theme_butbord"].ToString()));
86+
TXT_bg.BackColor = Color.FromArgb(Settings.Instance.GetInt32("theme_bg"));
87+
TXT_ctlbg.BackColor = Color.FromArgb(Settings.Instance.GetInt32("theme_ctlbg"));
88+
TXT_text.BackColor = Color.FromArgb(Settings.Instance.GetInt32("theme_text"));
89+
TXT_butbg.BackColor = Color.FromArgb(Settings.Instance.GetInt32("theme_butbg"));
90+
TXT_butbord.BackColor = Color.FromArgb(Settings.Instance.GetInt32("theme_butbord"));
9091
}
9192
catch
9293
{

CurrentState.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,9 +1456,9 @@ public void UpdateCurrentSettings(System.Windows.Forms.BindingSource bs, bool up
14561456
}
14571457

14581458
if (oldmode != mode && MainV2.speechEnable && MainV2.comPort.MAV.cs == this &&
1459-
MainV2.getConfig("speechmodeenabled") == "True")
1459+
Settings.Instance.GetBoolean("speechmodeenabled"))
14601460
{
1461-
MainV2.speechEngine.SpeakAsync(Common.speechConversion(MainV2.getConfig("speechmode")));
1461+
MainV2.speechEngine.SpeakAsync(Common.speechConversion(""+ Settings.Instance["speechmode"]));
14621462
}
14631463
}
14641464
}
@@ -1728,9 +1728,9 @@ public void UpdateCurrentSettings(System.Windows.Forms.BindingSource bs, bool up
17281728
}
17291729

17301730
if (oldwp != wpno && MainV2.speechEnable && MainV2.comPort.MAV.cs == this &&
1731-
MainV2.getConfig("speechwaypointenabled") == "True")
1731+
Settings.Instance.GetBoolean("speechwaypointenabled"))
17321732
{
1733-
MainV2.speechEngine.SpeakAsync(Common.speechConversion(MainV2.getConfig("speechwaypoint")));
1733+
MainV2.speechEngine.SpeakAsync(Common.speechConversion(""+ Settings.Instance["speechwaypoint"]));
17341734
}
17351735

17361736
//MAVLink.packets[(byte)MAVLink.MSG_NAMES.WAYPOINT_CURRENT] = null;

GCSViews/ConfigurationView/ConfigBatteryMonitoring.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel;
33
using System.Windows.Forms;
44
using MissionPlanner.Controls;
5+
using MissionPlanner.Utilities;
56

67
namespace MissionPlanner.GCSViews.ConfigurationView
78
{
@@ -55,9 +56,7 @@ public void Activate()
5556
if (MainV2.comPort.MAV.param["AMP_PER_VOLT"] != null)
5657
TXT_ampspervolt.Text = MainV2.comPort.MAV.param["AMP_PER_VOLT"].ToString();
5758

58-
if (MainV2.config["speechbatteryenabled"] != null &&
59-
MainV2.config["speechbatteryenabled"].ToString() == "True" && MainV2.config["speechenable"] != null &&
60-
MainV2.config["speechenable"].ToString() == "True")
59+
if (Settings.Instance.GetBoolean("speechbatteryenabled") && Settings.Instance.GetBoolean("speechenable"))
6160
{
6261
CHK_speechbattery.Checked = true;
6362
}
@@ -528,35 +527,35 @@ private void CHK_speechbattery_CheckedChanged(object sender, EventArgs e)
528527
return;
529528

530529
// enable the battery event
531-
MainV2.config["speechbatteryenabled"] = ((CheckBox) sender).Checked.ToString();
530+
Settings.Instance["speechbatteryenabled"] = ((CheckBox) sender).Checked.ToString();
532531
// enable speech engine
533-
MainV2.config["speechenable"] = true.ToString();
532+
Settings.Instance["speechenable"] = true.ToString();
534533

535534
if (((CheckBox) sender).Checked)
536535
{
537536
var speechstring = "WARNING, Battery at {batv} Volt, {batp} percent";
538-
if (MainV2.config["speechbattery"] != null)
539-
speechstring = MainV2.config["speechbattery"].ToString();
537+
if (Settings.Instance["speechbattery"] != null)
538+
speechstring = Settings.Instance["speechbattery"].ToString();
540539
if (DialogResult.Cancel ==
541540
InputBox.Show("Notification", "What do you want it to say?", ref speechstring))
542541
return;
543-
MainV2.config["speechbattery"] = speechstring;
542+
Settings.Instance["speechbattery"] = speechstring;
544543

545544
speechstring = "9.6";
546-
if (MainV2.config["speechbatteryvolt"] != null)
547-
speechstring = MainV2.config["speechbatteryvolt"].ToString();
545+
if (Settings.Instance["speechbatteryvolt"] != null)
546+
speechstring = Settings.Instance["speechbatteryvolt"].ToString();
548547
if (DialogResult.Cancel ==
549548
InputBox.Show("Battery Level", "What Voltage do you want to warn at?", ref speechstring))
550549
return;
551-
MainV2.config["speechbatteryvolt"] = speechstring;
550+
Settings.Instance["speechbatteryvolt"] = speechstring;
552551

553552
speechstring = "20";
554-
if (MainV2.config["speechbatterypercent"] != null)
555-
speechstring = MainV2.config["speechbatterypercent"].ToString();
553+
if (Settings.Instance["speechbatterypercent"] != null)
554+
speechstring = Settings.Instance["speechbatterypercent"].ToString();
556555
if (DialogResult.Cancel ==
557556
InputBox.Show("Battery Level", "What percentage do you want to warn at?", ref speechstring))
558557
return;
559-
MainV2.config["speechbatterypercent"] = speechstring;
558+
Settings.Instance["speechbatterypercent"] = speechstring;
560559
}
561560
}
562561

GCSViews/ConfigurationView/ConfigBatteryMonitoring2.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public void Activate()
3737
if (MainV2.comPort.MAV.param["BATT2_AMP_PERVOL"] != null)
3838
TXT_ampspervolt.Text = MainV2.comPort.MAV.param["BATT2_AMP_PERVOL"].ToString();
3939

40-
if (MainV2.config["speechbatteryenabled"] != null &&
41-
MainV2.config["speechbatteryenabled"].ToString() == "True" && MainV2.config["speechenable"] != null &&
42-
MainV2.config["speechenable"].ToString() == "True")
40+
if (Settings.Instance.GetBoolean("speechbatteryenabled") && Settings.Instance.GetBoolean("speechenable"))
4341
{
4442
CHK_speechbattery.Checked = true;
4543
}
@@ -173,35 +171,35 @@ private void CHK_speechbattery_CheckedChanged(object sender, EventArgs e)
173171
return;
174172

175173
// enable the battery event
176-
MainV2.config["speechbatteryenabled"] = ((CheckBox) sender).Checked.ToString();
174+
Settings.Instance["speechbatteryenabled"] = ((CheckBox) sender).Checked.ToString();
177175
// enable speech engine
178-
MainV2.config["speechenable"] = true.ToString();
176+
Settings.Instance["speechenable"] = true.ToString();
179177

180178
if (((CheckBox) sender).Checked)
181179
{
182180
var speechstring = "WARNING, Battery at {batv} Volt, {batp} percent";
183-
if (MainV2.config["speechbattery"] != null)
184-
speechstring = MainV2.config["speechbattery"].ToString();
181+
if (Settings.Instance["speechbattery"] != null)
182+
speechstring = Settings.Instance["speechbattery"].ToString();
185183
if (DialogResult.Cancel ==
186184
InputBox.Show("Notification", "What do you want it to say?", ref speechstring))
187185
return;
188-
MainV2.config["speechbattery"] = speechstring;
186+
Settings.Instance["speechbattery"] = speechstring;
189187

190188
speechstring = "9.6";
191-
if (MainV2.config["speechbatteryvolt"] != null)
192-
speechstring = MainV2.config["speechbatteryvolt"].ToString();
189+
if (Settings.Instance["speechbatteryvolt"] != null)
190+
speechstring = Settings.Instance["speechbatteryvolt"].ToString();
193191
if (DialogResult.Cancel ==
194192
InputBox.Show("Battery Level", "What Voltage do you want to warn at?", ref speechstring))
195193
return;
196-
MainV2.config["speechbatteryvolt"] = speechstring;
194+
Settings.Instance["speechbatteryvolt"] = speechstring;
197195

198196
speechstring = "20";
199-
if (MainV2.config["speechbatterypercent"] != null)
200-
speechstring = MainV2.config["speechbatterypercent"].ToString();
197+
if (Settings.Instance["speechbatterypercent"] != null)
198+
speechstring = Settings.Instance["speechbatterypercent"].ToString();
201199
if (DialogResult.Cancel ==
202200
InputBox.Show("Battery Level", "What percentage do you want to warn at?", ref speechstring))
203201
return;
204-
MainV2.config["speechbatterypercent"] = speechstring;
202+
Settings.Instance["speechbatterypercent"] = speechstring;
205203
}
206204
}
207205

0 commit comments

Comments
 (0)