webui : use TrackerIcons class

This commit is contained in:
Martijn Voncken 2008-10-22 16:08:53 +00:00
parent aadb6edec1
commit 984c4f8203
5 changed files with 26 additions and 8 deletions

View File

@ -11,12 +11,13 @@ def del_old():
os.remove(filename)
def test_get():
del_old()
#del_old()
trackericons = TrackerIcons()
print trackericons.images
print trackericons.get("unknown2")
print trackericons.get("google.com")
print trackericons.get("legaltorrents.com")
time.sleep(1.0)
time.sleep(5.0)
print trackericons.get("legaltorrents.com")
def callback1(value):

View File

@ -90,9 +90,9 @@ class TrackerIcons(object):
def get_async(self, tracker_host, callback):
if tracker_host in self.images:
if callback:
callback(self.images[tracker_host])
callback(self.images[tracker_host])
else:
self.images[tracker_host] = None
threading.Thread(target=self. _fetch_icon_thread,
args=(tracker_host, callback)).start()
@ -103,7 +103,6 @@ class TrackerIcons(object):
if tracker_host in self.images:
return self.images[tracker_host]
else:
self.images[tracker_host] = None
self.get_async(tracker_host, None)
return None

View File

@ -51,6 +51,7 @@ import os
from deluge import component
from deluge.ui.client import sclient as proxy
from deluge.configmanager import ConfigManager
from deluge.tracker_icons import TrackerIcons
page_manager = component.get("PageManager")
config = ConfigManager("webui06.conf")
@ -447,6 +448,23 @@ class pixmaps:
print content
route("/pixmaps/(.*)", pixmaps)
class tracker_icon:
tracker_icons = TrackerIcons()
def GET(self, name):
filename = self.tracker_icons.get(name)
if filename:
log.debug("file-name=%s" % name)
web.header("Cache-Control" , "public, must-revalidate, max-age=86400")
web.header("Content-Type", "image/x-icon")
data = open(filename, "rb").read()
print data
else:
log.debug("not found:%s" % name)
web.header("Content-Type", "image/x-icon")
route("/tracker/icon/(.*)", tracker_icon)
class close:
"close open window"
@deco.deluge_page

View File

@ -22,7 +22,7 @@ $for cat in filter_items.keys():
$if cat == "state":
<img src="/pixmaps/$(value.lower())"></img>
$if cat == "tracker_host":
<img src="http://$value/favicon.ico" width="16" height="16"></img>
<img src="$base/tracker/icon/$value" width="16" height="16"></img>
$if not value:
$if cat == "label":
$_("No Label") ($count)</a>

View File

@ -43,9 +43,9 @@ $for cat in filter_items.keys():
>
<a href="$self_url(filter_cat=cat, filter_value=value, sort=get('sort'), order=get('order')) ">
$if cat == "state":
<img src="/pixmaps/$(value.lower())"></img>
<img src="$base/pixmaps/$(value.lower())"></img>
$if cat == "tracker_host":
<img src="http://$value/favicon.ico" width="16" height="16"></img>
<img src="$base/tracker/icon/$value" width="16" height="16"></img>
$if not value:
$if cat == "label":
$_("No Label") ($count)</a>