[gnome-sound-recorder] multiple files: Add date recorded label and new file name according to Jakub's mockups



commit 08026416183b450baf2dc788eefbe553f6569430
Author: Meg Ford <meg387 gmail com>
Date:   Sun Mar 2 01:36:01 2014 -0600

    multiple files: Add date recorded label and new file name according to Jakub's mockups

 src/fileUtil.js   |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/listview.js   |    8 ++++++--
 src/mainWindow.js |   20 +++++++++++++++++---
 src/record.js     |   17 ++++++++++++-----
 4 files changed, 81 insertions(+), 10 deletions(-)
---
diff --git a/src/fileUtil.js b/src/fileUtil.js
index 941d77e..c09de79 100644
--- a/src/fileUtil.js
+++ b/src/fileUtil.js
@@ -19,6 +19,7 @@
  
 imports.gi.versions.Gst = '1.0';
 
+const Gettext = imports.gettext;
 const _ = imports.gettext.gettext;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
@@ -69,4 +70,49 @@ const OffsetController = new Lang.Class({
     }
 });
 
+const DisplayTime = new Lang.Class({
+    Name: 'DisplayTime',
+    
+    getDisplayTime: function(timeVal) {
+        let text = "";
+        let DAY = 86400000000;
+        let now = GLib.DateTime.new_now_local();
+        let mtime = GLib.DateTime.new_from_timeval_local(timeVal);
+        let difference = now.difference(mtime);
+        let days = Math.floor(difference / DAY);
+        let weeks = Math.floor(difference / (7 * DAY));
+        let months = Math.floor(difference / (30 * DAY));
+        let years = Math.floor(difference / (365 * DAY));
+
+        if (difference < DAY) {
+            text = mtime.format('%X');
+        } else if (difference < 2 * DAY) {
+            text = _("Yesterday");
+        } else if (difference < 7 * DAY) {
+            text = Gettext.ngettext("%d day ago",
+                                                 "%d days ago",
+                                                 days).format(days);
+        } else if (difference < 14 * DAY) {
+            text = _("Last week");
+        } else if (difference < 28 * DAY) {
+            text = Gettext.ngettext("%d week ago",
+                                                 "%d weeks ago",
+                                                 weeks).format(weeks);
+        } else if (difference < 60 * DAY) {
+            text = _("Last month");
+        } else if (difference < 360 * DAY) {
+            text = Gettext.ngettext("%d month ago",
+                                                 "%d months ago",
+                                                 months).format(months);
+        } else if (difference < 730 * DAY) {
+            text = _("Last year");
+        } else {
+            text = Gettext.ngettext("%d year ago",
+                                                 "%d years ago",
+                                                 years).format(years);
+        }
+        return text;
+    }
+});    
+
 
diff --git a/src/listview.js b/src/listview.js
index ca66da9..1dd9239 100644
--- a/src/listview.js
+++ b/src/listview.js
@@ -73,6 +73,7 @@ let fileInfo = null;
 let listType = null;
 let startRecording = false; 
 let stopVal = null;
+let trackNumber = 0;
 
 const Listview = new Lang.Class({
     Name: "Listview",
@@ -124,7 +125,7 @@ const Listview = new Lang.Class({
                                 let timeVal = file.get_modification_time();
                                 let date = GLib.DateTime.new_from_timeval_local(timeVal);
                                 let dateModifiedSortString = date.format("%Y%m%d%H%M%S");
-                                let dateModifiedDisplayString = date.format(_("%Y-%m-%d %H:%M:%S"));
+                                let dateModifiedDisplayString = 
MainWindow.displayTime.getDisplayTime(timeVal);
                                 let dateCreatedYes = file.has_attribute("time::created");
                                 if (this.dateCreatedYes) {
                                     let dateCreatedVal = file.get_attribute_uint64("time::created");
@@ -219,8 +220,11 @@ const Listview = new Lang.Class({
             allFilesInfo[this.idx].duration = durationInfo;
             
             if (title != null) {
-                this.file.title = title;
+                allFilesInfo[this.idx].title = title;
+                if (parseInt(title) > trackNumber)
+                    trackNumber = parseInt(title);
             }
+            
              
             /* this.file.dateCreated will usually be null since time::created it doesn't usually exist. 
                Therefore, we prefer to set it with tags */
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d63487b..7d2f578 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -37,6 +37,7 @@ const Waveform = imports.waveform;
 
 let activeProfile = null;
 let audioProfile = null;
+let displayTime = null;
 let grid = null;
 let groupGrid;
 let list = null;
@@ -86,6 +87,7 @@ const MainWindow = new Lang.Class({
      _init: function(params) {
         audioProfile = new AudioProfile.AudioProfile();
         offsetController = new FileUtil.OffsetController;
+        displayTime = new FileUtil.DisplayTime;
         view = new MainView();
         play = new Play.Play();
         
@@ -420,7 +422,7 @@ const MainView = new Lang.Class({
                 this._playLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
                                                    name: "PlayLabelBox",
                                                    height_request: 45 });
-                this.rowGrid.attach(this._playLabelBox, 3, 1, 10, 1);
+                this.rowGrid.attach(this._playLabelBox, 3, 1, 6, 1);
                 this._playLabelBox.show();       
                 this.playDurationLabel = new Gtk.Label({ margin_left: rtl ? 0 : 15,
                                                          margin_right: rtl ? 15 : 0,
@@ -449,15 +451,27 @@ const MainView = new Lang.Class({
                 this._playLabelBox.pack_start(this.playTimeLabel, false, true, 0);
                 this.playTimeLabel.hide();
                 
+                //Date Modified label
+                this.dateModifiedLabel = new Gtk.Label({ margin_left: 15,
+                                                         margin_right: 15,
+                                                         halign: Gtk.Align.END,
+                                                         valign: Gtk.Align.CENTER,
+                                                         margin_top: 5,
+                                                         name: "dateModifiedLabel" });
+                this.dateModifiedLabel.label = this._files[i].dateModified;
+                this.dateModifiedLabel.get_style_context().add_class('dim-label');
+                this.rowGrid.attach(this.dateModifiedLabel, 3, 1, 6, 1);
+                this.dateModifiedLabel.show();
+                
                 this.waveFormGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
                                                    height_request: 45,
-                                                   width_request: 350,
+                                                   width_request: 300,
                                                    valign: Gtk.Align.FILL,
                                                    hexpand: true,
                                                    vexpand: true,
                                                    name: "WaveFormGrid" });
                 this.waveFormGrid.set_no_show_all(true);
-                this.rowGrid.attach(this.waveFormGrid, 11, 1, 18, 2);
+                this.rowGrid.attach(this.waveFormGrid, 12, 1, 17, 2);
                 this.waveFormGrid.show();
                 
                 // info button
diff --git a/src/record.js b/src/record.js
index 6381b17..f01b346 100644
--- a/src/record.js
+++ b/src/record.js
@@ -34,6 +34,7 @@ const Signals = imports.signals;
 const Application = imports.application;
 const AudioProfile = imports.audioProfile;
 const MainWindow = imports.mainWindow;
+const Listview = imports.listview;
 
 const PipelineStates = {
     PLAYING: 0,
@@ -93,6 +94,10 @@ const Record = new Lang.Class({
                             this.taglist = Gst.TagList.new_empty();
                             this.taglist.add_value(Gst.TagMergeMode.APPEND, Gst.TAG_APPLICATION_NAME, 
_("Sound Recorder"));
                             element.merge_tags(this.taglist, Gst.TagMergeMode.REPLACE);
+                            let trackNumber = Listview.trackNumber + 1;
+                            let trackNumberString = trackNumber.toString();
+                            this.taglist.add_value(Gst.TagMergeMode.APPEND, Gst.TAG_TITLE, 
trackNumberString);
+                            element.merge_tags(this.taglist, Gst.TagMergeMode.REPLACE);
                             this.taglist.add_value(Gst.TagMergeMode.APPEND, Gst.TAG_DATE_TIME, 
this.gstreamerDateTime);
                             element.merge_tags(this.taglist, Gst.TagMergeMode.REPLACE);
                     }
@@ -279,10 +284,12 @@ const BuildFileName = new Lang.Class({
         let fileExtensionName = MainWindow.audioProfile.fileExtensionReturner();
         let dir = Gio.Application.get_default().saveDir;
         this.dateTime = GLib.DateTime.new_now_local();
-        /* Translators: "Audio from %Y-%m-%d %H:%M:%S" is the default name assigned to a file created
-            by the application (for example, "Audio from 2013-10-05 13:25:21.ogg"). */
-        let dateTimeString = this.dateTime.format(_("Audio from %Y-%m-%d %H:%M:%S"));
-        let file = dir.get_child_for_display_name(dateTimeString + fileExtensionName);
+        this.clipNumber = Listview.trackNumber + 1;
+        this.clipNumberString = this.clipNumber.toString();
+        /* Translators: ""Clip %d"" is the default name assigned to a file created
+            by the application (for example, "Clip 1"). */
+        let clipName = _("Clip %d").format(this.clipNumberString);
+        let file = dir.get_child_for_display_name(clipName);
 
         return file;
     },
@@ -293,7 +300,7 @@ const BuildFileName = new Lang.Class({
     
     getOrigin: function() {
         return this.dateTime;
-    }    
+    } 
 });
 
 


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