[moserial] move profile access methods into the Profile class, not the MoUtils class
- From: Michael J. Chudobiak <mjc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [moserial] move profile access methods into the Profile class, not the MoUtils class
- Date: Fri, 22 Jan 2021 13:44:01 +0000 (UTC)
commit f088b9302e2e5a3bfea665aa16dd39acbd27d671
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Fri Jan 22 08:43:35 2021 -0500
move profile access methods into the Profile class, not the MoUtils class
src/DefaultPaths.vala | 2 +-
src/MainWindow.vala | 14 +++++++-------
src/MoUtils.vala | 33 ---------------------------------
src/Preferences.vala | 24 ++++++++++++------------
src/Profile.vala | 34 ++++++++++++++++++++++++++++++++++
src/Settings.vala | 16 ++++++++--------
6 files changed, 62 insertions(+), 61 deletions(-)
---
diff --git a/src/DefaultPaths.vala b/src/DefaultPaths.vala
index f746682..4fb3ce6 100644
--- a/src/DefaultPaths.vala
+++ b/src/DefaultPaths.vala
@@ -57,7 +57,7 @@ public class DefaultPaths : GLib.Object
public static string ? getPath (Profile profile, string group, string key)
{
string ? path = null;
- path = MoUtils.getKeyString (profile, group, key);
+ path = profile.getString (group, key);
if ((path==null) || !MoUtils.fileExists (path))
return null;
return path;
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index b3e77f3..bc1cf69 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -128,9 +128,9 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
profile = new Profile ();
profile.load (null, gtkWindow);
currentSettings = Settings.loadFromProfile (profile);
- int width = MoUtils.getKeyInteger(profile, "window", "width", -1);
- int height = MoUtils.getKeyInteger(profile, "window", "height", -1);;
- int panedPosition = MoUtils.getKeyInteger(profile, "window", "paned_pos", -1);
+ int width = profile.getInteger("window", "width", -1);
+ int height = profile.getInteger("window", "height", -1);;
+ int panedPosition = profile.getInteger("window", "paned_pos", -1);
if ((width > 0) && (height > 0))
{
gtkWindow.resize (width, height);
@@ -241,12 +241,12 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
// setup incoming notebook
incoming_notebook = (Notebook) builder.get_object ("incoming_notebook");
- incoming_notebook.set_current_page (MoUtils.getKeyInteger(profile, "main_ui_controls",
"incoming_tab", 0));
+ incoming_notebook.set_current_page (profile.getInteger("main_ui_controls", "incoming_tab", 0));
incoming_notebook.switch_page.connect (onIncomingNotebookSwitchPage);
// setup outgoing notebook
outgoing_notebook = (Notebook) builder.get_object ("outgoing_notebook");
- outgoing_notebook.set_current_page (MoUtils.getKeyInteger(profile, "main_ui_controls",
"outgoing_tab", 0));
+ outgoing_notebook.set_current_page (profile.getInteger("main_ui_controls", "outgoing_tab", 0));
outgoing_notebook.switch_page.connect (onOutgoingNotebookSwitchPage);
// setup textBuffers;
@@ -290,7 +290,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
inputModeCombo = (ComboBox) builder.get_object ("input_mode");
MoUtils.populateComboBox (inputModeCombo, inputModeStrings);
- if (MoUtils.getKeyBoolean(profile, "main_ui_controls", "input_mode_hex", false))
+ if (profile.getBoolean("main_ui_controls", "input_mode_hex", false))
{
inputModeCombo.set_active (inputModeValues.HEX);
} else
@@ -301,7 +301,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
lineEndModeCombo = (ComboBox) builder.get_object ("termination_mode");
MoUtils.populateComboBox (lineEndModeCombo, SerialConnection.LineEndStrings);
- lineEndModeCombo.set_active (MoUtils.getKeyInteger(profile, "main_ui_controls", "input_line_end",
0));
+ lineEndModeCombo.set_active (profile.getInteger("main_ui_controls", "input_line_end", 0));
lineEndModeCombo.changed.connect (lineEndChanged);
// setup recent chooser
diff --git a/src/MoUtils.vala b/src/MoUtils.vala
index b08bdaa..c8245bd 100644
--- a/src/MoUtils.vala
+++ b/src/MoUtils.vala
@@ -57,39 +57,6 @@ public class MoUtils : GLib.Object
return parent.get_parse_name ();
}
- public static string ? getKeyString (Profile profile, string group, string key)
- {
- string ? result = null;
- try {
- result = profile.keyFile.get_string (group, key);
- } catch (GLib.KeyFileError e) {
- stdout.printf ("%s\n", e.message);
- }
- return result;
- }
-
- public static int getKeyInteger (Profile profile, string group, string key, int default_val)
- {
- int result = default_val;
- try {
- result = profile.keyFile.get_integer (group, key);
- } catch (GLib.KeyFileError e) {
- stdout.printf ("%s\n", e.message);
- }
- return result;
- }
-
- public static bool getKeyBoolean (Profile profile, string group, string key, bool default_val)
- {
- bool result = default_val;
- try {
- result = profile.keyFile.get_boolean (group, key);
- } catch (GLib.KeyFileError e) {
- stdout.printf ("%s\n", e.message);
- }
- return result;
- }
-
public static string ? getLastMessage (string ? messages)
{
string ? message = null;
diff --git a/src/Preferences.vala b/src/Preferences.vala
index fc0173b..e974c88 100644
--- a/src/Preferences.vala
+++ b/src/Preferences.vala
@@ -154,18 +154,18 @@ public class Preferences : GLib.Object
string recordAutoExtension;
string recordAutoFolder;
- useSystemMonospaceFont = MoUtils.getKeyBoolean (profile, "preferences", "use_system_monospace_font",
Preferences.DEFAULT_USE_SYSTEM_MONOSPACE_FONT);
- font = MoUtils.getKeyString (profile, "preferences", "font");
- fontColor = MoUtils.getKeyString (profile, "preferences", "font_color");
- backgroundColor = MoUtils.getKeyString (profile, "preferences", "background_color");
- highlightColor = MoUtils.getKeyString (profile, "preferences", "highlight_color");
- recordLaunch = MoUtils.getKeyBoolean (profile, "preferences", "record_launch", true);
- enableTimeout = MoUtils.getKeyBoolean (profile, "preferences", "enable_timeout", false);
- timeout = MoUtils.getKeyInteger (profile, "preferences", "timeout", 30);
- recordAutoName = MoUtils.getKeyBoolean(profile, "preferences", "record_auto_name", false);
- recordAutoDirection = MoUtils.getKeyInteger(profile, "preferences", "record_auto_direction", 0);
- recordAutoExtension = MoUtils.getKeyString(profile, "preferences", "record_auto_extension");
- recordAutoFolder = MoUtils.getKeyString(profile, "preferences", "record_auto_folder");
+ useSystemMonospaceFont = profile.getBoolean ("preferences", "use_system_monospace_font",
Preferences.DEFAULT_USE_SYSTEM_MONOSPACE_FONT);
+ font = profile.getString ("preferences", "font");
+ fontColor = profile.getString ("preferences", "font_color");
+ backgroundColor = profile.getString ("preferences", "background_color");
+ highlightColor = profile.getString ("preferences", "highlight_color");
+ recordLaunch = profile.getBoolean ("preferences", "record_launch", true);
+ enableTimeout = profile.getBoolean ("preferences", "enable_timeout", false);
+ timeout = profile.getInteger ("preferences", "timeout", 30);
+ recordAutoName = profile.getBoolean("preferences", "record_auto_name", false);
+ recordAutoDirection = profile.getInteger("preferences", "record_auto_direction", 0);
+ recordAutoExtension = profile.getString("preferences", "record_auto_extension");
+ recordAutoFolder = profile.getString("preferences", "record_auto_folder");
return new Preferences (useSystemMonospaceFont, font, fontColor,
backgroundColor, highlightColor, recordLaunch,
enableTimeout, timeout, recordAutoName,
diff --git a/src/Profile.vala b/src/Profile.vala
index ff16ea5..59be5e3 100644
--- a/src/Profile.vala
+++ b/src/Profile.vala
@@ -27,6 +27,40 @@ public class Profile : GLib.Object
construct {
keyFile = new KeyFile ();
}
+
+ public string ? getString (string group, string key)
+ {
+ string ? result = null;
+ try {
+ result = keyFile.get_string (group, key);
+ } catch (GLib.KeyFileError e) {
+ stdout.printf ("%s\n", e.message);
+ }
+ return result;
+ }
+
+ public int getInteger (string group, string key, int default_val)
+ {
+ int result = default_val;
+ try {
+ result = keyFile.get_integer (group, key);
+ } catch (GLib.KeyFileError e) {
+ stdout.printf ("%s\n", e.message);
+ }
+ return result;
+ }
+
+ public bool getBoolean (string group, string key, bool default_val)
+ {
+ bool result = default_val;
+ try {
+ result = keyFile.get_boolean (group, key);
+ } catch (GLib.KeyFileError e) {
+ stdout.printf ("%s\n", e.message);
+ }
+ return result;
+ }
+
public void saveWindowSize (int w, int h)
{
if (w > 0)
diff --git a/src/Settings.vala b/src/Settings.vala
index 84794fc..10e5275 100644
--- a/src/Settings.vala
+++ b/src/Settings.vala
@@ -147,14 +147,14 @@ public class Settings : GLib.Object
AccessMode accessMode;
bool localEcho;
- device = MoUtils.getKeyString (profile, "port_settings", "device");
- baudRate = MoUtils.getKeyInteger (profile, "port_settings", "baud_rate", Settings.DEFAULT_BAUDRATE);
- dataBits = MoUtils.getKeyInteger (profile, "port_settings", "data_bits", Settings.DEFAULT_DATABITS);
- stopBits = MoUtils.getKeyInteger (profile, "port_settings", "stop_bits", Settings.DEFAULT_STOPBITS);
- parity = (Settings.Parity)MoUtils.getKeyInteger (profile, "port_settings", "parity",
Settings.DEFAULT_PARITY);
- handshake = (Settings.Handshake)MoUtils.getKeyInteger (profile, "port_settings", "handshake",
Settings.DEFAULT_HANDSHAKE);
- accessMode = (Settings.AccessMode)MoUtils.getKeyInteger (profile, "port_settings", "access_mode",
Settings.DEFAULT_ACCESSMODE);
- localEcho = MoUtils.getKeyBoolean (profile, "port_settings", "local_echo",
Settings.DEFAULT_LOCAL_ECHO);
+ device = profile.getString ("port_settings", "device");
+ baudRate = profile.getInteger ("port_settings", "baud_rate", Settings.DEFAULT_BAUDRATE);
+ dataBits = profile.getInteger ("port_settings", "data_bits", Settings.DEFAULT_DATABITS);
+ stopBits = profile.getInteger ("port_settings", "stop_bits", Settings.DEFAULT_STOPBITS);
+ parity = (Settings.Parity)profile.getInteger ("port_settings", "parity", Settings.DEFAULT_PARITY);
+ handshake = (Settings.Handshake)profile.getInteger ("port_settings", "handshake",
Settings.DEFAULT_HANDSHAKE);
+ accessMode = (Settings.AccessMode)profile.getInteger ("port_settings", "access_mode",
Settings.DEFAULT_ACCESSMODE);
+ localEcho = profile.getBoolean ("port_settings", "local_echo", Settings.DEFAULT_LOCAL_ECHO);
return new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, localEcho);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]