From 7b72d79d322d36f92a26459a98424628e7a4bd35 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 28 Apr 2009 02:35:08 +0000 Subject: [PATCH] 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 --- deluge/ui/gtkui/filtertreeview.py | 3 +-- deluge/ui/gtkui/gtkui.py | 2 ++ deluge/ui/gtkui/torrentview.py | 10 +++++++--- deluge/ui/tracker_icons.py | 7 +++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/deluge/ui/gtkui/filtertreeview.py b/deluge/ui/gtkui/filtertreeview.py index a0659c66d..1b77ce4a7 100644 --- a/deluge/ui/gtkui/filtertreeview.py +++ b/deluge/ui/gtkui/filtertreeview.py @@ -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")) diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 55c2df7c8..38a5effe5 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -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() diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index fed2f4141..dd7d30cb4 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -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): diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index d50e33467..e36ab85d2 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -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)