mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-01 00:42:16 +01:00 
			
		
		
		
	Bug 624991 - GSettings mapping for G_TYPE_STRV
Added default mapping for G_TYPE_STRV based on a patch from Garrett Regier. Add a test case.
This commit is contained in:
		| @@ -377,6 +377,14 @@ g_settings_set_mapping (const GValue       *value, | ||||
|         return g_variant_new_signature (g_value_get_string (value)); | ||||
|     } | ||||
|  | ||||
|   else if (G_VALUE_HOLDS (value, G_TYPE_STRV)) | ||||
|     { | ||||
|       if (g_value_get_boxed (value) == NULL) | ||||
|         return NULL; | ||||
|       return g_variant_new_strv ((const gchar **) g_value_get_boxed (value), | ||||
|                                  -1); | ||||
|     } | ||||
|  | ||||
|   else if (G_VALUE_HOLDS_ENUM (value)) | ||||
|     { | ||||
|       GEnumValue *enumval; | ||||
| @@ -498,7 +506,13 @@ g_settings_get_mapping (GValue   *value, | ||||
|     } | ||||
|   else if (g_variant_is_of_type (variant, G_VARIANT_TYPE ("as"))) | ||||
|     { | ||||
|       if (G_VALUE_HOLDS_FLAGS (value)) | ||||
|       if (G_VALUE_HOLDS (value, G_TYPE_STRV)) | ||||
|         { | ||||
|           g_value_take_boxed (value, g_variant_dup_strv (variant, NULL)); | ||||
|           return TRUE; | ||||
|         } | ||||
|  | ||||
|       else if (G_VALUE_HOLDS_FLAGS (value)) | ||||
|         { | ||||
|           GFlagsClass *fclass; | ||||
|           GFlagsValue *fvalue; | ||||
| @@ -569,6 +583,8 @@ g_settings_mapping_is_compatible (GType               gvalue_type, | ||||
|           g_variant_type_equal (variant_type, G_VARIANT_TYPE ("ay")) || | ||||
|           g_variant_type_equal (variant_type, G_VARIANT_TYPE_OBJECT_PATH) || | ||||
|           g_variant_type_equal (variant_type, G_VARIANT_TYPE_SIGNATURE)); | ||||
|   else if (gvalue_type == G_TYPE_STRV) | ||||
|     ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE ("as")); | ||||
|   else if (G_TYPE_IS_ENUM (gvalue_type)) | ||||
|     ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE_STRING); | ||||
|   else if (G_TYPE_IS_FLAGS (gvalue_type)) | ||||
|   | ||||
| @@ -687,6 +687,7 @@ enum | ||||
|   PROP_STRING, | ||||
|   PROP_NO_READ, | ||||
|   PROP_NO_WRITE, | ||||
|   PROP_STRV, | ||||
|   PROP_ENUM | ||||
| }; | ||||
|  | ||||
| @@ -706,6 +707,7 @@ typedef struct | ||||
|   gchar *string_prop; | ||||
|   gchar *no_read_prop; | ||||
|   gchar *no_write_prop; | ||||
|   gchar **strv_prop; | ||||
|   guint enum_prop; | ||||
| } TestObject; | ||||
|  | ||||
| @@ -725,6 +727,7 @@ static void | ||||
| test_object_finalize (GObject *object) | ||||
| { | ||||
|   TestObject *testo = (TestObject*)object; | ||||
|   g_strfreev (testo->strv_prop); | ||||
|   g_free (testo->string_prop); | ||||
|   G_OBJECT_CLASS (test_object_parent_class)->finalize (object); | ||||
| } | ||||
| @@ -772,6 +775,9 @@ test_object_get_property (GObject    *object, | ||||
|     case PROP_NO_WRITE: | ||||
|       g_value_set_string (value, test_object->no_write_prop); | ||||
|       break; | ||||
|     case PROP_STRV: | ||||
|       g_value_set_boxed (value, test_object->strv_prop); | ||||
|       break; | ||||
|     case PROP_ENUM: | ||||
|       g_value_set_enum (value, test_object->enum_prop); | ||||
|       break; | ||||
| @@ -826,6 +832,10 @@ test_object_set_property (GObject      *object, | ||||
|       g_free (test_object->no_read_prop); | ||||
|       test_object->no_read_prop = g_value_dup_string (value); | ||||
|       break; | ||||
|     case PROP_STRV: | ||||
|       g_strfreev (test_object->strv_prop); | ||||
|       test_object->strv_prop = g_value_dup_boxed (value); | ||||
|       break; | ||||
|     case PROP_ENUM: | ||||
|       test_object->enum_prop = g_value_get_enum (value); | ||||
|       break; | ||||
| @@ -890,6 +900,8 @@ test_object_class_init (TestObjectClass *class) | ||||
|     g_param_spec_string ("no-write", "", "", NULL, G_PARAM_READABLE)); | ||||
|   g_object_class_install_property (gobject_class, PROP_NO_READ, | ||||
|     g_param_spec_string ("no-read", "", "", NULL, G_PARAM_WRITABLE)); | ||||
|   g_object_class_install_property (gobject_class, PROP_STRV, | ||||
|     g_param_spec_boxed ("strv", "", "", G_TYPE_STRV, G_PARAM_READWRITE)); | ||||
|   g_object_class_install_property (gobject_class, PROP_ENUM, | ||||
|     g_param_spec_enum ("enum", "", "", test_enum_get_type (), TEST_ENUM_FOO, G_PARAM_READWRITE)); | ||||
| } | ||||
| @@ -919,6 +931,7 @@ test_simple_binding (void) | ||||
|   gdouble d; | ||||
|   gchar *s; | ||||
|   GVariant *value; | ||||
|   gchar **strv; | ||||
|  | ||||
|   settings = g_settings_new ("org.gtk.test.binding"); | ||||
|   obj = test_object_new (); | ||||
| @@ -1040,6 +1053,24 @@ test_simple_binding (void) | ||||
|   g_object_get (obj, "double", &d, NULL); | ||||
|   g_assert_cmpfloat (d, ==, -G_MINDOUBLE); | ||||
|  | ||||
|   strv = g_strsplit ("plastic bag,middle class,polyethylene", ",", 0); | ||||
|   g_settings_bind (settings, "strv", obj, "strv", G_SETTINGS_BIND_DEFAULT); | ||||
|   g_object_set (obj, "strv", strv, NULL); | ||||
|   g_strfreev (strv); | ||||
|   strv = g_settings_get_strv (settings, "strv"); | ||||
|   s = g_strjoinv (",", strv); | ||||
|   g_assert_cmpstr (s, ==, "plastic bag,middle class,polyethylene"); | ||||
|   g_strfreev (strv); | ||||
|   g_free (s); | ||||
|   strv = g_strsplit ("decaffeinate,unleaded,keep all surfaces clean", ",", 0); | ||||
|   g_settings_set_strv (settings, "strv", (const gchar **) strv); | ||||
|   g_strfreev (strv); | ||||
|   g_object_get (obj, "strv", &strv, NULL); | ||||
|   s = g_strjoinv (",", strv); | ||||
|   g_assert_cmpstr (s, ==, "decaffeinate,unleaded,keep all surfaces clean"); | ||||
|   g_strfreev (strv); | ||||
|   g_free (s); | ||||
|  | ||||
|   g_settings_bind (settings, "enum", obj, "enum", G_SETTINGS_BIND_DEFAULT); | ||||
|   g_object_set (obj, "enum", TEST_ENUM_BAZ, NULL); | ||||
|   g_assert_cmpstr (g_settings_get_string (settings, "enum"), ==, "baz"); | ||||
|   | ||||
| @@ -111,6 +111,9 @@ | ||||
|     <key name="chararray" type="ay"> | ||||
|       <default>[48, 49]</default> | ||||
|     </key> | ||||
|     <key name="strv" type="as"> | ||||
|       <default>[]</default> | ||||
|     </key> | ||||
|     <key name="enum" enum="org.gtk.test.TestEnum"> | ||||
|       <default>'foo'</default> | ||||
|     </key> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user