From 8b671f7f75b6381a394c591852d811b05a9edf8b Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 25 May 2011 01:34:48 +0530 Subject: [PATCH] file i/o works --- chrome/content/speedtag.html | 46 +++++++++++++++++++++++++++++++++-- chrome/content/speedtag.js | 25 ++++++++++++++++--- chrome/content/staticfuncs.js | 39 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/chrome/content/speedtag.html b/chrome/content/speedtag.html index d37baed..01d5514 100644 --- a/chrome/content/speedtag.html +++ b/chrome/content/speedtag.html @@ -7,6 +7,7 @@ +
@@ -14,8 +15,9 @@
-
+
+ + + + + + + + + + + + + + + + +
@@ -25,14 +27,54 @@
+ Is Secret: + + +
+ Gender: + + +
+ Marital Status: + + +
+ Profession: + + +
- +
+
+ diff --git a/chrome/content/speedtag.js b/chrome/content/speedtag.js index e75acab..1e3fb8f 100644 --- a/chrome/content/speedtag.js +++ b/chrome/content/speedtag.js @@ -1,11 +1,30 @@ +var startTime = new Date(); + $(function() { var savePath = ''; $('#saveLocationBtn').click(function() { - savePath = selectFile(); + savePath = mozillaSelectFolder().file.path; +// alert(savePath.file.path); }); $('#selectAudioFile').click(function() { + if (savePath === '') { alert("Please select a save location first."); return false; } fil = selectFile(); - data = mozillaLoadFile(fil); - mozillaSaveFile("/tmp/blah.mp3", data); +// alert(savePath); + var destName = getDateString(startTime) + ".mp3"; + mozillaCopyFile(fil.file.path, savePath, destName); + }); + $('#saveFormData').click(function() { + if (savePath === '') { alert("Please select a save location first."); return false; } + var arr = $('#metadataForm').serializeArray(); + var s = JSON.stringify(arr); + // alert(s); + var destFilePath = savePath + "/" + getDateString(startTime) + ".json"; + // alert(destFilePath); + mozillaSaveFile(destFilePath, s); + alert("saved " + destFilePath); }); }); + +function getDateString(dateObj) { + return dateObj.toUTCString().replace(",", "").replace(":", "."); +} diff --git a/chrome/content/staticfuncs.js b/chrome/content/staticfuncs.js index 3a9cfb0..a5c0cbd 100755 --- a/chrome/content/staticfuncs.js +++ b/chrome/content/staticfuncs.js @@ -126,6 +126,25 @@ function mozillaSaveFile(filePath,content) return null; } +function mozillaSelectFolder() { + const nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); + fp.init(window, "Select Save Folder", Components.interfaces.nsIFilePicker.modeGetFolder); + var rv = fp.show(); + if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { +// alert("hoo"); + return fp; +/* + var file = fp.file; + var path = fp.file.path; + return path; +*/ + } else { +// alert("ho"); + } + return false; +} + function mozillaSaveAs() { const nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); @@ -186,6 +205,26 @@ function mozillaLoadFile(filePath) return null; } +function mozillaCopyFile(sourcePath, destPath, destName) { + if (window.Components) { + try { + var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); +// alert(sourcePath); + file.initWithPath(sourcePath); +// file.copyTo(destPath); + var dest = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); + dest.initWithPath(destPath); + file.copyTo(dest, destName); + alert("copied to " + destPath + "/" + destName); + return true; + } catch(ex) { + alert(ex); + return false; + } + } else { + return null; + } +} function checkFileExists(filePath) { if(window.Components) {