[telepathy-ashes/master] Enabled file transfer code (currently broken).

David Laban david.laban at collabora.co.uk
Wed Oct 7 04:41:42 PDT 2009


---
 ashes/tools/echo_bot.py      |    4 ++-
 ashes/tools/file_transfer.py |   46 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletions(-)
 create mode 100644 ashes/tools/file_transfer.py

diff --git a/ashes/tools/echo_bot.py b/ashes/tools/echo_bot.py
index 04222b9..7a19e7e 100644
--- a/ashes/tools/echo_bot.py
+++ b/ashes/tools/echo_bot.py
@@ -19,6 +19,7 @@ from media_echoer import MediaChannelEchoer, IceEchoer
 from presence import PresenceEchoer, Onlineifier
 from groups import ContactAcceptor
 from text import TextChannelEchoer
+from file_transfer import FileTransferEchoer
 #TODO: wrap everything to 80 chars so that I can hack on my eeepc.
 
 
@@ -34,7 +35,8 @@ class EchoBot(  PresenceEchoer,
     into a nice tasty echo bot.
     """
     # Using python's name mangling to avoid name collisions.
-    __handler_classes = MediaChannelEchoer, ContactAcceptor, TextChannelEchoer
+    __channel_handler_classes = [MediaChannelEchoer, ContactAcceptor,
+        TextChannelEchoer, FileTransferEchoer]
 
 
 
diff --git a/ashes/tools/file_transfer.py b/ashes/tools/file_transfer.py
new file mode 100644
index 0000000..1fb1c24
--- /dev/null
+++ b/ashes/tools/file_transfer.py
@@ -0,0 +1,46 @@
+
+import telepathy
+
+from bases import ChannelListener
+from helper_functions import get_property, error_printer, printer, green
+
+class FileTransferEchoer(ChannelListener):
+    """
+    Automatically accepts file transfers and sends them back.
+    This might actually be easier with the help of a ConnectionLister subclass.
+    """
+    channel_type = 'org.freedesktop.Telepathy.Channel.Type.FileTransfer'
+    handle_type = telepathy.HANDLE_TYPE_CONTACT
+    capabilities_flag = 3 # send and receive
+
+    def __init__(self, connection, channel, properties):
+        ChannelListener.__init__(self, connection, channel, properties)
+        self.initial_offset = None
+        get_property(channel,
+            'org.freedesktop.Telepathy.Channel.Type.FileTransfer',
+            'State',
+            reply_handler=self.FileTransferStateChanged,
+            error_handler=error_printer("get_property(FileTransfer.state)"))
+
+    def FileTransferStateChanged(self, state, reason=0):
+        """Handles Channel.Interface.FileTransfer.FileTransferStateChanged"""
+        if state == 1: # Pending: incoming file.
+            offset = 0
+            self.channel.AcceptFile(address_type, access_control,
+                access_control_param, offset)
+        elif state == 2: # Accepted: outgoing file.
+            pass
+        elif state == 3: # Open
+            pass
+        elif state == 4: # Completed
+            pass
+        elif state == 5: # Cancelled
+            pass
+        else:
+            print "WTF: FileTransferStateChanged(%s, %s)" % (state, reason)
+
+    def InitialOffsetDefined(self, offset):
+        self.initial_offset = offset
+
+    def TransferredBytesChanged(self, count):
+        pass
-- 
1.5.6.5



More information about the telepathy-commits mailing list