new add contact window. TODO: enable the register button when our server have this transport. Fixes #872

This commit is contained in:
Yann Leboulanger 2006-07-31 13:32:40 +00:00
parent b106481011
commit 6e5ce765d9
2 changed files with 824 additions and 350 deletions

File diff suppressed because it is too large Load Diff

View File

@ -395,6 +395,9 @@ 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',
5:'yahoo'}
tab_num = {'jabber':0, 'aim':1, 'gadu-gadu':2, 'icq':3, 'msn':4, 'yahoo':5}
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
@ -416,60 +419,47 @@ class AddNewContactWindow:
self.account_label = self.xml.get_widget('account_label') 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.uid_entry = self.xml.get_widget('uid_entry')
self.protocol_combobox = self.xml.get_widget('protocol_combobox')
self.protocol_hbox = self.xml.get_widget('protocol_hbox')
self.jid_entry = self.xml.get_widget('jid_entry')
self.nickname_entry = self.xml.get_widget('nickname_entry') self.nickname_entry = self.xml.get_widget('nickname_entry')
self.transports_notebook = self.xml.get_widget('transports_notebook')
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.old_uid_value = '' self.agents = {'jabber': ''}
liststore = gtk.ListStore(str, str)
liststore.append(['Jabber', ''])
self.agents = ['Jabber']
jid_agents = []
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' and\ if _('Transports') in contact.groups and contact.show != 'offline' \
contact.show != 'error': and contact.show != 'error':
jid_agents.append(j) type_ = gajim.get_transport_name_from_jid(contact.jid)
for a in jid_agents: if not type_ in self.tab_num:
if a.find('aim') > -1: # unknown transport type
name = 'AIM' continue
elif a.find('icq') > -1: if type_ in self.agents:
name = 'ICQ' # we already have it
elif a.find('msn') > -1: continue
name = 'MSN' widget = self.xml.get_widget(type_ + '_register_button')
elif a.find('yahoo') > -1: widget.set_no_show_all(True)
name = 'Yahoo!' widget.hide()
else: self.agents[type_] = contact.jid
name = a for type_ in self.tab_num:
liststore.append([name, a]) if type_ in self.agents:
self.agents.append(name) continue
self.protocol_combobox.set_model(liststore) widget = self.xml.get_widget(type_ + '_register_form')
self.protocol_combobox.set_active(0) widget.set_no_show_all(True)
self.fill_jid() widget.hide()
#TODO: make button sensitive if we can register and add callback
if jid: if jid:
self.jid_entry.set_text(jid) type_ = gajim.get_transport_name_from_jid(jid)
self.uid_entry.set_sensitive(False) if not type_:
jid_splited = jid.split('@') type_ = 'jabber'
if jid_splited[1] in jid_agents: self.xml.get_widget(type_ + '_entry').set_text(jid)
uid = jid_splited[0].replace('%', '@') self.transports_notebook.set_active_tab(self.tab_num[type_])
self.uid_entry.set_text(uid)
self.protocol_combobox.set_active(jid_agents.index(jid_splited[1])\
+ 1)
else:
self.uid_entry.set_text(jid)
self.protocol_combobox.set_active(0)
if user_nick: if user_nick:
self.nickname_entry.set_text(user_nick) self.nickname_entry.set_text(user_nick)
else:
self.set_nickname()
self.nickname_entry.grab_focus() self.nickname_entry.grab_focus()
self.group_comboboxentry = self.xml.get_widget('group_comboboxentry') self.group_comboboxentry = self.xml.get_widget('group_comboboxentry')
liststore = gtk.ListStore(str) liststore = gtk.ListStore(str)
@ -485,18 +475,11 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
self.group_comboboxentry.set_active(i) self.group_comboboxentry.set_active(i)
i += 1 i += 1
if not jid_agents:
# There are no transports, so hide the protocol combobox and label
self.protocol_hbox.hide()
self.protocol_hbox.set_no_show_all(True)
protocol_label = self.xml.get_widget('protocol_label')
protocol_label.hide()
protocol_label.set_no_show_all(True)
if self.account: if self.account:
self.account_label.hide()
self.account_hbox.hide() self.account_hbox.hide()
self.account_label.set_no_show_all(True) self.account_label.hide()
self.account_hbox.set_no_show_all(True) self.account_hbox.set_no_show_all(True)
self.account_label.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:
@ -516,10 +499,18 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
def on_subscribe_button_clicked(self, widget): def on_subscribe_button_clicked(self, widget):
'''When Subscribe button is clicked''' '''When Subscribe button is clicked'''
jid = self.jid_entry.get_text().decode('utf-8') active_tab = self.transports_notebook.get_current_page()
nickname = self.nickname_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
if type_ != 'jabber':
jid = jid.replace('@', '%') + '@' + self.agents[type_]
# check if jid is conform to RFC and stringprep it # check if jid is conform to RFC and stringprep it
try: try:
@ -535,6 +526,10 @@ _('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')
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()
@ -549,53 +544,20 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
_('This contact is already listed in your roster.')) _('This contact is already listed in your roster.'))
return return
message_buffer = self.xml.get_widget('message_textview').get_buffer() if type_ == 'jabber':
start_iter = message_buffer.get_start_iter() message_buffer = self.xml.get_widget('jabber_message_textview').\
end_iter = message_buffer.get_end_iter() get_buffer()
message = message_buffer.get_text(start_iter, end_iter).decode('utf-8') start_iter = message_buffer.get_start_iter()
end_iter = message_buffer.get_end_iter()
message = message_buffer.get_text(start_iter, end_iter).decode('utf-8')
else:
message = ''
group = self.group_comboboxentry.child.get_text().decode('utf-8') group = self.group_comboboxentry.child.get_text().decode('utf-8')
auto_auth = self.xml.get_widget('auto_authorize_checkbutton').get_active() auto_auth = self.xml.get_widget('auto_authorize_checkbutton').get_active()
gajim.interface.roster.req_sub(self, jid, message, self.account, gajim.interface.roster.req_sub(self, jid, message, self.account,
group = group, pseudo = nickname, auto_auth = auto_auth) group = group, pseudo = nickname, auto_auth = auto_auth)
self.window.destroy() self.window.destroy()
def fill_jid(self):
model = self.protocol_combobox.get_model()
index = self.protocol_combobox.get_active()
jid = self.uid_entry.get_text().decode('utf-8').strip()
if index > 0: # it's not jabber but a transport
jid = jid.replace('@', '%')
agent = model[index][1].decode('utf-8')
if agent:
jid += '@' + agent
self.jid_entry.set_text(jid)
def on_protocol_combobox_changed(self, widget):
self.fill_jid()
def guess_agent(self):
uid = self.uid_entry.get_text().decode('utf-8')
model = self.protocol_combobox.get_model()
#If login contains only numbers, it's probably an ICQ number
if uid.isdigit():
if 'ICQ' in self.agents:
self.protocol_combobox.set_active(self.agents.index('ICQ'))
return
def set_nickname(self):
uid = self.uid_entry.get_text().decode('utf-8')
nickname = self.nickname_entry.get_text().decode('utf-8')
if nickname == self.old_uid_value:
self.nickname_entry.set_text(uid.split('@')[0])
def on_uid_entry_changed(self, widget):
uid = self.uid_entry.get_text().decode('utf-8')
self.guess_agent()
self.set_nickname()
self.fill_jid()
self.old_uid_value = uid.split('@')[0]
class AboutDialog: class AboutDialog:
'''Class for about dialog''' '''Class for about dialog'''
def __init__(self): def __init__(self):