use NEC to handle stanza arrived / sent events

This commit is contained in:
Yann Leboulanger 2010-11-09 20:58:11 +01:00
parent c4f5a8ceec
commit f5b38c8253
4 changed files with 30 additions and 18 deletions

View File

@ -611,9 +611,11 @@ class CommonConnection:
def _event_dispatcher(self, realm, event, data):
if realm == '':
if event == common.xmpp.transports_nb.DATA_RECEIVED:
self.dispatch('STANZA_ARRIVED', unicode(data, errors='ignore'))
gajim.nec.push_incoming_event(StanzaReceivedEvent(None,
conn=self, stanza_str=unicode(data, errors='ignore')))
elif event == common.xmpp.transports_nb.DATA_SENT:
self.dispatch('STANZA_SENT', unicode(data))
gajim.nec.push_incoming_event(StanzaSentEvent(None, conn=self,
stanza_str=unicode(data)))
def change_status(self, show, msg, auto=False):
if not msg:

View File

@ -1283,4 +1283,12 @@ class VcardPublishedEvent(nec.NetworkIncomingEvent):
class VcardNotPublishedEvent(nec.NetworkIncomingEvent):
name = 'vcard-not-published'
base_network_events = []
class StanzaReceivedEvent(nec.NetworkIncomingEvent):
name = 'stanza-received'
base_network_events = []
class StanzaSentEvent(nec.NetworkIncomingEvent):
name = 'stanza-sent'
base_network_events = []

View File

@ -3051,11 +3051,19 @@ class XMLConsoleWindow:
self.window.set_title(title)
self.window.show_all()
gajim.ged.register_event_handler('stanza-received', ged.GUI1,
self._nec_stanza_received)
gajim.ged.register_event_handler('stanza-sent', ged.GUI1,
self._nec_stanza_sent)
self.xml.connect_signals(self)
def on_xml_console_window_destroy(self, widget):
del gajim.interface.instances[self.account]['xml_console']
gajim.ged.remove_event_handler('stanza-received', ged.GUI1,
self._nec_stanza_received)
gajim.ged.remove_event_handler('stanza-sent', ged.GUI1,
self._nec_stanza_sent)
def on_clear_button_clicked(self, widget):
buffer_ = self.stanzas_log_textview.get_buffer()
@ -3143,6 +3151,16 @@ class XMLConsoleWindow:
if at_the_end:
gobject.idle_add(self.scroll_to_end)
def _nec_stanza_received(self, obj):
if obj.conn.name != self.account:
return
self.print_stanza(obj.stanza_str, 'incoming')
def _nec_stanza_sent(self, obj):
if obj.conn.name != self.account:
return
self.print_stanza(obj.stanza_str, 'outgoing')
def on_send_button_clicked(self, widget):
if gajim.connections[self.account].connected <= 1:
# if offline or connecting

View File

@ -1219,20 +1219,6 @@ class Interface:
notify.popup(event_type, jid, account, msg_type, path_to_image=path,
title=event_type, text=txt)
def handle_event_stanza_arrived(self, account, stanza):
if account not in self.instances:
return
if 'xml_console' in self.instances[account]:
self.instances[account]['xml_console'].print_stanza(stanza,
'incoming')
def handle_event_stanza_sent(self, account, stanza):
if account not in self.instances:
return
if 'xml_console' in self.instances[account]:
self.instances[account]['xml_console'].print_stanza(stanza,
'outgoing')
def ask_offline_status(self, account):
for contact in gajim.contacts.iter_contacts(account):
gajim.connections[account].request_last_status_time(contact.jid,
@ -1791,8 +1777,6 @@ class Interface:
'FILE_REQUEST': [self.handle_event_file_request],
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
'STANZA_ARRIVED': [self.handle_event_stanza_arrived],
'STANZA_SENT': [self.handle_event_stanza_sent],
'SIGNED_IN': [self.handle_event_signed_in],
'METACONTACTS': [self.handle_event_metacontacts],
'ATOM_ENTRY': [self.handle_atom_entry],