From 0e31d4243c47b8e0df2c41c54e4b697ea4f136b7 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 3 Mar 2008 09:05:02 +0000 Subject: [PATCH] Add 'Queued' label to SideBar. Fix the labels filter from not displaying properly. --- deluge/ui/gtkui/listview.py | 11 +++++++++++ deluge/ui/gtkui/sidebar.py | 11 +++++++---- deluge/ui/gtkui/torrentview.py | 19 +++++++++++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 8da2ac506..1c67eeb53 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -211,6 +211,17 @@ class ListView: else: return self.columns[name].column_indices[0] + def get_state_field_column(self, field): + """Returns the column number for the state field""" + for column in self.columns.keys(): + if self.columns[column].status_field == None: + continue + + for f in self.columns[column].status_field: + if field == f: + return self.columns[column].column_indices[ + self.columns[column].status_field.index(f)] + def on_menuitem_toggled(self, widget): """Callback for the generated column menuitems.""" # Get the column name from the widget diff --git a/deluge/ui/gtkui/sidebar.py b/deluge/ui/gtkui/sidebar.py index 1af71b4e2..a48dc2f22 100644 --- a/deluge/ui/gtkui/sidebar.py +++ b/deluge/ui/gtkui/sidebar.py @@ -57,6 +57,9 @@ class SideBar(component.Component): self.liststore.append([_("Seeding"), gtk.gdk.pixbuf_new_from_file( deluge.common.get_pixmap("seeding16.png"))]) + self.liststore.append([_("Queued"), + gtk.gdk.pixbuf_new_from_file( + deluge.common.get_pixmap("queued16.png"))]) self.liststore.append([_("Paused"), gtk.gdk.pixbuf_new_from_file( deluge.common.get_pixmap("inactive16.png"))]) @@ -104,9 +107,9 @@ class SideBar(component.Component): component.get("TorrentView").set_filter("state", "Downloading") if value == "Seeding": - component.get("TorrentView").set_filter("state", - "Seeding") + component.get("TorrentView").set_filter("state", "Seeding") + if value == "Queued": + component.get("TorrentView").set_filter("state", "Queued") if value == "Paused": - component.get("TorrentView").set_filter("state", - "Paused") + component.get("TorrentView").set_filter("state", "Paused") diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 5ccdbf335..dd268ff89 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -187,7 +187,8 @@ class TorrentView(listview.ListView, component.Component): def _on_session_state(self, state): for torrent_id in state: self.add_row(torrent_id) - + + self.update_filter() self.update() def stop(self): @@ -201,7 +202,12 @@ class TorrentView(listview.ListView, component.Component): def set_filter(self, field, condition): """Sets filters for the torrentview..""" + if self.filter != (None, None): + self.filter = (None, None) + self.update_filter() + self.filter = (field, condition) + self.update_filter() self.update() def send_status_request(self, columns=None): @@ -254,7 +260,7 @@ class TorrentView(listview.ListView, component.Component): client.get_torrents_status( self._on_get_torrents_status, torrent_ids, status_keys) - def update(self): + def update_filter(self): # Update the filter view def foreachrow(model, path, row, data): filter_column = self.columns["filter"].column_indices[0] @@ -266,10 +272,8 @@ class TorrentView(listview.ListView, component.Component): return torrent_id = model.get_value(row, 0) - try: - value = self.status[torrent_id][field] - except: - return + value = model.get_value(row, self.get_state_field_column(field)) + # Condition is True, so lets show this row, if not we hide it if value == condition: model.set_value(row, filter_column, True) @@ -277,6 +281,8 @@ class TorrentView(listview.ListView, component.Component): model.set_value(row, filter_column, False) self.liststore.foreach(foreachrow, self.filter) + + def update(self): # Send a status request self.send_status_request() @@ -349,6 +355,7 @@ class TorrentView(listview.ListView, component.Component): row, self.columns["torrent_id"].column_indices[0], torrent_id) + self.update() def remove_row(self, torrent_id): """Removes a row with torrent_id"""