Ticket #1885: 10fc58779baa0e5baa94f3a697a9ffa355763f61.patch

File 10fc58779baa0e5baa94f3a697a9ffa355763f61.patch, 5.0 KB (added by Calum, 12 years ago)
  • deluge/ui/gtkui/filtertreeview.py

    From 10fc58779baa0e5baa94f3a697a9ffa355763f61 Mon Sep 17 00:00:00 2001
    From: bendikro <bendikro@gmail.com>
    Date: Mon, 18 Feb 2013 01:18:54 +0100
    Subject: [PATCH] Fixed bug in tracker icons for torrentview.
    
    ---
     deluge/ui/gtkui/filtertreeview.py |    2 +-
     deluge/ui/gtkui/torrentview.py    |   65 ++++++++++++++++++++++---------------
     deluge/ui/tracker_icons.py        |   18 ++++++++++
     3 files changed, 57 insertions(+), 28 deletions(-)
    
    diff --git a/deluge/ui/gtkui/filtertreeview.py b/deluge/ui/gtkui/filtertreeview.py
    index 51cde26..8c29c39 100644
    a b def on_get_icon(icon):  
    247247            self.filters[(cat, value)] = row
    248248
    249249            if cat == "tracker_host" and value not in ("All", "Error") and value:
    250                 d = self.tracker_icons.get(value)
     250                d = self.tracker_icons.fetch(value)
    251251                d.addCallback(on_get_icon)
    252252
    253253        self.treestore.set_value(row, FILTER_COLUMN, True)
  • deluge/ui/gtkui/torrentview.py

    diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py
    index cdfbcc8..a15ea7e 100644
    a b def cell_data_statusicon(column, cell, model, row, data):  
    109109    except KeyError:
    110110        pass
    111111
    112 def cell_data_trackericon(column, cell, model, row, data):
    113     def on_get_icon(icon):
    114         def create_blank_pixbuf():
    115             i = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
    116             i.fill(0x00000000)
    117             return i
    118 
    119         if icon:
    120             pixbuf = icon.get_cached_icon()
    121             if not pixbuf:
    122                 try:
    123                     pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16)
    124                 except gobject.GError, e:
    125                     # Failed to load the pixbuf (Bad image file), so set a blank pixbuf
    126                     pixbuf = create_blank_pixbuf()
    127                 finally:
    128                     icon.set_cached_icon(pixbuf)
    129         else:
    130             pixbuf = create_blank_pixbuf()
     112def create_blank_pixbuf():
     113    i = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
     114    i.fill(0x00000000)
     115    return i
     116
     117def set_icon(icon, cell):
     118    if icon:
     119        pixbuf = icon.get_cached_icon()
     120        if pixbuf is None:
     121            try:
     122                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16)
     123            except gobject.GError, e:
     124                # Failed to load the pixbuf (Bad image file), so set a blank pixbuf
     125                pixbuf = create_blank_pixbuf()
     126            finally:
     127                icon.set_cached_icon(pixbuf)
     128    else:
     129        pixbuf = create_blank_pixbuf()
     130
     131    #Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
     132    with warnings.catch_warnings():
     133        warnings.simplefilter("ignore")
     134        cell.set_property("pixbuf", pixbuf)
    131135
    132         #Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
    133         with warnings.catch_warnings():
    134             warnings.simplefilter("ignore")
    135             if cell.get_property("pixbuf") != pixbuf:
    136                 cell.set_property("pixbuf", pixbuf)
     136last_host = None
    137137
     138def cell_data_trackericon(column, cell, model, row, data):
     139    global last_host
    138140    host = model[row][data]
    139141    if host:
    140         d = component.get("TrackerIcons").get(host)
    141         d.addCallback(on_get_icon)
     142        if last_host == host:
     143            return
     144        else:
     145            last_host = host
     146
     147        if not component.get("TrackerIcons").has(host):
     148            # Set blank icon while waiting for the icon to be loaded
     149            set_icon(None, cell)
     150            component.get("TrackerIcons").fetch(host)
     151        else:
     152            set_icon(component.get("TrackerIcons").get(host), cell)
    142153    else:
    143         on_get_icon(None)
     154        set_icon(None, cell)
    144155
    145156def cell_data_progress(column, cell, model, row, data):
    146157    """Display progress bar with text"""
  • deluge/ui/tracker_icons.py

    diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py
    index ffc099c..8fa58fc 100644
    a b def __init__(self, icon_dir=None, no_icon=None):  
    178178        self.pending = {}
    179179        self.redirects = {}
    180180
     181    def has(self, host):
     182        return host in self.icons
     183
    181184    def get(self, host):
    182185        """
    183186        Returns a TrackerIcon for the given tracker's host
    184187
    185188        :param host: the host to obtain the TrackerIcon for
    186189        :type host: string
     190        :returns: the TrackerIcon for the host
     191        :rtype: TrackerIcon
     192        """
     193        host = host.lower()
     194        if host in self.icons:
     195            return self.icons[host]
     196        else:
     197            return None
     198
     199    def fetch(self, host):
     200        """
     201        Returns a TrackerIcon for the given tracker's host
     202
     203        :param host: the host to obtain the TrackerIcon for
     204        :type host: string
    187205        :returns: a Deferred which fires with the TrackerIcon for the given host
    188206        :rtype: Deferred
    189207        """