From: Matthias Clasen Date: Fri, 4 Aug 2023 12:36:38 +0000 (-0400) Subject: examples: Deprecation cleanup X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~5^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=33fe93d9f24d58f998a842b7f7ab949e1e221617;p=gtk4.git examples: Deprecation cleanup --- diff --git a/examples/application6/exampleappprefs.c b/examples/application6/exampleappprefs.c index 4bdf6542ca..a5372e602d 100644 --- a/examples/application6/exampleappprefs.c +++ b/examples/application6/exampleappprefs.c @@ -15,18 +15,78 @@ struct _ExampleAppPrefs G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) +static gboolean +string_to_font_desc (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + PangoFontDescription *desc; + + desc = pango_font_description_from_string (s); + g_value_take_boxed (value, desc); + + return TRUE; +} + +static GVariant * +font_desc_to_string (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + PangoFontDescription *desc = g_value_get_boxed (value); + char *s = pango_font_description_to_string (desc); + return g_variant_new_take_string (s); +} + +static gboolean +transition_to_pos (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + if (strcmp (s, "none") == 0) + g_value_set_uint (value, 0); + else if (strcmp (s, "crossfade") == 0) + g_value_set_uint (value, 1); + else + g_value_set_uint (value, 2); + + return TRUE; +} + +static GVariant * +pos_to_transition (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + switch (g_value_get_uint (value)) + { + case 0: return g_variant_new_string ("none"); + case 1: return g_variant_new_string ("crossfade"); + case 2: return g_variant_new_string ("slide-left-right"); + default: g_assert_not_reached (); + } +} + static void example_app_prefs_init (ExampleAppPrefs *prefs) { gtk_widget_init_template (GTK_WIDGET (prefs)); prefs->settings = g_settings_new ("org.gtk.exampleapp"); - g_settings_bind (prefs->settings, "font", - prefs->font, "font", - G_SETTINGS_BIND_DEFAULT); - g_settings_bind (prefs->settings, "transition", - prefs->transition, "active-id", - G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping (prefs->settings, "font", + prefs->font, "font-desc", + G_SETTINGS_BIND_DEFAULT, + string_to_font_desc, + font_desc_to_string, + NULL, NULL); + g_settings_bind_with_mapping (prefs->settings, "transition", + prefs->transition, "selected", + G_SETTINGS_BIND_DEFAULT, + transition_to_pos, + pos_to_transition, + NULL, NULL); } static void diff --git a/examples/application6/prefs.ui b/examples/application6/prefs.ui index 04ca33c92d..4d58c291e3 100644 --- a/examples/application6/prefs.ui +++ b/examples/application6/prefs.ui @@ -27,7 +27,10 @@ - + + + + 1 0 @@ -47,12 +50,16 @@ - - - None - Fade - Slide - + + + + + None + Fade + Slide + + + 1 1 diff --git a/examples/application7/exampleappprefs.c b/examples/application7/exampleappprefs.c index 4bdf6542ca..a5372e602d 100644 --- a/examples/application7/exampleappprefs.c +++ b/examples/application7/exampleappprefs.c @@ -15,18 +15,78 @@ struct _ExampleAppPrefs G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) +static gboolean +string_to_font_desc (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + PangoFontDescription *desc; + + desc = pango_font_description_from_string (s); + g_value_take_boxed (value, desc); + + return TRUE; +} + +static GVariant * +font_desc_to_string (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + PangoFontDescription *desc = g_value_get_boxed (value); + char *s = pango_font_description_to_string (desc); + return g_variant_new_take_string (s); +} + +static gboolean +transition_to_pos (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + if (strcmp (s, "none") == 0) + g_value_set_uint (value, 0); + else if (strcmp (s, "crossfade") == 0) + g_value_set_uint (value, 1); + else + g_value_set_uint (value, 2); + + return TRUE; +} + +static GVariant * +pos_to_transition (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + switch (g_value_get_uint (value)) + { + case 0: return g_variant_new_string ("none"); + case 1: return g_variant_new_string ("crossfade"); + case 2: return g_variant_new_string ("slide-left-right"); + default: g_assert_not_reached (); + } +} + static void example_app_prefs_init (ExampleAppPrefs *prefs) { gtk_widget_init_template (GTK_WIDGET (prefs)); prefs->settings = g_settings_new ("org.gtk.exampleapp"); - g_settings_bind (prefs->settings, "font", - prefs->font, "font", - G_SETTINGS_BIND_DEFAULT); - g_settings_bind (prefs->settings, "transition", - prefs->transition, "active-id", - G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping (prefs->settings, "font", + prefs->font, "font-desc", + G_SETTINGS_BIND_DEFAULT, + string_to_font_desc, + font_desc_to_string, + NULL, NULL); + g_settings_bind_with_mapping (prefs->settings, "transition", + prefs->transition, "selected", + G_SETTINGS_BIND_DEFAULT, + transition_to_pos, + pos_to_transition, + NULL, NULL); } static void diff --git a/examples/application7/prefs.ui b/examples/application7/prefs.ui index 04ca33c92d..4d58c291e3 100644 --- a/examples/application7/prefs.ui +++ b/examples/application7/prefs.ui @@ -27,7 +27,10 @@ - + + + + 1 0 @@ -47,12 +50,16 @@ - - - None - Fade - Slide - + + + + + None + Fade + Slide + + + 1 1 diff --git a/examples/application8/exampleappprefs.c b/examples/application8/exampleappprefs.c index 4bdf6542ca..a5372e602d 100644 --- a/examples/application8/exampleappprefs.c +++ b/examples/application8/exampleappprefs.c @@ -15,18 +15,78 @@ struct _ExampleAppPrefs G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) +static gboolean +string_to_font_desc (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + PangoFontDescription *desc; + + desc = pango_font_description_from_string (s); + g_value_take_boxed (value, desc); + + return TRUE; +} + +static GVariant * +font_desc_to_string (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + PangoFontDescription *desc = g_value_get_boxed (value); + char *s = pango_font_description_to_string (desc); + return g_variant_new_take_string (s); +} + +static gboolean +transition_to_pos (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + if (strcmp (s, "none") == 0) + g_value_set_uint (value, 0); + else if (strcmp (s, "crossfade") == 0) + g_value_set_uint (value, 1); + else + g_value_set_uint (value, 2); + + return TRUE; +} + +static GVariant * +pos_to_transition (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + switch (g_value_get_uint (value)) + { + case 0: return g_variant_new_string ("none"); + case 1: return g_variant_new_string ("crossfade"); + case 2: return g_variant_new_string ("slide-left-right"); + default: g_assert_not_reached (); + } +} + static void example_app_prefs_init (ExampleAppPrefs *prefs) { gtk_widget_init_template (GTK_WIDGET (prefs)); prefs->settings = g_settings_new ("org.gtk.exampleapp"); - g_settings_bind (prefs->settings, "font", - prefs->font, "font", - G_SETTINGS_BIND_DEFAULT); - g_settings_bind (prefs->settings, "transition", - prefs->transition, "active-id", - G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping (prefs->settings, "font", + prefs->font, "font-desc", + G_SETTINGS_BIND_DEFAULT, + string_to_font_desc, + font_desc_to_string, + NULL, NULL); + g_settings_bind_with_mapping (prefs->settings, "transition", + prefs->transition, "selected", + G_SETTINGS_BIND_DEFAULT, + transition_to_pos, + pos_to_transition, + NULL, NULL); } static void diff --git a/examples/application8/prefs.ui b/examples/application8/prefs.ui index 04ca33c92d..4d58c291e3 100644 --- a/examples/application8/prefs.ui +++ b/examples/application8/prefs.ui @@ -27,7 +27,10 @@ - + + + + 1 0 @@ -47,12 +50,16 @@ - - - None - Fade - Slide - + + + + + None + Fade + Slide + + + 1 1 diff --git a/examples/application9/exampleappprefs.c b/examples/application9/exampleappprefs.c index 4bdf6542ca..a5372e602d 100644 --- a/examples/application9/exampleappprefs.c +++ b/examples/application9/exampleappprefs.c @@ -15,18 +15,78 @@ struct _ExampleAppPrefs G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) +static gboolean +string_to_font_desc (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + PangoFontDescription *desc; + + desc = pango_font_description_from_string (s); + g_value_take_boxed (value, desc); + + return TRUE; +} + +static GVariant * +font_desc_to_string (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + PangoFontDescription *desc = g_value_get_boxed (value); + char *s = pango_font_description_to_string (desc); + return g_variant_new_take_string (s); +} + +static gboolean +transition_to_pos (GValue *value, + GVariant *variant, + gpointer user_data) +{ + const char *s = g_variant_get_string (variant, NULL); + if (strcmp (s, "none") == 0) + g_value_set_uint (value, 0); + else if (strcmp (s, "crossfade") == 0) + g_value_set_uint (value, 1); + else + g_value_set_uint (value, 2); + + return TRUE; +} + +static GVariant * +pos_to_transition (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + switch (g_value_get_uint (value)) + { + case 0: return g_variant_new_string ("none"); + case 1: return g_variant_new_string ("crossfade"); + case 2: return g_variant_new_string ("slide-left-right"); + default: g_assert_not_reached (); + } +} + static void example_app_prefs_init (ExampleAppPrefs *prefs) { gtk_widget_init_template (GTK_WIDGET (prefs)); prefs->settings = g_settings_new ("org.gtk.exampleapp"); - g_settings_bind (prefs->settings, "font", - prefs->font, "font", - G_SETTINGS_BIND_DEFAULT); - g_settings_bind (prefs->settings, "transition", - prefs->transition, "active-id", - G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping (prefs->settings, "font", + prefs->font, "font-desc", + G_SETTINGS_BIND_DEFAULT, + string_to_font_desc, + font_desc_to_string, + NULL, NULL); + g_settings_bind_with_mapping (prefs->settings, "transition", + prefs->transition, "selected", + G_SETTINGS_BIND_DEFAULT, + transition_to_pos, + pos_to_transition, + NULL, NULL); } static void diff --git a/examples/application9/prefs.ui b/examples/application9/prefs.ui index 04ca33c92d..4d58c291e3 100644 --- a/examples/application9/prefs.ui +++ b/examples/application9/prefs.ui @@ -27,7 +27,10 @@ - + + + + 1 0 @@ -47,12 +50,16 @@ - - - None - Fade - Slide - + + + + + None + Fade + Slide + + + 1 1