<?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>
					// TODO
					return;
					
					// 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");
					var change_text = false;
					
					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;
						case "copyurl":
							default_open = document.getAnonymousElementByAttribute(this, "id", "copy_url");
							change_text = true;
							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"));
					if (change_text) {
						open_btn.setAttribute("label", default_open.getAttribute("label"));
					}
					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['flashgot']) {
						var el = document.getAnonymousElementByAttribute(this, "id", "dl_flashgot")
						el.style.display = "block";
						default_dl = el;
					}
					
					if (caps['downthemall']) {
						var el = document.getAnonymousElementByAttribute(this, "id", "dl_dta")
						el.style.display = "block";
						default_dl = el;
					}
					
					if (caps['downloader'] == "saveas") {
						default_dl = document.getAnonymousElementByAttribute(this, "id", "dl_saveas")
					}
					
					// 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>
			<method name="checkDuplicates">
				<parameter name="p"/>
				<body>
					var thiselem = this;
					var reslist = p.getElementsByTagName("unplug_result");
					for (var i=0; i &lt; reslist.length; i++) {
						var elem = reslist[i];
						if (elem === thiselem) {
							continue;
						}
						if (elem.getAttribute("url") == thiselem.getAttribute("url") &amp;&amp; elem.getAttribute("post") == thiselem.getAttribute("post")) {
							// this is a duplicate: remove thiselem
							return elem;
						}
					}
					return false;
				</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="copy_url"
						accesskey="&copyurl.accesskey;"
						label="&copyurl.label;"
						tooltiptext="&copyurl.tooltip;"
						class="menuitem-iconic copyurl"
						type="button"
						oncommand="UnPlug2SearchPage.copy_url(document.getBindingParent(this)); event.stopPropagation();"
						/>
					<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:menuitem
								id="dl_flashgot"
								style="display : none;"
								accesskey="&dl.flashgot.accesskey;"
								label="&dl.flashgot.label;"
								tooltiptext="&dl.flashgot.tooltip;"
								class="menuitem-iconic flashgot"
								oncommand="UnPlug2SearchPage.download_flashgot(document.getBindingParent(this)); event.stopPropagation();"
								/>
							<xul:menuseparator />
							<xul:menuitem
								id="open_tab"
								accesskey="&open.tab.accesskey;"
								label="&open.tab.label;"
								tooltiptext="&open.tab.tooltip;"
								class="menuitem-iconic opentab"
								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;"
								class="menuitem-iconic opennew"
								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;"
								class="menuitem-iconic openover"
								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;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>

