Removed mms:, Added "send clipboard", option to remember whether to send the QR code, selection correction for iframes

This commit is contained in:
amla70
2010-08-13 15:01:36 +00:00
parent 7f93c4f1b5
commit 0249229eb7
11 changed files with 134 additions and 73 deletions

View File

@@ -56,13 +56,12 @@ sendtophone.installToolbarButton = function()
//Toggle Protocol Prefrences onFlyout Menu Click //Toggle Protocol Prefrences onFlyout Menu Click
sendtophone.onToggleOption = function(menuitem) sendtophone.onToggleOption = function(menuitem)
{ {
var option = menuitem.getAttribute("option"); var option = menuitem.getAttribute("option");
var checked = menuitem.getAttribute("checked") == "true"; var checked = menuitem.getAttribute("checked") == "true";
this.prefs.setBoolPref("protocols."+option, checked ); this.prefs.setBoolPref("protocols."+option, checked );
if(!option.indexOf("sms")|!option.indexOf("mms")){ if (!option.indexOf("sms"))
this.prefs.setBoolPref("protocols."+option+"to", checked ); this.prefs.setBoolPref("protocols."+option+"to", checked );
}
} }
//Set MenuItem as checked based on preferences. //Set MenuItem as checked based on preferences.
@@ -83,9 +82,9 @@ sendtophone.onOptionsShowing= function(popup)
} }
sendtophone.showFirefoxContextMenu = function(event) { sendtophone.showFirefoxContextMenu = function(event) {
// show or hide the menuitem based on what the context menu is on // show or hide the menuitem based on what the context menu is on
// see http://kb.mozillazine.org/Adding_items_to_menus // see http://kb.mozillazine.org/Adding_items_to_menus
gContextMenu.showItem("context-sendtophone-link", gContextMenu.onLink); gContextMenu.showItem("context-sendtophone-link", gContextMenu.onLink);
gContextMenu.showItem("context-sendtophone-image", false); gContextMenu.showItem("context-sendtophone-image", false);
gContextMenu.showItem("context-sendtophone-qrimage", false); gContextMenu.showItem("context-sendtophone-qrimage", false);
@@ -95,7 +94,7 @@ sendtophone.showFirefoxContextMenu = function(event) {
if (data) if (data)
{ {
gContextMenu.showItem("context-sendtophone-qrimage", true); gContextMenu.showItem("context-sendtophone-qrimage", true);
var label = this.strings.getString("qrContextMenu"); var label = this.getString("qrContextMenu");
label = label.replace("%s", data.substring(0, 20) + "..." ); label = label.replace("%s", data.substring(0, 20) + "..." );
document.getElementById("context-sendtophone-qrimage").setAttribute("label", label); document.getElementById("context-sendtophone-qrimage").setAttribute("label", label);
} }
@@ -159,7 +158,7 @@ sendtophone.doDrop = function(event)
if (file instanceof Ci.nsIFile ) if (file instanceof Ci.nsIFile )
sendtophoneCore.sendFile(file); sendtophoneCore.sendFile(file);
else else
this.alert(this.strings.getString("InvalidFile")); this.alert(this.getString("InvalidFile"));
} }
break; break;
} }
@@ -171,10 +170,10 @@ sendtophone.pickFile = function(folder)
.createInstance(Ci.nsIFilePicker); .createInstance(Ci.nsIFilePicker);
if (folder) if (folder)
fp.init(window, this.strings.getString("SendFolderToPhone"), Ci.nsIFilePicker.modeGetFolder); fp.init(window, this.getString("SendFolderToPhone"), Ci.nsIFilePicker.modeGetFolder);
else else
{ {
fp.init(window, this.strings.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple); fp.init(window, this.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple);
fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterImages); fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterImages);
} }
@@ -191,4 +190,3 @@ sendtophone.pickFile = function(folder)
} }
} }

View File

@@ -11,6 +11,9 @@
<popupset id="mainPopupSet"> <popupset id="mainPopupSet">
<menupopup id="sendtophoneContextMenu" onpopupshowing="sendtophone.initPopup();"> <menupopup id="sendtophoneContextMenu" onpopupshowing="sendtophone.initPopup();">
<menuitem label="&sendtophoneContextSendClipboard.label;"
accesskey="&sendtophoneContextSendClipboard.accesskey;"
oncommand="sendtophone.sendClipboard()" id="sendtophoneContextMenuSendClipboard"/>
<menuitem label="&sendtophoneContextSendFile.label;" <menuitem label="&sendtophoneContextSendFile.label;"
accesskey="&sendtophoneContextSendFile.accesskey;" accesskey="&sendtophoneContextSendFile.accesskey;"
oncommand="sendtophone.pickFile(false)" id="sendtophoneContextMenuSendFiles"/> oncommand="sendtophone.pickFile(false)" id="sendtophoneContextMenuSendFiles"/>
@@ -20,7 +23,6 @@
<menu label="&sendtophoneProtocols.label;"> <menu label="&sendtophoneProtocols.label;">
<menupopup id="menu_Protocols" onpopupshowing="sendtophone.onOptionsShowing(this)"> <menupopup id="menu_Protocols" onpopupshowing="sendtophone.onOptionsShowing(this)">
<menuitem type="checkbox" id="marketcheck" label="market:" oncommand="sendtophone.onToggleOption(this)" option="market"/> <menuitem type="checkbox" id="marketcheck" label="market:" oncommand="sendtophone.onToggleOption(this)" option="market"/>
<menuitem type="checkbox" id="mmscheck" label="mms:" oncommand="sendtophone.onToggleOption(this)" option="mms"/>
<menuitem type="checkbox" id="smscheck" label="sms:" oncommand="sendtophone.onToggleOption(this)" option="sms"/> <menuitem type="checkbox" id="smscheck" label="sms:" oncommand="sendtophone.onToggleOption(this)" option="sms"/>
<menuitem type="checkbox" id="telcheck" label="tel:" oncommand="sendtophone.onToggleOption(this)" option="tel"/> <menuitem type="checkbox" id="telcheck" label="tel:" oncommand="sendtophone.onToggleOption(this)" option="tel"/>
</menupopup> </menupopup>

View File

@@ -11,8 +11,6 @@
<preference id="extensions.sendtophone.protocols.market" name="extensions.sendtophone.protocols.market" type="bool"/> <preference id="extensions.sendtophone.protocols.market" name="extensions.sendtophone.protocols.market" type="bool"/>
<preference id="extensions.sendtophone.protocols.sms" name="extensions.sendtophone.protocols.sms" type="bool"/> <preference id="extensions.sendtophone.protocols.sms" name="extensions.sendtophone.protocols.sms" type="bool"/>
<preference id="extensions.sendtophone.protocols.smsto" name="extensions.sendtophone.protocols.smsto" type="bool"/> <preference id="extensions.sendtophone.protocols.smsto" name="extensions.sendtophone.protocols.smsto" type="bool"/>
<preference id="extensions.sendtophone.protocols.mms" name="extensions.sendtophone.protocols.mms" type="bool"/>
<preference id="extensions.sendtophone.protocols.mmsto" name="extensions.sendtophone.protocols.mmsto" type="bool"/>
<preference id="extensions.sendtophone.protocols.tel" name="extensions.sendtophone.protocols.tel" type="bool"/> <preference id="extensions.sendtophone.protocols.tel" name="extensions.sendtophone.protocols.tel" type="bool"/>
</preferences> </preferences>
@@ -21,12 +19,7 @@
<checkbox preference="extensions.sendtophone.protocols.market" <checkbox preference="extensions.sendtophone.protocols.market"
label="market:" /> label="market:" />
<checkbox preference="extensions.sendtophone.protocols.mms"
label="mms:" oncommand="var o = document.getElementById('mmsto'); o.checked=this.checked; o.doCommand();" />
<checkbox id="mmsto" preference="extensions.sendtophone.protocols.mmsto"
label="mmsto:" style="display:none" />
<checkbox id="sms" preference="extensions.sendtophone.protocols.sms" <checkbox id="sms" preference="extensions.sendtophone.protocols.sms"
label="sms:" oncommand="var o = document.getElementById('smsto'); o.checked=this.checked; o.doCommand();" /> label="sms:" oncommand="var o = document.getElementById('smsto'); o.checked=this.checked; o.doCommand();" />
<checkbox id="smsto" preference="extensions.sendtophone.protocols.smsto" <checkbox id="smsto" preference="extensions.sendtophone.protocols.smsto"

View File

@@ -38,7 +38,12 @@ var sendtophone = {
.getBranch("extensions.sendtophone.") ; .getBranch("extensions.sendtophone.") ;
me.init(); me.init();
}, },
getString: function(name)
{
return this.strings.getString(name);
},
// Detect images of QR codes generated by the Google Charts API // Detect images of QR codes generated by the Google Charts API
detectQR: function( url ) detectQR: function( url )
@@ -56,8 +61,8 @@ var sendtophone = {
} }
} }
}, },
onMenuItemCommand: function(e, type) onMenuItemCommand: function(e, type)
{ {
var title, url, selection = ''; var title, url, selection = '';
switch(type) switch(type)
@@ -82,7 +87,7 @@ var sendtophone = {
//If the QR Image has no title text, give it one. //If the QR Image has no title text, give it one.
if (!title) if (!title)
title=this.strings.getString("qrTitle"); title=this.getString("qrTitle");
break; break;
case 'text': case 'text':
@@ -104,34 +109,47 @@ var sendtophone = {
case 'pageButton': case 'pageButton':
// Check if there's a single image with a QR code in the contents // Check if there's a single image with a QR code in the contents
var images = gBrowser.contentDocument.getElementsByTagName( "img" ); var images = gBrowser.contentDocument.getElementsByTagName( "img" );
var QRs = [];
for( var i=0; i<images.length; i++) // 0: search and prompt, 1: search and launch automatically, 2: don't search
var pref = this.prefs.getIntPref("SearchQR")
if (pref!=2)
{ {
var data = this.detectQR( images[i].src ); var QRs = [];
if (data) for( var i=0; i<images.length; i++)
QRs.push({data: data, img: images[i]});
}
if (QRs.length==1)
{
var data = QRs[0].data;
var url = data.substring(0, 80);
var question = this.strings.getString("ConfirmQR").replace("%s", url) ;
if (this.confirm( question ) )
{ {
title = QRs[0].img.title || QRs[0].img.alt; var data = this.detectQR( images[i].src );
if (data)
if (this.validURI(data)) QRs.push({data: data, img: images[i]});
url = data;
else
selection = data;
if (!title)
title=this.strings.getString("qrTitle");
// We got the data, break out of the select
break;
} }
} if (QRs.length==1)
{
var data = QRs[0].data;
if (pref == 0)
{
var question = this.getString("ConfirmQR").replace("%s", data.substring(0, 80)) ;
var answer = this.confirm( question );
pref = (answer.confirm ? 1 : 2 );
if (answer.remember)
this.prefs.setIntPref("SearchQR", pref);
}
if ( pref!=2 )
{
title = QRs[0].img.title || QRs[0].img.alt;
if (this.validURI(data))
url = data;
else
selection = data;
if (!title)
title=this.getString("qrTitle");
// We got the data, break out of the select
break;
}
}
} // pref != 2
// fall through // fall through
case 'page': case 'page':
@@ -151,7 +169,7 @@ var sendtophone = {
{ {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService); .getService(Ci.nsIPromptService);
promptService.alert(window, this.strings.getString("SendToPhoneTitle"), promptService.alert(window, this.getString("SendToPhoneTitle"),
text); text);
}, },
@@ -162,10 +180,12 @@ var sendtophone = {
.getService(Ci.nsIPromptService); .getService(Ci.nsIPromptService);
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#confirmEx // https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#confirmEx
var check = {value: true}; var check = {value: false};
var button = promptService.confirmEx(window, this.getString("SendToPhoneTitle"),
text, promptService.STD_YES_NO_BUTTONS, "", "", "", this.getString("RememberMyDecision"), check);
// confirmEx returns the pressed button, and Yes it's the first one. // confirmEx returns the pressed button, and Yes it's the first one.
return (0 == promptService.confirmEx(window, this.strings.getString("SendToPhoneTitle"), return ({confirm: (0 == button), remember: check.value});
text, promptService.STD_YES_NO_BUTTONS, "", "", "", null, check));
}, },
onToolbarButtonCommand: function(e) { onToolbarButtonCommand: function(e) {
@@ -175,10 +195,9 @@ var sendtophone = {
getInfo: function() { getInfo: function() {
var doc = gBrowser.contentDocument, var doc = gBrowser.contentDocument,
win = doc.defaultView; href = doc.location.href;
var href = doc.location.href;
// Is it the Google Maps page? // Is it the Google Maps page?
if (this.isMapsURL(href)) if (this.isMapsURL(href))
{ {
// Then try to send the current view: // Then try to send the current view:
@@ -187,11 +206,13 @@ var sendtophone = {
href = link.href; href = link.href;
} }
return { var focusedWindow = document.commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection().toString();
return {
"title": doc.title, "title": doc.title,
"url": href, "url": href,
"selection": win.getSelection().toString() "selection": selection
}; };
}, },
@@ -203,7 +224,7 @@ var sendtophone = {
validURI: function(uri) validURI: function(uri)
{ {
return (/^(https?|market|tel|sms(to)?|mms(to)?|mailto|ftp):/i).test( uri ); return (/^(https?|market|tel|sms(to)?|mailto|ftp):/i).test( uri );
}, },
initPopup: function() initPopup: function()
@@ -214,10 +235,55 @@ var sendtophone = {
document.getElementById("sendtophoneContextMenuSendFiles").hidden = true; document.getElementById("sendtophoneContextMenuSendFiles").hidden = true;
document.getElementById("sendtophoneContextMenuSendFolder").hidden = true; document.getElementById("sendtophoneContextMenuSendFolder").hidden = true;
} }
document.getElementById("sendtophoneContextMenuSendClipboard").disabled = !this.clipboardHasText();
// returning true will make the popup show // returning true will make the popup show
return true; return true;
}, },
clipboardHasText : function()
{
var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
if (!clip) return false;
if (!clip.hasDataMatchingFlavors(["text/unicode"], 1, clip.kGlobalClipboard))
return false;
return true;
},
sendClipboard : function()
{
// https://developer.mozilla.org/en/using_the_clipboard
// Access Clipboard
var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
if (!clip) return false;
if (!clip.hasDataMatchingFlavors(["text/unicode"], 1, clip.kGlobalClipboard))
return false;
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
if (!trans) return false;
trans.addDataFlavor("text/unicode");
// Get the data
clip.getData(trans, clip.kGlobalClipboard);
var str = new Object();
var strLength = new Object();
var pastetext;
trans.getTransferData("text/unicode", str, strLength);
// Convert to js string
if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
if (str) pastetext = str.data.substring(0, strLength.value / 2);
// Send it.
if (pastetext)
sendtophoneCore.send("Clipboard", "http://google.com", pastetext);
},
logout: function() logout: function()
{ {
sendtophoneCore.logout(); sendtophoneCore.logout();

View File

@@ -18,3 +18,5 @@
<!ENTITY sendtophoneContextSendFolder.accesskey "F"> <!ENTITY sendtophoneContextSendFolder.accesskey "F">
<!ENTITY sendtophoneContextQrImage.label "Send decoded QR Link to Android"> <!ENTITY sendtophoneContextQrImage.label "Send decoded QR Link to Android">
<!ENTITY sendtophoneContextQrImage.accesskey "Q"> <!ENTITY sendtophoneContextQrImage.accesskey "Q">
<!ENTITY sendtophoneContextSendClipboard.label "Send Clipboard">
<!ENTITY sendtophoneContextSendClipboard.accesskey "C">

View File

@@ -10,14 +10,13 @@ LogoutSuccessful=You are logged out
marketLink=Market Link marketLink=Market Link
smsLink=SMS Number smsLink=SMS Number
smstoLink=SMS Number smstoLink=SMS Number
mmsLink=MMS Number
mmstoLink=MMS Number
telLink=Telephone Number telLink=Telephone Number
InvalidFile=Not a valid file InvalidFile=Not a valid file
SendFileToPhone=Send files to your phone. SendFileToPhone=Send files to your phone.
SendFolderToPhone=Send a folder to your phone. SendFolderToPhone=Send a folder to your phone.
qrTitle=QR Image Link qrTitle=QR Image Link
ConfirmQR=A QR image has been detected\r\n"%s"\r\nDo you want to send that instead of the page? ConfirmQR=A QR image has been detected\r\n"%s"\r\nDo you want to send that instead of the page?
RememberMyDecision=Remember my decision
qrContextMenu=Send "%s" to Android qrContextMenu=Send "%s" to Android
FileUploadsDisabled=It's not possible to upload files to the phone. FileUploadsDisabled=It's not possible to upload files to the phone.
FileTooBig=The file is too big. FileTooBig=The file is too big.

View File

@@ -18,3 +18,5 @@
<!ENTITY sendtophoneContextSendFolder.accesskey "C"> <!ENTITY sendtophoneContextSendFolder.accesskey "C">
<!ENTITY sendtophoneContextQrImage.label "Enviar imagen QR a Android"> <!ENTITY sendtophoneContextQrImage.label "Enviar imagen QR a Android">
<!ENTITY sendtophoneContextQrImage.accesskey "Q"> <!ENTITY sendtophoneContextQrImage.accesskey "Q">
<!ENTITY sendtophoneContextSendClipboard.label "Enviar el portapapeles">
<!ENTITY sendtophoneContextSendClipboard.accesskey "C">

View File

@@ -10,14 +10,13 @@ LogoutSuccessful=Ha cerrado su sesión
marketLink=Market link marketLink=Market link
smsLink=Número SMS smsLink=Número SMS
smstoLink=Número SMS smstoLink=Número SMS
mmsLink=Número MMS
mmstoLink=Número MMS
telLink=Número de teléfono telLink=Número de teléfono
InvalidFile=No es un fichero válido. InvalidFile=No es un fichero válido.
SendFileToPhone=Envía ficheros al teléfono. SendFileToPhone=Envía ficheros al teléfono.
SendFolderToPhone=Envía una carpeta al teléfono. SendFolderToPhone=Envía una carpeta al teléfono.
qrTitle=Imagen QR qrTitle=Imagen QR
ConfirmQR=A QR image has been detected\r\n"%s"\r\nDo you want to send that instead of the page? ConfirmQR=Se ha detectado una imagen QR\r\n"%s"\r\n¿Quiere enviarlo en lugar de la página?
qrContextMenu=Send "%s" to Android RememberMyDecision=Recordar mi decisión
qrContextMenu=Enviar "%s" a Android
FileUploadsDisabled=No se pueden enviar ficheros al teléfono. FileUploadsDisabled=No se pueden enviar ficheros al teléfono.
FileTooBig=El fichero que quiere enviar es demasiado grande. FileTooBig=El fichero que quiere enviar es demasiado grande.

View File

@@ -4,12 +4,11 @@ pref("extensions.sendtophone.appUrl", "https://chrometophone.appspot.com");
pref("extensions.sendtophone.proxyUrl", "http://smallroomstudios.net/s2p.php?ml="); pref("extensions.sendtophone.proxyUrl", "http://smallroomstudios.net/s2p.php?ml=");
pref("extensions.sendtophone.fileServerUrl", "http://martinezdelizarrondo.com/sendtophone.php"); pref("extensions.sendtophone.fileServerUrl", "http://martinezdelizarrondo.com/sendtophone.php");
pref("extensions.sendtophone.fileUploadMaxKb", 50000); pref("extensions.sendtophone.fileUploadMaxKb", 50000);
pref("extensions.sendtophone.SearchQR", 0); // 0: search and prompt, 1: search and launch automatically, 2: don't search
pref("extensions.sendtophone.protocols.market", true); pref("extensions.sendtophone.protocols.market", true);
pref("extensions.sendtophone.protocols.sms", true); pref("extensions.sendtophone.protocols.sms", true);
pref("extensions.sendtophone.protocols.smsto", true); pref("extensions.sendtophone.protocols.smsto", true);
pref("extensions.sendtophone.protocols.mms", false); // conflicts with http://en.wikipedia.org/wiki/Microsoft_Media_Server
pref("extensions.sendtophone.protocols.mmsto", true);
pref("extensions.sendtophone.protocols.tel", true); pref("extensions.sendtophone.protocols.tel", true);
// https://developer.mozilla.org/en/Localizing_extension_descriptions // https://developer.mozilla.org/en/Localizing_extension_descriptions

View File

@@ -124,8 +124,6 @@ var sendToPhoneProtocols = {
market: SendToPhone_ProtocolWrapper( { scheme: "market", ID: "{751de080-95d1-11df-981c-0800200c9a66}" } ) , market: SendToPhone_ProtocolWrapper( { scheme: "market", ID: "{751de080-95d1-11df-981c-0800200c9a66}" } ) ,
sms: SendToPhone_ProtocolWrapper( { scheme: "sms", ID: "{345de080-95d1-11df-981c-0800200c9a66}" } ) , sms: SendToPhone_ProtocolWrapper( { scheme: "sms", ID: "{345de080-95d1-11df-981c-0800200c9a66}" } ) ,
smsto: SendToPhone_ProtocolWrapper( { scheme: "smsto", ID: "{854de080-95d1-11df-981c-0800200c9a66}" } ) , smsto: SendToPhone_ProtocolWrapper( { scheme: "smsto", ID: "{854de080-95d1-11df-981c-0800200c9a66}" } ) ,
mms: SendToPhone_ProtocolWrapper( { scheme: "mms", ID: "{457de080-95d1-11df-981c-0800200c9a66}" } ) ,
mmsto: SendToPhone_ProtocolWrapper( { scheme: "mmsto", ID: "{331de080-95d1-11df-981c-0800200c9a66}" } ) ,
tel: SendToPhone_ProtocolWrapper( { scheme: "tel", ID: "{948de080-95d1-11df-981c-0800200c9a66}" } ) tel: SendToPhone_ProtocolWrapper( { scheme: "tel", ID: "{948de080-95d1-11df-981c-0800200c9a66}" } )
}; };

View File

@@ -131,7 +131,10 @@ var sendtophoneCore = {
} }
else else
{ {
sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body); if (req.status==500 && body.substr(0,27) =="ERROR (Unable to send link)")
sendtophoneCore.openTab( "http://www.foxtophone.com/status500/" );
else
sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body);
} }
} }
}; };
@@ -171,7 +174,7 @@ var sendtophoneCore = {
return; return;
} }
if (!(/^(https?|market|tel|sms(to)?|mms(to)?|mailto|ftp):/i).test( url )) if (!(/^(https?|market|tel|sms(to)?|mailto|ftp):/i).test( url ))
{ {
this.alert(this.getString("InvalidScheme")); this.alert(this.getString("InvalidScheme"));
return; return;