Reuse existing "TorrentAddedEvent" instead of creating a new one.
This commit is contained in:
parent
6cefb49f28
commit
63fa5bf85b
|
@ -476,23 +476,16 @@ class TorrentManager(component.Component):
|
|||
# Save the session state
|
||||
self.save_state()
|
||||
|
||||
# Emit signals
|
||||
# Emit torrent_added signal
|
||||
from_state = False
|
||||
if torrent_info and state is None:
|
||||
# Emit the torrent_added signal
|
||||
component.get("EventManager").emit(
|
||||
TorrentAddedEvent(torrent.torrent_id)
|
||||
)
|
||||
signal_type = "added"
|
||||
else:
|
||||
# Emit the torrent_loaded signal
|
||||
component.get("EventManager").emit(
|
||||
TorrentLoadedEvent(torrent.torrent_id)
|
||||
)
|
||||
signal_type = "loaded"
|
||||
|
||||
from_state = True
|
||||
component.get("EventManager").emit(
|
||||
TorrentAddedEvent(torrent.torrent_id, from_state)
|
||||
)
|
||||
log.info("Torrent %s %s by user: %s",
|
||||
torrent.get_status(["name"])["name"],
|
||||
signal_type,
|
||||
(from_state and "added" or "loaded"),
|
||||
component.get("RPCServer").get_session_user())
|
||||
return torrent.torrent_id
|
||||
|
||||
|
|
|
@ -79,24 +79,14 @@ class TorrentAddedEvent(DelugeEvent):
|
|||
"""
|
||||
Emitted when a new torrent is successfully added to the session.
|
||||
"""
|
||||
def __init__(self, torrent_id):
|
||||
def __init__(self, torrent_id, from_state):
|
||||
"""
|
||||
:param torrent_id: the torrent_id of the torrent that was added
|
||||
:type torrent_id: string
|
||||
:param from_state: was the torrent loaded from state? Or is it a new torrent.
|
||||
:type from_state: bool
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
|
||||
class TorrentLoadedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when an already managed torrent is loaded successfully and added to
|
||||
the session.
|
||||
"""
|
||||
def __init__(self, torrent_id):
|
||||
"""
|
||||
:param torrent_id: the torrent_id of the torrent that was added
|
||||
:type torrent_id: string
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
self._args = [torrent_id, from_state]
|
||||
|
||||
class TorrentRemovedEvent(DelugeEvent):
|
||||
"""
|
||||
|
|
|
@ -55,7 +55,6 @@ EXECUTE_COMMAND = 2
|
|||
|
||||
EVENT_MAP = {
|
||||
"complete": "TorrentFinishedEvent",
|
||||
"loaded": "TorrentLoadedEvent",
|
||||
"added": "TorrentAddedEvent"
|
||||
}
|
||||
|
||||
|
|
|
@ -110,8 +110,7 @@ class Core(CorePluginBase):
|
|||
|
||||
self.clean_initial_config()
|
||||
|
||||
component.get("EventManager").register_event_handler("TorrentLoadedEvent", self.post_torrent_load_or_add)
|
||||
component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_load_or_add)
|
||||
component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_add)
|
||||
component.get("EventManager").register_event_handler("TorrentRemovedEvent", self.post_torrent_remove)
|
||||
|
||||
#register tree:
|
||||
|
@ -133,7 +132,7 @@ class Core(CorePluginBase):
|
|||
return dict( [(label, 0) for label in self.labels.keys()])
|
||||
|
||||
## Plugin hooks ##
|
||||
def post_torrent_load_or_add(self, torrent_id):
|
||||
def post_torrent_add(self, torrent_id, from_state):
|
||||
log.debug("post_torrent_load_or_add")
|
||||
torrent = self.torrents[torrent_id]
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ class EventLog(component.Component):
|
|||
self.console = component.get("ConsoleUI")
|
||||
self.prefix = "{!event!}* "
|
||||
|
||||
client.register_event_handler("TorrentLoadedEvent", self.on_torrent_loaded_event)
|
||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event)
|
||||
client.register_event_handler("PreTorrentRemovedEvent", self.on_torrent_removed_event)
|
||||
client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed_event)
|
||||
|
@ -62,14 +61,11 @@ class EventLog(component.Component):
|
|||
client.register_event_handler("PluginEnabledEvent", self.on_plugin_enabled_event)
|
||||
client.register_event_handler("PluginDisabledEvent", self.on_plugin_disabled_event)
|
||||
|
||||
def on_torrent_loaded_event(self, torrent_id):
|
||||
def on_torrent_added_event(self, torrent_id, from_state):
|
||||
def on_torrent_status(status):
|
||||
self.console.write(self.prefix + "TorrentLoaded: {!info!}%s (%s)" % (status["name"], torrent_id))
|
||||
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
|
||||
|
||||
def on_torrent_added_event(self, torrent_id):
|
||||
def on_torrent_status(status):
|
||||
self.console.write(self.prefix + "TorrentAdded: {!info!}%s (%s)" % (status["name"], torrent_id))
|
||||
self.console.write(self.prefix + "TorrentAdded(from_state=%s): {!info!}%s (%s)" % (
|
||||
from_state, status["name"], torrent_id)
|
||||
)
|
||||
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
|
||||
|
||||
def on_torrent_removed_event(self, torrent_id):
|
||||
|
|
|
@ -241,8 +241,7 @@ class ConsoleUI(component.Component):
|
|||
client.core.get_session_state().addCallback(on_session_state)
|
||||
|
||||
# Register some event handlers to keep the torrent list up-to-date
|
||||
client.register_event_handler("TorrentLoadedEvent", self.on_torrent_loaded_or_added_event)
|
||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_loaded_or_added_event)
|
||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event)
|
||||
client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed_event)
|
||||
|
||||
def update(self):
|
||||
|
@ -440,7 +439,7 @@ class ConsoleUI(component.Component):
|
|||
|
||||
return ret
|
||||
|
||||
def on_torrent_loaded_or_added_event(self, torrent_id):
|
||||
def on_torrent_added_event(self, torrent_id, from_state):
|
||||
def on_torrent_status(status):
|
||||
self.torrents.append((torrent_id, status["name"]))
|
||||
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
|
||||
|
|
|
@ -67,8 +67,7 @@ class SessionProxy(component.Component):
|
|||
|
||||
client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed)
|
||||
client.register_event_handler("TorrentRemovedEvent", self.on_torrent_removed)
|
||||
client.register_event_handler("TorrentLoadedEvent", self.on_torrent_loaded_or_added)
|
||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_loaded_or_added)
|
||||
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added)
|
||||
|
||||
def start(self):
|
||||
def on_torrent_status(status):
|
||||
|
@ -241,7 +240,7 @@ class SessionProxy(component.Component):
|
|||
self.torrents[torrent_id][1]["state"] = state
|
||||
self.cache_times[torrent_id]["state"] = time.time()
|
||||
|
||||
def on_torrent_loaded_or_added(self, torrent_id):
|
||||
def on_torrent_added(self, torrent_id, from_state):
|
||||
self.torrents[torrent_id] = [time.time() - self.cache_time - 1, {}]
|
||||
self.cache_times[torrent_id] = {}
|
||||
def on_status(status):
|
||||
|
|
Loading…
Reference in New Issue