new add_contact window with a combobox. Fixes #872

This commit is contained in:
Yann Leboulanger 2006-08-03 19:13:42 +00:00
parent e261e0a7a0
commit 2428298bda
4 changed files with 446 additions and 908 deletions

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ class Connection(ConnectionHandlers):
self.jids_for_auto_auth = [] # list of jid to auto-authorize self.jids_for_auto_auth = [] # list of jid to auto-authorize
self.muc_jid = {} # jid of muc server for each transport type self.muc_jid = {} # jid of muc server for each transport type
self.available_transports = {} # list of available transports on this self.available_transports = {} # list of available transports on this
# server {'icq': 'icq.server.com', } # server {'icq': ['icq.server.com', 'icq2.server.com'], }
self.vcard_supported = True self.vcard_supported = True
# END __init__ # END __init__

View File

@ -758,7 +758,10 @@ class ConnectionDisco:
type_ = transport_type or 'jabber' type_ = transport_type or 'jabber'
self.muc_jid[type_] = jid self.muc_jid[type_] = jid
if transport_type: if transport_type:
self.available_transports[transport_type] = jid if self.available_transports.has_key(transport_type):
self.available_transports[transport_type].append(jid)
else:
self.available_transports[transport_type] = [jid]
self.dispatch('AGENT_INFO_INFO', (jid, node, identities, self.dispatch('AGENT_INFO_INFO', (jid, node, identities,
features, data)) features, data))

View File

@ -21,7 +21,6 @@
import gtk import gtk
import gobject import gobject
import os import os
import sys
import gtkgui_helpers import gtkgui_helpers
import vcard import vcard
@ -395,9 +394,12 @@ class ChangeStatusMessageDialog:
class AddNewContactWindow: class AddNewContactWindow:
'''Class for AddNewContactWindow''' '''Class for AddNewContactWindow'''
tab_transport = {0: 'jabber', 1:'aim', 2:'gadu-gadu', 3:'icq', 4:'msn', uid_labels = {'jabber': _('Jabber ID'),
5:'yahoo'} 'aim': _('AIM Address'),
tab_num = {'jabber':0, 'aim':1, 'gadu-gadu':2, 'icq':3, 'msn':4, 'yahoo':5} 'gadu-gadu': _('GG Number'),
'icq': _('ICQ Number'),
'msn': _('MSN Address'),
'yahoo': _('Yahoo! Address')}
def __init__(self, account = None, jid = None, user_nick = None, def __init__(self, account = None, jid = None, user_nick = None,
group = None): group = None):
self.account = account self.account = account
@ -423,60 +425,98 @@ class AddNewContactWindow:
return return
location['add_contact'] = self location['add_contact'] = self
self.xml = gtkgui_helpers.get_glade('add_new_contact_window.glade') self.xml = gtkgui_helpers.get_glade('add_new_contact_window.glade')
self.account_combobox = self.xml.get_widget('account_combobox')
self.account_hbox = self.xml.get_widget('account_hbox')
self.account_label = self.xml.get_widget('account_label')
self.window = self.xml.get_widget('add_new_contact_window') self.window = self.xml.get_widget('add_new_contact_window')
self.window.set_transient_for(gajim.interface.roster.window) self.window.set_transient_for(gajim.interface.roster.window)
self.nickname_entry = self.xml.get_widget('nickname_entry') for w in ('account_combobox', 'account_hbox', 'account_label',
self.transports_notebook = self.xml.get_widget('transports_notebook') 'uid_label', 'uid_entry', 'protocol_combobox', 'protocol_jid_combobox',
'protocol_hbox', 'nickname_entry', 'message_scrolledwindow',
'register_hbox', 'subscription_table', 'add_button',
'message_textview', 'connected_label', 'group_comboboxentry'):
self.__dict__[w] = self.xml.get_widget(w)
if account and len(gajim.connections) >= 2: if account and len(gajim.connections) >= 2:
prompt_text =\ prompt_text =\
_('Please fill in the data of the contact you want to add in account %s') %account _('Please fill in the data of the contact you want to add in account %s') %account
else: else:
prompt_text = _('Please fill in the data of the contact you want to add') prompt_text = _('Please fill in the data of the contact you want to add')
self.xml.get_widget('prompt_label').set_text(prompt_text) self.xml.get_widget('prompt_label').set_text(prompt_text)
self.agents = {'jabber': ''} self.agents = {'jabber': []}
# types to which we are not subscribed but account has an agent for it
self.available_types = []
for acct in accounts: for acct in accounts:
for j in gajim.contacts.get_jid_list(acct): for j in gajim.contacts.get_jid_list(acct):
contact = gajim.contacts.get_first_contact_from_jid(acct, j) contact = gajim.contacts.get_first_contact_from_jid(acct, j)
if _('Transports') in contact.groups and contact.show != 'offline' \ if _('Transports') in contact.groups:
and contact.show != 'error': type_ = gajim.get_transport_name_from_jid(j)
type_ = gajim.get_transport_name_from_jid(contact.jid) if self.agents.has_key(type_):
if not type_ in self.tab_num: self.agents[type_].append(j)
# unknown transport type else:
continue self.agents[type_] = [j]
if type_ in self.agents: # Now add the one to which we can register
# we already have it for acct in accounts:
continue for type_ in gajim.connections[account].available_transports:
widget = self.xml.get_widget(type_ + '_register_button')
widget.set_no_show_all(True)
widget.hide()
self.agents[type_] = contact.jid
for type_ in self.tab_num:
if type_ in self.agents: if type_ in self.agents:
continue continue
widget = self.xml.get_widget(type_ + '_register_form') self.agents[type_] = []
widget.set_no_show_all(True) for jid_ in gajim.connections[account].available_transports[type_]:
widget.hide() self.agents[type_].append(jid_)
if type_ in gajim.connections[self.account].available_transports: self.available_types.append(type_)
widget = self.xml.get_widget(type_ + '_register_button') liststore = gtk.ListStore(str)
widget.set_sensitive(True) self.group_comboboxentry.set_model(liststore)
widget.connect('clicked', self.on_register_button_clicked, liststore = gtk.ListStore(str, str)
gajim.connections[self.account].available_transports[type_]) uf_type = {'jabber': 'Jabber', 'aim': 'AIM', 'gadu-gadu': 'Gadu Gadu',
'icq': 'ICQ', 'msn': 'MSN', 'yahoo': 'Yahoo'}
# Jabber as first
liststore.append(['Jabber', 'jabber'])
for type_ in self.agents:
if type_ == 'jabber':
continue
liststore.append([uf_type[type_], type_])
self.protocol_combobox.set_model(liststore)
self.protocol_combobox.set_active(0)
self.protocol_jid_combobox.set_sensitive(False)
self.subscription_table.set_no_show_all(True)
self.message_scrolledwindow.set_no_show_all(True)
self.register_hbox.set_no_show_all(True)
self.register_hbox.hide()
self.connected_label.set_no_show_all(True)
self.connected_label.hide()
liststore = gtk.ListStore(str)
self.protocol_jid_combobox.set_model(liststore)
self.xml.signal_autoconnect(self)
if jid: if jid:
type_ = gajim.get_transport_name_from_jid(jid) type_ = gajim.get_transport_name_from_jid(jid) or 'jabber'
if not type_: if type_ == 'jabber':
type_ = 'jabber' self.uid_entry.set_text(jid)
self.xml.get_widget(type_ + '_entry').set_text(jid) else:
self.transports_notebook.set_active_tab(self.tab_num[type_]) uid, transport = gajim.get_room_name_and_server_from_room_jid(jid)
self.uid_entry.set_text(uid.replace('%', '@', 1))
#set protocol_combobox
model = self.protocol_combobox.get_model()
iter = model.get_iter_first()
i = 0
while iter:
if model[iter][1] == type_:
self.protocol_combobox.set_active(i)
break
iter = model.iter_next(iter)
i += 1
# set protocol_jid_combobox
self.protocol_combobox.set_active(o)
model = self.protocol_jid_combobox.get_model()
iter = model.get_iter_first()
i = 0
while iter:
if model[iter][0] == transport:
self.protocol_combobox.set_active(i)
break
iter = model.iter_next(iter)
i += 1
if user_nick: if user_nick:
self.nickname_entry.set_text(user_nick) self.nickname_entry.set_text(user_nick)
self.nickname_entry.grab_focus() self.nickname_entry.grab_focus()
self.group_comboboxentry = self.xml.get_widget('group_comboboxentry') else:
liststore = gtk.ListStore(str) self.uid_entry.grab_focus()
self.group_comboboxentry.set_model(liststore)
group_names = [] group_names = []
i = 0 i = 0
for acct in accounts: for acct in accounts:
@ -489,17 +529,16 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
i += 1 i += 1
if self.account: if self.account:
self.account_hbox.hide()
self.account_label.hide() self.account_label.hide()
self.account_hbox.set_no_show_all(True) self.account_hbox.hide()
self.account_label.set_no_show_all(True) self.account_label.set_no_show_all(True)
self.account_hbox.set_no_show_all(True)
else: else:
liststore = gtk.ListStore(str, str) liststore = gtk.ListStore(str, str)
for acct in accounts: for acct in accounts:
liststore.append([acct, acct]) liststore.append([acct, acct])
self.account_combobox.set_model(liststore) self.account_combobox.set_model(liststore)
self.account_combobox.set_active(0) self.account_combobox.set_active(0)
self.xml.signal_autoconnect(self)
self.window.show_all() self.window.show_all()
def on_add_new_contact_window_destroy(self, widget): def on_add_new_contact_window_destroy(self, widget):
@ -509,7 +548,8 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
location = gajim.interface.instances location = gajim.interface.instances
del location['add_contact'] del location['add_contact']
def on_register_button_clicked(self, widget, jid): def on_register_button_clicked(self, widget):
jid = self.protocol_jid_combobox.get_active_text().decode('utf-8')
gajim.connections[self.account].request_register_agent_info(jid) gajim.connections[self.account].request_register_agent_info(jid)
def on_add_new_contact_window_key_press_event(self, widget, event): def on_add_new_contact_window_key_press_event(self, widget, event):
@ -520,20 +560,19 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
'''When Cancel button is clicked''' '''When Cancel button is clicked'''
self.window.destroy() self.window.destroy()
def on_subscribe_button_clicked(self, widget): def on_add_button_clicked(self, widget):
'''When Subscribe button is clicked''' '''When Subscribe button is clicked'''
active_tab = self.transports_notebook.get_current_page() jid = self.uid_entry.get_text().decode('utf-8')
type_ = self.tab_transport[active_tab]
if type_ not in self.agents:
pritext = _('Transport Not Registered')
ErrorDialog(pritext, _('You must register to a transport to be able to add a %s contact.') % type_)
return
jid = self.xml.get_widget(type_ + '_entry').get_text().decode('utf-8')
if not jid: if not jid:
return return
model = self.protocol_combobox.get_model()
iter = self.protocol_combobox.get_active_iter()
type_ = model[iter][1]
if type_ != 'jabber': if type_ != 'jabber':
jid = jid.replace('@', '%') + '@' + self.agents[type_] transport = self.protocol_jid_combobox.get_active_text().decode(
'utf-8')
jid = jid.replace('@', '%') + '@' + transport
# check if jid is conform to RFC and stringprep it # check if jid is conform to RFC and stringprep it
try: try:
@ -549,10 +588,7 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
ErrorDialog(pritext, _('The user ID must not contain a resource.')) ErrorDialog(pritext, _('The user ID must not contain a resource.'))
return return
nickname = self.nickname_entry.get_text().decode('utf-8') nickname = self.nickname_entry.get_text().decode('utf-8') or ''
if not nickname:
nickname = ''
# get value of account combobox, if account was not specified # get value of account combobox, if account was not specified
if not self.account: if not self.account:
model = self.account_combobox.get_model() model = self.account_combobox.get_model()
@ -568,8 +604,7 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
return return
if type_ == 'jabber': if type_ == 'jabber':
message_buffer = self.xml.get_widget('jabber_message_textview').\ message_buffer = self.message_textview.get_buffer()
get_buffer()
start_iter = message_buffer.get_start_iter() start_iter = message_buffer.get_start_iter()
end_iter = message_buffer.get_end_iter() end_iter = message_buffer.get_end_iter()
message = message_buffer.get_text(start_iter, end_iter).decode('utf-8') message = message_buffer.get_text(start_iter, end_iter).decode('utf-8')
@ -581,21 +616,60 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
group = group, pseudo = nickname, auto_auth = auto_auth) group = group, pseudo = nickname, auto_auth = auto_auth)
self.window.destroy() self.window.destroy()
def on_protocol_combobox_changed(self, widget):
model = widget.get_model()
iter = widget.get_active_iter()
type_ = model[iter][1]
model = self.protocol_jid_combobox.get_model()
model.clear()
if len(self.agents[type_]):
for jid_ in self.agents[type_]:
model.append([jid_])
self.protocol_jid_combobox.set_active(0)
self.protocol_jid_combobox.set_sensitive(True)
else:
self.protocol_jid_combobox.set_sensitive(False)
if type_ in self.uid_labels:
self.uid_label.set_text(self.uid_labels[type_])
else:
self.uid_label.set_text(_('User ID'))
if type_ == 'jabber':
self.message_scrolledwindow.show()
else:
self.message_scrolledwindow.hide()
if type_ in self.available_types:
self.register_hbox.set_no_show_all(False)
self.register_hbox.show_all()
self.connected_label.hide()
self.subscription_table.hide()
self.add_button.set_sensitive(False)
else:
self.register_hbox.hide()
if type_ != 'jabber':
jid = self.protocol_jid_combobox.get_active_text()
contact = gajim.contacts.get_first_contact_from_jid(self.account,
jid)
if contact.show in ('offline', 'error'):
self.subscription_table.hide()
self.connected_label.show()
self.add_button.set_sensitive(False)
return
self.subscription_table.show_all()
self.connected_label.hide()
self.add_button.set_sensitive(True)
def transport_signed_in(self, jid): def transport_signed_in(self, jid):
type_ = gajim.get_transport_name_from_jid(jid) if self.protocol_jid_combobox.get_active_text() == jid:
self.xml.get_widget(type_ + '_register_button').hide() self.register_hbox.hide()
self.agents[type_] = jid self.connected_label.hide()
widget = self.xml.get_widget(type_ + '_register_form') self.subscription_table.show_all()
widget.set_no_show_all(False) self.add_button.set_sensitive(True)
widget.show_all()
def transport_signed_out(self, jid): def transport_signed_out(self, jid):
type_ = gajim.get_transport_name_from_jid(jid) if self.protocol_jid_combobox.get_active_text() == jid:
widget = self.xml.get_widget(type_ + '_register_button') self.subscription_table.hide()
widget.set_no_show_all(False) self.connected_label.show()
widget.show_all() self.add_button.set_sensitive(False)
del self.agents[type_]
self.xml.get_widget(type_ + '_register_form').hide()
class AboutDialog: class AboutDialog:
'''Class for about dialog''' '''Class for about dialog'''