mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 04:24:27 +00:00
use core filtering for torrentview
This commit is contained in:
parent
5c1ec8dbb3
commit
862cec9e0a
@ -403,13 +403,13 @@ class LabelSideBar(component.Component):
|
||||
if cat == "tracker":
|
||||
cat = "tracker_host"
|
||||
|
||||
filter = (cat, value)
|
||||
filter_dict = {cat: [value]}
|
||||
if value == "All" or cat == "cat":
|
||||
filter = (None, None)
|
||||
filter_dict = {}
|
||||
elif (cat == "label" and value == NO_LABEL):
|
||||
filter = ("label","")
|
||||
filter_dict["label"] = [""]
|
||||
|
||||
component.get("TorrentView").set_filter(*filter)
|
||||
component.get("TorrentView").set_filter(filter_dict)
|
||||
|
||||
except Exception, e:
|
||||
log.debug(e)
|
||||
|
@ -10,6 +10,10 @@ torrent_id = sclient.get_session_state()[0]
|
||||
torrent_id2 = sclient.get_session_state()[1]
|
||||
#/init
|
||||
|
||||
def test_filter(filter):
|
||||
status = sclient.get_torrents_status(filter, KEYS)
|
||||
print len(status),status
|
||||
|
||||
print "#get_status_keys"
|
||||
#both lines should return the same if all plugins are disabled.
|
||||
#the 1st should be longer if the label plugin is enabled.
|
||||
@ -17,17 +21,22 @@ print sorted(sclient.get_torrent_status(torrent_id,[]).keys())
|
||||
print sorted(sclient.get_status_keys())
|
||||
|
||||
print "#default, no filter argument."
|
||||
print sclient.get_torrents_status(None, KEYS)
|
||||
test_filter(None)
|
||||
if not (sclient.get_torrents_status({}, KEYS) == sclient.get_torrents_status(None, KEYS)):
|
||||
raise Exception("should be equal")
|
||||
|
||||
print "#torrent_id filter:"
|
||||
print sclient.get_torrents_status({"id":[torrent_id, torrent_id2]}, KEYS)
|
||||
test_filter({"id":[torrent_id, torrent_id2]})
|
||||
|
||||
print "#filters on default status fields:"
|
||||
print sclient.get_torrents_status({"state":["Paused","Downloading"]}, KEYS)
|
||||
print sclient.get_torrents_status({"tracker_host":["aelitis.com"]}, KEYS)
|
||||
|
||||
print "#status fields from plugins:"
|
||||
print sclient.get_torrents_status({"label":["test","tpb"]}, KEYS)
|
||||
print "test&tpb:",len(sclient.get_torrents_status({"label":["test","tpb"]}, KEYS))
|
||||
print "test:",len(sclient.get_torrents_status({"label":["test"]}, KEYS))
|
||||
print "No Label:" , len(sclient.get_torrents_status({"label":[""]}, KEYS))
|
||||
|
||||
|
||||
print "#special filters (ERRORS START HERE!):"
|
||||
print sclient.get_torrents_status({"keyword":["az"]}, KEYS)
|
||||
|
@ -166,7 +166,7 @@ class TorrentView(listview.ListView, component.Component):
|
||||
self.add_text_column(_("Tracker"), status_field=["tracker_host"])
|
||||
|
||||
# Set filter to None for now
|
||||
self.filter = (None, None)
|
||||
self.filter = None
|
||||
|
||||
### Connect Signals ###
|
||||
# Connect to the 'button-press-event' to know when to bring up the
|
||||
@ -189,8 +189,6 @@ class TorrentView(listview.ListView, component.Component):
|
||||
def _on_session_state(self, state):
|
||||
for torrent_id in state:
|
||||
self.add_row(torrent_id, update=False)
|
||||
|
||||
self.update_filter()
|
||||
self.update()
|
||||
|
||||
def stop(self):
|
||||
@ -202,17 +200,15 @@ class TorrentView(listview.ListView, component.Component):
|
||||
"""Called when GtkUi is exiting"""
|
||||
self.save_state("torrentview.state")
|
||||
|
||||
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()
|
||||
def set_filter(self, filter_dict):
|
||||
"""Sets filters for the torrentview..
|
||||
see: core.get_torrents_status
|
||||
"""
|
||||
self.filter = dict(filter_dict) #copied version of filter_dict.
|
||||
self.update()
|
||||
|
||||
def send_status_request(self, columns=None):
|
||||
log.debug("send_status_req:%s" % (self.filter,))
|
||||
# Store the 'status_fields' we need to send to core
|
||||
status_keys = []
|
||||
# Store the actual columns we will be updating
|
||||
@ -243,44 +239,10 @@ class TorrentView(listview.ListView, component.Component):
|
||||
# Remove duplicates from status_key list
|
||||
status_keys = list(set(status_keys))
|
||||
|
||||
# Create list of torrent_ids in need of status updates
|
||||
torrent_ids = []
|
||||
for row in self.liststore:
|
||||
# Only add this torrent_id if it's not filtered
|
||||
if row[self.columns["filter"].column_indices[0]] == True or \
|
||||
row[self.columns["dirty"].column_indices[0]] == True :
|
||||
torrent_ids.append(row[self.columns["torrent_id"].column_indices[0]])
|
||||
row[self.columns["dirty"].column_indices[0]] = False
|
||||
|
||||
if torrent_ids == []:
|
||||
return
|
||||
|
||||
# Request the statuses for all these torrent_ids, this is async so we
|
||||
# will deal with the return in a signal callback.
|
||||
client.get_torrents_status(
|
||||
self._on_get_torrents_status, {"id":torrent_ids}, status_keys)
|
||||
|
||||
def update_filter(self):
|
||||
# Update the filter view
|
||||
for row in self.liststore:
|
||||
self.update_filter_row(row)
|
||||
|
||||
def update_filter_row(self, row):
|
||||
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 = self.filter
|
||||
if field == None and condition == None:
|
||||
row[filter_column] = True
|
||||
return
|
||||
|
||||
value = row[self.get_state_field_column(field)]
|
||||
|
||||
# Condition is True, so lets show this row, if not we hide it
|
||||
if value == condition:
|
||||
row[filter_column] = True
|
||||
else:
|
||||
row[filter_column] = False
|
||||
self._on_get_torrents_status, self.filter, status_keys)
|
||||
|
||||
def update(self):
|
||||
# Send a status request
|
||||
@ -290,11 +252,18 @@ class TorrentView(listview.ListView, component.Component):
|
||||
"""Update the view. If columns is not None, it will attempt to only
|
||||
update those columns selected.
|
||||
"""
|
||||
filter_column = self.columns["filter"].column_indices[0]
|
||||
|
||||
# Update the torrent view model with data we've received
|
||||
status = self.status
|
||||
for row in self.liststore:
|
||||
torrent_id = row[self.columns["torrent_id"].column_indices[0]]
|
||||
if torrent_id in status.keys():
|
||||
|
||||
if not torrent_id in status.keys():
|
||||
row[filter_column] = False
|
||||
else:
|
||||
row[filter_column] = True
|
||||
log.debug("show:%s" % torrent_id)
|
||||
# Set values for each column in the row
|
||||
for column in self.columns_to_update:
|
||||
column_index = self.get_column_index(column)
|
||||
@ -327,7 +296,6 @@ class TorrentView(listview.ListView, component.Component):
|
||||
column_index.index(index)]]
|
||||
except:
|
||||
pass
|
||||
self.update_filter_row(row)
|
||||
# Update the toolbar buttons just in case some state has changed
|
||||
component.get("ToolBar").update_buttons()
|
||||
component.get("MenuBar").update_menu()
|
||||
@ -335,13 +303,8 @@ class TorrentView(listview.ListView, component.Component):
|
||||
def _on_get_torrents_status(self, status):
|
||||
"""Callback function for get_torrents_status(). 'status' should be a
|
||||
dictionary of {torrent_id: {key, value}}."""
|
||||
if status != None:
|
||||
self.status = status
|
||||
else:
|
||||
self.status = {}
|
||||
|
||||
if self.status != {}:
|
||||
self.update_view()
|
||||
self.status = status
|
||||
self.update_view()
|
||||
|
||||
def add_row(self, torrent_id, update=True):
|
||||
"""Adds a new torrent row to the treeview"""
|
||||
@ -354,7 +317,6 @@ class TorrentView(listview.ListView, component.Component):
|
||||
torrent_id)
|
||||
if update:
|
||||
self.update()
|
||||
self.update_filter()
|
||||
|
||||
def remove_row(self, torrent_id):
|
||||
"""Removes a row with torrent_id"""
|
||||
@ -363,7 +325,6 @@ class TorrentView(listview.ListView, component.Component):
|
||||
self.liststore.remove(row.iter)
|
||||
# Force an update of the torrentview
|
||||
self.update()
|
||||
self.update_filter()
|
||||
break
|
||||
|
||||
def mark_dirty(self, torrent_id = None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user