mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-04 07:33:31 +00:00
Sorting # column will place downloaders above seeds
This commit is contained in:
parent
90d310edd4
commit
07eaf8ed36
@ -7,3 +7,4 @@ Deluge 1.1.0 - "" (In Development)
|
||||
GtkUI:
|
||||
* Add peer progress to the peers tab
|
||||
* Add 'edit' to edit trackers dialog
|
||||
* Sorting # column will place downloaders above seeds
|
||||
|
@ -119,6 +119,9 @@ class ListView:
|
||||
# If column is 'hidden' then it will not be visible and will not
|
||||
# show up in any menu listing; it cannot be shown ever.
|
||||
self.hidden = False
|
||||
# If this is set, it is used to sort the model
|
||||
self.sort_func = None
|
||||
self.sort_id = None
|
||||
|
||||
def __init__(self, treeview_widget=None, state_file=None):
|
||||
log.debug("ListView initialized..")
|
||||
@ -168,10 +171,20 @@ class ListView:
|
||||
model_filter.set_visible_column(
|
||||
self.columns["filter"].column_indices[0])
|
||||
self.model_filter = gtk.TreeModelSort(model_filter)
|
||||
self.set_sort_functions()
|
||||
self.treeview.set_model(self.model_filter)
|
||||
if sort_column and sort_column != (None, None):
|
||||
self.model_filter.set_sort_column_id(*sort_column)
|
||||
|
||||
|
||||
def set_sort_functions(self):
|
||||
for column in self.columns.values():
|
||||
if column.sort_func:
|
||||
log.debug("sort_func: %s sort_id: %s", column.sort_func, column.sort_id)
|
||||
self.model_filter.set_sort_func(
|
||||
column.sort_id,
|
||||
column.sort_func,
|
||||
column.sort_id)
|
||||
|
||||
def save_state(self, filename):
|
||||
"""Saves the listview state (column positions and visibility) to
|
||||
filename."""
|
||||
@ -354,7 +367,7 @@ class ListView:
|
||||
|
||||
def add_column(self, header, render, col_types, hidden, position,
|
||||
status_field, sortid, text=0, value=0, pixbuf=0, function=None,
|
||||
column_type=None):
|
||||
column_type=None, sort_func=None):
|
||||
"""Adds a column to the ListView"""
|
||||
# Add the column types to liststore_columns
|
||||
column_indices = []
|
||||
@ -376,6 +389,8 @@ class ListView:
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
self.columns[header].status_field = status_field
|
||||
self.columns[header].sort_func = sort_func
|
||||
self.columns[header].sort_id = column_indices[sortid]
|
||||
|
||||
# Create a new list with the added column
|
||||
self.create_new_liststore()
|
||||
@ -457,12 +472,13 @@ class ListView:
|
||||
position=None,
|
||||
status_field=None,
|
||||
sortid=0,
|
||||
column_type="text"):
|
||||
column_type="text",
|
||||
sort_func=None):
|
||||
"""Add a text column to the listview. Only the header name is required.
|
||||
"""
|
||||
render = gtk.CellRendererText()
|
||||
self.add_column(header, render, col_type, hidden, position,
|
||||
status_field, sortid, column_type=column_type)
|
||||
status_field, sortid, column_type=column_type, sort_func=sort_func)
|
||||
|
||||
return True
|
||||
|
||||
@ -479,14 +495,14 @@ class ListView:
|
||||
|
||||
def add_func_column(self, header, function, col_types, sortid=0,
|
||||
hidden=False, position=None, status_field=None,
|
||||
column_type="func"):
|
||||
column_type="func", sort_func=None):
|
||||
"""Add a function column to the listview. Need a header name, the
|
||||
function and the column types."""
|
||||
|
||||
render = gtk.CellRendererText()
|
||||
self.add_column(header, render, col_types, hidden, position,
|
||||
status_field, sortid, column_type=column_type,
|
||||
function=function)
|
||||
function=function, sort_func=sort_func)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -100,6 +100,20 @@ def cell_data_queue(column, cell, model, row, data):
|
||||
else:
|
||||
cell.set_property("text", value + 1)
|
||||
|
||||
def queue_column_sort(model, iter1, iter2, data):
|
||||
v1 = model[iter1][data]
|
||||
v2 = model[iter2][data]
|
||||
if v1 == v2:
|
||||
return 0
|
||||
if v2 < 0:
|
||||
return -1
|
||||
if v1 < 0:
|
||||
return 1
|
||||
if v1 > v2:
|
||||
return 1
|
||||
if v2 > v1:
|
||||
return -1
|
||||
|
||||
class TorrentView(listview.ListView, component.Component):
|
||||
"""TorrentView handles the listing of torrents."""
|
||||
def __init__(self):
|
||||
@ -122,7 +136,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("dirty", hidden=True)
|
||||
self.add_func_column("#", cell_data_queue, [int], status_field=["queue"])
|
||||
self.add_func_column("#", cell_data_queue, [int], status_field=["queue"], sort_func=queue_column_sort)
|
||||
self.add_texticon_column(_("Name"), status_field=["state", "name"],
|
||||
function=cell_data_statusicon)
|
||||
self.add_func_column(_("Size"),
|
||||
@ -179,7 +193,7 @@ class TorrentView(listview.ListView, component.Component):
|
||||
self.on_selection_changed)
|
||||
|
||||
self.treeview.connect("drag-drop", self.on_drag_drop)
|
||||
|
||||
|
||||
def start(self):
|
||||
"""Start the torrentview"""
|
||||
# We need to get the core session state to know which torrents are in
|
||||
@ -187,9 +201,13 @@ class TorrentView(listview.ListView, component.Component):
|
||||
client.get_session_state(self._on_session_state)
|
||||
|
||||
def _on_session_state(self, state):
|
||||
self.treeview.freeze_child_notify()
|
||||
model = self.treeview.get_model()
|
||||
for torrent_id in state:
|
||||
self.add_row(torrent_id, update=False)
|
||||
self.mark_dirty(torrent_id)
|
||||
self.treeview.set_model(model)
|
||||
self.treeview.thaw_child_notify()
|
||||
self.update()
|
||||
|
||||
def stop(self):
|
||||
@ -253,9 +271,10 @@ class TorrentView(listview.ListView, component.Component):
|
||||
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
|
||||
(sort_id, sort_type) = self.treeview.get_model().get_sort_column_id()
|
||||
self.treeview.get_model().set_sort_column_id(-1, gtk.SORT_ASCENDING)
|
||||
for row in self.liststore:
|
||||
torrent_id = row[self.columns["torrent_id"].column_indices[0]]
|
||||
|
||||
@ -271,10 +290,9 @@ class TorrentView(listview.ListView, component.Component):
|
||||
# update
|
||||
try:
|
||||
# Only update if different
|
||||
if row[column_index] != \
|
||||
status[torrent_id][self.columns[column].status_field[0]]:
|
||||
row[column_index] = status[torrent_id][
|
||||
self.columns[column].status_field[0]]
|
||||
row_value = status[torrent_id][self.columns[column].status_field[0]]
|
||||
if row[column_index] != row_value:
|
||||
row[column_index] = row_value
|
||||
except (TypeError, KeyError), e:
|
||||
log.warning("Unable to update column %s: %s",
|
||||
column, e)
|
||||
@ -284,17 +302,12 @@ class TorrentView(listview.ListView, component.Component):
|
||||
# Only update the column if the status field exists
|
||||
try:
|
||||
# Only update if different
|
||||
if row[index] != \
|
||||
status[torrent_id][
|
||||
self.columns[column].status_field[
|
||||
column_index.index(index)]]:
|
||||
|
||||
row[index] = \
|
||||
status[torrent_id][
|
||||
self.columns[column].status_field[
|
||||
column_index.index(index)]]
|
||||
row_value = status[torrent_id][self.columns[column].status_field[column_index.index(index)]]
|
||||
if row[index] != row_value:
|
||||
row[index] = row_value
|
||||
except:
|
||||
pass
|
||||
self.treeview.get_model().set_sort_column_id(sort_id, sort_type)
|
||||
# Update the toolbar buttons just in case some state has changed
|
||||
component.get("ToolBar").update_buttons()
|
||||
component.get("MenuBar").update_menu()
|
||||
@ -415,4 +428,3 @@ class TorrentView(listview.ListView, component.Component):
|
||||
|
||||
def on_drag_drop(self, widget, drag_context, x, y, timestamp):
|
||||
widget.stop_emission("drag-drop")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user