add new contact dialog code cleanup and some GUI fixes:\nProtocol combobox is disabled if uid is empty\nguess_agent() doesnt change to Jabber if not ICQ\nBecause of massive usage of get_widget() I self'ed them [it's ok this dialog dies soon and it is always better to do less glade parsing

This commit is contained in:
Nikos Kouremenos 2005-05-04 17:44:49 +00:00
parent bc6e64bf16
commit 49ff06842c
2 changed files with 34 additions and 31 deletions

View File

@ -242,6 +242,10 @@ class Add_new_contact_window:
self.account = account self.account = account
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'add_new_contact_window', APP) self.xml = gtk.glade.XML(GTKGUI_GLADE, 'add_new_contact_window', APP)
self.window = self.xml.get_widget('add_new_contact_window') self.window = self.xml.get_widget('add_new_contact_window')
self.uid_entry = self.xml.get_widget('uid_entry')
self.protocol_combobox = self.xml.get_widget('protocol_combobox')
self.jid_entry = self.xml.get_widget('jid_entry')
self.nickname_entry = self.xml.get_widget('nickname_entry')
self.old_uid_value = '' self.old_uid_value = ''
liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
liststore.append(['Jabber', '']) liststore.append(['Jabber', ''])
@ -264,20 +268,20 @@ class Add_new_contact_window:
name = a name = a
iter = liststore.append([name, a]) iter = liststore.append([name, a])
self.agents.append(name) self.agents.append(name)
protocol_combobox = self.xml.get_widget('protocol_combobox')
protocol_combobox.set_model(liststore) self.protocol_combobox.set_model(liststore)
protocol_combobox.set_active(0) self.protocol_combobox.set_active(0)
self.fill_jid() self.fill_jid()
if jid: if jid:
self.xml.get_widget('jid_entry').set_text(jid) self.jid_entry.set_text(jid)
jid_splited = jid.split('@') jid_splited = jid.split('@')
if jid_splited[1] in jid_agents: if jid_splited[1] in jid_agents:
uid = jid_splited[0].replace('%', '@') uid = jid_splited[0].replace('%', '@')
self.xml.get_widget('uid_entry').set_text(uid) self.uid_entry.set_text(uid)
protocol_combobox.set_active(jid_agents.index(jid_splited[1]) + 1) self.protocol_combobox.set_active(jid_agents.index(jid_splited[1]) + 1)
else: else:
self.xml.get_widget('uid_entry').set_text(jid) self.uid_entry.set_text(jid)
protocol_combobox.set_active(0) self.protocol_combobox.set_active(0)
self.set_nickname() self.set_nickname()
self.group_comboboxentry = self.xml.get_widget('group_comboboxentry') self.group_comboboxentry = self.xml.get_widget('group_comboboxentry')
@ -300,8 +304,8 @@ class Add_new_contact_window:
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.xml.get_widget('jid_entry').get_text() jid = self.jid_entry.get_text()
nickname = self.xml.get_widget('nickname_entry').get_text() nickname = self.nickname_entry.get_text()
if not jid: if not jid:
return return
if jid.find('@') < 0: if jid.find('@') < 0:
@ -319,47 +323,44 @@ class Add_new_contact_window:
self.window.destroy() self.window.destroy()
def fill_jid(self): def fill_jid(self):
protocol_combobox = self.xml.get_widget('protocol_combobox') model = self.protocol_combobox.get_model()
model = protocol_combobox.get_model() index = self.protocol_combobox.get_active()
index = protocol_combobox.get_active() jid = self.uid_entry.get_text()
jid = self.xml.get_widget('uid_entry').get_text() if index > 0: # it's not jabber but a transport
if index > 0:
jid = jid.replace('@', '%') jid = jid.replace('@', '%')
agent = model[index][1] agent = model[index][1]
if agent: if agent:
jid += '@' + agent jid += '@' + agent
self.xml.get_widget('jid_entry').set_text(jid) self.jid_entry.set_text(jid)
def on_protocol_combobox_changed(self, widget): def on_protocol_combobox_changed(self, widget):
self.fill_jid() self.fill_jid()
def guess_agent(self): def guess_agent(self):
uid = self.xml.get_widget('uid_entry').get_text() uid = self.uid_entry.get_text()
protocol_combobox = self.xml.get_widget('protocol_combobox') model = self.protocol_combobox.get_model()
model = protocol_combobox.get_model()
#If login contains only numbers, it's probably an ICQ number #If login contains only numbers, it's probably an ICQ number
try: if uid.isdigit():
int(uid) # will raise ValueError if not all numbers
except:
pass
else:
if 'ICQ' in self.agents: if 'ICQ' in self.agents:
protocol_combobox.set_active(self.agents.index('ICQ')) self.protocol_combobox.set_active(self.agents.index('ICQ'))
return return
protocol_combobox.set_active(0)
def set_nickname(self): def set_nickname(self):
uid = self.xml.get_widget('uid_entry').get_text() uid = self.uid_entry.get_text()
nickname = self.xml.get_widget('nickname_entry').get_text() nickname = self.nickname_entry.get_text()
if nickname == self.old_uid_value: if nickname == self.old_uid_value:
self.xml.get_widget('nickname_entry').set_text(uid.split('@')[0]) self.nickname_entry.set_text(uid.split('@')[0])
def on_uid_entry_changed(self, widget): def on_uid_entry_changed(self, widget):
uid = self.uid_entry.get_text()
if len(uid) == 0:
self.protocol_combobox.set_sensitive(False)
else:
self.protocol_combobox.set_sensitive(True)
self.guess_agent() self.guess_agent()
self.set_nickname() self.set_nickname()
self.fill_jid() self.fill_jid()
uid = self.xml.get_widget('uid_entry').get_text()
self.old_uid_value = uid.split('@')[0] self.old_uid_value = uid.split('@')[0]
class About_dialog: class About_dialog:

View File

@ -1733,6 +1733,7 @@
<child> <child>
<widget class="GtkComboBox" id="protocol_combobox"> <widget class="GtkComboBox" id="protocol_combobox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property>
<property name="items" translatable="yes"></property> <property name="items" translatable="yes"></property>
<signal name="changed" handler="on_protocol_combobox_changed" last_modification_time="Wed, 23 Mar 2005 13:13:12 GMT"/> <signal name="changed" handler="on_protocol_combobox_changed" last_modification_time="Wed, 23 Mar 2005 13:13:12 GMT"/>
</widget> </widget>
@ -1770,13 +1771,14 @@
<child> <child>
<widget class="GtkEntry" id="jid_entry"> <widget class="GtkEntry" id="jid_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property>
<property name="editable">False</property> <property name="editable">False</property>
<property name="visibility">True</property> <property name="visibility">True</property>
<property name="max_length">0</property> <property name="max_length">0</property>
<property name="text" translatable="yes"></property> <property name="text" translatable="yes"></property>
<property name="has_frame">True</property> <property name="has_frame">True</property>
<property name="invisible_char">*</property> <property name="invisible_char">*</property>
<property name="activates_default">True</property> <property name="activates_default">False</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>