[moserial] add option to connect automatically on startup or profile load



commit 87b68b1370ac3a9b6c55311aa870e0ea6a92ece1
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Tue Jan 26 09:30:57 2021 -0500

    add option to connect automatically on startup or profile load

 data/ui/settings_dialog.ui | 57 +++++++++++++++++++++++++++++-----------------
 src/MainWindow.vala        |  5 ++++
 src/Settings.vala          | 12 +++++++---
 src/SettingsDialog.vala    | 14 +++++++++++-
 4 files changed, 63 insertions(+), 25 deletions(-)
---
diff --git a/data/ui/settings_dialog.ui b/data/ui/settings_dialog.ui
index 50f1a66..809b1e8 100644
--- a/data/ui/settings_dialog.ui
+++ b/data/ui/settings_dialog.ui
@@ -77,7 +77,7 @@
               </packing>
             </child>
             <child>
-              <!-- n-columns=3 n-rows=8 -->
+              <!-- n-columns=2 n-rows=9 -->
               <object class="GtkGrid" id="table1">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
@@ -104,6 +104,7 @@
                         <property name="visible">True</property>
                         <property name="can-focus">True</property>
                         <property name="receives-default">False</property>
+                        <property name="halign">start</property>
                         <property name="use-underline">True</property>
                         <property name="draw-indicator">True</property>
                       </object>
@@ -120,6 +121,7 @@
                         <property name="visible">True</property>
                         <property name="can-focus">True</property>
                         <property name="receives-default">False</property>
+                        <property name="halign">start</property>
                         <property name="use-underline">True</property>
                         <property name="draw-indicator">True</property>
                       </object>
@@ -172,6 +174,7 @@
                     <property name="visible">True</property>
                     <property name="can-focus">True</property>
                     <property name="receives-default">False</property>
+                    <property name="halign">start</property>
                     <property name="use-underline">True</property>
                     <property name="draw-indicator">True</property>
                   </object>
@@ -184,6 +187,7 @@
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Device</property>
                     <property name="xalign">1</property>
                   </object>
@@ -196,6 +200,7 @@
                   <object class="GtkLabel" id="label2">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Baud Rate</property>
                     <property name="xalign">1</property>
                   </object>
@@ -208,6 +213,7 @@
                   <object class="GtkLabel" id="label3">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Data Bits</property>
                     <property name="xalign">1</property>
                   </object>
@@ -220,6 +226,7 @@
                   <object class="GtkLabel" id="label4">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Stop Bits</property>
                     <property name="xalign">1</property>
                   </object>
@@ -232,6 +239,7 @@
                   <object class="GtkLabel" id="label5">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Parity</property>
                     <property name="xalign">1</property>
                   </object>
@@ -244,6 +252,7 @@
                   <object class="GtkLabel" id="label7">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Handshake</property>
                     <property name="xalign">1</property>
                   </object>
@@ -256,6 +265,7 @@
                   <object class="GtkLabel" id="label8">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Access Mode</property>
                     <property name="xalign">1</property>
                   </object>
@@ -268,6 +278,7 @@
                   <object class="GtkLabel" id="label26">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
+                    <property name="halign">end</property>
                     <property name="label" translatable="yes">Local Echo</property>
                     <property name="xalign">1</property>
                   </object>
@@ -320,28 +331,32 @@
                   </packing>
                 </child>
                 <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="halign">end</property>
+                    <property name="label" translatable="yes">On Startup</property>
+                    <property name="xalign">1</property>
+                  </object>
+                  <packing>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">8</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <object class="GtkCheckButton" id="settings_auto_connect">
+                    <property name="label" translatable="yes">Connect immediately</property>
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="receives-default">False</property>
+                    <property name="halign">start</property>
+                    <property name="use-underline">True</property>
+                    <property name="draw-indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="left-attach">1</property>
+                    <property name="top-attach">8</property>
+                  </packing>
                 </child>
               </object>
               <packing>
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 4980dda..ba14613 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -466,6 +466,11 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
                 stdout.printf ("%s\n", e.message);
             }
         }
+
+        // auto-connect
+        if (currentSettings.autoConnect) {
+            ensureConnected ();
+        }
     }
 
     private void setWindowTitle (string ? recordingFilename)
diff --git a/src/Settings.vala b/src/Settings.vala
index 2ff76cc..eb6853c 100644
--- a/src/Settings.vala
+++ b/src/Settings.vala
@@ -55,6 +55,7 @@ public class Settings : GLib.Object
     public static Handshake DEFAULT_HANDSHAKE = Handshake.HARDWARE;
     public static AccessMode DEFAULT_ACCESSMODE = AccessMode.READWRITE;
     public static bool DEFAULT_LOCAL_ECHO = false;
+    public static bool DEFAULT_AUTO_CONNECT = false;
     public string ? device { get; construct; }
     public int baudRate { get; construct; }
     public int dataBits { get; construct; }
@@ -63,7 +64,8 @@ public class Settings : GLib.Object
     public Handshake handshake { get; construct; }
     public AccessMode accessMode { get; construct; }
     public bool localEcho { get; construct; }
-    public Settings (string ? device, int baudRate, int dataBits, int stopBits, Parity parity, Handshake 
handshake, AccessMode accessMode, bool localEcho)
+    public bool autoConnect {get; construct; }
+    public Settings (string ? device, int baudRate, int dataBits, int stopBits, Parity parity, Handshake 
handshake, AccessMode accessMode, bool localEcho, bool autoConnect)
     {
         GLib.Object (device: device,
                      baudRate: baudRate,
@@ -72,7 +74,8 @@ public class Settings : GLib.Object
                      parity: parity,
                      handshake: handshake,
                      accessMode: accessMode,
-                     localEcho: localEcho);
+                     localEcho: localEcho,
+                     autoConnect: autoConnect);
     }
 
     construct {
@@ -134,6 +137,7 @@ public class Settings : GLib.Object
         profile.setInteger ("port_settings", "handshake", handshake);
         profile.setInteger ("port_settings", "access_mode", accessMode);
         profile.setBoolean ("port_settings", "local_echo", localEcho);
+        profile.setBoolean ("port_settings", "auto_connect", autoConnect);
     }
 
     public static Settings loadFromProfile (Profile profile)
@@ -146,6 +150,7 @@ public class Settings : GLib.Object
         Handshake handshake;
         AccessMode accessMode;
         bool localEcho;
+        bool autoConnect;
 
         device = profile.getString ("port_settings", "device");
         baudRate = profile.getInteger ("port_settings", "baud_rate", Settings.DEFAULT_BAUDRATE);
@@ -155,7 +160,8 @@ public class Settings : GLib.Object
         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);
+        autoConnect = profile.getBoolean ("port_settings", "auto_connect", Settings.DEFAULT_AUTO_CONNECT);
 
-        return new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, localEcho);
+        return new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, localEcho, 
autoConnect);
     }
 }
diff --git a/src/SettingsDialog.vala b/src/SettingsDialog.vala
index d9c8a2b..947d66a 100644
--- a/src/SettingsDialog.vala
+++ b/src/SettingsDialog.vala
@@ -40,6 +40,7 @@ public class moserial.SettingsDialog : GLib.Object
     private CheckButton softwareHandshake;
     private ComboBox accessModeCombo;
     private CheckButton localEcho;
+    private CheckButton autoConnect;
     private Gtk.ListStore deviceModel;
     private Gtk.Entry deviceInput;
     private Gtk.Entry baudRateInput;
@@ -81,6 +82,9 @@ public class moserial.SettingsDialog : GLib.Object
         localEcho = (CheckButton) builder.get_object ("settings_local_echo");
         localEcho.set_tooltip_text (_("Normally disabled"));
 
+        autoConnect = (CheckButton) builder.get_object ("settings_auto_connect");
+        autoConnect.set_tooltip_text (_("Enable to automatically connect on startup or when a profile is 
loaded"));
+
         dialog.delete_event.connect (hide);
         cancelButton.clicked.connect (this.cancel);
         okButton.clicked.connect (this.ok);
@@ -180,6 +184,11 @@ public class moserial.SettingsDialog : GLib.Object
             localEcho.set_active (true);
         else
             localEcho.set_active (false);
+        if (currentSettings.autoConnect)
+            autoConnect.set_active (true);
+        else
+            autoConnect.set_active (false);
+
     }
 
     public bool hide ()
@@ -205,6 +214,7 @@ public class moserial.SettingsDialog : GLib.Object
         Settings.Handshake handshake;
         Settings.AccessMode accessMode;
         bool pLocalEcho;
+        bool pAutoConnect;
 
         if (deviceInput.get_text_length () == 0) {
             device = Settings.DEFAULT_DEVICEFILE;
@@ -239,7 +249,9 @@ public class moserial.SettingsDialog : GLib.Object
         else
             handshake = Settings.Handshake.NONE;
         pLocalEcho = localEcho.get_active ();
-        settings = new Settings (device, baudRate, dataBits, stopBits, parity, handshake, accessMode, 
pLocalEcho);
+        pAutoConnect = autoConnect.get_active ();
+        settings = new Settings (device, baudRate, dataBits, stopBits, parity,
+                                 handshake, accessMode, pLocalEcho, pAutoConnect);
         currentSettings = settings;
         this.updateSettings (currentSettings);
         dialog.hide ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]