From 855a31ff253297b3cc25dde6e21058612923b505 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 25 Sep 2012 21:53:36 +0200 Subject: [PATCH] components: Allow cancelling of dialog between prompts Some callers of the keyring prompt keep the dialog up while processing the prompt. Allow the user to cancel the prompt while in this state. This is propagated to the caller, who can cancel the operation in question when this occurs. https://bugzilla.gnome.org/show_bug.cgi?id=682830 --- js/ui/components/keyring.js | 2 +- src/shell-keyring-prompt.c | 40 ++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/js/ui/components/keyring.js b/js/ui/components/keyring.js index ae67b5510..40d06d154 100644 --- a/js/ui/components/keyring.js +++ b/js/ui/components/keyring.js @@ -25,7 +25,7 @@ const KeyringDialog = new Lang.Class({ this.prompt = new Shell.KeyringPrompt(); this.prompt.connect('show-password', Lang.bind(this, this._onShowPassword)); this.prompt.connect('show-confirm', Lang.bind(this, this._onShowConfirm)); - this.prompt.connect('hide-prompt', Lang.bind(this, this._onHidePrompt)); + this.prompt.connect('prompt-close', Lang.bind(this, this._onHidePrompt)); let mainContentBox = new St.BoxLayout({ style_class: 'prompt-dialog-main-layout', vertical: false }); diff --git a/src/shell-keyring-prompt.c b/src/shell-keyring-prompt.c index 01eb409f8..bafcb90b4 100644 --- a/src/shell-keyring-prompt.c +++ b/src/shell-keyring-prompt.c @@ -100,7 +100,6 @@ G_DEFINE_TYPE_WITH_CODE (ShellKeyringPrompt, shell_keyring_prompt, G_TYPE_OBJECT enum { SIGNAL_SHOW_PASSWORD, SIGNAL_SHOW_CONFIRM, - SIGNAL_HIDE_PROMPT, SIGNAL_LAST }; @@ -258,10 +257,8 @@ shell_keyring_prompt_dispose (GObject *obj) { ShellKeyringPrompt *self = SHELL_KEYRING_PROMPT (obj); - if (self->shown) { - self->shown = FALSE; - g_signal_emit (self, signals[SIGNAL_HIDE_PROMPT], 0); - } + if (self->shown) + gcr_prompt_close (GCR_PROMPT (self)); if (self->async_result) shell_keyring_prompt_cancel (self); @@ -384,11 +381,6 @@ shell_keyring_prompt_class_init (ShellKeyringPromptClass *klass) 0, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - - signals[SIGNAL_HIDE_PROMPT] = g_signal_new ("hide-prompt", G_TYPE_FROM_CLASS (klass), - 0, 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } static void @@ -482,6 +474,19 @@ shell_keyring_prompt_confirm_finish (GcrPrompt *prompt, return self->last_reply; } +static void +shell_keyring_prompt_close (GcrPrompt *prompt) +{ + ShellKeyringPrompt *self = SHELL_KEYRING_PROMPT (prompt); + + /* + * We expect keyring.js to connect to this signal and do the + * actual work of closing the prompt. + */ + + self->shown = FALSE; +} + static void shell_keyring_prompt_iface (GcrPromptIface *iface) { @@ -489,6 +494,7 @@ shell_keyring_prompt_iface (GcrPromptIface *iface) iface->prompt_password_finish = shell_keyring_prompt_password_finish; iface->prompt_confirm_async = shell_keyring_prompt_confirm_async; iface->prompt_confirm_finish = shell_keyring_prompt_confirm_finish; + iface->prompt_close = shell_keyring_prompt_close; } /** @@ -746,9 +752,19 @@ shell_keyring_prompt_cancel (ShellKeyringPrompt *self) GSimpleAsyncResult *res; g_return_if_fail (SHELL_IS_KEYRING_PROMPT (self)); - g_return_if_fail (self->mode != PROMPTING_NONE); - g_return_if_fail (self->async_result != NULL); + /* + * If cancelled while not prompting, we should just close the prompt, + * the user wants it to go away. + */ + if (self->mode == PROMPTING_NONE) + { + if (self->shown) + gcr_prompt_close (GCR_PROMPT (self)); + return; + } + + g_return_if_fail (self->async_result != NULL); self->last_reply = GCR_PROMPT_REPLY_CANCEL; res = self->async_result;