put chatstate in the banner
This commit is contained in:
parent
92453bca1b
commit
2db64d9ce8
|
@ -218,7 +218,7 @@ class Connection:
|
||||||
tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
|
tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
|
||||||
tim = time.localtime(timegm(tim))
|
tim = time.localtime(timegm(tim))
|
||||||
encrypted = False
|
encrypted = False
|
||||||
chatstate_tag = None
|
chatstate = None
|
||||||
xtags = msg.getTags('x')
|
xtags = msg.getTags('x')
|
||||||
encTag = None
|
encTag = None
|
||||||
decmsg = ''
|
decmsg = ''
|
||||||
|
@ -231,7 +231,7 @@ class Connection:
|
||||||
children = msg.getChildren()
|
children = msg.getChildren()
|
||||||
for child in children:
|
for child in children:
|
||||||
if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
|
if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
|
||||||
chatstate_tag = child.getName()
|
chatstate = child.getName()
|
||||||
break
|
break
|
||||||
|
|
||||||
if encTag and USE_GPG:
|
if encTag and USE_GPG:
|
||||||
|
@ -264,7 +264,7 @@ class Connection:
|
||||||
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
|
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
|
||||||
mtype, subject, None))
|
mtype, subject, None))
|
||||||
else: # it's type 'chat'
|
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
|
return
|
||||||
log_msgtxt = msgtxt
|
log_msgtxt = msgtxt
|
||||||
if subject:
|
if subject:
|
||||||
|
@ -272,7 +272,7 @@ class Connection:
|
||||||
gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()),
|
gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()),
|
||||||
tim = tim)
|
tim = tim)
|
||||||
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
|
self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted,
|
||||||
mtype, subject, chatstate_tag))
|
mtype, subject, chatstate))
|
||||||
# END messageCB
|
# END messageCB
|
||||||
|
|
||||||
def _presenceCB(self, con, prs):
|
def _presenceCB(self, con, prs):
|
||||||
|
|
15
src/gajim.py
15
src/gajim.py
|
@ -345,10 +345,10 @@ class Interface:
|
||||||
self.remote.raise_signal('GCPresence', (account, array))
|
self.remote.raise_signal('GCPresence', (account, array))
|
||||||
|
|
||||||
def handle_event_msg(self, 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]
|
jid = array[0].split('/')[0]
|
||||||
msg_type = array[4]
|
msg_type = array[4]
|
||||||
chatstate_tag = array[6]
|
chatstate = array[6]
|
||||||
if jid.find('@') <= 0:
|
if jid.find('@') <= 0:
|
||||||
jid = jid.replace('@', '')
|
jid = jid.replace('@', '')
|
||||||
|
|
||||||
|
@ -371,18 +371,17 @@ class Interface:
|
||||||
self.roster.new_chat(c, account)
|
self.roster.new_chat(c, account)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if gajim.config.get('ignore_unknown_contacts') and \
|
if gajim.config.get('ignore_unknown_contacts') and \
|
||||||
not gajim.contacts[account].has_key(jid):
|
not gajim.contacts[account].has_key(jid):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.windows[account]['chats'].has_key(jid):
|
if self.windows[account]['chats'].has_key(jid):
|
||||||
chat_win = self.windows[account]['chats'][jid]
|
chat_win = self.windows[account]['chats'][jid]
|
||||||
# chatstates - display jep85 events in window
|
if chatstate is not None: # he sent us reply, so he supports jep85
|
||||||
if chatstate_tag is not None:
|
if chat_win.chatstates[jid] == 'ask': # we were jep85 disco?
|
||||||
if chat_win.chatstates[jid] == 'ask':
|
chat_win.chatstates[jid] = 'active' # no more
|
||||||
chat_win.chatstates[jid] = 'active'
|
|
||||||
chat_win.print_conversation(jid + ' is now ' + chatstate_tag, jid, 'status', tim = array[2])
|
chat_win.handle_incoming_chatstate(account, jid, chatstate)
|
||||||
else:
|
else:
|
||||||
# got no valid jep85 answer, peer does not support it
|
# got no valid jep85 answer, peer does not support it
|
||||||
chat_win.chatstates[jid] = False
|
chat_win.chatstates[jid] = False
|
||||||
|
|
|
@ -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
|
|
@ -31,6 +31,7 @@ import history_window
|
||||||
import dialogs
|
import dialogs
|
||||||
import config
|
import config
|
||||||
import cell_renderer_image
|
import cell_renderer_image
|
||||||
|
import gtkgui_helpers
|
||||||
|
|
||||||
from gajim import Contact
|
from gajim import Contact
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
@ -201,7 +202,8 @@ class RosterWindow:
|
||||||
return 'gadugadu'
|
return 'gadugadu'
|
||||||
elif host.startswith('irc'):
|
elif host.startswith('irc'):
|
||||||
return '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'
|
return 'icq'
|
||||||
elif host.startswith('msn'):
|
elif host.startswith('msn'):
|
||||||
return 'msn'
|
return 'msn'
|
||||||
|
@ -225,32 +227,34 @@ class RosterWindow:
|
||||||
iters = self.get_contact_iter(jid, account)
|
iters = self.get_contact_iter(jid, account)
|
||||||
if len(iters) == 0:
|
if len(iters) == 0:
|
||||||
return
|
return
|
||||||
users = gajim.contacts[account][jid]
|
contact_instances = gtkgui_helpers.get_contact_instances_from_jid(account,
|
||||||
name = users[0].name
|
jid)
|
||||||
if len(users) > 1:
|
contact = contact_instances[0]
|
||||||
name += ' (' + str(len(users)) + ')'
|
name = contact.name
|
||||||
prio = 0
|
if len(contact_instances) > 1:
|
||||||
user = users[0]
|
name += ' (' + str(len(contact_instances)) + ')'
|
||||||
for u in users:
|
|
||||||
if u.priority > prio:
|
prio = 0 # FIXME: add a comment explain what you do here
|
||||||
prio = u.priority
|
for c in contact_instances:
|
||||||
user = u
|
if c.priority > prio:
|
||||||
|
prio = c.priority
|
||||||
|
contact = c
|
||||||
|
|
||||||
state_images = self.get_appropriate_state_images(jid)
|
state_images = self.get_appropriate_state_images(jid)
|
||||||
if gajim.awaiting_messages[account].has_key(jid):
|
if gajim.awaiting_messages[account].has_key(jid):
|
||||||
img = state_images['message']
|
img = state_images['message']
|
||||||
elif jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent
|
elif jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent
|
||||||
img = state_images[user.show]
|
img = state_images[contact.show]
|
||||||
else:
|
else:
|
||||||
if user.sub == 'both':
|
if contact.sub == 'both':
|
||||||
img = state_images[user.show]
|
img = state_images[contact.show]
|
||||||
else:
|
else:
|
||||||
if user.ask == 'subscribe':
|
if contact.ask == 'subscribe':
|
||||||
img = state_images['requested']
|
img = state_images['requested']
|
||||||
else:
|
else:
|
||||||
transport = self.get_transport_name_by_jid(jid)
|
transport = self.get_transport_name_by_jid(jid)
|
||||||
if transport and state_images.has_key(user.show):
|
if transport and state_images.has_key(contact.show):
|
||||||
img = state_images[user.show]
|
img = state_images[contact.show]
|
||||||
else:
|
else:
|
||||||
img = state_images[_('not in the roster')]
|
img = state_images[_('not in the roster')]
|
||||||
for iter in iters:
|
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.tooltip = dialogs.RosterTooltip(self.plugin)
|
||||||
self.make_menu()
|
self.make_menu()
|
||||||
self.draw_roster()
|
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'):
|
if gajim.config.get('show_roster_on_startup'):
|
||||||
self.window.show_all()
|
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
|
# cannot happen via GUI, but I put this incase user touches config
|
||||||
self.window.show_all() # without trayicon, he should see the roster!
|
self.window.show_all() # without trayicon, he should see the roster!
|
||||||
gajim.config.set('show_roster_on_startup', True)
|
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)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import base64
|
||||||
|
|
||||||
import dialogs
|
import dialogs
|
||||||
import chat
|
import chat
|
||||||
|
import gtkgui_helpers
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import helpers
|
from common import helpers
|
||||||
|
@ -105,14 +106,17 @@ class TabbedChatWindow(chat.Chat):
|
||||||
tip.set_tip(self.xmls[jid].get_widget('gpg_eventbox'), tt)
|
tip.set_tip(self.xmls[jid].get_widget('gpg_eventbox'), tt)
|
||||||
|
|
||||||
# add the fat line at the top
|
# 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
|
'''Draw the fat line at the top of the window that
|
||||||
houses the status icon, name, jid, and avatar'''
|
houses the status icon, name, jid, and avatar'''
|
||||||
# this is the text for the big brown bar
|
# this is the text for the big brown bar
|
||||||
# some chars need to be escaped.. this fixes '&'
|
# some chars need to be escaped..
|
||||||
name = name.replace('&', '&')
|
name = contact.name.replace('&', '&').replace('>','>').replace(
|
||||||
|
'<','<')
|
||||||
|
|
||||||
|
jid = contact.jid
|
||||||
|
|
||||||
#FIXME: uncomment me when we support sending messages to specific resource
|
#FIXME: uncomment me when we support sending messages to specific resource
|
||||||
# composing full jid
|
# composing full jid
|
||||||
|
@ -122,8 +126,12 @@ class TabbedChatWindow(chat.Chat):
|
||||||
#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
|
#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
|
||||||
# % (name, fulljid)
|
# % (name, fulljid)
|
||||||
|
|
||||||
label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
|
if chatstate:
|
||||||
% (name, jid)
|
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
|
# setup the label that holds name and jid
|
||||||
banner_name_label = self.xmls[jid].get_widget('banner_name_label')
|
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,
|
gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate,
|
||||||
contact)
|
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):
|
def check_for_possible_paused_chatstate(self, contact):
|
||||||
''' did we move mouse of that window or kbd activity in that window
|
''' did we move mouse of that window or kbd activity in that window
|
||||||
in the last 5 seconds?
|
in the last 5 seconds?
|
||||||
|
|
Loading…
Reference in New Issue