History action, some chatstate stuff moved over, etc.

This commit is contained in:
Travis Shirk 2006-01-02 01:23:40 +00:00
parent 1360933ba9
commit b239d4ff00
4 changed files with 80 additions and 62 deletions

View File

@ -292,7 +292,7 @@ class ChatControlBase(MessageControl):
if gajim.interface.systray_enabled and\
gajim.config.get('trayicon_notification_on_new_messages'):
gajim.interface.systray.add_jid(jid, self.account, self.type)
self.redraw_tab(jid)
self.parent_win.redraw_tab(jid)
self.show_title(urgent)
def toggle_emoticons(self):
@ -393,6 +393,16 @@ class ChatControlBase(MessageControl):
del self.print_time_timeout_id
return False
def on_history_menuitem_clicked(self, widget = None, jid = None):
'''When history menuitem is pressed: call history window'''
# FIXME for GC, jid is None
print widget, jid
if gajim.interface.instances['logs'].has_key(jid):
gajim.interface.instances['logs'][jid].window.present()
else:
gajim.interface.instances['logs'][jid] = history_window.HistoryWindow(
jid, self.account)
################################################################################
class ChatControl(ChatControlBase):
'''A control for standard 1-1 chat'''
@ -423,6 +433,7 @@ class ChatControl(ChatControlBase):
ChatControlBase.draw_widgets(self)
def _update_banner_state_image(self):
# FIXME: The cyling of contact_list ... is this necessary if I have the contact
contact = self.contact
show = contact.show
jid = contact.jid
@ -453,9 +464,12 @@ class ChatControl(ChatControlBase):
self._update_gpg()
def draw_banner(self):
def draw_banner(self, chatstate = None):
'''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. The chatstate arg should
only be used if the control's chatstate member is NOT to be use, such as
composing, paused, etc.
'''
ChatControlBase.draw_banner(self)
contact = self.contact
@ -686,8 +700,7 @@ class ChatControl(ChatControlBase):
if color:
color = gtk.gdk.colormap_get_system().alloc_color(color)
# We set the color for when it's the current tab or not
nickname.modify_fg(gtk.STATE_NORMAL, color)
# FIXME
# FIXME: why was this only happening for inactive or gone
#if chatstate in ('inactive', 'gone'):
# In inactive tab color to be lighter against the darker inactive
# background
@ -697,7 +710,6 @@ class ChatControl(ChatControlBase):
color.red = int((color.red * p) + (mask * (1 - p)))
color.green = int((color.green * p) + (mask * (1 - p)))
color.blue = int((color.blue * p) + (mask * (1 - p)))
nickname.modify_fg(gtk.STATE_ACTIVE, color)
if num_unread: # if unread, text in the label becomes bold
label_str = '<b>' + unread + label_str + '</b>'
@ -746,7 +758,7 @@ class ChatControl(ChatControlBase):
issensitive = gpg_btn.get_property('sensitive')
childs[3].set_active(isactive)
childs[3].set_property('sensitive', issensitive)
# If we don't have resource, we can't do file transfert
# If we don't have resource, we can't do file transfer
if not contact.resource:
childs[2].set_sensitive(False)
else:
@ -887,3 +899,10 @@ class ChatControl(ChatControlBase):
return True #stop the propagation of the event
return False
def handle_incoming_chatstate(self):
''' handle incoming chatstate that jid SENT TO us '''
self.draw_banner()
# update chatstate in tab for this chat
self.parent_win.redraw_tab(self.contact, self.contact.chatstate)

View File

@ -24,16 +24,23 @@
import common.gajim
class Contact:
class ContactBase:
def __init__(self, jid='', name='', show='', status=''):
self.jid = jid
self.name = name
self.show = show
self.status = status
def get_full_jid(self):
pass # Derived types MUST implement this method
class Contact(ContactBase):
'''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=5, keyID='', our_chatstate=None,
chatstate=None):
self.jid = jid
self.name = name
ContactBase.__init__(self, jid = jid, name = name, status = status, show = show)
self.groups = groups
self.show = show
self.status = status
self.sub = sub
self.ask = ask
self.resource = resource
@ -56,17 +63,14 @@ class Contact:
return self.jid + '/' + self.resource
return self.jid
class GC_Contact:
class GC_Contact(ContactBase):
'''Information concerning each groupchat contact'''
def __init__(self, room_jid='', name='', show='', status='', role='',
affiliation='', jid = ''):
ContactBase.__init__(self, jid = jid, name = name, status = status, show = show)
self.room_jid = room_jid
self.name = name
self.show = show
self.status = status
self.role = role
self.affiliation = affiliation
self.jid = jid
def get_full_jid(self):
return self.room_jid + '/' + self.name

View File

@ -344,8 +344,7 @@ class Interface:
if gajim.config.get_per('soundevents', 'contact_connected',
'enabled') and gajim.allow_notifications[account]:
helpers.play_sound('contact_connected')
# FIXME
if not self.instances[account]['chats'].has_key(jid) and \
if not gajim.interface.msg_win_mgr.has_window(jid) and \
not gajim.awaiting_events[account].has_key(jid) and \
gajim.config.get('notify_on_signin') and \
gajim.allow_notifications[account]:
@ -365,8 +364,7 @@ class Interface:
if gajim.config.get_per('soundevents', 'contact_disconnected',
'enabled'):
helpers.play_sound('contact_disconnected')
# FIXME
if not self.instances[account]['chats'].has_key(jid) and \
if not gajim.interface.msg_win_mgr.has_window(jid) and \
not gajim.awaiting_events[account].has_key(jid) and \
gajim.config.get('notify_on_signout'):
show_notification = False
@ -408,8 +406,7 @@ class Interface:
if self.instances[account]['gc'].has_key(jid): # it's a Private Message
nick = gajim.get_nick_from_fjid(array[0])
fjid = array[0]
# FIXME
if not self.instances[account]['chats'].has_key(fjid) and \
if not gajim.interface.msg_win_mgr.has_window(fjid) and \
not gajim.awaiting_events[account].has_key(fjid):
if show_notification:
notify.notify(_('New Private Message'), fjid, account, 'pm')
@ -424,15 +421,14 @@ class Interface:
# Handle chat states
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
# FIXME
if self.instances[account]['chats'].has_key(jid):
chat_win = self.instances[account]['chats'][jid]
if gajim.interface.msg_win_mgr.has_window(jid):
chat_ctl = gajim.interface.msg_win_mgr.get_control(jid)
if chatstate is not None: # he or she sent us reply, so he supports jep85
contact.chatstate = chatstate
if contact.our_chatstate == 'ask': # we were jep85 disco?
contact.our_chatstate = 'active' # no more
chat_win.handle_incoming_chatstate(account, contact)
chat_ctl.handle_incoming_chatstate()
elif contact.chatstate != 'active':
# got no valid jep85 answer, peer does not support it
contact.chatstate = False
@ -445,8 +441,7 @@ class Interface:
return
first = False
# FIXME
if not self.instances[account]['chats'].has_key(jid) and \
if not gajim.interface.msg_win_mgr.has_window(jid) and \
not gajim.awaiting_events[account].has_key(jid):
first = True
if gajim.config.get('notify_on_new_message'):
@ -483,8 +478,7 @@ class Interface:
if jid in gcs:
if len(jids) > 1: # it's a pm
nick = jids[1]
# FIXME
if not self.instances[account]['chats'].has_key(fjid):
if not gajim.interface.msg_win_mgr.has_window(fjid):
gc = gcs[jid]
tv = gc.list_treeview[jid]
model = tv.get_model()
@ -497,10 +491,11 @@ class Interface:
name = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(c)
self.roster.new_chat(c, account)
# FIXME
self.instances[account]['chats'][fjid].print_conversation(
'Error %s: %s' % (array[1], array[2]), fjid, 'status')
ctl = gajim.interface.msg_win_mgr.get_control(fjid)
ctl.print_conversation('Error %s: %s' % (array[1], array[2]),
'status')
return
# FIXME
gcs[jid].print_conversation('Error %s: %s' % \
(array[1], array[2]), jid)
if gcs[jid].get_active_jid() == jid:
@ -651,14 +646,17 @@ class Interface:
# show avatar in chat
win = None
# FIXME
if self.instances[account]['chats'].has_key(jid):
win = self.instances[account]['chats'][jid]
elif resource and self.instances[account]['chats'].has_key(
jid + '/' + resource):
win = self.instances[account]['chats'][jid + '/' + resource]
ctl = None
if gajim.interface.msg_win_mgr.has_window(jid):
win = gajim.interface.msg_type.get_window(jid)
ctl = win.get_control(jid)
# FIXME: Why is this needed
elif resource and gajim.interface.msg_win_mgr.has_window(jid + '/' + resource):
win = gajim.interface.msg_type.get_window(jid + '/' + resource)
ctl = win.get_control(jid + '/' + resource)
if win:
win.show_avatar(jid, resource)
# FIXME: Are these args needed
ctl.show_avatar(jid, resource)
# Show avatar in roster
self.roster.draw_avatar(jid, account)
if self.remote_ctrl:
@ -686,17 +684,16 @@ class Interface:
show = array[1]
status = array[2]
# print status in chat window and update status/GPG image
# FIXME
if self.instances[account]['chats'].has_key(fjid):
contact = self.instances[account]['chats'][fjid].contacts[fjid]
if gajim.interface.msg_win_mgr.has_window(fjid):
ctl = gajim.interface.msg_win_mgr.get_control(fjid)
contact = ctl.contact
contact.show = show
contact.status = status
self.instances[account]['chats'][fjid].set_state_image(fjid)
ctl.update_state()
uf_show = helpers.get_uf_show(show)
self.instances[account]['chats'][fjid].print_conversation(
_('%s is now %s (%s)') % (nick, uf_show, status), fjid,
'status')
self.instances[account]['chats'][fjid].draw_name_banner(contact)
ctl.print_conversation(_('%s is now %s (%s)') % (nick, uf_show, status),
'status')
ctl.draw_banner()
if self.instances[account]['gc'].has_key(room_jid):
self.instances[account]['gc'][room_jid].chg_contact_status(room_jid,
@ -1244,26 +1241,24 @@ class Interface:
sys.exit()
def handle_event(self, account, jid, typ):
wins = self.instances[account]
w = None
if typ == 'gc':
if wins['gc'].has_key(jid):
w = wins['gc'][jid]
elif typ == 'chat':
# FIXME
if wins['chats'].has_key(jid):
w = wins['chats'][jid]
if gajim.interface.msg_win_mgr.has_window(jid):
w = gajim.interface.msg_win_mgr.get_window(jid)
else:
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
self.roster.new_chat(contact, account)
w = wins['chats'][jid]
w = gajim.interface.msg_win_mgr.get_window(jid)
elif typ == 'pm':
# FIXME
if wins['chats'].has_key(jid):
w = wins['chats'][jid]
if gajim.interface.msg_win_mgr.has_window(jid):
w = gajim.interface.msg_win_mgr.get_window(jid)
else:
room_jid, nick = jid.split('/', 1)
gc_contact = gajim.contacts.get_gc_contact(account, room_jid, nick)
gc_contact = gajim.contacts.get_gc_contact(account, room_jid,
nick)
if gc_contact:
show = gc_contact.show
else:
@ -1272,7 +1267,7 @@ class Interface:
name = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(gc_contact)
self.roster.new_chat(c, account)
w = wins['chats'][jid]
w = gajim.interface.msg_win_mgr.get_window(jid)
elif typ in ('normal', 'file-request', 'file-request-error',
'file-send-error', 'file-error', 'file-stopped', 'file-completed'):
# Get the first single message event

View File

@ -1942,16 +1942,16 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
recent = False
if self.nb_unread > 0:
unread = True
for win in gajim.interface.msg_win_mgr.windows.values():
for win in gajim.interface.msg_win_mgr.windows():
unrd = 0
for ctl in win.controls():
unrd += ctl.nb_unread
if unrd:
unread = True
break
for ctl in win.control():
for ctl in win.controls():
jid = ctl.contact.jid
if time.time() - gajim.last_message_time[account][ji] < 2:
if time.time() - gajim.last_message_time[acct][jid] < 2:
recent = True
break
if unread: