-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlitosappprefs.c
116 lines (91 loc) · 3.44 KB
/
litosappprefs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Copyright (C) 2023-2024 Giovanni Resta <[email protected]>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include "litosapp.h"
#include "litosappwin.h"
#include "litosappprefs.h"
void litos_app_window_update_font ();
GSettings *litos_app_get_settings(LitosApp *app);
struct _LitosAppPrefs
{
GtkDialog parent;
GtkWidget *font;
};
G_DEFINE_TYPE (LitosAppPrefs, litos_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 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 ();
}
}
void _application_set_font(LitosAppPrefs *prefs)
{
LitosApp *app = LITOS_APP(g_application_get_default());
g_settings_bind_with_mapping (litos_app_get_settings(app), "font",
prefs->font, "font-desc",
G_SETTINGS_BIND_DEFAULT,
string_to_font_desc,
font_desc_to_string,
NULL, NULL);
}
static void
litos_app_prefs_init (LitosAppPrefs *prefs)
{
gtk_widget_init_template (GTK_WIDGET (prefs));
g_signal_connect(prefs->font, "font-set", G_CALLBACK (litos_app_window_update_font), NULL);
g_signal_connect(G_OBJECT(prefs), "notify::application", G_CALLBACK (_application_set_font), NULL);
}
static void
litos_app_prefs_dispose (GObject *object)
{
LitosAppPrefs *prefs;
prefs = LITOS_APP_PREFS (object);
G_OBJECT_CLASS (litos_app_prefs_parent_class)->dispose (object);
}
static void
litos_app_prefs_class_init (LitosAppPrefsClass *class)
{
G_OBJECT_CLASS (class)->dispose = litos_app_prefs_dispose;
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
"/org/gtk/litos/prefs.ui");
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), LitosAppPrefs, font);
}
LitosAppPrefs *
litos_app_prefs_new (LitosAppWindow *win)
{
LitosAppPrefs *prefs = g_object_new (LITOS_APP_PREFS_TYPE, "transient-for", win, "use-header-bar", TRUE, NULL);
gtk_window_set_application(GTK_WINDOW(prefs), GTK_APPLICATION(g_application_get_default()));
return prefs;
}