make EditGroups and ChangePassword dialogs asynchronous. see #4147

This commit is contained in:
Yann Leboulanger 2008-08-06 20:34:36 +00:00
parent f5be05a14a
commit d5a8f75080
3 changed files with 33 additions and 40 deletions

View File

@ -1880,18 +1880,19 @@ class AccountsWindow:
return
def on_change_password_button1_clicked(self, widget):
def on_changed(new_password):
if new_password is not None:
gajim.connections[self.current_account].change_password(
new_password)
if self.xml.get_widget('save_password_checkbutton1').get_active():
self.xml.get_widget('password_entry1').set_text(new_password)
try:
dialog = dialogs.ChangePasswordDialog(self.current_account)
dialog = dialogs.ChangePasswordDialog(self.current_account, on_changed)
except GajimGeneralException:
# if we showed ErrorDialog, there will not be dialog instance
return
new_password = dialog.run()
if new_password != -1:
gajim.connections[self.current_account].change_password(new_password)
if self.xml.get_widget('save_password_checkbutton1').get_active():
self.xml.get_widget('password_entry1').set_text(new_password)
def on_autoconnect_checkbutton_toggled(self, widget):
if self.ignore_events:
return

View File

@ -81,7 +81,6 @@ class EditGroupsDialog:
self.xml.signal_autoconnect(self)
self.init_list()
def run(self):
self.dialog.show_all()
if self.changes_made:
for (contact, account) in self.list_:
@ -1979,43 +1978,38 @@ class NewChatDialog(InputDialog):
gajim.interface.new_chat_from_jid(self.account, jid)
class ChangePasswordDialog:
def __init__(self, account):
def __init__(self, account, on_response):
# 'account' can be None if we are about to create our first one
if not account or gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not change your password.'))
raise GajimGeneralException, 'You are not connected to the server'
self.account = account
self.on_response = on_response
self.xml = gtkgui_helpers.get_glade('change_password_dialog.glade')
self.dialog = self.xml.get_widget('change_password_dialog')
self.password1_entry = self.xml.get_widget('password1_entry')
self.password2_entry = self.xml.get_widget('password2_entry')
self.dialog.connect('response', self.on_dialog_response)
self.dialog.show_all()
def run(self):
'''Wait for OK button to be pressed and return new password'''
end = False
while not end:
rep = self.dialog.run()
if rep == gtk.RESPONSE_OK:
password1 = self.password1_entry.get_text().decode('utf-8')
if not password1:
ErrorDialog(_('Invalid password'),
_('You must enter a password.'))
continue
password2 = self.password2_entry.get_text().decode('utf-8')
if password1 != password2:
ErrorDialog(_('Passwords do not match'),
_('The passwords typed in both fields must be identical.'))
continue
message = password1
else:
message = -1
end = True
self.dialog.destroy()
return message
def on_dialog_response(self, dialog, response):
if response != gtk.RESPONSE_OK:
dialog.destroy()
self.on_response(None)
return
password1 = self.password1_entry.get_text().decode('utf-8')
if not password1:
ErrorDialog(_('Invalid password'), _('You must enter a password.'))
return
password2 = self.password2_entry.get_text().decode('utf-8')
if password1 != password2:
ErrorDialog(_('Passwords do not match'),
_('The passwords typed in both fields must be identical.'))
return
dialog.destroy()
self.on_response(password1)
class PopupNotificationWindow:
def __init__(self, event_type, jid, account, msg_type = '',

View File

@ -2727,14 +2727,13 @@ class RosterWindow:
on_canceled)
def on_remove_group_item_activated(self, widget, group, account):
dlg = dialogs.ConfirmationDialogCheck(_('Remove Group'),
dialogs.ConfirmationDialogCheck(_('Remove Group'),
_('Do you want to remove group %s from the roster?' % group),
_('Remove also all contacts in this group from your roster'))
dlg.set_default_response(gtk.BUTTONS_OK_CANCEL)
response = dlg.run()
if response == gtk.RESPONSE_OK:
_('Remove also all contacts in this group from your roster'),
on_response_ok=on_ok)
def on_ok(checked):
for contact in gajim.contacts.get_contacts_from_group(account, group):
if not dlg.is_checked():
if not checked:
self.remove_contact_from_groups(contact.jid,account, [group])
else:
gajim.connections[account].unsubscribe(contact.jid)
@ -2820,8 +2819,7 @@ class RosterWindow:
on_response_clear = on_clear)
def on_edit_groups(self, widget, list_):
dlg = dialogs.EditGroupsDialog(list_)
dlg.run()
dialogs.EditGroupsDialog(list_)
def on_history(self, widget, contact, account):
'''When history menuitem is activated: call log window'''