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 return
def on_change_password_button1_clicked(self, widget): 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: try:
dialog = dialogs.ChangePasswordDialog(self.current_account) dialog = dialogs.ChangePasswordDialog(self.current_account, on_changed)
except GajimGeneralException: except GajimGeneralException:
# if we showed ErrorDialog, there will not be dialog instance # if we showed ErrorDialog, there will not be dialog instance
return 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): def on_autoconnect_checkbutton_toggled(self, widget):
if self.ignore_events: if self.ignore_events:
return return

View file

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

View file

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