Module: deluge
Branch: master
Commit: 0b2f2f2c8a803c8b1540890d47eb2380d6b23fea

Author: Andrew Resch <[email protected]>
Date:   Fri Sep  3 17:11:37 2010 -0700

Add TorrentFileCompleted event.

---

 deluge/core/torrentmanager.py |    8 ++++++++
 deluge/event.py               |   16 ++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py
index b0b230f..6346f32 100644
--- a/deluge/core/torrentmanager.py
+++ b/deluge/core/torrentmanager.py
@@ -196,6 +196,8 @@ class TorrentManager(component.Component):
             self.on_alert_metadata_received)
         self.alerts.register_handler("file_error_alert",
             self.on_alert_file_error)
+        self.alerts.register_handler("file_completed_alert",
+            self.on_alert_file_completed)
 
     def start(self):
         # Get the pluginmanager reference
@@ -1020,3 +1022,9 @@ class TorrentManager(component.Component):
         except:
             return
         torrent.update_state()
+
+    def on_alert_file_completed(self, alert):
+        log.debug("file_completed_alert: %s", alert.message())
+        torrent_id = str(alert.handle.info_hash())
+        component.get("EventManager").emit(
+            TorrentFileCompletedEvent(torrent_id, alert.index))
diff --git a/deluge/event.py b/deluge/event.py
index e36913b..4289990 100644
--- a/deluge/event.py
+++ b/deluge/event.py
@@ -164,6 +164,22 @@ class TorrentResumedEvent(DelugeEvent):
         """
         self._args = [torrent_id]
 
+class TorrentFileCompletedEvent(DelugeEvent):
+    """
+    Emitted when a file completes.
+
+    This will only work with libtorrent 0.15 or greater.
+
+    """
+    def __init__(self, torrent_id, index):
+        """
+        :param torrent_id: the torrent_id
+        :type torrent_id: string
+        :param index: the file index
+        :type index: int
+        """
+        self._args = [torrent_id, index]
+
 class NewVersionAvailableEvent(DelugeEvent):
     """
     Emitted when a more recent version of Deluge is available.

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to