From 0980ae39378ecf2d85907c3ef4b44c39093bf9b8 Mon Sep 17 00:00:00 2001 From: Ben Bucksch Date: Sat, 2 Sep 2017 00:07:20 +0200 Subject: [PATCH 1/4] Replace usage of nsISupportsArray with nsIMutableArray for logger. Fixes TB 57 --- components/nsISipgateFFX.js | 4 ++-- components/nsISipgateFFXStorage.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/nsISipgateFFX.js b/components/nsISipgateFFX.js index b6c7ed7..1713061 100644 --- a/components/nsISipgateFFX.js +++ b/components/nsISipgateFFX.js @@ -122,7 +122,7 @@ function SipgateFFX() { "44": ["^00","^\\+"], "49": ["^00","^\\+"] }; - this.mLogBuffer = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + this.mLogBuffer = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray); this.mLogBufferMaxSize = 1000; this.getBalanceTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); this.getRecommendedIntervalsTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); @@ -1613,7 +1613,7 @@ SipgateFFX.prototype = { } } while (this.mLogBuffer.Count() > this.mLogBufferMaxSize) { - this.mLogBuffer.DeleteElementAt(0); + this.mLogBuffer.RemoveElementAt(0); } } catch (ex) { dump("Error in _log(): "+ex+"\n"); diff --git a/components/nsISipgateFFXStorage.js b/components/nsISipgateFFXStorage.js index e2ecfa9..41b4059 100644 --- a/components/nsISipgateFFXStorage.js +++ b/components/nsISipgateFFXStorage.js @@ -36,7 +36,7 @@ function SipgateFFXStorage() { this.blacklisted = []; - this.mLogBuffer = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + this.mLogBuffer = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray); this.mLogBufferMaxSize = 1000; } @@ -206,7 +206,7 @@ SipgateFFXStorage.prototype = { this.mLogBuffer.AppendElement(_CStringLogMessage); dump("[" + timestampFloat.toFixed(3) + "] " + logMessage + "\n"); while (this.mLogBuffer.Count() > this.mLogBufferMaxSize) { - this.mLogBuffer.DeleteElementAt(0); + this.mLogBuffer.RemoveElementAt(0); } } catch (ex) { dump("Error in _log(): "+ex+"\n"); From 09ebe3aa2f8aaeaca7d83930b188769fae18ae39 Mon Sep 17 00:00:00 2001 From: Ben Bucksch Date: Sat, 2 Sep 2017 00:48:25 +0200 Subject: [PATCH 2/4] Fix TB 75: Use new XMLHttpRequest() --- content/overlay.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/overlay.js b/content/overlay.js index 730a980..1840c0c 100644 --- a/content/overlay.js +++ b/content/overlay.js @@ -603,11 +603,11 @@ var sipgateffx = { var httpServer = sipgateffx.component.sipgateCredentials.HttpServer.replace(/^www/, 'secure'); var urlSessionLogin = protocol + httpServer + "/user/slogin.php"; - var oHttpRequest = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] - .getService(Components.interfaces.nsIJSXMLHttpRequest); + var oHttpRequest = new XMLHttpRequest(); oHttpRequest.open("POST",urlSessionLogin,false); oHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - oHttpRequest.send("username="+user+"&password="+pass); + oHttpRequest.send("username=" + encodeURIComponent(user) + + "&password=" + encodeURIComponent(pass)); return oHttpRequest.responseText.match(/\d\d\d/).toString(); }, From b63d4adc85ffda06602613930cd791f15fb3de22 Mon Sep 17 00:00:00 2001 From: Ben Bucksch Date: Sat, 2 Sep 2017 02:26:37 +0200 Subject: [PATCH 3/4] SMS button in Thunderbird address book --- content/sms.js | 25 ++++++----- content/thunderbirdABEditOverlay.js | 65 +++++++++++++++++++++++----- content/thunderbirdABOverlay.js | 50 +++++++++++++++++---- locale/de-DE/sipgateffx.properties | 2 + locale/en-US/sipgateffx.properties | 2 + skin/icon_sms.gif | Bin 0 -> 109 bytes skin/thunderbirdABOverlay.css | 12 ++++- 7 files changed, 123 insertions(+), 33 deletions(-) create mode 100644 skin/icon_sms.gif diff --git a/content/sms.js b/content/sms.js index 187c75c..bd4cd89 100644 --- a/content/sms.js +++ b/content/sms.js @@ -1,9 +1,9 @@ /***************************************************************************** sipgate FFX - Firefox Extension for Mozilla Firefox Webbrowser - Copyright (C) 2011 sipgate GmbH, Germany - - The original code is hosted at + Copyright (C) 2011 sipgate GmbH, Germany + + The original code is hosted at http://www.github.com/sipgate/sipgateffx sipgateFFX is free software; you can redistribute it and/or modify @@ -29,15 +29,15 @@ var sipgateffx_sms = { onLoad: function() { sipgateffx_sms.promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); - - try { - sipgateffx_sms.component = Components.classes['@api.sipgate.net/sipgateffx;1'].getService().wrappedJSObject; - } - catch (anError) { - dump("ERROR: " + anError); - return; - } - + + try { + sipgateffx_sms.component = Components.classes['@api.sipgate.net/sipgateffx;1'].getService().wrappedJSObject; + } + catch (anError) { + dump("ERROR: " + anError); + return; + } + sipgateffx_sms.strings = document.getElementById("sipgateffx_sms-strings"); if(sipgateffx_sms.component.tosList.indexOf('text') == -1) { @@ -86,6 +86,7 @@ var sipgateffx_sms = { } if(typeof window.arguments[1] != "undefined") { document.getElementById("sipgate_sms_number").setAttribute('value', window.arguments[1]); + document.getElementById("sipgate_sms_text").focus(); } } diff --git a/content/thunderbirdABEditOverlay.js b/content/thunderbirdABEditOverlay.js index 8f41162..ee4e3d5 100644 --- a/content/thunderbirdABEditOverlay.js +++ b/content/thunderbirdABEditOverlay.js @@ -48,6 +48,7 @@ var sipgateffx_ABEditOverlay = this.strings = document.getElementById("sipgateffx-strings"); // Create UI + // Call buttons const containerIDs = [ "WorkPhoneContainer", "HomePhoneContainer", @@ -59,18 +60,37 @@ var sipgateffx_ABEditOverlay = let container = document.getElementById(containerIDs[i]); let button = document.createElement("button"); - button.id = "call_" + containerIDs[i]; + button.id = "sipgateFFX_call_" + containerIDs[i]; button.classList.add("call"); button.setAttribute("label", this.strings.getString("call.label")); button.setAttribute("tooltiptext", this.strings.getString("call.tooltip")); - button.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClick(e); }, false); + button.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClickCall(e); }, false); container.appendChild(button); + let smsButton = document.createElement("button"); + smsButton.id = "sipgateFFX_sms_" + containerIDs[i]; + smsButton.classList.add("sms"); + smsButton.setAttribute("label", this.strings.getString("sms.label")); + smsButton.setAttribute("tooltiptext", this.strings.getString("sms.tooltip")); + if (containerIDs[i] == "CellularNumberContainer") { + smsButton.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClickSMS(e); }, false); + } else { + smsButton.setAttribute("disabled", true); + } + container.appendChild(smsButton); + var textbox = container.getElementsByTagName("textbox").item(0); textbox.addEventListener("change", function(e) { this.onPhoneChanged(e); }, false); textbox.addEventListener("blur", function(e) { this.onPhoneChanged(e); }, false); this.onPhoneChanged({ target : textbox }); // update right now } + + // SMS button + { + let containerID = "CellularNumberContainer"; + let container = document.getElementById(containerID); + + } } catch (e) { alert(e); } }, @@ -86,23 +106,25 @@ var sipgateffx_ABEditOverlay = var textbox = e.target; var button = textbox.parentNode.getElementsByClassName("call").item(0); if ( !button) throw "button not found"; - button.setAttribute("disabled", !textbox.value); + + var smsButton = textbox.parentNode.getElementsByClassName("sms").item(0); + if ( !smsButton) throw "button not found"; + if (smsButton.id == "sipgateFFX_sms_CellularNumberContainer") { + smsButton.setAttribute("disabled", !textbox.value); + } }, /** * Called when the user clicks on the "Call" button inside the contact overview pane. - * @param e {Event} - */ - onClick: function onClick(e) + * @param e {Event} + */ + onClickCall: function onClickCall(e) { try { e.preventDefault(); var button = e.target; - var textbox = button.parentNode.getElementsByTagName("textbox").item(0); - if ( !textbox) throw "textfield not found"; - - var number = textbox.value; + var number = this._getNumber(button); button.setAttribute("status", "calling"); var done = function() { button.removeAttribute("status"); @@ -119,7 +141,6 @@ var sipgateffx_ABEditOverlay = */ call : function call(number, successCallback, errorCallback) { - number = this.component.niceNumber(number); if (this.component.getPref("extensions.sipgateffx.previewnumber", "bool")) { window.openDialog('chrome://sipgateffx/content/previewnumber.xul', 'sipgatePreviewnumber', 'chrome,centerscreen,resizable=no,titlebar=yes,alwaysRaised=yes', number); } else { @@ -129,6 +150,28 @@ var sipgateffx_ABEditOverlay = }); } }, + + /** + * Called when the user clicks on the "SMS" button inside the contact overview pane. + * @param e {Event} + */ + onClickSMS: function onClickSMS(e) + { + try { + e.preventDefault(); + var number = "+" + this._getNumber(e.target); + window.openDialog("chrome://sipgateffx/content/sms.xul", "sipgateSMS", "chrome,centerscreen,resizable=yes,titlebar=yes,alwaysRaised=yes", "", number); + } catch (e) { alert(e); } + }, + + _getNumber : function(button) + { + var textbox = button.parentNode.getElementsByTagName("textbox").item(0); + if ( !textbox) throw "textfield not found"; + var number = textbox.value; + return this.component.niceNumber(number); // without leading + + }, + }; window.addEventListener("load", function () { sipgateffx_ABEditOverlay.onLoad(); }, false); diff --git a/content/thunderbirdABOverlay.js b/content/thunderbirdABOverlay.js index 0209693..da39272 100644 --- a/content/thunderbirdABOverlay.js +++ b/content/thunderbirdABOverlay.js @@ -73,10 +73,12 @@ var sipgateffx_ABOverlay = { try { // create UI + + // Call button const descrIDs = [ "cvPhWork", "cvPhHome", - "cvPhFax", + //"cvPhFax", "cvPhCellular", "cvPhPager", ]; @@ -85,16 +87,29 @@ var sipgateffx_ABOverlay = for (let i = 0; i < descrIDs.length; i++) { let descr = document.getElementById(descrIDs[i]); let button = document.createElement("button"); - button.id = "call_" + descrIDs[i]; + button.id = "sipgateFFX_call_" + descrIDs[i]; button.classList.add("call"); button.setAttribute("label", this.strings.getString("call.label")); button.setAttribute("tooltiptext", this.strings.getString("call.tooltip")); - button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClick(e); }, false); + button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClickCall(e); }, false); descr.appendChild(button); // disabling not necessary, because TB collapses unused s. //let hasContent = descr.firstChild.nodeName == "#text"; //button.setAttribute("disabled", !hasContent); } + + // SMS button + { + let descrID = "cvPhCellular"; + let descr = document.getElementById(descrID); + let button = document.createElement("button"); + button.id = "sipgateFFX_sms"; + button.classList.add("sms"); + button.setAttribute("label", this.strings.getString("sms.label")); + button.setAttribute("tooltiptext", this.strings.getString("sms.tooltip")); + button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClickSMS(e); }, false); + descr.appendChild(button); + } } catch (e) { alert(e); } }, @@ -102,14 +117,12 @@ var sipgateffx_ABOverlay = * Called when the user clicks on the "Call" button inside the contact overview pane. * @param e {Event} */ - onClick: function onClick(e) + onClickCall: function onClickCall(e) { try { e.preventDefault(); var button = e.target; - var descr = button.parentNode.firstChild.textContent; - // descr is e.g. "Home: 1343" - var number = descr.substr(descr.indexOf(":") + 2); + var number = this._getNumber(button); button.setAttribute("status", "calling"); var done = function() { button.removeAttribute("status"); @@ -126,7 +139,6 @@ var sipgateffx_ABOverlay = */ call : function call(number, successCallback, errorCallback) { - number = this.component.niceNumber(number); if (this.component.getPref("extensions.sipgateffx.previewnumber", "bool")) { window.openDialog('chrome://sipgateffx/content/previewnumber.xul', 'sipgatePreviewnumber', 'chrome,centerscreen,resizable=no,titlebar=yes,alwaysRaised=yes', number); } else { @@ -136,6 +148,28 @@ var sipgateffx_ABOverlay = }); } }, + + /** + * Called when the user clicks on the "SMS" button inside the contact overview pane. + * @param e {Event} + */ + onClickSMS: function onClickSMS(e) + { + try { + e.preventDefault(); + var number = "+" + this._getNumber(e.target); + window.openDialog("chrome://sipgateffx/content/sms.xul", "sipgateSMS", "chrome,centerscreen,resizable=yes,titlebar=yes,alwaysRaised=yes", "", number); + } catch (e) { alert(e); } + }, + + _getNumber : function(button) + { + var descr = button.parentNode.firstChild.textContent; + // descr is e.g. "Home: 1343" + var number = descr.substr(descr.indexOf(":") + 2); + return this.component.niceNumber(number); // without leading + + }, + }; window.addEventListener("load", function () { sipgateffx_ABOverlay.onLoad(); }, false); diff --git a/locale/de-DE/sipgateffx.properties b/locale/de-DE/sipgateffx.properties index 5ed3e0f..b2bad05 100644 --- a/locale/de-DE/sipgateffx.properties +++ b/locale/de-DE/sipgateffx.properties @@ -32,3 +32,5 @@ notification.voice=%S neue Voicemails notification.x-call=%S neue Anrufe call.label=Anrufen call.tooltip=Anrufen +sms.label=SMS +sms.tooltip=SMS diff --git a/locale/en-US/sipgateffx.properties b/locale/en-US/sipgateffx.properties index f580050..87edaa1 100644 --- a/locale/en-US/sipgateffx.properties +++ b/locale/en-US/sipgateffx.properties @@ -32,3 +32,5 @@ notification.voice=%S new voicemails notification.x-call=%S new calls call.label=Call call.tooltip=Call +sms.label=SMS +sms.tooltip=Text with SMS diff --git a/skin/icon_sms.gif b/skin/icon_sms.gif new file mode 100644 index 0000000000000000000000000000000000000000..cfc734d30df7fda745cc589e710af3d7032ef356 GIT binary patch literal 109 zcmZ?wbhEHb6krfwIK<2l8y&T9(UN=j@Bc>yia%Kxxfoa&bQpjDq?Uo%$Ya-?e*z~g zWhE@q53Kvgw7eo-OfSW9&f=^tm#9q}yDu7PJeyU(wr_#Kj>Qt%6PA3M$iQF?0Hhu; AP5=M^ literal 0 HcmV?d00001 diff --git a/skin/thunderbirdABOverlay.css b/skin/thunderbirdABOverlay.css index bba05e2..8e47f96 100644 --- a/skin/thunderbirdABOverlay.css +++ b/skin/thunderbirdABOverlay.css @@ -4,12 +4,20 @@ button.call min-width: 20px; } +button.sms +{ + list-style-image: url("chrome://sipgateffx/skin/icon_sms.gif"); + min-width: 20px; +} + /* remove label */ -button.call label.button-text { +button.call label.button-text, +button.sms label.button-text { display: none; } -button.call[disabled=true] +button.call[disabled=true], +button.sms[disabled=true] { /* not using display:none or hidden=true, because these change the layout */ visibility: hidden; From eb81308c31ba03a29900fcde5c1ffb57d3516b86 Mon Sep 17 00:00:00 2001 From: Ben Bucksch Date: Sat, 2 Sep 2017 02:46:53 +0200 Subject: [PATCH 4/4] Update maxVersion --- install.rdf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.rdf b/install.rdf index aa0c3aa..79a95a0 100644 --- a/install.rdf +++ b/install.rdf @@ -31,22 +31,22 @@ + em:minVersion="45.0" + em:maxVersion="59.*" /> + em:minVersion="45.0" + em:maxVersion="59.*" /> + em:minVersion="5.0" + em:maxVersion="10.*" />