gcr: Add way to set the labels for the prompt buttons
authorStef Walter <stefw@gnome.org>
Fri, 10 Feb 2012 12:52:36 +0000 (13:52 +0100)
committerStef Walter <stefw@gnome.org>
Fri, 10 Feb 2012 12:59:57 +0000 (13:59 +0100)
 * Add continue-label and cancel-label properties to GcrPrompt
 * Implement in GcrSystemPrompt and in the mock prompter

https://bugzilla.gnome.org/show_bug.cgi?id=669793

docs/reference/gcr/gcr-sections.txt
gcr/gcr-base.symbols
gcr/gcr-mock-prompter.c
gcr/gcr-prompt-dialog.c
gcr/gcr-prompt.c
gcr/gcr-prompt.h
gcr/gcr-system-prompt.c
gcr/gcr-system-prompter.c
gcr/tests/files/prompt-tests/multiple.prompt
gcr/tests/test-system-prompt.c
po/POTFILES.in

index a71516a..129cfdc 100644 (file)
@@ -731,6 +731,10 @@ gcr_prompt_get_description
 gcr_prompt_set_description
 gcr_prompt_get_warning
 gcr_prompt_set_warning
+gcr_prompt_get_continue_label
+gcr_prompt_set_continue_label
+gcr_prompt_get_cancel_label
+gcr_prompt_set_cancel_label
 gcr_prompt_get_choice_label
 gcr_prompt_set_choice_label
 gcr_prompt_get_choice_chosen
index 5ca9cbd..8d101e7 100644 (file)
@@ -157,8 +157,10 @@ gcr_prompt_confirm_async
 gcr_prompt_confirm_finish
 gcr_prompt_confirm_run
 gcr_prompt_get_caller_window
+gcr_prompt_get_cancel_label
 gcr_prompt_get_choice_chosen
 gcr_prompt_get_choice_label
+gcr_prompt_get_continue_label
 gcr_prompt_get_description
 gcr_prompt_get_message
 gcr_prompt_get_password_new
@@ -172,8 +174,10 @@ gcr_prompt_password_finish
 gcr_prompt_password_run
 gcr_prompt_reply_get_type
 gcr_prompt_set_caller_window
+gcr_prompt_set_cancel_label
 gcr_prompt_set_choice_chosen
 gcr_prompt_set_choice_label
+gcr_prompt_set_continue_label
 gcr_prompt_set_description
 gcr_prompt_set_message
 gcr_prompt_set_password_new
index ccd6a4d..e506b3b 100644 (file)
@@ -76,7 +76,9 @@ enum {
        PROP_PASSWORD_STRENGTH,
        PROP_CHOICE_LABEL,
        PROP_CHOICE_CHOSEN,
-       PROP_CALLER_WINDOW
+       PROP_CALLER_WINDOW,
+       PROP_CONTINUE_LABEL,
+       PROP_CANCEL_LABEL,
 };
 
 struct _GcrMockPrompt {
@@ -195,6 +197,8 @@ _gcr_mock_prompt_init (GcrMockPrompt *self)
        blank_string_property (self->properties, "warning");
        blank_string_property (self->properties, "choice-label");
        blank_string_property (self->properties, "caller-window");
+       blank_string_property (self->properties, "continue-label");
+       blank_string_property (self->properties, "cancel-label");
 
        blank_boolean_property (self->properties, "choice-chosen");
        blank_boolean_property (self->properties, "password-new");
@@ -220,6 +224,8 @@ _gcr_mock_prompt_set_property (GObject *obj,
        case PROP_CHOICE_LABEL:
        case PROP_CHOICE_CHOSEN:
        case PROP_CALLER_WINDOW:
+       case PROP_CONTINUE_LABEL:
+       case PROP_CANCEL_LABEL:
                param = g_new0 (GParameter, 1);
                param->name = pspec->name;
                g_value_init (&param->value, pspec->value_type);
@@ -252,6 +258,8 @@ _gcr_mock_prompt_get_property (GObject *obj,
        case PROP_CHOICE_LABEL:
        case PROP_CHOICE_CHOSEN:
        case PROP_CALLER_WINDOW:
+       case PROP_CONTINUE_LABEL:
+       case PROP_CANCEL_LABEL:
                param = g_hash_table_lookup (self->properties, pspec->name);
                g_return_if_fail (param != NULL);
                g_value_copy (&param->value, value);
@@ -388,6 +396,8 @@ _gcr_mock_prompt_class_init (GcrMockPromptClass *klass)
        g_object_class_override_property (gobject_class, PROP_CHOICE_CHOSEN, "choice-chosen");
        g_object_class_override_property (gobject_class, PROP_PASSWORD_NEW, "password-new");
        g_object_class_override_property (gobject_class, PROP_PASSWORD_STRENGTH, "password-strength");
+       g_object_class_override_property (gobject_class, PROP_CONTINUE_LABEL, "continue-label");
+       g_object_class_override_property (gobject_class, PROP_CANCEL_LABEL, "cancel-label");
 }
 
 static gboolean
@@ -453,7 +463,7 @@ gcr_mock_prompt_confirm_finish (GcrPrompt *prompt,
                              gcr_mock_prompt_confirm_async), GCR_PROMPT_REPLY_CANCEL);
 
        return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)) ?
-                      GCR_PROMPT_REPLY_OK : GCR_PROMPT_REPLY_CANCEL;
+                      GCR_PROMPT_REPLY_CONTINUE : GCR_PROMPT_REPLY_CANCEL;
 }
 
 static void
index 9174904..3c4b331 100644 (file)
@@ -78,6 +78,8 @@ enum {
        PROP_PASSWORD_NEW,
        PROP_PASSWORD_STRENGTH,
        PROP_CALLER_WINDOW,
+       PROP_CONTINUE_LABEL,
+       PROP_CANCEL_LABEL,
 
        PROP_PASSWORD_VISIBLE,
        PROP_CONFIRM_VISIBLE,
@@ -95,6 +97,8 @@ struct _GcrPromptDialogPrivate {
        gboolean password_new;
        guint password_strength;
        gchar *caller_window;
+       gchar *continue_label;
+       gchar *cancel_label;
 
        GSimpleAsyncResult *async_result;
        GcrPromptReply last_reply;
@@ -226,6 +230,16 @@ gcr_prompt_dialog_set_property (GObject *obj,
                update_transient_for (self);
                g_object_notify (obj, "caller-window");
                break;
+       case PROP_CONTINUE_LABEL:
+               g_free (self->pv->continue_label);
+               self->pv->continue_label = g_value_dup_string (value);
+               g_object_notify (obj, "continue-label");
+               break;
+       case PROP_CANCEL_LABEL:
+               g_free (self->pv->cancel_label);
+               self->pv->cancel_label = g_value_dup_string (value);
+               g_object_notify (obj, "cancel-label");
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
                break;
@@ -278,6 +292,12 @@ gcr_prompt_dialog_get_property (GObject *obj,
        case PROP_CHOICE_VISIBLE:
                g_value_set_boolean (value, self->pv->choice_label && self->pv->choice_label[0]);
                break;
+       case PROP_CONTINUE_LABEL:
+               g_value_set_string (value, self->pv->continue_label);
+               break;
+       case PROP_CANCEL_LABEL:
+               g_value_set_string (value, self->pv->cancel_label);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
                break;
@@ -466,15 +486,16 @@ gcr_prompt_dialog_constructed (GObject *obj)
        GtkWidget *widget;
        GtkWidget *entry;
        GtkWidget *content;
+       GtkWidget *button;
        GtkGrid *grid;
 
        G_OBJECT_CLASS (gcr_prompt_dialog_parent_class)->constructed (obj);
 
        dialog = GTK_DIALOG (self);
-       gtk_dialog_add_buttons (dialog,
-                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                               _("Continue"), GTK_RESPONSE_OK,
-                               NULL);
+       button = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+       g_object_bind_property (self, "cancel-label", button, "label", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+       button = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
+       g_object_bind_property (self, "continue-label", button, "label", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
 
        gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
        gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
@@ -656,7 +677,7 @@ gcr_prompt_dialog_response (GtkDialog *dialog,
                default:
                        break;
                }
-               self->pv->last_reply = GCR_PROMPT_REPLY_OK;
+               self->pv->last_reply = GCR_PROMPT_REPLY_CONTINUE;
                break;
 
        default:
@@ -741,6 +762,10 @@ gcr_prompt_dialog_class_init (GcrPromptDialogClass *klass)
 
        g_object_class_override_property (gobject_class, PROP_CALLER_WINDOW, "caller-window");
 
+       g_object_class_override_property (gobject_class, PROP_CONTINUE_LABEL, "continue-label");
+
+       g_object_class_override_property (gobject_class, PROP_CANCEL_LABEL, "cancel-label");
+
        /**
         * GcrPromptDialog:password-visible
         *
@@ -829,7 +854,7 @@ gcr_prompt_dialog_password_finish (GcrPrompt *prompt,
        if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
                return NULL;
 
-       if (self->pv->last_reply == GCR_PROMPT_REPLY_OK)
+       if (self->pv->last_reply == GCR_PROMPT_REPLY_CONTINUE)
                return gtk_entry_buffer_get_text (self->pv->password_buffer);
        return NULL;
 }
index df6629b..29d6492 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "gcr-prompt.h"
 
+#include <glib/gi18n-lib.h>
+
 /**
  * SECTION:gcr-prompt
  * @title: GcrPrompt
@@ -68,7 +70,7 @@
 
 /**
  * GcrPromptReply:
- * @GCR_PROMPT_REPLY_OK: the user replied with 'ok'
+ * @GCR_PROMPT_REPLY_CONTINUE: the user replied with 'ok'
  * @GCR_PROMPT_REPLY_CANCEL: the prompt was cancelled
  *
  * Various replies returned by gcr_prompt_confirm() and friends.
@@ -206,6 +208,24 @@ gcr_prompt_default_init (GcrPromptIface *iface)
                                g_param_spec_string ("caller-window", "Caller window", "Window ID of application window requesting prompt",
                                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+               /**
+                * GcrPrompt:continue-label:
+                *
+                * The label for the continue button in the prompt.
+                */
+               g_object_interface_install_property (iface,
+                               g_param_spec_string ("continue-label", "Continue label", "Continue button label",
+                                                    _("Continue"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
+               /**
+                * GcrPrompt:cancel-label:
+                *
+                * The label for the cancel button in the prompt.
+                */
+               g_object_interface_install_property (iface,
+                               g_param_spec_string ("cancel-label", "Cancel label", "Cancel button label",
+                                                    _("Cancel"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
                g_once_init_leave (&initialized, 1);
        }
 }
@@ -583,6 +603,80 @@ gcr_prompt_set_caller_window (GcrPrompt *prompt,
 }
 
 /**
+ * gcr_prompt_get_continue_label:
+ * @prompt: the prompt
+ *
+ * Get the label for the continue button.
+ *
+ * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
+ * from the prompt.
+ *
+ * Returns: (transfer full): a newly allocated string containing the label
+ */
+gchar *
+gcr_prompt_get_continue_label (GcrPrompt *prompt)
+{
+       gchar *continue_label = NULL;
+       g_object_get (prompt, "continue-label", &continue_label, NULL);
+       return continue_label;
+}
+
+/**
+ * gcr_prompt_set_continue_label:
+ * @prompt: the prompt
+ * @continue_label: the label
+ *
+ * Set the label for the continue button.
+ *
+ * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
+ * from the prompt.
+ */
+void
+gcr_prompt_set_continue_label (GcrPrompt *prompt,
+                               const gchar *continue_label)
+{
+       g_return_if_fail (GCR_IS_PROMPT (prompt));
+       g_object_set (prompt, "continue-label", continue_label, NULL);
+}
+
+/**
+ * gcr_prompt_get_cancel_label:
+ * @prompt: the prompt
+ *
+ * Get the label for the cancel button.
+ *
+ * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
+ * from the prompt.
+ *
+ * Returns: (transfer full): a newly allocated string containing the label
+ */
+gchar *
+gcr_prompt_get_cancel_label (GcrPrompt *prompt)
+{
+       gchar *cancel_label = NULL;
+       g_object_get (prompt, "cancel-label", &cancel_label, NULL);
+       return cancel_label;
+}
+
+/**
+ * gcr_prompt_set_cancel_label:
+ * @prompt: the prompt
+ * @cancel_label: the label
+ *
+ * Set the label for the continue button.
+ *
+ * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
+ * from the prompt.
+ */
+void
+gcr_prompt_set_cancel_label (GcrPrompt *prompt,
+                             const gchar *cancel_label)
+{
+       g_return_if_fail (GCR_IS_PROMPT (prompt));
+       g_object_set (prompt, "cancel-label", cancel_label, NULL);
+}
+
+/**
  * gcr_prompt_password_async:
  * @prompt: a prompt
  * @cancellable: optional cancellation object
index 5fa0055..e68982d 100644 (file)
@@ -36,7 +36,7 @@ G_BEGIN_DECLS
 
 typedef enum {
        GCR_PROMPT_REPLY_CANCEL = 0,
-       GCR_PROMPT_REPLY_OK = 1,
+       GCR_PROMPT_REPLY_CONTINUE = 1,
 } GcrPromptReply;
 
 #define GCR_TYPE_PROMPT                 (gcr_prompt_get_type ())
@@ -113,6 +113,16 @@ gchar *              gcr_prompt_get_caller_window         (GcrPrompt *prompt);
 void                 gcr_prompt_set_caller_window         (GcrPrompt *prompt,
                                                            const gchar *window_id);
 
+gchar *              gcr_prompt_get_continue_label        (GcrPrompt *prompt);
+
+void                 gcr_prompt_set_continue_label        (GcrPrompt *prompt,
+                                                           const gchar *continue_label);
+
+gchar *              gcr_prompt_get_cancel_label          (GcrPrompt *prompt);
+
+void                 gcr_prompt_set_cancel_label          (GcrPrompt *prompt,
+                                                           const gchar *cancel_label);
+
 void                 gcr_prompt_password_async            (GcrPrompt *prompt,
                                                            GCancellable *cancellable,
                                                            GAsyncReadyCallback callback,
index cae19a6..08b2db5 100644 (file)
@@ -101,7 +101,9 @@ enum {
        PROP_PASSWORD_STRENGTH,
        PROP_CHOICE_LABEL,
        PROP_CHOICE_CHOSEN,
-       PROP_CALLER_WINDOW
+       PROP_CALLER_WINDOW,
+       PROP_CONTINUE_LABEL,
+       PROP_CANCEL_LABEL
 };
 
 struct _GcrSystemPromptPrivate {
@@ -306,6 +308,12 @@ gcr_system_prompt_set_property (GObject *obj,
        case PROP_CALLER_WINDOW:
                prompt_set_string_property (self, "caller-window", g_value_get_string (value));
                break;
+       case PROP_CONTINUE_LABEL:
+               prompt_set_string_property (self, "continue-label", g_value_get_string (value));
+               break;
+       case PROP_CANCEL_LABEL:
+               prompt_set_string_property (self, "cancel-label", g_value_get_string (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
                break;
@@ -354,6 +362,12 @@ gcr_system_prompt_get_property (GObject *obj,
        case PROP_CALLER_WINDOW:
                g_value_set_string (value, prompt_get_string_property (self, "caller-window", TRUE));
                break;
+       case PROP_CONTINUE_LABEL:
+               g_value_set_string (value, prompt_get_string_property (self, "continue-label", TRUE));
+               break;
+       case PROP_CANCEL_LABEL:
+               g_value_set_string (value, prompt_get_string_property (self, "cancel-label", TRUE));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
                break;
@@ -460,6 +474,8 @@ gcr_system_prompt_class_init (GcrSystemPromptClass *klass)
        g_object_class_override_property (gobject_class, PROP_CHOICE_LABEL, "choice-label");
        g_object_class_override_property (gobject_class, PROP_CHOICE_CHOSEN, "choice-chosen");
        g_object_class_override_property (gobject_class, PROP_CALLER_WINDOW, "caller-window");
+       g_object_class_override_property (gobject_class, PROP_CONTINUE_LABEL, "continue-label");
+       g_object_class_override_property (gobject_class, PROP_CANCEL_LABEL, "cancel-label");
 }
 
 /**
@@ -1020,7 +1036,7 @@ handle_last_response (GcrSystemPrompt *self)
                              GCR_PROMPT_REPLY_CANCEL);
 
        if (g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_YES)) {
-               response = GCR_PROMPT_REPLY_OK;
+               response = GCR_PROMPT_REPLY_CONTINUE;
 
        } else if (g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_NO) ||
                   g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_NONE)) {
@@ -1061,7 +1077,7 @@ gcr_system_prompt_password_finish (GcrPrompt *prompt,
        if (g_simple_async_result_propagate_error (res, error))
                return FALSE;
 
-       if (handle_last_response (self) == GCR_PROMPT_REPLY_OK)
+       if (handle_last_response (self) == GCR_PROMPT_REPLY_CONTINUE)
                return gcr_secret_exchange_get_secret (self->pv->exchange, NULL);
 
        return NULL;
index b094f01..49727ed 100644 (file)
@@ -776,7 +776,7 @@ on_prompt_confirm (GObject *source,
        }
 
        switch (reply) {
-       case GCR_PROMPT_REPLY_OK:
+       case GCR_PROMPT_REPLY_CONTINUE:
                response = GCR_DBUS_PROMPT_REPLY_YES;
                break;
        case GCR_PROMPT_REPLY_CANCEL:
index 29489c5..5f02425 100644 (file)
@@ -5,6 +5,8 @@ message = Enter password for keyring 'sean' to unlock
 description = An application wants access to the keyring 'sean', but it is locked
 choice-label = Always unlock this keyring whenever I'm logged in.
 password-new = false
+continue-label = Go
+cancel-label = Stop
 
 [one]
 type = password
index 99344bf..96920c9 100644 (file)
@@ -335,6 +335,8 @@ test_prompt_properties (Test *test,
                                             "choice-chosen", TRUE,
                                             "password-new", TRUE,
                                             "password-strength", 0,
+                                            "continue-label", "My Continue",
+                                            "cancel-label", "My Cancel",
                                             NULL);
 
        prompt = gcr_system_prompt_open_for_prompter (test->prompter_name, 0, NULL, &error);
@@ -350,6 +352,8 @@ test_prompt_properties (Test *test,
                      "warning", "Other Warning",
                      "password-new", FALSE,
                      "choice-chosen", TRUE,
+                     "continue-label", "Other Continue",
+                     "cancel-label", "Other Cancel",
                      NULL);
 
        g_assert_cmpstr (gcr_prompt_get_title (prompt), ==, "Other Title");
@@ -358,6 +362,8 @@ test_prompt_properties (Test *test,
        g_assert_cmpstr (gcr_prompt_get_message (prompt), ==, "Other Message");
        g_assert_cmpstr (gcr_prompt_get_caller_window (prompt), ==, "01012");
        g_assert_cmpstr (gcr_prompt_get_warning (prompt), ==, "Other Warning");
+       g_assert_cmpstr (gcr_prompt_get_continue_label (prompt), ==, "Other Continue");
+       g_assert_cmpstr (gcr_prompt_get_cancel_label (prompt), ==, "Other Cancel");
        g_assert (gcr_prompt_get_password_new (prompt) == FALSE);
        g_assert (gcr_prompt_get_choice_chosen (prompt) == TRUE);
 
@@ -367,6 +373,8 @@ test_prompt_properties (Test *test,
        gcr_prompt_set_message (prompt, "My Message");
        gcr_prompt_set_caller_window (prompt, "01010");
        gcr_prompt_set_warning (prompt, "My Warning");
+       gcr_prompt_set_continue_label (prompt, "My Continue");
+       gcr_prompt_set_cancel_label (prompt, "My Cancel");
        gcr_prompt_set_password_new (prompt, TRUE);
        gcr_prompt_set_choice_chosen (prompt, TRUE);
 
@@ -398,6 +406,8 @@ test_prompt_properties_unset (Test *test,
        g_assert_cmpstr (gcr_prompt_get_message (prompt), ==, NULL);
        g_assert_cmpstr (gcr_prompt_get_caller_window (prompt), ==, NULL);
        g_assert_cmpstr (gcr_prompt_get_warning (prompt), ==, NULL);
+       g_assert_cmpstr (gcr_prompt_get_continue_label (prompt), ==, "Continue");
+       g_assert_cmpstr (gcr_prompt_get_cancel_label (prompt), ==, "Cancel");
        g_assert (gcr_prompt_get_password_new (prompt) == FALSE);
        g_assert (gcr_prompt_get_choice_chosen (prompt) == FALSE);
        g_assert_cmpint (gcr_prompt_get_password_strength (prompt), ==, 0);
index ec60cdd..c78d448 100644 (file)
@@ -25,6 +25,7 @@ gcr/gcr-parser.c
 gcr/gcr-pkcs11-import-dialog.c
 [type: gettext/glade]gcr/gcr-pkcs11-import-dialog.ui
 gcr/gcr-pkcs11-import-interaction.c
+gcr/gcr-prompt.c
 gcr/gcr-prompt-dialog.c
 gcr/gcr-subject-public-key.c
 gcr/gcr-system-prompt.c