From 37a315ac9d0f73a9adc7b1344216f17d42178038 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 5 Aug 2005 23:43:28 +0000 Subject: [PATCH] xml console now print everything that is sent/received --- src/common/connection.py | 8 ++++++-- src/common/xmpp/transports.py | 6 +++++- src/dialogs.py | 38 ++++++++++++----------------------- src/gajim.py | 7 ++++++- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 0b062b31b..f7f558db5 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -127,7 +127,7 @@ class Connection: 'GC_SUBJECT': [], 'GC_CONFIG': [], 'BAD_PASSPHRASE': [], 'ROSTER_INFO': [], 'ERROR_ANSWER': [], 'BOOKMARKS': [], 'CON_TYPE': [], 'FILE_REQUEST': [], 'FILE_RCV_COMPLETED': [], 'FILE_PROGRESS': [], - 'STANZA_ARRIVED': [], 'HTTP_AUTH': [] + 'STANZA_ARRIVED': [], 'STANZA_SENT': [], 'HTTP_AUTH': [] } self.name = name self.connected = 0 # offline @@ -887,7 +887,6 @@ class Connection: self.dispatch('ERROR_ANSWER', (id, jid_from, errmsg, errcode)) def _StanzaArrivedCB(self, con, obj): - self.dispatch('STANZA_ARRIVED', str(obj)) self.last_incoming = time.time() self.keep_alive_sent = False @@ -917,6 +916,11 @@ class Connection: self.new_account_info = None return self.dispatch('REGISTER_AGENT_INFO', (data[0], data[1].asDict())) + elif realm == '': + if event == common.xmpp.transports.DATA_RECEIVED: + self.dispatch('STANZA_ARRIVED', str(data)) + elif event == common.xmpp.transports.DATA_SENT: + self.dispatch('STANZA_SENT', str(data)) def connect(self): """Connect and authenticate to the Jabber server diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index 0badc8b83..9095df2bf 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -36,7 +36,9 @@ try: import dns.resolver except: pass - + +DATA_RECEIVED='DATA RECEIVED' +DATA_SENT='DATA SENT' class error: """An exception to be raised in case of low-level errors in methods of 'transports' module.""" @@ -129,6 +131,7 @@ class TCPsocket(PlugIn): if len(received): # length of 0 means disconnect self.DEBUG(received,'got') + self._owner.Dispatcher.Event('', DATA_RECEIVED, received) else: self.DEBUG('Socket error while receiving data','error') self._owner.disconnected() @@ -142,6 +145,7 @@ class TCPsocket(PlugIn): try: self._send(raw_data) self.DEBUG(raw_data,'sent') + self._owner.Dispatcher.Event('', DATA_SENT, raw_data) except: self.DEBUG("Socket error while sending data",'error') self._owner.disconnected() diff --git a/src/dialogs.py b/src/dialogs.py index 177810111..86707cde6 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1321,31 +1321,18 @@ class XMLConsoleWindow: self.window = self.xml.get_widget('xml_console_window') self.input_textview = self.xml.get_widget('input_textview') self.stanzas_log_textview = self.xml.get_widget('stanzas_log_textview') - self.input_tv_buffer = self.input_textview.get_buffer() - self.input_textview.modify_base( - gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) - self.input_textview.modify_text( - gtk.STATE_NORMAL, gtk.gdk.color_parse('green')) - - - #st = self.input_textview.get_style() - - - #style = gtk.Style() - #style.font_desc = st.font_desc - - #self.input_textview.set_name('input') - #s = '''\ -#style "console" { GtkTextView::cursor-color="%s" } -#widget "*.*.input" style : application "console"''' % '#FFFFFF' - #gtk.rc_parse_string(s) - - - self.stanzas_log_textview.modify_base( - gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) + buffer = self.stanzas_log_textview.get_buffer() + self.tagIn = buffer.create_tag('incoming') + color = gajim.config.get('inmsgcolor') + self.tagIn.set_property('foreground', color) + self.tagOut = buffer.create_tag('outgoing') + color = gajim.config.get('outmsgcolor') + self.tagOut.set_property('foreground', color) + + self.stanzas_log_textview.modify_text( - gtk.STATE_NORMAL, gtk.gdk.color_parse('green')) + gtk.STATE_NORMAL, gtk.gdk.color_parse(color)) if len(gajim.connections) > 1: title = _('XML Console for %s') % self.account @@ -1357,10 +1344,11 @@ class XMLConsoleWindow: self.xml.signal_autoconnect(self) self.window.show_all() - def print_incomming_stanza(self, stanza): + def print_stanza(self, stanza, tag): + # tag must be 'incoming' or 'outgoing' buffer = self.stanzas_log_textview.get_buffer() end_iter = buffer.get_end_iter() - buffer.insert(end_iter, stanza) + buffer.insert_with_tags_by_name(end_iter, stanza + '\n\n', tag) def on_send_button_clicked(self, widget): begin_iter, end_iter = self.input_tv_buffer.get_bounds() diff --git a/src/gajim.py b/src/gajim.py index 749845e9b..c92514adc 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -773,7 +773,11 @@ class Interface: def handle_event_stanza_arrived(self, account, stanza): if self.windows[account].has_key('xml_console'): - self.windows[account]['xml_console'].print_incomming_stanza(stanza) + self.windows[account]['xml_console'].print_stanza(stanza, 'incoming') + + def handle_event_stanza_sent(self, account, stanza): + if self.windows[account].has_key('xml_console'): + self.windows[account]['xml_console'].print_stanza(stanza, 'outgoing') def read_sleepy(self): '''Check idle status and change that status if needed''' @@ -942,6 +946,7 @@ class Interface: con.register_handler('CON_TYPE', self.handle_event_con_type) con.register_handler('FILE_REQUEST', self.handle_event_file_request) con.register_handler('STANZA_ARRIVED', self.handle_event_stanza_arrived) + con.register_handler('STANZA_SENT', self.handle_event_stanza_sent) def process_connections(self): try: