mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-25 17:45:26 +00:00
Updates to ListView and the TorrentQueue plugin.
This commit is contained in:
parent
98ecdd12a9
commit
38dd216e16
@ -132,12 +132,19 @@ class Core(dbus.service.Object):
|
||||
|
||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue",
|
||||
in_signature="", out_signature="as")
|
||||
def get_queue(self):
|
||||
def get_queue_list(self):
|
||||
"""Returns the queue list.
|
||||
"""
|
||||
log.debug("Getting queue list")
|
||||
return self.queue.queue
|
||||
|
||||
|
||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue",
|
||||
in_signature="s", out_signature="i")
|
||||
def get_position(self, torrent_id):
|
||||
"""Returns the queue position of torrent_id"""
|
||||
log.debug("Getting queue position for %s", torrent_id)
|
||||
return self.queue[torrent_id]
|
||||
|
||||
## Signals ##
|
||||
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge.Queue",
|
||||
signature="")
|
||||
|
@ -33,6 +33,19 @@
|
||||
|
||||
import logging
|
||||
|
||||
try:
|
||||
import dbus, dbus.service
|
||||
dbus_version = getattr(dbus, "version", (0,0,0))
|
||||
if dbus_version >= (0,41,0) and dbus_version < (0,80,0):
|
||||
import dbus.glib
|
||||
elif dbus_version >= (0,80,0):
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
else:
|
||||
pass
|
||||
except: dbus_imported = False
|
||||
else: dbus_imported = True
|
||||
|
||||
# Get the logger
|
||||
log = logging.getLogger("deluge")
|
||||
|
||||
@ -40,6 +53,21 @@ class GtkUI:
|
||||
def __init__(self, plugin_manager):
|
||||
log.debug("Queue GtkUI plugin initalized..")
|
||||
self.plugin = plugin_manager
|
||||
# Get a reference to the core portion of the plugin
|
||||
bus = dbus.SessionBus()
|
||||
proxy = bus.get_object("org.deluge_torrent.Deluge",
|
||||
"/org/deluge_torrent/Plugin/Queue")
|
||||
self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge.Queue")
|
||||
# Get the torrentview component from the plugin manager
|
||||
self.torrentview = self.plugin.get_torrentview()
|
||||
|
||||
# Add the '#' column at the first position
|
||||
self.torrentview.add_text_column("#",
|
||||
col_type=int,
|
||||
position=0,
|
||||
get_function=self.column_get_function)
|
||||
|
||||
def column_get_function(self, torrent_id):
|
||||
"""Returns the queue position for torrent_id"""
|
||||
# Return the value + 1 because we want the queue list to start at 1
|
||||
# for the user display.
|
||||
return self.core.get_position(torrent_id) + 1
|
||||
|
@ -87,6 +87,9 @@ class ListView:
|
||||
self.column_indices = column_indices
|
||||
# Column is a reference to the GtkTreeViewColumn object
|
||||
self.column = None
|
||||
# The get_function is called when a column is in need of an update
|
||||
# This is primarily used by plugins.
|
||||
self.get_function = None
|
||||
# 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
|
||||
@ -162,7 +165,7 @@ class ListView:
|
||||
# Create a new liststore with added column and move the data from the
|
||||
# old one to the new one.
|
||||
new_list = gtk.ListStore(*tuple(self.liststore_columns))
|
||||
|
||||
|
||||
# This function is used in the liststore.foreach method with user_data
|
||||
# being the new liststore and the columns list
|
||||
def copy_row(model, path, row, user_data):
|
||||
@ -211,14 +214,25 @@ class ListView:
|
||||
|
||||
return
|
||||
|
||||
def add_text_column(self, header, hidden=False):
|
||||
def add_text_column(self, header, col_type=str, hidden=False,
|
||||
position=None, get_function=None):
|
||||
# Create a new column object and add it to the list
|
||||
self.liststore_columns.append(str)
|
||||
self.liststore_columns.append(col_type)
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
else:
|
||||
self.column_index.append(header)
|
||||
|
||||
self.columns[header] = self.ListViewColumn(header,
|
||||
[len(self.liststore_columns) - 1])
|
||||
|
||||
|
||||
# Set the get_function.. This function is used mainly for plugins.
|
||||
# You can have your listview call this function to update the column
|
||||
# value.
|
||||
if get_function is not None:
|
||||
self.columns[header].get_function = get_function
|
||||
|
||||
# Create a new list with the added column
|
||||
self.create_new_liststore()
|
||||
|
||||
@ -233,7 +247,10 @@ class ListView:
|
||||
column.set_min_width(10)
|
||||
column.set_reorderable(True)
|
||||
column.set_visible(not hidden)
|
||||
self.treeview.append_column(column)
|
||||
if position is not None:
|
||||
self.treeview.insert_column(column, position)
|
||||
else:
|
||||
self.treeview.append_column(column)
|
||||
# Set hidden in the column
|
||||
self.columns[header].hidden = hidden
|
||||
self.columns[header].column = column
|
||||
@ -243,7 +260,7 @@ class ListView:
|
||||
return True
|
||||
|
||||
def add_func_column(self, header, function, column_types, sortid=0,
|
||||
hidden=False):
|
||||
hidden=False, position=None, get_function=None):
|
||||
# Add the new column types to the list and keep track of the liststore
|
||||
# columns that this column object uses.
|
||||
# Set sortid to the column index relative the to column_types used.
|
||||
@ -256,6 +273,13 @@ class ListView:
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
else:
|
||||
self.column_index.append(header)
|
||||
|
||||
# Create a new column object and add it to the list
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
@ -278,7 +302,10 @@ class ListView:
|
||||
column.set_min_width(10)
|
||||
column.set_reorderable(True)
|
||||
column.set_visible(not hidden)
|
||||
self.treeview.append_column(column)
|
||||
if position is not None:
|
||||
self.treeview.insert_column(column, position)
|
||||
else:
|
||||
self.treeview.append_column(column)
|
||||
# Set hidden in the column
|
||||
self.columns[header].hidden = hidden
|
||||
self.columns[header].column = column
|
||||
@ -287,7 +314,8 @@ class ListView:
|
||||
|
||||
return True
|
||||
|
||||
def add_progress_column(self, header, hidden=False):
|
||||
def add_progress_column(self, header, hidden=False, position=None,
|
||||
get_function=None):
|
||||
# For the progress value
|
||||
self.liststore_columns.append(float)
|
||||
# For the text
|
||||
@ -296,7 +324,12 @@ class ListView:
|
||||
len(self.liststore_columns) - 1]
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
else:
|
||||
self.column_index.append(header)
|
||||
# Create a new column object and add it to the list
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
@ -314,7 +347,10 @@ class ListView:
|
||||
column.set_min_width(10)
|
||||
column.set_reorderable(True)
|
||||
column.set_visible(not hidden)
|
||||
self.treeview.append_column(column)
|
||||
if position is not None:
|
||||
self.treeview.insert_column(column, position)
|
||||
else:
|
||||
self.treeview.append_column(column)
|
||||
# Set hidden in the column
|
||||
self.columns[header].hidden = hidden
|
||||
self.columns[header].column = column
|
||||
@ -323,7 +359,8 @@ class ListView:
|
||||
|
||||
return True
|
||||
|
||||
def add_texticon_column(self, header, hidden=False):
|
||||
def add_texticon_column(self, header, hidden=False, position=None,
|
||||
get_function=None):
|
||||
# For icon
|
||||
self.liststore_columns.append(gtk.gdk.Pixbuf)
|
||||
# For text
|
||||
@ -332,6 +369,13 @@ class ListView:
|
||||
len(self.liststore_columns) - 1]
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
else:
|
||||
self.column_index.append(header)
|
||||
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
# Create new list with the added columns
|
||||
@ -352,7 +396,10 @@ class ListView:
|
||||
column.add_attribute(render, 'text',
|
||||
self.columns[header].column_indices[1])
|
||||
column.set_visible(not hidden)
|
||||
self.treeview.append_column(column)
|
||||
if position is not None:
|
||||
self.treeview.insert_column(column, position)
|
||||
else:
|
||||
self.treeview.append_column(column)
|
||||
# Set hidden in the column
|
||||
self.columns[header].hidden = hidden
|
||||
self.columns[header].column = column
|
||||
|
@ -146,8 +146,8 @@ class TorrentView(listview.ListView):
|
||||
"upload_payload_rate", "eta"]
|
||||
status = functions.get_torrent_status(self.core, torrent_id,
|
||||
status_keys)
|
||||
# Insert the row with info provided from core
|
||||
self.liststore.append([
|
||||
|
||||
row_list = [
|
||||
torrent_id,
|
||||
None,
|
||||
status["name"],
|
||||
@ -162,7 +162,24 @@ class TorrentView(listview.ListView):
|
||||
status["upload_payload_rate"],
|
||||
status["eta"],
|
||||
0.0
|
||||
])
|
||||
]
|
||||
|
||||
# Insert any column info from get_functions.. this is usually from
|
||||
# plugins
|
||||
for column in self.columns.values():
|
||||
if column.get_function is not None:
|
||||
if len(column.column_indices) == 1:
|
||||
row_list.insert(column.column_indices[0],
|
||||
column.get_function(torrent_id))
|
||||
else:
|
||||
result = column.get_function(torrent_id)
|
||||
r_index = 0
|
||||
for index in column.column_indices:
|
||||
row_list.insert(index, result[r_index])
|
||||
r_index = r_index + 1
|
||||
|
||||
# Insert the row with info provided from core
|
||||
self.liststore.append(row_list)
|
||||
|
||||
def remove_row(self, torrent_id):
|
||||
"""Removes a row with torrent_id"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user