<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      eventCookie="@@@eventCookie@@@" dtvPlatform="@@@dtvPlatform@@@">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="resource:css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="resource:templates/osxdnd.js" />
<t:include filename="dynamic.js" />
<t:include filename="settings.js" />

    <t:execOnLoad><![CDATA[
import config
import prefs
import platformutils
import util

def getFreeSpace():
    bytes = platformutils.getAvailableBytesForMovies()
    return util.formatSizeForUser(bytes, "0B")

def getAvailableSpace():
    bytes = platformutils.getAvailableBytesForMovies()
    if config.get(prefs.PRESERVE_DISK_SPACE):
        preserved = config.get(prefs.PRESERVE_X_GB_FREE) * 1024 * 1024 * 1024
        bytes -= preserved
    return util.formatSizeForUser(bytes, "0B")


global searchFilter
searchFilter = lambda x: filters.matchingItems(x, None)

def makeDownloadCategoryView(cat):
    return views.downloadingItems.filterWithIndex(indexes.downloadsByCategory, cat)
allNormalDownloads = makeDownloadCategoryView('normal')
allExternalDownloads = views.items.filter(lambda x: x.getFeed().url == 'dtv:manualFeed' and x.isNonVideoFile())
allPendingDownloads = makeDownloadCategoryView('pending')

matchingNormalDLs = allNormalDownloads.filter(lambda x:searchFilter(x))
matchingExternalDLs = allExternalDownloads.filter(lambda x:searchFilter(x))
matchingPendingDLs = allPendingDownloads.filter(lambda x:searchFilter(x))

normalDownloads = matchingNormalDLs.sort(sorts.item)
externalDownloads = matchingExternalDLs.sort(sorts.item)
pendingDownloads = matchingPendingDLs.sort(sorts.item)

def updateSearchString(newSearch):
    global searchFilter
    if len(newSearch) == 0:
        searchFilter = lambda x: filters.matchingItems(x, None)
    else:
        searchFilter = lambda x: filters.matchingItems(x, newSearch)
    allNormalDownloads.recomputeFilter(matchingNormalDLs)
    allExternalDownloads.recomputeFilter(matchingExternalDLs)
    allPendingDownloads.recomputeFilter(matchingPendingDLs)
]]>
    </t:execOnLoad>
    <t:execOnUnload><![CDATA[
matchingNormalDLs.unlink()
allExternalDownloads.unlink()
matchingPendingDLs.unlink()
]]>
    </t:execOnUnload>
</head>

<body onkeydown="sendKeyToSearchBox(event);">

<!-- TITLE BAR ************************************************************ -->
<div id="main-titlebar">
	<div id="main-icon" class="noborder"><img src="resource:images/download-icon.png" /></div>
	<div id="main-titlebar-center">
            <h1 id="main-title" i18n:translate="">Downloading</h1>
            <div id="main-subtitle">
                <input id="search-box" type="search" placeholder="Search" onfocus="startEditSearch(this, null)" onblur="endEditSearch()" />
            </div>
	</div>
	<div t:updateForConfigChange="">
	<div id="main-upper-right">
		<div t:hideIf="getFreeSpace() == getAvailableSpace()">
			<p i18n:translate=""><span i18n:name="size" t:replace="getFreeSpace()" /> disk space free</p>
		</div>
		<p i18n:translate=""><span i18n:name="size" t:replace="getAvailableSpace()" /> available for downloads</p>
	</div>
	</div>
</div>
<!-- / TITLE BAR -->

<div id="main-container">

	<!-- VIDEOS ************************************************** -->
	<span t:repeatForView="normalDownloads">
                <span t:replaceMarkup="this.getItemXML(viewName, view)" />
	</span>
	<span t:repeatForView="pendingDownloads">
                <span t:replaceMarkup="this.getItemXML(viewName, view)" />
	</span>
	<!-- / VIDEOS -->
	<div t:hideIf="externalDownloads.len() == 0" 
		t:updateHideOnView="externalDownloads" class="main-channelbar">
		<span style="margin-left: 12px"> External Torrents</span>
		<a i18n:translate="" href="#" onclick="return eventURL('action:clearTorrents');" class="clear-completed-link" title="Clear Completed Torrents">Clear Completed Torrents</a>
        </div>
	<span t:repeatForView="externalDownloads">
            <span t:replaceMarkup="this.getItemXML(viewName, view)" />
	</span>
</div>

</body>
</html>
