use PassphraseDialog only asynchronously. see #4147

This commit is contained in:
Yann Leboulanger 2008-07-31 06:14:48 +00:00
parent 52b8adb6be
commit 0c662cf2fd
4 changed files with 48 additions and 51 deletions

View file

@ -2553,18 +2553,21 @@ class RemoveAccountWindow:
gajim.connections[self.account].change_status('offline', 'offline')
if self.remove_and_unregister_radiobutton.get_active():
if not gajim.connections[self.account].password:
passphrase = ''
w = dialogs.PassphraseDialog(
_('Password Required'),
_('Enter your password for account %s') % self.account,
_('Save password'))
passphrase, save = w.run()
def on_ok(passphrase, checked):
if passphrase == -1:
# We don't remove account cause we canceled pw window
return
gajim.connections[self.account].password = passphrase
gajim.connections[self.account].unregister_account(
self._on_remove_success)
w = dialogs.PassphraseDialog(
_('Password Required'),
_('Enter your password for account %s') % self.account,
_('Save password'), ok_handler=on_ok)
return
gajim.connections[self.account].unregister_account(
self._on_remove_success)
else:
self._on_remove_success(True)

View file

@ -199,25 +199,7 @@ class EditGroupsDialog:
class PassphraseDialog:
'''Class for Passphrase dialog'''
def run(self):
'''Wait for OK button to be pressed and return passphrase/password'''
rep = self.window.run()
if rep == gtk.RESPONSE_OK:
passphrase = self.passphrase_entry.get_text().decode('utf-8')
else:
passphrase = -1
if self.check:
save_passphrase_checkbutton = self.xml.\
get_widget('save_passphrase_checkbutton')
checked = save_passphrase_checkbutton.get_active()
else:
checked = False
self.window.destroy()
return passphrase, checked
def __init__(self, titletext, labeltext, checkbuttontext=None, is_modal=True,
def __init__(self, titletext, labeltext, checkbuttontext=None,
ok_handler=None, cancel_handler=None):
self.xml = gtkgui_helpers.get_glade('passphrase_dialog.glade')
self.window = self.xml.get_widget('passphrase_dialog')
@ -229,8 +211,6 @@ class PassphraseDialog:
self.ok = False
self.cancel_handler = cancel_handler
self.is_modal = is_modal
if not is_modal and ok_handler is not None:
self.ok_handler = ok_handler
okbutton = self.xml.get_widget('ok_button')
okbutton.connect('clicked', self.on_okbutton_clicked)
@ -248,6 +228,9 @@ class PassphraseDialog:
checkbutton.hide()
def on_okbutton_clicked(self, widget):
if not self.ok_handler:
return
passph = self.passphrase_entry.get_text().decode('utf-8')
if self.check:

View file

@ -1440,11 +1440,10 @@ class Interface:
# ask again
dialogs.PassphraseDialog(_('Wrong Passphrase'),
_('Please retype your GPG passphrase or press Cancel.'),
is_modal=False, ok_handler=(_ok, count), cancel_handler=_cancel)
dialogs.PassphraseDialog(title, second,
is_modal=False, ok_handler=(_ok, 0), cancel_handler=_cancel)
ok_handler=(_ok, count), cancel_handler=_cancel)
dialogs.PassphraseDialog(title, second, ok_handler=(_ok, 0),
cancel_handler=_cancel)
def handle_event_roster_info(self, account, array):
#('ROSTER_INFO', account, (jid, name, sub, ask, groups))

View file

@ -1950,27 +1950,39 @@ class RosterWindow:
text += '\n' + _('Gnome Keyring is installed but not \
correctly started (environment variable probably not \
correctly set)')
w = dialogs.PassphraseDialog(_('Password Required'), text,
_('Save password'))
passphrase, save = w.run()
if passphrase == -1:
def on_ok(passphrase, save):
gajim.connections[account].password = passphrase
if save:
gajim.config.set_per('accounts', account, 'savepass', True)
passwords.save_password(account, passphrase)
keyid = gajim.config.get_per('accounts', account, 'keyid')
if keyid and not gajim.connections[account].gpg:
dialog = dialogs.WarningDialog(_('GPG is not usable'),
_('You will be connected to %s without OpenPGP.') % \
account)
self.send_status_continue(account, status, txt, auto, to)
def on_cancel():
if child_iterA:
self.model[child_iterA][0] = \
gajim.interface.jabber_state_images['16']['offline']
if gajim.interface.systray_enabled:
gajim.interface.systray.change_status('offline')
self.update_status_combobox()
w = dialogs.PassphraseDialog(_('Password Required'), text,
_('Save password'), ok_handler=on_ok,
cancel_handler=on_cancel)
return
gajim.connections[account].password = passphrase
if save:
gajim.config.set_per('accounts', account, 'savepass', True)
passwords.save_password(account, passphrase)
keyid = gajim.config.get_per('accounts', account, 'keyid')
if keyid and not gajim.connections[account].gpg:
dialog = dialogs.WarningDialog(_('GPG is not usable'),
_('You will be connected to %s without OpenPGP.') % account)
self.send_status_continue(account, status, txt, auto, to)
def send_status_continue(self, account, status, txt, auto, to):
if gajim.account_is_connected(account):
if status == 'online' and gajim.interface.sleeper.getState() != \
common.sleepy.STATE_UNKNOWN: