1 | /* Copyright 2015 Timm Bäder |
2 | * |
3 | * GTK+ is free software; you can redistribute it and/or modify it |
4 | * under the terms of the GNU Lesser General Public License as |
5 | * published by the Free Software Foundation; either version 2 of the |
6 | * License, or (at your option) any later version. |
7 | * |
8 | * GLib is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * Lesser General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU Lesser General Public |
14 | * License along with GTK+; see the file COPYING. If not, |
15 | * see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #include <glib.h> |
19 | #include <gtk/gtk.h> |
20 | #include <string.h> |
21 | |
22 | |
23 | int |
24 | main (int argc, char **argv) |
25 | { |
26 | GtkSettings *settings; |
27 | GParamSpec **props; |
28 | guint n_properties; |
29 | guint i; |
30 | int max_prop_name_length = 0; |
31 | char *pattern = NULL; |
32 | |
33 | gtk_init (); |
34 | |
35 | if (argc > 1) |
36 | pattern = argv[1]; |
37 | |
38 | settings = gtk_settings_get_default (); |
39 | props = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), n_properties: &n_properties); |
40 | |
41 | for (i = 0; i < n_properties; i ++) |
42 | { |
43 | int len = strlen (s: props[i]->name); |
44 | |
45 | if (len > max_prop_name_length) |
46 | max_prop_name_length = len; |
47 | } |
48 | |
49 | |
50 | for (i = 0; i < n_properties; i ++) |
51 | { |
52 | GValue value = {0}; |
53 | GParamSpec *prop = props[i]; |
54 | char *value_str; |
55 | int spacing = max_prop_name_length - strlen (s: prop->name) + 1; |
56 | gboolean deprecated; |
57 | |
58 | if (pattern && !g_strrstr (haystack: prop->name, needle: pattern)) |
59 | continue; |
60 | |
61 | g_value_init (value: &value, g_type: prop->value_type); |
62 | g_object_get_property (G_OBJECT (settings), property_name: prop->name, value: &value); |
63 | deprecated = prop->flags & G_PARAM_DEPRECATED; |
64 | |
65 | if (G_VALUE_HOLDS_ENUM (&value)) |
66 | { |
67 | GEnumClass *enum_class = G_PARAM_SPEC_ENUM (prop)->enum_class; |
68 | GEnumValue *enum_value = g_enum_get_value (enum_class, value: g_value_get_enum (value: &value)); |
69 | |
70 | value_str = g_strdup (str: enum_value->value_name); |
71 | } |
72 | else |
73 | { |
74 | value_str = g_strdup_value_contents (value: &value); |
75 | } |
76 | |
77 | if (deprecated) |
78 | { |
79 | printf (format: "!" ); |
80 | spacing --; |
81 | } |
82 | |
83 | for (; spacing >= 0; spacing --) |
84 | printf (format: " " ); |
85 | |
86 | printf (format: "%s: %s\n" , prop->name, value_str); |
87 | |
88 | g_free (mem: value_str); |
89 | g_value_unset (value: &value); |
90 | } |
91 | |
92 | g_free (mem: props); |
93 | |
94 | return 0; |
95 | } |
96 | |