Made TrackerIcons a component to prevent trying to get an icon multiple

times
Fixed showing the wrong tracker icon in the TorrentView when the icon 
could not be retrieved from the tracker
This commit is contained in:
Andrew Resch 2009-04-28 02:35:08 +00:00
parent 925dcd43b8
commit 7b72d79d32
4 changed files with 15 additions and 7 deletions

View File

@ -30,7 +30,6 @@ import pkg_resources
import deluge.component as component
import deluge.common
from deluge.ui.tracker_icons import TrackerIcons
from deluge.log import LOG as log
from deluge.ui.client import client
from deluge.configmanager import ConfigManager
@ -71,7 +70,7 @@ class FilterTreeView(component.Component):
self.scrolled = glade.get_widget("scrolledwindow_sidebar")
self.sidebar = component.get("SideBar")
self.config = ConfigManager("gtkui.conf")
self.tracker_icons = TrackerIcons()
self.tracker_icons = component.get("TrackerIcons")
self.label_view = gtk.TreeView()
self.sidebar.add_tab(self.label_view, "filters", _("Filters"))

View File

@ -50,6 +50,7 @@ from statusbar import StatusBar
from connectionmanager import ConnectionManager
from pluginmanager import PluginManager
from ipcinterface import IPCInterface
from deluge.ui.tracker_icons import TrackerIcons
from queuedtorrents import QueuedTorrents
from addtorrentdialog import AddTorrentDialog
@ -166,6 +167,7 @@ class GtkUI:
# We make sure that the UI components start once we get a core URI
client.set_disconnect_callback(self.__on_disconnect)
self.trackericons = TrackerIcons()
# Initialize various components of the gtkui
self.mainwindow = MainWindow()
self.menubar = MenuBar()

View File

@ -75,14 +75,18 @@ def cell_data_statusicon(column, cell, model, row, data):
pass
def cell_data_trackericon(column, cell, model, row, data):
icon_path = TrackerIcons().get(model[row][data])
icon_path = component.get("TrackerIcons").get(model[row][data])
if icon_path:
try:
icon = gtk.gdk.pixbuf_new_from_file_at_size(icon_path, 16, 16)
except Exception, e:
pass
if cell.get_property("pixbuf") != icon:
cell.set_property("pixbuf", icon)
else:
icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
icon.fill(0x00000000)
if cell.get_property("pixbuf") != icon:
cell.set_property("pixbuf", icon)
def cell_data_progress(column, cell, model, row, data):

View File

@ -31,6 +31,7 @@ from deluge.log import LOG as log
from deluge.common import get_pixmap
import os
import deluge.configmanager
import deluge.component as component
#some servers don't have their favicon at the expected location
RENAMES = {
@ -60,8 +61,9 @@ def fetch_url(url, valid_subtypes=None):
return data
class TrackerIcons(object):
class TrackerIcons(component.Component):
def __init__(self):
component.Component.__init__(self, "TrackerIcons")
#set image cache dir
self.image_dir = os.path.join(deluge.configmanager.get_config_dir(), "icons")
if not os.path.exists(self.image_dir):
@ -140,10 +142,11 @@ class TrackerIcons(object):
f = open(filename,"wb")
f.write(icon_data)
f.close()
self.images[tracker_host] = filename
else:
filename = None
self.images[tracker_host] = filename
if callback:
gobject.idle_add(callback, filename)