diff --git a/chrome/chromeFiles/content/scholar/fileInterface.js b/chrome/chromeFiles/content/scholar/fileInterface.js index 09da946809..5cbfecde17 100644 --- a/chrome/chromeFiles/content/scholar/fileInterface.js +++ b/chrome/chromeFiles/content/scholar/fileInterface.js @@ -1,4 +1,6 @@ Scholar_File_Interface = new function() { + var _unresponsiveScriptPreference; + this.exportFile = exportFile; this.importFile = importFile; this.bibliographyFromProject = bibliographyFromProject; @@ -21,11 +23,42 @@ Scholar_File_Interface = new function() { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { translation.setLocation(fp.file); translation.setTranslator(translators[fp.filterIndex]); - //translation.setHandler("done", _exportDone); - translation.translate(); + //translation.setHandler("itemCount", _exportItemCount); + //translation.setHandler("itemDone", _exportItemDone); + translation.setHandler("done", _exportDone); + _disableUnresponsive(); + Scholar_File_Interface.Progress.show( + Scholar.getString("fileInterface.itemsExported"), + function() { + translation.translate(); + }); } } + /* + * set progress indicator length + */ + function _exportItemCount(obj, number) { + Scholar.debug("count called with "+number); + Scholar_File_Interface.Progress.setNumber(number); + } + + /* + * Increment progress for each item exported + */ + function _exportItemDone(obj, item) { + Scholar_File_Interface.Progress.increment(); + } + + /* + * closes items exported indicator + */ + function _exportDone(obj) { + Scholar_File_Interface.Progress.close(); + _restoreUnresponsive(); + } + + /* * Creates Scholar.Translate instance and shows file picker for file import */ @@ -49,12 +82,56 @@ Scholar_File_Interface = new function() { if(translators.length) { // TODO: display a list of available translators translation.setTranslator(translators[0]); + // show progress indicator translation.setHandler("itemDone", _importItemDone); - translation.translate(); + translation.setHandler("done", _importDone); + _disableUnresponsive(); + Scholar_File_Interface.Progress.show( + Scholar.getString("fileInterface.itemsImported"), + function() { + translation.translate(); + }); } } } + /* + * Saves items after they've been imported. We could have a nice little + * "items imported" indicator, too. + */ + function _importItemDone(obj, item) { + //Scholar_File_Interface.Progress.increment(); + item.save(); + } + + /* + * closes items imported indicator + */ + function _importDone(obj) { + Scholar_File_Interface.Progress.close(); + _restoreUnresponsive(); + } + + /* + * disables the "unresponsive script" warning; necessary for import and + * export, which can take quite a while to execute + */ + function _disableUnresponsive() { + var prefService = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + _unresponsiveScriptPreference = prefService.getIntPref("dom.max_script_run_time"); + prefService.setIntPref("dom.max_script_run_time", 0); + } + + /* + * restores the "unresponsive script" warning + */ + function _restoreUnresponsive() { + var prefService = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + prefService.setIntPref("dom.max_script_run_time", _unresponsiveScriptPreference); + } + /* * Creates a bibliography */ @@ -65,14 +142,6 @@ Scholar_File_Interface = new function() { _doBibliographyOptions(Scholar.getItems(collection.getID())); } - /* - * Saves items after they've been imported. We could have a nice little - * "items imported" indicator, too. - */ - function _importItemDone(obj, item) { - item.save(); - } - /* * Shows bibliography options and creates a bibliography */ @@ -161,4 +230,79 @@ Scholar_File_Interface = new function() { clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard); } } -} \ No newline at end of file +} + +// Handles the display of a progress indicator +Scholar_File_Interface.Progress = new function() { + var _windowLoaded = false; + var _windowLoading = false; + var _progressWindow; + // keep track of all of these things in case they're called before we're + // done loading the progress window + var _loadHeadline, _loadNumber, _outOf, _callback; + + this.show = show; + //this.setNumber = setNumber; + //this.increment = increment; + this.close = close; + + function show(headline, callback) { + if(_windowLoading || _windowLoaded) { // already loading or loaded + return false; + } + _windowLoading = true; + + _loadHeadline = headline; + _loadNumber = 0; + _outOf = 0; + _callback = callback; + + _progressWindow = window.openDialog("chrome://scholar/chrome/fileProgress.xul", "", "chrome,resizable=no,close=no,dependent,dialog,centerscreen"); + _progressWindow.addEventListener("pageshow", _onWindowLoaded, false); + } + + /*function setNumber(number) { + _outOf = number; + if(_windowLoaded) { + var progressMeter = _progressWindow.document.getElementById("progress-indicator"); + progressMeter.mode = "normal"; + progressMeter.value = "0%"; + } + } + + function increment() { + _loadNumber++; + if(_windowLoaded) { + _progressWindow.document.getElementById("progress-items").value = _loadNumber; + if(_outOf) { + _progressWindow.document.getElementById("progress-indicator").value = ((_loadNumber/_outOf)*100).toString()+"%"; + } + _progressWindow.getSelection(); + } + }*/ + + function close() { + _windowLoaded = false; + try { + _progressWindow.close(); + } catch(ex) {} + } + + function _onWindowLoaded() { + _windowLoading = false; + _windowLoaded = true; + + // do things we delayed because the winodw was loading + /*if(_outOf) { + var progressMeter = _progressWindow.document.getElementById("progress-indicator"); + progressMeter.mode = "normal"; + progressMeter.value = ((_loadNumber/_outOf)*100).toString()+"%"; + } + _progressWindow.document.getElementById("progress-items").value = _loadNumber;*/ + _progressWindow.document.getElementById("progress-label").value = _loadHeadline; + + if(_callback) { + window.setTimeout(_callback, 1500); + } + } +} diff --git a/chrome/chromeFiles/content/scholar/fileProgress.xul b/chrome/chromeFiles/content/scholar/fileProgress.xul new file mode 100644 index 0000000000..8d2e34883f --- /dev/null +++ b/chrome/chromeFiles/content/scholar/fileProgress.xul @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/chrome/chromeFiles/content/scholar/xpcom/translate.js b/chrome/chromeFiles/content/scholar/xpcom/translate.js index 703c517b77..bd1b779efc 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/translate.js +++ b/chrome/chromeFiles/content/scholar/xpcom/translate.js @@ -137,6 +137,12 @@ Scholar.Translate.prototype.setTranslator = function(translator) { * returns: a numerically indexed array of ids, as extracted from the passed * string * + * itemCount + * valid: export + * called: when the export + * passed: the number of items to be processed + * returns: N/A + * * itemDone * valid: web * called: when an item has been processed; may be called asynchronously @@ -146,7 +152,7 @@ Scholar.Translate.prototype.setTranslator = function(translator) { * done * valid: all * called: when all processing is finished - * passed: returns true if successful, false if an error occurred + * passed: true if successful, false if an error occurred * returns: N/A */ Scholar.Translate.prototype.setHandler = function(type, handler) { @@ -708,6 +714,8 @@ Scholar.Translate.prototype._export = function() { // get items this._itemsLeft = Scholar.getItems(); + // run handler for items available + this._runHandler("itemCount", this._itemsLeft.length); // get collections, if requested if(this._configOptions.getCollections) { @@ -760,8 +768,10 @@ Scholar.Translate.prototype._exportConfigureIO = function() { Scholar.Translate.prototype._exportGetItem = function() { if(this._itemsLeft.length != 0) { var returnItem = this._itemsLeft.shift(); + this._runHandler("itemDone", returnItem); return returnItem.toArray(); } + return false; } diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd index d3f8e7a463..c4dd43bdde 100644 --- a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd +++ b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd @@ -49,4 +49,6 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.properties b/chrome/chromeFiles/locale/en-US/scholar/scholar.properties index 146718e450..812482689c 100644 --- a/chrome/chromeFiles/locale/en-US/scholar/scholar.properties +++ b/chrome/chromeFiles/locale/en-US/scholar/scholar.properties @@ -86,4 +86,7 @@ ingester.scrapeErrorDescription = An error occurred while saving this item. Plea db.dbCorruptedNoBackup = The Scholar database appears to have become corrupted, and no automatic backup is available.\n\nA new database file has been created. The damaged file was saved in your Scholar directory. db.dbRestored = The Scholar database appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %1 at %2. The damaged file was saved in your Scholar directory. -db.dbRestoreFailed = The Scholar database appears to have become corrupted, and an attempt to restore from the last automatic backup failed.\n\nA new database file has been created. The damaged file was saved in your Scholar directory. \ No newline at end of file +db.dbRestoreFailed = The Scholar database appears to have become corrupted, and an attempt to restore from the last automatic backup failed.\n\nA new database file has been created. The damaged file was saved in your Scholar directory. + +fileInterface.itemsImported = Importing items... +fileInterface.itemsExported = Exporting items... \ No newline at end of file