<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE bindings SYSTEM "chrome://unplug/locale/unplug_result.dtd" >
<bindings xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

	
	<!--
		a result to display in searchpage.xul
		these are created as we find the search results
	-->	
	<binding id="unplug_result">




		<!--
		<handlers>
			<handler event="event-name" action="script"/>
		</handlers>
		-->


		<!-- example .doAlert("foo")
		https://developer.mozilla.org/en/XUL_Tutorial/Adding_Methods_to_XBL-defined_Elements
		on accessing annonymous nodes -->
		<implementation>
			<constructor>
				// pass
			</constructor>
			<method name="setOpeners">
				<parameter name="caps"/>
				<parameter name="res"/>
				<body>
					// if the result isn't completely described by a link, disable this option
					// as it only considers links at the moment
					if (!res.is_link()) {
						var open_btn = document.getAnonymousElementByAttribute(this, "id", "open");
						open_btn.disabled = true;
						return;
					}
					
					// set this to be the default menu item (the element)
					var default_open = document.getAnonymousElementByAttribute(this, "id", "open_tab");
					
					switch (caps['opener']) {
						case "tab":
							default_open = document.getAnonymousElementByAttribute(this, "id", "open_tab");
							break;
						case "new":
							default_open = document.getAnonymousElementByAttribute(this, "id", "open_new");
							break;
						case "over":
							default_open = document.getAnonymousElementByAttribute(this, "id", "open_over");
							break;
					}
					
					// set the button
					var open_btn = document.getAnonymousElementByAttribute(this, "id", "open")
					open_btn.setAttribute("oncommand", default_open.getAttribute("oncommand"));
					open_btn.setAttribute("tooltiptext", default_open.getAttribute("tooltiptext"));
					open_btn.setAttribute("class", default_open.getAttribute("class"));
					default_open.style.fontWeight = "bold";
				</body>
			</method>
			<method name="setDownloaders">
				<parameter name="caps"/>
				<parameter name="res"/>
				<body>
					// if the result isn't completely described by a link, disable this option
					// as it only considers links at the moment and only http/https links at that :(
					if (!res.is_link() || (res.protocol != "http" &amp;&amp; res.protocol != "https")) {
						var dl_btn = document.getAnonymousElementByAttribute(this, "id", "dl");
						dl_btn.disabled = true;
						return;
					}
						
					// set this to be the default menu item (the element)
					var default_dl = document.getAnonymousElementByAttribute(this, "id", "dl_saveas")
					
					if (caps['downthemall']) {
						var el = document.getAnonymousElementByAttribute(this, "id", "dl_dta")
						el.style.display = "block";
						default_dl = el;
					}
					
					// set the button
					var dl_btn = document.getAnonymousElementByAttribute(this, "id", "dl")
					dl_btn.setAttribute("oncommand", default_dl.getAttribute("oncommand"));
					dl_btn.setAttribute("tooltiptext", default_dl.getAttribute("tooltiptext"));
					dl_btn.setAttribute("class", default_dl.getAttribute("class"));
					default_dl.style.fontWeight = "bold";
				</body>
			</method>
		</implementation>





		<content>
			<xul:vbox flex="1" style="border: 1px black solid" xbl:inherits="tooltiptext=url">
				<xul:toolbar id="test-toolbar" flex="1">
					<xul:image xbl:inherits="src=thumbnail" id="thumbnail" />
					<xul:vbox flex="1" style="overflow: hidden;">
						<xul:hbox>
							<xul:label id="host" xbl:inherits="value=url_host" />
							<xul:label id="name" xbl:inherits="value=title" />
						</xul:hbox>
						<xul:hbox>
							<xul:label id="protocol" class="unplug-sub-heading" xbl:inherits="value=url_protocol" />
							<xul:label id="description" class="unplug-sub-heading" xbl:inherits="value=description" />
						</xul:hbox>
					</xul:vbox>
					<!--
						we want these to be drop-down buttons
						ie Open / Open in a new window
						and Download / Dowload with dTa / download with XXX
						and Play / Play in vlc / Play in totem / Look for media players
					-->
					<!-- aternative is type="menu" -->
					<xul:toolbarbutton
						id="open"
						accesskey="&open.accesskey;"
						label="&open.label;"
						type="menu-button"
						>
						<xul:menupopup>
							<xul:menuitem
								id="open_tab"
								accesskey="&open.tab.accesskey;"
								label="&open.tab.label;"
								tooltiptext="&open.tab.tooltip;"
								oncommand="UnPlug2SearchPage.open_new_tab(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuitem
								id="open_new"
								accesskey="&open.new.accesskey;"
								label="&open.new.label;"
								tooltiptext="&open.new.tooltip;"
								oncommand="UnPlug2SearchPage.open_new_window(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuitem
								id="open_over"
								accesskey="&open.over.accesskey;"
								label="&open.over.label;"
								tooltiptext="&open.over.tooltip;"
								oncommand="UnPlug2SearchPage.open_over_window(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuseparator />
							<xul:menuitem
								accesskey="&config.accesskey;"
								label="&config.label;"
								tooltiptext="&config.tooltip;"
								class="menuitem-iconic config"
								oncommand="UnPlug2SearchPage.configure(&quot;open&quot;); event.stopPropagation();"
								/>
						</xul:menupopup>
					</xul:toolbarbutton>
					<xul:toolbarbutton
						id="dl"
						accesskey="&dl.accesskey;"
						label="&dl.label;"
						type="menu-button"
						>
						<xul:menupopup>
							<xul:menuitem
								id="dl_saveas"
								accesskey="&dl.saveas.accesskey;"
								label="&dl.saveas.label;"
								tooltiptext="&dl.saveas.tooltip;"
								class="menuitem-iconic saveas"
								oncommand="UnPlug2SearchPage.download_saveas(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuitem
								id="dl_dta"
								style="display : none;"
								accesskey="&dl.dta.accesskey;"
								label="&dl.dta.label;"
								tooltiptext="&dl.dta.tooltip;"
								class="menuitem-iconic dta"
								oncommand="UnPlug2SearchPage.download_dta(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuseparator />
							<xul:menuitem
								accesskey="&config.accesskey;"
								label="&config.label;"
								tooltiptext="&config.tooltip;"
								class="menuitem-iconic config"
								oncommand="UnPlug2SearchPage.configure(&quot;dl&quot;); event.stopPropagation();"
								/>
						</xul:menupopup>
					</xul:toolbarbutton>
				</xul:toolbar>

			
				<!-- this is some sort of hidden drop-down box with more information -->
				<!--
				<xul:vbox>
					<xul:label xul:class="unplug-text" xbl:inherits="value=url"/>
				</xul:vbox>
				-->
			</xul:vbox>
		</content>
	</binding>

</bindings>

