we now know when we are connected in a room or not (fix #570)

This commit is contained in:
Yann Leboulanger 2005-08-03 09:23:36 +00:00
parent 11e4f6b471
commit 4e203be8bc
5 changed files with 45 additions and 32 deletions

View file

@ -47,6 +47,7 @@ encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}} gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
gc_connected = {} # tell if we are connected to the room or not {room_jid: True}
groups = {} # list of groups groups = {} # list of groups
newly_added = {} # list of contacts that has just signed in newly_added = {} # list of contacts that has just signed in

View file

@ -1207,6 +1207,7 @@ _('To change the account name, you must be disconnected.')).get_response()
gajim.groups[name] = gajim.groups[self.account] gajim.groups[name] = gajim.groups[self.account]
gajim.contacts[name] = gajim.contacts[self.account] gajim.contacts[name] = gajim.contacts[self.account]
gajim.gc_contacts[name] = gajim.gc_contacts[self.account] gajim.gc_contacts[name] = gajim.gc_contacts[self.account]
gajim.gc_connected[name] = gajim.gc_connected[self.account]
gajim.newly_added[name] = gajim.newly_added[self.account] gajim.newly_added[name] = gajim.newly_added[self.account]
gajim.to_be_removed[name] = gajim.to_be_removed[self.account] gajim.to_be_removed[name] = gajim.to_be_removed[self.account]
gajim.sleeper_state[name] = gajim.sleeper_state[self.account] gajim.sleeper_state[name] = gajim.sleeper_state[self.account]
@ -1234,6 +1235,7 @@ _('To change the account name, you must be disconnected.')).get_response()
del gajim.groups[self.account] del gajim.groups[self.account]
del gajim.contacts[self.account] del gajim.contacts[self.account]
del gajim.gc_contacts[self.account] del gajim.gc_contacts[self.account]
del gajim.gc_connected[self.account]
del gajim.newly_added[self.account] del gajim.newly_added[self.account]
del gajim.to_be_removed[self.account] del gajim.to_be_removed[self.account]
del gajim.sleeper_state[self.account] del gajim.sleeper_state[self.account]
@ -1285,6 +1287,7 @@ _('To change the account name, you must be disconnected.')).get_response()
gajim.groups[name] = {} gajim.groups[name] = {}
gajim.contacts[name] = {} gajim.contacts[name] = {}
gajim.gc_contacts[name] = {} gajim.gc_contacts[name] = {}
gajim.gc_connnected[name] = {}
gajim.newly_added[name] = [] gajim.newly_added[name] = []
gajim.to_be_removed[name] = [] gajim.to_be_removed[name] = []
gajim.nicks[name] = config['name'] gajim.nicks[name] = config['name']
@ -2385,6 +2388,7 @@ class RemoveAccountWindow:
del gajim.groups[self.account] del gajim.groups[self.account]
del gajim.contacts[self.account] del gajim.contacts[self.account]
del gajim.gc_contacts[self.account] del gajim.gc_contacts[self.account]
del gajim.gc_connected[self.account]
del gajim.to_be_removed[self.account] del gajim.to_be_removed[self.account]
del gajim.newly_added[self.account] del gajim.newly_added[self.account]
del gajim.sleeper_state[self.account] del gajim.sleeper_state[self.account]

View file

@ -217,6 +217,9 @@ class Interface:
gobject.timeout_add(30000, self.allow_notif, account) gobject.timeout_add(30000, self.allow_notif, account)
else: else:
gajim.allow_notifications[account] = False gajim.allow_notifications[account] = False
# we are disconnected from all gc
for room_jid in gajim.gc_connected[account]:
self.windows[account]['gc'][room_jid].got_disconnected(room_jid)
self.roster.on_status_changed(account, status) self.roster.on_status_changed(account, status)
if self.remote and self.remote.is_enabled(): if self.remote and self.remote.is_enabled():
self.remote.raise_signal('AccountPresence', (status, account)) self.remote.raise_signal('AccountPresence', (status, account))
@ -1003,6 +1006,7 @@ class Interface:
gajim.contacts[a] = {} gajim.contacts[a] = {}
gajim.groups[a] = {} gajim.groups[a] = {}
gajim.gc_contacts[a] = {} gajim.gc_contacts[a] = {}
gajim.gc_connected[a] = {}
gajim.newly_added[a] = [] gajim.newly_added[a] = []
gajim.to_be_removed[a] = [] gajim.to_be_removed[a] = []
gajim.awaiting_messages[a] = {} gajim.awaiting_messages[a] = {}

View file

@ -50,7 +50,6 @@ class GroupchatWindow(chat.Chat):
'leave', 'me', 'msg', 'nick', 'part', 'topic'] 'leave', 'me', 'msg', 'nick', 'part', 'topic']
self.nicks = {} # our nick for each groupchat we are in self.nicks = {} # our nick for each groupchat we are in
gajim.gc_contacts[account] = {} # contact instances for each room
self.list_treeview = {} self.list_treeview = {}
self.subjects = {} self.subjects = {}
self.name_labels = {} self.name_labels = {}
@ -85,8 +84,6 @@ class GroupchatWindow(chat.Chat):
gajim.config.get('gc-y-position')) gajim.config.get('gc-y-position'))
self.window.resize(gajim.config.get('gc-width'), self.window.resize(gajim.config.get('gc-width'),
gajim.config.get('gc-height')) gajim.config.get('gc-height'))
# whether to ask for comfirmation before closing muc
self.confirm_close = gajim.config.get('confirm_close_muc')
self.window.show_all() self.window.show_all()
def save_var(self, room_jid): def save_var(self, room_jid):
@ -122,24 +119,22 @@ class GroupchatWindow(chat.Chat):
dialog.destroy() dialog.destroy()
return True # stop the propagation of the delete event return True # stop the propagation of the delete event
if self.confirm_close: # whether to ask for comfirmation before closing muc
name = '' if gajim.config.get('confirm_close_muc'):
names = '' names = []
if len(self.xmls) >= 2: for room_jid in self.xmls:
for room in self.xmls: if gajim.gc_connected[self.account][room_jid]:
if names != '': names.append(gajim.get_nick_from_jid(room_jid))
names += ', '
names += gajim.get_nick_from_jid(room)
else:
name = gajim.get_nick_from_jid(room_jid)
pritext = ngettext('Are you sure you want to leave room "%s"?' % name, if len(names): #if one or more rooms connected
'Are you sure you want to leave rooms "%s"?' % names, len(self.xmls)) pritext = ngettext('Are you sure you want to leave room "%s"?' % \
names[0], 'Are you sure you want to leave rooms "%s"?' % \
', '.join(names), len(names))
sectext = ngettext( sectext = ngettext(
'If you close this window, you will be disconnected from this room.', 'If you close this window, you will be disconnected from this room.',
'If you close this window, you will be disconnected from these rooms.', 'If you close this window, you will be disconnected from these rooms.',
len(self.xmls)) len(names))
dialog = dialogs.ConfirmationDialogCheck(pritext, sectext, dialog = dialogs.ConfirmationDialogCheck(pritext, sectext,
_('Do not ask me again') ) _('Do not ask me again') )
@ -152,6 +147,7 @@ class GroupchatWindow(chat.Chat):
dialog.destroy() dialog.destroy()
for room_jid in self.xmls: for room_jid in self.xmls:
if gajim.gc_connected[self.account][room_jid]:
gajim.connections[self.account].send_gc_status(self.nicks[room_jid], gajim.connections[self.account].send_gc_status(self.nicks[room_jid],
room_jid, 'offline', 'offline') room_jid, 'offline', 'offline')
@ -286,6 +282,8 @@ class GroupchatWindow(chat.Chat):
gajim.gc_contacts[self.account][room_jid][nick] = \ gajim.gc_contacts[self.account][room_jid][nick] = \
Contact(jid = j, name = nick, show = show, resource = resource, Contact(jid = j, name = nick, show = show, resource = resource,
role = role, affiliation = affiliation) role = role, affiliation = affiliation)
if nick == self.nicks[room_jid]: # we became online
gajim.gc_connected[self.account][room_jid] = True
self.list_treeview[room_jid].expand_row((model.get_path(role_iter)), self.list_treeview[room_jid].expand_row((model.get_path(role_iter)),
False) False)
return iter return iter
@ -341,8 +339,7 @@ class GroupchatWindow(chat.Chat):
self.nicks[room_jid] = new_nick self.nicks[room_jid] = new_nick
self.remove_contact(room_jid, nick) self.remove_contact(room_jid, nick)
if nick == self.nicks[room_jid] and statusCode != '303': # We became offline if nick == self.nicks[room_jid] and statusCode != '303': # We became offline
model.clear() self.got_disconnected(room_jid)
gajim.gc_contacts[self.account][room_jid] = {}
else: else:
iter = self.get_contact_iter(room_jid, nick) iter = self.get_contact_iter(room_jid, nick)
if not iter: if not iter:
@ -945,18 +942,24 @@ class GroupchatWindow(chat.Chat):
room_jid, 'offline', 'offline') room_jid, 'offline', 'offline')
del self.nicks[room_jid] del self.nicks[room_jid]
del gajim.gc_contacts[self.account][room_jid] del gajim.gc_contacts[self.account][room_jid]
del gajim.gc_connected[self.account][room_jid]
del self.list_treeview[room_jid] del self.list_treeview[room_jid]
del self.subjects[room_jid] del self.subjects[room_jid]
del self.name_labels[room_jid] del self.name_labels[room_jid]
del self.hpaneds[room_jid] del self.hpaneds[room_jid]
def got_disconnected(self, room_jid):
model = self.list_treeview[room_jid].get_model()
model.clear()
gajim.gc_contacts[self.account][room_jid] = {}
gajim.gc_connected[self.account][room_jid] = False
def new_room(self, room_jid, nick): def new_room(self, room_jid, nick):
self.names[room_jid] = room_jid.split('@')[0] self.names[room_jid] = room_jid.split('@')[0]
self.xmls[room_jid] = gtk.glade.XML(GTKGUI_GLADE, 'gc_vbox', APP) self.xmls[room_jid] = gtk.glade.XML(GTKGUI_GLADE, 'gc_vbox', APP)
self.childs[room_jid] = self.xmls[room_jid].get_widget('gc_vbox') self.childs[room_jid] = self.xmls[room_jid].get_widget('gc_vbox')
chat.Chat.new_tab(self, room_jid) chat.Chat.new_tab(self, room_jid)
self.nicks[room_jid] = nick self.nicks[room_jid] = nick
gajim.gc_contacts[self.account][room_jid] = {}
self.subjects[room_jid] = '' self.subjects[room_jid] = ''
self.room_creation[room_jid] = time.time() self.room_creation[room_jid] = time.time()
self.nick_hits[room_jid] = [] self.nick_hits[room_jid] = []
@ -1021,6 +1024,7 @@ class GroupchatWindow(chat.Chat):
self.redraw_tab(room_jid) self.redraw_tab(room_jid)
self.show_title() self.show_title()
self.set_subject(room_jid, '') # Set an empty subject to show the room_jid self.set_subject(room_jid, '') # Set an empty subject to show the room_jid
self.got_disconnected(room_jid) #init some variables
conversation_textview.grab_focus() conversation_textview.grab_focus()
self.childs[room_jid].show_all() self.childs[room_jid].show_all()

View file

@ -264,8 +264,8 @@ class RosterWindow:
#FIXME: add avatar #FIXME: add avatar
def join_gc_room(self, account, room_jid, nick, password): def join_gc_room(self, account, room_jid, nick, password):
#FIXME: maybe remove this and just let the server do the message? if room_jid in self.plugin.windows[account]['gc'] and \
if room_jid in self.plugin.windows[account]['gc']: 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()
return return