multiple chat session windows per contact. groupchat and pms broken.

This commit is contained in:
Brendan Taylor 2008-04-30 02:55:13 +00:00
parent 2648aa4a9f
commit d4a766963f
5 changed files with 87 additions and 60 deletions

View File

@ -709,11 +709,10 @@ class ChatControlBase(MessageControl):
not self.parent_win.is_active() or not end) and \
kind in ('incoming', 'incoming_queue'):
self.parent_win.redraw_tab(self)
ctrl = gajim.interface.msg_win_mgr.get_control(full_jid, self.account)
if not self.parent_win.is_active():
self.parent_win.show_title(True, ctrl) # Enabled Urgent hint
self.parent_win.show_title(True, self) # Enabled Urgent hint
else:
self.parent_win.show_title(False, ctrl) # Disabled Urgent hint
self.parent_win.show_title(False, self) # Disabled Urgent hint
def toggle_emoticons(self):
'''hide show emoticons_button and make sure emoticons_menu is always there
@ -905,8 +904,7 @@ class ChatControlBase(MessageControl):
self.parent_win.get_active_control() == self and \
self.parent_win.window.is_active():
# we are at the end
if not gajim.events.remove_events(self.account, self.get_full_jid(),
types = ['printed_' + type_, type_]):
if not self.session.remove_events(['printed_' + type_, type_]):
# There were events to remove
self.redraw_after_event_removed(jid)
@ -2052,12 +2050,6 @@ class ChatControl(ChatControlBase):
if hasattr(self, 'session') and self.session and self.session.enable_encryption:
self.print_esession_details()
# Is it a pm ?
is_pm = False
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
control = gajim.interface.msg_win_mgr.get_control(room_jid, self.account)
if control and control.type_id == message_control.TYPE_GC:
is_pm = True
# list of message ids which should be marked as read
message_ids = []
for event in events:
@ -2082,11 +2074,16 @@ class ChatControl(ChatControlBase):
types = [self.type_id])
typ = 'chat' # Is it a normal chat or a pm ?
# reset to status image in gc if it is a pm
if is_pm:
control.update_ui()
control.parent_win.show_title()
typ = 'pm'
# Is it a pm ?
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
# XXX fixme somehow
# control = gajim.interface.msg_win_mgr.get_control(room_jid, self.account)
# if control and control.type_id == message_control.TYPE_GC:
# control.update_ui()
# control.parent_win.show_title()
# typ = 'pm'
self.redraw_after_event_removed(jid)
if (self.contact.show in ('offline', 'error')):
@ -2097,8 +2094,8 @@ class ChatControl(ChatControlBase):
len(gajim.contacts.get_contacts(self.account, jid)) < 2):
gajim.interface.roster.really_remove_contact(self.contact,
self.account)
elif typ == 'pm':
control.remove_contact(nick)
# elif typ == 'pm':
# control.remove_contact(nick)
def show_bigger_avatar(self, small_avatar):
'''resizes the avatar, if needed, so it has at max half the screen size

View File

@ -116,7 +116,7 @@ class Events:
def remove_events(self, account, jid, event = None, types = []):
'''if event is not specified, remove all events from this jid,
optionnaly only from given type
optionally only from given type
return True if no such event found'''
if not self._events.has_key(account):
return True

View File

@ -152,7 +152,8 @@ class MessageWindow(object):
def get_num_controls(self):
n = 0
for dict in self._controls.values():
for jid_dict in self._controls.values():
for dict in jid_dict.values():
n += len(dict)
return n
@ -206,7 +207,11 @@ class MessageWindow(object):
if not self._controls.has_key(control.account):
self._controls[control.account] = {}
fjid = control.get_full_jid()
self._controls[control.account][fjid] = control
if not self._controls[control.account].has_key(fjid):
self._controls[control.account][fjid] = {}
self._controls[control.account][fjid][control.session.thread_id] = control
if self.get_num_controls() == 2:
# is first conversation_textview scrolled down ?
@ -391,8 +396,8 @@ class MessageWindow(object):
else:
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
def set_active_tab(self, jid, acct):
ctrl = self._controls[acct][jid]
def set_active_tab(self, session):
ctrl = self._controls[session.conn.name][session.jid][session.thread_id]
ctrl_page = self.notebook.page_num(ctrl.widget)
self.notebook.set_current_page(ctrl_page)
@ -424,7 +429,12 @@ class MessageWindow(object):
self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
fjid = ctrl.get_full_jid()
thread_id = ctrl.session.thread_id
del self._controls[ctrl.account][fjid][thread_id]
if len(self._controls[ctrl.account][fjid]) == 0:
del self._controls[ctrl.account][fjid]
if len(self._controls[ctrl.account]) == 0:
del self._controls[ctrl.account]
@ -563,7 +573,8 @@ class MessageWindow(object):
del gajim.last_message_time[acct][old_jid]
def controls(self):
for ctrl_dict in self._controls.values():
for jid_dict in self._controls.values():
for ctrl_dict in jid_dict.values():
for ctrl in ctrl_dict.values():
yield ctrl

View File

@ -4312,18 +4312,18 @@ class RosterWindow:
if not session:
session = conn.get_session(fjid, None, 'chat')
win = gajim.interface.msg_win_mgr.get_window(fjid, account)
if not win:
if not session.control:
session.control = self.new_chat(session, contact, account, resource=resource)
if len(gajim.events.get_events(account, fjid)):
session.control.read_queue()
win = gajim.interface.msg_win_mgr.get_window(fjid, account)
# last message is long time ago
gajim.last_message_time[account][session.control.get_full_jid()] = 0
win.set_active_tab(fjid, account)
win = session.control.parent_win
win.set_active_tab(session)
if conn.is_zeroconf and conn.status in ('offline', 'invisible'):
win.get_control(fjid, account).got_disconnected()
@ -5204,6 +5204,7 @@ class RosterWindow:
start = '[' + str(nb_unread) + '] '
elif nb_unread == 1:
start = '* '
self.window.set_title(start + 'Gajim')
gtkgui_helpers.set_unset_urgency_hint(self.window, nb_unread)

View File

@ -19,6 +19,21 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
self.control = None
# remove events associated with this session from the queue
def remove_events(self, types):
any_removed = False
for event in gajim.events.get_events(self.conn, self.jid, types=types):
if event.parameters[8] != self:
continue
r = gajim.events.remove_events(self.conn, self.jid, event)
if not_any_removed:
any_removed = r
return any_removed
# extracts chatstate from a <message/> stanza
def get_chatstate(self, msg, msgtxt):
composing_xep = None
@ -93,16 +108,18 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
jid = jid.replace('@', '')
groupchat_control = gajim.interface.msg_win_mgr.get_control(jid, self.conn.name)
if not groupchat_control and \
jid in gajim.interface.minimized_controls[self.conn.name]:
groupchat_control = self.minimized_controls[self.conn.name][jid]
# XXX fixme
# if not groupchat_control and \
# jid in gajim.interface.minimized_controls[self.conn.name]:
# groupchat_control = self.minimized_controls[self.conn.name][jid]
pm = False
if groupchat_control and groupchat_control.type_id == \
message_control.TYPE_GC:
# if groupchat_control and groupchat_control.type_id == \
# message_control.TYPE_GC:
# It's a Private message
pm = True
msg_type = 'pm'
# pm = True
# msg_type = 'pm'
jid_of_control = full_jid_with_resource
@ -184,6 +201,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
subject=None, resource='', msg_id=None, user_nick='',
advanced_notif_num=None, xhtml=None, form_node=None):
contact = None
# if chat window will be for specific resource
resource_for_chat = resource