From a8eedfc7817addb526e29a65220a11b55bfa8889 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sat, 26 Sep 2009 10:29:08 +0200 Subject: [PATCH] ability to accept contents and not only session --- data/glade/voip_call_received_dialog.glade | 2 +- src/common/events.py | 2 +- src/common/jingle.py | 1 + src/dialogs.py | 53 ++++++++++++++++------ src/gajim.py | 28 +++++++----- 5 files changed, 59 insertions(+), 27 deletions(-) diff --git a/data/glade/voip_call_received_dialog.glade b/data/glade/voip_call_received_dialog.glade index d2afca0a9..b4314fe22 100644 --- a/data/glade/voip_call_received_dialog.glade +++ b/data/glade/voip_call_received_dialog.glade @@ -13,7 +13,7 @@ yes-no <b><big>Incoming call</big></b> True - %(contact)s wants to start a voice chat with you. Do you want to answer the call? + diff --git a/src/common/events.py b/src/common/events.py index 88593cf45..c69fc27d1 100644 --- a/src/common/events.py +++ b/src/common/events.py @@ -46,7 +46,7 @@ class Event: gc-invitation: [room_jid, reason, password, is_continued] subscription_request: [text, nick] unsubscribed: contact - jingle-*: (fulljid, sessionid) + jingle-incoming: (fulljid, sessionid, content_types) ''' self.type_ = type_ self.time_ = time_ diff --git a/src/common/jingle.py b/src/common/jingle.py index 7d7d0677e..2f533dd2b 100644 --- a/src/common/jingle.py +++ b/src/common/jingle.py @@ -54,6 +54,7 @@ import gajim import xmpp +import helpers import farsight, gst diff --git a/src/dialogs.py b/src/dialogs.py index 0ad73314b..b96220433 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -4443,14 +4443,14 @@ class GPGInfoWindow: self.window.destroy() class VoIPCallReceivedDialog(object): - instances = WeakValueDictionary() + instances = {} - def __init__(self, account, contact_jid, sid): + def __init__(self, account, contact_jid, sid, content_types): + self.instances[(contact_jid, sid)] = self self.account = account self.fjid = contact_jid self.sid = sid - - self.instances[(contact_jid, sid)] = self + self.content_types = content_types xml = gtkgui_helpers.get_glade('voip_call_received_dialog.glade') xml.signal_autoconnect(self) @@ -4458,17 +4458,14 @@ class VoIPCallReceivedDialog(object): jid = gajim.get_jid_without_resource(self.fjid) contact = gajim.contacts.get_first_contact_from_jid(account, jid) if contact and contact.name: - contact_text = '%s (%s)' % (contact.name, jid) + self.contact_text = '%s (%s)' % (contact.name, jid) else: - contact_text = contact_jid + self.contact_text = contact_jid - # do the substitution - dialog = xml.get_widget('voip_call_received_messagedialog') - dialog.set_property('secondary-text', - dialog.get_property('secondary-text') % {'contact': contact_text}) - self._dialog = dialog + self.dialog = xml.get_widget('voip_call_received_messagedialog') + self.set_secondary_text() - dialog.show_all() + self.dialog.show_all() @classmethod def get_dialog(cls, jid, sid): @@ -4477,6 +4474,29 @@ class VoIPCallReceivedDialog(object): else: return None + def set_secondary_text(self): + if 'audio' in self.content_types and 'video' in self.content_types: + types_text = _('an audio and video') + elif 'audio' in self.content_types: + types_text = _('an audio') + elif 'video' in self.content_types: + types_text = _('a video') + + # do the substitution + self.dialog.set_property('secondary-text', + _('%(contact)s wants to start %(type)s session with you. Do you want ' + 'to answer the call?') % {'contact': self.contact_text, 'type': types_text}) + + def add_contents(self, content_types): + for type_ in content_types: + if type_ not in self.content_types: + self.content_types.append(type_) + self.set_secondary_text() + + def on_voip_call_received_messagedialog_destroy(self, dialog): + if (self.fjid, self.sid) in self.instances: + del self.instances[(self.fjid, self.sid)] + def on_voip_call_received_messagedialog_close(self, dialog): return self.on_voip_call_received_messagedialog_response(dialog, gtk.RESPONSE_NO) @@ -4485,8 +4505,13 @@ class VoIPCallReceivedDialog(object): # we've got response from user, either stop connecting or accept the call session = gajim.connections[self.account].get_jingle_session(self.fjid, self.sid) - if response==gtk.RESPONSE_YES: - session.approve_session() + if not session: + return + if response == gtk.RESPONSE_YES: + if not session.accepted: + session.approve_session() + for content in self.content_types: + session.approve_content(content) jid = gajim.get_jid_without_resource(self.fjid) resource = gajim.get_resource_from_jid(self.fjid) ctrl = gajim.interface.msg_win_mgr.get_control(self.fjid, self.account) diff --git a/src/gajim.py b/src/gajim.py index cc4abe2b5..15733dc81 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -2098,7 +2098,7 @@ class Interface: # ('JINGLE_INCOMING', account, peer jid, sid, tuple-of-contents==(type, # data...)) # TODO: conditional blocking if peer is not in roster - + # unpack data peerjid, sid, contents = data content_types = set(c[0] for c in contents) @@ -2124,11 +2124,17 @@ class Interface: if 'video' in content_types: ctrl.set_video_state('connection_received', sid) - if helpers.allow_popup_window(account): - dialogs.VoIPCallReceivedDialog(account, peerjid, sid) + dlg = dialogs.VoIPCallReceivedDialog.get_dialog(peerjid, sid) + if dlg: + dlg.add_contents(content_types) return - self.add_event(account, peerjid, 'voip-incoming', (peerjid, sid,)) + if helpers.allow_popup_window(account): + dialogs.VoIPCallReceivedDialog(account, peerjid, sid, content_types) + return + + self.add_event(account, peerjid, 'jingle-incoming', (peerjid, sid, + content_types)) if helpers.allow_showing_notification(account): # TODO: we should use another pixmap ;-) @@ -2138,7 +2144,7 @@ class Interface: account, peerjid) path = gtkgui_helpers.get_path_to_generic_or_avatar(img) event_type = _('Voice Chat Request') - notify.popup(event_type, peerjid, account, 'voip-incoming', + notify.popup(event_type, peerjid, account, 'jingle-incoming', path_to_image = path, title = event_type, text = txt) def handle_event_jingle_connected(self, account, data): @@ -2169,7 +2175,7 @@ class Interface: ctrl.set_video_state('stop', sid=sid, reason=reason) dialog = dialogs.VoIPCallReceivedDialog.get_dialog(peerjid, sid) if dialog: - dialog._dialog.destroy() + dialog.dialog.destroy() def handle_event_jingle_error(self, account, data): # ('JINGLE_ERROR', account, (peerjid, sid, reason)) @@ -2457,7 +2463,7 @@ class Interface: jid = gajim.get_jid_without_resource(jid) no_queue = len(gajim.events.get_events(account, jid)) == 0 # type_ can be gc-invitation file-send-error file-error file-request-error - # file-request file-completed file-stopped voip-incoming + # file-request file-completed file-stopped jingle-incoming # event_type can be in advancedNotificationWindow.events_list event_types = {'file-request': 'ft_request', 'file-completed': 'ft_finished'} @@ -2617,10 +2623,10 @@ class Interface: self.show_unsubscribed_dialog(account, contact) gajim.events.remove_events(account, jid, event) self.roster.draw_contact(jid, account) - elif type_ == 'voip-incoming': - event = gajim.events.get_first_event(account, jid, type_) - peerjid, sid = event.parameters - dialogs.VoIPCallReceivedDialog(account, peerjid, sid) + elif type_ == 'jingle-incoming': + event = gajim.events.get_first_event(account, jid, type_) + peerjid, sid, content_types = event.parameters + dialogs.VoIPCallReceivedDialog(account, peerjid, sid, content_types) gajim.events.remove_events(account, jid, event) if w: w.set_active_tab(ctrl)