commit 0ccce187bf6e79a20e3af21f992ca5c70bdbb121 Author: Alexander Myltsev Date: Sat Aug 22 02:14:10 2009 +0400 Maintain a queue to show passphrase dialogs sequentially. Gajim 0.12 has mostly asynchronous dialogues, which is good, but showing many dialogues on the screen can be confusing and inconvenient. This patch adds a queue so that password dialogues are only displayed sequentially. The patch requires PassphraseDialog to have a cancel() method. diff --git a/gajim/src/dialogs.py b/gajim/src/dialogs.py index 956e865..dea7b38 100644 --- a/gajim/src/dialogs.py +++ b/gajim/src/dialogs.py @@ -197,7 +197,7 @@ class EditGroupsDialog: renderer.connect('toggled', self.group_toggled_cb) column.set_attributes(renderer, active=1, inconsistent=2) -class PassphraseDialog: +class PassphraseDialogImplementation: '''Class for Passphrase dialog''' def __init__(self, titletext, labeltext, checkbuttontext=None, ok_handler=None, cancel_handler=None): @@ -259,6 +259,54 @@ class PassphraseDialog: if self.cancel_handler and not self.ok: self.cancel_handler() +""" The dialog queue. +The head of the queue is the active dialog (on screen), +the rest are waiting to be shown.""" +dialog_queue = [] + +class PassphraseDialog: + def __init__(self, *args, **kwargs): + self.params = args, kwargs + self.cancelled = False + self.impl = None + if not dialog_queue: + # there's nobody to call us, we'll have to start + self.show() + dialog_queue.append(self) + + def show(self): + if self.cancelled: + return self.next() + args, kwargs = self.params + for handler_name in 'ok_handler', 'cancel_handler': + if handler_name in kwargs: + handler = kwargs[handler_name] + if isinstance(handler, tuple): + handler = (self.wrap_handler(handler[0]),) + handler[1:] + else: + handler = self.wrap_handler(handler) + kwargs[handler_name] = handler + + self.impl = PassphraseDialogImplementation(*args, **kwargs) + + def next(self): + """ Shows next dialog in the queue (if any). """ + head = dialog_queue.pop(0) + assert head is self + if dialog_queue: + dialog_queue[0].show() + + def cancel(self): + self.cancelled = True + if self.impl is not None: + self.impl.cancel() + + def wrap_handler(self, handler): + def wrapper(*args, **kwargs): + self.next() + handler(*args, **kwargs) + return wrapper + class ChooseGPGKeyDialog: '''Class for GPG key dialog''' def __init__(self, title_text, prompt_text, secret_keys, on_response,