[gnome-sound-recorder/issue_17: 2/6] Add option to use filename extensions to preferences



commit 5fac811a5540981b3209e083c24ed1fa718cce32
Author: Meg Ford <megford gnome org>
Date:   Mon Feb 18 23:21:10 2019 -0600

    Add option to use filename extensions to preferences

 src/application.js |  9 ++++++++-
 src/fileUtil.js    | 38 +++++++++++++++++++++++++++++++++++++-
 src/preferences.js | 13 +++++++++++++
 src/record.js      |  6 +++---
 4 files changed, 61 insertions(+), 5 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b15f8e9..9842771 100644
--- a/src/application.js
+++ b/src/application.js
@@ -32,7 +32,6 @@ var SIGINT = 2;
 var SIGTERM = 15;
 
 var application = null;
-let settings = null;
 
 var Application = GObject.registerClass(class Application extends Gtk.Application {
     _init() {
@@ -140,6 +139,14 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
          settings.set_double("speaker-volume", level);
     }
 
+    getShowFileExtension() {
+        return settings.get_boolean("file-extension");
+    }
+
+    setShowFileExtension(show) {
+        settings.set_boolean("file-extension", show);
+    }
+
     _showAbout() {
         let aboutDialog = new Gtk.AboutDialog();
         aboutDialog.artists = [ 'Reda Lazri <the red shortcut gmail com>',
diff --git a/src/fileUtil.js b/src/fileUtil.js
index c21f1e0..a70e335 100644
--- a/src/fileUtil.js
+++ b/src/fileUtil.js
@@ -1,4 +1,4 @@
-/* exported OffsetController DisplayTime */
+/* exported OffsetController DisplayTime BuildFileName */
 /*
  * Copyright 2013 Meg Ford
  * This library is free software; you can redistribute it and/or
@@ -27,6 +27,7 @@ const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
 const Signals = imports.signals;
 
+const Application = imports.application;
 const Listview = imports.listview;
 const MainWindow = imports.mainWindow;
 const Record = imports.record;
@@ -108,3 +109,38 @@ var DisplayTime = class DisplayTime {
         return text;
     }
 }
+
+var BuildFileName = class BuildFileName {
+    _getShowFileExtension() {
+        return Application.application.getShowFileExtension();
+    }
+
+    buildInitialFilename() {
+        var showFileExtension = this._getShowFileExtension();
+        var fileExtensionName = MainWindow.audioProfile.fileExtensionReturner();
+        var dir = Gio.Application.get_default().saveDir;
+        this.dateTime = GLib.DateTime.new_now_local();
+        var clipNumber = Listview.trackNumber + 1;
+        if(showFileExtension){
+            /* Translators: ""Clip %d"" is the default name assigned to a file created
+                by the application (for example, "Clip 1"). */
+            var clipName = _("Clip %d%s").format(clipNumber.toString(), fileExtensionName);
+        } else {
+            /* Translators: ""Clip %d"" is the default name assigned to a file created
+                by the application (for example, "Clip 1"). */
+            var clipName = _("Clip %d").format(clipNumber.toString());
+        }
+        this.clip = dir.get_child_for_display_name(clipName);
+        var file = this.clip.get_path();
+        return file;
+    }
+
+    getTitle() {
+        return this.clip;
+    }
+
+    getOrigin() {
+        return this.dateTime;
+    }
+}
+
diff --git a/src/preferences.js b/src/preferences.js
index 7209f19..d6d80ca 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -25,6 +25,7 @@ const Gtk = imports.gi.Gtk;
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
 
+const Application = imports.application;
 const MainWindow = imports.mainWindow;
 const Main = imports.main;
 
@@ -103,6 +104,18 @@ var Preferences = class Preferences {
         });
         grid.attach(recordVolume, 2, 3, 2, 1);
 
+        let fileExtensionLabel = new Gtk.Label({ label: _("Include file extension"),
+                                            halign: Gtk.Align.END });
+        fileExtensionLabel.get_style_context().add_class('dim-label');
+        grid.attach(fileExtensionLabel, 0, 4, 2, 1);
+
+        let fileExtensionButton = new Gtk.CheckButton();
+        grid.attach(fileExtensionButton, 2, 4, 2, 1);
+        fileExtensionButton.set_active(Application.application.getShowFileExtension());
+        fileExtensionButton.connect("toggled", () => {
+            Application.application.setShowFileExtension(fileExtensionButton.get_active());
+        });
+
         this.widget.show_all();
     }
 
diff --git a/src/record.js b/src/record.js
index 00405c5..6b1bc73 100644
--- a/src/record.js
+++ b/src/record.js
@@ -32,6 +32,7 @@ const Signals = imports.signals;
 
 const Application = imports.application;
 const AudioProfile = imports.audioProfile;
+const fileUtil = imports.fileUtil;
 const MainWindow = imports.mainWindow;
 const Listview = imports.listview;
 
@@ -58,9 +59,8 @@ let errorDialogState;
 var Record = class Record {
     _recordPipeline() {
         errorDialogState = ErrState.OFF;
-        this.baseTime = 0;
-        this._view = MainWindow.view;
-        this._buildFileName = new BuildFileName();
+        this._baseTime = 0;
+        this._buildFileName = new fileUtil.BuildFileName();
         this.initialFileName = this._buildFileName.buildInitialFilename();
         let localDateTime = this._buildFileName.getOrigin();
         this.gstreamerDateTime = Gst.DateTime.new_from_g_date_time(localDateTime);


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