Skip to content

Commit

Permalink
Preferences wired up. Alerts on service discovery added. select poll …
Browse files Browse the repository at this point in the history
…interval reduced. More...
  • Loading branch information
andrewtj committed Mar 9, 2009
1 parent 5d5a4b4 commit c74df0f
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 117 deletions.
13 changes: 11 additions & 2 deletions content/firefoxOverlay.xul
Expand Up @@ -10,11 +10,11 @@
</stringbundleset>

<menubar id="main-menubar">
<menu label="Bonjour" insertbefore="tools-menu" onpopupshowing="menuAddServices();">
<menu label="BonjourFoxy" insertbefore="tools-menu" onpopupshowing="menuAddServices();">
<menupopup id="bonjourMenuPopup">
<menuitem id="key_openEmptySidebar" label="&bonjourfoxyMenuSidebar.label;" observes="viewBonjourServices"
oncommand="bonjourfoxy.onMenuItemCommand(event);"/>
<menuitem label="Preferences" disabled="true" />
<menuitem label="Preferences" oncommand="bonjourfoxy.openPreferences(event);"/>
<menuseparator/>
</menupopup>
</menu>
Expand Down Expand Up @@ -43,4 +43,13 @@
oncommand="toggleSidebar('viewBonjourServices');" />
</broadcasterset>

<statusbar id="status-bar">
<statusbarpanel id="bonjourStatusIcon"
class="statusbarpanel-iconic"
image="chrome://bonjourfoxy/content/transparent.gif"
context="bonjourSBMenuPopup"
onclick="bonjourfoxy.onMenuItemCommand(event);"
/>
</statusbar>

</overlay>
89 changes: 47 additions & 42 deletions content/list.js
@@ -1,83 +1,88 @@
function contextListEventHandler(event) {
var node = document.popupNode;
var pNode = node.parentNode;
/*
dump("context\n");
dump(node.value + "\n");
dump(pNode.onclick + "\n");
dump(event.target.value + "\n");
dump(event.bubbles + "\n");
dump(event.type + "\n");
dump(event.shiftKey + "\n");
dump(event.button + "\n");
*/
pNode.onclick(event);
}

function listEventHandler(event,target,serviceName,regType,regDomain) {
// dump("list\n");
// event.shiftKey
// event.type == "click"
if (event.type=="click") {
if (event.button=="0") {
if (event.shiftKey) {
openLink("window",serviceName,regType,regDomain);
} else {
openLink("default",serviceName,regType,regDomain);
}
} else if (event.button=="1") {
openLink("tab",serviceName,regType,regDomain);
}
} if (event.type=="command") {
openLink(event.target.value,serviceName,regType,regDomain);
}
}

function updateServiceList() {
var obj=Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
obj.discoverServices("_http._tcp.",null);

var serviceList = document.getElementById('serviceList');
if (serviceList.hasChildNodes()) {
if (serviceList.hasChildNodes())
{
while (serviceList.firstChild) {
serviceList.removeChild(serviceList.firstChild);
}
}

var discoveredServices = obj.getDiscoveredServices("_http._tcp.",null);

for(var i=0;i<discoveredServices.length;i++) {
for(var i=0;i<discoveredServices.length;i++)
{
var discoveredService = discoveredServices.queryElementAt(i,Components.interfaces.nsIArray);
var serviceName = discoveredService.queryElementAt(2,Components.interfaces.nsIVariant);


var richlistEl = document.createElement('richlistitem');
var descriptionEl = document.createElement('description');
descriptionEl.setAttribute('value', serviceName);
descriptionEl.setAttribute('crop','center');
descriptionEl.setAttribute('flex','1');
richlistEl.appendChild(descriptionEl);
richlistEl.setAttribute('onclick','openLink("content","' + escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant)) + '");');

richlistEl.setAttribute('onclick','listEventHandler(event,"default","' + [
escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)),
escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)),
escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant))
].join('","') + '");');
serviceList.appendChild(richlistEl);

// listitem.setAttribute('label', foo);
// listitem.setAttribute('onclick','openLink("content","' + escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant)) + '");');
// listitem.setAttribute('label',obj[i].replyName);
// listitem.setAttribute('onclick','window._content.location="' + obj[i].url + '"');
// serviceList.appendChild(listitem);
}
}

/*
function onTreeClicked(event){
var tree = document.getElementById("serviceListT");
var tbo = tree.treeBoxObject;
try {
// get the row, col and child element at the point
var row = { }, col = { }, child = { };
tbo.getCellAt(event.clientX, event.clientY, row, col, child);
var cellValue = tree.view.getCellValue(row.value, col.value);
window._content.location=cellValue;
}
catch (e) {
return;
}
}
*/

function dsdObserver()
{
this.register();
}
dsdObserver.prototype = {
observe: function(subject, topic, data) {
var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
aConsoleService.logStringMessage("dsdObserver: " + topic + " " + data);
updateServiceList();
},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "dsd_add_http._tcp.", false);
observerService.addObserver(this, "dsd_rmv_http._tcp.", false);
observerService.addObserver(this, "dsd_service_add__http._tcp.", false);
observerService.addObserver(this, "dsd_service_rmv__http._tcp.", false);
},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "dsd_add_http._tcp.", false);
observerService.removeObserver(this, "dsd_rmv_http._tcp.", false);
observerService.removeObserver(this, "dsd_service_add__http._tcp.", false);
observerService.removeObserver(this, "dsd_service_rmv__http._tcp.", false);
}
}

var dsdObserverInstance = new dsdObserver();
var dsdObserverInstance = new dsdObserver();
10 changes: 8 additions & 2 deletions content/list.xul
Expand Up @@ -14,8 +14,14 @@
src="chrome://bonjourfoxy/content/list.js" />
<script type="application/x-javascript"
src="chrome://bonjourfoxy/content/shared.js" />

<richlistbox id="serviceList" flex="1" style="background-color: HighlightText; padding:0;margin:0;">

<menupopup id="targetmenu" oncommand="contextListEventHandler(event);">
<menuitem label="Open" value="current"/>
<menuitem label="Open in New Tab" value="tab"/>
<menuitem label="Open in New Window" value="window"/>
</menupopup>

<richlistbox id="serviceList" flex="1" context="targetmenu" style="background-color: HighlightText; padding:0;margin:0;">
</richlistbox>

</page>
40 changes: 40 additions & 0 deletions content/options.xul
@@ -0,0 +1,40 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<prefwindow id="BrowserPreferences"
title="BonjourFoxy Options"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
buttons="accept">

<prefpane id="bonjourfoxy-prefpane" label="BonjourFoxy Preferences">
<preferences>
<preference id="pref_alerts" name="extensions.bonjourfoxy.alerts" instantApply="true" type="bool"/>
<preference id="pref_target" name="extensions.bonjourfoxy.target" instantApply="true" type="string"/>
</preferences>

<html:h2 flex="1" style="text-align: center;">BonjourFoxy Preferences</html:h2>
<groupbox flex="1">
<vbox flex="1">
<hbox>
<label control="alerts" value="Discovery notifications:"/>
<spacer flex="1"/>
<checkbox preference="pref_alerts" id="alerts"/>
</hbox>
<hbox flex="1">
<label control="target" value="Open links in:"/>
<spacer flex="1"/>
<menulist preference="pref_target" id="target">
<menupopup>
<menuitem label="Current Page" value="current"/>
<menuitem label="New Tab" value="tab"/>
<menuitem label="New Window" value="window" />
</menupopup>
</menulist>
</hbox>
</vbox>
</groupbox>
<hbox style='padding-bottom: 30px;'><spacer flex="1"/><description>Settings apply instantly</description><spacer flex="1"/></hbox>
</prefpane>

</prefwindow>
75 changes: 71 additions & 4 deletions content/overlay.js
Expand Up @@ -3,16 +3,39 @@ var bonjourfoxy = {
// initialization code
this.initialized = true;
this.strings = document.getElementById("bonjourfoxy-strings");
var obj=Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
obj.discoverServices("_http._tcp.",null);
},
onMenuItemCommand: function(e) {
toggleSidebar("viewBonjourServices");
},
onToolbarButtonCommand: function(e) {
// just reuse the function above
bonjourfoxy.onMenuItemCommand(e);
},
openPreferences: function(e) {
var paneID = "bonjourfoxy-prefpane";
var features = "chrome,titlebar,toolbar,centerscreen,true,dialog=no"
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Browser:Preferences");
if (win) {
win.focus();
if (paneID) {
var pane = win.document.getElementById(paneID);
win.document.documentElement.showPane(pane);
}
} else {
openDialog("chrome://bonjourfoxy/content/options.xul",
"Preferences", features, paneID);
}
}
};

function menuEventHandler(element) {
window.alert(element.getAttribute('value'));
};

function menuAddServices() {
var menu = document.getElementById("bonjourMenuPopup");
while (menu.childNodes.length>3) {
Expand All @@ -35,13 +58,57 @@ function menuAddServices() {
var foo = discoveredService.queryElementAt(2,Components.interfaces.nsIVariant);
var item = document.createElement('menuitem');
item.setAttribute('label', foo);
item.setAttribute('oncommand','openLink("content","' + escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant)) + '");');
// listitem.setAttribute('onclick','openLink("content","' + escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)) + '","' + escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant)) + '");');
// listitem.setAttribute('label',obj[i].replyName);
// listitem.setAttribute('onclick','window._content.location="' + obj[i].url + '"');
item.setAttribute('oncommand','openLink("default","' + [
escape(discoveredService.queryElementAt(2,Components.interfaces.nsIVariant)),
escape(discoveredService.queryElementAt(1,Components.interfaces.nsIVariant)),
escape(discoveredService.queryElementAt(0,Components.interfaces.nsIVariant))
].join('","')+'");');
menu.appendChild(item);
}
}
}

window.addEventListener("load", function(e) { bonjourfoxy.onLoad(e); }, false);

function dsdOverlayObserver()
{
this.register();
}
dsdOverlayObserver.prototype = {
observe: function(subject, topic, data) {
var obj=Components.classes["@andrew.tj.id.au/dsdmanager;1"].getService(Components.interfaces.IDSDMANAGER);
if (obj.getDiscoveredServicesCount("_http._tcp.",null)>0)
{
document.getElementById('bonjourStatusIcon').style.display = "";
document.getElementById('bonjourStatusIcon').setAttribute("image","chrome://bonjourfoxy/content/status_color.png");
} else {
document.getElementById('bonjourStatusIcon').style.display = "none";
document.getElementById('bonjourStatusIcon').setAttribute("image","chrome://bonjourfoxy/content/transparent.gif");
}
if (topic=="dsd_service_add__http._tcp.")
{
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.bonjourfoxy.");
if (prefs.getBoolPref("alerts"))
{
var alertsService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
alertsService.showAlertNotification(null,"Service Discovered",data,null,null,null);
}
}
},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "dsd_service_add__http._tcp.", false);
observerService.addObserver(this, "dsd_service_rmv__http._tcp.", false);
},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "dsd_service_add__http._tcp.", false);
observerService.removeObserver(this, "dsd_service_rmv__http._tcp.", false);
}
}

var dsdOverlayObserverInstance = new dsdOverlayObserver();
21 changes: 19 additions & 2 deletions content/shared.js
Expand Up @@ -22,15 +22,32 @@ function checkResolver(context) {
finalurl += txtRecord.queryElementAt(1,Components.interfaces.nsIVariant)
}
}
window._content.location=finalurl;
switch(context.target)
{
case "tab":
var win = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('navigator:browser');
win.openUILinkIn(finalurl, 'tab');
break;
case "window":
var win = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('navigator:browser');
win.openUILinkIn(finalurl, 'window');
break;
default:
window._content.location=finalurl;
}
}
} else {
context.timer = setTimeout(function(){checkResolver(context)}, 1000);
}
}

function openLink(target,serviceName,regType,regDomain) {
// window.alert(target + ' : ' + serviceName + ' : ' + regType + ' : ' + regDomain);
if (target=="default") {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("extensions.bonjourfoxy.");
target = prefs.getCharPref("target");
}
var context = new Object();
context.target = target;
context.count=0;
Expand Down
Binary file added content/status_color.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/transparent.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions defaults/preferences/defaults.js
@@ -1 +1,3 @@
pref("extensions.dsd.logToErrorConsole", false);
pref("extensions.bonjourfoxy.alerts", true);
pref("extensions.bonjourfoxy.target", "current");
8 changes: 4 additions & 4 deletions locale/en-US/bonjourfoxy.dtd
@@ -1,5 +1,5 @@
<!ENTITY bonjourfoxy.title "Bonjour">
<!ENTITY bonjourfoxy.label "Bonjour">
<!ENTITY bonjourfoxy.title "BonjourFoxy">
<!ENTITY bonjourfoxy.label "BonjourFoxy">
<!ENTITY bonjourfoxyMenuSidebar.label "Display Sidebar">
<!ENTITY bonjourfoxyToolbar.label "Bonjour Button">
<!ENTITY bonjourfoxyToolbar.tooltip "Toggle Bonjour Sidebar">
<!ENTITY bonjourfoxyToolbar.label "BonjourFoxy Button">
<!ENTITY bonjourfoxyToolbar.tooltip "Toggle BonjourFoxy Sidebar">
2 changes: 1 addition & 1 deletion locale/en-US/bonjourfoxy.properties
@@ -1 +1 @@
title="Bonjour Foxy"
title="BonjourFoxy"
2 changes: 1 addition & 1 deletion src/browse/dsdbrowse-impl.cpp
Expand Up @@ -293,7 +293,7 @@ nsresult CDSDBROWSE::StartTimer()
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (!mTimer)
return NS_ERROR_FAILURE;
return mTimer->InitWithFuncCallback(this->TimeoutHandler, this, 1000,
return mTimer->InitWithFuncCallback(this->TimeoutHandler, this, 100,
nsITimer::TYPE_REPEATING_SLACK);
}

Expand Down
2 changes: 1 addition & 1 deletion src/enumerate/dsdenumerate-impl.cpp
Expand Up @@ -279,7 +279,7 @@ nsresult CDSDENUMERATE::StartTimer()
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (!mTimer)
return NS_ERROR_FAILURE;
return mTimer->InitWithFuncCallback(this->TimeoutHandler, this, 1000,
return mTimer->InitWithFuncCallback(this->TimeoutHandler, this, 100,
nsITimer::TYPE_REPEATING_SLACK);
}

Expand Down

0 comments on commit c74df0f

Please sign in to comment.