JSProtoObject = {
onShown: function (strWiId) {
this.toggleAccess(strWiId);
}
,
toggleAccess: function (strWiId) {
setTimeout(function () {
var prefix = "wgt-" + strWiId + "-pref-sound-";
var textbox = document.getElementById(prefix + "uri");
document.getElementById(prefix + "preview").disabled = ! textbox.value;
}
,1);
}
,
openFileDialog: function (strWiId) {
var prefix = "wgt-" + strWiId + "-pref-sound-";
var stringBundle = this.getBundle();
const nsIFilePicker = Ci.nsIFilePicker;
var filePicker = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
filePicker.init(window,stringBundle.GetStringFromName("ChooseASoundFile"),nsIFilePicker.modeOpen);
filePicker.appendFilter(stringBundle.GetStringFromName("ChooseASoundFilterWav"),"*.wav");
filePicker.appendFilter(stringBundle.GetStringFromName("ChooseASoundFilterAll"),"*.*");
if (filePicker.show() == nsIFilePicker.returnOK)
{
let textbox = document.getElementById(prefix + "uri");
textbox.value = filePicker.file.path;
textbox.doCommand();
}

JSProtoObject.toggleAccess(strWiId);
}
,
getBundle: function () {
var appName = JSNativeModule.core.API.Environment.barPlatform.name;
return this.bundleService.createBundle("chrome://" + appName + "/locale/preferences/preferences.properties");
}
,
play: function (strWiId) {
try {
let prefix = "wgt-" + strWiId + "-pref-sound-";
let strURI = document.getElementById(prefix + "uri").value;
let tempLocalFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
tempLocalFile.initWithPath(strURI);
let uri = this.ioService.newFileURI(tempLocalFile);
this.soundService.play(uri);
}
catch (e) {

}

}
,
ioService: Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
soundService: Cc["@mozilla.org/sound;1"].createInstance(Ci.nsISound),
bundleService: Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService),
filePicker: Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker)};
