we can now invite to new room

This commit is contained in:
Yann Leboulanger 2006-07-25 22:26:07 +00:00
parent c16d1bff63
commit 65d57253c9
6 changed files with 70 additions and 22 deletions

View File

@ -84,6 +84,7 @@ class Connection(ConnectionHandlers):
self.on_connect_failure = None
self.retrycount = 0
self.jids_for_auto_auth = [] # list of jid to auto-authorize
self.muc_jid = None
# END __init__
def build_user_nick(self, user_nick):

View File

@ -724,11 +724,15 @@ class ConnectionDisco:
qc = iq_obj.getQueryChildren()
if not qc:
qc = []
is_muc = False
for i in qc:
if i.getName() == 'identity':
attr = {}
for key in i.getAttrs().keys():
attr[key] = i.getAttr(key)
if attr.has_key('category') and attr['category'] == 'conference' \
and attr.has_key('type') and attr['type'] == 'text':
is_muc = True
identities.append(attr)
elif i.getName() == 'feature':
features.append(i.getAttr('var'))
@ -742,6 +746,8 @@ class ConnectionDisco:
if id[0] == 'p':
if features.__contains__(common.xmpp.NS_BYTESTREAM):
gajim.proxy65_manager.resolve(jid, self.connection, self.name)
if features.__contains__(common.xmpp.NS_MUC) and is_muc:
self.muc_jid = jid
self.dispatch('AGENT_INFO_INFO', (jid, node, identities,
features, data))

View File

@ -90,6 +90,7 @@ encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
contacts = Contacts()
gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}}
gc_passwords = {} # list of the pass required to enter a room {room_jid: password}
automatic_rooms = {} # list of rooms that must be automaticaly configured and for which we have a list of invities {account: {room_jid: {'invities': []}}}
groups = {} # list of groups
newly_added = {} # list of contacts that has just signed in

View File

@ -923,8 +923,13 @@ class SubscriptionRequestWindow:
self.window.destroy()
class JoinGroupchatWindow:
def __init__(self, account, server = '', room = '', nick = ''):
def __init__(self, account, server = '', room = '', nick = '',
automatic = False):
'''automatic is a dict like {'invities': []}
If automatic is not empty, this means room must be automaticaly configured
and when done, invities must be automatically invited'''
self.account = account
self.automatic = automatic
if nick == '':
nick = gajim.nicks[self.account]
if gajim.connections[account].connected < 2:
@ -1026,10 +1031,12 @@ _('You can not join a group chat unless you are connected.'))
def on_join_button_clicked(self, widget):
'''When Join button is clicked'''
nickname = self.xml.get_widget('nickname_entry').get_text().decode('utf-8')
nickname = self.xml.get_widget('nickname_entry').get_text().decode(
'utf-8')
room = self.xml.get_widget('room_entry').get_text().decode('utf-8')
server = self.xml.get_widget('server_entry').get_text().decode('utf-8')
password = self.xml.get_widget('password_entry').get_text().decode('utf-8')
password = self.xml.get_widget('password_entry').get_text().decode(
'utf-8')
jid = '%s@%s' % (room, server)
try:
jid = helpers.parse_jid(jid)
@ -1044,7 +1051,9 @@ _('You can not join a group chat unless you are connected.'))
if len(self.recently_groupchat) > 10:
self.recently_groupchat = self.recently_groupchat[0:10]
gajim.config.set('recently_groupchat', ' '.join(self.recently_groupchat))
if self.automatic:
gajim.automatic_rooms[self.account][jid] = self.automatic
gajim.interface.roster.join_gc_room(self.account, jid, nickname, password)
self.window.destroy()

View File

@ -899,10 +899,18 @@ class Interface:
def handle_event_gc_config(self, account, array):
#('GC_CONFIG', account, (jid, config)) config is a dict
jid = array[0].split('/')[0]
if not self.instances[account]['gc_config'].has_key(jid):
self.instances[account]['gc_config'][jid] = \
config.GroupchatConfigWindow(account, jid, array[1])
room_jid = array[0].split('/')[0]
if room_jid in gajim.automatic_rooms[account]:
# use default configuration
gajim.connections[account].send_gc_config(room_jid, array[1])
# invite contacts
if gajim.automatic_rooms[account][room_jid].has_key('invities'):
for jid in gajim.automatic_rooms[account][room_jid]['invities']:
gajim.connections[account].send_invite(room_jid, jid)
del gajim.automatic_rooms[account][room_jid]
elif not self.instances[account]['gc_config'].has_key(room_jid):
self.instances[account]['gc_config'][room_jid] = \
config.GroupchatConfigWindow(account, room_jid, array[1])
def handle_event_gc_affiliation(self, account, array):
#('GC_AFFILIATION', account, (room_jid, affiliation, list)) list is list
@ -1840,6 +1848,7 @@ class Interface:
gajim.contacts.add_account(a)
gajim.groups[a] = {}
gajim.gc_connected[a] = {}
gajim.automatic_rooms[a] = {}
gajim.newly_added[a] = []
gajim.to_be_removed[a] = []
gajim.awaiting_events[a] = {}

View File

@ -1393,24 +1393,30 @@ class RosterWindow:
send_single_message_menuitem.connect('activate',
self.on_send_single_message_menuitem_activate, account, contact)
submenu = gtk.Menu()
invite_menuitem.set_submenu(submenu)
menuitem = gtk.ImageMenuItem(_('_New room'))
icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
menuitem.set_image(icon)
menuitem.connect('activate', self.on_invite_to_new_room, [(contact,
account)])
submenu.append(menuitem)
rooms = [] # a list of (room_jid, account) tuple
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC):
acct = gc_control.account
account = gc_control.account
room_jid = gc_control.room_jid
if gajim.gc_connected[acct].has_key(room_jid) and \
gajim.gc_connected[acct][room_jid]:
rooms.append((room_jid, acct))
if gajim.gc_connected[account].has_key(room_jid) and \
gajim.gc_connected[account][room_jid]:
rooms.append((room_jid, account))
if len(rooms):
submenu = gtk.Menu()
invite_menuitem.set_submenu(submenu)
item = gtk.SeparatorMenuItem() # separator
submenu.append(item)
for (room_jid, acct) in rooms:
menuitem = gtk.MenuItem(room_jid.split('@')[0])
menuitem.connect('activate', self.on_invite_to_room,
[(contact, account)], room_jid, acct)
submenu.append(menuitem)
else:
invite_menuitem.set_sensitive(False)
rename_menuitem.connect('activate', self.on_rename, iter, path)
remove_from_roster_menuitem.connect('activate', self.on_req_usub,
[(contact, account)])
@ -1480,8 +1486,6 @@ class RosterWindow:
remove_from_roster_menuitem]:
widget.set_sensitive(False)
#FIXME: create menu for sub contacts
event_button = gtkgui_helpers.get_possible_button_event(event)
roster_contact_context_menu.attach_to_widget(self.tree, None)
@ -1492,10 +1496,28 @@ class RosterWindow:
event.time)
def on_invite_to_new_room(self, widget, list_):
print 'TODO: create a new room'
# Create room
# configure room
# send invitations
account_list = []
jid_list = []
for (contact, account) in list_:
if contact.jid not in jid_list:
jid_list.append(contact.jid)
if account not in account_list:
account_list.append(account)
for account in account_list:
if gajim.connections[account].muc_jid:
# create invities list
# create the room on this muc server
if gajim.interface.instances[account].has_key('join_gc'):
gajim.interface.instances[account]['join_gc'].window.destroy()
try:
gajim.interface.instances[account]['join_gc'] = \
dialogs.JoinGroupchatWindow(account,
server = gajim.connections[account].muc_jid,
automatic = {'invities': jid_list})
except RuntimeError:
continue
break
def on_invite_to_room(self, widget, list_, room_jid, account):
for (contact, acct) in list_: