mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-04 23:53:23 +00:00
Updates to the TorrentQueue plugin.
Added 'add_toolbutton()' and 'add_separator()' to ToolBar. Added 'get_toolbar()' and 'get_selected_torrents()' to PluginManager.
This commit is contained in:
parent
38dd216e16
commit
d12e333e3a
@ -58,6 +58,11 @@ class GtkUI:
|
|||||||
proxy = bus.get_object("org.deluge_torrent.Deluge",
|
proxy = bus.get_object("org.deluge_torrent.Deluge",
|
||||||
"/org/deluge_torrent/Plugin/Queue")
|
"/org/deluge_torrent/Plugin/Queue")
|
||||||
self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge.Queue")
|
self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge.Queue")
|
||||||
|
|
||||||
|
# Connect to the 'torrent_queue_changed' signal
|
||||||
|
self.core.connect_to_signal("torrent_queue_changed",
|
||||||
|
self.torrent_queue_changed_signal)
|
||||||
|
|
||||||
# Get the torrentview component from the plugin manager
|
# Get the torrentview component from the plugin manager
|
||||||
self.torrentview = self.plugin.get_torrentview()
|
self.torrentview = self.plugin.get_torrentview()
|
||||||
# Add the '#' column at the first position
|
# Add the '#' column at the first position
|
||||||
@ -65,7 +70,41 @@ class GtkUI:
|
|||||||
col_type=int,
|
col_type=int,
|
||||||
position=0,
|
position=0,
|
||||||
get_function=self.column_get_function)
|
get_function=self.column_get_function)
|
||||||
|
# Add a toolbar buttons
|
||||||
|
self.plugin.get_toolbar().add_separator()
|
||||||
|
self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-up",
|
||||||
|
label="Queue Up",
|
||||||
|
tooltip="Queue selected torrents up",
|
||||||
|
callback=self.on_queueup_toolbutton_clicked)
|
||||||
|
|
||||||
|
self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-down",
|
||||||
|
label="Queue Down",
|
||||||
|
tooltip="Queue selected torrents down",
|
||||||
|
callback=self.on_queuedown_toolbutton_clicked)
|
||||||
|
|
||||||
|
def on_queuedown_toolbutton_clicked(self, widget):
|
||||||
|
log.debug("Queue down toolbutton clicked.")
|
||||||
|
# Get the selected torrents
|
||||||
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
|
for torrent_id in torrent_ids:
|
||||||
|
self.core.queue_down(torrent_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
def on_queueup_toolbutton_clicked(self, widget):
|
||||||
|
log.debug("Queue Up toolbutton clicked.")
|
||||||
|
# Get the selected torrents
|
||||||
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
|
for torrent_id in torrent_ids:
|
||||||
|
self.core.queue_up(torrent_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
def torrent_queue_changed_signal(self):
|
||||||
|
"""This function is called whenever we receive a 'torrent_queue_changed'
|
||||||
|
signal from the core plugin.
|
||||||
|
"""
|
||||||
|
log.debug("torrent_queue_changed signal received..")
|
||||||
|
return
|
||||||
|
|
||||||
def column_get_function(self, torrent_id):
|
def column_get_function(self, torrent_id):
|
||||||
"""Returns the queue position for torrent_id"""
|
"""Returns the queue position for torrent_id"""
|
||||||
# Return the value + 1 because we want the queue list to start at 1
|
# Return the value + 1 because we want the queue list to start at 1
|
||||||
|
@ -112,34 +112,6 @@ def resume_torrent(torrent_ids):
|
|||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
core.resume_torrent(torrent_id)
|
core.resume_torrent(torrent_id)
|
||||||
|
|
||||||
def queue_top(torrent_ids):
|
|
||||||
"""Attempts to queue all torrent_ids to the top"""
|
|
||||||
log.debug("Attempting to queue to top these torrents: %s", torrent_ids)
|
|
||||||
core = get_core_plugin("Queue")
|
|
||||||
for torrent_id in torrent_ids:
|
|
||||||
core.queue_top(torrent_id)
|
|
||||||
|
|
||||||
def queue_up(torrent_ids):
|
|
||||||
"""Attempts to queue all torrent_ids up"""
|
|
||||||
log.debug("Attempting to queue up these torrents: %s", torrent_ids)
|
|
||||||
core = get_core()
|
|
||||||
for torrent_id in torrent_ids:
|
|
||||||
core.queue_up(torrent_id)
|
|
||||||
|
|
||||||
def queue_down(torrent_ids):
|
|
||||||
"""Attempts to queue all torrent_ids down"""
|
|
||||||
log.debug("Attempting to queue down these torrents: %s", torrent_ids)
|
|
||||||
core = get_core()
|
|
||||||
for torrent_id in torrent_ids:
|
|
||||||
core.queue_down(torrent_id)
|
|
||||||
|
|
||||||
def queue_bottom(torrent_ids):
|
|
||||||
"""Attempts to queue all torrent_ids to the bottom"""
|
|
||||||
log.debug("Attempting to queue to bottom these torrents: %s", torrent_ids)
|
|
||||||
core = get_core()
|
|
||||||
for torrent_id in torrent_ids:
|
|
||||||
core.queue_bottom(torrent_id)
|
|
||||||
|
|
||||||
def get_torrent_info(core, torrent_id):
|
def get_torrent_info(core, torrent_id):
|
||||||
"""Builds the info dictionary and returns it"""
|
"""Builds the info dictionary and returns it"""
|
||||||
info = core.get_torrent_info(torrent_id)
|
info = core.get_torrent_info(torrent_id)
|
||||||
|
@ -124,6 +124,7 @@ class ListView:
|
|||||||
|
|
||||||
def set_treeview(self, treeview_widget):
|
def set_treeview(self, treeview_widget):
|
||||||
self.treeview = treeview_widget
|
self.treeview = treeview_widget
|
||||||
|
self.treeview.set_model(self.liststore)
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_column_index(self, name):
|
def get_column_index(self, name):
|
||||||
|
@ -70,3 +70,11 @@ class PluginManager:
|
|||||||
def get_torrentview(self):
|
def get_torrentview(self):
|
||||||
"""Returns a reference to the torrentview component"""
|
"""Returns a reference to the torrentview component"""
|
||||||
return self._gtkui.mainwindow.torrentview
|
return self._gtkui.mainwindow.torrentview
|
||||||
|
|
||||||
|
def get_toolbar(self):
|
||||||
|
"""Returns a reference to the toolbar component"""
|
||||||
|
return self._gtkui.mainwindow.toolbar
|
||||||
|
|
||||||
|
def get_selected_torrents(self):
|
||||||
|
"""Returns a list of the selected torrent_ids"""
|
||||||
|
return self._gtkui.mainwindow.torrentview.get_selected_torrents()
|
||||||
|
@ -44,7 +44,7 @@ class ToolBar:
|
|||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
log.debug("ToolBar Init..")
|
log.debug("ToolBar Init..")
|
||||||
self.window = window
|
self.window = window
|
||||||
|
self.toolbar = self.window.main_glade.get_widget("toolbar")
|
||||||
### Connect Signals ###
|
### Connect Signals ###
|
||||||
self.window.main_glade.signal_autoconnect({
|
self.window.main_glade.signal_autoconnect({
|
||||||
"on_toolbutton_add_clicked": self.on_toolbutton_add_clicked,
|
"on_toolbutton_add_clicked": self.on_toolbutton_add_clicked,
|
||||||
@ -52,15 +52,43 @@ class ToolBar:
|
|||||||
"on_toolbutton_clear_clicked": self.on_toolbutton_clear_clicked,
|
"on_toolbutton_clear_clicked": self.on_toolbutton_clear_clicked,
|
||||||
"on_toolbutton_pause_clicked": self.on_toolbutton_pause_clicked,
|
"on_toolbutton_pause_clicked": self.on_toolbutton_pause_clicked,
|
||||||
"on_toolbutton_resume_clicked": self.on_toolbutton_resume_clicked,
|
"on_toolbutton_resume_clicked": self.on_toolbutton_resume_clicked,
|
||||||
"on_toolbutton_queueup_clicked": \
|
|
||||||
self.on_toolbutton_queueup_clicked,
|
|
||||||
"on_toolbutton_queuedown_clicked": \
|
|
||||||
self.on_toolbutton_queuedown_clicked,
|
|
||||||
"on_toolbutton_preferences_clicked": \
|
"on_toolbutton_preferences_clicked": \
|
||||||
self.on_toolbutton_preferences_clicked,
|
self.on_toolbutton_preferences_clicked,
|
||||||
"on_toolbutton_plugins_clicked": \
|
"on_toolbutton_plugins_clicked": \
|
||||||
self.on_toolbutton_plugins_clicked,
|
self.on_toolbutton_plugins_clicked,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def add_toolbutton(self, callback, label=None, image=None, stock=None,
|
||||||
|
tooltip=None):
|
||||||
|
"""Adds a toolbutton to the toolbar"""
|
||||||
|
# Create the button
|
||||||
|
toolbutton = gtk.ToolButton(stock)
|
||||||
|
if label is not None:
|
||||||
|
toolbutton.set_label(label)
|
||||||
|
if image is not None:
|
||||||
|
toolbutton.set_icon_widget(image)
|
||||||
|
# Set the tooltip
|
||||||
|
if tooltip is not None:
|
||||||
|
tip = gtk.Tooltips()
|
||||||
|
tip.set_tip(toolbutton, tooltip)
|
||||||
|
|
||||||
|
# Connect the 'clicked' event callback
|
||||||
|
toolbutton.connect("clicked", callback)
|
||||||
|
|
||||||
|
# Append the button to the toolbar
|
||||||
|
self.toolbar.insert(toolbutton, -1)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def add_separator(self, position=None):
|
||||||
|
"""Adds a separator toolitem"""
|
||||||
|
sep = gtk.SeparatorToolItem()
|
||||||
|
if position is not None:
|
||||||
|
self.toolbar.insert(sep, position)
|
||||||
|
else:
|
||||||
|
# Append the separator
|
||||||
|
self.toolbar.insert(sep, -1)
|
||||||
|
return
|
||||||
|
|
||||||
### Callbacks ###
|
### Callbacks ###
|
||||||
def on_toolbutton_add_clicked(self, data):
|
def on_toolbutton_add_clicked(self, data):
|
||||||
@ -88,16 +116,6 @@ class ToolBar:
|
|||||||
# Use the menubar's calbacks
|
# Use the menubar's calbacks
|
||||||
self.window.menubar.on_menuitem_resume_activate(data)
|
self.window.menubar.on_menuitem_resume_activate(data)
|
||||||
|
|
||||||
def on_toolbutton_queueup_clicked(self, data):
|
|
||||||
log.debug("on_toolbutton_queueup_clicked")
|
|
||||||
# Use the menubar's callbacks
|
|
||||||
self.window.menubar.on_menuitem_queueup_activate(data)
|
|
||||||
|
|
||||||
def on_toolbutton_queuedown_clicked(self, data):
|
|
||||||
log.debug("on_toolbutton_queuedown_clicked")
|
|
||||||
# Use the menubar's callbacks
|
|
||||||
self.window.menubar.on_menuitem_queuedown_activate(data)
|
|
||||||
|
|
||||||
def on_toolbutton_preferences_clicked(self, data):
|
def on_toolbutton_preferences_clicked(self, data):
|
||||||
log.debug("on_toolbutton_preferences_clicked")
|
log.debug("on_toolbutton_preferences_clicked")
|
||||||
# Use the menubar's callbacks
|
# Use the menubar's callbacks
|
||||||
|
@ -47,14 +47,14 @@ log = logging.getLogger("deluge")
|
|||||||
|
|
||||||
class TorrentView(listview.ListView):
|
class TorrentView(listview.ListView):
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
# Call the ListView constructor
|
|
||||||
listview.ListView.__init__(self)
|
|
||||||
log.debug("TorrentView Init..")
|
|
||||||
self.window = window
|
self.window = window
|
||||||
|
# Call the ListView constructor
|
||||||
|
listview.ListView.__init__(self,
|
||||||
|
self.window.main_glade.get_widget("torrent_view"))
|
||||||
|
log.debug("TorrentView Init..")
|
||||||
self.core = functions.get_core()
|
self.core = functions.get_core()
|
||||||
# Set the treeview used in listview with the one from our glade file
|
|
||||||
self.set_treeview(self.window.main_glade.get_widget("torrent_view"))
|
# Add the columns to the listview
|
||||||
|
|
||||||
self.add_text_column("torrent_id", hidden=True)
|
self.add_text_column("torrent_id", hidden=True)
|
||||||
self.add_texticon_column("Name")
|
self.add_texticon_column("Name")
|
||||||
self.add_func_column("Size",
|
self.add_func_column("Size",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user