Commit e0e846aa authored by Meg Ford's avatar Meg Ford

code cleanup

parent e89f4239
......@@ -61,10 +61,16 @@ const FileUtil = new Lang.Class({
_deleteFileCallback: function(obj, res) {
this._deleted = obj.delete_finish(res);
//this._list = new Listview.Listview();
//this._list.enumerateDirectory();
// Application.offsetController.resetOffset();
//Application.add_named(groupGrid, name);
//this._list.refreshListview();
//MainWindow.offsetController.resetOffset();
//MainWindow.view.listBoxAdd();
},
getDirPath: function() {
let path = MainWindow.path;
let dirName = GLib.build_filenamev(path);
let dir = Gio.file_new_for_path(dirName);
return dir;
}
});
......@@ -118,16 +124,14 @@ const OffsetController = new Lang.Class({
log(this.totItems);
this.ensureCount = this._offset + _OFFSET_STEP - 1;
log(this.ensureCount);
log("counitn");
this.getItemCount();
if (this.ensureCount < this.totItems) {
this.endIdx = this.ensureCount;
log(this.endIdx);
log("wtf");}
else {
} else {
this.endIdx = this.totItems - 1;
log(this.endIdx);
log("ttt");}
}
CurrentEndIdx = this.endIdx;
this.getcidx();
......@@ -137,6 +141,5 @@ const OffsetController = new Lang.Class({
return CurrentEndIdx;
}
});
Signals.addSignalMethods(OffsetController.prototype); //Do I use this?
......@@ -46,24 +46,45 @@ const mediaTypeMap = {
FLAC: "FLAC",
MP3: "MP3",
MP4: "MP4"
};
};
const ListType = {
NEW: 0,
REFRESH: 1
};
const CurrentlyEnumerating = {
TRUE: 0,
FALSE: 1
};
let currentlyEnumerating = null;
let stopVal = null;
let allFilesInfo = null;
let fileInfo = null;
let listType = null;
let startRecording = false;
const Listview = new Lang.Class({
Name: "Listview",
_init: function() {
this._stopVal = EnumeratorState.ACTIVE;
this._allFilesInfo = [];
stopVal = EnumeratorState.ACTIVE;
allFilesInfo = [];
this.mp3Caps = Gst.Caps.from_string("audio/mpeg, mpegversion=(int)1");
this.oggCaps = Gst.Caps.from_string("audio/ogg");
this.mp4Caps = Gst.Caps.from_string("video/quicktime, variant=(string)iso");
this.flacCaps = Gst.Caps.from_string("audio/x-flac");
},
monitorListview: function() {
let dir = MainWindow.fileUtil.getDirPath();
this.dirMonitor = dir.monitor_directory(Gio.FileMonitorFlags.NONE, null);
this.dirMonitor.connect('changed', this._onDirChanged);
},
enumerateDirectory: function() {
let path = MainWindow.path;
let dirName = GLib.build_filenamev(path);
let dir = Gio.file_new_for_path(dirName);
let dir = MainWindow.fileUtil.getDirPath();
dir.enumerate_children_async('standard::name,time::created,time::modified',
Gio.FileQueryInfoFlags.NONE,
......@@ -82,7 +103,7 @@ const Listview = new Lang.Class({
},
_onNextFileComplete: function () {
this._fileInfo = [];
fileInfo = [];
try{
this._enumerator.next_files_async(10, GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
function(obj, res) {
......@@ -107,8 +128,8 @@ const Listview = new Lang.Class({
this.dateCreatedString = dateCreated.format(_("%Y-%m-%d %H:%M:%S"));
}
this._fileInfo =
this._fileInfo.concat({ appName: null,
fileInfo =
fileInfo.concat({ appName: null,
dateCreated: null,
dateForSort: dateModifiedSortString,
dateModified: dateModifiedDisplayString,
......@@ -118,10 +139,10 @@ const Listview = new Lang.Class({
title: null,
uri: null });
}));
this._sortItems(this._fileInfo);
this._sortItems(fileInfo);
} else {
//log("done");
this._stopVal = EnumeratorState.CLOSED;
log("done");
stopVal = EnumeratorState.CLOSED;
this._enumerator.close(null);
this._setDiscover();
......@@ -133,27 +154,30 @@ const Listview = new Lang.Class({
}
},
_sortItems: function(fileArr) {
_sortItems: function(fileArr) {
log("sort");
this._fileArr = fileArr;
this._allFilesInfo = this._allFilesInfo.concat(this._fileArr);
this._allFilesInfo.sort(function(a, b) {
allFilesInfo = allFilesInfo.concat(this._fileArr);
allFilesInfo.sort(function(a, b) {
return b.dateForSort - a.dateForSort;
});
if (this._stopVal == EnumeratorState.ACTIVE)
this._onNextFileComplete();
log("this._stopVal " + stopVal);
if (stopVal == EnumeratorState.ACTIVE) {
this._onNextFileComplete();
log("sort done");
}
},
getItemCount: function() {
//log(this._allFilesInfo.length);
return this._allFilesInfo.length;
log(allFilesInfo.length);
return allFilesInfo.length;
},
_setDiscover: function() {
this._controller = MainWindow.offsetController;
this.totItems = this.getItemCount();
this.startIdx = this._controller.getOffset();
//log(this.startIdx);
log("this.startIdx" + this.startIdx);
this.ensureCount = this.startIdx + this._controller.getOffsetStep() - 1;
if (this.ensureCount < this.totItems)
......@@ -167,14 +191,14 @@ const Listview = new Lang.Class({
},
_runDiscover: function() {
this.file = this._allFilesInfo[this.idx];
this.file = allFilesInfo[this.idx];
this._buildFileName = new Record.BuildFileName();
let initialFileName = this._buildFileName.buildPath();
initialFileName.push(this.file.fileName);
let finalFileName = GLib.build_filenamev(initialFileName);
let uri = GLib.filename_to_uri(finalFileName, null);
this.file.uri = uri;
//log(this.file.uri);
log(this.file.uri);
this._discoverer = new GstPbutils.Discoverer();
this._discoverer.start();
this._discoverer.discover_uri_async(uri);
......@@ -222,21 +246,57 @@ const Listview = new Lang.Class({
}
this._getCapsForList(info);
if (this.idx < this.endIdx && this.idx >= 0) {
this.idx++;
//log(this.idx);
this._runDiscover();
} else {
this._discoverer.stop();
MainWindow.offsetController.setEndIdx();
//Application.view.list();
MainWindow.view.listBoxAdd();
}
} else {
// don't index files we can't play
log("File cannot be played");
}
if (this.idx < this.endIdx && this.idx >= 0) {
this.idx++;
log("this.listType discovering" + listType);
this._runDiscover();
} else {
this._discoverer.stop();
log("this.listType discovering" + listType);
MainWindow.offsetController.setEndIdx();
if (listType == ListType.NEW) {
MainWindow.view.listBoxAdd();
MainWindow.view.scrolledWinAdd();
currentlyEnumerating = CurrentlyEnumerating.FALSE;
log("this.currentlyEnumerating new" +currentlyEnumerating);
} else if (listType == ListType.REFRESH){
MainWindow.view.scrolledWinDelete();
currentlyEnumerating = CurrentlyEnumerating.FALSE;
log("this.currentlyEnumerating " +currentlyEnumerating);
}
}
},
setListTypeNew: function() {
listType = ListType.NEW;
},
_onDirChanged: function(dirMonitor, file1, file2, eventType) {
log("eventType" + eventType);
if (eventType == Gio.FileMonitorEvent.DELETED ||
(eventType == Gio.FileMonitorEvent.CHANGES_DONE_HINT && MainWindow.recordPipeline == MainWindow.RecordPipelineStates.STOPPED)) {
stopVal = EnumeratorState.ACTIVE;
allFilesInfo.length = 0;
fileInfo.length = 0;
log(stopVal + "this._stopVal");
listType = ListType.REFRESH;
log("this.listType" + listType);
log("this.currentlyEnumerating " + currentlyEnumerating);
if(currentlyEnumerating == CurrentlyEnumerating.FALSE) {
currentlyEnumerating = CurrentlyEnumerating.TRUE;
MainWindow.view.listBoxRefresh();
}
}
if (eventType == Gio.FileMonitorEvent.CREATED)
startRecording = true;
log("MainWindow.recordPipeline" + MainWindow.recordPipeline);
},
_getCapsForList: function(info) {
......@@ -285,7 +345,7 @@ const Listview = new Lang.Class({
},
getFilesInfoForList: function() {
return this._allFilesInfo;//return
return allFilesInfo;
},
getEndIdx: function() {
......
......@@ -37,8 +37,8 @@ const Record = imports.record;
const Waveform = imports.waveform;
let audioProfile = null;
let fileManager = null; // do I use this?
let fileUtil = null;
let grid = null;
let groupGrid;
let list = null;
let offsetController = null;
......@@ -47,6 +47,8 @@ let play = null;
let selectable = null;
let view = null;
let wave = null;
let recordPipeline = null;
let recordButton = null;
const ActiveArea = {
RECORD: 0,
......@@ -64,6 +66,12 @@ const PipelineStates = {
STOPPED: 2
};
const RecordPipelineStates = {
PLAYING: 0,
PAUSED: 1,
STOPPED: 2
};
const _TIME_DIVISOR = 60;
const _SEC_TIMEOUT = 100;
......@@ -76,19 +84,23 @@ const MainWindow = new Lang.Class({
this._buildFileName = new Record.BuildFileName()
path = this._buildFileName.buildPath();
this._buildFileName.ensureDirectory(path);
offsetController = new FileUtil.OffsetController;
fileUtil = new FileUtil.FileUtil();
offsetController = new FileUtil.OffsetController;
view = new MainView();
play = new Play.Play();
params = Params.fill(params, { title: GLib.get_application_name(), //change this
default_width: 700,
default_height: 480,
border_width: 12 });
default_height: 480 });
this.parent(params);
let grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
halign: Gtk.Align.CENTER });
grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
halign: Gtk.Align.CENTER,
height_request: 109,
width_request: 900,
border_width: 12,
vexpand: false });
grid.set_row_homogeneous(true);
let stackSwitcher = Gtk.StackSwitcher.new();
stackSwitcher.set_stack(view);
let header = new Gtk.HeaderBar({ hexpand: true });
......@@ -98,7 +110,7 @@ const MainWindow = new Lang.Class({
let recordToolbar = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 0 });
header.pack_start(recordToolbar);
let recordButton = new RecordButton({ label: "Record",
recordButton = new RecordButton({ label: "Record",
margin_bottom: 4,
margin_top: 6,
margin_left: 6,
......@@ -115,11 +127,11 @@ const MainWindow = new Lang.Class({
this.add(grid);
grid.show_all();
this.show_all();
log("grid" + grid.get_preferred_height());
},
_defineThemes: function() {
let settings = Gtk.Settings.get_default();
//settings.gtk_application_prefer_dark_theme = true;
}
});
......@@ -137,19 +149,15 @@ const MainView = new Lang.Class({
let listviewPage = this._addListviewPage('listviewPage');
this.visible_child_name = 'playerPage';
let recorderPage = this._addRecorderPage('recorderPage');
this.visible_child_name = 'listviewPage';
let playerPage = this._addPlayerPage('playerPage');
this.visible_child_name = 'recorderPage';
this.labelID = null;
},
_addListviewPage: function(name) {
list = new Listview.Listview();
list.setListTypeNew();
list.enumerateDirectory();
this._record = new Record.Record(audioProfile);
let initialPage = new Gtk.EventBox();
groupGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
......@@ -160,84 +168,6 @@ const MainView = new Lang.Class({
groupGrid.add(initialPage);
this.add_titled(groupGrid, name, "View");
},
_addRecorderPage: function(name) {
this._record = new Record.Record(audioProfile);
this.recordBox = new Gtk.EventBox();
this._comboBoxText = new EncoderComboBox();
//recordGrid.attach(this._comboBoxText, 20, 1, 3, 1);
// this.recordTimeLabel = new Gtk.Label();
//recordGrid.attach(this.recordTimeLabel, 20, 2, 3, 1);
this.recordVolume = new Gtk.VolumeButton();
this.recordRange = Gtk.Adjustment.new(0.2, 0, 1.0, 0.05, 0.0, 0.0);
this.recordVolume.set_adjustment(this.recordRange);
this.recordVolume.connect ("value-changed", Lang.bind(this, this.setVolume));
//recordGrid.attach(this.recordVolume, 20, 4, 3, 1);
this.add_titled(this.recordBox, name, "Record");
},
_addPlayerPage: function(name) {
this.playBox = new Gtk.EventBox();
let playGrid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
halign: Gtk.Align.CENTER,
valign: Gtk.Align.CENTER,
column_homogeneous: true,
column_spacing: 15 });
this.playBox.add(playGrid);
let playToolbar = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 0 });
playToolbar.get_style_context().add_class(Gtk.STYLE_CLASS_LINKED);
playGrid.attach(playToolbar, 20, 0, 2, 1);
let loadButton = new LoadMoreButton(playGrid);
this.progressScale = new Gtk.Scale();
this.progressScale.sensitive = false;
this.progressScale.connect("button-press-event", Lang.bind(this,
function() {
MainWindow.play.onProgressScaleConnect();
return false;
}));
this.progressScale.connect("button-release-event", Lang.bind(this,
function() {
this.setProgressScaleInsensitive();
this.onProgressScaleChangeValue();
this._updatePositionCallback();
return false;
}));
playGrid.attach(this.progressScale, 20, 3, 3, 1);
/*this.playVolume = new Gtk.VolumeButton();
this.range = Gtk.Adjustment.new(0.90, 0, 1.0, 0.05, 0.0, 0.0);
this.playVolume.set_adjustment(this.range);
this.playVolume.connect("value-changed", Lang.bind(this, this.setVolume));
playGrid.attach(this.playVolume, 20, 4, 3, 1);*/
//this.playButton = new PlayPauseButton();
//playToolbar.pack_end(this.playButton, false, true, 0);
let stopPlay = new Gtk.Button();
this.stopImage = Gtk.Image.new_from_icon_name("media-playback-stop-symbolic", Gtk.IconSize.BUTTON);
stopPlay.set_image(this.stopImage);
stopPlay.connect("clicked", Lang.bind(this, this.onPlayStopClicked));
playToolbar.pack_end(stopPlay, true, true, 0);
this.add_titled(this.playBox, name, "Play");
},
onPlayStopClicked: function() {
//this.playButton.set_active(false);
......@@ -247,23 +177,8 @@ const MainView = new Lang.Class({
onRecordStopClicked: function() {
this._record.stopRecording();
this.recordGrid.hide();
wave.resize();
},
setProgressScaleSensitive: function() {
this.progressScale.sensitive = true;
},
setProgressScaleInsensitive: function() {
this.progressScale.sensitive = false;
},
onProgressScaleChangeValue: function() {
let seconds = Math.ceil(this.progressScale.get_value());
MainWindow.play.progressScaleValueChanged(seconds);
return true;
recordPipeline = RecordPipelineStates.STOPPED;
recordButton.set_sensitive(true);
},
_formatTime: function(unformattedTime) {
......@@ -356,13 +271,15 @@ const MainView = new Lang.Class({
stopRecord.connect("clicked", Lang.bind(this, this.onRecordStopClicked));
this.toolbarStart.pack_start(stopRecord, true, true, 0);
this.recordGrid.attach(this.toolbarStart, 5, 1, 1, 2);
},
scrolledWinAdd: function() {
this._scrolledWin = new Gtk.ScrolledWindow({ shadow_type: Gtk.ShadowType.IN,
margin_bottom: 3,
margin_top: 5,
hexpand: false,
vexpand: false,
width_request: 800,
width_request: 900,
height_request: 400 });
this._scrolledWin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
this._scrolledWin.get_style_context().add_class('view');
......@@ -391,7 +308,7 @@ const MainView = new Lang.Class({
for (let i = this._startIdx; i <= this._endIdx; i++) {
this.rowGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 45,
width_request: 400,
width_request: 900,
name: i.toString() });
this.rowGrid.set_orientation(Gtk.Orientation.HORIZONTAL);
this.listBox.add(this.rowGrid);
......@@ -549,9 +466,23 @@ const MainView = new Lang.Class({
this.selectionRow = this._separator.get_parent();
this.selectionRow.set_sensitive(false);
this._separator.show();
list.monitorListview();
}
},
listBoxRefresh: function() {
fileUtil = new FileUtil.FileUtil();
list.enumerateDirectory();
},
scrolledWinDelete: function() {
let w = this.rowGrid.get_allocated_width();
this._scrolledWin.destroy();
this.scrolledWinAdd();
log("destroy " + w);
},
rowGridCallback: function(selectedRow) {
if (selectedRow) {
......@@ -620,7 +551,6 @@ const MainView = new Lang.Class({
_onInfoButton: function(selected) {
this._selected = selected;
//let fileForInfo = this._getFileNameFromRow(this._selected);
let infoDialog = new Info.InfoDialog(selected);
infoDialog.widget.connect('response', Lang.bind(this,
......@@ -629,18 +559,10 @@ const MainView = new Lang.Class({
}));
},
setLabel: function(time, duration) {
setLabel: function(time) {
this.time = time
this.duration = duration;
this.playPipeState = play.getPipeStates();
/* if (this.playPipeState != PipelineStates.STOPPED) { //test this
if (this.playDurationLabel.label == "0:00" && duration != 0)
this.durationString = this._formatTime(duration);
} else {
this.durationString = this._formatTime(duration);
}*/
this.timeLabelString = this._formatTime(time);
if (this.setVisibleID == ActiveArea.RECORD) {
......@@ -648,13 +570,6 @@ const MainView = new Lang.Class({
this.recordTimeLabel.get_style_context().add_class('dim-label');
} else if (this.setVisibleID == ActiveArea.PLAY) {
this.playTimeLabel.label = this.timeLabelString;
if (this.playDurationLabel.label == "0:00" || this.playPipeState == PipelineStates.STOPPED) {
//this.playDurationLabel.label = this.durationString;
this.setProgressScaleSensitive();
this.progressScale.set_range(0.0, duration);
}
this.progressScale.set_value(this.time);
}
},
});
......@@ -671,6 +586,7 @@ const RecordButton = new Lang.Class({
},
_onRecord: function() {
this.set_sensitive(false);
view.setVisibleID = ActiveArea.RECORD;
view.recordGrid.show_all();
audioProfile.assignProfile();
......
......@@ -136,7 +136,7 @@ const _TENTH_SEC = 100000000;
case Gst.MessageType.ERROR:
log("Error :" + e.parse_error());
this._showErrorDialog(_("Error :" + e.parse_error())); //should I only show for specific error messages
this._showErrorDialog(_("Error:" + e.parse_error())); //should I only show for specific error messages
break;
case Gst.MessageType.DURATION:
......@@ -180,9 +180,9 @@ const _TENTH_SEC = 100000000;
if (time >= 0 && this.playState != PipelineStates.STOPPED) {
log("called UPDATE");
this.view.setLabel(time, this.trackDurationSecs);
this.view.setLabel(time);
} else if (time >= 0 && this.playState == PipelineStates.STOPPED) {
this.view.setLabel(0, this.trackDurationSecs);
this.view.setLabel(0);
}
this.absoluteTime = this.clock.get_time();
......
......@@ -25,39 +25,83 @@ const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
const C_ = imports.gettext.pgettext;
const MainWindow = imports.mainWindow;
const Main = imports.main;
const Preferences = new Lang.Class({
Name: 'Preferences',
_init: function() {
_init: function() {
//let toplevel = Main.Application.get_windows()[0];
this.widget = new Gtk.Dialog ({ resizable: false,
//transient_for: toplevel,
modal: true,
destroy_with_parent: true,
default_width: 400,
title: _("Preferences"),
hexpand: true });
width_request: 350,
margin_top: 5,
hexpand: true });
this.widget.add_button(_("Done"), Gtk.ResponseType.OK);
let mainGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
row_spacing: 6,
margin_left: 12,
margin_right: 12,
margin_bottom: 12,
margin_top: 12 });
let contentArea = this.widget.get_content_area();
contentArea.pack_start(mainGrid, true, true, 0);
let grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
hexpand: true,
vexpand: true,
column_spacing: 18,
row_spacing: 6,
margin_bottom: 12,
margin_top: 12 });
mainGrid.add(grid);
let grid = new Gtk.Grid ({ orientation: Gtk.Orientation.VERTICAL,
row_homogeneous: true,
column_homogeneous: true,
halign: Gtk.Align.CENTER,
row_spacing: 6,
column_spacing: 24,
margin_top: 12,
margin_left: 24,
margin_right: 24,
margin_bottom: 12 });
let contentArea = this.widget.get_content_area();
contentArea.pack_start(grid, true, true, 2);
this.widget.add_button(_("Done"), Gtk.ResponseType.OK);
let formatLabel = new Gtk.Label({ label: '<b>' + _("Preferred format") + '</b>',
halign: Gtk.Align.START,
use_markup: true });
grid.attach(formatLabel, 0, 0, 1, 1);
let comboBoxText = new MainWindow.EncoderComboBox({ halign: Gtk.Align.END });
comboBoxText.set_active(0);
grid.attach(comboBoxText, 2, 0, 1, 1);
let volumeLabel = new Gtk.Label({ label: '<b>' + _("Volume") + '</b>',
halign: Gtk.Align.START,
use_markup: true });
grid.attach(volumeLabel, 0, 1, 2, 1);
this.playVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.playRange = Gtk.Adjustment.new(0.75, 0, 1.0, 0.05, 0.0, 0.0);
this.playVolume.set_adjustment(this.playRange);
this.playVolume.set_sensitive(true);
this.playVolume.connect("value-changed", Lang.bind(this,
function() {
MainWindow.view.setVisibleID == MainWindow.ActiveArea.PLAY;
MainWindow.view.setVolume();
}));
grid.attach(this.playVolume, 2, 1, 2, 1);
let micVolLabel = new Gtk.Label({ label: '<b>' + _("Microphone") + '</b>',
halign: Gtk.Align.START,
use_markup: true });
grid.attach(micVolLabel, 0, 2, 2, 1);
this._name = new Gtk.Label({ label: C_("File Name", "Name"),
halign: Gtk.Align.END });
this._name.get_style_context ().add_class('dim-label');
grid.add(this._name);
this.recordVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.recordRange = Gtk.Adjustment.new(0.75, 0, 1.0, 0.05, 0.0, 0.0);
this.recordVolume.set_adjustment(this.recordRange);
this.recordVolume.set_sensitive(true);
this.recordVolume.connect("value-changed", Lang.bind(this,
function() {
MainWindow.view.setVisibleID == MainWindow.ActiveArea.RECORD;
MainWindow.view.setVolume();
}));
grid.attach(this.recordVolume, 2, 2, 2, 1);
this.widget.show_all();
},
......
......@@ -285,6 +285,6 @@ const WaveForm = new Lang.Class({
this.count = 0;
peaks.length = 0;
this.drawing.destroy();
cr.$dispose();
//cr.$dispose();
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment