Queue plugin updates.

This commit is contained in:
Andrew Resch 2007-11-04 23:54:38 +00:00
parent eacc6dd08f
commit cfc05729ee
8 changed files with 45 additions and 32 deletions

View File

@ -179,7 +179,7 @@ class Core(
self.torrents = TorrentManager(self.session, self.alerts) self.torrents = TorrentManager(self.session, self.alerts)
# Load plugins # Load plugins
self.plugins = PluginManager() self.plugins = PluginManager(self)
# Register alert handlers # Register alert handlers
self.alerts.register_handler("torrent_paused_alert", self.alerts.register_handler("torrent_paused_alert",

View File

@ -40,7 +40,8 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
"""PluginManager handles the loading of plugins and provides plugins with """PluginManager handles the loading of plugins and provides plugins with
functions to access parts of the core.""" functions to access parts of the core."""
def __init__(self): def __init__(self, core):
self.core = core
# Set up the hooks dictionary # Set up the hooks dictionary
self.hooks = { self.hooks = {
"post_torrent_add": [], "post_torrent_add": [],
@ -53,6 +54,10 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
deluge.pluginmanagerbase.PluginManagerBase.__init__( deluge.pluginmanagerbase.PluginManagerBase.__init__(
self, "core.conf", "deluge.plugin.core") self, "core.conf", "deluge.plugin.core")
def get_core(self):
"""Returns a reference to the core"""
return self.core
def register_status_field(self, field, function): def register_status_field(self, field, function):
"""Register a new status field. This can be used in the same way the """Register a new status field. This can be used in the same way the
client requests other status information from core.""" client requests other status information from core."""

View File

@ -107,7 +107,7 @@ class PluginManagerBase:
for name in egg.get_entry_map(self.entry_name): for name in egg.get_entry_map(self.entry_name):
entry_point = egg.get_entry_info(self.entry_name, name) entry_point = egg.get_entry_info(self.entry_name, name)
cls = entry_point.load() cls = entry_point.load()
instance = cls(self) instance = cls(self, plugin_name.replace("-", "_"))
instance.enable() instance.enable()
plugin_name = plugin_name.replace("-", " ") plugin_name = plugin_name.replace("-", " ")
self.plugins[plugin_name] = instance self.plugins[plugin_name] = instance

View File

@ -36,19 +36,19 @@ from deluge.log import LOG as log
from deluge.plugins.init import PluginBase from deluge.plugins.init import PluginBase
class CorePlugin(PluginBase): class CorePlugin(PluginBase):
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
# Load the Core portion of the plugin # Load the Core portion of the plugin
try: try:
from core import Core from core import Core
self.plugin = Core(plugin_api) self.plugin = Core(plugin_api, plugin_name)
except Exception, e: except Exception, e:
log.debug("Did not load a Core plugin: %s", e) log.debug("Did not load a Core plugin: %s", e)
class GtkUIPlugin(PluginBase): class GtkUIPlugin(PluginBase):
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
# Load the GtkUI portion of the plugin # Load the GtkUI portion of the plugin
try: try:
from gtkui import GtkUI from gtkui import GtkUI
self.plugin = GtkUI(plugin_api) self.plugin = GtkUI(plugin_api, plugin_name)
except Exception, e: except Exception, e:
log.debug("Did not load a GtkUI plugin: %s", e) log.debug("Did not load a GtkUI plugin: %s", e)

View File

@ -33,13 +33,9 @@
from torrentqueue import TorrentQueue from torrentqueue import TorrentQueue
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.plugins.corepluginbase import CorePluginBase
class Core: class Core(CorePluginBase):
def __init__(self, plugin_api):
# Get the plugin_api
self.plugin = plugin_api
log.info("Queue Core plugin initialized..")
def enable(self): def enable(self):
# Instantiate the TorrentQueue object # Instantiate the TorrentQueue object
self.queue = TorrentQueue() self.queue = TorrentQueue()
@ -90,7 +86,7 @@ class Core:
try: try:
# If the queue method returns True, then we should emit a signal # If the queue method returns True, then we should emit a signal
if self.queue.top(torrent_id): if self.queue.top(torrent_id):
self.torrent_queue_changed() self._torrent_queue_changed()
except KeyError: except KeyError:
log.warning("torrent_id: %s does not exist in the queue", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@ -100,7 +96,7 @@ class Core:
try: try:
# If the queue method returns True, then we should emit a signal # If the queue method returns True, then we should emit a signal
if self.queue.up(torrent_id): if self.queue.up(torrent_id):
self.torrent_queue_changed() self._torrent_queue_changed()
except KeyError: except KeyError:
log.warning("torrent_id: %s does not exist in the queue", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@ -110,7 +106,7 @@ class Core:
try: try:
# If the queue method returns True, then we should emit a signal # If the queue method returns True, then we should emit a signal
if self.queue.down(torrent_id): if self.queue.down(torrent_id):
self.torrent_queue_changed() self._torrent_queue_changed()
except KeyError: except KeyError:
log.warning("torrent_id: %s does not exist in the queue", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@ -120,7 +116,7 @@ class Core:
try: try:
# If the queue method returns True, then we should emit a signal # If the queue method returns True, then we should emit a signal
if self.queue.bottom(torrent_id): if self.queue.bottom(torrent_id):
self.torrent_queue_changed() self._torrent_queue_changed()
except KeyError: except KeyError:
log.warning("torrent_id: %s does not exist in the queue", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)

View File

@ -37,10 +37,10 @@ from deluge.log import LOG as log
import ui import ui
class GtkUI(ui.UI): class GtkUI(ui.UI):
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
log.debug("Calling UI init") log.debug("Calling UI init")
# Call UI constructor # Call UI constructor
ui.UI.__init__(self, plugin_api) ui.UI.__init__(self, plugin_api, plugin_name)
log.debug("Queue GtkUI plugin initalized..") log.debug("Queue GtkUI plugin initalized..")
def load_interface(self): def load_interface(self):
@ -73,7 +73,7 @@ class GtkUI(ui.UI):
position=0, position=0,
status_field=["queue"]) status_field=["queue"])
# Update the new column right away # Update the new column right away
self.update_interface() self.update()
# Add a toolbar buttons # Add a toolbar buttons
self.toolbar_sep = self.plugin.add_toolbar_separator() self.toolbar_sep = self.plugin.add_toolbar_separator()
@ -105,5 +105,5 @@ class GtkUI(ui.UI):
self.plugin.remove_toolbar_button(self.toolbutton_down) self.plugin.remove_toolbar_button(self.toolbutton_down)
self.plugin.remove_torrentview_column("#") self.plugin.remove_torrentview_column("#")
def update_interface(self): def update(self):
self.plugin.update_torrent_view(["#"]) self.plugin.update_torrent_view(["#"])

View File

@ -34,10 +34,11 @@
import gettext import gettext
import locale import locale
import pkg_resources import pkg_resources
import deluge.ui.client as client
from deluge.log import LOG as log from deluge.log import LOG as log
class UI: class UI:
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
self.plugin = plugin_api self.plugin = plugin_api
# Initialize gettext # Initialize gettext
locale.setlocale(locale.LC_MESSAGES, '') locale.setlocale(locale.LC_MESSAGES, '')
@ -67,7 +68,7 @@ class UI:
def unload_interface(self): def unload_interface(self):
pass pass
def update_interface(self): def update(self):
pass pass
## Menu callbacks ## ## Menu callbacks ##
@ -76,7 +77,10 @@ class UI:
# Get the selected torrents # Get the selected torrents
torrent_ids = self.plugin.get_selected_torrents() torrent_ids = self.plugin.get_selected_torrents()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
self.core.queue_top(torrent_id) try:
client.get_core().queue_queue_top(torrent_id)
except Exception, e:
log.debug("Unable to queue top torrent: %s", e)
return return
def on_queueup_activate(self, data=None): def on_queueup_activate(self, data=None):
@ -84,7 +88,10 @@ class UI:
# Get the selected torrents # Get the selected torrents
torrent_ids = self.plugin.get_selected_torrents() torrent_ids = self.plugin.get_selected_torrents()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
self.core.queue_up(torrent_id) try:
client.get_core().queue_queue_up(torrent_id)
except Exception, e:
log.debug("Unable to queue up torrent: %s", e)
return return
def on_queuedown_activate(self, data=None): def on_queuedown_activate(self, data=None):
@ -92,7 +99,10 @@ class UI:
# Get the selected torrents # Get the selected torrents
torrent_ids = self.plugin.get_selected_torrents() torrent_ids = self.plugin.get_selected_torrents()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
self.core.queue_down(torrent_id) try:
client.get_core().queue_queue_down(torrent_id)
except Exception, e:
log.debug("Unable to queue down torrent: %s", e)
return return
def on_queuebottom_activate(self, data=None): def on_queuebottom_activate(self, data=None):
@ -100,7 +110,10 @@ class UI:
# Get the selected torrents # Get the selected torrents
torrent_ids = self.plugin.get_selected_torrents() torrent_ids = self.plugin.get_selected_torrents()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
self.core.queue_bottom(torrent_id) try:
client.get_core().queue_queue_bottom(torrent_id)
except Exception, e:
log.debug("Unable to queue bottom torrent: %s", e)
return return
## Signals ## ## Signals ##
@ -110,7 +123,6 @@ class UI:
""" """
log.debug("torrent_queue_changed signal received..") log.debug("torrent_queue_changed signal received..")
# We only need to update the queue column # We only need to update the queue column
# self.torrentview.update(["#"]) self.update()
self.update_interface()
return return

View File

@ -36,16 +36,16 @@ from deluge.log import LOG as log
from deluge.plugins.init import PluginBase from deluge.plugins.init import PluginBase
class CorePlugin(PluginBase): class CorePlugin(PluginBase):
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
# Load the Core portion of the plugin # Load the Core portion of the plugin
try: try:
from core import Core from core import Core
self.plugin = Core(plugin_api) self.plugin = Core(plugin_api, plugin_name)
except: except:
pass pass
class GtkUIPlugin(PluginBase): class GtkUIPlugin(PluginBase):
def __init__(self, plugin_api): def __init__(self, plugin_api, plugin_name):
# Load the GtkUI portion of the plugin # Load the GtkUI portion of the plugin
try: try:
from gtkui import GtkUI from gtkui import GtkUI