Add filtering to torrentview for use with sidebar labels.

Implement sidebar filtering.
This commit is contained in:
Andrew Resch 2007-12-05 05:21:34 +00:00
parent 622080de50
commit 3b9983f110
4 changed files with 92 additions and 12 deletions

6
TODO
View File

@ -17,12 +17,10 @@
* Add autoload folder
* Add wizard
* Add a health indication to the statusbar
* Add sidebar for labels and other things.. Plugins should be able to add their
own section to this.
* Option for adding torrents in paused/active state
* Add filtering to torrentview to use with the sidebar
* Fix up preferences for when using a remote host.. the download folders, etc..
* Add decay items to statusbar.. items that will disappear after X seconds
* Do not update UI when minimized or hidden
* Add command line option to change config dir.. --config
* Add method for plugins to add labels
* Add context menus for labels.. ie. setting options for all torrents in label

View File

@ -273,7 +273,6 @@ class ListView:
# Create a new column object and add it to the list
self.columns[header] = self.ListViewColumn(header, column_indices)
self.columns[header].status_field = status_field
@ -285,6 +284,10 @@ class ListView:
column.pack_start(render)
column.add_attribute(render, "text",
self.columns[header].column_indices[text])
elif column_type == "bool":
column.pack_start(render)
column.add_attribute(render, "active",
self.columns[header].column_indices[0])
elif column_type == "func":
column.pack_start(render, True)
if len(self.columns[header].column_indices) > 1:
@ -345,7 +348,18 @@ class ListView:
status_field, sortid, column_type=column_type)
return True
def add_bool_column(self, header, col_type=bool, hidden=False,
position=None,
status_field=None,
sortid=0,
column_type="bool"):
"""Add a bool column to the listview"""
render = gtk.CellRendererToggle()
self.add_column(header, render, col_type, hidden, position,
status_field, sortid, column_type=column_type)
def add_func_column(self, header, function, col_types, sortid=0,
hidden=False, position=None, status_field=None,
column_type="func"):

View File

@ -73,6 +73,13 @@ class SideBar(component.Component):
self.label_view.set_model(self.liststore)
self.label_view.get_selection().connect("changed",
self.on_selection_changed)
# Select the 'All' label on init
self.label_view.get_selection().select_iter(
self.liststore.get_iter_first())
def visible(self, visible):
if visible:
self.scrolled.show()
@ -81,4 +88,27 @@ class SideBar(component.Component):
self.hpaned.set_position(-1)
self.is_visible = visible
def on_selection_changed(self, selection):
try:
(model, row) = self.label_view.get_selection().get_selected()
except Exception, e:
log.debug(e)
# paths is likely None .. so lets return None
return None
value = model.get_value(row, 0)
if value == "All":
component.get("TorrentView").set_filter(None, None)
if value == "Downloading":
component.get("TorrentView").set_filter("state",
deluge.common.TORRENT_STATE.index("Downloading"))
if value == "Seeding":
component.get("TorrentView").set_filter("state",
deluge.common.TORRENT_STATE.index("Seeding"))
if value == "Paused":
component.get("TorrentView").set_filter("state",
deluge.common.TORRENT_STATE.index("Paused"))

View File

@ -124,6 +124,7 @@ class TorrentView(listview.ListView, component.Component):
# Add the columns to the listview
self.add_text_column("torrent_id", hidden=True)
self.add_bool_column("filter", hidden=True)
self.add_texticon_column(_("Name"), status_field=["state", "name"],
function=cell_data_statusicon)
self.add_func_column(_("Size"),
@ -164,7 +165,16 @@ class TorrentView(listview.ListView, component.Component):
listview.cell_data_ratio,
[float],
status_field=["distributed_copies"])
# Set filter to None for now
self.filter = (None, None)
# Set the liststore filter column
self.model_filter = self.liststore.filter_new()
self.model_filter.set_visible_column(
self.columns["filter"].column_indices[0])
self.treeview.set_model(self.model_filter)
### Connect Signals ###
# Connect to the 'button-press-event' to know when to bring up the
# torrent menu popup.
@ -187,21 +197,49 @@ class TorrentView(listview.ListView, component.Component):
"""Stops the torrentview"""
# We need to clear the liststore
self.liststore.clear()
def set_filter(self, field, condition):
"""Sets filters for the torrentview.."""
self.filter = (field, condition)
self.update()
def update(self, columns=None):
"""Update the view. If columns is not None, it will attempt to only
update those columns selected.
"""
# Iterates through every row and updates them accordingly
if self.liststore is not None:
def foreachrow(model, path, row, data):
filter_column = self.columns["filter"].column_indices[0]
# Create a function to create a new liststore with only the
# desired rows based on the filter.
field, condition = data
if field == None and condition == None:
model.set_value(row, filter_column, True)
return
torrent_id = model.get_value(row, 0)
value = client.get_torrent_status(torrent_id, [field])[field]
# Condition is True, so lets show this row, if not we hide it
if value == condition:
model.set_value(row, filter_column, True)
else:
model.set_value(row, filter_column, False)
self.liststore.foreach(foreachrow, self.filter)
if self.liststore != None:
self.liststore.foreach(self.update_row, columns)
def update_row(self, model=None, path=None, row=None, columns=None):
"""Updates the column values for 'row'. If columns is None it will
update all visible columns."""
# Check to see if this row is visible and return if not
if not model.get_value(row, self.columns["filter"].column_indices[0]):
return
# Get the torrent_id from the liststore
torrent_id = model.get_value(row,
self.columns["torrent_id"].column_indices[0])
# Store the 'status_fields' we need to send to core
status_keys = []
# Store the actual columns we will be updating