Skip to content

Commit

Permalink
many changes...
Browse files Browse the repository at this point in the history
* added first run routine - welcome page and sidebar displayed and toolbar button added automatically
* a few helpers added to dsdmanager to make handling service resolution easier
* dedicated component for handling notifications added
* custom handler ui added but not totally wired up
  • Loading branch information
andrewtj committed Mar 31, 2009
1 parent 6414ee3 commit 270a1ce
Show file tree
Hide file tree
Showing 19 changed files with 1,167 additions and 318 deletions.
189 changes: 103 additions & 86 deletions content/browser.xul
Expand Up @@ -5,62 +5,59 @@
<script>
<![CDATA[
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var ServiceBrowser = {
IDSDMANAGER: Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER),
known: [
'_http._tcp.',
],
removeChildren: function (el) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
},
resolveService: function(serviceName,regType,regDomain) {
resolveService: function(serviceId) {
var serviceInfo = ServiceBrowser.IDSDMANAGER.getServiceInfoFromId(serviceId);
var context = new Object();
context.count=0;
context.serviceName = unescape(serviceName);
context.regType = unescape(regType);
context.regDomain = unescape(regDomain);
ServiceBrowser.IDSDMANAGER.resolveService(context.serviceName,context.regType,context.regDomain,3);
context.serviceId = serviceId;
context.serviceName = serviceInfo.queryElementAt(0,Components.interfaces.nsIVariant);
context.regType = serviceInfo.queryElementAt(1,Components.interfaces.nsIVariant);
context.regSubTypes = serviceInfo.queryElementAt(3,Components.interfaces.nsIVariant);
context.regDomain = serviceInfo.queryElementAt(2,Components.interfaces.nsIVariant);
ServiceBrowser.IDSDMANAGER.resolveServiceFromId(serviceId);
ServiceBrowser.checkResolver(context);
},
checkResolver: function(context) {
var result = ServiceBrowser.IDSDMANAGER.resolveService(context.serviceName,context.regType,context.regDomain,3);
if (result.length>0) {
if (result.length==1) {
var errorArray = result.queryElementAt(0,Components.interfaces.nsIArray)
var error = errorArray.queryElementAt(0,Components.interfaces.nsIVariant);
var status = errorArray.queryElementAt(1,Components.interfaces.nsIVariant);
if (error==98) {
window.alert("Timed out resolving '" + context.serviceName + "'");
} else {
window.alert("Error " + error + " State: " + status);
}
} else {
document.getElementById('tbServiceName').setAttribute('value',context.serviceName);
document.getElementById('tbRegistrationType').setAttribute('value',context.regType);
document.getElementById('tbRegistrationDomain').setAttribute('value',context.regDomain);
document.getElementById('tbHost').setAttribute('value',result.queryElementAt(0,Components.interfaces.nsIVariant));
document.getElementById('tbPort').setAttribute('value',result.queryElementAt(1,Components.interfaces.nsIVariant));
var txtRecordsTxt = "None";
var txtRecords = result.queryElementAt(2,Components.interfaces.nsIArray);
for (var i=0;i<txtRecords.length;i++) {
var txtRecord = txtRecords.queryElementAt(i,Components.interfaces.nsIArray);
var txtRecordKey = txtRecord.queryElementAt(0,Components.interfaces.nsIVariant);
var txtRecordValue = txtRecord.queryElementAt(1,Components.interfaces.nsIVariant)
if (txtRecordKey!='') {
if (txtRecordsTxt=="None") {
txtRecordsTxt = "";
}
txtRecordsTxt += [txtRecordKey,'=',txtRecordValue,"\n"].join('');
}
var result = ServiceBrowser.IDSDMANAGER.resolveServiceFromId(context.serviceId);
var returnCode = result.queryElementAt(0,Components.interfaces.nsIVariant);
if (returnCode==-1)
{
window.alert(['Unable to resolve service - (',returnCode,')'].join(''));
}
else if (returnCode==1)
{
var returnPayload = result.queryElementAt(1,Components.interfaces.nsIArray)
document.getElementById('tbServiceName').setAttribute('value',context.serviceName);
document.getElementById('tbRegistrationType').setAttribute('value',context.regType);
document.getElementById('tbRegistrationSubTypes').setAttribute('value',context.regSubTypes);
document.getElementById('tbRegistrationDomain').setAttribute('value',context.regDomain);
document.getElementById('tbHost').setAttribute('value',returnPayload.queryElementAt(0,Components.interfaces.nsIVariant));
document.getElementById('tbPort').setAttribute('value',returnPayload.queryElementAt(1,Components.interfaces.nsIVariant));
var txtRecordsTxt = "None";
var txtRecords = returnPayload.queryElementAt(2,Components.interfaces.nsIArray);
for (var i=0;i<txtRecords.length;i++) {
var txtRecord = txtRecords.queryElementAt(i,Components.interfaces.nsIArray);
var txtRecordKey = txtRecord.queryElementAt(0,Components.interfaces.nsIVariant);
var txtRecordValue = txtRecord.queryElementAt(1,Components.interfaces.nsIVariant)
if (txtRecordKey!='') {
if (txtRecordsTxt=="None") {
txtRecordsTxt = "";
}
document.getElementById('tbTextRecords').setAttribute('value',txtRecordsTxt);
document.getElementById('gpServiceInfo').setAttribute('style','');
}
} else {
txtRecordsTxt += [txtRecordKey,'=',txtRecordValue,"\n"].join('');
}
}
document.getElementById('tbTextRecords').setAttribute('value',txtRecordsTxt);
document.getElementById('gpServiceInfo').setAttribute('style','');
}
else if (returnCode==0)
{
context.timer = setTimeout(function(){ServiceBrowser.checkResolver(context)}, 1000);
}
},
Expand All @@ -72,35 +69,35 @@ var ServiceBrowser = {
}
},
appendListItemsFromServices: function(lb,services,protocol) {
var showUnknown = true;
for (var i=0; i<services.length;i++) {
var service = services.queryElementAt(i,Components.interfaces.nsIArray);
var regtype = service.queryElementAt(2,Components.interfaces.nsIVariant) + ['._',protocol,'.'].join('');
var rServices = ServiceBrowser.IDSDMANAGER.getDiscoveredServices(regtype,null);
if (showUnknown||ServiceBrowser.known.indexOf(regtype)!=-1) {
for (var j=0; j<rServices.length;j++) {
var rService = rServices.queryElementAt(j,Components.interfaces.nsIArray);
var newListItem = document.createElement('listitem');
var newLabelDomain = document.createElement('label');
var newLabelRegistrationType = document.createElement('label');
var newLabelServiceName = document.createElement('label');
newLabelDomain.setAttribute('value',rService.queryElementAt(0,Components.interfaces.nsIVariant));
newLabelDomain.setAttribute('flex',1);
newLabelRegistrationType.setAttribute('value',rService.queryElementAt(1,Components.interfaces.nsIVariant));
newLabelRegistrationType.setAttribute('flex',1);
newLabelServiceName.setAttribute('value',rService.queryElementAt(2,Components.interfaces.nsIVariant));
newLabelServiceName.setAttribute('flex',1);
newListItem.appendChild(newLabelServiceName);
newListItem.appendChild(newLabelRegistrationType);
newListItem.appendChild(newLabelDomain);
newListItem.setAttribute('onclick','ServiceBrowser.resolveService("' + [
escape(rService.queryElementAt(2,Components.interfaces.nsIVariant)),
escape(rService.queryElementAt(1,Components.interfaces.nsIVariant)),
escape(rService.queryElementAt(0,Components.interfaces.nsIVariant))
].join('","')+'");');
newListItem.setAttribute('style','cursor: pointer;');
lb.appendChild(newListItem);
}
for (var j=0; j<rServices.length;j++) {
var rService = rServices.queryElementAt(j,Components.interfaces.nsIArray);
var newListItem = document.createElement('listitem');
var newLabelDomain = document.createElement('label');
var newLabelRegistrationType = document.createElement('label');
var newLabelServiceName = document.createElement('label');
var newLabelRegistrationSubTypes = document.createElement('label');
newLabelDomain.setAttribute('value',rService.queryElementAt(0,Components.interfaces.nsIVariant));
newLabelDomain.setAttribute('crop','center');
newLabelDomain.setAttribute('flex',1);
newLabelRegistrationType.setAttribute('value',rService.queryElementAt(1,Components.interfaces.nsIVariant));
newLabelRegistrationType.setAttribute('crop','center');
newLabelRegistrationType.setAttribute('flex',1);
newLabelServiceName.setAttribute('value',rService.queryElementAt(2,Components.interfaces.nsIVariant));
newLabelServiceName.setAttribute('crop','center');
newLabelServiceName.setAttribute('flex',1);
newLabelRegistrationSubTypes.setAttribute('value',rService.queryElementAt(4,Components.interfaces.nsIVariant));
newLabelRegistrationSubTypes.setAttribute('crop','center');
newLabelRegistrationSubTypes.setAttribute('flex',1);
newListItem.appendChild(newLabelServiceName);
newListItem.appendChild(newLabelRegistrationType);
newListItem.appendChild(newLabelDomain);
// newListItem.appendChild(newLabelRegistrationSubTypes);
newListItem.setAttribute('value',rService.queryElementAt(3,Components.interfaces.nsIVariant));
lb.appendChild(newListItem);
}
}
},
Expand All @@ -119,58 +116,78 @@ var ServiceBrowser = {
} else {
var tcpservices = ServiceBrowser.IDSDMANAGER.getDiscoveredServices("_tcp.",null);
var udpservices = ServiceBrowser.IDSDMANAGER.getDiscoveredServices("_udp.",null);
}
ServiceBrowser.discoverServicesFromServices(tcpservices,'tcp');
}
ServiceBrowser.discoverServicesFromServices(tcpservices,'tcp');
ServiceBrowser.discoverServicesFromServices(udpservices,'udp');
ServiceBrowser.appendListItemsFromServices(lbServices,tcpservices,'tcp');
ServiceBrowser.appendListItemsFromServices(lbServices,udpservices,'udp');
}
}
document.addEventListener("DOMContentLoaded", ServiceBrowser.renderServices, false);
function bodgie(count) {
ServiceBrowser.renderServices()
if (count<3) {
setTimeout(function(){bodgie(count++);},300);
}
}
document.addEventListener("DOMContentLoaded", function(){bodgie(0);}, false);
]]>
</script>
<vbox flex="1" style="padding: 0; margin: 0;">
<listbox id="lbServices" rows="5" flex="1" style="padding: 0; margin: 0;">
<listbox id="lbServices" rows="5" flex="1" style="padding: 0; margin: 0;" onselect="ServiceBrowser.resolveService(event.explicitOriginalTarget.value);">
<listcols>
<listcol flex="1" />
<splitter class="tree-splitter" />
<listcol flex="1" />
<splitter class="tree-splitter" />
<listcol flex="1" />
<listcol flex="1" />
<splitter class="tree-splitter" />
<listcol flex="1" />
<splitter class="tree-splitter" />
<listcol flex="1" />
<!--//
<splitter class="tree-splitter" />
<listcol flex="1" />
//-->
</listcols>
<listhead>
<listheader label="Service Name" />
<listheader label="Registration Type" />
<listheader label="Domain" />
<listheader label="Service Name" />
<listheader label="Registration Type" />
<listheader label="Registration Domain" />
<!--//
<listheader label="Registration Subtypes" />
//-->
</listhead>
</listbox>
<groupbox id="gpServiceInfo" style="display: none;">
<hbox align="center">
<label style="width: 10em;" value="Service Name"/>
<label style="width: 11em;" value="Service Name"/>
<textbox flex="1" value="Service Name" id="tbServiceName" readonly="true" />
</hbox>
<hbox align="center">
<label style="width: 10em;" value="Registration Type"/>
<label style="width: 11em;" value="Registration Type"/>
<textbox flex="1" value="Registration Type" id="tbRegistrationType" readonly="true" />
</hbox>
<hbox align="center">
<label style="width: 10em;" value="Registration Domain"/>
<label style="width: 11em;" value="Registration Subtypes*"/>
<textbox flex="1" value="Registration Type" id="tbRegistrationSubTypes" readonly="true" />
</hbox>
<hbox align="center">
<label style="width: 11em;" value="Registration Domain"/>
<textbox flex="1" value="Registration Domain" id="tbRegistrationDomain" readonly="true" />
</hbox>
<hbox align="center">
<label style="width: 10em;" value="Host"/>
<label style="width: 11em;" value="Host"/>
<textbox flex="1" value="Host" id="tbHost" readonly="true" />
</hbox>
<hbox align="center">
<label style="width: 10em;" value="Port"/>
<label style="width: 11em;" value="Port"/>
<textbox flex="1" value="Port" id="tbPort" readonly="true" />
</hbox>
<hbox>
<label style="width: 10em; padding-top: 5px;" value="Text Records"/>
<label style="width: 11em; padding-top: 5px;" value="Text Records"/>
<textbox flex="1" multiline="true" id="tbTextRecords" readonly="true" rows="7" />
</hbox>
<hbox>
<spacer flex="1" /><description>* Registration Subtypes only discovered when explictly sought</description>
</hbox>
</groupbox>
<hbox>
<spacer flex="1" />
Expand Down
1 change: 1 addition & 0 deletions content/browserOverlay.xul
Expand Up @@ -5,6 +5,7 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="overlay.js"/>
<script src="shared.js"/>
<script src="firstrun.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="bonjourfoxy-strings" src="chrome://bonjourfoxy/locale/bonjourfoxy.properties"/>
</stringbundleset>
Expand Down
102 changes: 102 additions & 0 deletions content/firstrun.html
@@ -0,0 +1,102 @@
<html>
<head>
<style>
html{
-x-system-font:message-box;
background-color:-moz-dialog;
color:-moz-dialogtext;
font-family:-moz-use-system-font;
font-size:-moz-use-system-font;
font-size-adjust:-moz-use-system-font;
font-stretch:-moz-use-system-font;
font-style:-moz-use-system-font;
font-variant:-moz-use-system-font;
font-weight:-moz-use-system-font;
line-height:-moz-use-system-font;
padding-left:2em;
padding-right:2em;
}
body{
-moz-border-radius-bottomleft:10px;
-moz-border-radius-bottomright:10px;
-moz-border-radius-topleft:10px;
-moz-border-radius-topright:10px;
background-color:-moz-field;
border:1px solid threedshadow;
color:-moz-fieldtext;
margin:1em auto 1em auto;
width:31em;
padding:1.5em 2em 2em 2em;
font-family: Helvetica Neue;
font-size: 1.1em;
}
h5 {
margin-top: -1.1em;
}
h1,h3 {
margin-bottom: 0;
}
a {
color: #00c;
}
li.note {
list-style: none;
font-size: 0.7em;
margin-top: 0.5em;
margin-left: -12px;
}
li.note:before {
content: "(";
}
li.note:after {
content: ")";
}
ul,p {
margin-top: 0.5em;
}
.beta {
color: #c00;
}
</style>
<body>
<h1>BonjourFoxy <span class='beta'>Beta</span> 0.4</h2>
<div class='note'>
<h3>Status Bar Icon</h3>
<ul style='clear: left;'>
<li style='width: 50%; float: right; list-style-image: url("chrome://bonjourfoxy/content/status_color.png");'/> Services found</li>
<li style='width: 50%; list-style-image: url("chrome://bonjourfoxy/content/status_bw.png");'/> No services found</li>
<li class='note'>bottom right-hand corner when first installed</li>
</ul>
</div>
<div class='note'>
<h3>Toolbar Button</h3>
<ul>
<li style='margin-left: -20px; list-style: none;'><div style='background: url("chrome://bonjourfoxy/skin/toolbar-button.png"); clip: rect( 0px 40px 16px 24px); height: 22px; width: 36px; float: left;'/></div>&nbsp;Display or hide sidebar</li>
<li class='note'>to the right of 'Home' or far-right when first installed</li>
</ul>
</div>
<div class='note'>
<h3>Menu Items</h3>
<ul>
<li>Browser - browse all Bonjour Services</li>
<li>Sidebar - display or hide sidebar</li>
<li>Services Discovered</li>
<li class='note'>named BonjourFoxy, just before Tools</li>
</ul>
</div>
<div class='note'>
<h3>Extension Preferences</h3>
<ul>
<li>Turn on or off service discovery notifications</li>
<li>Turn on or off status bar icon</li>
<li>Set default link target - current page, new tab or new window</li>
<li>Configure service handlers</li>
<li class='note'>via Tools &rarr; Add-ons &rarr; BonjourFoxy &rarr; Preferences</li>
</ul>
</div>
<div class='note'>
<h3>Feedback</h3>
<p>How'd I do? Comment on the <a href="http://andrew.tj.id.au/projects/bonjourfoxy/">project page</a> or <a href="mailto:andrew@tj.id.au?subject=BonjourFoxy">email me</a></p>
</div>
</body>
</html>

0 comments on commit 270a1ce

Please sign in to comment.