[zimio and me] Ask what to do when we want to unregister from a server but connection fails. Fixes #324

This commit is contained in:
Yann Leboulanger 2010-02-03 19:59:41 +01:00
parent 64da0b0671
commit 9230f12496
3 changed files with 96 additions and 16 deletions

View File

@ -553,10 +553,15 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
widget.modify_fg(gtk.STATE_NORMAL, fg_color)
self.connect_style_event(widget, opts[0], opts[1])
def _conv_textview_key_press_event(self, widget, event):
if (event.state & gtk.gdk.CONTROL_MASK and event.keyval in (gtk.keysyms.c,
# translate any layout to latin_layout
keymap = gtk.gdk.keymap_get_default()
keycode, group, level = keymap.get_entries_for_keyval(event.keyval)[0]
keycodec, group, level = keymap.get_entries_for_keyval(gtk.keysyms.c)[0]
if (event.state & gtk.gdk.CONTROL_MASK and keyval in (keycodec,
gtk.keysyms.Insert)) or (event.state & gtk.gdk.SHIFT_MASK and \
event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)):
keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)):
return False
self.parent_win.notebook.emit('key_press_event', event)
return True

View File

@ -2904,10 +2904,20 @@ class RemoveAccountWindow:
else:
remove()
def on_remove_responce_ok(self, is_checked):
if is_checked[0]:
self._on_remove_success(True)
def _on_remove_success(self, res):
# action of unregistration has failed, we don't remove the account
# Error message is send by connect_and_auth()
if not res:
confirmation_check = dialogs.ConfirmationDialogDoubleRadio(
_('Connection to server %s failed') % self.account,
_('What would you like to do?'),
_('Remove only from Gajim'),
_('Don\'t remove anything. I\'ll try again later'),
on_response_ok=self.on_remove_responce_ok, is_modal=False)
return
# Close all opened windows
gajim.interface.roster.close_all(self.account, force = True)

View File

@ -1299,23 +1299,34 @@ class HigDialog(gtk.MessageDialog):
self.format_secondary_markup(sectext)
buttons = self.action_area.get_children()
possible_responses = {gtk.STOCK_OK: on_response_ok,
gtk.STOCK_CANCEL: on_response_cancel, gtk.STOCK_YES: on_response_yes,
gtk.STOCK_NO: on_response_no}
self.possible_responses = {gtk.STOCK_OK: on_response_ok,
gtk.STOCK_CANCEL: on_response_cancel, gtk.STOCK_YES: on_response_yes,
gtk.STOCK_NO: on_response_no}
for b in buttons:
for response in possible_responses:
for response in self.possible_responses:
if b.get_label() == response:
if not possible_responses[response]:
if not self.possible_responses[response]:
b.connect('clicked', self.just_destroy)
elif isinstance(possible_responses[response], tuple):
if len(possible_responses[response]) == 1:
b.connect('clicked', possible_responses[response][0])
elif isinstance(self.possible_responses[response], tuple):
if len(self.possible_responses[response]) == 1:
b.connect('clicked', self.possible_responses[response][0])
else:
b.connect('clicked', *possible_responses[response])
b.connect('clicked', *self.possible_responses[response])
else:
b.connect('clicked', possible_responses[response])
b.connect('clicked', self.possible_responses[response])
break
self.connect('destroy', self.on_dialog_destroy)
def on_dialog_destroy(self, widget):
cancel_handler = self.possible_responses[gtk.STOCK_CANCEL]
if not cancel_handler:
return False
if isinstance(cancel_handler, tuple):
cancel_handler[0](None, *cancel_handler[1:])
else:
cancel_handler(None)
def just_destroy(self, widget):
self.destroy()
@ -1548,8 +1559,6 @@ class ConfirmationDialogCheck(ConfirmationDialog):
self.set_modal(is_modal)
self.popup()
# XXX should cancel if somebody closes the dialog
def on_response_ok(self, widget):
if self.user_response_ok:
if isinstance(self.user_response_ok, tuple):
@ -1607,8 +1616,6 @@ class ConfirmationDialogDubbleCheck(ConfirmationDialog):
self.set_modal(is_modal)
self.popup()
# XXX should cancel if somebody closes the dialog
def on_response_ok(self, widget):
if self.user_response_ok:
if isinstance(self.user_response_ok, tuple):
@ -1638,6 +1645,64 @@ class ConfirmationDialogDubbleCheck(ConfirmationDialog):
is_checked_2 = False
return [is_checked_1, is_checked_2]
class ConfirmationDialogDoubleRadio(ConfirmationDialog):
"""
HIG compliant confirmation dialog with 2 radios
"""
def __init__(self, pritext, sectext='', radiotext1='', radiotext2='',
on_response_ok=None, on_response_cancel=None, is_modal=True):
self.user_response_ok = on_response_ok
self.user_response_cancel = on_response_cancel
HigDialog.__init__(self, None, gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK_CANCEL, pritext, sectext, self.on_response_ok,
self.on_response_cancel)
self.set_default_response(gtk.RESPONSE_OK)
ok_button = self.action_area.get_children()[0] # right to left
ok_button.grab_focus()
self.radiobutton1 = gtk.RadioButton(label=radiotext1)
self.vbox.pack_start(self.radiobutton1, expand=False, fill=True)
self.radiobutton2 = gtk.RadioButton(group=self.radiobutton1,
label=radiotext2)
self.vbox.pack_start(self.radiobutton2, expand=False, fill=True)
self.set_modal(is_modal)
self.popup()
def on_response_ok(self, widget):
if self.user_response_ok:
if isinstance(self.user_response_ok, tuple):
self.user_response_ok[0](self.is_checked(),
*self.user_response_ok[1:])
else:
self.user_response_ok(self.is_checked())
self.destroy()
def on_response_cancel(self, widget):
if self.user_response_cancel:
if isinstance(self.user_response_cancel, tuple):
self.user_response_cancel[0](*self.user_response_cancel[1:])
else:
self.user_response_cancel()
self.destroy()
def is_checked(self):
''' Get active state of the checkbutton '''
if self.radiobutton1:
is_checked_1 = self.radiobutton1.get_active()
else:
is_checked_1 = False
if self.radiobutton2:
is_checked_2 = self.radiobutton2.get_active()
else:
is_checked_2 = False
return [is_checked_1, is_checked_2]
class FTOverwriteConfirmationDialog(ConfirmationDialog):
"""
HIG compliant confirmation dialog to overwrite or resume a file transfert