Add filtering to torrentview for use with sidebar labels.
Implement sidebar filtering.
This commit is contained in:
parent
622080de50
commit
3b9983f110
6
TODO
6
TODO
|
@ -17,12 +17,10 @@
|
||||||
* Add autoload folder
|
* Add autoload folder
|
||||||
* Add wizard
|
* Add wizard
|
||||||
* Add a health indication to the statusbar
|
* 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
|
* 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..
|
* 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
|
* Add decay items to statusbar.. items that will disappear after X seconds
|
||||||
* Do not update UI when minimized or hidden
|
* Do not update UI when minimized or hidden
|
||||||
* Add command line option to change config dir.. --config
|
* 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
|
||||||
|
|
|
@ -273,7 +273,6 @@ class ListView:
|
||||||
|
|
||||||
# Create a new column object and add it to the list
|
# Create a new column object and add it to the list
|
||||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||||
|
|
||||||
|
|
||||||
self.columns[header].status_field = status_field
|
self.columns[header].status_field = status_field
|
||||||
|
|
||||||
|
@ -285,6 +284,10 @@ class ListView:
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "text",
|
column.add_attribute(render, "text",
|
||||||
self.columns[header].column_indices[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":
|
elif column_type == "func":
|
||||||
column.pack_start(render, True)
|
column.pack_start(render, True)
|
||||||
if len(self.columns[header].column_indices) > 1:
|
if len(self.columns[header].column_indices) > 1:
|
||||||
|
@ -345,7 +348,18 @@ class ListView:
|
||||||
status_field, sortid, column_type=column_type)
|
status_field, sortid, column_type=column_type)
|
||||||
|
|
||||||
return True
|
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,
|
def add_func_column(self, header, function, col_types, sortid=0,
|
||||||
hidden=False, position=None, status_field=None,
|
hidden=False, position=None, status_field=None,
|
||||||
column_type="func"):
|
column_type="func"):
|
||||||
|
|
|
@ -73,6 +73,13 @@ class SideBar(component.Component):
|
||||||
|
|
||||||
self.label_view.set_model(self.liststore)
|
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):
|
def visible(self, visible):
|
||||||
if visible:
|
if visible:
|
||||||
self.scrolled.show()
|
self.scrolled.show()
|
||||||
|
@ -81,4 +88,27 @@ class SideBar(component.Component):
|
||||||
self.hpaned.set_position(-1)
|
self.hpaned.set_position(-1)
|
||||||
|
|
||||||
self.is_visible = visible
|
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"))
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
|
|
||||||
# Add the columns to the listview
|
# Add the columns to the listview
|
||||||
self.add_text_column("torrent_id", hidden=True)
|
self.add_text_column("torrent_id", hidden=True)
|
||||||
|
self.add_bool_column("filter", hidden=True)
|
||||||
self.add_texticon_column(_("Name"), status_field=["state", "name"],
|
self.add_texticon_column(_("Name"), status_field=["state", "name"],
|
||||||
function=cell_data_statusicon)
|
function=cell_data_statusicon)
|
||||||
self.add_func_column(_("Size"),
|
self.add_func_column(_("Size"),
|
||||||
|
@ -164,7 +165,16 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
listview.cell_data_ratio,
|
listview.cell_data_ratio,
|
||||||
[float],
|
[float],
|
||||||
status_field=["distributed_copies"])
|
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 Signals ###
|
||||||
# Connect to the 'button-press-event' to know when to bring up the
|
# Connect to the 'button-press-event' to know when to bring up the
|
||||||
# torrent menu popup.
|
# torrent menu popup.
|
||||||
|
@ -187,21 +197,49 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
"""Stops the torrentview"""
|
"""Stops the torrentview"""
|
||||||
# We need to clear the liststore
|
# We need to clear the liststore
|
||||||
self.liststore.clear()
|
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):
|
def update(self, columns=None):
|
||||||
"""Update the view. If columns is not None, it will attempt to only
|
"""Update the view. If columns is not None, it will attempt to only
|
||||||
update those columns selected.
|
update those columns selected.
|
||||||
"""
|
"""
|
||||||
# Iterates through every row and updates them accordingly
|
def foreachrow(model, path, row, data):
|
||||||
if self.liststore is not None:
|
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)
|
self.liststore.foreach(self.update_row, columns)
|
||||||
|
|
||||||
def update_row(self, model=None, path=None, row=None, columns=None):
|
def update_row(self, model=None, path=None, row=None, columns=None):
|
||||||
"""Updates the column values for 'row'. If columns is None it will
|
"""Updates the column values for 'row'. If columns is None it will
|
||||||
update all visible columns."""
|
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,
|
torrent_id = model.get_value(row,
|
||||||
self.columns["torrent_id"].column_indices[0])
|
self.columns["torrent_id"].column_indices[0])
|
||||||
|
|
||||||
# Store the 'status_fields' we need to send to core
|
# Store the 'status_fields' we need to send to core
|
||||||
status_keys = []
|
status_keys = []
|
||||||
# Store the actual columns we will be updating
|
# Store the actual columns we will be updating
|
||||||
|
|
Loading…
Reference in New Issue