Pass account to window/control lookup methods

This commit is contained in:
Travis Shirk 2006-01-25 02:43:55 +00:00
parent 1d49a10c58
commit a63132500b
8 changed files with 106 additions and 103 deletions

View File

@ -1313,7 +1313,7 @@ class ChatControl(ChatControlBase):
# Is it a pm ? # Is it a pm ?
is_pm = False is_pm = False
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
control = gajim.interface.msg_win_mgr.get_control(room_jid) control = gajim.interface.msg_win_mgr.get_control(room_jid, self.account)
if control.type_id == message_control.TYPE_GC: if control.type_id == message_control.TYPE_GC:
is_pm = True is_pm = True
events_to_keep = [] events_to_keep = []

View File

@ -153,7 +153,7 @@ def get_real_jid_from_fjid(account, fjid):
if not nick: # It's not a fake_jid, it is a real jid if not nick: # It's not a fake_jid, it is a real jid
return fjid # we return the real jid return fjid # we return the real jid
real_jid = fjid real_jid = fjid
if interface.msg_win_mgr.get_control(room_jid): if interface.msg_win_mgr.get_control(room_jid, account):
# It's a pm, so if we have real jid it's in contact.jid # It's a pm, so if we have real jid it's in contact.jid
gc_contact = contacts.get_gc_contact(account, room_jid, nick) gc_contact = contacts.get_gc_contact(account, room_jid, nick)
if not gc_contact: if not gc_contact:

View File

@ -178,7 +178,7 @@ class Interface:
title = data[1] title = data[1]
prompt = data[2] prompt = data[2]
proposed_nick = data[3] proposed_nick = data[3]
gc_control = gajim.interface.msg_win_mgr.get_control(room_jid) gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, account)
if gc_control: # user may close the window before we are here if gc_control: # user may close the window before we are here
gc_control.show_change_nick_input_dialog(title, prompt, proposed_nick) gc_control.show_change_nick_input_dialog(title, prompt, proposed_nick)
@ -220,7 +220,7 @@ class Interface:
(jid_from, file_props)) (jid_from, file_props))
conn.disconnect_transfer(file_props) conn.disconnect_transfer(file_props)
return return
ctrl = gajim.interface.msg_win_mgr.get_control(jid_from) ctrl = gajim.interface.msg_win_mgr.get_control(jid_from, account)
if ctrl and ctrl.type_id == message_control.TYPE_GC: if ctrl and ctrl.type_id == message_control.TYPE_GC:
ctrl.print_conversation('Error %s: %s' % (array[2], array[1])) ctrl.print_conversation('Error %s: %s' % (array[2], array[1]))
@ -241,7 +241,7 @@ class Interface:
if not gajim.gc_connected.has_key(account): if not gajim.gc_connected.has_key(account):
return return
for room_jid in gajim.gc_connected[account]: for room_jid in gajim.gc_connected[account]:
gc_control = gajim.interface.msg_win_mgr.get_control(room_jid) gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, account)
if gc_control: if gc_control:
gc_control.got_disconnected() gc_control.got_disconnected()
else: else:
@ -348,7 +348,7 @@ class Interface:
if gajim.config.get_per('soundevents', 'contact_connected', if gajim.config.get_per('soundevents', 'contact_connected',
'enabled') and gajim.allow_notifications[account]: 'enabled') and gajim.allow_notifications[account]:
helpers.play_sound('contact_connected') helpers.play_sound('contact_connected')
if not gajim.interface.msg_win_mgr.has_window(jid) and \ if not gajim.interface.msg_win_mgr.has_window(jid, account) and \
not gajim.awaiting_events[account].has_key(jid) and \ not gajim.awaiting_events[account].has_key(jid) and \
gajim.config.get('notify_on_signin') and \ gajim.config.get('notify_on_signin') and \
gajim.allow_notifications[account]: gajim.allow_notifications[account]:
@ -373,7 +373,7 @@ class Interface:
if gajim.config.get_per('soundevents', 'contact_disconnected', if gajim.config.get_per('soundevents', 'contact_disconnected',
'enabled'): 'enabled'):
helpers.play_sound('contact_disconnected') helpers.play_sound('contact_disconnected')
if not gajim.interface.msg_win_mgr.has_window(jid) and \ if not gajim.interface.msg_win_mgr.has_window(jid, account) and \
not gajim.awaiting_events[account].has_key(jid) and \ not gajim.awaiting_events[account].has_key(jid) and \
gajim.config.get('notify_on_signout'): gajim.config.get('notify_on_signout'):
show_notification = False show_notification = False
@ -416,12 +416,12 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True show_notification = True
chat_control = gajim.interface.msg_win_mgr.get_control(jid) chat_control = gajim.interface.msg_win_mgr.get_control(jid, account)
if chat_control and chat_control.type_id == message_control.TYPE_GC: if chat_control and chat_control.type_id == message_control.TYPE_GC:
# it's a Private Message # it's a Private Message
nick = gajim.get_nick_from_fjid(array[0]) nick = gajim.get_nick_from_fjid(array[0])
fjid = array[0] fjid = array[0]
if not gajim.interface.msg_win_mgr.has_window(fjid) and \ if not gajim.interface.msg_win_mgr.has_window(fjid, account) and \
not gajim.awaiting_events[account].has_key(fjid): not gajim.awaiting_events[account].has_key(fjid):
if show_notification: if show_notification:
room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid) room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
@ -435,6 +435,7 @@ class Interface:
chat_control.on_private_message(nick, array[1], array[2]) chat_control.on_private_message(nick, array[1], array[2])
return return
# FIXME: This should happen first
if gajim.config.get('ignore_unknown_contacts') and \ if gajim.config.get('ignore_unknown_contacts') and \
not gajim.contacts.get_contact(account, jid): not gajim.contacts.get_contact(account, jid):
return return
@ -442,13 +443,14 @@ class Interface:
# Handle chat states # Handle chat states
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if chat_control and chat_control.type_id == message_control.TYPE_CHAT: if chat_control and chat_control.type_id == message_control.TYPE_CHAT:
ctrl = gajim.interface.msg_win_mgr.get_control(jid) # FIXME: Why is this here?
#ctrl = gajim.interface.msg_win_mgr.get_control(jid,)
if chatstate is not None: # he or she sent us reply, so he supports jep85 if chatstate is not None: # he or she sent us reply, so he supports jep85
contact.chatstate = chatstate contact.chatstate = chatstate
if contact.our_chatstate == 'ask': # we were jep85 disco? if contact.our_chatstate == 'ask': # we were jep85 disco?
contact.our_chatstate = 'active' # no more contact.our_chatstate = 'active' # no more
ctrl.handle_incoming_chatstate() chat_control.handle_incoming_chatstate()
elif contact.chatstate != 'active': elif contact.chatstate != 'active':
# got no valid jep85 answer, peer does not support it # got no valid jep85 answer, peer does not support it
contact.chatstate = False contact.chatstate = False
@ -461,7 +463,7 @@ class Interface:
return return
first = False first = False
if not gajim.interface.msg_win_mgr.has_window(jid) and \ if not gajim.interface.msg_win_mgr.has_window(jid, account) and \
not gajim.awaiting_events[account].has_key(jid): not gajim.awaiting_events[account].has_key(jid):
first = True first = True
if gajim.config.get('notify_on_new_message'): if gajim.config.get('notify_on_new_message'):
@ -506,7 +508,7 @@ class Interface:
if jid == gc_control.contact.jid: if jid == gc_control.contact.jid:
if len(jids) > 1: # it's a pm if len(jids) > 1: # it's a pm
nick = jids[1] nick = jids[1]
if not gajim.interface.msg_win_mgr.get_control(fjid): if not gajim.interface.msg_win_mgr.get_control(fjid, account):
tv = gc_control.list_treeview tv = gc_control.list_treeview
model = tv.get_model() model = tv.get_model()
i = gc_control.get_contact_iter(nick) i = gc_control.get_contact_iter(nick)
@ -518,7 +520,7 @@ class Interface:
name = nick, show = show) name = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(c) c = gajim.contacts.contact_from_gc_contct(c)
self.roster.new_chat(c, account, private_chat = True) self.roster.new_chat(c, account, private_chat = True)
ctrl = gajim.interface.msg_win_mgr.get_control(fjid) ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account)
ctrl.print_conversation('Error %s: %s' % (array[1], array[2]), ctrl.print_conversation('Error %s: %s' % (array[1], array[2]),
'status') 'status')
return return
@ -676,12 +678,12 @@ class Interface:
# show avatar in chat # show avatar in chat
win = None win = None
ctrl = None ctrl = None
if gajim.interface.msg_win_mgr.has_window(jid): if gajim.interface.msg_win_mgr.has_window(jid, account):
win = gajim.interface.msg_win_mgr.get_window(jid) win = gajim.interface.msg_win_mgr.get_window(jid, account)
ctrl = win.get_control(jid) ctrl = win.get_control(jid, account)
elif resource and gajim.interface.msg_win_mgr.has_window(jid + '/' + resource): elif resource and gajim.interface.msg_win_mgr.has_window(jid + '/' + resource, account):
win = gajim.interface.msg_win_mgr.get_window(jid + '/' + resource) win = gajim.interface.msg_win_mgr.get_window(jid + '/' + resource, account)
ctrl = win.get_control(jid + '/' + resource) ctrl = win.get_control(jid + '/' + resource, account)
if win and ctrl.type_id != message_control.TYPE_GC: if win and ctrl.type_id != message_control.TYPE_GC:
ctrl.show_avatar() ctrl.show_avatar()
@ -712,8 +714,8 @@ class Interface:
show = array[1] show = array[1]
status = array[2] status = array[2]
# print status in chat window and update status/GPG image # print status in chat window and update status/GPG image
if gajim.interface.msg_win_mgr.has_window(fjid): if gajim.interface.msg_win_mgr.has_window(fjid, account):
ctrl = gajim.interface.msg_win_mgr.get_control(fjid) ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account)
contact = ctrl.contact contact = ctrl.contact
contact.show = show contact.show = show
contact.status = status contact.status = status
@ -724,12 +726,12 @@ class Interface:
ctrl.draw_banner() ctrl.draw_banner()
# Get the window and control for the updated status, this may be a PrivateChatControl # Get the window and control for the updated status, this may be a PrivateChatControl
control = gajim.interface.msg_win_mgr.get_control(room_jid) control = gajim.interface.msg_win_mgr.get_control(room_jid, account)
if control: if control:
control.chg_contact_status(nick, show, status, array[4], array[5], array[6], control.chg_contact_status(nick, show, status, array[4], array[5], array[6],
array[7], array[8], array[9], array[10]) array[7], array[8], array[9], array[10])
# Find any PM chat through this room, and tell it to update. # Find any PM chat through this room, and tell it to update.
pm_control = gajim.interface.msg_win_mgr.get_control(fjid) pm_control = gajim.interface.msg_win_mgr.get_control(fjid, account)
if pm_control: if pm_control:
pm_control.parent_win.redraw_tab(pm_control.contact) pm_control.parent_win.redraw_tab(pm_control.contact)
if self.remote_ctrl: if self.remote_ctrl:
@ -739,7 +741,7 @@ class Interface:
# ('GC_MSG', account, (jid, msg, time)) # ('GC_MSG', account, (jid, msg, time))
jids = array[0].split('/', 1) jids = array[0].split('/', 1)
room_jid = jids[0] room_jid = jids[0]
gc_control = gajim.interface.msg_win_mgr.get_control(room_jid) gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, account)
if not gc_control: if not gc_control:
return return
if len(jids) == 1: if len(jids) == 1:
@ -756,7 +758,7 @@ class Interface:
#('GC_SUBJECT', account, (jid, subject, body)) #('GC_SUBJECT', account, (jid, subject, body))
jids = array[0].split('/', 1) jids = array[0].split('/', 1)
jid = jids[0] jid = jids[0]
gc_control = gajim.interface.msg_win_mgr.get_control(jid) gc_control = gajim.interface.msg_win_mgr.get_control(jid, account)
if not gc_control: if not gc_control:
return return
gc_control.set_subject(array[1]) gc_control.set_subject(array[1])
@ -1364,17 +1366,17 @@ class Interface:
def handle_event(self, account, jid, typ): def handle_event(self, account, jid, typ):
w = None w = None
if typ == message_control.TYPE_GC: if typ == message_control.TYPE_GC:
w = gajim.interface.msg_win_mgr.get_window(jid) w = gajim.interface.msg_win_mgr.get_window(jid, account)
elif typ == message_control.TYPE_CHAT: elif typ == message_control.TYPE_CHAT:
if gajim.interface.msg_win_mgr.has_window(jid): if gajim.interface.msg_win_mgr.has_window(jid, account):
w = gajim.interface.msg_win_mgr.get_window(jid) w = gajim.interface.msg_win_mgr.get_window(jid, account)
else: else:
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
self.roster.new_chat(contact, account) self.roster.new_chat(contact, account)
w = gajim.interface.msg_win_mgr.get_window(jid) w = gajim.interface.msg_win_mgr.get_window(jid, account)
elif typ == message_control.TYPE_PM: elif typ == message_control.TYPE_PM:
if gajim.interface.msg_win_mgr.has_window(jid): if gajim.interface.msg_win_mgr.has_window(jid, account):
w = gajim.interface.msg_win_mgr.get_window(jid) w = gajim.interface.msg_win_mgr.get_window(jid, account)
else: else:
room_jid, nick = jid.split('/', 1) room_jid, nick = jid.split('/', 1)
gc_contact = gajim.contacts.get_gc_contact(account, room_jid, gc_contact = gajim.contacts.get_gc_contact(account, room_jid,
@ -1387,7 +1389,7 @@ class Interface:
name = nick, show = show) name = nick, show = show)
c = gajim.contacts.contact_from_gc_contact(gc_contact) c = gajim.contacts.contact_from_gc_contact(gc_contact)
self.roster.new_chat(c, account, private_chat = True) self.roster.new_chat(c, account, private_chat = True)
w = gajim.interface.msg_win_mgr.get_window(jid) w = gajim.interface.msg_win_mgr.get_window(jid, account)
elif typ in ('normal', 'file-request', 'file-request-error', elif typ in ('normal', 'file-request', 'file-request-error',
'file-send-error', 'file-error', 'file-stopped', 'file-completed'): 'file-send-error', 'file-error', 'file-stopped', 'file-completed'):
# Get the first single message event # Get the first single message event
@ -1401,10 +1403,10 @@ class Interface:
url = ('http://mail.google.com/') url = ('http://mail.google.com/')
helpers.launch_browser_mailer('url', url) helpers.launch_browser_mailer('url', url)
if w: if w:
w.set_active_tab(jid) w.set_active_tab(jid, account)
w.window.present() w.window.present()
w.window.window.focus() w.window.window.focus()
ctrl = w.get_control(jid) ctrl = w.get_control(jid, account)
# Using isinstance here because we want to catch all derived types # Using isinstance here because we want to catch all derived types
if isinstance(ctrl, ChatControlBase): if isinstance(ctrl, ChatControlBase):
tv = ctrl.conv_textview tv = ctrl.conv_textview

View File

@ -305,7 +305,7 @@ class GroupchatControl(ChatControlBase):
no_queue = False no_queue = False
# We print if window is opened # We print if window is opened
pm_control = gajim.interface.msg_win_mgr.get_control(fjid) pm_control = gajim.interface.msg_win_mgr.get_control(fjid, self.account)
if pm_control: if pm_control:
pm_control.print_conversation(msg, tim = tim) pm_control.print_conversation(msg, tim = tim)
return return
@ -422,7 +422,7 @@ class GroupchatControl(ChatControlBase):
and does not already have it as last event. If it goes to add this line and does not already have it as last event. If it goes to add this line
it removes previous line first''' it removes previous line first'''
win = gajim.interface.msg_win_mgr.get_window(self.room_jid) win = gajim.interface.msg_win_mgr.get_window(self.room_jid, self.account)
if self.room_jid == win.get_active_jid() and\ if self.room_jid == win.get_active_jid() and\
win.window.get_property('has-toplevel-focus'): win.window.get_property('has-toplevel-focus'):
# it's the current room and it's the focused window. # it's the current room and it's the focused window.
@ -556,7 +556,7 @@ class GroupchatControl(ChatControlBase):
self._start_private_message(nick) self._start_private_message(nick)
if msg: if msg:
gajim.interface.msg_win_mgr.get_control(fjid).send_message(msg) gajim.interface.msg_win_mgr.get_control(fjid, self.account).send_message(msg)
def draw_contact(self, nick, selected=False, focus=False): def draw_contact(self, nick, selected=False, focus=False):
iter = self.get_contact_iter(nick) iter = self.get_contact_iter(nick)
@ -860,7 +860,7 @@ class GroupchatControl(ChatControlBase):
reason = message_array.pop(0) reason = message_array.pop(0)
gajim.connections[self.account].send_gc_status(self.nick, self.room_jid, gajim.connections[self.account].send_gc_status(self.nick, self.room_jid,
show='offline', status=reason) show='offline', status=reason)
self.parent_win.remove_tab(self.contact) self.parent_win.remove_tab(self)
return True return True
elif command == 'ban': elif command == 'ban':
if len(message_array): if len(message_array):
@ -1312,11 +1312,11 @@ class GroupchatControl(ChatControlBase):
c = gajim.contacts.contact_from_gc_contact(gc_c) c = gajim.contacts.contact_from_gc_contact(gc_c)
nick_jid = c.jid nick_jid = c.jid
win = gajim.interface.msg_win_mgr.get_window(nick_jid) win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
if not win: if not win:
gajim.interface.roster.new_chat(c, self.account, private_chat = True) gajim.interface.roster.new_chat(c, self.account, private_chat = True)
win = gajim.interface.msg_win_mgr.get_window(nick_jid) win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
win.set_active_tab(nick_jid) win.set_active_tab(nick_jid, self.account)
win.window.present() win.window.present()
def on_list_treeview_row_activated(self, widget, path, col = 0): def on_list_treeview_row_activated(self, widget, path, col = 0):

View File

@ -131,8 +131,8 @@ class MessageWindow:
# Add notebook page and connect up to the tab's close button # Add notebook page and connect up to the tab's close button
xml = gtk.glade.XML(GTKGUI_GLADE, 'chat_tab_ebox', APP) xml = gtk.glade.XML(GTKGUI_GLADE, 'chat_tab_ebox', APP)
tab_label_box = xml.get_widget('chat_tab_ebox') tab_label_box = xml.get_widget('chat_tab_ebox')
xml.signal_connect('on_close_button_clicked', self.on_close_button_clicked, xml.signal_connect('on_close_button_clicked', self._on_close_button_clicked,
control.contact) control)
xml.signal_connect('on_tab_eventbox_button_press_event', xml.signal_connect('on_tab_eventbox_button_press_event',
self.on_tab_eventbox_button_press_event, control.widget) self.on_tab_eventbox_button_press_event, control.widget)
self.notebook.append_page(control.widget, tab_label_box) self.notebook.append_page(control.widget, tab_label_box)
@ -173,9 +173,9 @@ class MessageWindow:
elif event.keyval == gtk.keysyms.Page_Up: # CTRL + PAGE UP elif event.keyval == gtk.keysyms.Page_Up: # CTRL + PAGE UP
self.notebook.emit('key_press_event', event) self.notebook.emit('key_press_event', event)
def on_close_button_clicked(self, button, contact): def _on_close_button_clicked(self, button, control):
'''When close button is pressed: close a tab''' '''When close button is pressed: close a tab'''
self.remove_tab(contact) self.remove_tab(control)
def show_title(self, urgent = True, control = None): def show_title(self, urgent = True, control = None):
'''redraw the window's title''' '''redraw the window's title'''
@ -209,28 +209,28 @@ class MessageWindow:
else: else:
gtkgui_helpers.set_unset_urgency_hint(self.window, False) gtkgui_helpers.set_unset_urgency_hint(self.window, False)
def set_active_tab(self, jid): def set_active_tab(self, jid, acct):
# FIXME: Use acct
ctrl = self._controls[jid] ctrl = self._controls[jid]
ctrl_page = self.notebook.page_num(ctrl.widget) ctrl_page = self.notebook.page_num(ctrl.widget)
self.notebook.set_current_page(ctrl_page) self.notebook.set_current_page(ctrl_page)
def remove_tab(self, contact): def remove_tab(self, ctrl):
# Shutdown the MessageControl # Shutdown the MessageControl
ctrl = self.get_control(contact.jid)
if not ctrl.allow_shutdown(): if not ctrl.allow_shutdown():
return return
ctrl.shutdown() ctrl.shutdown()
# Update external state # Update external state
if gajim.interface.systray_enabled: if gajim.interface.systray_enabled:
gajim.interface.systray.remove_jid(contact.jid, ctrl.account, gajim.interface.systray.remove_jid(ctrl.contact.jid, ctrl.account,
ctrl.type_id) ctrl.type_id)
del gajim.last_message_time[ctrl.account][ctrl.contact.jid] del gajim.last_message_time[ctrl.account][ctrl.contact.jid]
self.disconnect_tab_dnd(ctrl.widget) self.disconnect_tab_dnd(ctrl.widget)
self.notebook.remove_page(self.notebook.page_num(ctrl.widget)) self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
del self._controls[contact.jid] del self._controls[ctrl.contact.jid]
if len(self._controls) == 1: # we are going from two tabs to one if len(self._controls) == 1: # we are going from two tabs to one
show_tabs_if_one_tab = gajim.config.get('tabs_always_visible') show_tabs_if_one_tab = gajim.config.get('tabs_always_visible')
self.notebook.set_show_tabs(show_tabs_if_one_tab) self.notebook.set_show_tabs(show_tabs_if_one_tab)
@ -319,8 +319,10 @@ class MessageWindow:
for ctrl in self.controls(): for ctrl in self.controls():
ctrl.update_tags() ctrl.update_tags()
def get_control(self, key): def get_control(self, key, acct):
'''Return the MessageControl for jid or n, where n is the notebook page index''' '''Return the MessageControl for jid or n, where n is a notebook page index.
When key is an int index acct may be None'''
# FIXME: Use acct
if isinstance(key, str): if isinstance(key, str):
key = unicode(key, 'utf-8') key = unicode(key, 'utf-8')
@ -371,7 +373,7 @@ class MessageWindow:
ind = self.notebook.get_n_pages() - 1 ind = self.notebook.get_n_pages() - 1
if ind == current: if ind == current:
break # a complete cycle without finding an unread tab break # a complete cycle without finding an unread tab
ctrl = self.get_control(ind) ctrl = self.get_control(ind, None)
if ctrl.nb_unread > 0: if ctrl.nb_unread > 0:
found = True found = True
break # found break # found
@ -403,7 +405,8 @@ class MessageWindow:
gtk.ICON_SIZE_MENU) gtk.ICON_SIZE_MENU)
item.set_image(img) item.set_image(img)
item.connect('activate', item.connect('activate',
lambda obj, jid:self.set_active_tab(jid), jid) lambda obj, jid:self.set_active_tab(jid, ctrl.account),
jid)
menu.append(item) menu.append(item)
# show the menu # show the menu
menu.popup(None, None, None, event.button, event.time) menu.popup(None, None, None, event.button, event.time)
@ -433,9 +436,9 @@ class MessageWindow:
elif event.keyval == gtk.keysyms.Tab: # CTRL + TAB elif event.keyval == gtk.keysyms.Tab: # CTRL + TAB
self.move_to_next_unread_tab(True) self.move_to_next_unread_tab(True)
elif event.keyval == gtk.keysyms.F4: # CTRL + F4 elif event.keyval == gtk.keysyms.F4: # CTRL + F4
self.remove_tab(contact) self.remove_tab(ctrl)
elif event.keyval == gtk.keysyms.w: # CTRL + W elif event.keyval == gtk.keysyms.w: # CTRL + W
self.remove_tab(contact) self.remove_tab(ctrl)
# MOD1 (ALT) mask # MOD1 (ALT) mask
elif event.state & gtk.gdk.MOD1_MASK: elif event.state & gtk.gdk.MOD1_MASK:
@ -457,7 +460,7 @@ class MessageWindow:
ctrl.set_compact_view(not ctrl.compact_view_current) ctrl.set_compact_view(not ctrl.compact_view_current)
# Close tab bindings # Close tab bindings
elif event.keyval == gtk.keysyms.Escape: # ESCAPE elif event.keyval == gtk.keysyms.Escape: # ESCAPE
self.remove_tab(contact) self.remove_tab(ctrl)
else: else:
# If the active control has a message_textview pass the event to it # If the active control has a message_textview pass the event to it
active_ctrl = self.get_active_control() active_ctrl = self.get_active_control()
@ -572,14 +575,14 @@ class MessageWindowMgr:
return w return w
return None return None
def get_window(self, jid): def get_window(self, jid, acct):
for win in self.windows(): for win in self.windows():
if win.get_control(jid): if win.get_control(jid, acct):
return win return win
return None return None
def has_window(self, jid): def has_window(self, jid, acct):
return self.get_window(jid) return self.get_window(jid, acct)
def one_window_opened(self, contact, acct, type): def one_window_opened(self, contact, acct, type):
try: try:
@ -679,14 +682,15 @@ class MessageWindowMgr:
del self._windows[k] del self._windows[k]
return return
def get_control(self, jid): def get_control(self, jid, acct):
'''Amongst all windows, return the MessageControl for jid''' '''Amongst all windows, return the MessageControl for jid'''
win = self.get_window(jid) win = self.get_window(jid, acct)
if win: if win:
return win.get_control(jid) return win.get_control(jid, acct)
return None return None
def get_controls(self, type): def get_controls(self, type):
# FIXME: Optionally accept an account arg
ctrls = [] ctrls = []
for c in self.controls(): for c in self.controls():
if c.type_id == type: if c.type_id == type:
@ -774,12 +778,10 @@ class MessageWindowMgr:
controls.append(ctrl) controls.append(ctrl)
w.window.destroy() w.window.destroy()
for k in self._windows.keys():
del self._windows[k]
self._windows = {} self._windows = {}
for ctrl in controls: for ctrl in controls:
mw = self.get_window(ctrl.contact.jid) mw = self.get_window(ctrl.contact.jid, ctr.account)
if not mw: if not mw:
mw = self.create_window(ctrl.contact, ctrl.account, ctrl.type_id) mw = self.create_window(ctrl.contact, ctrl.account, ctrl.type_id)
ctrl.parent_win = mw ctrl.parent_win = mw

View File

@ -233,7 +233,7 @@ class SignalObject(DbusPrototype):
for acct in accounts: for acct in accounts:
if gajim.connections[acct].connected > 1: # account is online if gajim.connections[acct].connected > 1: # account is online
contact = gajim.contacts.get_first_contact_from_jid(acct, jid) contact = gajim.contacts.get_first_contact_from_jid(acct, jid)
if gajim.interface.msg_win_mgr.has_window(jid): if gajim.interface.msg_win_mgr.has_window(jid, acct):
connected_account = acct connected_account = acct
break break
# jid is in roster # jid is in roster
@ -254,7 +254,7 @@ class SignalObject(DbusPrototype):
if connected_account: if connected_account:
gajim.interface.roster.new_chat_from_jid(connected_account, jid) gajim.interface.roster.new_chat_from_jid(connected_account, jid)
# preserve the 'steal focus preservation' # preserve the 'steal focus preservation'
win = gajim.interface.msg_win_mgr.get_window(jid).window win = gajim.interface.msg_win_mgr.get_window(jid, connected_account).window
if win.get_property('visible'): if win.get_property('visible'):
win.window.focus() win.window.focus()
return True return True

View File

@ -333,7 +333,7 @@ class RosterWindow:
def join_gc_room(self, account, room_jid, nick, password): def join_gc_room(self, account, room_jid, nick, password):
'''joins the room immediatelly''' '''joins the room immediatelly'''
if gajim.interface.msg_win_mgr.has_window(room_jid) and \ if gajim.interface.msg_win_mgr.has_window(room_jid, account) and \
gajim.gc_connected[account][room_jid]: gajim.gc_connected[account][room_jid]:
dialogs.ErrorDialog(_('You are already in room %s') % room_jid dialogs.ErrorDialog(_('You are already in room %s') % room_jid
).get_response() ).get_response()
@ -344,10 +344,10 @@ class RosterWindow:
).get_response() ).get_response()
return return
room, server = room_jid.split('@') room, server = room_jid.split('@')
if not gajim.interface.msg_win_mgr.has_window(room_jid): if not gajim.interface.msg_win_mgr.has_window(room_jid, account):
self.new_room(room_jid, nick, account) self.new_room(room_jid, nick, account)
gc_win = gajim.interface.msg_win_mgr.get_window(room_jid) gc_win = gajim.interface.msg_win_mgr.get_window(room_jid, account)
gc_win.set_active_tab(room_jid) gc_win.set_active_tab(room_jid, account)
gc_win.window.present() gc_win.window.present()
gajim.connections[account].join_gc(nick, room, server, password) gajim.connections[account].join_gc(nick, room, server, password)
if password: if password:
@ -726,10 +726,10 @@ class RosterWindow:
self.add_contact_to_roster(contact.jid, account) self.add_contact_to_roster(contact.jid, account)
self.draw_contact(contact.jid, account) self.draw_contact(contact.jid, account)
# print status in chat window and update status/GPG image # print status in chat window and update status/GPG image
if gajim.interface.msg_win_mgr.has_window(contact.jid): if gajim.interface.msg_win_mgr.has_window(contact.jid, account):
jid = contact.jid jid = contact.jid
win = gajim.interface.msg_win_mgr.get_window(contact.jid) win = gajim.interface.msg_win_mgr.get_window(contact.jid, account)
ctl = win.get_control(jid) ctl = win.get_control(jid, account)
ctl.update_ui() ctl.update_ui()
win.redraw_tab(contact) win.redraw_tab(contact)
@ -923,8 +923,8 @@ class RosterWindow:
keys[contact.jid] = keyID[0] keys[contact.jid] = keyID[0]
for u in gajim.contacts.get_contact(account, contact.jid): for u in gajim.contacts.get_contact(account, contact.jid):
u.keyID = keyID[0] u.keyID = keyID[0]
if gajim.interface.msg_win_mgr.has_window(contact.jid): if gajim.interface.msg_win_mgr.has_window(contact.jid, account):
ctl = gajim.interface.msg_win_mgr.get_control(contact.jid) ctl = gajim.interface.msg_win_mgr.get_control(contact.jid, account)
ctl.update_ui() ctl.update_ui()
keys_str = '' keys_str = ''
for jid in keys: for jid in keys:
@ -1389,12 +1389,12 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
win = None win = None
c = gajim.contacts.get_contact_with_highest_priority(account, jid) c = gajim.contacts.get_contact_with_highest_priority(account, jid)
if gajim.interface.msg_win_mgr.has_window(c.jid): if gajim.interface.msg_win_mgr.has_window(c.jid, account):
win = gajim.interface.msg_win_mgr.get_window(c.jid) win = gajim.interface.msg_win_mgr.get_window(c.jid, account)
elif c: elif c:
self.new_chat(c, account) self.new_chat(c, account)
win = gajim.interface.msg_win_mgr.get_window(jid) win = gajim.interface.msg_win_mgr.get_window(jid, account)
win.set_active_tab(jid) win.set_active_tab(jid, account)
win.window.present() win.window.present()
elif type == 'account': elif type == 'account':
account = model[iter][C_ACCOUNT] account = model[iter][C_ACCOUNT]
@ -1451,7 +1451,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
for u in gajim.contacts.get_contact(account, contact.jid): for u in gajim.contacts.get_contact(account, contact.jid):
self.remove_contact(u, account) self.remove_contact(u, account)
gajim.contacts.remove_jid(account, u.jid) gajim.contacts.remove_jid(account, u.jid)
if gajim.interface.msg_win_mgr.has_window(contact.jid): if gajim.interface.msg_win_mgr.has_window(contact.jid, account):
c = gajim.contacts.create_contact(jid = contact.jid, c = gajim.contacts.create_contact(jid = contact.jid,
name = contact.name, groups = [_('Not in Roster')], name = contact.name, groups = [_('Not in Roster')],
show = 'Not in Roster', status = '', ask = 'none', show = 'Not in Roster', status = '', ask = 'none',
@ -1548,8 +1548,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
passphrase) passphrase)
gajim.connections[account].gpg_passphrase(passphrase) gajim.connections[account].gpg_passphrase(passphrase)
for gc_control in gajim.interface.msg_win_mgr.get_controls( for gc_control in gajim.interface.msg_win_mgr.get_controls(message_control.TYPE_GC):
message_control.TYPE_GC):
if gc_control.account == account: if gc_control.account == account:
gajim.connections[account].send_gc_status(gc_control.nick, gajim.connections[account].send_gc_status(gc_control.nick,
gc_control.room_jid, status, txt) gc_control.room_jid, status, txt)
@ -1698,7 +1697,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
else: else:
type = message_control.TYPE_PM type = message_control.TYPE_PM
mw = gajim.interface.msg_win_mgr.get_window(contact.jid) mw = gajim.interface.msg_win_mgr.get_window(contact.jid, account)
if not mw: if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account, type) mw = gajim.interface.msg_win_mgr.create_window(contact, account, type)
@ -1728,16 +1727,16 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
gajim.contacts.add_contact(account, contact) gajim.contacts.add_contact(account, contact)
self.add_contact_to_roster(contact.jid, account) self.add_contact_to_roster(contact.jid, account)
if not gajim.interface.msg_win_mgr.has_window(contact.jid): if not gajim.interface.msg_win_mgr.has_window(contact.jid, account):
self.new_chat(contact, account) self.new_chat(contact, account)
mw = gajim.interface.msg_win_mgr.get_window(contact.jid) mw = gajim.interface.msg_win_mgr.get_window(contact.jid, account)
mw.set_active_tab(jid) mw.set_active_tab(jid, account)
mw.window.present() mw.window.present()
def new_room(self, room_jid, nick, account): def new_room(self, room_jid, nick, account):
# Get target window, create a control, and associate it with the window # Get target window, create a control, and associate it with the window
contact = gajim.contacts.create_contact(jid = room_jid, name = nick) contact = gajim.contacts.create_contact(jid = room_jid, name = nick)
mw = gajim.interface.msg_win_mgr.get_window(contact.jid) mw = gajim.interface.msg_win_mgr.get_window(contact.jid, account)
if not mw: if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account, mw = gajim.interface.msg_win_mgr.create_window(contact, account,
GroupchatControl.TYPE_ID) GroupchatControl.TYPE_ID)
@ -1786,11 +1785,11 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
return return
# We print if window is opened and it's not a single message # We print if window is opened and it's not a single message
if gajim.interface.msg_win_mgr.has_window(jid) and msg_type != 'normal': if gajim.interface.msg_win_mgr.has_window(jid, account) and msg_type != 'normal':
typ = '' typ = ''
if msg_type == 'error': if msg_type == 'error':
typ = 'status' typ = 'status'
ctl = gajim.interface.msg_win_mgr.get_control(jid) ctl = gajim.interface.msg_win_mgr.get_control(jid, account)
ctl.print_conversation(msg, typ, tim = tim, encrypted = encrypted, ctl.print_conversation(msg, typ, tim = tim, encrypted = encrypted,
subject = subject) subject = subject)
return return
@ -1804,7 +1803,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
qs[jid].append((kind, (msg, subject, msg_type, tim, encrypted, resource))) qs[jid].append((kind, (msg, subject, msg_type, tim, encrypted, resource)))
self.nb_unread += 1 self.nb_unread += 1
if popup: if popup:
if not gajim.interface.msg_win_mgr.has_window(jid): if not gajim.interface.msg_win_mgr.has_window(jid, account):
self.new_chat(contact, account) self.new_chat(contact, account)
if path: if path:
self.tree.expand_row(path[0:1], False) self.tree.expand_row(path[0:1], False)
@ -2062,13 +2061,13 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
return return
c = gajim.contacts.get_contact_with_highest_priority(account, jid) c = gajim.contacts.get_contact_with_highest_priority(account, jid)
# Get the window containing the chat # Get the window containing the chat
win = gajim.interface.msg_win_mgr.get_window(jid) win = gajim.interface.msg_win_mgr.get_window(jid, account)
if win: if win:
win.set_active_tab(jid) win.set_active_tab(jid, account)
elif c: elif c:
self.new_chat(c, account) self.new_chat(c, account)
win = gajim.interface.msg_win_mgr.get_window(jid) win = gajim.interface.msg_win_mgr.get_window(jid, account)
win.set_active_tab(jid) win.set_active_tab(jid, account)
win.window.present() win.window.present()
def on_roster_treeview_row_expanded(self, widget, iter, path): def on_roster_treeview_row_expanded(self, widget, iter, path):

View File

@ -101,13 +101,13 @@ class Systray:
def start_chat(self, widget, account, jid): def start_chat(self, widget, account, jid):
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if gajim.interface.msg_win_mgr.has_window(jid): if gajim.interface.msg_win_mgr.has_window(jid, account):
gajim.interface.msg_win_mgr.get_window(jid).set_active_tab(jid) gajim.interface.msg_win_mgr.get_window(jid, account).set_active_tab(jid, account)
gajim.interface.msg_win_mgr.get_window(jid).present() gajim.interface.msg_win_mgr.get_window(jid, account).present()
elif contact: elif contact:
gajim.interface.roster.new_chat(gajim.contacts[account][jid][0], gajim.interface.roster.new_chat(gajim.contacts[account][jid][0],
account) account)
gajim.interface.msg_win_mgr.get_window(jid).set_active_tab(jid) gajim.interface.msg_win_mgr.get_window(jid, account).set_active_tab(jid, account)
def on_new_message_menuitem_activate(self, widget, account): def on_new_message_menuitem_activate(self, widget, account):
"""When new message menuitem is activated: """When new message menuitem is activated: