[moserial] add automatic filename to allow immediate recording, bug 793146



commit 90108544df656847e86df78f91f81e7878c8e162
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Mon Jan 18 13:56:10 2021 -0500

    add automatic filename to allow immediate recording, bug 793146

 data/ui/preferences.ui     | 193 ++++++++++++++++++++++++++++++++++++++++++++-
 src/MainWindow.vala        |  44 +++++++++--
 src/Preferences.vala       |  48 ++++++++++-
 src/PreferencesDialog.vala |  55 ++++++++++++-
 4 files changed, 325 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 6577441..6b2b968 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -2,6 +2,38 @@
 <!-- Generated with glade 3.38.2 -->
 <interface>
   <requires lib="gtk+" version="3.20"/>
+  <object class="GtkFileChooserDialog" id="preferences_record_auto_folder_chooser">
+    <property name="can-focus">False</property>
+    <property name="type-hint">dialog</property>
+    <property name="action">select-folder</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can-focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
   <object class="GtkDialog" id="preferences_dialog">
     <property name="can-focus">False</property>
     <property name="border-width">5</property>
@@ -263,10 +295,9 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkBox" id="vbox9">
+                  <object class="GtkBox" id="launchbox">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
                       <object class="GtkCheckButton" id="preferences_record_launch">
@@ -292,7 +323,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkBox" id="hbox8">
+                  <object class="GtkBox" id="timeoutbox">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
                     <child>
@@ -306,7 +337,7 @@
                       </object>
                       <packing>
                         <property name="expand">False</property>
-                        <property name="fill">True</property>
+                        <property name="fill">False</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
@@ -343,6 +374,160 @@
                     <property name="position">2</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkBox" id="autobox">
+                    <property name="visible">True</property>
+                    <property name="can-focus">False</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkBox" id="enableautobox">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkCheckButton" id="preferences_record_auto_name">
+                            <property name="label" translatable="yes">Use automatic timestamped 
filename</property>
+                            <property name="use-action-appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can-focus">True</property>
+                            <property name="receives-default">False</property>
+                            <property name="use-underline">True</property>
+                            <property name="draw-indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="folderbox">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="can-focus">False</property>
+                            <property name="label" translatable="yes">In this folder</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkFileChooserButton" id="preferences_record_auto_folder">
+                            <property name="visible">True</property>
+                            <property name="sensitive">False</property>
+                            <property name="can-focus">False</property>
+                            <property name="action">select-folder</property>
+                            <property name="dialog">preferences_record_auto_folder_chooser</property>
+                            <property name="title" translatable="yes"/>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="extensionbox">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel" id="label1">
+                            <property name="visible">True</property>
+                            <property name="can-focus">False</property>
+                            <property name="label" translatable="yes">With this extension</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkEntry" id="preferences_record_auto_extension">
+                            <property name="visible">True</property>
+                            <property name="sensitive">False</property>
+                            <property name="can-focus">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="directionbox">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="can-focus">False</property>
+                            <property name="label" translatable="yes">Direction</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkComboBox" id="preferences_record_auto_direction">
+                            <property name="visible">True</property>
+                            <property name="sensitive">False</property>
+                            <property name="can-focus">False</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 6c82ccc..1a67d32 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -650,8 +650,40 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
                 button.set_active (false);
                 return;
             }
-            button.set_label_widget (stopRecordingLabel);
-            recordDialog.show (currentPaths.recordTo);
+            button.set_label_widget(stopRecordingLabel);
+            if (currentPreferences.recordAutoName) {
+                var now = new DateTime.now_local();
+                var year = now.get_year();
+                var month = now.get_month();
+                var day = now.get_day_of_month();
+                var hour = now.get_hour();
+                var minute = now.get_minute();
+                var second = now.get_second();
+                string folder = currentPreferences.recordAutoFolder;
+                string pExtension = currentPreferences.recordAutoExtension;
+                string extension = "";
+                if (pExtension!="") {
+                    extension = ".%s".printf(pExtension);
+                }
+                string filename = "%s/moserial_%04d-%02d-%02d_%02d-%02d-%02d%s".printf(
+                                      folder, year, month, day, hour, minute, second, extension);
+                SerialStreamRecorder.Direction direction;
+                switch(currentPreferences.recordAutoDirection) {
+                case 0:
+                default:
+                    direction=SerialStreamRecorder.Direction.INCOMING;
+                    break;
+                case 1:
+                    direction=SerialStreamRecorder.Direction.OUTGOING;
+                    break;
+                case 2:
+                    direction=SerialStreamRecorder.Direction.BOTH;
+                    break;
+                }
+                startRecording(filename, direction);
+            } else {
+                recordDialog.show(currentPaths.recordTo);
+            }
         } else {
             streamRecorder.close (currentPreferences.recordLaunch);
             button.set_label_widget (recordLabel);
@@ -663,24 +695,24 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
         }
     }
 
-    public void stopRecording (moserial.RecordDialog dialog)
+    public void stopRecording ()
     {
         recordButton.set_active (false); // this generates recordButton.clicked signal
     }
 
-    public void startRecording (moserial.RecordDialog dialog, string filename, 
moserial.SerialStreamRecorder.Direction direction)
+    public void startRecording (string filename, moserial.SerialStreamRecorder.Direction direction)
     {
         try {
             streamRecorder.open (filename, direction);
             currentPaths.recordTo = MoUtils.getParentFolder (filename);
             if (!ensureConnected ())
-                stopRecording (dialog);
+                stopRecording ();
             setWindowTitle (filename);
         } catch (GLib.Error e) {
             var errorDialog = new MessageDialog (gtkWindow, DialogFlags.DESTROY_WITH_PARENT, 
MessageType.ERROR, ButtonsType.CLOSE, "%s: %s\n%s", _("Error: Could not open file"), filename, e.message);
             errorDialog.run ();
             errorDialog.destroy ();
-            stopRecording (dialog);
+            stopRecording ();
         }
     }
 
diff --git a/src/Preferences.vala b/src/Preferences.vala
index 1f49d17..fc0173b 100644
--- a/src/Preferences.vala
+++ b/src/Preferences.vala
@@ -35,8 +35,18 @@ public class Preferences : GLib.Object
     public bool recordLaunch { get; construct; }
     public bool enableTimeout { get; construct; }
     public int timeout { get; construct; }
+    public bool recordAutoName{get; construct;}
+    public int recordAutoDirection{get; construct;}
+    public string recordAutoExtension{get; construct;}
+    public string recordAutoFolder{get; construct;}
 
-    public Preferences (bool useSystemMonospaceFont, string ? font, string ? fontColor, string ? 
backgroundColor, string ? highlightColor, bool recordLaunch, bool enableTimeout, int timeout)
+    public Preferences (bool useSystemMonospaceFont, string? font,
+                        string? fontColor,string? backgroundColor,
+                        string? highlightColor, bool recordLaunch,
+                        bool enableTimeout, int timeout,
+                        bool recordAutoName, int recordAutoDirection,
+                        string? recordAutoExtension,
+                        string? recordAutoFolder)
     {
         GLib.Object (useSystemMonospaceFont: useSystemMonospaceFont,
                      font: font,
@@ -45,7 +55,11 @@ public class Preferences : GLib.Object
                      backgroundColor: backgroundColor,
                      highlightColor: highlightColor,
                      enableTimeout: enableTimeout,
-                     timeout: timeout);
+                     timeout: timeout,
+                     recordAutoName: recordAutoName,
+                     recordAutoDirection: recordAutoDirection,
+                     recordAutoExtension: recordAutoExtension,
+                     recordAutoFolder: recordAutoFolder);
     }
 
     construct {
@@ -57,6 +71,10 @@ public class Preferences : GLib.Object
             backgroundColor = DEFAULT_BACKGROUND_COLOR;
         if (highlightColor == null)
             highlightColor = DEFAULT_HIGHLIGHT_COLOR;
+        if(recordAutoExtension==null)
+            recordAutoExtension="";
+        if(recordAutoFolder==null)
+            recordAutoFolder=Environment.get_home_dir ();
     }
     public static string getSystemDefaultMonospaceFont ()
     {
@@ -95,6 +113,14 @@ public class Preferences : GLib.Object
             stdout.printf ("true\n");
         else
             stdout.printf ("false\n");
+        stdout.printf("recordAutoName: ");
+        if(recordAutoName)
+            stdout.printf("true\n");
+        else
+            stdout.printf("false\n");
+        stdout.printf("recordAutoDirection: %d\n", recordAutoDirection);
+        stdout.printf("recordAutoExtension: %s\n", recordAutoExtension);
+        stdout.printf("recordAutoFolder: %s\n", recordAutoFolder);
     }
 
     public void saveToProfile (Profile profile)
@@ -107,6 +133,10 @@ public class Preferences : GLib.Object
         profile.keyFile.set_boolean ("preferences", "record_launch", recordLaunch);
         profile.keyFile.set_boolean ("preferences", "enable_timeout", enableTimeout);
         profile.keyFile.set_integer ("preferences", "timeout", timeout);
+        profile.keyFile.set_boolean("preferences", "record_auto_name", recordAutoName);
+        profile.keyFile.set_integer("preferences", "record_auto_direction", recordAutoDirection);
+        profile.keyFile.set_string("preferences", "record_auto_extension", recordAutoExtension);
+        profile.keyFile.set_string("preferences", "record_auto_folder", recordAutoFolder);
     }
 
     public static Preferences loadFromProfile (Profile profile)
@@ -119,6 +149,10 @@ public class Preferences : GLib.Object
         bool recordLaunch;
         bool enableTimeout;
         int timeout;
+        bool recordAutoName;
+        int recordAutoDirection;
+        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");
@@ -128,6 +162,14 @@ public class Preferences : GLib.Object
         recordLaunch = MoUtils.getKeyBoolean (profile, "preferences", "record_launch", true);
         enableTimeout = MoUtils.getKeyBoolean (profile, "preferences", "enable_timeout", false);
         timeout = MoUtils.getKeyInteger (profile, "preferences", "timeout", 30);
-        return new Preferences (useSystemMonospaceFont, font, fontColor, backgroundColor, highlightColor, 
recordLaunch, enableTimeout, timeout);
+        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");
+        return new Preferences (useSystemMonospaceFont, font, fontColor,
+                                backgroundColor, highlightColor, recordLaunch,
+                                enableTimeout, timeout, recordAutoName,
+                                recordAutoDirection, recordAutoExtension,
+                                recordAutoFolder);
     }
 }
diff --git a/src/PreferencesDialog.vala b/src/PreferencesDialog.vala
index a58c0e8..5f16f5b 100644
--- a/src/PreferencesDialog.vala
+++ b/src/PreferencesDialog.vala
@@ -31,6 +31,11 @@ public class moserial.PreferencesDialog : GLib.Object
     private CheckButton recordLaunch;
     private CheckButton enableTimeout;
     private SpinButton timeout;
+    private CheckButton recordAutoName;
+    private ComboBox recordAutoDirection;
+    private Entry recordAutoExtension;
+    private Widget recordAutoFolder;
+
     public signal void updatePreferences (Preferences preferences);
 
     public PreferencesDialog (Window parent)
@@ -59,6 +64,14 @@ public class moserial.PreferencesDialog : GLib.Object
         timeout.adjustment.step_increment = 1;
         timeout.adjustment.page_increment = 60;
 
+        recordAutoName = (CheckButton)builder.get_object("preferences_record_auto_name");
+        recordAutoName.toggled.connect(this.recordAutoToggled);
+        recordAutoDirection = (ComboBox)builder.get_object("preferences_record_auto_direction");
+        MoUtils.populateComboBox (recordAutoDirection, SerialStreamRecorder.DirectionStrings);
+        recordAutoDirection.set_active(SerialStreamRecorder.Direction.INCOMING);
+        recordAutoExtension = (Entry)builder.get_object("preferences_record_auto_extension");
+        recordAutoFolder = (Widget)builder.get_object("preferences_record_auto_folder");
+
         systemFont.toggled.connect (this.systemFontToggled);
         enableTimeout.toggled.connect (this.enableTimeoutToggled);
         okButton.clicked.connect (ok);
@@ -77,6 +90,11 @@ public class moserial.PreferencesDialog : GLib.Object
         bool pRecordLaunch;
         bool pEnableTimeout;
         int pTimeout;
+        bool pRecordAutoName;
+        int pRecordAutoDirection;
+        string pRecordAutoExtension;
+        string pRecordAutoFolder;
+
         if (systemFont.get_active ())
             pSystemFont = true;
         else
@@ -98,7 +116,21 @@ public class moserial.PreferencesDialog : GLib.Object
         else
             pEnableTimeout = false;
         pTimeout = (int) timeout.get_value ();
-        Preferences preferences = new Preferences (pSystemFont, pFont, pFontColor, pBackgroundColor, 
pHighlightColor, pRecordLaunch, pEnableTimeout, pTimeout);
+        if(recordAutoName.get_active())
+            pRecordAutoName=true;
+        else
+            pRecordAutoName=false;
+        pRecordAutoDirection = recordAutoDirection.get_active();
+        pRecordAutoExtension = recordAutoExtension.get_text();
+
+        pRecordAutoFolder = ((FileChooser)recordAutoFolder).get_filename ();
+
+        Preferences preferences=new Preferences(
+            pSystemFont, pFont, pFontColor, pBackgroundColor,
+            pHighlightColor, pRecordLaunch, pEnableTimeout,
+            pTimeout, pRecordAutoName, pRecordAutoDirection,
+            pRecordAutoExtension, pRecordAutoFolder);
+
         this.updatePreferences (preferences);
     }
 
@@ -132,10 +164,16 @@ public class moserial.PreferencesDialog : GLib.Object
         } else
             enableTimeout.set_sensitive (true);
         timeout.set_value (preferences.timeout);
+        recordAutoName.set_active(preferences.recordAutoName);
+        recordAutoDirection.set_active(preferences.recordAutoDirection);
+        recordAutoExtension.set_text(preferences.recordAutoExtension);
+
+        ((FileChooser)recordAutoFolder).set_current_folder(preferences.recordAutoFolder);
+
         dialog.show_all ();
     }
 
-    public void cancel (Widget w)
+    public void cancel (Button button)
     {
         // currentPreferences=null;
         hide ();
@@ -162,4 +200,17 @@ public class moserial.PreferencesDialog : GLib.Object
         else
             timeout.set_sensitive (false);
     }
+
+    public void recordAutoToggled(ToggleButton button)
+    {
+        if (button.get_active()) {
+            recordAutoExtension.set_sensitive(true);
+            recordAutoDirection.set_sensitive(true);
+            recordAutoFolder.set_sensitive(true);
+        } else {
+            recordAutoExtension.set_sensitive(false);
+            recordAutoDirection.set_sensitive(false);
+            recordAutoFolder.set_sensitive(false);
+        }
+    }
 }


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