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
main(int argc,char ** argv)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   gchar        *pattern = NULL;
32 
33   gtk_init (&argc, &argv);
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);
40 
41   for (i = 0; i < n_properties; i ++)
42     {
43       int len = strlen (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       gchar      *value_str;
55       int         spacing = max_prop_name_length - strlen (prop->name) + 1;
56       gboolean    deprecated;
57 
58       if (pattern && !g_strrstr (prop->name, pattern))
59         continue;
60 
61       g_value_init (&value, prop->value_type);
62       g_object_get_property (G_OBJECT (settings), prop->name, &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, g_value_get_enum (&value));
69 
70           value_str = g_strdup (enum_value->value_name);
71         }
72       else
73         {
74           value_str = g_strdup_value_contents (&value);
75         }
76 
77       if (deprecated)
78         {
79           printf ("!");
80           spacing --;
81         }
82 
83       for (; spacing >= 0; spacing --)
84         printf (" ");
85 
86       printf ("%s: %s\n", prop->name, value_str);
87 
88       g_free (value_str);
89       g_value_unset (&value);
90     }
91 
92   g_free (props);
93 
94   return 0;
95 }
96