GTK:如何以编程方式从 GSchema 枚举中获取缺刻和值

GTK: How to get the nicks and values from a GSchema enum programmatically

我有以下 GSchema:

<schemalist gettext-domain="example">
    <enum id="com.example.unit.temperature">
        <value nick="Celsius" value="0"/>
        <value nick="Fahrenheit" value="1"/>
    </enum>
    <schema id="com.example.corefreqgtk" path="/com/example/">
        <key name="unit-of-temperature" enum="com.example.corefreqgtk.unit.temperature">
            <default>'Celsius'</default>
            <summary>Unit of temperature</summary>
            <description>The unit of temperature used across the app</description>
        </key>
    </schema>
</schemalist>

我正在寻找一种以编程方式获取枚举 com.example.unit.temperaturenickvalue 的方法。

我想做的是将 unit-of-temperature 键绑定到 ComboBoxText 以允许用户 select 温度单位,但我想避免在 GScheme 和代码中定义两次枚举。

我的目标是初始化 ComboBoxText 直接从 GSettings 中读取可能的值。

您可以使用 GSettingsSchema 在 GSettings 架构中收集数据。对于与枚举值关联的键,g_settings_schema_key_get_range() 将 return 所有可能的值作为数组。