nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
1#include <gio/gio.h> 2#include <glib-object.h> 3 4void schema_id_literal() { 5 GSettings *settings; 6 { 7 g_autoptr(GSettingsSchemaSource) schema_source; 8 g_autoptr(GSettingsSchema) schema; 9 schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 10 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution-data-server.addressbook", FALSE); 11 settings = g_settings_new_full(schema, NULL, NULL); 12 } 13 g_object_unref(settings); 14} 15 16#define SELF_UID_PATH_ID "org.gnome.evolution-data-server.addressbook" 17int schema_id_from_constant() { 18 GSettings *settings; 19 { 20 g_autoptr(GSettingsSchemaSource) schema_source; 21 g_autoptr(GSettingsSchema) schema; 22 schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 23 schema = g_settings_schema_source_lookup(schema_source, SELF_UID_PATH_ID, FALSE); 24 settings = g_settings_new_full(schema, NULL, NULL); 25 } 26 g_object_unref(settings); 27} 28 29void schema_id_autoptr() { 30 g_autoptr(GSettings) settings = NULL; 31 { 32 g_autoptr(GSettingsSchemaSource) schema_source; 33 g_autoptr(GSettingsSchema) schema; 34 schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 35 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 36 settings = g_settings_new_full(schema, NULL, NULL); 37 } 38} 39 40void schema_id_with_backend() { 41 GSettings *settings; 42 { 43 g_autoptr(GSettingsSchemaSource) schema_source; 44 g_autoptr(GSettingsSchema) schema; 45 schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 46 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution-data-server.addressbook", FALSE); 47 settings = g_settings_new_full(schema, g_settings_backend_get_default(), NULL); 48 } 49 g_object_unref(settings); 50} 51 52void schema_id_with_backend_and_path() { 53 GSettings *settings; 54 { 55 g_autoptr(GSettingsSchemaSource) schema_source; 56 g_autoptr(GSettingsSchema) schema; 57 schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL); 58 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE); 59 settings = g_settings_new_full(schema, g_settings_backend_get_default(), "/org/gnome/seahorse/nautilus/windows/123/"); 60 } 61 g_object_unref(settings); 62} 63 64void schema_id_with_path() { 65 GSettings *settings; 66 { 67 g_autoptr(GSettingsSchemaSource) schema_source; 68 g_autoptr(GSettingsSchema) schema; 69 schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL); 70 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE); 71 settings = g_settings_new_full(schema, NULL, "/org/gnome/seahorse/nautilus/windows/123/"); 72 } 73 g_object_unref(settings); 74} 75 76void exists_fn_guard() { 77 if (!e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 78 return; 79 } 80 81 g_autoptr(GSettings) settings = NULL; 82 { 83 g_autoptr(GSettingsSchemaSource) schema_source; 84 g_autoptr(GSettingsSchema) schema; 85 schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 86 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 87 settings = g_settings_new_full(schema, NULL, NULL); 88 } 89} 90 91void exists_fn_nested() { 92 if (e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 93 g_autoptr(GSettings) settings = NULL; 94 { 95 g_autoptr(GSettingsSchemaSource) schema_source; 96 g_autoptr(GSettingsSchema) schema; 97 schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 98 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 99 settings = g_settings_new_full(schema, NULL, NULL); 100 } 101 } 102} 103 104void exists_fn_unknown() { 105 if (e_ews_common_utils_gsettings_schema_exists("org.gnome.foo")) { 106 g_autoptr(GSettings) settings = NULL; 107 { 108 g_autoptr(GSettingsSchemaSource) schema_source; 109 g_autoptr(GSettingsSchema) schema; 110 schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 111 schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 112 settings = g_settings_new_full(schema, NULL, NULL); 113 } 114 } 115} 116 117int main() { 118 schema_id_literal(); 119 schema_id_from_constant(); 120 schema_id_autoptr(); 121 schema_id_with_backend(); 122 schema_id_with_backend_and_path(); 123 schema_id_with_path(); 124 exists_fn_guard(); 125 exists_fn_nested(); 126 exists_fn_unknown(); 127 128 return 0; 129}