[Telepathy-commits] [mingle/master] Polish the UI, keep track of jinglesession so we can terminate them

Sjoerd Simons sjoerd at luon.net
Tue Nov 11 11:10:05 PST 2008


---
 mingle-client.py |   69 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/mingle-client.py b/mingle-client.py
index 18d6296..5fc183f 100644
--- a/mingle-client.py
+++ b/mingle-client.py
@@ -38,6 +38,7 @@ except ImportError, e:
 class VideoSink(gtk.DrawingArea):
     def __init__(self, pipeline):
         gtk.DrawingArea.__init__(self)
+        self.set_double_buffered(False)
         self.set_size_request (320, 240)
         self.sink = gst.element_factory_make("xvimagesink")
         self.sink.set_property("force-aspect-ratio", True)
@@ -77,38 +78,71 @@ class VideoSink(gtk.DrawingArea):
 
 
 class UI(gtk.Window):
+    WIDTH = 340
+    HEIGHT = 260
     def __init__(self, jid, conference):
         gtk.Window.__init__(self)
         self.connect('destroy', lambda x: reactor.stop())
-        #self.set_size_request(320, 240)
         self.hbox = gtk.HBox()
         self.add(self.hbox)
+        self.outputs = {}
 
-        self.label = gtk.Label("Waiting for video streams...")
+        self.label = gtk.Label("Waiting for other participants...")
+        self.label.set_size_request(self.WIDTH, self.HEIGHT)
         self.hbox.add(self.label)
         self.conference = conference
         self.set_title(jid.userhost())
 
         self.show_all()
 
-    def add_video_output(self, label, pad):
+    def add_output(self, name):
         gtk.gdk.threads_enter()
         if self.label:
             self.hbox.remove(self.label)
             self.label = None
 
-        frame = gtk.Frame(label)
+        assert not self.outputs.has_key(name)
+
+        frame = gtk.Frame(name)
         frame.set_border_width(3)
-        vsink = VideoSink(self.conference)
+        label = gtk.Label("Waiting for video streams...")
+        label.set_size_request(320, 240)
+        frame.add(label)
+
+        self.outputs[name] = frame
+
+        self.hbox.pack_start(frame, False, False, 3)
+        frame.show_all()
+
+        gtk.gdk.threads_leave()
+
+    def remove_output (self, name):
+        frame = self.outputs.pop(name)
+        self.hbox.remove(frame)
+        if len(self.outputs) == 0:
+            self.label = gtk.Label("Waiting for other participants...")
+            self.hbox.add(self.label)
+            self.hbox.show_all()
+
+        self.resize(self.WIDTH, self.HEIGHT)
+
+    def add_video_output(self, name, stream, pad):
+        gtk.gdk.threads_enter()
 
-        self.hbox.add(frame)
+        frame = self.outputs[name]
+
+        if type(frame.get_child()) == gtk.Label:
+            frame.remove(frame.get_child())
+
+        vsink = VideoSink(self.conference)
         frame.add(vsink)
         frame.show_all()
 
-        vsink.sink.set_state(gst.STATE_PLAYING)
+        stream.add_sink (vsink.sink)
+
         self.conference.add(vsink.sink)
-        vsink.sink.set_state(gst.STATE_PLAYING)
         pad.link(vsink.sink.get_pad("sink"))
+        vsink.sink.set_state(gst.STATE_PLAYING)
 
         gtk.gdk.threads_leave()
 
@@ -123,6 +157,7 @@ class Muc:
         self.state = Muc.PREPARING
         self.members = []
         self.conference = jingle.JingleConference()
+        self.jingle_sessions = {}
         self.mingle_presences = {}
 
         self.my_jid = JID('%s/%s' % (self.jid.userhost(),
@@ -145,15 +180,27 @@ class Muc:
         client.add_iq_handler('set', ns.JINGLE, 'jingle',
             self.jingle_iq_received)
 
+        self.client.resourceOffline.addCallback(False, self.resource_offline)
+
+    def resource_offline(self, contact):
+        if self.jingle_sessions.has_key(contact):
+            self.jingle_sessions.pop(contact).terminate()
+            self.ui.remove_output(contact.jid.full())
+
     def jingle_iq_received(self, iq):
         j = xpath.queryForNodes('/iq/jingle', iq)[0]
         if j['action'] != 'session-initiate':
             return None
 
+        jid = JID(iq['from'])
+        contact = self.client.get_contact (jid)
+
         session = jingle.JingleSession(self.client, self.conference)
+        self.jingle_sessions[contact] = session
 
+        self.ui.add_output (jid.full())
         return session.handle_session_initiate (iq,
-            self.client.get_contact (JID(iq['from'])))
+            self.client.get_contact (jid))
 
     def new_stream(self, participant, stream):
         if stream.session.type == farsight.MEDIA_TYPE_VIDEO:
@@ -161,7 +208,7 @@ class Muc:
                 self.new_video_output(participant, stream, pad, codec)
 
     def new_video_output(self, participant, stream, pad, codec):
-        self.ui.add_video_output(participant.cname, pad)
+        self.ui.add_video_output(participant.cname, stream, pad)
 
     def join(self):
         self.state = Muc.JOINING
@@ -230,8 +277,10 @@ class Muc:
 
         for jid in self.mingle_presences.iterkeys():
             print "Calling: %s" % jid.full()
+            self.ui.add_output (jid.full())
             session = jingle.JingleSession (self.client, self.conference)
             contact = self.client.get_contact (jid)
+            self.jingle_sessions[contact] = session
             session.initiate(contact)
 
     def participant_got_stream (self, stream, session, description):
-- 
1.5.6.5




More information about the Telepathy-commits mailing list