Skip to content

Commit

Permalink
Updated menu to sort services into subtype labels
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtj committed Apr 1, 2009
1 parent 8b94fa3 commit 96fee0b
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 147 deletions.
48 changes: 21 additions & 27 deletions content/browser.xul
Expand Up @@ -81,17 +81,14 @@ var ServiceBrowser = {
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);
// newLabelDomain.setAttribute('flex',1);
newLabelRegistrationType.setAttribute('value',rService.queryElementAt(1,Components.interfaces.nsIVariant));
newLabelRegistrationType.setAttribute('crop','center');
newLabelRegistrationType.setAttribute('flex',1);
// 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);
// 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);
Expand Down Expand Up @@ -124,39 +121,36 @@ var ServiceBrowser = {
}
}
function bodgie(count) {
ServiceBrowser.renderServices()
if (count<3) {
setTimeout(function(){bodgie(count++);},300);
}
}
document.addEventListener("DOMContentLoaded", function(){bodgie(0);}, false);
document.addEventListener("DOMContentLoaded", function(){
setTimeout(ServiceBrowser.renderServices,0);
setTimeout(ServiceBrowser.renderServices,100);
setTimeout(ServiceBrowser.renderServices,200);
}, false);
]]>
</script>
<vbox 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);">
<listbox id="lbServices" 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="3"/>
<listcol flex="2"/>
<listcol flex="1"/>
<!--//
<splitter class="tree-splitter" />
<listcol flex="1" />
//-->
</listcols>
<listhead>
<listheader label="Service Name" />
<listheader label="Registration Type" />
<listheader label="Registration Domain" />
<listheader label="Service Name" flex="1"/>
<listheader label="Registration Type" flex="1"/>
<listheader label="Registration Domain" flex="1"/>
<!--//
<listheader label="Registration Subtypes" />
//-->
</listhead>
</listbox>
<groupbox id="gpServiceInfo" style="display: none;">
<vbox id="gpServiceInfo" style="display: none;">
<hbox align="center">
<label style="width: 11em;" value="Service Name"/>
<textbox flex="1" value="Service Name" id="tbServiceName" readonly="true" />
Expand Down Expand Up @@ -188,7 +182,7 @@ document.addEventListener("DOMContentLoaded", function(){bodgie(0);}, false);
<hbox>
<spacer flex="1" /><description>* Registration Subtypes only discovered when explictly sought</description>
</hbox>
</groupbox>
</vbox>
<hbox>
<spacer flex="1" />
<button oncommand="ServiceBrowser.renderServices()" label="Refresh Service List" />
Expand Down
2 changes: 1 addition & 1 deletion content/browserOverlay.xul
Expand Up @@ -11,7 +11,7 @@
</stringbundleset>

<menubar id="main-menubar">
<menu label="BonjourFoxy" insertbefore="tools-menu" onpopupshowing="menuAddServices();">
<menu label="BonjourFoxy" insertbefore="tools-menu" onpopupshowing="bonjourfoxy.menuAddServices();">
<menupopup id="bonjourMenuPopup">
<menuitem id="key_openEmptySidebar" label="&bonjourfoxyMenuSidebar.label;" observes="viewBonjourServices"
oncommand="bonjourfoxy.onMenuItemCommand(event);"/>
Expand Down
147 changes: 91 additions & 56 deletions content/list.xul
Expand Up @@ -4,8 +4,7 @@
<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
<?xml-stylesheet href="list.css"?>

<page onload="init();"
orient="vertical"
<page orient="vertical"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
style="background-color: transparent !important; -moz-appearance: none !important;">

Expand All @@ -25,7 +24,7 @@
<treecol id="title" flex="1" primary="true" hideheader="true"/>
</treecols>

<treechildren id="serviceListChildren" context="targetmenu" class="sidebar-placesTreechildren" />
<treechildren id="serviceListChildren" context="targetmenu" class="sidebar-placesTreechildren" flex="1" />
</tree>

<script>
Expand Down Expand Up @@ -57,21 +56,11 @@ function listEventHandler(event) {
}
var treeView = {
regTypes : {},
childData : {
"Web Sites": [["service1",1],["service2",2],["service3",3]],
"Wikis": [["service1",4],["service2",5],["service3",6]],
},
visibleData : [
["Web Sites", true, false, -1],
["Wikis", true, false, -1],
],
treeBox: null,
var treeView = {
childData : {},
visibleData : [],
selection: null,
get rowCount() { return this.visibleData.length; },
setTree: function(treeBox) { this.treeBox = treeBox; },
getCellText: function(idx, column) { return this.visibleData[idx][0]; },
Expand All @@ -81,7 +70,6 @@ var treeView = {
isSeparator: function(idx) { return false; },
isSorted: function() { return false; },
isEditable: function(idx, column) { return false; },
getParentIndex: function(idx) {
if (this.isContainer(idx)) return -1;
for (var t = idx - 1; t >= 0 ; t--) {
Expand Down Expand Up @@ -123,13 +111,10 @@ var treeView = {
item[2] = true;
var label = this.visibleData[idx][0];
// dump("label: "+label+"\n");
var toinsert = this.childData[label];
// dump("toinsert: "+toinsert+"\n");
if (toinsert) {
for (var i = 0; i < toinsert.length; i++) {
this.visibleData.splice(idx + i + 1, 0, [toinsert[i][0], false, false, toinsert[i][1]]);
// dump(idx + i + 1 + "\n");
}
this.treeBox.rowCountChanged(idx + 1, toinsert.length);
}
Expand All @@ -139,26 +124,56 @@ var treeView = {
getImageSrc: function(idx, column) {},
getProgressMode : function(idx,column) {},
getCellValue: function(idx, column) {
// dump("getCellValue ("+idx+","+column+")\n");
},
getCellValue: function(idx, column) {},
cycleHeader: function(col, elem) {},
selectionChanged: function() {},
cycleCell: function(idx, column) {},
performAction: function(action) {},
performActionOnCell: function(action, index, column) {},
getRowProperties: function(idx, column, prop) {},
getCellProperties: function(idx, column, prop) {},
getColumnProperties: function(column, element, prop) {},
};
function init() {
var dsdManager=Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
var storageService = Components.classes["@mozilla.org/storage/service;1"]
.getService(Components.interfaces.mozIStorageService);
var dbFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
getColumnProperties: function(column, element, prop) {}
}
var treeManager = {
visibleDataOpenMap: {},
regtypes: {},
startup: function() {
this.dsdManager = Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
this.prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.bonjourfoxy.");
this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefs.addObserver("", this, false);
this.observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
this.setRegtypeObservers();
this.updateServices();
document.getElementById("serviceList").view = treeView;
},
shutdown: function() {
this.removeRegtypeObservers();
this.prefs.removeObserver("", this);
},
removeRegtypeObservers: function() {
for (regtype in this.regtypes) {
this.observerService.removeObserver(this, "dsd_service_rmv:"+regtype, false);
this.observerService.removeObserver(this, "dsd_service_add:"+regtype, false);
}
},
observe: function(subject, topic, data) {
if (topic == "nsPref:changed") {
if (data=="hst") {
this.setRegtypeObservers();
this.updateServices();
setTimeout(this.updateServices, 1000); // repoll in case of slow
setTimeout(this.updateServices, 2000); // responses back
}
}
if (topic.match(/^dsd_service_/)) {
this.updateServices();
}
},
updateRegtypes: function() {
var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
var dbFile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
dbFile.append("bonjourfoxy.sqlite");
var DBConn = storageService.openDatabase(dbFile);
var sqlServices = DBConn.createStatement(" \
Expand All @@ -171,39 +186,44 @@ SELECT \
FROM Services \
LEFT OUTER JOIN ServiceSubtypes ON Services.id = ServiceSubtypes.s_id \
GROUP BY Services.regtype, Services.scheme, Services.label; ");
var newVisibleData = [];
var newRegTypes = {};
var newChildData = {};
var newRegtypes={};
while(sqlServices.executeStep()) {
var label = sqlServices.getUTF8String(0);
var regtype = sqlServices.getUTF8String(1);
try { var subtypePairs = sqlServices.getUTF8String(2).split(","); }
catch (e) { var subtypePairs = []; }
// dump ([label,regtype,subtypePairs,"\n"].join(' '));
newVisibleData.push([label, true, false, -1]);
if(!newRegTypes[regtype]) {
newRegTypes[regtype] = {
if(!newRegtypes[regtype]) {
newRegtypes[regtype] = {
label: label,
subtypes: {},
};
}
for (var i=0;i<subtypePairs.length;i++) {
// dump(subtypePairs[i]+"\n");
var subtypePairsA = subtypePairs[i].split(':');
var subtypeLabel = subtypePairsA[0];
var subtypeType = subtypePairsA[1];
// dump (["subtypeLabel",subtypeLabel,"subtypeType",subtypeType].join('\t')+"\n");
newVisibleData.push([subtypeLabel, true, false, -1]);
if(!newRegTypes[regtype]["subtypes"][subtypeType]) {
newRegTypes[regtype]["subtypes"][subtypeType] = subtypeLabel;
// dump("newRegTypes[regtype]['subtypes'][subtypeType]" + newRegTypes[regtype]["subtypes"][subtypeType] + "\n");
if(!newRegtypes[regtype]["subtypes"][subtypeType]) {
newRegtypes[regtype]["subtypes"][subtypeType] = subtypeLabel;
}
}
}
var dsdManager=Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
for (regType in newRegTypes) {
// dump(regType+"\n");
var discoveredServices = dsdManager.getDiscoveredServices(regType,null);
this.regtypes = newRegtypes;
},
addRegtypeObservers: function() {
for (regtype in this.regtypes) {
this.observerService.addObserver(this, "dsd_service_rmv:"+regtype, false);
this.observerService.addObserver(this, "dsd_service_add:"+regtype, false);
}
},
setRegtypeObservers: function() {
this.removeRegtypeObservers();
this.updateRegtypes();
this.addRegtypeObservers();
},
updateServices: function() {
var newChildData={}, newVisibleData=[];
for (regtype in this.regtypes) {
var discoveredServices = this.dsdManager.getDiscoveredServices(regtype,null);
for(var i=0;i<discoveredServices.length;i++)
{
var discoveredService = discoveredServices.queryElementAt(i,Components.interfaces.nsIArray);
Expand All @@ -213,38 +233,53 @@ GROUP BY Services.regtype, Services.scheme, Services.label; ");
catch (e) { var subtypes = null; }
if (subtypes) {
if (subtypes.indexOf(',')==-1) {
var category = newRegTypes[regType]["subtypes"][subtypes];
var category = this.regtypes[regtype]["subtypes"][subtypes];
if (!newChildData[category]) {
newChildData[category] = [];
}
newChildData[category].push([serviceName,serviceID]);
} else {
var subtypesA = subtypes.split(',');
for (var j=0;i<subtypesA.length;j++) {
var category = newRegTypes[regType]["subtypes"][subtypesA[j]];
var category = this.regtypes[regtype]["subtypes"][subtypesA[j]];
if (!newChildData[category]) {
newChildData[category] = [];
}
newChildData[category].push([serviceName,serviceID]);
}
}
} else {
var category = newRegTypes[regType]["label"];
var category = this.regtypes[regtype]["label"];
if (!newChildData[category]) {
newChildData[category] = [];
}
newChildData[category].push([serviceName,serviceID]);
}
}
}
treeView.childData = newChildData;
var visibleDataOpenMap = {};
for (i=0;i<treeView.visibleData.length;i++) {
this.visibleDataOpenMap[treeView.visibleData[i][0]] = treeView.visibleData[i][2];
}
for (visibleDataLabel in newChildData) {
newVisibleData.push([visibleDataLabel, true, false, -1]);
}
treeView.childData={};
treeView.visibleData = newVisibleData;
treeView.childData = newChildData;
for (var i=0;i<treeView.visibleData.length;i++) {
if (this.visibleDataOpenMap[treeView.visibleData[i][0]]) {
treeView.toggleOpenState(i);
}
}
}
};
window.addEventListener("load", function(e) {treeManager.startup();}, false);
window.addEventListener("unload", function(e) { treeManager.shutdown(); }, false);
document.getElementById("serviceList").view = treeView;
}
]]></script>

Expand Down

0 comments on commit 96fee0b

Please sign in to comment.