Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit b63d4ad

Browse files
committed
SMS button in Thunderbird address book
1 parent 09ebe3a commit b63d4ad

7 files changed

Lines changed: 123 additions & 33 deletions

File tree

content/sms.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*****************************************************************************
22
33
sipgate FFX - Firefox Extension for Mozilla Firefox Webbrowser
4-
Copyright (C) 2011 sipgate GmbH, Germany
5-
6-
The original code is hosted at
4+
Copyright (C) 2011 sipgate GmbH, Germany
5+
6+
The original code is hosted at
77
http://www.github.com/sipgate/sipgateffx
88
99
sipgateFFX is free software; you can redistribute it and/or modify
@@ -29,15 +29,15 @@ var sipgateffx_sms = {
2929

3030
onLoad: function() {
3131
sipgateffx_sms.promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
32-
33-
try {
34-
sipgateffx_sms.component = Components.classes['@api.sipgate.net/sipgateffx;1'].getService().wrappedJSObject;
35-
}
36-
catch (anError) {
37-
dump("ERROR: " + anError);
38-
return;
39-
}
40-
32+
33+
try {
34+
sipgateffx_sms.component = Components.classes['@api.sipgate.net/sipgateffx;1'].getService().wrappedJSObject;
35+
}
36+
catch (anError) {
37+
dump("ERROR: " + anError);
38+
return;
39+
}
40+
4141
sipgateffx_sms.strings = document.getElementById("sipgateffx_sms-strings");
4242

4343
if(sipgateffx_sms.component.tosList.indexOf('text') == -1) {
@@ -86,6 +86,7 @@ var sipgateffx_sms = {
8686
}
8787
if(typeof window.arguments[1] != "undefined") {
8888
document.getElementById("sipgate_sms_number").setAttribute('value', window.arguments[1]);
89+
document.getElementById("sipgate_sms_text").focus();
8990
}
9091
}
9192

content/thunderbirdABEditOverlay.js

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var sipgateffx_ABEditOverlay =
4848
this.strings = document.getElementById("sipgateffx-strings");
4949

5050
// Create UI
51+
// Call buttons
5152
const containerIDs = [
5253
"WorkPhoneContainer",
5354
"HomePhoneContainer",
@@ -59,18 +60,37 @@ var sipgateffx_ABEditOverlay =
5960
let container = document.getElementById(containerIDs[i]);
6061

6162
let button = document.createElement("button");
62-
button.id = "call_" + containerIDs[i];
63+
button.id = "sipgateFFX_call_" + containerIDs[i];
6364
button.classList.add("call");
6465
button.setAttribute("label", this.strings.getString("call.label"));
6566
button.setAttribute("tooltiptext", this.strings.getString("call.tooltip"));
66-
button.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClick(e); }, false);
67+
button.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClickCall(e); }, false);
6768
container.appendChild(button);
6869

70+
let smsButton = document.createElement("button");
71+
smsButton.id = "sipgateFFX_sms_" + containerIDs[i];
72+
smsButton.classList.add("sms");
73+
smsButton.setAttribute("label", this.strings.getString("sms.label"));
74+
smsButton.setAttribute("tooltiptext", this.strings.getString("sms.tooltip"));
75+
if (containerIDs[i] == "CellularNumberContainer") {
76+
smsButton.addEventListener("command", function(e) { sipgateffx_ABEditOverlay.onClickSMS(e); }, false);
77+
} else {
78+
smsButton.setAttribute("disabled", true);
79+
}
80+
container.appendChild(smsButton);
81+
6982
var textbox = container.getElementsByTagName("textbox").item(0);
7083
textbox.addEventListener("change", function(e) { this.onPhoneChanged(e); }, false);
7184
textbox.addEventListener("blur", function(e) { this.onPhoneChanged(e); }, false);
7285
this.onPhoneChanged({ target : textbox }); // update right now
7386
}
87+
88+
// SMS button
89+
{
90+
let containerID = "CellularNumberContainer";
91+
let container = document.getElementById(containerID);
92+
93+
}
7494
} catch (e) { alert(e); }
7595
},
7696

@@ -86,23 +106,25 @@ var sipgateffx_ABEditOverlay =
86106
var textbox = e.target;
87107
var button = textbox.parentNode.getElementsByClassName("call").item(0);
88108
if ( !button) throw "button not found";
89-
90109
button.setAttribute("disabled", !textbox.value);
110+
111+
var smsButton = textbox.parentNode.getElementsByClassName("sms").item(0);
112+
if ( !smsButton) throw "button not found";
113+
if (smsButton.id == "sipgateFFX_sms_CellularNumberContainer") {
114+
smsButton.setAttribute("disabled", !textbox.value);
115+
}
91116
},
92117

93118
/**
94119
* Called when the user clicks on the "Call" button inside the contact overview pane.
95-
* @param e {Event}
96-
*/
97-
onClick: function onClick(e)
120+
* @param e {Event}
121+
*/
122+
onClickCall: function onClickCall(e)
98123
{
99124
try {
100125
e.preventDefault();
101126
var button = e.target;
102-
var textbox = button.parentNode.getElementsByTagName("textbox").item(0);
103-
if ( !textbox) throw "textfield not found";
104-
105-
var number = textbox.value;
127+
var number = this._getNumber(button);
106128
button.setAttribute("status", "calling");
107129
var done = function() {
108130
button.removeAttribute("status");
@@ -119,7 +141,6 @@ var sipgateffx_ABEditOverlay =
119141
*/
120142
call : function call(number, successCallback, errorCallback)
121143
{
122-
number = this.component.niceNumber(number);
123144
if (this.component.getPref("extensions.sipgateffx.previewnumber", "bool")) {
124145
window.openDialog('chrome://sipgateffx/content/previewnumber.xul', 'sipgatePreviewnumber', 'chrome,centerscreen,resizable=no,titlebar=yes,alwaysRaised=yes', number);
125146
} else {
@@ -129,6 +150,28 @@ var sipgateffx_ABEditOverlay =
129150
});
130151
}
131152
},
153+
154+
/**
155+
* Called when the user clicks on the "SMS" button inside the contact overview pane.
156+
* @param e {Event}
157+
*/
158+
onClickSMS: function onClickSMS(e)
159+
{
160+
try {
161+
e.preventDefault();
162+
var number = "+" + this._getNumber(e.target);
163+
window.openDialog("chrome://sipgateffx/content/sms.xul", "sipgateSMS", "chrome,centerscreen,resizable=yes,titlebar=yes,alwaysRaised=yes", "", number);
164+
} catch (e) { alert(e); }
165+
},
166+
167+
_getNumber : function(button)
168+
{
169+
var textbox = button.parentNode.getElementsByTagName("textbox").item(0);
170+
if ( !textbox) throw "textfield not found";
171+
var number = textbox.value;
172+
return this.component.niceNumber(number); // without leading +
173+
},
174+
132175
};
133176

134177
window.addEventListener("load", function () { sipgateffx_ABEditOverlay.onLoad(); }, false);

content/thunderbirdABOverlay.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ var sipgateffx_ABOverlay =
7373
{
7474
try {
7575
// create UI
76+
77+
// Call button
7678
const descrIDs = [
7779
"cvPhWork",
7880
"cvPhHome",
79-
"cvPhFax",
81+
//"cvPhFax",
8082
"cvPhCellular",
8183
"cvPhPager",
8284
];
@@ -85,31 +87,42 @@ var sipgateffx_ABOverlay =
8587
for (let i = 0; i < descrIDs.length; i++) {
8688
let descr = document.getElementById(descrIDs[i]);
8789
let button = document.createElement("button");
88-
button.id = "call_" + descrIDs[i];
90+
button.id = "sipgateFFX_call_" + descrIDs[i];
8991
button.classList.add("call");
9092
button.setAttribute("label", this.strings.getString("call.label"));
9193
button.setAttribute("tooltiptext", this.strings.getString("call.tooltip"));
92-
button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClick(e); }, false);
94+
button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClickCall(e); }, false);
9395
descr.appendChild(button);
9496
// disabling not necessary, because TB collapses unused <descr>s.
9597
//let hasContent = descr.firstChild.nodeName == "#text";
9698
//button.setAttribute("disabled", !hasContent);
9799
}
100+
101+
// SMS button
102+
{
103+
let descrID = "cvPhCellular";
104+
let descr = document.getElementById(descrID);
105+
let button = document.createElement("button");
106+
button.id = "sipgateFFX_sms";
107+
button.classList.add("sms");
108+
button.setAttribute("label", this.strings.getString("sms.label"));
109+
button.setAttribute("tooltiptext", this.strings.getString("sms.tooltip"));
110+
button.addEventListener("command", function(e) { sipgateffx_ABOverlay.onClickSMS(e); }, false);
111+
descr.appendChild(button);
112+
}
98113
} catch (e) { alert(e); }
99114
},
100115

101116
/**
102117
* Called when the user clicks on the "Call" button inside the contact overview pane.
103118
* @param e {Event}
104119
*/
105-
onClick: function onClick(e)
120+
onClickCall: function onClickCall(e)
106121
{
107122
try {
108123
e.preventDefault();
109124
var button = e.target;
110-
var descr = button.parentNode.firstChild.textContent;
111-
// descr is e.g. "Home: 1343"
112-
var number = descr.substr(descr.indexOf(":") + 2);
125+
var number = this._getNumber(button);
113126
button.setAttribute("status", "calling");
114127
var done = function() {
115128
button.removeAttribute("status");
@@ -126,7 +139,6 @@ var sipgateffx_ABOverlay =
126139
*/
127140
call : function call(number, successCallback, errorCallback)
128141
{
129-
number = this.component.niceNumber(number);
130142
if (this.component.getPref("extensions.sipgateffx.previewnumber", "bool")) {
131143
window.openDialog('chrome://sipgateffx/content/previewnumber.xul', 'sipgatePreviewnumber', 'chrome,centerscreen,resizable=no,titlebar=yes,alwaysRaised=yes', number);
132144
} else {
@@ -136,6 +148,28 @@ var sipgateffx_ABOverlay =
136148
});
137149
}
138150
},
151+
152+
/**
153+
* Called when the user clicks on the "SMS" button inside the contact overview pane.
154+
* @param e {Event}
155+
*/
156+
onClickSMS: function onClickSMS(e)
157+
{
158+
try {
159+
e.preventDefault();
160+
var number = "+" + this._getNumber(e.target);
161+
window.openDialog("chrome://sipgateffx/content/sms.xul", "sipgateSMS", "chrome,centerscreen,resizable=yes,titlebar=yes,alwaysRaised=yes", "", number);
162+
} catch (e) { alert(e); }
163+
},
164+
165+
_getNumber : function(button)
166+
{
167+
var descr = button.parentNode.firstChild.textContent;
168+
// descr is e.g. "Home: 1343"
169+
var number = descr.substr(descr.indexOf(":") + 2);
170+
return this.component.niceNumber(number); // without leading +
171+
},
172+
139173
};
140174

141175
window.addEventListener("load", function () { sipgateffx_ABOverlay.onLoad(); }, false);

locale/de-DE/sipgateffx.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ notification.voice=%S neue Voicemails
3232
notification.x-call=%S neue Anrufe
3333
call.label=Anrufen
3434
call.tooltip=Anrufen
35+
sms.label=SMS
36+
sms.tooltip=SMS

locale/en-US/sipgateffx.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ notification.voice=%S new voicemails
3232
notification.x-call=%S new calls
3333
call.label=Call
3434
call.tooltip=Call
35+
sms.label=SMS
36+
sms.tooltip=Text with SMS

skin/icon_sms.gif

109 Bytes
Loading

skin/thunderbirdABOverlay.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ button.call
44
min-width: 20px;
55
}
66

7+
button.sms
8+
{
9+
list-style-image: url("chrome://sipgateffx/skin/icon_sms.gif");
10+
min-width: 20px;
11+
}
12+
713
/* remove label */
8-
button.call label.button-text {
14+
button.call label.button-text,
15+
button.sms label.button-text {
916
display: none;
1017
}
1118

12-
button.call[disabled=true]
19+
button.call[disabled=true],
20+
button.sms[disabled=true]
1321
{
1422
/* not using display:none or hidden=true, because these change the layout */
1523
visibility: hidden;

0 commit comments

Comments
 (0)