From a849d524df493d8e054badbf26bc13a666e2fdcb Mon Sep 17 00:00:00 2001 From: amla70 Date: Wed, 13 Jul 2011 15:57:49 +0000 Subject: [PATCH] FoxToPhone. Compatibility with Seamonkey and folder uploads in Windows. Ready for public test. --- .../chrome/content/ff-overlay.js | 27 +++++++++++-------- .../chrome/content/options.xul | 12 ++++----- .../chrome/content/overlay.js | 8 +++--- .../chrome/content/uploads.js | 4 ++- .../chrome/locale/en-US/overlay.dtd | 5 ++++ .../chrome/locale/es/overlay.dtd | 5 ++++ .../modules/sendtophone.js | 2 +- .../modules/uploadsManager.js | 10 ++++--- 8 files changed, 45 insertions(+), 28 deletions(-) diff --git a/third_party/firefox_sendtophone/chrome/content/ff-overlay.js b/third_party/firefox_sendtophone/chrome/content/ff-overlay.js index 504e510..efb3d2c 100644 --- a/third_party/firefox_sendtophone/chrome/content/ff-overlay.js +++ b/third_party/firefox_sendtophone/chrome/content/ff-overlay.js @@ -162,7 +162,7 @@ sendtophone.doDrop = function(event) for (var i = 0; i < dt.mozItemCount; i++) { var file = dt.mozGetDataAt("application/x-moz-file", i); - if (file instanceof Ci.nsIFile ) + if (file instanceof Components.interfaces.nsIFile ) sendtophoneCore.sendFile(file); else this.alert(this.getString("InvalidFile")); @@ -173,26 +173,31 @@ sendtophone.doDrop = function(event) sendtophone.pickFile = function(folder) { - var fp = Cc["@mozilla.org/filepicker;1"] - .createInstance(Ci.nsIFilePicker); + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(Components.interfaces.nsIFilePicker); if (folder) - fp.init(window, this.getString("SendFolderToPhone"), Ci.nsIFilePicker.modeGetFolder); + fp.init(window, this.getString("SendFolderToPhone"), Components.interfaces.nsIFilePicker.modeGetFolder); else { - fp.init(window, this.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple); - fp.appendFilters( Ci.nsIFilePicker.filterAll ); + fp.init(window, this.getString("SendFileToPhone"), Components.interfaces.nsIFilePicker.modeOpenMultiple); + fp.appendFilters( Components.interfaces.nsIFilePicker.filterAll ); } var rv = fp.show(); - if (rv == Ci.nsIFilePicker.returnOK) + if (rv == Components.interfaces.nsIFilePicker.returnOK) { - var files = fp.files; - while (files.hasMoreElements()) + if (folder) + sendtophoneCore.sendFile( fp.file ); + else { - var file = files.getNext().QueryInterface(Ci.nsILocalFile); - sendtophoneCore.sendFile( file ); + var files = fp.files; + while (files.hasMoreElements()) + { + var file = files.getNext().QueryInterface(Components.interfaces.nsILocalFile); + sendtophoneCore.sendFile( file ); + } } } diff --git a/third_party/firefox_sendtophone/chrome/content/options.xul b/third_party/firefox_sendtophone/chrome/content/options.xul index efe6266..9e622c9 100644 --- a/third_party/firefox_sendtophone/chrome/content/options.xul +++ b/third_party/firefox_sendtophone/chrome/content/options.xul @@ -31,24 +31,22 @@ - + - diff --git a/third_party/firefox_sendtophone/chrome/content/overlay.js b/third_party/firefox_sendtophone/chrome/content/overlay.js index 039325a..4d94b3c 100644 --- a/third_party/firefox_sendtophone/chrome/content/overlay.js +++ b/third_party/firefox_sendtophone/chrome/content/overlay.js @@ -236,11 +236,9 @@ var sendtophone = { initPopup: function() { var fileServerUrl = this.prefs.getCharPref( "fileServerUrl" ); - if (!fileServerUrl) - { - document.getElementById("sendtophoneContextMenuSendFiles").hidden = true; - document.getElementById("sendtophoneContextMenuSendFolder").hidden = true; - } + document.getElementById("sendtophoneContextMenuSendFiles").hidden = !fileServerUrl; + document.getElementById("sendtophoneContextMenuSendFolder").hidden = !fileServerUrl; + document.getElementById("sendtophoneContextMenuSendClipboard").disabled = !this.clipboardHasText(); // returning true will make the popup show diff --git a/third_party/firefox_sendtophone/chrome/content/uploads.js b/third_party/firefox_sendtophone/chrome/content/uploads.js index e9a36e6..f403925 100644 --- a/third_party/firefox_sendtophone/chrome/content/uploads.js +++ b/third_party/firefox_sendtophone/chrome/content/uploads.js @@ -34,6 +34,8 @@ let gUploadListener = { // If no more pending uploads, close the tab. // Use a 0 ms timeout to avoid flicker while compress -> upload a folder + // The trick won't work if in order to upload the file itself we have to perform an extra request before + // (like creating a gallery in min.us) let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); checkTimer.initWithCallback( this.checkTimerEvent, 0, Ci.nsITimer.TYPE_ONE_SHOT ); }, @@ -42,7 +44,7 @@ let gUploadListener = { { notify: function(timer) { - if (!sendtophoneUploadsManager.isWindowNeeded()) + if (!sendtophoneUploadsManager.isWindowNeeded(true)) { if (gUploadListener.UploadsView.children.length==0) window.close(); diff --git a/third_party/firefox_sendtophone/chrome/locale/en-US/overlay.dtd b/third_party/firefox_sendtophone/chrome/locale/en-US/overlay.dtd index c71a9bd..078f7b5 100644 --- a/third_party/firefox_sendtophone/chrome/locale/en-US/overlay.dtd +++ b/third_party/firefox_sendtophone/chrome/locale/en-US/overlay.dtd @@ -22,3 +22,8 @@ + + + + + diff --git a/third_party/firefox_sendtophone/chrome/locale/es/overlay.dtd b/third_party/firefox_sendtophone/chrome/locale/es/overlay.dtd index 8466d1b..f4f9a7a 100644 --- a/third_party/firefox_sendtophone/chrome/locale/es/overlay.dtd +++ b/third_party/firefox_sendtophone/chrome/locale/es/overlay.dtd @@ -22,3 +22,8 @@ + + + + + diff --git a/third_party/firefox_sendtophone/modules/sendtophone.js b/third_party/firefox_sendtophone/modules/sendtophone.js index e7affaf..3c10fe6 100644 --- a/third_party/firefox_sendtophone/modules/sendtophone.js +++ b/third_party/firefox_sendtophone/modules/sendtophone.js @@ -393,7 +393,7 @@ var sendtophoneCore = { sendtophoneUploadsManager.finishedUpload( progressId ); // Send the zip and delete it afterwards - sendtophoneCore.sendFile(nsZip, function() { nsZip.remove(false); }); + sendtophoneCore.sendFile(nsZip, function() { nsZip.remove(false); if (callback) callback(); } ); } ); return; diff --git a/third_party/firefox_sendtophone/modules/uploadsManager.js b/third_party/firefox_sendtophone/modules/uploadsManager.js index c04d155..775a018 100644 --- a/third_party/firefox_sendtophone/modules/uploadsManager.js +++ b/third_party/firefox_sendtophone/modules/uploadsManager.js @@ -158,10 +158,14 @@ var sendtophoneUploadsManager = { // or there's some file that might take longer than 2 seconds. // If there's some file that we still don't know the speed // then consider it also as needed. - isWindowNeeded: function() + isWindowNeeded: function( alreadyOpen ) { for (let id in this.uploads) { + // If the progress window is already open and there's something pending then leave the window open + if (alreadyOpen) + return true; + let upload = this.uploads[id] ; // zipping folder: if takes so long to compress it, it will also take some time to upload it @@ -198,7 +202,7 @@ var showTimerEvent = { notify: function(timer) { - if (sendtophoneUploadsManager.isWindowNeeded()) + if (sendtophoneUploadsManager.isWindowNeeded(false)) { cancelShowTimer(); sendtophoneUploadsManager.showWindow(); @@ -260,7 +264,7 @@ function openAndReuseOneTabPerURL(url) { var recentWindow = wm.getMostRecentWindow("navigator:browser"); if (recentWindow) { // Use an existing browser window - recentWindow.delayedOpenTab(url, null, null, null, null); + recentWindow.getBrowser().loadOneTab( url, null, null, null, false, null ); } else { // No browser windows are open, so open a new one.