[moserial] read profile data via MoUtils routines for consistency and less duplication of code
- From: Michael J. Chudobiak <mjc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [moserial] read profile data via MoUtils routines for consistency and less duplication of code
- Date: Fri, 22 Jan 2021 13:21:07 +0000 (UTC)
commit 70524034e91866b6475a612cc0d615a41af59427
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date: Fri Jan 22 08:20:23 2021 -0500
read profile data via MoUtils routines for consistency and less duplication of code
src/DefaultPaths.vala | 10 +++------
src/MainWindow.vala | 14 ++++++------
src/Profile.vala | 62 ---------------------------------------------------
3 files changed, 10 insertions(+), 76 deletions(-)
---
diff --git a/src/DefaultPaths.vala b/src/DefaultPaths.vala
index d3800c5..f746682 100644
--- a/src/DefaultPaths.vala
+++ b/src/DefaultPaths.vala
@@ -57,13 +57,9 @@ public class DefaultPaths : GLib.Object
public static string ? getPath (Profile profile, string group, string key)
{
string ? path = null;
- try {
- path = profile.keyFile.get_string (group, key);
- if (!MoUtils.fileExists (path))
- return null;
- } catch (GLib.KeyFileError e) {
- // stdout.printf("%s\n", e.message);
- }
+ path = MoUtils.getKeyString (profile, group, key);
+ if ((path==null) || !MoUtils.fileExists (path))
+ return null;
return path;
}
}
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 7a223f5..b3e77f3 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 = profile.getWindowWidth ();
- int height = profile.getWindowHeight ();
- int panedPosition = profile.getWindowPanedPosition ();
+ 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);
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 (profile.getNotebookTab (false));
+ incoming_notebook.set_current_page (MoUtils.getKeyInteger(profile, "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 (profile.getNotebookTab (true));
+ outgoing_notebook.set_current_page (MoUtils.getKeyInteger(profile, "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 (profile.getInputModeHex ())
+ if (MoUtils.getKeyBoolean(profile, "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 (profile.getInputLineEnd ());
+ lineEndModeCombo.set_active (MoUtils.getKeyInteger(profile, "main_ui_controls", "input_line_end",
0));
lineEndModeCombo.changed.connect (lineEndChanged);
// setup recent chooser
diff --git a/src/Profile.vala b/src/Profile.vala
index d2b7f1a..ff16ea5 100644
--- a/src/Profile.vala
+++ b/src/Profile.vala
@@ -40,33 +40,6 @@ public class Profile : GLib.Object
keyFile.set_integer ("window", "paned_pos", pos);
}
- public int getWindowPanedPosition ()
- {
- try {
- return keyFile.get_integer ("window", "paned_pos");
- } catch (GLib.KeyFileError e) {
- return -1;
- }
- }
-
- public int getWindowWidth ()
- {
- try {
- return keyFile.get_integer ("window", "width");
- } catch (GLib.KeyFileError e) {
- return -1;
- }
- }
-
- public int getWindowHeight ()
- {
- try {
- return keyFile.get_integer ("window", "height");
- } catch (GLib.KeyFileError e) {
- return -1;
- }
- }
-
public void setNotebookTab (bool outgoing, uint tab)
{
string n = "incoming_tab";
@@ -83,53 +56,18 @@ public class Profile : GLib.Object
profileChanged = true;
}
- public int getNotebookTab (bool outgoing)
- {
- string n = "incoming_tab";
- if (outgoing) {
- n = "outgoing_tab";
- }
-
- try {
- if (keyFile.get_integer ("main_ui_controls", n) != 0) {
- return 1;
- }
- return 0;
- } catch (GLib.KeyFileError e) {
- return 0;
- }
- }
-
public void setInputModeHex (bool hex)
{
keyFile.set_boolean ("main_ui_controls", "input_mode_hex", hex);
profileChanged = true;
}
- public bool getInputModeHex ()
- {
- try {
- return keyFile.get_boolean ("main_ui_controls", "input_mode_hex");
- } catch (GLib.KeyFileError e) {
- return false;
- }
- }
-
public void setInputLineEnd (int end)
{
keyFile.set_integer ("main_ui_controls", "input_line_end", end);
profileChanged = true;
}
- public int getInputLineEnd ()
- {
- try {
- return keyFile.get_integer ("main_ui_controls", "input_line_end");
- } catch (GLib.KeyFileError e) {
- return 0;
- }
- }
-
public bool load (string ? filename, Gtk.Window window)
{
string f;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]