Add gtk-query-settings

A small utility binary to query all properties of GtkSettings.

https://bugzilla.gnome.org/show_bug.cgi?id=756174
This commit is contained in:
Timm Bäder 2015-10-07 11:26:53 +02:00 committed by Matthias Clasen
parent bddc524cd8
commit 7aa2bfdc77
5 changed files with 127 additions and 2 deletions

View File

@ -315,7 +315,8 @@ content_files = \
input-handling.xml \
visual_index.xml \
getting_started.xml \
overview.xml
overview.xml \
gtk-query-settings.xml
expand_content_files = \
compiling.sgml \
@ -499,7 +500,8 @@ man_MANS = \
gtk3-widget-factory.1 \
gtk3-icon-browser.1 \
broadwayd.1 \
gtk-builder-tool.1
gtk-builder-tool.1 \
gtk-query-settings.1
if ENABLE_MAN

View File

@ -406,6 +406,7 @@
<xi:include href="gtk-encode-symbolic-svg.xml" />
<xi:include href="gtk-builder-tool.xml" />
<xi:include href="gtk-launch.xml" />
<xi:include href="gtk-query-settings.xml" />
<xi:include href="broadwayd.xml" />
</part>

View File

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
]>
<refentry id="gtk-query-settings">
<refentryinfo>
<title>gtk-query-settings</title>
<productname>GTK+</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Timm</firstname>
<surname>Bäder</surname>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>gtk-query-settings</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">User Commands</refmiscinfo>
</refmeta>
<refnamediv>
<refname>gtk-query-settings</refname>
<refpurpose>Utility to print name and value of all GtkSettings properties</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>gtk-query-settings</command>
<arg choice="opt"><replaceable>PATTERN</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>Description</title>
<para>
<command>gtk-query-settings</command> prints both name and value of all properties
available in the GtkSettings class. Optionally, you can filter which properties
to list by specifying a PATTERN.
</para>
</refsect1>
</refentry>

View File

@ -1404,6 +1404,7 @@ bin_PROGRAMS = \
gtk-update-icon-cache \
gtk-encode-symbolic-svg \
gtk-builder-tool \
gtk-query-settings \
gtk-launch
gtk_query_immodules_3_0_SOURCES = queryimmodules.c
@ -1428,6 +1429,12 @@ gtk_builder_tool_LDADD = \
$(top_builddir)/gdk/libgdk-3.la \
$(GTK_DEP_LIBS)
gtk_query_settings_SOURCES = gtk-query-settings.c
gtk_query_settings_LDADD= \
libgtk-3.la \
$(top_builddir)/gdk/libgdk-3.la \
$(GTK_DEP_LIBS)
gtk_launch_SOURCES = gtk-launch.c
gtk_launch_LDADD = \
libgtk-3.la \

70
gtk/gtk-query-settings.c Normal file
View File

@ -0,0 +1,70 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <string.h>
int
main (int argc, char **argv)
{
GtkSettings *settings;
GParamSpec **props;
guint n_properties;
int i;
int max_prop_name_length = 0;
gchar *pattern = NULL;
gtk_init (&argc, &argv);
if (argc > 1)
pattern = argv[1];
settings = gtk_settings_get_default ();
props = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), &n_properties);
for (i = 0; i < n_properties; i ++)
{
int len = strlen (props[i]->name);
if (len > max_prop_name_length)
max_prop_name_length = len;
}
for (i = 0; i < n_properties; i ++)
{
GValue value = {0};
GParamSpec *prop = props[i];
gchar *value_str;
int spacing = max_prop_name_length - strlen (prop->name);
if (pattern && !g_strrstr (prop->name, pattern))
continue;
g_value_init (&value, prop->value_type);
g_object_get_property (G_OBJECT (settings), prop->name, &value);
if (G_VALUE_HOLDS_ENUM (&value))
{
GEnumClass *enum_class = G_PARAM_SPEC_ENUM (prop)->enum_class;
GEnumValue *enum_value = g_enum_get_value (enum_class, g_value_get_enum (&value));
value_str = g_strdup (enum_value->value_name);
}
else
{
value_str = g_strdup_value_contents (&value);
}
for (; spacing >= 0; spacing --)
printf (" ");
printf ("%s: %s\n", prop->name, value_str);
g_free (value_str);
g_value_unset (&value);
}
g_free (props);
return 0;
}