examples: Deprecation cleanup

This commit is contained in:
Matthias Clasen 2023-08-04 08:36:38 -04:00
parent 645043d5a2
commit 33fe93d9f2
8 changed files with 320 additions and 52 deletions

View File

@ -15,18 +15,78 @@ struct _ExampleAppPrefs
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) 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 static void
example_app_prefs_init (ExampleAppPrefs *prefs) example_app_prefs_init (ExampleAppPrefs *prefs)
{ {
gtk_widget_init_template (GTK_WIDGET (prefs)); gtk_widget_init_template (GTK_WIDGET (prefs));
prefs->settings = g_settings_new ("org.gtk.exampleapp"); prefs->settings = g_settings_new ("org.gtk.exampleapp");
g_settings_bind (prefs->settings, "font", g_settings_bind_with_mapping (prefs->settings, "font",
prefs->font, "font", prefs->font, "font-desc",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT,
g_settings_bind (prefs->settings, "transition", string_to_font_desc,
prefs->transition, "active-id", font_desc_to_string,
G_SETTINGS_BIND_DEFAULT); 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 static void

View File

@ -27,7 +27,10 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkFontButton" id="font"> <object class="GtkFontDialogButton" id="font">
<property name="dialog">
<object class="GtkFontDialog"/>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -47,12 +50,16 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="transition"> <object class="GtkDropDown" id="transition">
<items> <property name="model">
<item translatable="yes" id="none">None</item> <object class="GtkStringList">
<item translatable="yes" id="crossfade">Fade</item> <items>
<item translatable="yes" id="slide-left-right">Slide</item> <item translatable="yes">None</item>
</items> <item translatable="yes">Fade</item>
<item translatable="yes">Slide</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>

View File

@ -15,18 +15,78 @@ struct _ExampleAppPrefs
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) 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 static void
example_app_prefs_init (ExampleAppPrefs *prefs) example_app_prefs_init (ExampleAppPrefs *prefs)
{ {
gtk_widget_init_template (GTK_WIDGET (prefs)); gtk_widget_init_template (GTK_WIDGET (prefs));
prefs->settings = g_settings_new ("org.gtk.exampleapp"); prefs->settings = g_settings_new ("org.gtk.exampleapp");
g_settings_bind (prefs->settings, "font", g_settings_bind_with_mapping (prefs->settings, "font",
prefs->font, "font", prefs->font, "font-desc",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT,
g_settings_bind (prefs->settings, "transition", string_to_font_desc,
prefs->transition, "active-id", font_desc_to_string,
G_SETTINGS_BIND_DEFAULT); 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 static void

View File

@ -27,7 +27,10 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkFontButton" id="font"> <object class="GtkFontDialogButton" id="font">
<property name="dialog">
<object class="GtkFontDialog"/>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -47,12 +50,16 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="transition"> <object class="GtkDropDown" id="transition">
<items> <property name="model">
<item translatable="yes" id="none">None</item> <object class="GtkStringList">
<item translatable="yes" id="crossfade">Fade</item> <items>
<item translatable="yes" id="slide-left-right">Slide</item> <item translatable="yes">None</item>
</items> <item translatable="yes">Fade</item>
<item translatable="yes">Slide</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>

View File

@ -15,18 +15,78 @@ struct _ExampleAppPrefs
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) 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 static void
example_app_prefs_init (ExampleAppPrefs *prefs) example_app_prefs_init (ExampleAppPrefs *prefs)
{ {
gtk_widget_init_template (GTK_WIDGET (prefs)); gtk_widget_init_template (GTK_WIDGET (prefs));
prefs->settings = g_settings_new ("org.gtk.exampleapp"); prefs->settings = g_settings_new ("org.gtk.exampleapp");
g_settings_bind (prefs->settings, "font", g_settings_bind_with_mapping (prefs->settings, "font",
prefs->font, "font", prefs->font, "font-desc",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT,
g_settings_bind (prefs->settings, "transition", string_to_font_desc,
prefs->transition, "active-id", font_desc_to_string,
G_SETTINGS_BIND_DEFAULT); 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 static void

View File

@ -27,7 +27,10 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkFontButton" id="font"> <object class="GtkFontDialogButton" id="font">
<property name="dialog">
<object class="GtkFontDialog"/>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -47,12 +50,16 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="transition"> <object class="GtkDropDown" id="transition">
<items> <property name="model">
<item translatable="yes" id="none">None</item> <object class="GtkStringList">
<item translatable="yes" id="crossfade">Fade</item> <items>
<item translatable="yes" id="slide-left-right">Slide</item> <item translatable="yes">None</item>
</items> <item translatable="yes">Fade</item>
<item translatable="yes">Slide</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>

View File

@ -15,18 +15,78 @@ struct _ExampleAppPrefs
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG) 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 static void
example_app_prefs_init (ExampleAppPrefs *prefs) example_app_prefs_init (ExampleAppPrefs *prefs)
{ {
gtk_widget_init_template (GTK_WIDGET (prefs)); gtk_widget_init_template (GTK_WIDGET (prefs));
prefs->settings = g_settings_new ("org.gtk.exampleapp"); prefs->settings = g_settings_new ("org.gtk.exampleapp");
g_settings_bind (prefs->settings, "font", g_settings_bind_with_mapping (prefs->settings, "font",
prefs->font, "font", prefs->font, "font-desc",
G_SETTINGS_BIND_DEFAULT); G_SETTINGS_BIND_DEFAULT,
g_settings_bind (prefs->settings, "transition", string_to_font_desc,
prefs->transition, "active-id", font_desc_to_string,
G_SETTINGS_BIND_DEFAULT); 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 static void

View File

@ -27,7 +27,10 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkFontButton" id="font"> <object class="GtkFontDialogButton" id="font">
<property name="dialog">
<object class="GtkFontDialog"/>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">0</property> <property name="row">0</property>
@ -47,12 +50,16 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="transition"> <object class="GtkDropDown" id="transition">
<items> <property name="model">
<item translatable="yes" id="none">None</item> <object class="GtkStringList">
<item translatable="yes" id="crossfade">Fade</item> <items>
<item translatable="yes" id="slide-left-right">Slide</item> <item translatable="yes">None</item>
</items> <item translatable="yes">Fade</item>
<item translatable="yes">Slide</item>
</items>
</object>
</property>
<layout> <layout>
<property name="column">1</property> <property name="column">1</property>
<property name="row">1</property> <property name="row">1</property>