Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "exampleapp.h"
|
|
|
|
#include "exampleappwin.h"
|
|
|
|
#include "exampleappprefs.h"
|
|
|
|
|
2013-07-28 00:33:08 +00:00
|
|
|
struct _ExampleAppPrefs
|
|
|
|
{
|
|
|
|
GtkDialog parent;
|
|
|
|
|
|
|
|
GSettings *settings;
|
|
|
|
GtkWidget *font;
|
|
|
|
GtkWidget *transition;
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
};
|
|
|
|
|
2018-05-08 09:04:03 +00:00
|
|
|
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
|
2023-08-04 12:36:38 +00:00
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
static void
|
|
|
|
example_app_prefs_init (ExampleAppPrefs *prefs)
|
|
|
|
{
|
2013-07-28 00:33:08 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (prefs));
|
2018-05-08 09:04:03 +00:00
|
|
|
prefs->settings = g_settings_new ("org.gtk.exampleapp");
|
2013-07-28 00:33:08 +00:00
|
|
|
|
2023-08-04 12:36:38 +00:00
|
|
|
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);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
example_app_prefs_dispose (GObject *object)
|
|
|
|
{
|
2018-05-08 09:04:03 +00:00
|
|
|
ExampleAppPrefs *prefs;
|
|
|
|
|
|
|
|
prefs = EXAMPLE_APP_PREFS (object);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
|
2018-05-08 09:04:03 +00:00
|
|
|
g_clear_object (&prefs->settings);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
|
2013-07-28 00:33:08 +00:00
|
|
|
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
example_app_prefs_class_init (ExampleAppPrefsClass *class)
|
|
|
|
{
|
2013-07-28 00:33:08 +00:00
|
|
|
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
|
|
|
"/org/gtk/exampleapp/prefs.ui");
|
2018-05-08 09:04:03 +00:00
|
|
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, font);
|
|
|
|
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, transition);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExampleAppPrefs *
|
|
|
|
example_app_prefs_new (ExampleAppWindow *win)
|
|
|
|
{
|
2014-04-17 19:18:01 +00:00
|
|
|
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, "use-header-bar", TRUE, NULL);
|
Add a new example app
Add a new example to the getting started part of the docs. The focus
of this example is on 'new stuff': GtkApplication, templates, settings,
gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer,
GtkListBox, GtkMenuButton, etc.
It is being developed in several steps. Each step is put in a separate
directory below examples/: application1, ..., application8. This is a
little repetitive, but lets us use the code of all examples in the
documentation.
2013-07-20 04:21:48 +00:00
|
|
|
}
|