diff --git a/data/glade/account_creation_wizard_window.glade b/data/glade/account_creation_wizard_window.glade index c3afcd23f..50d61e400 100644 --- a/data/glade/account_creation_wizard_window.glade +++ b/data/glade/account_creation_wizard_window.glade @@ -1,1244 +1,825 @@ - - - + + + - - - 12 - Gajim: Account Creation Wizard - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - - - - - True - False - 6 - - - - True - False - False - GTK_POS_TOP - False - False - - - - True - False - 12 - - - - True - You need to have an account in order to connect + + 12 + Gajim: Account Creation Wizard + False + + + + True + 6 + + + True + False + False + + + True + 12 + + + True + 0 + You need to have an account in order to connect to the Jabber network. - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 0 - 0.5 - GTK_SHADOW_NONE - - - - True - 0.5 - 0.5 - 1 - 1 - 5 - 0 - 12 - 0 - - - - 6 - True - False - 6 - - - - True - True - I already have an account I want to use - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - True - I want to _register for a new account - True - GTK_RELIEF_NORMAL - True - False - False - True - use_existing_account_radiobutton - - - 0 - False - False - - - - - - - - - - True - <b>Please choose one of the options below:</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - 0 - False - False - - - - - False - True - - - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - 6 - True - False - 12 - - - - True - <b>Please fill in the data for your new account</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - True - 6 - 3 - False - 6 - 12 - - - - True - True - True - True - True - 0 - - True - * - False - - - - - 1 - 2 - 0 - 1 - - - - - - - True - _Server: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - False - True - True - - - - 1 - 2 - 1 - 2 - fill - fill - - - - - - True - Click to see features (like MSN, ICQ transports) of jabber servers - True - Servers Features - True - GTK_RELIEF_NORMAL - True - - - - 2 - 3 - 1 - 2 - fill - - - - - - - True - _Password: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - pass1_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - If checked, Gajim will remember the password for this account - True - Save pass_word - True - GTK_RELIEF_NORMAL - False - True - False - True - - - - 2 - 3 - 2 - 3 - fill - - - - - - - True - True - True - False - 0 - - True - * - True - - - 1 - 2 - 2 - 3 - - - - - - - True - _Username: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - username_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - True - True - False - 0 - - True - * - True - - - 1 - 2 - 3 - 4 - - - - - - - True - _Retype Password: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - pass2_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - False - 0 - - - - 5 - True - 4 - 2 - False - 5 - 5 - - - - True - _Host: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - proxyhost_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 0 - 1 - fill - - - - - - - True - _Port: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - proxyport_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 1 - 2 - fill - - - - - - - True - _Username: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - proxyuser_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - - - - True - Pass_word: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - proxypass_entry - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 3 - 4 - fill - - - - - - - True - True - True - True - 0 - - True - * - False - - - 1 - 2 - 0 - 1 - - - - - - - True - True - True - True - 0 - 3128 - True - * - False - - - - 1 - 2 - 1 - 2 - - - - - - - True - True - True - True - 0 - - True - * - False - - - - 1 - 2 - 2 - 3 - - - - - - - True - True - True - False - 0 - - True - * - False - - - - 1 - 2 - 3 - 4 - - - - - - - - - True - _Use proxy - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - 0 - 3 - 5 - 6 - fill - - - - - - True - Your JID: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 4 - 5 - fill - - - - - - - True - True - - False - True - GTK_JUSTIFY_LEFT - False - True - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 1 - 3 - 4 - 5 - fill - - - - - - 0 - True - True - - - - - False - True - - - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - True - False - 0 - - - - True - <b>Account is being created</b> + + + False + False + + + + + True + 0 + GTK_SHADOW_NONE + + + True + 5 + 12 + + + True + 6 + 6 + + + True + True + I already have an account I want to use + True + True + + + False + False + + + + + True + True + I want to _register for a new account + True + True + use_existing_account_radiobutton + + + False + False + 1 + + + + + + + + + True + <b>Please choose one of the options below:</b> + True + + + label_item + + + + + False + False + 1 + + + + + False + + + + + True + + + tab + False + False + + + + + True + 6 + 12 + + + True + 0 + <b>Please fill in the data for your new account</b> + True + + + False + False + + + + + True + 4 + 3 + 12 + 6 + + + + + + + + + True + True + 0 + True + True + + + 1 + 3 + 3 + 4 + GTK_FILL + + + + + + True + 0 + Your JID: + + + 3 + 4 + GTK_FILL + + + + + + True + 0 + _Username: + True + username_entry + + + GTK_FILL + + + + + + True + True + False + * + True + + + 1 + 2 + 2 + 3 + + + + + + True + True + If checked, Gajim will remember the password for this account + Save pass_word + True + False + True + True + + + + 2 + 3 + 2 + 3 + GTK_FILL + + + + + + True + 0 + _Password: + True + password_entry + + + 2 + 3 + GTK_FILL + + + + + + True + + + + + + + + 1 + 2 + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + _Server: + True + + + 1 + 2 + GTK_FILL + + + + + + True + True + True + * + + + + + 1 + 2 + + + + + + 1 + + + + + 1 + False + + + + + True + + + tab + 1 + False + False + + + + + True + 6 + 12 + + + True + 0 + <b>Please select a server</b> + True + + + False + False + + + + + True + 6 + + + True + 0 + _Server: + True + + + False + False + + + + + True + + + + + + + 1 + + + + + True + True + Click to see features (like MSN, ICQ transports) of jabber servers + Servers Features + True + + + + False + False + 2 + + + + + False + False + 1 + + + + + True + True + + + True + 5 + 3 + 3 + 5 + 5 + + + True + False + 6 + + + True + 0 + _Hostname: + True + custom_host_entry + + + False + False + + + + + True + True + + + 1 + + + + + True + 0 + _Port: + True + custom_port_entry + + + False + False + 2 + + + + + True + True + 6 + 5222 + + + False + 3 + + + + + 3 + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + Use custom hostname/port + True + True + + + + 3 + 1 + 2 + + + + + + True + True + Manage... + True + + + + 2 + 3 + + + + + + + True + None + + + 1 + 2 + GTK_FILL + + + + + True + 0 + Prox_y: + True + + + GTK_FILL + + + + + + + + True + _Advanced + True + + + label_item + + + + + 2 + + + + + 2 + False + + + + + True + + + tab + 2 + False + False + + + + + True + + + + + + 3 + False + + + + + True + + + tab + 3 + False + False + + + + + True + + + True + <b>Connecting to server</b> Please wait... - False - True - GTK_JUSTIFY_CENTER - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - True - False - - - - - - True - GTK_PROGRESS_LEFT_TO_RIGHT - 0 - 0.10000000149 - PANGO_ELLIPSIZE_NONE - - - 0 - False - False - - - - - False - True - - - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - - True - False - 0 - - - - True - False - 12 - - - - True - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - - False - True - GTK_JUSTIFY_LEFT - True - False - 0.10000000149 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - True - True - - - - - 0 - True - True - - - - - - True - True - Connect when I press Finish - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - - True - True - Set my profile when I connect - True - GTK_RELIEF_NORMAL - True - True - False - True - - - 0 - False - False - - - - - False - True - - - - - - True - - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - tab - - - - - 0 - True - True - - - - - - True - GTK_BUTTONBOX_END - 12 - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - - - - - - - True - False - True - True - gtk-go-back - True - GTK_RELIEF_NORMAL - True - - - - - - - True - True - True - True - gtk-go-forward - True - GTK_RELIEF_NORMAL - True - - - - - - - True - True - GTK_RELIEF_NORMAL - True - - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-preferences - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Advanced - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - - True - True - GTK_RELIEF_NORMAL - True - - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-apply - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Finish - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - 0 - False - True - - - - - - + True + GTK_JUSTIFY_CENTER + + + False + + + + + True + 0.10000000149 + + + False + False + 1 + + + + + 4 + False + + + + + True + + + tab + 4 + False + False + + + + + True + + + True + 12 + + + True + gtk-missing-image + + + False + False + + + + + True + 0.10000000149011612 + True + True + + + 1 + + + + + + + True + True + Connect when I press Finish + True + True + True + + + False + False + 1 + + + + + True + True + Set my profile when I connect + True + True + True + + + False + False + 2 + + + + + 5 + False + + + + + True + + + tab + 5 + False + False + + + + + + + True + 12 + GTK_BUTTONBOX_END + + + True + True + True + gtk-cancel + True + + + + + + True + False + True + True + gtk-go-back + True + + + + 1 + + + + + True + True + True + True + gtk-go-forward + True + + + + 2 + + + + + True + True + + + + True + 0 + 0 + + + True + 2 + + + True + gtk-preferences + + + False + False + + + + + True + _Advanced + True + + + False + False + 1 + + + + + + + + + 3 + + + + + True + True + + + + True + 0 + 0 + + + True + 2 + + + True + gtk-apply + + + False + False + + + + + True + _Finish + True + + + False + False + 1 + + + + + + + + + 4 + + + + + False + 1 + + + + + diff --git a/src/common/connection.py b/src/common/connection.py index 717d8ff91..3445d3821 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -206,30 +206,15 @@ class Connection(ConnectionHandlers): # it's a new account if not data[1]: # wrong answer self.dispatch('ACC_NOT_OK', ( - _('Transport %s answered wrongly to register request: %s')\ + _('Server %s answered wrongly to register request: %s')\ % (data[0], data[3]))) return - req = data[1].asDict() - req['username'] = self.new_account_info['name'] - req['password'] = self.new_account_info['password'] - def _on_register_result(result): - if not common.xmpp.isResultNode(result): - self.dispatch('ACC_NOT_OK', (result.getError())) - return - self.password = self.new_account_info['password'] - if USE_GPG: - self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent')) - gajim.config.set('usegpg', True) - else: - gajim.config.set('usegpg', False) - gajim.connections[self.name] = self - self.dispatch('ACC_OK', (self.new_account_info)) - self.new_account_info = None - if self.connection: - self.connection.UnregisterDisconnectHandler(self._on_new_account) - self.disconnect(on_purpose=True) - common.xmpp.features_nb.register(self.connection, data[0], - req, _on_register_result) + is_form = data[2] + if is_form: + conf = data[1] + else: + conf = data[1].asDict() + self.dispatch('NEW_ACC_CONNECTED', (conf, is_form)) return if not data[1]: # wrong answer self.dispatch('ERROR', (_('Invalid answer'), @@ -1014,12 +999,46 @@ class Connection(ConnectionHandlers): self.connection.getRoster().setItem(jid = jid, name = name, groups = groups) + def send_new_account_infos(self, form, is_form): + def _on_register_result(result): + if not common.xmpp.isResultNode(result): + self.dispatch('ACC_NOT_OK', (result.getError())) + return + if USE_GPG: + self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent')) + gajim.config.set('usegpg', True) + else: + gajim.config.set('usegpg', False) + gajim.connections[self.name] = self + self.dispatch('ACC_OK', (self.new_account_info)) + self.new_account_info = None + if self.connection: + self.connection.UnregisterDisconnectHandler(self._on_new_account) + self.disconnect(on_purpose=True) + if is_form: + # Get username and password and put them in new_account_info + for field in self._data_form.iter_fields(): + if field.var == 'username': + self.new_account_info['name'] = field.value + if field.var == 'password': + self.new_account_info['password'] = field.value + iq=Iq('set', NS_REGISTER, to = self._hostname) + iq.setTag('query').addChild(node = form) + self.connection.SendAndCallForResponse(iq, _on_register_result) + else: + # Get username and password and put them in new_account_info + if form.has_key('username'): + self.new_account_info['name'] = form['username'] + if form.has_key('password'): + self.new_account_info['password'] = form['password'] + common.xmpp.features_nb.register(self.connection, self._hostname, + form, _on_register_result) + def new_account(self, name, config, sync = False): # If a connection already exist we cannot create a new account if self.connection: return self._hostname = config['hostname'] - self.server_resource = config['resource'] self.new_account_info = config self.name = name self.on_connect_success = self._on_new_account @@ -1028,13 +1047,11 @@ class Connection(ConnectionHandlers): def _on_new_account(self, con = None, con_type = None): if not con_type: - self.dispatch('ACC_NOT_OK', + self.dispatch('NEW_ACC_NOT_CONNECTED', (_('Could not connect to "%s"') % self._hostname)) return self.on_connect_failure = None self.connection = con - #if con: - # con.RegisterDisconnectHandler(self._on_new_account) common.xmpp.features_nb.getRegInfo(con, self._hostname) def account_changed(self, new_name): diff --git a/src/common/xmpp/features_nb.py b/src/common/xmpp/features_nb.py index 61e54ce7d..5785a3034 100644 --- a/src/common/xmpp/features_nb.py +++ b/src/common/xmpp/features_nb.py @@ -143,7 +143,6 @@ def _ReceivedRegInfo(con, resp, agent): def register(disp, host, info, cb): """ Perform registration on remote server with provided info. disp must be connected dispatcher instance. - Returns true or false depending on registration result. If registration fails you can get additional info from the dispatcher's owner attributes lastErrNode, lastErr and lastErrCode. """ diff --git a/src/config.py b/src/config.py index f35629fe4..e1bcfa062 100644 --- a/src/config.py +++ b/src/config.py @@ -2097,7 +2097,7 @@ class FakeDataForm(gtk.Table, object): self._draw_table() def _draw_table(self): - '''Draw the table in the window''' + '''Draw the table''' nbrow = 0 if self.infos.has_key('instructions'): nbrow = 1 @@ -2778,13 +2778,21 @@ class AccountCreationWizardWindow: 'account_creation_wizard_window.glade') self.window = self.xml.get_widget('account_creation_wizard_window') + completion = gtk.EntryCompletion() # Connect events from comboboxentry.child server_comboboxentry = self.xml.get_widget('server_comboboxentry') entry = server_comboboxentry.child entry.connect('key_press_event', - self.on_server_comboboxentry_key_press_event) - completion = gtk.EntryCompletion() + self.on_server_comboboxentry_key_press_event, server_comboboxentry) entry.set_completion(completion) + # Do the same for the other server comboboxentry + server_comboboxentry1 = self.xml.get_widget('server_comboboxentry1') + entry = server_comboboxentry1.child + entry.connect('key_press_event', + self.on_server_comboboxentry_key_press_event, server_comboboxentry1) + entry.set_completion(completion) + + self.update_proxy_list() # parse servers.xml servers_xml = os.path.join(gajim.DATA_DIR, 'other', 'servers.xml') @@ -2800,6 +2808,8 @@ class AccountCreationWizardWindow: # Put servers into comboboxentries server_comboboxentry.set_model(servers_model) server_comboboxentry.set_text_column(0) + server_comboboxentry1.set_model(servers_model) + server_comboboxentry1.set_text_column(0) # Generic widgets self.notebook = self.xml.get_widget('notebook') @@ -2838,28 +2848,18 @@ class AccountCreationWizardWindow: self.window.destroy() def on_back_button_clicked(self, widget): - if self.notebook.get_current_page() == 1: + if self.notebook.get_current_page() in (1, 2): self.notebook.set_current_page(0) self.back_button.set_sensitive(False) - elif self.notebook.get_current_page() == 3: # finish page + elif self.notebook.get_current_page() == 3: + self.notebook.set_current_page(2) + self.xml.get_widget('form_vbox').remove(self.data_form_widget) + elif self.notebook.get_current_page() == 5: # finish page self.forward_button.show() - self.notebook.set_current_page(1) # Goto parameters page - - def get_widgets(self): - widgets = {} - for widget in ( - 'username_entry', - 'server_comboboxentry', - 'pass1_entry', - 'pass2_entry', - 'save_password_checkbutton', - 'proxyhost_entry', - 'proxyport_entry', - 'proxyuser_entry', - 'proxypass_entry', - 'jid_label'): - widgets[widget] = self.xml.get_widget(widget) - return widgets + if self.modify: + self.notebook.set_current_page(1) # Go to parameters page + else: + self.notebook.set_current_page(2) # Go to server page def on_forward_button_clicked(self, widget): cur_page = self.notebook.get_current_page() @@ -2868,74 +2868,64 @@ class AccountCreationWizardWindow: widget = self.xml.get_widget('use_existing_account_radiobutton') if widget.get_active(): self.modify = True - self.xml.get_widget('server_features_button').hide() - self.xml.get_widget('pass2_entry').hide() - self.xml.get_widget('pass2_label').hide() + self.notebook.set_current_page(1) else: self.modify = False - self.xml.get_widget('server_features_button').show() - self.xml.get_widget('pass2_entry').show() - self.xml.get_widget('pass2_label').show() - self.notebook.set_current_page(1) + self.notebook.set_current_page(2) self.back_button.set_sensitive(True) return - widgets = self.get_widgets() - username = widgets['username_entry'].get_text().decode('utf-8') - if not username: - pritext = _('Invalid username') - sectext = _('You must provide a username to configure this account.') - dialogs.ErrorDialog(pritext, sectext) - return - server = widgets['server_comboboxentry'].child.get_text().decode('utf-8') - savepass = widgets['save_password_checkbutton'].get_active() - password = widgets['pass1_entry'].get_text().decode('utf-8') + elif cur_page == 1: + # We are adding an existing account + username = self.xml.get_widget('username_entry').get_text().decode( + 'utf-8') + if not username: + pritext = _('Invalid username') + sectext = _( + 'You must provide a username to configure this account.') + dialogs.ErrorDialog(pritext, sectext) + return + server = self.xml.get_widget('server_comboboxentry').child.get_text().\ + decode('utf-8') + savepass = self.xml.get_widget('save_password_checkbutton').\ + get_active() + password = self.xml.get_widget('password_entry').get_text().decode( + 'utf-8') - if not self.modify: - if password == '': - dialogs.ErrorDialog(_('Invalid password'), - _('You must enter a password for the new account.')) + jid = username + '@' + server + # check if jid is conform to RFC and stringprep it + try: + jid = helpers.parse_jid(jid) + except helpers.InvalidFormat, s: + pritext = _('Invalid Jabber ID') + dialogs.ErrorDialog(pritext, str(s)) return - if widgets['pass2_entry'].get_text() != password: - dialogs.ErrorDialog(_('Passwords do not match'), - _('The passwords typed in both fields must be identical.')) + already_in_jids = [] + for account in gajim.connections: + j = gajim.config.get_per('accounts', account, 'name') + j += '@' + gajim.config.get_per('accounts', account, 'hostname') + already_in_jids.append(j) + + if jid in already_in_jids: + pritext = _('Duplicate Jabber ID') + sectext = _('This account is already configured in Gajim.') + dialogs.ErrorDialog(pritext, sectext) return - jid = username + '@' + server - # check if jid is conform to RFC and stringprep it - try: - jid = helpers.parse_jid(jid) - except helpers.InvalidFormat, s: - pritext = _('Invalid Jabber ID') - dialogs.ErrorDialog(pritext, str(s)) - return + self.account = server + i = 1 + while self.account in gajim.connections: + self.account = server + str(i) + i += 1 - already_in_jids = [] - for account in gajim.connections: - j = gajim.config.get_per('accounts', account, 'name') - j += '@' + gajim.config.get_per('accounts', account, 'hostname') - already_in_jids.append(j) - - if jid in already_in_jids: - pritext = _('Duplicate Jabber ID') - sectext = _('This account is already configured in Gajim.') - dialogs.ErrorDialog(pritext, sectext) - return - - self.account = server - i = 1 - while self.account in gajim.connections: - self.account = server + str(i) - i += 1 - - username, server = gajim.get_name_and_server_from_jid(jid) - self.save_account(username, server, savepass, password) - self.cancel_button.hide() - self.back_button.hide() - self.forward_button.hide() - if self.modify: - finish_text = '%s\n\n%s' % ( + username, server = gajim.get_name_and_server_from_jid(jid) + self.save_account(username, server, savepass, password) + self.cancel_button.hide() + self.back_button.hide() + self.forward_button.hide() + if self.modify: + finish_text = '%s\n\n%s' % ( _('Account has been added successfully'), _('You can set advanced account options by pressing the ' 'Advanced button, or later by choosing the Accounts menuitem ' @@ -2947,20 +2937,130 @@ class AccountCreationWizardWindow: self.go_online_checkbutton.show() img = self.xml.get_widget('finish_image') img.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_DIALOG) - self.notebook.set_current_page(3) # show finish page + self.notebook.set_current_page(5) # show finish page self.show_vcard_checkbutton.set_active(False) - else: - self.notebook.set_current_page(2) # show creating page + elif cur_page == 2: + server = self.xml.get_widget('server_comboboxentry1').child.get_text()\ + .decode('utf-8') + + if not server: + dialogs.ErrorDialog(_('Invalid server'), + _('Please provide a server on which you want to register.')) + return + self.account = server + i = 1 + while self.account in gajim.connections: + self.account = server + str(i) + i += 1 + + config = self.get_config('', server, '', '') + # Get advanced options + proxies_combobox = self.xml.get_widget('proxies_combobox') + active = proxies_combobox.get_active() + proxy = proxies_combobox.get_model()[active][0].decode('utf-8') + if proxy == _('None'): + proxy = '' + config['proxy'] = proxy + + config['use_custom_host'] = self.xml.get_widget( + 'custom_host_port_checkbutton').get_active() + custom_port = self.xml.get_widget('custom_port_entry').get_text() + try: + custom_port = int(custom_port) + except: + dialogs.ErrorDialog(_('Invalid entry'), + _('Custom port must be a port number.')) + return + config['custom_port'] = custom_port + config['custom_host'] = self.xml.get_widget( + 'custom_host_entry').get_text().decode('utf-8') + + self.notebook.set_current_page(4) # show creating page + self.back_button.hide() + self.forward_button.hide() self.update_progressbar_timeout_id = gobject.timeout_add(100, self.update_progressbar) + # Get form from serveur + con = connection.Connection(self.account) + con.new_account(self.account, config) + gajim.connections[self.account] = con + elif cur_page == 3: + if self.is_form: + form = self.data_form_widget.data_form + else: + form = self.data_form_widget.get_infos() + gajim.connections[self.account].send_new_account_infos(form, + self.is_form) + self.xml.get_widget('form_vbox').remove(self.data_form_widget) + self.xml.get_widget('progressbar_label').set_markup('Account is being created\n\nPlease wait...') + self.notebook.set_current_page(4) # show creating page + self.back_button.hide() + self.forward_button.hide() + self.update_progressbar_timeout_id = gobject.timeout_add(100, + self.update_progressbar) + + def update_proxy_list(self): + proxies_combobox = self.xml.get_widget('proxies_combobox') + model = gtk.ListStore(str) + proxies_combobox.set_model(model) + l = gajim.config.get_per('proxies') + l.insert(0, _('None')) + for i in xrange(len(l)): + model.append([l[i]]) + proxies_combobox.set_active(0) + + def on_manage_proxies_button_clicked(self, widget): + if gajim.interface.instances.has_key('manage_proxies'): + gajim.interface.instances['manage_proxies'].window.present() + else: + gajim.interface.instances['manage_proxies'] = \ + ManageProxiesWindow() + + def on_custom_host_port_checkbutton_toggled(self, widget): + self.xml.get_widget('custom_host_hbox').set_sensitive(widget.get_active()) def update_progressbar(self): self.progressbar.pulse() return True # loop forever + def new_acc_connected(self, form, is_form): + '''connection to server succeded, present the form to the user''' + if self.update_progressbar_timeout_id is not None: + gobject.source_remove(self.update_progressbar_timeout_id) + self.back_button.show() + self.forward_button.show() + self.notebook.set_current_page(3) # show form page + self.is_form = is_form + if is_form: + dataform = dataforms.ExtendForm(node = form) + self.data_form_widget = dataforms_widget.DataFormWidget(dataform) + else: + self.data_form_widget = FakeDataForm(form) + self.data_form_widget.show_all() + self.xml.get_widget('form_vbox').pack_start(self.data_form_widget) + + def new_acc_not_connected(self, reason): + '''Account creation failed: connection to server failed''' + if self.update_progressbar_timeout_id is not None: + gobject.source_remove(self.update_progressbar_timeout_id) + del gajim.connections[self.account] + self.back_button.show() + self.cancel_button.show() + self.go_online_checkbutton.hide() + self.show_vcard_checkbutton.hide() + img = self.xml.get_widget('finish_image') + img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG) + finish_text = '%s\n\n%s' % ( + _('An error occurred during account creation') , reason) + self.finish_label.set_markup(finish_text) + self.notebook.set_current_page(5) # show finish page + def acc_is_ok(self, config): '''Account creation succeeded''' self.create_vars(config) + self.cancel_button.hide() + self.back_button.hide() + self.forward_button.hide() self.finish_button.show() self.finish_button.set_property('has-default', True) self.advanced_button.show() @@ -2976,7 +3076,7 @@ class AccountCreationWizardWindow: 'button, or later by choosing the Accounts menuitem under the Edit ' 'menu from the main window.')) self.finish_label.set_markup(finish_text) - self.notebook.set_current_page(3) # show finish page + self.notebook.set_current_page(5) # show finish page if self.update_progressbar_timeout_id is not None: gobject.source_remove(self.update_progressbar_timeout_id) @@ -2987,12 +3087,16 @@ class AccountCreationWizardWindow: self.cancel_button.show() self.go_online_checkbutton.hide() self.show_vcard_checkbutton.hide() + del gajim.connections[self.account] img = self.xml.get_widget('finish_image') img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG) finish_text = '%s\n\n%s' % (_('An error occurred during ' 'account creation') , reason) self.finish_label.set_markup(finish_text) - self.notebook.set_current_page(3) # show finish page + self.notebook.set_current_page(5) # show finish page + + if self.update_progressbar_timeout_id is not None: + gobject.source_remove(self.update_progressbar_timeout_id) def on_advanced_button_clicked(self, widget): gajim.interface.instances[self.account]['account_modification'] = \ @@ -3022,12 +3126,11 @@ class AccountCreationWizardWindow: combobox.child.set_position(-1) return True - def on_server_comboboxentry_key_press_event(self, widget, event): + def on_server_comboboxentry_key_press_event(self, widget, event, combobox): # If backspace is pressed in empty field, return to the nick entry field backspace = event.keyval == gtk.keysyms.BackSpace - combobox = self.xml.get_widget('server_comboboxentry') empty = len(combobox.get_active_text()) == 0 - if backspace and empty: + if backspace and empty and self.modify: username_entry = self.xml.get_widget('username_entry') username_entry.grab_focus() username_entry.set_position(-1) @@ -3045,14 +3148,7 @@ class AccountCreationWizardWindow: string = '%s@%s' % (name, server) jid_label.set_label(string) - def save_account(self, login, server, savepass, password): - if self.account in gajim.connections: - dialogs.ErrorDialog(_('Account name is in use'), - _('You already have an account using this name.')) - return - con = connection.Connection(self.account) - con.password = password - + def get_config(self, login, server, savepass, password): config = {} config['name'] = login config['hostname'] = server @@ -3072,6 +3168,17 @@ class AccountCreationWizardWindow: config['keyid'] = '' config['savegpgpass'] = False config['gpgpassword'] = '' + return config + + def save_account(self, login, server, savepass, password): + if self.account in gajim.connections: + dialogs.ErrorDialog(_('Account name is in use'), + _('You already have an account using this name.')) + return + con = connection.Connection(self.account) + con.password = password + + config = self.get_config(login, server, savepass, password) if not self.modify: con.new_account(self.account, config) diff --git a/src/gajim.py b/src/gajim.py index 0bb8df28d..15cb1b726 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -948,6 +948,17 @@ class Interface: except AttributeError: return + def handle_event_new_acc_connected(self, account, array): + #('NEW_ACC_CONNECTED', account, (infos, is_form)) + if self.instances.has_key('account_creation_wizard'): + self.instances['account_creation_wizard'].new_acc_connected(array[0], + array[1]) + + def handle_event_new_acc_not_connected(self, account, array): + #('NEW_ACC_NOT_CONNECTED', account, (reason)) + if self.instances.has_key('account_creation_wizard'): + self.instances['account_creation_wizard'].new_acc_not_connected(array) + def handle_event_acc_ok(self, account, array): #('ACC_OK', account, (config)) if self.instances.has_key('account_creation_wizard'): @@ -2047,6 +2058,8 @@ class Interface: 'AGENT_INFO_ITEMS': self.handle_event_agent_info_items, 'AGENT_INFO_INFO': self.handle_event_agent_info_info, 'QUIT': self.handle_event_quit, + 'NEW_ACC_CONNECTED': self.handle_event_new_acc_connected, + 'NEW_ACC_NOT_CONNECTED': self.handle_event_new_acc_not_connected, 'ACC_OK': self.handle_event_acc_ok, 'ACC_NOT_OK': self.handle_event_acc_not_ok, 'MYVCARD': self.handle_event_myvcard,