Logo Search packages:      
Sourcecode: gajim version File versions  Download package

def config::AccountModificationWindow::on_save_button_clicked (   self,
  widget 
)

When save button is clicked: Save information in config file

Definition at line 1126 of file config.py.

01126                                               :
            '''When save button is clicked: Save information in config file'''
            config = {}
            name = self.xml.get_widget('name_entry').get_text().decode('utf-8')
            if gajim.connections.has_key(self.account):
                  if name != self.account:
                        if gajim.connections[self.account].connected != 0:
                              dialogs.ErrorDialog(
                                    _('You are currently connected to the server'),
                                    _('To change the account name, you must be disconnected.'))
                              return
                        if len(gajim.awaiting_events[self.account]):
                              dialogs.ErrorDialog(_('Unread events'),
                                    _('To change the account name, you must read all pending '
                                    'events.'))
                              return
                        if name in gajim.connections:
                              dialogs.ErrorDialog(_('Account Name Already Used'),
                                    _('This name is already used by another of your accounts. Please choose '
                                    'another name.'))
                              return
            if (name == ''):
                  dialogs.ErrorDialog(_('Invalid account name'),
                        _('Account name cannot be empty.'))
                  return
            if name.find(' ') != -1:
                  dialogs.ErrorDialog(_('Invalid account name'),
                        _('Account name cannot contain spaces.'))
                  return
            jid = self.xml.get_widget('jid_entry').get_text().decode('utf-8')

            # 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

            n, hn = jid.split('@', 1)
            if not n:
                  pritext = _('Invalid Jabber ID')
                  sectext = _('A Jabber ID must be in the form "user@servername".')
                  dialogs.ErrorDialog(pritext, sectext)
                  return

            resource = self.xml.get_widget('resource_entry').get_text().decode('utf-8')
            try:
                  resource = helpers.parse_resource(resource)
            except helpers.InvalidFormat, s:
                  pritext = _('Invalid Jabber ID')
                  dialogs.ErrorDialog(pritext, (s))
                  return

            config['savepass'] = self.xml.get_widget(
                        'save_password_checkbutton').get_active()
            config['password'] = self.xml.get_widget('password_entry').get_text().\
                  decode('utf-8')
            config['resource'] = resource
            config['priority'] = self.xml.get_widget('priority_spinbutton').\
                                                                                                                  get_value_as_int()
            config['autoconnect'] = self.xml.get_widget('autoconnect_checkbutton').\
                                                                                                                              get_active()
            config['autoreconnect'] = self.xml.get_widget('autoreconnect_checkbutton').\
                                                                                                                              get_active()

            if self.account:
                  list_no_log_for = gajim.config.get_per('accounts',
                              self.account, 'no_log_for').split()
            else:
                  list_no_log_for = []
            if self.account in list_no_log_for:
                  list_no_log_for.remove(self.account)
            if not self.xml.get_widget('log_history_checkbutton').get_active():
                  list_no_log_for.append(name)
            config['no_log_for'] = ' '.join(list_no_log_for)

            config['sync_with_global_status'] = self.xml.get_widget(
                        'sync_with_global_status_checkbutton').get_active()
            config['use_ft_proxies'] = self.xml.get_widget(
                  'use_ft_proxies_checkbutton').get_active()

            active = self.proxy_combobox.get_active()
            proxy = self.proxy_combobox.get_model()[active][0].decode('utf-8')
            if proxy == 'None':
                  proxy = ''
            config['proxy'] = proxy

            config['usessl'] = self.xml.get_widget('use_ssl_checkbutton').get_active()
            config['name'] = n
            config['hostname'] = hn

            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')

            config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8')
            if config['keyname'] == '': #no key selected
                  config['keyid'] = ''
                  config['savegpgpass'] = False
                  config['gpgpassword'] = ''
            else:
                  config['keyid'] = self.xml.get_widget('gpg_key_label').get_text().decode('utf-8')
                  config['savegpgpass'] = self.xml.get_widget(
                              'gpg_save_password_checkbutton').get_active()
                  config['gpgpassword'] = self.xml.get_widget('gpg_password_entry'
                        ).get_text().decode('utf-8')
            #if we modify the name of the account
            if name != self.account:
                  #update variables
                  gajim.interface.instances[name] = gajim.interface.instances[self.account]
                  gajim.awaiting_events[name] = gajim.awaiting_events[self.account]
                  gajim.nicks[name] = gajim.nicks[self.account]
                  gajim.block_signed_in_notifications[name] = \
                        gajim.block_signed_in_notifications[self.account]
                  gajim.groups[name] = gajim.groups[self.account]
                  gajim.gc_connected[name] = gajim.gc_connected[self.account]
                  gajim.newly_added[name] = gajim.newly_added[self.account]
                  gajim.to_be_removed[name] = gajim.to_be_removed[self.account]
                  gajim.sleeper_state[name] = gajim.sleeper_state[self.account]
                  gajim.encrypted_chats[name] = gajim.encrypted_chats[self.account]
                  gajim.last_message_time[name] = \
                        gajim.last_message_time[self.account]
                  gajim.status_before_autoaway[name] = \
                        gajim.status_before_autoaway[self.account]

                  gajim.contacts.change_account_name(self.account, name)

                  #upgrade account variable in opened windows
                  for kind in ('infos', 'disco', 'chats', 'gc', 'gc_config'):
                        for j in gajim.interface.instances[name][kind]:
                              gajim.interface.instances[name][kind][j].account = name

                  #upgrade account in systray
                  if gajim.interface.systray_enabled:
                        for list in gajim.interface.systray.jids:
                              if list[0] == self.account:
                                    list[0] = name

                  # ServiceCache object keep old property account
                  if hasattr(gajim.connections[self.account], 'services_cache'):
                        gajim.connections[self.account].services_cache.account = name
                  del gajim.interface.instances[self.account]
                  del gajim.awaiting_events[self.account]
                  del gajim.nicks[self.account]
                  del gajim.block_signed_in_notifications[self.account]
                  del gajim.groups[self.account]
                  del gajim.gc_connected[self.account]
                  del gajim.newly_added[self.account]
                  del gajim.to_be_removed[self.account]
                  del gajim.sleeper_state[self.account]
                  del gajim.encrypted_chats[self.account]
                  del gajim.last_message_time[self.account]
                  del gajim.status_before_autoaway[self.account]
                  gajim.connections[self.account].name = name
                  gajim.connections[name] = gajim.connections[self.account]
                  del gajim.connections[self.account]
                  gajim.config.del_per('accounts', self.account)
                  gajim.config.add_per('accounts', name)
                  self.account = name

            resend_presence = False
            if gajim.connections[self.account].connected == 0: # we're disconnected
                  relogin_needed = False
            else: # we're connected to the account we want to apply changes
                  # check if relogin is needed
                  relogin_needed = self.options_changed_need_relogin(config,
                        ('resource', 'proxy', 'usessl', 'keyname',
                        'use_custom_host', 'custom_host'))

                  if config['use_custom_host'] and (self.option_changed(config,
                        'custom_host') or self.option_changed(config, 'custom_port')):
                        relogin_needed = True

                  if self.option_changed(config, 'use_ft_proxies') and \
                  config['use_ft_proxies']:
                        gajim.connections[self.account].discover_ft_proxies()

                  if self.option_changed(config, 'priority'):
                        resend_presence = True

            for opt in config:
                  gajim.config.set_per('accounts', name, opt, config[opt])
            if config['savepass']:
                  gajim.connections[name].password = config['password']
            else:
                  gajim.connections[name].password = None
            # refresh accounts window
            if gajim.interface.instances.has_key('accounts'):
                  gajim.interface.instances['accounts'].init_accounts()
            # refresh roster
            gajim.interface.roster.draw_roster()
            gajim.interface.save_config()
            self.window.destroy()

            if relogin_needed:
                  def login(account, show_before, status_before):
                        ''' login with previous status'''
                        # first make sure connection is really closed, 
                        # 0.5 may not be enough
                        gajim.connections[account].disconnect(True)
                        gajim.interface.roster.send_status(account, show_before, 
                              status_before)

                  def relog(widget):
                        self.dialog.destroy()
                        show_before = gajim.SHOW_LIST[gajim.connections[self.account].\
                              connected]
                        status_before = gajim.connections[self.account].status
                        gajim.interface.roster.send_status(self.account, 'offline',
                              _('Be right back.'))
                        gobject.timeout_add(500, login, self.account, show_before, 
                              status_before)

                  def resend(widget):
                        self.resend_presence()

                  on_no = None
                  if resend_presence:
                        on_no = resend
                  self.dialog = dialogs.YesNoDialog(_('Relogin now?'),
                        _('If you want all the changes to apply instantly, '
                        'you must relogin.'), on_response_yes = relog,
                              on_response_no = on_no)
            elif resend_presence:
                  self.resend_presence()

      def resend_presence(self):


Generated by  Doxygen 1.6.0   Back to index