Commit a0f655f2 authored by Philipp Hörist's avatar Philipp Hörist

Refactor printing info and status messages

Add some methods to ChatControlBase to add status and info message to the ConversationTextview instead of going through
print_conversation() and print_conversation_line() which adds nothing to info and status messages
parent 603ad003
......@@ -560,7 +560,7 @@ class ChatControl(ChatControlBase):
if state in ('connecting', 'connected', 'stop', 'error') and reason:
info = _('%(type)s state : %(state)s, reason: %(reason)s') % {
'type': jingle_type.capitalize(), 'state': state, 'reason': reason}
self.print_conversation(info, 'info')
self.add_info_message(info)
states = {'connecting': self.JINGLE_STATE_CONNECTING,
'connection_received': self.JINGLE_STATE_CONNECTION_RECEIVED,
......@@ -967,17 +967,9 @@ class ChatControl(ChatControlBase):
if additional_data is None:
additional_data = AdditionalDataDict()
if frm == 'status':
if not app.config.get('print_status_in_chats'):
return
kind = 'status'
name = ''
elif frm == 'error':
if frm == 'error':
kind = 'error'
name = ''
elif frm == 'info':
kind = 'info'
name = ''
else:
if not frm:
kind = 'incoming'
......@@ -1217,12 +1209,12 @@ class ChatControl(ChatControlBase):
if self.contact != obj.contact:
return
if obj.name == 'ping-sent':
self.print_conversation(_('Ping?'), 'status')
self.add_info_message(_('Ping?'))
elif obj.name == 'ping-reply':
self.print_conversation(
_('Pong! (%s seconds)') % obj.seconds, 'status')
self.add_info_message(
_('Pong! (%s seconds)') % obj.seconds)
elif obj.name == 'ping-error':
self.print_conversation(_('Error.'), 'status')
self.add_info_message(_('Error.'))
def show_avatar(self):
if not app.config.get('show_avatar_in_chat'):
......@@ -1422,11 +1414,14 @@ class ChatControl(ChatControlBase):
self.update_ui()
self.parent_win.redraw_tab(self)
if not app.config.get('print_status_in_chats'):
return
if status:
status = '- %s' % status
status_line = _('%(name)s is now %(show)s %(status)s') % {
'name': name, 'show': uf_show, 'status': status or ''}
self.print_conversation(status_line, 'status')
self.add_status_message(status_line)
def _info_bar_show_message(self):
if self.info_bar.get_visible():
......
......@@ -922,6 +922,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
else:
self.received_history_pos = pos
def add_info_message(self, text):
jid = self.contact.jid
self.conv_textview.print_conversation_line(
text, jid, 'info', '', None, graphics=False)
def add_status_message(self, text):
jid = self.contact.jid
self.conv_textview.print_conversation_line(
text, jid, 'status', '', None)
def print_conversation_line(self, text, kind, name, tim,
other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None,
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
......
......@@ -226,7 +226,7 @@ class Message(BaseModule):
if not event.msgtxt:
event.msgtxt = _('message')
if event.gc_control:
event.gc_control.print_conversation(event.msgtxt)
event.gc_control.add_info_message(event.msgtxt)
else:
self._log_error_message(event)
error_msg = event.stanza.getErrorMsg() or event.msgtxt
......
This diff is collapsed.
......@@ -206,7 +206,7 @@ class Interface:
ctrl = self.msg_win_mgr.get_control(event.properties.jid.getBare(),
event.account)
if ctrl and ctrl.type_id == message_control.TYPE_GC:
ctrl.print_conversation('Error: %s' % event.properties.error)
ctrl.add_info_message('Error: %s' % event.properties.error)
@staticmethod
def handle_event_connection_lost(obj):
......@@ -360,12 +360,12 @@ class Interface:
account=account, name=nick, show=show)
ctrl = self.new_private_chat(gc_c, account, session)
ctrl.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
ctrl.add_info_message(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg})
return
gc_control.print_conversation(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg}, 'status')
gc_control.add_info_message(_('Error %(code)s: %(msg)s') % {
'code': obj.error_code, 'msg': obj.error_msg})
if gc_control.parent_win and \
gc_control.parent_win.get_active_jid() == jid:
gc_control.set_subject(gc_control.subject)
......@@ -509,9 +509,9 @@ class Interface:
gc_control = self.msg_win_mgr.get_gc_control(obj.jid,
account)
if gc_control:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s has been invited in this room') % {
'jid': jid}, graphics=False)
'jid': jid})
del app.automatic_rooms[account][obj.jid]
else:
win = app.get_app_window('GroupchatConfig', account, obj.jid)
......@@ -525,14 +525,13 @@ class Interface:
event.account)
if gc_control:
if event.reason:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s declined the invitation: %(reason)s') % {
'jid': event.from_, 'reason': event.reason},
graphics=False)
'jid': event.from_, 'reason': event.reason})
else:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s declined the invitation') % {
'jid': event.from_}, graphics=False)
'jid': event.from_})
def handle_event_gc_invitation(self, event):
if helpers.allow_popup_window(event.account) or not self.systray_enabled:
......
......@@ -114,7 +114,7 @@ class PrivateChatControl(ChatControl):
message = _('{nick} is now known '
'as {new_nick}').format(nick=nick, new_nick=new_nick)
self.print_conversation(message, 'info')
self.add_info_message(message)
self.draw_banner()
app.interface.msg_win_mgr.change_key(str(event.properties.jid),
......@@ -140,14 +140,14 @@ class PrivateChatControl(ChatControl):
if event.properties.is_muc_self_presence:
message = _('You are now {show}{status}').format(show=show,
status=status)
self.print_conversation(message, 'info')
self.add_status_message(message)
elif app.config.get_per('rooms', self.room_name,
'print_status', status_default):
message = _('{nick} is now {show}{status}').format(nick=nick,
show=show,
status=status)
self.print_conversation(message, 'info')
self.add_status_message(message)
self.parent_win.redraw_tab(self)
self.update_ui()
......
......@@ -3013,9 +3013,9 @@ class RosterWindow:
gc_control = app.interface.msg_win_mgr.get_gc_control(room_jid,
room_account)
if gc_control:
gc_control.print_conversation(
gc_control.add_info_message(
_('%(jid)s has been invited in this room') % {
'jid': contact_jid}, graphics=False)
'jid': contact_jid})
def on_all_groupchat_maximized(self, widget, group_list):
for (contact, account) in group_list:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment