Window and control lookup functions, and set_Active_tab

This commit is contained in:
Travis Shirk 2005-12-31 17:00:04 +00:00
parent fb5ca97eba
commit 1102356937
2 changed files with 46 additions and 11 deletions

View file

@ -196,10 +196,21 @@ class MessageWindow:
self.window.set_title(title)
if urgent:
gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
def set_active_tab(self, jid):
ctl = self._controls[jid]
ctl_page = self.notebook.page_num(ctl.widget)
self.notebook.set_current_page(ctl_page)
def remove_tab(self, contact):
# TODO
print "MessageWindow.remove_tab"
if len(self._controls) == 1:
# There is only one tab
# FIXME: Should we assert on contact?
self.window.destroy()
else:
pass
# TODO
def redraw_tab(self, contact, chatstate = None):
ctl = self._controls[contact.jid]
@ -273,6 +284,12 @@ class MessageWindow:
for ctl in self._controls.values():
ctl.update_tags()
def get_control_from_jid(self, jid):
for ctl in self._controls.values():
if ctl.contact.jid == jid:
return ctl
return None
class MessageWindowMgr:
'''A manager and factory for MessageWindow objects'''
@ -317,7 +334,16 @@ class MessageWindowMgr:
print "MessageWindowMgr._on_window_destroy:", win
# TODO: Clean up windows
def get_window(self, contact, acct, type):
def get_window(self, jid):
for win in self.windows.values():
if win.get_control_from_jid(jid):
return win
return None
def has_window(self, jid):
return self.get_window(jid)
def create_window(self, contact, acct, type):
key = None
if self.mode == self.CONFIG_NEVER:
key = contact.jid
@ -336,6 +362,7 @@ class MessageWindowMgr:
print "Creating tabbed chat window for '%s'" % str(key)
win = self._new_window()
self.windows[key] = win
assert(win)
return win

View file

@ -315,6 +315,7 @@ class RosterWindow:
def join_gc_room(self, account, room_jid, nick, password):
'''joins the room immediatelly'''
# FIXME
if room_jid in gajim.interface.instances[account]['gc'] and \
gajim.gc_connected[account][room_jid]:
dialogs.ErrorDialog(_('You are already in room %s') % room_jid
@ -1355,6 +1356,7 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
model = self.tree.get_model()
iter = model.get_iter(path)
type = model[iter][C_TYPE]
# FIXME
if type in ('agent', 'contact'):
account = model[iter][C_ACCOUNT].decode('utf-8')
jid = model[iter][C_JID].decode('utf-8')
@ -1649,7 +1651,9 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
def new_chat(self, contact, account):
# Get target window, create a control, and associate it with the window
mw = gajim.interface.msg_win_mgr.get_window(contact, account,
mw = gajim.interface.msg_win_mgr.get_window(contact.jid)
if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account,
ChatControl.TYPE_ID)
chat_control = ChatControl(mw, contact, account)
mw.new_tab(chat_control)
@ -1680,7 +1684,9 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
def new_room(self, jid, nick, account):
# FIXME: Not contact. Use jid and nick
# Get target window, create a control, and associate it with the window
mw = gajim.interface.msg_win_mgr.get_window(contact, account,
mw = gajim.interface.msg_win_mgr.get_window(contact.jid)
if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account,
GroupchatControl.TYPE_ID)
gc_control = ChatControl(mw, contact, account)
mw.new_tab(gc_control)
@ -2006,14 +2012,16 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
if first_ev:
if self.open_event(account, jid, first_ev):
return
chats = gajim.interface.instances[account]['chats']
if chats.has_key(jid):
chats[jid].set_active_tab(jid)
# Get the window containing the chat
win = gajim.interface.msg_win_mgr.get_window(jid)
if win:
win.set_active_tab(jid)
elif gajim.contacts[account].has_key(jid):
c = gajim.get_contact_instance_with_highest_priority(account, jid)
self.new_chat(c, account)
chats[jid].set_active_tab(jid)
chats[jid].window.present()
contact = gajim.get_contact_instance_with_highest_priority(account, jid)
self.new_chat(contact, account)
win = gajim.interface.msg_win_mgr.get_window(jid)
win.set_active_tab(jid)
win.window.present()
def on_roster_treeview_row_expanded(self, widget, iter, path):
'''When a row is expanded change the icon of the arrow'''