[gcr] gcr: Add gcr_prompt_reset() function



commit 5ef12d63fed8037151bdcbe904abe7c88ce5e507
Author: Stef Walter <stefw gnome org>
Date:   Fri Feb 10 14:24:51 2012 +0100

    gcr: Add gcr_prompt_reset() function
    
     * Resets all properties of the prompt to the defaults in the
       interface

 docs/reference/gcr/gcr-sections.txt |    1 +
 docs/reference/gcr/gcr.interfaces   |   43 -------------------------
 gcr/gcr-base.symbols                |    1 +
 gcr/gcr-prompt.c                    |   54 ++++++++++++++++++++++++++++---
 gcr/gcr-prompt.h                    |    2 +
 gcr/tests/test-system-prompt.c      |   60 +++++++++++++++++++++++++++++++++--
 6 files changed, 109 insertions(+), 52 deletions(-)
---
diff --git a/docs/reference/gcr/gcr-sections.txt b/docs/reference/gcr/gcr-sections.txt
index 129cfdc..6b7f4c0 100644
--- a/docs/reference/gcr/gcr-sections.txt
+++ b/docs/reference/gcr/gcr-sections.txt
@@ -723,6 +723,7 @@ gcr_prompt_confirm
 gcr_prompt_confirm_async
 gcr_prompt_confirm_finish
 gcr_prompt_confirm_run
+gcr_prompt_reset
 gcr_prompt_get_title
 gcr_prompt_set_title
 gcr_prompt_get_message
diff --git a/gcr/gcr-base.symbols b/gcr/gcr-base.symbols
index 8d101e7..efb4f27 100644
--- a/gcr/gcr-base.symbols
+++ b/gcr/gcr-base.symbols
@@ -173,6 +173,7 @@ gcr_prompt_password_async
 gcr_prompt_password_finish
 gcr_prompt_password_run
 gcr_prompt_reply_get_type
+gcr_prompt_reset
 gcr_prompt_set_caller_window
 gcr_prompt_set_cancel_label
 gcr_prompt_set_choice_chosen
diff --git a/gcr/gcr-prompt.c b/gcr/gcr-prompt.c
index 29d6492..379808b 100644
--- a/gcr/gcr-prompt.c
+++ b/gcr/gcr-prompt.c
@@ -104,7 +104,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("title", "Title", "Prompt title",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:message:
@@ -115,7 +115,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("message", "Message", "Prompt message",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:description:
@@ -127,7 +127,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("description", "Description", "Prompt description",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:warning:
@@ -139,7 +139,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("warning", "Warning", "Prompt warning",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:password-new:
@@ -182,7 +182,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("choice-label", "Choice label", "Label for prompt choice",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:choice-chosen:
@@ -206,7 +206,7 @@ gcr_prompt_default_init (GcrPromptIface *iface)
 		 */
 		g_object_interface_install_property (iface,
 		                g_param_spec_string ("caller-window", "Caller window", "Window ID of application window requesting prompt",
-		                                     NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+		                                     NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
 		/**
 		 * GcrPrompt:continue-label:
@@ -269,6 +269,48 @@ on_run_complete (GObject *source,
 	g_main_loop_quit (closure->loop);
 }
 
+void
+gcr_prompt_reset (GcrPrompt *prompt)
+{
+	GParamSpec **params;
+	GcrPromptIface *iface;
+	guint i, n_params;
+
+	g_return_if_fail (GCR_IS_PROMPT (prompt));
+
+	iface = GCR_PROMPT_GET_INTERFACE (prompt);
+	params = g_object_interface_list_properties (iface, &n_params);
+
+	g_object_freeze_notify (G_OBJECT (prompt));
+
+	for (i = 0; i < n_params; i++) {
+		if (!(params[i]->flags & G_PARAM_WRITABLE))
+			continue;
+
+		if (params[i]->value_type == G_TYPE_STRING)
+			g_object_set (prompt, params[i]->name,
+			              ((GParamSpecString *)params[i])->default_value,
+			              NULL);
+
+		else if (params[i]->value_type == G_TYPE_INT)
+			g_object_set (prompt, params[i]->name,
+			              ((GParamSpecInt *)params[i])->default_value,
+			              NULL);
+
+		else if (params[i]->value_type == G_TYPE_BOOLEAN)
+			g_object_set (prompt, params[i]->name,
+			              ((GParamSpecBoolean *)params[i])->default_value,
+			              NULL);
+
+		else
+			g_assert_not_reached ();
+	}
+
+	g_free (params);
+
+	g_object_thaw_notify (G_OBJECT (prompt));
+}
+
 /**
  * gcr_prompt_get_title:
  * @prompt: the prompt
diff --git a/gcr/gcr-prompt.h b/gcr/gcr-prompt.h
index e68982d..00ff8a6 100644
--- a/gcr/gcr-prompt.h
+++ b/gcr/gcr-prompt.h
@@ -71,6 +71,8 @@ struct _GcrPromptIface {
 
 GType                gcr_prompt_get_type                  (void);
 
+void                 gcr_prompt_reset                     (GcrPrompt *prompt);
+
 gchar *              gcr_prompt_get_title                 (GcrPrompt *prompt);
 
 void                 gcr_prompt_set_title                 (GcrPrompt *prompt,
diff --git a/gcr/tests/test-system-prompt.c b/gcr/tests/test-system-prompt.c
index 96920c9..944d773 100644
--- a/gcr/tests/test-system-prompt.c
+++ b/gcr/tests/test-system-prompt.c
@@ -400,10 +400,63 @@ test_prompt_properties_unset (Test *test,
 	g_assert_no_error (error);
 	g_assert (GCR_IS_SYSTEM_PROMPT (prompt));
 
-	g_assert_cmpstr (gcr_prompt_get_title (prompt), ==, NULL);
+	g_assert_cmpstr (gcr_prompt_get_title (prompt), ==, "");
 	g_assert_cmpstr (gcr_prompt_get_choice_label (prompt), ==, NULL);
-	g_assert_cmpstr (gcr_prompt_get_description (prompt), ==, NULL);
-	g_assert_cmpstr (gcr_prompt_get_message (prompt), ==, NULL);
+	g_assert_cmpstr (gcr_prompt_get_description (prompt), ==, "");
+	g_assert_cmpstr (gcr_prompt_get_message (prompt), ==, "");
+	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);
+
+	g_object_unref (prompt);
+	egg_assert_not_object (prompt);
+}
+
+
+static void
+test_prompt_properties_reset (Test *test,
+                              gconstpointer unused)
+{
+	GcrPrompt *prompt;
+	GError *error = NULL;
+
+	prompt = gcr_system_prompt_open_for_prompter (test->prompter_name, 0, NULL, &error);
+	g_assert_no_error (error);
+
+	g_object_set (prompt,
+	              "title", "Other Title",
+	              "choice-label", "Other Choice",
+	              "description", "Other Description",
+	              "message", "Other Message",
+	              "caller-window", "01012",
+	              "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");
+	g_assert_cmpstr (gcr_prompt_get_choice_label (prompt), ==, "Other Choice");
+	g_assert_cmpstr (gcr_prompt_get_description (prompt), ==, "Other Description");
+	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);
+
+	gcr_prompt_reset (prompt);
+
+	g_assert_cmpstr (gcr_prompt_get_title (prompt), ==, "");
+	g_assert_cmpstr (gcr_prompt_get_choice_label (prompt), ==, NULL);
+	g_assert_cmpstr (gcr_prompt_get_description (prompt), ==, "");
+	g_assert_cmpstr (gcr_prompt_get_message (prompt), ==, "");
 	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");
@@ -510,6 +563,7 @@ main (int argc, char **argv)
 	g_test_add ("/gcr/system-prompt/confirm-cancel", Test, NULL, setup, test_cancel_confirm, teardown);
 	g_test_add ("/gcr/system-prompt/properties", Test, NULL, setup, test_prompt_properties, teardown);
 	g_test_add ("/gcr/system-prompt/properties-unset", Test, NULL, setup, test_prompt_properties_unset, teardown);
+	g_test_add ("/gcr/system-prompt/properties-reset", Test, NULL, setup, test_prompt_properties_reset, teardown);
 	g_test_add ("/gcr/system-prompt/close", Test, NULL, setup, test_prompt_close, teardown);
 	g_test_add ("/gcr/system-prompt/close-cancels", Test, NULL, setup, test_close_cancels, teardown);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]