put chatstate in the banner

This commit is contained in:
Nikos Kouremenos 2005-07-21 14:56:39 +00:00
parent 92453bca1b
commit 2db64d9ce8
5 changed files with 69 additions and 38 deletions

View File

@ -218,7 +218,7 @@ class Connection:
tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
tim = time.localtime(timegm(tim))
encrypted = False
chatstate_tag = None
chatstate = None
xtags = msg.getTags('x')
encTag = None
decmsg = ''
@ -231,7 +231,7 @@ class Connection:
children = msg.getChildren()
for child in children:
if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
chatstate_tag = child.getName()
chatstate = child.getName()
break
if encTag and USE_GPG:
@ -264,7 +264,7 @@ class Connection:
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
mtype, subject, None))
else: # it's type 'chat'
if not msg.getTag('body') and chatstate_tag is None: #no <body>
if not msg.getTag('body') and chatstate is None: #no <body>
return
log_msgtxt = msgtxt
if subject:
@ -272,7 +272,7 @@ class Connection:
gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()),
tim = tim)
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
mtype, subject, chatstate_tag))
mtype, subject, chatstate))
# END messageCB
def _presenceCB(self, con, prs):

View File

@ -345,10 +345,10 @@ class Interface:
self.remote.raise_signal('GCPresence', (account, array))
def handle_event_msg(self, account, array):
#('MSG', account, (contact, msg, time, encrypted, msg_type, subject, chatstate_tag))
#('MSG', account, (contact, msg, time, encrypted, msg_type, subject, chatstate))
jid = array[0].split('/')[0]
msg_type = array[4]
chatstate_tag = array[6]
chatstate = array[6]
if jid.find('@') <= 0:
jid = jid.replace('@', '')
@ -370,7 +370,6 @@ class Interface:
ask = 'none')
self.roster.new_chat(c, account)
return
if gajim.config.get('ignore_unknown_contacts') and \
not gajim.contacts[account].has_key(jid):
@ -378,11 +377,11 @@ class Interface:
if self.windows[account]['chats'].has_key(jid):
chat_win = self.windows[account]['chats'][jid]
# chatstates - display jep85 events in window
if chatstate_tag is not None:
if chat_win.chatstates[jid] == 'ask':
chat_win.chatstates[jid] = 'active'
chat_win.print_conversation(jid + ' is now ' + chatstate_tag, jid, 'status', tim = array[2])
if chatstate is not None: # he sent us reply, so he supports jep85
if chat_win.chatstates[jid] == 'ask': # we were jep85 disco?
chat_win.chatstates[jid] = 'active' # no more
chat_win.handle_incoming_chatstate(account, jid, chatstate)
else:
# got no valid jep85 answer, peer does not support it
chat_win.chatstates[jid] = False

14
src/gtkgui_helpers.py Normal file
View File

@ -0,0 +1,14 @@
from common import gajim
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
contact_instances = gajim.contacts[account][jid]
return contact_instances
def get_first_contact_instance_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0]
def get_contact_name_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0].name

View File

@ -31,6 +31,7 @@ import history_window
import dialogs
import config
import cell_renderer_image
import gtkgui_helpers
from gajim import Contact
from common import gajim
@ -201,7 +202,8 @@ class RosterWindow:
return 'gadugadu'
elif host.startswith('irc'):
return 'irc'
elif host.startswith('icq'): # abc@icqsucks.org will match as ICQ, but what to do..
# abc@icqsucks.org will match as ICQ, but what to do..
elif host.startswith('icq'):
return 'icq'
elif host.startswith('msn'):
return 'msn'
@ -225,32 +227,34 @@ class RosterWindow:
iters = self.get_contact_iter(jid, account)
if len(iters) == 0:
return
users = gajim.contacts[account][jid]
name = users[0].name
if len(users) > 1:
name += ' (' + str(len(users)) + ')'
prio = 0
user = users[0]
for u in users:
if u.priority > prio:
prio = u.priority
user = u
contact_instances = gtkgui_helpers.get_contact_instances_from_jid(account,
jid)
contact = contact_instances[0]
name = contact.name
if len(contact_instances) > 1:
name += ' (' + str(len(contact_instances)) + ')'
prio = 0 # FIXME: add a comment explain what you do here
for c in contact_instances:
if c.priority > prio:
prio = c.priority
contact = c
state_images = self.get_appropriate_state_images(jid)
if gajim.awaiting_messages[account].has_key(jid):
img = state_images['message']
elif jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent
img = state_images[user.show]
img = state_images[contact.show]
else:
if user.sub == 'both':
img = state_images[user.show]
if contact.sub == 'both':
img = state_images[contact.show]
else:
if user.ask == 'subscribe':
if contact.ask == 'subscribe':
img = state_images['requested']
else:
transport = self.get_transport_name_by_jid(jid)
if transport and state_images.has_key(user.show):
img = state_images[user.show]
if transport and state_images.has_key(contact.show):
img = state_images[contact.show]
else:
img = state_images[_('not in the roster')]
for iter in iters:
@ -2079,9 +2083,6 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
self.tooltip = dialogs.RosterTooltip(self.plugin)
self.make_menu()
self.draw_roster()
if len(gajim.connections) == 0: # if no account
self.plugin.windows['account_modification'] = \
config.AccountModificationWindow(self.plugin)
if gajim.config.get('show_roster_on_startup'):
self.window.show_all()
@ -2090,3 +2091,7 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
# cannot happen via GUI, but I put this incase user touches config
self.window.show_all() # without trayicon, he should see the roster!
gajim.config.set('show_roster_on_startup', True)
if len(gajim.connections) == 0: # if we have no account
self.plugin.windows['account_modification'] = \
config.AccountModificationWindow(self.plugin)

View File

@ -27,6 +27,7 @@ import base64
import dialogs
import chat
import gtkgui_helpers
from common import gajim
from common import helpers
@ -105,14 +106,17 @@ class TabbedChatWindow(chat.Chat):
tip.set_tip(self.xmls[jid].get_widget('gpg_eventbox'), tt)
# add the fat line at the top
self.draw_name_banner(contact.name, jid)
self.draw_name_banner(contact)
def draw_name_banner(self, name, jid):
def draw_name_banner(self, contact, chatstate = None):
'''Draw the fat line at the top of the window that
houses the status icon, name, jid, and avatar'''
# this is the text for the big brown bar
# some chars need to be escaped.. this fixes '&'
name = name.replace('&', '&amp;')
# some chars need to be escaped..
name = contact.name.replace('&', '&amp;').replace('>','&gt;').replace(
'<','&lt;')
jid = contact.jid
#FIXME: uncomment me when we support sending messages to specific resource
# composing full jid
@ -122,8 +126,12 @@ class TabbedChatWindow(chat.Chat):
#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
# % (name, fulljid)
label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
% (name, jid)
if chatstate:
label_text = '<span weight="heavy" size="x-large">%s</span> (chat state: %s)\n%s' \
% (name, chatstate, jid)
else:
label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
% (name, jid)
# setup the label that holds name and jid
banner_name_label = self.xmls[jid].get_widget('banner_name_label')
@ -316,6 +324,11 @@ class TabbedChatWindow(chat.Chat):
gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate,
contact)
def handle_incoming_chatstate(self, account, jid, chatstate):
''' handle incoming chatstate that jid SENT TO us '''
contact = gtkgui_helpers.get_first_contact_instance_from_jid(account, jid)
self.draw_name_banner(contact, chatstate)
def check_for_possible_paused_chatstate(self, contact):
''' did we move mouse of that window or kbd activity in that window
in the last 5 seconds?